Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not crash on no account references #5857

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const fiscal = require('../fiscal');
async function configuration(req, res, next) {
try {
const { query } = req;

const params = {
typeFeeCenter : query.typeFeeCenter,
fee_center_id : query.fee_center_id,
Expand All @@ -21,6 +22,11 @@ async function configuration(req, res, next) {
const refAccounts = accounts;
const accountsId = accounts.map(account => account.account_id);

if (accountsId.length === 0) {
res.status(200).json([]);
return;
}

const options = {
accounts_id : accountsId,
excludes_distributed : true,
Expand All @@ -40,6 +46,7 @@ async function configuration(req, res, next) {
if (query.fee_center_id || query.trans_id) {
delete options.limit;
}

const rows = await generalLedger.findTransactions(options);

rows.forEach(item => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* of a profit or a cost, of an auxiliary center towards the main centers
*/
const db = require('../../../lib/db');
const BadRequest = require('../../../lib/errors/BadRequest');
const { BadRequest } = require('../../../lib/errors');

function proceed(req, res, next) {
const { data } = req.body;
Expand Down
26 changes: 15 additions & 11 deletions server/controllers/finance/distributionFeeCenter/setting.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
/**
* Distribution Fee Center Controller
*
* This function is used to set the various distribution keys of the ancillary cost centers to the Main center.
* This function is used to set the various distribution keys of the auxiliary cost centers to the main cost center.
*/

const db = require('../../../lib/db');

function setting(req, res, next) {
const { data } = req.body;

const dataValues = data.values;

data.user_id = req.session.user.id;

const distributionKey = [];

Object.entries(dataValues).forEach(([principalCenterId, rateDistribution]) => {
if (rateDistribution) {
distributionKey.push([
data.auxiliary_fee_center_id,
principalCenterId,
rateDistribution,
data.user_id,
]);
}
});
Object.entries(dataValues)
.forEach(([principalCenterId, rateDistribution]) => {
if (rateDistribution) {
distributionKey.push([
data.auxiliary_fee_center_id,
principalCenterId,
rateDistribution,
data.user_id,
]);
}
});

const delDistribution = `DELETE FROM distribution_key WHERE auxiliary_fee_center_id = ?`;

Expand Down