Browse Source

Fix transaction search inequality in Inventory section

Neal Wilson 11 years ago
parent
commit
30cf433917
1 changed files with 31 additions and 15 deletions
  1. 31
    15
      config/Reports/dailyproductiondetail.xml

+ 31
- 15
config/Reports/dailyproductiondetail.xml View File

312
 				output.writeEndElement();
312
 				output.writeEndElement();
313
 				output.writeEndElement();
313
 				output.writeEndElement();
314
 				output.writeStartElement("tbody");
314
 				output.writeStartElement("tbody");
315
-				q = "SELECT DISTINCT item, (SELECT name FROM items WHERE id = item) AS name, (SELECT out FROM coffee_history WHERE id = item) FROM all_transactions WHERE time > '" + dateString + "' AND time < '" + dateString + "'::date + integer '1' ORDER BY name ASC";
315
+				q = "SELECT DISTINCT item, (SELECT name FROM items WHERE id = item) AS name, (SELECT out FROM coffee_history WHERE id = item) FROM all_transactions WHERE time >= '" + dateString + "' AND time < '" + dateString + "'::date + integer '1' ORDER BY name ASC";
316
 				query.exec(q)
316
 				query.exec(q)
317
 				var subQuery = new QSqlQuery();
317
 				var subQuery = new QSqlQuery();
318
 				var qq;
318
 				var qq;
319
 				while(query.next())
319
 				while(query.next())
320
 				{
320
 				{
321
-					output.writeStartElement("tr");
322
-					output.writeTextElement("td", query.value(1));
321
+					var validRow = true;
322
+					var td1 = query.value(1);
323
+					var td2 = 0;
324
+					var td3 = 0;
325
+					var td4 = 0;
326
+					var td5 = query.value(2);
323
 					qq = "SELECT balance FROM item_history(" + query.value(0) + ") WHERE time = (SELECT max(time) FROM all_transactions WHERE time <= '" + dateString + "' AND item = " + query.value(0) + ") OR time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "'::date + integer '1' AND item = " + query.value(0) + ") ORDER BY time ASC";
327
 					qq = "SELECT balance FROM item_history(" + query.value(0) + ") WHERE time = (SELECT max(time) FROM all_transactions WHERE time <= '" + dateString + "' AND item = " + query.value(0) + ") OR time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "'::date + integer '1' AND item = " + query.value(0) + ") ORDER BY time ASC";
324
 					subQuery.exec(qq);
328
 					subQuery.exec(qq);
325
 					var startValue = "0.0";
329
 					var startValue = "0.0";
329
 						switch(unitBox.currentIndex)
333
 						switch(unitBox.currentIndex)
330
 						{
334
 						{
331
 							case 0:
335
 							case 0:
332
-								output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
336
+								td2 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
333
 								break;
337
 								break;
334
 							case 1:
338
 							case 1:
335
-								output.writeTextElement("td", subQuery.value(0));
339
+								td2 = subQuery.value(0);
336
 								break;
340
 								break;
337
 						}
341
 						}
338
 						startValue = subQuery.value(0);
342
 						startValue = subQuery.value(0);
339
 					}
343
 					}
340
 					else
344
 					else
341
 					{
345
 					{
342
-						output.writeEmptyElement("td");
346
+						/* This should never happen. */
347
+						validRow = false;
343
 					}
348
 					}
344
 					if(subQuery.next())
349
 					if(subQuery.next())
345
 					{
350
 					{
346
 						switch(unitBox.currentIndex)
351
 						switch(unitBox.currentIndex)
347
 						{
352
 						{
348
 							case 0:
353
 							case 0:
349
-								output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
354
+								td3 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
350
 								break;
355
 								break;
351
 							case 1:
356
 							case 1:
352
-								output.writeTextElement("td", subQuery.value(0));
357
+								td3 = subQuery.value(0);
353
 								break;
358
 								break;
354
 						}
359
 						}
355
 						endValue = subQuery.value(0);
360
 						endValue = subQuery.value(0);
356
 					}
361
 					}
357
 					else
362
 					else
358
 					{
363
 					{
359
-						output.writeEmptyElement("td");
364
+						/* If only one transaction exists for the current query
365
+						   this is a purchase transaction. Until something is
366
+						   done with the coffee, it should not appear in this
367
+						   section of the report. */
368
+						endValue = startValue;
369
+						validRow = false;
360
 					}
370
 					}
361
 					var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
371
 					var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
362
 					var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
372
 					var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
363
 					switch(unitBox.currentIndex)
373
 					switch(unitBox.currentIndex)
364
 					{
374
 					{
365
 						case 0:
375
 						case 0:
366
-							output.writeTextElement("td", (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec)));
376
+							td4 = (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec));
367
 							break;
377
 							break;
368
 						case 1:
378
 						case 1:
369
-							output.writeTextElement("td", (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec)));
379
+							td4 = (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec));
370
 							break;
380
 							break;
371
-					}					
372
-					output.writeTextElement("td", query.value(2));
373
-					output.writeEndElement();
381
+					}
382
+					if(validRow) {
383
+						output.writeStartElement("tr");
384
+						output.writeTextElement("td", td1);
385
+						output.writeTextElement("td", td2);
386
+						output.writeTextElement("td", td3);
387
+						output.writeTextElement("td", td4);
388
+						output.writeTextElement("td", td5);
389
+						output.writeEndElement();
390
+					}
374
 				}
391
 				}
375
 				query = query.invalidate();
392
 				query = query.invalidate();
376
 				subQuery = subQuery.invalidate();
393
 				subQuery = subQuery.invalidate();
380
 				output.writeEndElement();
397
 				output.writeEndElement();
381
 				output.writeEndElement();//End of inventory table
398
 				output.writeEndElement();//End of inventory table
382
 				
399
 				
383
-				
384
 				output.writeEndElement();
400
 				output.writeEndElement();
385
 				output.writeEndElement();
401
 				output.writeEndElement();
386
 				output.writeEndDocument();
402
 				output.writeEndDocument();

Loading…
Cancel
Save