7984-addCurrency #3316

Open
carlosap wants to merge 8 commits from 7984-addCurrency into dev
82 changed files with 1178 additions and 720 deletions

View File

@ -127,15 +127,15 @@ module.exports = Self => {
async function getBarcodes(ticketId, options) {
const query =
`SELECT s.id movementId,
b.code,
`SELECT s.id movementId,
b.code,
c.id
FROM vn.sale s
LEFT JOIN vn.itemBarcode b ON b.itemFk = s.itemFk
LEFT JOIN vn.buy c ON c.itemFk = s.itemFk
LEFT JOIN vn.entry e ON e.id = c.entryFk
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
WHERE s.ticketFk = ?
WHERE s.ticketFk = ?
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
return Self.rawSql(query, [ticketId], options);
}

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)
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)
VALUES (1, 442);
@ -312,3 +313,4 @@ INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`)
FROM mysql.roles_mapping
WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost;
FLUSH PRIVILEGES;

View File

@ -613,13 +613,13 @@ INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`)
VALUES
(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
(69 , 'CCs', NULL, 30, 0, NULL, 1, NULL , NULL),
(442 , 'VNL', 241, 30, 1, NULL, 2, 'VNL Company - Plant passport' , 1101),
(567 , 'VNH', NULL, 30, 4, NULL, 1, 'VNH Company - Plant passport' , NULL),
(791 , 'FTH', NULL, 30, 3, '2015-11-30', 1, NULL , NULL),
(1381, 'ORN', NULL, 30, 7, NULL, 1, 'ORN Company - Plant passport' , NULL);
(69 , 'CCs', NULL, 30, 0, NULL, 1, NULL , NULL, 1),
(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, 1),
(791 , 'FTH', NULL, 30, 3, '2015-11-30', 1, NULL , NULL, 1),
(1381, 'ORN', NULL, 30, 7, NULL, 1, 'ORN Company - Plant passport' , NULL, 1);
INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`)
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()),
(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
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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),
(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);
(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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 1, util.VN_CURDATE(), NULL, NULL, NULL, NULL);
INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`)
VALUES
@ -2691,6 +2691,18 @@ UPDATE `vn`.`invoiceIn`
SET isBooked = TRUE
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 $$
CREATE PROCEDURE `tmp`.`ticket_recalc`()
BEGIN
@ -4045,14 +4057,15 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel)
INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate)
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)
VALUES (1,'https://router.project-osrm.org', 0.002);
INSERT IGNORE INTO vn.inventoryConfig
SET id = 1,
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;
SELECT total INTO vTotal FROM tmp.orderTotal;
SELECT IFNULL(foreignTotal, total) INTO vTotal FROM tmp.orderTotal;
DROP TEMPORARY TABLE
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
*/
DECLARE vCompany INT;
DECLARE vCurrencyFk INT;
SELECT defaultCompanyFk INTO vCompany
FROM orderConfig;
SELECT oc.defaultCompanyFk, c.currencyFk INTO vCompany, vCurrencyFk
FROM orderConfig oc
LEFT JOIN vn.company c ON c.id = oc.defaultCompanyFk
LIMIT 1;
INSERT INTO `order`
SET customer_id = account.myUser_getId(),
source_app = 'WEB',
company_id = vCompany;
company_id = vCompany,
currencyFk = vCurrencyFk;
SET vSelf = LAST_INSERT_ID();
CALL myOrder_configure(

View File

@ -1,10 +1,10 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getRows`(vSelf INT)
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.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7,
i.image, im.updated
i.image, im.updated
FROM myTicketRow r
JOIN vn.item i ON i.id = r.itemFk
LEFT JOIN image im

View File

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

View File

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

View File

@ -13,9 +13,10 @@ BEGIN
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
DECLARE vCurrencyFk INT;
SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
SELECT date_send, address_id, agency_id, currencyFk
INTO vDate, vAddress, vAgencyMode, vCurrencyFk
FROM `order`
WHERE id = vSelf;
@ -23,11 +24,11 @@ BEGIN
CREATE TEMPORARY TABLE tmp.item
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT itemFk FROM orderRow
SELECT itemFk FROM orderRow
WHERE orderFk = vSelf
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;
END$$

View File

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

View File

@ -16,13 +16,14 @@ BEGIN
DECLARE vDate DATE;
DECLARE vAddress INT;
DECLARE vAgencyMode INT;
DECLARE vCurrencyFk INT;
SELECT date_send, address_id, agency_id
INTO vDate, vAddress, vAgencyMode
SELECT date_send, address_id, agency_id, currencyFk
INTO vDate, vAddress, vAgencyMode, vCurrencyFk
FROM `order`
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
UPDATE tmp.ticketCalculateItem

View File

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

View File

@ -13,7 +13,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
CREATE TEMPORARY TABLE tmp.addressCompany
(INDEX (addressFk, companyFk))
ENGINE = MEMORY
ENGINE = MEMORY
SELECT DISTINCT o.address_id addressFk, o.company_id companyFk
FROM tmp.`order` tmpOrder
JOIN `order` o ON o.id = tmpOrder.orderFk;
@ -29,7 +29,8 @@ BEGIN
oro.amount * oro.price total,
s.countryFk,
ata.areaFk,
itc.taxClassFk
itc.taxClassFk,
o.currencyFk
FROM hedera.orderRow oro
JOIN tmp.order tor ON tor.orderFk = oro.orderFk
JOIN hedera.`order` o ON o.id = tor.orderFk
@ -45,7 +46,10 @@ BEGIN
SELECT o.orderFk,
tc.code,
SUM(o.total) taxableBase,
pgc.rate
pgc.rate,
vn.currency_getRate(o.currencyFk, NULL) *
SUM(o.total) foreignTaxableBase,
o.currencyFk
FROM orders o
JOIN vn.bookingPlanner bp ON bp.countryFk = o.countryFk
AND bp.taxAreaFk = o.areaFk
@ -55,17 +59,23 @@ BEGIN
GROUP BY o.orderFk, pgc.code, pgc.rate
HAVING taxableBase
ORDER BY bp.priority;
-- No poner create or replace, ya que da problemas
DROP TEMPORARY TABLE IF EXISTS tmp.orderAmount;
CREATE TEMPORARY TABLE tmp.orderAmount
(INDEX (orderFk))
ENGINE = MEMORY
SELECT orderFk, taxableBase, `code`,
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax
SELECT orderFk,
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
GROUP BY orderFk, `code`;
DROP TEMPORARY TABLE tmp.addressTaxArea;
END$$
DELIMITER ;

View File

@ -13,7 +13,9 @@ BEGIN
CREATE TEMPORARY TABLE tmp.orderTotal
(INDEX (orderFk))
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
LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk
GROUP BY orderFk;

View File

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

View File

@ -22,28 +22,27 @@ proc: BEGIN
SELECT COUNT(*) INTO vNRows
FROM orderRow WHERE orderFk = vSelf;
IF vNRows > 0
THEN
IF vNRows > 0 THEN
CALL order_calcCatalog(vSelf);
DELETE c
FROM orderRow r
JOIN orderRowComponent c ON c.rowFk = r.id
WHERE r.orderFk = vSelf;
WHERE r.orderFk = vSelf;
UPDATE orderRow r
LEFT JOIN tmp.ticketComponentPrice p
ON p.warehouseFk = r.warehouseFk
JOIN `order` o ON o.id = r.orderFk
LEFT JOIN tmp.ticketComponentPrice p ON p.warehouseFk = r.warehouseFk
AND p.itemFk = r.itemFk
AND p.rate = r.rate
LEFT JOIN tmp.zoneGetShipped t
ON t.warehouseFk = r.warehouseFk
SET
r.price = p.price,
LEFT JOIN tmp.zoneGetShipped t ON t.warehouseFk = r.warehouseFk
SET r.price = p.price,
r.foreignPrice = vn.currency_getRate(o.currencyFk, NULL) * p.price,
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
WHERE r.orderFk = vSelf;
WHERE o.id = vSelf;
INSERT INTO orderRowComponent(rowFk, componentFk, price)
SELECT r.id, c.componentFk, c.cost
@ -55,12 +54,11 @@ proc: BEGIN
ON t.id = c.componentFk
AND (t.classRate IS NULL OR t.classRate = r.rate)
WHERE r.orderFk = vSelf;
CALL vn.ticketCalculatePurge;
END IF;
UPDATE `order` SET date_make = util.VN_NOW()
WHERE id = vSelf;
UPDATE `order` SET date_make = util.VN_NOW() WHERE id = vSelf;
COMMIT;
END$$

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@ AS SELECT `t`.`id` AS `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`

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,
vAddressFk INT,
vAgencyModeFk INT,
vCurrencyFk INT,
vItemFk INT)
BEGIN
/**
@ -17,10 +18,10 @@ BEGIN
*/
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item
ENGINE = MEMORY
ENGINE = MEMORY
SELECT vItemFk itemFk;
CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, TRUE);
CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk, vCurrencyFk, TRUE);
DROP TEMPORARY TABLE tmp.item;
END$$
DELIMITER ;

View File

@ -3,17 +3,21 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_calculate`(
vLanded DATE,
vAddressFk INT,
vAgencyModeFk INT,
vShowExpiredZones BOOLEAN)
BEGIN
vCurrencyFk INT,
vShowExpiredZones BOOLEAN
)
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
* @param vLanded Fecha de recepcion de mercancia
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id de la agencia
* @return tmp.ticketCalculateItem(itemFk, available, producer,
* item, size, stems, category, inkFk, image, origin, price)
* @param vCurrencyFk Id de la moneda
* @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.ticketComponent
* @return tmp.ticketComponentPrice
@ -46,23 +50,25 @@ BEGIN
CALL catalog_componentPrepare();
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem(
itemFk INT(11) NOT NULL,
itemFk INT(11) NOT NULL,
available INT(11),
producer VARCHAR(50),
item VARCHAR(50),
size INT(10) UNSIGNED,
stems INT(11),
category VARCHAR(3),
inkFk VARCHAR(3),
producer VARCHAR(50),
item VARCHAR(50),
size INT(10) UNSIGNED,
stems INT(11),
category VARCHAR(3),
inkFk VARCHAR(3),
image VARCHAR(50),
origin VARCHAR(3),
origin VARCHAR(3),
price DECIMAL(10,2),
priceKg DECIMAL(10,2),
foreignPrice DECIMAL(10,2),
foreignPriceKg DECIMAL(10,2),
`grouping` INT(10) UNSIGNED,
minQuantity INT(10) UNSIGNED,
PRIMARY KEY `itemFk` (`itemFk`)
) ENGINE = MEMORY DEFAULT CHARSET=utf8;
OPEN cTravelTree;
l: LOOP
SET vDone = FALSE;
@ -83,20 +89,20 @@ BEGIN
bu.buyFk,
vZoneFk
FROM `cache`.available a
LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id
LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id
AND anr.calc_id = vAvailableNoRaidsCalc
JOIN tmp.item i ON i.itemFk = a.item_id
JOIN item it ON it.id = i.itemFk
JOIN `zone` z ON z.id = vZoneFk
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id
LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk
LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id
LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk
LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID
LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID
LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed
FROM addressFilter af
JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed
FROM address ad
JOIN province p ON p.id = ad.provinceFk
JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed
FROM address ad
JOIN province p ON p.id = ad.provinceFk
WHERE ad.id = vAddressFk
) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk)
AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk)
@ -113,13 +119,13 @@ BEGIN
JOIN itemType itt ON itt.id = it.typeFk
JOIN itemCategory itc on itc.id = itt.categoryFk
JOIN address ad ON ad.id = vAddressFk
LEFT JOIN clientItemType cit
LEFT JOIN clientItemType cit
ON cit.clientFk = ad.clientFk
AND cit.itemTypeFk = itt.id
LEFT JOIN zoneItemType zit
LEFT JOIN zoneItemType zit
ON zit.zoneFk = vZoneFk
AND zit.itemTypeFk = itt.id
LEFT JOIN agencyModeItemType ait
LEFT JOIN agencyModeItemType ait
ON ait.agencyModeFk = vAgencyModeFk
AND ait.itemTypeFk = itt.id
WHERE a.calc_id = vAvailableCalc
@ -136,7 +142,7 @@ BEGIN
DROP TEMPORARY TABLE tmp.buyUltimate;
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk, vCurrencyFk);
INSERT INTO tmp.ticketCalculateItem(
itemFk,
@ -151,6 +157,8 @@ BEGIN
origin,
price,
priceKg,
foreignPrice,
foreignPriceKg,
`grouping`,
minQuantity)
SELECT tl.itemFk,
@ -165,6 +173,8 @@ BEGIN
o.code origin,
bl.price,
bl.priceKg,
currency_getRate(vCurrencyFk, NULL) * bl.price,
currency_getRate(vCurrencyFk, NULL) * bl.priceKg,
bl.`grouping`,
mq.quantity
FROM tmp.ticketLot tl

View File

@ -3,7 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_componentCalc
vZoneFk INT,
vAddressFk INT,
vShipped DATE,
vWarehouseFk INT
vWarehouseFk INT,
vCurrencyFk INT
)
BEGIN
/**
@ -16,7 +17,7 @@ BEGIN
* @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
* @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 vVNHWarehouseFk INT DEFAULT 7;
@ -245,7 +246,8 @@ BEGIN
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;
-- Precio especial
@ -284,54 +286,66 @@ BEGIN
JOIN component c ON c.id = tc.componentFk
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,
tcc.itemFk,
1 rate,
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)) / weightGrouping priceKg
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg,
currency_getRate(vCurrencyFk, NULL) * SUM(tcs.sumCost) foreignPrice
FROM tmp.ticketComponentCalculate tcc
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 1) = 1
AND (tcc.groupingMode = 'grouping' OR tcc.groupingMode IS NULL)
AND (tcc.packing > tcc.`grouping` OR tcc.groupingMode IS NULL)
GROUP BY tcs.warehouseFk, tcs.itemFk;
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
GROUP BY tcs.warehouseFk, tcs.itemFk
UNION ALL
SELECT tcc.warehouseFk,
tcc.itemFk,
2 rate,
tcc.packing `grouping`,
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
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk
WHERE tcc.available IS NULL
OR (IFNULL(tcs.classRate, 2) = 2
AND tcc.packing > 0 AND tcc.available >= tcc.packing)
GROUP BY tcs.warehouseFk, tcs.itemFk;
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
GROUP BY tcs.warehouseFk, tcs.itemFk
UNION ALL
SELECT tcc.warehouseFk,
tcc.itemFk,
3 rate,
tcc.available `grouping`,
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
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
AND tcs.warehouseFk = tcc.warehouseFk
WHERE IFNULL(tcs.classRate, 3) = 3
GROUP BY tcs.warehouseFk, tcs.itemFk;
INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg)
SELECT * FROM (
SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000
) t
GROUP BY itemFk, warehouseFk, `grouping`;
INSERT INTO tmp.ticketComponentPrice(
warehouseFk,
itemFk,
rate,
`grouping`,
price,
priceKg,
foreignPrice
)SELECT * FROM (
SELECT *
FROM tmp.ticketComponentRate
ORDER BY price
LIMIT 10000000000000000000
) t
GROUP BY itemFk, warehouseFk, `grouping`;
DROP TEMPORARY TABLE
tmp.ticketComponentCalculate,

View File

@ -19,7 +19,9 @@ BEGIN
`rate` INT NOT NULL,
`grouping` INT UNSIGNED 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),
UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC)
)ENGINE=MEMORY DEFAULT CHARSET=utf8;

View File

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

View File

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

View File

@ -1,14 +1,14 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfConsumption`(
vShelvingCode VARCHAR(10) COLLATE utf8_general_ci,
vItemFk INT,
vShelvingCode VARCHAR(10) COLLATE utf8_general_ci,
vItemFk INT,
vQuantity INT
)
BEGIN
BEGIN
/**
* Leave the indicated amount on the shelve
* and create a ticket with the difference.
*
*
* @param vShelvingCode Code of the shelve where the item is located
* @param vItemFk Item of which the self-consumption ticket is to be created
* @param vQuantity Amount that will stay on the shelve
@ -18,6 +18,7 @@ BEGIN
DECLARE vTicketFk INT;
DECLARE vWarehouseFk INT;
DECLARE vCompanyFk INT;
DECLARE vCurrencyFk INT;
DECLARE vAgencyModeFk INT;
DECLARE vItemShelvingFk INT;
DECLARE vAddressFk INT;
@ -28,10 +29,12 @@ BEGIN
WHERE code = vShelvingCode;
SELECT c.id,
c.currencyFk,
pc.clientSelfConsumptionFk,
s.warehouseFk,
pc.addressSelfConsumptionFk
INTO vCompanyFk,
vCurrencyFk,
vClientFk,
vWarehouseFk,
vAddressFk
@ -61,10 +64,10 @@ BEGIN
END IF;
SELECT SUM(visible), id INTO vVisible, vItemShelvingFk
FROM itemShelving
FROM itemShelving
WHERE shelvingFk = vShelvingFk
AND itemFk = vItemFk;
IF vVisible IS NULL THEN
CALL util.throw('The item is not on the shelf.');
END IF;
@ -75,6 +78,7 @@ BEGIN
CURDATE(),
vAddressFk,
vCompanyFk,
vCurrencyFk,
NULL,
vTicketFk
);

View File

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

View File

@ -3,23 +3,25 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`orderCreate`(
vLanded DATE,
vAgencyMode INT,
vAddress INT,
vCompany INT,
vCurrency INT,
vSourceApp VARCHAR(10),
OUT vOrderId INT)
BEGIN
DECLARE vDeliveryMethod INT;
DECLARE vClient INT;
SELECT deliveryMethodFk INTO vDeliveryMethod
FROM vn.agencyMode
FROM vn.agencyMode
WHERE id = vAgencyMode;
SELECT clientFk INTO vClient
FROM vn.address
WHERE id = vAddress;
INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,source_app)
VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode ,vAddress ,vSourceApp);
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,vCompany,vCurrency,vSourceApp);
SET vOrderId = LAST_INSERT_ID();

View File

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

View File

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

View File

@ -1,43 +1,42 @@
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
DECLARE vNewSaleFk INT;
DECLARE vNewSaleFk INT;
INSERT INTO vn.sale(itemFk,
concept,
price,
discount,
quantity,
ticketFk,
isPriceFixed)
SELECT s.itemFk,
i.longName,
s.price,
s.discount,
vQuantity,
s.ticketFk,
s.isPriceFixed
INSERT INTO vn.sale(
itemFk,
concept,
price,
foreignPrice,
discount,
quantity,
ticketFk,
isPriceFixed
)SELECT s.itemFk,
i.longName,
s.price,
s.foreignPrice,
s.discount,
vQuantity,
s.ticketFk,
s.isPriceFixed
FROM vn.sale s
JOIN vn.item i ON i.id = s.itemFk
WHERE s.id = vSaleFk;
UPDATE vn.sale s
JOIN vn.item i ON i.id = s.itemFk
SET s.quantity = s.quantity - vQuantity, s.concept = i.longName
WHERE s.id = vSaleFk;
SELECT LAST_INSERT_ID() INTO vNewSaleFk;
INSERT INTO vn.saleComponent( saleFk,
componentFk,
value)
SELECT vNewSaleFk,
componentFk,
value
FROM vn.saleComponent
WHERE saleFk = vSaleFk;
UPDATE vn.sale s
JOIN vn.item i ON i.id = s.itemFk
SET s.quantity = s.quantity - vQuantity, s.concept = i.longName
WHERE s.id = vSaleFk;
SELECT LAST_INSERT_ID() INTO vNewSaleFk;
INSERT INTO vn.saleComponent(saleFk, componentFk, value)
SELECT vNewSaleFk, componentFk, value
FROM vn.saleComponent
WHERE saleFk = vSaleFk;
END$$
DELIMITER ;

View File

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

View File

@ -1,15 +1,24 @@
DELIMITER $$
$$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE vn.sale_boxPickingPrint(
IN vPrinterFk INT,
IN vSaleFk INT,
IN vPacking INT,
IN vSectorFk INT,
IN vUserFk INT,
IN vPackagingFk VARCHAR(10),
IN vPackingSiteFk INT)
vPrinterFk INT,
vSaleFk INT,
vPacking INT,
vSectorFk INT,
vUserFk INT,
vPackagingFk VARCHAR(10),
vPackingSiteFk INT
)
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 vConcept VARCHAR(30);
@ -30,25 +39,38 @@ BEGIN
DECLARE vShelvingFk VARCHAR(10);
DECLARE vTicketFk INT;
SELECT s.quantity,
s.quantity MOD vPacking,
s.ticketFk,
s.itemFk,
s.concept
SELECT quantity,
quantity MOD vPacking,
ticketFk,
itemFk,
concept
INTO vQuantity,
vRemainder,
vTicketFk,
vItemFk,
vConcept
FROM sale s
WHERE s.id = vSaleFk;
WHERE id = vSaleFk;
IF vRemainder THEN
UPDATE sale SET quantity = quantity - vRemainder WHERE id = vSaleFk;
INSERT INTO sale(ticketFk, itemFk, quantity, price, discount, concept)
SELECT ticketFk, itemFk, vRemainder, price, discount, concept
FROM sale
INSERT INTO sale(
ticketFk,
itemFk,
quantity,
price,
foreignPrice,
discount,
concept
)SELECT ticketFk,
itemFk,
vRemainder,
price,
foreignPrice,
discount,
concept
FROM sale
WHERE id = vSaleFk;
SET vRemainderSaleFk = LAST_INSERT_ID();
@ -62,7 +84,6 @@ BEGIN
w1: WHILE vQuantity >= vPacking DO
SET vQuantity = vQuantity - vPacking;
SET vItemShelvingFk = NULL;
SELECT sub.id
@ -114,25 +135,25 @@ w1: WHILE vQuantity >= vPacking DO
AND tt.clientFk = t.clientFk
AND t.shipped BETWEEN tt.shipped AND util.dayend(tt.shipped)
AND t.warehouseFk = tt.warehouseFk
WHERE tls.name = 'Encajado' ;
WHERE tls.name = 'Encajado';
IF ISNULL(vNewTicketFk) THEN
INSERT INTO ticket( clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk,
priority,
hasPriority,
clonedFrom)
SELECT clientFk,
shipped,
addressFk,
agencyModeFk,
nickname,
warehouseFk,
companyFk,
landed,
zoneFk,
zonePrice,
zoneBonus,
routeFk,
priority,
hasPriority,
clonedFrom
)SELECT clientFk,
shipped,
addressFk,
agencyModeFk,
@ -161,9 +182,9 @@ w1: WHILE vQuantity >= vPacking DO
UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk;
UPDATE itemShelving
SET visible = visible - vPacking,
available = available - vPacking
WHERE id = vItemShelvingFk;
SET visible = visible - vPacking,
available = available - vPacking
WHERE id = vItemShelvingFk;
SET vNewSaleFk = NULL;
@ -199,8 +220,21 @@ w1: WHILE vQuantity >= vPacking DO
WHERE id = vItemShelvingSaleFk;
END IF;
ELSE
INSERT INTO sale(ticketFk, itemFk, concept, quantity, discount, price)
SELECT vNewTicketFk, itemFk, concept, vPacking, discount, price
INSERT INTO sale(
ticketFk,
itemFk,
concept,
quantity,
discount,
price,
foreignPrice
)SELECT vNewTicketFk,
itemFk,
concept,
vPacking,
discount,
price,
foreignPrice
FROM sale
WHERE id = vSaleFk;
@ -227,19 +261,18 @@ w1: WHILE vQuantity >= vPacking DO
WHERE id = vNewTicketFk;
INSERT INTO expedition(
agencyModeFk,
ticketFk,
freightItemFk,
workerFk,
packagingFk,
itemPackingTypeFk,
hostFk,
packingSiteFk,
monitorId,
started,
ended
)
SELECT vAgencyModeFk,
agencyModeFk,
ticketFk,
freightItemFk,
workerFk,
packagingFk,
itemPackingTypeFk,
hostFk,
packingSiteFk,
monitorId,
started,
ended
)SELECT vAgencyModeFk,
vNewTicketFk,
pc.defaultFreightItemFk,
vUserFk,
@ -256,7 +289,6 @@ w1: WHILE vQuantity >= vPacking DO
WHERE ps.id = vPackingSiteFk;
SET vExpeditionFk = LAST_INSERT_ID();
SET vLastExpeditionTimeStamp = NOW();
CALL dipole.expedition_Add(vExpeditionFk,vPrinterFk, TRUE);
@ -282,8 +314,6 @@ w1: WHILE vQuantity >= vPacking DO
DELETE FROM sale
WHERE quantity = 0
AND id = vSaleFk;
END WHILE;
END$$
DELIMITER ;

View File

@ -2,20 +2,21 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25))
proc: BEGIN
/**
* Este procedimiento recalcula los componentes de un conjunto de sales,
* Este procedimiento recalcula los componentes de un conjunto de sales,
* eliminando los componentes existentes e insertandolos de nuevo
*
* @param vOption si no se quiere forzar llamar con NULL
* @table tmp.recalculateSales (id)
*/
DECLARE vShipped DATE;
*/
DECLARE vShipped DATE;
DECLARE vWarehouseFk SMALLINT;
DECLARE vAgencyModeFk INT;
DECLARE vAddressFk INT;
DECLARE vTicketFk INT;
DECLARE vLanded DATE;
DECLARE vLanded DATE;
DECLARE vIsEditable BOOLEAN;
DECLARE vZoneFk INTEGER;
DECLARE vCurrencyFk SMALLINT;
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vCur CURSOR FOR
@ -23,47 +24,49 @@ proc: BEGIN
FROM tmp.recalculateSales rs
JOIN vn.sale s ON s.id = rs.id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
OPEN vCur;
l: LOOP
SET vDone = FALSE;
FETCH vCur INTO vTicketFk;
FETCH vCur INTO vTicketFk;
IF vDone THEN
LEAVE l;
END IF;
SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL,
t.zoneFk,
t.warehouseFk,
t.shipped,
t.addressFk,
t.agencyModeFk,
t.landed
INTO vIsEditable,
vZoneFk,
vWarehouseFk,
vShipped,
vAddressFk,
vAgencyModeFk,
vLanded
SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL,
t.zoneFk,
t.warehouseFk,
t.shipped,
t.addressFk,
t.agencyModeFk,
t.landed,
t.currencyFk
INTO vIsEditable,
vZoneFk,
vWarehouseFk,
vShipped,
vAddressFk,
vAgencyModeFk,
vLanded,
vCurrencyFk
FROM ticket t
LEFT JOIN ticketState ts ON t.id = ts.ticketFk
LEFT JOIN alertLevel al ON al.id = ts.alertLevel
WHERE t.id = vTicketFk;
CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN
CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk));
END IF;
IF vLanded IS NULL OR vZoneFk IS NULL THEN
UPDATE ticket t
SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
WHERE t.id = vTicketFk AND t.landed IS NULL;
IF vZoneFk IS NULL THEN
@ -72,14 +75,14 @@ proc: BEGIN
SET t.zoneFk = vZoneFk
WHERE t.id = vTicketFk AND t.zoneFk IS NULL;
END IF;
END IF;
DROP TEMPORARY TABLE tmp.zoneGetLanded;
-- rellena la tabla buyUltimate con la ultima compra
CALL buy_getUltimate(NULL, vWarehouseFk, vShipped);
-- rellena la tabla buyUltimate con la ultima compra
CALL buy_getUltimate(NULL, vWarehouseFk, vShipped);
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
SELECT s.id saleFk, vWarehouseFk warehouseFk
@ -87,7 +90,7 @@ proc: BEGIN
JOIN tmp.recalculateSales rs ON s.id = rs.id
WHERE s.ticketFk = vTicketFk;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot
SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk
FROM sale s
JOIN tmp.recalculateSales rs ON s.id = rs.id
@ -96,7 +99,7 @@ proc: BEGIN
GROUP BY s.itemFk;
CALL catalog_componentPrepare();
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk, vCurrencyFk);
IF vOption IS NULL THEN
SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance');
@ -109,7 +112,7 @@ proc: BEGIN
DROP TEMPORARY TABLE tmp.sale;
END LOOP;
CLOSE vCur;
CLOSE vCur;
END$$
DELIMITER ;

View File

@ -2,11 +2,11 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_replaceItem`(vSaleFk INT, vNewItemFk INT, vQuantity INT)
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 vNewItemFk articulo sustituto
* @param vQuantity cantidad que se va a sustituir
* @param vSaleFk Id de la tabla sale
* @param vNewItemFk Artículo sustituto
* @param vQuantity Cantidad que se va a sustituir
*/
DECLARE vTicketFk INT;
DECLARE vItemFk INT;
@ -21,9 +21,13 @@ BEGIN
DECLARE vAgencyModeFk INT;
DECLARE vNewPrice DECIMAL(10,2);
DECLARE vOldPrice DECIMAL(10,2);
DECLARE vNewForeignPrice DECIMAL(10,2);
DECLARE vOldForeignPrice DECIMAL(10,2);
DECLARE vOption VARCHAR(255);
DECLARE vNewSaleFk INT;
DECLARE vFinalPrice DECIMAL(10,2);
DECLARE vFinalForeignPrice DECIMAL(10,2);
DECLARE vCurrencyFk INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
@ -39,7 +43,9 @@ BEGIN
t.landed,
t.addressFk,
t.agencyModeFk,
s.price
s.price,
s.foreignPrice,
t.currencyFk
INTO vTicketFk,
vQuantity,
vItemFk,
@ -48,7 +54,9 @@ BEGIN
vLanded,
vAddressFk,
vAgencyModeFk,
vOldPrice
vOldPrice,
vOldForeignPrice,
vCurrencyFk
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
WHERE s.id = vSaleFk;
@ -62,7 +70,7 @@ BEGIN
WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk;
DROP TEMPORARY TABLE tmp.buyUltimate;
IF vGroupingMode = 'packing' AND vPacking > 0 THEN
SET vRoundQuantity = vPacking;
END IF;
@ -74,9 +82,10 @@ BEGIN
vLanded,
vAddressFk,
vAgencyModeFk,
vCurrencyFk,
vNewItemFk);
SELECT price INTO vNewPrice
SELECT price, foreignPrice INTO vNewPrice, vNewForeignPrice
FROM tmp.ticketComponentPrice
ORDER BY (vQuantity % `grouping`) ASC
LIMIT 1;
@ -86,11 +95,13 @@ BEGIN
END IF;
IF vNewPrice > vOldPrice THEN
SET vFinalPrice = vOldPrice;
SET vOption = 'substitution';
SET vFinalPrice = vOldPrice,
vFinalForeignPrice = vOldForeignPrice,
vOption = 'substitution';
ELSE
SET vFinalPrice = vNewPrice;
SET vOption = 'renewPrices';
SET vFinalPrice = vNewPrice,
vFinalForeignPrice = vNewForeignPrice,
vOption = 'renewPrices';
END IF;
START TRANSACTION;
@ -104,12 +115,14 @@ BEGIN
itemFk,
quantity,
concept,
price)
price,
foreignPrice)
SELECT vTicketFk,
vNewItemFk,
CEIL(vQuantity / vRoundQuantity) * vRoundQuantity,
CONCAT('+ ', i.name),
vFinalPrice
vFinalPrice,
vFinalForeignPrice
FROM vn.item i
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,28 +1,30 @@
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
/**
* 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
**/
DECLARE vComponentFk INT;
IF vCode <> 'renewPrices' THEN
IF vCode <> 'renewPrices' THEN
SELECT id INTO vComponentFk FROM component WHERE `code` = vCode;
END IF;
DELETE sc.*
FROM tmp.sale tmps
DELETE sc
FROM tmp.sale tmps
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
JOIN `component` c ON c.id = sc.componentFk
WHERE c.isRenewable;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, tc.componentFk, tc.cost
FROM sale s
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
@ -40,7 +42,7 @@ BEGIN
JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id
JOIN vn.buy b ON b.id = buy_id
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage'
JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage'
LEFT JOIN (
SELECT s.id
FROM vn.sale s
@ -63,43 +65,46 @@ BEGIN
HAVING dif <> 0;
ELSE
UPDATE sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN item i on i.id = s.itemFk
JOIN itemType it on it.id = i.typeFk
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.price = sumValue / ((100 - s.discount) / 100)
WHERE it.code != 'PRT' ;
SET s.price = sumValue / ((100 - s.discount) / 100),
s.foreignPrice = currency_getRate(t.currencyFk, NULL) * (sumValue / ((100 - s.discount) / 100))
WHERE it.code <> 'PRT' ;
REPLACE INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue
FROM sale s
JOIN tmp.sale tmps ON tmps.saleFk = s.id
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
WHERE sc.componentFk != 21
WHERE sc.componentFk <> 21
GROUP BY s.id
HAVING ROUND(saleValue, 4) <> 0;
END IF;
UPDATE sale s
JOIN (
SELECT SUM(sc.value) sumValue, sc.saleFk
SELECT SUM(sc.value) sumValue, sc.saleFk
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN `component` c ON c.id = sc.componentFk
JOIN componentType ct on ct.id = c.typeFk AND ct.isBase
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
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN sale s on s.id = sc.saleFk
JOIN item i ON i.id = s.itemFk
JOIN itemType it ON it.id = i.typeFk
WHERE it.code = 'PRT';
INSERT INTO saleComponent(saleFk, componentFk, value)
SELECT s.id, 15, s.price
FROM sale s

View File

@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketGetTotal`(vTaxA
BEGIN
/**
* Calcula el total con IVA para un conjunto de tickets.
*
*
* @param vTaxArea
* @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
* @return tmp.ticketTotal Total para cada ticket
@ -15,12 +15,14 @@ BEGIN
(INDEX (ticketFk))
ENGINE = MEMORY
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
LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk
GROUP BY ticketFk;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax;
END$$

View File

@ -2,35 +2,33 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketGetVisibleAvailable`(
vTicket INT)
BEGIN
DECLARE vVisibleCalc INT;
DECLARE vAvailableCalc INT;
DECLARE vShipped DATE;
DECLARE vWarehouse TINYINT;
DECLARE vAlertLevel INT;
DECLARE vVisibleCalc INT;
DECLARE vAvailableCalc INT;
DECLARE vShipped DATE;
DECLARE vWarehouse TINYINT;
DECLARE vAlertLevel INT;
DECLARE vAlertLevelFree INT;
SELECT t.warehouseFk, t.shipped, ts.alertLevel, al.id
SELECT t.warehouseFk, t.shipped, ts.alertLevel, al.id
INTO vWarehouse, vShipped, vAlertLevel, vAlertLevelFree
FROM ticket t
FROM ticket t
JOIN alertLevel al ON al.code = 'FREE'
LEFT JOIN ticketState ts ON ts.ticketFk = vTicket
WHERE t.id = vTicket;
LEFT JOIN ticketState ts ON ts.ticketFk = vTicket
WHERE t.id = vTicket;
IF vAlertLevel IS NULL OR vAlertLevel = vAlertLevelFree THEN
IF vShipped >= util.VN_CURDATE() THEN
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
END IF;
IF vShipped = util.VN_CURDATE() THEN
CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse);
END IF;
END IF;
IF vAlertLevel IS NULL OR vAlertLevel = vAlertLevelFree THEN
IF vShipped >= util.VN_CURDATE() THEN
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
END IF;
IF vShipped = util.VN_CURDATE() THEN
CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse);
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
FROM sale s
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 item it ON it.id = s.itemFk
WHERE s.ticketFk = vTicket
ORDER BY s.concept;
SELECT s.itemFk, v.visible, av.available
FROM sale s
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
WHERE s.ticketFk = vTicket;
END$$
DELIMITER ;

View File

@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketPackaging_add`(
vClientFk INT,
vDated DATE,
vCompanyFk INT,
vCurrencyFk INT,
vWithoutPeriodGrace BOOLEAN)
BEGIN
/**
@ -12,6 +13,7 @@ BEGIN
* @param vClientFk Cliente en caso de NULL todos los clientes
* @param vDated Fecha hasta la cual se revisan los embalajes
* @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
*/
DECLARE vNewTicket INT;
@ -22,7 +24,7 @@ BEGIN
DECLARE vComponentCost INT;
DECLARE vDone INT DEFAULT FALSE;
DECLARE vClientId INT;
DECLARE vCursor CURSOR FOR
SELECT DISTINCT clientFk
FROM (
@ -42,31 +44,31 @@ BEGIN
RESIGNAL;
END;
SELECT id INTO vWarehouseInventory
FROM warehouse
SELECT id INTO vWarehouseInventory
FROM warehouse
WHERE `code`= 'inv';
SELECT id INTO vComponentCost
FROM component
SELECT id INTO vComponentCost
FROM component
WHERE `code`= 'purchaseValue';
SELECT packagingInvoicingDated INTO vDateStart
FROM ticketConfig;
SELECT packagingInvoicingDated INTO vDateStart
FROM ticketConfig;
IF vWarehouseInventory IS NULL THEN
CALL util.throw('Warehouse inventory not set');
END IF;
IF vComponentCost IS NULL THEN
CALL util.throw('Component cost not set');
END IF;
END IF;
SET vDateEnd = vDated + INTERVAL 1 DAY;
IF NOT vWithoutPeriodGrace THEN
SET vGraceDate = vGraceDate -INTERVAL 1 MONTH;
END IF;
DROP TEMPORARY TABLE IF EXISTS tmp.packagingToInvoice;
CREATE TEMPORARY TABLE tmp.packagingToInvoice
(INDEX (clientFk))
@ -79,7 +81,7 @@ BEGIN
t.clientFk
FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk
JOIN ticket t ON t.id = tp.ticketFk
JOIN ticket t ON t.id = tp.ticketFk
JOIN client c ON c.id = t.clientFk
WHERE c.isActive
AND (vClientFk IS NULL OR t.clientFk = vClientFk)
@ -87,7 +89,7 @@ BEGIN
AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate))
AND tp.quantity
AND p.itemFk;
OPEN vCursor;
l: LOOP
@ -100,25 +102,26 @@ BEGIN
START TRANSACTION;
CALL ticket_add(
vClientId,
vClientId,
vDateEnd,
vWarehouseInventory,
vCompanyFk,
NULL,
NULL,
NULL,
vDateEnd,
account.myUser_getId(),
vWarehouseInventory,
vCompanyFk,
NULL,
NULL,
NULL,
vDateEnd,
account.myUser_getId(),
TRUE,
vCurrencyFk,
vNewTicket);
INSERT INTO ticketPackaging(ticketFk, packagingFk, quantity, pvp)
SELECT vNewTicket, packagingFk, - SUM(quantity) totalQuantity, price
FROM tmp.packagingToInvoice
FROM tmp.packagingToInvoice
WHERE clientFk = vClientId
GROUP BY packagingFk
HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity < 0);
INSERT INTO sale(ticketFk, itemFk, concept, quantity, price)
SELECT vNewTicket, pti.itemFk, i.name, SUM(pti.quantity) totalQuantity, pti.price
FROM tmp.packagingToInvoice pti
@ -126,12 +129,12 @@ BEGIN
WHERE pti.clientFk = vClientId
GROUP BY pti.itemFk
HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity > 0);
INSERT INTO saleComponent(saleFk, componentFk, value)
SELECT id, vComponentCost, price
FROM sale
WHERE ticketFk = vNewTicket;
COMMIT;
END LOOP;
CLOSE vCursor;

View File

@ -1,5 +1,8 @@
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
/**
* Clona el contenido de un ticket en otro
@ -29,10 +32,9 @@ BEGIN
routeFk,
priority,
hasPriority,
clonedFrom
)
SELECT
clientFk,
clonedFrom,
currencyFk
)SELECT clientFk,
shipped,
addressFk,
agencyModeFk,
@ -46,7 +48,8 @@ BEGIN
routeFk,
priority,
hasPriority,
vOriginalTicket
vOriginalTicket,
currencyFk
FROM ticket
WHERE id = vOriginalTicket;

View File

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

View File

@ -1,19 +1,20 @@
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
INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed)
SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed
FROM vn.ticket t
INSERT INTO ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed, currencyFk)
SELECT t.clientFk, t.addressFk, t.shipped, w.id, t.companyFk, t.landed, t.currencyFk
FROM ticket t
JOIN vn.warehouse w ON w.name = 'INVENTARIO'
WHERE t.id = vOriginalTicket;
SELECT LAST_INSERT_ID() INTO vNewTicket;
INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount)
SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount
FROM vn.sale s
WHERE s.ticketFk = vOriginalTicket;
INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount, foreignPrice)
SELECT vNewTicket, itemFk , concept, quantity, price, discount, foreignPrice
FROM sale
WHERE ticketFk = vOriginalTicket;
END$$
DELIMITER ;

View File

@ -1,55 +1,76 @@
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
DECLARE vDone BOOLEAN DEFAULT FALSE;
DECLARE vOldSaleFk INT;
DECLARE vNewSaleFk INT;
DECLARE cur1 CURSOR FOR
SELECT id
FROM sale
WHERE ticketFk = vTicketFk;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE());
CALL ticket_Clone(vTicketFk, vNewTicketFk);
UPDATE ticket
UPDATE ticket
SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed),
shipped = vNewShipped,
warehouseFk = IF(vWithWarehouse, warehouseFk, NULL)
WHERE id = vNewTicketFk;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO vOldSaleFk;
IF vDone THEN
LEAVE read_loop;
END IF;
INSERT INTO sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed)
SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed
INSERT INTO sale(
ticketFk,
itemFk,
quantity,
concept,
price,
foreignPrice,
discount,
priceFixed,
isPriceFixed
)SELECT vNewTicketFk,
itemFk,
quantity,
concept,
price,
foreignPrice,
discount,
priceFixed,
isPriceFixed
FROM sale
WHERE id = vOldSaleFk;
SELECT max(id) INTO vNewSaleFk
SELECT MAX(id) INTO vNewSaleFk
FROM sale
WHERE ticketFk = vNewTicketFk;
INSERT INTO saleComponent(saleFk, componentFk, value, isGreuge)
SELECT vNewSaleFk, componentFk, value, isGreuge
FROM saleComponent
WHERE saleFk = vOldSaleFk;
END LOOP;
CLOSE cur1;
END$$
DELIMITER ;

View File

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

View File

@ -18,6 +18,7 @@ BEGIN
DECLARE vWithPackage BOOL;
DECLARE vHasToInvoice BOOL;
DECLARE vSerial VARCHAR(2);
DECLARE vCurrencyFk INT;
DECLARE cur CURSOR FOR
SELECT ticketFk FROM tmp.ticket_close;
@ -45,14 +46,16 @@ BEGIN
t.shipped,
c.hasDailyInvoice,
w.isManaged,
c.hasToInvoice
c.hasToInvoice,
t.currencyFk
INTO vClientFk,
vIsTaxDataChecked,
vCompanyFk,
vShipped,
vHasDailyInvoice,
vWithPackage,
vHasToInvoice
vHasToInvoice,
vCurrencyFk
FROM ticket t
JOIN `client` c ON c.id = t.clientFk
JOIN warehouse w ON w.id = t.warehouseFk
@ -71,14 +74,29 @@ BEGIN
GROUP BY p.itemFk);
-- 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
JOIN item i ON i.id = e.freightItemFk
LEFT JOIN packaging p ON p.itemFk = i.id
WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
AND getSpecialPrice(e.freightItemFk, vClientFk) > 0
GROUP BY e.freightItemFk);
GROUP BY e.freightItemFk;
IF(vHasDailyInvoice) AND vHasToInvoice THEN
SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial;

View File

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

View File

@ -1,10 +1,12 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_componentPreview`(
vTicketFk INT,
vLanded DATE,
vLanded DATE,
vAddressFk INT,
vZoneFk INT,
vWarehouseFk SMALLINT)
vWarehouseFk SMALLINT,
vCurrencyFk SMALLINT
)
BEGIN
/**
* Calcula los componentes de los articulos de un ticket
@ -17,26 +19,27 @@ BEGIN
*
* @return tmp.ticketComponentPreview (warehouseFk, itemFk, componentFk, cost)
*/
DECLARE vHasDataChanged BOOL DEFAULT FALSE;
DECLARE vHasDataChanged BOOL DEFAULT FALSE;
DECLARE vHasAddressChanged BOOL;
DECLARE vHasZoneChanged BOOL DEFAULT FALSE;
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
DECLARE vShipped DATE;
DECLARE vAddressTypeRateFk INT DEFAULT NULL;
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
DECLARE vHasChangeAll BOOL DEFAULT FALSE;
SELECT DATE(landed) <> vLanded,
addressFk <> vAddressFk,
SELECT DATE(landed) <> vLanded,
addressFk <> vAddressFk,
zoneFk <> vZoneFk,
warehouseFk <> vWarehouseFk
warehouseFk <> vWarehouseFk,
IFNULL(vCurrencyFk, currencyFk)
INTO
vHasDataChanged,
vHasAddressChanged,
vHasZoneChanged,
vHasWarehouseChanged
vHasWarehouseChanged,
vCurrencyFk
FROM vn.ticket t
WHERE t.id = vTicketFk;
@ -52,14 +55,14 @@ BEGIN
SET vAgencyModeTypeRateFk = 6;
END IF;
SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped
SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped
FROM zone
WHERE id = vZoneFk;
CALL buy_getUltimate(NULL, vWarehouseFk, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
SELECT vWarehouseFk warehouseFk,
NULL available,
s.itemFk,
@ -71,7 +74,7 @@ BEGIN
GROUP BY bu.warehouseFk, bu.itemFk);
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)
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value
@ -79,9 +82,9 @@ BEGIN
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN `component` c ON c.id = sc.componentFk
WHERE s.ticketFk = vTicketFk
AND (c.isRenewable = FALSE
OR
WHERE s.ticketFk = vTicketFk
AND (c.isRenewable = FALSE
OR
(NOT vHasChangeAll
AND (NOT (c.typeFk <=> vAddressTypeRateFk
OR c.typeFk <=> vAgencyModeTypeRateFk))));

View File

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

View File

@ -22,7 +22,7 @@ BEGIN
JOIN ticket t ON t.id = tmpTicket.ticketFk;
CALL addressTaxArea();
IF vTaxArea IS NOT NULL THEN
UPDATE tmp.addressTaxArea
SET areaFk = vTaxArea;
@ -39,6 +39,7 @@ BEGIN
SELECT s.ticketFk,
s.itemFk,
s.quantity * s.price * (100 - s.discount) / 100 total,
s.quantity * s.foreignPrice * (100 - s.discount) / 100 foreignTotal,
t.companyFk,
t.addressFk,
su.countryFk,
@ -57,6 +58,7 @@ BEGIN
SELECT s.ticketFk,
bp.pgcFk,
SUM(s.total) taxableBase,
SUM(s.foreignTotal) foreignTaxableBase,
pgc.rate,
tc.code,
bp.priority
@ -76,6 +78,7 @@ BEGIN
SELECT tt.ticketFk,
pgc.code pgcFk,
SUM(ts.quantity * ts.price) taxableBase,
SUM(ts.quantity * ts.foreignPrice) foreignTaxableBase,
pgc.rate,
tc.code
FROM tmp.ticket tt
@ -92,17 +95,21 @@ BEGIN
GROUP BY tt.ticketFk, pgc.code
HAVING taxableBase;
INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code)
SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.rate, ts.code
INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, foreignTaxableBase, rate, code)
SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.foreignTaxableBase, ts.rate, ts.code
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
(INDEX (ticketFk))
ENGINE = MEMORY
SELECT ticketFk,
taxableBase,
SELECT ticketFk,
taxableBase,
foreignTaxableBase,
SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,
SUM(CAST(foreignTaxableBase * rate / 100 AS DECIMAL(10, 2))) foreignTax,
code
FROM tmp.ticketTax
GROUP BY ticketFk, code;

View File

@ -1,10 +1,11 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getWithParameters`(
vClientFk INT,
vClientFk INT,
vWarehouseFk INT,
vShipped DATE,
vAddressFk INT,
vCompanyFk INT,
vShipped DATE,
vAddressFk INT,
vCompanyFk INT,
vCurrencyFk INT,
vAgencyModeFk INT,
OUT vTicketFk INT
)
@ -17,9 +18,10 @@ BEGIN
* @param vShipped Fecha de preparacion
* @param vAddressFk Consignatario
* @param vCompanyFk Empresa
* @param vCurrencyFk Id de moneda
* @param vAgencyModeFk agencia
*/
*/
SELECT t.id INTO vTicketFk
FROM vn.ticket t
WHERE t.clientFk <=> vClientFk
@ -29,9 +31,9 @@ BEGIN
AND (t.companyFk <=> vCompanyFk OR vCompanyFk IS NULL)
AND (t.agencyModeFk <=> vAgencyModeFk OR vAgencyModeFk IS NULL)
LIMIT 1;
IF vTicketFk IS NULL THEN
CALL vn.ticket_add(
CALL vn.pticket_add(
vClientFk,
IFNULL(vShipped, util.VN_CURDATE()),
vWarehouseFk,
@ -42,6 +44,7 @@ BEGIN
vShipped,
`account`.`myUser_getId`(),
TRUE,
vCurrencyFk,
vTicketFk
);
END IF;

View File

@ -1,43 +1,52 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_priceDifference`(
vTicketFk INT,
vLanded DATE,
vLanded DATE,
vAddressFk INT,
vZoneFk INT,
vWarehouseFk INT)
vWarehouseFk INT,
vCurrencyFk SMALLINT
)
BEGIN
/**
* Devuelve las diferencias de precio de los movimientos de un ticket.
*
*
* @param vTicketFk Id del ticket
* @param vLanded Fecha de recepcion
* @param vAddressFk Id del consignatario
* @param vZoneFk Id de la zona
* @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);
SELECT s.itemFk,
i.name,
i.size,
i.category,
IFNULL(s.quantity, 0) AS quantity,
IFNULL(s.price, 0) AS price,
ROUND(SUM(tc.cost), 2) AS newPrice,
s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference,
s.id AS saleFk
FROM sale s
JOIN item i ON i.id = s.itemFk
JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
AND tc.warehouseFk = vWarehouseFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk
LEFT JOIN `component` c ON c.id = tc.componentFk
WHERE t.id = vTicketFk
AND IF(sc.componentFk IS NULL
AND c.classRate IS NOT NULL, FALSE, TRUE)
GROUP BY s.id ORDER BY s.id;
WITH ticketPriceDifference AS (
SELECT s.itemFk,
i.name,
i.size,
i.category,
IFNULL(s.quantity, 0) quantity,
IFNULL(s.price, 0) price,
ROUND(SUM(tc.cost), 2) newPrice,
s.id saleFk
FROM vn.sale s
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk
AND tc.warehouseFk = vWarehouseFk
LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
AND sc.componentFk = tc.componentFk
LEFT JOIN vn.`component` c ON c.id = tc.componentFk
WHERE t.id = vTicketFk
AND IF(sc.componentFk IS NULL
AND c.classRate IS NOT NULL, FALSE, TRUE)
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;
END$$

View File

@ -9,12 +9,12 @@ proc:BEGIN
*/
DECLARE hasInvoice BOOL;
SELECT COUNT(*) INTO hasInvoice
FROM ticket
SELECT COUNT(*) INTO hasInvoice
FROM ticket
WHERE id = vSelf
AND refFk IS NOT NULL;
IF hasInvoice THEN
IF hasInvoice THEN
LEAVE proc;
END IF;
@ -27,8 +27,10 @@ proc:BEGIN
UPDATE ticket t
JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id
SET t.totalWithVat = tt.total,
t.totalWithoutVat = tt.totalWithoutVat;
SET t.totalWithoutVat = tt.totalWithoutVat,
t.foreignTotalWithoutVat = tt.foreignTotalWithoutVat,
t.totalWithVat = tt.total,
t.foreignTotalWithVat = tt.foreignTotal;
DROP TEMPORARY TABLE
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

@ -211,7 +211,7 @@
"Name should be uppercase": "Name should be uppercase",
"You cannot update these fields": "You cannot update these fields",
"CountryFK cannot be empty": "Country cannot be empty",
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
"You already have the mailAlias": "You already have the mailAlias",
"This machine is already in use.": "This machine is already in use.",
@ -250,6 +250,5 @@
"Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available",
"Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced",
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
"There are tickets to be invoiced": "There are tickets to be invoiced"
}

View File

@ -398,5 +398,5 @@
"Holidays to past days not available": "Las vacaciones a días pasados no están disponibles",
"All tickets have a route order": "Todos los tickets tienen orden de ruta",
"Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "La zona tiene tickets por facturar"
"There are tickets to be invoiced": "La zona tiene tickets por facturar"
}

View File

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

View File

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

View File

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

View File

@ -92,11 +92,12 @@ module.exports = Self => {
// Calculate items
const order = await Self.findById(orderFk, null, myOptions);
stmts.push(new ParameterizedSQL(
'CALL vn.catalog_calculate(?, ?, ?, ?)', [
'CALL vn.catalog_calculate(?, ?, ?, ?, ?)', [
order.landed,
order.address_id,
order.agency_id,
false
order.currencyFk,
false,
]
));
@ -119,7 +120,9 @@ module.exports = Self => {
w.firstName,
tci.priceKg,
ink.hex,
tci.minQuantity
tci.minQuantity,
tci.foreignPrice,
tci.foreignPriceKg
FROM tmp.ticketCalculateItem tci
JOIN vn.item i ON i.id = tci.itemFk
JOIN vn.itemType it ON it.id = i.typeFk
@ -161,9 +164,11 @@ module.exports = Self => {
`SELECT tcp.itemFk,
tcp.grouping,
tcp.price,
tcp.foreignPrice,
tcp.rate,
tcp.warehouseFk,
tcp.priceKg,
tcp.foreignPriceKg,
w.name warehouse
FROM tmp.ticketComponentPrice tcp
JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1;

View File

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

View File

@ -10,7 +10,7 @@ module.exports = Self => {
http: {source: 'path'}
}],
returns: {
type: 'number',
type: 'object',
root: true
},
http: {
@ -25,9 +25,22 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const query = `SELECT hedera.order_getTotal(?) total;`;
const [total] = await Self.rawSql(query, [orderFk], myOptions);
const query = `
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'}
}],
returns: {
type: 'number',
type: 'object',
root: true
},
http: {
@ -25,12 +25,19 @@ module.exports = Self => {
if (typeof options == 'object')
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);
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',
type: 'number',
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: {
@ -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};
let tx;
@ -59,11 +69,13 @@ module.exports = Self => {
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, [
landed,
agencyModeId,
addressId,
companyId,
currencyId,
'SALIX'
], myOptions);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,6 +46,11 @@ module.exports = Self => {
arg: 'routeId',
type: 'number',
description: `The route id filter`
},
{
arg: 'currencyId',
type: 'number',
description: `The currency id filter`
}],
returns: {
type: 'object',
@ -106,19 +111,20 @@ module.exports = Self => {
args.landed = landedResult && landedResult.landed;
}
query = `CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
query = `CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result);
SELECT @result newTicketId;`;
const result = await Self.rawSql(query, [
args.clientId,
args.shipped,
args.warehouseId,
args.companyId || 442,
args.companyId || null,
args.addressId,
args.agencyModeId || null,
args.routeId || null,
args.landed,
userId,
true,
userId
args.currencyId || 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',
description: 'shipped',
required: true
},
{
arg: 'currencyId',
type: 'number',
description: 'The currency ticket'
}],
returns: {
type: ['object'],
@ -91,7 +96,7 @@ module.exports = Self => {
}
}
const items = await models.Sale.find({
const sales = await models.Sale.find({
where: {
ticketFk: args.id
},
@ -99,19 +104,22 @@ module.exports = Self => {
include: 'item'
}, myOptions);
const salesObj = {
items: items,
const salesTotals = {
sales,
totalUnitPrice: 0.00,
totalNewPrice: 0.00,
totalDifference: 0.00,
totalForeignUnitPrice: 0.00,
totalForeignNewPrice: 0.00,
totalForeignDifference: 0.00,
};
// Get items movable
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;
salesObj.haveDifferences = differenceShipped || differenceWarehouse;
salesTotals.haveDifferences = differenceShipped || differenceWarehouse;
let query = `CALL ticket_getMovable(?,?,?)`;
let params = [args.id, args.shipped, args.warehouseId];
@ -124,34 +132,35 @@ module.exports = Self => {
}
// Sale price component, one per sale
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?)`;
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId];
query = `CALL vn.ticket_priceDifference(?, ?, ?, ?, ?, ?)`;
params = [args.id, args.landed, args.addressId, args.zoneId, args.warehouseId, args.currencyId];
const [difComponents] = await Self.rawSql(query, params, myOptions);
const map = new Map();
for (let difComponent of difComponents)
map.set(difComponent.saleFk, difComponent);
for (sale of salesObj.items) {
for (let sale of salesTotals.sales) {
const difComponent = map.get(sale.id);
if (difComponent) {
sale.component = difComponent;
salesObj.totalDifference += difComponent.difference;
salesObj.totalDifference = round(salesObj.totalDifference);
salesTotals.totalNewPrice += round(difComponent.newPrice * difComponent.quantity);
salesTotals.totalForeignNewPrice += round(difComponent.newForeignPrice * difComponent.quantity);
salesObj.totalNewPrice += difComponent.newPrice;
salesObj.totalNewPrice = round(salesObj.totalNewPrice);
salesTotals.totalUnitPrice += round(sale.price * difComponent.quantity);
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);
}
if (tx) await tx.commit();
return salesObj;
return salesTotals;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

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

View File

@ -72,10 +72,11 @@ module.exports = Self => {
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.addressFk,
ticket.agencyModeFk,
ticket.currencyFk,
itemId
],
ctx.options);

View File

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

View File

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

View File

@ -1,9 +1,10 @@
{
"name": "Currency",
"description": "Currencies",
"base": "VnModel",
"options": {
"mysql": {
"table": "currency"
"table": "currency"
}
},
"properties": {