bcquality/microsoft/knowledge/scm/reconcile-warehouse-adjustments-with-the-item-ledger.good.al
Jesper Schulz-Wedde 9ac62e3967 Add SCM functional knowledge domain
Introduce nine source-backed rules with original AL sample pairs, bounded SCM review routing, and complete positive/clean evaluation coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-17 15:54:23 +02:00

50 lines
2.1 KiB
AL

namespace BCQuality.SCM.Samples;
using Microsoft.Inventory.Item;
using Microsoft.Inventory.Journal;
using Microsoft.Inventory.Location;
using Microsoft.Inventory.Posting;
using Microsoft.Warehouse.Journal;
codeunit 50111 "SCM Warehouse Adjustment Good"
{
procedure ReconcileRegisteredWarehouseAdjustment(ItemNo: Code[20]; LocationCode: Code[10]; TemplateName: Code[10]; BatchName: Code[10]; PostingDate: Date; DocumentNo: Code[20]): Boolean
var
Item: Record Item;
ItemJournalBatch: Record "Item Journal Batch";
ItemJournalLine: Record "Item Journal Line";
Location: Record Location;
CalculateWhseAdjustment: Report "Calculate Whse. Adjustment";
ItemJnlPostBatch: Codeunit "Item Jnl.-Post Batch";
begin
Location.Get(LocationCode);
Location.TestField("Directed Put-away and Pick", true);
Location.TestField("Adjustment Bin Code");
ItemJournalBatch.Get(TemplateName, BatchName);
ItemJournalLine.SetRange("Journal Template Name", TemplateName);
ItemJournalLine.SetRange("Journal Batch Name", BatchName);
if not ItemJournalLine.IsEmpty() then
Error(EmptyBatchErr);
Item.Get(ItemNo);
Item.SetRecFilter();
Item.SetRange("Location Filter", LocationCode);
ItemJournalLine."Journal Template Name" := TemplateName;
ItemJournalLine."Journal Batch Name" := BatchName;
CalculateWhseAdjustment.SetItemJnlLine(ItemJournalLine);
CalculateWhseAdjustment.SetTableView(Item);
CalculateWhseAdjustment.InitializeRequest(PostingDate, DocumentNo);
CalculateWhseAdjustment.SetHideValidationDialog(true);
CalculateWhseAdjustment.UseRequestPage(false);
CalculateWhseAdjustment.RunModal();
if ItemJournalLine.FindFirst() then begin
ItemJournalLine.TestField("Warehouse Adjustment", true);
ItemJnlPostBatch.Run(ItemJournalLine);
end;
exit(true);
end;
var
EmptyBatchErr: Label 'Use an empty, dedicated item journal batch for warehouse reconciliation.';
}