浏览代码

COGR report now allows selection between cost per pound or cost per kilo

Neal Wilson 9 年前
父节点
当前提交
33ed49fe5d
共有 1 个文件被更改,包括 160 次插入141 次删除
  1. 160
    141
      config/Reports/cogr.xml

+ 160
- 141
config/Reports/cogr.xml 查看文件

@@ -1,151 +1,170 @@
1 1
 <window id="greencost">
2
-	<reporttitle>Production:->Cost of Green Coffee for Roasted Coffee</reporttitle>
3
-	<layout type="vertical">
4
-		<webview id="report" />
5
-	</layout>
6
-	<menu name="File">
7
-		<item id="print" shortcut="Ctrl+P">Print</item>
8
-	</menu>
9
-	<program>
10
-		<![CDATA[
11
-			this.windowTitle = "Typica - Cost of Green Coffee for Roasted Coffee";
12
-			var report = findChildObject(this, 'report');
13
-			var printMenu = findChildObject(this, 'print');
14
-			printMenu.triggered.connect(function() {
15
-				report.print();
16
-			});
17
-			function refresh() {
18
-				var buffer = new QBuffer;
19
-				buffer.open(3);
20
-				var output = new XmlWriter(buffer);
21
-				output.writeStartDocument("1.0");
22
-				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">');
2
+    <reporttitle>Production:->Cost of Green Coffee for Roasted Coffee</reporttitle>	<layout type="vertical">
3
+        <layout type="horizontal">
4
+            <label>Weight Unit:</label>
5
+            <sqldrop id="unit" />
6
+            <stretch />
7
+        </layout>
8
+        <webview id="report" />
9
+    </layout>
10
+    <menu name="File">
11
+        <item id="print" shortcut="Ctrl+P">Print</item>
12
+    </menu>
13
+    <program>
14
+        <![CDATA[
15
+            this.windowTitle = "Typica - Cost of Green Coffee for Roasted Coffee";
16
+            var report = findChildObject(this, 'report');
17
+            var printMenu = findChildObject(this, 'print');
18
+            printMenu.triggered.connect(function() {
19
+                report.print();
20
+            });
21
+            var unitBox = findChildObject(this, 'unit');
22
+            unitBox.addItem("Kg");
23
+            unitBox.addItem("Lb");
24
+            unitBox.currentIndex = QSettings.value("script/report_unit", 1);
25
+            unitBox['currentIndexChanged(int)'].connect(function() {
26
+                QSettings.setValue("script/report_unit", unitBox.currentIndex);
27
+                refresh();
28
+            });
29
+            function refresh() {
30
+                var conversion = 1;
31
+                if(unitBox.currentIndex == 0) {
32
+                    conversion = 2.2;
33
+                }
34
+                var buffer = new QBuffer;
35
+                buffer.open(3);
36
+                var output = new XmlWriter(buffer);
37
+                output.writeStartDocument("1.0");
38
+                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">');
23 39
                 output.writeStartElement("html");
24 40
                 output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
25 41
                 output.writeStartElement("head");
26 42
                 output.writeTextElement("title", "Cost of Green Coffee for Roasted Coffee");
27 43
                 output.writeEndElement();
28 44
                 output.writeStartElement("body");
45
+                var unit = (unitBox.currentIndex == 0 ? "Kg" : "Lb");
29 46
                 output.writeTextElement("h1", "Cost of Green Coffee for Roasted Coffee");
30
-				var query = new QSqlQuery();
31
-				query.exec("SELECT item, (SELECT name FROM items WHERE id = item) AS name FROM current_items ORDER BY name");
32
-				var roastedItems = new Array();
33
-				var roastedNames = new Array();
34
-				while(query.next()) {
35
-					roastedItems.push(query.value(0));
36
-					roastedNames.push(query.value(1));
37
-				}
38
-				var recipes = new Array();
39
-				var recipeQuantities = new Array();
40
-				query.prepare("SELECT unroasted_id, unroasted_quantity FROM roasting_log WHERE roasted_id = :item AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = :item2)");
41
-				for(var i = 0; i < roastedItems.length; i++) {
42
-					query.bind("item", roastedItems[i]);
43
-					query.bind("item2", roastedItems[i]);
44
-					query.exec();
45
-					if(query.next()) {
46
-						recipes.push(query.value(0));
47
-						recipeQuantities.push(query.value(1));
48
-					} else {
49
-						recipes.push("{-1}");
50
-						recipeQuantities.push("{-1}");
51
-					}
52
-				}
53
-				query.prepare("SELECT min(unroasted_total_quantity / roasted_quantity), max(unroasted_total_quantity / roasted_quantity), avg(unroasted_total_quantity / roasted_quantity) FROM roasting_log WHERE roasted_id = :ri AND unroasted_id = :gi AND unroasted_total_quantity > 0 AND roasted_quantity > 0 AND approval = true");
54
-				var mins = new Array();
55
-				var maxes = new Array();
56
-				var means = new Array();
57
-				for(var i = 0; i < roastedItems.length; i++) {
58
-					if(recipes[i] == "{-1}") {
59
-						mins.push("undefined");
60
-						maxes.push("undefined");
61
-						means.push("undefined");
62
-					} else {
63
-						query.bind(":ri", Number(roastedItems[i]));
64
-						query.bind(":gi", recipes[i]);
65
-						query.exec();
66
-						if(query.next()) {
67
-							mins.push(query.value(0));
68
-							maxes.push(query.value(1));
69
-							means.push(query.value(2));
70
-						} else {
71
-							print("Error 2");
72
-						}
73
-					}
74
-				}
75
-				var proportionalCosts = new Array();
76
-				query.prepare("SELECT cost * :proportion FROM purchase WHERE item = :id");
77
-				for(var i = 0; i < roastedItems.length; i++) {
78
-					if(recipes[i] == "{-1}") {
79
-						proportionalCosts.push("undefined");
80
-					} else {
81
-						greens = sqlToArray(recipes[i]);
82
-						weights = sqlToArray(recipeQuantities[i]);
83
-						proportions = new Array();
84
-						quantitySum = weights.reduce(function(p, c) {
85
-							return Number(p) + Number(c);
86
-						});
87
-						for(var j = 0; j < weights.length; j++) {
88
-							proportions.push(weights[j]/quantitySum);
89
-						}
90
-						partialSum = 0;
91
-						for(var j = 0; j < greens.length; j++) {
92
-							query.bind(":proportion", proportions[j]);
93
-							query.bind(":id", greens[j]);
94
-							query.exec();
95
-							if(query.next()) {
96
-								partialSum += Number(query.value(0));
97
-							} else {
98
-								print("Error 3");
99
-							}
100
-						}
101
-						proportionalCosts.push(partialSum);
102
-					}
103
-				}
104
-				query = query.invalidate();
105
-				var minCosts = new Array();
106
-				var maxCosts = new Array();
107
-				var meanCosts = new Array();
108
-				for(var i = 0; i < roastedItems.length; i++) {
109
-					if(recipes[i] == "{-1}") {
110
-						minCosts.push("undefined");
111
-						maxCosts.push("undefined");
112
-						meanCosts.push("undefined");
113
-					} else {
114
-						minCosts.push(proportionalCosts[i] * mins[i]);
115
-						maxCosts.push(proportionalCosts[i] * maxes[i]);
116
-						meanCosts.push(proportionalCosts[i] * means[i]);
117
-					}
118
-				}
119
-				output.writeStartElement("table");
120
-				output.writeAttribute("rules", "groups");
121
-				output.writeAttribute("cellpadding", "3px");
122
-				output.writeStartElement("thead");
123
-				output.writeStartElement("tr");
124
-				output.writeTextElement("th", "Coffee");
125
-				output.writeTextElement("th", "Minimum Cost");
126
-				output.writeTextElement("th", "Maximum Cost");
127
-				output.writeTextElement("th", "Mean Cost");
128
-				output.writeEndElement();
129
-				output.writeEndElement();
130
-				output.writeStartElement("tbody");
131
-				for(var i = 0; i < roastedItems.length; i++) {
132
-					output.writeStartElement("tr");
133
-					output.writeTextElement("td", roastedNames[i]);
134
-					output.writeTextElement("td", Number(minCosts[i]).toFixed(2));
135
-					output.writeTextElement("td", Number(maxCosts[i]).toFixed(2));
136
-					output.writeTextElement("td", Number(meanCosts[i]).toFixed(2));
137
-					output.writeEndElement();
138
-				}
139
-				output.writeEndElement();
140
-				output.writeEndElement();
141
-				output.writeEndElement();
142
-				output.writeEndElement();
143
-				output.writeEndDocument();
144
-				report.setContent(buffer);
145
-				buffer.close();
146
-			};
147
-			refresh();
148
-		]]>
149
-	</program>
47
+                output.writeTextElement("p", "Cost of green coffee per " + unit + " of roasted coffee");
48
+                var query = new QSqlQuery();
49
+                query.exec("SELECT item, (SELECT name FROM items WHERE id = item) AS name FROM current_items ORDER BY name");
50
+                var roastedItems = new Array();
51
+                var roastedNames = new Array();
52
+                while(query.next()) {
53
+                    roastedItems.push(query.value(0));
54
+                    roastedNames.push(query.value(1));
55
+                }
56
+                var recipes = new Array();
57
+                var recipeQuantities = new Array();
58
+                query.prepare("SELECT unroasted_id, unroasted_quantity FROM roasting_log WHERE roasted_id = :item AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = :item2)");
59
+                for(var i = 0; i < roastedItems.length; i++) {
60
+                    query.bind("item", roastedItems[i]);
61
+                    query.bind("item2", roastedItems[i]);
62
+                    query.exec();
63
+                    if(query.next()) {
64
+                        recipes.push(query.value(0));
65
+                        recipeQuantities.push(query.value(1));
66
+                    } else {
67
+                        recipes.push("{-1}");
68
+                        recipeQuantities.push("{-1}");
69
+                    }
70
+                }
71
+                query.prepare("SELECT min(unroasted_total_quantity / roasted_quantity), max(unroasted_total_quantity / roasted_quantity), avg(unroasted_total_quantity / roasted_quantity) FROM roasting_log WHERE roasted_id = :ri AND unroasted_id = :gi AND unroasted_total_quantity > 0 AND roasted_quantity > 0 AND approval = true");
72
+                var mins = new Array();
73
+                var maxes = new Array();
74
+                var means = new Array();
75
+                for(var i = 0; i < roastedItems.length; i++) {
76
+                    if(recipes[i] == "{-1}") {
77
+                        mins.push("undefined");
78
+                        maxes.push("undefined");
79
+                        means.push("undefined");
80
+                    } else {
81
+                        query.bind(":ri", Number(roastedItems[i]));
82
+                        query.bind(":gi", recipes[i]);
83
+                        query.exec();
84
+                        if(query.next()) {
85
+                            mins.push(query.value(0));
86
+                            maxes.push(query.value(1));
87
+                            means.push(query.value(2));
88
+                        } else {
89
+                            print("Error 2");
90
+                        }
91
+                    }
92
+                }
93
+                var proportionalCosts = new Array();
94
+                query.prepare("SELECT cost * :proportion * :conversion FROM purchase WHERE item = :id");
95
+                for(var i = 0; i < roastedItems.length; i++) {
96
+                    if(recipes[i] == "{-1}") {
97
+                        proportionalCosts.push("undefined");
98
+                    } else {
99
+                        greens = sqlToArray(recipes[i]);
100
+                        weights = sqlToArray(recipeQuantities[i]);
101
+                        proportions = new Array();
102
+                        quantitySum = weights.reduce(function(p, c) {
103
+                            return Number(p) + Number(c);
104
+                        });
105
+                        for(var j = 0; j < weights.length; j++) {
106
+                            proportions.push(weights[j]/quantitySum);
107
+                        }
108
+                        partialSum = 0;
109
+                        for(var j = 0; j < greens.length; j++) {
110
+                            query.bind(":proportion", proportions[j]);
111
+                            query.bind(":id", greens[j]);
112
+                            query.bind(":conversion", conversion);
113
+                            query.exec();
114
+                            if(query.next()) {
115
+                                partialSum += Number(query.value(0));
116
+                            } else {
117
+                                print("Error 3");
118
+                            }
119
+                        }
120
+                        proportionalCosts.push(partialSum);
121
+                    }
122
+                }
123
+                query = query.invalidate();
124
+                var minCosts = new Array();
125
+                var maxCosts = new Array();
126
+                var meanCosts = new Array();
127
+                for(var i = 0; i < roastedItems.length; i++) {
128
+                    if(recipes[i] == "{-1}") {
129
+                        minCosts.push("undefined");
130
+                        maxCosts.push("undefined");
131
+                        meanCosts.push("undefined");
132
+                    } else {
133
+                        minCosts.push(proportionalCosts[i] * mins[i]);
134
+                        maxCosts.push(proportionalCosts[i] * maxes[i]);
135
+                        meanCosts.push(proportionalCosts[i] * means[i]);
136
+                    }
137
+                }
138
+                output.writeStartElement("table");
139
+                output.writeAttribute("rules", "groups");
140
+                output.writeAttribute("cellpadding", "3px");
141
+                output.writeStartElement("thead");
142
+                output.writeStartElement("tr");
143
+                output.writeTextElement("th", "Coffee");
144
+                output.writeTextElement("th", "Minimum Cost");
145
+                output.writeTextElement("th", "Maximum Cost");
146
+                output.writeTextElement("th", "Mean Cost");
147
+                output.writeEndElement();
148
+                output.writeEndElement();
149
+                output.writeStartElement("tbody");
150
+                for(var i = 0; i < roastedItems.length; i++) {
151
+                    output.writeStartElement("tr");
152
+                    output.writeTextElement("td", roastedNames[i]);
153
+                    output.writeTextElement("td", Number(minCosts[i]).toFixed(2));
154
+                    output.writeTextElement("td", Number(maxCosts[i]).toFixed(2));
155
+                    output.writeTextElement("td", Number(meanCosts[i]).toFixed(2));
156
+                    output.writeEndElement();
157
+                }
158
+                output.writeEndElement();
159
+                output.writeEndElement();
160
+                output.writeEndElement();
161
+                output.writeEndElement();
162
+                output.writeEndDocument();
163
+                report.setContent(buffer);
164
+                buffer.close();
165
+            };
166
+            refresh();
167
+        ]]>
168
+    </program>
150 169
 </window>
151 170
 

正在加载...
取消
保存