24 lines
2 KiB
MySQL
24 lines
2 KiB
MySQL
|
|
-- Planlama (App.Prc.MaterialRequestPlan): onaylanmış (satınalmada ilerleyen dahil) talebin bekleyen ve planlanacak miktarı kalan kalemleri.
|
|||
|
|
-- Stok bütün iç konumların toplamıdır (kalemin biriminde); DueState termin süzgecidir (Late / Week = 7 gün içinde / Later). Taslak Plan,
|
|||
|
|
-- Planla diyaloğunda girilip henüz onaylanmamış dağıtımın toplamıdır (Prc_T_MaterialRequestPlanLine).
|
|||
|
|
CREATE OR REPLACE VIEW public."Prc_V_MaterialRequestPlan" AS
|
|||
|
|
SELECT i."Id", i."TenantId", i."MaterialRequestId", r."RequestNo", r."Priority", r."RequesterUserId", r."BranchId", r."DepartmentId", r."WarehouseId", r."LocationId",
|
|||
|
|
r."RequestDate", i."ProductId", p."CategoryId", i."Quantity", i."UomId", i."DueDate",
|
|||
|
|
CAST(CASE WHEN i."DueDate" < CURRENT_DATE THEN 'Late'
|
|||
|
|
WHEN i."DueDate" <= CURRENT_DATE + 7 THEN 'Week' ELSE 'Later' END AS varchar(8)) AS "DueState",
|
|||
|
|
i."RequestReason",
|
|||
|
|
pl."PurchaseQuantity", pl."TransferQuantity", pl."RemainingQuantity", COALESCE(st."Quantity", 0) AS "StockQuantity",
|
|||
|
|
(SELECT SUM(x."Quantity") FROM "Prc_T_MaterialRequestPlanLine" x WHERE x."MaterialRequestItemId" = i."Id" AND x."IsDeleted" = false) AS "DraftQuantity",
|
|||
|
|
i."IsDeleted"
|
|||
|
|
FROM "Prc_T_MaterialRequestItem" i
|
|||
|
|
INNER JOIN "Prc_T_MaterialRequest" r ON r."Id" = i."MaterialRequestId"
|
|||
|
|
INNER JOIN public."Prc_V_MaterialRequestItemPlan" pl ON pl."Id" = i."Id"
|
|||
|
|
LEFT JOIN "Inv_T_Product" p ON p."Id" = i."ProductId"
|
|||
|
|
LEFT JOIN LATERAL (
|
|||
|
|
SELECT SUM(public."Inv_F_UomConvert"(s."Quantity", s."UomId", i."UomId")) AS "Quantity"
|
|||
|
|
FROM "Inv_T_Stock" s
|
|||
|
|
INNER JOIN "Inv_T_Location" l ON l."Id" = s."LocationId" AND l."LocationType" = 'Internal'
|
|||
|
|
WHERE s."ProductId" = i."ProductId" AND s."IsDeleted" = false) st ON true
|
|||
|
|
WHERE i."IsDeleted" = false AND r."IsDeleted" = false AND i."LineStatus" = 'Waiting' AND pl."RemainingQuantity" > 0
|
|||
|
|
AND r."ApprovalStatus" IN ('Onaylandı', 'Teklif Talebi', 'Teklif Talebi Gönderildi', 'Satınalma Siparişi');
|