sozsoft-platform/configs/seeds/postgres/object/Prc_V_MaterialRequestAvailableItem.sql
2026-10-11 22:57:23 +03:00

18 lines
1.3 KiB
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.

-- Teklife ya da siparişe aktarılabilecek talep kalemleri: onaylı talebin satınalma ile karşılanacak,
-- bekleyen ve iptal olmayan bir teklif/siparişte yer almayan kalemi. Aktarım ve talep seçimi buradan okur.
CREATE OR REPLACE VIEW public."Prc_V_MaterialRequestAvailableItem" AS
SELECT i."Id", i."TenantId", i."MaterialRequestId", r."RequestNo", r."RequesterUserId", i."ProductId", i."Quantity", i."UomId",
i."RequestReason", i."DueDate"
FROM "Prc_T_MaterialRequestItem" i
INNER JOIN "Prc_T_MaterialRequest" r ON r."Id" = i."MaterialRequestId"
WHERE i."IsDeleted" = false AND r."IsDeleted" = false
AND r."ApprovalStatus" = 'Onaylandı'
AND i."FulfillmentMethod" = 'Purchase' AND i."LineStatus" = 'Waiting'
AND NOT EXISTS (SELECT 1 FROM "Prc_T_PurchaseRfqLine" rl
INNER JOIN "Prc_T_PurchaseRfq" q ON q."Id" = rl."PurchaseRfqId"
WHERE rl."MaterialRequestItemId" = i."Id" AND rl."IsDeleted" = false
AND q."IsDeleted" = false AND q."Status" <> 'Cancelled')
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');