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

17 lines
1.5 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.

-- İç transfere aktarılabilecek talep kalemleri: onaylı talebin transferle karşılanacak, bekleyen ve açık bir transferde yer almayan
-- kalemi, aynı şubedeki taslak iç transfer belgesiyle eşlenir. Id = belge|kalem; Talepten Aktar seçilen satırları Inv_P_TransferImportItem ile ekler.
CREATE OR ALTER VIEW [dbo].[Prc_V_MaterialRequestTransferItem] AS
SELECT CONCAT(CAST(d.Id AS nvarchar(36)), '|', CAST(i.Id AS nvarchar(36))) AS Id, d.Id AS BaseId, i.TenantId, i.Id AS MaterialRequestItemId,
i.MaterialRequestId, r.RequestNo, r.RequesterUserId, i.ProductId, i.Quantity - i.DeliveredQuantity AS Quantity, i.UomId,
i.RequestReason, i.DueDate, r.WarehouseId, r.LocationId
FROM Inv_T_Transfer d
INNER JOIN Prc_T_MaterialRequest r ON r.BranchId = d.BranchId AND (r.TenantId = d.TenantId OR (r.TenantId IS NULL AND d.TenantId IS NULL))
INNER JOIN Prc_T_MaterialRequestItem i ON i.MaterialRequestId = r.Id
WHERE d.IsDeleted = 0 AND d.OperationKind = 'InternalTransfer' AND d.Status = 'Draft'
AND r.IsDeleted = 0 AND i.IsDeleted = 0
AND r.ApprovalStatus IN (N'Onaylandı', N'Teklif Talebi', N'Teklif Talebi Gönderildi', N'Satınalma Siparişi')
AND i.FulfillmentMethod = 'Transfer' AND i.LineStatus = 'Waiting' AND i.Quantity > i.DeliveredQuantity
AND NOT EXISTS (SELECT 1 FROM Inv_T_TransferLine tl
INNER JOIN Inv_T_Transfer t ON t.Id = tl.TransferId
WHERE tl.MaterialRequestItemId = i.Id AND tl.IsDeleted = 0
AND t.IsDeleted = 0 AND t.Status NOT IN ('Done', 'Cancelled'))