I’m working on a BPM that when an invoice for a specific customer is posted, it automatically writes it off to an intercompany GL account. I’m struggling with getting it to post. I followed the code in the trace, but there was never anything that showed up in the trace for the posting process, so when the invoice is posted, nothing happens regarding the write off.
Anyone know the code to post it?
//var _writeTaskLog = new System.Lazy<Ice.Core.WriteTaskLog>(() => new Ice.Core.WriteTaskLog(this.Db));
var tt = ttInvcHead.FirstOrDefault();
if( tt != null )
{
int iNum = tt.InvoiceNum;
decimal iAmt = tt.InvoiceAmt;
decimal iBal = tt.InvoiceBal;
string writeOffAcct = "01-01-2020-00-0000";
string writeOffAcctPipe = "2020|01|01|00|0000";
using(var arBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ARAdjustmentSvcContract>(Db))
{
ARAdjustmentTableset arTS = new ARAdjustmentTableset();
// Load the invoice information in to the arTS tableset
arTS = arBO.GetByID(iNum);
// Get a new AR Write Off Record
arBO.GetNewCashDtl1(ref arTS, iNum);
//_writeTaskLog.Value.WriteToTaskLog("CheckNum: " + arTS.CashDtl[0].HeadNum.ToString(),tasknum);
// Change the adjustment amount to the invoice balance
bool reload = false;
arTS.CashDtl[0].DocDispTranAmt = -iBal;
arTS.CashDtl[0].DocTranAmt = -iBal;
arTS.CashDtl[0].DispTranAmt = -iBal;
arTS.CashDtl[0].Comment = "Auto Write Off by BPM";
arTS.CashDtl[0].TranType = "ADJUST";
arTS.CashDtl[0].RowMod = "A";
arTS.CashDtlTGLC[0].GLAccount = writeOffAcctPipe;
arTS.CashDtlTGLC[0].RowMod = "A";
arTS.CashDtlTGLC[0].SegValue1 = "2020";
arTS.CashDtlTGLC[0].SegValue2 = "01";
arTS.CashDtlTGLC[0].SegValue3 = "01";
arTS.CashDtlTGLC[0].SegValue4 = "00";
arTS.CashDtlTGLC[0].SegValue5 = "0000";
arBO.ChangeAdjAmount(ref arTS, out reload);
// Change GL Account to the write off account
string ipCompany = Session.CompanyID;
string ipCOACode = "ISIMain";
string ipGLAccount = writeOffAcctPipe;
arBO.ChangeGLAcctDisp(ipCompany, ipCOACode, ipGLAccount);
// Validate the transaction set is accurate
arBO.ValidateTransaction(ref arTS);
}
}
Or if someone knows a different way, I’m open to suggestions.
Was trying to go the GL Control route for the customer where I set the Receivables context to the write off account, but was stuck with the invoice out in AR Aging.
No matter what you do the invoice will sit in some aging as open until it is either adjusted out or a receipt is posted against it.
My suggestion would be to have the customer AR account set to an intercompany account. This will allow you to see the IC invoices separated from the trade invoices and see all of the intercompany bookings.
As necessary you can write off the Intercompany invoices to the appropriate account.
This is exactly the process I’m attempting to automate–I’m not trying to “fake it” by setting flags; I’m trying to use the ARAdjustments BO to actually make it happen. I’ve got most of it pieced together, I’m just struggling with the posting portion.
I have solved this issue, but get another one
The type or namespace name ‘ARInvAdjPostTableset’ could not be found (are you missing a using directive or an assembly reference?)
No, the issue is that the Adjustment failed due to an error, and then it’s locked in someplace in the database. What is needed is to know the table that holds the error record and remove it.
Is there a table that saves the invoice adjustments?