Browse Source

Clean up inventory adjustment and loss transaction entries. Fixes #62.

Neal Wilson 8 years ago
parent
commit
442fe34e4e
1 changed files with 34 additions and 78 deletions
  1. 34
    78
      config/Windows/greeninventory.xml

+ 34
- 78
config/Windows/greeninventory.xml View File

@@ -1,6 +1,7 @@
1 1
 <window id="inventory">
2 2
     <layout type="vertical">
3 3
         <layout type="horizontal">
4
+            <label>Transaction type: </label>
4 5
             <sqldrop id="transactiontype" />
5 6
             <stretch />
6 7
         </layout>
@@ -10,12 +11,19 @@
10 11
             </sqldrop>
11 12
             <line id="quantity" />
12 13
             <sqldrop id="units" />
13
-            <label id="reasonlabel">Reason: </label>
14
-            <line id="reason" />
14
+            <layout type="stack" id="optional">
15
+                <page />
16
+                <page>    
17
+                    <layout type="horizontal">
18
+                        <label id="reasonlabel">Reason: </label>
19
+                        <line id="reason" />
20
+                    </layout>
21
+                </page>
22
+            </layout>
15 23
         </layout>
16 24
         <layout type="horizontal">
17
-            <stretch />
18 25
             <button type="push" name="Update" id="update" />
26
+            <stretch />
19 27
         </layout>
20 28
         <textarea id="current" />
21 29
     </layout>
@@ -24,34 +32,31 @@
24 32
             var types = findChildObject(this, 'transactiontype');
25 33
             types.addItem("inventory");
26 34
             types.addItem("loss");
35
+            var optionalDisplay = findChildObject(this, 'optional');
27 36
             var units = findChildObject(this, 'units');
28 37
             units.addItem("bag");
29 38
             units.addItem("lb");
30 39
             units.addItem("kg");
31 40
             var items = findChildObject(this, 'item');
32 41
             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)";
53
-            query = query.invalidate();
54
-            status.plainText = text;
42
+            function updateStatus() {
43
+                query = new QSqlQuery();
44
+                query.prepare("SELECT quantity, (quantity / 2.2)::numeric(12,3), (quantity / (SELECT conversion FROM lb_bag_conversion WHERE item = :id1))::numeric(12,2) FROM items WHERE id = :id2");
45
+                query.bind(":id1", items.currentData());
46
+                query.bind(":id2", items.currentData());
47
+                query.exec();
48
+                query.next();
49
+                var text = items.currentText;
50
+                text += " Current inventory: ";
51
+                text += query.value(0);
52
+                text += " Lb (";
53
+                text += query.value(1);
54
+                text += " Kg), ";
55
+                text += query.value(2);
56
+                text += (query.value(2) == "1" ? " bag" : " bags");
57
+                query = query.invalidate();
58
+                status.plainText = text;
59
+            }
55 60
             var button = findChildObject(this, 'update');
56 61
             var value = findChildObject(this, 'quantity');
57 62
             var reason = findChildObject(this, 'reason');
@@ -81,60 +86,11 @@ text = text + " bags)";
81 86
                     ", '" + reason.text + "')");
82 87
                 query = new QSqlQuery();
83 88
                 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;
102
-                query = query.invalidate();
103
-            });
104
-            items['currentIndexChanged(int)'].connect(function() {
105
-                q = "SELECT quantity FROM items WHERE id = ";
106
-                q = q + items.currentData();
107
-                query = new QSqlQuery();
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;
126
-                query = query.invalidate();
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
-                }
89
+                updateStatus();
137 90
             });
91
+            items['currentIndexChanged(int)'].connect(updateStatus);
92
+            types['currentIndexChanged(int)'].connect(optionalDisplay.setCurrentIndex);
93
+            updateStatus();
138 94
         ]]>
139 95
     </program>
140 96
 </window>

Loading…
Cancel
Save