Compare commits

...

60 Commits

Author SHA1 Message Date
Alex Moreno b4bcfb2886 Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details
2025-02-17 07:55:13 +01:00
Alex Moreno 05af629a62 build: empty commit
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 14:32:15 +01:00
Guillermo Bonet c79867188a Merge branch 'test' into dev
gitea/salix/pipeline/head There was a failure building this commit Details
2025-02-14 12:36:24 +01:00
Guillermo Bonet dce263992e fix: refs #8227 Roadmap columns
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 12:36:06 +01:00
Carlos Andrés a874b96c5e revert a119d9f7fb
gitea/salix/pipeline/head There was a failure building this commit Details
revert feat: invoiceIn move deductible field from head to lines
2025-02-14 11:32:45 +00:00
Carlos Andrés a119d9f7fb feat: invoiceIn move deductible field from head to lines
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 12:29:56 +01:00
Guillermo Bonet 309a287748 Merge branch 'test' into dev
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 12:08:43 +01:00
Guillermo Bonet d9e177d6b4 Merge pull request 'feat: refs #8227 Update roadmap triggers to manage eta adjustments and prevent recursive calls' (!3428) from 8227-roadmapChanges into test
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3428
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-14 10:54:18 +00:00
Guillermo Bonet aca49505bd Merge branch 'test' into 8227-roadmapChanges
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-14 10:52:40 +00:00
Guillermo Bonet 28deadfbad fix: refs #8573 version
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 10:37:08 +01:00
Guillermo Bonet d6f08d7e27 feat: refs #8227 update roadmap triggers and views, remove obsolete trigger and column
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-14 10:04:04 +01:00
Alex Moreno 8110e88aa7 fix: vnUser, default false
gitea/salix/pipeline/head There was a failure building this commit Details
2025-02-14 08:29:55 +01:00
Ivan Mas 9000becf07 Merge pull request 'refactor: refs #8573 add fk to expedition.hostFk' (!3447) from 8573-addFkExpeditionHost into dev
gitea/salix/pipeline/head There was a failure building this commit Details
Reviewed-on: #3447
Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
2025-02-14 07:06:21 +00:00
Ivan Mas 5a37bd332e Merge branch 'dev' into 8573-addFkExpeditionHost
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-14 06:55:47 +00:00
Alex Moreno 44ed6254c3 Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details
2025-02-14 07:02:45 +01:00
Carlos Andrés 4e9bcf530b Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into test
gitea/salix/pipeline/pr-dev This commit looks good Details
gitea/salix/pipeline/head This commit looks good Details
2025-02-13 18:59:26 +01:00
Carlos Andrés b06ffdff52 Actualizar modules/ticket/back/methods/ticket/closeAll.js
gitea/salix/pipeline/head This commit looks good Details
2025-02-13 16:42:20 +00:00
Carlos Andrés 536203e0a1 Merge pull request 'fix: facturacion por consignatario en el cierre nocturno y unificación de backs' (!3453) from Hotfix-cierre-facturacion into master
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3453
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-13 16:37:00 +00:00
Ivan Mas 13a76e5c70 Merge branch 'dev' into 8573-addFkExpeditionHost
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-13 15:43:56 +00:00
Ivan Mas caa921020d refactor: refs #8573 update before alter table
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-13 16:41:29 +01:00
Carlos Andrés 7f32a10c06 fix: facturacion por consignatario en el cierre nocturno y unificación de backs
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-13 15:22:37 +01:00
Guillermo Bonet 845ce8d6d8 feat: refs #8227 Minor changes
gitea/salix/pipeline/pr-test There was a failure building this commit Details
2025-02-13 14:36:09 +01:00
Guillermo Bonet 4042679c9b feat: refs #8227 Grants
gitea/salix/pipeline/pr-test There was a failure building this commit Details
2025-02-13 14:12:44 +01:00
Pako Natek 86091571cd Merge pull request 'fix(item_getBalance): refs #8408 availabled field prevails over landed' (!3449) from 8408-Disponible-por-zonas-y-horas into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3449
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-13 12:39:29 +00:00
Carlos Andrés b2071994da fix: update closeAll method to improve date handling and ticket selection logic
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-13 13:28:14 +01:00
Carlos Satorres cd258eb44e Merge pull request 'fix: refs #6553 remove business' (!3451) from 6553-warnFixBusinessSummary into test
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3451
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-13 11:14:15 +00:00
Jorge Penadés e99fbca255 Merge pull request 'feat: refs #8571 enhance email formatting in sendToSupport function with structured HTML table' (!3445) from 8571-hotfix-notShowToken into master
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3445
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2025-02-13 11:01:37 +00:00
Jorge Penadés fa12debcd7 Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 8571-hotfix-notShowToken
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-13 11:59:36 +01:00
Carlos Satorres 1b7026fa00 fix: refs #6553 remove business
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-13 10:46:48 +01:00
Guillermo Bonet bd53f7367c Merge branch 'test' into 8227-roadmapChanges
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-13 08:34:20 +00:00
Guillermo Bonet 92ab3648e7 feat: refs #8227 Fix tests
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-13 09:22:45 +01:00
Pablo Natek 4b7c20075b Merge pull request 'feat: refs #6897 add search method and enhance ACL permissions for Entry model' (!3448) from 6897-addItemSearch into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3448
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2025-02-13 07:59:58 +00:00
Pako Natek 3a1849326b fix(item_getBalance): refs #8408 availabled field prevails over landed
gitea/salix/pipeline/pr-dev This commit looks good Details
Refs: #8408
2025-02-13 08:41:13 +01:00
Pako Natek d773aec0f5 Merge pull request 'feat(productionControl and collection_new): refs #8575 new itempackingtype a' (!3444) from 8575-itemPackingType-Altillo into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3444
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-13 06:45:37 +00:00
Pako Natek 317c152c66 Merge branch 'dev' into 8575-itemPackingType-Altillo
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-13 06:41:43 +00:00
Pablo Natek 514ddf1045 feat: refs #6897 add search method and enhance ACL permissions for Entry model
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-12 19:40:22 +01:00
Ivan Mas f12c47cdf8 Merge branch 'dev' into 8573-addFkExpeditionHost
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-12 16:11:53 +00:00
Ivan Mas 5404f895b2 refactor: refs #8573 add fk to expedition.hostFk
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-12 17:08:45 +01:00
Javier Segarra 0b8a54d057 Merge pull request 'Fix TicketNegative' (!3446) from fix_ticketNegative into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3446
Reviewed-by: Jon Elias <jon@verdnatura.es>
2025-02-12 15:43:59 +00:00
Jon Elias 307c8d92df Merge branch 'dev' into fix_ticketNegative
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-12 15:30:09 +00:00
Javier Segarra f631aa1314 fix: remotMethodCtx
gitea/salix/pipeline/pr-dev This commit looks good Details
2025-02-12 16:26:01 +01:00
Guillermo Bonet 8959eb21f6 Merge branch 'test' into dev
gitea/salix/pipeline/head This commit looks good Details
2025-02-12 14:37:34 +01:00
Guillermo Bonet 5543da2c80 Merge branch 'master' into test
gitea/salix/pipeline/head This commit looks good Details
2025-02-12 14:37:10 +01:00
Guillermo Bonet ef9ca5f56c Merge pull request 'refactor: refs #6944 Update ticket_setState to improve state change logic and user tracking' (!3439) from 6944-stateNoRepeat into master
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3439
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2025-02-12 13:36:14 +00:00
Carlos Andrés 65a4967d46 fix: update maxShipped to use toDate in closeAll method
gitea/salix/pipeline/head This commit looks good Details
2025-02-12 14:16:43 +01:00
Jorge Penadés 3754ede42d feat: refs #8571 enhance email formatting in sendToSupport function with structured HTML table
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-12 14:15:53 +01:00
Guillermo Bonet ba3909a984 refactor: refs #6944 Requested changes
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-12 14:13:39 +01:00
Pako Natek b95db2eff1 feat(productionControl and collection_new): refs #8575 new itempackingtype a
gitea/salix/pipeline/pr-dev This commit looks good Details
Refs: #8575
2025-02-12 13:45:07 +01:00
Carlos Andrés 9785ab5a7d feat: enhance ticket closure process with error handling and email notifications
gitea/salix/pipeline/head This commit looks good Details
2025-02-12 13:23:57 +01:00
Carlos Andrés b40981aa03 feat: enhance ticket closure process with error handling and email notifications
gitea/salix/pipeline/head This commit looks good Details
2025-02-12 13:18:18 +01:00
Carlos Andrés fad95f2cf9 Merge pull request 'hotFix_daily_addressInvoice_2' (!3441) from hotFix_daily_addressInvoice_2 into test
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3441
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2025-02-12 11:22:08 +00:00
Alex Moreno 5d155ef6bd Merge branch 'test' into hotFix_daily_addressInvoice_2
gitea/salix/pipeline/pr-test This commit looks good Details
2025-02-12 11:17:27 +00:00
Carlos Andrés 1c9417556b feat: enhance ticket closure process with error handling and email notifications
gitea/salix/pipeline/pr-test There was a failure building this commit Details
2025-02-12 12:13:23 +01:00
Guillermo Bonet e7c027a8b1 refactor: refs #6944 Update ticket_setState to improve state change logic and user tracking
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-12 10:06:48 +01:00
Carlos Satorres 798d8a514e Merge pull request 'fix: hotfix delivery-note' (!3437) from hotfix-producerPdf into master
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3437
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
2025-02-11 15:13:27 +00:00
Carlos Satorres b49df364bf Merge branch 'master' into hotfix-producerPdf
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-11 14:58:16 +00:00
Carlos Satorres 92232b34ce fix: hotfix delivery-note
gitea/salix/pipeline/pr-master This commit looks good Details
2025-02-11 15:55:08 +01:00
Alex Moreno 3fbd740a2b fix: address invoice daily
gitea/salix/pipeline/pr-master There was a failure building this commit Details
2025-02-11 14:31:26 +01:00
Guillermo Bonet 75b6867be8 feat: refs #8227 Minor change
gitea/salix/pipeline/pr-test There was a failure building this commit Details
2025-02-10 13:06:05 +01:00
Guillermo Bonet e19e50de14 feat: refs #8227 Update roadmap triggers to manage eta adjustments and prevent recursive calls
gitea/salix/pipeline/pr-test There was a failure building this commit Details
2025-02-10 13:04:23 +01:00
31 changed files with 410 additions and 309 deletions

View File

@ -33,25 +33,52 @@ module.exports = Self => {
const emailUser =
await Self.app.models.EmailUser.findById(userId, {fields: ['email']});
let html = `<h2>Motivo: ${reason}</h2>`;
html += `<h3>Usuario: ${userId} ${emailUser.email}</h3>`;
html += `<h3>Additional Data:</h3>`;
html += '<ul>';
const tableStyle = 'width:100%; border-collapse: collapse; text-align: left;';
const thStyle = 'padding: 8px; border: 1px solid #ddd; background-color: #f4f4f4;';
const tdStyle = 'padding: 8px; border: 1px solid #ddd;';
const tdBoldStyle = 'padding: 8px; border: 1px solid #ddd; font-weight: bold;';
const subTdStyle = 'padding: 6px; border: 1px solid #ddd;';
const subTdBoldStyle = 'padding: 6px; border: 1px solid #ddd; font-weight: bold;';
let html = `
<h2>Motivo: ${reason}</h2>
<h3>Usuario: ${userId} ${emailUser.email}</h3>
<h3>Additional Data:</h3>
<table style="${tableStyle}">
<thead>
<tr>
<th style="${thStyle}">Clave</th><th style="${thStyle}">Valor</th></tr>
</thead>
<tbody>`;
for (const [key, val] of Object.entries(additionalData)) {
if (key !== 'config') html += `<li>${key}: ${parse(val)}</li>`;
else {
html += `<li>${key}:</li><ul style="list-style-type: square;">`;
for (const [confKey, confVal] of Object.entries(val))
html += `<li>${confKey}: ${parse(confVal)}</li>`;
html += '</ul>';
if (key !== 'config') {
html += `<tr>
<td style="${tdBoldStyle}">${key}</td>
<td style="${tdStyle}">${parse(val)}</td>
</tr>`;
} else {
html += `<tr>
<td style="${tdBoldStyle}">${key}</td>
<td style="${tdStyle}">
<table style="${tableStyle}">
<tbody>`;
for (const [confKey, confVal] of Object.entries(val)) {
html += `<tr>
<td style="${subTdBoldStyle}">${confKey}</td>
<td style="${subTdStyle}">${parse(confVal)}</td>
</tr>`;
}
html += `</tbody></table></td></tr>`;
}
}
html += '</ul>';
html += `</tbody></table>`;
const {message, path, name} = additionalData;
const err = name && message ? `${name}: ${message}` : name || message || '';
await smtp.send({
to: `${config.app.reportEmail}, ${emailUser.email}`,
subject: `[Support-Salix] ${path} ${name}: ${message}`,
subject: `[Support-Salix] ${path.split('?')[0]} ${err}`,
html
});
};

View File

@ -54,7 +54,8 @@
"type": "string"
},
"hasGrant": {
"type": "boolean"
"type": "boolean",
"default": false
},
"passExpired": {
"type": "date"

View File

@ -2785,11 +2785,11 @@ INSERT INTO `vn`.`roadmapAddress` (`addressFk`)
(3),
(4);
INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `eta`, `observations`, `editorFk`, `price`, `driverName`)
INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `editorFk`, `price`, `driverName`)
VALUES
(1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'this is test observation', 1, 15, 'Batman'),
(2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), DATE_ADD(util.VN_NOW(), INTERVAL 5 DAY), 'test observation', 1, 20, 'Robin'),
(3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 3 DAY), DATE_ADD(util.VN_NOW(), INTERVAL 6 DAY), 'observations...', 2, 25, 'Driverman');
(1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'),
(2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'),
(3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 3 DAY), 'observations...', 2, 25, 'Driverman');
INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `roadmapAddressFk`, `eta`, `description`, `editorFk`)
VALUES

View File

@ -160,9 +160,11 @@ BEGIN
OR (NOT s.isPreparable AND NOT s.isPrintable)
OR pb.collectionH IS NOT NULL
OR pb.collectionV IS NOT NULL
OR pb.collectionA IS NOT NULL
OR pb.collectionN IS NOT NULL
OR (NOT pb.H AND pb.V > 0 AND vItemPackingTypeFk = 'H')
OR (NOT pb.H AND pb.V + pb.A > 0 AND vItemPackingTypeFk = 'H')
OR (NOT pb.V AND vItemPackingTypeFk = 'V')
OR (NOT pb.A AND vItemPackingTypeFk = 'A')
OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking)
OR LENGTH(pb.problem)
OR pb.lines > vLinesLimit

View File

@ -30,7 +30,7 @@ BEGIN
WITH entriesIn AS (
SELECT 'entry' originType,
e.id originId,
tr.landed shipped,
IFNULL(tr.availabled, tr.landed) shipped,
b.quantity `in`,
NULL `out`,
st.alertLevel ,
@ -54,7 +54,7 @@ BEGIN
OR (util.VN_CURDATE() AND tr.isReceived),
'DELIVERED',
'FREE')
WHERE tr.landed >= vDateInventory
WHERE IFNULL(tr.availabled, tr.landed) >= vDateInventory
AND tr.warehouseInFk = vWarehouseFk
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
AND b.itemFk = vItemFk
@ -99,7 +99,7 @@ BEGIN
),
sales AS (
WITH itemSales AS (
SELECT DATE(t.shipped) shipped,
SELECT DATE(t.shipped) + INTERVAL HOUR(z.`hour`) HOUR shipped,
s.quantity,
st2.alertLevel,
st2.name,
@ -114,6 +114,7 @@ BEGIN
cb.claimFk
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
JOIN vn.`zone` z ON z.id = t.zoneFk
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
LEFT JOIN vn.state st ON st.code = ts.code
JOIN vn.client c ON c.id = t.clientFk
@ -189,14 +190,15 @@ BEGIN
SELECT * FROM sales
UNION ALL
SELECT * FROM orders
ORDER BY shipped,
ORDER BY DATE(shipped),
(inventorySupplierFk = entityId) DESC,
alertLevel DESC,
isTicket,
`order` DESC,
isPicked DESC,
`in` DESC,
`out` DESC;
`out` DESC,
shipped;
IF vDated IS NULL THEN
SET @a := 0;
@ -205,7 +207,7 @@ BEGIN
SELECT t.originType,
t.originId,
DATE(@shipped:= t.shipped) shipped,
@shipped:= t.shipped,
t.alertLevel,
t.stateName,
t.reference,

View File

@ -91,6 +91,7 @@ proc: BEGIN
pk.code parking,
0 H,
0 V,
0 A,
0 N,
st.isOk,
ag.isOwn,
@ -138,6 +139,7 @@ proc: BEGIN
CHANGE COLUMN `problem` `problem` VARCHAR(255),
ADD COLUMN `collectionH` INT,
ADD COLUMN `collectionV` INT,
ADD COLUMN `collectionA` INT,
ADD COLUMN `collectionN` INT;
-- Clientes Nuevos o Recuperados
@ -179,11 +181,13 @@ proc: BEGIN
SELECT ticketFk,
SUM(sub.H) H,
SUM(sub.V) V,
SUM(sub.A) A,
SUM(sub.N) N
FROM (
SELECT t.ticketFk,
SUM(i.itemPackingTypeFk = 'H') H,
SUM(i.itemPackingTypeFk = 'V') V,
SUM(i.itemPackingTypeFk = 'A') A,
SUM(i.itemPackingTypeFk IS NULL) N
FROM tmp.productionTicket t
JOIN sale s ON s.ticketFk = t.ticketFk
@ -196,6 +200,7 @@ proc: BEGIN
JOIN tItemPackingType ti ON ti.ticketFk = pb.ticketFk
SET pb.H = ti.H,
pb.V = ti.V,
pb.A = ti.A,
pb.N = ti.N;
-- Colecciones segun tipo de encajado
@ -203,6 +208,7 @@ proc: BEGIN
JOIN ticketCollection tc ON pb.ticketFk = tc.ticketFk
SET pb.collectionH = IF(pb.H, tc.collectionFk, NULL),
pb.collectionV = IF(pb.V, tc.collectionFk, NULL),
pb.collectionA = IF(pb.A, tc.collectionFk, NULL),
pb.collectionN = IF(pb.N, tc.collectionFk, NULL);
-- Previa pendiente

View File

@ -9,15 +9,12 @@ BEGIN
*/
DECLARE vDone BOOL;
DECLARE vClientFk INT;
DECLARE vCurTicketFk INT;
DECLARE vIsTaxDataChecked BOOL;
DECLARE vCompanyFk INT;
DECLARE vShipped DATE;
DECLARE vCurTicketFk INT;
DECLARE vNewInvoiceId INT;
DECLARE vHasDailyInvoice BOOL;
DECLARE vWithPackage BOOL;
DECLARE vHasToInvoice BOOL;
DECLARE vSerial VARCHAR(2);
DECLARE vHasToInvoice BOOL;
DECLARE vStateCode VARCHAR(45);
DECLARE cur CURSOR FOR
SELECT ticketFk FROM tmp.ticket_close;
@ -38,18 +35,11 @@ BEGIN
LEAVE proc;
END IF;
SELECT
c.id,
c.isTaxDataChecked,
t.companyFk,
t.shipped,
SELECT c.id,
c.hasDailyInvoice,
w.isManaged,
c.hasToInvoice
INTO vClientFk,
vIsTaxDataChecked,
vCompanyFk,
vShipped,
vHasDailyInvoice,
vWithPackage,
vHasToInvoice
@ -59,7 +49,7 @@ BEGIN
WHERE t.id = vCurTicketFk;
INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity)
(SELECT vCurTicketFk, p.id, COUNT(*)
SELECT vCurTicketFk, p.id, COUNT(*)
FROM expedition e
JOIN packaging p ON p.id = e.packagingFk
JOIN ticket t ON t.id = e.ticketFk
@ -68,39 +58,35 @@ BEGIN
WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable
AND vWithPackage
AND NOT dm.`code`= 'PICKUP'
GROUP BY p.itemFk);
GROUP BY p.itemFk;
-- No retornables o no catalogados
INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed)
(SELECT e.freightItemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.freightItemFk, vClientFk), 1
INSERT INTO sale (
itemFk,
ticketFk,
concept,
quantity,
price, isPriceFixed
)SELECT e.freightItemFk,
vCurTicketFk,
i.name,
COUNT(*) amount,
getSpecialPrice(e.freightItemFk, vClientFk),
TRUE
FROM expedition e
JOIN item i ON i.id = e.freightItemFk
LEFT JOIN packaging p ON p.itemFk = i.id
WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
WHERE e.ticketFk = vCurTicketFk
AND (p.isPackageReturnable = 0 OR p.isPackageReturnable IS NULL)
AND getSpecialPrice(e.freightItemFk, vClientFk) > 0
GROUP BY e.freightItemFk);
GROUP BY e.freightItemFk;
IF(vHasDailyInvoice) AND vHasToInvoice THEN
SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial;
IF vSerial IS NULL THEN
CALL util.throw('Cannot booking without a serial');
END IF;
CALL ticket_setState(vCurTicketFk, 'DELIVERED');
IF vIsTaxDataChecked THEN
CALL invoiceOut_newFromClient(
vClientFk,
vSerial,
vShipped,
vCompanyFk,
NULL,
NULL,
vNewInvoiceId);
END IF;
IF vHasDailyInvoice AND vHasToInvoice THEN
SET vStateCode = 'DELIVERED';
ELSE
CALL ticket_setState(vCurTicketFk, (SELECT vn.getAlert3State(vCurTicketFk)));
SELECT getAlert3State(vCurTicketFk) INTO vStateCode;
END IF;
CALL ticket_setState(vCurTicketFk, vStateCode);
END LOOP;
CLOSE cur;

View File

@ -3,21 +3,25 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_setState`(
vSelf INT,
vStateCode VARCHAR(255) COLLATE utf8_general_ci
)
BEGIN
proc:BEGIN
/**
* Modifica el estado de un ticket si se cumplen las condiciones necesarias.
*
* @param vSelf el id del ticket
* @param vStateCode estado a modificar del ticket
*/
DECLARE vticketAlertLevel INT;
DECLARE vTicketStateCode VARCHAR(255);
DECLARE vTicketAlertLevel INT;
DECLARE vTicketStateCode VARCHAR(255) COLLATE utf8_general_ci;
DECLARE vCanChangeState BOOL;
DECLARE vPackedAlertLevel INT;
DECLARE vZoneFk INT;
DECLARE vOldWorkerFk INT;
DECLARE vNewWorkerFk INT;
SELECT s.alertLevel, s.`code`, t.zoneFk
INTO vticketAlertLevel, vTicketStateCode, vZoneFk
SET vNewWorkerFk = account.myUser_getId();
SELECT s.alertLevel, s.`code`, t.zoneFk, tt.userFk
INTO vTicketAlertLevel, vTicketStateCode, vZoneFk, vOldWorkerFk
FROM state s
JOIN ticketTracking tt ON tt.stateFk = s.id
JOIN ticket t ON t.id = tt.ticketFk
@ -33,24 +37,27 @@ BEGIN
SET vCanChangeState = ((
vStateCode <> 'ON_CHECKING' AND vStateCode <> 'CHECKED') OR
vticketAlertLevel < vPackedAlertLevel
)AND NOT (
vTicketAlertLevel < vPackedAlertLevel
) AND NOT (
vTicketStateCode IN ('CHECKED', 'CHECKING')
AND vStateCode IN ('PREPARED', 'ON_PREPARATION')
);
IF vCanChangeState THEN
INSERT INTO ticketTracking (stateFk, ticketFk, userFk)
SELECT id, vSelf, account.myUser_getId()
FROM state
WHERE `code` = vStateCode COLLATE utf8_unicode_ci;
IF vStateCode = 'PACKED' THEN
CALL ticket_doCmr(vSelf);
END IF;
IF vStateCode = vTicketStateCode AND vOldWorkerFk = vNewWorkerFk THEN
LEAVE proc;
END IF;
INSERT INTO ticketTracking (stateFk, ticketFk, userFk)
SELECT id, vSelf, vNewWorkerFk
FROM state
WHERE `code` = vStateCode COLLATE utf8_unicode_ci;
ELSE
CALL util.throw('INCORRECT_TICKET_STATE');
END IF;
END$$
DELIMITER ;

View File

@ -1,26 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeDelete`
BEFORE DELETE ON `roadmapStop`
FOR EACH ROW
BEGIN
DECLARE vMaxEta DATETIME;
DECLARE vRoadmapEta DATETIME;
IF OLD.roadmapFk IS NOT NULL THEN
SELECT MAX(eta) INTO vMaxEta
FROM roadmapStop
WHERE roadmapFk = OLD.roadmapFk
AND id <> OLD.id;
SELECT eta INTO vRoadmapEta
FROM roadmap
WHERE id = OLD.roadmapFk;
IF vMaxEta <> vRoadmapEta OR vMaxEta IS NULL THEN
UPDATE roadmap
SET eta = vMaxEta
WHERE id = OLD.roadmapFk;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -3,8 +3,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeInser
BEFORE INSERT ON `roadmapStop`
FOR EACH ROW
BEGIN
DECLARE vRoadmapEta DATETIME;
SET NEW.editorFk = account.myUser_getId();
IF NEW.description IS NOT NULL THEN
@ -16,17 +14,5 @@ BEGIN
CALL util.throw('Departure time can not be after arrival time');
END IF;
END IF;
IF NEW.roadmapFk IS NOT NULL AND NEW.eta IS NOT NULL THEN
SELECT eta INTO vRoadmapEta
FROM roadmap
WHERE id = NEW.roadmapFk;
IF vRoadmapEta < NEW.eta OR vRoadmapEta IS NULL THEN
UPDATE roadmap
SET eta = NEW.eta
WHERE id = NEW.roadmapFk;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -3,40 +3,17 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeUpdat
BEFORE UPDATE ON `roadmapStop`
FOR EACH ROW
BEGIN
DECLARE vMaxEta DATETIME;
DECLARE vCurrentEta DATETIME;
SET NEW.editorFk = account.myUser_getId();
IF NOT (NEW.description <=> OLD.description) THEN
SET NEW.description = UCASE(NEW.description);
END IF;
IF (NOT (NEW.roadmapFk <=> OLD.roadmapFk) AND NEW.roadmapFk IS NOT NULL)
OR (NOT (NEW.eta <=> OLD.eta)) THEN
IF NOT (NEW.roadmapFk <=> OLD.roadmapFk) OR NOT (NEW.eta <=> OLD.eta) THEN
IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN
CALL util.throw('Departure time can not be after arrival time');
END IF;
SELECT MAX(eta) INTO vMaxEta
FROM roadmapStop
WHERE roadmapFk = NEW.roadmapFk
AND id <> OLD.id;
IF vMaxEta < NEW.eta OR vMaxEta IS NULL THEN
SET vMaxEta = NEW.eta;
END IF;
SELECT eta INTO vCurrentEta
FROM roadmap
WHERE id = NEW.roadmapFk;
IF (vMaxEta <> vCurrentEta OR vMaxEta IS NULL) OR vMaxEta IS NOT NULL THEN
UPDATE roadmap
SET eta = vMaxEta
WHERE id = NEW.roadmapFk;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -1,17 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_afterUpdate`
AFTER UPDATE ON `roadmap`
FOR EACH ROW
BEGIN
DECLARE vSeconds INT;
IF NOT (NEW.etd <=> OLD.etd) THEN
SET vSeconds = TIME_TO_SEC(TIMEDIFF(NEW.etd, OLD.etd));
IF vSeconds IS NOT NULL AND vSeconds <> 0 THEN
UPDATE roadmapStop
SET eta = eta + INTERVAL vSeconds SECOND
WHERE roadmapFk = NEW.id;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate`
BEFORE UPDATE ON `roadmap`
FOR EACH ROW
BEGIN
DECLARE vSeconds INT;
SET NEW.editorFk = account.myUser_getId();
IF NOT (NEW.name <=> OLD.name) THEN
@ -37,5 +39,15 @@ BEGIN
FROM worker w
WHERE w.id = NEW.driverChangeFk);
END IF;
IF NOT (NEW.etd <=> OLD.etd) THEN
SET vSeconds = TIME_TO_SEC(TIMEDIFF(NEW.etd, OLD.etd));
IF vSeconds <> 0 THEN
UPDATE roadmapStop
SET eta = eta + INTERVAL vSeconds SECOND
WHERE roadmapFk = NEW.id;
END IF;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,8 @@
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`roadmapEta`
AS SELECT `roadmapFk` AS id,
MAX(`eta`) AS `eta`
FROM `vn`.`roadmapStop`
WHERE `roadmapFk` IS NOT NULL
GROUP BY `roadmapFk`;

View File

@ -1,6 +1,7 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Entry','getBuyList','READ','ALLOW','ROLE','buyer'),
('Entry','getBuyUltimate','READ','ALLOW','ROLE','buyer'),
('Entry','search','READ','ALLOW','ROLE','buyer'),
('Entry','create','WRITE','ALLOW','ROLE','buyer'),
('Entry','cloneEntry','WRITE','ALLOW','ROLE','buyer'),
('Entry','deleteEntry','WRITE','ALLOW','ROLE','buyer'),
@ -11,4 +12,79 @@ INSERT INTO salix.ACL (model,property,accessType,permission,principalType,princi
ALTER TABLE vn.ink ADD IF NOT EXISTS hexJson TEXT NOT NULL;
UPDATE vn.ink
SET hexJson = CONCAT('{"value": ["',hex,'"]}')
SET hexJson = CONCAT('{"value": ["',hex,'"]}');
UPDATE vn.ink
SET hexJson = CASE `name`
WHEN 'Blanco/Naranja' THEN '{"value": ["FFFFFF", "FFA500"]}'
WHEN 'Sin especificar' THEN '{"value": ["808080"]}'
WHEN '2 Colores' THEN '{"value": ["000000", "FFFFFF"]}'
WHEN 'Amarillo/Marrón' THEN '{"value": ["FFFF00", "8B4513"]}'
WHEN 'Amarillo/Naranja' THEN '{"value": ["FFFF00", "FFA500"]}'
WHEN 'Rosa/Blanco/Amarillo' THEN '{"value": ["FFC0CB", "FFFFFF", "FFFF00"]}'
WHEN 'Rosa/Amarillo' THEN '{"value": ["FFC0CB", "FFFF00"]}'
WHEN 'Antracita' THEN '{"value": ["2F2F2F"]}'
WHEN 'Azul/Amarillo' THEN '{"value": ["0000FF", "FFFF00"]}'
WHEN 'Azul Claro' THEN '{"value": ["ADD8E6"]}'
WHEN 'Azul/Marron' THEN '{"value": ["0000FF", "8B4513"]}'
WHEN 'Azul/Verde' THEN '{"value": ["0000FF", "008000"]}'
WHEN 'Blanco/Amarillo' THEN '{"value": ["FFFFFF", "FFFF00"]}'
WHEN 'Blaugrana' THEN '{"value": ["A50044", "004D98"]}'
WHEN 'Blanco/Negro' THEN '{"value": ["FFFFFF", "000000"]}'
WHEN 'Blanco/Verde' THEN '{"value": ["FFFFFF", "008000"]}'
WHEN 'Blanco/Azul' THEN '{"value": ["FFFFFF", "0000FF"]}'
WHEN 'Blanco/Rosa' THEN '{"value": ["FFFFFF", "FFC0CB"]}'
WHEN 'Cognac/Verde' THEN '{"value": ["9A463D", "008000"]}'
WHEN 'Champagne/Verde' THEN '{"value": ["F7E7CE", "008000"]}'
WHEN 'Camuflaje' THEN '{"value": ["6B8E23", "556B2F", "8B4513"]}'
WHEN 'Crema/Rosa' THEN '{"value": ["FFFDD0", "FFC0CB"]}'
WHEN 'Fucsia/Amarillo' THEN '{"value": ["FF00FF", "FFFF00"]}'
WHEN 'Fucsia/Blanco' THEN '{"value": ["FF00FF", "FFFFFF"]}'
WHEN 'Fucsia/Crema' THEN '{"value": ["FF00FF", "FFFDD0"]}'
WHEN 'Fucsia/Rosa' THEN '{"value": ["FF00FF", "FFC0CB"]}'
WHEN 'Fucsia/Verde' THEN '{"value": ["FF00FF", "008000"]}'
WHEN 'Granate/Blanco' THEN '{"value": ["800000", "FFFFFF"]}'
WHEN 'Gris Lila' THEN '{"value": ["808080", "C8A2C8"]}'
WHEN 'Lavanda/Amarillo' THEN '{"value": ["E6E6FA", "FFFF00"]}'
WHEN 'Lavanda/Gris' THEN '{"value": ["E6E6FA", "808080"]}'
WHEN 'Lividum' THEN '{"value": ["702963"]}'
WHEN 'Morado/Amarillo' THEN '{"value": ["800080", "FFFF00"]}'
WHEN 'Marrón/Blanco' THEN '{"value": ["8B4513", "FFFFFF"]}'
WHEN 'Marron/Gris' THEN '{"value": ["8B4513", "808080"]}'
WHEN 'Marron/Negro' THEN '{"value": ["8B4513", "000000"]}'
WHEN 'Marrón/Verde' THEN '{"value": ["8B4513", "008000"]}'
WHEN 'Matizado' THEN '{"value": ["D3D3D3", "808080", "FFFFFF"]}'
WHEN 'Mixto' THEN '{"value": ["FF0000", "0000FF", "008000", "FFFF00"]}'
WHEN 'Marrón Oscuro' THEN '{"value": ["654321"]}'
WHEN 'Naranja/Marron' THEN '{"value": ["FFA500", "8B4513"]}'
WHEN 'Naranja/Rosa' THEN '{"value": ["FFA500", "FFC0CB"]}'
WHEN 'Ocre/Burgundi' THEN '{"value": ["CC7722", "800020"]}'
WHEN 'Oro/Plata' THEN '{"value": ["FFD700", "C0C0C0"]}'
WHEN 'Oro/Negro' THEN '{"value": ["FFD700", "000000"]}'
WHEN 'Oro/Verde' THEN '{"value": ["FFD700", "008000"]}'
WHEN 'Purpura/Blanco' THEN '{"value": ["800080", "FFFFFF"]}'
WHEN 'Purpura/Rosa' THEN '{"value": ["800080", "FFC0CB"]}'
WHEN 'Pastel' THEN '{"value": ["FFB6C1", "87CEFA", "98FB98"]}'
WHEN 'Plata' THEN '{"value": ["C0C0C0"]}'
WHEN 'Plata/Verde' THEN '{"value": ["C0C0C0", "008000"]}'
WHEN 'Rojo/Amarillo' THEN '{"value": ["FF0000", "FFFF00"]}'
WHEN 'Rojo/Blanco' THEN '{"value": ["FF0000", "FFFFFF"]}'
WHEN 'Rojo/Naranja' THEN '{"value": ["FF0000", "FFA500"]}'
WHEN 'Rojo/Oro' THEN '{"value": ["FF0000", "FFD700"]}'
WHEN 'Rojo/Verde' THEN '{"value": ["FF0000", "008000"]}'
WHEN 'Rosa/Lila' THEN '{"value": ["FFC0CB", "C8A2C8"]}'
WHEN 'Rosa/Naranja' THEN '{"value": ["FFC0CB", "FFA500"]}'
WHEN 'Rojo/Rosa' THEN '{"value": ["FF0000", "FFC0CB"]}'
WHEN 'Rosa empolvado' THEN '{"value": ["E6B8AF"]}'
WHEN 'Rosa/Verde' THEN '{"value": ["FFC0CB", "008000"]}'
WHEN 'Topo/Blanco' THEN '{"value": ["8B8589", "FFFFFF"]}'
WHEN 'Topo' THEN '{"value": ["8B8589"]}'
WHEN 'Transparente' THEN '{"value": ["00000000"]}'
WHEN 'Verde/Amarillo' THEN '{"value": ["008000", "FFFF00"]}'
WHEN 'Verde/Negro' THEN '{"value": ["008000", "000000"]}'
WHEN 'Variado' THEN '{"value": ["FF0000", "0000FF", "008000", "FFFF00", "FFA500"]}'
WHEN 'Verde Claro/Morado' THEN '{"value": ["90EE90", "800080"]}'
WHEN 'Verde/Lila' THEN '{"value": ["008000", "C8A2C8"]}'
WHEN 'Vaquero Neon' THEN '{"value": ["1560BD", "FFFF00"]}'
ELSE hexJson
END;

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.roadmap
MODIFY COLUMN dollyPlate varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT
'Vehículo sin motor diseñado para conectarse a una unidad tractora, un camión o un vehículo tractor con fuerte potencia de tracción';

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.volumeConfig ADD COLUMN id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
GRANT UPDATE (palletM3) ON vn.volumeConfig TO deliveryBoss;

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.vehicle
MODIFY COLUMN typeFk enum('car','van','truck','trailer','tug','dolly','trailerLink')
CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'van' NOT NULL;

View File

@ -0,0 +1 @@
ALTER TABLE vn.roadmap DROP COLUMN eta;

View File

@ -0,0 +1,8 @@
UPDATE vn.expedition e
JOIN (
SELECT id
FROM vn.expedition
WHERE hostFk COLLATE utf8mb3_unicode_ci NOT IN
(SELECT code COLLATE utf8mb3_unicode_ci FROM vn.host WHERE code IS NOT NULL)
) s ON e.id = s.id
SET e.hostFk = 'pc336';

View File

@ -0,0 +1,9 @@
ALTER TABLE vn.expedition
MODIFY COLUMN hostFk VARCHAR(30) COLLATE utf8mb3_general_ci;
ALTER TABLE vn.expedition
ADD CONSTRAINT fk_expedition_host_code
FOREIGN KEY (hostFk)
REFERENCES host(code)
ON UPDATE CASCADE
ON DELETE CASCADE;

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('getSimilar', {
Self.remoteMethodCtx('getSimilar', {
description: 'Returns list of items with similar item requested',
accessType: 'READ',
accepts: [

View File

@ -0,0 +1,38 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethodCtx('search', {
description: 'Returns an array of search results for a specified item',
accepts: [{
arg: 'filter',
type: 'object',
description: 'Filter to define conditions and paginate the data.',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/search`,
verb: 'GET'
}
});
Self.search = async(ctx, filter) => {
const conn = Self.dataSource.connector;
const stmt = new ParameterizedSQL(`
SELECT *
FROM(
SELECT i.id, i.name, i.size, p.name producerName
FROM item i
LEFT JOIN producer p ON p.id = i.producerFk
) sub
`);
stmt.merge(conn.makeSuffix(filter));
return conn.executeStmt(stmt);
};
};

View File

@ -18,6 +18,7 @@ module.exports = Self => {
require('../methods/item/buyerWasteEmail')(Self);
require('../methods/item/setVisibleDiscard')(Self);
require('../methods/item/get')(Self);
require('../methods/item/search')(Self);
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});

View File

@ -33,7 +33,7 @@
"observations": {
"type": "string"
},
"userFk": {
"editorFk": {
"type": "number"
},
"price": {

View File

@ -15,16 +15,13 @@
"roadmapFk": {
"type": "number"
},
"addressFk": {
"type": "number"
},
"eta": {
"type": "date"
},
"description": {
"type": "string"
},
"userFk": {
"editorFk": {
"type": "number"
}
},
@ -37,7 +34,7 @@
"address": {
"type": "belongsTo",
"model": "RoadmapAddress",
"foreignKey": "addressFk"
"foreignKey": "roadmapAddressFk"
}
}
}

View File

@ -49,7 +49,7 @@ module.exports = Self => {
ps.monitorId,
e.created
FROM expedition e
JOIN host h ON Convert(h.code USING utf8mb3) COLLATE utf8mb3_unicode_ci = e.hostFk
JOIN host h ON h.code = e.hostFk
JOIN packingSite ps ON ps.hostFk = h.id
WHERE e.id = ?;`;
const [expedition] = await models.Expedition.rawSql(query, [id]);

View File

@ -44,7 +44,7 @@ module.exports = Self => {
ps.monitorId,
e.created
FROM expedition e
JOIN host h ON Convert(h.code USING utf8mb3) COLLATE utf8mb3_unicode_ci = e.hostFk
JOIN host h ON h.code = e.hostFk
JOIN packingSite ps ON ps.hostFk = h.id
WHERE e.id = ?;`;

View File

@ -1,4 +1,5 @@
const closure = require('./closure');
const smtp = require('vn-print/core/smtp');
const config = require('vn-print/core/config');
module.exports = Self => {
Self.remoteMethodCtx('closeAll', {
@ -25,122 +26,62 @@ module.exports = Self => {
Self.closeAll = async(ctx, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
let tx;
// IMPORTANT: Due to its high cost in production, wrapping this process in a transaction may cause timeouts.
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
const toDate = Date.vnNew();
toDate.setHours(0, 0, 0, 0);
toDate.setDate(toDate.getDate() - 1);
const [{dateFrom, dateTo}] = await Self.rawSql(`
SELECT ? - INTERVAL closureDaysAgo DAY dateFrom,
util.dayEnd(?) dateTo
FROM ticketConfig
LIMIT 1`, [toDate, toDate], myOptions);
const tickets = await Self.rawSql(`
SELECT t.id,
await Self.rawSql(`
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close;
CREATE TEMPORARY TABLE tmp.ticket_close
ENGINE = MEMORY
WITH wTickets AS(
SELECT t.id ticketFk
FROM ticket t
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
WHERE t.shipped BETWEEN ? AND ?
AND t.refFk IS NULL
), wTicketsTracking AS(
SELECT wt.ticketFk, MAX(tt.id) maxTracking
FROM wTickets wt
JOIN ticketTracking tt ON tt.ticketFk = wt.ticketFk
GROUP BY tt.ticketFk
), wTicketsLastState AS(
SELECT wt.ticketFk, tt.stateFk
FROM wTicketsTracking wt
JOIN ticketTracking tt ON tt.id = wt.maxTracking
) SELECT tls.ticketFk,
t.clientFk,
t.companyFk,
c.id clientFk,
c.name clientName,
c.email recipient,
c.salesPersonFk,
c.isToBeMailed,
c.hasToInvoice,
c.hasDailyInvoice,
eu.email salesPersonEmail,
t.addressFk
FROM ticket t
t.addressFk,
c.hasDailyInvoice,
c.hasToInvoiceByAddress,
t.totalWithVat,
t.companyFk
FROM wTicketsLastState tls
JOIN ticket t ON t.id = tls.ticketFk
JOIN state s ON s.id =tls.stateFk
JOIN alertLevel al ON al.id = s.alertLevel
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN alertLevel al ON al.id = ts.alertLevel
JOIN client c ON c.id = t.clientFk
JOIN province p ON p.id = c.provinceFk
JOIN country co ON co.id = p.countryFk
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
JOIN ticketConfig tc ON TRUE
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?)
AND t.refFk IS NULL
GROUP BY t.id
`, [toDate, toDate], myOptions);
const ticketIds = tickets.map(ticket => ticket.id);
await Self.rawSql(`
INSERT INTO util.debug (variable, value)
VALUES ('nightInvoicing', ?)
`, [ticketIds.join(',')], myOptions);
await Self.rawSql(`
WITH ticketNotInvoiceable AS(
SELECT JSON_OBJECT(
'tickets',
JSON_ARRAYAGG(
JSON_OBJECT(
'ticketId', ticketFk,
'reason', reason,
'clientId', clientFk
)
)
)errors
FROM (
SELECT ticketFk,
CONCAT_WS(', ',
IF(hasErrorToInvoice, 'Facturar', NULL),
IF(hasErrorTaxDataChecked, 'Datos comprobados', NULL),
IF(hasErrorDeleted, 'Eliminado', NULL),
IF(hasErrorItemTaxCountry, 'Impuesto no informado', NULL),
IF(hasErrorAddress, 'Sin dirección', NULL),
IF(hasErrorInfoTaxAreaWorld, 'Datos exportaciones', NULL)) reason,
clientFk
FROM (
SELECT t.id ticketFk,
SUM(NOT c.hasToInvoice) hasErrorToInvoice,
SUM(NOT c.isTaxDataChecked) hasErrorTaxDataChecked,
SUM(t.isDeleted) hasErrorDeleted,
SUM(itc.id IS NULL) hasErrorItemTaxCountry,
SUM(a.id IS NULL) hasErrorAddress,
SUM(ios.code IS NOT NULL
AND(ad.customsAgentFk IS NULL
OR ad.incotermsFk IS NULL)) hasErrorInfoTaxAreaWorld,
t.clientFk clientFk
FROM ticket t
LEFT JOIN address ad ON ad.id = t.addressFk
JOIN sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk
JOIN supplier su ON su.id = t.companyFk
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN warehouse wh ON wh.id = t.warehouseFk AND wh.hasComission
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN alertLevel al ON al.id = ts.alertLevel
JOIN client c ON c.id = t.clientFk
JOIN province p ON p.id = c.provinceFk
JOIN ticketConfig tc ON TRUE
LEFT JOIN autonomy a ON a.id = p.autonomyFk
JOIN country co ON co.id = p.countryFk
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
AND itc.countryFk = su.countryFk
LEFT JOIN vn.invoiceOutSerial ios ON ios.taxAreaFk = 'WORLD'
AND ios.code = invoiceSerial(t.clientFk, t.companyFk, 'multiple')
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?)
AND t.refFk IS NULL
AND c.hasDailyInvoice
GROUP BY ticketFk
HAVING hasErrorToInvoice
OR hasErrorTaxDataChecked
OR hasErrorDeleted
OR hasErrorItemTaxCountry
OR hasErrorAddress
OR hasErrorInfoTaxAreaWorld
)sub
)sub2
) SELECT IF(errors = '{"tickets": null}',
'No errors',
util.notification_send('invoice-ticket-closure', errors, NULL))
FROM ticketNotInvoiceable`, [toDate, toDate], myOptions);
await closure(ctx, Self, tickets, myOptions);
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'));
CALL ticket_close();
`, [dateFrom, dateTo], myOptions);
await Self.rawSql(`
UPDATE ticket t
@ -151,17 +92,100 @@ module.exports = Self => {
JOIN ticketConfig tc ON TRUE
LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id
SET t.routeFk = NULL
WHERE t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?)
WHERE t.shipped BETWEEN ? AND ?
AND al.code NOT IN ('DELIVERED', 'PACKED')
AND NOT t.packages
AND tob.id IS NULL
AND t.routeFk`, [toDate, toDate], myOptions);
AND t.routeFk`, [dateFrom, dateTo], myOptions);
const [clients] = await Self.rawSql(`
SELECT clientFk clientId,
clientName,
recipient,
salesPersonEmail,
addressFk addressId,
companyFk,
SUM(totalWithVat) total,
'quick' serialType
FROM tmp.ticket_close
WHERE hasDailyInvoice
GROUP BY IF (hasToInvoiceByAddress, addressFk, clientFk), companyFk
HAVING total > 0;
DROP TEMPORARY TABLE tmp.ticket_close;
`, [], myOptions);
if (tx)
await tx.commit();
const failedClients = [];
const nestedTransaction = options?.transaction ? myOptions : {};
for (const client of clients) {
ctx.args = {
...client,
invoiceDate: Date.vnNew(),
maxShipped: toDate
};
try {
const id = await Self.app.models.InvoiceOut.invoiceClient(ctx, nestedTransaction);
if (id)
await Self.app.models.InvoiceOut.makePdfAndNotify(ctx, id, null, nestedTransaction);
} catch (error) {
await Self.rawSql(`
INSERT INTO util.debug (variable, value)
VALUES ('invoicingTicketError', ?)
`, [client.clientId + ' - ' + error]);
if (error.responseCode == 450) {
await invalidEmail(client);
continue;
}
failedClients.push({
id: client.clientId,
address: client.addressId,
error
});
}
}
if (failedClients.length > 0) {
let body = 'This following tickets have failed:<br/><br/>';
for (const client of failedClients) {
body += `Client: <strong>${client.id}</strong>
Address: <strong>${client.address}</strong>
<br/> <strong>${client.error}</strong><br/><br/>`;
}
smtp.send({
to: config.app.reportEmail,
subject: '[API] Nightly ticket closure report',
html: body,
}).catch(err => console.error(err));
}
return {
message: 'Success'
};
};
async function invalidEmail(client) {
await Self.rawSql(
`UPDATE client SET email = NULL WHERE id = ?`,
[client.clientId],
myOptions
);
const body = `No se ha podido facturar al cliente <strong>${client.clientId} - ${client.clientName}</strong>
porque la dirección de email <strong>"${client.recipient}"</strong> no es correcta
o no está disponible.<br/><br/>
Para evitar que se repita este error, se ha eliminado la dirección de email de la ficha del cliente.
Actualiza la dirección de email con una correcta.`;
smtp.send({
to: client.salesPersonEmail,
subject: 'No se ha podido enviar el albarán',
html: body,
}).catch(err => console.error(err));
}
};

View File

@ -284,39 +284,6 @@
}
}
},
{
"relation": "business",
"scope": {
"fields": [
"id",
"started",
"ended",
"reasonEndFk",
"departmentFk",
"workerBusinessProfessionalCategoryFk"
],
"include":[
{
"relation": "department",
"scope": {
"fields": ["id", "name"]
}
},
{
"relation": "reasonEnd",
"scope": {
"fields": ["id", "reason"]
}
},
{
"relation": "workerBusinessProfessionalCategory",
"scope": {
"fields": ["id", "description"]
}
}
]
}
},
{
"relation": "boss",
"scope": {

View File

@ -70,7 +70,7 @@
<td width="5%">{{sale.itemFk}}</td>
<td class="number">{{sale.quantity}}</td>
<td width="50%">{{sale.concept}}</td>
<td width="5%" class="font light-gray" v-if="sale.subName">{{sale.subName}}</td>
<td width="5%" class="font light-gray">{{sale.subName}}</td>
<td class="number" v-if="showPrices">{{sale.price | currency('EUR', $i18n.locale)}}</td>
<td class="centered" width="5%" v-if="showPrices">{{(sale.discount / 100) | percentage}}</td>
<td class="centered" v-if="showPrices">{{sale.vatType}}</td>