#7134 SupplierBalance #3173

Merged
jsegarra merged 27 commits from 7134-supplierBalance into dev 2025-01-29 15:16:00 +00:00
2 changed files with 88 additions and 65 deletions
Showing only changes of commit 0a4f4c5926 - Show all commits

View File

@ -1,77 +1,89 @@
const UserError = require('vn-loopback/util/user-error');
// const UserError = require('vn-loopback/util/user-error');
jsegarra marked this conversation as resolved Outdated

comentarios

comentarios

He eliminado el archivo

He eliminado el archivo
// Insert payment
// divisa = solo en caso que la moneda sea distinta a €,
module.exports = function(Self) {
Self.remoteMethodCtx('createReceipt', {
Self.remoteMethodCtx('createPayment', {
description: 'Creates receipt and its compensation if necessary',
accessType: 'READ',
accepts: [{
arg: 'supplierFk',
type: 'number',
description: 'The supplier id',
http: {source: 'path'}
},
{
arg: 'received',
type: 'Date',
required: true
},
{
arg: 'dueDate',
type: 'Date',
required: true
},
{
arg: 'companyFk',
type: 'number',
required: true
},
{
arg: 'currencyFk',
type: 'number',
required: true
},
{
arg: 'bankFk',
type: 'number',
required: true
},
{
arg: 'payMethodFk',
type: 'number',
required: true
},
{
arg: 'amount',
type: 'number',
required: true
},
{
arg: 'concept',
type: 'string',
required: true
},
{
arg: 'divisa',
type: 'number'
},
{
arg: 'compensationAccount',
type: 'any'
}],
accepts: [
{
arg: 'received',
type: 'Date',
required: true
},
{
arg: 'dueDate',
type: 'Date',
required: true
},
{
arg: 'supplierFk',
type: 'number',
description: 'The supplier id',
http: {source: 'path'}
},
{
arg: 'amount',
type: 'number',
required: true
},
{
arg: 'currencyFk',
type: 'number',
required: true
}, {
arg: 'divisa',
type: 'number',
required: true
},
{
arg: 'bankFk',
type: 'number',
required: true
},
{
arg: 'payMethodFk',
type: 'number',
required: true
},
{
arg: 'bankingFees',
type: 'number',
required: true
},
{
arg: 'concept',
type: 'string',
required: true
}, {
arg: 'companyFk',
type: 'number',
required: true
},
{
arg: 'isConciliated',
type: 'boolean'
},
{
arg: 'compensationAccount',
type: 'any'
}
],
returns: {
root: true,
type: 'Object'
},
http: {
verb: 'post',
path: '/:supplierFk/createReceipt'
path: '/:supplierFk/createPayment'
},
accessScopes: ['DEFAULT', 'read:multimedia']
});
Self.createReceipt = async(ctx, options) => {
Self.createPayment = async(ctx, options) => {
const models = Self.app.models;
const args = ctx.args;
const date = Date.vnNew();
@ -91,11 +103,11 @@ module.exports = function(Self) {
try {
delete args.ctx; // Remove unwanted properties
const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions);
const bank = await models.Accounting.findById(args.bankFk, null, myOptions);
const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
// const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions);
// const bank = await models.Accounting.findById(args.bankFk, null, myOptions);
// const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
if (accountingType.code == 'compensation') {
/* if (accountingType.code == 'compensation') {
if (!args.compensationAccount)
throw new UserError('Compensation account is empty');
@ -161,10 +173,21 @@ module.exports = function(Self) {
myOptions
);
}
const newReceipt = await models.Receipt.create(args, myOptions);
*/
const newPayment = await models.Payment.create(args, myOptions);
// if (/* Supplier is client*/ false) {
// const newReceipt = await models.Receipt.create({
// invoiceFk: newPayment.id,
// amountPaid: args.amount,
// payed: args.received,
// bankFk: args.bankFk,
// companyFk: args.companyFk,
// clientFk: args.supplierFk,
// }, myOptions);
// }
if (tx) await tx.commit();
return newReceipt;
return newPayment;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

@ -8,7 +8,7 @@ module.exports = Self => {
require('../methods/supplier/updateFiscalData')(Self);
require('../methods/supplier/consumption')(Self);
require('../methods/supplier/freeAgencies')(Self);
require('../methods/supplier/createReceipt')(Self);
require('../methods/supplier/createPayment')(Self);
require('../methods/supplier/receipts')(Self);
require('../methods/supplier/campaignMetricsPdf')(Self);
require('../methods/supplier/campaignMetricsEmail')(Self);