Hi BC Guru's,
We have some custom code written for us but unfortunately it is not working properly, and we cannot seem to find the issue. It seems that the code is always using the marketing G/L accounts regardless of the criteria.
The criteria that must be met to use the marketing G/L is below:
The Cost of Goods Sold G/L Account Reassignment functionality uses the Return Reason code and the line amount field values specified in the Sales Line to determine if posting to the Marketing G/L Account is required. The following are the scenarios:
#1) If the good is sold for $0, and the return reason is blank, then the COG will flow through to the appropriate Market COGS G/L Account.
#2) If the good is sold for $0, and the return reason is populated with an option on the table, but it is not checked off; then it does NOT flow to the Market COGS G/L Account, and it stays in the general posting group of cost of goods. As an example, if someone receives a damaged product and we send a new one at $0, this COGS G/L Account will remain in the general posting group of cost of goods; and it would not be charged to marketing.
#3) If the good is sold for $0, and the return reason is populated with an option on the table that is checked in the box, then it does flow to the Market COGS G/L Account.
I have attached our code below:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Inventory Posting To G/L", 'OnBeforeSetAccNo', '', true, true)]
local procedure OnBeforeSetAccNo(var InvtPostBuf: Record "Invt. Posting Buffer"; ValueEntry: Record "Value Entry"; var IsHandled: Boolean)
var
lrecItem: Record Item;
lrecItemDiscountGroup: Record "Item Discount Group";
lrecReturnReason: Record "Return Reason";
bMarketing: Boolean;
begin
bMarketing := false;
IsHandled := false;
if InvtPostBuf."Account Type" <> InvtPostBuf."Account Type"::COGS then
exit;
if ValueEntry."Return Reason Code" <> '' then
if lrecReturnReason.Get(ValueEntry."Return Reason Code") then
bMarketing := lrecReturnReason."INT-Marketing";
if lrecItem.Get(ValueEntry."Item No.") then
if lrecItem."Item Disc. Group" <> '' then
if lrecItemDiscountGroup.Get(lrecItem."Item Disc. Group") then
if ((ValueEntry."Sales Amount (Actual)" = 0) and (ValueEntry."Sales Amount (Expected)" = 0)) then
if ((ValueEntry."Return Reason Code" = '') or ((ValueEntry."Return Reason Code" <> '') and bMarketing)) then
case ValueEntry."Gen. Bus. Posting Group" of
'GENERAL':
If lrecItemDiscountGroup."INT-General G/L" <> '' then begin
InvtPostBuf."Account No." := lrecItemDiscountGroup."INT-General G/L";
IsHandled := true;
end;
'INTERCO':
If lrecItemDiscountGroup."INT-Intercompany G/L" <> '' then begin
InvtPostBuf."Account No." := lrecItemDiscountGroup."INT-Intercompany G/L";
IsHandled := true;
end;
end;
end;
}