Skip to content

Commit

Permalink
BAH-3049 | Fix. report.startDate undefined error | [Riya/Sweety/Deepti]
Browse files Browse the repository at this point in the history
  • Loading branch information
riyaTw committed Dec 6, 2023
1 parent dae233a commit 0323898
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions ui/app/reports/controllers/reportsController.js
Original file line number Diff line number Diff line change
@@ -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());

Expand Down Expand Up @@ -35,21 +35,18 @@ angular.module('bahmni.reports')
$scope.setDefault = function (item, header) {
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 (_.isUndefined($rootScope.default[header][item])) {
$rootScope.default.reportsRequiringDateRange.startDate = dateRange[0];
angular.forEach($rootScope.reportsRequiringDateRange, function (report) {
report.startDate = dateRange[0];
report.stopDate = isPreviousMonth ? getPreviousMonthEndDate() : dateRange[0];
report.responseType = format[1];
});
} else {
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];
}
});
Expand Down

0 comments on commit 0323898

Please sign in to comment.