Codeunit 20515 Subc. ItemJnlPostLine Ext
src/Apps/W1/Subcontracting/App/src/General/SubcItemJnlPostLineExt.Codeunit.al137 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Manufacturing.Subcontracting;using Microsoft.Inventory.Costing;using Microsoft.Inventory.Journal;using Microsoft.Inventory.Ledger;using Microsoft.Inventory.Posting;using Microsoft.Manufacturing.Capacity;using Microsoft.Manufacturing.Document;codeunit 20515 "Subc. ItemJnlPostLine Ext"{#if not CLEAN29 var#pragma warning disable AL0432 SubcFeatureFlagHandler: Codeunit "Subc. Feature Flag Handler";#pragma warning restore AL0432#endif [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnAfterInitItemLedgEntry, '', false, false)] local procedure OnAfterInitItemLedgEntry(var NewItemLedgEntry: Record "Item Ledger Entry"; ItemJournalLine: Record "Item Journal Line"; var ItemLedgEntryNo: Integer) begin#if not CLEAN29#pragma warning disable AL0432 if not SubcFeatureFlagHandler.IsSubcontractingEnabled() then#pragma warning restore AL0432 exit;#endif UpdateNewItemLedgerEntry(NewItemLedgEntry, ItemJournalLine); end; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnBeforeInsertCapLedgEntry, '', false, false)] local procedure OnBeforeInsertCapLedgEntry(var CapLedgEntry: Record "Capacity Ledger Entry"; ItemJournalLine: Record "Item Journal Line") begin#if not CLEAN29#pragma warning disable AL0432 if not SubcFeatureFlagHandler.IsSubcontractingEnabled() then#pragma warning restore AL0432 exit;#endif UpdateCapLedgerEntry(CapLedgEntry, ItemJournalLine); end;#if not CLEAN27#pragma warning disable AL0432 [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnAfterPostOutput, '', false, false)]#pragma warning restore AL0432#else [EventSubscriber(ObjectType::Codeunit, Codeunit::"Mfg. Item Jnl.-Post Line", OnAfterPostOutput, '', false, false)]#endif local procedure OnAfterPostOutput(var ItemLedgerEntry: Record "Item Ledger Entry"; var ProdOrderLine: Record "Prod. Order Line"; var ItemJournalLine: Record "Item Journal Line") begin#if not CLEAN29#pragma warning disable AL0432 if not SubcFeatureFlagHandler.IsSubcontractingEnabled() then#pragma warning restore AL0432 exit;#endif UpdateProdOrderRoutingLine(ProdOrderLine, ItemJournalLine); end; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnBeforeInsertCapValueEntry, '', false, false)] local procedure "Item Jnl.-Post Line_OnBeforeInsertCapValueEntry"(var ValueEntry: Record "Value Entry"; ItemJnlLine: Record "Item Journal Line") begin#if not CLEAN29#pragma warning disable AL0432 if not SubcFeatureFlagHandler.IsSubcontractingEnabled() then#pragma warning restore AL0432 exit;#endif ClearInvoicedQuantityForItemChargeSubAssign(ValueEntry, ItemJnlLine); CopyItemChargeNoForItemChargeSubAssign(ValueEntry, ItemJnlLine); end; local procedure UpdateProdOrderRoutingLine(var ProdOrderLine: Record "Prod. Order Line"; var ItemJournalLine: Record "Item Journal Line") var CapacityLedgerEntry: Record "Capacity Ledger Entry"; ProdOrderRoutingLine: Record "Prod. Order Routing Line"; ProductionOrder: Record "Production Order"; begin if not ItemJournalLine.Subcontracting then exit; if not ProductionOrder.Get(ProdOrderLine.Status, ProdOrderLine."Prod. Order No.") then exit; if not ProdOrderRoutingLine.Get(ProdOrderLine.Status, ProdOrderLine."Prod. Order No.", ProdOrderLine."Line No.", ProdOrderLine."Routing No.", ItemJournalLine."Operation No.") then exit; CapacityLedgerEntry.SetRange("Routing No.", ProdOrderRoutingLine."Routing No."); CapacityLedgerEntry.SetRange("Routing Reference No.", ProdOrderRoutingLine."Routing Reference No."); CapacityLedgerEntry.SetRange("Operation No.", ProdOrderRoutingLine."Operation No."); CapacityLedgerEntry.SetRange("Order No.", ProdOrderRoutingLine."Prod. Order No."); CapacityLedgerEntry.CalcSums("Output Quantity"); if CapacityLedgerEntry."Output Quantity" >= ProdOrderLine."Quantity (Base)" then begin ProdOrderRoutingLine."Routing Status" := "Prod. Order Routing Status"::Finished; ProdOrderRoutingLine.Modify(); end; end; local procedure UpdateNewItemLedgerEntry(var NewItemLedgerEntry: Record "Item Ledger Entry"; var ItemJournalLine: Record "Item Journal Line") begin NewItemLedgerEntry."Subc. Prod. Order No." := ItemJournalLine."Subc. Prod. Order No."; NewItemLedgerEntry."Subc. Prod. Order Line No." := ItemJournalLine."Subc. Prod. Order Line No."; NewItemLedgerEntry."Subc. Purch. Order No." := ItemJournalLine."Subc. Purch. Order No."; NewItemLedgerEntry."Subc. Purch. Order Line No." := ItemJournalLine."Subc. Purch. Order Line No."; NewItemLedgerEntry."Subc. Operation No." := ItemJournalLine."Subc. Operation No."; end; local procedure UpdateCapLedgerEntry(var CapacityLedgerEntry: Record "Capacity Ledger Entry"; var ItemJournalLine: Record "Item Journal Line") begin CapacityLedgerEntry."Subc. Subcontractor No." := ItemJournalLine."Source No."; CapacityLedgerEntry."Subc. Purch. Order No." := ItemJournalLine."Subc. Purch. Order No."; CapacityLedgerEntry."Subc. Purch. Order Line No." := ItemJournalLine."Subc. Purch. Order Line No."; end; local procedure ClearInvoicedQuantityForItemChargeSubAssign(var ValueEntry: Record "Value Entry"; var ItemJournalLine: Record "Item Journal Line") begin if ItemJournalLine."Subc. Item Charge Assign." and (ValueEntry."Entry Type" = "Cost Entry Type"::"Direct Cost") then ValueEntry."Invoiced Quantity" := 0; end; local procedure CopyItemChargeNoForItemChargeSubAssign(var ValueEntry: Record "Value Entry"; ItemJournalLine: Record "Item Journal Line") begin if ItemJournalLine."Subc. Item Charge Assign." and (ItemJournalLine."Item Charge No." <> '') then ValueEntry."Item Charge No." := ItemJournalLine."Item Charge No."; end;}