Skip to content

Commit

Permalink
Merge #6196
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] and mbayopanda authored Jan 5, 2022
2 parents c6b605c + dda07f0 commit f3820ed
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 21 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
"AMOUNT_PAID" : "Montant Payé",
"ARTICLES":"Articles",
"CASHBOXES": "Caisses",
"DEBTOR_GROUP_OPTIONAL": "Groupe débiteur (optionel)",
"SELECT_ALL_LOTS": "Sélectionner tous les lots",
"MERGE_LOCATIONS": "Fusionner les localisations",
"MERGE_LOCATIONS_TO_ONE":"Fusionner les localisations en une seule localisation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ angular.module('bhima.controllers')

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

function UnbalancedInvoicePaymentsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state) {
function UnbalancedInvoicePaymentsConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, Session) {
const vm = this;
const cache = new AppCache('configure_unpaid_invoice_payments');
const reportUrl = 'reports/finance/unpaid_invoice_payments';

vm.previewGenerated = false;
vm.reportDetails = {};
vm.reportDetails = {
currencyId : Session.enterprise.currency_id,
};

checkCachedConfiguration();

Expand All @@ -24,6 +27,10 @@ function UnbalancedInvoicePaymentsConfigController($sce, Notify, SavedReports, A
vm.reportDetails = angular.copy(report);
};

vm.onSelectCurrency = currency => {
vm.reportDetails.currencyId = currency.id;
};

vm.onClear = () => {
delete vm.reportDetails.debtorGroupName;
delete vm.reportDetails.debtorGroupUuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ <h3 class="text-capitalize" translate>REPORT.UNPAID_INVOICE_PAYMENTS_REPORT.TITL
<bh-clear on-clear="ReportConfigCtrl.clear('serviceUuid')"></bh-clear>
</bh-service-select>

<bh-currency-select
currency-id="ReportConfigCtrl.reportDetails.currencyId"
on-change="ReportConfigCtrl.onSelectCurrency(currency)">
</bh-currency-select>


<bh-loading-button loading-state="ConfigForm.$loading">
<span translate>REPORT.UTIL.PREVIEW</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ async function build(req, res, next) {

const metadata = _.clone(req.session);

qs.isEnterpriseCurrency = !!(parseInt(qs.currencyId, 10) === metadata.enterprise.currency_id);

let report;
let results;

Expand All @@ -38,6 +40,14 @@ async function build(req, res, next) {
results = { dataset : [], totals : {}, services : [] };
}

if (results.services.length === 1) {
[qs.uniqueService] = results.services;
// remove last column of total in the report rendered
if (results.totals && results.totals.Total) {
delete results.totals.Total;
}
}

const data = _.extend({}, qs, results);

const compiled = await report.render(data);
Expand Down Expand Up @@ -66,6 +76,7 @@ async function getUnbalancedInvoices(options) {
const params = [
new Date(options.dateFrom),
new Date(options.dateTo),
parseInt(options.currencyId, 10),
];

const { debtorGroupName, serviceUuid } = options;
Expand All @@ -78,7 +89,7 @@ async function getUnbalancedInvoices(options) {
}

const rows = await db.transaction()
.addQuery('CALL UnbalancedInvoicePaymentsTable(?, ?);', params)
.addQuery('CALL UnbalancedInvoicePaymentsTable(?, ?, ?);', params)
.addQuery(`CALL Pivot(
"unbalanced_invoices",
"debtorGroupName,debtorUuid",
Expand Down Expand Up @@ -120,6 +131,7 @@ async function getUnbalancedInvoices(options) {
dataset.forEach(row => {
if (!row.debtorUuid) {
row.isTotalRow = true;
row.hideTotalRow = !!(debtorGroupName && row.isTotalRow);
}

if (!row.debtorGroupName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,84 @@
<strong>{{translate "REPORT.UNPAID_INVOICE_PAYMENTS_REPORT.TITLE"}}</strong>
</h3>

<h5 style="margin:15px;" class="text-center">
{{#if debtorGroupName}}
<h4 class="text-center"><strong>{{ debtorGroupName }}</strong></h4>
{{/if}}

{{#if uniqueService}}
<h4 class="text-center"><strong>{{ uniqueService }}</strong></h4>
{{/if}}

<h4 style="margin:15px; font-weight:bold" class="text-center text-uppercase">
{{date dateFrom "DD/MM/YYYY"}} - {{date dateTo "DD/MM/YYYY"}}
</h5>
</h4>

<table class="table table-condensed table-report">
{{#unless isEnterpriseCurrency}}
<div class="alert alert-warning">
<p>{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}</p>
</div>
{{/unless}}

<table class="table table-condensed table-report table-header-rotated">
<thead>
<tr style="background-color:#ddd;">
<tr class="text-center">
{{#unless debtorGroupName}}
<th class="text-center">{{translate 'FORM.LABELS.DEBTOR_GROUP'}}</th>
{{/unless}}

<th class="text-center text-capitalize">{{translate 'FORM.LABELS.PATIENT'}}</th>
{{#each services as |service|}}
<th class="text-center">{{service}}</th>
{{/each}}
{{#unless uniqueService}}
{{#each services as |service|}}
<th class="rotate-45"><div><span style="padding-left:2px;">{{service}}</span></div></th>
{{/each}}
{{/unless}}
<th class="text-center">{{translate 'FORM.LABELS.TOTAL'}}</th>
</tr>
</thead>
<tbody>
{{#each dataset as |row|}}
{{#unless row.hideTotalRow}}
<tr
{{#if row.isTotalRow}}class="table-subtotal-row"{{/if}}
{{#if row.isGroupTotalRow}}style="font-style:italic"{{/if}}
>
<td>{{ row.debtorGroupName }}</td>
{{#unless ../debtorGroupName}}
<td>{{ row.debtorGroupName }}</td>
{{/unless}}

<td>
{{#if row.debtorReference }}
<strong>{{ row.debtorReference }}</strong> - {{row.debtorText}}, {{translate 'FORM.LABELS.AGE'}} : {{row.debtorAge}}
{{/if}}
</td>
{{#each ../services as |service|}}
<td class="text-right">{{look row service}}</td>
{{/each}}
<td class="text-right">{{ row.Total }}</td>
{{#unless ../uniqueService}}
{{#each ../services as |service|}}
<td class="text-right">{{debcred (look row service) ../../currencyId}}</td>
{{/each}}
{{/unless}}

<td class="text-right">{{debcred row.Total ../currencyId}}</td>
</tr>
{{/unless}}
{{else}}
{{> emptyTable columns=3}}
{{/each}}
<tr>
{{#each totals as |value key|}}
{{#if @first}}
<th>{{translate 'FORM.LABELS.TOTAL'}}</th>
{{#unless ../debtorGroupName}}
<th>{{translate 'FORM.LABELS.TOTAL'}}</th>
{{/unless}}
{{else}}
<th class="text-right">{{ value }}</th>
{{#equal key 'debtorUuid'}}
{{#if ../debtorGroupName}}
<th>{{translate 'FORM.LABELS.TOTAL'}}</th>
{{else}}
<th>&nbsp;</th>
{{/if}}
{{else}}
<th class="text-right">{{debcred value ../currencyId}}</th>
{{/equal}}
{{/if}}
{{/each}}
</tr>
Expand Down
17 changes: 13 additions & 4 deletions server/models/procedures/invoicing.sql
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,14 @@ END$$
DROP PROCEDURE IF EXISTS UnbalancedInvoicePaymentsTable$$
CREATE PROCEDURE UnbalancedInvoicePaymentsTable(
IN dateFrom DATE,
IN dateTo DATE
IN dateTo DATE,
IN currencyId INT
) BEGIN

DECLARE exchangeRate DECIMAL(19, 8) UNSIGNED;
DECLARE _enterpriseId SMALLINT;
SET _enterpriseId = (SELECT id FROM enterprise LIMIT 1);

-- this holds all the invoices that were made during the period
-- two copies are needed for the UNION ALL query.
DROP TEMPORARY TABLE IF EXISTS tmp_invoices_1;
Expand Down Expand Up @@ -976,15 +981,19 @@ CREATE PROCEDURE UnbalancedInvoicePaymentsTable(
-- even though this column is called "balance", it is actually the amount remaining
-- on the invoice.

SET exchangeRate = (SELECT IFNULL(GetExchangeRate(_enterpriseId, currencyId, dateTo), 1));

DROP TEMPORARY TABLE IF EXISTS unbalanced_invoices;
CREATE TEMPORARY TABLE `unbalanced_invoices` AS (
SELECT BUID(ivc.uuid) as invoice_uuid , em.text AS debtorReference, debtor.text AS debtorName,
BUID(debtor.uuid) as debtorUuid,
balances.debit_equiv AS debit,
balances.credit_equiv AS credit, iv.date AS creation_date, balances.balance,
(balances.debit_equiv * exchangeRate) AS debit,
(balances.credit_equiv * exchangeRate) AS credit,
(balances.balance * exchangeRate) AS balance,
iv.date AS creation_date,
dm.text AS reference, ivc.project_id, p.name as 'projectName', dbtg.name as 'debtorGroupName',
s.name as 'serviceName', s.uuid as 'serviceUuid',
((balances.credit_equiv / IF(balances.debit_equiv = 0, 1, balances.debit_equiv )*100)) AS paymentPercentage
((balances.credit_equiv * exchangeRate / IF(balances.debit_equiv = 0, 1, balances.debit_equiv * exchangeRate)) * 100) AS paymentPercentage
FROM tmp_invoices_1 AS iv
JOIN invoice ivc ON ivc.uuid = iv.uuid
JOIN service s On s.uuid = ivc.service_uuid
Expand Down

0 comments on commit f3820ed

Please sign in to comment.