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