浏览代码

Add item transaction report

Neal Wilson 11 年前
父节点
当前提交
86cd1dc2b1
共有 1 个文件被更改,包括 199 次插入0 次删除
  1. 199
    0
      config/Reports/itemtransactions.xml

+ 199
- 0
config/Reports/itemtransactions.xml 查看文件

@@ -0,0 +1,199 @@
1
+<window id="item_transactions">
2
+	<reporttitle>Inventory:->Item Transactions</reporttitle>
3
+	<layout type="vertical">
4
+		<layout type="horizontal">
5
+			<label>Item:</label>
6
+			<sqldrop id="item" data="0" display="1" showdata="true">
7
+				<null />
8
+				<query>SELECT id, name FROM items WHERE category = 'Coffee: Unroasted' ORDER BY name</query>
9
+			</sqldrop>
10
+			<label>Weight Unit:</label>
11
+			<sqldrop id="unit" />
12
+			<stretch />
13
+		</layout>
14
+		<webview id="report" />
15
+	</layout>
16
+	<menu name="File">
17
+		<item id="print" shortcut="Ctrl+P">Print</item>
18
+	</menu>
19
+	<program>
20
+		<![CDATA[
21
+			this.windowTitle = "Typica - Item Transactions";
22
+			var itemBox = findChildObject(this, 'item');
23
+			var unitBox = findChildObject(this, 'unit');
24
+			unitBox.addItem("Kg");
25
+			unitBox.addItem("Lb");
26
+			unitBox.currentIndex = QSettings.value("script/report_unit", 1);
27
+			unitBox['currentIndexChanged(int)'].connect(function() {
28
+				QSettings.setValue("script/report_unit", unitBox.currentIndex);
29
+				refresh();
30
+			});
31
+			var view = findChildObject(this, 'report');
32
+			var printMenu = findChildObject(this, 'print');
33
+			printMenu.triggered.connect(function() {
34
+				view.print();
35
+			});
36
+			itemBox['currentIndexChanged(int)'].connect(function() {
37
+				refresh();
38
+			});
39
+			function refresh() {
40
+				var buffer = new QBuffer;
41
+				buffer.open(3);
42
+				var output = new XmlWriter(buffer);
43
+				output.writeStartDocument("1.0");
44
+				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">');
45
+				output.writeStartElement("html");
46
+				output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
47
+				output.writeStartElement("head");
48
+				output.writeTextElement("title", "Item Transactions");
49
+				output.writeStartElement("style");
50
+				output.writeAttribute("type", "text/css");
51
+				output.writeCDATA("tr.PURCHASE {background-color: #77FF77}");
52
+				output.writeCDATA("tr.USE {background-color: #FFFFFF}");
53
+				output.writeCDATA("tr.INVENTORY {background-color: #7777FF}");
54
+				output.writeCDATA("tr.SALE {background-color: #FF77FF}");
55
+				output.writeCDATA("tr.LOSS {background-color: #FF7777}");
56
+				output.writeCDATA("tr.MAKE {background-color: #FFFF77}");
57
+				output.writeEndElement(); // style
58
+				
59
+				output.writeEndElement();
60
+				output.writeStartElement("body");
61
+				output.writeTextElement("h1", "Item Transactions:");
62
+				output.writeStartElement("table");
63
+				output.writeStartElement("tr");
64
+				output.writeStartElement("td");
65
+				output.writeTextElement("strong", "Item: ")
66
+				output.writeTextElement("span", itemBox.currentText);
67
+				output.writeEndElement(); // td
68
+				var query = new QSqlQuery();
69
+				query.prepare("SELECT reference, category FROM items WHERE id = :item");
70
+				query.bind(":item", itemBox.currentData());
71
+				query.exec();
72
+				if(query.next()) {
73
+					output.writeStartElement("td");
74
+					output.writeTextElement("strong", "Reference: ");
75
+					output.writeTextElement("span", query.value(0));
76
+					output.writeEndElement(); // td
77
+					output.writeStartElement("td");
78
+					output.writeTextElement("strong", "Category: ");
79
+					output.writeTextElement("span", query.value(1));
80
+					output.writeEndElement(); //td
81
+					output.writeEndElement(); //tr
82
+					query.prepare("SELECT origin, region, producer, grade, milling, drying FROM coffees WHERE id = :item");
83
+					query.bind(":item", itemBox.currentData());
84
+					query.exec();
85
+					if(query.next()) {
86
+						output.writeStartElement("tr");
87
+						output.writeStartElement("td");
88
+						output.writeTextElement("strong", "Origin: ");
89
+						output.writeTextElement("span", query.value(0));
90
+						output.writeEndElement(); // td
91
+						output.writeStartElement("td");
92
+						output.writeTextElement("strong", "Region: ");
93
+						output.writeTextElement("span", query.value(1));
94
+						output.writeEndElement(); // td
95
+						output.writeStartElement("td");
96
+						output.writeTextElement("strong", "Producer: ");
97
+						output.writeTextElement("span", query.value(2));
98
+						output.writeEndElement(); // td
99
+						output.writeEndElement(); // tr
100
+						output.writeStartElement("tr");
101
+						output.writeStartElement("td");
102
+						output.writeTextElement("strong", "Grade: ");
103
+						output.writeTextElement("span", query.value(3));
104
+						output.writeEndElement(); // td
105
+						output.writeStartElement("td");
106
+						output.writeTextElement("strong", "Milling: ");
107
+						output.writeTextElement("span", query.value(4));
108
+						output.writeEndElement(); // td
109
+						output.writeStartElement("td");
110
+						output.writeTextElement("strong", "Drying: ");
111
+						output.writeTextElement("span", query.value(5));
112
+						output.writeEndElement(); // td
113
+						output.writeEndElement(); // tr
114
+						query.prepare("SELECT decaf_method FROM decaf_coffees WHERE id = :item");
115
+						query.bind(":item", itemBox.currentData());
116
+						query.exec();
117
+						if(query.next()) {
118
+							output.writeStartElement("tr");
119
+							output.writeStartElement("td");
120
+							output.writeAttribute("colspan", "3");
121
+							output.writeTextElement("strong", "Decaffeination Method: ");
122
+							output.writeTextElement("span", query.value(0));
123
+							output.writeEndElement(); // td
124
+							output.writeEndElement(); // tr
125
+						}
126
+					}
127
+					output.writeEndElement() // table
128
+					
129
+					query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2 FROM item_history(:item)");
130
+					switch(unitBox.currentIndex)
131
+					{
132
+						case 0:
133
+							query.bind(":c1", 2.2);
134
+							query.bind(":c2", 2.2);
135
+							break;
136
+						case 1:
137
+							query.bind(":c1", 1);
138
+							query.bind(":c2", 1);
139
+							break;
140
+					}
141
+					query.bind(":item", itemBox.currentData());
142
+					query.exec();
143
+					output.writeStartElement("table");
144
+					output.writeStartElement("tr");
145
+					output.writeTextElement("th", "Date");
146
+					output.writeTextElement("th", "Type");
147
+					output.writeTextElement("th", "Quantity");
148
+					output.writeTextElement("th", "Balance");
149
+					output.writeEndElement(); // tr
150
+					var prev_balance = "0";
151
+					var prev_prec = 0;
152
+					var cur_prec = 0;
153
+					while(query.next()) {
154
+						output.writeStartElement("tr");
155
+						output.writeAttribute("class", query.value(1));
156
+						output.writeTextElement("td", query.value(0));
157
+						output.writeTextElement("td", query.value(1));
158
+						if(query.value(1) == "INVENTORY") {
159
+							var split = prev_balance.split('.');
160
+							if(split.length > 1) {
161
+								prev_prec = split[1].length;
162
+							} else {
163
+								prev_prec = 0;
164
+							}
165
+							split = query.value(2).split('.');
166
+							if(split.length > 1) {
167
+								cur_prec = split[1].length;
168
+							} else {
169
+								cur_prec = 0;
170
+							}
171
+							var prec = prev_prec > cur_prec ? prev_prec : cur_prec;
172
+							output.writeTextElement("td", (Number(query.value(2)) - Number(prev_balance)).toFixed(prec));
173
+						} else {
174
+							output.writeTextElement("td", query.value(2));
175
+						}
176
+						output.writeTextElement("td", query.value(3));
177
+						prev_balance = query.value(3);
178
+						output.writeEndElement(); // tr
179
+					}
180
+					output.writeEndElement(); // table
181
+					/* Put the rest of the report here. No sense running queries if
182
+					   the item doesn't exist. */
183
+				} else {
184
+					/* Close tags if item data not found. */
185
+					output.writeEndElement(); // tr
186
+					output.writeEndElement(); // table
187
+				}
188
+				
189
+				output.writeEndElement(); // body
190
+				output.writeEndElement(); // html
191
+				output.writeEndDocument();
192
+				view.setContent(buffer);
193
+				buffer.close();
194
+				query = query.invalidate();
195
+			}
196
+			refresh();
197
+		]]>
198
+	</program>
199
+</window>

正在加载...
取消
保存