Browse Source

Inventory Change Summary Report

Neal Wilson 11 years ago
parent
commit
255c5a0e9a
1 changed files with 128 additions and 0 deletions
  1. 128
    0
      config/Reports/invchange.xml

+ 128
- 0
config/Reports/invchange.xml View File

@@ -0,0 +1,128 @@
1
+<window id="invchange">
2
+	<reporttitle>Inventory:->Inventory Change Summary</reporttitle>
3
+	<layout type="vertical">
4
+		<layout type="horizontal">
5
+			<label>Start Date:</label>
6
+			<calendar id="startdate" />
7
+			<label>End Date:</label>
8
+			<calendar id="enddate" />
9
+			<label>Weight Unit:</label>
10
+			<sqldrop id="unit" />
11
+			<stretch />
12
+		</layout>
13
+		<webview id="report" />
14
+	</layout>
15
+	<menu name="File">
16
+		<item id="print" shortcut="Ctrl+P">Print</item>
17
+	</menu>
18
+	<program>
19
+		<![CDATA[
20
+			this.windowTitle = "Typica - Inventory Change Summary";
21
+			var startDateField = findChildObject(this, 'startdate');
22
+			startDateField.setDate(startDateField.year(), 1, 1);
23
+			var endDateField = findChildObject(this, 'enddate');
24
+			var unitBox = findChildObject(this, 'unit');
25
+			unitBox.addItem("Kg");
26
+			unitBox.addItem("Lb");
27
+			unitBox.currentIndex = QSettings.value("script/report_unit", 1);
28
+			unitBox['currentIndexChanged(int)'].connect(function() {
29
+				QSettings.setValue("script/report_unit", unitBox.currentIndex);
30
+				refresh();
31
+			});
32
+			var view = findChildObject(this, 'report');
33
+			var printMenu = findChildObject(this, 'print');
34
+			printMenu.triggered.connect(function() {
35
+				view.print();
36
+			});
37
+			function refresh() {
38
+				var buffer = new QBuffer;
39
+				buffer.open(3);
40
+				var output = new XmlWriter(buffer);
41
+				output.writeStartDocument("1.0");
42
+				output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
43
+				output.writeStartElement("html");
44
+				output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
45
+				output.writeStartElement("head");
46
+				output.writeTextElement("title", "Inventory Change Summary");
47
+				output.writeEndElement();
48
+				output.writeStartElement("body");
49
+				var startDate = "" + startDateField.year() + "-" + startDateField.month() + "-" + startDateField.day();
50
+				var endDate = "" + endDateField.year() + "-" + endDateField.month() + "-" + endDateField.day();
51
+				output.writeTextElement("h1", "Inventory Change Summary: " + startDate + " – " + endDate);
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";
54
+				query.prepare(q);
55
+				query.bind(":sd1", startDate);
56
+				query.bind(":sd2", startDate);
57
+				query.bind(":sd3", startDate);
58
+				query.bind(":sd4", startDate);
59
+				query.bind(":sd5", startDate);
60
+				query.bind(":sd6", startDate);
61
+				query.bind(":ed1", endDate);
62
+				query.bind(":ed2", endDate);
63
+				query.bind(":ed3", endDate);
64
+				query.bind(":ed4", endDate);
65
+				query.bind(":ed5", endDate);
66
+				query.bind(":ed6", endDate);
67
+				query.exec();
68
+				output.writeStartElement("table");
69
+				output.writeAttribute("rules", "groups");
70
+				output.writeAttribute("cellpadding", "3px");
71
+				output.writeStartElement("thead");
72
+				output.writeStartElement("tr");
73
+				output.writeTextElement("th", "ID"); // 0
74
+				output.writeTextElement("th", "Coffee"); // 1
75
+				output.writeTextElement("th", "Reference"); // 2
76
+				output.writeTextElement("th", "Starting (Lb)"); // 3
77
+				output.writeTextElement("th", "Cost"); // 10
78
+				output.writeTextElement("th", "Purchase (Lb)"); // 4
79
+				output.writeTextElement("th", "Cost"); // 11
80
+				output.writeTextElement("th", "Use (Lb)"); // 5
81
+				output.writeTextElement("th", "Cost"); // 12
82
+				output.writeTextElement("th", "Sale (Lb)"); // 6
83
+				output.writeTextElement("th", "Cost"); // 13
84
+				output.writeTextElement("th", "Adjustment (Lb)"); // 9
85
+				output.writeTextElement("th", "Cost"); // 15
86
+				output.writeTextElement("th", "Ending (Lb)"); // 7
87
+				output.writeTextElement("th", "Cost"); // 14
88
+				output.writeEndElement();
89
+				output.writeEndElement();
90
+				output.writeStartElement("tbody");
91
+				while(query.next())
92
+				{
93
+					output.writeStartElement("tr");
94
+					output.writeTextElement("td", query.value(0)); //ID
95
+					output.writeTextElement("td", query.value(1)); //Coffee
96
+					output.writeTextElement("td", query.value(2)); //Reference
97
+					output.writeTextElement("td", query.value(3)); //Starting Wt
98
+					output.writeTextElement("td", query.value(10)); //Starting Cost
99
+					output.writeTextElement("td", query.value(4)); //Purchase Wt
100
+					output.writeTextElement("td", query.value(11)); //Purchase Cost
101
+					output.writeTextElement("td", query.value(5)); //Use Wt
102
+					output.writeTextElement("td", query.value(12)); //Use Cost
103
+					output.writeTextElement("td", query.value(6)); //Sale Wt
104
+					output.writeTextElement("td", query.value(13)); //Sale Cost
105
+					output.writeTextElement("td", query.value(9)); //Adjustment Wt
106
+					output.writeTextElement("td", query.value(15)); //Adjustment Cost
107
+					output.writeTextElement("td", query.value(7)); //Ending Wt
108
+					output.writeTextElement("td", query.value(14)); //Ending Cost
109
+					output.writeEndElement();
110
+				}
111
+				output.writeEndElement(); // tbody
112
+				output.writeEndElement();
113
+				output.writeEndElement();
114
+				output.writeEndElement();
115
+				output.writeEndDocument();
116
+				view.setContent(buffer);
117
+				buffer.close();
118
+			}
119
+			refresh();
120
+			startDateField.dateChanged.connect(function() {
121
+				refresh();
122
+			});
123
+			endDateField.dateChanged.connect(function() {
124
+				refresh();
125
+			});
126
+		]]>
127
+	</program>
128
+</window>

Loading…
Cancel
Save