Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6556-ChangeImages

This commit is contained in:
Jon Elias 2024-03-22 08:22:49 +01:00
commit eadd8f750d
41 changed files with 726 additions and 728 deletions

View File

@ -49,6 +49,7 @@ describe('MRWConfig createShipment()', () => {
await models.MrwConfig.create( await models.MrwConfig.create(
{ {
'id': 1,
'url': 'https://url.com', 'url': 'https://url.com',
'user': 'user', 'user': 'user',
'password': 'password', 'password': 'password',

View File

@ -9,6 +9,7 @@
"properties": { "properties": {
"id": { "id": {
"type": "number", "type": "number",
"id": true,
"required": true "required": true
}, },
"url": { "url": {

View File

@ -7,8 +7,8 @@ SET foreign_key_checks = 0;
-- XXX: vn-database -- XXX: vn-database
INSERT INTO util.config (environment, mockTime, mockUtcTime, mockEnabled) INSERT INTO util.config (id, environment, mockTime, mockUtcTime, mockEnabled)
VALUES ('local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); VALUES (1, 'local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE);
/* #5483 /* #5483
INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk) INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk)
VALUES(1, NULL, 1, 300, 1); VALUES(1, NULL, 1, 300, 1);

View File

@ -60,13 +60,13 @@ INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`)
VALUES VALUES
('1', '6'); ('1', '6');
INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVolumetricWeight`, `verdnaturaVolumeBox`, `itemCarryBox`) INSERT INTO `vn`.`bionicConfig` (`id`, `generalInflationCoeficient`, `minimumDensityVolumetricWeight`, `verdnaturaVolumeBox`, `itemCarryBox`)
VALUES VALUES
(1.30, 167.00, 138000, 71); (1, 1.30, 167.00, 138000, 71);
INSERT INTO `vn`.`chatConfig` (`host`, `api`) INSERT INTO `vn`.`chatConfig` (`id`, `host`, `api`)
VALUES VALUES
('https://chat.verdnatura.es', 'https://chat.verdnatura.es/api/v1'); (1, 'https://chat.verdnatura.es', 'https://chat.verdnatura.es/api/v1');
INSERT IGNORE INTO `vn`.`greugeConfig`(`id`, `freightPickUpPrice`) INSERT IGNORE INTO `vn`.`greugeConfig`(`id`, `freightPickUpPrice`)
VALUES VALUES
@ -608,7 +608,8 @@ INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`
('WORLD', 2, 15); ('WORLD', 2, 15);
INSERT INTO vn.invoiceOutConfig INSERT INTO vn.invoiceOutConfig
SET parallelism = 8; SET id = 1,
parallelism = 8;
INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`)
VALUES VALUES
@ -714,7 +715,7 @@ INSERT INTO `vn`.`zoneClosure` (`zoneFk`, `dated`, `hour`)
(12, util.VN_CURDATE(), '23:59'), (12, util.VN_CURDATE(), '23:59'),
(13, util.VN_CURDATE(), '23:59'); (13, util.VN_CURDATE(), '23:59');
INSERT INTO `vn`.`zoneConfig` (`scope`) VALUES ('1'); INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1');
INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`) INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`)
VALUES VALUES
@ -759,8 +760,8 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF
(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), (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),
(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), (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),
(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), (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),
(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); (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),
(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);
INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`)
VALUES VALUES
(1, 11, 1, 'ready'), (1, 11, 1, 'ready'),
@ -983,9 +984,9 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack
('cc', 1640038.00, 56.00, 220.00, 128.00, 1, util.VN_CURDATE(), 15, 90.00), ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, util.VN_CURDATE(), 15, 90.00),
('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, util.VN_CURDATE(), 16, 0.00); ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, util.VN_CURDATE(), 16, 0.00);
INSERT INTO `vn`.`packagingConfig`(`upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`) INSERT INTO `vn`.`packagingConfig`(`id`, `upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`)
VALUES VALUES
('10', 1, 'pallet 100'); (1, '10', 1, 'pallet 100');
INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`)
VALUES VALUES
@ -1868,8 +1869,7 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`) INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`)
VALUES VALUES
(1, 50), (1, 50);
(2, 30);
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
VALUES VALUES
@ -2504,9 +2504,9 @@ INSERT INTO `hedera`.`imageCollectionSize`(`id`, `collectionFk`,`width`, `height
VALUES VALUES
(1, 4, 160, 160); (1, 4, 160, 160);
INSERT INTO `vn`.`rateConfig`(`rate0`, `rate1`, `rate2`, `rate3`) INSERT INTO `vn`.`rateConfig`(`id`, `rate0`, `rate1`, `rate2`, `rate3`)
VALUES VALUES
(36, 31, 25, 21); (1, 36, 31, 25, 21);
INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate3`) INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate3`)
VALUES VALUES
@ -2697,9 +2697,9 @@ INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`)
(4, 33.8, util.VN_CURDATE(), 1, 1101), (4, 33.8, util.VN_CURDATE(), 1, 1101),
(30, 34.4, util.VN_CURDATE(), 1, 1108); (30, 34.4, util.VN_CURDATE(), 1, 1108);
INSERT INTO `vn`.`docuwareConfig` (`url`) INSERT INTO `vn`.`docuwareConfig` (`id`, `url`)
VALUES VALUES
('http://docuware.url/'); (1, 'http://docuware.url/');
INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`) INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`)
VALUES VALUES
@ -2796,11 +2796,12 @@ INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`)
VALUES VALUES
(1, 'h1', 1, ''); (1, 'h1', 1, '');
INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`) INSERT INTO `vn`.`packingSiteConfig` (`id`, `shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`)
VALUES VALUES
('', 'SHINNOBI_TOKEN', 'GROUP_TOKEN', 6000); (1, '', 'SHINNOBI_TOKEN', 'GROUP_TOKEN', 6000);
INSERT INTO `util`.`notificationConfig` INSERT INTO `util`.`notificationConfig`
SET `cleanDays` = 90; SET `id` = 1,
`cleanDays` = 90;
INSERT INTO `util`.`notification` (`id`, `name`, `description`) INSERT INTO `util`.`notification` (`id`, `name`, `description`)
VALUES VALUES
@ -2855,7 +2856,7 @@ INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPack
INSERT INTO `vn`.`itemConfig` (`id`, `isItemTagTriggerDisabled`, `monthToDeactivate`, `wasteRecipients`, `validPriorities`, `defaultPriority`, `defaultTag`, `warehouseFk`) INSERT INTO `vn`.`itemConfig` (`id`, `isItemTagTriggerDisabled`, `monthToDeactivate`, `wasteRecipients`, `validPriorities`, `defaultPriority`, `defaultTag`, `warehouseFk`)
VALUES VALUES
(0, 0, 24, '', '[1,2,3]', 2, 56, 60); (1, 0, 24, '', '[1,2,3]', 2, 56, 60);
INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`) INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`)
VALUES VALUES
@ -2892,7 +2893,7 @@ INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedM
(1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL); (1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL);
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)
VALUES VALUES
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', '1,6', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all'); (1, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', '1,6', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all');
INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`)
VALUES VALUES
@ -3713,8 +3714,8 @@ UPDATE vn.collection
UPDATE vn.sale UPDATE vn.sale
SET isPicked =FALSE; SET isPicked =FALSE;
INSERT INTO vn.machineWorkerConfig(maxHours) INSERT INTO vn.machineWorkerConfig(id, maxHours)
VALUES(12); VALUES(1, 12);
INSERT INTO vn.workerAppTester(workerFk) VALUES(66); INSERT INTO vn.workerAppTester(workerFk) VALUES(66);

View File

@ -23,7 +23,7 @@ BEGIN
ENGINE = MEMORY ENGINE = MEMORY
SELECT Id_Ticket SELECT Id_Ticket
FROM vn2008.Tickets t FROM vn2008.Tickets t
JOIN vn.invoiceOut io ON io.id = t.Factura JOIN vn.invoiceOut io ON io.`ref` = t.Factura
WHERE year(io.issued) = vYear WHERE year(io.issued) = vYear
AND month(io.issued) = vMonth; AND month(io.issued) = vMonth;

View File

@ -7,6 +7,7 @@ BEGIN
* @vInvoiceInFk Factura recibida * @vInvoiceInFk Factura recibida
* @vXDiarioFk Id tabla XDiario * @vXDiarioFk Id tabla XDiario
*/ */
DECLARE vInvoiceInOriginalFk INT;
DECLARE vDone BOOL DEFAULT FALSE; DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vBase DOUBLE; DECLARE vBase DOUBLE;
DECLARE vVat DOUBLE; DECLARE vVat DOUBLE;
@ -198,5 +199,36 @@ BEGIN
AND e.name = 'Retenciones' AND e.name = 'Retenciones'
AND id.id IS NULL; AND id.id IS NULL;
SELECT correctedFk INTO vInvoiceInOriginalFk
FROM vn.invoiceInCorrection
WHERE correctingFk = vInvoiceInFk;
IF vInvoiceInOriginalFk THEN
UPDATE movContaIVA mci
JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk
JOIN (SELECT issued,
SUM(sub.taxableBase) taxableBase,
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
FROM(SELECT issued,
SUM(iit.taxableBase) taxableBase,
ti.PorcentajeIva
FROM vn.invoiceIn i
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
WHERE i.id = vInvoiceInOriginalFk
GROUP BY ti.CodigoIva)sub
)invoiceInOriginal
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
SET mci.TipoRectificativa = iir.refundCategoryFk,
mci.ClaseAbonoRectificativas = iir.refundType,
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
mci.FechaOperacion = invoiceInOriginal.issued,
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
WHERE mci.id = vXDiarioFk;
END IF;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,102 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
vItemFk INT,
vWarehouseFk INT,
vDate DATETIME
)
BEGIN
/**
* Calcula y proporciona un historial de inventario absoluto
* para un artículo específico en un almacén dado
* hasta una fecha determinada.
*
* @param vItemFk Id de artículo
* @param vWarehouseFk Id de almacén
* @param vDate Fecha
*/
DECLARE vCalculatedInventory INT;
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
DECLARE vStartDate DATE DEFAULT '2001-01-01';
CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
ENGINE = MEMORY
SELECT *
FROM (
SELECT tr.landed `date`,
b.quantity input,
NULL `output`,
tr.isReceived ok,
s.name alias,
e.invoiceNumber reference,
e.id id,
tr.isDelivered f5
FROM buy b
JOIN `entry` e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk
WHERE tr.landed >= vStartDate
AND s.id <> (SELECT supplierFk FROM inventoryConfig)
AND vWarehouseFk IN (tr.warehouseInFk, 0)
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
UNION ALL
SELECT tr.shipped,
NULL,
b.quantity,
tr.isDelivered,
s.name,
e.invoiceNumber,
e.id,
tr.isDelivered
FROM buy b
JOIN `entry` e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk
WHERE tr.shipped >= vStartDate
AND vWarehouseFk = tr.warehouseOutFk
AND s.id <> (SELECT supplierFk FROM inventoryConfig)
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
UNION ALL
SELECT t.shipped,
NULL,
m.quantity,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL),
t.nickname,
t.refFk,
t.id,
t.isPrinted
FROM sale m
JOIN ticket t ON t.id = m.ticketFk
JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= vStartDate
AND m.itemFk = vItemFk
AND vWarehouseFk IN (t.warehouseFk, 0)
) t1
ORDER BY `date`, input DESC, ok DESC;
SELECT SUM(input) - SUM(`output`) INTO vCalculatedInventory
FROM tHistoricalPast
WHERE `date` < vDate;
SELECT p1.*, NULL v_virtual
FROM (
SELECT vDate `date`,
vCalculatedInventory input,
NULL `output`,
1 ok,
'Inventario calculado' alias,
'' reference,
0 id,
1 f5
UNION ALL
SELECT *
FROM tHistoricalPast
WHERE `date` >= vDate
) p1;
DROP TEMPORARY TABLE tHistoricalPast;
END$$
DELIMITER ;

View File

@ -10,20 +10,15 @@ BEGIN
* @param vInvoiceInFk Id de factura recibida * @param vInvoiceInFk Id de factura recibida
*/ */
DECLARE vRate DOUBLE DEFAULT 1; DECLARE vRate DOUBLE DEFAULT 1;
DECLARE vDated DATE; DECLARE vExpenseFk VARCHAR(10);
DECLARE vExpenseFk INT;
SELECT MAX(rr.dated) INTO vDated SELECT `value` INTO vRate
FROM referenceRate rr FROM referenceRate rr
JOIN invoiceIn ii ON ii.id = vInvoiceInFk JOIN invoiceIn ii ON ii.id = vInvoiceInFk
WHERE rr.dated <= ii.issued WHERE rr.dated <= ii.issued
AND rr.currencyFk = ii.currencyFk; AND rr.currencyFk = ii.currencyFk
ORDER BY dated DESC
IF vDated THEN LIMIT 1;
SELECT `value` INTO vRate
FROM referenceRate
WHERE dated = vDated;
END IF;
DELETE FROM invoiceInTax WHERE invoiceInFk = vInvoiceInFk; DELETE FROM invoiceInTax WHERE invoiceInFk = vInvoiceInFk;

View File

@ -1,234 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`invoiceIn_add`(vInvoiceInFk INT, vXDiarioFk INT)
BEGIN
/**
* Traslada la info de contabilidad relacionada con las facturas recibidas
*
* @vInvoiceInFk Factura recibida
* @vXDiarioFk Id tabla XDiario
*/
DECLARE vInvoiceInOriginalFk INT;
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vBase DOUBLE;
DECLARE vVat DOUBLE;
DECLARE vRate DOUBLE;
DECLARE vTransactionCode INT;
DECLARE vCounter INT DEFAULT 0;
DECLARE vTransactionCodeOld INT;
DECLARE vTaxCode INT;
DECLARE vTaxCodeOld INT;
DECLARE vOperationCode VARCHAR(1);
DECLARE vIsIntracommunity BOOL DEFAULT FALSE;
DECLARE vSerialDua VARCHAR(1) DEFAULT 'D';
DECLARE vInvoiceTypeReceived VARCHAR(1);
DECLARE vInvoiceTypeInformative VARCHAR(1);
DECLARE vIsInformativeExportation BOOL DEFAULT FALSE;
DECLARE vCursor CURSOR FOR
SELECT it.taxableBase,
CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)),
t.PorcentajeIva,
it.transactionTypeSageFk,
it.taxTypeSageFk,
tty.isIntracommunity,
tt.ClaveOperacionDefecto
FROM vn.invoiceIn i
JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id
JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk
JOIN taxType tty ON tty.id = t.CodigoIva
JOIN TiposTransacciones tt ON tt.CodigoTransaccion = it.transactionTypeSageFk
LEFT JOIN vn.dua d ON d.id = vInvoiceInFk
WHERE i.id = vInvoiceInFk
AND d.id IS NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
DELETE FROM movContaIVA
WHERE id = vXDiarioFk;
SELECT codeSage INTO vInvoiceTypeReceived
FROM invoiceType WHERE code ='received';
SELECT codeSage INTO vInvoiceTypeInformative
FROM invoiceType WHERE code ='informative';
INSERT INTO movContaIVA(id, LibreA1)
VALUES (vXDiarioFk, vInvoiceInFk);
OPEN vCursor;
l: LOOP
FETCH vCursor INTO vBase,
vVat,
vRate,
vTransactionCode,
vTaxCode,
vIsIntracommunity,
vOperationCode;
IF vDone THEN
LEAVE l;
END IF;
SET vTransactionCodeOld = vTransactionCode;
SET vTaxCodeOld = vTaxCode;
IF vOperationCode IS NOT NULL THEN
UPDATE movContaIVA
SET ClaveOperacionFactura = vOperationCode
WHERE id = vXDiarioFk;
END IF;
SET vCounter = vCounter + 1;
CASE vCounter
WHEN 1 THEN
UPDATE movContaIVA
SET BaseIva1 = vBase,
PorIva1 = vRate,
CuotaIva1 = vVat,
CodigoTransaccion1 = vTransactionCode,
CodigoIva1 = vTaxCode
WHERE id = vXDiarioFk;
WHEN 2 THEN
UPDATE movContaIVA
SET BaseIva2 = vBase,
PorIva2 = vRate,
CuotaIva2 = vVat,
CodigoTransaccion2 = vTransactionCode,
CodigoIva2 = vTaxCode
WHERE id = vXDiarioFk;
WHEN 3 THEN
UPDATE movContaIVA
SET BaseIva3 = vBase,
PorIva3 = vRate,
CuotaIva3 = vVat,
CodigoTransaccion3 = vTransactionCode,
CodigoIva3 = vTaxCode
WHERE id = vXDiarioFk;
WHEN 4 THEN
UPDATE movContaIVA
SET BaseIva4 = vBase,
PorIva4 = vRate,
CuotaIva4 = vVat,
CodigoTransaccion4 = vTransactionCode,
CodigoIva4 = vTaxCode
WHERE id = vXDiarioFk;
ELSE
SELECT vXDiarioFk INTO vXDiarioFk;
END CASE;
IF vIsIntracommunity THEN
UPDATE movContaIVA
SET Intracomunitaria = TRUE
WHERE id = vXDiarioFk;
END IF;
SET vTransactionCodeOld = vTransactionCode;
SET vTaxCodeOld = vTaxCode;
END LOOP;
CLOSE vCursor;
SELECT d.ASIEN AND x.ASIEN IS NULL INTO vIsInformativeExportation
FROM vn.dua d
LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN
AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci
WHERE d.ASIEN = (
SELECT ASIEN
FROM vn.XDiario
WHERE id = vXDiarioFk)
LIMIT 1;
UPDATE movContaIVA mci
JOIN tmp.invoiceIn ii ON ii.id = vInvoiceInFk
JOIN vn.XDiario x ON x.id = mci.id
LEFT JOIN tmp.invoiceDua id ON id.id = mci.id
JOIN vn.supplier s ON s.id = ii.supplierFk
JOIN Naciones n ON n.countryFk = s.countryFk
SET mci.CodigoDivisa = ii.currencyFk,
mci.Año = YEAR(ii.issued),
mci.Serie = ii.serial,
mci.Factura = ii.id,
mci.FechaFactura = ii.issued,
mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) +
IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) +
IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) +
IFNULL(mci.BaseIva4, 0) + IFNULL(mci.CuotaIva4, 0),
mci.TipoFactura = IF(id.id,
IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative),
IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)),
mci.CodigoCuentaFactura = x.SUBCTA,
mci.CifDni = IF(LEFT(TRIM(s.nif), 2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif), 3), s.nif),
mci.Nombre = s.name,
mci.SiglaNacion = n.SiglaNacion,
mci.EjercicioFactura = YEAR(ii.issued),
mci.FechaOperacion = ii.issued,
mci.MantenerAsiento = TRUE,
mci.SuFacturaNo = ii.supplierRef,
mci.IvaDeducible1 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva1, FALSE) = FALSE, FALSE, ii.isVatDeductible)),
mci.IvaDeducible2 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva2, FALSE) = FALSE, FALSE, ii.isVatDeductible)),
mci.IvaDeducible3 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva3, FALSE) = FALSE, FALSE, ii.isVatDeductible)),
mci.IvaDeducible4 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva4, FALSE) = FALSE, FALSE, ii.isVatDeductible)),
mci.FechaFacturaOriginal = x.FECHA_EX
WHERE mci.id = vXDiarioFk;
-- RETENCIONES
UPDATE movContaIVA mci
JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk
JOIN vn.XDiario x ON x.id = mci.id
JOIN vn.supplier s ON s.id = supplierFk
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id
JOIN vn.expense e ON e.id = iit.expenseFk
JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk
LEFT JOIN tmp.invoiceDua id ON id.id = mci.id
JOIN (SELECT SUM(x2.BASEEURO) taxableBase, SUM(x2.EURODEBE) taxBase
FROM vn.XDiario x1
JOIN vn.XDiario x2 ON x1.ASIEN = x2.ASIEN
WHERE x2.BASEEURO <> 0
AND x1.id = vXDiarioFk
)sub
JOIN ClavesOperacion co ON co.Descripcion = 'Arrendamiento de locales de negocio'
SET mci.CodigoRetencion = t.CodigoRetencion,
mci.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', co.ClaveOperacionFactura_, mci.ClaveOperacionFactura),
mci.BaseRetencion = IF (t.Retencion = 'ACTIVIDADES AGRICOLAS O GANADERAS', sub.taxableBase + sub.taxBase, sub.taxableBase),
mci.PorRetencion = t.PorcentajeRetencion,
mci.ImporteRetencion = iit.taxableBase * - 1
WHERE mci.id = vXDiarioFk
AND e.name = 'Retenciones'
AND id.id IS NULL;
SELECT correctedFk INTO vInvoiceInOriginalFk
FROM vn.invoiceInCorrection
WHERE correctingFk = vInvoiceInFk;
IF vInvoiceInOriginalFk THEN
UPDATE movContaIVA mci
JOIN vn.invoiceInRefund iir ON iir.invoiceInRefundFk = vInvoiceInFk
JOIN (SELECT issued,
SUM(sub.taxableBase) taxableBase,
SUM(ROUND((sub.taxableBase * sub.PorcentajeIva) / 100 , 2)) vat
FROM(SELECT issued,
SUM(iit.taxableBase) taxableBase,
ti.PorcentajeIva
FROM vn.invoiceIn i
JOIN vn.invoiceInTax iit ON iit.invoiceInFk = i.id
JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
WHERE i.id = vInvoiceInOriginalFk
GROUP BY ti.CodigoIva)sub
)invoiceInOriginal
JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa'
SET mci.TipoRectificativa = iir.refundCategoryFk,
mci.ClaseAbonoRectificativas = iir.refundType,
mci.FechaFacturaOriginal = invoiceInOriginal.issued,
mci.FechaOperacion = invoiceInOriginal.issued,
mci.BaseImponibleOriginal = invoiceInOriginal.taxableBase,
mci.CuotaIvaOriginal = invoiceInOriginal.vat,
mci.ClaveOperacionFactura = co.ClaveOperacionFactura_
WHERE mci.id = vXDiarioFk;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,158 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`(
vItemFk INT
)
BEGIN
/**
* Calcula y proporciona un historial de inventario detallado
* para un artículo dividiendo la información
* por almacén.
*
* @param vItemFk Artículo
*/
DECLARE vDateInventory DATETIME;
SELECT inventoried INTO vDateInventory FROM config;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory1;
CREATE TEMPORARY TABLE tMultipleHistory1
SELECT DATE(`date`) `date`,
input,
`output`,
ok,
reference,
history.id,
warehouse,
`name` warehouseName
FROM (
SELECT tr.landed `date`,
c.quantity input,
NULL `output`,
tr.warehouseInFk warehouse,
tr.isReceived ok,
e.invoiceNumber reference,
e.id
FROM buy c
JOIN `entry` e ON e.id = c.entryFk
JOIN travel tr ON tr.id = e.travelFk
WHERE tr.landed >= vDateInventory
AND c.itemFk = vItemFk
AND NOT e.isRaid
AND c.quantity
UNION ALL
SELECT tr.shipped,
NULL,
c.quantity,
tr.warehouseOutFk,
tr.isDelivered,
e.invoiceNumber,
e.id
FROM buy c
JOIN `entry` e ON e.id = c.entryFk
JOIN travel tr ON tr.id = e.travelFk
WHERE tr.shipped >= vDateInventory
AND c.itemFk = vItemFk
AND NOT e.isRaid
AND c.quantity
UNION ALL
SELECT t.shipped,
NULL,
m.quantity,
t.warehouseFk,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL),
t.refFk,
t.id
FROM sale m
JOIN ticket t ON t.id = m.ticketFk
WHERE t.shipped >= vDateInventory
AND m.itemFk = vItemFk
) history
JOIN warehouse ON warehouse.id = history.warehouse
ORDER BY `date`, input DESC, ok DESC;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2, tMultipleHistory3,
tMultipleHistory4, tMultipleHistory5, tMultipleHistory6, tMultipleHistory7, tMultipleHistory8;
CREATE TEMPORARY TABLE tMultipleHistory2 SELECT * FROM tMultipleHistory1 WHERE warehouse = 19;
CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7;
CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60;
CREATE TEMPORARY TABLE tMultipleHistory5 SELECT * FROM tMultipleHistory1 WHERE warehouse = 5;
CREATE TEMPORARY TABLE tMultipleHistory6 SELECT * FROM tMultipleHistory1 WHERE warehouse = 17;
CREATE TEMPORARY TABLE tMultipleHistory7 SELECT * FROM tMultipleHistory1 WHERE warehouse = 37;
CREATE TEMPORARY TABLE tMultipleHistory8 SELECT * FROM tMultipleHistory1 WHERE warehouse = 55;
SELECT *
FROM (
SELECT `date`, input BOGinput, `output` BOGoutput, ok BOGok, reference BOGreference, id BOGid,
NULL VNHinput, NULL VNHoutput, NULL VNHok, NULL VNHreference, NULL VNHid,
NULL ALGinput, NULL ALGoutput, NULL ALGok, NULL ALGreference, NULL ALGid,
NULL MADinput, NULL MADoutput, NULL MADok, NULL MADreference, NULL MADid,
NULL MCFinput, NULL MCFoutput, NULL MCFok, NULL MCFreference, NULL MCFid,
NULL VILinput, NULL VILoutput, NULL VILok, NULL VILreference, NULL VILid,
NULL BARinput, NULL BARoutput, NULL BARok, NULL BARreference, NULL BARid
FROM tMultipleHistory2
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory3
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory4
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory5
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory6
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory7
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id
FROM tMultipleHistory8
) sub
ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL,
MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL;
END$$
DELIMITER ;

View File

@ -9,6 +9,7 @@ trig: BEGIN
DECLARE vGroupingMode TINYINT; DECLARE vGroupingMode TINYINT;
DECLARE vGenericFk INT; DECLARE vGenericFk INT;
DECLARE vGenericInDate BOOL; DECLARE vGenericInDate BOOL;
DECLARE vBuyerFk INT;
IF @isModeInventory THEN IF @isModeInventory THEN
LEAVE trig; LEAVE trig;
@ -20,6 +21,13 @@ trig: BEGIN
SET NEW.editorFk = account.myUser_getId(); SET NEW.editorFk = account.myUser_getId();
SELECT it.workerFk INTO vBuyerFk
FROM item i
JOIN itemType it ON it.id = i.typeFk
WHERE i.id = NEW.itemFk;
SET NEW.buyerFk = vBuyerFk;
CALL buy_checkGrouping(NEW.`grouping`); CALL buy_checkGrouping(NEW.`grouping`);
SELECT t.warehouseInFk, t.landed SELECT t.warehouseInFk, t.landed

View File

@ -7,6 +7,7 @@ trig:BEGIN
DECLARE vGenericInDate BOOL; DECLARE vGenericInDate BOOL;
DECLARE vIsInventory BOOL; DECLARE vIsInventory BOOL;
DECLARE vDefaultEntry INT; DECLARE vDefaultEntry INT;
DECLARE vBuyerFk INT;
IF @isTriggerDisabled THEN IF @isTriggerDisabled THEN
LEAVE trig; LEAVE trig;
@ -65,6 +66,15 @@ trig:BEGIN
SET NEW.isIgnored = TRUE; SET NEW.isIgnored = TRUE;
END IF; END IF;
IF NOT (NEW.itemFk <=> OLD.itemFk) THEN
SELECT it.workerFk INTO vBuyerFk
FROM item i
JOIN itemType it ON it.id = i.typeFk
WHERE i.id = NEW.itemFk;
SET NEW.buyerFk = vBuyerFk;
END IF;
IF NOT (NEW.itemFk <=> OLD.itemFk) OR IF NOT (NEW.itemFk <=> OLD.itemFk) OR
NOT (OLD.entryFk <=> NEW.entryFk) THEN NOT (OLD.entryFk <=> NEW.entryFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck

View File

@ -1,61 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`add_awb_component`(IN vAwbFk SMALLINT)
BEGIN
DECLARE vShipped DATE;
DECLARE vHasStems BOOLEAN;
SELECT t.shipped, IF(a.stems, TRUE, FALSE)
INTO vShipped, vHasStems
FROM vn.travel t
JOIN vn.awb a ON a.id = t.awbFk
WHERE awbFk = vAwbFk
LIMIT 1;
INSERT IGNORE INTO awb_component (awb_id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,value,Id_Moneda)
SELECT id, Id_Proveedor, awb_component_type_id, awb_role_id,awb_unit_id, LEAST(GREATEST(value1, IFNULL(min_value, value1)), IFNULL(max_value, value1)), Id_Moneda
FROM (
SELECT a.id,
IFNULL(act.carguera_id,
CASE awb_role_id
WHEN 1 THEN a.carguera_id
WHEN 2 THEN a.transitario_id
WHEN 3 THEN f.airline_id
END
) Id_Proveedor,
act.awb_component_type_id,
act.awb_role_id,
act.awb_unit_id,
value *
CASE awb_unit_id
WHEN '1000Tj-20' THEN ((CAST(stems AS SIGNED) - 20000)/1000) + (min_value / value)
WHEN '1000Tj-10' THEN ((CAST(stems AS SIGNED) - 10000)/1000) + (min_value / value)
WHEN '100GW' THEN peso/100
WHEN 'AWB' THEN 1 -- No action
WHEN 'FB' THEN hb/2
WHEN 'GW' THEN peso
WHEN 'TW' THEN GREATEST(peso,volume_weight)
WHEN 'PN' THEN LEAST(90, value + a.propertyNumber * 10)
END value1,
value,
act.Id_Moneda,
act.min_value,
act.max_value
FROM awb a
JOIN flight f ON f.flight_id = a.flight_id
LEFT JOIN awb_component_template act ON
((IFNULL(act.carguera_id, a.carguera_id) = a.carguera_id AND awb_role_id = 1)
OR (IFNULL(act.carguera_id, a.transitario_id) = a.transitario_id AND awb_role_id = 2)
OR (IFNULL(act.airline_id, f.airline_id) = f.airline_id AND awb_role_id = 3)
OR (awb_role_id = 4))
AND IFNULL(act.airport_out, f.airport_out) = f.airport_out
AND IFNULL(act.airport_in, f.airport_in) = f.airport_in
AND IFNULL(act.airline_id, f.airline_id) = f.airline_id
AND INSTR(IFNULL(act.days, WEEKDAY(vShipped) + 1),WEEKDAY(vShipped) + 1)
JOIN awb_component_type acty ON acty.awb_component_type_id = act.awb_component_type_id
WHERE a.id = vAwbFk AND Fecha <= vShipped
AND (vHasStems = TRUE OR acty.hasStems)
ORDER BY Fecha DESC, act.days DESC LIMIT 10000000000000000000
) t;
END$$
DELIMITER ;

View File

@ -1,50 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencyModeImbalance`(vStarted DATE, vEnded DATE)
BEGIN
/**
* Devuelve el valor de los precios teorico, practico de las agencias
* y si ademas es de mrw lo compara con su fichero previamente procesado
*
* @param vEktFk Identificador de edi.ekt
*/
DECLARE vEndedDayEnd DATETIME;
SET vEndedDayEnd = util.dayEnd(vEnded);
SELECT t.id ticketFk,t.addressFk,
CAST(v.amount AS DECIMAL (10,2)) AS VN,
CAST(v.amount - e.shipping_charge AS DECIMAL (10,2)) AS Difer,
CAST(mrwPrice AS DECIMAL (10,2)) mrwPrice,
CAST(e.shipping_charge - mrwPrice AS DECIMAL (10,2)) mrwDifference,
CAST(e.shipping_charge AS DECIMAL (10,2)) AS teorico,
CAST(e.extraCharge AS DECIMAL (10,2)) AS extraCharge,
t.packages, t.clientFk,
t.zoneFk, a.provinceFk, mrwCount
FROM vn.ticket t
LEFT JOIN
(SELECT ticketFk, SUM(amount) amount, fc.shipped
FROM vn.sale_freightComponent fc
JOIN vn.ticket t ON t.id = fc.ticketFk
JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk
WHERE fc.shipped BETWEEN vStarted AND vEndedDayEnd
GROUP BY ticketFk) v ON t.id = v.ticketFk
LEFT JOIN (SELECT t.id,
SUM(t.zonePrice) shipping_charge,
SUM(IFNULL(aex.price,0)) extraCharge
FROM vn.ticket t
LEFT JOIN vn.expedition e ON e.ticketFk = t.id
LEFT JOIN vn.packaging p ON p.id = e.packagingFk
JOIN tmp.agencyMode amc ON amc.agencyModeFk = t.agencyModeFk
JOIN vn.agencyMode am ON am.id = amc.agencyModeFk
LEFT JOIN vn.agencyExtraCharge aex ON p.width+p.depth+p.height BETWEEN aex.sizeMin AND aex.sizeMax AND aex.agencyFk = am.agencyFk
WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd
GROUP BY t.id
) e ON t.id = e.id
LEFT JOIN (SELECT ticketFk, SUM(price) mrwPrice, COUNT(*) mrwCount
FROM vn.mrw
GROUP BY ticketFk) mrw ON mrw.ticketFk = t.id
JOIN vn.address a ON a.id = t.addressFk
JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk
WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd;
END$$
DELIMITER ;

View File

@ -1,91 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_absoluto`(IN idART INT, IN wh INT, IN datfecha DATETIME)
BEGIN
DECLARE inv_calculado INT;
DECLARE inv INT;
DECLARE today DATETIME;
DECLARE fecha_inv DATETIME;
SET today = util.VN_CURDATE();
CREATE OR REPLACE TEMPORARY TABLE historico_pasado
SELECT *
FROM (
SELECT TR.landing Fecha,
C.Cantidad Entrada,
NULL Salida,
(TR.received != FALSE) OK,
P.Proveedor Alias,
E.Referencia Referencia,
E.Id_Entrada id,
TR.delivered F5
FROM Compres C -- mirar perque no entra en received
INNER JOIN Entradas E USING (Id_Entrada)
INNER JOIN travel TR ON TR.id = E.travel_id
INNER JOIN Proveedores P USING (Id_Proveedor)
WHERE TR.landing >= '2001-01-01'
AND Id_proveedor <> 4
AND wh IN (TR.warehouse_id , 0)
AND C.Id_Article = idART
AND E.Inventario = 0
AND E.Redada = 0
UNION ALL
SELECT TR.shipment Fecha,
NULL Entrada,
C.Cantidad Salida,
TR.delivered OK,
P.Proveedor Alias,
E.Referencia Referencia,
E.Id_Entrada id,
TR.delivered F5
FROM Compres C
INNER JOIN Entradas E USING (Id_Entrada)
INNER JOIN travel TR ON TR.id = E.travel_id
INNER JOIN Proveedores P USING (Id_Proveedor)
WHERE TR.shipment >= '2001-01-01'
AND wh = TR.warehouse_id_out
AND Id_Proveedor <> 4
AND C.Id_Article = idART
AND E.Inventario = 0
AND E.Redada = 0
UNION ALL
SELECT T.Fecha Fecha,
NULL Entrada,
M.Cantidad Salida,
(M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK,
T.Alias Alias,
T.Factura Referencia,
T.Id_Ticket,
T.PedidoImpreso
FROM Movimientos M
INNER JOIN Tickets T USING (Id_Ticket)
JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente
WHERE T.Fecha >= '2001-01-01'
AND M.Id_Article = idART
AND wh IN (T.warehouse_id , 0)
) t1
ORDER BY Fecha, Entrada DESC, OK DESC;
SELECT sum(Entrada) - sum(Salida) INTO inv_calculado
FROM historico_pasado
WHERE Fecha < datfecha;
SELECT p1.*, NULL v_virtual
FROM(
SELECT datfecha Fecha,
inv_calculado Entrada,
NULL Salida,
1 OK,
'Inventario calculado' Alias,
'' Referencia, 0 id,
1 F5
UNION ALL
SELECT *
FROM historico_pasado
WHERE Fecha >= datfecha
) p1;
DROP TEMPORARY TABLE historico_pasado;
END$$
DELIMITER ;

View File

@ -1,206 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_multiple`(IN vItemFk INT)
BEGIN
DECLARE vDateInventory DATETIME;
SELECT Fechainventario INTO vDateInventory FROM tblContadores;
SET @a = 0;
DROP TEMPORARY TABLE IF EXISTS hm1;
CREATE TEMPORARY TABLE hm1
SELECT DATE(Fecha) as Fecha,
Entrada,
Salida,
OK,
Referencia,
Historia.id,
wh,
`name` as wh_name
FROM
( SELECT TR.landing as Fecha,
C.Cantidad as Entrada,
NULL as Salida,
IF(warehouse_id = 44, 1, warehouse_id) as wh,
(TR.received != FALSE) as OK,
E.Referencia as Referencia,
E.Id_Entrada as id
FROM Compres C
INNER JOIN Entradas E USING (Id_Entrada)
INNER JOIN travel TR ON TR.id = E.travel_id
WHERE TR.landing >= vDateInventory
AND C.Id_Article = vItemFk
AND E.Redada = 0
AND C.Cantidad <> 0
UNION ALL
SELECT TR.shipment as Fecha,
NULL as Entrada,
C.Cantidad as Salida,
warehouse_id_out as wh,
TR.delivered as OK,
E.Referencia as Referencia,
E.Id_Entrada as id
FROM Compres C
INNER JOIN Entradas E USING (Id_Entrada)
INNER JOIN travel TR ON TR.id = E.travel_id
WHERE TR.shipment >= vDateInventory
AND C.Id_Article = vItemFk
AND E.Redada = 0
AND C.Cantidad <> 0
UNION ALL
SELECT T.Fecha as Fecha,
NULL as Entrada,
M.Cantidad as Salida,
warehouse_id as wh,
(M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) as OK,
T.Factura as Referencia,
T.Id_Ticket as id
FROM Movimientos M
INNER JOIN Tickets T USING (Id_Ticket)
WHERE T.Fecha >= vDateInventory
AND M.Id_Article = vItemFk
) AS Historia
INNER JOIN warehouse ON warehouse.id = Historia.wh
ORDER BY Fecha, Entrada DESC, OK DESC;
DROP TEMPORARY TABLE IF EXISTS hm2;
DROP TEMPORARY TABLE IF EXISTS hm3;
DROP TEMPORARY TABLE IF EXISTS hm4;
DROP TEMPORARY TABLE IF EXISTS hm5;
DROP TEMPORARY TABLE IF EXISTS hm6;
DROP TEMPORARY TABLE IF EXISTS hm7;
DROP TEMPORARY TABLE IF EXISTS hm8;
CREATE TEMPORARY TABLE hm2 SELECT * FROM hm1 WHERE wh = 19;
CREATE TEMPORARY TABLE hm3 SELECT * FROM hm1 WHERE wh = 7;
CREATE TEMPORARY TABLE hm4 SELECT * FROM hm1 WHERE wh = 60;
CREATE TEMPORARY TABLE hm5 SELECT * FROM hm1 WHERE wh = 5;
CREATE TEMPORARY TABLE hm6 SELECT * FROM hm1 WHERE wh = 17;
CREATE TEMPORARY TABLE hm7 SELECT * FROM hm1 WHERE wh = 37;
CREATE TEMPORARY TABLE hm8 SELECT * FROM hm1 WHERE wh = 55;
SELECT * FROM
(
SELECT Fecha, Entrada as BOGEntrada, Salida as BOGSalida, OK as BOGOK, Referencia as BOGReferencia, id as BOGid,
NULL AS VNHEntrada, NULL AS VNHSalida, NULL AS VNHOK, NULL AS VNHReferencia, NULL AS VNHid,
NULL AS ALGEntrada, NULL AS ALGSalida, NULL AS ALGOK, NULL AS ALGReferencia, NULL AS ALGid,
NULL AS MADEntrada, NULL AS MADSalida, NULL AS MADOK, NULL AS MADReferencia, NULL AS MADid,
NULL AS MCFEntrada, NULL AS MCFSalida, NULL AS MCFOK, NULL AS MCFReferencia, NULL AS MCFid,
NULL AS VILEntrada, NULL AS VILSalida, NULL AS VILOK, NULL AS VILReferencia, NULL AS VILid,
NULL AS BAREntrada, NULL AS BARSalida, NULL AS BAROK, NULL AS BARReferencia, NULL AS BARid
FROM hm2
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
,Entrada, Salida, OK, Referencia, id
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
FROM hm3
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, Entrada, Salida, OK, Referencia, id
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
FROM hm4
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, Entrada, Salida, OK, Referencia, id
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
FROM hm5
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, Entrada, Salida, OK, Referencia, id
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
FROM hm6
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, Entrada, Salida, OK, Referencia, id
, NULL, NULL, NULL, NULL, NULL
FROM hm7
UNION ALL
SELECT Fecha
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, NULL, NULL, NULL, NULL, NULL
, Entrada, Salida, OK, Referencia, id
FROM hm8
) sub
ORDER BY Fecha, BOGEntrada IS NULL, VNHEntrada IS NULL, ALGEntrada IS NULL, MADEntrada IS NULL, MCFEntrada IS NULL, VILEntrada IS NULL, BAREntrada IS NULL;
END$$
DELIMITER ;

View File

@ -5,7 +5,6 @@ AS SELECT `c`.`id` AS `id`,
`c`.`code` AS `abbreviation`, `c`.`code` AS `abbreviation`,
`c`.`supplierAccountFk` AS `Id_Proveedores_account`, `c`.`supplierAccountFk` AS `Id_Proveedores_account`,
`c`.`workerManagerFk` AS `gerente_id`, `c`.`workerManagerFk` AS `gerente_id`,
`c`.`sage200Company` AS `digito_factura`,
`c`.`phytosanitary` AS `phytosanitary`, `c`.`phytosanitary` AS `phytosanitary`,
`c`.`companyCode` AS `CodigoEmpresa`, `c`.`companyCode` AS `CodigoEmpresa`,
`c`.`companyGroupFk` AS `empresa_grupo`, `c`.`companyGroupFk` AS `empresa_grupo`,

View File

@ -0,0 +1 @@
ALTER TABLE vn.buy ADD buyerFk int(10) unsigned DEFAULT NULL NULL;

View File

@ -0,0 +1,22 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`(
vItemFk INT)
BEGIN
DECLARE vDateInventory DATETIME;
SELECT inventoried INTO vDateInventory FROM config;
END$$
DELIMITER ;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
vItemFk INT, vWarehouse INT, vDate DATETIME)
BEGIN
DECLARE vCalculatedInventory INT;
SET vCalculatedInventory = 0;
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE vn.absoluteInventoryHistory TO buyer;
GRANT EXECUTE ON PROCEDURE vn.multipleInventoryHistory TO buyer;

View File

@ -0,0 +1,23 @@
-- account.accountConfig
ALTER TABLE account.accountConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE account.accountConfig ADD CONSTRAINT accountConfig_check CHECK (id = 1);
-- account.ldapConfig
ALTER TABLE account.ldapConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE account.ldapConfig ADD CONSTRAINT ldapConfig_check CHECK (id = 1);
-- account.mailConfig
ALTER TABLE account.mailConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE account.mailConfig ADD CONSTRAINT mailConfig_check CHECK (id = 1);
-- account.roleConfig
ALTER TABLE account.roleConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE account.roleConfig ADD CONSTRAINT roleConfig_check CHECK (id = 1);
-- account.sambaConfig
ALTER TABLE account.sambaConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE account.sambaConfig ADD CONSTRAINT sambaConfig_check CHECK (id = 1);
-- account.userConfig
ALTER TABLE account.userConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE account.userConfig ADD CONSTRAINT userConfig_check CHECK (id = 1);

View File

@ -0,0 +1,7 @@
-- bs.nightTaskConfig
ALTER TABLE bs.nightTaskConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE bs.nightTaskConfig ADD CONSTRAINT nightTaskConfig_check CHECK (id = 1);
-- bs.workerProductivityConfig
ALTER TABLE bs.workerProductivityConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE bs.workerProductivityConfig ADD CONSTRAINT workerProductivityConfig_check CHECK (id = 1);

View File

@ -0,0 +1,15 @@
-- edi.exchangeConfig
ALTER TABLE edi.exchangeConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE edi.exchangeConfig ADD CONSTRAINT exchangeConfig_check CHECK (id = 1);
-- edi.ftpConfig
ALTER TABLE edi.ftpConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE edi.ftpConfig ADD CONSTRAINT ftpConfig_check CHECK (id = 1);
-- edi.imapConfig (Tiene más de 1 registro en producción)
-- ALTER TABLE edi.imapConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
-- ALTER TABLE edi.imapConfig ADD CONSTRAINT imapConfig_check CHECK (id = 1);
-- edi.offerRefreshConfig
ALTER TABLE edi.offerRefreshConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE edi.offerRefreshConfig ADD CONSTRAINT offerRefreshConfig_check CHECK (id = 1);

View File

@ -0,0 +1,27 @@
-- hedera.config
ALTER TABLE hedera.config MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE hedera.config ADD CONSTRAINT config_check CHECK (id = 1);
-- hedera.imageConfig
ALTER TABLE hedera.imageConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE hedera.imageConfig ADD CONSTRAINT imageConfig_check CHECK (id = 1);
-- hedera.mailConfig
ALTER TABLE hedera.mailConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE hedera.mailConfig ADD CONSTRAINT mailConfig_check CHECK (id = 1);
-- hedera.orderConfig
ALTER TABLE hedera.orderConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE hedera.orderConfig ADD CONSTRAINT orderConfig_check CHECK (id = 1);
-- hedera.shelfConfig (Tiene más de 1 registro en producción)
-- ALTER TABLE hedera.shelfConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
-- ALTER TABLE hedera.shelfConfig ADD CONSTRAINT shelfConfig_check CHECK (id = 1);
-- hedera.tpvConfig
ALTER TABLE hedera.tpvConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE hedera.tpvConfig ADD CONSTRAINT tpvConfig_check CHECK (id = 1);
-- hedera.tpvImapConfig
ALTER TABLE hedera.tpvImapConfig MODIFY COLUMN id tinyint(3) unsigned NOT NULL;
ALTER TABLE hedera.tpvImapConfig ADD CONSTRAINT tpvImapConfig_check CHECK (id = 1);

View File

@ -0,0 +1,15 @@
-- pbx.config
ALTER TABLE pbx.config MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE pbx.config ADD CONSTRAINT config_check CHECK (id = 1);
-- pbx.followmeConfig
ALTER TABLE pbx.followmeConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE pbx.followmeConfig ADD CONSTRAINT followmeConfig_check CHECK (id = 1);
-- pbx.queueConfig (Tiene más de 1 registro en producción)
-- ALTER TABLE pbx.queueConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
-- ALTER TABLE pbx.queueConfig ADD CONSTRAINT queueConfig_check CHECK (id = 1);
-- pbx.sipConfig
ALTER TABLE pbx.sipConfig MODIFY COLUMN id mediumint(8) unsigned NOT NULL;
ALTER TABLE pbx.sipConfig ADD CONSTRAINT sipConfig_check CHECK (id = 1);

View File

@ -0,0 +1,3 @@
-- sage.config
ALTER TABLE sage.config MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE sage.config ADD CONSTRAINT config_check CHECK (id = 1);

View File

@ -0,0 +1,7 @@
-- salix.accessTokenConfig
ALTER TABLE salix.accessTokenConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE salix.accessTokenConfig ADD CONSTRAINT accessTokenConfig_check CHECK (id = 1);
-- salix.printConfig
ALTER TABLE salix.printConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE salix.printConfig ADD CONSTRAINT printConfig_check CHECK (id = 1);

View File

@ -0,0 +1,3 @@
-- srt.config
ALTER TABLE srt.config MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE srt.config ADD CONSTRAINT config_check CHECK (id = 1);

View File

@ -0,0 +1,11 @@
-- util.config
ALTER TABLE util.config MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE util.config ADD CONSTRAINT config_check CHECK (id = 1);
-- util.notificationConfig
ALTER TABLE util.notificationConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE util.notificationConfig ADD CONSTRAINT notificationConfig_check CHECK (id = 1);
-- util.versionConfig
ALTER TABLE util.versionConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE util.versionConfig ADD CONSTRAINT versionConfig_check CHECK (id = 1);

View File

@ -0,0 +1,87 @@
-- vn.accountingConfig
ALTER TABLE vn.accountingConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.accountingConfig ADD CONSTRAINT accountingConfig_check CHECK (id = 1);
-- vn.auctionConfig
ALTER TABLE vn.auctionConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.auctionConfig ADD CONSTRAINT auctionConfig_check CHECK (id = 1);
-- vn.autoRadioConfig
ALTER TABLE vn.autoRadioConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.autoRadioConfig ADD CONSTRAINT autoRadioConfig_check CHECK (id = 1);
-- vn.bankEntityConfig
ALTER TABLE vn.bankEntityConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.bankEntityConfig ADD CONSTRAINT bankEntityConfig_check CHECK (id = 1);
-- vn.bionicConfig
ALTER TABLE vn.bionicConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.bionicConfig ADD CONSTRAINT bionicConfig_check CHECK (id = 1);
-- vn.buyConfig
ALTER TABLE vn.buyConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.buyConfig ADD CONSTRAINT buyConfig_check CHECK (id = 1);
-- vn.chatConfig
ALTER TABLE vn.chatConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.chatConfig ADD CONSTRAINT chatConfig_check CHECK (id = 1);
-- vn.claimConfig
ALTER TABLE vn.claimConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.claimConfig ADD CONSTRAINT claimConfig_check CHECK (id = 1);
-- vn.clientConfig
ALTER TABLE vn.clientConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.clientConfig ADD CONSTRAINT clientConfig_check CHECK (id = 1);
-- vn.comparativeAddConfig
ALTER TABLE vn.comparativeAddConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.comparativeAddConfig ADD CONSTRAINT comparativeAddConfig_check CHECK (id = 1);
-- vn.comparativeConfig
ALTER TABLE vn.comparativeConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.comparativeConfig ADD CONSTRAINT comparativeConfig_check CHECK (id = 1);
-- vn.config
ALTER TABLE vn.config MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.config ADD CONSTRAINT config_check CHECK (id = 1);
-- vn.conveyorConfig (Tiene más de 1 registro en producción)
-- ALTER TABLE vn.conveyorConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
-- ALTER TABLE vn.conveyorConfig ADD CONSTRAINT conveyorConfig_check CHECK (id = 1);
-- vn.deviceProductionConfig
ALTER TABLE vn.deviceProductionConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.deviceProductionConfig ADD CONSTRAINT deviceProductionConfig_check CHECK (id = 1);
-- vn.docuwareConfig
ALTER TABLE vn.docuwareConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.docuwareConfig ADD CONSTRAINT docuwareConfig_check CHECK (id = 1);
-- vn.floramondoConfig
ALTER TABLE vn.floramondoConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.floramondoConfig ADD CONSTRAINT floramondoConfig_check CHECK (id = 1);
-- vn.franceExpressConfig
ALTER TABLE vn.franceExpressConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.franceExpressConfig ADD CONSTRAINT franceExpressConfig_check CHECK (id = 1);
-- vn.glsConfig
ALTER TABLE vn.glsConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.glsConfig ADD CONSTRAINT glsConfig_check CHECK (id = 1);
-- vn.greugeConfig
ALTER TABLE vn.greugeConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.greugeConfig ADD CONSTRAINT greugeConfig_check CHECK (id = 1);
-- vn.inventoryConfig
ALTER TABLE vn.inventoryConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.inventoryConfig ADD CONSTRAINT inventoryConfig_check CHECK (id = 1);
-- vn.invoiceInConfig
ALTER TABLE vn.invoiceInConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.invoiceInConfig ADD CONSTRAINT invoiceInConfig_check CHECK (id = 1);
-- vn.invoiceOutConfig
ALTER TABLE vn.invoiceOutConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.invoiceOutConfig ADD CONSTRAINT invoiceOutConfig_check CHECK (id = 1);

View File

@ -0,0 +1,91 @@
-- vn.invoiceOutTaxConfig (Tiene más de 1 registro en producción)
-- ALTER TABLE vn.invoiceOutTaxConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
-- ALTER TABLE vn.invoiceOutTaxConfig ADD CONSTRAINT invoiceOutTaxConfig_check CHECK (id = 1);
-- vn.itemConfig
ALTER TABLE vn.itemConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.itemConfig ADD CONSTRAINT itemConfig_check CHECK (id = 1);
-- vn.machineWorkerConfig
ALTER TABLE vn.machineWorkerConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.machineWorkerConfig ADD CONSTRAINT machineWorkerConfig_check CHECK (id = 1);
-- vn.mdbConfig
ALTER TABLE vn.mdbConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.mdbConfig ADD CONSTRAINT mdbConfig_check CHECK (id = 1);
-- vn.mrwConfig
ALTER TABLE vn.mrwConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.mrwConfig ADD CONSTRAINT mrwConfig_check CHECK (id = 1);
-- vn.osTicketConfig
ALTER TABLE vn.osTicketConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.osTicketConfig ADD CONSTRAINT osTicketConfig_check CHECK (id = 1);
-- vn.packagingConfig
ALTER TABLE vn.packagingConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.packagingConfig ADD CONSTRAINT packagingConfig_check CHECK (id = 1);
-- vn.packingSiteConfig
ALTER TABLE vn.packingSiteConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.packingSiteConfig ADD CONSTRAINT packingSiteConfig_check CHECK (id = 1);
-- vn.productionConfig
ALTER TABLE vn.productionConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_check CHECK (id = 1);
-- vn.rateConfig
ALTER TABLE vn.rateConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.rateConfig ADD CONSTRAINT rateConfig_check CHECK (id = 1);
-- vn.routeConfig
ALTER TABLE vn.routeConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.routeConfig ADD CONSTRAINT routeConfig_check CHECK (id = 1);
-- vn.salespersonConfig
ALTER TABLE vn.salespersonConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.salespersonConfig ADD CONSTRAINT salespersonConfig_check CHECK (id = 1);
-- vn.sendingConfig
ALTER TABLE vn.sendingConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.sendingConfig ADD CONSTRAINT sendingConfig_check CHECK (id = 1);
-- vn.smsConfig
ALTER TABLE vn.smsConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.smsConfig ADD CONSTRAINT smsConfig_check CHECK (id = 1);
-- vn.ticketConfig
ALTER TABLE vn.ticketConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.ticketConfig ADD CONSTRAINT ticketConfig_check CHECK (id = 1);
-- vn.tillConfig
ALTER TABLE vn.tillConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.tillConfig ADD CONSTRAINT tillConfig_check CHECK (id = 1);
-- vn.travelConfig
ALTER TABLE vn.travelConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.travelConfig ADD CONSTRAINT travelConfig_check CHECK (id = 1);
-- vn.viaexpressConfig
ALTER TABLE vn.viaexpressConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.viaexpressConfig ADD CONSTRAINT viaexpressConfig_check CHECK (id = 1);
-- vn.wagonConfig
ALTER TABLE vn.wagonConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_check CHECK (id = 1);
-- vn.workerConfig
ALTER TABLE vn.workerConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.workerConfig ADD CONSTRAINT workerConfig_check CHECK (id = 1);
-- vn.workerTimeControlConfig
ALTER TABLE vn.workerTimeControlConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.workerTimeControlConfig ADD CONSTRAINT workerTimeControlConfig_check CHECK (id = 1);
-- vn.zipConfig
ALTER TABLE vn.zipConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.zipConfig ADD CONSTRAINT zipConfig_check CHECK (id = 1);
-- vn.zoneConfig
ALTER TABLE vn.zoneConfig MODIFY COLUMN id int(10) unsigned NOT NULL;
ALTER TABLE vn.zoneConfig ADD CONSTRAINT zoneConfig_check CHECK (id = 1);

View File

@ -0,0 +1 @@
ALTER TABLE util.debug MODIFY COLUMN value text CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;

View File

@ -24,7 +24,7 @@ describe('Ticket descriptor path', () => {
it('should go back to the ticket index then search and access a ticket summary', async() => { it('should go back to the ticket index then search and access a ticket summary', async() => {
await page.accessToSection('ticket.index'); await page.accessToSection('ticket.index');
await page.accessToSearchResult('11'); await page.accessToSearchResult('33');
}); });
it('should add the ticket to thursday turn using the descriptor more menu', async() => { it('should add the ticket to thursday turn using the descriptor more menu', async() => {
@ -33,7 +33,7 @@ describe('Ticket descriptor path', () => {
await page.waitToClick(selectors.ticketDescriptor.thursdayButton); await page.waitToClick(selectors.ticketDescriptor.thursdayButton);
const message = await page.waitForSnackbar(); const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!'); expect(message.text).toContain('Current ticket deleted and added to shift');
}); });
it('should again click on the Tickets button of the top bar menu', async() => { it('should again click on the Tickets button of the top bar menu', async() => {
@ -43,7 +43,7 @@ describe('Ticket descriptor path', () => {
await page.waitForState('ticket.index'); await page.waitForState('ticket.index');
}); });
it('should confirm the ticket 11 was added to thursday', async() => { it('should confirm the ticket 33 was added to thursday', async() => {
await page.accessToSection('ticket.weekly.index'); await page.accessToSection('ticket.weekly.index');
const result = await page.waitToGetProperty(selectors.ticketsIndex.thirdWeeklyTicket, 'value'); const result = await page.waitToGetProperty(selectors.ticketsIndex.thirdWeeklyTicket, 'value');
@ -57,8 +57,8 @@ describe('Ticket descriptor path', () => {
await page.waitForState('ticket.index'); await page.waitForState('ticket.index');
}); });
it('should now search for the ticket 11', async() => { it('should now search for the ticket 33', async() => {
await page.accessToSearchResult('11'); await page.accessToSearchResult('33');
await page.waitForState('ticket.card.summary'); await page.waitForState('ticket.card.summary');
}); });
@ -68,7 +68,7 @@ describe('Ticket descriptor path', () => {
await page.waitToClick(selectors.ticketDescriptor.saturdayButton); await page.waitToClick(selectors.ticketDescriptor.saturdayButton);
const message = await page.waitForSnackbar(); const message = await page.waitForSnackbar();
expect(message.text).toContain('Data saved!'); expect(message.text).toContain('Current ticket deleted and added to shift');
}); });
it('should click on the Tickets button of the top bar menu once again', async() => { it('should click on the Tickets button of the top bar menu once again', async() => {
@ -78,7 +78,7 @@ describe('Ticket descriptor path', () => {
await page.waitForState('ticket.index'); await page.waitForState('ticket.index');
}); });
it('should confirm the ticket 11 was added on saturday', async() => { it('should confirm the ticket 33 was added on saturday', async() => {
await page.accessToSection('ticket.weekly.index'); await page.accessToSection('ticket.weekly.index');
await page.waitForTimeout(5000); await page.waitForTimeout(5000);
@ -87,14 +87,14 @@ describe('Ticket descriptor path', () => {
expect(result).toEqual('Saturday'); expect(result).toEqual('Saturday');
}); });
it('should now search for the weekly ticket 11', async() => { it('should now search for the weekly ticket 33', async() => {
await page.doSearch('11'); await page.doSearch('33');
const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult);
expect(nResults).toEqual(2); expect(nResults).toEqual(2);
}); });
it('should delete the weekly ticket 11', async() => { it('should delete the weekly ticket 33', async() => {
await page.waitToClick(selectors.ticketsIndex.firstWeeklyTicketDeleteIcon); await page.waitToClick(selectors.ticketsIndex.firstWeeklyTicketDeleteIcon);
await page.waitToClick(selectors.ticketsIndex.acceptDeleteTurn); await page.waitToClick(selectors.ticketsIndex.acceptDeleteTurn);
const message = await page.waitForSnackbar(); const message = await page.waitForSnackbar();

View File

@ -58,6 +58,11 @@ module.exports = Self => {
AND t.refFk IS NULL AND t.refFk IS NULL
GROUP BY t.id GROUP BY t.id
`, [toDate, toDate]); `, [toDate, toDate]);
const ticketIds = tickets.map(ticket => ticket.id);
await Self.rawSql(`
INSERT INTO util.debug (variable, value)
VALUES ('nightInvoicing', ?)
`, [ticketIds.join(',')]);
await closure(ctx, Self, tickets); await closure(ctx, Self, tickets);

View File

@ -13,6 +13,8 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) {
const failedtickets = []; const failedtickets = [];
for (const ticket of tickets) { for (const ticket of tickets) {
try { try {
await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId});
await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'M'); await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'M');
await Self.rawSql( await Self.rawSql(
`CALL vn.ticket_closeByTicket(?)`, `CALL vn.ticket_closeByTicket(?)`,

View File

@ -68,7 +68,7 @@ describe('ticket filter()', () => {
const filter = {}; const filter = {};
const result = await models.Ticket.filter(ctx, filter, options); const result = await models.Ticket.filter(ctx, filter, options);
expect(result.length).toEqual(6); expect(result.length).toEqual(7);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const LoopBackContext = require('loopback-context');
module.exports = Self => { module.exports = Self => {
require('../methods/ticket-weekly/filter')(Self); require('../methods/ticket-weekly/filter')(Self);
@ -8,4 +9,11 @@ module.exports = Self => {
return new UserError(`This ticket is already on weekly tickets`); return new UserError(`This ticket is already on weekly tickets`);
return err; return err;
}); });
Self.observe('after save', async ctx => {
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http;
await Self.app.models.Ticket.setDeleted(httpRequest, ctx.instance.ticketFk, ctx.options);
});
}; };

View File

@ -147,7 +147,8 @@ class Controller extends Section {
return this.$http.patch(`TicketWeeklies`, params) return this.$http.patch(`TicketWeeklies`, params)
.then(() => { .then(() => {
this.$.addTurn.hide(); this.$.addTurn.hide();
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Current ticket deleted and added to shift'));
this.reload();
}); });
} }

View File

@ -41,6 +41,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
})); }));
describe('addTurn()', () => { describe('addTurn()', () => {
pending('refs #6302');
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$.addTurn = {hide: () => {}}; controller.$.addTurn = {hide: () => {}};
jest.spyOn(controller.$.addTurn, 'hide'); jest.spyOn(controller.$.addTurn, 'hide');

View File

@ -28,3 +28,4 @@ Create a single ticket with all the content of the current ticket: Crea un ticke
Set ticket weight: Establecer peso al ticket Set ticket weight: Establecer peso al ticket
Ticket weight: Peso del ticket Ticket weight: Peso del ticket
This address has incoterms, you should set the weight before invoice it: Este consigatario tiene incoterms, deberías establecer el peso antes de facturar This address has incoterms, you should set the weight before invoice it: Este consigatario tiene incoterms, deberías establecer el peso antes de facturar
Current ticket deleted and added to shift: Ticket actual borrado y añadido a turno

View File

@ -56,7 +56,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/plugin-syntax-dynamic-import": "^7.7.4",
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",
"@babel/register": "^7.7.7", "@babel/register": "^7.7.7",
"@verdnatura/myt": "^1.6.8", "@verdnatura/myt": "^1.6.9",
"angular-mocks": "^1.7.9", "angular-mocks": "^1.7.9",
"babel-jest": "^26.0.1", "babel-jest": "^26.0.1",
"babel-loader": "^8.2.4", "babel-loader": "^8.2.4",

View File

@ -131,8 +131,8 @@ devDependencies:
specifier: ^7.7.7 specifier: ^7.7.7
version: 7.23.7(@babel/core@7.23.9) version: 7.23.7(@babel/core@7.23.9)
'@verdnatura/myt': '@verdnatura/myt':
specifier: ^1.6.8 specifier: ^1.6.9
version: 1.6.8 version: 1.6.9
angular-mocks: angular-mocks:
specifier: ^1.7.9 specifier: ^1.7.9
version: 1.8.3 version: 1.8.3
@ -2633,8 +2633,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@verdnatura/myt@1.6.8: /@verdnatura/myt@1.6.9:
resolution: {integrity: sha512-jpadr6yAR9TQXPv+has5yOYAolR/YEzsxbLgMR7BoDrpLyVFLHJEy4Dfe+Hy11r3AmxCB/8lWM+La1YGvXMWOA==} resolution: {integrity: sha512-29IauYra9igfdPWwV4+pVV/tBXvIg0fkVHEpSz8Zz3G3lRtzm286FN2Kv6hZkxmD/F1n52O37jN9WLiLHDTW1Q==}
hasBin: true hasBin: true
dependencies: dependencies:
'@sqltools/formatter': 1.2.5 '@sqltools/formatter': 1.2.5
@ -4886,6 +4886,7 @@ packages:
/deep-extend@0.6.0: /deep-extend@0.6.0:
resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
engines: {node: '>=4.0.0'} engines: {node: '>=4.0.0'}
requiresBuild: true
/deep-is@0.1.4: /deep-is@0.1.4:
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
@ -12714,6 +12715,7 @@ packages:
/strip-json-comments@2.0.1: /strip-json-comments@2.0.1:
resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==} resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
requiresBuild: true
/strip-json-comments@3.1.1: /strip-json-comments@3.1.1:
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}