#7134 SupplierBalance #3173
|
@ -1,17 +1,12 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
// const UserError = require('vn-loopback/util/user-error');
|
||||||
// Insert payment
|
// Insert payment
|
||||||
|
|
||||||
// divisa = solo en caso que la moneda sea distinta a €,
|
// divisa = solo en caso que la moneda sea distinta a €,
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
Self.remoteMethodCtx('createReceipt', {
|
Self.remoteMethodCtx('createPayment', {
|
||||||
description: 'Creates receipt and its compensation if necessary',
|
description: 'Creates receipt and its compensation if necessary',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [{
|
accepts: [
|
||||||
arg: 'supplierFk',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The supplier id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
arg: 'received',
|
arg: 'received',
|
||||||
type: 'Date',
|
type: 'Date',
|
||||||
|
@ -23,7 +18,13 @@ module.exports = function(Self) {
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'companyFk',
|
arg: 'supplierFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The supplier id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'amount',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
@ -31,6 +32,10 @@ module.exports = function(Self) {
|
||||||
arg: 'currencyFk',
|
arg: 'currencyFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
|
}, {
|
||||||
|
arg: 'divisa',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'bankFk',
|
arg: 'bankFk',
|
||||||
|
@ -43,35 +48,42 @@ module.exports = function(Self) {
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'amount',
|
arg: 'bankingFees',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
arg: 'concept',
|
arg: 'concept',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
|
}, {
|
||||||
|
arg: 'companyFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
arg: 'divisa',
|
arg: 'isConciliated',
|
||||||
type: 'number'
|
type: 'boolean'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'compensationAccount',
|
arg: 'compensationAccount',
|
||||||
type: 'any'
|
type: 'any'
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
returns: {
|
returns: {
|
||||||
root: true,
|
root: true,
|
||||||
type: 'Object'
|
type: 'Object'
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
verb: 'post',
|
verb: 'post',
|
||||||
path: '/:supplierFk/createReceipt'
|
path: '/:supplierFk/createPayment'
|
||||||
},
|
},
|
||||||
accessScopes: ['DEFAULT', 'read:multimedia']
|
accessScopes: ['DEFAULT', 'read:multimedia']
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.createReceipt = async(ctx, options) => {
|
Self.createPayment = async(ctx, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const date = Date.vnNew();
|
const date = Date.vnNew();
|
||||||
|
@ -91,11 +103,11 @@ module.exports = function(Self) {
|
||||||
try {
|
try {
|
||||||
delete args.ctx; // Remove unwanted properties
|
delete args.ctx; // Remove unwanted properties
|
||||||
|
|
||||||
const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions);
|
// const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions);
|
||||||
const bank = await models.Accounting.findById(args.bankFk, null, myOptions);
|
// const bank = await models.Accounting.findById(args.bankFk, null, myOptions);
|
||||||
const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
|
// const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
|
||||||
|
|
||||||
if (accountingType.code == 'compensation') {
|
/* if (accountingType.code == 'compensation') {
|
||||||
if (!args.compensationAccount)
|
if (!args.compensationAccount)
|
||||||
throw new UserError('Compensation account is empty');
|
throw new UserError('Compensation account is empty');
|
||||||
|
|
||||||
|
@ -161,10 +173,21 @@ module.exports = function(Self) {
|
||||||
myOptions
|
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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return newReceipt;
|
return newPayment;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
||||||
require('../methods/supplier/updateFiscalData')(Self);
|
require('../methods/supplier/updateFiscalData')(Self);
|
||||||
require('../methods/supplier/consumption')(Self);
|
require('../methods/supplier/consumption')(Self);
|
||||||
require('../methods/supplier/freeAgencies')(Self);
|
require('../methods/supplier/freeAgencies')(Self);
|
||||||
require('../methods/supplier/createReceipt')(Self);
|
require('../methods/supplier/createPayment')(Self);
|
||||||
require('../methods/supplier/receipts')(Self);
|
require('../methods/supplier/receipts')(Self);
|
||||||
require('../methods/supplier/campaignMetricsPdf')(Self);
|
require('../methods/supplier/campaignMetricsPdf')(Self);
|
||||||
require('../methods/supplier/campaignMetricsEmail')(Self);
|
require('../methods/supplier/campaignMetricsEmail')(Self);
|
||||||
|
|
Loading…
Reference in New Issue