Sfoglia il codice sorgente

Enable item drill down in AUCO report

Neal Wilson 10 anni fa
parent
commit
b1cc2657d6
1 ha cambiato i file con 54 aggiunte e 2 eliminazioni
  1. 54
    2
      config/Reports/auco.xml

+ 54
- 2
config/Reports/auco.xml Vedi File

37
 				QSettings.setValue("script/report_unit", unitBox.currentIndex);
37
 				QSettings.setValue("script/report_unit", unitBox.currentIndex);
38
 				refresh();
38
 				refresh();
39
 			});
39
 			});
40
+			var rowData = new Array();
41
+			var rowIndex;
40
             function refresh() {
42
             function refresh() {
43
+				rowIndex = 0;
41
                 var buffer = new QBuffer;
44
                 var buffer = new QBuffer;
42
                 buffer.open(3);
45
                 buffer.open(3);
43
                 var output = new XmlWriter(buffer);
46
                 var output = new XmlWriter(buffer);
119
                 while(query.next())
122
                 while(query.next())
120
                 {
123
                 {
121
                     output.writeStartElement("tr");
124
                     output.writeStartElement("tr");
122
-                    output.writeTextElement("td", query.value(0));
125
+					output.writeAttribute("id", "r" + rowIndex);
126
+					output.writeStartElement("td");
127
+					output.writeStartElement("a");
128
+					output.writeAttribute("href", "typica://script/r" + rowIndex);
129
+					rowIndex++;
130
+					rowData.push(query.value(0));
131
+					output.writeCharacters(query.value(0));
132
+					output.writeEndElement();
133
+					output.writeEndElement();
123
                     output.writeTextElement("td", query.value(1));
134
                     output.writeTextElement("td", query.value(1));
124
                     output.writeTextElement("td", query.value(2));
135
                     output.writeTextElement("td", query.value(2));
125
 					output.writeTextElement("td", query.value(3));
136
 					output.writeTextElement("td", query.value(3));
146
                 while(query.next())
157
                 while(query.next())
147
                 {
158
                 {
148
                     output.writeStartElement("tr");
159
                     output.writeStartElement("tr");
149
-                    output.writeTextElement("td", query.value(0));
160
+					output.writeAttribute("id", "d" + rowIndex);
161
+					output.writeStartElement("td");
162
+					output.writeStartElement("a");
163
+					output.writeAttribute("href", "typica://script/d" + rowIndex);
164
+					rowIndex++;
165
+					rowData.push(query.value(0));
166
+					output.writeCharacters(query.value(0));
167
+					output.writeEndElement();
168
+					output.writeEndElement();
150
                     output.writeTextElement("td", query.value(1));
169
                     output.writeTextElement("td", query.value(1));
151
                     output.writeTextElement("td", query.value(2));
170
                     output.writeTextElement("td", query.value(2));
152
 					output.writeTextElement("td", query.value(3));
171
 					output.writeTextElement("td", query.value(3));
170
                 QSettings.setValue("auco_sort", sortBox.currentIndex);
189
                 QSettings.setValue("auco_sort", sortBox.currentIndex);
171
                 refresh();
190
                 refresh();
172
             });
191
             });
192
+			report.scriptLinkClicked.connect(function(url) {
193
+				var element = new WebElement(report.findFirstElement("#" + url));
194
+				var regular = url[0] == 'r';
195
+				var index = url.slice(1, url.length);
196
+				var tableref;
197
+				if(regular) {
198
+					tableref = "regular_coffees";
199
+				} else {
200
+					tableref = "decaf_coffees";
201
+				}
202
+				var origin = rowData[Number(url.slice(1, url.length))];
203
+				var details = '<tr><td /><td colspan="6"><table><tr><th>Id</th><th>Name</th><th>Rate</th><th>Inventory</th><th>First Use</th><th>Last Use</th></tr>';
204
+				var query = new QSqlQuery();
205
+				query.prepare("SELECT id, name, (rate/:conversion1)::numeric(12,3), (stock/:conversion2)::numeric(12,3), (SELECT min(time)::date FROM use WHERE item = id) AS first_use, (SELECT max(time)::date FROM use WHERE item = id) AS last_use FROM coffee_history WHERE origin = :origin AND id IN (SELECT id FROM " + tableref + ") ORDER BY first_use DESC");
206
+				var conversion = 1;
207
+				if(unitBox.currentIndex == 0) {
208
+					conversion = 2.2;
209
+				}
210
+				query.bind(":conversion1", conversion);
211
+				query.bind(":conversion2", conversion);
212
+				query.bind(":origin", origin);
213
+				query.exec();
214
+				while(query.next()) {
215
+					details += "<tr>";
216
+					for(var i = 0; i < 6; i++) {
217
+						details += "<td>" + query.value(i) + "</td>";
218
+					}
219
+					details += "</tr>";
220
+				}
221
+				query = query.invalidate();
222
+				details += "</table></td></tr>";
223
+				element.appendOutside(details);
224
+			});
173
         ]]>
225
         ]]>
174
     </program>
226
     </program>
175
 </window>
227
 </window>

Loading…
Annulla
Salva