Skip to content

Commit

Permalink
Updates for the Aged Debtors report
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Jan 3, 2022
1 parent 3a7c3c8 commit ad233a1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@
"UNKNOWN": "Unknown",
"UNLOCKED": "Unlocked",
"UNTIL_DATE": "Until the date",
"UNTIL_PERIOD": "Until the period",
"UNTIL_PERIOD": "Through the period",
"UPDATED": "Updated",
"UPDATE_GROUP_DEBTOR": "Update Debtor Group",
"UPDATE_PATIENT_GROUP": "Update Patient Group Subscription",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"VIEW_RECEIPT": "View Receipt",
"VIEW_REQUISITION": "View requisition",
"VIEW_VOUCHER": "View Vouchers",
"WARN_PREV_FY_NOT_CLOSED": "Attention! The previous Fiscal Year is not closed. The results in this report may not be accurate until is it closed! ",
"ZERO_TO_THIRTY_DAYS": "Less Than 30 Days",
"REPORT_ACCOUNTS": {
"TITLE": "Account Report",
Expand Down
5 changes: 3 additions & 2 deletions client/src/i18n/fr/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
"FINANCIAL_SITUATION_EMPLOYEE": "Situation financière de l'employé",
"FINANCIAL_SITUATION_EMPLOYEES": "Situation financière des employés",
"INCLUDE_MEDICAL_CARE_EMPLOYEE": "Inclure les soins médicaux accordé à l'employé",
"LIMIT_TO_TIME_INTERVAL": "Limiter à l'intervalle de temps",
"NORMAL_REPORT": "Rapport simple",
"LIMIT_TO_TIME_INTERVAL": "Limiter à l'intervalle de temps",
"NORMAL_REPORT": "Rapport simple",
"REPORT": "Situation financière de l'employé",
"SEE_SITUATION_ALL_EMPLOYEES": "Voir la situation global de tous les employés",
"SUMMARY_REPORT": "Rapport synthétique",
Expand Down Expand Up @@ -242,6 +242,7 @@
"VIEW_RECEIPT": "Voir le document",
"VIEW_REQUISITION": "Voir la réquisition",
"VIEW_VOUCHER": "Voir les bordereaux",
"WARN_PREV_FY_NOT_CLOSED": "Attention ! L'année fiscale précédente n'est pas clôturée. Les résultats de ce rapport peuvent ne pas être exacts tant qu'il n'est pas clôturé !",
"ZERO_TO_THIRTY_DAYS": "Moins de 30 jours",
"REPORT_ACCOUNTS": {
"TITLE": "Rapport de comptes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ angular.module('bhima.controllers')
.controller('aged_debtorsController', AgedDebtorsConfigController);

AgedDebtorsConfigController.$inject = [
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state',
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state', 'SessionService',
];

function AgedDebtorsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state) {
function AgedDebtorsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, Session) {
const vm = this;
const cache = new AppCache('configure_aged_debtors');
const reportUrl = 'reports/finance/debtors/aged';
Expand Down Expand Up @@ -65,5 +65,10 @@ function AgedDebtorsConfigController($sce, Notify, SavedReports, AppCache, repor
if (cache.reportDetails) {
vm.reportDetails = angular.copy(cache.reportDetails);
}

// Set the defaults
if (!angular.isDefined(vm.reportDetails.currencyId)) {
vm.reportDetails.currency_id = Session.enterprise.currency_id;
}
}
}
11 changes: 9 additions & 2 deletions server/controllers/finance/reports/debtors/aged.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
<strong>{{translate "REPORT.AGED_DEBTORS.TITLE"}}</strong>
</h3>

<h5 class="text-center">
<h4 class="text-center">
<strong>
<span class="text-capitalize">{{translate "FORM.LABELS.UNTIL_PERIOD"}}</span> <span class="text-capitalize"> {{date dateUntil "MMMM YYYY"}} </span>
</strong>
</h5>
</h4>

{{#unless previousFyClosed}}
<div class="alert alert-warning">
<p>{{translate "REPORT.WARN_PREV_FY_NOT_CLOSED"}}</p>
</div>
{{/unless}}

<!-- margin is the cell size -->
<section>
<table class="table table-condensed table-report table-bordered">
Expand Down
15 changes: 12 additions & 3 deletions server/controllers/finance/reports/debtors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const db = require('../../../../lib/db');
const TEMPLATE = './server/controllers/finance/reports/debtors/aged.handlebars';

const DEFAULT_OPTIONS = {
csvKey : 'debtors',
orientation : 'landscape',
csvKey: 'debtors',
orientation: 'landscape',
};

/**
Expand All @@ -40,6 +40,7 @@ function agedDebtorReport(req, res, next) {
const metadata = _.clone(req.session);

let report;
let previousFyLocked;

try {
report = new ReportManager(TEMPLATE, metadata, qs);
Expand Down Expand Up @@ -70,7 +71,7 @@ function agedDebtorReport(req, res, next) {
/**
* @method queryContext
*
* @param {Object} params Parameters passed in to customise the report - these
* @param {Object} params Parameters passed in to customize the report - these
* are usually passed in through the query string
* @description
* The HTTP interface which actually creates the report.
Expand All @@ -86,6 +87,13 @@ async function queryContext(params = {}) {
const currencyId = db.escape(params.currency_id);
const enterpriseId = db.escape(params.enterprise_id);

const fySql = `
SELECT locked FROM fiscal_year
WHERE ID = (SELECT previous_FISCAL_year_id from fiscal_year where id = ?)
`;

const previousFy = await db.one(fySql, [params.fiscal_id]);

const groupByMonthColumns = `
SUM(IF(MONTH(?) - MONTH(gl.trans_date) = 0, (gl.debit_equiv - gl.credit_equiv)*
IFNULL(GetExchangeRate(${enterpriseId}, ${currencyId}, gl.trans_date), 1), 0)) AS thirty,
Expand Down Expand Up @@ -152,6 +160,7 @@ async function queryContext(params = {}) {

data.debtors = debtors;
data.dateUntil = params.date;
data.previousFyClosed = previousFy.locked;

// this is specific to grouping by months
data.firstMonth = params.date;
Expand Down

0 comments on commit ad233a1

Please sign in to comment.