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
                 output.writeStartElement("thead");
65
                 output.writeStartElement("thead");
66
                 output.writeStartElement("tr");
66
                 output.writeStartElement("tr");
67
                 output.writeStartElement("th");
67
                 output.writeStartElement("th");
68
-                output.writeAttribute("colspan", "3");
68
+                output.writeAttribute("colspan", "5");
69
                 output.writeCharacters("Regular Coffees");
69
                 output.writeCharacters("Regular Coffees");
70
                 output.writeEndElement();
70
                 output.writeEndElement();
71
                 output.writeEndElement();
71
                 output.writeEndElement();
73
                 output.writeTextElement("th", "Origin");
73
                 output.writeTextElement("th", "Origin");
74
                 output.writeTextElement("th", "Avg. Rate");
74
                 output.writeTextElement("th", "Avg. Rate");
75
                 output.writeTextElement("th", "Avg. Cost");
75
                 output.writeTextElement("th", "Avg. Cost");
76
+				output.writeTextElement("th", "Last Cost");
77
+				output.writeTextElement("th", "Last Purchase Date");
76
                 output.writeEndElement();
78
                 output.writeEndElement();
77
                 output.writeEndElement();
79
                 output.writeEndElement();
78
                 output.writeStartElement("tbody");
80
                 output.writeStartElement("tbody");
81
 				if(unitBox.currentIndex == 0) {
83
 				if(unitBox.currentIndex == 0) {
82
 					conversion = 2.2;
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
 				query.bind(":conversion", conversion);
109
 				query.bind(":conversion", conversion);
106
 				query.bind(":conversion2", conversion);
110
 				query.bind(":conversion2", conversion);
111
+				query.bind(":conversion3", conversion);
107
 				query.exec();
112
 				query.exec();
108
                 while(query.next())
113
                 while(query.next())
109
                 {
114
                 {
111
                     output.writeTextElement("td", query.value(0));
116
                     output.writeTextElement("td", query.value(0));
112
                     output.writeTextElement("td", query.value(1));
117
                     output.writeTextElement("td", query.value(1));
113
                     output.writeTextElement("td", query.value(2));
118
                     output.writeTextElement("td", query.value(2));
119
+					output.writeTextElement("td", query.value(3));
120
+					output.writeTextElement("td", query.value(4));
114
                     output.writeEndElement();
121
                     output.writeEndElement();
115
                 }
122
                 }
116
                 output.writeStartElement("tr");
123
                 output.writeStartElement("tr");
117
                 output.writeStartElement("th");
124
                 output.writeStartElement("th");
118
-                output.writeAttribute("colspan", "3");
125
+                output.writeAttribute("colspan", "5");
119
                 output.writeCharacters("Decaffeinated Coffees");
126
                 output.writeCharacters("Decaffeinated Coffees");
120
                 output.writeEndElement();
127
                 output.writeEndElement();
121
                 output.writeEndElement();
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
 				query.bind(":conversion", conversion);
130
 				query.bind(":conversion", conversion);
144
 				query.bind(":conversion2", conversion);
131
 				query.bind(":conversion2", conversion);
132
+				query.bind(":conversion3", conversion);
145
 				query.exec();
133
 				query.exec();
146
                 while(query.next())
134
                 while(query.next())
147
                 {
135
                 {
149
                     output.writeTextElement("td", query.value(0));
137
                     output.writeTextElement("td", query.value(0));
150
                     output.writeTextElement("td", query.value(1));
138
                     output.writeTextElement("td", query.value(1));
151
                     output.writeTextElement("td", query.value(2));
139
                     output.writeTextElement("td", query.value(2));
140
+					output.writeTextElement("td", query.value(3));
141
+					output.writeTextElement("td", query.value(4));
152
                     output.writeEndElement();
142
                     output.writeEndElement();
153
                 }
143
                 }
154
 				query = query.invalidate();
144
 				query = query.invalidate();

Loading…
Cancel
Save