From 3813dbb9fddaa84bdf70af85cefcb52f98c23e22 Mon Sep 17 00:00:00 2001 From: ivanm Date: Tue, 20 Feb 2024 13:10:03 +0100 Subject: [PATCH 1/5] refs #6784 Delete clientTypeFk --- db/dump/fixtures.before.sql | 2 +- db/routines/bs/procedures/waste_addSales.sql | 2 +- db/routines/vn/procedures/comparative_add.sql | 2 +- db/routines/vn/procedures/itemShelving_filterBuyer.sql | 4 ++-- db/routines/vn/procedures/item_getBalance.sql | 2 +- db/routines/vn/views/saleValue.sql | 2 +- db/routines/vn2008/views/Clientes.sql | 1 - db/versions/10891-chocolateRuscus/00-firstScript.sql | 2 ++ modules/client/back/models/client.json | 2 +- modules/ticket/back/models/sale.js | 2 +- 10 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 db/versions/10891-chocolateRuscus/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 094b956af..5ad6f30ea 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -371,7 +371,7 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk__`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) VALUES (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index ac6690129..0ab328b49 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -19,7 +19,7 @@ BEGIN itemFk, itemTypeFk, floor(sum(value)) as total, - floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas + floor(sum(IF(typeFk = 'loses', value, 0))) as mermas FROM vn.saleValue where year = vYear and week = vWeek diff --git a/db/routines/vn/procedures/comparative_add.sql b/db/routines/vn/procedures/comparative_add.sql index 756096e54..b64c20201 100644 --- a/db/routines/vn/procedures/comparative_add.sql +++ b/db/routines/vn/procedures/comparative_add.sql @@ -47,7 +47,7 @@ BEGIN JOIN itemCategory ic ON ic.id = tp.categoryFk JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN clientType ct ON ct.code = c.typeFk JOIN warehouse w ON w.id = t.warehouseFk JOIN address ad ON ad.id = t.addressFk LEFT JOIN province p ON p.id = ad.provinceFk diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index a232139d3..d8f20d95f 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -44,7 +44,7 @@ proc:BEGIN LEFT JOIN saleTracking st ON st.saleFk = s.id JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk - JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN clientType ct ON ct.code = c.typeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL AND ct.code IN ('normal', 'trust') @@ -70,7 +70,7 @@ proc:BEGIN LEFT JOIN saleTracking st ON st.saleFk = s.id JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk - JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN clientType ct ON ct.code = c.typeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL AND ct.code IN ('normal', 'trust') diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 5fe57f2a4..87d46db6d 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -128,7 +128,7 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN state st ON st.`code` = ts.`code` JOIN client c ON c.id = t.clientFk - JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN clientType ct ON ct.code = c.typeFk JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), diff --git a/db/routines/vn/views/saleValue.sql b/db/routines/vn/views/saleValue.sql index 4394769d1..2dee4695e 100644 --- a/db/routines/vn/views/saleValue.sql +++ b/db/routines/vn/views/saleValue.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn`.`saleValue` AS SELECT `wh`.`name` AS `warehouse`, `c`.`name` AS `client`, - `c`.`typeFk` AS `clientTypeFk`, + `c`.`typeFk` AS `typeFk`, `u`.`name` AS `buyer`, `it`.`id` AS `itemTypeFk`, `it`.`name` AS `family`, diff --git a/db/routines/vn2008/views/Clientes.sql b/db/routines/vn2008/views/Clientes.sql index 12583915a..a696cb6e0 100644 --- a/db/routines/vn2008/views/Clientes.sql +++ b/db/routines/vn2008/views/Clientes.sql @@ -34,7 +34,6 @@ AS SELECT `c`.`id` AS `id_cliente`, `c`.`hasLcr` AS `hasLcr`, `c`.`defaultAddressFk` AS `default_address`, `c`.`riskCalculated` AS `risk_calculated`, - `c`.`clientTypeFk` AS `clientes_tipo_id`, `c`.`hasToInvoiceByAddress` AS `invoiceByAddress`, `c`.`isTaxDataChecked` AS `contabilizado`, `c`.`isFreezed` AS `congelado`, diff --git a/db/versions/10891-chocolateRuscus/00-firstScript.sql b/db/versions/10891-chocolateRuscus/00-firstScript.sql new file mode 100644 index 000000000..8666e0b24 --- /dev/null +++ b/db/versions/10891-chocolateRuscus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.client DROP FOREIGN KEY tipos_de_cliente; +ALTER TABLE vn.client CHANGE COLUMN clientTypeFk clientTypeFk__ INT NOT NULL DEFAULT 1 COMMENT '@deprecated 2024-02-20 refs #6784'; diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index bfde05162..3d381e186 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -197,7 +197,7 @@ "type": { "type": "belongsTo", "model": "ClientType", - "foreignKey": "clientTypeFk" + "foreignKey": "clientTypeFk__" }, "businessType": { "type": "belongsTo", diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 30fb74b75..31a2fbf35 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -41,7 +41,7 @@ module.exports = Self => { include: { relation: 'client', scope: { - fields: ['id', 'clientTypeFk'], + fields: ['id', 'clientTypeFk__'], include: { relation: 'type', scope: { From f59204592571fa708b136392b7a2b95f8ed408cd Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 21 Feb 2024 11:49:27 +0100 Subject: [PATCH 2/5] refs #6784 Delete clientType.id and modify relationships in json and js --- db/dump/fixtures.before.sql | 36 +++++++++---------- .../10891-chocolateRuscus/00-firstScript.sql | 4 +++ modules/client/back/models/client-type.json | 7 ++-- modules/client/back/models/client.json | 2 +- .../order/back/methods/order/isEditable.js | 10 ++---- modules/order/back/methods/order/new.js | 9 ++--- .../back/methods/ticket/isEditableOrThrow.js | 13 +++---- modules/ticket/back/methods/ticket/new.js | 9 ++--- modules/ticket/back/models/sale.js | 10 ++---- 9 files changed, 37 insertions(+), 63 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 5ad6f30ea..b3f2088ab 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -352,12 +352,12 @@ INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) ('46600', 4, 7), ('EC170150', 5, 8); -INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) +INSERT INTO `vn`.`clientType`(`code`, `type`) VALUES - (1, 'normal', 'Normal'), - (2, 'internalUse', 'Autoconsumo'), - (3, 'handMaking', 'Confección'), - (4, 'loses', 'Mermas'); + ('normal', 'Normal'), + ('internalUse', 'Autoconsumo'), + ('handMaking', 'Confección'), + ('loses', 'Mermas'); INSERT INTO `vn`.`cplusTerIdNif`(`id`, `description`) VALUES @@ -371,20 +371,20 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk__`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) VALUES - (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'), - (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'), - (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'), - (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'); + (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'), + (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'), + (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'), + (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 diff --git a/db/versions/10891-chocolateRuscus/00-firstScript.sql b/db/versions/10891-chocolateRuscus/00-firstScript.sql index 8666e0b24..711850323 100644 --- a/db/versions/10891-chocolateRuscus/00-firstScript.sql +++ b/db/versions/10891-chocolateRuscus/00-firstScript.sql @@ -1,2 +1,6 @@ ALTER TABLE vn.client DROP FOREIGN KEY tipos_de_cliente; ALTER TABLE vn.client CHANGE COLUMN clientTypeFk clientTypeFk__ INT NOT NULL DEFAULT 1 COMMENT '@deprecated 2024-02-20 refs #6784'; +ALTER TABLE vn.clientType CHANGE COLUMN id id__ INT NOT NULL COMMENT '@deprecated 2024-02-20 refs #6784'; +ALTER TABLE vn.clientType DROP PRIMARY KEY; +ALTER TABLE vn.clientType ADD PRIMARY KEY (code); + diff --git a/modules/client/back/models/client-type.json b/modules/client/back/models/client-type.json index eeae845eb..ecf0c065f 100644 --- a/modules/client/back/models/client-type.json +++ b/modules/client/back/models/client-type.json @@ -7,12 +7,9 @@ } }, "properties": { - "id": { - "type": "number", - "id": true - }, "code": { - "type": "string" + "type": "string", + "id": true }, "type": { "type": "string" diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 3d381e186..550ac380e 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -197,7 +197,7 @@ "type": { "type": "belongsTo", "model": "ClientType", - "foreignKey": "clientTypeFk__" + "foreignKey": "typeFk" }, "businessType": { "type": "belongsTo", diff --git a/modules/order/back/methods/order/isEditable.js b/modules/order/back/methods/order/isEditable.js index 4ef76c11f..3fd2f993c 100644 --- a/modules/order/back/methods/order/isEditable.js +++ b/modules/order/back/methods/order/isEditable.js @@ -29,17 +29,11 @@ module.exports = Self => { where: {id: orderId}, fields: ['isConfirmed', 'clientFk'], include: [ - {relation: 'client', - scope: { - include: { - relation: 'type' - } - } - } + {relation: 'client'} ] }, myOptions); - if (exists && exists.client().type().code !== 'normal') + if (exists && exists.client().typeFk !== 'normal') return true; if (!exists || exists.isConfirmed === 1) diff --git a/modules/order/back/methods/order/new.js b/modules/order/back/methods/order/new.js index d65b18e12..2aad27c9a 100644 --- a/modules/order/back/methods/order/new.js +++ b/modules/order/back/methods/order/new.js @@ -49,17 +49,12 @@ module.exports = Self => { where: {id: addressId}, fields: ['clientFk'], include: [ - {relation: 'client', - scope: { - include: { - relation: 'type' - } - } + {relation: 'client' } ] }, myOptions); - if (address.client().type().code === 'normal') { + if (address.client().typeFk === 'normal') { if (!address.client().isActive) throw new UserError(`You can't create an order for an inactive client`); } diff --git a/modules/ticket/back/methods/ticket/isEditableOrThrow.js b/modules/ticket/back/methods/ticket/isEditableOrThrow.js index 41438be3a..16cff84f1 100644 --- a/modules/ticket/back/methods/ticket/isEditableOrThrow.js +++ b/modules/ticket/back/methods/ticket/isEditableOrThrow.js @@ -17,21 +17,16 @@ module.exports = Self => { const alertLevel = state ? state.alertLevel : null; const ticket = await models.Ticket.findById(id, { fields: ['clientFk'], - include: [{ - relation: 'client', - scope: { - include: { - relation: 'type' - } - } - }] + include: { + relation: 'client' + } }, myOptions); const isLocked = await models.Ticket.isLocked(id, myOptions); const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions); const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0); - const isNormalClient = ticket && ticket.client().type().code == 'normal'; + const isNormalClient = ticket && ticket.client().typeFk == 'normal'; const isEditable = !(alertLevelGreaterThanZero && isNormalClient); if (!ticket) diff --git a/modules/ticket/back/methods/ticket/new.js b/modules/ticket/back/methods/ticket/new.js index 288d38d77..8c27101ef 100644 --- a/modules/ticket/back/methods/ticket/new.js +++ b/modules/ticket/back/methods/ticket/new.js @@ -77,12 +77,7 @@ module.exports = Self => { where: {id: args.addressId}, fields: ['id', 'clientFk'], include: { - relation: 'client', - scope: { - include: { - relation: 'type' - } - } + relation: 'client' } }, myOptions); @@ -93,7 +88,7 @@ module.exports = Self => { if (args.agencyModeId) agencyMode = await models.AgencyMode.findById(args.agencyModeId, null, myOptions); - if (address.client().type().code === 'normal' && (!agencyMode || agencyMode.code != 'refund')) { + if (address.client().typeFk === 'normal' && (!agencyMode || agencyMode.code != 'refund')) { const canCreateTicket = await models.Client.canCreateTicket(args.clientId, myOptions); if (!canCreateTicket) throw new UserError(`You can't create a ticket for an inactive client`); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 31a2fbf35..17d228301 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -41,18 +41,12 @@ module.exports = Self => { include: { relation: 'client', scope: { - fields: ['id', 'clientTypeFk__'], - include: { - relation: 'type', - scope: { - fields: ['code', 'description'] - } - } + fields: ['id', 'typeFk'] } } }, ctx.options); - if (ticket?.client()?.type()?.code === 'loses') return; + if (ticket?.client()?.typeFk === 'loses') return; const isRefund = await models.TicketRefund.findOne({ fields: ['id'], From f0daf2dd9a92529f66f8ec54c326ee017788c5a7 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 21 Feb 2024 12:22:27 +0100 Subject: [PATCH 3/5] refs #6784 Modify fixtures.before.sql --- db/dump/fixtures.before.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b3f2088ab..f7bbcb512 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -373,6 +373,7 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) VALUES + (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), From 65cb2d45fd41ed67ff11f6a8c6a4e444b1448656 Mon Sep 17 00:00:00 2001 From: ivanm Date: Wed, 21 Feb 2024 12:30:25 +0100 Subject: [PATCH 4/5] refs #6784 Eliminate row in fixtures.before.sql --- db/dump/fixtures.before.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index f7bbcb512..0b9bb81a8 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -376,7 +376,6 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist','normal'), (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), From a0cb32ea10e7a9083982262abe6270fa4f4406b3 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 22 Feb 2024 14:01:19 +0100 Subject: [PATCH 5/5] refs #6784 Delete unnecessary JOINs --- db/routines/vn/procedures/comparative_add.sql | 3 +-- db/routines/vn/procedures/itemShelving_filterBuyer.sql | 6 ++---- db/routines/vn/procedures/item_getBalance.sql | 3 +-- modules/ticket/back/models/sale.js | 8 +++++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/db/routines/vn/procedures/comparative_add.sql b/db/routines/vn/procedures/comparative_add.sql index b64c20201..44f9686aa 100644 --- a/db/routines/vn/procedures/comparative_add.sql +++ b/db/routines/vn/procedures/comparative_add.sql @@ -47,12 +47,11 @@ BEGIN JOIN itemCategory ic ON ic.id = tp.categoryFk JOIN ticket t ON t.id = s.ticketFk JOIN client c ON c.id = t.clientFk - JOIN clientType ct ON ct.code = c.typeFk JOIN warehouse w ON w.id = t.warehouseFk JOIN address ad ON ad.id = t.addressFk LEFT JOIN province p ON p.id = ad.provinceFk WHERE tm.period BETWEEN vMaxPeriod AND vPeriod - AND ct.code <> 'loses' + AND c.typeFk <> 'loses' AND NOT w.code = 'inv' GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk; END IF; diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index d8f20d95f..7112aa48e 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -44,10 +44,9 @@ proc:BEGIN LEFT JOIN saleTracking st ON st.saleFk = s.id JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk - JOIN clientType ct ON ct.code = c.typeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL - AND ct.code IN ('normal', 'trust') + AND c.typeFk IN ('normal', 'trust') GROUP BY s.itemFk ) sub2 ON sub2.itemFk = sub.itemFk UNION ALL @@ -70,10 +69,9 @@ proc:BEGIN LEFT JOIN saleTracking st ON st.saleFk = s.id JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk - JOIN clientType ct ON ct.code = c.typeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL - AND ct.code IN ('normal', 'trust') + AND c.typeFk IN ('normal', 'trust') GROUP BY s.itemFk ) sub5 ON sub5.itemFk = v.item_id WHERE v.calc_id = vCalcVisibleFk diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 87d46db6d..95596d3bc 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -120,7 +120,7 @@ BEGIN TRUE, s.id, st.`order`, - ct.`code`, + c.typeFk, cb.claimFk, NULL FROM sale s @@ -128,7 +128,6 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN state st ON st.`code` = ts.`code` JOIN client c ON c.id = t.clientFk - JOIN clientType ct ON ct.code = c.typeFk JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 17d228301..22ad40184 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -41,7 +41,13 @@ module.exports = Self => { include: { relation: 'client', scope: { - fields: ['id', 'typeFk'] + fields: ['id', 'typeFk'], + include: { + relation: 'type', + scope: { + fields: ['code', 'description'] + } + } } } },