fix: closeTicket idem salix Refs: #6549
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Carlos Andrés 2024-04-04 14:46:51 +02:00
parent 75a4d6947f
commit 9fcad457a7
1 changed files with 19 additions and 19 deletions

View File

@ -62,14 +62,15 @@ module.exports = Self => {
await Self.rawSql(` await Self.rawSql(`
WITH ticketNotInvoiceable AS( WITH ticketNotInvoiceable AS(
SELECT JSON_OBJECT( SELECT JSON_OBJECT(
'tickets', 'tickets',
JSON_ARRAYAGG( JSON_ARRAYAGG(
JSON_OBJECT( JSON_OBJECT(
'ticketId', ticketFk, 'ticketId', ticketFk,
'reason', 'reason',
LEFT(reason,LENGTH(reason) - 2) LEFT(reason,LENGTH(reason) - 2)
)
) )
))errors )errors
FROM ( FROM (
SELECT ticketFk, SELECT ticketFk,
CONCAT_WS('', CONCAT_WS('',
@ -87,8 +88,8 @@ module.exports = Self => {
SUM(itc.id IS NULL) hasErrorItemTaxCountry, SUM(itc.id IS NULL) hasErrorItemTaxCountry,
SUM(a.id IS NULL) hasErrorAddress, SUM(a.id IS NULL) hasErrorAddress,
SUM(ios.code IS NOT NULL SUM(ios.code IS NOT NULL
AND(ad.customsAgentFk IS NULL AND(ad.customsAgentFk IS NULL
OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld
FROM ticket t FROM ticket t
LEFT JOIN address ad ON ad.id = t.addressFk LEFT JOIN address ad ON ad.id = t.addressFk
JOIN sale s ON s.ticketFk = t.id JOIN sale s ON s.ticketFk = t.id
@ -107,14 +108,13 @@ module.exports = Self => {
AND itc.countryFk = su.countryFk AND itc.countryFk = su.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD' LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD'
AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M') AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'M')
WHERE (al.code = 'PACKED' WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
OR (am.code = 'refund' AND al.code != 'delivered')) AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?)
AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?)
AND t.refFk IS NULL AND t.refFk IS NULL
AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice)
GROUP BY ticketFk GROUP BY ticketFk
HAVING hasErrorToInvoice HAVING hasErrorToInvoice
OR NOT hasErrorTaxDataChecked OR hasErrorTaxDataChecked
OR hasErrorDeleted OR hasErrorDeleted
OR hasErrorItemTaxCountry OR hasErrorItemTaxCountry
OR hasErrorAddress OR hasErrorAddress
@ -130,12 +130,12 @@ module.exports = Self => {
await Self.rawSql(` await Self.rawSql(`
UPDATE ticket t UPDATE ticket t
JOIN ticketState ts ON t.id = ts.ticketFk JOIN ticketState ts ON t.id = ts.ticketFk
JOIN alertLevel al ON al.id = ts.alertLevel JOIN alertLevel al ON al.id = ts.alertLevel
JOIN agencyMode am ON am.id = t.agencyModeFk JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
JOIN zone z ON z.id = t.zoneFk JOIN zone z ON z.id = t.zoneFk
SET t.routeFk = NULL SET t.routeFk = NULL
WHERE DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) WHERE DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY)
AND util.dayEnd(?) AND util.dayEnd(?)
AND al.code NOT IN('DELIVERED','PACKED') AND al.code NOT IN('DELIVERED','PACKED')