Skip to content

Commit

Permalink
Merge pull request Bahmni#795 from Bahmni/BAH-3049_Reports-2
Browse files Browse the repository at this point in the history
BAH-3049 | Fix. Add max attritute in start date field
  • Loading branch information
deeptirawat1510 committed Dec 6, 2023
2 parents adf3759 + a3daacd commit 4b4f598
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
35 changes: 16 additions & 19 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 All @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/reports/views/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 class="section-title">{{::'REPORTS_TITLE_KEY' | translate}}</h2>
<tr ng-repeat="report in ::reportsRequiringDateRange" show-if-privilege="{{:: report.requiredPrivilege}}">
<td>{{:: report.name |translate }}</td>
<td class="reports-start-date">
<input date-converter class="form-field start-date" type="date" ng-model="report.startDate">
<input date-converter class="form-field start-date" type="date" max="{{report.stopDate | date:'yyyy-MM-dd'}}" ng-model="report.startDate">
</td>
<td class="reports-stop-date">
<input date-converter class="form-field stop-date" type="date" min="{{report.startDate | date:'yyyy-MM-dd'}}" ng-model="report.stopDate">
Expand Down

0 comments on commit 4b4f598

Please sign in to comment.