7199-devToTest_2316 #2287

Merged
alexm merged 169 commits from 7199-devToTest_2316 into test 2024-04-11 06:25:23 +00:00
13 changed files with 251 additions and 238 deletions
Showing only changes of commit d031fef1a0 - Show all commits

View File

@ -5,22 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [24.16.01] - 2024-04-18
## [2414.01] - 2024-04-04 ## [2414.01] - 2024-04-04
### Added
### Changed
### Fixed
## [2408.01] - 2024-02-22 ## [2408.01] - 2024-02-22
### Added
### Changed
### Fixed
## [2406.01] - 2024-02-08 ## [2406.01] - 2024-02-08
### Added ### Added

View File

@ -8,13 +8,16 @@ BEGIN
SELECT rate3 INTO price SELECT rate3 INTO price
FROM vn.priceFixed FROM vn.priceFixed
WHERE itemFk = vItemFk WHERE itemFk = vItemFk
AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1;
SELECT `value` INTO price SELECT `value` INTO price
FROM vn.specialPrice FROM vn.specialPrice
WHERE itemFk = vItemFk WHERE itemFk = vItemFk
AND clientFk = vClientFk ; AND (clientFk = vClientFk OR clientFk IS NULL)
AND started <= util.VN_CURDATE()
AND (ended >= util.VN_CURDATE() OR ended IS NULL)
ORDER BY id DESC LIMIT 1;
RETURN price; RETURN price;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -10,7 +10,7 @@ BEGIN
* Calcula los componentes de los articulos de tmp.ticketLot * Calcula los componentes de los articulos de tmp.ticketLot
* *
* @param vZoneFk para calcular el transporte * @param vZoneFk para calcular el transporte
* @param vAddressFk Consignatario * @param vAddressFk Consignatario
* @param vShipped dia de salida del pedido * @param vShipped dia de salida del pedido
* @param vWarehouseFk warehouse de salida del pedido * @param vWarehouseFk warehouse de salida del pedido
* @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
@ -24,7 +24,20 @@ BEGIN
SELECT clientFk INTO vClientFK SELECT clientFk INTO vClientFK
FROM address FROM address
WHERE id = vAddressFk; WHERE id = vAddressFk;
CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice
(INDEX (itemFk))
ENGINE = MEMORY
SELECT * FROM (
SELECT *
FROM specialPrice
WHERE (clientFk = vClientFk OR clientFk IS NULL)
AND started <= vShipped
AND (ended >= vShipped OR ended IS NULL)
ORDER BY (clientFk = vClientFk) DESC, id DESC
LIMIT 10000000000000000000) t
GROUP BY itemFk;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate
(PRIMARY KEY (itemFk, warehouseFk)) (PRIMARY KEY (itemFk, warehouseFk))
ENGINE = MEMORY ENGINE = MEMORY
@ -36,7 +49,7 @@ BEGIN
IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing,
IFNULL(pf.`grouping`, b.`grouping`) `grouping`, IFNULL(pf.`grouping`, b.`grouping`) `grouping`,
ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, ABS(IFNULL(pf.box, b.groupingMode)) groupingMode,
tl.buyFk, tl.buyFk,
i.typeFk, i.typeFk,
IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping
FROM tmp.ticketLot tl FROM tmp.ticketLot tl
@ -44,8 +57,7 @@ BEGIN
JOIN item i ON i.id = tl.itemFk JOIN item i ON i.id = tl.itemFk
JOIN itemType it ON it.id = i.typeFk JOIN itemType it ON it.id = i.typeFk
JOIN itemCategory ic ON ic.id = it.categoryFk JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN specialPrice sp ON sp.itemFk = i.id LEFT JOIN tSpecialPrice sp ON sp.itemFk = i.id
AND sp.clientFk = vClientFk
LEFT JOIN ( LEFT JOIN (
SELECT * FROM ( SELECT * FROM (
SELECT pf.itemFk, SELECT pf.itemFk,
@ -63,7 +75,7 @@ BEGIN
LIMIT 10000000000000000000 LIMIT 10000000000000000000
) tpf ) tpf
GROUP BY tpf.itemFk, tpf.warehouseFk GROUP BY tpf.itemFk, tpf.warehouseFk
) pf ON pf.itemFk = tl.itemFk ) pf ON pf.itemFk = tl.itemFk
AND pf.warehouseFk = tl.warehouseFk AND pf.warehouseFk = tl.warehouseFk
WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01
AND ic.merchandise AND ic.merchandise
@ -95,10 +107,10 @@ BEGIN
FROM tmp.ticketComponent tc FROM tmp.ticketComponent tc
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk
GROUP BY tc.itemFk, warehouseFk; GROUP BY tc.itemFk, warehouseFk;
-- RECOBRO -- RECOBRO
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT tcb.warehouseFk, tcb.itemFk, c2.id, SELECT tcb.warehouseFk, tcb.itemFk, c2.id,
ROUND(tcb.base * ROUND(tcb.base *
LEAST( LEAST(
MAX(GREATEST(IFNULL(cr.priceIncreasing,0), MAX(GREATEST(IFNULL(cr.priceIncreasing,0),
@ -129,29 +141,29 @@ BEGIN
ROUND(base * wm.pricesModifierRate, 3) manaAuto ROUND(base * wm.pricesModifierRate, 3) manaAuto
FROM tmp.ticketComponentBase tcb FROM tmp.ticketComponentBase tcb
JOIN `client` c on c.id = vClientFk JOIN `client` c on c.id = vClientFk
JOIN workerMana wm ON c.salesPersonFk = wm.workerFk JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
JOIN vn.component c2 ON c2.code = 'autoMana' JOIN vn.component c2 ON c2.code = 'autoMana'
WHERE wm.isPricesModifierActivated WHERE wm.isPricesModifierActivated
HAVING manaAuto <> 0; HAVING manaAuto <> 0;
-- Precios especiales -- Precios especiales
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT tcb.warehouseFk, SELECT tcb.warehouseFk,
tcb.itemFk, tcb.itemFk,
c2.id, c2.id,
GREATEST( GREATEST(
IFNULL(ROUND(tcb.base * c2.tax, 4), 0), IFNULL(ROUND(tcb.base * c2.tax, 4), 0),
IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3 IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3
) cost ) cost
FROM tmp.ticketComponentBase tcb FROM tmp.ticketComponentBase tcb
JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount'
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
JOIN vn.item i ON i.id = tcb.itemFk JOIN vn.item i ON i.id = tcb.itemFk
WHERE sp.value IS NULL WHERE sp.value IS NULL
AND i.supplyResponseFk IS NULL; AND i.supplyResponseFk IS NULL;
-- Individual -- Individual
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT tcb.warehouseFk, SELECT tcb.warehouseFk,
tcb.itemFk, tcb.itemFk,
@ -162,14 +174,14 @@ BEGIN
JOIN vn.client c ON c.id = vClientFk JOIN vn.client c ON c.id = vClientFk
JOIN vn.businessType bt ON bt.code = c.businessTypeFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk
WHERE bt.code = 'individual'; WHERE bt.code = 'individual';
-- Venta por paquetes -- Venta por paquetes
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3
FROM tmp.ticketComponentCalculate tcc FROM tmp.ticketComponentCalculate tcc
JOIN vn.component c2 ON c2.code = 'salePerPackage' JOIN vn.component c2 ON c2.code = 'salePerPackage'
JOIN buy b ON b.id = tcc.buyFk JOIN buy b ON b.id = tcc.buyFk
LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
WHERE sp.value IS NULL; WHERE sp.value IS NULL;
CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id)) CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id))
@ -177,7 +189,7 @@ BEGIN
SELECT vZoneFk id; SELECT vZoneFk id;
CALL zone_getOptionsForShipment(vShipped, TRUE); CALL zone_getOptionsForShipment(vShipped, TRUE);
-- Reparto -- Reparto
INSERT INTO tmp.ticketComponent INSERT INTO tmp.ticketComponent
SELECT tcc.warehouseFK, SELECT tcc.warehouseFK,
@ -191,7 +203,7 @@ BEGIN
JOIN agencyMode am ON am.id = z.agencyModeFk JOIN agencyMode am ON am.id = z.agencyModeFk
JOIN vn.volumeConfig vc JOIN vn.volumeConfig vc
JOIN vn.component c2 ON c2.code = 'delivery' JOIN vn.component c2 ON c2.code = 'delivery'
LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
AND ic.itemFk = tcc.itemFk AND ic.itemFk = tcc.itemFk
HAVING cost <> 0; HAVING cost <> 0;
@ -208,7 +220,7 @@ BEGIN
sp.value - SUM(tcc.cost) sumCost sp.value - SUM(tcc.cost) sumCost
FROM tmp.ticketComponentCopy tcc FROM tmp.ticketComponentCopy tcc
JOIN component c ON c.id = tcc.componentFk JOIN component c ON c.id = tcc.componentFk
JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
JOIN vn.component c2 ON c2.code = 'specialPrices' JOIN vn.component c2 ON c2.code = 'specialPrices'
WHERE c.classRate IS NULL WHERE c.classRate IS NULL
AND tcc.warehouseFk = vWarehouseFk AND tcc.warehouseFk = vWarehouseFk
@ -244,9 +256,9 @@ BEGIN
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price,
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg
FROM tmp.ticketComponentCalculate tcc FROM tmp.ticketComponentCalculate tcc
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 1) = 1 WHERE IFNULL(tcs.classRate, 1) = 1
AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0) AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0)
GROUP BY tcs.warehouseFk, tcs.itemFk; GROUP BY tcs.warehouseFk, tcs.itemFk;
@ -283,12 +295,13 @@ BEGIN
SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000
) t ) t
GROUP BY itemFk, warehouseFk, `grouping`; GROUP BY itemFk, warehouseFk, `grouping`;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE
tmp.ticketComponentCalculate, tmp.ticketComponentCalculate,
tmp.ticketComponentSum, tmp.ticketComponentSum,
tmp.ticketComponentBase, tmp.ticketComponentBase,
tmp.ticketComponentRate, tmp.ticketComponentRate,
tmp.ticketComponentCopy; tmp.ticketComponentCopy,
tSpecialPrice;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -12,7 +12,7 @@ BEGIN
DECLARE v1Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; DECLARE v1Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR;
DECLARE v2Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; DECLARE v2Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR;
DECLARE v4Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; DECLARE v4Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR;
DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR; DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR;
DECLARE vTrashId VARCHAR(15); DECLARE vTrashId VARCHAR(15);
DECLARE vCompanyBlk INT; DECLARE vCompanyBlk INT;
@ -30,8 +30,9 @@ BEGIN
DELETE IGNORE FROM expedition WHERE created < v26Months; DELETE IGNORE FROM expedition WHERE created < v26Months;
DELETE FROM sms WHERE created < v18Months; DELETE FROM sms WHERE created < v18Months;
DELETE FROM saleTracking WHERE created < v1Years; DELETE FROM saleTracking WHERE created < v1Years;
DELETE FROM productionError WHERE dated < v1Years;
DELETE FROM ticketTracking WHERE created < v18Months; DELETE FROM ticketTracking WHERE created < v18Months;
DELETE tobs FROM ticketObservation tobs DELETE tobs FROM ticketObservation tobs
JOIN ticket t ON tobs.ticketFk = t.id JOIN ticket t ON tobs.ticketFk = t.id
WHERE t.shipped < v5Years; WHERE t.shipped < v5Years;
DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < v1Years; DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < v1Years;
@ -113,12 +114,12 @@ BEGIN
FROM travel t FROM travel t
LEFT JOIN entry e ON e.travelFk = t.id LEFT JOIN entry e ON e.travelFk = t.id
WHERE t.shipped < v3Months AND e.travelFk IS NULL; WHERE t.shipped < v3Months AND e.travelFk IS NULL;
UPDATE dms d UPDATE dms d
JOIN dmsType dt ON dt.id = d.dmsTypeFk JOIN dmsType dt ON dt.id = d.dmsTypeFk
SET d.dmsTypeFk = vTrashId SET d.dmsTypeFk = vTrashId
WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH; WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH;
-- borrar entradas sin compras -- borrar entradas sin compras
CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete
SELECT e.* SELECT e.*
@ -136,7 +137,7 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete
SELECT * SELECT *
FROM route r FROM route r
WHERE created < v4Years; WHERE created < v4Years;
UPDATE tRouteToDelete tmp UPDATE tRouteToDelete tmp
JOIN dms d ON d.id = tmp.gestdocFk JOIN dms d ON d.id = tmp.gestdocFk
@ -180,7 +181,7 @@ BEGIN
DELETE FROM mail WHERE creationDate < v2Months; DELETE FROM mail WHERE creationDate < v2Months;
DELETE FROM split WHERE dated < v18Months; DELETE FROM split WHERE dated < v18Months;
DELETE FROM remittance WHERE dated < v18Months; DELETE FROM remittance WHERE dated < v18Months;
CREATE OR REPLACE TEMPORARY TABLE tTicketDelete CREATE OR REPLACE TEMPORARY TABLE tTicketDelete
SELECT DISTINCT tl.originFk ticketFk SELECT DISTINCT tl.originFk ticketFk
FROM ticketLog tl FROM ticketLog tl
@ -189,11 +190,11 @@ BEGIN
FROM ticket t FROM ticket t
JOIN ticketLog tl ON tl.originFk = t.id JOIN ticketLog tl ON tl.originFk = t.id
LEFT JOIN ticketWeekly tw ON tw.ticketFk = t.id LEFT JOIN ticketWeekly tw ON tw.ticketFk = t.id
WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31'
AND t.isDeleted AND t.isDeleted
AND tw.ticketFk IS NULL AND tw.ticketFk IS NULL
GROUP BY t.id GROUP BY t.id
) sub ON sub.ids = tl.id ) sub ON sub.ids = tl.id
WHERE tl.creationDate <= v2Months; WHERE tl.creationDate <= v2Months;
DELETE t DELETE t
FROM ticket t FROM ticket t

View File

@ -7,81 +7,81 @@ BEGIN
* @param vSelf company id * @param vSelf company id
* @param vMonthAgo time interval to be consulted * @param vMonthAgo time interval to be consulted
*/ */
DECLARE vStartingDate DATETIME DEFAULT TIMESTAMPADD (MONTH,- vMonthsAgo,util.VN_CURDATE()); DECLARE vStartingDate DATETIME DEFAULT TIMESTAMPADD (MONTH,- vMonthsAgo,util.VN_CURDATE());
DECLARE vCurrencyEuroFk INT; DECLARE vCurrencyEuroFk INT;
DECLARE vStartDate DATE; DECLARE vStartDate DATE;
DECLARE vInvalidBalances DOUBLE; DECLARE vInvalidBalances DOUBLE;
SELECT dated, invalidBalances INTO vStartDate, vInvalidBalances FROM supplierDebtConfig; SELECT dated, invalidBalances INTO vStartDate, vInvalidBalances FROM supplierDebtConfig;
SELECT id INTO vCurrencyEuroFk FROM currency WHERE code = 'EUR'; SELECT id INTO vCurrencyEuroFk FROM currency WHERE code = 'EUR';
DROP TEMPORARY TABLE IF EXISTS tOpeningBalances; DROP TEMPORARY TABLE IF EXISTS tOpeningBalances;
CREATE TEMPORARY TABLE tOpeningBalances ( CREATE TEMPORARY TABLE tOpeningBalances (
supplierFk INT NOT NULL, supplierFk INT NOT NULL,
companyFk INT NOT NULL, companyFk INT NOT NULL,
openingBalances DOUBLE NOT NULL, openingBalances DOUBLE NOT NULL,
closingBalances DOUBLE NOT NULL, closingBalances DOUBLE NOT NULL,
currencyFk INT NOT NULL, currencyFk INT NOT NULL,
PRIMARY KEY (supplierFk, companyFk, currencyFk) PRIMARY KEY (supplierFk, companyFk, currencyFk)
) ENGINE = MEMORY; ) ENGINE = MEMORY;
-- Calculates the opening and closing balance for each supplier -- Calculates the opening and closing balance for each supplier
INSERT INTO tOpeningBalances INSERT INTO tOpeningBalances
SELECT supplierFk, SELECT supplierFk,
companyFk, companyFk,
SUM(amount * isBeforeStarting) AS openingBalances, SUM(amount * isBeforeStarting) AS openingBalances,
SUM(amount) closingBalances, SUM(amount) closingBalances,
currencyFk currencyFk
FROM ( FROM (
SELECT p.supplierFk, SELECT p.supplierFk,
p.companyFk, p.companyFk,
IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount, IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount,
p.dueDated < vStartingDate isBeforeStarting, p.dueDated < vStartingDate isBeforeStarting,
p.currencyFk p.currencyFk
FROM payment p FROM payment p
WHERE p.received > vStartDate WHERE p.received > vStartDate
AND p.companyFk = vSelf AND p.companyFk = vSelf
UNION ALL UNION ALL
SELECT r.supplierFk, SELECT r.supplierFk,
r.companyFk, r.companyFk,
- IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total, - IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total,
rv.dueDated < vStartingDate isBeforeStarting, rv.dueDated < vStartingDate isBeforeStarting,
r.currencyFk r.currencyFk
FROM invoiceIn r FROM invoiceIn r
INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk
WHERE r.issued > vStartDate WHERE r.issued > vStartDate
AND r.isBooked AND r.isBooked
AND r.companyFk = vSelf AND r.companyFk = vSelf
) sub GROUP BY companyFk, supplierFk, currencyFk; ) sub GROUP BY companyFk, supplierFk, currencyFk;
DROP TEMPORARY TABLE IF EXISTS tPendingDuedates; DROP TEMPORARY TABLE IF EXISTS tPendingDuedates;
CREATE TEMPORARY TABLE tPendingDuedates ( CREATE TEMPORARY TABLE tPendingDuedates (
id INT auto_increment, id INT auto_increment,
expirationId INT, expirationId INT,
dated DATE, dated DATE,
supplierFk INT NOT NULL, supplierFk INT NOT NULL,
companyFk INT NOT NULL, companyFk INT NOT NULL,
amount DECIMAL(10, 2) NOT NULL, amount DECIMAL(10, 2) NOT NULL,
currencyFk INT NOT NULL, currencyFk INT NOT NULL,
pending DECIMAL(10, 2) DEFAULT 0, pending DECIMAL(10, 2) DEFAULT 0,
balance DECIMAL(10, 2) DEFAULT 0, balance DECIMAL(10, 2) DEFAULT 0,
endingBalance DECIMAL(10, 2) DEFAULT 0, endingBalance DECIMAL(10, 2) DEFAULT 0,
isPayment BOOLEAN, isPayment BOOLEAN,
isReconciled BOOLEAN, isReconciled BOOLEAN,
PRIMARY KEY (id), PRIMARY KEY (id),
INDEX (supplierFk, companyFk, currencyFk) INDEX (supplierFk, companyFk, currencyFk)
) ENGINE = MEMORY; ) ENGINE = MEMORY;
INSERT INTO tPendingDuedates ( INSERT INTO tPendingDuedates (
expirationId, expirationId,
dated, dated,
supplierFk, supplierFk,
companyFk, companyFk,
amount, amount,
currencyFk, currencyFk,
isPayment, isPayment,
isReconciled isReconciled
)SELECT p.id, )SELECT p.id,
p.dueDated, p.dueDated,
p.supplierFk, p.supplierFk,
p.companyFk, p.companyFk,
@ -100,80 +100,80 @@ BEGIN
-IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue), -IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue),
r.currencyFk, r.currencyFk,
FALSE isPayment, FALSE isPayment,
TRUE TRUE
FROM invoiceIn r FROM invoiceIn r
LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk
AND r.supplierFk = si.supplierFk AND r.supplierFk = si.supplierFk
AND r.currencyFk = si.currencyFk AND r.currencyFk = si.currencyFk
JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk
WHERE rv.dueDated >= vStartingDate WHERE rv.dueDated >= vStartingDate
AND (si.closingBalances IS NULL OR si.closingBalances <> 0) AND (si.closingBalances IS NULL OR si.closingBalances <> 0)
AND r.isBooked AND r.isBooked
AND r.companyFk = vSelf AND r.companyFk = vSelf
ORDER BY supplierFk, companyFk, companyFk, dueDated, isPayment DESC, id; ORDER BY supplierFk, companyFk, companyFk, dueDated, isPayment DESC, id;
-- Now, we calculate the outstanding amount for each receipt in descending order -- Now, we calculate the outstanding amount for each receipt in descending order
SET @risk := 0.0; SET @risk := 0.0;
SET @supplier := 0.0; SET @supplier := 0.0;
SET @company := 0.0; SET @company := 0.0;
SET @moneda := 0.0; SET @moneda := 0.0;
SET @pending := 0.0; SET @pending := 0.0;
SET @day := util.VN_CURDATE(); SET @day := util.VN_CURDATE();
UPDATE tPendingDuedates vp UPDATE tPendingDuedates vp
LEFT JOIN tOpeningBalances si ON vp.companyFk = si.companyFk LEFT JOIN tOpeningBalances si ON vp.companyFk = si.companyFk
AND vp.supplierFk = si.supplierFk AND vp.supplierFk = si.supplierFk
AND vp.currencyFk = si.currencyFk AND vp.currencyFk = si.currencyFk
SET vp.balance = @risk := ( SET vp.balance = @risk := (
IF ( IF (
@company <> vp.companyFk @company <> vp.companyFk
OR @supplier <> vp.supplierFk OR @supplier <> vp.supplierFk
OR @moneda <> vp.currencyFk, OR @moneda <> vp.currencyFk,
IFNULL(si.openingBalances, 0), IFNULL(si.openingBalances, 0),
@risk @risk
) + ) +
vp.amount vp.amount
), ),
-- if there is a change of company or supplier or currency, the balance is reset -- if there is a change of company or supplier or currency, the balance is reset
vp.pending = @pending := IF ( vp.pending = @pending := IF (
@company <> vp.companyFk @company <> vp.companyFk
OR @supplier <> vp.supplierFk OR @supplier <> vp.supplierFk
OR @moneda <> vp.currencyFk OR @moneda <> vp.currencyFk
OR @day <> vp.dated, OR @day <> vp.dated,
vp.amount * (NOT vp.isPayment), vp.amount * (NOT vp.isPayment),
@pending + vp.amount @pending + vp.amount
), ),
vp.companyFk = @company := vp.companyFk, vp.companyFk = @company := vp.companyFk,
vp.supplierFk = @supplier := vp.supplierFk, vp.supplierFk = @supplier := vp.supplierFk,
vp.currencyFk = @moneda := vp.currencyFk, vp.currencyFk = @moneda := vp.currencyFk,
vp.dated = @day := vp.dated, vp.dated = @day := vp.dated,
vp.balance = @risk, vp.balance = @risk,
vp.pending = @pending; vp.pending = @pending;
CREATE OR REPLACE TEMPORARY TABLE tRowsToDelete ENGINE = MEMORY CREATE OR REPLACE TEMPORARY TABLE tRowsToDelete ENGINE = MEMORY
SELECT expirationId, SELECT expirationId,
dated, dated,
supplierFk, supplierFk,
companyFk, companyFk,
currencyFk, currencyFk,
balance balance
FROM tPendingDuedates FROM tPendingDuedates
WHERE balance < vInvalidBalances WHERE balance < vInvalidBalances
AND balance > - vInvalidBalances; AND balance > - vInvalidBalances;
DELETE vp.*
FROM tPendingDuedates vp
JOIN tRowsToDelete rd ON (
vp.dated < rd.dated
OR (vp.dated = rd.dated AND vp.expirationId <= rd.expirationId)
)
AND vp.supplierFk = rd.supplierFk
AND vp.companyFk = rd.companyFk
AND vp.currencyFk = rd.currencyFk
WHERE vp.isPayment = FALSE;
SELECT vp.expirationId, DELETE vp.*
vp.dated, FROM tPendingDuedates vp
vp.supplierFk, JOIN tRowsToDelete rd ON (
vp.dated < rd.dated
OR (vp.dated = rd.dated AND vp.expirationId <= rd.expirationId)
)
AND vp.supplierFk = rd.supplierFk
AND vp.companyFk = rd.companyFk
AND vp.currencyFk = rd.currencyFk
WHERE NOT vp.isPayment;
SELECT vp.expirationId,
vp.dated,
vp.supplierFk,
vp.companyFk, vp.companyFk,
vp.currencyFk, vp.currencyFk,
vp.amount, vp.amount,
@ -183,15 +183,19 @@ BEGIN
vp.isPayment, vp.isPayment,
vp.isReconciled, vp.isReconciled,
vp.endingBalance, vp.endingBalance,
cr.amount clientRiskAmount cr.amount clientRiskAmount,
FROM tPendingDuedates vp co.CEE
LEFT JOIN supplier s ON s.id = vp.supplierFk FROM tPendingDuedates vp
LEFT JOIN client c ON c.fi = s.nif LEFT JOIN supplier s ON s.id = vp.supplierFk
LEFT JOIN clientRisk cr ON cr.clientFk = c.id LEFT JOIN client c ON c.fi = s.nif
AND cr.companyFk = vp.companyFk; LEFT JOIN clientRisk cr ON cr.clientFk = c.id
LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id
DROP TEMPORARY TABLE tOpeningBalances; LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk
DROP TEMPORARY TABLE tPendingDuedates; LEFT JOIN country co ON co.id = be.countryFk
DROP TEMPORARY TABLE tRowsToDelete; AND cr.companyFk = vp.companyFk;
DROP TEMPORARY TABLE tOpeningBalances;
DROP TEMPORARY TABLE tPendingDuedates;
DROP TEMPORARY TABLE tRowsToDelete;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,42 @@
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

@ -1,31 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`()
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
CREATE TEMPORARY TABLE tmp.client_list
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc
JOIN vn.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_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo,
cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo,
f.Consumo consumo_anual, c.Vencimiento, ci.grade
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
JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente
GROUP BY Id_cliente;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
END$$
DELIMITER ;

View File

@ -0,0 +1,2 @@
-- Place your SQL code here
ALTER TABLE vn.entry CHANGE isBlocked isBlocked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT '@deprecated 27/03/2024';

View File

@ -0,0 +1,10 @@
ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) NULL;
ALTER TABLE vn.specialPrice ADD started date NOT NULL DEFAULT '2024-01-01';
ALTER TABLE vn.specialPrice ADD ended date NULL;
ALTER TABLE vn.specialPrice MODIFY COLUMN itemFk int(11) NOT NULL;
ALTER TABLE vn.specialPrice MODIFY COLUMN value DECIMAL(10,2) NOT NULL;
ALTER TABLE vn.`specialPrice`
ADD CONSTRAINT `check_date_range`
CHECK (`ended` IS NULL OR `ended` >= `started`);

View File

@ -126,20 +126,5 @@
"allowedContentTypes": [ "allowedContentTypes": [
"application/x-7z-compressed" "application/x-7z-compressed"
] ]
},
"supplierStorage": {
"name": "supplierStorage",
"connector": "loopback-component-storage",
"provider": "filesystem",
"root": "./storage/dms",
"maxFileSize": "31457280",
"allowedContentTypes": [
"image/png",
"image/jpeg",
"image/jpg",
"image/webp",
"video/mp4",
"application/pdf"
]
} }
} }

View File

@ -57,9 +57,6 @@
"columnName": "evaNotes" "columnName": "evaNotes"
} }
}, },
"isBlocked": {
"type": "boolean"
},
"loadPriority": { "loadPriority": {
"type": "number" "type": "number"
}, },

View File

@ -8,9 +8,6 @@
"SupplierDms": { "SupplierDms": {
"dataSource": "vn" "dataSource": "vn"
}, },
"SupplierContainer": {
"dataSource": "supplierStorage"
},
"SupplierAddress": { "SupplierAddress": {
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -1,6 +1,6 @@
{ {
"name": "salix-back", "name": "salix-back",
"version": "24.14.0", "version": "24.16.0",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix backend", "description": "Salix backend",
"license": "GPL-3.0", "license": "GPL-3.0",