feat: previas con reserva refs #6861
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
c20747434e
commit
5967bd545c
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getSales', {
|
||||
description: 'Get sales from ticket or collection',
|
||||
description: 'Get sales from ticket, collection or sectorCollection',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ module.exports = Self => {
|
|||
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
|
||||
|
||||
for (let ticket of tickets) {
|
||||
let observations = ticket.observaciones.split(' ');
|
||||
let observations = ticket.observation.split(' ');
|
||||
|
||||
for (let observation of observations) {
|
||||
const salesPerson = ticket.salesPersonFk;
|
||||
|
|
|
@ -37,6 +37,7 @@ module.exports = Self => {
|
|||
|
||||
const promises = [];
|
||||
const [tickets] = await Self.rawSql(`CALL vn.collection_getTickets(?)`, [id], myOptions);
|
||||
|
||||
const sales = await Self.rawSql(`
|
||||
SELECT s.ticketFk,
|
||||
sgd.saleGroupFk,
|
||||
|
@ -76,17 +77,55 @@ module.exports = Self => {
|
|||
LEFT JOIN origin o ON o.id = i.originFk
|
||||
WHERE tc.collectionFk = ?
|
||||
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)
|
||||
await Self.rawSql(`CALL vn.collection_printSticker(?, ?)`, [id, null], myOptions);
|
||||
|
||||
const collection = {collectionFk: id, tickets: []};
|
||||
|
||||
if (tickets && tickets.length) {
|
||||
for (const ticket of tickets) {
|
||||
const ticketId = ticket.ticketFk;
|
||||
if (ticket.observaciones != '') {
|
||||
for (observation of ticket.observaciones.split(' ')) {
|
||||
if (ticket.observation) {
|
||||
for (observation of ticket.observation?.split(' ')) {
|
||||
if (['#', '@'].includes(observation.charAt(0))) {
|
||||
promises.push(Self.app.models.Chat.send(ctx, observation,
|
||||
$t('The ticket is in preparation', {
|
||||
|
@ -100,11 +139,11 @@ module.exports = Self => {
|
|||
if (sales && sales.length) {
|
||||
const barcodes = await Self.rawSql(`
|
||||
SELECT s.id saleFk, b.code, c.id
|
||||
FROM vn.sale s
|
||||
LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk
|
||||
LEFT JOIN vn.buy c ON c.itemFk = s.itemFk
|
||||
LEFT JOIN vn.entry e ON e.id = c.entryFk
|
||||
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
|
||||
FROM sale s
|
||||
LEFT JOIN itemBarcode b ON b.itemFk = s.itemFk
|
||||
LEFT JOIN buy c ON c.itemFk = s.itemFk
|
||||
LEFT JOIN entry e ON e.id = c.entryFk
|
||||
LEFT JOIN travel tr ON tr.id = e.travelFk
|
||||
WHERE s.ticketFk = ?
|
||||
AND tr.landed >= util.VN_CURDATE() - INTERVAL 1 YEAR`,
|
||||
[ticketId], myOptions);
|
||||
|
|
|
@ -1,64 +1,44 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT)
|
||||
RETURNS int(11)
|
||||
RETURNS INT(11)
|
||||
NOT DETERMINISTIC
|
||||
READS SQL DATA
|
||||
proc:BEGIN
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el número de ticket / collection / sectorCollection consultando
|
||||
* en que tabla se encuantra en la última semana
|
||||
*
|
||||
* @param vParamFk Número a validar
|
||||
* @return vReturn Identificador validado
|
||||
*/
|
||||
DECLARE vReturn INT DEFAULT NULL;
|
||||
DECLARE vDated DATE;
|
||||
|
||||
/* Devuelve el número de ticket o collection consultando en varias tablas posibles
|
||||
*
|
||||
* @param vParamFk Número a validar
|
||||
* @return vValidFk Identificador validado
|
||||
*/
|
||||
SET vDated = util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||
|
||||
DECLARE vValidFk INT;
|
||||
SELECT COALESCE(
|
||||
(SELECT s.ticketFk
|
||||
FROM sale s
|
||||
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||
JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||
WHERE sg.id = vParamFk
|
||||
AND sg.created > vDated
|
||||
LIMIT 1),
|
||||
(SELECT c.id
|
||||
FROM collection c
|
||||
WHERE c.id = vParamFk
|
||||
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;
|
||||
|
||||
-- Tabla vn.saleGroup
|
||||
SELECT s.ticketFk INTO vValidFk
|
||||
FROM vn.sale s
|
||||
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||
JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||
WHERE sg.id = vParamFk
|
||||
AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE())
|
||||
LIMIT 1;
|
||||
|
||||
IF vValidFk THEN
|
||||
|
||||
RETURN vValidFk;
|
||||
|
||||
LEAVE proc;
|
||||
|
||||
END IF;
|
||||
|
||||
-- Tabla vn.collection
|
||||
SELECT c.id INTO vValidFk
|
||||
FROM vn.collection c
|
||||
WHERE c.id = vParamFk
|
||||
AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE());
|
||||
|
||||
IF vValidFk THEN
|
||||
|
||||
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;
|
||||
RETURN vReturn;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -2,61 +2,88 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Selecciona los tickets de una colección/ticket
|
||||
* @param vParamFk ticketFk/collectionFk
|
||||
* @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones
|
||||
* Selecciona los tickets de una colección/ticket/sectorCollection
|
||||
* @param vParamFk ticketFk/collectionFk/sectorCollection
|
||||
* @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observation
|
||||
*/
|
||||
DECLARE vItemPackingTypeFk VARCHAR(1);
|
||||
DECLARE vDated DATE;
|
||||
|
||||
-- Si los sacadores son los de pruebas, pinta los colores
|
||||
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
|
||||
FROM vn.collection
|
||||
SELECT itemPackingTypeFk
|
||||
INTO vItemPackingTypeFk
|
||||
FROM collection
|
||||
WHERE id = vParamFk;
|
||||
|
||||
SELECT t.id ticketFk,
|
||||
IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`,
|
||||
am.name agencyName,
|
||||
t.warehouseFk,
|
||||
w.id salesPersonFk,
|
||||
IFNULL(tob.description,'') observaciones,
|
||||
cc.rgb
|
||||
FROM vn.ticket t
|
||||
LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
||||
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
|
||||
SET vDated = util.yesterday();
|
||||
|
||||
WITH observation AS (
|
||||
SELECT tob.ticketFk, tob.description
|
||||
FROM ticketObservation tob
|
||||
JOIN ticketCollection tc ON tc.ticketFk = tob.ticketFk
|
||||
LEFT JOIN observationType ot ON ot.id = tob.observationTypeFk
|
||||
WHERE ot.`code` = 'itemPicker'
|
||||
AND tc.collectionFk = vParamFk
|
||||
)
|
||||
SELECT t.id ticketFk,
|
||||
IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`,
|
||||
am.name agencyName,
|
||||
t.warehouseFk,
|
||||
w.id salesPersonFk,
|
||||
IFNULL(tob.description, '') observaciones,
|
||||
IF(!(vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb`
|
||||
FROM vn.ticket t
|
||||
JOIN vn.ticketCollection tc ON t.id = tc.ticketFk
|
||||
LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21
|
||||
LEFT JOIN vn.collectionColors cc
|
||||
w.id salesPersonFk,
|
||||
IFNULL(ob.description,'') observation,
|
||||
cc.rgb
|
||||
FROM ticket t
|
||||
LEFT 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 t.id = 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 -- 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 tc.collectionFk = vParamFk;
|
||||
|
||||
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$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue