sozsoft-platform/configs/seeds/postgres/object/Inv_P_TransferImportItem.sql
2026-10-13 00:43:05 +03:00

21 lines
1.4 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Talepten Aktar: seçilen malzeme talebi kalemini (p_key = belge|kalem) taslak iç transfere satır olarak ekler; kalanı (talep − teslim) aktarılır.
-- Belgenin hedef konumu boşsa talebin konumu yazılır.
CREATE OR REPLACE PROCEDURE public."Inv_P_TransferImportItem"(p_key varchar)
LANGUAGE plpgsql AS $$
DECLARE v_doc uuid; v_tenant uuid; v_item uuid; v_product uuid; v_description varchar(256); v_quantity numeric(18, 4); v_uom varchar(64); v_location uuid;
BEGIN
SELECT "BaseId", "TenantId", "MaterialRequestItemId", "ProductId", "RequestReason", "Quantity", "UomId", "LocationId"
INTO v_doc, v_tenant, v_item, v_product, v_description, v_quantity, v_uom, v_location
FROM "Prc_V_MaterialRequestTransferItem"
WHERE "Id" = p_key;
IF v_doc IS NULL THEN
RAISE EXCEPTION 'Talep kalemi artık aktarılamaz: belge taslak değil, kalem başka bir transfere aktarılmış ya da talep değişmiş.' USING ERRCODE = 'P0001', DETAIL = '50319';
END IF;
INSERT INTO "Inv_T_TransferLine" ("Id", "TenantId", "TransferId", "ProductId", "Description", "DemandQuantity", "Quantity", "UomId", "MaterialRequestItemId", "CreationTime", "IsDeleted")
VALUES (gen_random_uuid(), v_tenant, v_doc, v_product, v_description, v_quantity, 0, v_uom, v_item, NOW() AT TIME ZONE 'UTC', false);
UPDATE "Inv_T_Transfer" SET "DestinationLocationId" = COALESCE("DestinationLocationId", v_location) WHERE "Id" = v_doc;
CALL public."Inv_P_TransferRecalc"(v_doc);
END;
$$;