Browse Source

Improve data selection

Neal Wilson 11 years ago
parent
commit
24aca71c46
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      config/Reports/invchange.xml

+ 3
- 2
config/Reports/invchange.xml View File

50
 				var endDate = "" + endDateField.year() + "-" + endDateField.month() + "-" + endDateField.day();
50
 				var endDate = "" + endDateField.year() + "-" + endDateField.month() + "-" + endDateField.day();
51
 				output.writeTextElement("h1", "Inventory Change Summary: " + startDate + " – " + endDate);
51
 				output.writeTextElement("h1", "Inventory Change Summary: " + startDate + " – " + endDate);
52
 				var query = new QSqlQuery();
52
 				var query = new QSqlQuery();
53
-				var q = "WITH q AS (SELECT id, name, reference, COALESCE((SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :sd1)), 0) AS starting_balance, COALESCE((SELECT sum(quantity) FROM purchase WHERE item = id AND time >= :sd2 AND time < :ed1 ::date + interval '1 day'), 0) AS purchase, COALESCE((SELECT sum(quantity) FROM use WHERE item = id AND time >= :sd3 AND time < :ed2 ::date + interval '1 day'), 0) AS use, COALESCE((SELECT sum(quantity) FROM sale WHERE item = id AND time >= :sd4 AND time < :ed3 ::date + interval '1 day'), 0) AS sale, (SElECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed4 ::date + interval '1 day')) AS quantity, (SELECT sum(cost * quantity) / sum(quantity) FROM purchase WHERE item = id AND time >= :sd5 AND time < :ed5 ::date + interval '1 day') AS unit_cost FROM coffees WHERE id IN (SELECT item FROM purchase WHERE time >= :sd6) OR ((SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed6 ::date + interval '1 day')) > 0)) SELECT *, (starting_balance + purchase - use - sale - quantity) AS adjustment, starting_balance * unit_cost AS starting_cost, purchase * unit_cost AS purchase_cost, use * unit_cost AS use_cost, sale * unit_cost AS sale_cost, quantity * unit_cost AS quantity_cost, (starting_balance + purchase - use - sale - quantity) * unit_cost AS adjustment_cost FROM q ORDER BY name";
53
+					var q = "WITH q AS (SELECT id, name, reference, COALESCE((SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :sd1)), 0) AS starting_balance, COALESCE((SELECT sum(quantity) FROM purchase WHERE item = id AND time >= :sd2 AND time < :ed1 ::date + interval '1 day'), 0) AS purchase, COALESCE((SELECT sum(quantity) FROM use WHERE item = id AND time >= :sd3 AND time < :ed2 ::date + interval '1 day'), 0) AS use, COALESCE((SELECT sum(quantity) FROM sale WHERE item = id AND time >= :sd4 AND time < :ed3 ::date + interval '1 day'), 0) AS sale, (SElECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed4 ::date + interval '1 day')) AS quantity, (SELECT sum(cost * quantity) / sum(quantity) FROM purchase WHERE item = id) AS unit_cost FROM coffees WHERE id IN (SELECT item FROM purchase WHERE time >= :sd6 AND time < :ed5 ::date + interval '1 day') OR id IN (SELECT id FROM items WHERE (SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed6 ::date + interval '1 day')) > 0) OR id IN (SELECT DISTINCT item FROM all_transactions WHERE time > :sd7 AND time < :ed7 ::date + interval '1 day')) SELECT *, (starting_balance + purchase - use - sale - quantity) AS adjustment, starting_balance * unit_cost AS starting_cost, purchase * unit_cost AS purchase_cost, use * unit_cost AS use_cost, sale * unit_cost AS sale_cost, quantity * unit_cost AS quantity_cost, (starting_balance + purchase - use - sale - quantity) * unit_cost AS adjustment_cost FROM q ORDER BY name";
54
 				query.prepare(q);
54
 				query.prepare(q);
55
 				query.bind(":sd1", startDate);
55
 				query.bind(":sd1", startDate);
56
 				query.bind(":sd2", startDate);
56
 				query.bind(":sd2", startDate);
57
 				query.bind(":sd3", startDate);
57
 				query.bind(":sd3", startDate);
58
 				query.bind(":sd4", startDate);
58
 				query.bind(":sd4", startDate);
59
-				query.bind(":sd5", startDate);
60
 				query.bind(":sd6", startDate);
59
 				query.bind(":sd6", startDate);
60
+				query.bind(":sd7", startDate);
61
 				query.bind(":ed1", endDate);
61
 				query.bind(":ed1", endDate);
62
 				query.bind(":ed2", endDate);
62
 				query.bind(":ed2", endDate);
63
 				query.bind(":ed3", endDate);
63
 				query.bind(":ed3", endDate);
64
 				query.bind(":ed4", endDate);
64
 				query.bind(":ed4", endDate);
65
 				query.bind(":ed5", endDate);
65
 				query.bind(":ed5", endDate);
66
 				query.bind(":ed6", endDate);
66
 				query.bind(":ed6", endDate);
67
+				query.bind(":ed7", endDate);
67
 				query.exec();
68
 				query.exec();
68
 				output.writeStartElement("table");
69
 				output.writeStartElement("table");
69
 				output.writeAttribute("rules", "groups");
70
 				output.writeAttribute("rules", "groups");

Loading…
Cancel
Save