Browse Source

Use new date range selector in Previous Year Production Comparison report.

Neal Wilson 11 years ago
parent
commit
a5e7e8b960
1 changed files with 11 additions and 17 deletions
  1. 11
    17
      config/Reports/chart.xml

+ 11
- 17
config/Reports/chart.xml View File

2
 	<reporttitle>Production:->Previous Year Production Comparison</reporttitle>
2
 	<reporttitle>Production:->Previous Year Production 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="19" /><!-- Current Year to Date -->
9
             <label>Days to Average</label>
6
             <label>Days to Average</label>
10
             <line validator="integer" id="days">7</line>
7
             <line validator="integer" id="days">7</line>
11
 			<label>Weight Unit:</label>
8
 			<label>Weight Unit:</label>
20
     <program>
17
     <program>
21
         <![CDATA[
18
         <![CDATA[
22
             this.windowTitle = "Typica - Previous Year Production Comparison";
19
             this.windowTitle = "Typica - Previous Year Production Comparison";
23
-            var startDateField = findChildObject(this, 'startdate');
24
-            startDateField.setDate(startDateField.year(), 1, 1);
25
-            var endDateField = findChildObject(this, 'enddate');
20
+			var dateSelect = findChildObject(this, 'dates');
26
             var view = findChildObject(this, 'report');
21
             var view = findChildObject(this, 'report');
27
             var printMenu = findChildObject(this, 'print');
22
             var printMenu = findChildObject(this, 'print');
28
             printMenu.triggered.connect(function() {
23
             printMenu.triggered.connect(function() {
79
                 output.writeStartElement("tbody");
74
                 output.writeStartElement("tbody");
80
                 var query = new QSqlQuery();
75
                 var query = new QSqlQuery();
81
                 query.exec("START TRANSACTION");
76
                 query.exec("START TRANSACTION");
82
-                var curStartDate = "'"+startDateField.year()+"-"+startDateField.month()+"-"+startDateField.day()+"'";
83
-                query.exec("SELECT "+curStartDate+"::date - interval '1 year', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date - interval '1 year' + interval '1 day', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date + interval '1 day'");
84
-                query.next();
85
-                var curEndDate = "'"+query.value(2)+"'";
77
+				var dateRange = dateSelect.currentRange();
78
+				var curStartDate = "'"+dateRange[0]+"'";
79
+				var curEndDate = "'"+dateRange[dateRange.length - 1]+"'";
80
+                query.exec("SELECT "+curStartDate+"::date - interval '1 year', "+curEndDate+"::date - interval '1 year' + interval '1 day', "+curEndDate+"::date + interval '1 day'");
81
+				query.next();
82
+                curEndDate = "'"+query.value(2)+"'";
86
                 var prevStartDate = "'"+query.value(0)+"'";
83
                 var prevStartDate = "'"+query.value(0)+"'";
87
                 var prevEndDate = "'"+query.value(1)+"'";
84
                 var prevEndDate = "'"+query.value(1)+"'";
88
                 var q = "CREATE TEMPORARY TABLE previous ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS p FROM roasting_log WHERE time > "+prevStartDate+" AND time < "+prevEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
85
                 var q = "CREATE TEMPORARY TABLE previous ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS p FROM roasting_log WHERE time > "+prevStartDate+" AND time < "+prevEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
501
                 buffer.close();
498
                 buffer.close();
502
             }
499
             }
503
             refresh();
500
             refresh();
504
-            startDateField.dateChanged.connect(function() {
505
-                refresh();
506
-            });
507
-            endDateField.dateChanged.connect(function() {
508
-                refresh();
509
-            });
501
+			dateSelect.rangeUpdated.connect(function() {
502
+				refresh();
503
+			});
510
 			avgField.editingFinished.connect(function() {
504
 			avgField.editingFinished.connect(function() {
511
 				refresh();
505
 				refresh();
512
 			});
506
 			});

Loading…
Cancel
Save