This commit is contained in:
parent
15d6c9a65b
commit
3b14c7cd23
|
@ -62,6 +62,7 @@ async function test() {
|
|||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
jasmine.exitOnCompletion = true;
|
||||
}
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
|
||||
const backSpecs = [
|
||||
'./back/**/*[sS]pec.js',
|
||||
|
|
|
@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketPositionInPath
|
|||
RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
|
||||
|
||||
DECLARE vRestTicketsMaxOrder INT;
|
||||
DECLARE vRestTicketsMinOrder INT;
|
||||
DECLARE vRestTicketsPacking INT;
|
||||
|
@ -15,7 +15,9 @@ BEGIN
|
|||
DECLARE vExpeditionsCount INT;
|
||||
DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
|
||||
|
||||
SELECT `order`
|
||||
|
||||
|
||||
SELECT `order`
|
||||
INTO PACKING_ORDER
|
||||
FROM state
|
||||
WHERE code = 'PACKING';
|
||||
|
@ -26,7 +28,7 @@ SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
|
|||
LEFT JOIN ticketState ts on ts.ticketFk = t.id
|
||||
WHERE t.id = vTicketId;
|
||||
|
||||
SELECT (ag.`name` = 'VN_VALENCIA')
|
||||
SELECT (ag.`name` = 'VN_VALENCIA')
|
||||
INTO vIsValenciaPath
|
||||
FROM vn2008.Rutas r
|
||||
JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
|
||||
|
@ -40,7 +42,7 @@ IF vIsValenciaPath THEN -- Rutas Valencia
|
|||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
WHERE t.routeFk = vMyPath;
|
||||
|
||||
|
||||
SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
|
||||
INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
|
||||
FROM ticket t
|
||||
|
@ -49,7 +51,7 @@ IF vIsValenciaPath THEN -- Rutas Valencia
|
|||
AND t.warehouseFk = vMyWarehouse
|
||||
AND t.id != vTicketid;
|
||||
|
||||
SELECT COUNT(*)
|
||||
SELECT COUNT(*)
|
||||
INTO vRestTicketsPacking
|
||||
FROM ticket t
|
||||
LEFT JOIN ticketState ts on t.id = ts.ticketFk
|
||||
|
|
|
@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_getVisible
|
|||
vType INT,
|
||||
vPrefix VARCHAR(255))
|
||||
BEGIN
|
||||
|
||||
|
||||
/**
|
||||
* Gets visible items of the specified type at specified date.
|
||||
*
|
||||
|
@ -14,7 +14,7 @@ BEGIN
|
|||
* @param vType The type id
|
||||
* @param vPrefix The article prefix to filter or %NULL for all
|
||||
* @return tmp.itemVisible Visible items
|
||||
*/
|
||||
*/
|
||||
DECLARE vPrefixLen SMALLINT;
|
||||
DECLARE vFilter VARCHAR(255) DEFAULT NULL;
|
||||
DECLARE vDateInv DATE DEFAULT vn.getInventoryDate();
|
||||
|
@ -23,13 +23,13 @@ BEGIN
|
|||
GET DIAGNOSTICS CONDITION 1
|
||||
@message = MESSAGE_TEXT;
|
||||
CALL vn.mail_insert(
|
||||
'cau@verdnatura.es',
|
||||
NULL,
|
||||
'cau@verdnatura.es',
|
||||
NULL,
|
||||
CONCAT('hedera.item_getVisible error: ', @message),
|
||||
CONCAT(
|
||||
'warehouse: ', IFNULL(vWarehouse, ''),
|
||||
', Fecha:', IFNULL(vDate, ''),
|
||||
', tipo: ', IFNULL(vType,''),
|
||||
'warehouse: ', IFNULL(vWarehouse, ''),
|
||||
', Fecha:', IFNULL(vDate, ''),
|
||||
', tipo: ', IFNULL(vType,''),
|
||||
', prefijo: ', IFNULL(vPrefix,'')));
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
@ -108,7 +108,7 @@ BEGIN
|
|||
IF(p.depth > 0, p.depth, 0) depth, p.width, p.height,
|
||||
CEIL(s.quantity / t.packing) etiquetas
|
||||
FROM vn.item i
|
||||
JOIN `filter` f ON f.itemFk = i.id
|
||||
JOIN `filter` f ON f.itemFk = i.id
|
||||
JOIN currentStock s ON s.itemFk = i.id
|
||||
LEFT JOIN tmp t ON t.itemFk = i.id
|
||||
LEFT JOIN vn.packaging p ON p.id = t.packagingFk
|
||||
|
@ -187,7 +187,7 @@ BEGIN
|
|||
END;
|
||||
|
||||
-- Carga los datos del pedido
|
||||
SELECT o.date_send, o.address_id, o.note, a.clientFk,
|
||||
SELECT o.date_send, o.address_id, o.note, a.clientFk,
|
||||
o.company_id, o.agency_id, c.isTaxDataChecked
|
||||
INTO vDelivery, vAddress, vNotes, vClientId,
|
||||
vCompanyId, vAgencyModeId, vIsTaxDataChecked
|
||||
|
@ -256,7 +256,7 @@ BEGIN
|
|||
WHERE o.id = vSelf
|
||||
AND t.refFk IS NULL
|
||||
AND tp.ticketFk IS NULL
|
||||
AND IFNULL(tls.alertLevel,0) = 0
|
||||
AND IFNULL(tls.alertLevel,0) = 0
|
||||
LIMIT 1;
|
||||
|
||||
-- Crea el ticket en el caso de no existir uno adecuado
|
||||
|
@ -572,7 +572,7 @@ BEGIN
|
|||
JOIN state s
|
||||
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
||||
|
||||
INSERT INTO ticketTracking(stateFk,ticketFk,workerFk)
|
||||
INSERT INTO ticketTracking(stateFk,ticketFk,userFk)
|
||||
SELECT * FROM tmp.updateInter;
|
||||
|
||||
CALL invoiceExpenseMake(vNewInvoiceId);
|
||||
|
@ -696,7 +696,7 @@ DELIMITER ;
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar`(vSectorFk INT)
|
||||
proc:BEGIN
|
||||
|
||||
|
||||
DECLARE vCalcVisibleFk INT;
|
||||
DECLARE vCalcAvailableFk INT;
|
||||
DECLARE hasFatherSector BOOLEAN;
|
||||
|
@ -704,17 +704,17 @@ proc:BEGIN
|
|||
DECLARE vWarehouseFk INT DEFAULT 0;
|
||||
DECLARE vSonSectorFk INT;
|
||||
DECLARE vWorkerFk INT;
|
||||
|
||||
SELECT s.workerFk
|
||||
INTO vWorkerFk
|
||||
|
||||
SELECT s.workerFk
|
||||
INTO vWorkerFk
|
||||
FROM vn.sector s
|
||||
WHERE s.id = vSectorFk;
|
||||
|
||||
SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk
|
||||
FROM vn.worker w
|
||||
FROM vn.worker w
|
||||
JOIN vn.sector s ON s.code = w.code
|
||||
WHERE s.id = vSectorFk;
|
||||
|
||||
|
||||
SELECT s.id INTO vSectorFk
|
||||
FROM vn.sector s
|
||||
WHERE s.warehouseFk = vWarehouseFk
|
||||
|
@ -723,21 +723,21 @@ proc:BEGIN
|
|||
SELECT COUNT(*) INTO hasFatherSector
|
||||
FROM vn.sector
|
||||
WHERE sonFk = vSectorFk;
|
||||
|
||||
|
||||
SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk
|
||||
FROM vn.sector
|
||||
WHERE id = vSectorFk;
|
||||
|
||||
|
||||
CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk);
|
||||
CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar;
|
||||
|
||||
|
||||
IF hasFatherSector THEN
|
||||
CREATE TEMPORARY TABLE tmp.itemShelvingRadar
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT iss.itemFk,
|
||||
i.longName,
|
||||
|
@ -756,9 +756,9 @@ proc:BEGIN
|
|||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
|
||||
WHERE vSectorFk IN (iss.sectorFk, s.sonFk)
|
||||
GROUP BY iss.itemFk
|
||||
|
||||
|
||||
UNION ALL
|
||||
|
||||
|
||||
SELECT v.item_id,
|
||||
i.longName,
|
||||
i.size,
|
||||
|
@ -768,7 +768,7 @@ proc:BEGIN
|
|||
0 downstairs,
|
||||
IF(it.isPackaging, NULL, v.visible) visible,
|
||||
vSectorFk as sectorFk
|
||||
FROM cache.visible v
|
||||
FROM cache.visible v
|
||||
JOIN vn.item i on i.id = v.item_id
|
||||
JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk)
|
||||
LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk
|
||||
|
@ -777,8 +777,8 @@ proc:BEGIN
|
|||
AND iss.itemFk IS NULL
|
||||
AND it.isInventory
|
||||
) sub GROUP BY itemFk;
|
||||
|
||||
SELECT ishr.*,
|
||||
|
||||
SELECT ishr.*,
|
||||
CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho,
|
||||
CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente
|
||||
FROM tmp.itemShelvingRadar ishr
|
||||
|
@ -795,7 +795,7 @@ proc:BEGIN
|
|||
ELSE
|
||||
CREATE TEMPORARY TABLE tmp.itemShelvingRadar
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
ENGINE = MEMORY
|
||||
SELECT iss.itemFk,
|
||||
0 `hour`,
|
||||
0 `minute`,
|
||||
|
@ -807,7 +807,7 @@ proc:BEGIN
|
|||
IFNULL(a.available,0) available,
|
||||
IFNULL(v.visible - iss.visible,0) dayEndVisible,
|
||||
IFNULL(v.visible - iss.visible,0) firstNegative,
|
||||
IFNULL(v.visible - iss.visible,0) itemPlacementVisible,
|
||||
IFNULL(v.visible - iss.visible,0) itemPlacementVisible,
|
||||
IFNULL(i.minimum * b.packing,0) itemPlacementSize,
|
||||
ips.onTheWay,
|
||||
iss.visible itemShelvingStock,
|
||||
|
@ -821,20 +821,20 @@ proc:BEGIN
|
|||
LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
|
||||
LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay
|
||||
FROM vn.itemPlacementSupplyList
|
||||
WHERE saldo > 0
|
||||
FROM vn.itemPlacementSupplyList
|
||||
WHERE saldo > 0
|
||||
GROUP BY itemFk
|
||||
) ips ON ips.itemFk = i.id
|
||||
WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk)
|
||||
OR iss.sectorFk = vSectorFk;
|
||||
WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk)
|
||||
OR iss.sectorFk = vSectorFk;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime;
|
||||
CREATE TEMPORARY TABLE tmp.itemOutTime
|
||||
SELECT *,SUM(amount) quantity
|
||||
FROM
|
||||
FROM
|
||||
(SELECT item_id itemFk,
|
||||
amount,
|
||||
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours,
|
||||
amount,
|
||||
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours,
|
||||
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes
|
||||
FROM vn2008.item_out io
|
||||
JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id
|
||||
|
@ -842,23 +842,23 @@ proc:BEGIN
|
|||
JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk
|
||||
JOIN vn.state s ON s.id = ts.stateFk
|
||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
||||
LEFT JOIN (SELECT DISTINCT saleFk
|
||||
FROM vn.saleTracking st
|
||||
WHERE st.created > util.VN_CURDATE()
|
||||
LEFT JOIN (SELECT DISTINCT saleFk
|
||||
FROM vn.saleTracking st
|
||||
WHERE st.created > util.VN_CURDATE()
|
||||
AND st.isChecked
|
||||
) stPrevious ON `stPrevious`.`saleFk` = io.saleFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND s.isPicked = 0
|
||||
AND NOT io.Reservado
|
||||
AND s.isPicked = 0
|
||||
AND NOT io.Reservado
|
||||
AND stPrevious.saleFk IS NULL
|
||||
AND io.dat >= util.VN_CURDATE()
|
||||
AND io.dat >= util.VN_CURDATE()
|
||||
AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY
|
||||
) sub
|
||||
GROUP BY itemFk, hours, minutes;
|
||||
|
||||
|
||||
INSERT INTO tmp.itemShelvingRadar (itemFk)
|
||||
SELECT itemFk FROM tmp.itemOutTime
|
||||
ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity,
|
||||
ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity,
|
||||
firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity),
|
||||
`hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0),
|
||||
`minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0);
|
||||
|
@ -878,7 +878,7 @@ proc:BEGIN
|
|||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.itemShelvingRadar;
|
||||
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
|
@ -892,13 +892,13 @@ BEGIN
|
|||
/**
|
||||
* @vItemFk item a buscar
|
||||
* @vWarehouseFk almacen donde buscar
|
||||
* @vDate Si la fecha es null, muestra el histórico desde el inventario.
|
||||
* @vDate Si la fecha es null, muestra el histórico desde el inventario.
|
||||
* Si la fecha no es null, muestra histórico desde la fecha pasada.
|
||||
*/
|
||||
DECLARE vDateInventory DATETIME;
|
||||
|
||||
IF vDate IS NULL THEN
|
||||
SELECT inventoried INTO vDateInventory
|
||||
SELECT inventoried INTO vDateInventory
|
||||
FROM config;
|
||||
ELSE
|
||||
SELECT mockUtcTime INTO vDateInventory
|
||||
|
@ -924,7 +924,7 @@ BEGIN
|
|||
inventorySupplierFk INT(10)
|
||||
);
|
||||
|
||||
INSERT INTO tItemDiary
|
||||
INSERT INTO tItemDiary
|
||||
SELECT tr.landed shipped,
|
||||
b.quantity `in`,
|
||||
NULL `out`,
|
||||
|
@ -945,14 +945,14 @@ BEGIN
|
|||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN supplier s ON s.id = e.supplierFk
|
||||
JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
||||
JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
||||
OR (util.VN_CURDATE() AND tr.isReceived),
|
||||
'DELIVERED',
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN entryConfig ec
|
||||
WHERE tr.landed >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseInFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND b.itemFk = vItemFk
|
||||
AND e.isExcludedFromAvailable = FALSE
|
||||
AND e.isRaid = FALSE
|
||||
|
@ -978,14 +978,14 @@ BEGIN
|
|||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN warehouse w ON w.id = tr.warehouseOutFk
|
||||
JOIN supplier s ON s.id = e.supplierFk
|
||||
JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
||||
JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
||||
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
||||
'DELIVERED',
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN entryConfig ec
|
||||
WHERE tr.shipped >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseOutFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND b.itemFk = vItemFk
|
||||
AND e.isExcludedFromAvailable = FALSE
|
||||
AND w.isFeedStock = FALSE
|
||||
|
@ -1014,12 +1014,12 @@ BEGIN
|
|||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN clientType ct ON ct.id = c.clientTypeFk
|
||||
JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||
'DELIVERED',
|
||||
'DELIVERED',
|
||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||
'FREE',
|
||||
IFNULL(ts.code, 'FREE')))
|
||||
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id
|
||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id
|
||||
AND stk.stateFk = stPrep.id
|
||||
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
||||
WHERE t.shipped >= vDateInventory
|
||||
|
@ -1035,7 +1035,7 @@ BEGIN
|
|||
`out` DESC;
|
||||
|
||||
IF vDate IS NULL THEN
|
||||
|
||||
|
||||
SET @a := 0;
|
||||
SET @currentLineFk := 0;
|
||||
SET @shipped := '';
|
||||
|
@ -1050,9 +1050,9 @@ BEGIN
|
|||
`in` invalue,
|
||||
`out`,
|
||||
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance,
|
||||
@currentLineFk := IF (@shipped < util.VN_CURDATE()
|
||||
@currentLineFk := IF (@shipped < util.VN_CURDATE()
|
||||
OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')),
|
||||
lineFk,
|
||||
lineFk,
|
||||
@currentLineFk) lastPreparedLineFk,
|
||||
isTicket,
|
||||
lineFk,
|
||||
|
@ -1084,32 +1084,32 @@ BEGIN
|
|||
0 clientType,
|
||||
0 claimFk
|
||||
UNION ALL
|
||||
SELECT shipped,
|
||||
alertlevel,
|
||||
stateName,
|
||||
origin,
|
||||
reference,
|
||||
clientFk,
|
||||
name, `in`,
|
||||
`out`,
|
||||
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
||||
0,
|
||||
isTicket,
|
||||
lineFk,
|
||||
isPicked,
|
||||
clientType,
|
||||
SELECT shipped,
|
||||
alertlevel,
|
||||
stateName,
|
||||
origin,
|
||||
reference,
|
||||
clientFk,
|
||||
name, `in`,
|
||||
`out`,
|
||||
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
||||
0,
|
||||
isTicket,
|
||||
lineFk,
|
||||
isPicked,
|
||||
clientType,
|
||||
claimFk
|
||||
FROM tItemDiary
|
||||
WHERE shipped >= vDate;
|
||||
END IF;
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE tItemDiary;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionControl`(
|
||||
vWarehouseFk INT,
|
||||
vWarehouseFk INT,
|
||||
vScopeDays INT
|
||||
)
|
||||
proc: BEGIN
|
||||
|
@ -1210,7 +1210,7 @@ proc: BEGIN
|
|||
LEFT JOIN parking pk ON pk.id = tp.parkingFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP');
|
||||
|
||||
|
||||
UPDATE tmp.productionBuffer pb
|
||||
JOIN (
|
||||
SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking
|
||||
|
@ -1218,12 +1218,12 @@ proc: BEGIN
|
|||
JOIN sale s ON s.ticketFk = pb.ticketFk
|
||||
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||
JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
||||
JOIN parking p ON p.id = sg.parkingFk
|
||||
JOIN parking p ON p.id = sg.parkingFk
|
||||
GROUP BY pb.ticketFk
|
||||
) t ON t.ticketFk = pb.ticketFk
|
||||
SET pb.previaParking = t.previaParking;
|
||||
|
||||
-- Problemas por ticket
|
||||
-- Problemas por ticket
|
||||
ALTER TABLE tmp.productionBuffer
|
||||
CHANGE COLUMN `problem` `problem` VARCHAR(255),
|
||||
ADD COLUMN `collectionH` INT,
|
||||
|
@ -1380,20 +1380,409 @@ BEGIN
|
|||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
IF NEW.freightItemFk IS NOT NULL THEN
|
||||
IF NEW.freightItemFk IS NOT NULL THEN
|
||||
|
||||
UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk;
|
||||
|
||||
SELECT IFNULL(MAX(counter),0) +1 INTO intcounter
|
||||
FROM expedition e
|
||||
INNER JOIN ticket t1 ON e.ticketFk = t1.id
|
||||
SELECT IFNULL(MAX(counter),0) +1 INTO intcounter
|
||||
FROM expedition e
|
||||
INNER JOIN ticket t1 ON e.ticketFk = t1.id
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t1.id
|
||||
INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped)
|
||||
INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped)
|
||||
AND t1.warehouseFk = t2.warehouseFk
|
||||
WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk
|
||||
WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk
|
||||
AND t1.agencyModeFk = t2.agencyModeFk;
|
||||
|
||||
SET NEW.`counter` = intcounter;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT)
|
||||
proc: BEGIN
|
||||
/**
|
||||
* 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 vWarehouseFk SMALLINT;
|
||||
DECLARE vAgencyModeFk INT;
|
||||
DECLARE vAddressFk INT;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vIsEditable BOOLEAN;
|
||||
DECLARE vZoneFk INTEGER;
|
||||
DECLARE vDone BOOL DEFAULT FALSE;
|
||||
|
||||
DECLARE vCur CURSOR FOR
|
||||
SELECT DISTINCT s.ticketFk
|
||||
FROM tmp.recalculateSales rs
|
||||
JOIN vn.sale s ON s.id = rs.id;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
OPEN vCur;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
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
|
||||
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)
|
||||
WHERE t.id = vTicketFk AND t.landed IS NULL;
|
||||
|
||||
IF vZoneFk IS NULL THEN
|
||||
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
|
||||
UPDATE ticket t
|
||||
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 buyUltimate (vWarehouseFk, vShipped);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouseFk warehouseFk
|
||||
FROM sale s
|
||||
JOIN tmp.recalculateSales rs ON s.id = rs.id
|
||||
WHERE s.ticketFk = vTicketFk;
|
||||
|
||||
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
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketFk
|
||||
GROUP BY s.itemFk;
|
||||
|
||||
CALL catalog_componentPrepare();
|
||||
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
|
||||
|
||||
IF vOption IS NULL THEN
|
||||
SET vOption = IF(vIsEditable, 1, 6);
|
||||
END IF;
|
||||
|
||||
CALL ticketComponentUpdateSale(vOption);
|
||||
CALL catalog_componentPurge();
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
|
||||
END LOOP;
|
||||
CLOSE vCur;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`(
|
||||
vSerial VARCHAR(255),
|
||||
vInvoiceDate DATE,
|
||||
vTaxArea VARCHAR(25),
|
||||
OUT vNewInvoiceId INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Creación de facturas emitidas.
|
||||
* requiere previamente tabla tmp.ticketToInvoice(id).
|
||||
*
|
||||
* @param vSerial serie a la cual se hace la factura
|
||||
* @param vInvoiceDate fecha de la factura
|
||||
* @param vTaxArea tipo de iva en relacion a la empresa y al cliente
|
||||
* @param vNewInvoiceId id de la factura que se acaba de generar
|
||||
* @return vNewInvoiceId
|
||||
*/
|
||||
DECLARE vIsAnySaleToInvoice BOOL;
|
||||
DECLARE vIsAnyServiceToInvoice BOOL;
|
||||
DECLARE vNewRef VARCHAR(255);
|
||||
DECLARE vWorker INT DEFAULT account.myUser_getId();
|
||||
DECLARE vCompanyFk INT;
|
||||
DECLARE vInterCompanyFk INT;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
|
||||
DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
|
||||
DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2;
|
||||
DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
|
||||
DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S';
|
||||
DECLARE vNewInvoiceInFk INT;
|
||||
DECLARE vIsInterCompany BOOL DEFAULT FALSE;
|
||||
DECLARE vIsCEESerial BOOL DEFAULT FALSE;
|
||||
DECLARE vIsCorrectInvoiceDate BOOL;
|
||||
DECLARE vMaxShipped DATE;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vCursor CURSOR FOR
|
||||
SELECT id
|
||||
FROM tmp.ticketToInvoice;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE());
|
||||
|
||||
SELECT t.clientFk,
|
||||
t.companyFk,
|
||||
MAX(DATE(t.shipped)),
|
||||
DATE(vInvoiceDate) >= invoiceOut_getMaxIssued(
|
||||
vSerial,
|
||||
t.companyFk,
|
||||
YEAR(vInvoiceDate))
|
||||
INTO vClientFk,
|
||||
vCompanyFk,
|
||||
vMaxShipped,
|
||||
vIsCorrectInvoiceDate
|
||||
FROM tmp.ticketToInvoice tt
|
||||
JOIN ticket t ON t.id = tt.id;
|
||||
|
||||
IF(vMaxShipped > vInvoiceDate) THEN
|
||||
CALL util.throw("Invoice date can't be less than max date");
|
||||
END IF;
|
||||
|
||||
IF NOT vIsCorrectInvoiceDate THEN
|
||||
CALL util.throw('Exists an invoice with a previous date');
|
||||
END IF;
|
||||
|
||||
-- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats
|
||||
DELETE ti.*
|
||||
FROM tmp.ticketToInvoice ti
|
||||
JOIN ticket t ON t.id = ti.id
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk
|
||||
WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted)
|
||||
OR c.isTaxDataChecked = FALSE
|
||||
OR t.isDeleted
|
||||
OR c.hasToInvoice = FALSE
|
||||
OR itc.id IS NULL;
|
||||
|
||||
SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0
|
||||
INTO vIsAnySaleToInvoice
|
||||
FROM tmp.ticketToInvoice t
|
||||
JOIN sale s ON s.ticketFk = t.id;
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice
|
||||
FROM tmp.ticketToInvoice t
|
||||
JOIN ticketService ts ON ts.ticketFk = t.id;
|
||||
|
||||
IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice)
|
||||
AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase())
|
||||
THEN
|
||||
|
||||
-- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
|
||||
INSERT INTO invoiceOut(
|
||||
ref,
|
||||
serial,
|
||||
issued,
|
||||
clientFk,
|
||||
dued,
|
||||
companyFk,
|
||||
siiTypeInvoiceOutFk
|
||||
)
|
||||
SELECT
|
||||
1,
|
||||
vSerial,
|
||||
vInvoiceDate,
|
||||
vClientFk,
|
||||
getDueDate(vInvoiceDate, dueDay),
|
||||
vCompanyFk,
|
||||
IF(vSerial = vCorrectingSerial,
|
||||
vCplusCorrectingInvoiceTypeFk,
|
||||
IF(vSerial = vSimplifiedSerial,
|
||||
vCplusSimplifiedInvoiceTypeFk,
|
||||
vCplusStandardInvoiceTypeFk))
|
||||
FROM client
|
||||
WHERE id = vClientFk;
|
||||
|
||||
SET vNewInvoiceId = LAST_INSERT_ID();
|
||||
|
||||
SELECT `ref`
|
||||
INTO vNewRef
|
||||
FROM invoiceOut
|
||||
WHERE id = vNewInvoiceId;
|
||||
|
||||
OPEN vCursor;
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vCursor INTO vTicketFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
CALL ticket_recalc(vTicketFk, vTaxArea);
|
||||
|
||||
END LOOP;
|
||||
CLOSE vCursor;
|
||||
|
||||
UPDATE ticket t
|
||||
JOIN tmp.ticketToInvoice ti ON ti.id = t.id
|
||||
SET t.refFk = vNewRef;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
|
||||
CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
|
||||
SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
|
||||
FROM tmp.ticketToInvoice ti
|
||||
LEFT JOIN ticketState ts ON ti.id = ts.ticketFk
|
||||
JOIN state s
|
||||
WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id);
|
||||
|
||||
INSERT INTO ticketTracking(stateFk,ticketFk,userFk)
|
||||
SELECT * FROM tmp.updateInter;
|
||||
|
||||
CALL invoiceExpenseMake(vNewInvoiceId);
|
||||
CALL invoiceTaxMake(vNewInvoiceId,vTaxArea);
|
||||
|
||||
UPDATE invoiceOut io
|
||||
JOIN (
|
||||
SELECT SUM(amount) total
|
||||
FROM invoiceOutExpense
|
||||
WHERE invoiceOutFk = vNewInvoiceId
|
||||
) base
|
||||
JOIN (
|
||||
SELECT SUM(vat) total
|
||||
FROM invoiceOutTax
|
||||
WHERE invoiceOutFk = vNewInvoiceId
|
||||
) vat
|
||||
SET io.amount = base.total + vat.total
|
||||
WHERE io.id = vNewInvoiceId;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.updateInter;
|
||||
|
||||
SELECT COUNT(*), id
|
||||
INTO vIsInterCompany, vInterCompanyFk
|
||||
FROM company
|
||||
WHERE clientFk = vClientFk;
|
||||
|
||||
IF (vIsInterCompany) THEN
|
||||
|
||||
INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk)
|
||||
SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk;
|
||||
|
||||
SET vNewInvoiceInFk = LAST_INSERT_ID();
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
|
||||
CREATE TEMPORARY TABLE tmp.ticket
|
||||
(KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk
|
||||
FROM tmp.ticketToInvoice;
|
||||
|
||||
CALL `ticket_getTax`('NATIONAL');
|
||||
|
||||
SET @vTaxableBaseServices := 0.00;
|
||||
SET @vTaxCodeGeneral := NULL;
|
||||
|
||||
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk)
|
||||
SELECT vNewInvoiceInFk,
|
||||
@vTaxableBaseServices,
|
||||
sub.expenseFk,
|
||||
sub.taxTypeSageFk,
|
||||
sub.transactionTypeSageFk
|
||||
FROM (
|
||||
SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase,
|
||||
i.expenseFk,
|
||||
i.taxTypeSageFk,
|
||||
i.transactionTypeSageFk,
|
||||
@vTaxCodeGeneral := i.taxClassCodeFk
|
||||
FROM tmp.ticketServiceTax tst
|
||||
JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code
|
||||
WHERE i.isService
|
||||
HAVING taxableBase
|
||||
) sub;
|
||||
|
||||
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk)
|
||||
SELECT vNewInvoiceInFk,
|
||||
SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral,
|
||||
@vTaxableBaseServices, 0) taxableBase,
|
||||
i.expenseFk,
|
||||
i.taxTypeSageFk ,
|
||||
i.transactionTypeSageFk
|
||||
FROM tmp.ticketTax tt
|
||||
JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code
|
||||
WHERE !i.isService
|
||||
GROUP BY tt.pgcFk
|
||||
HAVING taxableBase
|
||||
ORDER BY tt.priority;
|
||||
|
||||
CALL invoiceInDueDay_calculate(vNewInvoiceInFk);
|
||||
|
||||
SELECT COUNT(*) INTO vIsCEESerial
|
||||
FROM invoiceOutSerial
|
||||
WHERE code = vSerial;
|
||||
|
||||
IF vIsCEESerial THEN
|
||||
|
||||
INSERT INTO invoiceInIntrastat (
|
||||
invoiceInFk,
|
||||
intrastatFk,
|
||||
amount,
|
||||
stems,
|
||||
countryFk,
|
||||
net)
|
||||
SELECT
|
||||
vNewInvoiceInFk,
|
||||
i.intrastatFk,
|
||||
SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))),
|
||||
SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))),
|
||||
su.countryFk,
|
||||
CAST(SUM(IFNULL(i.stems, 1)
|
||||
* s.quantity
|
||||
* IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2))
|
||||
FROM sale s
|
||||
JOIN ticket t ON s.ticketFk = t.id
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk
|
||||
WHERE t.refFk = vNewRef
|
||||
GROUP BY i.intrastatFk;
|
||||
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.ticketAmount;
|
||||
DROP TEMPORARY TABLE tmp.ticketTax;
|
||||
DROP TEMPORARY TABLE tmp.ticketServiceTax;
|
||||
END IF;
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -40,16 +40,19 @@ FROM (
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`ticketStateToday`
|
||||
AS SELECT `ts`.`ticketFk` AS `ticket`,
|
||||
`ts`.`state` AS `state`,
|
||||
`ts`.`productionOrder` AS `productionOrder`,
|
||||
`ts`.`alertLevel` AS `alertLevel`,
|
||||
`ts`.`userFk` AS `worker`,
|
||||
`ts`.`code` AS `code`,
|
||||
`ts`.`updated` AS `updated`,
|
||||
`ts`.`isPicked` AS `isPicked`
|
||||
FROM (
|
||||
`vn`.`ticketState` `ts`
|
||||
JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ts`.`ticketFk`)
|
||||
)
|
||||
WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`())
|
||||
AS
|
||||
SELECT
|
||||
`ts`.`ticketFk` AS `ticket`,
|
||||
`ts`.`state` AS `state`,
|
||||
`ts`.`productionOrder` AS `productionOrder`,
|
||||
`ts`.`alertLevel` AS `alertLevel`,
|
||||
`ts`.`userFk` AS `worker`,
|
||||
`ts`.`code` AS `code`,
|
||||
`ts`.`updated` AS `updated`,
|
||||
`ts`.`isPicked` AS `isPicked`
|
||||
FROM
|
||||
`vn`.`ticketState` `ts`
|
||||
JOIN `vn`.`ticket` `t` ON `t`.`id` = `ts`.`ticketFk`
|
||||
WHERE
|
||||
`t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`VN_CURDATE`() + INTERVAL 1 DAY;
|
||||
|
||||
|
|
Loading…
Reference in New Issue