diff --git a/ui/app/reports/controllers/reportsController.js b/ui/app/reports/controllers/reportsController.js index d9d0af9582..9b5ca7b740 100644 --- a/ui/app/reports/controllers/reportsController.js +++ b/ui/app/reports/controllers/reportsController.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('bahmni.reports') - .controller('ReportsController', ['$scope', 'appService', 'reportService', 'FileUploader', 'messagingService', 'spinner', '$rootScope', '$translate', 'auditLogService', function ($scope, appService, reportService, FileUploader, messagingService, spinner, $rootScope, $translate, auditLogService) { + .controller('ReportsController', ['$scope', '$filter', 'appService', 'reportService', 'FileUploader', 'messagingService', 'spinner', '$rootScope', '$translate', 'auditLogService', function ($scope, $filter, appService, reportService, FileUploader, messagingService, spinner, $rootScope, $translate, auditLogService) { const format = _.values(reportService.getAvailableFormats()); const dateRange = _.values(reportService.getAvailableDateRange()); @@ -18,36 +18,33 @@ angular.module('bahmni.reports') fileItem.report.reportTemplateLocation = response; }; - $rootScope.default = _.isUndefined($rootScope.default) ? { + $rootScope.default = $rootScope.default || { reportsRequiringDateRange: { responseType: format[1], dateRangeType: dateRange[0], startDate: dateRange[0], stopDate: dateRange[0], - report: { - responseType: format[1] - } + report: { responseType: format[1] } }, reportsNotRequiringDateRange: {} - } : $rootScope.default; + }; + $scope.reportsDefined = true; $scope.enableReportQueue = appService.getAppDescriptor().getConfigValue("enableReportQueue"); + $scope.setDefault = function (item, header) { - var setToChange = header === 'reportsRequiringDateRange' ? $rootScope.reportsRequiringDateRange : $rootScope.reportsNotRequiringDateRange; - var isPreviousMonth = $rootScope.default[header][item] && $rootScope.default[header][item] === dateRange[2]; - setToChange.forEach(function (report) { - if (item == 'dateRangeType') { + var setToChange = (header === 'reportsRequiringDateRange') ? $rootScope.reportsRequiringDateRange : $rootScope.reportsNotRequiringDateRange; + var isPreviousMonth = $rootScope.default[header][item] === dateRange[2]; + angular.forEach(setToChange, function (report) { + if (item === 'dateRangeType') { $rootScope.default.reportsRequiringDateRange.startDate = $rootScope.default[header][item]; $rootScope.default.reportsRequiringDateRange.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0]; - report['startDate'] = $rootScope.default[header][item]; - report['stopDate'] = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0]; - } else if ($rootScope.default[header][item] === undefined) { - $rootScope.default.reportsRequiringDateRange.startDate = dateRange[0]; - $rootScope.reportsRequiringDateRange.forEach(function (report) { - report.startDate = dateRange[0]; - report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0]; - report.responseType = format[1]; - }); + report.startDate = $rootScope.default[header][item]; + report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0]; + } else if (_.isUndefined($rootScope.default[header][item])) { + report.startDate = $filter('date')(dateRange[0], 'yyyy-MM-dd'); + report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0]; + report.responseType = format[1]; } else { report[item] = $rootScope.default[header][item]; } diff --git a/ui/app/reports/views/reports.html b/ui/app/reports/views/reports.html index 767460b8c2..f341195e00 100644 --- a/ui/app/reports/views/reports.html +++ b/ui/app/reports/views/reports.html @@ -45,7 +45,7 @@

{{::'REPORTS_TITLE_KEY' | translate}}

{{:: report.name |translate }} - +