7299_testToMaster #2411

Merged
alexm merged 342 commits from 7299_testToMaster into master 2024-05-07 05:30:42 +00:00
12 changed files with 140 additions and 215 deletions
Showing only changes of commit 800fa36d04 - Show all commits

View File

@ -1973,6 +1973,15 @@ INSERT INTO `vn`.`ticketService`(`id`, `description`, `quantity`, `price`, `taxC
(4, 'Documentos', 1, 2.00, 1, 9, 1),
(5, 'Documentos', 1, 2.00, 1, 8, 1);
INSERT INTO `pbx`.`config` (id,defaultPrefix)
VALUES (1,'0034');
INSERT INTO `pbx`.`prefix` (country, prefix)
VALUES
('es', '0034'),
('fr', '0033'),
('pt', '00351');
INSERT INTO `pbx`.`sip`(`user_id`, `extension`)
VALUES
(1, 1010),
@ -3736,18 +3745,3 @@ INSERT INTO vn.ticketLog (originFk,userFk,`action`,creationDate,changedModel,new
INSERT INTO `vn`.`supplierDms`(`supplierFk`, `dmsFk`, `editorFk`)
VALUES
(1, 10, 9);
INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,valueDated,amount,concept,debitCredit,calculatedCode,created)
VALUES
(241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',19.36,'BEL 1','debit','2','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-07 00:00:00.000',30226.43,'BEL 2','debit','1','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',118.81,'RCBO','debit','10','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',150.03,'TJ','debit','12','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',150.03,'TJ','debit','12','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',2149.71,'RCBO.AMAZON','debit','122','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',3210.5,'RCBO.VOLVO','debit','121','2023-12-14 08:39:53.000'),
(241,'2023-12-13 00:00:00.000','2023-12-13 00:00:00.000',6513.7,'RCBO.ENERPLUS','debit','120','2023-12-14 08:39:53.000');
INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
VALUES
(1, 1);

View File

@ -0,0 +1,35 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_getRisk`(
vDate DATE
)
BEGIN
/**
* Retorna el riesgo de los clientes activos.
*
* @param vDate Fecha a calcular
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt
(PRIMARY KEY (clientFk))
ENGINE = MEMORY
SELECT id clientFk
FROM client
WHERE isActive;
CALL client_getDebt(vDate);
SELECT c.socialName,
r.clientFk,
c.credit,
CAST(r.risk AS DECIMAL (10,2)) risk,
CAST(c.credit - r.risk AS DECIMAL (10,2)) difference,
co.country
FROM client c
JOIN tmp.risk r ON r.clientFk = c.id
JOIN country co ON co.id = c.countryFk
GROUP BY c.id;
DROP TEMPORARY TABLE
tmp.risk,
tmp.clientGetDebt;
END$$
DELIMITER ;

View File

@ -1,42 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`()
BEGIN
/**
* Devuelve el riesgo de los clientes que estan asegurados
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.client_list
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT * FROM (
SELECT cc.client Id_Cliente, ci.grade
FROM creditClassification cc
JOIN creditInsurance ci ON cc.id = ci.creditClassification
WHERE dateEnd IS NULL
ORDER BY ci.creationDate DESC
LIMIT 10000000000000000000) t1
GROUP BY Id_Cliente;
CALL vn2008.risk_vs_client_list(util.VN_CURDATE());
SELECT
c.id,
c.name,
c.credit clientCredit,
c.creditInsurance solunion,
CAST(r.risk AS DECIMAL(10,0)) risk,
CAST(c.creditInsurance - r.risk AS DECIMAL(10,0)) riskAlive,
cac.invoiced billedAnnually,
c.dueDay,
ci.grade,
c2.country
FROM tmp.client_list ci
LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.Id_Cliente
JOIN client c ON c.id = ci.Id_Cliente
JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk
JOIN country c2 ON c2.id = c.countryFk
GROUP BY c.id;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
END$$
DELIMITER ;

View File

@ -233,8 +233,6 @@ BEGIN
UPDATE config SET inventoried = vInventoryDate;
SET @isModeInventory := FALSE;
CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete
(INDEX(entryId)) ENGINE = MEMORY
SELECT e.id entryId,
@ -262,6 +260,8 @@ BEGIN
FROM travel t
JOIN tEntryToDelete tmp ON tmp.travelId = t.id;
SET @isModeInventory := FALSE;
DROP TEMPORARY TABLE IF EXISTS tEntryToDelete;
COMMIT;

View File

@ -1,29 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
CREATE TEMPORARY TABLE tmp.client_list
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT id Id_Cliente, null grade FROM vn.client;
CALL vn2008.risk_vs_client_list(maxRiskDate);
SELECT
c.RazonSocial,
c.Id_Cliente,
c.Credito,
CAST(r.risk as DECIMAL (10,2)) risk,
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
c.Id_Pais
FROM
vn2008.Clientes c
JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente
JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente
GROUP BY c.Id_cliente;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
END$$
DELIMITER ;

View File

@ -29,7 +29,6 @@ BEGIN
JOIN province p ON p.id = a.provinceFk
JOIN country co ON co.id = p.countryFk
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
JOIN warehouse w ON w.id = t.warehouseFk
JOIN company com ON com.id = t.companyFk
JOIN client c2 ON c2.id = com.clientFk
@ -38,12 +37,10 @@ BEGIN
LEFT JOIN route r ON r.id = t.routeFk
LEFT JOIN worker wo ON wo.id = r.workerFk
LEFT JOIN vehicle v ON v.id = r.vehicleFk
WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE())
AND al.code IN ('PACKED', 'DELIVERED')
WHERE al.code IN ('PACKED', 'DELIVERED')
AND co.code <> 'ES'
AND am.name <> 'ABONO'
AND w.code = 'ALG'
AND dm.code = 'DELIVERY'
AND t.id = vSelf
GROUP BY t.id;

View File

@ -1,84 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`risk_vs_client_list`(maxRiskDate DATE)
BEGIN
/**
* Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list
*
* @deprecated usar vn.client_getDebt
* @param maxRiskDate Fecha maxima de los registros
* @return table tmp.risk
*/
DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(util.VN_CURDATE()) - 60, util.VN_CURDATE());
DECLARE endingDate DATETIME;
DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
SET maxRiskDate = IFNULL(maxRiskDate, util.VN_CURDATE());
SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
CREATE TEMPORARY TABLE tmp.client_list_2
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT *
FROM tmp.client_list;
DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
CREATE TEMPORARY TABLE tmp.client_list_3
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT *
FROM tmp.client_list;
DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar;
CREATE TEMPORARY TABLE tmp.tickets_sin_facturar
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT t.Id_Cliente, floor(IF(cl.isVies, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total
FROM Movimientos m
JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
JOIN vn.client cl ON cl.id = t.Id_Cliente
WHERE Factura IS NULL
AND Fecha BETWEEN startingDate AND endingDate
GROUP BY t.Id_Cliente;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
CREATE TEMPORARY TABLE tmp.risk
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo
FROM Clientes c
JOIN (
SELECT clientFk, SUM(amount) amount,SUM(amount) saldo
FROM vn.clientRisk
JOIN tmp.client_list on Id_Cliente = clientFk
GROUP BY clientFk
UNION ALL
SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
FROM Recibos
JOIN tmp.client_list_2 using(Id_Cliente)
WHERE Fechacobro > endingDate
GROUP BY Id_Cliente
UNION ALL
SELECT Id_Cliente, total,0
FROM tmp.tickets_sin_facturar
UNION ALL
SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
FROM hedera.tpvTransaction t
JOIN tmp.client_list_3 on Id_Cliente = t.clientFk
WHERE t.receiptFk IS NULL
AND t.status = 'ok'
GROUP BY t.clientFk
) t ON c.Id_Cliente = t.clientFk
WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
DELETE r.*
FROM tmp.risk r
JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
WHERE IFNULL(r.saldo,0) < 10
AND r.risk <= MAX_RISK_ALLOWED
AND pm.`name` = 'TARJETA';
END$$
DELIMITER ;

View File

@ -0,0 +1,35 @@
CREATE TABLE IF NOT EXISTS pbx.prefix (
country CHAR(2) NOT NULL COMMENT 'Country code',
prefix varchar(100) NOT NULL COMMENT 'Country prefix',
CONSTRAINT prefix_pk PRIMARY KEY (country)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
ALTER TABLE pbx.config
CHANGE countryPrefix defaultPrefix varchar(20)
CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
ALTER TABLE pbx.config DROP COLUMN IF EXISTS sundayFestive;
CREATE TABLE IF NOT EXISTS pbx.holiday (
id INT UNSIGNED auto_increment NOT NULL,
country CHAR(2) NOT NULL,
`day` DATE NOT NULL,
CONSTRAINT holiday_pk PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
CREATE UNIQUE INDEX holiday_country_IDX USING BTREE ON pbx.holiday (country,`day`);
ALTER TABLE pbx.schedule
CHANGE timeStart startTime time NOT NULL,
CHANGE timeEnd endTime time NOT NULL,
DROP FOREIGN KEY schedule_ibfk_1,
DROP COLUMN queue,
ADD country CHAR(2) NOT NULL,
CHANGE weekDay weekDays set('mon','tue','wed','thu','fri','sat','sun') NOT NULL
COMMENT '0 = Monday, 6 = Sunday';

View File

@ -0,0 +1,13 @@
INSERT INTO pbx.prefix (country,prefix)
VALUES ('es','0034');
INSERT INTO pbx.prefix (country,prefix)
VALUES ('fr','0033');
INSERT INTO pbx.prefix (country,prefix)
VALUES ('pt','00351');
INSERT INTO pbx.schedule (weekDays,startTime,endTime,country)
VALUES ('mon,tue,wed,thu,fri,sat,sun','00:00','24:00','es');
INSERT INTO pbx.schedule (weekDays,startTime,endTime,country)
VALUES ('mon,tue,wed,thu,fri,sat,sun','00:00','24:00','fr');
INSERT INTO pbx.schedule (weekDays,startTime,endTime,country)
VALUES ('mon,tue,wed,thu,fri,sat,sun','00:00','24:00','pt');

View File

@ -0,0 +1,5 @@
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_getRisk`()
BEGIN
END;
GRANT EXECUTE ON PROCEDURE vn.client_getRisk TO financialBoss;

View File

@ -98,40 +98,38 @@ module.exports = Self => {
let stmts = [];
const stmt = new ParameterizedSQL(`
SELECT *
FROM (
SELECT t.cmrFk,
t.id ticketFk,
t.routeFk,
co.country,
t.clientFk,
IF(sub.id, TRUE, FALSE) hasCmrDms,
DATE(t.shipped) shipped
FROM ticket t
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN state s ON s.id = ts.stateFk
JOIN alertLevel al ON al.id = s.alertLevel
JOIN client c ON c.id = t.clientFk
JOIN address a ON a.id = t.addressFk
JOIN province p ON p.id = a.provinceFk
JOIN country co ON co.id = p.countryFk
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN (
SELECT td.ticketFk, d.id
FROM ticketDms td
JOIN dms d ON d.id = td.dmsFk
JOIN dmsType dt ON dt.id = d.dmsTypeFk
WHERE dt.name = 'cmr'
) sub ON sub.ticketFk = t.id
WHERE co.code <> 'ES'
AND am.name <> 'ABONO'
AND w.code = 'ALG'
AND dm.code = 'DELIVERY'
AND t.cmrFk
) sub
`);
SELECT *
FROM (
SELECT t.cmrFk,
t.id ticketFk,
t.routeFk,
co.country,
t.clientFk,
IF(sub.id, TRUE, FALSE) hasCmrDms,
DATE(t.shipped) shipped
FROM ticket t
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN state s ON s.id = ts.stateFk
JOIN alertLevel al ON al.id = s.alertLevel
JOIN client c ON c.id = t.clientFk
JOIN address a ON a.id = t.addressFk
JOIN province p ON p.id = a.provinceFk
JOIN country co ON co.id = p.countryFk
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN warehouse w ON w.id = t.warehouseFk
LEFT JOIN (
SELECT td.ticketFk, d.id
FROM ticketDms td
JOIN dms d ON d.id = td.dmsFk
JOIN dmsType dt ON dt.id = d.dmsTypeFk
WHERE dt.name = 'cmr'
) sub ON sub.ticketFk = t.id
WHERE co.code <> 'ES'
AND am.name <> 'ABONO'
AND w.code = 'ALG'
AND t.cmrFk
) sub
`);
stmt.merge(conn.makeSuffix(filter));
const itemsIndex = stmts.push(stmt) - 1;

View File

@ -152,7 +152,10 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
VALUES ('invoicingTicketError', ?)
`, [ticket.id + ' - ' + error]);
// Domain not found
if (error.responseCode == 450) return invalidEmail(ticket);
if (error.responseCode == 450) {
await invalidEmail(ticket);
continue;
}
// Save tickets on a list of failed ids
failedtickets.push({