InvcMisc Misc Charge Recalculation help

bpm

(Joe Gollakner) #1

Currently when we add a misc charge to an Invoice Epicor calculates the InvcMisc.MiscAmt (InvcDtl.UnitPrice * InvcDtl.SellingShipQty) * (InvcMisc.Percentage / 100), we’re trying to recalculate Our Invoice Misc Charges by the Net Price with the following formula ((InvcDtl.UnitPrice * InvcDtl.SellingShipQty) - InvcDtl.DocDiscount) * (InvcMisc.Percentage / 100)

The issue I am running into is when I update the InvcMisc.MiscAmt/ InvcMisc.DocMiscAmt with the new calculation, the InvcDtl.TotalMiscCharge will not recalculate correctly.

Currently I have the Following code in my InvcMisc DataDirective (In-Transition), however, the InvcMisc.MiscAmt will calculate and show on screen correctly, but the Sum of all the Misc Charges on the InvcDtl does not recalculate correctly.

//InvcMisc Vars
decimal percent = 0.0m;
//InvcDtl Vars
decimal unitPrice = 0.0m;
decimal SellingShippedQty = 0.0m;
decimal disc = 0.0m;
//Recalculated Misc Amount
decimal miscAmt = 0.0m;

//Get current Updates or Added InvcMisc record
var ttInvcMisc_xRow = (from ttInvcMisc_Row in ttInvcMisc
where ttInvcMisc_Row.RowMod == IceRow.ROWSTATE_ADDED || ttInvcMisc_Row.RowMod == IceRow.ROWSTATE_UPDATED
select ttInvcMisc_Row).FirstOrDefault();

if (ttInvcMisc_xRow != null)
{

//Set InvcMisc New Percentage
percent = ttInvcMisc_xRow.Percentage;
 
//Get InvcDtl Vars 
var InvcDtl_iterator = (from InvcDtl_Row in Db.InvcDtl
                        where InvcDtl_Row.Company == Session.CompanyID &&
                        InvcDtl_Row.InvoiceNum == ttInvcMisc_xRow.InvoiceNum &&
                        InvcDtl_Row.InvoiceLine == ttInvcMisc_xRow.InvoiceLine
                    select InvcDtl_Row).FirstOrDefault();
if(InvcDtl_iterator != null)
{
  //InvcDtl.UnitPrice
  unitPrice = InvcDtl_iterator.UnitPrice;
  //InvcDtl.SellingShippedQty
  SellingShippedQty = InvcDtl_iterator.SellingShipQty;
  //InvcDtl.DocDiscount
  disc = InvcDtl_iterator.DocDiscount;
  //Recalculate
  miscAmt = ((unitPrice * SellingShippedQty) - disc) * (percent /100);
}
//Set new InvcMisc.MiscAmt Vals
ttInvcMisc_xRow.MiscAmt = miscAmt;
ttInvcMisc_xRow.DocMiscAmt = miscAmt;
//Commit Db Changes
Db.Validate();

}

ScreenShot of correct MiscCharges

Screenshot of incorrect InvcDtl Sum of Misc Charges

Any help would be appreciated.