Browse Source

Add last purchase data to AUCO report

Neal Wilson 11 years ago
parent
commit
d7df6a96e6
1 changed files with 34 additions and 44 deletions
  1. 34
    44
      config/Reports/auco.xml

+ 34
- 44
config/Reports/auco.xml View File

@@ -65,7 +65,7 @@
65 65
                 output.writeStartElement("thead");
66 66
                 output.writeStartElement("tr");
67 67
                 output.writeStartElement("th");
68
-                output.writeAttribute("colspan", "3");
68
+                output.writeAttribute("colspan", "5");
69 69
                 output.writeCharacters("Regular Coffees");
70 70
                 output.writeEndElement();
71 71
                 output.writeEndElement();
@@ -73,6 +73,8 @@
73 73
                 output.writeTextElement("th", "Origin");
74 74
                 output.writeTextElement("th", "Avg. Rate");
75 75
                 output.writeTextElement("th", "Avg. Cost");
76
+				output.writeTextElement("th", "Last Cost");
77
+				output.writeTextElement("th", "Last Purchase Date");
76 78
                 output.writeEndElement();
77 79
                 output.writeEndElement();
78 80
                 output.writeStartElement("tbody");
@@ -81,29 +83,32 @@
81 83
 				if(unitBox.currentIndex == 0) {
82 84
 					conversion = 2.2;
83 85
 				}
84
-                switch(sortBox.currentIndex)
85
-                {
86
-                    case 0:
87
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin ASC");
88
-                        break;
89
-                    case 1:
90
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin DESC");
91
-                        break;
92
-                    case 2:
93
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate ASC");
94
-                        break;
95
-                    case 3:
96
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate DESC");
97
-                        break;
98
-                    case 4:
99
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost ASC");
100
-                        break;
101
-                    case 5:
102
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost DESC");
103
-                        break;
104
-                }
86
+				var orderClause;
87
+				switch(sortBox.currentIndex)
88
+				{
89
+					case 0:
90
+						orderClause = "origin ASC";
91
+						break;
92
+					case 1:
93
+						orderClause = "origin DESC";
94
+						break;
95
+					case 2:
96
+						orderClause = "rate ASC";
97
+						break;
98
+					case 3:
99
+						orderClause = "rate DESC";
100
+						break;
101
+					case 4:
102
+						orderClause = "cost ASC";
103
+						break;
104
+					case 5:
105
+						orderClause = "cost DESC";
106
+						break;
107
+				}
108
+				query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost, (SELECT avg(cost)*:conversion3 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin) AND time = (SELECT max(time) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))), (SELECT max(time)::date FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin)) FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY " + orderClause);
105 109
 				query.bind(":conversion", conversion);
106 110
 				query.bind(":conversion2", conversion);
111
+				query.bind(":conversion3", conversion);
107 112
 				query.exec();
108 113
                 while(query.next())
109 114
                 {
@@ -111,37 +116,20 @@
111 116
                     output.writeTextElement("td", query.value(0));
112 117
                     output.writeTextElement("td", query.value(1));
113 118
                     output.writeTextElement("td", query.value(2));
119
+					output.writeTextElement("td", query.value(3));
120
+					output.writeTextElement("td", query.value(4));
114 121
                     output.writeEndElement();
115 122
                 }
116 123
                 output.writeStartElement("tr");
117 124
                 output.writeStartElement("th");
118
-                output.writeAttribute("colspan", "3");
125
+                output.writeAttribute("colspan", "5");
119 126
                 output.writeCharacters("Decaffeinated Coffees");
120 127
                 output.writeEndElement();
121 128
                 output.writeEndElement();
122
-                switch(sortBox.currentIndex)
123
-                {
124
-                    case 0:
125
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin ASC");
126
-                        break;
127
-                    case 1:
128
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin DESC");
129
-                        break;
130
-                    case 2:
131
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate ASC");
132
-                        break;
133
-                    case 3:
134
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate DESC");
135
-                        break;
136
-                    case 4:
137
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost ASC");
138
-                        break;
139
-                    case 5:
140
-						query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost DESC");
141
-                        break;
142
-                }
129
+				query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost, (SELECT avg(cost)*:conversion3 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin) AND time = (SELECT max(time) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))), (SELECT max(time)::date FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin)) FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY " + orderClause);
143 130
 				query.bind(":conversion", conversion);
144 131
 				query.bind(":conversion2", conversion);
132
+				query.bind(":conversion3", conversion);
145 133
 				query.exec();
146 134
                 while(query.next())
147 135
                 {
@@ -149,6 +137,8 @@
149 137
                     output.writeTextElement("td", query.value(0));
150 138
                     output.writeTextElement("td", query.value(1));
151 139
                     output.writeTextElement("td", query.value(2));
140
+					output.writeTextElement("td", query.value(3));
141
+					output.writeTextElement("td", query.value(4));
152 142
                     output.writeEndElement();
153 143
                 }
154 144
 				query = query.invalidate();

Loading…
Cancel
Save