Skip to content

Commit

Permalink
improvement(All Employee Standing report)
Browse files Browse the repository at this point in the history
- Cache the currency used
- Using optional chaining
- Display warning when the user does not choose the enterprise exchage
  rate
- Update label using report instead repport and detailed instead
  detailled
- Update url for Report of All Employees
- Use only one try/Catch
- Improve the using of function Exchange.getExchangeRate() use the
  dateTo for getting report
  • Loading branch information
lomamech committed Dec 20, 2021
1 parent ee876ac commit 15032dc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ <h3 class="text-capitalize" translate>REPORT.EMPLOYEE_STANDING.TITLE</h3>
<label class="radio-inline">
<input
type="radio"
name="modeRepport"
name="modeReport"
value="summary"
ng-model="ReportConfigCtrl.reportDetails.modeRepport"
ng-model="ReportConfigCtrl.reportDetails.modeReport"
ng-click="ReportConfigCtrl.onSelectMode('summary')"
required>
<span translate>
Expand All @@ -48,9 +48,9 @@ <h3 class="text-capitalize" translate>REPORT.EMPLOYEE_STANDING.TITLE</h3>
<label class="radio-inline">
<input
type="radio"
name="modeRepport"
name="modeReport"
value="normal"
ng-model="ReportConfigCtrl.reportDetails.modeRepport"
ng-model="ReportConfigCtrl.reportDetails.modeReport"
ng-click="ReportConfigCtrl.onSelectMode('normal')"
required>
<span translate>
Expand All @@ -62,10 +62,10 @@ <h3 class="text-capitalize" translate>REPORT.EMPLOYEE_STANDING.TITLE</h3>
<label class="radio-inline">
<input
type="radio"
name="modeRepport"
value="detailled"
ng-model="ReportConfigCtrl.reportDetails.modeRepport"
ng-click="ReportConfigCtrl.onSelectMode('detailled')"
name="modeReport"
value="detailed"
ng-model="ReportConfigCtrl.reportDetails.modeReport"
ng-click="ReportConfigCtrl.onSelectMode('detailed')"
required>
<span translate>
REPORT.EMPLOYEE_STANDING.DETAILED_REPORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function EmployeeStandingController($state, $sce, Notify, AppCache, SavedReports

checkCachedConfiguration();

vm.reportDetails.currency_id = Session.enterprise.currency_id;
vm.reportDetails.currency_id = vm.reportDetails?.currency_id || Session.enterprise.currency_id;


// custom filter employee_uuid
vm.onSelectEmployee = function onSelectEmployee(employee) {
Expand All @@ -48,8 +49,8 @@ function EmployeeStandingController($state, $sce, Notify, AppCache, SavedReports
.catch(Notify.handleError);
};

vm.onSelectMode = function onSelectMode(modeRepport) {
vm.reportDetails.modeRepport = modeRepport;
vm.onSelectMode = function onSelectMode(modeReport) {
vm.reportDetails.modeReport = modeReport;
};

vm.preview = function preview(form) {
Expand All @@ -61,7 +62,7 @@ function EmployeeStandingController($state, $sce, Notify, AppCache, SavedReports
if (vm.reportDetails.allEmployee) {
delete vm.reportDetails.employee_uuid;
delete vm.reportDetails.includeMedicalCare;
reportUrl = '/reports/finance/employees_standing';
reportUrl = '/reports/finance/all_employees_standing';
} else if (!vm.reportDetails.allEmployee && vm.reportDetails.employee_uuid) {
reportUrl = '/reports/finance/employee_standing';
}
Expand All @@ -87,6 +88,6 @@ function EmployeeStandingController($state, $sce, Notify, AppCache, SavedReports
vm.reportDetails = angular.copy(cache.reportDetails);
}

vm.reportDetails.modeRepport = 'summary';
vm.reportDetails.modeReport = 'summary';
}
}
2 changes: 1 addition & 1 deletion server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ exports.configure = function configure(app) {
app.get('/reports/finance/cost_center_income_and_expense', financeReports.costCenterStepdown.incomeAndExpenseReport);
app.get('/reports/finance/annual_clients_report', financeReports.annualClientsReport);
app.get('/reports/finance/employee_standing/', financeReports.employee);
app.get('/reports/finance/employees_standing/', financeReports.employees);
app.get('/reports/finance/all_employees_standing/', financeReports.allEmployees);
app.get('/reports/finance/break_even', financeReports.breakEven.report);
app.get('/reports/finance/break_even_cost_center', financeReports.breakEvenCostCenter.report);
app.get('/reports/finance/operating', financeReports.operating.document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
</span>
</h3>

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

{{#if limitTimeInterval}}
<div class="text-center">
<strong>
Expand Down Expand Up @@ -68,7 +74,7 @@
</tfoot>
{{/if}}

{{#if detailled}}
{{#if detailed}}
<thead>
<tr class="text-uppercase text-center" style="background-color: #ddd;" >
<th style="width: 2%;"></th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ReportManager = require('../../../lib/ReportManager');
const db = require('../../../lib/db');
const Exchange = require('../exchange');

const TEMPLATE = './server/controllers/finance/reports/financial.employees.handlebars';
const TEMPLATE = './server/controllers/finance/reports/financial.all_employees.handlebars';

const PDF_OPTIONS = {
filename : 'FORM.LABELS.FINANCIAL_STATUS',
Expand All @@ -34,7 +34,7 @@ async function build(req, res, next) {
let filterBydatePosting = ``;
let filterBydateLegder = ``;
let report;
let exchange;
let dateExchangeRate;

options.limitTimeInterval = parseInt(options.limitTimeInterval, 10);

Expand All @@ -47,29 +47,22 @@ async function build(req, res, next) {
filterBydateLegder = ` WHERE (DATE(gl.trans_date) >= DATE('${transDateFrom}')
AND DATE(gl.trans_date) <= DATE('${transDateTo}'))`;

exchange = await Exchange.getExchangeRate(req.session.enterprise.id, Number(options.currency_id), transDateFrom);
dateExchangeRate = transDateTo;
} else {
exchange = await Exchange.getExchangeRate(req.session.enterprise.id, Number(options.currency_id), new Date());
dateExchangeRate = new Date();
}

_.defaults(options, PDF_OPTIONS);

// set up the report with report manager
try {
report = new ReportManager(TEMPLATE, req.session, options);
} catch (e) {
return next(e);
}

try {

const data = {};
data.exchangeRate = exchange.rate || 1;
data.currencyId = options.currency_id;

let sql;

if (options.modeRepport === 'summary') {
if (options.modeReport === 'summary') {
data.summary = 1;

sql = `
Expand All @@ -96,8 +89,8 @@ async function build(req, res, next) {
GROUP BY aggr.account_id
ORDER BY aggr.number ASC
`;
} else if (options.modeRepport === 'detailled') {
data.detailled = 1;
} else if (options.modeReport === 'detailed') {
data.detailed = 1;

sql = `
SELECT SUM(aggr.debit) AS debit, SUM(aggr.credit) AS credit,
Expand Down Expand Up @@ -129,7 +122,7 @@ async function build(req, res, next) {
GROUP BY aggr.employee_uuid, aggr.account_id
ORDER BY aggr.employee_name, aggr.number ASC
`;
} else if (options.modeRepport === 'normal') {
} else if (options.modeReport === 'normal') {
data.normal = 1;

sql = `
Expand Down Expand Up @@ -164,10 +157,19 @@ async function build(req, res, next) {
`;
}

const [financialData] = await Promise.all([
const [financialData, exchange] = await Promise.all([
db.exec(sql),
Exchange.getExchangeRate(
req.session.enterprise.id,
Number(options.currency_id),
dateExchangeRate,
),
]);

data.exchangeRate = exchange.rate || 1;
data.currencyId = options.currency_id;
data.isEnterpriseCurrency = req.session.enterprise.currency_id === Number(options.currency_id);

let sumDebit = 0;
let sumCredit = 0;
let sumBalance = 0;
Expand Down Expand Up @@ -198,9 +200,10 @@ async function build(req, res, next) {
const result = await report.render(data);
return res.set(result.headers).send(result.report);

} catch (error) {
return next(error);
} catch (e) {
return next(e);
}

}

exports.report = build;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
{{translate balanceCreditorText}} = {{debcred (multiply ./creditorAggregates.balance exchangeRate) currencyId}}
</b>
</h4>

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

{{#if includeMedicalCare }}
<h5 class="text-uppercase" style="background-color: #efefef;">
<em>
Expand Down
28 changes: 16 additions & 12 deletions server/controllers/finance/reports/financial.employee.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PDF_OPTIONS = {
async function build(req, res, next) {
const options = req.query;
let report;
let exchange;
let dateExchangeRate;

options.currency_id = options.currency_id || req.session.enterprise.currency_id;

Expand All @@ -43,36 +43,40 @@ async function build(req, res, next) {
options.dateFrom = ``;
options.dateTo = ``;

exchange = await Exchange.getExchangeRate(req.session.enterprise.id, Number(options.currency_id), new Date());
dateExchangeRate = new Date();
} else {
exchange = await Exchange.getExchangeRate(req.session.enterprise.id, Number(options.currency_id), options.dateFrom);
dateExchangeRate = options.dateTo;
}

_.defaults(options, PDF_OPTIONS);

// set up the report with report manager
try {
report = new ReportManager(TEMPLATE, req.session, options);
} catch (e) {
return next(e);
}

try {
const data = {};
data.exchangeRate = exchange.rate || 1;

data.currencyId = options.currency_id;
data.isEnterpriseCurrency = req.session.enterprise.currency_id === Number(options.currency_id);

const sql = `
SELECT BUID(p.debtor_uuid) as debtor_uuid
FROM patient p
JOIN employee em ON p.uuid = em.patient_uuid
WHERE em.uuid = ?`;

const [employee, patient] = await Promise.all([
const [employee, patient, exchange] = await Promise.all([
Employee.lookupEmployee(options.employee_uuid),
db.one(sql, db.bid(options.employee_uuid)),
Exchange.getExchangeRate(
req.session.enterprise.id,
Number(options.currency_id),
dateExchangeRate,
),
]);

data.exchangeRate = exchange.rate || 1;

// get debtor/creditor information
const [creditorOperations, debtorOperations] = await Promise.all([
Creditors.getFinancialActivity(employee.creditor_uuid, options.dateFrom, options.dateTo),
Expand Down Expand Up @@ -121,10 +125,10 @@ async function build(req, res, next) {
// let render
const result = await report.render(data);
return res.set(result.headers).send(result.report);

} catch (error) {
return next(error);
} catch (e) {
return next(e);
}

}

exports.report = build;
2 changes: 1 addition & 1 deletion server/controllers/finance/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.accountStatement = require('./account_statement');
exports.cashReport = require('./cashReport');
exports.purchases = require('./purchases');
exports.employee = require('./financial.employee').report;
exports.employees = require('./financial.employees').report;
exports.allEmployees = require('./financial.all_employees').report;
exports.priceList = require('./priceList').report;
exports.ohadaBalanceSheet = require('./ohada_balance_sheet');
exports.ohadaProfitLoss = require('./ohada_profit_loss');
Expand Down

0 comments on commit 15032dc

Please sign in to comment.