Kaynağa Gözat

Green Coffee Sales Report. Fixes #61

Neal Wilson 10 yıl önce
ebeveyn
işleme
823992b16d
1 değiştirilmiş dosya ile 112 ekleme ve 0 silme
  1. 112
    0
      config/Reports/greensales.xml

+ 112
- 0
config/Reports/greensales.xml Dosyayı Görüntüle

@@ -0,0 +1,112 @@
1
+<window id="greensales">
2
+	<reporttitle>Sales:->Green Coffee Sales</reporttitle>
3
+	<layout type="vertical">
4
+		<layout type="horizontal">
5
+			<daterange id="dates" initial="9" /><!-- Current Month to Date-->
6
+			<label>Weight Unit:</label>
7
+			<sqldrop id="unit" />
8
+			<stretch />
9
+		</layout>
10
+		<webview id="report" />
11
+	</layout>
12
+	<menu name="File">
13
+		<item id="print" shortcut="Ctrl+P">Print</item>
14
+	</menu>
15
+	<program>
16
+		<![CDATA[
17
+			this.windowTitle = "Typica - Green Coffee Sales";
18
+			var dateSelect = findChildObject(this, 'dates');
19
+			var dateQuery = new QSqlQuery();
20
+			dateQuery.exec("SELECT time::date FROM sale WHERE time = (SELECT min(time) FROM sale) OR time = (SELECT max(time) FROM sale) ORDER BY time ASC");
21
+			dateQuery.next();
22
+			var lifetimeStartDate = dateQuery.value(0);
23
+			var lifetimeEndDate;
24
+			if(dateQuery.next()) {
25
+				lifetimeEndDate = dateQuery.value(0);
26
+			} else {
27
+				lifetimeEndDate = lifetimeStartDate;
28
+			}
29
+			dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
30
+			dateQuery = dateQuery.invalidate();
31
+			var unitBox = findChildObject(this, 'unit');
32
+			unitBox.addItem("Kg");
33
+			unitBox.addItem("Lb");
34
+			unitBox.currentIndex = QSettings.value("script/report_unit", 1);
35
+			unitBox['currentIndexChanged(int)'].connect(function() {
36
+				QSettings.setValue("script/report_unit", unitBox.currentIndex);
37
+				refresh();
38
+			});
39
+			var view = findChildObject(this, 'report');
40
+			var printMenu = findChildObject(this, 'print');
41
+			printMenu.triggered.connect(function() {
42
+				view.print();
43
+			});
44
+			var reportitems = new Array();
45
+			function refresh() {
46
+				var buffer = new QBuffer;
47
+				buffer.open(3);
48
+				var output = new XmlWriter(buffer);
49
+				var output = new XmlWriter(buffer);
50
+				output.writeStartDocument("1.0");
51
+				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">');
52
+				output.writeStartElement("html");
53
+				output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
54
+				output.writeStartElement("head");
55
+				output.writeTextElement("title", "Green Coffee Sales");
56
+				output.writeEndElement();
57
+				output.writeStartElement("body");
58
+				var dateRange = dateSelect.currentRange();
59
+				var startDate = dateRange[0];
60
+				var endDate = dateRange[dateRange.length - 1];
61
+				output.writeTextElement("h1", "Green Coffee Sales: " + startDate + " - " + endDate);
62
+				var conversion = 1;
63
+				var unitText = 'Lb';
64
+				if(unitBox.currentIndex == 0) {
65
+					conversion = 2.2;
66
+					unitText = 'Kg';
67
+				}
68
+				var query = new QSqlQuery();
69
+				query.prepare("SELECT item, (SELECT name FROM coffees WHERE id = item) AS name, (SELECT origin FROM coffees WHERE id = item) AS origin, (SELECT reference FROM coffees WHERE id = item) AS reference, (SUM(quantity)/:conversion)::numeric(12,3) FROM sale WHERE time < :ed ::date + interval '1 day' AND time >= :sd GROUP BY item ORDER BY name ASC");
70
+				query.bind(":conversion", conversion);
71
+				query.bind(":ed", endDate);
72
+				query.bind(":sd", startDate);
73
+				query.exec();
74
+				output.writeStartElement("table");
75
+				output.writeAttribute("rules", "groups");
76
+				output.writeAttribute("cellpadding", "3px");
77
+				output.writeStartElement("thead");
78
+				output.writeStartElement("tr");
79
+				output.writeTextElement("th", "ID"); // 0
80
+				output.writeTextElement("th", "Coffee"); // 1
81
+				output.writeTextElement("th", "Origin"); // 2
82
+				output.writeTextElement("th", "Reference"); // 3
83
+				output.writeTextElement("th", "Quantity"); // 4
84
+				output.writeEndElement();
85
+				output.writeEndElement();
86
+				output.writeStartElement("tbody");
87
+				while(query.next()) {
88
+					output.writeStartElement("tr");
89
+					output.writeAttribute("id", "r"+query.value(0));
90
+					reportitems.push(query.value(0));
91
+					output.writeTextElement("td", query.value(0));
92
+					output.writeTextElement("td", query.value(1));
93
+					output.writeTextElement("td", query.value(2));
94
+					output.writeTextElement("td", query.value(3));
95
+					output.writeTextElement("td", query.value(4));
96
+					output.writeEndElement();
97
+				}
98
+				output.writeEndElement();
99
+				output.writeEndElement();
100
+				output.writeEndElement();
101
+				output.writeEndElement();
102
+				output.writeEndDocument();
103
+				view.setContent(buffer);
104
+				buffer.close();
105
+				query = query.invalidate();
106
+			}
107
+			refresh();
108
+			dateSelect.rangeUpdated.connect(refresh);
109
+		]]>
110
+	</program>
111
+</window>
112
+

Loading…
İptal
Kaydet