feat: Turn issues into calculated columns refs#7213
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
cbd46330b3
commit
49183c79f1
|
@ -8,6 +8,7 @@ BEGIN
|
||||||
* @param vClientFk Id cliente
|
* @param vClientFk Id cliente
|
||||||
*/
|
*/
|
||||||
DECLARE vHasDebt BOOL;
|
DECLARE vHasDebt BOOL;
|
||||||
|
DECLARE vStarted DATETIME;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vHasDebt
|
SELECT COUNT(*) INTO vHasDebt
|
||||||
FROM `client`
|
FROM `client`
|
||||||
|
@ -16,22 +17,24 @@ BEGIN
|
||||||
|
|
||||||
IF vHasDebt THEN
|
IF vHasDebt THEN
|
||||||
|
|
||||||
|
SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted
|
||||||
|
FROM clientConfig;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tTicketRisk
|
CREATE OR REPLACE TEMPORARY TABLE tTicketRisk
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH ticket AS(
|
WITH ticket AS(
|
||||||
SELECT id ticketFk, companyFk, DATE(shipped) dated
|
SELECT id ticketFk,
|
||||||
FROM vn.ticket t
|
companyFk,
|
||||||
|
DATE(shipped) dated,
|
||||||
|
totalWithVat,
|
||||||
|
ticket_isProblemCalcNeeded(id) isProblemCalcNeeded
|
||||||
|
FROM vn.ticket
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vClientFk
|
||||||
AND refFk IS NULL
|
AND refFk IS NULL
|
||||||
AND NOT isDeleted
|
AND NOT isDeleted
|
||||||
AND totalWithoutVat <> 0
|
AND IFNULL(totalWithVat, 0) <> 0
|
||||||
), dated AS(
|
AND shipped > vStarted
|
||||||
SELECT t.companyFk, MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started,
|
|
||||||
MAX(DATE(t.dated)) ended
|
|
||||||
FROM ticket t
|
|
||||||
JOIN vn.clientConfig cc
|
|
||||||
GROUP BY t.companyFk
|
|
||||||
), balance AS(
|
), balance AS(
|
||||||
SELECT SUM(amount)amount, companyFk
|
SELECT SUM(amount)amount, companyFk
|
||||||
FROM (
|
FROM (
|
||||||
|
@ -49,15 +52,11 @@ BEGIN
|
||||||
WHERE companyFk
|
WHERE companyFk
|
||||||
GROUP BY companyFk
|
GROUP BY companyFk
|
||||||
), uninvoiced AS(
|
), uninvoiced AS(
|
||||||
SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount
|
SELECT companyFk, dated, SUM(totalWithVat) amount
|
||||||
FROM vn.ticket t
|
FROM ticket
|
||||||
JOIN dated d
|
GROUP BY companyFk, dated
|
||||||
WHERE t.clientFk = vClientFk
|
|
||||||
AND t.refFk IS NULL
|
|
||||||
AND t.shipped BETWEEN d.started AND d.ended
|
|
||||||
GROUP BY t.companyFk, DATE(t.shipped)
|
|
||||||
), receipt AS(
|
), receipt AS(
|
||||||
SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount
|
SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount
|
||||||
FROM vn.receipt
|
FROM vn.receipt
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vClientFk
|
||||||
AND payed > util.VN_CURDATE()
|
AND payed > util.VN_CURDATE()
|
||||||
|
@ -79,7 +78,15 @@ BEGIN
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
||||||
SET t.risk = tr.amount;
|
SET t.risk = tr.amount
|
||||||
|
WHERE tr.isProblemCalcNeeded
|
||||||
|
ORDER BY t.id;
|
||||||
|
|
||||||
|
UPDATE ticket t
|
||||||
|
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
||||||
|
SET t.risk = NULL
|
||||||
|
WHERE tr.isProblemCalcNeeded
|
||||||
|
ORDER BY t.id;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTicketRisk;
|
DROP TEMPORARY TABLE tTicketRisk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
Loading…
Reference in New Issue