Neal Wilson 10 years ago
parent
commit
2bd67a9480
1 changed files with 48 additions and 31 deletions
  1. 48
    31
      config/Reports/cogr.xml

+ 48
- 31
config/Reports/cogr.xml View File

@@ -46,7 +46,8 @@
46 46
 						recipes.push(query.value(0));
47 47
 						recipeQuantities.push(query.value(1));
48 48
 					} else {
49
-						print("Error 1");
49
+						recipes.push("{-1}");
50
+						recipeQuantities.push("{-1}");
50 51
 					}
51 52
 				}
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,49 +55,65 @@
54 55
 				var maxes = new Array();
55 56
 				var means = new Array();
56 57
 				for(var i = 0; i < roastedItems.length; i++) {
57
-					query.bind(":ri", Number(roastedItems[i]));
58
-					query.bind(":gi", recipes[i]);
59
-					query.exec();
60
-					if(query.next()) {
61
-						mins.push(query.value(0));
62
-						maxes.push(query.value(1));
63
-						means.push(query.value(2));
58
+					if(recipes[i] == "{-1}") {
59
+						mins.push("undefined");
60
+						maxes.push("undefined");
61
+						means.push("undefined");
64 62
 					} else {
65
-						print("Error 2");
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
+						}
66 73
 					}
67 74
 				}
68 75
 				var proportionalCosts = new Array();
69 76
 				query.prepare("SELECT cost * :proportion FROM purchase WHERE item = :id");
70 77
 				for(var i = 0; i < roastedItems.length; i++) {
71
-					greens = sqlToArray(recipes[i]);
72
-					weights = sqlToArray(recipeQuantities[i]);
73
-					proportions = new Array();
74
-					quantitySum = weights.reduce(function(p, c) {
75
-						return p + c;
76
-					});
77
-					for(var j = 0; j < weights.length; j++) {
78
-						proportions.push(weights[j]/quantitySum);
79
-					}
80
-					partialSum = 0;
81
-					for(var j = 0; j < greens.length; j++) {
82
-						query.bind(":proportion", proportions[j]);
83
-						query.bind(":id", greens[j]);
84
-						query.exec();
85
-						if(query.next()) {
86
-							partialSum += query.value(0);
87
-						} else {
88
-							print("Error 3");
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 p + c;
86
+						});
87
+						for(var j = 0; j < weights.length; j++) {
88
+							proportions.push(weights[j]/quantitySum);
89 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 += query.value(0);
97
+							} else {
98
+								print("Error 3");
99
+							}
100
+						}
101
+						proportionalCosts.push(partialSum);
90 102
 					}
91
-					proportionalCosts.push(partialSum);
92 103
 				}
93 104
 				var minCosts = new Array();
94 105
 				var maxCosts = new Array();
95 106
 				var meanCosts = new Array();
96 107
 				for(var i = 0; i < roastedItems.length; i++) {
97
-					minCosts.push(proportionalCosts[i] * mins[i]);
98
-					maxCosts.push(proportionalCosts[i] * maxes[i]);
99
-					meanCosts.push(proportionalCosts[i] * means[i]);
108
+					if(recipes[i] == "{-1}") {
109
+						minCosts.push("undefined");
110
+						maxCosts.push("undefined");
111
+						meanCosts.push("undefined");
112
+					} else {
113
+						minCosts.push(proportionalCosts[i] * mins[i]);
114
+						maxCosts.push(proportionalCosts[i] * maxes[i]);
115
+						meanCosts.push(proportionalCosts[i] * means[i]);
116
+					}
100 117
 				}
101 118
 				output.writeStartElement("table");
102 119
 				output.writeAttribute("rules", "groups");

Loading…
Cancel
Save