7658-devToTest_2428 #2663
|
@ -28,7 +28,7 @@ Pull from repository.
|
||||||
|
|
||||||
Run this commands on project root directory to install Node dependencies.
|
Run this commands on project root directory to install Node dependencies.
|
||||||
```
|
```
|
||||||
$ npm install
|
$ pnpm install
|
||||||
$ gulp install
|
$ gulp install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"id": true
|
"id": true
|
||||||
},
|
},
|
||||||
|
"sectorFromCode": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sectorToCode": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"backupPrinterNotificationDelay": {
|
"backupPrinterNotificationDelay": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -839,9 +839,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`,
|
||||||
INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Diff', 'diff'),
|
(1, 'Diff', 'diff'),
|
||||||
(2, 'Recover', 'recover'),
|
(2, 'Recovery', 'recovery'),
|
||||||
(3, 'Mana', 'mana'),
|
(3, 'Mana', 'mana'),
|
||||||
(4, 'Reclaim', 'reclaim'),
|
(4, 'Claim', 'claim'),
|
||||||
(5, 'Heritage', 'heritage'),
|
(5, 'Heritage', 'heritage'),
|
||||||
(6, 'Miscellaneous', 'miscellaneous'),
|
(6, 'Miscellaneous', 'miscellaneous'),
|
||||||
(7, 'Freight Pickup', 'freightPickUp');
|
(7, 'Freight Pickup', 'freightPickUp');
|
||||||
|
@ -1885,9 +1885,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
||||||
(1, 31, 4, 21, 2),
|
(1, 31, 4, 21, 2),
|
||||||
(2, 32, 3, 21, 3);
|
(2, 32, 3, 21, 3);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`)
|
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 50);
|
(1, 5, 4, '2016-10-01');
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
|
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -1,167 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`claim_ratio_routine`()
|
|
||||||
BEGIN
|
|
||||||
DECLARE vMonthToRefund INT DEFAULT 4;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PAK 2015-11-20
|
|
||||||
* Se trata de añadir a la tabla Greuges todos los
|
|
||||||
* cargos que luego vamos a utilizar para calcular el recobro
|
|
||||||
*/
|
|
||||||
|
|
||||||
-- Reclamaciones demasiado sensibles
|
|
||||||
|
|
||||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
|
||||||
amount, greugeTypeFk, ticketFk)
|
|
||||||
SELECT c.ticketCreated
|
|
||||||
, c.clientFk
|
|
||||||
, concat('Claim ', c.id,' : ', s.concept)
|
|
||||||
,round( -1 * ((c.responsibility -1)/4) * s.quantity *
|
|
||||||
s.price * (100 - s.discount) / 100, 2)
|
|
||||||
, 4
|
|
||||||
, s.ticketFk
|
|
||||||
FROM vn.sale s
|
|
||||||
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
|
||||||
JOIN vn.claim c ON c.id = ce.claimFk
|
|
||||||
WHERE ce.claimDestinationFk NOT IN (1,5)
|
|
||||||
AND NOT ce.isGreuge
|
|
||||||
AND c.claimStateFk = 3;
|
|
||||||
|
|
||||||
-- Reclamaciones que pasan a Maná
|
|
||||||
|
|
||||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
|
||||||
amount, greugeTypeFk, ticketFk)
|
|
||||||
SELECT c.ticketCreated
|
|
||||||
, c.clientFk
|
|
||||||
, concat('Claim_mana ',c.id,' : ', s.concept)
|
|
||||||
,round( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2)
|
|
||||||
,3
|
|
||||||
,s.ticketFk
|
|
||||||
FROM vn.sale s
|
|
||||||
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
|
||||||
JOIN vn.claim c ON c.id = ce.claimFk
|
|
||||||
WHERE ce.claimDestinationFk NOT IN (1,5)
|
|
||||||
AND NOT ce.isGreuge
|
|
||||||
AND c.claimStateFk = 3
|
|
||||||
AND c.isChargedToMana;
|
|
||||||
|
|
||||||
-- Marcamos para no repetir
|
|
||||||
UPDATE vn.claimEnd ce
|
|
||||||
JOIN vn.claim c ON c.id = ce.claimFk
|
|
||||||
SET ce.isGreuge = TRUE
|
|
||||||
WHERE ce.claimDestinationFk NOT IN (1,5)
|
|
||||||
AND NOT ce.isGreuge
|
|
||||||
AND c.claimStateFk = 3;
|
|
||||||
|
|
||||||
-- Recobros
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
|
|
||||||
CREATE TEMPORARY TABLE tmp.ticket_list
|
|
||||||
(PRIMARY KEY (Id_Ticket))
|
|
||||||
SELECT DISTINCT t.id Id_Ticket
|
|
||||||
FROM vn.saleComponent sc
|
|
||||||
JOIN vn.sale s ON sc.saleFk = s.id
|
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
|
||||||
JOIN vn.ticketLastState ts ON ts.ticketFk = t.id
|
|
||||||
JOIN vn.ticketTracking tt ON tt.id = ts.ticketTrackingFk
|
|
||||||
JOIN vn.state st ON st.id = tt.stateFk
|
|
||||||
JOIN vn.alertLevel al ON al.code = 'DELIVERED'
|
|
||||||
WHERE sc.componentFk = 17
|
|
||||||
AND sc.isGreuge = 0
|
|
||||||
AND t.shipped >= '2016-10-01'
|
|
||||||
AND t.shipped < util.VN_CURDATE()
|
|
||||||
AND st.alertLevel >= al.id;
|
|
||||||
|
|
||||||
DELETE g.*
|
|
||||||
FROM vn.greuge g
|
|
||||||
JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket
|
|
||||||
WHERE g.greugeTypeFk = 2;
|
|
||||||
|
|
||||||
INSERT INTO vn.greuge(clientFk, description, amount,shipped,
|
|
||||||
greugeTypeFk, ticketFk)
|
|
||||||
SELECT t.clientFk
|
|
||||||
,concat('recobro ', s.ticketFk), - round(SUM(sc.value*s.quantity),2)
|
|
||||||
AS dif,
|
|
||||||
date(t.shipped)
|
|
||||||
, 2
|
|
||||||
,tt.Id_Ticket
|
|
||||||
FROM vn.sale s
|
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
|
||||||
JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id
|
|
||||||
JOIN vn.saleComponent sc
|
|
||||||
ON sc.saleFk = s.id AND sc.componentFk = 17
|
|
||||||
GROUP BY t.id
|
|
||||||
HAVING ABS(dif) > 1;
|
|
||||||
|
|
||||||
UPDATE vn.saleComponent sc
|
|
||||||
JOIN vn.sale s ON s.id = sc.saleFk
|
|
||||||
JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk
|
|
||||||
SET sc.isGreuge = 1
|
|
||||||
WHERE sc.componentFk = 17;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Recalculamos la ratio de las reclamaciones, que luego
|
|
||||||
* se va a utilizar en el recobro
|
|
||||||
*/
|
|
||||||
|
|
||||||
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
|
||||||
SELECT id, 0,0,0,0
|
|
||||||
FROM vn.client;
|
|
||||||
|
|
||||||
REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
|
|
||||||
SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones,
|
|
||||||
round(Reclamaciones / (12*fm.Consumo),4), 0
|
|
||||||
FROM bi.facturacion_media_anual fm
|
|
||||||
LEFT JOIN(
|
|
||||||
SELECT c.clientFk, round(sum(-1 * ((c.responsibility -1)/4) *
|
|
||||||
s.quantity * s.price * (100 - s.discount) / 100))
|
|
||||||
AS Reclamaciones
|
|
||||||
FROM vn.sale s
|
|
||||||
JOIN vn.claimEnd ce ON ce.saleFk = s.id
|
|
||||||
JOIN vn.claim c ON c.id = ce.claimFk
|
|
||||||
WHERE ce.claimDestinationFk NOT IN (1,5)
|
|
||||||
AND c.claimStateFk = 3
|
|
||||||
AND c.ticketCreated >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE())
|
|
||||||
GROUP BY c.clientFk
|
|
||||||
) claims ON claims.clientFk = fm.Id_Cliente;
|
|
||||||
|
|
||||||
|
|
||||||
-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
|
|
||||||
UPDATE bi.claims_ratio cr
|
|
||||||
JOIN (
|
|
||||||
SELECT clientFk Id_Cliente, IFNULL(SUM(amount), 0) AS Greuge
|
|
||||||
FROM vn.greuge
|
|
||||||
WHERE shipped <= util.VN_CURDATE()
|
|
||||||
GROUP BY clientFk
|
|
||||||
) g ON g.Id_Cliente = cr.Id_Cliente
|
|
||||||
SET recobro = GREATEST(0,round(IFNULL(Greuge, 0) /
|
|
||||||
(IFNULL(Consumo, 0) * vMonthToRefund / 12 ) ,3));
|
|
||||||
|
|
||||||
-- Protección neonatos
|
|
||||||
UPDATE bi.claims_ratio cr
|
|
||||||
JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente
|
|
||||||
SET recobro = 0, Ratio = 0
|
|
||||||
WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,util.VN_CURDATE());
|
|
||||||
|
|
||||||
-- CLIENTE 7983, JULIAN SUAU
|
|
||||||
UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983;
|
|
||||||
|
|
||||||
-- CLIENTE 4358
|
|
||||||
UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358;
|
|
||||||
|
|
||||||
-- CLIENTE 5523, VERDECORA
|
|
||||||
UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523;
|
|
||||||
|
|
||||||
-- CLIENTE 15979, SERVEIS VETERINARIS
|
|
||||||
UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979;
|
|
||||||
|
|
||||||
-- CLIENTE 5189 i 8942, son de CSR i son el mateix client
|
|
||||||
UPDATE bi.claims_ratio cr
|
|
||||||
JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro
|
|
||||||
FROM bi.claims_ratio
|
|
||||||
WHERE Id_Cliente IN ( 5189,8942)
|
|
||||||
) sub
|
|
||||||
SET cr.recobro = sub.recobro
|
|
||||||
WHERE Id_Cliente IN ( 5189,8942);
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -22,6 +22,7 @@ BEGIN
|
||||||
DECLARE vSerialDua VARCHAR(1) DEFAULT 'D';
|
DECLARE vSerialDua VARCHAR(1) DEFAULT 'D';
|
||||||
DECLARE vInvoiceTypeInformativeCode VARCHAR(1);
|
DECLARE vInvoiceTypeInformativeCode VARCHAR(1);
|
||||||
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
|
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
|
||||||
|
DECLARE vCompanyCode INT;
|
||||||
|
|
||||||
SELECT SiglaNacion INTO vCountryCanariasCode
|
SELECT SiglaNacion INTO vCountryCanariasCode
|
||||||
FROM Naciones
|
FROM Naciones
|
||||||
|
@ -31,9 +32,6 @@ BEGIN
|
||||||
FROM Naciones
|
FROM Naciones
|
||||||
WHERE Nacion ='CEUTA Y MELILLA';
|
WHERE Nacion ='CEUTA Y MELILLA';
|
||||||
|
|
||||||
SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk
|
|
||||||
FROM config;
|
|
||||||
|
|
||||||
SELECT id INTO vTaxImportFk
|
SELECT id INTO vTaxImportFk
|
||||||
FROM taxType
|
FROM taxType
|
||||||
WHERE code = 'import21';
|
WHERE code = 'import21';
|
||||||
|
@ -46,10 +44,14 @@ BEGIN
|
||||||
FROM taxType
|
FROM taxType
|
||||||
WHERE code = 'import4';
|
WHERE code = 'import4';
|
||||||
|
|
||||||
SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk
|
SELECT shipmentTransactionTypeFk,
|
||||||
FROM config;
|
definitiveExportTransactionTypeFk,
|
||||||
|
pendingServiceTransactionTypeFk,
|
||||||
SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk
|
company_getCode(vCompanyFk)
|
||||||
|
INTO vTransactionExportTaxFreeFk,
|
||||||
|
vTransactionExportFk,
|
||||||
|
vDuaTransactionFk,
|
||||||
|
vCompanyCode
|
||||||
FROM config;
|
FROM config;
|
||||||
|
|
||||||
SELECT codeSage INTO vInvoiceTypeInformativeCode
|
SELECT codeSage INTO vInvoiceTypeInformativeCode
|
||||||
|
@ -64,8 +66,6 @@ BEGIN
|
||||||
WHERE enlazadoSage = FALSE
|
WHERE enlazadoSage = FALSE
|
||||||
AND Asiento <> 1 ;
|
AND Asiento <> 1 ;
|
||||||
|
|
||||||
CALL clientSupplier_add(vCompanyFk);
|
|
||||||
CALL pgc_add(vCompanyFk);
|
|
||||||
CALL invoiceOut_manager(vYear, vCompanyFk);
|
CALL invoiceOut_manager(vYear, vCompanyFk);
|
||||||
CALL invoiceIn_manager(vYear, vCompanyFk);
|
CALL invoiceIn_manager(vYear, vCompanyFk);
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ BEGIN
|
||||||
)
|
)
|
||||||
SELECT 'EN' TipoEntrada,
|
SELECT 'EN' TipoEntrada,
|
||||||
YEAR(x.FECHA) Ejercicio,
|
YEAR(x.FECHA) Ejercicio,
|
||||||
company_getCode(vCompanyFk) AS CodigoEmpresa,
|
vCompanyCode CodigoEmpresa,
|
||||||
x.ASIEN Asiento,
|
x.ASIEN Asiento,
|
||||||
IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL),
|
IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL),
|
||||||
'D', 'H') CargoAbono,
|
'D', 'H') CargoAbono,
|
||||||
|
@ -291,20 +291,6 @@ BEGIN
|
||||||
WHERE m.CargoAbono = 'D'
|
WHERE m.CargoAbono = 'D'
|
||||||
AND m.enlazadoSage = FALSE;
|
AND m.enlazadoSage = FALSE;
|
||||||
|
|
||||||
-- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación
|
|
||||||
DELETE cp
|
|
||||||
FROM clientesProveedores cp
|
|
||||||
LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta
|
|
||||||
AND mc.enlazadoSage = FALSE
|
|
||||||
WHERE mc.codigoCuenta IS NULL;
|
|
||||||
|
|
||||||
-- Elimina cuentas contables que no se utilizarán en la importación
|
|
||||||
DELETE pc
|
|
||||||
FROM planCuentasPGC pc
|
|
||||||
LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta
|
|
||||||
AND mc.enlazadoSage = FALSE
|
|
||||||
WHERE mc.codigoCuenta IS NULL;
|
|
||||||
|
|
||||||
-- DUAS
|
-- DUAS
|
||||||
UPDATE movConta mci
|
UPDATE movConta mci
|
||||||
JOIN vn.XDiario x ON x.ASIEN = mci.Asiento
|
JOIN vn.XDiario x ON x.ASIEN = mci.Asiento
|
||||||
|
@ -411,5 +397,44 @@ BEGIN
|
||||||
AND importeDivisa > 0
|
AND importeDivisa > 0
|
||||||
AND ImporteAsiento < 0;
|
AND ImporteAsiento < 0;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.clientSupplier
|
||||||
|
(INDEX(idClientSupplier, `type`))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
WITH client AS(
|
||||||
|
SELECT DISTINCT c.id
|
||||||
|
FROM sage.movConta mc
|
||||||
|
JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta
|
||||||
|
WHERE NOT enlazadoSage
|
||||||
|
),supplier AS(
|
||||||
|
SELECT DISTINCT s.id
|
||||||
|
FROM sage.movConta mc
|
||||||
|
JOIN vn.supplier s ON s.account = mc.CodigoCuenta
|
||||||
|
WHERE NOT enlazadoSage
|
||||||
|
)SELECT idClientSupplier, `type`
|
||||||
|
FROM sage.clientSupplier cs
|
||||||
|
WHERE NOT isSync
|
||||||
|
UNION
|
||||||
|
SELECT id, 'C'
|
||||||
|
FROM client
|
||||||
|
UNION
|
||||||
|
SELECT id, 'P'
|
||||||
|
FROM supplier;
|
||||||
|
|
||||||
|
CALL clientSupplier_add(vCompanyFk);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync)
|
||||||
|
SELECT vCompanyCode, `type`, idClientSupplier, FALSE
|
||||||
|
FROM tmp.clientSupplier;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.clientSupplier;
|
||||||
|
|
||||||
|
CALL pgc_add(vCompanyFk);
|
||||||
|
-- Elimina cuentas contables que no se utilizarán en la importación
|
||||||
|
DELETE pc
|
||||||
|
FROM planCuentasPGC pc
|
||||||
|
LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta
|
||||||
|
AND mc.enlazadoSage = FALSE
|
||||||
|
WHERE mc.codigoCuenta IS NULL;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(
|
||||||
|
vCompanyFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Prepara los datos de clientes y proveedores para exportarlos a Sage
|
* Inserta en la tabla sage.clientesProveedores los datos de clientes y proveedores
|
||||||
* @vCompanyFk Empresa dela que se quiere trasladar datos
|
* que se actualizaran o se daran de alta en Sage
|
||||||
|
* @vCompanyFk Id de empresa
|
||||||
|
* @table tmp.clientSupplier(idClientSupplier, `type`)
|
||||||
*/
|
*/
|
||||||
DECLARE vCountryCeutaMelillaFk INT;
|
DECLARE vCountryCeutaMelillaFk INT;
|
||||||
|
DECLARE vCompanyCode INT DEFAULT company_getCode(vCompanyFk);
|
||||||
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
|
DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2);
|
||||||
|
|
||||||
SELECT SiglaNacion INTO vCountryCanariasCode
|
SELECT SiglaNacion INTO vCountryCanariasCode
|
||||||
|
@ -45,7 +50,7 @@ BEGIN
|
||||||
Email1,
|
Email1,
|
||||||
iban)
|
iban)
|
||||||
SELECT
|
SELECT
|
||||||
company_getCode(vCompanyFk),
|
vCompanyCode,
|
||||||
'C',
|
'C',
|
||||||
c.id,
|
c.id,
|
||||||
c.socialName,
|
c.socialName,
|
||||||
|
@ -75,15 +80,14 @@ BEGIN
|
||||||
IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''),
|
IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''),
|
||||||
IFNULL(c.iban, '')
|
IFNULL(c.iban, '')
|
||||||
FROM vn.`client` c
|
FROM vn.`client` c
|
||||||
JOIN clientLastTwoMonths clm ON clm.clientFk = c.id
|
JOIN tmp.clientSupplier cs ON cs.idClientSupplier = c.id
|
||||||
LEFT JOIN vn.country cu ON cu.id = c.countryFk
|
LEFT JOIN vn.country cu ON cu.id = c.countryFk
|
||||||
LEFT JOIN Naciones n ON n.countryFk = cu.id
|
LEFT JOIN Naciones n ON n.countryFk = cu.id
|
||||||
LEFT JOIN vn.province p ON p.id = c.provinceFk
|
LEFT JOIN vn.province p ON p.id = c.provinceFk
|
||||||
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
|
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
|
||||||
WHERE c.isRelevant
|
WHERE cs.type = 'C'
|
||||||
AND clm.companyFk = vCompanyFk
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT company_getCode(vCompanyFk),
|
SELECT vCompanyCode,
|
||||||
'P',
|
'P',
|
||||||
s.id,
|
s.id,
|
||||||
s.name,
|
s.name,
|
||||||
|
@ -107,18 +111,16 @@ BEGIN
|
||||||
IFNULL(s.transactionTypeSageFk, 0),
|
IFNULL(s.transactionTypeSageFk, 0),
|
||||||
IFNULL(s.withholdingSageFk, '0'),
|
IFNULL(s.withholdingSageFk, '0'),
|
||||||
IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''),
|
IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''),
|
||||||
IFNULL(iban, '')
|
IFNULL(sa.iban, '')
|
||||||
FROM vn.supplier s
|
FROM vn.supplier s
|
||||||
JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id
|
JOIN tmp.clientSupplier cs ON cs.idClientSupplier = s.id
|
||||||
LEFT JOIN vn.country co ON co.id = s.countryFk
|
LEFT JOIN vn.country co ON co.id = s.countryFk
|
||||||
LEFT JOIN Naciones n ON n.countryFk = co.id
|
LEFT JOIN Naciones n ON n.countryFk = co.id
|
||||||
LEFT JOIN vn.province p ON p.id = s.provinceFk
|
LEFT JOIN vn.province p ON p.id = s.provinceFk
|
||||||
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
|
LEFT JOIN Provincias pr ON pr.provinceFk = p.id
|
||||||
LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id
|
LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id
|
||||||
LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id
|
LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id
|
||||||
WHERE pl.companyFk = vCompanyFk AND
|
WHERE cs.type = 'P'
|
||||||
s.isActive AND
|
GROUP BY s.id;
|
||||||
s.nif <> ''
|
|
||||||
GROUP BY pl.supplierFk, pl.companyFk;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,190 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`()
|
||||||
|
BEGIN
|
||||||
|
/*
|
||||||
|
* Añade a la tabla greuges todos los cargos necesario y
|
||||||
|
* que luego lo utilizamos para calcular el recobro.
|
||||||
|
*/
|
||||||
|
DECLARE vMonthToRefund INT
|
||||||
|
DEFAULT (SELECT monthsToRefund FROM claimConfig);
|
||||||
|
DECLARE vRecoveryGreugeType INT
|
||||||
|
DEFAULT (SELECT id FROM greugeType WHERE code = 'recovery');
|
||||||
|
DECLARE vManaGreugeType INT
|
||||||
|
DEFAULT (SELECT id FROM greugeType WHERE code = 'mana');
|
||||||
|
DECLARE vClaimGreugeType INT
|
||||||
|
DEFAULT (SELECT id FROM greugeType WHERE code = 'claim');
|
||||||
|
DECLARE vDebtComponentType INT
|
||||||
|
DEFAULT (SELECT id FROM component WHERE code = 'debtCollection');
|
||||||
|
|
||||||
|
IF vMonthToRefund IS NULL
|
||||||
|
OR vRecoveryGreugeType IS NULL
|
||||||
|
OR vManaGreugeType IS NULL
|
||||||
|
OR vClaimGreugeType IS NULL
|
||||||
|
OR vDebtComponentType IS NULL THEN
|
||||||
|
|
||||||
|
CALL util.throw('Required variables not found');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Reclamaciones demasiado sensibles
|
||||||
|
INSERT INTO greuge(
|
||||||
|
shipped,
|
||||||
|
clientFk,
|
||||||
|
`description`,
|
||||||
|
amount,
|
||||||
|
greugeTypeFk,
|
||||||
|
ticketFk
|
||||||
|
)
|
||||||
|
SELECT c.ticketCreated,
|
||||||
|
c.clientFk,
|
||||||
|
CONCAT('Claim ', c.id,' : ', s.concept),
|
||||||
|
ROUND(-1 * ((c.responsibility - 1) / 4) * s.quantity *
|
||||||
|
s.price * (100 - s.discount) / 100, 2),
|
||||||
|
vClaimGreugeType,
|
||||||
|
s.ticketFk
|
||||||
|
FROM sale s
|
||||||
|
JOIN claimEnd ce ON ce.saleFk = s.id
|
||||||
|
JOIN claimDestination cd ON cd.id = ce.claimDestinationFk
|
||||||
|
JOIN claim c ON c.id = ce.claimFk
|
||||||
|
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||||
|
WHERE cd.description NOT IN ('Bueno', 'Corregido')
|
||||||
|
AND NOT ce.isGreuge
|
||||||
|
AND cs.code = 'resolved';
|
||||||
|
|
||||||
|
-- Reclamaciones que pasan a Maná
|
||||||
|
INSERT INTO greuge(
|
||||||
|
shipped,
|
||||||
|
clientFk,
|
||||||
|
`description`,
|
||||||
|
amount,
|
||||||
|
greugeTypeFk,
|
||||||
|
ticketFk
|
||||||
|
)
|
||||||
|
SELECT c.ticketCreated,
|
||||||
|
c.clientFk,
|
||||||
|
CONCAT('Claim_mana ', c.id,' : ', s.concept),
|
||||||
|
ROUND(((c.responsibility - 1) / 4) * s.quantity *
|
||||||
|
s.price * (100 - s.discount) / 100, 2),
|
||||||
|
vManaGreugeType,
|
||||||
|
s.ticketFk
|
||||||
|
FROM sale s
|
||||||
|
JOIN claimEnd ce ON ce.saleFk = s.id
|
||||||
|
JOIN claimDestination cd ON cd.id = ce.claimDestinationFk
|
||||||
|
JOIN claim c ON c.id = ce.claimFk
|
||||||
|
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||||
|
WHERE cd.description NOT IN ('Bueno', 'Corregido')
|
||||||
|
AND NOT ce.isGreuge
|
||||||
|
AND cs.code = 'resolved'
|
||||||
|
AND c.isChargedToMana;
|
||||||
|
|
||||||
|
-- Marcamos para no repetir
|
||||||
|
UPDATE claimEnd ce
|
||||||
|
JOIN claimDestination cd ON cd.id = ce.claimDestinationFk
|
||||||
|
JOIN claim c ON c.id = ce.claimFk
|
||||||
|
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||||
|
SET ce.isGreuge = TRUE
|
||||||
|
WHERE cd.description NOT IN ('Bueno', 'Corregido')
|
||||||
|
AND NOT ce.isGreuge
|
||||||
|
AND cs.code = 'resolved';
|
||||||
|
|
||||||
|
-- Recobros
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tTicketList
|
||||||
|
(PRIMARY KEY (ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT DISTINCT s.ticketFk
|
||||||
|
FROM saleComponent sc
|
||||||
|
JOIN sale s ON sc.saleFk = s.id
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
JOIN ticketLastState ts ON ts.ticketFk = t.id
|
||||||
|
JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk
|
||||||
|
JOIN state st ON st.id = tt.stateFk
|
||||||
|
JOIN alertLevel al ON al.id = st.alertLevel
|
||||||
|
WHERE sc.componentFk = vDebtComponentType
|
||||||
|
AND NOT sc.isGreuge
|
||||||
|
AND t.shipped >= (SELECT minShipped FROM claimConfig)
|
||||||
|
AND t.shipped < util.VN_CURDATE()
|
||||||
|
AND al.code = 'DELIVERED';
|
||||||
|
|
||||||
|
DELETE g.*
|
||||||
|
FROM greuge g
|
||||||
|
JOIN tTicketList t ON t.ticketFk = g.ticketFk
|
||||||
|
WHERE g.greugeTypeFk = vRecoveryGreugeType;
|
||||||
|
|
||||||
|
INSERT INTO greuge(
|
||||||
|
clientFk,
|
||||||
|
`description`,
|
||||||
|
amount,
|
||||||
|
shipped,
|
||||||
|
greugeTypeFk,
|
||||||
|
ticketFk
|
||||||
|
)
|
||||||
|
SELECT t.clientFk,
|
||||||
|
'Recobro',
|
||||||
|
- ROUND(SUM(sc.value * s.quantity), 2) dif,
|
||||||
|
DATE(t.shipped),
|
||||||
|
vRecoveryGreugeType,
|
||||||
|
tl.ticketFk
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
JOIN tTicketList tl ON tl.ticketFk = t.id
|
||||||
|
JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
|
AND sc.componentFk = vDebtComponentType
|
||||||
|
GROUP BY t.id
|
||||||
|
HAVING ABS(dif) > 1;
|
||||||
|
|
||||||
|
UPDATE saleComponent sc
|
||||||
|
JOIN sale s ON s.id = sc.saleFk
|
||||||
|
JOIN tTicketList tl ON tl.ticketFk = s.ticketFk
|
||||||
|
SET sc.isGreuge = TRUE
|
||||||
|
WHERE sc.componentFk = vDebtComponentType;
|
||||||
|
|
||||||
|
REPLACE claimRatio(
|
||||||
|
clientFk,
|
||||||
|
yearSale,
|
||||||
|
claimAmount,
|
||||||
|
claimingRate,
|
||||||
|
priceIncreasing
|
||||||
|
)
|
||||||
|
SELECT c.id,
|
||||||
|
12 * cac.invoiced,
|
||||||
|
totalClaims,
|
||||||
|
ROUND(totalClaims / (12 * cac.invoiced), 4),
|
||||||
|
0
|
||||||
|
FROM client c
|
||||||
|
LEFT JOIN bs.clientAnnualConsumption cac ON cac.clientFk = c.id
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT c.clientFk,
|
||||||
|
ROUND(SUM(-1 * ((c.responsibility - 1) / 4) *
|
||||||
|
s.quantity * s.price * (100 - s.discount)
|
||||||
|
/ 100)) totalClaims
|
||||||
|
FROM sale s
|
||||||
|
JOIN claimEnd ce ON ce.saleFk = s.id
|
||||||
|
JOIN claimDestination cd ON cd.id = ce.claimDestinationFk
|
||||||
|
JOIN claim c ON c.id = ce.claimFk
|
||||||
|
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||||
|
WHERE cd.description NOT IN ('Bueno', 'Corregido')
|
||||||
|
AND cs.code = 'resolved'
|
||||||
|
AND c.ticketCreated >= util.VN_CURDATE() - INTERVAL 1 YEAR
|
||||||
|
GROUP BY c.clientFk
|
||||||
|
) sub ON sub.clientFk = c.id;
|
||||||
|
|
||||||
|
-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
|
||||||
|
UPDATE claimRatio cr
|
||||||
|
JOIN (
|
||||||
|
SELECT clientFk, IFNULL(SUM(amount), 0) greuge
|
||||||
|
FROM greuge
|
||||||
|
WHERE shipped <= util.VN_CURDATE()
|
||||||
|
GROUP BY clientFk
|
||||||
|
) sub ON sub.clientFk = cr.clientFk
|
||||||
|
SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) /
|
||||||
|
(IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3));
|
||||||
|
|
||||||
|
-- Protección neonatos
|
||||||
|
UPDATE claimRatio cr
|
||||||
|
JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk
|
||||||
|
SET cr.priceIncreasing = 0,
|
||||||
|
cr.claimingRate = 0
|
||||||
|
WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tTicketList;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(
|
||||||
|
vDuaFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Genera el asiento de un DUA y marca las entradas como confirmadas
|
* Genera el asiento de un DUA y marca las entradas como confirmadas
|
||||||
|
@ -29,9 +31,7 @@ BEGIN
|
||||||
SET ii.booked = IFNULL(ii.booked, d.booked),
|
SET ii.booked = IFNULL(ii.booked, d.booked),
|
||||||
ii.operated = IFNULL(ii.operated, d.operated),
|
ii.operated = IFNULL(ii.operated, d.operated),
|
||||||
ii.issued = IFNULL(ii.issued, d.issued),
|
ii.issued = IFNULL(ii.issued, d.issued),
|
||||||
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried),
|
ii.bookEntried = IFNULL(ii.bookEntried, d.bookEntried)
|
||||||
e.isBooked = TRUE,
|
|
||||||
e.isConfirmed = TRUE
|
|
||||||
WHERE d.id = vDuaFk;
|
WHERE d.id = vDuaFk;
|
||||||
|
|
||||||
SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
|
SELECT ASIEN INTO vBookEntry FROM dua WHERE id = vDuaFk;
|
||||||
|
@ -39,7 +39,7 @@ BEGIN
|
||||||
IF vBookEntry IS NULL THEN
|
IF vBookEntry IS NULL THEN
|
||||||
SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear
|
SELECT YEAR(IFNULL(ii.bookEntried, d.bookEntried)) INTO vFiscalYear
|
||||||
FROM invoiceIn ii
|
FROM invoiceIn ii
|
||||||
JOIN entry e ON e.invoiceInFk = ii.id
|
JOIN `entry` e ON e.invoiceInFk = ii.id
|
||||||
JOIN duaEntry de ON de.entryFk = e.id
|
JOIN duaEntry de ON de.entryFk = e.id
|
||||||
JOIN dua d ON d.id = de.duaFk
|
JOIN dua d ON d.id = de.duaFk
|
||||||
WHERE d.id = vDuaFk
|
WHERE d.id = vDuaFk
|
||||||
|
@ -70,5 +70,28 @@ l: LOOP
|
||||||
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
|
JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id
|
||||||
SET ii.isBooked = TRUE
|
SET ii.isBooked = TRUE
|
||||||
WHERE dii.duaFk = vDuaFk;
|
WHERE dii.duaFk = vDuaFk;
|
||||||
|
|
||||||
|
UPDATE `entry` e
|
||||||
|
JOIN (
|
||||||
|
WITH entries AS (
|
||||||
|
SELECT e.id, de.duaFk
|
||||||
|
FROM `entry` e
|
||||||
|
JOIN duaEntry de ON de.entryFk = e.id
|
||||||
|
WHERE de.duaFk = vDuaFk
|
||||||
|
AND (NOT e.isBooked OR NOT e.isConfirmed)
|
||||||
|
),
|
||||||
|
notBookedEntries AS (
|
||||||
|
SELECT e.id
|
||||||
|
FROM duaEntry
|
||||||
|
WHERE duaFk = vDuaFk
|
||||||
|
AND NOT customsValue
|
||||||
|
)
|
||||||
|
SELECT e.id
|
||||||
|
FROM entries e
|
||||||
|
LEFT JOIN notBookedEntries nbe ON nbe.entryFk = e.id
|
||||||
|
WHERE nbe.entryFk IS NULL
|
||||||
|
) sub ON sub.id = e.id
|
||||||
|
SET e.isBooked = TRUE,
|
||||||
|
e.isConfirmed = TRUE;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientUnpaid_beforeInsert`
|
||||||
|
BEFORE INSERT ON `clientUnpaid`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientUnpaid_beforeUpdate`
|
||||||
|
BEFORE UPDATE ON `clientUnpaid`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -3,12 +3,35 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate`
|
||||||
AFTER UPDATE ON `client`
|
AFTER UPDATE ON `client`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN
|
IF NOT (NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN
|
||||||
UPDATE `address` SET isDefaultAddress = FALSE
|
UPDATE `address` SET isDefaultAddress = FALSE
|
||||||
WHERE clientFk = NEW.id;
|
WHERE clientFk = NEW.id;
|
||||||
|
|
||||||
UPDATE `address` SET isDefaultAddress = TRUE
|
UPDATE `address` SET isDefaultAddress = TRUE
|
||||||
WHERE id = NEW.defaultAddressFk;
|
WHERE id = NEW.defaultAddressFk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
IF NEW.id <> OLD.id
|
||||||
|
OR NOT (NEW.provinceFk <=> OLD.provinceFk)
|
||||||
|
OR NOT (NEW.socialName <=> OLD.socialName)
|
||||||
|
OR NOT (NEW.street <=> OLD.street)
|
||||||
|
OR NOT (NEW.accountingAccount <=> OLD.accountingAccount)
|
||||||
|
OR NOT (NEW.isVies <=> OLD.isVies)
|
||||||
|
OR NOT (NEW.fi <=> OLD.fi)
|
||||||
|
OR NOT (NEW.postcode <=> OLD.postcode)
|
||||||
|
OR NOT (NEW.city <=> OLD.city)
|
||||||
|
OR NOT (NEW.countryFk <=> OLD.countryFk)
|
||||||
|
OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk)
|
||||||
|
OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk)
|
||||||
|
OR NOT (NEW.email <=> OLD.email)
|
||||||
|
OR NOT (NEW.iban <=> OLD.iban)
|
||||||
|
OR NOT (NEW.phone <=> OLD.phone)
|
||||||
|
OR NOT (NEW.mobile <=> OLD.mobile) THEN
|
||||||
|
|
||||||
|
UPDATE sage.clientSupplier
|
||||||
|
SET isSync = FALSE
|
||||||
|
WHERE idClientSupplier IN (NEW.id, OLD.id)
|
||||||
|
AND `type` = 'C';
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -65,11 +65,11 @@ BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
|
IF NOT (NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
|
||||||
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
|
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||||
SET NEW.isTaxDataChecked = 0;
|
SET NEW.isTaxDataChecked = 0;
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_afterUpdate`
|
||||||
|
BEFORE UPDATE ON `supplier`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
IF NEW.id <> OLD.id
|
||||||
|
OR NOT (NEW.name <=> OLD.name)
|
||||||
|
OR NOT (NEW.street <=> OLD.street)
|
||||||
|
OR NOT (NEW.account <=> OLD.account)
|
||||||
|
OR NOT (NEW.nif <=> OLD.nif)
|
||||||
|
OR NOT (NEW.isVies <=> OLD.isVies)
|
||||||
|
OR NOT (NEW.provinceFk <=> OLD.provinceFk)
|
||||||
|
OR NOT (NEW.countryFk <=> OLD.countryFk)
|
||||||
|
OR NOT (NEW.postCode <=> OLD.postCode)
|
||||||
|
OR NOT (NEW.city <=> OLD.city)
|
||||||
|
OR NOT (NEW.taxTypeSageFk <=> OLD.taxTypeSageFk)
|
||||||
|
OR NOT (NEW.transactionTypeSageFk <=> OLD.transactionTypeSageFk)
|
||||||
|
OR NOT (NEW.withholdingSageFk <=> OLD.withholdingSageFk) THEN
|
||||||
|
|
||||||
|
UPDATE sage.clientSupplier
|
||||||
|
SET isSync = FALSE
|
||||||
|
WHERE idClientSupplier IN (NEW.id, OLD.id)
|
||||||
|
AND `type` = 'P';
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.';
|
|
@ -0,0 +1,12 @@
|
||||||
|
UPDATE IGNORE bs.nightTask
|
||||||
|
SET `schema` = 'vn',
|
||||||
|
`procedure` = 'claimRatio_add'
|
||||||
|
WHERE `procedure` = 'claim_ratio_routine';
|
||||||
|
|
||||||
|
ALTER TABLE vn.claimConfig
|
||||||
|
ADD monthsToRefund int(11) DEFAULT NULL NULL,
|
||||||
|
ADD minShipped date DEFAULT NULL NULL;
|
||||||
|
|
||||||
|
UPDATE IGNORE vn.claimConfig
|
||||||
|
SET monthsToRefund = 4,
|
||||||
|
minShipped = '2016-10-01';
|
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
CREATE OR REPLACE TABLE sage.clientSupplier (
|
||||||
|
`companyFk` smallint(6) NOT NULL,
|
||||||
|
`type` ENUM('C','P') NOT NULL,
|
||||||
|
`idClientSupplier` INT NOT NULL,
|
||||||
|
`isSync` TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (`companyFk`,`idClientSupplier`,`type`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
|
||||||
|
COMMENT='Clients and suppliers present in Sage and their synchronization status';
|
|
@ -0,0 +1,9 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(15) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear';
|
||||||
|
ALTER TABLE vn.productionConfig ADD sectorToCode varchar(15) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear';
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,14 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelvingBuy_FK;
|
||||||
|
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2;
|
||||||
|
ALTER TABLE vn.itemShelving DROP INDEX itemShelving_UN;
|
||||||
|
|
||||||
|
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE vn.clientUnpaid
|
||||||
|
ADD editorFk INT UNSIGNED NULL,
|
||||||
|
ADD CONSTRAINT ClientUnpaid_editorFk FOREIGN KEY (editorFk)
|
||||||
|
REFERENCES account.`user`(id);
|
|
@ -232,5 +232,6 @@
|
||||||
"Incoterms and Customs agent are required for a non UEE member": "Incoterms and Customs agent are required for a non UEE member",
|
"Incoterms and Customs agent are required for a non UEE member": "Incoterms and Customs agent are required for a non UEE member",
|
||||||
"It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated",
|
"It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated",
|
||||||
"It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated",
|
"It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated",
|
||||||
"Cannot add holidays on this day": "Cannot add holidays on this day"
|
"Cannot add holidays on this day": "Cannot add holidays on this day",
|
||||||
|
"Cannot send mail": "Cannot send mail"
|
||||||
}
|
}
|
|
@ -351,7 +351,7 @@
|
||||||
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
|
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
|
||||||
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas",
|
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas",
|
||||||
"The line could not be marked": "La linea no puede ser marcada",
|
"The line could not be marked": "La linea no puede ser marcada",
|
||||||
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
"Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado",
|
||||||
"They're not your subordinate": "No es tu subordinado/a.",
|
"They're not your subordinate": "No es tu subordinado/a.",
|
||||||
"No results found": "No se han encontrado resultados",
|
"No results found": "No se han encontrado resultados",
|
||||||
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
||||||
|
@ -365,5 +365,6 @@
|
||||||
"You can only have one PDA": "Solo puedes tener un PDA",
|
"You can only have one PDA": "Solo puedes tener un PDA",
|
||||||
"It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF",
|
"It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF",
|
||||||
"It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono",
|
"It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono",
|
||||||
"Payment method is required": "El método de pago es obligatorio"
|
"Payment method is required": "El método de pago es obligatorio",
|
||||||
|
"Cannot send mail": "Não é possível enviar o email"
|
||||||
}
|
}
|
|
@ -359,5 +359,6 @@
|
||||||
"Select ticket or client": "Choisissez un ticket ou un client",
|
"Select ticket or client": "Choisissez un ticket ou un client",
|
||||||
"It was not able to create the invoice": "Il n'a pas été possible de créer la facture",
|
"It was not able to create the invoice": "Il n'a pas été possible de créer la facture",
|
||||||
"It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
"It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
||||||
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré"
|
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré",
|
||||||
|
"Cannot send mail": "Impossible d'envoyer le mail"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,11 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.setUnverifiedPassword = async(id, pass, options) => {
|
Self.setUnverifiedPassword = async(id, pass, options) => {
|
||||||
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);
|
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);
|
||||||
if (emailVerified) throw new ForbiddenError('This password can only be changed by the user themselves');
|
if (emailVerified) {
|
||||||
|
throw new ForbiddenError(
|
||||||
|
'Through this procedure, it is not possible to modify the password of users with verified email'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await models.VnUser.setPassword(id, pass, options);
|
await models.VnUser.setPassword(id, pass, options);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: unpaid
|
||||||
|
columns:
|
||||||
|
clientFk: client
|
||||||
|
dated: date
|
||||||
|
amount: amount
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: impagado
|
||||||
|
columns:
|
||||||
|
clientFk: cliente
|
||||||
|
dated: fecha
|
||||||
|
amount: cantidad
|
|
@ -1,6 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "ClientUnpaid",
|
"name": "ClientUnpaid",
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
|
"mixins": {
|
||||||
|
"Loggable": true
|
||||||
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "clientUnpaid"
|
"table": "clientUnpaid"
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getListItemNewer', {
|
||||||
|
description:
|
||||||
|
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'shelvingFk',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'Shelving code'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'parking',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'Parking code'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: 'Array',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getListItemNewer`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getListItemNewer = async(shelvingFk, parking, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const [isParkingToReview] = await Self.rawSql(`
|
||||||
|
SELECT COUNT(p.id) parkingToReview
|
||||||
|
FROM vn.parking p
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE p.code = ? AND s.code = pc.sectorToCode;`,
|
||||||
|
[parking], myOptions);
|
||||||
|
|
||||||
|
if (isParkingToReview['parkingToReview'] < 1) return [];
|
||||||
|
|
||||||
|
const result = await Self.rawSql(`
|
||||||
|
WITH tItemShelving AS(
|
||||||
|
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
|
||||||
|
FROM vn.itemShelving is2
|
||||||
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
||||||
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode
|
||||||
|
), tItemInSector AS (
|
||||||
|
SELECT is2.itemFk, is2.created, is2.shelvingFk
|
||||||
|
FROM vn.itemShelving is2
|
||||||
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
||||||
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE is2.shelvingFk <> ?
|
||||||
|
AND s.code = pc.sectorFromCode)
|
||||||
|
SELECT ti.itemFK, tis.shelvingFk
|
||||||
|
FROM tItemShelving ti
|
||||||
|
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`,
|
||||||
|
[shelvingFk, shelvingFk], myOptions);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,63 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('hasItemOlder', {
|
|
||||||
description:
|
|
||||||
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
|
||||||
accessType: 'READ',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'shelvingFkIn',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
description: 'Shelving code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'parking',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Parking code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'shelvingFkOut',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Shelving code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'itemFk',
|
|
||||||
type: 'integer',
|
|
||||||
description: 'Item id'
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/hasItemOlder`,
|
|
||||||
verb: 'GET'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
|
||||||
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
|
|
||||||
|
|
||||||
const myOptions = {};
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
const result = await Self.rawSql(`
|
|
||||||
SELECT COUNT(ish.id) countItemOlder
|
|
||||||
FROM vn.itemShelving ish
|
|
||||||
JOIN (
|
|
||||||
SELECT ish.itemFk, created,shelvingFk
|
|
||||||
FROM vn.itemShelving ish
|
|
||||||
JOIN vn.shelving s ON ish.shelvingFk = s.code
|
|
||||||
WHERE ish.shelvingFk = ?
|
|
||||||
)sub ON sub.itemFK = ish.itemFk
|
|
||||||
JOIN vn.shelving s ON s.code = ish.shelvingFk
|
|
||||||
JOIN vn.parking p ON p.id = s.parkingFk
|
|
||||||
WHERE sub.created > ish.created
|
|
||||||
AND (p.code <> ? OR ? IS NULL)
|
|
||||||
AND (ish.shelvingFk <> ? OR ? IS NULL)
|
|
||||||
AND (ish.itemFk <> ? OR ? IS NULL)`,
|
|
||||||
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
|
|
||||||
return result[0]['countItemOlder'] > 0;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('itemShelving getListItemNewer()', () => {
|
||||||
|
it('should return true because there is an older item', async() => {
|
||||||
|
const shelving = 'NCC';
|
||||||
|
const parking = 'A-47-1';
|
||||||
|
|
||||||
|
const sectorCamHighCode = 'CAMARA SECTOR D';
|
||||||
|
const sectorCamCode = 'NAVE ALGEMESI';
|
||||||
|
|
||||||
|
const sectorCamCodeHighId = 1;
|
||||||
|
const sectorCamCodeId = 9991;
|
||||||
|
|
||||||
|
const tx = await models.Sector.beginTransaction({});
|
||||||
|
const myOptions = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions);
|
||||||
|
await sectorHighCam.updateAttributes({
|
||||||
|
code: sectorCamHighCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions);
|
||||||
|
await sectorCam.updateAttributes({
|
||||||
|
code: sectorCamCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const config = await models.ProductionConfig.findOne();
|
||||||
|
|
||||||
|
await config.updateAttributes({
|
||||||
|
sectorToCode: sectorCamHighCode,
|
||||||
|
sectorFromCode: sectorCamCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,45 +0,0 @@
|
||||||
|
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('itemShelving hasOlder()', () => {
|
|
||||||
it('should return false because there are not older items', async() => {
|
|
||||||
const shelvingFkIn = 'GVC';
|
|
||||||
const shelvingFkOut = 'HEJ';
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
|
|
||||||
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false because there are not older items in parking', async() => {
|
|
||||||
const shelvingFkIn = 'HEJ';
|
|
||||||
const parking = '700-01';
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
|
|
||||||
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true because there is an older item', async() => {
|
|
||||||
const shelvingFkIn = 'UXN';
|
|
||||||
const shelvingFkOut = 'PCC';
|
|
||||||
const parking = 'A-01-1';
|
|
||||||
const itemFk = 1;
|
|
||||||
|
|
||||||
const tx = await models.ItemShelving.beginTransaction({});
|
|
||||||
const myOptions = {transaction: tx};
|
|
||||||
const filter = {where: {shelvingFk: shelvingFkOut}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
|
|
||||||
await itemShelvingBefore.updateAttributes({
|
|
||||||
itemFk: itemFk
|
|
||||||
}, myOptions);
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
|
|
||||||
|
|
||||||
expect(result).toBe(true);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -4,5 +4,5 @@ module.exports = Self => {
|
||||||
require('../methods/item-shelving/getInventory')(Self);
|
require('../methods/item-shelving/getInventory')(Self);
|
||||||
require('../methods/item-shelving/getAlternative')(Self);
|
require('../methods/item-shelving/getAlternative')(Self);
|
||||||
require('../methods/item-shelving/updateFromSale')(Self);
|
require('../methods/item-shelving/updateFromSale')(Self);
|
||||||
require('../methods/item-shelving/hasItemOlder')(Self);
|
require('../methods/item-shelving/getListItemNewer')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,21 +20,4 @@ module.exports = Self => {
|
||||||
require('../methods/route/cmrEmail')(Self);
|
require('../methods/route/cmrEmail')(Self);
|
||||||
require('../methods/route/getExpeditionSummary')(Self);
|
require('../methods/route/getExpeditionSummary')(Self);
|
||||||
require('../methods/route/getByWorker')(Self);
|
require('../methods/route/getByWorker')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
|
||||||
message: 'Distance must be lesser than 4000'
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.validate('kmEnd', validateDistance, {
|
|
||||||
message: 'Distance must be lesser than 4000'
|
|
||||||
});
|
|
||||||
|
|
||||||
function validateDistance(err) {
|
|
||||||
if (this.kmEnd) {
|
|
||||||
const routeTotalKm = this.kmEnd - this.kmStart;
|
|
||||||
const routeMaxKm = 4000;
|
|
||||||
if (routeTotalKm > routeMaxKm || this.kmStart > this.kmEnd)
|
|
||||||
err();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -145,15 +145,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
const newTicket = await models.Ticket.new(ctx, myOptions);
|
const newTicket = await models.Ticket.new(ctx, myOptions);
|
||||||
|
|
||||||
const ticketRefund = await models.TicketRefund.findOne({
|
|
||||||
where: {refundTicketFk: ticketId}
|
|
||||||
}, myOptions);
|
|
||||||
if (negative && (withWarehouse || !ticketRefund?.id)) {
|
|
||||||
await models.TicketRefund.create({
|
await models.TicketRefund.create({
|
||||||
originalTicketFk: ticketId,
|
originalTicketFk: ticketId,
|
||||||
refundTicketFk: newTicket.id
|
refundTicketFk: newTicket.id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
|
||||||
|
|
||||||
return newTicket;
|
return newTicket;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket state()', () => {
|
xdescribe('ticket state()', () => {
|
||||||
const salesPersonId = 18;
|
const salesPersonId = 18;
|
||||||
const employeeId = 1;
|
const employeeId = 1;
|
||||||
const productionId = 49;
|
const productionId = 49;
|
||||||
|
@ -113,6 +113,7 @@ describe('ticket state()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
|
||||||
const ticket = await models.Ticket.create(sampleTicket, options);
|
const ticket = await models.Ticket.create(sampleTicket, options);
|
||||||
activeCtx.accessToken.userId = salesPersonId;
|
activeCtx.accessToken.userId = salesPersonId;
|
||||||
const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options);
|
const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options);
|
||||||
|
@ -124,6 +125,7 @@ describe('ticket state()', () => {
|
||||||
expect(resAssigned.userFk).toBe(paramsAssigned.userFk);
|
expect(resAssigned.userFk).toBe(paramsAssigned.userFk);
|
||||||
expect(resAssigned.userFk).toBe(1);
|
expect(resAssigned.userFk).toBe(1);
|
||||||
expect(resAssigned.id).toBeDefined();
|
expect(resAssigned.id).toBeDefined();
|
||||||
|
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
|
||||||
|
|
||||||
activeCtx.accessToken.userId = productionId;
|
activeCtx.accessToken.userId = productionId;
|
||||||
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
||||||
|
@ -183,5 +185,37 @@ describe('ticket state()', () => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not call sendCheckingPresence if sales.length is 0 because quantities are equal', async() => {
|
||||||
|
const tx = await models.TicketTracking.beginTransaction({});
|
||||||
|
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ticket = await models.Ticket.create(sampleTicket, options);
|
||||||
|
activeCtx.accessToken.userId = productionId;
|
||||||
|
|
||||||
|
const sampleSale = {
|
||||||
|
ticketFk: ticket.id,
|
||||||
|
itemFk: 1,
|
||||||
|
concept: 'Test',
|
||||||
|
quantity: 10,
|
||||||
|
originalQuantity: 10
|
||||||
|
};
|
||||||
|
await models.Sale.create(sampleSale, options);
|
||||||
|
|
||||||
|
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
||||||
|
const params = {ticketFk: ticket.id, stateFk: packedState.id};
|
||||||
|
|
||||||
|
await models.Ticket.state(ctx, params, options);
|
||||||
|
|
||||||
|
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
let newStateOrder;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -41,16 +40,11 @@ module.exports = Self => {
|
||||||
throw new UserError('State cannot be blank');
|
throw new UserError('State cannot be blank');
|
||||||
|
|
||||||
if (params.stateFk) {
|
if (params.stateFk) {
|
||||||
const {code, order} = await models.State.findById(
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
params.stateFk,
|
|
||||||
{fields: ['code', 'order']},
|
|
||||||
myOptions);
|
|
||||||
params.code = code;
|
params.code = code;
|
||||||
newStateOrder = order;
|
|
||||||
} else {
|
} else {
|
||||||
const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
||||||
params.stateFk = id;
|
params.stateFk = id;
|
||||||
newStateOrder = order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
|
@ -70,59 +64,7 @@ module.exports = Self => {
|
||||||
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
||||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(params.ticketFk, {
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
||||||
include: [{
|
|
||||||
relation: 'client',
|
|
||||||
scope: {
|
|
||||||
fields: ['salesPersonFk']
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
fields: ['id', 'clientFk']
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const salesPersonFk = ticket.client().salesPersonFk;
|
|
||||||
const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}});
|
|
||||||
|
|
||||||
if (salesPersonFk && newStateOrder >= stateChecked.order) {
|
|
||||||
const sales = await Self.rawSql(`
|
|
||||||
SELECT DISTINCT s.id,
|
|
||||||
s.itemFk,
|
|
||||||
s.concept,
|
|
||||||
s.originalQuantity AS oldQuantity,
|
|
||||||
s.quantity AS newQuantity
|
|
||||||
FROM vn.sale s
|
|
||||||
WHERE s.ticketFk = ?
|
|
||||||
AND s.originalQuantity IS NOT NULL
|
|
||||||
AND s.originalQuantity <> s.quantity
|
|
||||||
`, [params.ticketFk], myOptions);
|
|
||||||
|
|
||||||
if (sales.length) {
|
|
||||||
let changes = '';
|
|
||||||
const url = await models.Url.getUrl();
|
|
||||||
const $t = ctx.req.__;
|
|
||||||
for (let sale of sales) {
|
|
||||||
changes += `\r\n-` + $t('Changes in sales', {
|
|
||||||
itemId: sale.itemFk,
|
|
||||||
concept: sale.concept,
|
|
||||||
oldQuantity: sale.oldQuantity,
|
|
||||||
newQuantity: sale.newQuantity,
|
|
||||||
itemUrl: `${url}item/${sale.itemFk}/summary`
|
|
||||||
});
|
|
||||||
const currentSale = await models.Sale.findById(sale.id, null, myOptions);
|
|
||||||
await currentSale.updateAttributes({
|
|
||||||
originalQuantity: currentSale.quantity
|
|
||||||
}, myOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = $t('Changed sale quantity', {
|
|
||||||
ticketId: ticket.id,
|
|
||||||
changes: changes,
|
|
||||||
ticketUrl: `${url}ticket/${ticket.id}/sale`
|
|
||||||
});
|
|
||||||
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);
|
|
||||||
|
|
||||||
const ticketTracking = await models.TicketTracking.findOne({
|
const ticketTracking = await models.TicketTracking.findOne({
|
||||||
where: {ticketFk: params.ticketFk},
|
where: {ticketFk: params.ticketFk},
|
||||||
|
|
|
@ -42,7 +42,9 @@ describe('worker setPassword()', () => {
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toEqual(`This password can only be changed by the user themselves`);
|
expect(e.message).toEqual(
|
||||||
|
'Through this procedure, it is not possible to modify the password of users with verified email'
|
||||||
|
);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
? 'Click to allow the user to be disabled'
|
? 'Click to allow the user to be disabled'
|
||||||
: 'Click to exclude the user from getting disabled'}}
|
: 'Click to exclude the user from getting disabled'}}
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item ng-if="!$ctrl.worker.user.emailVerified && $ctrl.vnConfig.storage.currentUserWorkerId !=$ctrl.worker.id" ng-click="setPassword.show()" translate>
|
<vn-item ng-click="setPassword.show()" translate>
|
||||||
Change password
|
Change password
|
||||||
</vn-item>
|
</vn-item>
|
||||||
</slot-menu>
|
</slot-menu>
|
||||||
|
|
|
@ -2,6 +2,7 @@ const path = require('path');
|
||||||
const smtp = require('./smtp');
|
const smtp = require('./smtp');
|
||||||
const Component = require('./component');
|
const Component = require('./component');
|
||||||
const Report = require('./report');
|
const Report = require('./report');
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
if (!process.env.OPENSSL_CONF)
|
if (!process.env.OPENSSL_CONF)
|
||||||
process.env.OPENSSL_CONF = '/etc/ssl/';
|
process.env.OPENSSL_CONF = '/etc/ssl/';
|
||||||
|
@ -9,7 +10,6 @@ if (!process.env.OPENSSL_CONF)
|
||||||
class Email extends Component {
|
class Email extends Component {
|
||||||
constructor(name, args) {
|
constructor(name, args) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,11 @@ class Email extends Component {
|
||||||
force: options.force
|
force: options.force
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
return await smtp.send(mailOptions);
|
return await smtp.send(mailOptions);
|
||||||
|
} catch (error) {
|
||||||
|
throw new UserError('Cannot send mail');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue