Merge pull request 'master' (!2716) from master into test
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-dev This commit looks good Details

Reviewed-on: #2716
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Pablo Natek 2024-07-15 11:40:29 +00:00
commit 2baff02443
22 changed files with 262 additions and 165 deletions

View File

@ -63,8 +63,7 @@ module.exports = Self => {
iss.isPicked iss.isPicked
FROM ticketCollection tc FROM ticketCollection tc
LEFT JOIN collection c ON c.id = tc.collectionFk LEFT JOIN collection c ON c.id = tc.collectionFk
JOIN ticket t ON t.id = tc.ticketFk JOIN sale s ON s.ticketFk = tc.ticketFk
JOIN sale s ON s.ticketFk = t.id
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
LEFT JOIN parking p2 ON p2.id = sg.parkingFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk
@ -103,9 +102,8 @@ module.exports = Self => {
FROM sectorCollection sc FROM sectorCollection sc
JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id
JOIN saleGroup sg ON sg.id = ss.saleGroupFk JOIN saleGroup sg ON sg.id = ss.saleGroupFk
JOIN ticket t ON t.id = sg.ticketFk LEFT JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
JOIN sale s ON s.ticketFk = t.id JOIN sale s ON s.id = sgd.saleFk
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
LEFT JOIN parking p2 ON p2.id = sg.parkingFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN itemShelvingSale iss ON iss.saleFk = s.id JOIN itemShelvingSale iss ON iss.saleFk = s.id

View File

@ -2,7 +2,7 @@
<soap:Header> <soap:Header>
<mrw:AuthInfo> <mrw:AuthInfo>
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia> <mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado> <mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
<mrw:CodigoDepartamento/> <mrw:CodigoDepartamento/>
<mrw:UserName><%= mrw.user %></mrw:UserName> <mrw:UserName><%= mrw.user %></mrw:UserName>
<mrw:Password><%= mrw.password %></mrw:Password> <mrw:Password><%= mrw.password %></mrw:Password>

View File

@ -27,9 +27,9 @@ module.exports = Self => {
const mrw = await models.MrwConfig.findOne(); const mrw = await models.MrwConfig.findOne();
const {externalId} = await models.Expedition.findById(expeditionFk); const {externalId} = await models.Expedition.findById(expeditionFk);
const clientType = await models.MrwConfig.getClientType(expeditionFk);
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8'); const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
const renderedXml = ejs.render(template, {mrw, externalId}); const renderedXml = ejs.render(template, {mrw, externalId, clientType});
const response = await axios.post(mrw.url, renderedXml, { const response = await axios.post(mrw.url, renderedXml, {
headers: { headers: {
'Content-Type': 'application/soap+xml; charset=utf-8' 'Content-Type': 'application/soap+xml; charset=utf-8'

View File

@ -3,7 +3,7 @@
<soap:Header> <soap:Header>
<mrw:AuthInfo> <mrw:AuthInfo>
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia> <mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
<mrw:CodigoAbonado><%= expeditionData.clientType %></mrw:CodigoAbonado> <mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
<mrw:CodigoDepartamento/> <mrw:CodigoDepartamento/>
<mrw:UserName><%= mrw.user %></mrw:UserName> <mrw:UserName><%= mrw.user %></mrw:UserName>
<mrw:Password><%= mrw.password %></mrw:Password> <mrw:Password><%= mrw.password %></mrw:Password>

View File

@ -22,6 +22,7 @@ module.exports = Self => {
Self.createShipment = async expeditionFk => { Self.createShipment = async expeditionFk => {
const models = Self.app.models; const models = Self.app.models;
const mrw = await Self.getConfig(); const mrw = await Self.getConfig();
const clientType = await models.MrwConfig.getClientType(expeditionFk);
const today = Date.vnNew(); const today = Date.vnNew();
const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0]; const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0];
@ -52,8 +53,7 @@ module.exports = Self => {
CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference,
LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType,
IF(mw.weekdays, 'S', 'N') weekDays, IF(mw.weekdays, 'S', 'N') weekDays,
oa.description deliveryObservation, oa.description deliveryObservation
LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType
FROM expedition e FROM expedition e
JOIN ticket t ON e.ticketFk = t.id JOIN ticket t ON e.ticketFk = t.id
JOIN agencyMode am ON am.id = t.agencyModeFk JOIN agencyMode am ON am.id = t.agencyModeFk
@ -63,8 +63,7 @@ module.exports = Self => {
JOIN client c ON t.clientFk = c.id JOIN client c ON t.clientFk = c.id
JOIN address a ON t.addressFk = a.id JOIN address a ON t.addressFk = a.id
LEFT JOIN addressObservation oa ON oa.addressFk = a.id LEFT JOIN addressObservation oa ON oa.addressFk = a.id
LEFT JOIN observationType ot ON ot.id = oa.observationTypeFk AND oa.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery')
AND ot.code = 'delivery'
JOIN province p ON a.provinceFk = p.id JOIN province p ON a.provinceFk = p.id
JOIN country co ON co.id = p.countryFk JOIN country co ON co.id = p.countryFk
JOIN mrwConfig mc JOIN mrwConfig mc
@ -73,22 +72,19 @@ module.exports = Self => {
const [expeditionData] = await Self.rawSql(query, [expeditionFk]); const [expeditionData] = await Self.rawSql(query, [expeditionFk]);
if (!expeditionData)
throw new UserError(`This expedition is not a MRW shipment`);
if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0)) if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0))
throw new UserError(`This ticket has a shipped date earlier than today`); throw new UserError(`This ticket has a shipped date earlier than today`);
const shipmentResponse = await Self.sendXmlDoc( const shipmentResponse = await Self.sendXmlDoc(
__dirname + `/createShipment.ejs`, __dirname + `/createShipment.ejs`,
{mrw, expeditionData}, {mrw, expeditionData, clientType},
'application/soap+xml' 'application/soap+xml'
); );
const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio'); const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio');
if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje')); if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje'));
const file = await models.MrwConfig.getLabel(shipmentId); const file = await models.MrwConfig.getLabel(shipmentId, clientType);
return {shipmentId, file}; return {shipmentId, file};
}; };

View File

@ -2,7 +2,7 @@
<soapenv:Header> <soapenv:Header>
<mrw:AuthInfo> <mrw:AuthInfo>
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia> <mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado> <mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
<mrw:CodigoDepartamento/> <mrw:CodigoDepartamento/>
<mrw:UserName><%= mrw.user %></mrw:UserName> <mrw:UserName><%= mrw.user %></mrw:UserName>
<mrw:Password><%= mrw.password %></mrw:Password> <mrw:Password><%= mrw.password %></mrw:Password>

View File

@ -6,7 +6,13 @@ module.exports = Self => {
arg: 'shipmentId', arg: 'shipmentId',
type: 'string', type: 'string',
required: true required: true
}], },
{
arg: 'clientType',
type: 'string',
required: true
},
],
returns: { returns: {
type: 'string', type: 'string',
root: true root: true
@ -17,10 +23,14 @@ module.exports = Self => {
} }
}); });
Self.getLabel = async shipmentId => { Self.getLabel = async(shipmentId, clientType) => {
const mrw = await Self.getConfig(); const mrw = await Self.getConfig();
const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml'); const getLabelResponse = await Self.sendXmlDoc(
__dirname + `/getLabel.ejs`,
{mrw, shipmentId, clientType},
'text/xml'
);
return Self.getTextByTag(getLabelResponse, 'EtiquetaFile'); return Self.getTextByTag(getLabelResponse, 'EtiquetaFile');
}; };

View File

@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => {
); );
await models.MrwService.create(
{'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10}
);
await createMrwConfig(); await createMrwConfig();
await models.Application.rawSql(
`INSERT INTO vn.mrwService
SET agencyModeCodeFk = 'mrw',
clientType = 1,
serviceType = 1,
kg = 1`, null
);
await models.Ticket.create(ticket1); await models.Ticket.create(ticket1);
await models.Expedition.create(expedition1); await models.Expedition.create(expedition1);
}); });
@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => {
'user': 'user', 'user': 'user',
'password': 'password', 'password': 'password',
'franchiseCode': 'franchiseCode', 'franchiseCode': 'franchiseCode',
'subscriberCode': 'subscriberCode' 'subscriberCode': 'subscriberCode',
'clientTypeWidth': 6
} }
); );
} }
@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => {
it('should fail if expeditionFk is not a MrwExpedition', async() => { it('should fail if expeditionFk is not a MrwExpedition', async() => {
let error; let error;
await models.MrwConfig.createShipment(undefined).catch(e => { await models.MrwConfig.createShipment(15).catch(e => {
error = e; error = e;
}).finally(async() => { }).finally(async() => {
expect(error.message).toEqual(`This expedition is not a MRW shipment`); expect(error.message).toEqual(`ClientType not available`);
}); });
}); });

View File

@ -20,7 +20,7 @@ module.exports = Self => {
} }
}); });
Self.renderer = async (expeditionFk) => { Self.renderer = async expeditionFk => {
const models = Self.app.models; const models = Self.app.models;
const viaexpressConfig = await models.ViaexpressConfig.findOne({ const viaexpressConfig = await models.ViaexpressConfig.findOne({
@ -109,7 +109,7 @@ module.exports = Self => {
const ticket = expedition.ticket(); const ticket = expedition.ticket();
const sender = ticket.company().client(); const sender = ticket.company().client();
const shipped = ticket.shipped.toISOString(); const shipped = ticket.shipped.toISOString();
const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk);
const data = { const data = {
viaexpressConfig, viaexpressConfig,
sender, sender,

View File

@ -192,5 +192,8 @@
}, },
"RouteConfig": { "RouteConfig": {
"dataSource": "vn" "dataSource": "vn"
},
"MrwService": {
"dataSource": "vn"
} }
} }

View File

@ -31,5 +31,30 @@ module.exports = Self => {
}); });
return parser.parseFromString(data.data, 'text/xml'); return parser.parseFromString(data.data, 'text/xml');
}; };
Self.getClientType = async function(expeditionFk) {
if (!expeditionFk) throw new UserError(`No expeditionFk defined`);
const {clientTypeWidth} = await Self.getConfig();
const result = await Self.app.models.Expedition.findById(expeditionFk,
{include: [{
relation: 'ticket',
scope: {
include: {
relation: 'agencyMode',
scope: {
include: {
relation: 'mrwService',
}
}
}
}
}]}
);
const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType;
if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`);
return clientType.toString().padStart(clientTypeWidth, '0');
};
}; };

View File

@ -45,6 +45,9 @@
}, },
"notified":{ "notified":{
"type": "date" "type": "date"
},
"clientTypeWidth": {
"type": "number"
} }
} }
} }

View File

@ -0,0 +1,33 @@
{
"name": "MrwService",
"base": "VnModel",
"options": {
"mysql": {
"table": "mrwService"
}
},
"properties": {
"agencyModeCodeFk": {
"id": true,
"type": "string",
"required": true
},
"clientType": {
"type": "number",
"required": true
},
"serviceType": {
"type": "number"
},
"kg": {
"type": "number"
}
},
"relations": {
"agency": {
"type": "hasOne",
"model": "AgencyMode",
"foreignKey": "code"
}
}
}

View File

@ -1,102 +1,114 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`(
vSaleFk INT vSaleFk INT
) )
proc: BEGIN proc: BEGIN
/** /**
* Reserva una línea de venta en la ubicación más óptima * Reserva una línea de venta en la ubicación más óptima
* *
* @param vSaleFk Id de sale * @param vSaleFk Id de sale
* @param vItemShelvingSaleFk Id de reserva * @param vItemShelvingSaleFk Id de reserva
*/ */
DECLARE vLastPickingOrder INT; DECLARE vLastPickingOrder INT;
DECLARE vDone INT DEFAULT FALSE; DECLARE vDone INT DEFAULT FALSE;
DECLARE vItemShelvingFk INT; DECLARE vItemShelvingFk INT;
DECLARE vAvailable INT; DECLARE vAvailable INT;
DECLARE vReservedQuantity INT; DECLARE vReservedQuantity INT;
DECLARE vOutStanding INT; DECLARE vOutStanding INT;
DECLARE vUserFk INT; DECLARE vUserFk INT;
DECLARE vTotalReservedQuantity INT;
DECLARE vItemShelvingAvailable CURSOR FOR DECLARE vSaleQuantity INT;
SELECT ish.id itemShelvingFk,
ish.available DECLARE vItemShelvingAvailable CURSOR FOR
FROM sale s SELECT ish.id itemShelvingFk,
JOIN itemShelving ish ON ish.itemFk = s.itemFk ish.available
JOIN shelving sh ON sh.code = ish.shelvingFk FROM sale s
JOIN parking p ON p.id = sh.parkingFk JOIN itemShelving ish ON ish.itemFk = s.itemFk
JOIN sector sc ON sc.id = p.sectorFk JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN productionConfig pc JOIN parking p ON p.id = sh.parkingFk
WHERE s.id = vSaleFk JOIN sector sc ON sc.id = p.sectorFk
AND NOT sc.isHideForPickers JOIN productionConfig pc
ORDER BY s.id, WHERE s.id = vSaleFk
p.pickingOrder >= vLastPickingOrder, AND NOT sc.isHideForPickers
sh.priority DESC, ORDER BY s.id,
ish.available >= s.quantity DESC, p.pickingOrder >= vLastPickingOrder,
s.quantity MOD ish.grouping = 0 DESC, sh.priority DESC,
ish.grouping DESC, ish.available >= s.quantity DESC,
IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); s.quantity MOD ish.grouping = 0 DESC,
ish.grouping DESC,
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; IF(pc.orderMode = 'Location', p.pickingOrder, ish.created);
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
ROLLBACK; DECLARE EXIT HANDLER FOR SQLEXCEPTION
RESIGNAL; BEGIN
END; ROLLBACK;
RESIGNAL;
SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)) END;
INTO vLastPickingOrder, vOutStanding
FROM sale s SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id INTO vLastPickingOrder, vOutStanding, vSaleQuantity
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk FROM sale s
LEFT JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
LEFT JOIN parking p ON p.id = sh.parkingFk LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
WHERE s.id = vSaleFk; LEFT JOIN shelving sh ON sh.code = ish.shelvingFk
LEFT JOIN parking p ON p.id = sh.parkingFk
IF vOutStanding <= 0 THEN WHERE s.id = vSaleFk;
LEAVE proc;
END IF; IF vOutStanding <= 0 THEN
LEAVE proc;
SELECT getUser() INTO vUserFk; END IF;
OPEN vItemShelvingAvailable; SELECT getUser() INTO vUserFk;
l: LOOP
SET vDone = FALSE; OPEN vItemShelvingAvailable;
FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; l: LOOP
SET vDone = FALSE;
IF vOutStanding <= 0 OR vDone THEN FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable;
LEAVE l;
END IF; IF vOutStanding <= 0 OR vDone THEN
SELECT SUM(IFNULL(quantity, 0))
START TRANSACTION; INTO vTotalReservedQuantity
FROM itemShelvingSale
SELECT id INTO vItemShelvingFk WHERE saleFk = vSaleFk;
FROM itemShelving
WHERE id = vItemShelvingFk IF vTotalReservedQuantity <> vSaleQuantity THEN
FOR UPDATE; UPDATE sale
SET quantity = vTotalReservedQuantity
SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; WHERE id = vSaleFk;
SET vOutStanding = vOutStanding - vReservedQuantity; END IF;
LEAVE l;
IF vReservedQuantity > 0 THEN END IF;
INSERT INTO itemShelvingSale( START TRANSACTION;
itemShelvingFk,
saleFk, SELECT id INTO vItemShelvingFk
quantity, FROM itemShelving
userFk) WHERE id = vItemShelvingFk
SELECT vItemShelvingFk, FOR UPDATE;
vSaleFk,
vReservedQuantity, SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity;
vUserFk; SET vOutStanding = vOutStanding - vReservedQuantity;
UPDATE itemShelving IF vReservedQuantity > 0 THEN
SET available = available - vReservedQuantity
WHERE id = vItemShelvingFk; INSERT INTO itemShelvingSale(
itemShelvingFk,
END IF; saleFk,
quantity,
COMMIT; userFk)
END LOOP; SELECT vItemShelvingFk,
CLOSE vItemShelvingAvailable; vSaleFk,
END$$ vReservedQuantity,
vUserFk;
UPDATE itemShelving
SET available = available - vReservedQuantity
WHERE id = vItemShelvingFk;
END IF;
COMMIT;
END LOOP;
CLOSE vItemShelvingAvailable;
END$$
DELIMITER ; DELIMITER ;

View File

@ -21,6 +21,7 @@ BEGIN
DECLARE vRemainingQuantity INT; DECLARE vRemainingQuantity INT;
DECLARE vItemFk INT; DECLARE vItemFk INT;
DECLARE vTotalQuantity INT; DECLARE vTotalQuantity INT;
DECLARE vStateCode VARCHAR(45);
DECLARE EXIT HANDLER FOR SQLEXCEPTION DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
@ -32,10 +33,19 @@ BEGIN
CALL util.throw('Reservation completed'); CALL util.throw('Reservation completed');
END IF; END IF;
SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)) SELECT s.itemFk,
INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity iss.saleFk,
iss.itemShelvingFk,
SUM(IFNULL(iss.quantity,0)),
IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED')
INTO vItemFk,
vSaleFk,
vItemShelvingFk,
vReservedQuantity,
vStateCode
FROM itemShelvingSale iss FROM itemShelvingSale iss
JOIN sale s ON s.id = iss.saleFk JOIN sale s ON s.id = iss.saleFk
LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = iss.saleFk
WHERE iss.id = vItemShelvingSaleFk WHERE iss.id = vItemShelvingSaleFk
AND NOT iss.isPicked; AND NOT iss.isPicked;
@ -74,7 +84,7 @@ BEGIN
vTotalQuantity, vTotalQuantity,
`account`.`myUser_getId`(), `account`.`myUser_getId`(),
NULL, NULL,
'PREPARED', vStateCode,
TRUE); TRUE);
UPDATE sale s UPDATE sale s

View File

@ -19,21 +19,20 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tmp.sale CREATE OR REPLACE TEMPORARY TABLE tmp.sale
(saleFk INT PRIMARY KEY) (saleFk INT PRIMARY KEY)
SELECT SELECT s.ticketFk,
s.ticketFk, s.id saleFk,
s.id saleFk, s.itemFk,
s.itemFk, s.concept,
s.concept, s.quantity,
s.quantity, MAKETIME(pb.HH,pb.mm,0) etd,
MAKETIME(pb.HH,pb.mm,0) etd, pb.routeFk,
pb.routeFk, FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers,
FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing,
IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) packagingFk
b.packagingFk
FROM sale s FROM sale s
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN itemShelving ish ON ish.itemFk = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk
LEFT JOIN ( SELECT iss.itemShelvingFk, LEFT JOIN ( SELECT iss.itemShelvingFk,
s.itemFk, s.itemFk,
SUM(iss.quantity) reserve SUM(iss.quantity) reserve
FROM itemShelvingSale iss FROM itemShelvingSale iss
@ -52,6 +51,8 @@ BEGIN
LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk
LEFT JOIN buy b ON b.id = lb.buy_id LEFT JOIN buy b ON b.id = lb.buy_id
LEFT JOIN packaging pa ON pa.id = b.packagingFk
JOIN packagingConfig pc
WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut)
<= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0))
AND NOT pb.problem AND NOT pb.problem

View File

@ -44,14 +44,14 @@ BEGIN
t.shipped, t.shipped,
IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), IFNULL(a.hasDailyInvoice, co.hasDailyInvoice),
w.isManaged, w.isManaged,
c.hasToInvoice c.hasToInvoice
INTO vClientFk, INTO vClientFk,
vIsTaxDataChecked, vIsTaxDataChecked,
vCompanyFk, vCompanyFk,
vShipped, vShipped,
vHasDailyInvoice, vHasDailyInvoice,
vWithPackage, vWithPackage,
vHasToInvoice vHasToInvoice
FROM ticket t FROM ticket t
JOIN `client` c ON c.id = t.clientFk JOIN `client` c ON c.id = t.clientFk
JOIN province p ON p.id = c.provinceFk JOIN province p ON p.id = c.provinceFk
@ -64,8 +64,12 @@ BEGIN
(SELECT vCurTicketFk, p.id, COUNT(*) (SELECT vCurTicketFk, p.id, COUNT(*)
FROM expedition e FROM expedition e
JOIN packaging p ON p.id = e.packagingFk JOIN packaging p ON p.id = e.packagingFk
JOIN ticket t ON t.id = e.ticketFk
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable
AND vWithPackage AND vWithPackage
AND NOT dm.`code`= 'PICKUP'
GROUP BY p.itemFk); GROUP BY p.itemFk);
-- No retornables o no catalogados -- No retornables o no catalogados

View File

@ -53,7 +53,7 @@
<vn-autocomplete vn-one <vn-autocomplete vn-one
ng-model="$ctrl.location.countryFk" ng-model="$ctrl.location.countryFk"
url="Countries" url="Countries"
show-field="country" show-field="name"
value-field="id" value-field="id"
label="Country"> label="Country">
</vn-autocomplete> </vn-autocomplete>

View File

@ -35,10 +35,10 @@
</vn-one> </vn-one>
<vn-one> <vn-one>
<vn-label-value label="Starting time" <vn-label-value label="Starting time"
value="{{$ctrl.summary.route.time | date: 'HH:MM'}}"> value="{{$ctrl.summary.route.started | date: 'HH:mm'}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Finishing time" <vn-label-value label="Finishing time"
value="{{$ctrl.summary.route.finished | date: 'HH:MM'}}"> value="{{$ctrl.summary.route.finished | date: 'HH:mm'}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Km Start" <vn-label-value label="Km Start"
value="{{$ctrl.summary.route.kmStart}}"> value="{{$ctrl.summary.route.kmStart}}">

View File

@ -171,8 +171,8 @@ module.exports = Self => {
const address = await models.Address.create({ const address = await models.Address.create({
clientFk: user.id, clientFk: user.id,
street: street, street: street,
city: city, city,
provinceFk: provinceFk, provinceFk,
postalCode: postcode, postalCode: postcode,
mobile: phone, mobile: phone,
nickname: nickname, nickname: nickname,
@ -193,7 +193,9 @@ module.exports = Self => {
} }
await user.updateAttribute('email', email, myOptions); await user.updateAttribute('email', email, myOptions);
const {countryFk} = await Self.app.models.Province.findById(provinceFk, {
fields: ['countryFk']
});
await models.Worker.create({ await models.Worker.create({
id: user.id, id: user.id,
firstName, firstName,
@ -202,6 +204,7 @@ module.exports = Self => {
bossFk, bossFk,
fi, fi,
birth, birth,
originCountryFk: countryFk
}, myOptions); }, myOptions);
@ -212,11 +215,8 @@ module.exports = Self => {
const message = e.sqlMessage; const message = e.sqlMessage;
if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`);
if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`);
if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`); if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`);
throw e; throw e;
} }

View File

@ -27,11 +27,10 @@ module.exports = Self => {
}); });
async function tinIsValid(err, done) { async function tinIsValid(err, done) {
const filter = { const country = await Self.app.models.Country.findOne({
fields: ['code'], fields: ['code'],
where: {id: this.countryFk} where: {id: this.originCountryFk}
}; });
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null; const code = country ? country.code.toLowerCase() : null;
if (!this.fi || !validateTin(this.fi, code)) if (!this.fi || !validateTin(this.fi, code))

View File

@ -60,6 +60,11 @@
"type": "hasMany", "type": "hasMany",
"model": "Zone", "model": "Zone",
"foreignKey": "agencyModeFk" "foreignKey": "agencyModeFk"
},
"mrwService": {
"type": "belongsTo",
"model": "MrwService",
"foreignKey": "code"
} }
}, },
"acls": [ "acls": [