diff --git a/e2e/dms/8f1/7.jpeg b/e2e/dms/8f1/7.jpeg new file mode 100644 index 000000000..fb2483f69 Binary files /dev/null and b/e2e/dms/8f1/7.jpeg differ diff --git a/modules/client/back/methods/receipt/createReceipt.js b/modules/client/back/methods/receipt/createReceipt.js index eb199f518..cc2ce27e6 100644 --- a/modules/client/back/methods/receipt/createReceipt.js +++ b/modules/client/back/methods/receipt/createReceipt.js @@ -58,9 +58,11 @@ module.exports = function(Self) { delete args.ctx; // Remove unwanted properties const newReceipt = await models.Receipt.create(args, options); + const clientOriginal = await models.Client.findById(args.clientFk); + const bank = await models.Bank.findById(args.bankFk); + const accountingType = await models.AccountingType.findById(bank.accountingTypeFk); if (args.compensationAccount) { - const clientOriginal = await models.Client.findById(args.clientFk); const supplierCompensation = await models.Supplier.findOne({ where: { account: args.compensationAccount @@ -77,12 +79,6 @@ module.exports = function(Self) { if (!supplierCompensation && !clientCompensation) throw new UserError('Invalid account'); - const accountingType = await models.AccountingType.findOne({ - where: { - code: 'compensation' - } - }); - await Self.rawSql( `CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`, [ @@ -96,15 +92,14 @@ module.exports = function(Self) { ], options); } else { - const bank = await models.Bank.findById(args.bankFk); - const ledger = await Self.rawSql( - `SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, + const [xdiarioNew] = await Self.rawSql( + `SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`, [ null, Date(), bank.account, clientOriginal.accountingAccount, - clientOriginal.id + ':' + clientOriginal.nickname, '-', accountingType.receiptDescription, + clientOriginal.id + ':' + clientOriginal.nickname + '-' + accountingType.receiptDescription, args.amountPaid, 0, 0, @@ -120,11 +115,11 @@ module.exports = function(Self) { await Self.rawSql( `SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [ - ledger, + xdiarioNew.ledger, Date(), clientOriginal.accountingAccount, bank.account, - clientOriginal.id + ':' + clientOriginal.nickname, '-', accountingType.receiptDescription, + clientOriginal.id + ':' + clientOriginal.nickname + '-' + accountingType.receiptDescription, 0, args.amountPaid, 0,