From c036c7c7fe10c582d8c584d654ec46dbd5b4b527 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 31 Mar 2021 07:33:00 +0200 Subject: [PATCH 01/10] model ok --- db/changes/10300-newFacility/.keep | 1 - .../00-supplierBeneficiary.sql | 2 ++ .../supplier/back/models/supplier-account.json | 17 +---------------- modules/supplier/front/account/index.html | 4 ++++ modules/supplier/front/account/locale/es.yml | 3 ++- 5 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 db/changes/10300-newFacility/.keep create mode 100644 db/changes/10300-newFacility/00-supplierBeneficiary.sql diff --git a/db/changes/10300-newFacility/.keep b/db/changes/10300-newFacility/.keep deleted file mode 100644 index 3ece1d69e..000000000 --- a/db/changes/10300-newFacility/.keep +++ /dev/null @@ -1 +0,0 @@ -Delete this \ No newline at end of file diff --git a/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql new file mode 100644 index 000000000..6dadf16c2 --- /dev/null +++ b/db/changes/10300-newFacility/00-supplierBeneficiary.sql @@ -0,0 +1,2 @@ +ALTER TABLE `supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; +UPDATE supplierAccount SET beneficiary = `description`; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index 1d989cbfb..aaab38369 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -22,26 +22,11 @@ "iban": { "type": "String" }, - "office": { - "type": "String" - }, - "DC": { - "type": "String" - }, - "number": { - "type": "String" - }, - "description": { - "type": "String" - }, - "bicSufix": { + "beneficiary": { "type": "String" }, "bankEntityFk": { "type": "Number" - }, - "bankFk": { - "type": "Number" } }, "relations": { diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index 577fa4e87..be3c6e8be 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -35,6 +35,10 @@ ng-click="$ctrl.showBankEntity($event, $index)"> + + Date: Thu, 1 Apr 2021 17:36:27 +0200 Subject: [PATCH 02/10] reviso test --- .../supplier/back/models/supplier-account.js | 22 +++++++++++++++++++ .../back/models/supplier-account.json | 8 +------ modules/supplier/front/account/index.html | 11 +++++----- modules/supplier/front/account/locale/en.yml | 1 + modules/supplier/front/account/locale/es.yml | 3 ++- 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 modules/supplier/back/models/supplier-account.js create mode 100644 modules/supplier/front/account/locale/en.yml diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js new file mode 100644 index 000000000..9d6f10e3c --- /dev/null +++ b/modules/supplier/back/models/supplier-account.js @@ -0,0 +1,22 @@ +const validateIban = require('vn-loopback/util/validateIban'); + +module.exports = Self => { + Self.validateAsync('iban', ibanNeedsValidation, { + message: 'The IBAN does not have the correct format' + }); + + async function ibanNeedsValidation(err, done) { + let filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + let country = await Self.app.models.Country.findOne(filter); + let code = country ? country.code.toLowerCase() : null; + if (code != 'es') + return done(); + + if (!validateIban(this.iban)) + err(); + done(); + } +}; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index aaab38369..ffd2994ba 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -16,24 +16,18 @@ "id": true, "description": "Identifier" }, - "supplierFk": { - "type": "Number" - }, "iban": { "type": "String" }, "beneficiary": { "type": "String" - }, - "bankEntityFk": { - "type": "Number" } }, "relations": { "supplier": { "type": "belongsTo", "model": "Supplier", - "foreignKey": "supplierFk" + "foreignKey": "supplierFk" }, "bankEntity": { "type": "belongsTo", diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html index be3c6e8be..7264f6f2c 100644 --- a/modules/supplier/front/account/index.html +++ b/modules/supplier/front/account/index.html @@ -1,7 +1,7 @@ -
+ - - + ng-model="supplierAccount.beneficiary" + info="Beneficiary information"> Date: Thu, 1 Apr 2021 18:38:40 +0200 Subject: [PATCH 03/10] test --- .../models/specs/supplier-account.spec.js | 66 +++++++++++++++++++ .../back/models/specs/supplier.spec.js | 2 +- .../back/models/supplier-account.json | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 modules/supplier/back/models/specs/supplier-account.spec.js diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js new file mode 100644 index 000000000..438b87f8c --- /dev/null +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -0,0 +1,66 @@ +const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); + +describe('loopback model Supplier-account', () => { + describe('create', () => { + const supplierId = 1; + const bankEntityId = 2100; + it('should throw an error when attempting to set an invalid iban account', async() => { + let error; + const expectedError = 'The IBAN does not have the correct format'; + const iban = 'incorrect format'; + // si falla el error es extraño preguntar a carlos + + await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + ).catch(e => { + error = e; + + expect(error.message).toContain(expectedError); + }); + + expect(error).toBeDefined(); + }); + + it('should create a valid supplier account', async() => { + const tx = await app.models.Claim.beginTransaction({}); + try { + const options = {transaction: tx}; + const iban = 'ES91 2100 0418 4502 0005 1332'; + + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + activeCtx.http.req.__ = value => { + return value; + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + const createdSupplierAccount = await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + , options); + + expect(createdSupplierAccount.iban).toBe(iban); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + }); +}); diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 1853b1c9a..f7dd15139 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -describe('loopback model address', () => { +describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index ffd2994ba..8e2838fe5 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -7,7 +7,7 @@ }, "options": { "mysql": { - "table": "supplierAccount" + "table": "supplierAccount" } }, "properties": { From 63ec7677c698a46827e94b8092e0f6a9b3b4aa3b Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 1 Apr 2021 18:43:28 +0200 Subject: [PATCH 04/10] test ok --- db/changes/10300-newFacility/00-supplierBeneficiary.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/changes/10300-newFacility/00-supplierBeneficiary.sql b/db/changes/10300-newFacility/00-supplierBeneficiary.sql index 6dadf16c2..fcd5a1e2e 100644 --- a/db/changes/10300-newFacility/00-supplierBeneficiary.sql +++ b/db/changes/10300-newFacility/00-supplierBeneficiary.sql @@ -1,2 +1,2 @@ -ALTER TABLE `supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; -UPDATE supplierAccount SET beneficiary = `description`; +ALTER TABLE vn.`supplierAccount` ADD `beneficiary` VARCHAR(50) NULL DEFAULT NULL AFTER `bankFk`; +UPDATE vn.supplierAccount SET beneficiary = `description`; From cd4f93f326024a65368834864f0607dc4f696b60 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 16 Apr 2021 18:35:03 +0200 Subject: [PATCH 05/10] minor fixes --- README.md | 4 ++- .../models/specs/supplier-account.spec.js | 32 +++++++++---------- .../supplier/back/models/supplier-account.js | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index da51fe093..32377c115 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ Salix is also the scientific name of a beautifull tree! :) Required applications. -* Node.js = 14.15.1 LTS +* Node.js = 14.x LTS +* Docker +* Git * Docker You will need to install globally the following items. diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js index 438b87f8c..f56e70a89 100644 --- a/modules/supplier/back/models/specs/supplier-account.spec.js +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -9,19 +9,18 @@ describe('loopback model Supplier-account', () => { let error; const expectedError = 'The IBAN does not have the correct format'; const iban = 'incorrect format'; - // si falla el error es extraño preguntar a carlos - - await app.models.SupplierAccount.create( - { - supplierFk: supplierId, - bankEntityFk: bankEntityId, - iban: iban - } - ).catch(e => { + try { + await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + }); + } catch (e) { error = e; expect(error.message).toContain(expectedError); - }); + } expect(error).toBeDefined(); }); @@ -47,13 +46,12 @@ describe('loopback model Supplier-account', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - const createdSupplierAccount = await app.models.SupplierAccount.create( - { - supplierFk: supplierId, - bankEntityFk: bankEntityId, - iban: iban - } - , options); + const createdSupplierAccount = await app.models.SupplierAccount.create({ + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + }, + options); expect(createdSupplierAccount.iban).toBe(iban); await tx.rollback(); diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index 9d6f10e3c..85bf37510 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -1,11 +1,11 @@ const validateIban = require('vn-loopback/util/validateIban'); module.exports = Self => { - Self.validateAsync('iban', ibanNeedsValidation, { + Self.validateAsync('iban', ibanValidation, { message: 'The IBAN does not have the correct format' }); - async function ibanNeedsValidation(err, done) { + async function ibanValidation(err, done) { let filter = { fields: ['code'], where: {id: this.countryFk} From 4a7a4f6dcfb05aab440e9eddb01633d62f643f46 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 22 Apr 2021 09:06:08 +0200 Subject: [PATCH 06/10] test ok --- modules/ticket/back/models/ticket-service.js | 13 ++++--------- package-lock.json | 6 +++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/modules/ticket/back/models/ticket-service.js b/modules/ticket/back/models/ticket-service.js index cdb57650a..aa94c42e3 100644 --- a/modules/ticket/back/models/ticket-service.js +++ b/modules/ticket/back/models/ticket-service.js @@ -1,16 +1,13 @@ const UserError = require('vn-loopback/util/user-error'); -const LoopBackContext = require('loopback-context'); module.exports = Self => { Self.observe('before save', async ctx => { - const loopBackContext = LoopBackContext.getCurrentContext(); - const httpCtx = {req: loopBackContext.active}; const models = Self.app.models; let changes = ctx.currentInstance || ctx.instance; if (changes) { let ticketId = changes.ticketFk; - let isEditable = await models.Ticket.isEditable(httpCtx, ticketId); - if (!isEditable) + let isLocked = await models.Ticket.isLocked(ticketId); + if (isLocked) throw new UserError(`The current ticket can't be modified`); if (changes.ticketServiceTypeFk) { @@ -21,13 +18,11 @@ module.exports = Self => { }); Self.observe('before delete', async ctx => { - const loopBackContext = LoopBackContext.getCurrentContext(); - const httpCtx = {req: loopBackContext.active}; const models = Self.app.models; const service = await models.TicketService.findById(ctx.where.id); - const isEditable = await models.Ticket.isEditable(httpCtx, service.ticketFk); + const isLocked = await models.Ticket.isLocked(service.ticketFk); - if (!isEditable) + if (isLocked) throw new UserError(`The current ticket can't be modified`); }); }; diff --git a/package-lock.json b/package-lock.json index 68004c13c..1c02e021a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17073,9 +17073,9 @@ } }, "ssri": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", - "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz", + "integrity": "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==", "dev": true, "requires": { "figgy-pudding": "^3.5.1" From 42957f9ace9209dea3b0bf353b2b72e0a622f78b Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 26 Apr 2021 11:12:13 +0200 Subject: [PATCH 07/10] Added new SQL version --- db/changes/10310-mothersDay/.keep | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/changes/10310-mothersDay/.keep diff --git a/db/changes/10310-mothersDay/.keep b/db/changes/10310-mothersDay/.keep new file mode 100644 index 000000000..4acbf110f --- /dev/null +++ b/db/changes/10310-mothersDay/.keep @@ -0,0 +1 @@ +Delete me with the first .sql files addition \ No newline at end of file From 2395a0af63a7377e4a19a336ff011aae2335315f Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 26 Apr 2021 12:24:16 +0200 Subject: [PATCH 08/10] done --- modules/client/front/balance/index/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/front/balance/index/index.html b/modules/client/front/balance/index/index.html index 468ac98c3..596838c0c 100644 --- a/modules/client/front/balance/index/index.html +++ b/modules/client/front/balance/index/index.html @@ -128,7 +128,7 @@ Date: Mon, 26 Apr 2021 12:33:33 +0200 Subject: [PATCH 09/10] test ok --- db/changes/10310-mothersDay/.keep | 1 - db/changes/10310-mothersDay/00-receiptAcl.sql | 3 +++ modules/ticket/front/expedition/index.html | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) delete mode 100644 db/changes/10310-mothersDay/.keep create mode 100644 db/changes/10310-mothersDay/00-receiptAcl.sql diff --git a/db/changes/10310-mothersDay/.keep b/db/changes/10310-mothersDay/.keep deleted file mode 100644 index 4acbf110f..000000000 --- a/db/changes/10310-mothersDay/.keep +++ /dev/null @@ -1 +0,0 @@ -Delete me with the first .sql files addition \ No newline at end of file diff --git a/db/changes/10310-mothersDay/00-receiptAcl.sql b/db/changes/10310-mothersDay/00-receiptAcl.sql new file mode 100644 index 000000000..d3450cc9d --- /dev/null +++ b/db/changes/10310-mothersDay/00-receiptAcl.sql @@ -0,0 +1,3 @@ +UPDATE salix.ACL + SET principalId = "salesAssistant" + WHERE model = 'Client' AND property = 'createReceipt'; \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index 9f3d1b11a..26d9ef640 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -18,6 +18,7 @@ Name Package type Counter + externalId Worker Created @@ -41,6 +42,7 @@ {{::expedition.packageItemName}} {{::expedition.freightItemName}} {{::expedition.counter}} + {{::expedition.externalId}} Date: Mon, 26 Apr 2021 13:40:52 +0200 Subject: [PATCH 10/10] SQL fixes --- db/changes/10300-newFacility/00-weekWaste.sql | 38 +++++++++------- .../00-weekWaste_byWorker.sql | 44 ++++++++++--------- .../00-weekWaste_getDetail.sql | 43 ++++++++++-------- db/changes/10300-newFacility/01-waste.sql | 3 +- .../10300-newFacility/02-waste_addSales.sql | 29 ++++++------ 5 files changed, 84 insertions(+), 73 deletions(-) diff --git a/db/changes/10300-newFacility/00-weekWaste.sql b/db/changes/10300-newFacility/00-weekWaste.sql index efa988aea..4883a49fc 100644 --- a/db/changes/10300-newFacility/00-weekWaste.sql +++ b/db/changes/10300-newFacility/00-weekWaste.sql @@ -1,24 +1,28 @@ -drop procedure weekWaste; +DROP PROCEDURE IF EXISTS `bs`.`weekWaste`; -create definer = root@`%` procedure weekWaste__() +DELIMITER $$ +$$ +CREATE DEFINER = `root`@`%` PROCEDURE `bs`.`weekWaste__`() BEGIN - DECLARE vWeek INT; + DECLARE vWeek INT; DECLARE vYear INT; SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); + INTO vWeek, vYear + FROM vn.time + WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK); - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - sum(saleTotal) as total, - sum(saleWaste) as dwindle - FROM bs.waste - WHERE year = vYear and week = vWeek - GROUP BY buyer - ) sub - ORDER BY percentage DESC; -END; + SELECT *, 100 * dwindle / total AS percentage + FROM ( + SELECT buyer, + SUM(saleTotal) AS total, + SUM(saleWaste) AS dwindle + FROM bs.waste + WHERE year = vYear + AND week = vWeek + GROUP BY buyer + ) sub + ORDER BY percentage DESC; +END;$$ +DELIMITER ; diff --git a/db/changes/10300-newFacility/00-weekWaste_byWorker.sql b/db/changes/10300-newFacility/00-weekWaste_byWorker.sql index 2da098ae6..ff660494f 100644 --- a/db/changes/10300-newFacility/00-weekWaste_byWorker.sql +++ b/db/changes/10300-newFacility/00-weekWaste_byWorker.sql @@ -1,28 +1,32 @@ -drop procedure weekWaste_byWorker; +DROP PROCEDURE IF EXISTS `bs`.`weekWaste_byWorker`; -create definer = root@`%` procedure weekWaste_byWorker__(IN vWorkerFk int) +DELIMITER $$ +$$ +CREATE + DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_byWorker__`(IN vWorkerFk INT) BEGIN - DECLARE vWeek INT; + DECLARE vWeek INT; DECLARE vYear INT; - + SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = TIMESTAMPADD(WEEK,-1,CURDATE()); + INTO vWeek, vYear + FROM vn.time + WHERE dated = TIMESTAMPADD(WEEK, -1, CURDATE()); - SELECT *, 100 * mermas / total as porcentaje - FROM ( - SELECT ws.family, - sum(ws.saleTotal) as total, - sum(ws.saleWaste) as mermas - FROM bs.waste ws + SELECT *, 100 * mermas / total AS porcentaje + FROM ( + SELECT ws.family, + SUM(ws.saleTotal) AS total, + SUM(ws.saleWaste) AS mermas + FROM bs.waste ws JOIN vn.worker w ON w.user = ws.buyer - WHERE year = vYear AND week = vWeek - AND w.id = vWorkerFk - GROUP BY family - - ) sub - ORDER BY porcentaje DESC; -END; + WHERE year = vYear + AND week = vWeek + AND w.id = vWorkerFk + GROUP BY family + ) sub + ORDER BY porcentaje DESC; +END;;$$ +DELIMITER ; diff --git a/db/changes/10300-newFacility/00-weekWaste_getDetail.sql b/db/changes/10300-newFacility/00-weekWaste_getDetail.sql index 4dd0cab6c..5cf107d24 100644 --- a/db/changes/10300-newFacility/00-weekWaste_getDetail.sql +++ b/db/changes/10300-newFacility/00-weekWaste_getDetail.sql @@ -1,25 +1,30 @@ -drop procedure weekWaste_getDetail; +DROP PROCEDURE IF EXISTS `bs`.`weekWaste_getDetail`; -create definer = root@`%` procedure weekWaste_getDetail__() +DELIMITER $$ +$$ +CREATE + DEFINER = root@`%` PROCEDURE `bs`.`weekWaste_getDetail__`() BEGIN - DECLARE vLastWeek DATE; - DECLARE vWeek INT; + DECLARE vLastWeek DATE; + DECLARE vWeek INT; DECLARE vYear INT; - - SET vLastWeek = TIMESTAMPADD(WEEK,-1,CURDATE()); + + SET vLastWeek = TIMESTAMPADD(WEEK, -1, CURDATE()); SET vYear = YEAR(vLastWeek); SET vWeek = WEEK(vLastWeek, 1); - - SELECT *, 100 * dwindle / total AS percentage - FROM ( - SELECT buyer, - ws.family, - sum(ws.saleTotal) AS total, - sum(ws.saleWaste) AS dwindle - FROM bs.waste ws - WHERE year = vYear AND week = vWeek - GROUP BY buyer, family - ) sub - ORDER BY percentage DESC; -END; + + SELECT *, 100 * dwindle / total AS percentage + FROM ( + SELECT buyer, + ws.family, + SUM(ws.saleTotal) AS total, + SUM(ws.saleWaste) AS dwindle + FROM bs.waste ws + WHERE year = vYear + AND week = vWeek + GROUP BY buyer, family + ) sub + ORDER BY percentage DESC; +END;$$ +DELIMITER ; diff --git a/db/changes/10300-newFacility/01-waste.sql b/db/changes/10300-newFacility/01-waste.sql index 1f7f5fdeb..b01f3b6df 100644 --- a/db/changes/10300-newFacility/01-waste.sql +++ b/db/changes/10300-newFacility/01-waste.sql @@ -17,6 +17,5 @@ ALTER TABLE `bs`.`waste` ALTER TABLE `bs`.`waste` DROP PRIMARY KEY; ALTER TABLE `bs`.`waste` - AD PRIMARY KEY (buyer, year, week, family, itemFk); - + ADD PRIMARY KEY (buyer, `year`, week, family, itemFk); diff --git a/db/changes/10300-newFacility/02-waste_addSales.sql b/db/changes/10300-newFacility/02-waste_addSales.sql index df6db2d2c..ae9efd95b 100644 --- a/db/changes/10300-newFacility/02-waste_addSales.sql +++ b/db/changes/10300-newFacility/02-waste_addSales.sql @@ -2,27 +2,28 @@ UPDATE `bs`.nightTask t SET t.`procedure` = 'waste_addSales' WHERE t.id = 54; DROP PROCEDURE IF EXISTS `bs`.`waste_Add`; +DELIMITER $$ +$$ CREATE - DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`() + DEFINER = root@`%` PROCEDURE `bs`.`waste_addSales`() BEGIN - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year + DECLARE vYear INT; + + SELECT week, year INTO vWeek, vYear - FROM vn.time - WHERE dated = CURDATE(); + FROM vn.time + WHERE dated = CURDATE(); - REPLACE bs.waste + REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje FROM ( SELECT buyer, year, - week, + week, family, - itemFk, - itemTypeFk, + itemFk, + itemTypeFk, floor(sum(value)) as total, floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas FROM vn.saleValue @@ -32,7 +33,5 @@ BEGIN ) sub ORDER BY mermas DESC; - -END; - - +END;$$ +DELIMITER ;