|
@@ -1,109 +1,140 @@
|
1
|
1
|
<window id="inventory">
|
2
|
2
|
<layout type="vertical">
|
|
3
|
+ <layout type="horizontal">
|
|
4
|
+ <sqldrop id="transactiontype" />
|
|
5
|
+ <stretch />
|
|
6
|
+ </layout>
|
3
|
7
|
<layout type="horizontal">
|
4
|
8
|
<sqldrop data="0" display="1" showdata="true" id="item">
|
5
|
9
|
<query><![CDATA[SELECT id, name FROM coffees WHERE quantity <> 0 ORDER BY name ASC]]></query>
|
6
|
10
|
</sqldrop>
|
7
|
11
|
<line id="quantity" />
|
8
|
12
|
<sqldrop id="units" />
|
|
13
|
+ <label id="reasonlabel">Reason: </label>
|
|
14
|
+ <line id="reason" />
|
|
15
|
+ </layout>
|
|
16
|
+ <layout type="horizontal">
|
|
17
|
+ <stretch />
|
9
|
18
|
<button type="push" name="Update" id="update" />
|
10
|
19
|
</layout>
|
11
|
20
|
<textarea id="current" />
|
12
|
21
|
</layout>
|
13
|
22
|
<program>
|
14
|
23
|
<![CDATA[
|
15
|
|
- var units = findChildObject(this, 'units');
|
16
|
|
- units.addItem("bag");
|
17
|
|
- units.addItem("lb");
|
18
|
|
- units.addItem("kg");
|
19
|
|
- var items = findChildObject(this, 'item');
|
20
|
|
- var status = findChildObject(this, 'current');
|
21
|
|
- var q = "SELECT quantity FROM items WHERE id = ";
|
22
|
|
- q = q + items.currentData();
|
23
|
|
- query = new QSqlQuery();
|
24
|
|
- query.exec(q);
|
25
|
|
- query.next();
|
26
|
|
- var text = items.currentText;
|
27
|
|
- text = text + " Current inventory: ";
|
28
|
|
- text = text + query.value(0);
|
29
|
|
- text = text + " pounds ("
|
30
|
|
- text = text + Number(query.value(0)) / 2.2;
|
31
|
|
- text = text + " Kg (";
|
32
|
|
- q = "SELECT ";
|
33
|
|
- q = q + query.value(0);
|
34
|
|
- q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
35
|
|
- q = q + items.currentData();
|
36
|
|
- q = q + ")";
|
37
|
|
- query.exec(q);
|
38
|
|
- query.next();
|
39
|
|
- text = text + query.value(0);
|
40
|
|
- text = text + " bags)";
|
|
24
|
+ var types = findChildObject(this, 'transactiontype');
|
|
25
|
+ types.addItem("inventory");
|
|
26
|
+ types.addItem("loss");
|
|
27
|
+ var units = findChildObject(this, 'units');
|
|
28
|
+ units.addItem("bag");
|
|
29
|
+ units.addItem("lb");
|
|
30
|
+ units.addItem("kg");
|
|
31
|
+ var items = findChildObject(this, 'item');
|
|
32
|
+ var status = findChildObject(this, 'current');
|
|
33
|
+ var q = "SELECT quantity FROM items WHERE id = ";
|
|
34
|
+ q = q + items.currentData();
|
|
35
|
+ query = new QSqlQuery();
|
|
36
|
+ query.exec(q);
|
|
37
|
+ query.next();
|
|
38
|
+ var text = items.currentText;
|
|
39
|
+ text = text + " Current inventory: ";
|
|
40
|
+ text = text + query.value(0);
|
|
41
|
+ text = text + " pounds ("
|
|
42
|
+ text = text + Number(query.value(0)) / 2.2;
|
|
43
|
+ text = text + " Kg (";
|
|
44
|
+ q = "SELECT ";
|
|
45
|
+ q = q + query.value(0);
|
|
46
|
+ q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
|
47
|
+ q = q + items.currentData();
|
|
48
|
+ q = q + ")";
|
|
49
|
+ query.exec(q);
|
|
50
|
+ query.next();
|
|
51
|
+ text = text + query.value(0);
|
|
52
|
+text = text + " bags)";
|
41
|
53
|
query = query.invalidate();
|
42
|
|
- status.plainText = text;
|
43
|
|
- var button = findChildObject(this, 'update');
|
44
|
|
- var value = findChildObject(this, 'quantity');
|
45
|
|
- button.clicked.connect(function() {
|
46
|
|
- q = "INSERT INTO inventory (time, item, quantity) VALUES ('now', ";
|
47
|
|
- q = q + items.currentData();
|
48
|
|
- q = q + ", ";
|
49
|
|
- if(units.currentText == "lb") {
|
50
|
|
- q = q + value.text;
|
51
|
|
- } else if (units.currentText == "kg") {
|
52
|
|
- q = q + (value.text * 2.2);
|
53
|
|
- }
|
54
|
|
- else {
|
55
|
|
- q = q + value.text;
|
56
|
|
- q = q + " * (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
57
|
|
- q = q + items.currentData();
|
58
|
|
- q = q + ")";
|
59
|
|
- }
|
60
|
|
- q = q + ")";
|
|
54
|
+ status.plainText = text;
|
|
55
|
+ var button = findChildObject(this, 'update');
|
|
56
|
+ var value = findChildObject(this, 'quantity');
|
|
57
|
+ var reason = findChildObject(this, 'reason');
|
|
58
|
+ var reasonlabel = findChildObject(this, 'reasonlabel');
|
|
59
|
+ reason.enabled = false;
|
|
60
|
+ button.clicked.connect(function() {
|
|
61
|
+ q = "INSERT INTO ";
|
|
62
|
+ q += (types.currentIndex == 0 ?
|
|
63
|
+ "inventory (time, item, quantity)" :
|
|
64
|
+ "loss (time, item, quantity, reason)");
|
|
65
|
+ q += " VALUES ('now', ";
|
|
66
|
+ q = q + items.currentData();
|
|
67
|
+ q = q + ", ";
|
|
68
|
+ if(units.currentText == "lb") {
|
|
69
|
+ q = q + value.text;
|
|
70
|
+ } else if (units.currentText == "kg") {
|
|
71
|
+ q = q + (value.text * 2.2);
|
|
72
|
+ }
|
|
73
|
+ else {
|
|
74
|
+ q = q + value.text;
|
|
75
|
+ q = q + " * (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
|
76
|
+ q = q + items.currentData();
|
|
77
|
+ q = q + ")";
|
|
78
|
+ }
|
|
79
|
+ q += (types.currentIndex == 0 ?
|
|
80
|
+ ")" :
|
|
81
|
+ ", '" + reason.text + "')");
|
61
|
82
|
query = new QSqlQuery();
|
62
|
|
- query.exec(q);
|
63
|
|
- text = items.currentText;
|
64
|
|
- q = "SELECT quantity FROM items WHERE id = ";
|
65
|
|
- q = q + items.currentData();
|
66
|
|
- query.exec(q);
|
67
|
|
- query.next();
|
68
|
|
- text = text + " Current inventory: ";
|
69
|
|
- text = text + query.value(0);
|
70
|
|
- text = text + " pounds (";
|
71
|
|
- q = "SELECT ";
|
72
|
|
- q = q + query.value(0);
|
73
|
|
- q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
74
|
|
- q = q + items.currentData();
|
75
|
|
- q = q + ")";
|
76
|
|
- query.exec(q);
|
77
|
|
- query.next();
|
78
|
|
- text = text + query.value(0);
|
79
|
|
- text = text + " bags)";
|
80
|
|
- status.plainText = text;
|
|
83
|
+ query.exec(q);
|
|
84
|
+ text = items.currentText;
|
|
85
|
+ q = "SELECT quantity FROM items WHERE id = ";
|
|
86
|
+ q = q + items.currentData();
|
|
87
|
+ query.exec(q);
|
|
88
|
+ query.next();
|
|
89
|
+ text = text + " Current inventory: ";
|
|
90
|
+ text = text + query.value(0);
|
|
91
|
+ text = text + " pounds (";
|
|
92
|
+ q = "SELECT ";
|
|
93
|
+ q = q + query.value(0);
|
|
94
|
+ q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
|
95
|
+ q = q + items.currentData();
|
|
96
|
+ q = q + ")";
|
|
97
|
+ query.exec(q);
|
|
98
|
+ query.next();
|
|
99
|
+ text = text + query.value(0);
|
|
100
|
+ text = text + " bags)";
|
|
101
|
+ status.plainText = text;
|
81
|
102
|
query = query.invalidate();
|
82
|
|
- });
|
83
|
|
- items['currentIndexChanged(int)'].connect(function() {
|
84
|
|
- q = "SELECT quantity FROM items WHERE id = ";
|
85
|
|
- q = q + items.currentData();
|
|
103
|
+ });
|
|
104
|
+ items['currentIndexChanged(int)'].connect(function() {
|
|
105
|
+ q = "SELECT quantity FROM items WHERE id = ";
|
|
106
|
+ q = q + items.currentData();
|
86
|
107
|
query = new QSqlQuery();
|
87
|
|
- query.exec(q);
|
88
|
|
- query.next();
|
89
|
|
- var text = items.currentText;
|
90
|
|
- text = text + " Current inventory: ";
|
91
|
|
- text = text + query.value(0);
|
92
|
|
- text = text + " pounds ";
|
93
|
|
- text = text + Number(query.value(0)) / 2.2;
|
94
|
|
- text = text + " Kg (";
|
95
|
|
- q = "SELECT ";
|
96
|
|
- q = q + query.value(0);
|
97
|
|
- q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
98
|
|
- q = q + items.currentData();
|
99
|
|
- q = q + ")";
|
100
|
|
- query.exec(q);
|
101
|
|
- query.next();
|
102
|
|
- text = text + query.value(0);
|
103
|
|
- text = text + " bags)";
|
104
|
|
- status.plainText = text;
|
|
108
|
+ query.exec(q);
|
|
109
|
+ query.next();
|
|
110
|
+ var text = items.currentText;
|
|
111
|
+ text = text + " Current inventory: ";
|
|
112
|
+ text = text + query.value(0);
|
|
113
|
+ text = text + " pounds ";
|
|
114
|
+ text = text + Number(query.value(0)) / 2.2;
|
|
115
|
+ text = text + " Kg (";
|
|
116
|
+ q = "SELECT ";
|
|
117
|
+ q = q + query.value(0);
|
|
118
|
+ q = q + " / (SELECT conversion FROM lb_bag_conversion WHERE item = ";
|
|
119
|
+ q = q + items.currentData();
|
|
120
|
+ q = q + ")";
|
|
121
|
+ query.exec(q);
|
|
122
|
+ query.next();
|
|
123
|
+ text = text + query.value(0);
|
|
124
|
+ text = text + " bags)";
|
|
125
|
+ status.plainText = text;
|
105
|
126
|
query = query.invalidate();
|
106
|
|
- });
|
|
127
|
+ });
|
|
128
|
+ types['currentIndexChanged(int)'].connect(function(typeindex) {
|
|
129
|
+ switch(typeindex) {
|
|
130
|
+ case 0:
|
|
131
|
+ reason.enabled = false;
|
|
132
|
+ break;
|
|
133
|
+ case 1:
|
|
134
|
+ reason.enabled = true;
|
|
135
|
+ break;
|
|
136
|
+ }
|
|
137
|
+ });
|
107
|
138
|
]]>
|
108
|
139
|
</program>
|
109
|
140
|
</window>
|