|
@@ -312,14 +312,18 @@
|
312
|
312
|
output.writeEndElement();
|
313
|
313
|
output.writeEndElement();
|
314
|
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
|
316
|
query.exec(q)
|
317
|
317
|
var subQuery = new QSqlQuery();
|
318
|
318
|
var qq;
|
319
|
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
|
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
|
328
|
subQuery.exec(qq);
|
325
|
329
|
var startValue = "0.0";
|
|
@@ -329,48 +333,61 @@
|
329
|
333
|
switch(unitBox.currentIndex)
|
330
|
334
|
{
|
331
|
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
|
337
|
break;
|
334
|
338
|
case 1:
|
335
|
|
- output.writeTextElement("td", subQuery.value(0));
|
|
339
|
+ td2 = subQuery.value(0);
|
336
|
340
|
break;
|
337
|
341
|
}
|
338
|
342
|
startValue = subQuery.value(0);
|
339
|
343
|
}
|
340
|
344
|
else
|
341
|
345
|
{
|
342
|
|
- output.writeEmptyElement("td");
|
|
346
|
+ /* This should never happen. */
|
|
347
|
+ validRow = false;
|
343
|
348
|
}
|
344
|
349
|
if(subQuery.next())
|
345
|
350
|
{
|
346
|
351
|
switch(unitBox.currentIndex)
|
347
|
352
|
{
|
348
|
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
|
355
|
break;
|
351
|
356
|
case 1:
|
352
|
|
- output.writeTextElement("td", subQuery.value(0));
|
|
357
|
+ td3 = subQuery.value(0);
|
353
|
358
|
break;
|
354
|
359
|
}
|
355
|
360
|
endValue = subQuery.value(0);
|
356
|
361
|
}
|
357
|
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
|
371
|
var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
|
362
|
372
|
var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
|
363
|
373
|
switch(unitBox.currentIndex)
|
364
|
374
|
{
|
365
|
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
|
377
|
break;
|
368
|
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
|
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
|
392
|
query = query.invalidate();
|
376
|
393
|
subQuery = subQuery.invalidate();
|
|
@@ -380,7 +397,6 @@
|
380
|
397
|
output.writeEndElement();
|
381
|
398
|
output.writeEndElement();//End of inventory table
|
382
|
399
|
|
383
|
|
-
|
384
|
400
|
output.writeEndElement();
|
385
|
401
|
output.writeEndElement();
|
386
|
402
|
output.writeEndDocument();
|