Browse Source

Add date range selector to Coffee Purchase Previous Years Comparison report

Neal Wilson 11 years ago
parent
commit
f795c710b0
1 changed files with 13 additions and 16 deletions
  1. 13
    16
      config/Reports/fypurchase.xml

+ 13
- 16
config/Reports/fypurchase.xml View File

2
 	<reporttitle>Purchase:->Coffee Purchase Previous Years Comparison</reporttitle>
2
 	<reporttitle>Purchase:->Coffee Purchase Previous Years Comparison</reporttitle>
3
 	<layout type="vertical">
3
 	<layout type="vertical">
4
 		<layout type="horizontal">
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
 			<label>Weight Unit:</label>
6
 			<label>Weight Unit:</label>
10
 			<sqldrop id="unit" />
7
 			<sqldrop id="unit" />
11
 			<stretch />
8
 			<stretch />
18
 	<program>
15
 	<program>
19
 		<![CDATA[
16
 		<![CDATA[
20
 			this.windowTitle = "Typica - Coffee Purchase Previous Years Comparison";
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
 			var query = new QSqlQuery();
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
 			query.next();
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
 			query = query.invalidate();
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
 			/* Enable printing */
28
 			/* Enable printing */
32
 			var view = findChildObject(this, 'report');
29
 			var view = findChildObject(this, 'report');
33
 			var printMenu = findChildObject(this, 'print');
30
 			var printMenu = findChildObject(this, 'print');
81
 				var unittotal = 0;
78
 				var unittotal = 0;
82
 				var costtotal = 0;
79
 				var costtotal = 0;
83
 				var query = new QSqlQuery();
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
 					output.writeStartElement("tr");
86
 					output.writeStartElement("tr");
87
 					output.writeAttribute("id", "y"+i);
87
 					output.writeAttribute("id", "y"+i);
121
 			}
121
 			}
122
 			refresh();
122
 			refresh();
123
 			/* Update report as needed. */
123
 			/* Update report as needed. */
124
-			startDateField.dateChanged.connect(function() {
125
-				refresh();
126
-			});
127
-			endDateField.dateChanged.connect(function() {
124
+			dateSelect.rangeUpdated.connect(function() {
128
 				refresh();
125
 				refresh();
129
 			});
126
 			});
130
 			/* Expand year data */
127
 			/* Expand year data */

Loading…
Cancel
Save