7691-testToMaster #2703
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('getSales', {
|
Self.remoteMethodCtx('getSales', {
|
||||||
description: 'Get sales from ticket or collection',
|
description: 'Get sales from ticket, collection or sectorCollection',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ module.exports = Self => {
|
||||||
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
|
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
|
||||||
|
|
||||||
for (let ticket of tickets) {
|
for (let ticket of tickets) {
|
||||||
let observations = ticket.observaciones.split(' ');
|
let observations = ticket.observation.split(' ');
|
||||||
|
|
||||||
for (let observation of observations) {
|
for (let observation of observations) {
|
||||||
const salesPerson = ticket.salesPersonFk;
|
const salesPerson = ticket.salesPersonFk;
|
||||||
|
|
|
@ -37,6 +37,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
|
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
|
||||||
|
|
||||||
const sales = await Self.rawSql(`
|
const sales = await Self.rawSql(`
|
||||||
SELECT s.ticketFk,
|
SELECT s.ticketFk,
|
||||||
sgd.saleGroupFk,
|
sgd.saleGroupFk,
|
||||||
|
@ -76,17 +77,55 @@ module.exports = Self => {
|
||||||
LEFT JOIN origin o ON o.id = i.originFk
|
LEFT JOIN origin o ON o.id = i.originFk
|
||||||
WHERE tc.collectionFk = ?
|
WHERE tc.collectionFk = ?
|
||||||
GROUP BY s.id, ish.id, p.code, p2.code
|
GROUP BY s.id, ish.id, p.code, p2.code
|
||||||
ORDER BY pickingOrder;`, [id], myOptions);
|
UNION ALL
|
||||||
|
SELECT s.ticketFk,
|
||||||
|
sgd.saleGroupFk,
|
||||||
|
s.id saleFk,
|
||||||
|
s.itemFk,
|
||||||
|
i.longName,
|
||||||
|
i.size,
|
||||||
|
ic.color,
|
||||||
|
o.code origin,
|
||||||
|
ish.packing,
|
||||||
|
ish.grouping,
|
||||||
|
s.isAdded,
|
||||||
|
s.originalQuantity,
|
||||||
|
s.quantity,
|
||||||
|
iss.quantity,
|
||||||
|
SUM(iss.quantity) OVER (PARTITION BY s.id ORDER BY ish.id),
|
||||||
|
ROW_NUMBER () OVER (PARTITION BY s.id ORDER BY p.pickingOrder),
|
||||||
|
COUNT(*) OVER (PARTITION BY s.id ORDER BY s.id) ,
|
||||||
|
sh.code,
|
||||||
|
IFNULL(p2.code, p.code),
|
||||||
|
IFNULL(p2.pickingOrder, p.pickingOrder),
|
||||||
|
iss.id itemShelvingSaleFk,
|
||||||
|
iss.isPicked
|
||||||
|
FROM sectorCollection sc
|
||||||
|
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
|
||||||
|
JOIN saleGroup sg ON sg.id = ss.saleGroupFk
|
||||||
|
JOIN ticket t ON t.id = sg.ticketFk
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||||
|
LEFT JOIN parking p2 ON p2.id = sg.parkingFk
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
|
||||||
|
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
||||||
|
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk
|
||||||
|
LEFT JOIN parking p ON p.id = sh.parkingFk
|
||||||
|
LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk
|
||||||
|
LEFT JOIN origin o ON o.id = i.originFk
|
||||||
|
WHERE sc.id = ?
|
||||||
|
GROUP BY s.id, ish.id, p.code, p2.code`, [id, id], myOptions);
|
||||||
if (print)
|
if (print)
|
||||||
await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions);
|
await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions);
|
||||||
|
|
||||||
const collection = {collectionFk: id, tickets: []};
|
const collection = {collectionFk: id, tickets: []};
|
||||||
|
|
||||||
if (tickets && tickets.length) {
|
if (tickets && tickets.length) {
|
||||||
for (const ticket of tickets) {
|
for (const ticket of tickets) {
|
||||||
const ticketId = ticket.ticketFk;
|
const ticketId = ticket.ticketFk;
|
||||||
if (ticket.observaciones != '') {
|
if (ticket.observation) {
|
||||||
for (observation of ticket.observaciones.split(' ')) {
|
for (observation of ticket.observation?.split(' ')) {
|
||||||
if (['#', '@'].includes(observation.charAt(0))) {
|
if (['#', '@'].includes(observation.charAt(0))) {
|
||||||
promises.push(Self.app.models.Chat.send(ctx, observation,
|
promises.push(Self.app.models.Chat.send(ctx, observation,
|
||||||
$t('The ticket is in preparation', {
|
$t('The ticket is in preparation', {
|
||||||
|
@ -100,11 +139,11 @@ module.exports = Self => {
|
||||||
if (sales && sales.length) {
|
if (sales && sales.length) {
|
||||||
const barcodes = await Self.rawSql(`
|
const barcodes = await Self.rawSql(`
|
||||||
SELECT s.id saleFk, b.code, c.id
|
SELECT s.id saleFk, b.code, c.id
|
||||||
FROM vn.sale s
|
FROM sale s
|
||||||
LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk
|
LEFT JOIN itemBarcode b ON b.itemFk = s.itemFk
|
||||||
LEFT JOIN vn.buy c ON c.itemFk = s.itemFk
|
LEFT JOIN buy c ON c.itemFk = s.itemFk
|
||||||
LEFT JOIN vn.entry e ON e.id = c.entryFk
|
LEFT JOIN entry e ON e.id = c.entryFk
|
||||||
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
|
LEFT JOIN travel tr ON tr.id = e.travelFk
|
||||||
WHERE s.ticketFk = ?
|
WHERE s.ticketFk = ?
|
||||||
AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`,
|
AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`,
|
||||||
[ticketId], myOptions);
|
[ticketId], myOptions);
|
||||||
|
|
|
@ -1,64 +1,44 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT)
|
||||||
RETURNS int(11)
|
RETURNS INT(11)
|
||||||
NOT DETERMINISTIC
|
NOT DETERMINISTIC
|
||||||
READS SQL DATA
|
READS SQL DATA
|
||||||
proc:BEGIN
|
BEGIN
|
||||||
|
/**
|
||||||
/* Devuelve el número de ticket o collection consultando en varias tablas posibles
|
* Devuelve el número de ticket / collection / sectorCollection consultando
|
||||||
|
* en que tabla se encuantra en la última semana
|
||||||
*
|
*
|
||||||
* @param vParamFk Número a validar
|
* @param vParamFk Número a validar
|
||||||
* @return vValidFk Identificador validado
|
* @return vReturn Identificador validado
|
||||||
*/
|
*/
|
||||||
|
DECLARE vReturn INT DEFAULT NULL;
|
||||||
|
DECLARE vDated DATE;
|
||||||
|
|
||||||
DECLARE vValidFk INT;
|
SET vDated = util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||||
|
|
||||||
-- Tabla vn.saleGroup
|
SELECT COALESCE(
|
||||||
SELECT s.ticketFk INTO vValidFk
|
(SELECT s.ticketFk
|
||||||
FROM vn.sale s
|
FROM sale s
|
||||||
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
|
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||||
JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk
|
JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||||
WHERE sg.id = vParamFk
|
WHERE sg.id = vParamFk
|
||||||
AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE())
|
AND sg.created > vDated
|
||||||
LIMIT 1;
|
LIMIT 1),
|
||||||
|
(SELECT c.id
|
||||||
IF vValidFk THEN
|
FROM collection c
|
||||||
|
|
||||||
RETURN vValidFk;
|
|
||||||
|
|
||||||
LEAVE proc;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Tabla vn.collection
|
|
||||||
SELECT c.id INTO vValidFk
|
|
||||||
FROM vn.collection c
|
|
||||||
WHERE c.id = vParamFk
|
WHERE c.id = vParamFk
|
||||||
AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE());
|
AND c.created > vDated),
|
||||||
|
(SELECT id
|
||||||
|
FROM ticket
|
||||||
|
WHERE id = vParamFk
|
||||||
|
AND shipped > vDated),
|
||||||
|
(SELECT id
|
||||||
|
FROM sectorCollection
|
||||||
|
WHERE id = vParamFk
|
||||||
|
AND created > vDated)
|
||||||
|
) INTO vReturn;
|
||||||
|
|
||||||
IF vValidFk THEN
|
RETURN vReturn;
|
||||||
|
|
||||||
RETURN vValidFk;
|
|
||||||
|
|
||||||
LEAVE proc;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Tabla vn.ticket
|
|
||||||
SELECT t.id INTO vValidFk
|
|
||||||
FROM vn.ticket t
|
|
||||||
WHERE t.id = vParamFk
|
|
||||||
AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE());
|
|
||||||
|
|
||||||
IF vValidFk THEN
|
|
||||||
|
|
||||||
RETURN vValidFk;
|
|
||||||
|
|
||||||
LEAVE proc;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
RETURN NULL;
|
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -2,61 +2,88 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Selecciona los tickets de una colección/ticket
|
* Selecciona los tickets de una colección/ticket/sectorCollection
|
||||||
* @param vParamFk ticketFk/collectionFk
|
* @param vParamFk ticketFk/collectionFk/sectorCollection
|
||||||
* @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones
|
* @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observation
|
||||||
*/
|
*/
|
||||||
DECLARE vItemPackingTypeFk VARCHAR(1);
|
DECLARE vItemPackingTypeFk VARCHAR(1);
|
||||||
|
DECLARE vDated DATE;
|
||||||
|
|
||||||
-- Si los sacadores son los de pruebas, pinta los colores
|
-- Si los sacadores son los de pruebas, pinta los colores
|
||||||
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
|
SELECT itemPackingTypeFk
|
||||||
FROM vn.collection
|
INTO vItemPackingTypeFk
|
||||||
|
FROM collection
|
||||||
WHERE id = vParamFk;
|
WHERE id = vParamFk;
|
||||||
|
|
||||||
SELECT t.id ticketFk,
|
SET vDated = util.yesterday();
|
||||||
IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`,
|
|
||||||
am.name agencyName,
|
WITH observation AS (
|
||||||
t.warehouseFk,
|
SELECT tob.ticketFk, tob.description
|
||||||
w.id salesPersonFk,
|
FROM ticketObservation tob
|
||||||
IFNULL(tob.description,'') observaciones,
|
JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk
|
||||||
cc.rgb
|
LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||||
FROM vn.ticket t
|
WHERE ot.`code` = 'itemPicker'
|
||||||
LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
AND tc.collectionFk = vParamFk
|
||||||
LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21
|
)
|
||||||
LEFT JOIN vn.collectionColors cc
|
|
||||||
ON cc.wagon = tc.wagon
|
|
||||||
AND cc.shelve = tc.`level`
|
|
||||||
AND cc.trainFk = c2.trainFk -- PAK 23/12/21
|
|
||||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
|
||||||
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
|
||||||
LEFT JOIN vn.client c ON c.id = t.clientFk
|
|
||||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
|
||||||
LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id
|
|
||||||
AND tob.observationTypeFk = 1
|
|
||||||
WHERE t.id = vParamFk
|
|
||||||
AND t.shipped >= util.yesterday()
|
|
||||||
UNION ALL
|
|
||||||
SELECT t.id ticketFk,
|
SELECT t.id ticketFk,
|
||||||
IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
||||||
am.name agencyName,
|
am.name agencyName,
|
||||||
t.warehouseFk,
|
t.warehouseFk,
|
||||||
w.id salesPersonFk,
|
w.id salesPersonFk,
|
||||||
IFNULL(tob.description, '') observaciones,
|
IFNULL(ob.description,'') observation,
|
||||||
IF(!(vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb`
|
cc.rgb
|
||||||
FROM vn.ticket t
|
FROM ticket t
|
||||||
JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
LEFT JOIN ticketCollection tc ON t.id = tc.ticketFk
|
||||||
LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21
|
LEFT JOIN collection c2 ON c2.id = tc.collectionFk
|
||||||
LEFT JOIN vn.collectionColors cc
|
LEFT JOIN collectionColors cc
|
||||||
ON cc.wagon = tc.wagon
|
ON cc.wagon = tc.wagon
|
||||||
AND cc.shelve = tc.`level`
|
AND cc.shelve = tc.`level`
|
||||||
AND cc.trainFk = c2.trainFk -- PAK 23/12/21
|
AND cc.trainFk = c2.trainFk
|
||||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
LEFT JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
LEFT JOIN vn.client c ON c.id = t.clientFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
LEFT JOIN worker w ON w.id = c.salesPersonFk
|
||||||
LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
AND tob.observationTypeFk = 1
|
WHERE t.id = vParamFk
|
||||||
WHERE tc.collectionFk = vParamFk;
|
AND t.shipped >= vDated
|
||||||
|
UNION ALL
|
||||||
|
SELECT t.id ticketFk,
|
||||||
|
IF(NOT(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
||||||
|
am.name agencyName,
|
||||||
|
t.warehouseFk,
|
||||||
|
w.id salesPersonFk,
|
||||||
|
ob.description,
|
||||||
|
IF(NOT (vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb`
|
||||||
|
FROM ticket t
|
||||||
|
JOIN ticketCollection tc ON t.id = tc.ticketFk
|
||||||
|
LEFT JOIN collection c2 ON c2.id = tc.collectionFk
|
||||||
|
LEFT JOIN collectionColors cc
|
||||||
|
ON cc.wagon = tc.wagon
|
||||||
|
AND cc.shelve = tc.`level`
|
||||||
|
AND cc.trainFk = c2.trainFk
|
||||||
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
|
LEFT JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
|
LEFT JOIN worker w ON w.id = c.salesPersonFk
|
||||||
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
|
WHERE tc.collectionFk = vParamFk
|
||||||
|
UNION ALL
|
||||||
|
SELECT sg.ticketFk,
|
||||||
|
NULL `level`,
|
||||||
|
am.name agencyName,
|
||||||
|
t.warehouseFk,
|
||||||
|
c.salesPersonFk,
|
||||||
|
ob.description,
|
||||||
|
NULL `rgb`
|
||||||
|
FROM sectorCollection sc
|
||||||
|
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
|
||||||
|
JOIN saleGroup sg ON sg.id = ss.saleGroupFk
|
||||||
|
JOIN ticket t ON t.id = sg.ticketFk
|
||||||
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
|
LEFT JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||||
|
LEFT JOIN observation ob ON ob.ticketFk = t.id
|
||||||
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
|
WHERE sc.id = vParamFk
|
||||||
|
AND t.shipped >= vDated;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue