Change variable name: periods to period
This commit is contained in:
parent
84ba62394d
commit
20231dd2a1
@ -16,6 +16,6 @@ body:json {
|
||||
"type":"sell",
|
||||
"currency":"IDR",
|
||||
"value":36000,
|
||||
"periods":"2025-01-01 18:32:35"
|
||||
"period":"2025-01-01 18:32:35"
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ body:json {
|
||||
"type":"buy",
|
||||
"currency":"IDR",
|
||||
"value":20000,
|
||||
"periods":"2025-01-01 18:32:35"
|
||||
"period":"2025-01-01 18:32:35"
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class inventory:
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
ls = []
|
||||
self.cursor.execute("SELECT item.id AS item_id, item.name AS item_name, SUM(CASE WHEN inv.flow = 'sell' THEN price.value * inv.qty WHEN inv.flow = 'buy' THEN -price.value * inv.qty ELSE 0 END) AS profit, SUM(CASE WHEN inv.flow = 'buy' THEN inv.qty WHEN inv.flow = 'sell' THEN -inv.qty ELSE 0 END) AS current_qty FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.periods <= inv.when ORDER BY sub.periods DESC LIMIT 1) GROUP BY item.id, item.name ORDER BY item.name ASC;")
|
||||
self.cursor.execute("SELECT item.id AS item_id, item.name AS item_name, SUM(CASE WHEN inv.flow = 'sell' THEN price.value * inv.qty WHEN inv.flow = 'buy' THEN -price.value * inv.qty ELSE 0 END) AS profit, SUM(CASE WHEN inv.flow = 'buy' THEN inv.qty WHEN inv.flow = 'sell' THEN -inv.qty ELSE 0 END) AS current_qty FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.period <= inv.when ORDER BY sub.period DESC LIMIT 1) GROUP BY item.id, item.name ORDER BY item.name ASC;")
|
||||
l1 = self.cursor.fetchall()
|
||||
c1 = 0
|
||||
for d1 in l1:
|
||||
@ -28,7 +28,7 @@ class inventory:
|
||||
"profit" : int(d1["profit" ]),
|
||||
"history" : []
|
||||
})
|
||||
self.cursor.execute("SELECT inv.id, inv.flow, DATE_FORMAT(inv.when, '%Y-%m-%d %H:%i:%S') AS `when`, DATE_FORMAT(price.periods, '%Y-%m-%d %H:%i:%S') AS price_periods, price.value AS price_value, inv.qty, (price.value * inv.qty) AS `total` FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.periods <= inv.when ORDER BY sub.periods DESC LIMIT 1 ) WHERE item.id = %s ORDER BY inv.when DESC; ", ( d1["item_id"], ) )
|
||||
self.cursor.execute("SELECT inv.id, inv.flow, DATE_FORMAT(inv.when, '%Y-%m-%d %H:%i:%S') AS `when`, DATE_FORMAT(price.period, '%Y-%m-%d %H:%i:%S') AS price_period, price.value AS price_value, inv.qty, (price.value * inv.qty) AS `total` FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.period <= inv.when ORDER BY sub.period DESC LIMIT 1 ) WHERE item.id = %s ORDER BY inv.when DESC; ", ( d1["item_id"], ) )
|
||||
l2 = self.cursor.fetchall()
|
||||
c2 = 0
|
||||
for d2 in l2:
|
||||
@ -37,7 +37,7 @@ class inventory:
|
||||
"flow" : d2["flow" ],
|
||||
"when" : d2["when" ],
|
||||
"price" : {
|
||||
"periods" : d2["price_periods" ],
|
||||
"period" : d2["price_period" ],
|
||||
"value" : d2["price_value" ]
|
||||
},
|
||||
"qty" : d2["qty" ],
|
||||
@ -68,7 +68,7 @@ class inventory:
|
||||
id = params["id"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("SELECT item.id AS item_id, item.name AS item_name, SUM(CASE WHEN inv.flow = 'sell' THEN price.value * inv.qty WHEN inv.flow = 'buy' THEN -price.value * inv.qty ELSE 0 END) AS profit, SUM(CASE WHEN inv.flow = 'buy' THEN inv.qty WHEN inv.flow = 'sell' THEN -inv.qty ELSE 0 END) AS current_qty FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.periods <= inv.when ORDER BY sub.periods DESC LIMIT 1) WHERE item.id = %s GROUP BY item.id, item.name ORDER BY item.name ASC;", ( id, ) )
|
||||
self.cursor.execute("SELECT item.id AS item_id, item.name AS item_name, SUM(CASE WHEN inv.flow = 'sell' THEN price.value * inv.qty WHEN inv.flow = 'buy' THEN -price.value * inv.qty ELSE 0 END) AS profit, SUM(CASE WHEN inv.flow = 'buy' THEN inv.qty WHEN inv.flow = 'sell' THEN -inv.qty ELSE 0 END) AS current_qty FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.period <= inv.when ORDER BY sub.period DESC LIMIT 1) WHERE item.id = %s GROUP BY item.id, item.name ORDER BY item.name ASC;", ( id, ) )
|
||||
d1 = self.cursor.fetchone()
|
||||
data = {
|
||||
"item":{
|
||||
@ -79,7 +79,7 @@ class inventory:
|
||||
"profit" : int(d1["profit" ]),
|
||||
"history" : []
|
||||
}
|
||||
self.cursor.execute("SELECT inv.id, inv.flow, DATE_FORMAT(inv.when, '%Y-%m-%d %H:%i:%S') AS `when`, DATE_FORMAT(price.periods, '%Y-%m-%d %H:%i:%S') AS price_periods, price.value AS price_value, inv.qty, (price.value * inv.qty) AS `total` FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.periods <= inv.when ORDER BY sub.periods DESC LIMIT 1 ) WHERE item.id = %s ORDER BY inv.when DESC; ", ( d1["item_id"], ) )
|
||||
self.cursor.execute("SELECT inv.id, inv.flow, DATE_FORMAT(inv.when, '%Y-%m-%d %H:%i:%S') AS `when`, DATE_FORMAT(price.period, '%Y-%m-%d %H:%i:%S') AS price_period, price.value AS price_value, inv.qty, (price.value * inv.qty) AS `total` FROM inventory inv LEFT JOIN item ON inv.item = item.id LEFT JOIN item_price price ON price.id = (SELECT sub.id FROM item_price sub WHERE sub.item = item.id AND sub.type = inv.flow AND sub.period <= inv.when ORDER BY sub.period DESC LIMIT 1 ) WHERE item.id = %s ORDER BY inv.when DESC; ", ( d1["item_id"], ) )
|
||||
l2 = self.cursor.fetchall()
|
||||
c2 = 0
|
||||
for d2 in l2:
|
||||
@ -88,7 +88,7 @@ class inventory:
|
||||
"flow" : d2["flow" ],
|
||||
"when" : d2["when" ],
|
||||
"price" : {
|
||||
"periods" : d2["price_periods" ],
|
||||
"period" : d2["price_period" ],
|
||||
"value" : d2["price_value" ]
|
||||
},
|
||||
"qty" : d2["qty" ],
|
||||
|
@ -27,9 +27,9 @@ class item:
|
||||
"sell":[]
|
||||
}
|
||||
})
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( d1["sku"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY period DESC, id DESC; ", ( d1["sku"], ) )
|
||||
ls[c1]["price"]["buy" ] = self.cursor.fetchall()
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( d1["sku"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY period DESC, id DESC; ", ( d1["sku"], ) )
|
||||
ls[c1]["price"]["sell"] = self.cursor.fetchall()
|
||||
c1+=1
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
@ -65,9 +65,9 @@ class item:
|
||||
"sell":[]
|
||||
}
|
||||
}
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( sku, ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY period DESC, id DESC; ", ( sku, ) )
|
||||
data["price"]["buy" ] = self.cursor.fetchall()
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( sku, ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY period DESC, id DESC; ", ( sku, ) )
|
||||
data["price"]["sell"] = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
|
@ -14,7 +14,7 @@ class price:
|
||||
response = {}
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` ORDER BY periods DESC, id DESC;")
|
||||
self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` FROM `item_price` ORDER BY period DESC, id DESC;")
|
||||
ls = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
@ -39,7 +39,7 @@ class price:
|
||||
id = params["id"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` FROM `item_price` WHERE id= %s ORDER BY periods DESC, id DESC;", (id,))
|
||||
self.cursor.execute("SELECT `id`, `sku`, `type`, `currency`, `value`, DATE_FORMAT(`period`, '%Y-%m-%d %H:%i:%S') AS `period` FROM `item_price` WHERE id= %s ORDER BY period DESC, id DESC;", (id,))
|
||||
data = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
@ -65,11 +65,11 @@ class price:
|
||||
type = params["type" ]
|
||||
currency = params["currency" ]
|
||||
value = params["value" ]
|
||||
periods = params["periods" ]
|
||||
period = params["period" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Inserting")
|
||||
self.cursor.execute("INSERT INTO `item_price` VALUES (DEFAULT, %s, %s, %s, %s, %s) ;", (sku, type, currency, value, periods) )
|
||||
self.cursor.execute("INSERT INTO `item_price` VALUES (DEFAULT, %s, %s, %s, %s, %s) ;", (sku, type, currency, value, period) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
@ -94,11 +94,11 @@ class price:
|
||||
type = params["type" ]
|
||||
currency = params["currency" ]
|
||||
value = params["value" ]
|
||||
periods = params["periods" ]
|
||||
period = params["period" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Updating")
|
||||
self.cursor.execute("UPDATE `item_price` SET `sku` = %s,`type` = %s,`currency` = %s,`value` = %s,`periods` = %s WHERE `id` = %s ;", (sku, type, currency, value, periods, key) )
|
||||
self.cursor.execute("UPDATE `item_price` SET `sku` = %s,`type` = %s,`currency` = %s,`value` = %s,`period` = %s WHERE `id` = %s ;", (sku, type, currency, value, period, key) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data change"
|
||||
|
@ -11,7 +11,7 @@ CREATE TABLE `item_price` (
|
||||
`type` VARCHAR(4) NOT NULL, -- buy, sell
|
||||
`currency` VARCHAR(3) NOT NULL,
|
||||
`value` INT(11) NOT NULL,
|
||||
`periods` DATETIME NOT NULL,
|
||||
`period` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `sku` (`sku`),
|
||||
CONSTRAINT `item_price_fk_sku`
|
||||
|
Loading…
Reference in New Issue
Block a user