xdiario
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
87adbbfa3c
commit
3a6d62ac7d
|
@ -1,3 +0,0 @@
|
||||||
ALTER TABLE `vn`.`accountingType`
|
|
||||||
ADD COLUMN `code` VARCHAR(20) NULL DEFAULT NULL AFTER `receiptDescription`;
|
|
||||||
|
|
|
@ -148,12 +148,6 @@ INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `park
|
||||||
('GVC', '1', '0', '1', '0', '106'),
|
('GVC', '1', '0', '1', '0', '106'),
|
||||||
('HEJ', '2', '0', '1', '0', '106');
|
('HEJ', '2', '0', '1', '0', '106');
|
||||||
|
|
||||||
INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`)
|
|
||||||
VALUES
|
|
||||||
(1, 'Pay on receipt', '0000000000', 3, 0, 1, 1),
|
|
||||||
(2, 'Cash', '1111111111', 2, 0, 1, 1),
|
|
||||||
(3, 'Compensation', '0000000000', 7, 0, 1, 1);
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`)
|
INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'CC y Polizas de crédito', NULL, NULL),
|
(1, 'CC y Polizas de crédito', NULL, NULL),
|
||||||
|
@ -167,6 +161,12 @@ INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`cod
|
||||||
(9, 'Cash', 'Cash', 'cash'),
|
(9, 'Cash', 'Cash', 'cash'),
|
||||||
(10, 'Card', 'Pay on receipt', NULL);
|
(10, 'Card', 'Pay on receipt', NULL);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 'Pay on receipt', '0000000000', 3, 0, 1, 1),
|
||||||
|
(2, 'Cash', '1111111111', 2, 0, 1, 1),
|
||||||
|
(3, 'Compensation', '0000000000', 7, 0, 1, 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
|
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'AGENCY', 'Agencia'),
|
(1, 'AGENCY', 'Agencia'),
|
||||||
|
|
|
@ -77,18 +77,65 @@ module.exports = function(Self) {
|
||||||
if (!supplierCompensation && !clientCompensation)
|
if (!supplierCompensation && !clientCompensation)
|
||||||
throw new UserError('Invalid account');
|
throw new UserError('Invalid account');
|
||||||
|
|
||||||
|
const accountingType = await models.AccountingType.findOne({
|
||||||
|
where: {
|
||||||
|
code: 'compensation'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await Self.rawSql(
|
await Self.rawSql(
|
||||||
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
|
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
|
||||||
[
|
[
|
||||||
Date(),
|
Date(),
|
||||||
args.compensationAccount,
|
args.compensationAccount,
|
||||||
args.bankFk,
|
args.bankFk,
|
||||||
'compensar(tabla) ' + args.compensationAccount,
|
accountingType.receiptDescription + args.compensationAccount,
|
||||||
args.amountPaid,
|
args.amountPaid,
|
||||||
args.companyFk,
|
args.companyFk,
|
||||||
clientOriginal.accountingAccount
|
clientOriginal.accountingAccount
|
||||||
],
|
],
|
||||||
options);
|
options);
|
||||||
|
} else {
|
||||||
|
const bank = await models.Bank.findById(args.bankFk);
|
||||||
|
const ledger = await Self.rawSql(
|
||||||
|
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
Date(),
|
||||||
|
bank.account,
|
||||||
|
clientOriginal.accountingAccount,
|
||||||
|
clientOriginal.id + ':' + clientOriginal.nickname, '-', accountingType.receiptDescription,
|
||||||
|
args.amountPaid,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
args.companyFk
|
||||||
|
],
|
||||||
|
options);
|
||||||
|
|
||||||
|
await Self.rawSql(
|
||||||
|
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
||||||
|
[
|
||||||
|
ledger,
|
||||||
|
Date(),
|
||||||
|
clientOriginal.accountingAccount,
|
||||||
|
bank.account,
|
||||||
|
clientOriginal.id + ':' + clientOriginal.nickname, '-', accountingType.receiptDescription,
|
||||||
|
0,
|
||||||
|
args.amountPaid,
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
args.companyFk
|
||||||
|
],
|
||||||
|
options);
|
||||||
}
|
}
|
||||||
|
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
fdescribe('Receipt createReceipt', () => {
|
||||||
|
const clientFk = 108;
|
||||||
|
const payed = Date();
|
||||||
|
const companyFk = 442;
|
||||||
|
const amountPaid = 12.50;
|
||||||
|
const description = 'Receipt description';
|
||||||
|
|
||||||
|
it('should create a new receipt', async() => {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
clientFk: clientFk,
|
||||||
|
payed: payed,
|
||||||
|
companyFk: companyFk,
|
||||||
|
bankFk: 1,
|
||||||
|
amountPaid: amountPaid,
|
||||||
|
description: description
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const receipt = await app.models.Receipt.createReceipt(ctx);
|
||||||
|
console.log(receipt);
|
||||||
|
console.log(ctx.args);
|
||||||
|
|
||||||
|
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
|
||||||
|
// restores
|
||||||
|
await receipt.destroy();
|
||||||
|
// destroy till
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
clientFk: clientFk,
|
||||||
|
payed: payed,
|
||||||
|
companyFk: companyFk,
|
||||||
|
bankFk: 3,
|
||||||
|
amountPaid: amountPaid,
|
||||||
|
description: description,
|
||||||
|
compensationAccount: 'non existing account'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await app.models.Receipt.createReceipt(ctx);
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(err).toBeDefined();
|
||||||
|
expect(err.message).toEqual('Invalid account');
|
||||||
|
// validar que no ha creado el receipt porque el rollback ha funcionado
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new receipt with a compensation for a client', async() => {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
clientFk: clientFk,
|
||||||
|
payed: payed,
|
||||||
|
companyFk: companyFk,
|
||||||
|
bankFk: 3,
|
||||||
|
amountPaid: amountPaid,
|
||||||
|
description: description,
|
||||||
|
compensationAccount: '4300000001'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const receipt = await app.models.Receipt.createReceipt(ctx);
|
||||||
|
const receiptCompensated = await app.models.Receipt.findOne({
|
||||||
|
where: {
|
||||||
|
clientFk: ctx.args.clientFk,
|
||||||
|
payed: ctx.args.payed,
|
||||||
|
amountPaid: ctx.args.amountPaid,
|
||||||
|
bankFk: ctx.args.bankFk
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
expect(receiptCompensated.amountPaid).toEqual(-receiptCompensated.amountPaid);
|
||||||
|
// jasmine.objectContaining vs expect.objectContaining
|
||||||
|
|
||||||
|
// restores
|
||||||
|
await receipt.destroy();
|
||||||
|
await receiptCompensated.destroy();
|
||||||
|
// destroy till
|
||||||
|
// destroy XDiario
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new receipt with a compensation for a supplier', async() => {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
payed: payed,
|
||||||
|
companyFk: companyFk,
|
||||||
|
bankFk: 3,
|
||||||
|
amountPaid: amountPaid,
|
||||||
|
description: description,
|
||||||
|
compensationAccount: '4100000001'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const receipt = await app.models.Receipt.createReceipt(ctx);
|
||||||
|
/* esperar a que payment este en vn
|
||||||
|
const receiptCompensated = await app.models.Payment.findOne({
|
||||||
|
where: {
|
||||||
|
clientFk: ctx.args.sale,
|
||||||
|
payed: ctx.args.payed,
|
||||||
|
amountPaid: ctx.args.amountPaid,
|
||||||
|
bankFk: ctx.args.bankFk
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
|
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
// expect(receiptCompensated.amountPaid).toEqual(receiptCompensated.amountPaid);
|
||||||
|
// jasmine.objectContaining vs expect.objectContaining
|
||||||
|
|
||||||
|
// restores
|
||||||
|
await receipt.destroy();
|
||||||
|
// destroy payment
|
||||||
|
// destroy till
|
||||||
|
// destroy XDiario
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue