microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
791 stars 622 forks source link

[Event Request] Codeunit 7326 "Whse. Item Tracking FEFO".SummarizeInventoryFEFO #27667

Open fridrichovsky opened 21 hours ago

fridrichovsky commented 21 hours ago

Describe the request

Please add new event

   local procedure SummarizeInventoryFEFO(Location: Record Location; ItemNo: Code[20]; VariantCode: Code[10]; HasExpirationDate: Boolean)
    var
        ItemTrackingSetup: Record "Item Tracking Setup";
        SummarizedStockByItemTrkg: Query "Summarized Stock By Item Trkg.";
        QtyReservedFromItemLedger: Query "Qty. Reserved From Item Ledger";
        NonReservedQtyLotSN: Decimal;
        IsHandled: Boolean;
        // ----------------------------------------------------------------------------------------:BEGIN
        DoInsertEntrySummary: Boolean;
        // ----------------------------------------------------------------------------------------:END

#if not CLEAN23
        UseLegacyImplementation: Boolean;
#endif
    begin
        IsHandled := false;
        OnBeforeSummarizeInventoryFEFO(Location, ItemNo, VariantCode, HasExpirationDate, IsHandled,
            TempGlobalEntrySummary, StrictExpirationPosting, LastSummaryEntryNo, HasExpiredItems);
        if IsHandled then
            exit;

#if not CLEAN23
        UseLegacyImplementation := false;
        OnSummarizeInventoryFEFOLegacyImplementation(UseLegacyImplementation);
        if UseLegacyImplementation then begin
            SummarizeInventoryFEFO_LegacyImplementation(Location, ItemNo, VariantCode, HasExpirationDate);
            exit;
        end;
#endif
        SummarizedStockByItemTrkg.SetSKUFilters(ItemNo, VariantCode, Location.Code);
        SummarizedStockByItemTrkg.SetRange(Open, true);
        SummarizedStockByItemTrkg.SetRange(Positive, true);
        if HasExpirationDate then
            SummarizedStockByItemTrkg.SetFilter(Expiration_Date, '<>%1', 0D)
        else
            SummarizedStockByItemTrkg.SetRange(Expiration_Date, 0D);

        SummarizedStockByItemTrkg.Open();
        while SummarizedStockByItemTrkg.Read() do begin
            SummarizedStockByItemTrkg.GetItemTrackingSetup(ItemTrackingSetup);
            if not IsItemTrackingBlocked(ItemNo, VariantCode, ItemTrackingSetup) then begin
                NonReservedQtyLotSN := SummarizedStockByItemTrkg.Remaining_Quantity;

                QtyReservedFromItemLedger.SetSKUFilters(ItemNo, VariantCode, Location.Code);
                QtyReservedFromItemLedger.SetTrackingFilters(ItemTrackingSetup);
                QtyReservedFromItemLedger.Open();
                if QtyReservedFromItemLedger.Read() then
                    NonReservedQtyLotSN -= QtyReservedFromItemLedger.Quantity__Base_;
                // ----------------------------------------------------------------------------------------OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO:BEGIN
                // ORIG:BEGIN
                //if NonReservedQtyLotSN - CalcNonRegisteredQtyOutstanding(
                //      ItemNo, VariantCode, Location.Code, ItemTrackingSetup, HasExpirationDate) > 0
                //then
                //    InsertEntrySummaryFEFO(ItemTrackingSetup, SummarizedStockByItemTrkg.Expiration_Date);
                // ORIG:END
                DoInsertEntrySummary := NonReservedQtyLotSN - CalcNonRegisteredQtyOutstanding(ItemNo, VariantCode, Location.Code, ItemTrackingSetup
                 , HasExpirationDate) > 0
                OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO(Location, ItemNo, VariantCode, HasExpirationDate, NonReservedQtyLotSN, ItemTrackingSetup, SummarizedStockByItemTrkg.Expiration_Date, DoInsertEntrySummary);                    
                if DoInsertEntrySummary then
                    InsertEntrySummaryFEFO(ItemTrackingSetup, SummarizedStockByItemTrkg.Expiration_Date);
                // ----------------------------------------------------------------------------------------OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO:END
            end;
        end;
    end;

    // ----------------------------------------------------------------------------------------OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO:BEGIN
    [IntegrationEvent(true, false)]
    local procedure OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO(Location: Record Location; ItemNo: Code[20]; VariantCode: Code[10]; HasExpirationDate: Boolean; NonReservedQtyLotSN: Decimal; ItemTrackingSetup: Record "Item Tracking Setup"; ExpirationDate: Date; var DoInsertEntrySummary: Boolean)
    begin
    end;
    // ----------------------------------------------------------------------------------------OnSummarizeInventoryFEFOOnBeforeInsertEntrySummaryFEFO:END

Additional context

We need option decide if insert can be raise.