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/),
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
### Added
### Changed
### Fixed
## [2408.01] - 2024-02-22
### Added
### Changed
### Fixed
## [2406.01] - 2024-02-08
### Added

View File

@ -8,13 +8,16 @@ BEGIN
SELECT rate3 INTO price
FROM vn.priceFixed
WHERE itemFk = vItemFk
WHERE itemFk = vItemFk
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
WHERE itemFk = vItemFk
AND clientFk = vClientFk ;
WHERE itemFk = vItemFk
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;
END$$
DELIMITER ;

View File

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

View File

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

View File

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

View File

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

View File

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