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

18 lines
1.5 KiB
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 REPLACE VIEW public."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 numeric(18, 4)) AS "UnitPrice", o."CurrencyId",
CAST(ROUND(l."Quantity" * ol."UnitPrice" * f."Factor", 2) AS numeric(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"
LEFT JOIN LATERAL (SELECT public."Stk_F_UomConvert"(1, l."UomId", ol."UomId") AS "Factor" WHERE ol."Id" IS NOT NULL) f ON TRUE
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" = FALSE AND l."Quantity" > 0 AND t."OperationKind" = 'Receipt' AND t."Status" = 'Done' AND t."ReturnOfId" IS NULL;