sozsoft-platform/configs/seeds/postgres/object/Prc_V_MaterialRequestImportable.sql
2026-10-11 17:01:11 +03:00

11 lines
835 B
SQL
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.

CREATE OR REPLACE VIEW public."Prc_V_MaterialRequestImportable" AS
SELECT r."Id", r."TenantId", r."RequestNo", r."RequesterUserId", r."RequestDate",
(SELECT COUNT(*) FROM "Prc_T_MaterialRequestItem" i
WHERE i."MaterialRequestId" = r."Id" AND i."IsDeleted" = false
AND i."FulfillmentMethod" = 'Purchase' AND i."LineStatus" = 'Waiting'
AND NOT EXISTS (SELECT 1 FROM "Prc_T_PurchaseOrderLine" ol
INNER JOIN "Prc_T_PurchaseOrder" o ON o."Id" = ol."PurchaseOrderId"
WHERE ol."MaterialRequestItemId" = i."Id" AND ol."IsDeleted" = false
AND o."IsDeleted" = false AND o."Status" <> 'Cancelled')) AS "ImportableCount"
FROM "Prc_T_MaterialRequest" r
WHERE r."IsDeleted" = false AND r."ApprovalStatus" = 'Onaylandı';