sozsoft-platform/configs/seeds/postgres/object/Prc_P_MaterialRequestPlanConfirm.sql
2026-10-14 22:26:03 +03:00

29 lines
1.5 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.

-- Planla diyaloğunun Onayla'sı (App.Prc.MaterialRequestPlan › UpdateCommand): talep kaleminin taslak planındaki her satırı
-- Prc_P_MaterialRequestPlan ile belgeye çevirir (önce iç transferler ve Stoktan, sonra teklif talepleri) ve taslağı siler. Tek transaction'dır:
-- bir satır reddedilirse (stok, kalan, operasyon türü) hiçbir belge açılmaz ve taslak yerinde kalır.
CREATE OR REPLACE PROCEDURE public."Prc_P_MaterialRequestPlanConfirm"(
p_id uuid,
p_tenant_id uuid,
p_last_modifier_id uuid
)
LANGUAGE plpgsql AS $$
DECLARE r record;
BEGIN
PERFORM 1 FROM "Prc_T_MaterialRequestPlanLine" WHERE "MaterialRequestItemId" = p_id AND "IsDeleted" = false FOR UPDATE;
IF NOT FOUND THEN
RAISE EXCEPTION 'Onaylanacak taslak plan yok: önce Öner butonunu kullanın ya da İç Transfer veya Satınalma sekmesinde Plan Miktarı girin.'
USING ERRCODE = 'P0001', DETAIL = '50201';
END IF;
FOR r IN SELECT "PlanMethod", "Quantity", "SupplierId", "SourceLocationId", "LotNo"
FROM "Prc_T_MaterialRequestPlanLine"
WHERE "MaterialRequestItemId" = p_id AND "IsDeleted" = false
ORDER BY CASE "PlanMethod" WHEN 'Transfer' THEN 0 WHEN 'Stock' THEN 1 ELSE 2 END, "CreationTime"
LOOP
CALL public."Prc_P_MaterialRequestPlan"(p_id, r."PlanMethod", r."Quantity", r."SupplierId", r."SourceLocationId", r."LotNo",
p_tenant_id, p_last_modifier_id);
END LOOP;
DELETE FROM "Prc_T_MaterialRequestPlanLine" WHERE "MaterialRequestItemId" = p_id;
END;
$$;