sozsoft-platform/configs/seeds/sql/object/Prc_V_PurchaseReceiptLine.sql
2026-10-19 17:35:08 +03:00

19 lines
1.4 KiB
Transact-SQL
Raw Permalink 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_PurchaseReceiptLine]
AS
-- Planlama › Son Alımlar'ın kaynağı: tamamlanan alımların (iade hariç) yapılan satırları; siparişsiz alım da gelir.
-- Fiyat ve para birimi yalnız siparişli satırda dolar: sipariş birim fiyatı alım satırının birimine çevrilir.
-- Prc öneki migrate sırası içindir (Prc_T_* tablolarından sonra kurulur).
SELECT l.Id, t.TenantId, t.IsDeleted, l.ProductId, t.Id AS TransferId, t.TransferNo, t.EffectiveDate, t.PartnerId,
t.BranchId, t.WarehouseId, t.DestinationLocationId, l.Quantity, l.UomId,
CAST(ROUND(ol.UnitPrice * f.Factor, 4) AS decimal(18, 4)) AS UnitPrice, o.CurrencyId,
CAST(ROUND(l.Quantity * ol.UnitPrice * f.Factor, 2) AS decimal(18, 2)) AS UntaxedAmount,
o.Id AS PurchaseOrderId, o.OrderNo, m.RequestNo
FROM Stk_T_TransferLine l
INNER JOIN Stk_T_Transfer t ON t.Id = l.TransferId
LEFT JOIN Prc_T_PurchaseOrderLine ol ON ol.Id = l.PurchaseOrderLineId
LEFT JOIN Prc_T_PurchaseOrder o ON o.Id = ol.PurchaseOrderId
OUTER APPLY (SELECT dbo.Stk_F_UomConvert(1, l.UomId, ol.UomId) AS Factor WHERE ol.Id IS NOT NULL) f
LEFT JOIN Prc_T_MaterialRequestItem i ON i.Id = COALESCE(l.MaterialRequestItemId, ol.MaterialRequestItemId)
LEFT JOIN Prc_T_MaterialRequest m ON m.Id = i.MaterialRequestId
WHERE l.IsDeleted = 0 AND l.Quantity > 0 AND t.OperationKind = 'Receipt' AND t.Status = 'Done' AND t.ReturnOfId IS NULL;
GO