7984-addCurrency #3316

Open
carlosap wants to merge 9 commits from 7984-addCurrency into dev
82 changed files with 1177 additions and 718 deletions

View File

@ -275,6 +275,7 @@ UPDATE `vn`.`agencyMode` SET `description` = `name`;
INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl) INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl)
VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL); VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL);
*/ */
INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk) INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk)
VALUES (1, 442); VALUES (1, 442);
@ -312,3 +313,4 @@ INSERT INTO mysql.roles_mapping (`User`, `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;

View File

@ -613,13 +613,13 @@ INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`)
VALUES VALUES
(241, 442, 'ES111122333344111122221111', 128); (241, 442, 'ES111122333344111122221111', 128);
INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`) INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`, `currencyFk`)
VALUES VALUES
(69 , 'CCs', NULL, 30, 0, NULL, 1, NULL , NULL), (69 , 'CCs', NULL, 30, 0, NULL, 1, NULL , NULL, 1),
(442 , 'VNL', 241, 30, 1, NULL, 2, 'VNL Company - Plant passport' , 1101), (442 , 'VNL', 241, 30, 1, NULL, 2, 'VNL Company - Plant passport' , 1101, 1),
(567 , 'VNH', NULL, 30, 4, NULL, 1, 'VNH Company - Plant passport' , NULL), (567 , 'VNH', NULL, 30, 4, NULL, 1, 'VNH Company - Plant passport' , NULL, 1),
(791 , 'FTH', NULL, 30, 3, '2015-11-30', 1, NULL , NULL), (791 , 'FTH', NULL, 30, 3, '2015-11-30', 1, NULL , NULL, 1),
(1381, 'ORN', NULL, 30, 7, NULL, 1, 'ORN Company - Plant passport' , NULL); (1381, 'ORN', NULL, 30, 7, NULL, 1, 'ORN Company - Plant passport' , NULL, 1);
INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`)
VALUES VALUES
@ -755,45 +755,45 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen
(6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()),
(7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()); (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE());
INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `currencyFk`, `created`, `weight`, `cmrFk`, `problem`, `risk`)
VALUES VALUES
(1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'hasHighRisk', 901.4), (1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'hasHighRisk', 901.4),
(2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'hasHighRisk', 901.4), (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'hasHighRisk', 901.4),
(3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 3, NULL, NULL), (3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 3, NULL, NULL),
(4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, NULL, NULL, NULL), (4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, NULL, NULL, NULL),
(5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, NULL, NULL, NULL), (5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, NULL, NULL, NULL),
(6 , 1, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, NULL, 'hasHighRisk', 901.4), (6 , 1, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, NULL, 'hasHighRisk', 901.4),
(7 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4), (7 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4),
(8 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4), (8 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4),
(9 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (9 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(10, 1, 1, 5, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, 'isTooLittle', NULL), (10, 1, 1, 5, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'isTooLittle', NULL),
(11, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasTicketRequest', NULL), (11, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasTicketRequest', NULL),
(12, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (12, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(13, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (13, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(14, 1, 2, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (14, 1, 2, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(15, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, 'isFreezed', NULL), (15, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'isFreezed', NULL),
(16, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, 388.7), (16, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, 2, util.VN_CURDATE(), NULL, NULL, NULL, 388.7),
(17, 1, 7, 2, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, 388.7), (17, 1, 7, 2, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, 388.7),
(18, 1, 4, 4, 4, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL, NULL, 'isFreezed', NULL), (18, 1, 4, 4, 4, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL, NULL, 'isFreezed', NULL),
(19, 1, 5, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, util.VN_CURDATE(), NULL, NULL, 'isTaxDataChecked', NULL), (19, 1, 5, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'isTaxDataChecked', NULL),
(20, 1, 5, 5, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL), (20, 1, 5, 5, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL),
(21, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL), (21, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL),
(22, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL), (22, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL, NULL, 'isTaxDataChecked', NULL),
(23, NULL, 8, 1, 7, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasTicketRequest, hasHighRisk', 901.4), (23, NULL, 8, 1, 7, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasTicketRequest, hasHighRisk', 901.4),
(24 ,NULL, 8, 1, 7, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4), (24 ,NULL, 8, 1, 7, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4),
(25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4), (25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4),
(26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4), (26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, 'hasHighRisk', 901.4),
(27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, 901.4), (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, 901.4),
(28, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (28, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(29, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (29, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(34, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (34, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(35, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (35, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL), (36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL),
(37, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1110, 'Deadpool swords', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL, NULL, NULL); (37, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1110, 'Deadpool swords', 123, NULL, 0, 1, 16, 0, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL);
INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`)
VALUES VALUES
@ -2691,6 +2691,18 @@ UPDATE `vn`.`invoiceIn`
SET isBooked = TRUE SET isBooked = TRUE
WHERE id IN (5, 7, 8, 9, 10); WHERE id IN (5, 7, 8, 9, 10);
INSERT INTO vn.referenceRate (currencyFk, dated, value)
VALUES (2, '2000-12-01', 1.0495),
(2, '2001-01-01', 1.0531),
(2, '2001-02-01', 7.6347),
(2, '2000-12-31', 7.6347);
UPDATE vn.ticket t
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.referenceRate rr ON rr.currencyFk = t.currencyFk
AND rr.dated = util.VN_CURDATE()
SET s.foreignPrice = s.price * vn.currency_getRate(t.currencyFk, NULL);
DELIMITER $$ DELIMITER $$
CREATE PROCEDURE `tmp`.`ticket_recalc`() CREATE PROCEDURE `tmp`.`ticket_recalc`()
BEGIN BEGIN
@ -4045,14 +4057,15 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel)
INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate)
VALUES (1106,'26493101E','2019-09-20'); VALUES (1106,'26493101E','2019-09-20');
INSERT INTO vn.referenceRate (currencyFk, dated, value)
VALUES (2, '2000-12-01', 1.0495),
(2, '2001-01-01', 1.0531),
(2, '2001-02-01', 7.6347);
INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance) INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance)
VALUES (1,'https://router.project-osrm.org', 0.002); VALUES (1,'https://router.project-osrm.org', 0.002);
INSERT IGNORE INTO vn.inventoryConfig INSERT IGNORE INTO vn.inventoryConfig
SET id = 1, SET id = 1,
supplierFk = 4; supplierFk = 4;
UPDATE vn.ticket t
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.referenceRate rr ON rr.currencyFk = t.currencyFk
AND rr.dated = util.VN_CURDATE()
SET s.foreignPrice = s.price * vn.currency_getRate(t.currencyFk, NULL);

View File

@ -20,7 +20,7 @@ BEGIN
CALL order_getTotal; CALL order_getTotal;
SELECT total INTO vTotal FROM tmp.orderTotal; SELECT IFNULL(foreignTotal, total) INTO vTotal FROM tmp.orderTotal;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE
tmp.`order`, tmp.`order`,

View File

@ -1,39 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`catalog_calcFromMyAddress`(vDelivery DATE, vAddress INT)
BEGIN
/**
* Gets the available items list.
*
* @param vDelivery Delivery date
* @param vAddress Address id
* @return tmp.ticketCalculateItem
* @return tmp.ticketComponentPrice
* @return tmp.ticketComponent
* @return tmp.ticketLot
* @return tmp.zoneGetShipped
*/
DECLARE vAgencyMode INT;
SELECT a.agencyModeFk
INTO vAgencyMode
FROM myClient c
JOIN vn.address a ON a.clientFk = c.id
WHERE a.id = vAddress;
CALL vn.available_calc(vDelivery, vAddress, vAgencyMode);
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item
(INDEX (itemFk))
ENGINE = MEMORY
SELECT c.item_id itemFk
FROM `cache`.available c
JOIN tmp.availableCalc a ON a.calcFk = c.calc_id
WHERE c.available > 0
GROUP BY c.item_id;
CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode, FALSE);
DROP TEMPORARY TABLE tmp.item;
END$$
DELIMITER ;

View File

@ -1,31 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_calcCatalog`(
vSelf INT,
vLanded DATE,
vAddressFk INT,
vAgencyModeFk INT)
BEGIN
/**
* Calculates available and price for a single item.
*
* @param vItemFk The item id
* @return List of available lots
*/
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item
ENGINE = MEMORY
SELECT vSelf itemFk;
CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, FALSE);
SELECT l.warehouseFk, w.name warehouse,
p.`grouping`, p.price, p.rate, l.available
FROM tmp.ticketLot l
JOIN tmp.ticketComponentPrice p ON p.warehouseFk = l.warehouseFk
JOIN vn.warehouse w ON w.id = p.warehouseFk
ORDER BY warehouseFk, `grouping`;
CALL vn.ticketCalculatePurge();
DROP TEMPORARY TABLE tmp.item;
END$$
DELIMITER ;

View File

@ -16,14 +16,18 @@ proc: BEGIN
* @param vAddress Address id, @NULL for pickup * @param vAddress Address id, @NULL for pickup
*/ */
DECLARE vCompany INT; DECLARE vCompany INT;
DECLARE vCurrencyFk INT;
SELECT defaultCompanyFk INTO vCompany SELECT oc.defaultCompanyFk, c.currencyFk INTO vCompany, vCurrencyFk
FROM orderConfig; FROM orderConfig oc
LEFT JOIN vn.company c ON c.id = oc.defaultCompanyFk
LIMIT 1;
INSERT INTO `order` INSERT INTO `order`
SET customer_id = account.myUser_getId(), SET customer_id = account.myUser_getId(),
source_app = 'WEB', source_app = 'WEB',
company_id = vCompany; company_id = vCompany,
currencyFk = vCurrencyFk;
SET vSelf = LAST_INSERT_ID(); SET vSelf = LAST_INSERT_ID();
CALL myOrder_configure( CALL myOrder_configure(

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getRows`(vSelf INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getRows`(vSelf INT)
BEGIN BEGIN
SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, SELECT r.itemFk, r.quantity, r.concept, r.price, r.foreignPrice, r.discount,
i.category, i.size, i.stems, i.inkFk, i.category, i.size, i.stems, i.inkFk,
i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7, i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7,
i.image, im.updated i.image, im.updated

View File

@ -7,7 +7,7 @@ BEGIN
* @param vSelf The ticket identifier * @param vSelf The ticket identifier
* @select The ticket services * @select The ticket services
*/ */
SELECT id, description, quantity, price SELECT id, description, quantity, price, foreignPrice
FROM myTicketService FROM myTicketService
WHERE ticketFk = vSelf; WHERE ticketFk = vSelf;
END$$ END$$

View File

@ -22,8 +22,9 @@ BEGIN
DECLARE vRate INT; DECLARE vRate INT;
DECLARE vShipment DATE; DECLARE vShipment DATE;
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vForeignPrice DECIMAL(10,2);
DECLARE cur CURSOR FOR DECLARE cur CURSOR FOR
SELECT `grouping`, price, rate SELECT `grouping`, price, rate, foreignPrice
FROM tmp.ticketComponentPrice FROM tmp.ticketComponentPrice
WHERE warehouseFk = vWarehouse WHERE warehouseFk = vWarehouse
AND itemFk = vItem AND itemFk = vItem
@ -84,7 +85,7 @@ BEGIN
l: LOOP l: LOOP
SET vDone = FALSE; SET vDone = FALSE;
FETCH cur INTO vGrouping, vPrice, vRate; FETCH cur INTO vGrouping, vPrice, vRate, vForeignPrice;
IF vDone THEN IF vDone THEN
LEAVE l; LEAVE l;
@ -104,7 +105,8 @@ BEGIN
shipment = vShipment, shipment = vShipment,
rate = vRate, rate = vRate,
amount = vAdd, amount = vAdd,
price = vPrice; price = vPrice,
foreignPrice = vForeignPrice;
CALL cache.available_updateItem(vItem, vWarehouse, vShipment, vAdd); CALL cache.available_updateItem(vItem, vWarehouse, vShipment, vAdd);

View File

@ -13,9 +13,10 @@ BEGIN
DECLARE vDate DATE; DECLARE vDate DATE;
DECLARE vAddress INT; DECLARE vAddress INT;
DECLARE vAgencyMode INT; DECLARE vAgencyMode INT;
DECLARE vCurrencyFk INT;
SELECT date_send, address_id, agency_id SELECT date_send, address_id, agency_id, currencyFk
INTO vDate, vAddress, vAgencyMode INTO vDate, vAddress, vAgencyMode, vCurrencyFk
FROM `order` FROM `order`
WHERE id = vSelf; WHERE id = vSelf;
@ -27,7 +28,7 @@ BEGIN
WHERE orderFk = vSelf WHERE orderFk = vSelf
GROUP BY itemFk; GROUP BY itemFk;
CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, FALSE); CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, vCurrencyFk, FALSE);
DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item;
END$$ END$$

View File

@ -16,12 +16,13 @@ BEGIN
DECLARE vDate DATE; DECLARE vDate DATE;
DECLARE vAddress INT; DECLARE vAddress INT;
DECLARE vAgencyMode INT; DECLARE vAgencyMode INT;
DECLARE vCurrencyFk INT;
SELECT date_send, address_id, agency_id SELECT date_send, address_id, agency_id, currencyFk
INTO vDate, vAddress, vAgencyMode INTO vDate, vAddress, vAgencyMode, vCurrencyFk
FROM `order` FROM `order`
WHERE id = vSelf; WHERE id = vSelf;
CALL vn.catalog_calcFromItem(vDate, vAddress, vAgencyMode, vItem); CALL vn.catalog_calcFromItem(vDate, vAddress, vAgencyMode, vCurrencyFk, vItem);
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -16,13 +16,14 @@ BEGIN
DECLARE vDate DATE; DECLARE vDate DATE;
DECLARE vAddress INT; DECLARE vAddress INT;
DECLARE vAgencyMode INT; DECLARE vAgencyMode INT;
DECLARE vCurrencyFk INT;
SELECT date_send, address_id, agency_id SELECT date_send, address_id, agency_id, currencyFk
INTO vDate, vAddress, vAgencyMode INTO vDate, vAddress, vAgencyMode, vCurrencyFk
FROM `order` FROM `order`
WHERE id = vSelf; WHERE id = vSelf;
CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, FALSE); CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode, vCurrencyFk, FALSE);
IF account.myUser_getName() = 'visitor' THEN IF account.myUser_getName() = 'visitor' THEN
UPDATE tmp.ticketCalculateItem UPDATE tmp.ticketCalculateItem

View File

@ -23,6 +23,7 @@ BEGIN
DECLARE vConcept VARCHAR(30); DECLARE vConcept VARCHAR(30);
DECLARE vAmount INT; DECLARE vAmount INT;
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vForeignPrice DECIMAL(10,2);
DECLARE vSaleFk INT; DECLARE vSaleFk INT;
DECLARE vRowFk INT; DECLARE vRowFk INT;
DECLARE vPriceFixed DECIMAL(10,2); DECLARE vPriceFixed DECIMAL(10,2);
@ -32,6 +33,7 @@ BEGIN
DECLARE vCompanyFk INT; DECLARE vCompanyFk INT;
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vIsTaxDataChecked BOOL; DECLARE vIsTaxDataChecked BOOL;
DECLARE vCurrencyFk INT;
DECLARE vDates CURSOR FOR DECLARE vDates CURSOR FOR
SELECT zgs.shipped, r.warehouseFk SELECT zgs.shipped, r.warehouseFk
@ -47,7 +49,8 @@ BEGIN
r.itemFk, r.itemFk,
i.name, i.name,
r.amount, r.amount,
r.price r.price,
r.foreignPrice
FROM orderRow r FROM orderRow r
JOIN vn.item i ON i.id = r.itemFk JOIN vn.item i ON i.id = r.itemFk
WHERE r.amount WHERE r.amount
@ -70,14 +73,16 @@ BEGIN
a.clientFk, a.clientFk,
o.company_id, o.company_id,
o.agency_id, o.agency_id,
c.isTaxDataChecked c.isTaxDataChecked,
o.currencyFk
INTO vLanded, INTO vLanded,
vAddressFk, vAddressFk,
vNotes, vNotes,
vClientFk, vClientFk,
vCompanyFk, vCompanyFk,
vAgencyModeFk, vAgencyModeFk,
vIsTaxDataChecked vIsTaxDataChecked,
vCurrencyFk
FROM `order` o FROM `order` o
JOIN vn.address a ON a.id = o.address_id JOIN vn.address a ON a.id = o.address_id
JOIN vn.client c ON c.id = a.clientFk JOIN vn.client c ON c.id = a.clientFk
@ -144,6 +149,7 @@ BEGIN
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.ticket t ON t.id = s.ticketFk
WHERE t.shipped BETWEEN vShipment AND vShipmentDayEnd WHERE t.shipped BETWEEN vShipment AND vShipmentDayEnd
AND t.currencyFk = vCurrencyFk
) )
SELECT t.id INTO vTicketFk SELECT t.id INTO vTicketFk
FROM vn.ticket t FROM vn.ticket t
@ -154,6 +160,7 @@ BEGIN
AND t.shipped BETWEEN vShipment AND vShipmentDayEnd AND t.shipped BETWEEN vShipment AND vShipmentDayEnd
AND t.warehouseFk = vWarehouseFk AND t.warehouseFk = vWarehouseFk
AND o.date_send = t.landed AND o.date_send = t.landed
AND t.currencyFk = o.currencyFk
WHERE o.id = vSelf WHERE o.id = vSelf
AND t.refFk IS NULL AND t.refFk IS NULL
AND tp.ticketFk IS NULL AND tp.ticketFk IS NULL
@ -171,6 +178,7 @@ BEGIN
JOIN hedera.orderRow oro ON oro.itemFk = i.id JOIN hedera.orderRow oro ON oro.itemFk = i.id
JOIN hedera.`order` o ON o.id = oro.orderFk JOIN hedera.`order` o ON o.id = oro.orderFk
WHERE oro.orderFk = vSelf WHERE oro.orderFk = vSelf
AND o.currencyFk = vCurrencyFk
), ),
tItemPackingTypeTicket AS ( tItemPackingTypeTicket AS (
SELECT t.id, SELECT t.id,
@ -188,6 +196,7 @@ BEGIN
AND t.warehouseFk = vWarehouseFk AND t.warehouseFk = vWarehouseFk
AND t.addressFk = ipto.address_id AND t.addressFk = ipto.address_id
AND al.code = 'ON_PREVIOUS' AND al.code = 'ON_PREVIOUS'
AND t.currencyFk = vCurrencyFk
GROUP BY t.id GROUP BY t.id
) )
SELECT iptt.id INTO vTicketFk SELECT iptt.id INTO vTicketFk
@ -211,6 +220,7 @@ BEGIN
vLanded, vLanded,
vUserFk, vUserFk,
TRUE, TRUE,
vCurrencyFk,
vTicketFk vTicketFk
); );
ELSE ELSE
@ -239,7 +249,7 @@ BEGIN
lRows: LOOP lRows: LOOP
SET vSaleFk = NULL; SET vSaleFk = NULL;
SET vDone = FALSE; SET vDone = FALSE;
FETCH vRows INTO vRowFk, vItemFk, vConcept, vAmount, vPrice; FETCH vRows INTO vRowFk, vItemFk, vConcept, vAmount, vPrice, vForeignPrice;
IF vDone THEN IF vDone THEN
LEAVE lRows; LEAVE lRows;
@ -249,6 +259,7 @@ BEGIN
FROM vn.sale s FROM vn.sale s
WHERE ticketFk = vTicketFk WHERE ticketFk = vTicketFk
AND price = vPrice AND price = vPrice
AND foreignPrice = vForeignPrice
AND itemFk = vItemFk AND itemFk = vItemFk
AND discount = 0 AND discount = 0
LIMIT 1; LIMIT 1;
@ -274,7 +285,8 @@ BEGIN
quantity = vAmount, quantity = vAmount,
price = vPrice, price = vPrice,
priceFixed = vPriceFixed, priceFixed = vPriceFixed,
isPriceFixed = TRUE; isPriceFixed = TRUE,
foreignPrice = vForeignPrice;
SET vSaleFk = LAST_INSERT_ID(); SET vSaleFk = LAST_INSERT_ID();

View File

@ -29,7 +29,8 @@ BEGIN
oro.amount * oro.price total, oro.amount * oro.price total,
s.countryFk, s.countryFk,
ata.areaFk, ata.areaFk,
itc.taxClassFk itc.taxClassFk,
o.currencyFk
FROM hedera.orderRow oro FROM hedera.orderRow oro
JOIN tmp.order tor ON tor.orderFk = oro.orderFk JOIN tmp.order tor ON tor.orderFk = oro.orderFk
JOIN hedera.`order` o ON o.id = tor.orderFk JOIN hedera.`order` o ON o.id = tor.orderFk
@ -45,7 +46,10 @@ BEGIN
SELECT o.orderFk, SELECT o.orderFk,
tc.code, tc.code,
SUM(o.total) taxableBase, SUM(o.total) taxableBase,
pgc.rate pgc.rate,
vn.currency_getRate(o.currencyFk, NULL) *
SUM(o.total) foreignTaxableBase,
o.currencyFk
FROM orders o FROM orders o
JOIN vn.bookingPlanner bp ON bp.countryFk = o.countryFk JOIN vn.bookingPlanner bp ON bp.countryFk = o.countryFk
AND bp.taxAreaFk = o.areaFk AND bp.taxAreaFk = o.areaFk
@ -61,8 +65,14 @@ BEGIN
CREATE TEMPORARY TABLE tmp.orderAmount CREATE TEMPORARY TABLE tmp.orderAmount
(INDEX (orderFk)) (INDEX (orderFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT orderFk, taxableBase, `code`, SELECT orderFk,
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax taxableBase,
`code`,
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,
currencyFk,
foreignTaxableBase,
vn.currency_getRate(currencyFk, NULL) *
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) foreignTax
FROM tmp.orderTax FROM tmp.orderTax
GROUP BY orderFk, `code`; GROUP BY orderFk, `code`;

View File

@ -13,7 +13,9 @@ BEGIN
CREATE TEMPORARY TABLE tmp.orderTotal CREATE TEMPORARY TABLE tmp.orderTotal
(INDEX (orderFk)) (INDEX (orderFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total SELECT o.orderFk,
IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) total,
IFNULL(SUM(ot.foreignTaxableBase + ot.foreignTax), 0.0) foreignTotal
FROM tmp.`order` o FROM tmp.`order` o
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
GROUP BY orderFk; GROUP BY orderFk;

View File

@ -8,6 +8,8 @@ BEGIN
*/ */
DECLARE vTaxableBase DECIMAL(10,2); DECLARE vTaxableBase DECIMAL(10,2);
DECLARE vTax DECIMAL(10,2); DECLARE vTax DECIMAL(10,2);
DECLARE vForeignTaxableBase DECIMAL(10,2);
DECLARE vForeignTax DECIMAL(10,2);
DROP TEMPORARY TABLE IF EXISTS tmp.`order`; DROP TEMPORARY TABLE IF EXISTS tmp.`order`;
CREATE TEMPORARY TABLE tmp.`order` CREATE TEMPORARY TABLE tmp.`order`
@ -16,14 +18,23 @@ BEGIN
CALL order_getTax; CALL order_getTax;
SELECT IFNULL(SUM(taxableBase), 0.0), IFNULL(SUM(tax), 0.0) SELECT IFNULL(SUM(taxableBase), 0.0),
INTO vTaxableBase, vTax IFNULL(SUM(tax), 0.0),
IFNULL(SUM(foreignTaxableBase), 0.0),
IFNULL(SUM(foreignTax), 0.0)
INTO vTaxableBase,
vTax,
vForeignTaxableBase,
vForeignTax
FROM tmp.orderAmount; FROM tmp.orderAmount;
UPDATE `order` UPDATE `order`
SET taxableBase = vTaxableBase, SET taxableBase = vTaxableBase,
tax = vTax, tax = vTax,
total = vTaxableBase + vTax total = vTaxableBase + vTax,
foreignTaxableBase = vForeignTaxableBase,
foreignTax = vForeignTax,
foreignTotal = vForeignTaxableBase + vForeignTax
WHERE id = vSelf; WHERE id = vSelf;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE

View File

@ -22,8 +22,7 @@ proc: BEGIN
SELECT COUNT(*) INTO vNRows SELECT COUNT(*) INTO vNRows
FROM orderRow WHERE orderFk = vSelf; FROM orderRow WHERE orderFk = vSelf;
IF vNRows > 0 IF vNRows > 0 THEN
THEN
CALL order_calcCatalog(vSelf); CALL order_calcCatalog(vSelf);
DELETE c DELETE c
@ -32,18 +31,18 @@ proc: BEGIN
WHERE r.orderFk = vSelf; WHERE r.orderFk = vSelf;
UPDATE orderRow r UPDATE orderRow r
LEFT JOIN tmp.ticketComponentPrice p JOIN `order` o ON o.id = r.orderFk
ON p.warehouseFk = r.warehouseFk LEFT JOIN tmp.ticketComponentPrice p ON p.warehouseFk = r.warehouseFk
AND p.itemFk = r.itemFk AND p.itemFk = r.itemFk
AND p.rate = r.rate AND p.rate = r.rate
LEFT JOIN tmp.zoneGetShipped t LEFT JOIN tmp.zoneGetShipped t ON t.warehouseFk = r.warehouseFk
ON t.warehouseFk = r.warehouseFk SET r.price = p.price,
SET r.foreignPrice = vn.currency_getRate(o.currencyFk, NULL) * p.price,
r.price = p.price,
r.amount = IF(p.itemFk IS NOT NULL, r.amount = IF(p.itemFk IS NOT NULL,
r.amount + IF(@m := MOD(r.amount, p.`grouping`), p.`grouping` - @m, 0), 0), r.amount + IF(@m := MOD(r.amount, p.`grouping`), p.`grouping` - @m, 0)
, 0),
r.shipment = t.shipped r.shipment = t.shipped
WHERE r.orderFk = vSelf; WHERE o.id = vSelf;
INSERT INTO orderRowComponent(rowFk, componentFk, price) INSERT INTO orderRowComponent(rowFk, componentFk, price)
SELECT r.id, c.componentFk, c.cost SELECT r.id, c.componentFk, c.cost
@ -59,8 +58,7 @@ proc: BEGIN
CALL vn.ticketCalculatePurge; CALL vn.ticketCalculatePurge;
END IF; END IF;
UPDATE `order` SET date_make = util.VN_NOW() UPDATE `order` SET date_make = util.VN_NOW() WHERE id = vSelf;
WHERE id = vSelf;
COMMIT; COMMIT;
END$$ END$$

View File

@ -8,6 +8,7 @@ AS SELECT `orw`.`id` AS `id`,
`orw`.`shipment` AS `shipped`, `orw`.`shipment` AS `shipped`,
`orw`.`amount` AS `amount`, `orw`.`amount` AS `amount`,
`orw`.`price` AS `price`, `orw`.`price` AS `price`,
`orw`.`foreignPrice` AS `foreignPrice`,
`orw`.`rate` AS `rate`, `orw`.`rate` AS `rate`,
`orw`.`created` AS `created`, `orw`.`created` AS `created`,
`orw`.`Id_Movimiento` AS `saleFk` `orw`.`Id_Movimiento` AS `saleFk`

View File

@ -7,6 +7,7 @@ AS SELECT `s`.`id` AS `id`,
`s`.`concept` AS `concept`, `s`.`concept` AS `concept`,
`s`.`quantity` AS `quantity`, `s`.`quantity` AS `quantity`,
`s`.`price` AS `price`, `s`.`price` AS `price`,
`s`.`foreignPrice` AS `foreignPrice`,
`s`.`discount` AS `discount`, `s`.`discount` AS `discount`,
`s`.`reserved` AS `reserved`, `s`.`reserved` AS `reserved`,
`s`.`isPicked` AS `isPicked` `s`.`isPicked` AS `isPicked`

View File

@ -5,6 +5,7 @@ AS SELECT `s`.`id` AS `id`,
`s`.`description` AS `description`, `s`.`description` AS `description`,
`s`.`quantity` AS `quantity`, `s`.`quantity` AS `quantity`,
`s`.`price` AS `price`, `s`.`price` AS `price`,
`s`.`foreignPrice` AS `foreignPrice`,
`s`.`taxClassFk` AS `taxClassFk`, `s`.`taxClassFk` AS `taxClassFk`,
`s`.`ticketFk` AS `ticketFk`, `s`.`ticketFk` AS `ticketFk`,
`s`.`ticketServiceTypeFk` AS `ticketServiceTypeFk` `s`.`ticketServiceTypeFk` AS `ticketServiceTypeFk`

View File

@ -8,6 +8,7 @@ AS SELECT `t`.`id` AS `id`,
`t`.`shipment` AS `shipment`, `t`.`shipment` AS `shipment`,
`t`.`amount` AS `amount`, `t`.`amount` AS `amount`,
`t`.`price` AS `price`, `t`.`price` AS `price`,
`t`.`foreignPrice` AS `foreignPrice`,
`t`.`rate` AS `rate`, `t`.`rate` AS `rate`,
`t`.`created` AS `created`, `t`.`created` AS `created`,
`t`.`saleFk` AS `Id_Movimiento` `t`.`saleFk` AS `Id_Movimiento`

View File

@ -0,0 +1,23 @@
-- DELIMITER $$
-- CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION vn.client_getCompany(vSelf INT)
-- RETURNS INT(3)
-- DETERMINISTIC
-- BEGIN
-- /**
-- * Devuelve la moneda por defecto del cliente dado
-- *
-- * @param vSelf id del cliente
-- * @return devuelve id de la compañia por defecto
-- */
-- DECLARE vCompanyFk INT;
-- SELECT co.currencyFk INTO vCompanyFk
-- FROM client c
-- JOIN vn.province p ON p.id = c.provinceFk
-- JOIN vn.country co ON co.id = p.countryFk
-- WHERE c.id = vSelf
-- LIMIT 1;
-- RETURN vCompanyFk;
-- END$$
-- DELIMITER ;

View File

@ -0,0 +1,23 @@
-- DELIMITER $$
-- CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION vn.client_getCurrency(vSelf INT)
-- RETURNS INT(3)
-- DETERMINISTIC
-- BEGIN
-- /**
-- * Devuelve la moneda por defecto del cliente dado
-- *
-- * @param vSelf id del cliente
-- * @return devuelve id del tipo de moneda
-- */
-- DECLARE vCurrencyFk INT;
-- SELECT co.currencyFk INTO vCurrencyFk
-- FROM client c
-- JOIN vn.province p ON p.id = c.provinceFk
-- JOIN vn.country co ON co.id = p.countryFk
-- WHERE c.id = vSelf
-- LIMIT 1;
-- RETURN vCurrencyFk;
-- END$$
-- DELIMITER ;

View File

@ -0,0 +1,29 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`currency_getRate`(
vSelf VARCHAR(3),
vDated DATE
)
RETURNS DECIMAL(10,2)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
/**
* Returns the rate exchange based on the specified currency
* and yesterday's exchange rate.
*
* @param vSelf The currency code
* @param vDated The date of exchangue
* @return vForeignRate The rate e of currency exchange
*/
DECLARE vForeignRate DECIMAL(10,2);
SELECT value INTO vForeignRate
FROM referenceRate
WHERE dated = IFNULL(vDated, util.yesterday())
AND currencyFk = vSelf
ORDER BY dated DESC
LIMIT 1;
RETURN vForeignRate;
END$$
DELIMITER ;

View File

@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_calcFromItem`
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vAgencyModeFk INT, vAgencyModeFk INT,
vCurrencyFk INT,
vItemFk INT) vItemFk INT)
BEGIN BEGIN
/** /**
@ -20,7 +21,7 @@ BEGIN
ENGINE = MEMORY ENGINE = MEMORY
SELECT vItemFk itemFk; SELECT vItemFk itemFk;
CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, TRUE); CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, vCurrencyFk, TRUE);
DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -3,17 +3,21 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_calculate`(
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vAgencyModeFk INT, vAgencyModeFk INT,
vShowExpiredZones BOOLEAN) vCurrencyFk INT,
vShowExpiredZones BOOLEAN
)
BEGIN BEGIN
/** /**
* Calcula los articulos disponibles y sus precios * Calcula los articulos disponibles y sus precios.
* *
* @table tmp.item(itemFk) Listado de artículos a calcular * @table tmp.item(itemFk) Listado de artículos a calcular
* @param vLanded Fecha de recepcion de mercancia * @param vLanded Fecha de recepcion de mercancia
* @param vAddressFk Id del consignatario * @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id de la agencia * @param vAgencyModeFk Id de la agencia
* @return tmp.ticketCalculateItem(itemFk, available, producer, * @param vCurrencyFk Id de la moneda
* item, size, stems, category, inkFk, image, origin, price) * @return tmp.ticketCalculateItem(itemFk, available, producer, item, size, stems,
* category, inkFk,image, origin, price, priceKg, foreignPrice,
* foreignPriceKg, grouping, minQuantity)
* @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk) * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk)
* @return tmp.ticketComponent * @return tmp.ticketComponent
* @return tmp.ticketComponentPrice * @return tmp.ticketComponentPrice
@ -58,6 +62,8 @@ BEGIN
origin VARCHAR(3), origin VARCHAR(3),
price DECIMAL(10,2), price DECIMAL(10,2),
priceKg DECIMAL(10,2), priceKg DECIMAL(10,2),
foreignPrice DECIMAL(10,2),
foreignPriceKg DECIMAL(10,2),
`grouping` INT(10) UNSIGNED, `grouping` INT(10) UNSIGNED,
minQuantity INT(10) UNSIGNED, minQuantity INT(10) UNSIGNED,
PRIMARY KEY `itemFk` (`itemFk`) PRIMARY KEY `itemFk` (`itemFk`)
@ -136,7 +142,7 @@ BEGIN
DROP TEMPORARY TABLE tmp.buyUltimate; DROP TEMPORARY TABLE tmp.buyUltimate;
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk, vCurrencyFk);
INSERT INTO tmp.ticketCalculateItem( INSERT INTO tmp.ticketCalculateItem(
itemFk, itemFk,
@ -151,6 +157,8 @@ BEGIN
origin, origin,
price, price,
priceKg, priceKg,
foreignPrice,
foreignPriceKg,
`grouping`, `grouping`,
minQuantity) minQuantity)
SELECT tl.itemFk, SELECT tl.itemFk,
@ -165,6 +173,8 @@ BEGIN
o.code origin, o.code origin,
bl.price, bl.price,
bl.priceKg, bl.priceKg,
currency_getRate(vCurrencyFk, NULL) * bl.price,
currency_getRate(vCurrencyFk, NULL) * bl.priceKg,
bl.`grouping`, bl.`grouping`,
mq.quantity mq.quantity
FROM tmp.ticketLot tl FROM tmp.ticketLot tl

View File

@ -3,7 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_componentCalc
vZoneFk INT, vZoneFk INT,
vAddressFk INT, vAddressFk INT,
vShipped DATE, vShipped DATE,
vWarehouseFk INT vWarehouseFk INT,
vCurrencyFk INT
) )
BEGIN BEGIN
/** /**
@ -16,7 +17,7 @@ BEGIN
* @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
* @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) * @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
* *
* @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, foreignPrice)
*/ */
DECLARE vClientFk INT; DECLARE vClientFk INT;
DECLARE vVNHWarehouseFk INT DEFAULT 7; DECLARE vVNHWarehouseFk INT DEFAULT 7;
@ -258,7 +259,8 @@ BEGIN
DROP TEMPORARY TABLE tmp.zoneOption; DROP TEMPORARY TABLE tmp.zoneOption;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCopy
ENGINE = MEMORY
SELECT * FROM tmp.ticketComponent; SELECT * FROM tmp.ticketComponent;
-- Precio especial -- Precio especial
@ -297,52 +299,64 @@ BEGIN
JOIN component c ON c.id = tc.componentFk JOIN component c ON c.id = tc.componentFk
GROUP BY tc.itemFk, tc.warehouseFk, c.classRate; GROUP BY tc.itemFk, tc.warehouseFk, c.classRate;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentRate
ENGINE = MEMORY
SELECT tcc.warehouseFk, SELECT tcc.warehouseFk,
tcc.itemFk, tcc.itemFk,
1 rate, 1 rate,
IF(tcc.groupingMode = 'grouping', tcc.`grouping`, 1) `grouping`, IF(tcc.groupingMode = 'grouping', tcc.`grouping`, 1) `grouping`,
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price,
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg,
currency_getRate(vCurrencyFk, NULL) * SUM(tcs.sumCost) foreignPrice
FROM tmp.ticketComponentCalculate tcc FROM tmp.ticketComponentCalculate tcc
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 1) = 1 WHERE IFNULL(tcs.classRate, 1) = 1
AND (tcc.groupingMode = 'grouping' OR tcc.groupingMode IS NULL) AND (tcc.groupingMode = 'grouping' OR tcc.groupingMode IS NULL)
AND (tcc.packing > tcc.`grouping` OR tcc.groupingMode IS NULL) AND (tcc.packing > tcc.`grouping` OR tcc.groupingMode IS NULL)
GROUP BY tcs.warehouseFk, tcs.itemFk; GROUP BY tcs.warehouseFk, tcs.itemFk
UNION ALL
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
SELECT tcc.warehouseFk, SELECT tcc.warehouseFk,
tcc.itemFk, tcc.itemFk,
2 rate, 2 rate,
tcc.packing `grouping`, tcc.packing `grouping`,
SUM(tcs.sumCost) price, SUM(tcs.sumCost) price,
SUM(tcs.sumCost) / weightGrouping priceKg SUM(tcs.sumCost) / weightGrouping priceKg,
currency_getRate(vCurrencyFk, NULL) * SUM(tcs.sumCost) foreignPrice
FROM tmp.ticketComponentCalculate tcc FROM tmp.ticketComponentCalculate tcc
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk AND tcs.warehouseFk = tcc.warehouseFk
WHERE tcc.available IS NULL WHERE tcc.available IS NULL
OR (IFNULL(tcs.classRate, 2) = 2 OR (IFNULL(tcs.classRate, 2) = 2
AND tcc.packing > 0 AND tcc.available >= tcc.packing) AND tcc.packing > 0 AND tcc.available >= tcc.packing)
GROUP BY tcs.warehouseFk, tcs.itemFk; GROUP BY tcs.warehouseFk, tcs.itemFk
UNION ALL
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
SELECT tcc.warehouseFk, SELECT tcc.warehouseFk,
tcc.itemFk, tcc.itemFk,
3 rate, 3 rate,
tcc.available `grouping`, tcc.available `grouping`,
SUM(tcs.sumCost) price, SUM(tcs.sumCost) price,
SUM(tcs.sumCost) / weightGrouping priceKg SUM(tcs.sumCost) / weightGrouping priceKg,
currency_getRate(vCurrencyFk, NULL) * SUM(tcs.sumCost) foreignPrice
FROM tmp.ticketComponentCalculate tcc FROM tmp.ticketComponentCalculate tcc
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 3) = 3 WHERE IFNULL(tcs.classRate, 3) = 3
GROUP BY tcs.warehouseFk, tcs.itemFk; GROUP BY tcs.warehouseFk, tcs.itemFk;
INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) INSERT INTO tmp.ticketComponentPrice(
SELECT * FROM ( warehouseFk,
SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 itemFk,
rate,
`grouping`,
price,
priceKg,
foreignPrice
)SELECT * FROM (
SELECT *
FROM tmp.ticketComponentRate
ORDER BY price
LIMIT 10000000000000000000
) t ) t
GROUP BY itemFk, warehouseFk, `grouping`; GROUP BY itemFk, warehouseFk, `grouping`;

View File

@ -20,6 +20,8 @@ BEGIN
`grouping` INT UNSIGNED NOT NULL, `grouping` INT UNSIGNED NOT NULL,
`price` DECIMAL(10,4) NOT NULL, `price` DECIMAL(10,4) NOT NULL,
`priceKg` DECIMAL(10,4), `priceKg` DECIMAL(10,4),
`foreignPrice` DECIMAL(10,4),
`foreignPriceKg` DECIMAL(10,4),
INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC),
UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC) UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC)
)ENGINE=MEMORY DEFAULT CHARSET=utf8; )ENGINE=MEMORY DEFAULT CHARSET=utf8;

View File

@ -21,6 +21,7 @@ BEGIN
,CURDATE() ,CURDATE()
,account.myUser_getId() ,account.myUser_getId()
,TRUE ,TRUE
,1
,vNewTicket); ,vNewTicket);
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price)

View File

@ -8,23 +8,28 @@ BEGIN
DELETE FROM invoiceOutExpense DELETE FROM invoiceOutExpense
WHERE invoiceOutFk = vInvoice; WHERE invoiceOutFk = vInvoice;
INSERT INTO invoiceOutExpense(invoiceOutFk, expenseFk, amount) INSERT INTO invoiceOutExpense(invoiceOutFk, expenseFk, amount, foreignAmount)
SELECT vInvoice, SELECT vInvoice,
expenseFk, expenseFk,
SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount SUM(ROUND(quantity * price * (100 - discount) / 100, 2)) amount,
FROM tmp.ticketToInvoice t currency_getRate(t.currencyFk, NULL) *
SUM(ROUND(quantity * price * (100 - discount) / 100, 2)) foreignAmount
FROM tmp.ticketToInvoice tti
JOIN ticket t ON t.id = tti.id
JOIN sale s ON s.ticketFk = t.id JOIN sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
GROUP BY i.expenseFk GROUP BY i.expenseFk
HAVING amount != 0; HAVING amount <> 0
UNION ALL
INSERT INTO invoiceOutExpense(invoiceOutFk, expenseFk, amount)
SELECT vInvoice, SELECT vInvoice,
tst.expenseFk, tst.expenseFk,
SUM(ROUND(ts.quantity * ts.price ,2)) amount SUM(ROUND(ts.quantity * ts.price ,2)) amount,
FROM tmp.ticketToInvoice t currency_getRate(t.currencyFk, NULL),
SUM(ROUND(ts.quantity * ts.price, 2)) foreignAmount
FROM tmp.ticketToInvoice tti
JOIN ticket t ON t.id = tti.id
JOIN ticketService ts ON ts.ticketFk = t.id JOIN ticketService ts ON ts.ticketFk = t.id
JOIN ticketServiceType tst ON tst.id = ts.ticketServiceTypeFk JOIN ticketServiceType tst ON tst.id = ts.ticketServiceTypeFk
HAVING amount != 0; HAVING amount <> 0;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -18,6 +18,7 @@ BEGIN
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vWarehouseFk INT; DECLARE vWarehouseFk INT;
DECLARE vCompanyFk INT; DECLARE vCompanyFk INT;
DECLARE vCurrencyFk INT;
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vItemShelvingFk INT; DECLARE vItemShelvingFk INT;
DECLARE vAddressFk INT; DECLARE vAddressFk INT;
@ -28,10 +29,12 @@ BEGIN
WHERE code = vShelvingCode; WHERE code = vShelvingCode;
SELECT c.id, SELECT c.id,
c.currencyFk,
pc.clientSelfConsumptionFk, pc.clientSelfConsumptionFk,
s.warehouseFk, s.warehouseFk,
pc.addressSelfConsumptionFk pc.addressSelfConsumptionFk
INTO vCompanyFk, INTO vCompanyFk,
vCurrencyFk,
vClientFk, vClientFk,
vWarehouseFk, vWarehouseFk,
vAddressFk vAddressFk
@ -75,6 +78,7 @@ BEGIN
CURDATE(), CURDATE(),
vAddressFk, vAddressFk,
vCompanyFk, vCompanyFk,
vCurrencyFk,
NULL, NULL,
vTicketFk vTicketFk
); );

View File

@ -18,14 +18,12 @@ BEGIN
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vClientFk INT; DECLARE vClientFk INT;
DECLARE vDefaultCompanyFk INT; DECLARE vDefaultCompanyFk INT;
DECLARE vDefaultCurrencyFk INT;
DECLARE vCalc INT; DECLARE vCalc INT;
DECLARE vAddressShortage INT; DECLARE vAddressShortage INT;
SELECT barcodeToItem(vItemFk) INTO vItemFk; SELECT barcodeToItem(vItemFk) INTO vItemFk;
SELECT DEFAULT(companyFk) INTO vDefaultCompanyFk
FROM vn.ticket LIMIT 1;
IF vAddressFk IS NULL THEN IF vAddressFk IS NULL THEN
SELECT pc.shortageAddressFk INTO vAddressShortage SELECT pc.shortageAddressFk INTO vAddressShortage
FROM productionConfig pc ; FROM productionConfig pc ;
@ -50,6 +48,11 @@ BEGIN
CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
IF vTicketFk IS NULL THEN IF vTicketFk IS NULL THEN
SELECT DEFAULT(companyFk), DEFAULT(currencyFk)
INTO vDefaultCompanyFk, vDefaultCurrencyFk
FROM vn.ticket
LIMIT 1;
CALL ticket_add( CALL ticket_add(
vClientFk, vClientFk,
util.VN_CURDATE(), util.VN_CURDATE(),
@ -61,6 +64,7 @@ BEGIN
util.VN_CURDATE(), util.VN_CURDATE(),
account.myUser_getId(), account.myUser_getId(),
FALSE, FALSE,
vDefaultCurrencyFk,
vTicketFk); vTicketFk);
END IF; END IF;

View File

@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`orderCreate`(
vLanded DATE, vLanded DATE,
vAgencyMode INT, vAgencyMode INT,
vAddress INT, vAddress INT,
vCompany INT,
vCurrency INT,
vSourceApp VARCHAR(10), vSourceApp VARCHAR(10),
OUT vOrderId INT) OUT vOrderId INT)
BEGIN BEGIN
@ -18,8 +20,8 @@ BEGIN
FROM vn.address FROM vn.address
WHERE id = vAddress; WHERE id = vAddress;
INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,source_app) INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,company_id,currencyFk,source_app)
VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode ,vAddress ,vSourceApp); VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode,vAddress,vCompany,vCurrency,vSourceApp);
SET vOrderId = LAST_INSERT_ID(); SET vOrderId = LAST_INSERT_ID();

View File

@ -3,11 +3,13 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`orderListCreate`(
vLanded DATE, vLanded DATE,
vAgencyMode INT, vAgencyMode INT,
vAddress INT, vAddress INT,
vCompany INT,
vCurrency INT,
vSourceApp VARCHAR(10)) vSourceApp VARCHAR(10))
BEGIN BEGIN
DECLARE vOrderId INT; DECLARE vOrderId INT;
CALL vn.orderCreate(vLanded,vAgencyMode,vAddress,vSourceApp,vOrderId); CALL vn.orderCreate(vLanded,vAgencyMode,vAddress,vCompany,vCurrency,vSourceApp,vOrderId);
SELECT vOrderId; SELECT vOrderId;
END$$ END$$

View File

@ -1,5 +1,9 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`recipe_Plaster`(vItemFk INT, vTicketFk INT, vQuantity INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`recipe_Plaster`(
vItemFk INT,
vTicketFk INT,
vQuantity INT
)
BEGIN BEGIN
DECLARE vLastCost DECIMAL(10,2); DECLARE vLastCost DECIMAL(10,2);
@ -7,11 +11,12 @@ BEGIN
DECLARE vShipped DATE; DECLARE vShipped DATE;
DECLARE vEntryFk INT; DECLARE vEntryFk INT;
DECLARE vTravelFk INT; DECLARE vTravelFk INT;
DECLARE vCurrencyFk INT;
CALL cache.last_buy_refresh(FALSE); CALL cache.last_buy_refresh(FALSE);
SELECT warehouseFk, shipped SELECT warehouseFk, shipped, currencyFk
INTO vWarehouseFk, vShipped INTO vWarehouseFk, vShipped, vCurrencyFk
FROM vn.ticket FROM vn.ticket
WHERE id = vTicketFk; WHERE id = vTicketFk;
@ -27,8 +32,19 @@ BEGIN
ORDER BY (lb.warehouse_id = vWarehouseFk) DESC ORDER BY (lb.warehouse_id = vWarehouseFk) DESC
LIMIT 1; LIMIT 1;
INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) INSERT INTO vn.sale(
SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost ticketFk,
itemFk,
quantity,
concept,
price,
foreignPrice
)SELECT vTicketFk,
98,
- vQuantity,
i.longName,
vLastCost,
currency_getRate(vCurrencyFk, NULL) * vLastCost
FROM vn.item i FROM vn.item i
WHERE i.id = vItemFk; WHERE i.id = vItemFk;
END$$ END$$

View File

@ -1,20 +1,24 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleSplit`(vSaleFk INT, vQuantity INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`saleSplit`(
vSaleFk INT,
vQuantity INT
)
BEGIN BEGIN
DECLARE vNewSaleFk INT; DECLARE vNewSaleFk INT;
INSERT INTO vn.sale(itemFk, INSERT INTO vn.sale(
itemFk,
concept, concept,
price, price,
foreignPrice,
discount, discount,
quantity, quantity,
ticketFk, ticketFk,
isPriceFixed) isPriceFixed
SELECT s.itemFk, )SELECT s.itemFk,
i.longName, i.longName,
s.price, s.price,
s.foreignPrice,
s.discount, s.discount,
vQuantity, vQuantity,
s.ticketFk, s.ticketFk,
@ -30,14 +34,9 @@ BEGIN
SELECT LAST_INSERT_ID() INTO vNewSaleFk; SELECT LAST_INSERT_ID() INTO vNewSaleFk;
INSERT INTO vn.saleComponent( saleFk, INSERT INTO vn.saleComponent(saleFk, componentFk, value)
componentFk, SELECT vNewSaleFk, componentFk, value
value)
SELECT vNewSaleFk,
componentFk,
value
FROM vn.saleComponent FROM vn.saleComponent
WHERE saleFk = vSaleFk; WHERE saleFk = vSaleFk;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -2,21 +2,23 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_PriceFix`(vTicketFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_PriceFix`(vTicketFk INT)
BEGIN BEGIN
DELETE sc.* DELETE sc
FROM vn.saleComponent sc FROM saleComponent sc
JOIN vn.sale s ON s.id = sc.saleFk JOIN sale s ON s.id = sc.saleFk
JOIN vn.component c ON c.id = sc.componentFk JOIN component c ON c.id = sc.componentFk
JOIN vn.componentType ct ON ct.id = c.typeFk JOIN componentType ct ON ct.id = c.typeFk
WHERE s.ticketFk = vTicketFk WHERE s.ticketFk = vTicketFk
AND ct.code = 'other'; AND ct.code = 'other';
UPDATE vn.sale s UPDATE sale s
JOIN ( JOIN (
SELECT sc.saleFk, sum(sc.value ) price SELECT sc.saleFk, SUM(sc.value) price, t.currencyFk
FROM vn.saleComponent sc FROM ticket
JOIN vn.sale s ON s.id = sc.saleFk JOIN sale s ON s.ticketFk = t.id
WHERE s.ticketFk = vTicketFk JOIN saleComponent sc ON sc.saleFk = s.id
WHERE t.id = vTicketFk
GROUP BY sc.saleFk) sub ON sub.saleFk = s.id GROUP BY sc.saleFk) sub ON sub.saleFk = s.id
SET s.price = sub.price; SET s.price = sub.price,
s.foreignPrice = currency_getRate(sub.currencyFk, NULL) * sub.price;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,15 +1,24 @@
DELIMITER $$ DELIMITER $$
$$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE vn.sale_boxPickingPrint( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE vn.sale_boxPickingPrint(
IN vPrinterFk INT, vPrinterFk INT,
IN vSaleFk INT, vSaleFk INT,
IN vPacking INT, vPacking INT,
IN vSectorFk INT, vSectorFk INT,
IN vUserFk INT, vUserFk INT,
IN vPackagingFk VARCHAR(10), vPackagingFk VARCHAR(10),
IN vPackingSiteFk INT) vPackingSiteFk INT
)
BEGIN BEGIN
/** Splits a line of sale to a different ticket and prints the transport sticker /**
* Splits a line of sale to a different ticket and prints the transport sticker
*
* @param vPrinterFk Id printer
* @param vSaleFk Id sale
* @param vPacking Id packing
* @param vSectorFk Id sector
* @param vUserFk Id user
* @param vPackagingFk Id packaging
* @param vPackingSiteFk Id PackingSite
*/ */
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vConcept VARCHAR(30); DECLARE vConcept VARCHAR(30);
@ -30,24 +39,37 @@ BEGIN
DECLARE vShelvingFk VARCHAR(10); DECLARE vShelvingFk VARCHAR(10);
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
SELECT s.quantity, SELECT quantity,
s.quantity MOD vPacking, quantity MOD vPacking,
s.ticketFk, ticketFk,
s.itemFk, itemFk,
s.concept concept
INTO vQuantity, INTO vQuantity,
vRemainder, vRemainder,
vTicketFk, vTicketFk,
vItemFk, vItemFk,
vConcept vConcept
FROM sale s FROM sale s
WHERE s.id = vSaleFk; WHERE id = vSaleFk;
IF vRemainder THEN IF vRemainder THEN
UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk; UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk;
INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept) INSERT INTO sale(
SELECT ticketFk, itemFk, vRemainder, price, discount, concept ticketFk,
itemFk,
quantity,
price,
foreignPrice,
discount,
concept
)SELECT ticketFk,
itemFk,
vRemainder,
price,
foreignPrice,
discount,
concept
FROM sale FROM sale
WHERE id = vSaleFk; WHERE id = vSaleFk;
@ -62,7 +84,6 @@ BEGIN
w1: WHILE vQuantity >= vPacking DO w1: WHILE vQuantity >= vPacking DO
SET vQuantity = vQuantity - vPacking; SET vQuantity = vQuantity - vPacking;
SET vItemShelvingFk = NULL; SET vItemShelvingFk = NULL;
SELECT sub.id SELECT sub.id
@ -131,8 +152,8 @@ w1: WHILE vQuantity >= vPacking DO
routeFk, routeFk,
priority, priority,
hasPriority, hasPriority,
clonedFrom) clonedFrom
SELECT clientFk, )SELECT clientFk,
shipped, shipped,
addressFk, addressFk,
agencyModeFk, agencyModeFk,
@ -199,8 +220,21 @@ w1: WHILE vQuantity >= vPacking DO
WHERE id = vItemShelvingSaleFk; WHERE id = vItemShelvingSaleFk;
END IF; END IF;
ELSE ELSE
INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price) INSERT INTO sale(
SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price ticketFk,
itemFk,
concept,
quantity,
discount,
price,
foreignPrice
)SELECT vNewTicketFk,
itemFk,
concept,
vPacking,
discount,
price,
foreignPrice
FROM sale FROM sale
WHERE id = vSaleFk; WHERE id = vSaleFk;
@ -238,8 +272,7 @@ w1: WHILE vQuantity >= vPacking DO
monitorId, monitorId,
started, started,
ended ended
) )SELECT vAgencyModeFk,
SELECT vAgencyModeFk,
vNewTicketFk, vNewTicketFk,
pc.defaultFreightItemFk, pc.defaultFreightItemFk,
vUserFk, vUserFk,
@ -256,7 +289,6 @@ w1: WHILE vQuantity >= vPacking DO
WHERE ps.id = vPackingSiteFk; WHERE ps.id = vPackingSiteFk;
SET vExpeditionFk = LAST_INSERT_ID(); SET vExpeditionFk = LAST_INSERT_ID();
SET vLastExpeditionTimeStamp = NOW(); SET vLastExpeditionTimeStamp = NOW();
CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE); CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE);
@ -282,8 +314,6 @@ w1: WHILE vQuantity >= vPacking DO
DELETE FROM sale DELETE FROM sale
WHERE quantity = 0 WHERE quantity = 0
AND id = vSaleFk; AND id = vSaleFk;
END WHILE; END WHILE;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -16,6 +16,7 @@ proc: BEGIN
DECLARE vLanded DATE; DECLARE vLanded DATE;
DECLARE vIsEditable BOOLEAN; DECLARE vIsEditable BOOLEAN;
DECLARE vZoneFk INTEGER; DECLARE vZoneFk INTEGER;
DECLARE vCurrencyFk SMALLINT;
DECLARE vDone BOOL DEFAULT FALSE; DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vCur CURSOR FOR DECLARE vCur CURSOR FOR
@ -41,14 +42,16 @@ proc: BEGIN
t.shipped, t.shipped,
t.addressFk, t.addressFk,
t.agencyModeFk, t.agencyModeFk,
t.landed t.landed,
t.currencyFk
INTO vIsEditable, INTO vIsEditable,
vZoneFk, vZoneFk,
vWarehouseFk, vWarehouseFk,
vShipped, vShipped,
vAddressFk, vAddressFk,
vAgencyModeFk, vAgencyModeFk,
vLanded vLanded,
vCurrencyFk
FROM ticket t FROM ticket t
LEFT JOIN ticketState ts ON t.id = ts.ticketFk LEFT JOIN ticketState ts ON t.id = ts.ticketFk
LEFT JOIN alertLevel al ON al.id = ts.alertLevel LEFT JOIN alertLevel al ON al.id = ts.alertLevel
@ -96,7 +99,7 @@ proc: BEGIN
GROUP BY s.itemFk; GROUP BY s.itemFk;
CALL catalog_componentPrepare(); CALL catalog_componentPrepare();
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk, vCurrencyFk);
IF vOption IS NULL THEN IF vOption IS NULL THEN
SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance');

View File

@ -2,11 +2,11 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_replaceItem`(vSaleFk INT, vNewItemFk INT, vQuantity INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_replaceItem`(vSaleFk INT, vNewItemFk INT, vQuantity INT)
BEGIN BEGIN
/** /**
* Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. * Añade un nuevo artículo para sustituir a otro, y actualiza la memoria de sustituciones.
* *
* @param vSaleFk id de la tabla sale * @param vSaleFk Id de la tabla sale
* @param vNewItemFk articulo sustituto * @param vNewItemFk Artículo sustituto
* @param vQuantity cantidad que se va a sustituir * @param vQuantity Cantidad que se va a sustituir
*/ */
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vItemFk INT; DECLARE vItemFk INT;
@ -21,9 +21,13 @@ BEGIN
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vNewPrice DECIMAL(10,2); DECLARE vNewPrice DECIMAL(10,2);
DECLARE vOldPrice DECIMAL(10,2); DECLARE vOldPrice DECIMAL(10,2);
DECLARE vNewForeignPrice DECIMAL(10,2);
DECLARE vOldForeignPrice DECIMAL(10,2);
DECLARE vOption VARCHAR(255); DECLARE vOption VARCHAR(255);
DECLARE vNewSaleFk INT; DECLARE vNewSaleFk INT;
DECLARE vFinalPrice DECIMAL(10,2); DECLARE vFinalPrice DECIMAL(10,2);
DECLARE vFinalForeignPrice DECIMAL(10,2);
DECLARE vCurrencyFk INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
@ -39,7 +43,9 @@ BEGIN
t.landed, t.landed,
t.addressFk, t.addressFk,
t.agencyModeFk, t.agencyModeFk,
s.price s.price,
s.foreignPrice,
t.currencyFk
INTO vTicketFk, INTO vTicketFk,
vQuantity, vQuantity,
vItemFk, vItemFk,
@ -48,7 +54,9 @@ BEGIN
vLanded, vLanded,
vAddressFk, vAddressFk,
vAgencyModeFk, vAgencyModeFk,
vOldPrice vOldPrice,
vOldForeignPrice,
vCurrencyFk
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 = vSaleFk; WHERE s.id = vSaleFk;
@ -74,9 +82,10 @@ BEGIN
vLanded, vLanded,
vAddressFk, vAddressFk,
vAgencyModeFk, vAgencyModeFk,
vCurrencyFk,
vNewItemFk); vNewItemFk);
SELECT price INTO vNewPrice SELECT price, foreignPrice INTO vNewPrice, vNewForeignPrice
FROM tmp.ticketComponentPrice FROM tmp.ticketComponentPrice
ORDER BY (vQuantity % `grouping`) ASC ORDER BY (vQuantity % `grouping`) ASC
LIMIT 1; LIMIT 1;
@ -86,11 +95,13 @@ BEGIN
END IF; END IF;
IF vNewPrice > vOldPrice THEN IF vNewPrice > vOldPrice THEN
SET vFinalPrice = vOldPrice; SET vFinalPrice = vOldPrice,
SET vOption = 'substitution'; vFinalForeignPrice = vOldForeignPrice,
vOption = 'substitution';
ELSE ELSE
SET vFinalPrice = vNewPrice; SET vFinalPrice = vNewPrice,
SET vOption = 'renewPrices'; vFinalForeignPrice = vNewForeignPrice,
vOption = 'renewPrices';
END IF; END IF;
START TRANSACTION; START TRANSACTION;
@ -104,12 +115,14 @@ BEGIN
itemFk, itemFk,
quantity, quantity,
concept, concept,
price) price,
foreignPrice)
SELECT vTicketFk, SELECT vTicketFk,
vNewItemFk, vNewItemFk,
CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CEIL(vQuantity / vRoundQuantity) * vRoundQuantity,
CONCAT('+ ', i.name), CONCAT('+ ', i.name),
vFinalPrice vFinalPrice,
vFinalForeignPrice
FROM vn.item i FROM vn.item i
WHERE id = vNewItemFk; WHERE id = vNewItemFk;

View File

@ -1,18 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketCalculateFromType`( vLanded DATE,
vAddressFk INT,
vAgencyModeFk INT,
vTypeFk INT)
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item
(INDEX (itemFk))
ENGINE = MEMORY
SELECT id itemFk FROM vn.item
WHERE typeFk = vTypeFk;
CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, FALSE);
DROP TEMPORARY TABLE tmp.item;
DROP TEMPORARY TABLE tmp.ticketLot;
END$$
DELIMITER ;

View File

@ -1,11 +1,13 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(
vCode VARCHAR(25)
)
BEGIN BEGIN
/** /**
* A partir de la tabla tmp.sale, crea los Movimientos_componentes * A partir de la tabla tmp.sale, crea los Movimientos_componentes
* y modifica el campo Preu de la tabla Movimientos * y modifica el campo vn.sale.price
* *
* @param i_option integer tipo de actualizacion * @param vCode integer tipo de actualizacion
* @param table tmp.sale tabla memory con el campo saleFk, warehouseFk * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk
**/ **/
DECLARE vComponentFk INT; DECLARE vComponentFk INT;
@ -14,7 +16,7 @@ BEGIN
SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; SELECT id INTO vComponentFk FROM component WHERE `code` = vCode;
END IF; END IF;
DELETE sc.* DELETE sc
FROM tmp.sale tmps FROM tmp.sale tmps
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
JOIN `component` c ON c.id = sc.componentFk JOIN `component` c ON c.id = sc.componentFk
@ -63,21 +65,23 @@ BEGIN
HAVING dif <> 0; HAVING dif <> 0;
ELSE ELSE
UPDATE sale s UPDATE sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN item i on i.id = s.itemFk JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = sumValue / ((100 - s.discount) / 100) SET s.price = sumValue / ((100 - s.discount) / 100),
WHERE it.code != 'PRT' ; s.foreignPrice = currency_getRate(t.currencyFk, NULL) * (sumValue / ((100 - s.discount) / 100))
WHERE it.code <> 'PRT' ;
REPLACE INTO saleComponent(saleFk, componentFk, value) REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue
FROM sale s FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk != 21 WHERE sc.componentFk <> 21
GROUP BY s.id GROUP BY s.id
HAVING ROUND(saleValue, 4) <> 0; HAVING ROUND(saleValue, 4) <> 0;
END IF; END IF;
@ -90,9 +94,10 @@ BEGIN
JOIN `component` c ON c.id = sc.componentFk JOIN `component` c ON c.id = sc.componentFk
JOIN componentType ct on ct.id = c.typeFk AND ct.isBase JOIN componentType ct on ct.id = c.typeFk AND ct.isBase
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.priceFixed = sumValue, s.isPriceFixed = 1; SET s.priceFixed = sumValue,
s.isPriceFixed = TRUE;
DELETE sc.* DELETE sc
FROM saleComponent sc FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN sale s on s.id = sc.saleFk JOIN sale s on s.id = sc.saleFk

View File

@ -15,8 +15,10 @@ BEGIN
(INDEX (ticketFk)) (INDEX (ticketFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT t.ticketFk, SELECT t.ticketFk,
IFNULL(SUM(ta.taxableBase + ta.tax), 0.0) AS total, SUM(ta.taxableBase) totalWithoutVat,
SUM(ta.taxableBase) totalWithoutVat SUM(ta.foreignTaxableBase) foreignTotalWithoutVat,
IFNULL(SUM(ta.taxableBase + ta.tax), 0.0) total,
IFNULL(SUM(ta.foreignTaxableBase + ta.foreignTax), 0.0) foreignTotal
FROM tmp.ticket t FROM tmp.ticket t
LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk
GROUP BY ticketFk; GROUP BY ticketFk;

View File

@ -25,12 +25,10 @@ BEGIN
END IF; END IF;
END IF; END IF;
SELECT s.id, s.itemFk, s.quantity, s.concept, s.price, s.reserved, s.discount, v.visible, av.available, it.image, it.subName SELECT s.itemFk, v.visible, av.available
FROM sale s FROM sale s
LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc
LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc
LEFT JOIN item it ON it.id = s.itemFk WHERE s.ticketFk = vTicket;
WHERE s.ticketFk = vTicket
ORDER BY s.concept;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketPackaging_add`(
vClientFk INT, vClientFk INT,
vDated DATE, vDated DATE,
vCompanyFk INT, vCompanyFk INT,
vCurrencyFk INT,
vWithoutPeriodGrace BOOLEAN) vWithoutPeriodGrace BOOLEAN)
BEGIN BEGIN
/** /**
@ -12,6 +13,7 @@ BEGIN
* @param vClientFk Cliente en caso de NULL todos los clientes * @param vClientFk Cliente en caso de NULL todos los clientes
* @param vDated Fecha hasta la cual se revisan los embalajes * @param vDated Fecha hasta la cual se revisan los embalajes
* @param vCompanyFk Empresa de la cual se comprobaran sus clientes * @param vCompanyFk Empresa de la cual se comprobaran sus clientes
* @param vCurrencyFk Id de la moneda
* @param vWithoutPeriodGrace si no se aplica el periodo de gracia de un mes * @param vWithoutPeriodGrace si no se aplica el periodo de gracia de un mes
*/ */
DECLARE vNewTicket INT; DECLARE vNewTicket INT;
@ -110,6 +112,7 @@ BEGIN
vDateEnd, vDateEnd,
account.myUser_getId(), account.myUser_getId(),
TRUE, TRUE,
vCurrencyFk,
vNewTicket); vNewTicket);
INSERT INTO ticketPackaging(ticketFk, packagingFk, quantity, pvp) INSERT INTO ticketPackaging(ticketFk, packagingFk, quantity, pvp)

View File

@ -1,5 +1,8 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_Clone`(
vOriginalTicket INT,
OUT vNewTicket INT
)
BEGIN BEGIN
/** /**
* Clona el contenido de un ticket en otro * Clona el contenido de un ticket en otro
@ -29,10 +32,9 @@ BEGIN
routeFk, routeFk,
priority, priority,
hasPriority, hasPriority,
clonedFrom clonedFrom,
) currencyFk
SELECT )SELECT clientFk,
clientFk,
shipped, shipped,
addressFk, addressFk,
agencyModeFk, agencyModeFk,
@ -46,7 +48,8 @@ BEGIN
routeFk, routeFk,
priority, priority,
hasPriority, hasPriority,
vOriginalTicket vOriginalTicket,
currencyFk
FROM ticket FROM ticket
WHERE id = vOriginalTicket; WHERE id = vOriginalTicket;

View File

@ -1,16 +1,18 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_add`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_add`(
vClientId INT vClientId INT,
,vShipped DATE vShipped DATE,
,vWarehouseFk INT vWarehouseFk INT,
,vCompanyFk INT vCompanyFk INT,
,vAddressFk INT vAddressFk INT,
,vAgencyModeFk INT vAgencyModeFk INT,
,vRouteFk INT vRouteFk INT,
,vlanded DATE vlanded DATE,
,vUserId INT vUserId INT,
,vIsRequiredZone INT vIsRequiredZone INT,
,OUT vNewTicket INT) vCurrencyFk INT,
OUT vNewTicket INT
)
BEGIN BEGIN
/** /**
* Crea un ticket, * Crea un ticket,
@ -30,8 +32,11 @@ BEGIN
*/ */
DECLARE vZoneFk INT; DECLARE vZoneFk INT;
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vForeignPrice DECIMAL(10,2);
DECLARE vBonus DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2);
DECLARE vIsActive BOOL; DECLARE vIsActive BOOL;
DECLARE vDefaultCompanyFk INT;
DECLARE vDefaultCurrencyFk INT;
IF vClientId IS NULL THEN IF vClientId IS NULL THEN
CALL util.throw ('CLIENT_NOT_ESPECIFIED'); CALL util.throw ('CLIENT_NOT_ESPECIFIED');
@ -52,6 +57,13 @@ BEGIN
AND isDefaultAddress; AND isDefaultAddress;
END IF; END IF;
IF vCompanyFk IS NULL OR vCurrencyFk IS NULL THEN
SELECT DEFAULT(companyFk), DEFAULT(currencyFk)
INTO vDefaultCompanyFk, vDefaultCurrencyFk
FROM ticket
LIMIT 1;
END IF;
IF vAgencyModeFk IS NOT NULL THEN IF vAgencyModeFk IS NOT NULL THEN
CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE);
@ -81,7 +93,8 @@ BEGIN
landed, landed,
zoneFk, zoneFk,
zonePrice, zonePrice,
zoneBonus zoneBonus,
currencyFk
) )
SELECT vClientId, SELECT vClientId,
vShipped, vShipped,
@ -90,11 +103,12 @@ BEGIN
a.nickname, a.nickname,
vWarehouseFk, vWarehouseFk,
IF(vRouteFk,vRouteFk,NULL), IF(vRouteFk,vRouteFk,NULL),
vCompanyFk, IFNULL(vCompanyFk, vDefaultCompanyFk),
vlanded, vlanded,
vZoneFk, vZoneFk,
vPrice, vPrice,
vBonus vBonus,
IFNULL(vCurrencyFk, vDefaultCurrencyFk)
FROM address a FROM address a
JOIN agencyMode am ON am.id = a.agencyModeFk JOIN agencyMode am ON am.id = a.agencyModeFk
WHERE a.id = vAddressFk; WHERE a.id = vAddressFk;

View File

@ -1,19 +1,20 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_administrativeCopy`(
vOriginalTicket INT,
OUT vNewTicket INT
)
BEGIN BEGIN
INSERT INTO ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed, currencyFk)
INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) SELECT t.clientFk, t.addressFk, t.shipped, w.id, t.companyFk, t.landed, t.currencyFk
SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed FROM ticket t
FROM vn.ticket t
JOIN vn.warehouse w ON w.name = 'INVENTARIO' JOIN vn.warehouse w ON w.name = 'INVENTARIO'
WHERE t.id = vOriginalTicket; WHERE t.id = vOriginalTicket;
SELECT LAST_INSERT_ID() INTO vNewTicket; SELECT LAST_INSERT_ID() INTO vNewTicket;
INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount, foreignPrice)
SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount SELECT vNewTicket, itemFk , concept, quantity, price, discount, foreignPrice
FROM vn.sale s FROM sale
WHERE s.ticketFk = vOriginalTicket; WHERE ticketFk = vOriginalTicket;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -1,7 +1,11 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_cloneAll`(vTicketFk INT, vNewShipped DATE, vWithWarehouse BOOLEAN, OUT vNewTicketFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_cloneAll`(
vTicketFk INT,
vNewShipped DATE,
vWithWarehouse BOOLEAN,
OUT vNewTicketFk INT
)
BEGIN BEGIN
DECLARE vDone BOOLEAN DEFAULT FALSE; DECLARE vDone BOOLEAN DEFAULT FALSE;
DECLARE vOldSaleFk INT; DECLARE vOldSaleFk INT;
DECLARE vNewSaleFk INT; DECLARE vNewSaleFk INT;
@ -33,12 +37,29 @@ BEGIN
LEAVE read_loop; LEAVE read_loop;
END IF; END IF;
INSERT INTO sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) INSERT INTO sale(
SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed ticketFk,
itemFk,
quantity,
concept,
price,
foreignPrice,
discount,
priceFixed,
isPriceFixed
)SELECT vNewTicketFk,
itemFk,
quantity,
concept,
price,
foreignPrice,
discount,
priceFixed,
isPriceFixed
FROM sale FROM sale
WHERE id = vOldSaleFk; WHERE id = vOldSaleFk;
SELECT max(id) INTO vNewSaleFk SELECT MAX(id) INTO vNewSaleFk
FROM sale FROM sale
WHERE ticketFk = vNewTicketFk; WHERE ticketFk = vNewTicketFk;

View File

@ -12,6 +12,7 @@ BEGIN
DECLARE vCompanyFk INT; DECLARE vCompanyFk INT;
DECLARE vAddressFk INT; DECLARE vAddressFk INT;
DECLARE vAgencyModeFk INT; DECLARE vAgencyModeFk INT;
DECLARE vCurrencyFk INT;
DECLARE vNewTicket INT; DECLARE vNewTicket INT;
DECLARE vYear INT; DECLARE vYear INT;
DECLARE vObservationSalesPersonFk INT DECLARE vObservationSalesPersonFk INT
@ -29,6 +30,7 @@ BEGIN
t.clientFk, t.clientFk,
t.warehouseFk, t.warehouseFk,
t.companyFk, t.companyFk,
t.currencyFk,
t.addressFk, t.addressFk,
tt.agencyModeFk, tt.agencyModeFk,
ti.dated ti.dated
@ -49,6 +51,7 @@ BEGIN
vClientFk, vClientFk,
vWarehouseFk, vWarehouseFk,
vCompanyFk, vCompanyFk,
vCurrencyFk,
vAddressFk, vAddressFk,
vAgencyModeFk, vAgencyModeFk,
vShipment; vShipment;
@ -92,6 +95,7 @@ BEGIN
vLanding, vLanding,
account.myUser_getId(), account.myUser_getId(),
FALSE, FALSE,
vCurrencyFk,
vNewTicket); vNewTicket);
UPDATE ticket UPDATE ticket
@ -103,6 +107,7 @@ BEGIN
concept, concept,
quantity, quantity,
price, price,
foreignPrice,
discount, discount,
priceFixed, priceFixed,
isPriceFixed) isPriceFixed)
@ -111,6 +116,7 @@ BEGIN
concept, concept,
quantity, quantity,
price, price,
foreignPrice,
discount, discount,
priceFixed, priceFixed,
isPriceFixed isPriceFixed

View File

@ -18,6 +18,7 @@ BEGIN
DECLARE vWithPackage BOOL; DECLARE vWithPackage BOOL;
DECLARE vHasToInvoice BOOL; DECLARE vHasToInvoice BOOL;
DECLARE vSerial VARCHAR(2); DECLARE vSerial VARCHAR(2);
DECLARE vCurrencyFk INT;
DECLARE cur CURSOR FOR DECLARE cur CURSOR FOR
SELECT ticketFk FROM tmp.ticket_close; SELECT ticketFk FROM tmp.ticket_close;
@ -45,14 +46,16 @@ BEGIN
t.shipped, t.shipped,
c.hasDailyInvoice, c.hasDailyInvoice,
w.isManaged, w.isManaged,
c.hasToInvoice c.hasToInvoice,
t.currencyFk
INTO vClientFk, INTO vClientFk,
vIsTaxDataChecked, vIsTaxDataChecked,
vCompanyFk, vCompanyFk,
vShipped, vShipped,
vHasDailyInvoice, vHasDailyInvoice,
vWithPackage, vWithPackage,
vHasToInvoice vHasToInvoice,
vCurrencyFk
FROM ticket t FROM ticket t
JOIN `client` c ON c.id = t.clientFk JOIN `client` c ON c.id = t.clientFk
JOIN warehouse w ON w.id = t.warehouseFk JOIN warehouse w ON w.id = t.warehouseFk
@ -71,14 +74,29 @@ BEGIN
GROUP BY p.itemFk); GROUP BY p.itemFk);
-- No retornables o no catalogados -- No retornables o no catalogados
INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed)
(SELECT e.freightItemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.freightItemFk, vClientFk), 1 INSERT INTO sale (
itemFk,
ticketFk,
concept,
quantity,
price,
foreignPrice,
isPriceFixed
)SELECT e.freightItemFk,
vCurTicketFk,
i.name,
COUNT(*),
getSpecialPrice(e.freightItemFk, vClientFk),
getSpecialPrice(e.freightItemFk, vClientFk) *
currency_getRate(vCurrencyFk, vShipped - INTERVAL 1 DAY),
TRUE
FROM expedition e FROM expedition e
JOIN item i ON i.id = e.freightItemFk JOIN item i ON i.id = e.freightItemFk
LEFT JOIN packaging p ON p.itemFk = i.id LEFT JOIN packaging p ON p.itemFk = i.id
WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
AND getSpecialPrice(e.freightItemFk, vClientFk) > 0 AND getSpecialPrice(e.freightItemFk, vClientFk) > 0
GROUP BY e.freightItemFk); GROUP BY e.freightItemFk;
IF(vHasDailyInvoice) AND vHasToInvoice THEN IF(vHasDailyInvoice) AND vHasToInvoice THEN
SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial; SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial;

View File

@ -2,6 +2,7 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`(
vTicketFk INT, vTicketFk INT,
vClientFk INT, vClientFk INT,
vCurrencyFk INT,
vNickname VARCHAR(50), vNickname VARCHAR(50),
vAgencyModeFk INT, vAgencyModeFk INT,
vAddressFk INT, vAddressFk INT,
@ -12,15 +13,16 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentMakeU
vLanded DATE, vLanded DATE,
vIsDeleted BOOLEAN, vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN, vHasToBeUnrouted BOOLEAN,
vOption VARCHAR(25)) vOption VARCHAR(25)
)
BEGIN BEGIN
/** /**
* Modifica en el ticket los campos que se le pasan por parámetro * Modifica en el ticket los campos que se le pasan por parámetro
* y cambia sus componentes * y cambia sus componentes
* *
* @param vTicketFk Id del ticket a modificar * @param vTicketFk Id del ticket a modificar
* @param vClientFk nuevo cliente * @param vClientFk nuevo cliente
* @param vCurrencyFk moneda
* @param vNickname nuevo alias * @param vNickname nuevo alias
* @param vAgencyModeFk nueva agencia * @param vAgencyModeFk nueva agencia
* @param vAddressFk nuevo consignatario * @param vAddressFk nuevo consignatario
@ -33,54 +35,52 @@ BEGIN
* @param vHasToBeUnrouted si se le elimina la ruta al ticket * @param vHasToBeUnrouted si se le elimina la ruta al ticket
* @param vOption opcion para el case del proc ticketComponentUpdateSale * @param vOption opcion para el case del proc ticketComponentUpdateSale
*/ */
DECLARE vPrice DECIMAL(10,2); DECLARE vPrice DECIMAL(10,2);
DECLARE vBonus DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2);
CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk, NULL);
IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN
UPDATE ticket t UPDATE ticket t
JOIN address a ON a.id = vAddressFk JOIN address a ON a.id = vAddressFk
SET t.nickname = a.nickname SET t.nickname = a.nickname
WHERE t.id = vTicketFk; WHERE t.id = vTicketFk;
END IF; END IF;
CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE);
SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus
FROM tmp.zoneGetShipped FROM tmp.zoneGetShipped
WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped)
AND warehouseFk = vWarehouseFk
LIMIT 1;
UPDATE ticket t UPDATE ticket
SET SET clientFk = vClientFk,
t.clientFk = vClientFk, nickname = vNickname,
t.nickname = vNickname, agencyModeFk = vAgencyModeFk,
t.agencyModeFk = vAgencyModeFk, addressFk = vAddressFk,
t.addressFk = vAddressFk, zoneFk = vZoneFk,
t.zoneFk = vZoneFk, zonePrice = vPrice,
t.zonePrice = vPrice, zoneBonus = vBonus,
t.zoneBonus = vBonus, warehouseFk = vWarehouseFk,
t.warehouseFk = vWarehouseFk, companyFk = vCompanyFk,
t.companyFk = vCompanyFk, landed = vLanded,
t.landed = vLanded, shipped = vShipped,
t.shipped = vShipped, isDeleted = vIsDeleted,
t.isDeleted = vIsDeleted currencyFk = vCurrencyFk
WHERE WHERE id = vTicketFk;
t.id = vTicketFk;
IF vHasToBeUnrouted THEN IF vHasToBeUnrouted THEN
UPDATE ticket t SET t.routeFk = NULL UPDATE ticket SET routeFk = NULL
WHERE t.id = vTicketFk; WHERE id = vTicketFk;
END IF; END IF;
DROP TEMPORARY TABLE IF EXISTS tmp.sale; DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) (PRIMARY KEY (saleFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT id AS saleFk, vWarehouseFk warehouseFk SELECT id saleFk, vWarehouseFk warehouseFk
FROM sale s WHERE s.ticketFk = vTicketFk; FROM sale s WHERE s.ticketFk = vTicketFk;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
@ -89,9 +89,7 @@ BEGIN
CALL ticketComponentUpdateSale (vOption); CALL ticketComponentUpdateSale (vOption);
DROP TEMPORARY TABLE tmp.sale;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
DROP TEMPORARY TABLE tmp.sale, tmp.zoneGetShipped, tmp.ticketComponentPreview;
DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -4,7 +4,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentPrevi
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vZoneFk INT, vZoneFk INT,
vWarehouseFk SMALLINT) vWarehouseFk SMALLINT,
vCurrencyFk SMALLINT
)
BEGIN BEGIN
/** /**
* Calcula los componentes de los articulos de un ticket * Calcula los componentes de los articulos de un ticket
@ -21,7 +23,6 @@ BEGIN
DECLARE vHasAddressChanged BOOL; DECLARE vHasAddressChanged BOOL;
DECLARE vHasZoneChanged BOOL DEFAULT FALSE; DECLARE vHasZoneChanged BOOL DEFAULT FALSE;
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
DECLARE vShipped DATE; DECLARE vShipped DATE;
DECLARE vAddressTypeRateFk INT DEFAULT NULL; DECLARE vAddressTypeRateFk INT DEFAULT NULL;
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
@ -31,12 +32,14 @@ BEGIN
SELECT DATE(landed) <> vLanded, SELECT DATE(landed) <> vLanded,
addressFk <> vAddressFk, addressFk <> vAddressFk,
zoneFk <> vZoneFk, zoneFk <> vZoneFk,
warehouseFk <> vWarehouseFk warehouseFk <> vWarehouseFk,
IFNULL(vCurrencyFk, currencyFk)
INTO INTO
vHasDataChanged, vHasDataChanged,
vHasAddressChanged, vHasAddressChanged,
vHasZoneChanged, vHasZoneChanged,
vHasWarehouseChanged vHasWarehouseChanged,
vCurrencyFk
FROM vn.ticket t FROM vn.ticket t
WHERE t.id = vTicketFk; WHERE t.id = vTicketFk;
@ -71,7 +74,7 @@ BEGIN
GROUP BY bu.warehouseFk, bu.itemFk); GROUP BY bu.warehouseFk, bu.itemFk);
CALL catalog_componentPrepare(); CALL catalog_componentPrepare();
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk, vCurrencyFk);
REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value

View File

@ -34,6 +34,7 @@ BEGIN
s.quantity, s.quantity,
s.concept, s.concept,
s.price, s.price,
s.foreignPrice,
s.reserved, s.reserved,
s.discount, s.discount,
i.image, i.image,

View File

@ -39,6 +39,7 @@ BEGIN
SELECT s.ticketFk, SELECT s.ticketFk,
s.itemFk, s.itemFk,
s.quantity * s.price * (100 - s.discount) / 100 total, s.quantity * s.price * (100 - s.discount) / 100 total,
s.quantity * s.foreignPrice * (100 - s.discount) / 100 foreignTotal,
t.companyFk, t.companyFk,
t.addressFk, t.addressFk,
su.countryFk, su.countryFk,
@ -57,6 +58,7 @@ BEGIN
SELECT s.ticketFk, SELECT s.ticketFk,
bp.pgcFk, bp.pgcFk,
SUM(s.total) taxableBase, SUM(s.total) taxableBase,
SUM(s.foreignTotal) foreignTaxableBase,
pgc.rate, pgc.rate,
tc.code, tc.code,
bp.priority bp.priority
@ -76,6 +78,7 @@ BEGIN
SELECT tt.ticketFk, SELECT tt.ticketFk,
pgc.code pgcFk, pgc.code pgcFk,
SUM(ts.quantity * ts.price) taxableBase, SUM(ts.quantity * ts.price) taxableBase,
SUM(ts.quantity * ts.foreignPrice) foreignTaxableBase,
pgc.rate, pgc.rate,
tc.code tc.code
FROM tmp.ticket tt FROM tmp.ticket tt
@ -92,17 +95,21 @@ BEGIN
GROUP BY tt.ticketFk, pgc.code GROUP BY tt.ticketFk, pgc.code
HAVING taxableBase; HAVING taxableBase;
INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, foreignTaxableBase, rate, code)
SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.rate, ts.code SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.foreignTaxableBase, ts.rate, ts.code
FROM tmp.ticketServiceTax ts FROM tmp.ticketServiceTax ts
ON DUPLICATE KEY UPDATE ticketTax.taxableBase = VALUES (taxableBase) + ticketTax.taxableBase ; ON DUPLICATE KEY UPDATE
ticketTax.taxableBase = VALUES (taxableBase) + ticketTax.taxableBase,
ticketTax.foreignTaxableBase = VALUES (foreignTaxableBase) + ticketTax.foreignTaxableBase;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketAmount CREATE OR REPLACE TEMPORARY TABLE tmp.ticketAmount
(INDEX (ticketFk)) (INDEX (ticketFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT ticketFk, SELECT ticketFk,
taxableBase, taxableBase,
foreignTaxableBase,
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,
SUM(CAST(foreignTaxableBase * rate / 100 AS DECIMAL(10, 2))) foreignTax,
code code
FROM tmp.ticketTax FROM tmp.ticketTax
GROUP BY ticketFk, code; GROUP BY ticketFk, code;

View File

@ -5,6 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getWithParamet
vShipped DATE, vShipped DATE,
vAddressFk INT, vAddressFk INT,
vCompanyFk INT, vCompanyFk INT,
vCurrencyFk INT,
vAgencyModeFk INT, vAgencyModeFk INT,
OUT vTicketFk INT OUT vTicketFk INT
) )
@ -17,6 +18,7 @@ BEGIN
* @param vShipped Fecha de preparacion * @param vShipped Fecha de preparacion
* @param vAddressFk Consignatario * @param vAddressFk Consignatario
* @param vCompanyFk Empresa * @param vCompanyFk Empresa
* @param vCurrencyFk Id de moneda
* @param vAgencyModeFk agencia * @param vAgencyModeFk agencia
*/ */
@ -31,7 +33,7 @@ BEGIN
LIMIT 1; LIMIT 1;
IF vTicketFk IS NULL THEN IF vTicketFk IS NULL THEN
CALL vn.ticket_add( CALL vn.pticket_add(
vClientFk, vClientFk,
IFNULL(vShipped, util.VN_CURDATE()), IFNULL(vShipped, util.VN_CURDATE()),
vWarehouseFk, vWarehouseFk,
@ -42,6 +44,7 @@ BEGIN
vShipped, vShipped,
`account`.`myUser_getId`(), `account`.`myUser_getId`(),
TRUE, TRUE,
vCurrencyFk,
vTicketFk vTicketFk
); );
END IF; END IF;

View File

@ -4,7 +4,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_priceDifferenc
vLanded DATE, vLanded DATE,
vAddressFk INT, vAddressFk INT,
vZoneFk INT, vZoneFk INT,
vWarehouseFk INT) vWarehouseFk INT,
vCurrencyFk SMALLINT
)
BEGIN BEGIN
/** /**
* Devuelve las diferencias de precio de los movimientos de un ticket. * Devuelve las diferencias de precio de los movimientos de un ticket.
@ -15,29 +17,36 @@ BEGIN
* @param vZoneFk Id de la zona * @param vZoneFk Id de la zona
* @param vWarehouseFk Id del almacén * @param vWarehouseFk Id del almacén
*/ */
CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk, vCurrencyFk);
WITH ticketPriceDifference AS (
SELECT s.itemFk, SELECT s.itemFk,
i.name, i.name,
i.size, i.size,
i.category, i.category,
IFNULL(s.quantity, 0) AS quantity, IFNULL(s.quantity, 0) quantity,
IFNULL(s.price, 0) AS price, IFNULL(s.price, 0) price,
ROUND(SUM(tc.cost), 2) AS newPrice, ROUND(SUM(tc.cost), 2) newPrice,
s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, s.id saleFk
s.id AS saleFk FROM vn.sale s
FROM sale s JOIN vn.item i ON i.id = s.itemFk
JOIN item i ON i.id = s.itemFk JOIN vn.ticket t ON t.id = s.ticketFk
JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
AND tc.warehouseFk = vWarehouseFk AND tc.warehouseFk = vWarehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk AND sc.componentFk = tc.componentFk
LEFT JOIN `component` c ON c.id = tc.componentFk LEFT JOIN vn.`component` c ON c.id = tc.componentFk
WHERE t.id = vTicketFk WHERE t.id = vTicketFk
AND IF(sc.componentFk IS NULL AND IF(sc.componentFk IS NULL
AND c.classRate IS NOT NULL, FALSE, TRUE) AND c.classRate IS NOT NULL, FALSE, TRUE)
GROUP BY s.id ORDER BY s.id; GROUP BY s.id ORDER BY s.id
) SELECT
*,
currency_getRate(vCurrencyFk, NULL) * price foreignPrice,
currency_getRate(vCurrencyFk, NULL) * newPrice newForeignPrice,
quantity * (price - newPrice) difference,
currency_getRate(vCurrencyFk, NULL) * quantity * (price - newPrice) foreignDifference
FROM ticketPriceDifference;
DROP TEMPORARY TABLE tmp.ticketComponentPreview; DROP TEMPORARY TABLE tmp.ticketComponentPreview;
END$$ END$$

View File

@ -27,8 +27,10 @@ proc:BEGIN
UPDATE ticket t UPDATE ticket t
JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id
SET t.totalWithVat = tt.total, SET t.totalWithoutVat = tt.totalWithoutVat,
t.totalWithoutVat = tt.totalWithoutVat; t.foreignTotalWithoutVat = tt.foreignTotalWithoutVat,
t.totalWithVat = tt.total,
t.foreignTotalWithVat = tt.foreignTotal;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE
tmp.ticket, tmp.ticket,

View File

@ -0,0 +1,82 @@
ALTER TABLE hedera.order ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL AFTER total;
ALTER TABLE hedera.order ADD `foreignTaxableBase` decimal(10,2) NULL AFTER currencyFk;
ALTER TABLE hedera.order ADD `foreignTax` decimal(10,2) NULL AFTER foreignTaxableBase;
ALTER TABLE hedera.order ADD `foreignTotal` decimal(10,2) NULL AFTER foreignTax;
ALTER TABLE hedera.order DROP FOREIGN KEY IF EXISTS order_currency_FK;
ALTER TABLE hedera.order ADD CONSTRAINT order_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE hedera.orderRow ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.company ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL;
ALTER TABLE vn.company DROP FOREIGN KEY IF EXISTS company_currency_FK;
ALTER TABLE vn.company ADD CONSTRAINT company_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.ticket ADD `currencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL AFTER totalWithoutVat;
ALTER TABLE vn.ticket ADD `foreignTotalWithVat` decimal(10,2) NULL AFTER currencyFk;
ALTER TABLE vn.ticket ADD `foreignTotalWithoutVat` decimal(10,2) NULL AFTER foreignTotalWithVat;
ALTER TABLE vn.ticket DROP FOREIGN KEY IF EXISTS ticket_currency_FK;
ALTER TABLE vn.ticket ADD CONSTRAINT ticket_currency_FK FOREIGN KEY (currencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.sale ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.sale ADD `foreignTotal` decimal(10,2) NULL AFTER total;
ALTER TABLE vn.ticketService ADD `foreignPrice` decimal(10,2) NULL AFTER price;
ALTER TABLE vn.invoiceOut ADD `foreignAmount` decimal(10,2) NULL AFTER amount;
ALTER TABLE vn.invoiceOutExpense ADD `foreignAmount` DECIMAL(10,2) DEFAULT NULL AFTER amount;
ALTER TABLE vn.invoiceOutTax ADD `foreignTaxableBase` DECIMAL(10,2) DEFAULT NULL AFTER vat;
ALTER TABLE vn.invoiceOutTax ADD `foreignVat` DECIMAL(10,2) DEFAULT NULL AFTER foreignTaxableBase;
CREATE OR REPLACE DEFINER=`vn`@`localhost`
SQL SECURITY DEFINER
VIEW `hedera`.`order_row`
AS SELECT `t`.`id` AS `id`,
`t`.`orderFk` AS `order_id`,
`t`.`itemFk` AS `item_id`,
`t`.`warehouseFk` AS `warehouse_id`,
`t`.`shipment` AS `shipment`,
`t`.`amount` AS `amount`,
`t`.`price` AS `price`,
`t`.`foreignPrice` AS `foreignPrice`,
`t`.`rate` AS `rate`,
`t`.`created` AS `created`,
`t`.`saleFk` AS `Id_Movimiento`
FROM `hedera`.`orderRow` `t`;
ALTER TABLE vn.country ADD IF NOT EXISTS `companyFk` int(10) UNSIGNED DEFAULT 442 NOT NULL;
ALTER TABLE vn.country DROP FOREIGN KEY IF EXISTS country_defaultCompany_FK;
ALTER TABLE vn.country ADD CONSTRAINT country_defaultCompany_FK FOREIGN KEY (companyFk)
REFERENCES vn.company(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.client ADD IF NOT EXISTS `defaultCompanyFk` int(10) UNSIGNED DEFAULT 442 NOT NULL;
ALTER TABLE vn.client ADD IF NOT EXISTS `defaultCurrencyFk` tinyint(3) UNSIGNED DEFAULT 1 NOT NULL;
ALTER TABLE vn.client DROP FOREIGN KEY IF EXISTS client_defaultCompany_FK;
ALTER TABLE vn.client DROP FOREIGN KEY IF EXISTS client_defaultCurrency_FK;
ALTER TABLE vn.client ADD CONSTRAINT client_defaultCompany_FK FOREIGN KEY (defaultCompanyFk)
REFERENCES vn.company(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE vn.client ADD CONSTRAINT client_defaultCurrency_FK FOREIGN KEY (defaultCurrencyFk)
REFERENCES vn.currency(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
UPDATE vn.client c
JOIN vn.province p ON p.id = c.provinceFk
JOIN vn.country co ON co.id = p.countryFk
SET c.defaultCompanyFk = co.companyFk,
c.defaultCurrencyFk = co.currencyFk;

View File

@ -147,8 +147,13 @@
}, },
"hasDailyInvoice": { "hasDailyInvoice": {
"type": "boolean" "type": "boolean"
},
"defaultCompanyFk": {
"type": "number"
},
"defaultCurrencyFk": {
"type": "number"
} }
}, },
"relations": { "relations": {
"account": { "account": {
@ -256,6 +261,16 @@
"model": "Supplier", "model": "Supplier",
"foreignKey": "fi", "foreignKey": "fi",
"primaryKey": "nif" "primaryKey": "nif"
},
"currency": {
"type": "belongsTo",
"model": "Currency",
"foreignKey": "defaultCurrencyFk"
},
"company": {
"type": "belongsTo",
"model": "Comapny",
"foreignKey": "defaultCompanyFk"
} }
}, },
"scopes": { "scopes": {

View File

@ -1,5 +1,3 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('clientsToInvoice', { Self.remoteMethodCtx('clientsToInvoice', {
description: 'Get the clients to make global invoicing', description: 'Get the clients to make global invoicing',
@ -24,6 +22,11 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The company id to invoice', description: 'The company id to invoice',
required: true required: true
}, {
arg: 'currencyFk',
type: 'number',
description: 'The currency id',
required: true
}, },
], ],
returns: { returns: {
@ -36,7 +39,7 @@ module.exports = Self => {
} }
}); });
Self.clientsToInvoice = async(ctx, clientId, invoiceDate, maxShipped, companyFk, options) => { Self.clientsToInvoice = async(ctx, clientId, invoiceDate, maxShipped, companyFk, currencyFk, options) => {
let tx; let tx;
const myOptions = {userId: ctx.req.accessToken.userId}; const myOptions = {userId: ctx.req.accessToken.userId};
@ -50,10 +53,11 @@ module.exports = Self => {
try { try {
const vIsAllInvoiceable = false; const vIsAllInvoiceable = false;
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?, ?)', [
clientId, clientId,
invoiceDate, invoiceDate,
companyFk, companyFk,
currencyFk,
vIsAllInvoiceable vIsAllInvoiceable
], myOptions); ], myOptions);
@ -72,6 +76,7 @@ module.exports = Self => {
AND t.shipped BETWEEN ? AND util.dayEnd(?) AND t.shipped BETWEEN ? AND util.dayEnd(?)
AND (t.clientFk = ? OR ? IS NULL ) AND (t.clientFk = ? OR ? IS NULL )
AND t.companyFk = ? AND t.companyFk = ?
AND t.currencyFk = ?
AND NOT t.isDeleted AND NOT t.isDeleted
GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id)
HAVING SUM(t.totalWithVat) > 0 HAVING SUM(t.totalWithVat) > 0
@ -82,7 +87,8 @@ module.exports = Self => {
maxShipped, maxShipped,
clientId, clientId,
clientId, clientId,
companyFk companyFk,
currencyFk
], myOptions); ], myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -5,6 +5,7 @@ describe('InvoiceOut clientsToInvoice()', () => {
const userId = 1; const userId = 1;
const clientId = 1101; const clientId = 1101;
const companyFk = 442; const companyFk = 442;
const currencyFk = 1;
const maxShipped = Date.vnNew(); const maxShipped = Date.vnNew();
maxShipped.setMonth(11); maxShipped.setMonth(11);
maxShipped.setDate(31); maxShipped.setDate(31);
@ -54,7 +55,7 @@ describe('InvoiceOut clientsToInvoice()', () => {
}); });
const addresses = await models.InvoiceOut.clientsToInvoice( const addresses = await models.InvoiceOut.clientsToInvoice(
ctx, clientId, invoiceDate, maxShipped, companyFk, options); ctx, clientId, invoiceDate, maxShipped, companyFk, currencyFk, options);
expect(addresses.length).toBeGreaterThan(0); expect(addresses.length).toBeGreaterThan(0);
expect(addresses[0].clientId).toBe(clientId); expect(addresses[0].clientId).toBe(clientId);
@ -69,7 +70,8 @@ describe('InvoiceOut clientsToInvoice()', () => {
}); });
try { try {
await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options); await models.InvoiceOut.clientsToInvoice(
ctx, clientId, invoiceDate, maxShipped, companyFk, currencyFk, options);
} catch (e) { } catch (e) {
expect(e.message).toBe('Test Error'); expect(e.message).toBe('Test Error');
} }

View File

@ -92,11 +92,12 @@ module.exports = Self => {
// Calculate items // Calculate items
const order = await Self.findById(orderFk, null, myOptions); const order = await Self.findById(orderFk, null, myOptions);
stmts.push(new ParameterizedSQL( stmts.push(new ParameterizedSQL(
'CALL vn.catalog_calculate(?, ?, ?, ?)', [ 'CALL vn.catalog_calculate(?, ?, ?, ?, ?)', [
order.landed, order.landed,
order.address_id, order.address_id,
order.agency_id, order.agency_id,
false order.currencyFk,
false,
] ]
)); ));
@ -119,7 +120,9 @@ module.exports = Self => {
w.firstName, w.firstName,
tci.priceKg, tci.priceKg,
ink.hex, ink.hex,
tci.minQuantity tci.minQuantity,
tci.foreignPrice,
tci.foreignPriceKg
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
@ -161,9 +164,11 @@ module.exports = Self => {
`SELECT tcp.itemFk, `SELECT tcp.itemFk,
tcp.grouping, tcp.grouping,
tcp.price, tcp.price,
tcp.foreignPrice,
tcp.rate, tcp.rate,
tcp.warehouseFk, tcp.warehouseFk,
tcp.priceKg, tcp.priceKg,
tcp.foreignPriceKg,
w.name 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;

View File

@ -62,11 +62,12 @@ module.exports = Self => {
stmts.push(stmt); stmts.push(stmt);
stmt = new ParameterizedSQL( stmt = new ParameterizedSQL(
'CALL vn.catalog_calculate(?, ?, ?, ?)', [ 'CALL vn.catalog_calculate(?, ?, ?, ?, ?)', [
order.landed, order.landed,
order.addressFk, order.addressFk,
order.agencyModeFk, order.agencyModeFk,
false order.currencyFk,
false,
] ]
); );
stmts.push(stmt); stmts.push(stmt);

View File

@ -10,7 +10,7 @@ module.exports = Self => {
http: {source: 'path'} http: {source: 'path'}
}], }],
returns: { returns: {
type: 'number', type: 'object',
root: true root: true
}, },
http: { http: {
@ -25,9 +25,22 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const query = `SELECT hedera.order_getTotal(?) total;`; const query = `
const [total] = await Self.rawSql(query, [orderFk], myOptions); DROP TEMPORARY TABLE IF EXISTS tmp.order;
CREATE TEMPORARY TABLE tmp.order
ENGINE = MEMORY
SELECT ? orderFk;
return total.total; CALL hedera.order_getTotal;
SELECT total, foreignTotal FROM tmp.orderTotal;
DROP TEMPORARY TABLE
tmp.order,
tmp.orderTotal;`;
const totals = await Self.rawSql(query, [orderFk], myOptions);
const INDEX_QUERY = 3;
return totals[INDEX_QUERY][0];
}; };
}; };

View File

@ -10,7 +10,7 @@ module.exports = Self => {
http: {source: 'path'} http: {source: 'path'}
}], }],
returns: { returns: {
type: 'number', type: 'object',
root: true root: true
}, },
http: { http: {
@ -25,12 +25,19 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
let totalTax = 0.00; let vat = 0.00;
let foreignVat = 0.00;
const taxes = await Self.app.models.Order.getTaxes(orderId, myOptions); const taxes = await Self.app.models.Order.getTaxes(orderId, myOptions);
taxes.forEach(tax => { taxes.forEach(tax => {
totalTax += tax.tax; vat += tax.tax;
foreignVat += tax.foreignTax;
}); });
return Math.round(totalTax * 100) / 100; return {vat: round(vat), foreignVat: round(foreignVat)};
}; };
function round(amount) {
return Math.round(amount * 100) / 100;
}
}; };

View File

@ -20,6 +20,16 @@ module.exports = Self => {
description: 'The agencyMode for the order', description: 'The agencyMode for the order',
type: 'number', type: 'number',
required: true required: true
}, {
arg: 'companyId',
description: 'The company for the order',
type: 'number',
required: true
}, {
arg: 'currencyId',
description: 'The currency for the order',
type: 'number',
required: true
} }
], ],
returns: { returns: {
@ -32,7 +42,7 @@ module.exports = Self => {
} }
}); });
Self.new = async(ctx, landed, addressId, agencyModeId, options) => { Self.new = async(ctx, landed, addressId, agencyModeId, companyId, currencyId, options) => {
const myOptions = {userId: ctx.req.accessToken.userId}; const myOptions = {userId: ctx.req.accessToken.userId};
let tx; let tx;
@ -59,11 +69,13 @@ module.exports = Self => {
throw new UserError(`You can't create an order for an inactive client`); throw new UserError(`You can't create an order for an inactive client`);
} }
query = `CALL vn.orderListCreate(?, ?, ?, ?);`; query = `CALL vn.orderListCreate(?, ?, ?, ?, ?, ?);`;
[result] = await Self.rawSql(query, [ [result] = await Self.rawSql(query, [
landed, landed,
agencyModeId, agencyModeId,
addressId, addressId,
companyId,
currencyId,
'SALIX' 'SALIX'
], myOptions); ], myOptions);

View File

@ -31,15 +31,22 @@ module.exports = Self => {
} }
try { try {
const ticket = await Self.app.models.Ticket.findOne({ const {landed, addressFk, agencyModeFk, companyFk, currencyFk} =
where: {id: ticketFk} await Self.app.models.Ticket.findById(
}, myOptions); ticketFk,
{fields: ['landed', 'addressFk', 'agencyModeFk', 'companyFk', 'currencyFk']},
myOptions
);
const landed = ticket.landed; const orderID = await Self.app.models.Order.new(
const addressFk = ticket.addressFk; ctx,
const agencyModeFk = ticket.agencyModeFk; landed,
addressFk,
const orderID = await Self.app.models.Order.new(ctx, landed, addressFk, agencyModeFk, myOptions); agencyModeFk,
companyFk,
currencyFk,
myOptions
);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -57,6 +57,8 @@ module.exports = Self => {
'landed', 'landed',
'agencyModeFk', 'agencyModeFk',
'note', 'note',
'companyFk',
'currencyFk',
]); ]);
if (Object.keys(updateParams).length) if (Object.keys(updateParams).length)
await order.updateAttributes(updateParams, myOptions); await order.updateAttributes(updateParams, myOptions);

View File

@ -30,6 +30,9 @@
"price": { "price": {
"type": "number" "type": "number"
}, },
"foreignPrice": {
"type": "number"
},
"rate": { "rate": {
"type": "number" "type": "number"
}, },

View File

@ -82,6 +82,9 @@
}, },
"total": { "total": {
"type": "number" "type": "number"
},
"currencyFk": {
"type": "number"
} }
}, },
"relations": { "relations": {
@ -114,6 +117,11 @@
"type": "belongsTo", "type": "belongsTo",
"model": "Company", "model": "Company",
"foreignKey": "company_id" "foreignKey": "company_id"
},
"currency": {
"type": "belongsTo",
"model": "Currency",
"foreignKey": "currencyFk"
} }
} }
} }

View File

@ -84,9 +84,10 @@ module.exports = Self => {
required: true required: true
}, },
{ {
arg: 'withWarningAccept', arg: 'currencyFk',
type: 'boolean', type: 'integer',
description: 'Has pressed in confirm message', description: 'The currency id',
required: true
}, },
{ {
arg: 'newTicket', arg: 'newTicket',
@ -97,6 +98,11 @@ module.exports = Self => {
arg: 'keepPrice', arg: 'keepPrice',
type: 'boolean', type: 'boolean',
description: 'If prices should be maintained', description: 'If prices should be maintained',
},
{
arg: 'withWarningAccept',
type: 'boolean',
description: 'Has pressed in confirm message',
} }
], ],
returns: { returns: {
@ -176,7 +182,8 @@ module.exports = Self => {
'landed', 'landed',
'isDeleted', 'isDeleted',
'routeFk', 'routeFk',
'nickname' 'nickname',
'currencyFk'
], ],
include: [ include: [
{ {
@ -198,6 +205,7 @@ module.exports = Self => {
const originalTicket = JSON.parse(JSON.stringify(ticketToChange)); const originalTicket = JSON.parse(JSON.stringify(ticketToChange));
const ticketChanges = { const ticketChanges = {
clientFk: args.clientFk, clientFk: args.clientFk,
currencyFk: args.currencyFk,
nickname: args.nickname, nickname: args.nickname,
agencyModeFk: args.agencyModeFk, agencyModeFk: args.agencyModeFk,
addressFk: args.addressFk, addressFk: args.addressFk,
@ -206,7 +214,7 @@ module.exports = Self => {
companyFk: args.companyFk, companyFk: args.companyFk,
shipped: args.shipped, shipped: args.shipped,
landed: args.landed, landed: args.landed,
isDeleted: args.isDeleted isDeleted: args.isDeleted,
}; };
let response; let response;
@ -216,7 +224,7 @@ module.exports = Self => {
} else { } else {
const hasToBeUnrouted = true; const hasToBeUnrouted = true;
response = await Self.rawSql( response = await Self.rawSql(
'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', 'CALL vn.ticket_componentMakeUpdate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[args.id].concat(Object.values(ticketChanges), [hasToBeUnrouted, args.option]), [args.id].concat(Object.values(ticketChanges), [hasToBeUnrouted, args.option]),
myOptions myOptions
); );

View File

@ -46,6 +46,11 @@ module.exports = Self => {
arg: 'routeId', arg: 'routeId',
type: 'number', type: 'number',
description: `The route id filter` description: `The route id filter`
},
{
arg: 'currencyId',
type: 'number',
description: `The currency id filter`
}], }],
returns: { returns: {
type: 'object', type: 'object',
@ -106,19 +111,20 @@ module.exports = Self => {
args.landed = landedResult && landedResult.landed; args.landed = landedResult && landedResult.landed;
} }
query = `CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result); query = `CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
SELECT @result newTicketId;`; SELECT @result newTicketId;`;
const result = await Self.rawSql(query, [ const result = await Self.rawSql(query, [
args.clientId, args.clientId,
args.shipped, args.shipped,
args.warehouseId, args.warehouseId,
args.companyId || 442, args.companyId || null,
args.addressId, args.addressId,
args.agencyModeId || null, args.agencyModeId || null,
args.routeId || null, args.routeId || null,
args.landed, args.landed,
userId,
true, true,
userId args.currencyId || null
], myOptions); ], myOptions);
const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions); const ticket = await models.Ticket.findById(result[1][0].newTicketId, null, myOptions);

View File

@ -46,6 +46,11 @@ module.exports = Self => {
type: 'date', type: 'date',
description: 'shipped', description: 'shipped',
required: true required: true
},
{
arg: 'currencyId',
type: 'number',
description: 'The currency ticket'
}], }],
returns: { returns: {
type: ['object'], type: ['object'],
@ -91,7 +96,7 @@ module.exports = Self => {
} }
} }
const items = await models.Sale.find({ const sales = await models.Sale.find({
where: { where: {
ticketFk: args.id ticketFk: args.id
}, },
@ -99,19 +104,22 @@ module.exports = Self => {
include: 'item' include: 'item'
}, myOptions); }, myOptions);
const salesObj = { const salesTotals = {
items: items, sales,
totalUnitPrice: 0.00, totalUnitPrice: 0.00,
totalNewPrice: 0.00, totalNewPrice: 0.00,
totalDifference: 0.00, totalDifference: 0.00,
totalForeignUnitPrice: 0.00,
totalForeignNewPrice: 0.00,
totalForeignDifference: 0.00,
}; };
// Get items movable // Get items movable
const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions); const ticketOrigin = await models.Ticket.findById(args.id, null, myOptions);
const differenceShipped = ticketOrigin.shipped.getTime() > args.shipped.getTime(); const differenceShipped = !ticketOrigin.shipped || ticketOrigin.shipped?.getTime() > args.shipped.getTime();
const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId; const differenceWarehouse = ticketOrigin.warehouseFk != args.warehouseId;
salesObj.haveDifferences = differenceShipped || differenceWarehouse; salesTotals.haveDifferences = differenceShipped || differenceWarehouse;
let query = `CALL ticket_getMovable(?,?,?)`; let query = `CALL ticket_getMovable(?,?,?)`;
let params = [args.id, args.shipped, args.warehouseId]; let params = [args.id, args.shipped, args.warehouseId];
@ -124,34 +132,35 @@ module.exports = Self => {
} }
// Sale price component, one per sale // Sale price component, one per sale
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`; query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?, ?)`;
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId]; params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId, args.currencyId];
const [difComponents] = await Self.rawSql(query, params, myOptions); const [difComponents] = await Self.rawSql(query, params, myOptions);
const map = new Map(); const map = new Map();
for (let difComponent of difComponents) for (let difComponent of difComponents)
map.set(difComponent.saleFk, difComponent); map.set(difComponent.saleFk, difComponent);
for (sale of salesObj.items) { for (let sale of salesTotals.sales) {
const difComponent = map.get(sale.id); const difComponent = map.get(sale.id);
if (difComponent) { if (difComponent) {
sale.component = difComponent; sale.component = difComponent;
salesObj.totalDifference += difComponent.difference; salesTotals.totalNewPrice += round(difComponent.newPrice * difComponent.quantity);
salesObj.totalDifference = round(salesObj.totalDifference); salesTotals.totalForeignNewPrice += round(difComponent.newForeignPrice * difComponent.quantity);
salesObj.totalNewPrice += difComponent.newPrice; salesTotals.totalUnitPrice += round(sale.price * difComponent.quantity);
salesObj.totalNewPrice = round(salesObj.totalNewPrice); salesTotals.totalForeignUnitPrice += round(difComponent.foreignPrice * difComponent.quantity);
salesTotals.totalDifference += round(difComponent.difference);
salesTotals.totalForeignDifference += round(difComponent.foreignDifference);
} }
salesObj.totalUnitPrice += sale.price;
salesObj.totalUnitPrice = round(salesObj.totalUnitPrice);
sale.movable = itemMovable.get(sale.id); sale.movable = itemMovable.get(sale.id);
} }
if (tx) await tx.commit(); if (tx) await tx.commit();
return salesObj; return salesTotals;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;

View File

@ -19,6 +19,7 @@ describe('ticket new()', () => {
landed: null, landed: null,
warehouseId: 1, warehouseId: 1,
companyId: 442, companyId: 442,
currencyFk: 1,
addressId: 6 addressId: 6
}; };
@ -47,6 +48,7 @@ describe('ticket new()', () => {
landed: null, landed: null,
warehouseId: 1, warehouseId: 1,
companyId: 442, companyId: 442,
currencyFk: 1,
addressId: 'invalid address' addressId: 'invalid address'
}; };
@ -73,6 +75,7 @@ describe('ticket new()', () => {
landed: today, landed: today,
warehouseId: 2, warehouseId: 2,
companyId: 442, companyId: 442,
currencyFk: 1,
addressId: 4, addressId: 4,
agencyModeId: 1 agencyModeId: 1
}; };
@ -102,6 +105,7 @@ describe('ticket new()', () => {
shipped: null, shipped: null,
warehouseId: 2, warehouseId: 2,
companyId: 442, companyId: 442,
currencyFk: 1,
addressId: 4, addressId: 4,
agencyModeId: null agencyModeId: null
}; };

View File

@ -72,10 +72,11 @@ module.exports = Self => {
if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return; if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return;
await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [ await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?,?)`, [
ticket.landed, ticket.landed,
ticket.addressFk, ticket.addressFk,
ticket.agencyModeFk, ticket.agencyModeFk,
ticket.currencyFk,
itemId itemId
], ],
ctx.options); ctx.options);

View File

@ -25,6 +25,9 @@
"price": { "price": {
"type": "number" "type": "number"
}, },
"foreignPrice": {
"type": "number"
},
"discount": { "discount": {
"type": "number" "type": "number"
}, },

View File

@ -64,12 +64,21 @@
"totalWithoutVat": { "totalWithoutVat": {
"type": "number" "type": "number"
}, },
"foreignTotalWithVat": {
"type": "number"
},
"foreignTotalWithoutVat": {
"type": "number"
},
"weight": { "weight": {
"type": "number" "type": "number"
}, },
"cmrFk": { "cmrFk": {
"type": "number" "type": "number"
}, },
"currencyFk": {
"type": "number"
},
"problem": { "problem": {
"type": "string" "type": "string"
} }
@ -156,6 +165,11 @@
"model": "Cmr", "model": "Cmr",
"foreignKey": "cmrFk" "foreignKey": "cmrFk"
}, },
"currency": {
"type": "belongsTo",
"model": "Currency",
"foreignKey": "currencyFk"
},
"ticketCollections": { "ticketCollections": {
"type": "hasMany", "type": "hasMany",
"model": "TicketCollection", "model": "TicketCollection",

View File

@ -1,5 +1,6 @@
{ {
"name": "Currency", "name": "Currency",
"description": "Currencies",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {