7773-testToMaster_2430 #2774

Merged
alexm merged 368 commits from 7773-testToMaster_2430 into master 2024-07-23 06:21:03 +00:00
1 changed files with 31 additions and 26 deletions
Showing only changes of commit 6f0196d656 - Show all commits

View File

@ -6,13 +6,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(
) )
BEGIN BEGIN
/** /**
* Calcula el disponible. * Calcula el balance de un artículo.
* *
* @vItemFk Id de artículo * @vItemFk Id de artículo
* @vWarehouseFk Id de almacén * @vWarehouseFk Id de almacén
* @vDated Fecha * @vDated Fecha a calcular, si es NULL muestra el histórico desde el inventario
* Si la fecha es NULL, muestra el histórico desde el inventario.
* Si la fecha no es NULL, muestra histórico desde la fecha de vDated.
*/ */
DECLARE vDateInventory DATETIME; DECLARE vDateInventory DATETIME;
DECLARE vLifeScope DATE; DECLARE vLifeScope DATE;
@ -64,7 +62,8 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tItemDiary CREATE OR REPLACE TEMPORARY TABLE tItemDiary
ENGINE = MEMORY ENGINE = MEMORY
WITH entriesIn AS ( WITH entriesIn AS (
SELECT 'entry' `type`, SELECT 'entry' originType,
e.id origin,
tr.landed shipped, tr.landed shipped,
b.quantity `in`, b.quantity `in`,
NULL `out`, NULL `out`,
@ -72,8 +71,8 @@ BEGIN
st.name stateName, st.name stateName,
s.name `name`, s.name `name`,
e.invoiceNumber reference, e.invoiceNumber reference,
e.id origin, 'supplier' entityType,
s.id clientFk, s.id entity,
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
FALSE isTicket, FALSE isTicket,
b.id lineFk, b.id lineFk,
@ -98,6 +97,7 @@ BEGIN
), ),
entriesOut AS ( entriesOut AS (
SELECT 'entry', SELECT 'entry',
e.id originType,
tr.shipped, tr.shipped,
NULL, NULL,
b.quantity, b.quantity,
@ -105,8 +105,8 @@ BEGIN
st.name stateName, st.name stateName,
s.name, s.name,
e.invoiceNumber, e.invoiceNumber,
e.id entryFk, 'supplier' entityType,
s.id supplierFk, s.id entity,
IF(st.`code` = 'DELIVERED' , TRUE, FALSE), IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
FALSE isTicket, FALSE isTicket,
b.id, b.id,
@ -123,7 +123,6 @@ BEGIN
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
'DELIVERED', 'DELIVERED',
'FREE') 'FREE')
JOIN vn.entryConfig ec
WHERE tr.shipped >= vDateInventory WHERE tr.shipped >= vDateInventory
AND vWarehouseFk = tr.warehouseOutFk AND vWarehouseFk = tr.warehouseOutFk
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
@ -141,7 +140,8 @@ BEGIN
t.nickname, t.nickname,
t.refFk, t.refFk,
t.id ticketFk, t.id ticketFk,
t.clientFk, 'client' entityType,
t.clientFk entity,
s.id saleFk, s.id saleFk,
st.`order`, st.`order`,
c.typeFk, c.typeFk,
@ -162,6 +162,7 @@ BEGIN
AND vWarehouseFk = t.warehouseFk AND vWarehouseFk = t.warehouseFk
) )
SELECT 'ticket', SELECT 'ticket',
s.ticketFk,
s.shipped, s.shipped,
NULL `in`, NULL `in`,
s.quantity, s.quantity,
@ -169,8 +170,8 @@ BEGIN
s.name, s.name,
s.nickname, s.nickname,
s.refFk, s.refFk,
s.ticketFk, s.entityType,
s.clientFk, s.entity,
IF(stk.saleFk, TRUE, FALSE), IF(stk.saleFk, TRUE, FALSE),
TRUE, TRUE,
s.saleFk, s.saleFk,
@ -185,7 +186,8 @@ BEGIN
GROUP BY s.saleFk GROUP BY s.saleFk
), ),
orders AS ( orders AS (
SELECT 'order' `type`, SELECT 'order' originType,
o.id origin,
r.shipment, r.shipment,
NULL 'in', NULL 'in',
r.amount, r.amount,
@ -193,7 +195,7 @@ BEGIN
NULL stateName, NULL stateName,
c.name, c.name,
NULL invoiceNumber, NULL invoiceNumber,
o.id origin, 'client' entityType,
c.id, c.id,
FALSE, FALSE,
FALSE isTicket, FALSE isTicket,
@ -220,7 +222,7 @@ BEGIN
UNION ALL UNION ALL
SELECT * FROM orders SELECT * FROM orders
ORDER BY shipped, ORDER BY shipped,
(inventorySupplierFk = clientFk) DESC, (inventorySupplierFk = entity) DESC,
alertLevel DESC, alertLevel DESC,
isTicket, isTicket,
`order` DESC, `order` DESC,
@ -233,13 +235,14 @@ BEGIN
SET @currentLineFk := 0; SET @currentLineFk := 0;
SET @shipped := ''; SET @shipped := '';
SELECT t.type, SELECT t.originType,
t.origin,
DATE(@shipped:= t.shipped) shipped, DATE(@shipped:= t.shipped) shipped,
t.alertLevel, t.alertLevel,
t.stateName, t.stateName,
t.origin,
t.reference, t.reference,
t.clientFk, t.entityType,
t.entity,
t.name, t.name,
t.`in` invalue, t.`in` invalue,
t.`out`, t.`out`,
@ -261,13 +264,14 @@ BEGIN
FROM tItemDiary FROM tItemDiary
WHERE shipped < vDated; WHERE shipped < vDated;
SELECT NULL `type`, SELECT NULL originType,
NULL origin,
vDated shipped, vDated shipped,
NULL alertLevel, NULL alertLevel,
NULL stateName, NULL stateName,
NULL origin,
NULL reference, NULL reference,
NULL clientFk, NULL entityType,
NULL entity,
'Inventario calculado', 'Inventario calculado',
@a invalue, @a invalue,
NULL `out`, NULL `out`,
@ -280,13 +284,14 @@ BEGIN
NULL claimFk, NULL claimFk,
NULL `order` NULL `order`
UNION ALL UNION ALL
SELECT `type`, SELECT originType,
origin,
shipped, shipped,
alertlevel, alertlevel,
stateName, stateName,
origin, reference,
reference, entityType,
clientFk, entity,
name, `in`, name, `in`,
`out`, `out`,
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),