|
@@ -0,0 +1,71 @@
|
|
1
|
+<window id="editinventorytransaction">
|
|
2
|
+ <layout type="vertical">
|
|
3
|
+ <layout type="horizontal">
|
|
4
|
+ <label>Time:</label>
|
|
5
|
+ <line id="time" writable="false" />
|
|
6
|
+ <label>Item:</label>
|
|
7
|
+ <line id="item" writable="false" />
|
|
8
|
+ <label>Quantity:</label>
|
|
9
|
+ <line id="quantity" />
|
|
10
|
+ </layout>
|
|
11
|
+ <layout type="horizontal">
|
|
12
|
+ <button id="delete" name="Delete Transaction" type="push" />
|
|
13
|
+ <stretch />
|
|
14
|
+ <button id="save" name="Save Changes" type="push" />
|
|
15
|
+ </layout>
|
|
16
|
+ </layout>
|
|
17
|
+ <program>
|
|
18
|
+ <![CDATA[
|
|
19
|
+ var window = this;
|
|
20
|
+ var w = window;
|
|
21
|
+ this.windowTitle = TTR("editinventorytransaction", "Typica - Edit Inventory Transaction");
|
|
22
|
+ timeField = findChildObject(this, 'time');
|
|
23
|
+ itemField = findChildObject(this, 'item');
|
|
24
|
+ quantityField = findChildObject(this, 'quantity');
|
|
25
|
+ deleteButton = findChildObject(this, 'delete');
|
|
26
|
+ saveButton = findChildObject(this, 'save');
|
|
27
|
+ this.loadTransaction = function(item, timestamp) {
|
|
28
|
+ w.itemID = item;
|
|
29
|
+ w.timestamp = timestamp;
|
|
30
|
+ timeField.text = timestamp;
|
|
31
|
+ itemField.text = item;
|
|
32
|
+ var query = new QSqlQuery();
|
|
33
|
+ query.prepare("SELECT quantity FROM inventory WHERE time = :timestamp AND item = :item");
|
|
34
|
+ query.bind(":timestamp", timestamp);
|
|
35
|
+ query.bind(":item", item);
|
|
36
|
+ query.exec();
|
|
37
|
+ if(query.next()) {
|
|
38
|
+ quantityField.text = query.value(0);
|
|
39
|
+ }
|
|
40
|
+ query = query.invalidate();
|
|
41
|
+ };
|
|
42
|
+ saveButton.clicked.connect(function() {
|
|
43
|
+ var query = new QSqlQuery();
|
|
44
|
+ query.prepare("UPDATE inventory SET quantity = :quantity WHERE item = :item AND time = :timestamp");
|
|
45
|
+ query.bind(":quantity", Number(quantityField.text));
|
|
46
|
+ query.bind(":item", Number(itemField.text));
|
|
47
|
+ query.bind(":timestamp", timeField.text);
|
|
48
|
+ query.exec();
|
|
49
|
+ query.prepare("UPDATE items SET quantity = (SELECT balance FROM item_history(:item) ORDER BY time DESC LIMIT 1) WHERE id = :item2");
|
|
50
|
+ query.bind(":item", Number(itemField.text));
|
|
51
|
+ query.bind(":item2", Number(itemField.text));
|
|
52
|
+ query.exec();
|
|
53
|
+ query = query.invalidate();
|
|
54
|
+ window.close();
|
|
55
|
+ });
|
|
56
|
+ deleteButton.clicked.connect(function() {
|
|
57
|
+ var query = new QSqlQuery();
|
|
58
|
+ query.prepare("DELETE FROM inventory WHERE item = :item AND time = :timestamp");
|
|
59
|
+ query.bind(":item", Number(itemField.text));
|
|
60
|
+ query.bind(":timestamp", timeField.text);
|
|
61
|
+ query.exec();
|
|
62
|
+ query.prepare("UPDATE items SET quantity = (SELECT balance FROM item_history(:item) ORDER BY time DESC LIMIT 1) WHERE id = :item2");
|
|
63
|
+ query.bind(":item", Number(itemField.text));
|
|
64
|
+ query.bind(":item2", Number(itemField.text));
|
|
65
|
+ query.exec();
|
|
66
|
+ query = query.invalidate();
|
|
67
|
+ window.close();
|
|
68
|
+ });
|
|
69
|
+ ]]>
|
|
70
|
+ </program>
|
|
71
|
+</window>
|