From e8ce8e42fd1d07274343789f215834146d6c03c5 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 25 Apr 2023 14:25:22 +0200 Subject: [PATCH 01/13] refs #5153 --- db/changes/231601/00-clientWorkerName.sql | 73 +++++++++++++++++++ db/changes/231601/00-createWorker.sql | 9 +++ db/dump/fixtures.sql | 4 +- modules/client/back/methods/client/summary.js | 7 +- modules/client/front/summary/index.html | 3 + modules/client/front/summary/locale/es.yml | 1 + modules/worker/back/methods/worker/new.js | 6 +- modules/worker/back/models/worker-config.json | 3 + 8 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 db/changes/231601/00-clientWorkerName.sql create mode 100644 db/changes/231601/00-createWorker.sql diff --git a/db/changes/231601/00-clientWorkerName.sql b/db/changes/231601/00-clientWorkerName.sql new file mode 100644 index 000000000..676d26691 --- /dev/null +++ b/db/changes/231601/00-clientWorkerName.sql @@ -0,0 +1,73 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientCreate`( + vFirstname VARCHAR(50), + vSurnames VARCHAR(50), + vFi VARCHAR(9), + vAddress TEXT, + vPostcode CHAR(5), + vCity VARCHAR(25), + vProvinceFk SMALLINT(5), + vCompanyFk SMALLINT(5), + vPhone VARCHAR(11), + vEmail VARCHAR(255), + vUserFk INT) +BEGIN +/** + * Create new client + * + */ + DECLARE vPayMethodFk INT DEFAULT 4; + DECLARE vDueDay INT DEFAULT 5; + DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; + DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; + DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE; + DECLARE vMandateTypeFk INT DEFAULT 2; + + INSERT INTO `client` ( + id, + name, + street, + fi, + phone, + email, + provinceFk, + city, + postcode, + socialName, + payMethodFk, + dueDay, + credit, + isTaxDataChecked, + hasCoreVnl, + isEqualizated) + VALUES ( + vUserFk, + CONCAT(vFirstname, ' ', vSurnames), + vAddress, + TRIM(vFi), + vPhone, + vEmail, + vProvinceFk, + vCity, + vPostcode, + CONCAT(vSurnames, ' ', vFirstname), + vPayMethodFk, + vDueDay, + vDefaultCredit, + vIsTaxDataChecked, + vHasCoreVnl, + FALSE + ) ON duplicate key update + payMethodFk = vPayMethodFk, + dueDay = vDueDay, + credit = vDefaultCredit, + isTaxDataChecked = vIsTaxDataChecked, + hasCoreVnl = vHasCoreVnl, + isActive = TRUE; + + IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN + INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) + VALUES (vUserFk, vCompanyFk, vMandateTypeFk); + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/changes/231601/00-createWorker.sql b/db/changes/231601/00-createWorker.sql new file mode 100644 index 000000000..7a128415c --- /dev/null +++ b/db/changes/231601/00-createWorker.sql @@ -0,0 +1,9 @@ +INSERT INTO vn.businessType (code,description) + VALUES ('worker','Trabajador'); + +ALTER TABLE `vn`.`workerConfig` ADD businessTypeFk varchar(100) NULL + COMMENT 'Tipo de negocio por defecto al dar de alta un trabajador nuevo'; + +UPDATE `vn`.`workerConfig` + SET businessTypeFk = 'worker' + WHERE id = 1; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 4dc7dcafc..aae76afa7 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2800,9 +2800,9 @@ INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) VALUES (1, 1); -INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`) +INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `businessTypeFk`) VALUES - (1, NULL, 1); + (1, NULL, 1, 'worker'); INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES diff --git a/modules/client/back/methods/client/summary.js b/modules/client/back/methods/client/summary.js index caa3d8033..7dab1f68b 100644 --- a/modules/client/back/methods/client/summary.js +++ b/modules/client/back/methods/client/summary.js @@ -27,7 +27,6 @@ module.exports = Self => { Object.assign(myOptions, options); const summaryObj = await getSummary(models.Client, clientFk, myOptions); - summaryObj.mana = await models.Client.getMana(clientFk, myOptions); summaryObj.debt = await models.Client.getDebt(clientFk, myOptions); summaryObj.averageInvoiced = await models.Client.getAverageInvoiced(clientFk, myOptions); @@ -115,6 +114,12 @@ module.exports = Self => { fields: ['claimingRate', 'priceIncreasing'], limit: 1 } + }, + { + relation: 'businessType', + scope: { + fields: ['description'] + } } ], where: {id: clientId} diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index 1b58d42cc..a0d4b918a 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -64,6 +64,9 @@ + +

diff --git a/modules/client/front/summary/locale/es.yml b/modules/client/front/summary/locale/es.yml index ca6e96fef..c1fde0c17 100644 --- a/modules/client/front/summary/locale/es.yml +++ b/modules/client/front/summary/locale/es.yml @@ -23,3 +23,4 @@ Latest tickets: Últimos tickets Rating: Clasificación Value from 1 to 20. The higher the better value: Valor del 1 al 20. Cuanto más alto mejor valoración Go to grafana: Ir a grafana +Business type: Tipo de negocio \ No newline at end of file diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index 144b07f10..16c1a0011 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -1,4 +1,4 @@ -/* eslint max-len: ["error", { "code": 130 }]*/ +/* eslint max-len: ["error", { "code": 150 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { @@ -139,7 +139,7 @@ module.exports = Self => { if (!client) { const nickname = args.firstName.concat(' ', args.lastNames); - const workerConfig = await models.WorkerConfig.findOne({fields: ['roleFk']}); + const workerConfig = await models.WorkerConfig.findOne({fields: ['roleFk', 'businessTypeFk']}); const [randomPassword] = await models.Worker.rawSql( 'SELECT account.passwordGenerate() as password;' ); @@ -196,7 +196,7 @@ module.exports = Self => { client = await models.Client.findById( user.id, - {fields: ['id', 'name', 'socialName', 'street', 'city', 'iban', 'bankEntityFk', 'defaultAddressFk']}, + {fields: ['id', 'name', 'socialName', 'street', 'city', 'iban', 'bankEntityFk', 'defaultAddressFk', 'businessTypeFk']}, myOptions ); diff --git a/modules/worker/back/models/worker-config.json b/modules/worker/back/models/worker-config.json index 05cdfef42..bcee74067 100644 --- a/modules/worker/back/models/worker-config.json +++ b/modules/worker/back/models/worker-config.json @@ -14,6 +14,9 @@ }, "roleFk": { "type": "number" + }, + "businessTypeFk": { + "type": "string" } }, "acls": [ From 09dbd290862bfa32101bb0b0a06c0b7387dcc26f Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Apr 2023 14:46:16 +0200 Subject: [PATCH 02/13] =?UTF-8?q?refs=20#5594=20cuando=20se=20factura=20se?= =?UTF-8?q?=20env=C3=ADa=20autom=C3=A1ticamente=20un=20mail=20y=20quitados?= =?UTF-8?q?=20logs=20duplicados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/231601/00-invoiceOut_new.sql | 254 ++++++++++++++++++ .../ticket/back/methods/ticket/makeInvoice.js | 30 +-- 2 files changed, 269 insertions(+), 15 deletions(-) create mode 100644 db/changes/231601/00-invoiceOut_new.sql diff --git a/db/changes/231601/00-invoiceOut_new.sql b/db/changes/231601/00-invoiceOut_new.sql new file mode 100644 index 000000000..7406d4591 --- /dev/null +++ b/db/changes/231601/00-invoiceOut_new.sql @@ -0,0 +1,254 @@ +DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( + vSerial VARCHAR(255), + vInvoiceDate DATE, + vTaxArea VARCHAR(25), + OUT vNewInvoiceId INT) +BEGIN +/** + * Creación de facturas emitidas. + * requiere previamente tabla ticketToInvoice(id). + * + * @param vSerial serie a la cual se hace la factura + * @param vInvoiceDate fecha de la factura + * @param vTaxArea tipo de iva en relacion a la empresa y al cliente + * @param vNewInvoiceId id de la factura que se acaba de generar + * @return vNewInvoiceId + */ + DECLARE vIsAnySaleToInvoice BOOL; + DECLARE vIsAnyServiceToInvoice BOOL; + DECLARE vNewRef VARCHAR(255); + DECLARE vWorker INT DEFAULT account.myUser_getId(); + DECLARE vCompanyFk INT; + DECLARE vInterCompanyFk INT; + DECLARE vClientFk INT; + DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; + DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; + DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; + DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; + DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; + DECLARE vNewInvoiceInFk INT; + DECLARE vIsInterCompany BOOL DEFAULT FALSE; + DECLARE vIsCEESerial BOOL DEFAULT FALSE; + DECLARE vIsCorrectInvoiceDate BOOL; + DECLARE vMaxShipped DATE; + + SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); + + SELECT t.clientFk, + t.companyFk, + MAX(DATE(t.shipped)), + DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( + vSerial, + t.companyFk, + YEAR(vInvoiceDate)) + INTO vClientFk, + vCompanyFk, + vMaxShipped, + vIsCorrectInvoiceDate + FROM ticketToInvoice tt + JOIN ticket t ON t.id = tt.id; + + IF(vMaxShipped > vInvoiceDate) THEN + CALL util.throw("Invoice date can't be less than max date"); + END IF; + + IF NOT vIsCorrectInvoiceDate THEN + CALL util.throw('Exists an invoice with a previous date'); + END IF; + + -- Eliminem de ticketToInvoice els tickets que no han de ser facturats + DELETE ti.* + FROM ticketToInvoice ti + JOIN ticket t ON t.id = ti.id + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN supplier su ON su.id = t.companyFk + JOIN client c ON c.id = t.clientFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk + WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) + OR c.isTaxDataChecked = FALSE + OR t.isDeleted + OR c.hasToInvoice = FALSE + OR itc.id IS NULL; + + SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 + INTO vIsAnySaleToInvoice + FROM ticketToInvoice t + JOIN sale s ON s.ticketFk = t.id; + + SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice + FROM ticketToInvoice t + JOIN ticketService ts ON ts.ticketFk = t.id; + + IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) + AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) + THEN + + -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial + INSERT INTO invoiceOut( + ref, + serial, + issued, + clientFk, + dued, + companyFk, + cplusInvoiceType477Fk + ) + SELECT + 1, + vSerial, + vInvoiceDate, + vClientFk, + getDueDate(vInvoiceDate, dueDay), + vCompanyFk, + IF(vSerial = vCorrectingSerial, + vCplusCorrectingInvoiceTypeFk, + IF(vSerial = vSimplifiedSerial, + vCplusSimplifiedInvoiceTypeFk, + vCplusStandardInvoiceTypeFk)) + FROM client + WHERE id = vClientFk; + + SET vNewInvoiceId = LAST_INSERT_ID(); + + SELECT `ref` + INTO vNewRef + FROM invoiceOut + WHERE id = vNewInvoiceId; + + UPDATE ticket t + JOIN ticketToInvoice ti ON ti.id = t.id + SET t.refFk = vNewRef; + + DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; + CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY + SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + FROM ticketToInvoice ti + LEFT JOIN ticketState ts ON ti.id = ts.ticket + JOIN state s + WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); + + INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) + SELECT * FROM tmp.updateInter; + + CALL invoiceExpenceMake(vNewInvoiceId); + CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + + UPDATE invoiceOut io + JOIN ( + SELECT SUM(amount) total + FROM invoiceOutExpence + WHERE invoiceOutFk = vNewInvoiceId + ) base + JOIN ( + SELECT SUM(vat) total + FROM invoiceOutTax + WHERE invoiceOutFk = vNewInvoiceId + ) vat + SET io.amount = base.total + vat.total + WHERE io.id = vNewInvoiceId; + + DROP TEMPORARY TABLE tmp.updateInter; + + SELECT COUNT(*), id + INTO vIsInterCompany, vInterCompanyFk + FROM company + WHERE clientFk = vClientFk; + + IF (vIsInterCompany) THEN + + INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) + SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; + + SET vNewInvoiceInFk = LAST_INSERT_ID(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM ticketToInvoice; + + CALL `ticket_getTax`('NATIONAL'); + + SET @vTaxableBaseServices := 0.00; + SET @vTaxCodeGeneral := NULL; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInFk, + @vTaxableBaseServices, + sub.expenceFk, + sub.taxTypeSageFk, + sub.transactionTypeSageFk + FROM ( + SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, + i.expenceFk, + i.taxTypeSageFk, + i.transactionTypeSageFk, + @vTaxCodeGeneral := i.taxClassCodeFk + FROM tmp.ticketServiceTax tst + JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code + WHERE i.isService + HAVING taxableBase + ) sub; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInFk, + SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, + @vTaxableBaseServices, 0) taxableBase, + i.expenceFk, + i.taxTypeSageFk , + i.transactionTypeSageFk + FROM tmp.ticketTax tt + JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code + WHERE !i.isService + GROUP BY tt.pgcFk + HAVING taxableBase + ORDER BY tt.priority; + + CALL invoiceInDueDay_calculate(vNewInvoiceInFk); + + SELECT COUNT(*) INTO vIsCEESerial + FROM invoiceOutSerial + WHERE code = vSerial; + + IF vIsCEESerial THEN + + INSERT INTO invoiceInIntrastat ( + invoiceInFk, + intrastatFk, + amount, + stems, + countryFk, + net) + SELECT + vNewInvoiceInFk, + i.intrastatFk, + SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), + SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), + su.countryFk, + CAST(SUM(IFNULL(i.stems, 1) + * s.quantity + * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) + FROM sale s + JOIN ticket t ON s.ticketFk = t.id + JOIN supplier su ON su.id = t.companyFk + JOIN item i ON i.id = s.itemFk + LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk + WHERE t.refFk = vNewRef + GROUP BY i.intrastatFk; + + END IF; + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketAmount; + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticketServiceTax; + END IF; + END IF; + DROP TEMPORARY TABLE `ticketToInvoice`; +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 9739f5985..3228d15a8 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -89,21 +89,6 @@ module.exports = function(Self) { invoiceId = resultInvoice.id; - for (let ticket of tickets) { - const ticketInvoice = await models.Ticket.findById(ticket.id, { - fields: ['refFk'] - }, myOptions); - - await models.TicketLog.create({ - originFk: ticket.id, - userFk: userId, - action: 'insert', - changedModel: 'Ticket', - changedModelId: ticket.id, - newInstance: ticketInvoice - }, myOptions); - } - if (serial != 'R' && invoiceId) await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions); @@ -116,6 +101,21 @@ module.exports = function(Self) { if (serial != 'R' && invoiceId) await models.InvoiceOut.createPdf(ctx, invoiceId); + if (invoiceId) { + const invoiceOut = await models.InvoiceOut.findById(invoiceId, { + include: { + relation: 'client' + } + }); + + ctx.args = { + reference: invoiceOut.ref, + recipientId: invoiceOut.clientFk, + recipient: invoiceOut.client().email + }; + await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref); + } + return {invoiceFk: invoiceId, serial: serial}; }; }; From 8bb8b8cfba8ff6137414d8e559e5b16983f4d5b7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Apr 2023 14:55:37 +0200 Subject: [PATCH 03/13] refs #5594 fix backTest --- modules/ticket/back/methods/ticket/makeInvoice.js | 13 ++++++------- .../back/methods/ticket/specs/makeInvoice.spec.js | 7 ++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 3228d15a8..a3a684905 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -24,7 +24,6 @@ module.exports = function(Self) { }); Self.makeInvoice = async(ctx, ticketsIds, options) => { - const userId = ctx.req.accessToken.userId; const models = Self.app.models; const date = Date.vnNew(); date.setHours(0, 0, 0, 0); @@ -42,6 +41,7 @@ module.exports = function(Self) { let serial; let invoiceId; + let invoiceOut; try { const tickets = await models.Ticket.find({ where: { @@ -92,6 +92,11 @@ module.exports = function(Self) { if (serial != 'R' && invoiceId) await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions); + invoiceOut = await models.InvoiceOut.findById(invoiceId, { + include: { + relation: 'client' + } + }, myOptions); if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); @@ -102,12 +107,6 @@ module.exports = function(Self) { await models.InvoiceOut.createPdf(ctx, invoiceId); if (invoiceId) { - const invoiceOut = await models.InvoiceOut.findById(invoiceId, { - include: { - relation: 'client' - } - }); - ctx.args = { reference: invoiceOut.ref, recipientId: invoiceOut.clientFk, diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index 24d4a48ba..d83e7e5f2 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -1,11 +1,14 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -describe('ticket makeInvoice()', () => { +fdescribe('ticket makeInvoice()', () => { const userId = 19; const ticketId = 11; const clientId = 1102; const activeCtx = { + getLocale: () => { + return 'en'; + }, accessToken: {userId: userId}, headers: {origin: 'http://localhost:5000'}, }; @@ -67,6 +70,7 @@ describe('ticket makeInvoice()', () => { it('should invoice a ticket, then try again to fail', async() => { const invoiceOutModel = models.InvoiceOut; spyOn(invoiceOutModel, 'createPdf'); + spyOn(invoiceOutModel, 'invoiceEmail'); const tx = await models.Ticket.beginTransaction({}); @@ -90,6 +94,7 @@ describe('ticket makeInvoice()', () => { it('should success to invoice a ticket', async() => { const invoiceOutModel = models.InvoiceOut; spyOn(invoiceOutModel, 'createPdf'); + spyOn(invoiceOutModel, 'invoiceEmail'); const tx = await models.Ticket.beginTransaction({}); From 22b223038a0167686bd4956f34cc103ca73995b4 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Apr 2023 14:56:07 +0200 Subject: [PATCH 04/13] delete focus --- modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index d83e7e5f2..270ba5c93 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -fdescribe('ticket makeInvoice()', () => { +describe('ticket makeInvoice()', () => { const userId = 19; const ticketId = 11; const clientId = 1102; From 49233eefcd97ff0de16e1c811ffdd4515fe2a5a5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 4 May 2023 10:18:37 +0200 Subject: [PATCH 05/13] refs #5580 add button, yml --- print/templates/email/weekly-hour-record/locale/en.yml | 5 +++-- print/templates/email/weekly-hour-record/locale/es.yml | 5 +++-- .../email/weekly-hour-record/weekly-hour-record.html | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/print/templates/email/weekly-hour-record/locale/en.yml b/print/templates/email/weekly-hour-record/locale/en.yml index 817e5451e..b76372fb9 100644 --- a/print/templates/email/weekly-hour-record/locale/en.yml +++ b/print/templates/email/weekly-hour-record/locale/en.yml @@ -1,6 +1,7 @@ subject: Weekly time log title: Record of hours week {0} year {1} dear: Dear worker -description: Access the following link:

- {0}

+Acceda al siguiente enlace: Access the following link:
+description: Click 'SATISFIED' if you agree with the hours worked. Otherwise, press 'NOT SATISFIED', detailing the cause of the disagreement. +Hours: Hours \ No newline at end of file diff --git a/print/templates/email/weekly-hour-record/locale/es.yml b/print/templates/email/weekly-hour-record/locale/es.yml index b70862f16..95466addb 100644 --- a/print/templates/email/weekly-hour-record/locale/es.yml +++ b/print/templates/email/weekly-hour-record/locale/es.yml @@ -1,6 +1,7 @@ subject: Registro de horas semanal title: Registro de horas semana {0} año {1} dear: Estimado trabajador -description: Acceda al siguiente enlace:

- {0}

+toaccess: Acceda al siguiente enlace:
+description: Pulse 'CONFORME' si esta de acuerdo con las horas trabajadas. En caso contrario pulse 'NO CONFORME', detallando la causa de la disconformidad. +Hours: Horas \ No newline at end of file diff --git a/print/templates/email/weekly-hour-record/weekly-hour-record.html b/print/templates/email/weekly-hour-record/weekly-hour-record.html index 84abb4c61..b1eb4e0b3 100644 --- a/print/templates/email/weekly-hour-record/weekly-hour-record.html +++ b/print/templates/email/weekly-hour-record/weekly-hour-record.html @@ -3,7 +3,9 @@

{{ $t('title', [week, year]) }}

{{$t('dear')}},

-

+

+ +

{{$t('description')}}

From e019ab4160d68181661baf259ccbade0cea9f4f1 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 8 May 2023 12:40:52 +0200 Subject: [PATCH 06/13] deploy(232001): add changes folder, package and changelog --- CHANGELOG.md | 15 ++++++++++++++- db/changes/232001/.gitkeep | 0 package.json | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/changes/232001/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index fa318a908..5ff575175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2318.01] - 2023-05-04 +## [2320.01] - 2023-05-25 + +### Added +- + +### Changed +- + +### Fixed +- + + + +## [2318.01] - 2023-05-08 ### Added - (Usuarios -> Histórico) Nueva sección diff --git a/db/changes/232001/.gitkeep b/db/changes/232001/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package.json b/package.json index fee164f44..4b4f552ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.18.01", + "version": "23.20.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 313c641cd78ae54c2ac94368e542759d5d2ab033 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 9 May 2023 12:26:29 +0200 Subject: [PATCH 07/13] move chages sql --- db/changes/232001/00-invoiceOut_new.sql | 254 ++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 db/changes/232001/00-invoiceOut_new.sql diff --git a/db/changes/232001/00-invoiceOut_new.sql b/db/changes/232001/00-invoiceOut_new.sql new file mode 100644 index 000000000..b4fc5c824 --- /dev/null +++ b/db/changes/232001/00-invoiceOut_new.sql @@ -0,0 +1,254 @@ +DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( + vSerial VARCHAR(255), + vInvoiceDate DATE, + vTaxArea VARCHAR(25), + OUT vNewInvoiceId INT) +BEGIN +/** + * Creación de facturas emitidas. + * requiere previamente tabla tmp.ticketToInvoice(id). + * + * @param vSerial serie a la cual se hace la factura + * @param vInvoiceDate fecha de la factura + * @param vTaxArea tipo de iva en relacion a la empresa y al cliente + * @param vNewInvoiceId id de la factura que se acaba de generar + * @return vNewInvoiceId + */ + DECLARE vIsAnySaleToInvoice BOOL; + DECLARE vIsAnyServiceToInvoice BOOL; + DECLARE vNewRef VARCHAR(255); + DECLARE vWorker INT DEFAULT account.myUser_getId(); + DECLARE vCompanyFk INT; + DECLARE vInterCompanyFk INT; + DECLARE vClientFk INT; + DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; + DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; + DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; + DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; + DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; + DECLARE vNewInvoiceInFk INT; + DECLARE vIsInterCompany BOOL DEFAULT FALSE; + DECLARE vIsCEESerial BOOL DEFAULT FALSE; + DECLARE vIsCorrectInvoiceDate BOOL; + DECLARE vMaxShipped DATE; + + SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); + + SELECT t.clientFk, + t.companyFk, + MAX(DATE(t.shipped)), + DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( + vSerial, + t.companyFk, + YEAR(vInvoiceDate)) + INTO vClientFk, + vCompanyFk, + vMaxShipped, + vIsCorrectInvoiceDate + FROM tmp.ticketToInvoice tt + JOIN ticket t ON t.id = tt.id; + + IF(vMaxShipped > vInvoiceDate) THEN + CALL util.throw("Invoice date can't be less than max date"); + END IF; + + IF NOT vIsCorrectInvoiceDate THEN + CALL util.throw('Exists an invoice with a previous date'); + END IF; + + -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats + DELETE ti.* + FROM tmp.ticketToInvoice ti + JOIN ticket t ON t.id = ti.id + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN supplier su ON su.id = t.companyFk + JOIN client c ON c.id = t.clientFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk + WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) + OR c.isTaxDataChecked = FALSE + OR t.isDeleted + OR c.hasToInvoice = FALSE + OR itc.id IS NULL; + + SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 + INTO vIsAnySaleToInvoice + FROM tmp.ticketToInvoice t + JOIN sale s ON s.ticketFk = t.id; + + SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice + FROM tmp.ticketToInvoice t + JOIN ticketService ts ON ts.ticketFk = t.id; + + IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) + AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) + THEN + + -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial + INSERT INTO invoiceOut( + ref, + serial, + issued, + clientFk, + dued, + companyFk, + cplusInvoiceType477Fk + ) + SELECT + 1, + vSerial, + vInvoiceDate, + vClientFk, + getDueDate(vInvoiceDate, dueDay), + vCompanyFk, + IF(vSerial = vCorrectingSerial, + vCplusCorrectingInvoiceTypeFk, + IF(vSerial = vSimplifiedSerial, + vCplusSimplifiedInvoiceTypeFk, + vCplusStandardInvoiceTypeFk)) + FROM client + WHERE id = vClientFk; + + SET vNewInvoiceId = LAST_INSERT_ID(); + + SELECT `ref` + INTO vNewRef + FROM invoiceOut + WHERE id = vNewInvoiceId; + + UPDATE ticket t + JOIN tmp.ticketToInvoice ti ON ti.id = t.id + SET t.refFk = vNewRef; + + DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; + CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY + SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + FROM tmp.ticketToInvoice ti + LEFT JOIN ticketState ts ON ti.id = ts.ticket + JOIN state s + WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); + + INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) + SELECT * FROM tmp.updateInter; + + CALL invoiceExpenceMake(vNewInvoiceId); + CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + + UPDATE invoiceOut io + JOIN ( + SELECT SUM(amount) total + FROM invoiceOutExpence + WHERE invoiceOutFk = vNewInvoiceId + ) base + JOIN ( + SELECT SUM(vat) total + FROM invoiceOutTax + WHERE invoiceOutFk = vNewInvoiceId + ) vat + SET io.amount = base.total + vat.total + WHERE io.id = vNewInvoiceId; + + DROP TEMPORARY TABLE tmp.updateInter; + + SELECT COUNT(*), id + INTO vIsInterCompany, vInterCompanyFk + FROM company + WHERE clientFk = vClientFk; + + IF (vIsInterCompany) THEN + + INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) + SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; + + SET vNewInvoiceInFk = LAST_INSERT_ID(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM tmp.ticketToInvoice; + + CALL `ticket_getTax`('NATIONAL'); + + SET @vTaxableBaseServices := 0.00; + SET @vTaxCodeGeneral := NULL; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInFk, + @vTaxableBaseServices, + sub.expenceFk, + sub.taxTypeSageFk, + sub.transactionTypeSageFk + FROM ( + SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, + i.expenceFk, + i.taxTypeSageFk, + i.transactionTypeSageFk, + @vTaxCodeGeneral := i.taxClassCodeFk + FROM tmp.ticketServiceTax tst + JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code + WHERE i.isService + HAVING taxableBase + ) sub; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInFk, + SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, + @vTaxableBaseServices, 0) taxableBase, + i.expenceFk, + i.taxTypeSageFk , + i.transactionTypeSageFk + FROM tmp.ticketTax tt + JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code + WHERE !i.isService + GROUP BY tt.pgcFk + HAVING taxableBase + ORDER BY tt.priority; + + CALL invoiceInDueDay_calculate(vNewInvoiceInFk); + + SELECT COUNT(*) INTO vIsCEESerial + FROM invoiceOutSerial + WHERE code = vSerial; + + IF vIsCEESerial THEN + + INSERT INTO invoiceInIntrastat ( + invoiceInFk, + intrastatFk, + amount, + stems, + countryFk, + net) + SELECT + vNewInvoiceInFk, + i.intrastatFk, + SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), + SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), + su.countryFk, + CAST(SUM(IFNULL(i.stems, 1) + * s.quantity + * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) + FROM sale s + JOIN ticket t ON s.ticketFk = t.id + JOIN supplier su ON su.id = t.companyFk + JOIN item i ON i.id = s.itemFk + LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk + WHERE t.refFk = vNewRef + GROUP BY i.intrastatFk; + + END IF; + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketAmount; + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticketServiceTax; + END IF; + END IF; + DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`; +END$$ +DELIMITER ; From 8a843b37bd9067b6be1dfa090d557b59a0111bcf Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 11 May 2023 13:54:42 +0200 Subject: [PATCH 08/13] refs #5160 Back test timeout workaround --- back/tests.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/back/tests.js b/back/tests.js index a377011d3..ef5a7bca8 100644 --- a/back/tests.js +++ b/back/tests.js @@ -34,6 +34,8 @@ async function test() { app.boot(bootOptions, err => err ? reject(err) : resolve()); }); + // FIXME: Workaround to wait for loopback to be ready + await app.models.Application.status(); const Jasmine = require('jasmine'); const jasmine = new Jasmine(); @@ -53,7 +55,7 @@ async function test() { const JunitReporter = require('jasmine-reporters'); jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); - jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; jasmine.exitOnCompletion = true; } From 8419c76b12fb2aedd4675c4c08da3bc8715bbc31 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 12 May 2023 12:51:07 +0200 Subject: [PATCH 09/13] refs #5153 worker sin tr --- db/changes/{231801 => 232001}/00-clientWorkerName.sql | 0 db/changes/{231801 => 232001}/00-createWorker.sql | 7 ++++++- modules/worker/back/methods/worker/new.js | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) rename db/changes/{231801 => 232001}/00-clientWorkerName.sql (100%) rename db/changes/{231801 => 232001}/00-createWorker.sql (66%) diff --git a/db/changes/231801/00-clientWorkerName.sql b/db/changes/232001/00-clientWorkerName.sql similarity index 100% rename from db/changes/231801/00-clientWorkerName.sql rename to db/changes/232001/00-clientWorkerName.sql diff --git a/db/changes/231801/00-createWorker.sql b/db/changes/232001/00-createWorker.sql similarity index 66% rename from db/changes/231801/00-createWorker.sql rename to db/changes/232001/00-createWorker.sql index 7a128415c..df08b9df4 100644 --- a/db/changes/231801/00-createWorker.sql +++ b/db/changes/232001/00-createWorker.sql @@ -6,4 +6,9 @@ ALTER TABLE `vn`.`workerConfig` ADD businessTypeFk varchar(100) NULL UPDATE `vn`.`workerConfig` SET businessTypeFk = 'worker' - WHERE id = 1; \ No newline at end of file + WHERE id = 1; + + UPDATE client c + JOIN worker w ON w.id = c.id + SET c.name = REPLACE(c.name, 'TR ', ''), + c.businessTypeFk = 'worker'; \ No newline at end of file diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index 91dabda5d..cec7524c6 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -205,6 +205,7 @@ module.exports = Self => { iban: args.iban, bankEntityFk: args.bankEntityFk, defaultAddressFk: address.id, + businessTypeFk: workerConfig.businessTypeFk, }, myOptions ); From 9ce3e79e00016e789d264138644cdc40bca00574 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 15 May 2023 11:50:51 +0200 Subject: [PATCH 10/13] refs #5594 eliminado archivo ducplicado --- db/changes/231801/00-invoiceOut_new.sql | 254 ------------------------ 1 file changed, 254 deletions(-) delete mode 100644 db/changes/231801/00-invoiceOut_new.sql diff --git a/db/changes/231801/00-invoiceOut_new.sql b/db/changes/231801/00-invoiceOut_new.sql deleted file mode 100644 index 7406d4591..000000000 --- a/db/changes/231801/00-invoiceOut_new.sql +++ /dev/null @@ -1,254 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATE, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompanyFk INT; - DECLARE vInterCompanyFk INT; - DECLARE vClientFk INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInFk INT; - DECLARE vIsInterCompany BOOL DEFAULT FALSE; - DECLARE vIsCEESerial BOOL DEFAULT FALSE; - DECLARE vIsCorrectInvoiceDate BOOL; - DECLARE vMaxShipped DATE; - - SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); - - SELECT t.clientFk, - t.companyFk, - MAX(DATE(t.shipped)), - DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( - vSerial, - t.companyFk, - YEAR(vInvoiceDate)) - INTO vClientFk, - vCompanyFk, - vMaxShipped, - vIsCorrectInvoiceDate - FROM ticketToInvoice tt - JOIN ticket t ON t.id = tt.id; - - IF(vMaxShipped > vInvoiceDate) THEN - CALL util.throw("Invoice date can't be less than max date"); - END IF; - - IF NOT vIsCorrectInvoiceDate THEN - CALL util.throw('Exists an invoice with a previous date'); - END IF; - - -- Eliminem de ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 - INTO vIsAnySaleToInvoice - FROM ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id; - - SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice - FROM ticketToInvoice t - JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - cplusInvoiceType477Fk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClientFk, - getDueDate(vInvoiceDate, dueDay), - vCompanyFk, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - UPDATE ticket t - JOIN ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) - SELECT * FROM tmp.updateInter; - - CALL invoiceExpenceMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) total - FROM invoiceOutExpence - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT COUNT(*), id - INTO vIsInterCompany, vInterCompanyFk - FROM company - WHERE clientFk = vClientFk; - - IF (vIsInterCompany) THEN - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; - - SET vNewInvoiceInFk = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - @vTaxableBaseServices, - sub.expenceFk, - sub.taxTypeSageFk, - sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, - i.expenceFk, - i.taxTypeSageFk, - i.transactionTypeSageFk, - @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, - @vTaxableBaseServices, 0) taxableBase, - i.expenceFk, - i.taxTypeSageFk , - i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInFk); - - SELECT COUNT(*) INTO vIsCEESerial - FROM invoiceOutSerial - WHERE code = vSerial; - - IF vIsCEESerial THEN - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInFk, - i.intrastatFk, - SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), - SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - WHERE t.refFk = vNewRef - GROUP BY i.intrastatFk; - - END IF; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - END IF; - END IF; - DROP TEMPORARY TABLE `ticketToInvoice`; -END$$ -DELIMITER ; From 9f0d5097fea56e6ebb7b58e8e368b14eab118d1d Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 May 2023 09:14:38 +0200 Subject: [PATCH 11/13] refs #5160 increase jasmine timeout --- back/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/tests.js b/back/tests.js index ef5a7bca8..97e548d33 100644 --- a/back/tests.js +++ b/back/tests.js @@ -55,7 +55,7 @@ async function test() { const JunitReporter = require('jasmine-reporters'); jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); - jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; + jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; jasmine.exitOnCompletion = true; } From da5e6a43f6d53ba0deac64b9fd512c5a5c52f9f9 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 May 2023 07:44:39 +0200 Subject: [PATCH 12/13] set changes in changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 083e43199..e64b0a400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2320.01] - 2023-05-25 ### Added -- +- (Tickets -> Crear Factura) Al facturar se envia automáticamente el pdf al cliente + ### Changed -- +- (Trabajadores -> Nuevo trabajador) Los clientes se crean sin 'TR' pero se añade tipo de negocio 'Trabajador' ### Fixed - From e17b9a32b9e2430975edfbd6d6bd2d893aaf1405 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 May 2023 07:46:51 +0200 Subject: [PATCH 13/13] add schema --- db/changes/232001/00-createWorker.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/changes/232001/00-createWorker.sql b/db/changes/232001/00-createWorker.sql index df08b9df4..0ea7ecbe8 100644 --- a/db/changes/232001/00-createWorker.sql +++ b/db/changes/232001/00-createWorker.sql @@ -1,14 +1,14 @@ -INSERT INTO vn.businessType (code,description) +INSERT INTO `vn`.`businessType` (`code`, `description`) VALUES ('worker','Trabajador'); -ALTER TABLE `vn`.`workerConfig` ADD businessTypeFk varchar(100) NULL +ALTER TABLE `vn`.`workerConfig` ADD businessTypeFk varchar(100) NULL COMMENT 'Tipo de negocio por defecto al dar de alta un trabajador nuevo'; UPDATE `vn`.`workerConfig` SET businessTypeFk = 'worker' WHERE id = 1; - UPDATE client c - JOIN worker w ON w.id = c.id + UPDATE `vn`.`client` c + JOIN `vn`.`worker` w ON w.id = c.id SET c.name = REPLACE(c.name, 'TR ', ''), - c.businessTypeFk = 'worker'; \ No newline at end of file + c.businessTypeFk = 'worker';