Merge pull request 'refactor(database): organizar scripts SQL en estructura Database' (#20) from refactor/leandro/19-database-structure into master
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 1m56s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 1m56s
Reviewed-on: http://saludlab.com.ar:3000/leandro/phronCare/pulls/20
This commit is contained in:
commit
109ef556b9
@ -0,0 +1,44 @@
|
|||||||
|
USE [phronCare_OperationsHub]
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- =============================================
|
||||||
|
-- Procedure: PhLSM_Expedition_CheckStockItemConflicts
|
||||||
|
-- Module: Logistics / Stock (PhLSM)
|
||||||
|
-- Purpose: Detect serialized stock items already assigned
|
||||||
|
-- to active expeditions.
|
||||||
|
-- Author: Leandro Rojas
|
||||||
|
-- Created: 2026-03-05
|
||||||
|
-- =============================================
|
||||||
|
|
||||||
|
ALTER PROCEDURE [dbo].[PhLSM_Expedition_CheckStockItemConflicts]
|
||||||
|
(
|
||||||
|
@StockItemIds dbo.PhLSM_StockItemIdList READONLY,
|
||||||
|
@IgnoreExpeditionId INT = NULL
|
||||||
|
)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
d.stockitem_id AS StockitemId,
|
||||||
|
h.id AS ExpeditionId,
|
||||||
|
h.expeditionnumber AS Expeditionnumber,
|
||||||
|
h.status AS Status
|
||||||
|
FROM dbo.PhLSM_ExpeditionDetails d
|
||||||
|
INNER JOIN @StockItemIds ids
|
||||||
|
ON ids.stockitem_id = d.stockitem_id
|
||||||
|
INNER JOIN dbo.PhLSM_ExpeditionHeaders h
|
||||||
|
ON h.id = d.expedition_id
|
||||||
|
INNER JOIN dbo.PhLSM_StockItem si
|
||||||
|
ON si.id = d.stockitem_id
|
||||||
|
WHERE h.status NOT IN (5,6) -- 5=Cerrada, 6=Anulada
|
||||||
|
AND (@IgnoreExpeditionId IS NULL OR h.id <> @IgnoreExpeditionId)
|
||||||
|
AND si.serial IS NOT NULL
|
||||||
|
AND LTRIM(RTRIM(si.serial)) <> '';
|
||||||
|
END
|
||||||
|
GO
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
USE [phronCare_OperationsHub]
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- =============================================
|
||||||
|
-- Procedure: PhLSM_Stock_GetAvailabilityByStockItemIds
|
||||||
|
-- Module: Logistics / Stock (PhLSM)
|
||||||
|
-- Purpose: Returns quantity and availability data
|
||||||
|
-- for the requested stock items.
|
||||||
|
-- Author: Leandro Rojas
|
||||||
|
-- Created: 2026-03-09
|
||||||
|
-- =============================================
|
||||||
|
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[PhLSM_Stock_GetAvailabilityByStockItemIds]
|
||||||
|
(
|
||||||
|
@StockItemIds dbo.PhLSM_StockItemIdList READONLY
|
||||||
|
)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
si.id AS StockitemId,
|
||||||
|
si.quantity AS Quantity,
|
||||||
|
ISNULL(si.reserved_quantity, 0) AS ReservedQuantity,
|
||||||
|
si.quantity - ISNULL(si.reserved_quantity, 0) AS AvailableQuantity,
|
||||||
|
si.serial AS Serial
|
||||||
|
FROM dbo.PhLSM_StockItem si
|
||||||
|
INNER JOIN @StockItemIds ids
|
||||||
|
ON ids.stockitem_id = si.id;
|
||||||
|
END
|
||||||
|
GO
|
||||||
5
Database/Types/PhLSM_StockItemIdList.sql
Normal file
5
Database/Types/PhLSM_StockItemIdList.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TYPE dbo.PhLSM_StockItemIdList AS TABLE
|
||||||
|
(
|
||||||
|
stockitem_id INT NOT NULL
|
||||||
|
);
|
||||||
|
GO
|
||||||
135
Database/Verifications/Story 9 - Stock Reservation.sql
Normal file
135
Database/Verifications/Story 9 - Stock Reservation.sql
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/* =========================================================
|
||||||
|
VERIFICACIÓN STORY #9
|
||||||
|
Expedición -> EnTransito + reservas de stock
|
||||||
|
========================================================= */
|
||||||
|
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
|
DECLARE @ExpeditionNumber VARCHAR(50) = 'X-00000054'; -- cambiar
|
||||||
|
|
||||||
|
DECLARE @ExpeditionId INT;
|
||||||
|
|
||||||
|
SELECT @ExpeditionId = id
|
||||||
|
FROM dbo.PhLSM_ExpeditionHeaders
|
||||||
|
WHERE expeditionnumber = @ExpeditionNumber;
|
||||||
|
|
||||||
|
IF @ExpeditionId IS NULL
|
||||||
|
BEGIN
|
||||||
|
RAISERROR('Expedición no encontrada',16,1);
|
||||||
|
RETURN;
|
||||||
|
END
|
||||||
|
|
||||||
|
PRINT 'ExpeditionId: ' + CAST(@ExpeditionId AS VARCHAR);
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 1. CABECERA
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== CABECERA =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
expeditionnumber,
|
||||||
|
issuedate,
|
||||||
|
status,
|
||||||
|
observations
|
||||||
|
FROM dbo.PhLSM_ExpeditionHeaders
|
||||||
|
WHERE id = @ExpeditionId;
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 2. DETALLES
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== DETALLES =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
d.id,
|
||||||
|
d.expedition_id,
|
||||||
|
d.product_id,
|
||||||
|
d.stockitem_id,
|
||||||
|
d.quantity,
|
||||||
|
d.batch,
|
||||||
|
d.serial,
|
||||||
|
d.expiration
|
||||||
|
FROM dbo.PhLSM_ExpeditionDetails d
|
||||||
|
WHERE d.expedition_id = @ExpeditionId
|
||||||
|
ORDER BY d.id;
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 3. RESERVAS CREADAS
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== RESERVAS =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
r.id,
|
||||||
|
r.source_type,
|
||||||
|
r.source_id,
|
||||||
|
r.stockitem_id,
|
||||||
|
r.reserved_quantity,
|
||||||
|
r.status,
|
||||||
|
r.createdat
|
||||||
|
FROM dbo.PhLSM_StockReservation r
|
||||||
|
WHERE r.source_type = 1
|
||||||
|
AND r.source_id = @ExpeditionId
|
||||||
|
ORDER BY r.id;
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 4. STOCK ITEMS AFECTADOS
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== STOCK ITEMS =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
si.id,
|
||||||
|
si.product_id,
|
||||||
|
si.location_id,
|
||||||
|
si.quantity,
|
||||||
|
si.reserved_quantity,
|
||||||
|
(si.quantity - si.reserved_quantity) AS available
|
||||||
|
FROM dbo.PhLSM_StockItem si
|
||||||
|
WHERE si.id IN
|
||||||
|
(
|
||||||
|
SELECT stockitem_id
|
||||||
|
FROM dbo.PhLSM_ExpeditionDetails
|
||||||
|
WHERE expedition_id = @ExpeditionId
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 5. VALIDACIÓN DETALLE VS RESERVA
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== VALIDACION =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
d.id AS detail_id,
|
||||||
|
d.stockitem_id,
|
||||||
|
d.quantity AS requested,
|
||||||
|
r.reserved_quantity,
|
||||||
|
CASE
|
||||||
|
WHEN r.id IS NULL THEN 'FALTA RESERVA'
|
||||||
|
WHEN r.reserved_quantity <> d.quantity THEN 'CANTIDAD DISTINTA'
|
||||||
|
ELSE 'OK'
|
||||||
|
END AS resultado
|
||||||
|
FROM dbo.PhLSM_ExpeditionDetails d
|
||||||
|
LEFT JOIN dbo.PhLSM_StockReservation r
|
||||||
|
ON r.source_id = d.expedition_id
|
||||||
|
AND r.stockitem_id = d.stockitem_id
|
||||||
|
AND r.source_type = 1
|
||||||
|
AND r.status = 1
|
||||||
|
WHERE d.expedition_id = @ExpeditionId;
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------
|
||||||
|
-- 6. CHEQUEO DE DUPLICADOS
|
||||||
|
-------------------------------------------------------------
|
||||||
|
PRINT '===== DUPLICADOS =====';
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
stockitem_id,
|
||||||
|
COUNT(*) AS cantidad
|
||||||
|
FROM dbo.PhLSM_StockReservation
|
||||||
|
WHERE source_type = 1
|
||||||
|
AND source_id = @ExpeditionId
|
||||||
|
AND status = 1
|
||||||
|
GROUP BY stockitem_id
|
||||||
|
HAVING COUNT(*) > 1;
|
||||||
@ -43,6 +43,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1.5 Documents", "1.5 Docume
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Documents", "Documents\Documents.csproj", "{0EFF27D3-C585-49F3-BBB5-A5E99C52207B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Documents", "Documents\Documents.csproj", "{0EFF27D3-C585-49F3-BBB5-A5E99C52207B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.Database", "2.Database", "{F2A11E71-67B2-4317-9B15-ACF4C6105977}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.1 Procedures", "2.1 Procedures", "{BF5DC4E5-3589-4C44-AEC2-003681662271}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
Database\Procedures\PhLSM_Expedition_CheckStockItemConflicts.sql = Database\Procedures\PhLSM_Expedition_CheckStockItemConflicts.sql
|
||||||
|
Database\Procedures\PhLSM_Stock_GetAvailabilityByStockItemIds.sql = Database\Procedures\PhLSM_Stock_GetAvailabilityByStockItemIds.sql
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.2 Types", "2.2 Types", "{4B63D597-685C-463F-A909-BEADFA80235E}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
Database\Types\PhLSM_StockItemIdList.sql = Database\Types\PhLSM_StockItemIdList.sql
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.3 Verifications", "2.3 Verifications", "{E410D955-5A7B-4FD1-8D07-6DD9B3B9323A}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
Database\Verifications\Story 9 - Stock Reservation.sql = Database\Verifications\Story 9 - Stock Reservation.sql
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -104,6 +122,9 @@ Global
|
|||||||
{34FC5538-4779-41F5-8355-7866B1395A4F} = {13328F60-28A6-446D-9935-23866F3F3D9D}
|
{34FC5538-4779-41F5-8355-7866B1395A4F} = {13328F60-28A6-446D-9935-23866F3F3D9D}
|
||||||
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {74280C0B-F2CC-4A3E-86D6-05530F9766D5}
|
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {74280C0B-F2CC-4A3E-86D6-05530F9766D5}
|
||||||
{0EFF27D3-C585-49F3-BBB5-A5E99C52207B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
{0EFF27D3-C585-49F3-BBB5-A5E99C52207B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||||
|
{BF5DC4E5-3589-4C44-AEC2-003681662271} = {F2A11E71-67B2-4317-9B15-ACF4C6105977}
|
||||||
|
{4B63D597-685C-463F-A909-BEADFA80235E} = {F2A11E71-67B2-4317-9B15-ACF4C6105977}
|
||||||
|
{E410D955-5A7B-4FD1-8D07-6DD9B3B9323A} = {F2A11E71-67B2-4317-9B15-ACF4C6105977}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {92DE3FEB-7D7E-4C78-BE8C-34931CA1DAED}
|
SolutionGuid = {92DE3FEB-7D7E-4C78-BE8C-34931CA1DAED}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user