7806_devToTest_2332 #2801
|
@ -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
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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'
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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');
|
||||||
};
|
};
|
||||||
|
|
|
@ -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`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -192,5 +192,8 @@
|
||||||
},
|
},
|
||||||
"RouteConfig": {
|
"RouteConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"MrwService": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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');
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
},
|
},
|
||||||
"notified":{
|
"notified":{
|
||||||
"type": "date"
|
"type": "date"
|
||||||
|
},
|
||||||
|
"clientTypeWidth": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -314,5 +314,4 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`)
|
||||||
SELECT SUBSTR(`User`, @prefixLen + 1), `Host`, `Role`, `Admin_option`
|
SELECT SUBSTR(`User`, @prefixLen + 1), `Host`, `Role`, `Admin_option`
|
||||||
FROM mysql.roles_mapping
|
FROM mysql.roles_mapping
|
||||||
WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost;
|
WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost;
|
||||||
|
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
|
|
|
@ -115,10 +115,13 @@ INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType`
|
||||||
VALUES
|
VALUES
|
||||||
(1, 978, 1, 0, 2000, 9, 0);
|
(1, 978, 1, 0, 2000, 9, 0);
|
||||||
|
|
||||||
|
INSERT INTO hedera.orderConfig (`id`, `employeeFk`, `defaultAgencyFk`, `guestMethod`, `guestAgencyFk`, `reserveTime`, `defaultCompanyFk`)
|
||||||
|
VALUES (1, 1, 2, 'PICKUP', 1, '00:20:00', 442);
|
||||||
|
|
||||||
INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`)
|
INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`)
|
||||||
VALUES
|
VALUES
|
||||||
(1101, 'brucewayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es','1101'),
|
(1101, 'brucewayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es','1101'),
|
||||||
(1102, 'petterparker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'PetterParker@mydomain.com', 'en','1102'),
|
(1102, 'petterparker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 131, 1, 'PetterParker@mydomain.com', 'en','1102'),
|
||||||
(1103, 'clarkkent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr','1103'),
|
(1103, 'clarkkent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr','1103'),
|
||||||
(1104, 'tonystark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es','1104'),
|
(1104, 'tonystark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es','1104'),
|
||||||
(1105, 'maxeisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt','1105'),
|
(1105, 'maxeisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt','1105'),
|
||||||
|
@ -301,6 +304,17 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8;
|
||||||
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23;
|
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23;
|
||||||
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10;
|
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10;
|
||||||
|
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'inhouse pickup' WHERE `id` = 1;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Super-Man delivery' WHERE `id` = 2;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Teleportation device' WHERE `id` = 3;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Entanglement' WHERE `id` = 4;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Quantum break device' WHERE `id` = 5;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Walking' WHERE `id` = 6;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Gotham247' WHERE `id` = 7;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Gotham247Expensive' WHERE `id` = 8;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Other agency' WHERE `id` = 10;
|
||||||
|
UPDATE `vn`.`agencyMode` SET `description` = 'Refund' WHERE `id` = 23;
|
||||||
|
|
||||||
UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com';
|
UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com';
|
||||||
|
|
||||||
UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23;
|
UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23;
|
||||||
|
@ -979,6 +993,14 @@ INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`
|
||||||
(2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()),
|
(2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()),
|
||||||
(3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE());
|
(3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE());
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`itemMinimumQuantity`(`itemFk`, `quantity`, `started`, `ended`, `warehouseFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 5, util.VN_CURDATE() - INTERVAL 2 MONTH, util.VN_CURDATE() + INTERVAL 1 MONTH, 1),
|
||||||
|
(2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, util.VN_CURDATE() - INTERVAL 1 DAY, 2),
|
||||||
|
(3, 15, util.VN_CURDATE() + INTERVAL 3 DAY, util.VN_CURDATE() + INTERVAL 2 WEEK, 3),
|
||||||
|
(2, 10, util.VN_CURDATE() + INTERVAL 2 MONTH, NULL, 5),
|
||||||
|
(4, 8, util.VN_CURDATE() - INTERVAL 3 MONTH, NULL, NULL);
|
||||||
|
|
||||||
INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`)
|
INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`)
|
||||||
VALUES
|
VALUES
|
||||||
(71,0.141,1);
|
(71,0.141,1);
|
||||||
|
@ -1478,7 +1500,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO
|
||||||
(5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5),
|
(5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5),
|
||||||
(6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6),
|
(6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6),
|
||||||
(7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7),
|
(7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7),
|
||||||
(8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10);
|
(8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10),
|
||||||
|
(10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10);
|
||||||
|
|
||||||
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`)
|
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -1489,7 +1512,9 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed
|
||||||
(5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'),
|
(5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'),
|
||||||
(6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'),
|
(6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'),
|
||||||
(7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'),
|
(7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'),
|
||||||
(8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, '');
|
(8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''),
|
||||||
|
(9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''),
|
||||||
|
(10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, '');
|
||||||
|
|
||||||
INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`)
|
INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -25,12 +25,7 @@ BEGIN
|
||||||
JOIN vn.warehouse w ON w.id = p.warehouseFk
|
JOIN vn.warehouse w ON w.id = p.warehouseFk
|
||||||
ORDER BY warehouseFk, `grouping`;
|
ORDER BY warehouseFk, `grouping`;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
CALL vn.ticketCalculatePurge();
|
||||||
tmp.ticketCalculateItem,
|
DROP TEMPORARY TABLE tmp.item;
|
||||||
tmp.ticketComponentPrice,
|
|
||||||
tmp.ticketComponent,
|
|
||||||
tmp.ticketLot,
|
|
||||||
tmp.zoneGetShipped,
|
|
||||||
tmp.item;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -56,11 +56,23 @@ BEGIN
|
||||||
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
|
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT IFNULL(minQuantity, 0) INTO vMinQuantity
|
WITH itemMinQuantityPriority AS (
|
||||||
FROM vn.item
|
SELECT quantity,
|
||||||
WHERE id = vItem;
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY itemFk
|
||||||
|
ORDER BY warehouseFk IS NULL
|
||||||
|
) priority
|
||||||
|
FROM vn.itemMinimumQuantity
|
||||||
|
WHERE itemFk = vItem
|
||||||
|
AND `started` <= vShipment
|
||||||
|
AND (`ended` >= vShipment OR `ended` IS NULL)
|
||||||
|
AND (warehouseFk = vWarehouse OR warehouseFk IS NULL)
|
||||||
|
)
|
||||||
|
SELECT quantity INTO vMinQuantity
|
||||||
|
FROM itemMinQuantityPriority
|
||||||
|
WHERE priority = 1;
|
||||||
|
|
||||||
IF vAmount < LEAST(vMinQuantity, vAvailable) THEN
|
IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN
|
||||||
CALL util.throw ('quantityLessThanMin');
|
CALL util.throw ('quantityLessThanMin');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
|
RETURNS BOOL
|
||||||
|
DETERMINISTIC
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Check if the ticket requires to update column vn.ticket.problem
|
||||||
|
*
|
||||||
|
* @param vSelf Id ticket
|
||||||
|
* @return BOOL
|
||||||
|
*/
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vIsProblemCalcNeeded
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
|
WHERE t.id = vSelf
|
||||||
|
AND dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
||||||
|
AND c.typeFk = 'normal';
|
||||||
|
|
||||||
|
RETURN vIsProblemCalcNeeded;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_updateCoordinates`(
|
||||||
|
vTicketFk INT,
|
||||||
|
vLongitude INT,
|
||||||
|
vLatitude INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza las coordenadas de una dirección.
|
||||||
|
*
|
||||||
|
* @param vTicketFk Id del ticket
|
||||||
|
* @param vLongitude Longitud de la dirección
|
||||||
|
* @param vLatitude Latitud de la dirección
|
||||||
|
*/
|
||||||
|
DECLARE vAddressFK INT;
|
||||||
|
|
||||||
|
SELECT addressFK INTO vAddressFK
|
||||||
|
FROM ticket
|
||||||
|
WHERE id = vTicketFk;
|
||||||
|
|
||||||
|
UPDATE address
|
||||||
|
SET longitude = vLongitude,
|
||||||
|
latitude = vLatitude
|
||||||
|
WHERE id = vAddressFK;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,5 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vDated DATE
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula las últimas compras realizadas hasta una fecha
|
* Calcula las últimas compras realizadas hasta una fecha
|
||||||
|
@ -19,6 +22,7 @@ BEGIN
|
||||||
FROM cache.last_buy
|
FROM cache.last_buy
|
||||||
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
||||||
|
|
||||||
|
IF vDated >= util.VN_CURDATE() THEN
|
||||||
CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated);
|
CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated);
|
||||||
|
|
||||||
REPLACE INTO tmp.buyUltimate
|
REPLACE INTO tmp.buyUltimate
|
||||||
|
@ -34,6 +38,6 @@ BEGIN
|
||||||
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
AND landed > vDated
|
AND landed > vDated
|
||||||
ORDER BY isIgnored = FALSE DESC;
|
ORDER BY isIgnored = FALSE DESC;
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vStarted DATE,
|
||||||
|
vEnded DATE
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula las últimas compras realizadas
|
* Calcula las últimas compras realizadas
|
||||||
|
@ -21,12 +25,13 @@ BEGIN
|
||||||
-- Item
|
-- Item
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
||||||
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
||||||
(PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
(PRIMARY KEY (itemFk, warehouseFk),
|
||||||
|
INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT itemFk,
|
SELECT itemFk,
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
buyFk,
|
buyFk,
|
||||||
MAX(landed) landed,
|
landed,
|
||||||
isIgnored
|
isIgnored
|
||||||
FROM (SELECT b.itemFk,
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
|
@ -45,8 +50,12 @@ BEGIN
|
||||||
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
b.id buyFk,
|
b.id buyFk,
|
||||||
t.landed,
|
t.landed,
|
||||||
|
@ -58,11 +67,17 @@ BEGIN
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
AND b.price2 > 0
|
AND b.price2 > 0
|
||||||
AND NOT b.isIgnored
|
AND NOT b.isIgnored
|
||||||
GROUP BY itemFk, warehouseInFk;
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
b.id buyFk,
|
b.id buyFk,
|
||||||
t.landed,
|
t.landed,
|
||||||
|
@ -73,14 +88,16 @@ BEGIN
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
AND b.quantity = 0
|
AND b.quantity = 0
|
||||||
GROUP BY itemFk, warehouseInFk;
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
-- ItemOriginal
|
-- ItemOriginal
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT itemFk,
|
SELECT itemFk,
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
buyFk,
|
buyFk,
|
||||||
MAX(landed) landed,
|
landed,
|
||||||
isIgnored
|
isIgnored
|
||||||
FROM (SELECT b.itemFk,
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
|
@ -99,11 +116,14 @@ BEGIN
|
||||||
AND itemOriginalFk
|
AND itemOriginalFk
|
||||||
ORDER BY t.landed DESC, b.id DESC
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
LIMIT 10000000000000000000) sub
|
LIMIT 10000000000000000000) sub
|
||||||
GROUP BY itemOriginalFk, warehouseFk;
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
b.id buyFk,
|
b.id buyFk,
|
||||||
t.landed,
|
t.landed,
|
||||||
|
@ -116,11 +136,18 @@ BEGIN
|
||||||
AND b.price2 > 0
|
AND b.price2 > 0
|
||||||
AND NOT b.isIgnored
|
AND NOT b.isIgnored
|
||||||
AND itemOriginalFk
|
AND itemOriginalFk
|
||||||
GROUP BY itemOriginalFk, warehouseInFk;
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM
|
||||||
|
(SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
b.id buyFk,
|
b.id buyFk,
|
||||||
t.landed,
|
t.landed,
|
||||||
|
@ -132,6 +159,8 @@ BEGIN
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
AND b.quantity = 0
|
AND b.quantity = 0
|
||||||
AND itemOriginalFk
|
AND itemOriginalFk
|
||||||
GROUP BY itemOriginalFk, warehouseInFk;
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -45,8 +45,7 @@ BEGIN
|
||||||
|
|
||||||
CALL catalog_componentPrepare();
|
CALL catalog_componentPrepare();
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem(
|
||||||
CREATE TEMPORARY TABLE tmp.ticketCalculateItem(
|
|
||||||
itemFk INT(11) NOT NULL,
|
itemFk INT(11) NOT NULL,
|
||||||
available INT(11),
|
available INT(11),
|
||||||
producer VARCHAR(50),
|
producer VARCHAR(50),
|
||||||
|
@ -60,11 +59,11 @@ BEGIN
|
||||||
price DECIMAL(10,2),
|
price DECIMAL(10,2),
|
||||||
priceKg DECIMAL(10,2),
|
priceKg DECIMAL(10,2),
|
||||||
`grouping` INT(10) UNSIGNED,
|
`grouping` INT(10) UNSIGNED,
|
||||||
|
minQuantity INT(10) UNSIGNED,
|
||||||
PRIMARY KEY `itemFk` (`itemFk`)
|
PRIMARY KEY `itemFk` (`itemFk`)
|
||||||
) ENGINE = MEMORY DEFAULT CHARSET=utf8;
|
) ENGINE = MEMORY DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
OPEN cTravelTree;
|
OPEN cTravelTree;
|
||||||
|
|
||||||
l: LOOP
|
l: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped;
|
FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped;
|
||||||
|
@ -136,7 +135,7 @@ BEGIN
|
||||||
|
|
||||||
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
|
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
|
||||||
|
|
||||||
INSERT INTO tmp.ticketCalculateItem (
|
INSERT INTO tmp.ticketCalculateItem(
|
||||||
itemFk,
|
itemFk,
|
||||||
available,
|
available,
|
||||||
producer,
|
producer,
|
||||||
|
@ -149,9 +148,9 @@ BEGIN
|
||||||
origin,
|
origin,
|
||||||
price,
|
price,
|
||||||
priceKg,
|
priceKg,
|
||||||
`grouping`)
|
`grouping`,
|
||||||
SELECT
|
minQuantity)
|
||||||
tl.itemFk,
|
SELECT tl.itemFk,
|
||||||
SUM(tl.available) available,
|
SUM(tl.available) available,
|
||||||
p.name producer,
|
p.name producer,
|
||||||
i.name item,
|
i.name item,
|
||||||
|
@ -163,7 +162,8 @@ BEGIN
|
||||||
o.code origin,
|
o.code origin,
|
||||||
bl.price,
|
bl.price,
|
||||||
bl.priceKg,
|
bl.priceKg,
|
||||||
bl.`grouping`
|
bl.`grouping`,
|
||||||
|
mq.quantity
|
||||||
FROM tmp.ticketLot tl
|
FROM tmp.ticketLot tl
|
||||||
JOIN item i ON tl.itemFk = i.id
|
JOIN item i ON tl.itemFk = i.id
|
||||||
LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
|
LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
|
||||||
|
@ -179,12 +179,28 @@ BEGIN
|
||||||
) sub
|
) sub
|
||||||
GROUP BY itemFk
|
GROUP BY itemFk
|
||||||
) bl ON bl.itemFk = tl.itemFk
|
) bl ON bl.itemFk = tl.itemFk
|
||||||
WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
|
LEFT JOIN (
|
||||||
|
WITH itemMinQuantityPriority AS (
|
||||||
|
SELECT itemFk,
|
||||||
|
quantity,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY itemFk
|
||||||
|
ORDER BY warehouseFk IS NULL
|
||||||
|
) priority
|
||||||
|
FROM vn.itemMinimumQuantity
|
||||||
|
WHERE `started` <= vShipped
|
||||||
|
AND (`ended` >= vShipped OR `ended` IS NULL)
|
||||||
|
AND (warehouseFk = vWarehouseFk OR warehouseFk IS NULL)
|
||||||
|
)
|
||||||
|
SELECT itemFk, quantity
|
||||||
|
FROM itemMinQuantityPriority
|
||||||
|
WHERE priority = 1
|
||||||
|
) mq ON mq.itemFk = tl.itemFk
|
||||||
|
WHERE tl.zoneFk = vZoneFk
|
||||||
|
AND tl.warehouseFk = vWarehouseFk
|
||||||
GROUP BY tl.itemFk
|
GROUP BY tl.itemFk
|
||||||
ON DUPLICATE KEY UPDATE available = available + VALUES(available);
|
ON DUPLICATE KEY UPDATE available = available + VALUES(available);
|
||||||
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
CLOSE cTravelTree;
|
CLOSE cTravelTree;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -34,20 +34,25 @@ BEGIN
|
||||||
DECLARE vIsTaxDataChecked TINYINT(1);
|
DECLARE vIsTaxDataChecked TINYINT(1);
|
||||||
DECLARE vHasCoreVnl BOOLEAN;
|
DECLARE vHasCoreVnl BOOLEAN;
|
||||||
DECLARE vMandateTypeFk INT;
|
DECLARE vMandateTypeFk INT;
|
||||||
|
DECLARE vHasDailyInvoice BOOLEAN;
|
||||||
|
|
||||||
SELECT defaultPayMethodFk,
|
SELECT cc.defaultPayMethodFk,
|
||||||
defaultDueDay,
|
cc.defaultDueDay,
|
||||||
defaultCredit,
|
cc.defaultCredit,
|
||||||
defaultIsTaxDataChecked,
|
cc.defaultIsTaxDataChecked,
|
||||||
defaultHasCoreVnl,
|
cc.defaultHasCoreVnl,
|
||||||
defaultMandateTypeFk
|
cc.defaultMandateTypeFk,
|
||||||
|
c.hasDailyInvoice
|
||||||
INTO vPayMethodFk,
|
INTO vPayMethodFk,
|
||||||
vDueDay,
|
vDueDay,
|
||||||
vDefaultCredit,
|
vDefaultCredit,
|
||||||
vIsTaxDataChecked,
|
vIsTaxDataChecked,
|
||||||
vHasCoreVnl,
|
vHasCoreVnl,
|
||||||
vMandateTypeFk
|
vMandateTypeFk,
|
||||||
FROM clientConfig;
|
vHasDailyInvoice
|
||||||
|
FROM clientConfig cc
|
||||||
|
LEFT JOIN province p ON p.id = vProvinceFk
|
||||||
|
LEFT JOIN country c ON c.id = p.countryFk;
|
||||||
|
|
||||||
INSERT INTO `client`
|
INSERT INTO `client`
|
||||||
SET id = vUserFk,
|
SET id = vUserFk,
|
||||||
|
@ -65,7 +70,8 @@ BEGIN
|
||||||
credit = vDefaultCredit,
|
credit = vDefaultCredit,
|
||||||
isTaxDataChecked = vIsTaxDataChecked,
|
isTaxDataChecked = vIsTaxDataChecked,
|
||||||
hasCoreVnl = vHasCoreVnl,
|
hasCoreVnl = vHasCoreVnl,
|
||||||
isEqualizated = FALSE
|
isEqualizated = FALSE,
|
||||||
|
hasDailyInvoice = vHasDailyInvoice
|
||||||
ON duplicate KEY UPDATE
|
ON duplicate KEY UPDATE
|
||||||
payMethodFk = vPayMethodFk,
|
payMethodFk = vPayMethodFk,
|
||||||
dueDay = vDueDay,
|
dueDay = vDueDay,
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(
|
||||||
proc: BEGIN
|
vSelf INT,
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una colección en un parking.
|
* Aparca una colección en un parking.
|
||||||
*
|
*
|
||||||
* @param vCollectionFk Id de la colección
|
* @param vSelf Id colección
|
||||||
* @param vParkingFk Id del parking
|
* @param vParkingFk Id parking
|
||||||
*/
|
*/
|
||||||
REPLACE vn.ticketParking(ticketFk, parkingFk)
|
REPLACE ticketParking(ticketFk, parkingFk)
|
||||||
SELECT tc.ticketFk, vParkingFk
|
SELECT tc.ticketFk, vParkingFk
|
||||||
FROM vn.ticketCollection tc
|
FROM ticketCollection tc
|
||||||
WHERE tc.collectionFk = vCollectionFk;
|
WHERE tc.collectionFk = vSelf;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -16,6 +16,8 @@ proc: BEGIN
|
||||||
DECLARE vReservedQuantity INT;
|
DECLARE vReservedQuantity INT;
|
||||||
DECLARE vOutStanding INT;
|
DECLARE vOutStanding INT;
|
||||||
DECLARE vUserFk INT;
|
DECLARE vUserFk INT;
|
||||||
|
DECLARE vTotalReservedQuantity INT;
|
||||||
|
DECLARE vSaleQuantity INT;
|
||||||
|
|
||||||
DECLARE vItemShelvingAvailable CURSOR FOR
|
DECLARE vItemShelvingAvailable CURSOR FOR
|
||||||
SELECT ish.id itemShelvingFk,
|
SELECT ish.id itemShelvingFk,
|
||||||
|
@ -43,8 +45,8 @@ proc: BEGIN
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0))
|
SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity
|
||||||
INTO vLastPickingOrder, vOutStanding
|
INTO vLastPickingOrder, vOutStanding, vSaleQuantity
|
||||||
FROM sale s
|
FROM sale s
|
||||||
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
|
LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id
|
||||||
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk
|
||||||
|
@ -64,6 +66,16 @@ proc: BEGIN
|
||||||
FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable;
|
FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable;
|
||||||
|
|
||||||
IF vOutStanding <= 0 OR vDone THEN
|
IF vOutStanding <= 0 OR vDone THEN
|
||||||
|
SELECT SUM(IFNULL(quantity, 0))
|
||||||
|
INTO vTotalReservedQuantity
|
||||||
|
FROM itemShelvingSale
|
||||||
|
WHERE saleFk = vSaleFk;
|
||||||
|
|
||||||
|
IF vTotalReservedQuantity <> vSaleQuantity THEN
|
||||||
|
UPDATE sale
|
||||||
|
SET quantity = vTotalReservedQuantity
|
||||||
|
WHERE id = vSaleFk;
|
||||||
|
END IF;
|
||||||
LEAVE l;
|
LEAVE l;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -2,94 +2,84 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(
|
||||||
vItemFk INT,
|
vItemFk INT,
|
||||||
vWarehouseFk INT,
|
vWarehouseFk INT,
|
||||||
vDate DATETIME
|
vDated DATETIME
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* @vItemFk item a buscar
|
* Calcula el balance de un artículo.
|
||||||
* @vWarehouseFk almacen donde buscar
|
*
|
||||||
* @vDate Si la fecha es null, muestra el histórico desde el inventario.
|
* @vItemFk Id de artículo
|
||||||
* Si la fecha no es null, muestra histórico desde la fecha de vDate.
|
* @vWarehouseFk Id de almacén
|
||||||
|
* @vDated Fecha a calcular, si es NULL muestra el histórico desde el inventario
|
||||||
*/
|
*/
|
||||||
DECLARE vDateInventory DATETIME;
|
DECLARE vDateInventory DATETIME
|
||||||
|
DEFAULT (
|
||||||
|
SELECT IF(vDated, uc.mockUtcTime, c.inventoried)
|
||||||
|
FROM config c
|
||||||
|
JOIN util.config uc
|
||||||
|
);
|
||||||
|
DECLARE vSupplierInventoryFk INT
|
||||||
|
DEFAULT (SELECT supplierFk FROM inventoryConfig);
|
||||||
|
|
||||||
IF vDate IS NULL THEN
|
IF NOT vSupplierInventoryFk OR NOT vDateInventory THEN
|
||||||
SELECT inventoried INTO vDateInventory
|
CALL util.throw('Config variables are not set');
|
||||||
FROM config;
|
|
||||||
ELSE
|
|
||||||
SELECT mockUtcTime INTO vDateInventory
|
|
||||||
FROM util.config;
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemDiary(
|
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
|
||||||
shipped DATE,
|
ENGINE = MEMORY
|
||||||
`in` INT(11),
|
|
||||||
`out` INT(11),
|
|
||||||
alertLevel INT(11),
|
|
||||||
stateName VARCHAR(20),
|
|
||||||
`name` VARCHAR(50),
|
|
||||||
reference VARCHAR(50),
|
|
||||||
origin INT(11),
|
|
||||||
clientFk INT(11),
|
|
||||||
isPicked INT(11),
|
|
||||||
isTicket TINYINT(1),
|
|
||||||
lineFk INT(11),
|
|
||||||
`order` TINYINT(3) UNSIGNED,
|
|
||||||
clientType VARCHAR(20),
|
|
||||||
claimFk INT(10) UNSIGNED,
|
|
||||||
inventorySupplierFk INT(10)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO tItemDiary
|
|
||||||
WITH entriesIn AS (
|
WITH entriesIn AS (
|
||||||
SELECT tr.landed shipped,
|
SELECT 'entry' originType,
|
||||||
|
e.id originId,
|
||||||
|
tr.landed shipped,
|
||||||
b.quantity `in`,
|
b.quantity `in`,
|
||||||
NULL `out`,
|
NULL `out`,
|
||||||
st.alertLevel ,
|
st.alertLevel ,
|
||||||
st.name stateName,
|
st.name stateName,
|
||||||
s.name `name`,
|
|
||||||
e.invoiceNumber reference,
|
e.invoiceNumber reference,
|
||||||
e.id origin,
|
'supplier' entityType,
|
||||||
s.id clientFk,
|
s.id entityId,
|
||||||
|
s.name entityName,
|
||||||
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||||
FALSE isTicket,
|
FALSE isTicket,
|
||||||
b.id lineFk,
|
b.id lineFk,
|
||||||
NULL `order`,
|
NULL `order`,
|
||||||
NULL clientType,
|
NULL clientType,
|
||||||
NULL claimFk,
|
NULL claimFk,
|
||||||
ec.inventorySupplierFk
|
vSupplierInventoryFk inventorySupplierFk
|
||||||
FROM vn.buy b
|
FROM vn.buy b
|
||||||
JOIN vn.entry e ON e.id = b.entryFk
|
JOIN vn.entry e ON e.id = b.entryFk
|
||||||
JOIN vn.travel tr ON tr.id = e.travelFk
|
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||||
JOIN vn.supplier s ON s.id = e.supplierFk
|
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||||
JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
JOIN vn.state st ON st.`code` = IF(tr.landed < util.VN_CURDATE()
|
||||||
OR (util.VN_CURDATE() AND tr.isReceived),
|
OR (util.VN_CURDATE() AND tr.isReceived),
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
'FREE')
|
'FREE')
|
||||||
JOIN vn.entryConfig ec
|
|
||||||
WHERE tr.landed >= vDateInventory
|
WHERE tr.landed >= vDateInventory
|
||||||
AND vWarehouseFk = tr.warehouseInFk
|
AND tr.warehouseInFk = vWarehouseFk
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
), entriesOut AS (
|
),
|
||||||
SELECT tr.shipped,
|
entriesOut AS (
|
||||||
|
SELECT 'entry',
|
||||||
|
e.id originType,
|
||||||
|
tr.shipped,
|
||||||
NULL,
|
NULL,
|
||||||
b.quantity,
|
b.quantity,
|
||||||
st.alertLevel,
|
st.alertLevel,
|
||||||
st.name stateName,
|
st.name stateName,
|
||||||
s.name ,
|
|
||||||
e.invoiceNumber,
|
e.invoiceNumber,
|
||||||
e.id entryFk,
|
'supplier' entityType,
|
||||||
s.id supplierFk,
|
s.id entityId,
|
||||||
|
s.name,
|
||||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||||
FALSE isTicket,
|
FALSE isTicket,
|
||||||
b.id,
|
b.id,
|
||||||
NULL `order`,
|
NULL `order`,
|
||||||
NULL clientType,
|
NULL clientType,
|
||||||
NULL claimFk,
|
NULL claimFk,
|
||||||
ec.inventorySupplierFk
|
vSupplierInventoryFk
|
||||||
FROM vn.buy b
|
FROM vn.buy b
|
||||||
JOIN vn.entry e ON e.id = b.entryFk
|
JOIN vn.entry e ON e.id = b.entryFk
|
||||||
JOIN vn.travel tr ON tr.id = e.travelFk
|
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||||
|
@ -99,23 +89,25 @@ BEGIN
|
||||||
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
'FREE')
|
'FREE')
|
||||||
JOIN vn.entryConfig ec
|
|
||||||
WHERE tr.shipped >= vDateInventory
|
WHERE tr.shipped >= vDateInventory
|
||||||
AND vWarehouseFk = tr.warehouseOutFk
|
AND tr.warehouseOutFk = vWarehouseFk
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND NOT w.isFeedStock
|
AND NOT w.isFeedStock
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
), sales AS (
|
),
|
||||||
|
sales AS (
|
||||||
|
WITH itemSales AS (
|
||||||
SELECT DATE(t.shipped) shipped,
|
SELECT DATE(t.shipped) shipped,
|
||||||
s.quantity,
|
s.quantity,
|
||||||
st2.alertLevel,
|
st2.alertLevel,
|
||||||
st2.name,
|
st2.name,
|
||||||
t.nickname,
|
|
||||||
t.refFk,
|
t.refFk,
|
||||||
t.id ticketFk,
|
t.id ticketFk,
|
||||||
t.clientFk,
|
'client' entityType,
|
||||||
|
t.clientFk entityId,
|
||||||
|
t.nickname,
|
||||||
s.id saleFk,
|
s.id saleFk,
|
||||||
st.`order`,
|
st.`order`,
|
||||||
c.typeFk,
|
c.typeFk,
|
||||||
|
@ -123,62 +115,82 @@ BEGIN
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
||||||
LEFT JOIN vn.state st ON st.`code` = ts.`code`
|
LEFT JOIN vn.state st ON st.code = ts.code
|
||||||
JOIN vn.client c ON c.id = t.clientFk
|
JOIN vn.client c ON c.id = t.clientFk
|
||||||
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||||
'FREE',
|
'FREE',
|
||||||
IFNULL(ts.code, 'FREE')))
|
IFNULL(st.code, 'FREE')))
|
||||||
LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
|
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
|
||||||
WHERE t.shipped >= vDateInventory
|
WHERE t.shipped >= vDateInventory
|
||||||
AND s.itemFk = vItemFk
|
AND s.itemFk = vItemFk
|
||||||
AND vWarehouseFk = t.warehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
),sale AS (
|
)
|
||||||
SELECT s.shipped,
|
SELECT 'ticket',
|
||||||
|
s.ticketFk,
|
||||||
|
s.shipped,
|
||||||
NULL `in`,
|
NULL `in`,
|
||||||
s.quantity,
|
s.quantity,
|
||||||
s.alertLevel,
|
s.alertLevel,
|
||||||
s.name,
|
s.name,
|
||||||
s.nickname,
|
|
||||||
s.refFk,
|
s.refFk,
|
||||||
s.ticketFk,
|
s.entityType,
|
||||||
s.clientFk,
|
s.entityId,
|
||||||
IF(stk.saleFk, TRUE, NULL),
|
s.nickname,
|
||||||
|
IF(stk.saleFk, TRUE, FALSE),
|
||||||
TRUE,
|
TRUE,
|
||||||
s.saleFk,
|
s.saleFk,
|
||||||
s.`order`,
|
s.`order`,
|
||||||
s.typeFk,
|
s.typeFk,
|
||||||
s.claimFk,
|
s.claimFk,
|
||||||
NULL
|
NULL
|
||||||
FROM sales s
|
FROM itemSales s
|
||||||
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
|
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
|
||||||
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
|
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
|
||||||
AND stk.stateFk = stPrep.id
|
AND stk.stateFk = stPrep.id
|
||||||
GROUP BY s.saleFk
|
GROUP BY s.saleFk
|
||||||
) SELECT shipped,
|
),
|
||||||
`in`,
|
orders AS (
|
||||||
`out`,
|
SELECT 'order' originType,
|
||||||
alertLevel,
|
o.id originId,
|
||||||
stateName,
|
r.shipment,
|
||||||
`name`,
|
NULL 'in',
|
||||||
reference,
|
r.amount,
|
||||||
origin,
|
NULL alertLevel,
|
||||||
clientFk,
|
NULL stateName,
|
||||||
isPicked,
|
NULL invoiceNumber,
|
||||||
isTicket,
|
'client' entityType,
|
||||||
lineFk,
|
c.id,
|
||||||
`order`,
|
c.name,
|
||||||
clientType,
|
FALSE,
|
||||||
claimFk,
|
FALSE isTicket,
|
||||||
inventorySupplierFk
|
NULL buyFk,
|
||||||
FROM entriesIn
|
NULL 'order',
|
||||||
|
c.typeFk,
|
||||||
|
NULL claimFk,
|
||||||
|
NULL
|
||||||
|
FROM hedera.orderRow r
|
||||||
|
JOIN hedera.`order` o ON o.id = r.orderFk
|
||||||
|
JOIN vn.client c ON c.id = o.customer_id
|
||||||
|
WHERE r.shipment >= vDateInventory
|
||||||
|
AND r.warehouseFk = vWarehouseFk
|
||||||
|
AND r.created >= (
|
||||||
|
SELECT SUBTIME(util.VN_NOW(), reserveTime)
|
||||||
|
FROM hedera.orderConfig
|
||||||
|
)
|
||||||
|
AND NOT o.confirmed
|
||||||
|
AND r.itemFk = vItemFk
|
||||||
|
)
|
||||||
|
SELECT * FROM entriesIn
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT * FROM entriesOut
|
SELECT * FROM entriesOut
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT * FROM sale
|
SELECT * FROM sales
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM orders
|
||||||
ORDER BY shipped,
|
ORDER BY shipped,
|
||||||
(inventorySupplierFk = clientFk) DESC,
|
(inventorySupplierFk = entityId) DESC,
|
||||||
alertLevel DESC,
|
alertLevel DESC,
|
||||||
isTicket,
|
isTicket,
|
||||||
`order` DESC,
|
`order` DESC,
|
||||||
|
@ -186,19 +198,20 @@ BEGIN
|
||||||
`in` DESC,
|
`in` DESC,
|
||||||
`out` DESC;
|
`out` DESC;
|
||||||
|
|
||||||
IF vDate IS NULL THEN
|
IF vDated IS NULL THEN
|
||||||
|
|
||||||
SET @a := 0;
|
SET @a := 0;
|
||||||
SET @currentLineFk := 0;
|
SET @currentLineFk := 0;
|
||||||
SET @shipped := '';
|
SET @shipped := '';
|
||||||
|
|
||||||
SELECT DATE(@shipped:= t.shipped) shipped,
|
SELECT t.originType,
|
||||||
|
t.originId,
|
||||||
|
DATE(@shipped:= t.shipped) shipped,
|
||||||
t.alertLevel,
|
t.alertLevel,
|
||||||
t.stateName,
|
t.stateName,
|
||||||
t.origin,
|
|
||||||
t.reference,
|
t.reference,
|
||||||
t.clientFk,
|
t.entityType,
|
||||||
t.name,
|
t.entityId,
|
||||||
|
t.entityName,
|
||||||
t.`in` invalue,
|
t.`in` invalue,
|
||||||
t.`out`,
|
t.`out`,
|
||||||
@a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance,
|
@a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance,
|
||||||
|
@ -214,37 +227,41 @@ BEGIN
|
||||||
t.`order`
|
t.`order`
|
||||||
FROM tItemDiary t
|
FROM tItemDiary t
|
||||||
LEFT JOIN alertLevel a ON a.id = t.alertLevel;
|
LEFT JOIN alertLevel a ON a.id = t.alertLevel;
|
||||||
|
|
||||||
ELSE
|
ELSE
|
||||||
SELECT IFNULL(SUM(IFNULL(`in`, 0)) - SUM(IFNULL(`out`, 0)), 0) INTO @a
|
SELECT IFNULL(SUM(IFNULL(`in`, 0)) - SUM(IFNULL(`out`, 0)), 0) INTO @a
|
||||||
FROM tItemDiary
|
FROM tItemDiary
|
||||||
WHERE shipped < vDate;
|
WHERE shipped < vDated;
|
||||||
|
|
||||||
SELECT vDate shipped,
|
SELECT NULL originType,
|
||||||
0 alertLevel,
|
NULL originId,
|
||||||
0 stateName,
|
vDated shipped,
|
||||||
0 origin,
|
NULL alertLevel,
|
||||||
'' reference,
|
NULL stateName,
|
||||||
0 clientFk,
|
NULL reference,
|
||||||
|
NULL entityType,
|
||||||
|
NULL entityId,
|
||||||
'Inventario calculado',
|
'Inventario calculado',
|
||||||
@a invalue,
|
@a invalue,
|
||||||
NULL `out`,
|
NULL `out`,
|
||||||
@a balance,
|
@a balance,
|
||||||
0 lastPreparedLineFk,
|
NULL lastPreparedLineFk,
|
||||||
0 isTicket,
|
NULL isTicket,
|
||||||
0 lineFk,
|
NULL lineFk,
|
||||||
0 isPicked,
|
NULL isPicked,
|
||||||
0 clientType,
|
NULL clientType,
|
||||||
0 claimFk,
|
NULL claimFk,
|
||||||
NULL `order`
|
NULL `order`
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT shipped,
|
SELECT originType,
|
||||||
|
originId,
|
||||||
|
shipped,
|
||||||
alertlevel,
|
alertlevel,
|
||||||
stateName,
|
stateName,
|
||||||
origin,
|
|
||||||
reference,
|
reference,
|
||||||
clientFk,
|
entityType,
|
||||||
name, `in`,
|
entityId,
|
||||||
|
entityName,
|
||||||
|
`in`,
|
||||||
`out`,
|
`out`,
|
||||||
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
||||||
0,
|
0,
|
||||||
|
@ -255,7 +272,7 @@ BEGIN
|
||||||
claimFk,
|
claimFk,
|
||||||
`order`
|
`order`
|
||||||
FROM tItemDiary
|
FROM tItemDiary
|
||||||
WHERE shipped >= vDate;
|
WHERE shipped >= vDated;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tItemDiary;
|
DROP TEMPORARY TABLE tItemDiary;
|
||||||
|
|
|
@ -63,7 +63,7 @@ BEGIN
|
||||||
WHEN b.groupingMode = 'grouping' THEN b.grouping
|
WHEN b.groupingMode = 'grouping' THEN b.grouping
|
||||||
WHEN b.groupingMode = 'packing' THEN b.packing
|
WHEN b.groupingMode = 'packing' THEN b.packing
|
||||||
ELSE 1
|
ELSE 1
|
||||||
END AS minQuantity,
|
END minQuantity,
|
||||||
v.visible located,
|
v.visible located,
|
||||||
b.price2
|
b.price2
|
||||||
FROM vn.item i
|
FROM vn.item i
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(
|
||||||
proc: BEGIN
|
vSaleGroupFk VARCHAR(8),
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una preparación previa en un parking
|
* Aparca una preparación previa en un parking.
|
||||||
*
|
*
|
||||||
* @param vSaleGroupFk id de la preparación previa
|
* @param vSaleGroupFk id de la preparación previa
|
||||||
* @param vParkingFk id del parking
|
* @param vParkingFk id del parking
|
||||||
*/
|
*/
|
||||||
UPDATE vn.saleGroup sg
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
UPDATE saleGroup sg
|
||||||
SET sg.parkingFk = vParkingFk
|
SET sg.parkingFk = vParkingFk
|
||||||
WHERE sg.id = vSaleGroupFk
|
WHERE sg.id = vSaleGroupFk
|
||||||
AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
AND sg.created >= util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||||
|
|
||||||
CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk));
|
CALL ticket_setNextState(ticket_get(vSaleGroupFk));
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -19,8 +19,7 @@ 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,
|
||||||
|
@ -29,7 +28,7 @@ BEGIN
|
||||||
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,
|
||||||
b.packagingFk
|
IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) 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
|
||||||
|
@ -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
|
||||||
|
|
|
@ -5,14 +5,32 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Update column sale.problem with a problem code
|
* Update column sale.problem with a problem code
|
||||||
|
*
|
||||||
* @param vProblemCode Code to set or unset
|
* @param vProblemCode Code to set or unset
|
||||||
* @table tmp.sale(saleFk, hasProblem)
|
* @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded)
|
||||||
*/
|
*/
|
||||||
UPDATE sale s
|
DECLARE vSaleFk INT;
|
||||||
JOIN tmp.sale ts ON ts.saleFk = s.id
|
DECLARE vHasProblem INT;
|
||||||
SET s.problem = CONCAT(
|
DECLARE vDone BOOL;
|
||||||
IF(ts.hasProblem,
|
DECLARE vSaleList CURSOR FOR SELECT saleFk, hasProblem FROM tmp.sale;
|
||||||
CONCAT(s.problem, ',', vProblemCode),
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
REPLACE(s.problem, vProblemCode , '')));
|
|
||||||
|
OPEN vSaleList;
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH vSaleList INTO vSaleFk, vHasProblem;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE sale
|
||||||
|
SET problem = CONCAT(
|
||||||
|
IF(vHasProblem,
|
||||||
|
CONCAT(problem, ',', vProblemCode),
|
||||||
|
REPLACE(problem, vProblemCode , '')))
|
||||||
|
WHERE id = vSaleFk;
|
||||||
|
END LOOP;
|
||||||
|
CLOSE vSaleList;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -10,9 +10,13 @@ BEGIN
|
||||||
* @param vSelf Id del sale
|
* @param vSelf Id del sale
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(INDEX(saleFk))
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem;
|
SELECT vSelf saleFk,
|
||||||
|
sale_hasComponentLack(vSelf) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
||||||
|
FROM sale
|
||||||
|
WHERE id = vSelf;
|
||||||
|
|
||||||
CALL sale_setProblem('hasComponentLack');
|
CALL sale_setProblem('hasComponentLack');
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ BEGIN
|
||||||
* @param vComponentFk Id component
|
* @param vComponentFk Id component
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(INDEX(saleFk))
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem
|
SELECT saleFk,
|
||||||
|
sale_hasComponentLack(saleFk) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
||||||
FROM (
|
FROM (
|
||||||
SELECT s.id saleFk
|
SELECT s.id saleFk, s.ticketFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
|
|
|
@ -11,9 +11,10 @@ BEGIN
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vShipped DATE;
|
DECLARE vShipped DATE;
|
||||||
DECLARE vQuantity INT;
|
DECLARE vQuantity INT;
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity
|
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id)
|
||||||
INTO vItemFk, vWarehouseFk, vShipped, vQuantity
|
INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE s.id = vSelf;
|
WHERE s.id = vSelf;
|
||||||
|
@ -21,7 +22,9 @@ BEGIN
|
||||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
CALL buyUltimate(vWarehouseFk, vShipped);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
SELECT vSelf saleFk, MOD(vQuantity, b.`grouping`) hasProblem
|
SELECT vSelf saleFk,
|
||||||
|
MOD(vQuantity, b.`grouping`) hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded
|
||||||
FROM tmp.buyUltimate bu
|
FROM tmp.buyUltimate bu
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
JOIN buy b ON b.id = bu.buyFk
|
||||||
WHERE bu.itemFk = vItemFk;
|
WHERE bu.itemFk = vItemFk;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(
|
||||||
proc: BEGIN
|
vParam VARCHAR(8),
|
||||||
|
vParkingCode VARCHAR(8)
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
|
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
|
||||||
*
|
*
|
||||||
|
@ -8,56 +11,41 @@ proc: BEGIN
|
||||||
* @param vParkingCode código del parking
|
* @param vParkingCode código del parking
|
||||||
*/
|
*/
|
||||||
DECLARE vParkingFk INT;
|
DECLARE vParkingFk INT;
|
||||||
DECLARE vIsSaleGroup BOOL;
|
DECLARE vLastWeek DATE;
|
||||||
DECLARE vIsTicket BOOL;
|
|
||||||
DECLARE vIsCollection BOOL;
|
|
||||||
|
|
||||||
SET vParkingCode = replace(vParkingCode,' ','');
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK;
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
SET vParkingCode = REPLACE(vParkingCode, ' ', '');
|
||||||
|
|
||||||
SELECT id INTO vParkingFk
|
SELECT id INTO vParkingFk
|
||||||
FROM vn.parking
|
FROM parking
|
||||||
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
|
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
|
||||||
|
|
||||||
IF vParkingFk IS NULL THEN
|
IF vParkingFk IS NULL THEN
|
||||||
CALL util.throw('parkingNotExist');
|
CALL util.throw('parkingNotExist');
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF vParam REGEXP '^[0-9]+$' THEN
|
START TRANSACTION;
|
||||||
-- Se comprueba si es una preparación previa
|
|
||||||
SELECT COUNT(*) INTO vIsSaleGroup
|
|
||||||
FROM vn.saleGroup sg
|
|
||||||
WHERE sg.id = vParam;
|
|
||||||
|
|
||||||
IF vIsSaleGroup THEN
|
SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK;
|
||||||
CALL vn.saleGroup_setParking(vParam, vParkingFk);
|
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Se comprueba si es un ticket
|
-- Comprobamos si es una prep. previa, ticket, colección o shelving
|
||||||
SELECT COUNT(*) INTO vIsTicket
|
IF (SELECT TRUE FROM saleGroup WHERE id = vParam) THEN
|
||||||
FROM vn.ticket t
|
CALL saleGroup_setParking(vParam, vParkingFk);
|
||||||
WHERE t.id = vParam
|
ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam AND shipped >= vLastWeek) THEN
|
||||||
AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
CALL ticket_setParking(vParam, vParkingFk);
|
||||||
|
ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN
|
||||||
IF vIsTicket THEN
|
CALL collection_setParking(vParam, vParkingFk);
|
||||||
CALL vn.ticket_setParking(vParam, vParkingFk);
|
ELSEIF (SELECT TRUE FROM shelving WHERE code = vParam COLLATE utf8_unicode_ci) THEN
|
||||||
LEAVE proc;
|
CALL shelving_setParking(vParam, vParkingFk);
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Se comprueba si es una coleccion de tickets
|
|
||||||
SELECT COUNT(*) INTO vIsCollection
|
|
||||||
FROM vn.collection c
|
|
||||||
WHERE c.id = vParam
|
|
||||||
AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
|
|
||||||
|
|
||||||
IF vIsCollection THEN
|
|
||||||
CALL vn.collection_setParking(vParam, vParkingFk);
|
|
||||||
LEAVE proc;
|
|
||||||
END IF;
|
|
||||||
ELSE
|
ELSE
|
||||||
-- Por descarte, se considera una matrícula
|
CALL util.throw('paramNotExist');
|
||||||
CALL vn.shelving_setParking(vParam, vParkingFk);
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Cambia el estado del ticket al siguiente estado según la tabla state
|
* Cambia el estado del ticket al siguiente estado según la tabla state.
|
||||||
*
|
*
|
||||||
* @param vSelf id dle ticket
|
* @param vSelf Id ticket
|
||||||
*/
|
*/
|
||||||
DECLARE vStateFk INT;
|
DECLARE vStateFk INT;
|
||||||
DECLARE vNewStateFk INT;
|
DECLARE vNewStateFk INT;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
SELECT stateFk INTO vStateFk
|
SELECT stateFk INTO vStateFk
|
||||||
FROM ticketState
|
FROM ticketState
|
||||||
WHERE ticketFk = vSelf;
|
WHERE ticketFk = vSelf;
|
||||||
|
@ -17,6 +24,10 @@ BEGIN
|
||||||
FROM state
|
FROM state
|
||||||
WHERE id = vStateFk;
|
WHERE id = vStateFk;
|
||||||
|
|
||||||
|
IF vNewStateFk IS NULL THEN
|
||||||
|
CALL util.throw('The ticket not have next state');
|
||||||
|
END IF;
|
||||||
|
|
||||||
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
|
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
|
||||||
VALUES (vNewStateFk, vSelf, account.myUser_getId());
|
VALUES (vNewStateFk, vSelf, account.myUser_getId());
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(
|
||||||
proc: BEGIN
|
vSelf INT,
|
||||||
|
vParkingFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Aparca un ticket en un parking
|
* Aparca un ticket en un parking.
|
||||||
*
|
*
|
||||||
* @param vTicketFk id del ticket
|
* @param vSelf Id ticket
|
||||||
* @param vParkingFk id del parking
|
* @param vParkingFk Id parking
|
||||||
*/
|
*/
|
||||||
DECLARE vDone INT DEFAULT FALSE;
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
DECLARE vCollectionTicketFk INT;
|
DECLARE vCollectionTicketFk INT;
|
||||||
|
@ -14,16 +17,21 @@ proc: BEGIN
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
||||||
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
||||||
WHERE t.id = vTicketFk;
|
WHERE t.id = vSelf;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
|
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
|
||||||
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
|
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
|
||||||
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
|
||||||
WHERE t.id = vTicketFk
|
WHERE t.id = vSelf
|
||||||
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
|
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
|
||||||
|
|
||||||
OPEN vCursor;
|
OPEN vCursor;
|
||||||
|
|
|
@ -4,16 +4,34 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Update column ticket.problem with a problem code
|
* Update column ticket.problem with a problem code and SET NULL when
|
||||||
|
* the problem is not requiered
|
||||||
*
|
*
|
||||||
* @param vProblemCode Code to set or unset
|
* @param vProblemCode Code to set or unset
|
||||||
* @table tmp.ticket(ticketFk, hasProblem)
|
* @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded)
|
||||||
*/
|
*/
|
||||||
UPDATE ticket t
|
DECLARE vTicketFk INT;
|
||||||
JOIN tmp.ticket tt ON tt.ticketFk = t.id
|
DECLARE vHasProblem INT;
|
||||||
SET t.problem = CONCAT(
|
DECLARE vDone BOOL;
|
||||||
IF(tt.hasProblem,
|
DECLARE vTicketList CURSOR FOR SELECT ticketFk, hasProblem FROM tmp.ticket;
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
OPEN vTicketList;
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH vTicketList INTO vTicketFk, vHasProblem;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE ticket
|
||||||
|
SET problem = CONCAT(
|
||||||
|
IF(vHasProblem,
|
||||||
CONCAT(problem, ',', vProblemCode),
|
CONCAT(problem, ',', vProblemCode),
|
||||||
REPLACE(problem, vProblemCode , '')));
|
REPLACE(problem, vProblemCode , '')))
|
||||||
|
WHERE id = vTicketFk;
|
||||||
|
END LOOP;
|
||||||
|
CLOSE vTicketList;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vClientFk Id Cliente, if NULL all clients
|
* @param vClientFk Id Cliente, if NULL all clients
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
FALSE hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
||||||
|
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vSelf Id ticket, if NULL ALL tickets
|
* @param vSelf Id ticket, if NULL ALL tickets
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
FALSE hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vSelf IS NULL OR t.id = vSelf);
|
AND (vSelf IS NULL OR t.id = vSelf);
|
||||||
|
|
|
@ -10,21 +10,30 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
DECLARE vHasRisk BOOL;
|
DECLARE vHasRisk BOOL;
|
||||||
DECLARE vHasHighRisk BOOL;
|
DECLARE vHasHighRisk BOOL;
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10))
|
SELECT t.risk > (c.credit + 10),
|
||||||
INTO vHasRisk, vHasHighRisk
|
(t.risk - cc.riskTolerance) > (c.credit + 10),
|
||||||
|
ticket_isProblemCalcNeeded(t.id)
|
||||||
|
INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded
|
||||||
FROM client c
|
FROM client c
|
||||||
JOIN ticket t ON t.clientFk = c.id
|
JOIN ticket t ON t.clientFk = c.id
|
||||||
JOIN clientConfig cc
|
JOIN clientConfig cc
|
||||||
WHERE t.id = vSelf;
|
WHERE t.id = vSelf;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
SELECT vSelf ticketFk, vHasRisk hasProblem;
|
ENGINE = MEMORY
|
||||||
|
SELECT vSelf ticketFk,
|
||||||
|
vHasRisk hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('hasRisk');
|
CALL ticket_setProblem('hasRisk');
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
SELECT vSelf ticketFk, vHasHighRisk hasProblem;
|
ENGINE = MEMORY
|
||||||
|
SELECT vSelf ticketFk,
|
||||||
|
vHasHighRisk hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('hasHighRisk');
|
CALL ticket_setProblem('hasHighRisk');
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ BEGIN
|
||||||
CALL buyUltimate(vWarehouseFk, vDated);
|
CALL buyUltimate(vWarehouseFk, vDated);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
|
SELECT s.id saleFk ,
|
||||||
|
MOD(s.quantity, b.`grouping`) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||||
|
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vClientFk Id cliente, if NULL all clients
|
* @param vClientFk Id cliente, if NULL all clients
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
|
|
|
@ -8,13 +8,17 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @param vSelf Id del ticket
|
* @param vSelf Id del ticket
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
|
SELECT vSelf ticketFk,
|
||||||
|
ticket_isTooLittle(vSelf) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -10,7 +10,7 @@ BEGIN
|
||||||
* @param vItemFk Id del item, NULL ALL items
|
* @param vItemFk Id del item, NULL ALL items
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH tickets AS(
|
WITH tickets AS(
|
||||||
SELECT t.id ticketFk
|
SELECT t.id ticketFk
|
||||||
|
@ -19,7 +19,9 @@ BEGIN
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
)SELECT ticketFk,
|
||||||
|
ticket_isTooLittle(ticketFk) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM tickets;
|
FROM tickets;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
|
@ -8,6 +8,7 @@ BEGIN
|
||||||
* @param vClientFk Id cliente
|
* @param vClientFk Id cliente
|
||||||
*/
|
*/
|
||||||
DECLARE vHasDebt BOOL;
|
DECLARE vHasDebt BOOL;
|
||||||
|
DECLARE vStarted DATETIME;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vHasDebt
|
SELECT COUNT(*) INTO vHasDebt
|
||||||
FROM `client`
|
FROM `client`
|
||||||
|
@ -16,22 +17,24 @@ BEGIN
|
||||||
|
|
||||||
IF vHasDebt THEN
|
IF vHasDebt THEN
|
||||||
|
|
||||||
|
SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted
|
||||||
|
FROM clientConfig;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tTicketRisk
|
CREATE OR REPLACE TEMPORARY TABLE tTicketRisk
|
||||||
(KEY (ticketFk))
|
(KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH ticket AS(
|
WITH ticket AS(
|
||||||
SELECT id ticketFk, companyFk, DATE(shipped) dated
|
SELECT id ticketFk,
|
||||||
FROM vn.ticket t
|
companyFk,
|
||||||
|
DATE(shipped) dated,
|
||||||
|
totalWithVat,
|
||||||
|
ticket_isProblemCalcNeeded(id) isProblemCalcNeeded
|
||||||
|
FROM vn.ticket
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vClientFk
|
||||||
AND refFk IS NULL
|
AND refFk IS NULL
|
||||||
AND NOT isDeleted
|
AND NOT isDeleted
|
||||||
AND totalWithoutVat <> 0
|
AND IFNULL(totalWithVat, 0) <> 0
|
||||||
), dated AS(
|
AND shipped > vStarted
|
||||||
SELECT t.companyFk, MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started,
|
|
||||||
MAX(DATE(t.dated)) ended
|
|
||||||
FROM ticket t
|
|
||||||
JOIN vn.clientConfig cc
|
|
||||||
GROUP BY t.companyFk
|
|
||||||
), balance AS(
|
), balance AS(
|
||||||
SELECT SUM(amount)amount, companyFk
|
SELECT SUM(amount)amount, companyFk
|
||||||
FROM (
|
FROM (
|
||||||
|
@ -49,15 +52,11 @@ BEGIN
|
||||||
WHERE companyFk
|
WHERE companyFk
|
||||||
GROUP BY companyFk
|
GROUP BY companyFk
|
||||||
), uninvoiced AS(
|
), uninvoiced AS(
|
||||||
SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount
|
SELECT companyFk, dated, SUM(totalWithVat) amount
|
||||||
FROM vn.ticket t
|
FROM ticket
|
||||||
JOIN dated d
|
GROUP BY companyFk, dated
|
||||||
WHERE t.clientFk = vClientFk
|
|
||||||
AND t.refFk IS NULL
|
|
||||||
AND t.shipped BETWEEN d.started AND d.ended
|
|
||||||
GROUP BY t.companyFk, DATE(t.shipped)
|
|
||||||
), receipt AS(
|
), receipt AS(
|
||||||
SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount
|
SELECT companyFk, DATE(payed) dated, SUM(amountPaid) amount
|
||||||
FROM vn.receipt
|
FROM vn.receipt
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vClientFk
|
||||||
AND payed > util.VN_CURDATE()
|
AND payed > util.VN_CURDATE()
|
||||||
|
@ -79,7 +78,15 @@ BEGIN
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
||||||
SET t.risk = tr.amount;
|
SET t.risk = tr.amount
|
||||||
|
WHERE tr.isProblemCalcNeeded
|
||||||
|
ORDER BY t.id;
|
||||||
|
|
||||||
|
UPDATE ticket t
|
||||||
|
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
||||||
|
SET t.risk = NULL
|
||||||
|
WHERE tr.isProblemCalcNeeded
|
||||||
|
ORDER BY t.id;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTicketRisk;
|
DROP TEMPORARY TABLE tTicketRisk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
|
@ -3,18 +3,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert
|
||||||
BEFORE INSERT ON `delivery`
|
BEFORE INSERT ON `delivery`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
IF (NEW.longitude IS NOT NULL
|
||||||
IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL)
|
AND NEW.latitude IS NOT NULL
|
||||||
|
AND NEW.ticketFK IS NOT NULL)
|
||||||
THEN
|
THEN
|
||||||
UPDATE address
|
CALL address_updateCoordinates(NEW.ticketFk, NEW.longitude, NEW.latitude);
|
||||||
SET longitude = NEW.longitude,
|
|
||||||
latitude = NEW.latitude
|
|
||||||
WHERE id IN (
|
|
||||||
SELECT addressFK
|
|
||||||
FROM ticket
|
|
||||||
WHERE id = NEW.ticketFk
|
|
||||||
);
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,18 +3,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate
|
||||||
BEFORE UPDATE ON `delivery`
|
BEFORE UPDATE ON `delivery`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
IF (NEW.longitude IS NOT NULL
|
||||||
IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL)
|
AND NEW.latitude IS NOT NULL
|
||||||
|
AND NEW.ticketFK IS NOT NULL)
|
||||||
THEN
|
THEN
|
||||||
UPDATE address
|
CALL address_updateCoordinates(NEW.ticketFk, NEW.longitude, NEW.latitude);
|
||||||
SET longitude = NEW.longitude,
|
|
||||||
latitude = NEW.latitude
|
|
||||||
WHERE id IN (
|
|
||||||
SELECT addressFK
|
|
||||||
FROM ticket
|
|
||||||
WHERE id = NEW.ticketFk
|
|
||||||
);
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_afterDelete`
|
||||||
|
AFTER DELETE ON `itemMinimumQuantity`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO itemLog
|
||||||
|
SET `action` = 'delete',
|
||||||
|
`changedModel` = 'ItemMinimumQuantity',
|
||||||
|
`changedModelId` = OLD.id,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_beforeInsert`
|
||||||
|
BEFORE INSERT ON `itemMinimumQuantity`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_beforeUpdate`
|
||||||
|
BEFORE UPDATE ON `itemMinimumQuantity`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,5 +1,5 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving _afterDelete`
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterDelete`
|
||||||
AFTER DELETE ON `itemShelving`
|
AFTER DELETE ON `itemShelving`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_afterDelete`
|
||||||
|
AFTER DELETE ON `productionConfig`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO productionConfig
|
||||||
|
SET `action` = 'delete',
|
||||||
|
`changedModel` = 'ProductionConfig',
|
||||||
|
`changedModelId` = OLD.id,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeInsert`
|
||||||
|
BEFORE INSERT ON `productionConfig`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeUpdate`
|
||||||
|
BEFORE UPDATE ON `productionConfig`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -54,8 +54,7 @@ AS SELECT `b`.`entryFk` AS `Id_Entrada`,
|
||||||
`i`.`packingOut` AS `packingOut`,
|
`i`.`packingOut` AS `packingOut`,
|
||||||
`b`.`itemOriginalFk` AS `itemOriginalFk`,
|
`b`.`itemOriginalFk` AS `itemOriginalFk`,
|
||||||
`io`.`longName` AS `itemOriginalName`,
|
`io`.`longName` AS `itemOriginalName`,
|
||||||
`it`.`gramsMax` AS `gramsMax`,
|
`it`.`gramsMax` AS `gramsMax`
|
||||||
`i`.`minQuantity` AS `minQuantity`
|
|
||||||
FROM (
|
FROM (
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `vn`.`client`
|
||||||
|
ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice';
|
|
@ -0,0 +1,23 @@
|
||||||
|
ALTER TABLE vn.productionConfig
|
||||||
|
ADD editorFk int(10) unsigned DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE vn.productionConfig
|
||||||
|
ADD CONSTRAINT productionConfig_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id);
|
||||||
|
|
||||||
|
CREATE OR REPLACE TABLE `vn`.`productionConfigLog` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`originFk` int(11) DEFAULT NULL,
|
||||||
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
`action` set('insert','update','delete','select') NOT NULL,
|
||||||
|
`creationDate` timestamp NULL DEFAULT current_timestamp(),
|
||||||
|
`description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||||
|
`changedModel` enum('ProductionConfig') NOT NULL DEFAULT 'ProductionConfig',
|
||||||
|
`oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)),
|
||||||
|
`newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)),
|
||||||
|
`changedModelId` int(11) NOT NULL,
|
||||||
|
`changedModelValue` varchar(45) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `productionConfigLog_userFk` (`userFk`),
|
||||||
|
KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`),
|
||||||
|
KEY `productionConfigLog_originFk` (`originFk`,`creationDate`),
|
||||||
|
CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
@ -0,0 +1 @@
|
||||||
|
CREATE INDEX travel_landed_IDX USING BTREE ON vn.travel (landed DESC,warehouseInFk,warehouseOutFk);
|
|
@ -0,0 +1,30 @@
|
||||||
|
ALTER TABLE vn.item CHANGE minQuantity minQuantity__ int(10) unsigned DEFAULT
|
||||||
|
NULL NULL COMMENT '@deprecated 2024-07-11 refs #7704 Cantidad mínima para una línea de venta';
|
||||||
|
|
||||||
|
CREATE TABLE `vn`.`itemMinimumQuantity` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`itemFk` int(10) NOT NULL,
|
||||||
|
`quantity` int(10) NOT NULL,
|
||||||
|
`started` date NOT NULL,
|
||||||
|
`ended` date DEFAULT NULL,
|
||||||
|
`warehouseFk` smallint(5) unsigned DEFAULT NULL,
|
||||||
|
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
|
`editorFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `itemMinimumQuantity_UNIQUE` (`itemFk`, `started`, `ended`, `warehouseFk`),
|
||||||
|
KEY `itemFk` (`itemFk`),
|
||||||
|
KEY `started` (`started`),
|
||||||
|
KEY `ended` (`ended`),
|
||||||
|
KEY `warehouseFk` (`warehouseFk`),
|
||||||
|
KEY `editorFk` (`editorFk`),
|
||||||
|
CONSTRAINT `itemMinimumQuantity_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `itemMinimumQuantity_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `itemMinimumQuantity_ibfk_3` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`),
|
||||||
|
CONSTRAINT `itemMinimumQuantity_check_1` CHECK (`started` <= `ended`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE vn.itemMinimumQuantity TO buyer;
|
||||||
|
GRANT EXECUTE ON PROCEDURE vn.ticketCalculatePurge TO guest;
|
||||||
|
|
||||||
|
ALTER TABLE vn.itemLog MODIFY COLUMN changedModel enum('Item','ItemBarcode','ItemBotanical','ItemNiche','ItemTag','ItemTaxCountry','ItemMinimumQuantity')
|
||||||
|
CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Item' NOT NULL;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE vn.itemMinimumQuantity
|
||||||
|
ADD CONSTRAINT itemMinimumQuantity_check CHECK (quantity > 0);
|
|
@ -99,6 +99,10 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'hasElectronicInvoice',
|
arg: 'hasElectronicInvoice',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'hasDailyInvoice',
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -117,8 +121,6 @@ module.exports = Self => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
const $t = ctx.req.__;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
|
@ -144,6 +144,9 @@
|
||||||
},
|
},
|
||||||
"recommendedCredit": {
|
"recommendedCredit": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"hasDailyInvoice": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
@ -95,6 +94,11 @@ module.exports = Self => {
|
||||||
arg: 'to',
|
arg: 'to',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
description: `The to date filter`
|
description: `The to date filter`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'days',
|
||||||
|
type: 'number',
|
||||||
|
description: `N days interval`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -192,6 +196,15 @@ 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({
|
||||||
|
sql: `
|
||||||
|
AND t.shipped <= util.VN_CURDATE() + INTERVAL ? DAY
|
||||||
|
AND t.shipped >= util.VN_CURDATE()
|
||||||
|
`,
|
||||||
|
params: [ctx.args.days]
|
||||||
|
});
|
||||||
|
}
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
const itemsIndex = stmts.push(stmt) - 1;
|
const itemsIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ module.exports = Self => {
|
||||||
'stickers',
|
'stickers',
|
||||||
'packing',
|
'packing',
|
||||||
'grouping',
|
'grouping',
|
||||||
|
'packing',
|
||||||
'groupingMode',
|
'groupingMode',
|
||||||
'quantity',
|
'quantity',
|
||||||
'packagingFk',
|
'packagingFk',
|
||||||
|
@ -80,7 +81,9 @@ module.exports = Self => {
|
||||||
fields: [
|
fields: [
|
||||||
'id',
|
'id',
|
||||||
'typeFk',
|
'typeFk',
|
||||||
|
'stems',
|
||||||
'name',
|
'name',
|
||||||
|
'category',
|
||||||
'subName',
|
'subName',
|
||||||
'size',
|
'size',
|
||||||
'minPrice',
|
'minPrice',
|
||||||
|
@ -96,14 +99,31 @@ module.exports = Self => {
|
||||||
'value9',
|
'value9',
|
||||||
'tag10',
|
'tag10',
|
||||||
'value10',
|
'value10',
|
||||||
'groupingMode'
|
'groupingMode',
|
||||||
|
'inkFk',
|
||||||
|
'originFk',
|
||||||
|
'producerFk'
|
||||||
],
|
],
|
||||||
include: {
|
include: [
|
||||||
|
{
|
||||||
relation: 'itemType',
|
relation: 'itemType',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['code', 'description']
|
fields: ['code', 'description']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'origin',
|
||||||
|
scope: {
|
||||||
|
fields: ['code']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'producer',
|
||||||
|
scope: {
|
||||||
|
fields: ['name']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(9);
|
expect(result.length).toEqual(11);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -55,13 +55,13 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
args: {},
|
args: {days: 6},
|
||||||
req: {accessToken: {userId: 1102}}
|
req: {accessToken: {userId: 1102}}
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -84,7 +84,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -107,7 +107,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -131,7 +131,7 @@ describe('Entry filter()', () => {
|
||||||
|
|
||||||
const result = await models.Entry.filter(ctx, options);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(8);
|
expect(result.length).toEqual(10);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ describe('item getBalance()', () => {
|
||||||
const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options);
|
const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options);
|
||||||
|
|
||||||
expect(firstItemBalance[9].claimFk).toEqual(null);
|
expect(firstItemBalance[9].claimFk).toEqual(null);
|
||||||
expect(secondItemBalance[7].claimFk).toEqual(2);
|
expect(secondItemBalance[7].claimFk).toEqual(1);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
"ItemLog": {
|
"ItemLog": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"ItemMinimumQuantity": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"ItemPackingType": {
|
"ItemPackingType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
{
|
||||||
|
"name": "ItemMinimumQuantity",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "itemMinimumQuantity"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mixins": {
|
||||||
|
"Loggable": true
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Id"
|
||||||
|
},
|
||||||
|
"itemFk": {
|
||||||
|
"type": "number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"type": "number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"started": {
|
||||||
|
"type": "date",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"ended": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"warehouseFk": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"editorFk": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"item": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Item",
|
||||||
|
"foreignKey": "itemFk"
|
||||||
|
},
|
||||||
|
"warehouse": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Warehouse",
|
||||||
|
"foreignKey": "warehouseFk"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [
|
||||||
|
{
|
||||||
|
"accessType": "READ",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "buyer",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -152,10 +152,6 @@
|
||||||
"columnName": "doPhoto"
|
"columnName": "doPhoto"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minQuantity": {
|
|
||||||
"type": "number",
|
|
||||||
"description": "Min quantity"
|
|
||||||
},
|
|
||||||
"photoMotivation": {
|
"photoMotivation": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('itemMinimumQuantity model', () => {
|
||||||
|
const itemFk = 5;
|
||||||
|
const warehouseFk = 60;
|
||||||
|
|
||||||
|
beforeAll(async() => {
|
||||||
|
await models.ItemMinimumQuantity.destroyAll({where: {itemFk: itemFk}});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('CRUD operations', () => {
|
||||||
|
it('should create a new itemMinimumQuantity record', async() => {
|
||||||
|
const newRecord = {
|
||||||
|
itemFk: itemFk,
|
||||||
|
quantity: 100,
|
||||||
|
started: Date.vnNew(),
|
||||||
|
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 1)),
|
||||||
|
warehouseFk: warehouseFk
|
||||||
|
};
|
||||||
|
|
||||||
|
const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
|
||||||
|
expect(createdRecord).toBeDefined();
|
||||||
|
expect(createdRecord.quantity).toEqual(newRecord.quantity);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read an existing itemMinimumQuantity record', async() => {
|
||||||
|
const newRecord = {
|
||||||
|
itemFk: itemFk,
|
||||||
|
quantity: 100,
|
||||||
|
started: Date.vnNew(),
|
||||||
|
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 2)),
|
||||||
|
warehouseFk: warehouseFk
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
|
||||||
|
const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
|
||||||
|
|
||||||
|
expect(existingRecord).toBeDefined();
|
||||||
|
expect(existingRecord.itemFk).toEqual(itemFk);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update an existing itemMinimumQuantity record', async() => {
|
||||||
|
const newRecord = {
|
||||||
|
itemFk: itemFk,
|
||||||
|
quantity: 100,
|
||||||
|
started: Date.vnNew(),
|
||||||
|
ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 3)),
|
||||||
|
warehouseFk: warehouseFk
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
|
||||||
|
const newQuantity = 150;
|
||||||
|
const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
|
||||||
|
existingRecord.quantity = newQuantity;
|
||||||
|
|
||||||
|
await existingRecord.save();
|
||||||
|
const updatedRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
|
||||||
|
|
||||||
|
expect(updatedRecord.quantity).toEqual(newQuantity);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('validation and constraints', () => {
|
||||||
|
it('should enforce unique constraint on itemFk, started, ended, and warehouseFk', async() => {
|
||||||
|
const newRecord = {
|
||||||
|
itemFk: itemFk,
|
||||||
|
quantity: 100,
|
||||||
|
started: Date.vnNew(),
|
||||||
|
ended: Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 5),
|
||||||
|
warehouseFk: warehouseFk
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toBeDefined();
|
||||||
|
expect(e.code).toContain('ER_DUP_ENTRY');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow null values for ended and warehouseFk', async() => {
|
||||||
|
const newRecord = {
|
||||||
|
itemFk: itemFk,
|
||||||
|
quantity: 100,
|
||||||
|
started: Date.vnNew(),
|
||||||
|
ended: null,
|
||||||
|
warehouseFk: null
|
||||||
|
};
|
||||||
|
|
||||||
|
const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
|
||||||
|
|
||||||
|
expect(createdRecord).toBeDefined();
|
||||||
|
expect(createdRecord.ended).toBeNull();
|
||||||
|
expect(createdRecord.warehouseFk).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -128,9 +128,6 @@
|
||||||
<vn-label-value label="Non recycled plastic"
|
<vn-label-value label="Non recycled plastic"
|
||||||
value="{{$ctrl.summary.item.nonRecycledPlastic}}">
|
value="{{$ctrl.summary.item.nonRecycledPlastic}}">
|
||||||
</vn-label-value>
|
</vn-label-value>
|
||||||
<vn-label-value label="Minimum sales quantity"
|
|
||||||
value="{{$ctrl.summary.item.minQuantity}}">
|
|
||||||
</vn-label-value>
|
|
||||||
</vn-one>
|
</vn-one>
|
||||||
<vn-one name="tags">
|
<vn-one name="tags">
|
||||||
<h4 ng-show="$ctrl.isBuyer || $ctrl.isReplenisher">
|
<h4 ng-show="$ctrl.isBuyer || $ctrl.isReplenisher">
|
||||||
|
|
|
@ -119,7 +119,7 @@ module.exports = Self => {
|
||||||
w.firstName,
|
w.firstName,
|
||||||
tci.priceKg,
|
tci.priceKg,
|
||||||
ink.hex,
|
ink.hex,
|
||||||
i.minQuantity
|
tci.minQuantity
|
||||||
FROM tmp.ticketCalculateItem tci
|
FROM tmp.ticketCalculateItem tci
|
||||||
JOIN vn.item i ON i.id = tci.itemFk
|
JOIN vn.item i ON i.id = tci.itemFk
|
||||||
JOIN vn.itemType it ON it.id = i.typeFk
|
JOIN vn.itemType it ON it.id = i.typeFk
|
||||||
|
@ -158,21 +158,19 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Apply item prices
|
// Apply item prices
|
||||||
const pricesIndex = stmts.push(
|
const pricesIndex = stmts.push(
|
||||||
`SELECT
|
`SELECT tcp.itemFk,
|
||||||
tcp.itemFk,
|
|
||||||
tcp.grouping,
|
tcp.grouping,
|
||||||
tcp.price,
|
tcp.price,
|
||||||
tcp.rate,
|
tcp.rate,
|
||||||
tcp.warehouseFk,
|
tcp.warehouseFk,
|
||||||
tcp.priceKg,
|
tcp.priceKg,
|
||||||
w.name AS warehouse
|
w.name warehouse
|
||||||
FROM tmp.ticketComponentPrice tcp
|
FROM tmp.ticketComponentPrice tcp
|
||||||
JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1;
|
JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1;
|
||||||
|
|
||||||
// Get tags from all items
|
// Get tags from all items
|
||||||
const itemTagsIndex = stmts.push(
|
const itemTagsIndex = stmts.push(
|
||||||
`SELECT
|
`SELECT t.id,
|
||||||
t.id,
|
|
||||||
t.name,
|
t.name,
|
||||||
t.isFree,
|
t.isFree,
|
||||||
t.sourceTable,
|
t.sourceTable,
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
Order created: Orden creada
|
Order created: Orden creada
|
||||||
Minimal quantity: Cantidad mínima
|
|
|
@ -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}}">
|
||||||
|
|
|
@ -70,7 +70,7 @@ module.exports = Self => {
|
||||||
quantity: quantity
|
quantity: quantity
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
await Self.rawSql('CALL vn.sale_calculateComponent(?, NULL)', [newSale.id], myOptions);
|
await Self.rawSql('CALL vn.sale_calculateComponent(?, ?)', [newSale.id, 'renewPrices'], myOptions);
|
||||||
await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [id], myOptions);
|
await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [id], myOptions);
|
||||||
|
|
||||||
const sale = await models.Sale.findById(newSale.id, {
|
const sale = await models.Sale.findById(newSale.id, {
|
||||||
|
|
|
@ -65,7 +65,7 @@ module.exports = Self => {
|
||||||
throw new UserError('You can only add negative amounts in refund tickets');
|
throw new UserError('You can only add negative amounts in refund tickets');
|
||||||
|
|
||||||
const item = await models.Item.findOne({
|
const item = await models.Item.findOne({
|
||||||
fields: ['family', 'minQuantity'],
|
fields: ['family'],
|
||||||
where: {id: itemId},
|
where: {id: itemId},
|
||||||
}, ctx.options);
|
}, ctx.options);
|
||||||
if (item.family == 'EMB') return;
|
if (item.family == 'EMB') return;
|
||||||
|
@ -88,7 +88,30 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
||||||
|
|
||||||
if (newQuantity < item.minQuantity && newQuantity != available)
|
const itemMinimalQuantity = await models.ItemMinimumQuantity.find({
|
||||||
|
fields: ['quantity', 'warehouseFk'],
|
||||||
|
where: {
|
||||||
|
itemFk: itemId,
|
||||||
|
started: {lte: ticket.shipped},
|
||||||
|
or: [
|
||||||
|
{ended: {gte: ticket.shipped}},
|
||||||
|
{ended: null}
|
||||||
|
],
|
||||||
|
// eslint-disable-next-line no-dupe-keys
|
||||||
|
or: [
|
||||||
|
{warehouseFk: ticket.warehouseFk},
|
||||||
|
{warehouseFk: null}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}, ctx.options);
|
||||||
|
|
||||||
|
const minQuantity = itemMinimalQuantity.reduce((selected, item) => {
|
||||||
|
if (item.warehouseFk === ticket.warehouseFk) return item;
|
||||||
|
if (item.warehouseFk === null && !selected) return item;
|
||||||
|
return selected;
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
if (newQuantity < minQuantity?.quantity && newQuantity != available)
|
||||||
throw new UserError('The amount cannot be less than the minimum');
|
throw new UserError('The amount cannot be less than the minimum');
|
||||||
|
|
||||||
if (ctx.isNewInstance || isReduction) return;
|
if (ctx.isNewInstance || isReduction) return;
|
||||||
|
@ -114,4 +137,3 @@ module.exports = Self => {
|
||||||
throw new UserError('The price of the item changed');
|
throw new UserError('The price of the item changed');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,14 +112,10 @@ describe('sale model ', () => {
|
||||||
it('should throw an error if the quantity is less than the minimum quantity of the item', async() => {
|
it('should throw an error if the quantity is less than the minimum quantity of the item', async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
const itemId = 2;
|
|
||||||
const saleId = 17;
|
const saleId = 17;
|
||||||
const minQuantity = 30;
|
const newQuantity = 1;
|
||||||
const newQuantity = minQuantity - 1;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const item = await models.Item.findById(itemId, null, opts);
|
|
||||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
|
||||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY
|
sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY
|
||||||
|
@ -138,13 +134,8 @@ describe('sale model ', () => {
|
||||||
it('should change quantity if has minimum quantity and new quantity is equal than item available', async() => {
|
it('should change quantity if has minimum quantity and new quantity is equal than item available', async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
const itemId = 2;
|
|
||||||
const saleId = 17;
|
const saleId = 17;
|
||||||
const minQuantity = 30;
|
const newQuantity = 8;
|
||||||
const newQuantity = minQuantity - 1;
|
|
||||||
|
|
||||||
const item = await models.Item.findById(itemId, null, opts);
|
|
||||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
|
||||||
|
|
||||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
|
@ -162,13 +153,9 @@ describe('sale model ', () => {
|
||||||
it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => {
|
it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
const itemId = 2;
|
|
||||||
const saleId = 17;
|
const saleId = 17;
|
||||||
const minQuantity = 30;
|
|
||||||
const newQuantity = 31;
|
const newQuantity = 31;
|
||||||
|
|
||||||
const item = await models.Item.findById(itemId, null, opts);
|
|
||||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
|
||||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
sqlStatement = `
|
sqlStatement = `
|
||||||
|
@ -185,13 +172,9 @@ describe('sale model ', () => {
|
||||||
it('should increase quantity when the new price is lower than the previous one', async() => {
|
it('should increase quantity when the new price is lower than the previous one', async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
const itemId = 2;
|
|
||||||
const saleId = 17;
|
const saleId = 17;
|
||||||
const minQuantity = 30;
|
|
||||||
const newQuantity = 31;
|
const newQuantity = 31;
|
||||||
|
|
||||||
const item = await models.Item.findById(itemId, null, opts);
|
|
||||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
|
||||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
sqlStatement = `
|
sqlStatement = `
|
||||||
|
@ -208,14 +191,10 @@ describe('sale model ', () => {
|
||||||
it('should throw error when increase quantity and the new price is higher than the previous one', async() => {
|
it('should throw error when increase quantity and the new price is higher than the previous one', async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
const itemId = 2;
|
|
||||||
const saleId = 17;
|
const saleId = 17;
|
||||||
const minQuantity = 30;
|
|
||||||
const newQuantity = 31;
|
const newQuantity = 31;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const item = await models.Item.findById(itemId, null, opts);
|
|
||||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
|
||||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
sqlStatement = `
|
sqlStatement = `
|
||||||
|
@ -231,6 +210,48 @@ describe('sale model ', () => {
|
||||||
expect(e).toEqual(new Error('The price of the item changed'));
|
expect(e).toEqual(new Error('The price of the item changed'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the quantity is lower than the minimum quantity of the item and is in range', async() => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
|
const saleId = 25;
|
||||||
|
const newQuantity = 5;
|
||||||
|
|
||||||
|
try {
|
||||||
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
|
sqlStatement = `
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available;
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 100000 as price;`;
|
||||||
|
params = null;
|
||||||
|
}
|
||||||
|
return models.Ticket.rawSql(sqlStatement, params, opts);
|
||||||
|
});
|
||||||
|
|
||||||
|
await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toEqual(new Error('The amount cannot be less than the minimum'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update the quantity if the quantity is lower than the minimum quantity of the item and is out of the range', async() => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||||
|
|
||||||
|
const saleId = 17;
|
||||||
|
const newQuantity = 8;
|
||||||
|
|
||||||
|
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||||
|
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||||
|
sqlStatement = `
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available;
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 100000 as price;`;
|
||||||
|
params = null;
|
||||||
|
}
|
||||||
|
return models.Ticket.rawSql(sqlStatement, params, opts);
|
||||||
|
});
|
||||||
|
|
||||||
|
await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => {
|
||||||
|
|
||||||
const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
|
const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(8);
|
expect(result.length).toEqual(9);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the travel matching "cargoSupplierFk"', async() => {
|
it('should return the travel matching "cargoSupplierFk"', async() => {
|
||||||
|
@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => {
|
||||||
|
|
||||||
const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
|
const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe('Travel filter()', () => {
|
||||||
|
|
||||||
const result = await app.models.Travel.filter(ctx);
|
const result = await app.models.Travel.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(5);
|
expect(result.length).toEqual(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the routes matching "shipped from" and "shipped to"', async() => {
|
it('should return the routes matching "shipped from" and "shipped to"', async() => {
|
||||||
|
@ -80,6 +80,6 @@ describe('Travel filter()', () => {
|
||||||
|
|
||||||
const result = await app.models.Travel.filter(ctx);
|
const result = await app.models.Travel.filter(ctx);
|
||||||
|
|
||||||
expect(result.length).toEqual(5);
|
expect(result.length).toEqual(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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": [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "24.30.0",
|
"version": "24.32.0",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<td id="outline" class="ellipsize">{{dashIfEmpty(labelData.workerCode)}}</td>
|
<td id="outline" class="ellipsize">{{dashIfEmpty(labelData.workerCode)}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td id="outline" class="ellipsize">{{labelData.labelCount || 0}}</td>
|
<td id="outline" class="ellipsize">{{labelCount || labelData.labelCount || 0}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td id="outline" class="ellipsize">{{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}}</td>
|
<td id="outline" class="ellipsize">{{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}}</td>
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td width="5%">{{sale.itemFk}}</td>
|
<td width="5%">{{sale.itemFk}}</td>
|
||||||
<td class="number">{{sale.quantity}}</td>
|
<td class="number">{{sale.quantity}}</td>
|
||||||
<td width="50%">{{sale.concept}}</td>
|
<td width="50%">{{sale.concept}} <span class="font light-gray">{{sale.subName}}</span></td>
|
||||||
<td class="number">{{sale.price | currency('EUR', $i18n.locale)}}</td>
|
<td class="number">{{sale.price | currency('EUR', $i18n.locale)}}</td>
|
||||||
<td class="centered" width="5%">{{(sale.discount / 100) | percentage}}</td>
|
<td class="centered" width="5%">{{(sale.discount / 100) | percentage}}</td>
|
||||||
<td class="centered">{{sale.vatType}}</td>
|
<td class="centered">{{sale.vatType}}</td>
|
||||||
|
|
|
@ -35,3 +35,4 @@ observations: Observaciones
|
||||||
wireTransfer: "Forma de pago: Transferencia"
|
wireTransfer: "Forma de pago: Transferencia"
|
||||||
accountNumber: "Número de cuenta: {0}"
|
accountNumber: "Número de cuenta: {0}"
|
||||||
services: Servicios
|
services: Servicios
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ SELECT
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
s.concept,
|
s.concept,
|
||||||
tc.code vatType,
|
tc.code vatType,
|
||||||
it.isPackaging
|
it.isPackaging,
|
||||||
|
i.subName
|
||||||
FROM vn.invoiceOut io
|
FROM vn.invoiceOut io
|
||||||
JOIN vn.ticket t ON t.refFk = io.ref
|
JOIN vn.ticket t ON t.refFk = io.ref
|
||||||
JOIN vn.supplier su ON su.id = io.companyFk
|
JOIN vn.supplier su ON su.id = io.companyFk
|
||||||
|
@ -38,6 +39,7 @@ SELECT
|
||||||
NULL,
|
NULL,
|
||||||
ts.description,
|
ts.description,
|
||||||
tc.code,
|
tc.code,
|
||||||
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
FROM vn.invoiceOut io
|
FROM vn.invoiceOut io
|
||||||
JOIN vn.ticket t ON t.refFk = io.ref
|
JOIN vn.ticket t ON t.refFk = io.ref
|
||||||
|
|
Loading…
Reference in New Issue