|
@@ -2,10 +2,7 @@
|
2
|
2
|
<reporttitle>Purchase:->Coffee Purchase Previous Years Comparison</reporttitle>
|
3
|
3
|
<layout type="vertical">
|
4
|
4
|
<layout type="horizontal">
|
5
|
|
- <label>Start Date:</label>
|
6
|
|
- <calendar id="startdate" />
|
7
|
|
- <label>End Date:</label>
|
8
|
|
- <calendar id="enddate" />
|
|
5
|
+ <daterange id = "dates" initial="23" /><!--Lifetime-->
|
9
|
6
|
<label>Weight Unit:</label>
|
10
|
7
|
<sqldrop id="unit" />
|
11
|
8
|
<stretch />
|
|
@@ -18,16 +15,16 @@
|
18
|
15
|
<program>
|
19
|
16
|
<![CDATA[
|
20
|
17
|
this.windowTitle = "Typica - Coffee Purchase Previous Years Comparison";
|
21
|
|
- /* Set starting year to the first year on record. */
|
22
|
|
- var startDateField = findChildObject(this, 'startdate');
|
|
18
|
+ /* Set Lifetime range. */
|
|
19
|
+ var dateSelect = findChildObject(this, 'dates');
|
23
|
20
|
var query = new QSqlQuery();
|
24
|
|
- query.exec("SELECT EXTRACT(YEAR FROM time) FROM purchase WHERE time = (SELECT min(time) FROM purchase)");
|
|
21
|
+ query.exec("SELECT concat(EXTRACT(YEAR FROM time::date), '-01-01') FROM purchase WHERE time = (SELECT min(time) FROM purchase) UNION SELECT concat(EXTRACT(YEAR FROM 'now'::date), '-12-31')");
|
25
|
22
|
query.next();
|
26
|
|
- startDateField.setDate(query.value(0), 1, 1);
|
|
23
|
+ var lifetimeStartDate = query.value(0);
|
|
24
|
+ query.next();
|
|
25
|
+ var lifetimeEndDate = query.value(0);
|
|
26
|
+ dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
|
27
|
27
|
query = query.invalidate();
|
28
|
|
- /* Set ending year to the current year. */
|
29
|
|
- var endDateField = findChildObject(this, 'enddate');
|
30
|
|
- endDateField.setDate(endDateField.year(), 12, 31);
|
31
|
28
|
/* Enable printing */
|
32
|
29
|
var view = findChildObject(this, 'report');
|
33
|
30
|
var printMenu = findChildObject(this, 'print');
|
|
@@ -81,7 +78,10 @@
|
81
|
78
|
var unittotal = 0;
|
82
|
79
|
var costtotal = 0;
|
83
|
80
|
var query = new QSqlQuery();
|
84
|
|
- for(var i = startDateField.year(); i <= endDateField.year(); i++)
|
|
81
|
+ var dateRange = dateSelect.currentRange();
|
|
82
|
+ var startYear = Number(dateRange[0].substr(0, 4));
|
|
83
|
+ var endYear = Number(dateRange[dateRange.length - 1].substr(0, 4));
|
|
84
|
+ for(var i = startYear; i <= endYear; i++)
|
85
|
85
|
{
|
86
|
86
|
output.writeStartElement("tr");
|
87
|
87
|
output.writeAttribute("id", "y"+i);
|
|
@@ -121,10 +121,7 @@
|
121
|
121
|
}
|
122
|
122
|
refresh();
|
123
|
123
|
/* Update report as needed. */
|
124
|
|
- startDateField.dateChanged.connect(function() {
|
125
|
|
- refresh();
|
126
|
|
- });
|
127
|
|
- endDateField.dateChanged.connect(function() {
|
|
124
|
+ dateSelect.rangeUpdated.connect(function() {
|
128
|
125
|
refresh();
|
129
|
126
|
});
|
130
|
127
|
/* Expand year data */
|