|
@@ -66,7 +66,7 @@
|
66
|
66
|
unitText = TTR("invchange", "Kg");
|
67
|
67
|
}
|
68
|
68
|
var query = new QSqlQuery();
|
69
|
|
- 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)/:c1 AS starting_balance, COALESCE((SELECT sum(quantity) FROM purchase WHERE item = id AND time >= :sd2 AND time < :ed1 ::date + interval '1 day'), 0)/:c2 AS purchase, COALESCE((SELECT sum(quantity) FROM use WHERE item = id AND time >= :sd3 AND time < :ed2 ::date + interval '1 day'), 0)/:c3 AS use, COALESCE((SELECT sum(quantity) FROM sale WHERE item = id AND time >= :sd4 AND time < :ed3 ::date + interval '1 day'), 0)/:c4 AS sale, (SElECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed4 ::date + interval '1 day'))/:c5 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 * :c8 AS starting_cost, purchase * unit_cost * :c9 AS purchase_cost, use * unit_cost * :c10 AS use_cost, sale * unit_cost * :c11 AS sale_cost, quantity * unit_cost * :c12 AS quantity_cost, (starting_balance + purchase - use - sale - quantity) * unit_cost * :c13 AS adjustment_cost, (SELECT sum(quantity)/:c6 FROM purchase WHERE item = id) AS total_purchase FROM q ORDER BY name";
|
|
69
|
+ 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)/:c1 AS starting_balance, COALESCE((SELECT sum(quantity) FROM purchase WHERE item = id AND time >= :sd2 AND time < :ed1 ::date + interval '1 day'), 0)/:c2 AS purchase, COALESCE((SELECT sum(quantity) FROM use WHERE item = id AND time >= :sd3 AND time < :ed2 ::date + interval '1 day'), 0)/:c3 AS use, COALESCE((SELECT sum(quantity) FROM sale WHERE item = id AND time >= :sd4 AND time < :ed3 ::date + interval '1 day'), 0)/:c4 AS sale, COALESCE((SELECT sum(quantity) FROM loss WHERE item = id AND time >= :sd8 AND time < :ed8 ::date + interval '1 day'), 0)/:c14 AS loss, (SElECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed4 ::date + interval '1 day'))/:c5 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 - loss - quantity) AS adjustment, starting_balance * unit_cost * :c8 AS starting_cost, purchase * unit_cost * :c9 AS purchase_cost, use * unit_cost * :c10 AS use_cost, sale * unit_cost * :c11 AS sale_cost, loss * unit_cost * :c15 AS loss_cost, quantity * unit_cost * :c12 AS quantity_cost, (starting_balance + purchase - use - sale - loss - quantity) * unit_cost * :c13 AS adjustment_cost, (SELECT sum(quantity)/:c6 FROM purchase WHERE item = id) AS total_purchase FROM q ORDER BY name";
|
70
|
70
|
query.prepare(q);
|
71
|
71
|
query.bind(":sd1", startDate);
|
72
|
72
|
query.bind(":sd2", startDate);
|
|
@@ -74,6 +74,7 @@
|
74
|
74
|
query.bind(":sd4", startDate);
|
75
|
75
|
query.bind(":sd6", startDate);
|
76
|
76
|
query.bind(":sd7", startDate);
|
|
77
|
+ query.bind(":sd8", startDate);
|
77
|
78
|
query.bind(":ed1", endDate);
|
78
|
79
|
query.bind(":ed2", endDate);
|
79
|
80
|
query.bind(":ed3", endDate);
|
|
@@ -81,6 +82,7 @@
|
81
|
82
|
query.bind(":ed5", endDate);
|
82
|
83
|
query.bind(":ed6", endDate);
|
83
|
84
|
query.bind(":ed7", endDate);
|
|
85
|
+ query.bind(":ed8", endDate);
|
84
|
86
|
query.bind(":c1", conversion);
|
85
|
87
|
query.bind(":c2", conversion);
|
86
|
88
|
query.bind(":c3", conversion);
|
|
@@ -93,6 +95,8 @@
|
93
|
95
|
query.bind(":c11", conversion);
|
94
|
96
|
query.bind(":c12", conversion);
|
95
|
97
|
query.bind(":c13", conversion);
|
|
98
|
+ query.bind(":c14", conversion);
|
|
99
|
+ query.bind(":c15", conversion);
|
96
|
100
|
query.exec();
|
97
|
101
|
output.writeStartElement("table");
|
98
|
102
|
output.writeAttribute("rules", "groups");
|
|
@@ -103,17 +107,19 @@
|
103
|
107
|
output.writeTextElement("th", TTR("invchange", "Coffee")); // 1
|
104
|
108
|
output.writeTextElement("th", TTR("invchange", "Reference")); // 2
|
105
|
109
|
output.writeTextElement("th", TTR("invchange", "Starting (") + unitText + ")"); // 3
|
106
|
|
- output.writeTextElement("th", TTR("invchange", "Cost")); // 10
|
107
|
|
- output.writeTextElement("th", TTR("invchange", "Purchase (") + unitText + ")"); // 4
|
108
|
110
|
output.writeTextElement("th", TTR("invchange", "Cost")); // 11
|
109
|
|
- output.writeTextElement("th", TTR("invchange", "Use (") + unitText + ")"); // 5
|
|
111
|
+ output.writeTextElement("th", TTR("invchange", "Purchase (") + unitText + ")"); // 4
|
110
|
112
|
output.writeTextElement("th", TTR("invchange", "Cost")); // 12
|
111
|
|
- output.writeTextElement("th", TTR("invchange", "Sale (") + unitText + ")"); // 6
|
|
113
|
+ output.writeTextElement("th", TTR("invchange", "Use (") + unitText + ")"); // 5
|
112
|
114
|
output.writeTextElement("th", TTR("invchange", "Cost")); // 13
|
113
|
|
- output.writeTextElement("th", TTR("invchange", "Adjustment (") + unitText + ")"); // 9
|
114
|
|
- output.writeTextElement("th", TTR("invchange", "Cost")); // 15
|
115
|
|
- output.writeTextElement("th", TTR("invchange", "Ending (") + unitText + ")"); // 7
|
|
115
|
+ output.writeTextElement("th", TTR("invchange", "Sale (") + unitText + ")"); // 6
|
116
|
116
|
output.writeTextElement("th", TTR("invchange", "Cost")); // 14
|
|
117
|
+ output.writeTextElement("th", TTR("invchange", "Loss (") + unitText + ")"); // 7
|
|
118
|
+ output.writeTextElement("th", TTR("invchange", "Cost")) // 15
|
|
119
|
+ output.writeTextElement("th", TTR("invchange", "Adjustment (") + unitText + ")"); // 10
|
|
120
|
+ output.writeTextElement("th", TTR("invchange", "Cost")); // 17
|
|
121
|
+ output.writeTextElement("th", TTR("invchange", "Ending (") + unitText + ")"); // 8
|
|
122
|
+ output.writeTextElement("th", TTR("invchange", "Cost")); // 16
|
117
|
123
|
output.writeEndElement();
|
118
|
124
|
output.writeEndElement();
|
119
|
125
|
output.writeStartElement("tbody");
|
|
@@ -128,7 +134,9 @@
|
128
|
134
|
var sum9 = 0;
|
129
|
135
|
var sum15 = 0;
|
130
|
136
|
var sum7 = 0;
|
131
|
|
- var sum14 = 0;;
|
|
137
|
+ var sum14 = 0;
|
|
138
|
+ var loss_sum = 0;
|
|
139
|
+ var loss_cost_sum = 0;
|
132
|
140
|
while(query.next())
|
133
|
141
|
{
|
134
|
142
|
output.writeStartElement("tr");
|
|
@@ -141,48 +149,55 @@
|
141
|
149
|
output.writeTextElement("td", query.value(1)); //Coffee
|
142
|
150
|
output.writeTextElement("td", query.value(2)); //Reference
|
143
|
151
|
output.writeStartElement("td"); //Starting Wt
|
144
|
|
- output.writeAttribute("title", (parseFloat(query.value(3))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
|
152
|
+ output.writeAttribute("title", (parseFloat(query.value(3))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
145
|
153
|
output.writeCDATA(parseFloat(query.value(3)).toFixed(2));
|
146
|
154
|
output.writeEndElement(); //End of Starting Wt.
|
147
|
|
- output.writeTextElement("td", parseFloat(query.value(10)).toFixed(2)); //Starting Cost
|
|
155
|
+ output.writeTextElement("td", parseFloat(query.value(11)).toFixed(2)); //Starting Cost
|
148
|
156
|
output.writeStartElement("td"); //Purchase Wt
|
149
|
|
- output.writeAttribute("title", (parseFloat(query.value(4))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
|
157
|
+ output.writeAttribute("title", (parseFloat(query.value(4))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
150
|
158
|
output.writeCDATA(parseFloat(query.value(4)).toFixed(2));
|
151
|
159
|
output.writeEndElement(); //End of Purchase Wt
|
152
|
|
- output.writeTextElement("td", parseFloat(query.value(11)).toFixed(2)); //Purchase Cost
|
|
160
|
+ output.writeTextElement("td", parseFloat(query.value(12)).toFixed(2)); //Purchase Cost
|
153
|
161
|
output.writeStartElement("td"); //Use Wt
|
154
|
|
- output.writeAttribute("title", (parseFloat(query.value(5))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
|
162
|
+ output.writeAttribute("title", (parseFloat(query.value(5))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
155
|
163
|
output.writeCDATA(parseFloat(query.value(5)).toFixed(2));
|
156
|
164
|
output.writeEndElement(); //End of Use Wt
|
157
|
|
- output.writeTextElement("td", parseFloat(query.value(12)).toFixed(2)); //Use Cost
|
|
165
|
+ output.writeTextElement("td", parseFloat(query.value(13)).toFixed(2)); //Use Cost
|
158
|
166
|
output.writeStartElement("td"); //Sale Wt
|
159
|
|
- output.writeAttribute("title", (parseFloat(query.value(6))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
|
167
|
+ output.writeAttribute("title", (parseFloat(query.value(6))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
160
|
168
|
output.writeCDATA(parseFloat(query.value(6)).toFixed(2));
|
161
|
169
|
output.writeEndElement(); //End of Sale Wt
|
162
|
|
- output.writeTextElement("td", parseFloat(query.value(13)).toFixed(2)); //Sale Cost
|
163
|
|
- output.writeStartElement("td"); //Adjustment Wt
|
164
|
|
- output.writeAttribute("title", (parseFloat(query.value(9))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
165
|
|
- output.writeCDATA(parseFloat(query.value(9)).toFixed(2));
|
|
170
|
+ output.writeTextElement("td", parseFloat(query.value(14)).toFixed(2)); //Sale Cost
|
|
171
|
+ output.writeStartElement("td"); //Loss Wt
|
|
172
|
+ output.writeAttribute("title", (parseFloat(query.value(7))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
|
173
|
+ output.writeCDATA(parseFloat(query.value(7)).toFixed(2));
|
|
174
|
+ output.writeEndElement(); //End of loss Wt;
|
|
175
|
+ output.writeTextElement("td", parseFloat(query.value(15)).toFixed(2)); //Loss Cost
|
|
176
|
+ output.writeStartElement("td"); //Adjustment Wt
|
|
177
|
+ output.writeAttribute("title", (parseFloat(query.value(10))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
|
178
|
+ output.writeCDATA(parseFloat(query.value(10)).toFixed(2));
|
166
|
179
|
output.writeEndElement(); //Adjustment Wt
|
167
|
|
- output.writeTextElement("td", parseFloat(query.value(15)).toFixed(2)); //Adjustment Cost
|
|
180
|
+ output.writeTextElement("td", parseFloat(query.value(17)).toFixed(2)); //Adjustment Cost
|
168
|
181
|
output.writeStartElement("td"); //Ending Wt
|
169
|
|
- output.writeAttribute("title", (parseFloat(query.value(7))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
|
170
|
|
- output.writeCDATA(parseFloat(query.value(7)).toFixed(2));
|
|
182
|
+ output.writeAttribute("title", (parseFloat(query.value(8))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
|
|
183
|
+ output.writeCDATA(parseFloat(query.value(8)).toFixed(2));
|
171
|
184
|
output.writeEndElement(); //End of Ending Wt
|
172
|
|
- output.writeTextElement("td", parseFloat(query.value(14)).toFixed(2)); //Ending Cost
|
|
185
|
+ output.writeTextElement("td", parseFloat(query.value(16)).toFixed(2)); //Ending Cost
|
173
|
186
|
output.writeEndElement();
|
174
|
187
|
sum3 += parseFloat(query.value(3));
|
175
|
|
- sum10 += parseFloat(query.value(10));
|
|
188
|
+ sum10 += parseFloat(query.value(11));
|
176
|
189
|
sum4 += parseFloat(query.value(4));
|
177
|
|
- sum11 += parseFloat(query.value(11));
|
|
190
|
+ sum11 += parseFloat(query.value(12));
|
178
|
191
|
sum5 += parseFloat(query.value(5));
|
179
|
|
- sum12 += parseFloat(query.value(12));
|
|
192
|
+ sum12 += parseFloat(query.value(13));
|
180
|
193
|
sum6 += parseFloat(query.value(6));
|
181
|
|
- sum13 += parseFloat(query.value(13));
|
182
|
|
- sum9 += parseFloat(query.value(9));
|
183
|
|
- sum15 += parseFloat(query.value(15));
|
184
|
|
- sum7 += parseFloat(query.value(7));
|
185
|
|
- sum14 += parseFloat(query.value(14));
|
|
194
|
+ sum13 += parseFloat(query.value(14));
|
|
195
|
+ sum9 += parseFloat(query.value(10));
|
|
196
|
+ sum15 += parseFloat(query.value(17));
|
|
197
|
+ sum7 += parseFloat(query.value(8));
|
|
198
|
+ sum14 += parseFloat(query.value(16));
|
|
199
|
+ loss_sum += parseFloat(query.value(7));
|
|
200
|
+ loss_cost_sum += parseFloat(query.value(15));
|
186
|
201
|
}
|
187
|
202
|
output.writeEndElement(); // tbody
|
188
|
203
|
output.writeStartElement("tfoot");
|
|
@@ -198,6 +213,8 @@
|
198
|
213
|
output.writeTextElement("td", sum12.toFixed(2));
|
199
|
214
|
output.writeTextElement("td", sum6.toFixed(2));
|
200
|
215
|
output.writeTextElement("td", sum13.toFixed(2));
|
|
216
|
+ output.writeTextElement("td", loss_sum.toFixed(2));
|
|
217
|
+ output.writeTextElement("td", loss_cost_sum.toFixed(2));
|
201
|
218
|
output.writeTextElement("td", sum9.toFixed(2));
|
202
|
219
|
output.writeTextElement("td", sum15.toFixed(2));
|
203
|
220
|
output.writeTextElement("td", sum7.toFixed(2));
|