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

11 lines
768 B
Transact-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 ALTER VIEW [dbo].[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 = 0
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 = 0
AND o.IsDeleted = 0 AND o.Status <> 'Cancelled')) AS ImportableCount
FROM Prc_T_MaterialRequest r
WHERE r.IsDeleted = 0 AND r.ApprovalStatus = N'Onaylandı'