refs #6769 Changes, with error no database selected

This commit is contained in:
Guillermo Bonet 2024-07-04 11:34:55 +02:00
parent a7895ab0a4
commit cf7de14de6
1 changed files with 38 additions and 57 deletions

View File

@ -61,29 +61,11 @@ BEGIN
JOIN itemType it ON it.id = i.typeFk
HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL;
CREATE OR REPLACE TEMPORARY TABLE tItemDiary(
shipped DATE,
`in` INT(11),
`out` INT(11),
alertLevel INT(11),
stateName VARCHAR(20),
`name` VARCHAR(50),
reference VARCHAR(50),
origin INT(11),
clientFk INT(11),
isPicked INT(11),
isTicket TINYINT(1),
lineFk INT(11),
`order` TINYINT(3) UNSIGNED,
clientType VARCHAR(20),
claimFk INT(10) UNSIGNED,
inventorySupplierFk INT(10),
orderFk INT(10) UNSIGNED
) ENGINE = MEMORY;
INSERT INTO tItemDiary
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
ENGINE = MEMORY
WITH entriesIn AS (
SELECT tr.landed shipped,
SELECT 'entry' `type`,
tr.landed shipped,
b.quantity `in`,
NULL `out`,
st.alertLevel ,
@ -98,8 +80,7 @@ BEGIN
NULL `order`,
NULL clientType,
NULL claimFk,
vSupplierInventoryFk inventorySupplierFk,
NULL orderFk
vSupplierInventoryFk inventorySupplierFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
@ -116,7 +97,8 @@ BEGIN
AND NOT e.isRaid
),
entriesOut AS (
SELECT tr.shipped,
SELECT 'entry',
tr.shipped,
NULL,
b.quantity,
st.alertLevel,
@ -131,8 +113,7 @@ BEGIN
NULL `order`,
NULL clientType,
NULL claimFk,
vSupplierInventoryFk,
NULL orderFk
vSupplierInventoryFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
@ -180,7 +161,8 @@ BEGIN
AND s.itemFk = vItemFk
AND vWarehouseFk = t.warehouseFk
)
SELECT s.shipped,
SELECT 'ticket',
s.shipped,
NULL `in`,
s.quantity,
s.alertLevel,
@ -195,8 +177,7 @@ BEGIN
s.`order`,
s.typeFk,
s.claimFk,
NULL,
NULL orderFk
NULL
FROM itemSales s
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
@ -204,23 +185,23 @@ BEGIN
GROUP BY s.saleFk
),
orders AS (
SELECT r.shipment,
SELECT 'order' `type`,
r.shipment,
NULL 'in',
r.amount,
NULL alertLevel,
NULL stateName,
NULL,
c.name,
NULL invoiceNumber,
NULL entryFk,
NULL supplierFk,
o.id origin,
c.id,
FALSE,
FALSE isTicket,
NULL buyFk,
NULL 'order',
c.typeFk,
NULL claimFk,
NULL inventorySupplierFk,
o.id
NULL
FROM hedera.orderRow r
JOIN hedera.`order` o ON o.id = r.orderFk
JOIN tItemRange ir ON ir.itemFk = r.itemFk
@ -252,7 +233,8 @@ BEGIN
SET @currentLineFk := 0;
SET @shipped := '';
SELECT DATE(@shipped:= t.shipped) shipped,
SELECT t.type,
DATE(@shipped:= t.shipped) shipped,
t.alertLevel,
t.stateName,
t.origin,
@ -271,8 +253,7 @@ BEGIN
t.isPicked,
t.clientType,
t.claimFk,
t.`order`,
t.orderFk
t.`order`
FROM tItemDiary t
LEFT JOIN alertLevel a ON a.id = t.alertLevel;
ELSE
@ -280,26 +261,27 @@ BEGIN
FROM tItemDiary
WHERE shipped < vDated;
SELECT vDated shipped,
0 alertLevel,
0 stateName,
0 origin,
'' reference,
0 clientFk,
SELECT NULL `type`,
vDated shipped,
NULL alertLevel,
NULL stateName,
NULL origin,
NULL reference,
NULL clientFk,
'Inventario calculado',
@a invalue,
NULL `out`,
@a balance,
0 lastPreparedLineFk,
0 isTicket,
0 lineFk,
0 isPicked,
0 clientType,
0 claimFk,
NULL `order`,
0 orderFk
NULL lastPreparedLineFk,
NULL isTicket,
NULL lineFk,
NULL isPicked,
NULL clientType,
NULL claimFk,
NULL `order`
UNION ALL
SELECT shipped,
SELECT `type`,
shipped,
alertlevel,
stateName,
origin,
@ -314,8 +296,7 @@ BEGIN
isPicked,
clientType,
claimFk,
`order`,
orderFk
`order`
FROM tItemDiary
WHERE shipped >= vDated;
END IF;