|  | @@ -37,7 +37,10 @@
 | 
		
	
		
			
			| 37 | 37 |  				QSettings.setValue("script/report_unit", unitBox.currentIndex);
 | 
		
	
		
			
			| 38 | 38 |  				refresh();
 | 
		
	
		
			
			| 39 | 39 |  			});
 | 
		
	
		
			
			|  | 40 | +			var rowData = new Array();
 | 
		
	
		
			
			|  | 41 | +			var rowIndex;
 | 
		
	
		
			
			| 40 | 42 |              function refresh() {
 | 
		
	
		
			
			|  | 43 | +				rowIndex = 0;
 | 
		
	
		
			
			| 41 | 44 |                  var buffer = new QBuffer;
 | 
		
	
		
			
			| 42 | 45 |                  buffer.open(3);
 | 
		
	
		
			
			| 43 | 46 |                  var output = new XmlWriter(buffer);
 | 
		
	
	
		
			
			|  | @@ -119,7 +122,15 @@
 | 
		
	
		
			
			| 119 | 122 |                  while(query.next())
 | 
		
	
		
			
			| 120 | 123 |                  {
 | 
		
	
		
			
			| 121 | 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 | 134 |                      output.writeTextElement("td", query.value(1));
 | 
		
	
		
			
			| 124 | 135 |                      output.writeTextElement("td", query.value(2));
 | 
		
	
		
			
			| 125 | 136 |  					output.writeTextElement("td", query.value(3));
 | 
		
	
	
		
			
			|  | @@ -146,7 +157,15 @@
 | 
		
	
		
			
			| 146 | 157 |                  while(query.next())
 | 
		
	
		
			
			| 147 | 158 |                  {
 | 
		
	
		
			
			| 148 | 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 | 169 |                      output.writeTextElement("td", query.value(1));
 | 
		
	
		
			
			| 151 | 170 |                      output.writeTextElement("td", query.value(2));
 | 
		
	
		
			
			| 152 | 171 |  					output.writeTextElement("td", query.value(3));
 | 
		
	
	
		
			
			|  | @@ -170,6 +189,39 @@
 | 
		
	
		
			
			| 170 | 189 |                  QSettings.setValue("auco_sort", sortBox.currentIndex);
 | 
		
	
		
			
			| 171 | 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 | 226 |      </program>
 | 
		
	
		
			
			| 175 | 227 |  </window>
 |