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

17 lines
695 B
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.

-- Numarası olmayan transfer belgesine operasyon türünün numaratöründen (Inv_T_OperationType.SequenceName) numara verir.
CREATE OR REPLACE PROCEDURE public."Inv_P_TransferNumber"(p_id uuid)
LANGUAGE plpgsql AS $$
DECLARE v_seq varchar(128); v_tenant uuid; v_no varchar(128);
BEGIN
SELECT ot."SequenceName", t."TenantId" INTO v_seq, v_tenant
FROM "Inv_T_Transfer" t
INNER JOIN "Inv_T_OperationType" ot ON ot."Id" = t."OperationTypeId"
WHERE t."Id" = p_id AND t."TransferNo" IS NULL;
IF v_seq IS NULL THEN
RETURN;
END IF;
CALL public."Adm_P_SequenceNext"(v_seq, v_tenant, v_no);
UPDATE "Inv_T_Transfer" SET "TransferNo" = left(v_no, 32) WHERE "Id" = p_id;
END;
$$;