Browse Source

Enable drill down.

Neal Wilson 11 years ago
parent
commit
4a8e4fdf35
1 changed files with 59 additions and 3 deletions
  1. 59
    3
      config/Reports/fypurchase.xml

+ 59
- 3
config/Reports/fypurchase.xml View File

@@ -83,15 +83,18 @@
83 83
 				var query = new QSqlQuery();
84 84
 				for(var i = startDateField.year(); i <= endDateField.year(); i++)
85 85
 				{
86
-					var q = "SELECT sum(quantity/(SELECT conversion FROM lb_bag_conversion WHERE item = purchase.item)), (sum(quantity) / :conversion)::numeric(12,2), sum(cost*quantity)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
87
-					query.prepare(q);
88 86
 					output.writeStartElement("tr");
89 87
 					output.writeAttribute("id", "y"+i);
88
+					var q = "SELECT sum(quantity/(SELECT conversion FROM lb_bag_conversion WHERE item = purchase.item)), (sum(quantity) / :conversion)::numeric(12,2), sum(cost*quantity)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
89
+					query.prepare(q);
90 90
 					query.bind(":conversion", unitBox.currentIndex == 0 ? 2.2 : 1);
91 91
 					query.exec();
92 92
 					query.next();
93
-					output.writeStartElement("th");
93
+					output.writeStartElement("th", i);
94
+					output.writeStartElement("a");
95
+					output.writeAttribute("href", "typica://script/y" + i);
94 96
 					output.writeCharacters(i);
97
+					output.writeEndElement(); //a
95 98
 					output.writeEndElement(); //th
96 99
 					output.writeTextElement("td", query.value(0));
97 100
 					output.writeTextElement("td", query.value(1));
@@ -124,6 +127,59 @@
124 127
 			endDateField.dateChanged.connect(function() {
125 128
 				refresh();
126 129
 			});
130
+			/* Expand year data */
131
+			var expandedYears = new Array();
132
+			var expandYear = function(url) {
133
+				if(expandedYears.indexOf(url) == -1) {
134
+					expandedYears.push(url);
135
+					var element = new WebElement(view.findFirstElement("#" + url));
136
+					var year = url.slice(1,url.length);
137
+					var details = '<tr><td /><td colspan="3"><table><tr><th>Id</th><th>Invoice</th><th>Vendor</th><th>Cost</th></tr>';
138
+					q = "SELECT id, invoice, vendor, (SELECT sum(cost) FROM invoice_items WHERE invoice_id = id) FROM invoices WHERE time >= '" + year + "-01-01' AND time <= '" + year + "-12-31'";
139
+					var query = new QSqlQuery();
140
+					query.exec(q);
141
+					while(query.next())
142
+					{
143
+						details += '<tr><td><a href="typica://script/i' + query.value(0) + '">' + query.value(0) + '</a></td>';
144
+						details += '<td>' + query.value(1) + '</td>';
145
+						details += '<td>' + query.value(2) + '</td>';
146
+						details += '<td>' + Number(query.value(3)).toFixed(2) + '</td></tr>';
147
+					}
148
+					query = query.invalidate();
149
+					details += '</table></td></tr>'
150
+					element.appendOutside(details);
151
+				}
152
+			};
153
+			/* Open invoices */
154
+			var openInvoice = function(url) {
155
+				var arg = url.slice(1, url.length);
156
+				var info = createWindow("invoiceinfo");
157
+				info.setInvoiceID(arg);
158
+				var query = new QSqlQuery();
159
+				query.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + arg);
160
+				query.next();
161
+				var timefield = findChildObject(info, 'date');
162
+				timefield.text = query.value(0);
163
+				var vendorfield = findChildObject(info, 'vendor');
164
+				vendorfield.text = query.value(2);
165
+				var invoicefield = findChildObject(info, 'invoice');
166
+				invoicefield.text = query.value(1);
167
+				var itemtable = findChildObject(info, 'itemtable');
168
+				itemtable.setQuery("SELECT record_type, item_id, description, (SELECT reference FROM items WHERE id = item_id) AS reference, (SELECT cost FROM purchase WHERE item = item_id) AS unit_cost, (SELECT quantity FROM purchase WHERE item = item_id) AS quantity, ((SELECT quantity FROM purchase WHERE item = item_id)/(SELECT conversion FROM lb_bag_conversion WHERE item = item_id))::numeric(12,2) AS sacks, cost FROM invoice_items WHERE invoice_id = " + arg + " AND record_type = 'PURCHASE' UNION SELECT record_type, NULL, description, NULL, NULL, NULL, NULL, cost FROM invoice_items WHERE invoice_id = " + arg + " AND record_type = 'FEE' ORDER BY item_id");
169
+				query = query.invalidate();
170
+			};
171
+			/* Dispatch script link clicks */
172
+			view.scriptLinkClicked.connect(function(url) {
173
+				var linkType = url[0];
174
+				switch(linkType) {
175
+					case 'y':
176
+						expandYear(url);
177
+						break
178
+					case 'i':
179
+						openInvoice(url);
180
+						break;
181
+				}
182
+			});
127 183
 		]]>
128 184
 	</program>
129 185
 </window>

Loading…
Cancel
Save