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

17 lines
1.6 KiB
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 REPLACE VIEW public."Prc_V_MaterialRequestTransferItem" AS
SELECT d."Id"::text || '|' || i."Id"::text 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" IS NOT DISTINCT FROM d."TenantId"
INNER JOIN "Prc_T_MaterialRequestItem" i ON i."MaterialRequestId" = r."Id"
WHERE d."IsDeleted" = false AND d."OperationKind" = 'InternalTransfer' AND d."Status" = 'Draft'
AND r."IsDeleted" = false AND i."IsDeleted" = false
AND r."ApprovalStatus" IN ('Onaylandı', 'Teklif Talebi', 'Teklif Talebi Gönderildi', '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" = false
AND t."IsDeleted" = false AND t."Status" NOT IN ('Done', 'Cancelled'));