Skip to content

Commit

Permalink
eslint finance folder contnues
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed May 8, 2017
1 parent d55bca0 commit fbed510
Show file tree
Hide file tree
Showing 27 changed files with 249 additions and 1,693 deletions.
63 changes: 0 additions & 63 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,21 @@ const ledger = require('../controllers/finance/ledger');
const fiscal = require('../controllers/finance/fiscal');
const gl = require('../controllers/finance/ledgers/general');
const purchases = require('../controllers/finance/purchases');
const taxPayment = require('../controllers/finance/taxPayment');
const debtors = require('../controllers/finance/debtors');
const cashboxes = require('../controllers/finance/cashboxes');
const exchange = require('../controllers/finance/exchange');
const cash = require('../controllers/finance/cash');
const priceList = require('../controllers/finance/priceList');
const billingServices = require('../controllers/finance/billingServices');
const accounts = require('../controllers/finance/accounts');
const costCenter = require('../controllers/finance/costCenter');
const profitCenter = require('../controllers/finance/profitCenter');
const reference = require('../controllers/finance/reference');
const subsidies = require('../controllers/finance/subsidies');
const patientInvoice = require('../controllers/finance/patientInvoice');
const financeReports = require('../controllers/finance/reports');
const discounts = require('../controllers/finance/discounts');
const payroll = require('../controllers/finance/payroll');
const debtorGroups = require('../controllers/finance/debtors/groups');
const currencies = require('../controllers/finance/currencies');
const vouchers = require('../controllers/finance/vouchers');
const creditorGroups = require('../controllers/finance/creditorGroups');
const referenceGroup = require('../controllers/finance/referenceGroup');
const sectionResultats = require('../controllers/finance/sectionResultat');
const sectionBilans = require('../controllers/finance/sectionBilan');
const creditors = require('../controllers/finance/creditors.js');
const journal = require('../controllers/finance/journal');
const transactionType = require('../controllers/admin/transactionType');
Expand Down Expand Up @@ -152,57 +144,13 @@ exports.configure = function configure(app) {
app.post('/accounts', accounts.create);
app.put('/accounts/:id', accounts.update);

// API for cost_center routes CRUD
app.get('/cost_centers', costCenter.list);
app.get('/cost_centers/:id', costCenter.detail);
app.get('/cost_centers/:id/cost', costCenter.getCostValue);
app.post('/cost_centers', costCenter.create);
app.put('/cost_centers/:id', costCenter.update);
app.delete('/cost_centers/:id', costCenter.remove);

// API for service routes
app.post('/services', services.create);
app.get('/services', services.list);
app.get('/services/:id', services.detail);
app.put('/services/:id', services.update);
app.delete('/services/:id', services.remove);

// API for profit_center routes crud
app.get('/profit_centers', profitCenter.list);
app.get('/profit_centers/:id', profitCenter.detail);
app.get('/profit_centers/:id/profit', profitCenter.getProfitValue);
app.post('/profit_centers', profitCenter.create);
app.put('/profit_centers/:id', profitCenter.update);
app.delete('/profit_centers/:id', profitCenter.remove);

// API for reference routes crud
app.get('/references', reference.list);
app.get('/references/:id', reference.detail);
app.post('/references', reference.create);
app.put('/references/:id', reference.update);
app.delete('/references/:id', reference.remove);

// API for section resultats crud
app.get('/section_resultats', sectionResultats.list);
app.get('/section_resultats/:id', sectionResultats.detail);
app.post('/section_resultats', sectionResultats.create);
app.put('/section_resultats/:id', sectionResultats.update);
app.delete('/section_resultats/:id', sectionResultats.remove);

// API for section bilans crud
app.get('/section_bilans', sectionBilans.list);
app.get('/section_bilans/:id', sectionBilans.detail);
app.post('/section_bilans', sectionBilans.create);
app.put('/section_bilans/:id', sectionBilans.update);
app.delete('/section_bilans/:id', sectionBilans.remove);

// API for reference group crud
app.get('/reference_group', referenceGroup.list);
app.get('/reference_group/:id', referenceGroup.detail);
app.post('/reference_group', referenceGroup.create);
app.put('/reference_group/:id', referenceGroup.update);
app.delete('/reference_group/:id', referenceGroup.remove);

// API for subsidies routes crud
app.get('/subsidies', subsidies.list);
app.get('/subsidies/:id', subsidies.detail);
Expand Down Expand Up @@ -255,17 +203,6 @@ exports.configure = function configure(app) {
app.get('/getCheckHollyday/', employees.checkHoliday);
app.get('/getCheckOffday/', employees.checkOffday);

app.get('available_payment_period/', taxPayment.availablePaymentPeriod);
app.put('/setTaxPayment/', taxPayment.setTaxPayment);

// Payroll
app.get('/getDataPaiement/', payroll.listPaiementData);
app.get('/getEmployeePayment/:id', payroll.listPaymentByEmployee);
app.get('/getEnterprisePayment/:employee_id', payroll.listPaymentByEnterprise);
app.put('/setCotisationPayment/', payroll.setCotisationPayment);
app.get('/getEmployeeCotisationPayment/:id', payroll.listEmployeeCotisationPayments);
app.get('/taxe_ipr_currency/', payroll.listTaxCurrency);

/* Inventory and Stock Management */
app.post('/inventory/metadata', inventory.createInventoryItems);
app.get('/inventory/metadata', inventory.getInventoryItems);
Expand Down
8 changes: 0 additions & 8 deletions server/controllers/finance/analytics.js

This file was deleted.

56 changes: 18 additions & 38 deletions server/controllers/finance/billingServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @requires lib/errors/BadRequest
*
*/
const _ = require('lodash');
const db = require('../../lib/db');
const NotFound = require('../../lib/errors/NotFound');
const _ = require('lodash');
const db = require('../../lib/db');
const NotFound = require('../../lib/errors/NotFound');
const BadRequest = require('../../lib/errors/BadRequest');

/**
Expand All @@ -26,27 +26,18 @@ const BadRequest = require('../../lib/errors/BadRequest');
* service entity.
*/
function lookupBillingService(id) {

var sql =
`SELECT bs.id, bs.account_id, bs.label, bs.description, bs.value,
bs.created_at, bs.updated_at, a.number
FROM billing_service AS bs JOIN account AS a ON bs.account_id = a.id
WHERE bs.id = ?;`;

return db.exec(sql, [ id ])
return db.exec(sql, [id])
.then(function (rows) {

// if no records matching, throw a 404
if (rows.length === 0) {
throw new NotFound(

/** @todo - replace with ES6 template strings */
_.template(
'Could not find a billing service with id: ${id}.'
)({ id : id })
);
throw new NotFound(`Could not find a billing service with id: ${id}.`);
}

// return a single JSON of the record
return rows[0];
});
Expand All @@ -59,7 +50,6 @@ function lookupBillingService(id) {
* @description retrieve the details of a single billing service.
*/
exports.detail = function detail(req, res, next) {

// looks up the billing service by ID
lookupBillingService(req.params.id)
.then(function (billingService) {
Expand All @@ -77,8 +67,7 @@ exports.detail = function detail(req, res, next) {
* levels of detail
*/
exports.list = function list(req, res, next) {

var sql =
let sql =
`SELECT bs.id, bs.label, bs.created_at
FROM billing_service AS bs
ORDER BY bs.label;`;
Expand Down Expand Up @@ -108,34 +97,28 @@ exports.list = function list(req, res, next) {
* @desc creates a new billing service
*/
exports.create = function create(req, res, next) {

// cache posted data for easy lookup
var data = req.body.billingService;
const data = req.body.billingService;

// delete the id if it exists -- the db will create one via auto-increment
delete data.id;

// ensure that values inserted are positive
if (data.value <= 0) {
return next(
next(
new BadRequest(

/** @todo - replace with ES6 template strings */
_.template(
'The value submitted to a billing service must be positive. ' +
'You provided the negative value ${value}.'
)({ value : data.value })
`The value submitted to a billing service must be positive.
You provided the negative value ${data.value}.`
)
);
}

var sql =
const sql =
`INSERT INTO billing_service (account_id, label, description, value)
VALUES (?, ?, ?, ?);`;

db.exec(sql, [ data.account_id, data.label, data.description, data.value ])
db.exec(sql, [data.account_id, data.label, data.description, data.value])
.then(function (results) {

// return the id to the client for future lookups.
res.status(201).json({ id : results.insertId });
})
Expand All @@ -150,24 +133,22 @@ exports.create = function create(req, res, next) {
* @desc updates an existing billing service with new information
*/
exports.update = function update(req, res, next) {

// cache the id
var id = req.params.id;
var data = req.body.billingService;
const id = req.params.id;
const data = req.body.billingService;

// remove the :id if it exists inside the billingService object
delete data.id;

var sql =
const sql =
'UPDATE billing_service SET ? WHERE id = ?;';

// ensure that the billing service matching :id exists
lookupBillingService(id)
.then(function () {
return db.exec(sql, [ data, req.params.id ]);
return db.exec(sql, [data, req.params.id]);
})
.then(function () {

// return the full changed object
return lookupBillingService(id);
})
Expand All @@ -185,14 +166,13 @@ exports.update = function update(req, res, next) {
* @desc deletes a billing service in the database
*/
exports.delete = function del(req, res, next) {

var sql =
const sql =
'DELETE FROM billing_service WHERE id = ?;';

// first make sure that the billing service exists
lookupBillingService(req.params.id)
.then(function () {
return db.exec(sql, [ req.params.id ]);
return db.exec(sql, [req.params.id]);
})
.then(function () {
res.sendStatus(204);
Expand Down
18 changes: 11 additions & 7 deletions server/controllers/finance/cash.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ module.exports = create;
* @returns {Array} - an ordered array of arrays (cash_items)
*/
function processCashItems(cashUuid, items) {

// make sure uuids are defined and converted
items.forEach(item => {

items.map(function (item) {
item.cash_uuid = cashUuid;
item.uuid = item.uuid || uuid.v4();
item = db.convert(item, ['uuid', 'invoice_uuid']);
return db.convert(item, ['uuid', 'invoice_uuid']);
});

// make sure the items are in an ordered array
Expand All @@ -42,7 +42,8 @@ function processCashItems(cashUuid, items) {
*
*
*/
function processCash(cashUuid, payment) {
function processCash(cashUuid, cashPayment) {
let payment = cashPayment;

payment.uuid = cashUuid;
payment = db.convert(payment, ['debtor_uuid']);
Expand Down Expand Up @@ -82,20 +83,23 @@ function create(req, res, next) {

// disallow invoice payments with empty items by returning a 400 to the client
if (isInvoicePayment && !hasItems) {
return next(
next(
new BadRequest('You must submit cash items with the payments against previous invoices.')
);

return;
// disallow caution payments with items for more predictable application
// behavior.
} else if (!isInvoicePayment && hasItems) {
return next(
next(
new BadRequest(
`You must be confused. You submitted payment against items marked as a
caution payment. Please submit either a caution with no items or a payment
marked with is_caution = 0.`
)
);

return;
}

// generate a UUID if it not provided.
Expand Down Expand Up @@ -142,7 +146,7 @@ function create(req, res, next) {

transaction.execute()
.then(() => {
res.status(201).json({ uuid: uuid.unparse(cashUuid) });
res.status(201).json({ uuid : uuid.unparse(cashUuid) });

Topic.publish(Topic.channels.FINANCE, {
event : Topic.events.CREATE,
Expand Down
25 changes: 14 additions & 11 deletions server/controllers/finance/cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,21 @@ function list(req, res, next) {
* @method search
* @description search cash payment by some filters given
*/
function search(req, res, next) {
listPayment(req.query)
.then((rows) => {
res.status(200).json(rows);
})
.catch(next)
.done();
}
function search(req, res, next) {
listPayment(req.query)
.then((rows) => {
res.status(200).json(rows);
})
.catch(next)
.done();
}

/**
* @method listPayment
* @description list all payment made
*/
function listPayment(options) {
const filters = new FilterParser(options, { tableAlias: 'cash' });
const filters = new FilterParser(options, { tableAlias : 'cash' });

const sql = `
SELECT BUID(cash.uuid) as uuid, cash.project_id,
Expand Down Expand Up @@ -178,7 +178,10 @@ function listPayment(options) {
// @TODO Support ordering query (reference support for limit)?
filters.setOrder('ORDER BY cash.date DESC');

filters.custom('invoice_uuid', 'cash.uuid IN (SELECT cash_item.cash_uuid FROM cash_item WHERE cash_item.invoice_uuid = HUID(?))');
filters.custom(
'invoice_uuid',
'cash.uuid IN (SELECT cash_item.cash_uuid FROM cash_item WHERE cash_item.invoice_uuid = HUID(?))'
);

const query = filters.applyQuery(sql);
const parameters = filters.parameters();
Expand Down Expand Up @@ -234,7 +237,7 @@ function update(req, res, next) {

// properly parse date if it exists
if (req.body.date) {
_.extend(req.body, { date: new Date(req.body.date) });
_.extend(req.body, { date : new Date(req.body.date) });
}

// if checks pass, we are free to continue with our updates to the db
Expand Down
Loading

0 comments on commit fbed510

Please sign in to comment.