fix ticket basic data allow change company #1277
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-04-01 09:01:11 +02:00
parent 034bd77d52
commit dfe1a68d35
7 changed files with 247 additions and 4 deletions

View File

@ -0,0 +1,42 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentMakeUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentMakeUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk TINYINT,
vCompanyFk SMALLINT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
CALL vn.ticketComponentPreview (vTicketFk, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk);
CALL vn.ticketComponentUpdate (
vTicketFk,
vClientFk,
vAgencyModeFk,
vAddressFk,
vWarehouseFk,
vCompanyFk,
vShipped,
vLanded,
vIsDeleted,
vHasToBeUnrouted,
vOption
);
DROP TEMPORARY TABLE
tmp.ticketComponent,
tmp.ticketComponentPrice;
END$$
DELIMITER ;

View File

@ -0,0 +1,134 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentPreview`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`(
vTicketFk INT,
vLanded DATE,
vAddressFk INT,
vAgencyModeFk INT,
vWarehouseFk SMALLINT)
BEGIN
/**
* Devuelve un listado previo de
* componentes para un ticket
*
* @param vTicketFk Id del ticket
* @param vLanded Fecha de recepcion
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id del modo de agencia
* @param vWarehouseFk Id del almacén
*/
DECLARE vAgencyFk INT;
DECLARE vShipped DATE;
DECLARE vBuyOrderItem INT DEFAULT 100;
DECLARE vHasDataChanged BOOL DEFAULT FALSE;
DECLARE vHasAddressChanged BOOL;
DECLARE vHasAgencyModeChanged BOOL DEFAULT FALSE;
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
DECLARE vAddressTypeRateFk INT DEFAULT NULL;
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
DECLARE vHasChangeAll BOOL DEFAULT FALSE;
SELECT DATE(landed) <> vLanded,
addressFk <> vAddressFk,
agencyModeFk <> vAgencyModeFk,
warehouseFk <> vWarehouseFk
INTO
vHasDataChanged,
vHasAddressChanged,
vHasAgencyModeChanged,
vHasWarehouseChanged
FROM vn.ticket t
WHERE t.id = vTicketFk;
/*SELECT vHasDataChanged,
vHasAddressChanged,
vHasAgencyModeChanged,
vHasWarehouseChanged;
*/
IF vHasDataChanged OR vHasWarehouseChanged THEN
SET vHasChangeAll = TRUE;
END IF;
IF vHasAddressChanged THEN
SET vAddressTypeRateFk = 5;
END IF;
IF vHasAgencyModeChanged THEN
SET vAgencyModeTypeRateFk = 6;
END IF;
SELECT agencyFk INTO vAgencyFk
FROM agencyMode
WHERE id = vAgencyModeFk;
CALL agencyHourGetShipped(vLanded, vAddressFk, vAgencyFk);
SELECT shipped INTO vShipped
FROM tmp.agencyHourGetShipped
WHERE warehouseFk = vWarehouseFk;
CALL buyUltimate(vWarehouseFk, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
SELECT
vWarehouseFk AS warehouseFk,
NULL AS available,
s.itemFk,
bu.buyFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketFk
AND s.itemFk != vBuyOrderItem
GROUP BY bu.warehouseFk, bu.itemFk);
CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk);
/*SELECT *,vHasChangeAll,cr.isRenewable = FALSE,vHasChangeAll,
NOT (cr.componentTypeRate <=> vAddressTypeRateFk),NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk),
NOT (cr.componentTypeRate <=> vAddressTypeRateFk) OR NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk)
FROM saleComponent sc
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE s.ticketFk = vTicketFk
AND (cr.isRenewable = FALSE
OR
(NOT vHasChangeAll
AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk
OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));*/
/*SELECT * FROM tmp.ticketComponent;*/
-- Inserta los componentes que NO seran modificados
REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value
FROM saleComponent sc
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE s.ticketFk = vTicketFk
AND (cr.isRenewable = FALSE
OR
(NOT vHasChangeAll
AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk
OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));
/*SELECT * FROM tmp.ticketComponent;*/
SET @shipped = vShipped;
DROP TEMPORARY TABLE
tmp.agencyHourGetShipped,
tmp.buyUltimate,
tmp.ticketLot;
IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN
CALL util.throw('NO_AGENCY_AVAILABLE');
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,62 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk TINYINT,
vCompanyFk SMALLINT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
UPDATE ticket t
SET
t.clientFk = vClientFk,
t.agencyModeFk = vAgencyModeFk,
t.addressFk = vAddressFk,
t.warehouseFk = vWarehouseFk,
t.companyFk = vCompanyFk,
t.landed = vLanded,
t.shipped = vShipped,
t.isDeleted = vIsDeleted
WHERE
t.id = vTicketFk;
IF vHasToBeUnrouted THEN
UPDATE ticket t SET t.routeFk = NULL
WHERE t.id = vTicketFk;
END IF;
IF vOption <> 8 THEN
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk))
ENGINE = MEMORY
SELECT id AS saleFk, vWarehouseFk warehouseFk
FROM sale s WHERE s.ticketFk = vTicketFk;
CALL ticketComponentUpdateSale (vOption);
DROP TEMPORARY TABLE tmp.sale;
END IF;
COMMIT;
END$$
DELIMITER ;

View File

@ -30,7 +30,7 @@
value="{{$ctrl.summary.item.itemType.name}}"> value="{{$ctrl.summary.item.itemType.name}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Size" <vn-label-value label="Size"
value="{{$ctrl.summary.item.itemType.size}}"> value="{{$ctrl.summary.item.size}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Origin" <vn-label-value label="Origin"
value="{{$ctrl.summary.item.origin.name}}"> value="{{$ctrl.summary.item.origin.name}}">

View File

@ -38,13 +38,14 @@ module.exports = Self => {
if (!hasDeliveryRole) if (!hasDeliveryRole)
data.hasToBeUnrouted = true; data.hasToBeUnrouted = true;
let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; let query = 'CALL vn.ticketComponentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
let res = await Self.rawSql(query, [ let res = await Self.rawSql(query, [
ticketFk, ticketFk,
data.clientFk, data.clientFk,
data.agencyModeFk, data.agencyModeFk,
data.addressFk, data.addressFk,
data.warehouseFk, data.warehouseFk,
data.companyFk,
data.shipped, data.shipped,
data.landed, data.landed,
data.isDeleted, data.isDeleted,

View File

@ -27,6 +27,7 @@ describe('ticket componentUpdate()', () => {
agencyModeFk: 8, agencyModeFk: 8,
addressFk: 121, addressFk: 121,
warehouseFk: 1, warehouseFk: 1,
companyFk: 442,
shipped: today, shipped: today,
landed: today, landed: today,
isDeleted: false, isDeleted: false,
@ -54,6 +55,7 @@ describe('ticket componentUpdate()', () => {
agencyModeFk: 7, agencyModeFk: 7,
addressFk: 121, addressFk: 121,
warehouseFk: 1, warehouseFk: 1,
companyFk: 442,
shipped: today, shipped: today,
landed: today, landed: today,
isDeleted: false, isDeleted: false,
@ -62,7 +64,7 @@ describe('ticket componentUpdate()', () => {
}; };
let ctx = {req: {accessToken: {userId: 101}}}; let ctx = {req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(11, data, ctx); await app.models.Ticket.componentUpdate(ticketId, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven); [componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
let firstvalueAfterChange = componentValue.value; let firstvalueAfterChange = componentValue.value;

View File

@ -23,10 +23,11 @@ class Controller {
} }
onSubmit() { onSubmit() {
if (!this.ticket.option) if (!this.ticket.option) {
return this.vnApp.showError( return this.vnApp.showError(
this.$translate.instant('Choose an option') this.$translate.instant('Choose an option')
); );
}
let query = `/ticket/api/tickets/${this.ticket.id}/componentUpdate`; let query = `/ticket/api/tickets/${this.ticket.id}/componentUpdate`;
let data = { let data = {
@ -34,6 +35,7 @@ class Controller {
agencyModeFk: this.ticket.agencyModeFk, agencyModeFk: this.ticket.agencyModeFk,
addressFk: this.ticket.addressFk, addressFk: this.ticket.addressFk,
warehouseFk: this.ticket.warehouseFk, warehouseFk: this.ticket.warehouseFk,
companyFk: this.ticket.companyFk,
shipped: this.ticket.shipped, shipped: this.ticket.shipped,
landed: this.ticket.landed, landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted, isDeleted: this.ticket.isDeleted,