#7134 SupplierBalance #3173
|
@ -1,6 +0,0 @@
|
|||
|
||||
module.exports = Self => {
|
||||
require('./tillIn')(Self);
|
||||
require('./tillOut')(Self);
|
||||
require('./tiller')(Self);
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.tillIn = async(ctx, options) => {
|
||||
const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`;
|
||||
const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions);
|
||||
if (pagareId) return pagareId;
|
||||
throw new UserError('Till In');
|
||||
};
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.tillOut = async(ctx, options) => {
|
||||
const query = `INSERT INTO vn.promissoryNote ( id, dated, serie, concept, in, out, bankFk, companyFk, isAccountable, InForeignValue, OutForeignValue, workerFk, calculatedCode, number, isLinked, created, isOk, warehouseFk, isConciliate, supplierAccountFk) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )`;
|
||||
const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions);
|
||||
if (pagareId) return pagareId;
|
||||
throw new UserError('Till Out');
|
||||
};
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.tiller = async(ctx, options) => {
|
||||
throw new UserError('Till In');
|
||||
};
|
||||
};
|
|
@ -1,297 +0,0 @@
|
|||
// const UserError = require('vn-loopback/util/user-error');
|
||||
// Insert payment
|
||||
|
||||
// divisa = solo en caso que la moneda sea distinta a €,
|
||||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('createPayment', {
|
||||
description: 'Creates receipt and its compensation if necessary',
|
||||
accessType: 'READ',
|
||||
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: 'any',
|
||||
},
|
||||
{
|
||||
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/createPayment'
|
||||
},
|
||||
accessScopes: ['DEFAULT', 'read:multimedia']
|
||||
});
|
||||
|
||||
Self.createPayment = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
let tx;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* if (accountingType.code == 'compensation') {
|
||||
if (!args.compensationAccount)
|
||||
throw new UserError('Compensation account is empty');
|
||||
|
||||
// Check compensation account exists
|
||||
await models.Supplier.getClientOrSupplierReference(args.compensationAccount, myOptions);
|
||||
|
||||
await Self.rawSql(
|
||||
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
date,
|
||||
args.compensationAccount,
|
||||
args.bankFk,
|
||||
accountingType.receiptDescription + originalSupplier.accountingAccount,
|
||||
args.amountPaid,
|
||||
args.companyFk,
|
||||
originalSupplier.accountingAccount
|
||||
],
|
||||
myOptions
|
||||
);
|
||||
} else if (accountingType.isAutoConciliated == true) {
|
||||
const description =
|
||||
`${originalSupplier.id} : ${originalSupplier.socialName} - ${accountingType.receiptDescription}`;
|
||||
const [, [xdiarioNew]] = await Self.rawSql(
|
||||
`CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);
|
||||
SELECT @xdiarioNew ledger;`,
|
||||
[
|
||||
null,
|
||||
date,
|
||||
bank.account,
|
||||
originalSupplier.accountingAccount,
|
||||
description,
|
||||
args.amountPaid,
|
||||
0,
|
||||
0,
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
args.companyFk
|
||||
],
|
||||
myOptions
|
||||
);
|
||||
|
||||
await Self.rawSql(
|
||||
`CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);`,
|
||||
[
|
||||
xdiarioNew.ledger,
|
||||
date,
|
||||
originalSupplier.accountingAccount,
|
||||
bank.account,
|
||||
description,
|
||||
0,
|
||||
args.amountPaid,
|
||||
0,
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
args.companyFk
|
||||
],
|
||||
myOptions
|
||||
);
|
||||
}
|
||||
*/
|
||||
const bodyPayment = {
|
||||
...args,
|
||||
dueDate: args.received,
|
||||
};
|
||||
const newPayment = await models.Payment.create(bodyPayment, 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);
|
||||
// }
|
||||
// const supplier = await Self.app.models.Supplier.findById(args.supplierFk, {fields: ['nif'], include: {
|
||||
// relation: 'client'
|
||||
// }}, myOptions);
|
||||
// const client = await Self.app.models.Client.findOne({where: {nif: supplier.fi}}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
switch (bodyPayment.payMethodFk) {
|
||||
case 1:
|
||||
case 10:
|
||||
case 20:
|
||||
await models.Till.tillIn(args, myOptions);
|
||||
throw new UserError('Metálico');
|
||||
// Call Salidadecaja(
|
||||
// strCONCEPTO & " : " & DFirst("[Proveedor]", "Proveedores",
|
||||
// " [Id_Proveedor] = " & vSupplierFk),
|
||||
// "R",
|
||||
// _ "0",
|
||||
// _ Replace(str(Me.n_pago), ",", "."), _
|
||||
// Me.n_fecha, _
|
||||
// DFirst("[oficial]", "Proveedores", "[Id_Proveedor] =" & vSupplierFk),
|
||||
// _ Me.n_caja, Me.empresa)
|
||||
|
||||
// Call sql(msql("UPDATE pago SET conciliado = TRUE WHERE id = %", pagoId), False, True)
|
||||
// Public Function Salidadecaja(strCONCEPTE As String, strSERIE As String, strREF As String, strSALIDA As String, _
|
||||
// datfecha As Date, strCOLOR As String, strCAJA As String, intEmp As Integer)
|
||||
|
||||
// Select Case Trim(strCAJA)
|
||||
|
||||
// Case "11", "12", "13"
|
||||
|
||||
// Call abrecajon
|
||||
|
||||
// End Select
|
||||
|
||||
// Call sql(msql("INSERT INTO Cajas ( Concepto, Serie, Numero, Salida, Cajafecha, Partida, Id_Banco, Id_Trabajador,empresa_id ) " & _
|
||||
// "SELECT %,%,%,%,%,%,%,%,%", strCONCEPTE, strSERIE, Nz(strREF, 0), strSALIDA, datfecha, strCOLOR, strCAJA, workerId, intEmp), _
|
||||
// False, True)
|
||||
|
||||
// End Function
|
||||
// break;
|
||||
case 2:
|
||||
// Call emitir_pagare(pagoId, strCONCEPTO)
|
||||
await emitPagare(args.concept, newPayment.id);
|
||||
|
||||
// Public Function emitir_pagare(pagoId As Long, strCONCEPTO As String)
|
||||
// Call sql(msql("INSERT INTO Pagares(pago_id,Concepto) " & _
|
||||
// "VALUES (%,%)", pagoId, strCONCEPTO), False, True)
|
||||
|
||||
// Call sql("SELECT LAST_INSERT_ID() as id", True, False)
|
||||
|
||||
// Call sql("SELECT Pagares.Id_Pagare, Pagares.Concepto, Proveedores.Proveedor, Proveedores.Domicilio,empresa.logo, " & _
|
||||
// "Proveedores.codpos, Proveedores.Localidad, [importe] AS texto, Pagares.Fechaemision, pago.importe,pago.fecha, " & _
|
||||
// "pago.empresa_id, Proveedores.postcode_id AS CP FROM ((Proveedores INNER JOIN pago ON Proveedores.Id_Proveedor = pago.id_proveedor) " & _
|
||||
// "INNER JOIN Pagares ON pago.id = Pagares.pago_id) INNER JOIN empresa ON pago.empresa_id = empresa.id " & _
|
||||
// "WHERE Pagares.Id_Pagare = " & DFirst("[id]", "cstSQL"), True, False, "pagareultimo")
|
||||
// DoCmd.openReport "Pagare", acViewPreview
|
||||
// End Function
|
||||
// break;
|
||||
case 3:
|
||||
throw new UserError('Compensación');
|
||||
// Dim vOriginalAccount As String
|
||||
// vOriginalAccount = db.getValueV("SELECT account FROM vn.supplier WHERE id = #", vSupplierFk)
|
||||
// 'Call compensar(Me.n_caja, Me.n_fecha, strCONCEPTO, Me.empresa, Me.n_pago, vOriginalAccount, pagoId)
|
||||
// db.execV "CALL vn.ledger_doCompensation(#, #, #, #, #, #, #)", Me.n_fecha, vCompensationAccount, Me.n_caja, strCONCEPTO, Me.n_pago, Me.empresa, vOriginalAccount
|
||||
// db.execV "UPDATE pago SET conciliado = TRUE, concepte = CONCAT(concepte, ' ', #) WHERE id = #", vCompensationAccount, pagoId
|
||||
// break;
|
||||
case 8:
|
||||
throw new UserError('SEPA-CORE/B2B');
|
||||
|
||||
// If db.getValueFromDefV("paymentHasIban", vSupplierFk) = 0 Then
|
||||
// MsgBox "Rellene los campos iban y entidad.", vbCritical
|
||||
// Exit Sub
|
||||
// End If
|
||||
// Dim isUeeMember As Boolean
|
||||
// isUeeMember = db.getValueV("SELECT c.isUeeMember FROM vn.supplier s JOIN vn.country c ON c.id = s.countryFk WHERE s.id = #", vSupplierFk)
|
||||
|
||||
// Call GenerarPagoSEPA( _
|
||||
// Me.n_fecha, _
|
||||
// Me.empresa, _
|
||||
// Replace(Format(IIf(Me.n_moneda.column(1) = "EUR", Me.n_pago, Me.n_cambio), "0.00"), ",", "."), _
|
||||
// Me.n_caja, _
|
||||
// isUeeMember, _
|
||||
// "TRANSFER_" & DFirst("alias", "Proveedores", "[Id_Proveedor] =" & vSupplierFk), _
|
||||
// 1, _
|
||||
// Me.n_moneda.column(1), _
|
||||
// vSupplierFk)
|
||||
// MsgBox "Fichero Generado CORRECTAMENTE", vbInformation
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return newPayment;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
async function emitPagare(concept, paymentFk) {
|
||||
const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`;
|
||||
const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions);
|
||||
if (pagareId) return pagareId;
|
||||
throw new UserError('Pagaré');
|
||||
}
|
Loading…
Reference in New Issue