|  | @@ -14,12 +14,27 @@
 | 
		
	
		
			
			| 14 | 14 |  	<program>
 | 
		
	
		
			
			| 15 | 15 |  		<![CDATA[
 | 
		
	
		
			
			| 16 | 16 |  			var window = this;
 | 
		
	
		
			
			| 17 |  | -                        var invoiceID = 0;
 | 
		
	
		
			
			|  | 17 | +            var invoiceID = 0;
 | 
		
	
		
			
			| 18 | 18 |  			var table = findChildObject(this, 'itemtable');
 | 
		
	
		
			
			|  | 19 | +			var timefield = findChildObject(this, 'date');
 | 
		
	
		
			
			|  | 20 | +			var vendorfield = findChildObject(this, 'vendor');
 | 
		
	
		
			
			|  | 21 | +			var invoicefield = findChildObject(this, 'invoice');
 | 
		
	
		
			
			|  | 22 | +			var w = window;
 | 
		
	
		
			
			| 19 | 23 |  			this.setInvoiceID = function(arg) {
 | 
		
	
		
			
			| 20 |  | -				window.invoiceID = arg;
 | 
		
	
		
			
			| 21 |  | -                                invoiceID = arg;
 | 
		
	
		
			
			| 22 |  | -				window.windowTitle = TTR("invoiceinfo", "Typica - Invoice Details ") + arg;
 | 
		
	
		
			
			|  | 24 | +				w.invoiceID = arg;
 | 
		
	
		
			
			|  | 25 | +                invoiceID = arg;
 | 
		
	
		
			
			|  | 26 | +				w.windowTitle = TTR("invoiceinfo", "Typica - Invoice Details ") + arg;
 | 
		
	
		
			
			|  | 27 | +                var query = new QSqlQuery();
 | 
		
	
		
			
			|  | 28 | +                query.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + arg);
 | 
		
	
		
			
			|  | 29 | +                query.next();
 | 
		
	
		
			
			|  | 30 | +                timefield.text = query.value(0);
 | 
		
	
		
			
			|  | 31 | +                vendorfield.text = query.value(2);
 | 
		
	
		
			
			|  | 32 | +                invoicefield.text = query.value(1);
 | 
		
	
		
			
			|  | 33 | +                table.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");
 | 
		
	
		
			
			|  | 34 | +                query = query.invalidate();
 | 
		
	
		
			
			|  | 35 | +			};
 | 
		
	
		
			
			|  | 36 | +			this.refresh = function() {
 | 
		
	
		
			
			|  | 37 | +				w.setInvoiceID(w.invoiceID);
 | 
		
	
		
			
			| 23 | 38 |  			};
 | 
		
	
		
			
			| 24 | 39 |  			button = findChildObject(this, 'edit');
 | 
		
	
		
			
			| 25 | 40 |  			button.clicked.connect(function() {
 | 
		
	
	
		
			
			|  | @@ -34,6 +49,7 @@
 | 
		
	
		
			
			| 34 | 49 |  				if(table.data(arg, 0) == 'PURCHASE') {
 | 
		
	
		
			
			| 35 | 50 |  					var itemWindow = createWindow("invoiceitemdetail");
 | 
		
	
		
			
			| 36 | 51 |  					itemWindow.rowData = [];
 | 
		
	
		
			
			|  | 52 | +					itemWindow.pWindow = w;
 | 
		
	
		
			
			| 37 | 53 |  					for(var i = 0; i < 8; i++) {
 | 
		
	
		
			
			| 38 | 54 |  						itemWindow.rowData[i] = table.data(arg, i);
 | 
		
	
		
			
			| 39 | 55 |  					}
 | 
		
	
	
		
			
			|  | @@ -42,10 +58,11 @@
 | 
		
	
		
			
			| 42 | 58 |  				else {
 | 
		
	
		
			
			| 43 | 59 |  					var feeWindow = createWindow("invoicefeedetail");
 | 
		
	
		
			
			| 44 | 60 |  					feeWindow.rowData = [];
 | 
		
	
		
			
			|  | 61 | +					feeWindow.pWindow = w;
 | 
		
	
		
			
			| 45 | 62 |  					for(var i = 0; i < 8; i++) {
 | 
		
	
		
			
			| 46 | 63 |  						feeWindow.rowData[i] = table.data(arg, i);
 | 
		
	
		
			
			| 47 | 64 |  					}
 | 
		
	
		
			
			| 48 |  | -                                        feeWindow.invoiceID = invoiceID;
 | 
		
	
		
			
			|  | 65 | +                    feeWindow.invoiceID = invoiceID;
 | 
		
	
		
			
			| 49 | 66 |  					feeWindow.dataSet();
 | 
		
	
		
			
			| 50 | 67 |  				}
 | 
		
	
		
			
			| 51 | 68 |  			});
 |