Skip to content

Commit

Permalink
ohada_balance_sheet, ohada_income_expense, exploitation, balance emai…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
mbayopanda committed Jul 1, 2019
1 parent 7ab8b44 commit ea4fac0
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ <h4 style="border-top: 1px dashed #ccc; margin-top: 10px;" class="text-bold">
</bh-account-select>

<div ng-if="$ctrl.accountBalance.account_id && $ctrl.accountBalance.balance !== 0" class="alert alert-danger">
<p><span translate>FISCAL.ACCOUNT_HAS_VALUE</span> : <strong>{{ $ctrl.accountBalance.balance | currency : $ctrl.currency_id }}</strong></p>
<p>
<span translate>FISCAL.ACCOUNT_HAS_VALUE</span> : <strong>{{ $ctrl.accountBalance.balance | currency : $ctrl.currency_id }}</strong>
<i>({{ $ctrl.accountBalance.balance }})</i>
</p>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function OhadaBalanceSheetReportConfigController($sce, Notify, SavedReports, App
vm.reportDetails.fiscal_id = fiscalYear.id;
};

vm.onSelectCronReport = report => {
vm.reportDetails = angular.copy(report);
};

vm.clearPreview = function clearPreview() {
vm.previewGenerated = false;
vm.previewResult = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,15 @@ <h3 class="text-capitalize" translate>REPORT.OHADA.BALANCE_SHEET</h3>
</div>
</div>
</div>

<div class="col-md-6">
<bh-cron-email-report
report-id="20"
report-url="reports/finance/ohada_balance_sheet"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
</bh-cron-email-report>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,15 @@ <h3 class="text-capitalize" translate>REPORT.OHADA.PROFIT_LOSS</h3>
</div>
</div>
</div>

<div class="col-md-6">
<bh-cron-email-report
report-id="26"
report-url="reports/finance/ohada_profit_loss"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
</bh-cron-email-report>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function OhadaProfitLossReportConfigController($sce, Notify, SavedReports, AppCa
vm.reportDetails.fiscal_id = fiscalYear.id;
};

vm.onSelectCronReport = report => {
vm.reportDetails = angular.copy(report);
};

vm.clearPreview = function clearPreview() {
vm.previewGenerated = false;
vm.previewResult = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ function OperatingConfigController($sce, Notify, SavedReports, AppCache, reportD
vm.reportDetails.periodTo = period.id;
};

vm.onSelectCronReport = report => {
vm.reportDetails = angular.copy(report);
};

vm.preview = function preview(form) {
if (form.$invalid) { return; }
if (form.$invalid) { return null; }

// update cached configuration
cache.reportDetails = angular.copy(vm.reportDetails);
Expand Down
10 changes: 10 additions & 0 deletions client/src/modules/reports/generate/operating/operating.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,15 @@ <h3 class="text-capitalize" translate>TREE.OPERATING_ACCOUNT</h3>
</div>
</div>
</div>

<div class="col-md-6">
<bh-cron-email-report
report-id="15"
report-url="/reports/finance/operating"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
</bh-cron-email-report>
</div>
</div>
</div>
7 changes: 1 addition & 6 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ const transactions = require('../controllers/finance/transactions');
// looking up an entity by it reference
const referenceLookup = require('../lib/referenceLookup');

const operating = require('../controllers/finance/reports/operating/index');

const department = require('../controllers/admin/department');
const tags = require('../controllers/admin/tags');

Expand Down Expand Up @@ -397,7 +395,6 @@ exports.configure = function configure(app) {
app.get('/reports/finance/financialPatient/:uuid', financeReports.patient);
app.get('/reports/finance/income_expense', financeReports.income_expense.document);
app.get('/reports/finance/unpaid-invoice-payments', unpaidInvoicePayments.document);

app.get('/reports/finance/income_expense_by_month', financeReports.income_expense_by_month.document);
app.get('/reports/finance/income_expense_by_year', financeReports.income_expense_by_year.document);
app.get('/reports/finance/cash_report', financeReports.cashReport.document);
Expand All @@ -417,6 +414,7 @@ exports.configure = function configure(app) {
app.get('/reports/finance/employeeStanding/', financeReports.employee);
app.get('/reports/finance/break_even', financeReports.breakEven.report);
app.get('/reports/finance/break_even_fee_center', financeReports.breakEvenFeeCenter.report);
app.get('/reports/finance/operating', financeReports.operating.document);

// visits reports
app.get('/reports/visits', medicalReports.visitsReports.document);
Expand Down Expand Up @@ -791,9 +789,6 @@ exports.configure = function configure(app) {
app.post('/install', install.proceedInstall);

app.get('/diagnoses', diagnoses.list);

app.get('/reports/finance/operating', operating.document);

app.get('/roles', rolesCtrl.list);
app.get('/roles/:uuid', rolesCtrl.detail);

Expand Down
5 changes: 2 additions & 3 deletions server/controllers/admin/cronEmailReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ function remove(req, res, next) {

async function create(req, res, next) {
try {
const query = `
INSERT INTO cron_email_report SET ?;
`;
const query = 'INSERT INTO cron_email_report SET ?;';
const { cron, reportOptions } = req.body;
// FIXME: date cannot be dynamic here
const options = addDynamicDatesOptions(cron.cron_id, cron.has_dynamic_dates, reportOptions);

db.convert(cron, ['entity_group_uuid']);
Expand Down
1 change: 1 addition & 0 deletions server/controllers/finance/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ exports.feeCenter = require('./fee_center');
exports.annualClientsReport = require('./debtors/annual-clients-report').annualClientsReport;
exports.breakEven = require('./break_even');
exports.breakEvenFeeCenter = require('./break_even_fee_center');
exports.operating = require('./operating');
29 changes: 20 additions & 9 deletions server/controllers/finance/reports/ohada_balance_sheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,29 @@ const balanceSheetLiabilityTable = balanceSheetElement.balanceSheetLiabilityTabl

// expose to the API
exports.document = document;
exports.reporting = reporting;
exports.aggregateReferences = aggregateReferences;

/**
* @function document
* @description process and render the balance report document
* @description this function helps to get html document of the report in server side
* so that we can use it with others modules on the server side
* @param {object} options the report options
* @param {object} session the session
*/
function document(req, res, next) {
const params = req.query;
function reporting(options, session) {
const params = options;
const context = {};
let report;

_.defaults(params, DEFAULT_PARAMS);

try {
report = new ReportManager(TEMPLATE, req.session, params);
report = new ReportManager(TEMPLATE, session, params);
} catch (e) {
next(e);
return;
throw e;
}

balanceSheetElement.getFiscalYearDetails(params.fiscal_id)
return balanceSheetElement.getFiscalYearDetails(params.fiscal_id)
.then(fiscalYear => {
_.merge(context, { fiscalYear });
const currentPeriodReferences = AccountReference.computeAllAccountReference(fiscalYear.current.period_id);
Expand Down Expand Up @@ -254,7 +257,15 @@ function document(req, res, next) {

_.merge(context, { assetTable, liabilityTable });
return report.render(context);
})
});
}

/**
* @function document
* @description process and render the balance report document
*/
function document(req, res, next) {
reporting(req.query, req.session)
.then(result => {
res.set(result.header).send(result.report);
})
Expand Down
34 changes: 23 additions & 11 deletions server/controllers/finance/reports/ohada_profit_loss/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const _ = require('lodash');
const db = require('../../../../lib/db');
const AccountReference = require('../../accounts/references');
const ReportManager = require('../../../../lib/ReportManager');

// expose to the API
exports.document = document;
exports.reporting = reporting;

// report template
const TEMPLATE = './server/controllers/finance/reports/ohada_profit_loss/report.handlebars';

Expand Down Expand Up @@ -163,28 +168,27 @@ const mapTable = {};
profitLossTable.forEach(item => {
mapTable[item.ref] = item.sign;
});
// expose to the API
exports.document = document;

/**
* @function document
* @description process and render the balance report document
* @description this function helps to get html document of the report in server side
* so that we can use it with others modules on the server side
* @param {*} options the report options
* @param {*} session the session
*/
function document(req, res, next) {
const params = req.query;
function reporting(options, session) {
const params = options;
const context = {};
let report;

_.defaults(params, DEFAULT_PARAMS);

try {
report = new ReportManager(TEMPLATE, req.session, params);
report = new ReportManager(TEMPLATE, session, params);
} catch (e) {
next(e);
return;
throw e;
}

getFiscalYearDetails(params.fiscal_id)
return getFiscalYearDetails(params.fiscal_id)
.then(fiscalYear => {
_.merge(context, { fiscalYear });

Expand Down Expand Up @@ -297,7 +301,15 @@ function document(req, res, next) {
_.merge(context, { assetTable }, { totals });

return report.render(context);
})
});
}

/**
* @function document
* @description process and render the balance report document
*/
function document(req, res, next) {
reporting(req.query, req.session)
.then(result => {
res.set(result.header).send(result.report);
})
Expand Down
31 changes: 20 additions & 11 deletions server/controllers/finance/reports/operating/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,40 @@ const TEMPLATE = './server/controllers/finance/reports/operating/report.handleba

exports.document = document;
exports.formatData = formatData;
exports.reporting = reporting;

const EXPENSE_ACCOUNT_TYPE = 5;
const INCOME_ACCOUNT_TYPE = 4;
const DECIMAL_PRECISION = 2; // ex: 12.4567 => 12.46


function document(req, res, next) {
const params = req.query;
/**
* @description this function helps to get html document of the report in server side
* so that we can use it with others modules on the server side
* @param {*} options the report options
* @param {*} session the session
*/
function reporting(opts, session) {
const params = opts;
let docReport;
const options = _.extend(req.query, {
const options = _.extend(opts, {
filename : 'TREE.OPERATING_ACCOUNT',
csvKey : 'rows',
user : req.session.user,
user : session.user,
});

try {
docReport = new ReportManager(TEMPLATE, req.session, options);
docReport = new ReportManager(TEMPLATE, session, options);
} catch (e) {
next(e);
return;
throw e;
}

let queries;
let range;
let lastRateUsed;
let firstCurrency;
let secondCurrency;
const enterpriseId = req.session.enterprise.id;
const enterpriseCurrencyId = req.session.enterprise.currency_id;
const enterpriseId = session.enterprise.id;
const enterpriseCurrencyId = session.enterprise.currency_id;
const getQueryIncome = fiscal.getAccountBalancesByTypeId;

const periods = {
Expand Down Expand Up @@ -125,7 +130,11 @@ function document(req, res, next) {
context.total = diff;

return docReport.render(context);
})
});
}

function document(req, res, next) {
reporting(req.query, req.session)
.then((result) => {
res.set(result.headers).send(result.report);
})
Expand Down
3 changes: 3 additions & 0 deletions server/controllers/report.handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ const financeReports = require('./finance/reports');

module.exports = {
balance_report : financeReports.balance.reporting,
ohada_balance_sheet_report : financeReports.ohadaBalanceSheet.reporting,
ohada_profit_loss : financeReports.ohadaProfitLoss.reporting,
operating : financeReports.operating.reporting,
};
Loading

0 comments on commit ea4fac0

Please sign in to comment.