3604-route_agencyTerm #893

Merged
carlosjr merged 20 commits from 3604-route_agencyTerm into dev 2022-03-15 14:18:27 +00:00
3 changed files with 57 additions and 57 deletions
Showing only changes of commit d22be6620c - Show all commits

View File

@ -24,29 +24,37 @@ module.exports = Self => {
Self.createInvoiceIn = async(rows, dms, options) => {
const models = Self.app.models;
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const [firstRow] = rows;
const [firstDms] = dms;
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
const [reference] = await Self.rawSql(`SELECT reference FROM vn.dms WHERE id = ?`, [firstDms.id]);
try {
const [firstRow] = rows;
const [firstDms] = dms;
const newInvoiceIn = await models.InvoiceIn.create({
supplierFk: firstRow.supplierFk,
supplierRef: reference.value,
issued: firstRow.created,
booked: firstRow.created,
operated: firstRow.created,
bookEntried: firstRow.created,
gestdoc_id: firstDms.id
});
const [reference] = await Self.rawSql(`SELECT reference FROM vn.dms WHERE id = ?`, [firstDms.id], myOptions);
const [expence] = await Self.rawSql(`SELECT expenceFk value FROM vn.agencyTermConfig`);
const newInvoiceIn = await models.InvoiceIn.create({
supplierFk: firstRow.supplierFk,
supplierRef: reference.value,
issued: firstRow.created,
booked: firstRow.created,
operated: firstRow.created,
bookEntried: firstRow.created,
gestdoc_id: firstDms.id
}, myOptions);
const [taxTypeSage] = await Self.rawSql(`
const [expence] = await Self.rawSql(`SELECT expenceFk value FROM vn.agencyTermConfig`, null, myOptions);
const [taxTypeSage] = await Self.rawSql(`
SELECT IFNULL(s.taxTypeSageFk, CodigoIva) value
FROM vn.supplier s
JOIN sage.TiposIva ti ON TRUE
@ -54,32 +62,38 @@ module.exports = Self => {
WHERE s.id = ?
AND ti.CuentaIvaSoportado = atg.vatAccountSupported
AND ti.PorcentajeIva = atg.vatPercentage
`, [firstRow.supplierFk]);
`, [firstRow.supplierFk], myOptions);
const [transactionTypeSage] = await Self.rawSql(`
const [transactionTypeSage] = await Self.rawSql(`
SELECT IFNULL(s.transactionTypeSageFk, tt.CodigoTransaccion) value
FROM vn.supplier s
JOIN sage.TiposTransacciones tt ON TRUE
JOIN vn.agencyTermConfig atg
WHERE s.id = ?
AND tt.Transaccion = atg.transaction
`, [firstRow.supplierFk]);
`, [firstRow.supplierFk], myOptions);
await models.InvoiceInTax.create({
invoiceInFk: newInvoiceIn.id,
taxableBase: firstRow.totalPrice,
expenseFk: expence.value,
taxTypeSageFk: taxTypeSage.value,
transactionTypeSageFk: transactionTypeSage.value
});
await models.InvoiceInTax.create({
invoiceInFk: newInvoiceIn.id,
taxableBase: firstRow.totalPrice,
expenseFk: expence.value,
taxTypeSageFk: taxTypeSage.value,
transactionTypeSageFk: transactionTypeSage.value
}, myOptions);
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id]);
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
vicent marked this conversation as resolved Outdated
for (let agencyTerm of rows) {
const route = await models.Route.findById(agencyTerm.routeFk);
await Self.rawSql(`
for (let agencyTerm of rows) {
const route = await models.Route.findById(agencyTerm.routeFk, null, myOptions);
await Self.rawSql(`
UPDATE vn.route SET invoiceInFk = ? WHERE id = ?
`, [newInvoiceIn.id, route.id]);
`, [newInvoiceIn.id, route.id], myOptions);
}
vicent marked this conversation as resolved
Review

Maybe you want the endpoint to return the created invoiceIn.

Maybe you want the endpoint to return the created invoiceIn.
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -11,23 +11,9 @@ describe('AgencyTerm createInvoiceIn()', () => {
];
const dms = [
{
id: 7,
file: '7.pdf',
contentType: 'application/pdf',
reference: '1',
description: 'Plants SL',
hasFile: false,
companyFk: 442,
dmsTypeFk: 1,
warehouseFk: 1,
workerFk: 9
id: 6
}
];
const userId = 1;
const activeCtx = {
accessToken: {userId: userId},
};
const ctx = {req: activeCtx};
it('should make a global invoicing', async() => {
vicent marked this conversation as resolved Outdated

an invoiceIn

an invoiceIn
const tx = await models.AgencyTerm.beginTransaction({});
@ -38,19 +24,19 @@ describe('AgencyTerm createInvoiceIn()', () => {
const invoiceInDueDayId = 11;
const invoiceInTaxId = 12;
const oldInvoiceIn = await models.AgencyTerm.findById(invoiceInId, null, options);
const oldInvoiceInDueDay = await models.AgencyTerm.findById(invoiceInDueDayId, null, options);
const oldInvoiceInTax = await models.AgencyTerm.findById(invoiceInTaxId, null, options);
const [newInvoiceIn] = await models.Ticket.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
// const [newInvoiceInDueDay] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
// const [newInvoiceInTax] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
const oldInvoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options);
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options);
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
vicent marked this conversation as resolved Outdated

:(

:(
// expect(newInvoiceIn.id).toEqual(oldInvoiceIn.id + 1);
// expect(newInvoiceInDueDay.id).toEqual(oldInvoiceInDueDay.id + 1);
// expect(newInvoiceInTax.id).toEqual(oldInvoiceInTax.id + 1);
const [newInvoiceIn] = await models.InvoiceIn.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
const [newInvoiceInDueDay] = await models.InvoiceInDueDay.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
const [newInvoiceInTax] = await models.InvoiceInTax.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
vicent marked this conversation as resolved Outdated

conso was left alone

conso was left alone
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);
await tx.rollback();
} catch (e) {

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models;
xdescribe('AgencyTerm filter()', () => {
describe('AgencyTerm filter()', () => {
const authUserId = 9;
it('should all return the tickets matching the filter', async() => {
vicent marked this conversation as resolved Outdated

should return all the tickets...

should return all the tickets...
@ -9,9 +9,9 @@ xdescribe('AgencyTerm filter()', () => {
try {
const options = {transaction: tx};
const filter = {};
const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}};
const ctx = {req: {accessToken: {userId: authUserId}}};
const agencyTerms = await models.AgencyTerm.filter(ctx, null, options);
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
const firstAgencyTerm = agencyTerms[0];
expect(firstAgencyTerm.routeFk).toEqual(1);