7366-travelMigration #3054
|
@ -2442,30 +2442,32 @@ INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `
|
||||||
(1107, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 1),
|
(1107, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 1),
|
||||||
(1107, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 1);
|
(1107, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`dmsType`(`id`, `name`, `readRoleFk`, `writeRoleFk`, `code`)
|
INSERT INTO `vn`.`dmsType`
|
||||||
|
(`id`, `name`, `readRoleFk`, `writeRoleFk`, `code`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Facturas Recibidas', NULL, NULL, 'invoiceIn'),
|
(1, 'Facturas Recibidas', NULL, NULL, 'invoiceIn'),
|
||||||
(2, 'Doc oficial', NULL, NULL, 'officialDoc'),
|
(2, 'Doc oficial', NULL, NULL, 'officialDoc'),
|
||||||
(3, 'Laboral', 37, 37, 'hhrrData'),
|
(3, 'Laboral', 37, 37, 'hhrrData'),
|
||||||
(4, 'Albaranes recibidos', NULL, NULL, 'deliveryNote'),
|
(4, 'Albaranes recibidos', NULL, NULL, 'deliveryNote'),
|
||||||
(5, 'Otros', 1, 1, 'miscellaneous'),
|
(5, 'Otros', 1, 1, 'miscellaneous'),
|
||||||
(6, 'Pruebas', NULL, NULL, 'tests'),
|
(6, 'Pruebas', NULL, NULL, 'tests'),
|
||||||
(7, 'IAE Clientes', 1, 1, 'economicActivitiesTax'),
|
(7, 'IAE Clientes', 1, 1, 'economicActivitiesTax'),
|
||||||
(8, 'Fiscal', NULL, NULL, 'fiscal'),
|
(8, 'Fiscal', NULL, NULL, 'fiscal'),
|
||||||
(9, 'Vehiculos', NULL, NULL, 'vehicles'),
|
(9, 'Vehiculos', NULL, NULL, 'vehicles'),
|
||||||
(10, 'Plantillas', NULL, NULL, 'templates'),
|
(10, 'Plantillas', NULL, NULL, 'templates'),
|
||||||
(11, 'Contratos', NULL, NULL, 'contracts'),
|
(11, 'Contratos', NULL, NULL, 'contracts'),
|
||||||
(12, 'ley de pagos', 1, 1, 'paymentsLaw'),
|
(12, 'ley de pagos', 1, 1, 'paymentsLaw'),
|
||||||
(13, 'Basura', 1, 1, 'trash'),
|
(13, 'Basura', 1, 1, 'trash'),
|
||||||
(14, 'Ticket', 1, 1, 'ticket'),
|
(14, 'Ticket', 1, 1, 'ticket'),
|
||||||
(15, 'Presupuestos', NULL, NULL, 'budgets'),
|
(15, 'Presupuestos', NULL, NULL, 'budgets'),
|
||||||
(16, 'Logistica', NULL, NULL, 'logistics'),
|
(16, 'Logistica', NULL, NULL, 'logistics'),
|
||||||
(17, 'cmr', 1, 1, 'cmr'),
|
(17, 'cmr', 1, 1, 'cmr'),
|
||||||
(18, 'dua', NULL, NULL, 'dua'),
|
(18, 'dua', NULL, NULL, 'dua'),
|
||||||
(19, 'inmovilizado', NULL, NULL, 'fixedAssets'),
|
(19, 'inmovilizado', NULL, NULL, 'fixedAssets'),
|
||||||
(20, 'Reclamación', 1, 1, 'claim'),
|
(20, 'Reclamación', 1, 1, 'claim'),
|
||||||
(21, 'Entrada', 1, 1, 'entry'),
|
(21, 'Entrada', 1, 1, 'entry'),
|
||||||
(22, 'Proveedor', 1, 1, 'supplier');
|
(22, 'Proveedor', 1, 1, 'supplier'),
|
||||||
|
(23, 'Termografos', 35, 35, 'thermograph');
|
||||||
|
|
||||||
INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`)
|
INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -2473,7 +2475,7 @@ INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `wa
|
||||||
(2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', util.VN_CURDATE()),
|
(2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', util.VN_CURDATE()),
|
||||||
(3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', util.VN_CURDATE()),
|
(3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', util.VN_CURDATE()),
|
||||||
(4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', util.VN_CURDATE()),
|
(4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', util.VN_CURDATE()),
|
||||||
(5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', util.VN_CURDATE()),
|
(5, 23, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', util.VN_CURDATE()),
|
||||||
(6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', util.VN_CURDATE()),
|
(6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', util.VN_CURDATE()),
|
||||||
(7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()),
|
(7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()),
|
||||||
(8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()),
|
(8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()),
|
||||||
|
|
|
@ -59,7 +59,7 @@ BEGIN
|
||||||
DELETE b FROM buy b
|
DELETE b FROM buy b
|
||||||
JOIN entryConfig e ON e.defaultEntry = b.entryFk
|
JOIN entryConfig e ON e.defaultEntry = b.entryFk
|
||||||
WHERE b.created < v2Months;
|
WHERE b.created < v2Months;
|
||||||
DELETE FROM stockBuyed WHERE creationDate < v2Months;
|
DELETE FROM stockBought WHERE dated < v2Months;
|
||||||
DELETE FROM printQueue WHERE statusCode = 'printed' AND created < v2Months;
|
DELETE FROM printQueue WHERE statusCode = 'printed' AND created < v2Months;
|
||||||
-- Equipos duplicados
|
-- Equipos duplicados
|
||||||
DELETE w.*
|
DELETE w.*
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyedByWorker`(
|
|
||||||
vDated DATE,
|
|
||||||
vWorker INT
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Inserta el volumen de compra de un comprador
|
|
||||||
* en stockBuyed de acuerdo con la fecha.
|
|
||||||
*
|
|
||||||
* @param vDated Fecha de compra
|
|
||||||
* @param vWorker Id de trabajador
|
|
||||||
*/
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tStockBuyed
|
|
||||||
(INDEX (userFk))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT requested, reserved, userFk
|
|
||||||
FROM stockBuyed
|
|
||||||
WHERE dated = vDated
|
|
||||||
AND userFk = vWorker;
|
|
||||||
|
|
||||||
DELETE FROM stockBuyed
|
|
||||||
WHERE dated = vDated
|
|
||||||
AND userFk = vWorker;
|
|
||||||
|
|
||||||
CALL item_calculateStock(vDated);
|
|
||||||
|
|
||||||
INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description)
|
|
||||||
SELECT it.workerFk,
|
|
||||||
SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000,
|
|
||||||
vDated,
|
|
||||||
sb.reserved,
|
|
||||||
sb.requested,
|
|
||||||
u.name
|
|
||||||
FROM itemType it
|
|
||||||
JOIN item i ON i.typeFk = it.id
|
|
||||||
LEFT JOIN tmp.item ti ON ti.itemFk = i.id
|
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
|
||||||
JOIN warehouse wh ON wh.code = 'VNH'
|
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
|
|
||||||
AND bu.warehouseFk = wh.id
|
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
JOIN account.`user` u ON u.id = it.workerFk
|
|
||||||
LEFT JOIN tStockBuyed sb ON sb.userFk = it.workerFk
|
|
||||||
WHERE ic.display
|
|
||||||
AND it.workerFk = vWorker;
|
|
||||||
|
|
||||||
SELECT b.entryFk Id_Entrada,
|
|
||||||
i.id Id_Article,
|
|
||||||
i.name Article,
|
|
||||||
ti.quantity Cantidad,
|
|
||||||
(ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id))
|
|
||||||
/ (vc.trolleyM3 * 1000000) buyed,
|
|
||||||
b.packagingFk id_cubo,
|
|
||||||
b.packing
|
|
||||||
FROM tmp.item ti
|
|
||||||
JOIN item i ON i.id = ti.itemFk
|
|
||||||
JOIN itemType it ON i.typeFk = it.id
|
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
|
||||||
JOIN worker w ON w.id = it.workerFk
|
|
||||||
JOIN auctionConfig ac
|
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
|
|
||||||
AND bu.warehouseFk = ac.warehouseFk
|
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
WHERE ic.display
|
|
||||||
AND w.id = vWorker;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.buyUltimate,
|
|
||||||
tmp.item,
|
|
||||||
tStockBuyed;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,70 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockBuyed_add`(
|
|
||||||
vDated DATE
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Inserta el volumen de compra por comprador
|
|
||||||
* en stockBuyed de acuerdo con la fecha.
|
|
||||||
*
|
|
||||||
* @param vDated Fecha de compra
|
|
||||||
*/
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tStockBuyed
|
|
||||||
(INDEX (userFk))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT requested, reserved, userFk
|
|
||||||
FROM stockBuyed
|
|
||||||
WHERE dated = vDated;
|
|
||||||
|
|
||||||
DELETE FROM stockBuyed WHERE dated = vDated;
|
|
||||||
|
|
||||||
CALL item_calculateStock(vDated);
|
|
||||||
|
|
||||||
INSERT INTO stockBuyed(userFk, buyed, `dated`, description)
|
|
||||||
SELECT it.workerFk,
|
|
||||||
SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000,
|
|
||||||
vDated,
|
|
||||||
u.name
|
|
||||||
FROM itemType it
|
|
||||||
JOIN item i ON i.typeFk = it.id
|
|
||||||
LEFT JOIN tmp.item ti ON ti.itemFk = i.id
|
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
|
||||||
JOIN warehouse wh ON wh.code = 'VNH'
|
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id AND bu.warehouseFk = wh.id
|
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
JOIN account.`user` u ON u.id = it.workerFk
|
|
||||||
JOIN workerDepartment wd ON wd.workerFk = u.id
|
|
||||||
JOIN department d ON d.id = wd.departmentFk
|
|
||||||
WHERE ic.display
|
|
||||||
AND d.code IN ('shopping', 'logistic', 'franceTeam')
|
|
||||||
GROUP BY it.workerFk;
|
|
||||||
|
|
||||||
INSERT INTO stockBuyed(buyed, dated, description)
|
|
||||||
SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000),
|
|
||||||
vDated,
|
|
||||||
IF(c.code = 'ES', p.name, c.name) destiny
|
|
||||||
FROM itemTicketOut ito
|
|
||||||
JOIN ticket t ON t.id = ito.ticketFk
|
|
||||||
JOIN `address` a ON a.id = t.addressFk
|
|
||||||
JOIN province p ON p.id = a.provinceFk
|
|
||||||
JOIN country c ON c.id = p.countryFk
|
|
||||||
JOIN warehouse wh ON wh.id = t.warehouseFk
|
|
||||||
JOIN itemCost ic ON ic.itemFk = ito.itemFk
|
|
||||||
AND ic.warehouseFk = t.warehouseFk
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
WHERE ito.shipped BETWEEN vDated AND util.dayend(vDated)
|
|
||||||
AND wh.code = 'VNH'
|
|
||||||
GROUP BY destiny;
|
|
||||||
|
|
||||||
UPDATE stockBuyed s
|
|
||||||
JOIN tStockBuyed ts ON ts.userFk = s.userFk
|
|
||||||
SET s.requested = ts.requested,
|
|
||||||
s.reserved = ts.reserved
|
|
||||||
WHERE s.dated = vDated;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.buyUltimate,
|
|
||||||
tmp.item,
|
|
||||||
tStockBuyed;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketRefund_upsert`(
|
||||||
|
vRefundTicketFk INT,
|
||||||
|
vOriginalTicketFk INT
|
||||||
|
)
|
||||||
|
READS SQL DATA
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Common code for ticketRefund triggers
|
||||||
|
*
|
||||||
|
* @param vRefundTicketFk
|
||||||
|
* @param vOriginalTicketFk
|
||||||
|
*/
|
||||||
|
DECLARE vIsDeleted BOOL;
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vIsDeleted
|
||||||
|
FROM ticket
|
||||||
|
WHERE id IN (vRefundTicketFk, vOriginalTicketFk)
|
||||||
|
AND isDeleted;
|
||||||
|
|
||||||
|
IF vIsDeleted THEN
|
||||||
|
CALL util.throw('The refund ticket cannot be deleted tickets');
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`ticketRefund_beforeInse
|
||||||
BEFORE INSERT ON `ticketRefund`
|
BEFORE INSERT ON `ticketRefund`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
CALL ticketRefund_upsert(NEW.refundTicketFk, NEW.originalTicketFk);
|
||||||
|
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`ticketRefund_beforeUpda
|
||||||
BEFORE UPDATE ON `ticketRefund`
|
BEFORE UPDATE ON `ticketRefund`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
CALL ticketRefund_upsert(NEW.refundTicketFk, NEW.originalTicketFk);
|
||||||
|
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -4,5 +4,14 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`travelThermograph_befor
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
|
IF NEW.travelFk IS NULL AND
|
||||||
|
(SELECT COUNT(*) FROM travelThermograph
|
||||||
|
WHERE thermographFk = NEW.thermographFk
|
||||||
|
AND travelFk IS NULL
|
||||||
|
AND id <> NEW.id) > 0
|
||||||
|
THEN
|
||||||
|
CALL util.throw('Duplicate thermographFk without travelFk not allowed.');
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -4,5 +4,14 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`travelThermograph_befor
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
|
IF NEW.travelFk IS NULL AND
|
||||||
|
(SELECT COUNT(*) FROM travelThermograph
|
||||||
|
WHERE thermographFk = NEW.thermographFk
|
||||||
|
AND travelFk IS NULL
|
||||||
|
AND id <> NEW.id) > 0
|
||||||
|
THEN
|
||||||
|
CALL util.throw('Duplicate thermographFk without travelFk not allowed.');
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
RENAME TABLE vn.stockBuyed TO vn.stockBuyed__;
|
||||||
|
ALTER TABLE vn.stockBuyed__
|
||||||
|
COMMENT='@deprecated 2024-10-01 rename and refactor to stockBought';
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.address MODIFY COLUMN isEqualizated tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.autonomy MODIFY COLUMN isUeeMember tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.chat MODIFY COLUMN checkUserStatus tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE vn.warehouse
|
||||||
|
MODIFY COLUMN isOrigin tinyint(1) DEFAULT FALSE NOT NULL,
|
||||||
|
MODIFY COLUMN isDestiny tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE vn.zoneIncluded MODIFY COLUMN isIncluded tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE bs.defaulter MODIFY COLUMN hasChanged tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE account.user MODIFY COLUMN emailVerified tinyint(1) DEFAULT FALSE NOT NULL;
|
|
@ -106,10 +106,15 @@ module.exports = Self => {
|
||||||
description: `The to shipped date filter`
|
description: `The to shipped date filter`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'days',
|
arg: 'daysOnward',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: `N days interval`
|
description: `N days interval`
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'daysAgo',
|
||||||
|
type: 'number',
|
||||||
|
description: `N days ago interval`
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'invoiceAmount',
|
arg: 'invoiceAmount',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -216,16 +221,29 @@ module.exports = Self => {
|
||||||
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
JOIN vn.currency cu ON cu.id = e.currencyFk`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ctx.args.days) {
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
stmt.merge({
|
|
||||||
sql: `
|
const {daysAgo, daysOnward} = ctx.args;
|
||||||
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
if (daysOnward || daysAgo) {
|
||||||
AND t.shipped >= util.VN_CURDATE()
|
const params = [];
|
||||||
`,
|
let today = 'util.VN_CURDATE()';
|
||||||
params: [ctx.args.days]
|
let from = today;
|
||||||
});
|
let to = today;
|
||||||
|
|
||||||
|
if (daysAgo) {
|
||||||
|
from += ' - INTERVAL ? DAY';
|
||||||
|
params.push(daysAgo);
|
||||||
|
}
|
||||||
|
if (daysOnward) {
|
||||||
|
to += ' + INTERVAL ? DAY';
|
||||||
|
params.push(daysOnward);
|
||||||
|
}
|
||||||
|
|
||||||
|
const whereDays = (filter.where ? 'AND' : 'WHERE') + ` t.shipped BETWEEN ${from} AND ${to}`;
|
||||||
|
stmt.merge({sql: whereDays, params});
|
||||||
}
|
}
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
|
||||||
|
stmt.merge(conn.makePagination(filter));
|
||||||
const itemsIndex = stmts.push(stmt) - 1;
|
const itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
|
|
@ -49,13 +49,13 @@ describe('Entry filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should return the entry matching the supplier', () => {
|
describe('should return the entry matching the supplier', () => {
|
||||||
it('when userId is supplier ', async() => {
|
it('when userId is supplier and searching days onward', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {days: 6},
|
args: {daysOnward: 6},
|
||||||
req: {accessToken: {userId: 1102}}
|
req: {accessToken: {userId: 1102}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,6 +70,27 @@ describe('Entry filter()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('when userId is supplier and searching days ago', async() => {
|
||||||
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
|
args: {daysAgo: 31},
|
||||||
|
req: {accessToken: {userId: 1102}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('when userId is supplier fetching other supplier', async() => {
|
it('when userId is supplier fetching other supplier', async() => {
|
||||||
const tx = await models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
|
@ -142,12 +142,19 @@ module.exports = Self => {
|
||||||
ctx.args.addressId = ticket.addressFk;
|
ctx.args.addressId = ticket.addressFk;
|
||||||
|
|
||||||
const newTicket = await models.Ticket.new(ctx, myOptions);
|
const newTicket = await models.Ticket.new(ctx, myOptions);
|
||||||
|
const existingRefund = await models.TicketRefund.findOne({
|
||||||
await models.TicketRefund.create({
|
where: {
|
||||||
originalTicketFk: ticketId,
|
originalTicketFk: ticketId,
|
||||||
refundTicketFk: newTicket.id
|
refundTicketFk: newTicket.id
|
||||||
}, myOptions);
|
},
|
||||||
|
myOptions
|
||||||
|
});
|
||||||
|
if (!existingRefund) {
|
||||||
|
await models.TicketRefund.create({
|
||||||
|
originalTicketFk: ticketId,
|
||||||
|
refundTicketFk: newTicket.id
|
||||||
|
}, myOptions);
|
||||||
|
}
|
||||||
return newTicket;
|
return newTicket;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,7 +117,8 @@ module.exports = Self => {
|
||||||
result: state,
|
result: state,
|
||||||
maxTemperature,
|
maxTemperature,
|
||||||
minTemperature,
|
minTemperature,
|
||||||
temperatureFk
|
temperatureFk,
|
||||||
|
warehouseFk: warehouseId,
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
|
@ -4,7 +4,7 @@ describe('Thermograph saveThermograph()', () => {
|
||||||
const ctx = beforeAll.getCtx();
|
const ctx = beforeAll.getCtx();
|
||||||
const travelFk = 1;
|
const travelFk = 1;
|
||||||
const thermographId = '138350-0';
|
const thermographId = '138350-0';
|
||||||
const warehouseFk = '1';
|
const warehouseFk = 1;
|
||||||
const state = 'COMPLETED';
|
const state = 'COMPLETED';
|
||||||
const maxTemperature = 30;
|
const maxTemperature = 30;
|
||||||
const minTemperature = 10;
|
const minTemperature = 10;
|
||||||
|
@ -41,7 +41,7 @@ describe('Thermograph saveThermograph()', () => {
|
||||||
maxTemperature,
|
maxTemperature,
|
||||||
minTemperature,
|
minTemperature,
|
||||||
temperatureFk,
|
temperatureFk,
|
||||||
null,
|
warehouseFk,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
|
Loading…
Reference in New Issue