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

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

-- 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 ALTER VIEW [dbo].[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 = 0 AND r.IsDeleted = 0
AND r.ApprovalStatus = N'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 = 0
AND q.IsDeleted = 0 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 = 0
AND o.IsDeleted = 0 AND o.Status <> 'Cancelled')