Hi group!!!
So I’m doing a custom code for a Method at Sales Order preprocessing that calculates a specific commission and so far so good. But then a new requirement was added after I did all the custom.
Sales Manager wants to be able to manually enter an Agent Allocation even when there is no commission involved.
So I though adding a checkbox and just a condition to ignore my formula if the bool is true, but seems like is no working (clears the value and sets it to 0)
Some guidance will be appreciated
foreach (var qt in ttOrderHed.Where(w => w.Added() || w.Updated()))
{
//get the bits needed for calculation (from same table - OrderHed)
//note that UD fields have to be grabbed like this (be sure to give it the correct data type, decimal in this case - so int, string, decimal, etc
var AgentSplit1 = qt.UDField<decimal>("AgentSplit1_c");
var AgentSplit2 = qt.UDField<decimal>("AgentSplit2_c");
var AgentSplit3 = qt.UDField<decimal>("AgentSplit3_c");
var AgentSplitPer1 = qt.UDField<decimal>("AgentSplitPer1_c");
var AgentSplitPer2 = qt.UDField<decimal>("AgentSplitPer2_c");
var AgentSplitPer3 = qt.UDField<decimal>("AgentSplitPer3_c");
var AgentSplitOver1 = qt.UDField<decimal>("AgentSplitOver1_c");
var AgentSplitOver2 = qt.UDField<decimal>("AgentSplitOver2_c");
var AgentSplitOver3 = qt.UDField<decimal>("AgentSplitOver3_c");
var OverPer1 = qt.UDField<decimal>("OverPer1_c");
var OverPer2 = qt.UDField<decimal>("OverPer2_c");
var OverPer3 = qt.UDField<decimal>("OverPer3_c");
var OverageTotal = qt.UDField<decimal>("OverageTotal_c");
//Added custom fields
var TAgComm1 = qt.UDField<decimal>("TAgComm1_c");
var TAgComm2 = qt.UDField<decimal>("TAgComm2_c");
var TAgComm3 = qt.UDField<decimal>("TAgComm3_c");
var AgentAllocation1 = qt.UDField<decimal>("AgentAllocation1_c");
var AgentAllocation2 = qt.UDField<decimal>("AgentAllocation2_c");
var AgentAllocation3 = qt.UDField<decimal>("AgentAllocation3_c");
var MAllocation = qt.UDField<bool>("MAllocation_c");
//note for std fields, you can get them directly (ctl+space = autocomplete btw)
var OrderValue = qt.DocTotalCharges;
//Total Agent Calculation
if (!(MAllocation = true))
{
{; }
}
else
{
var DN = (OrderValue - OverageTotal);
var CTAgComm1 = (((AgentSplit1 / 100) * (AgentSplitPer1 / 100)) * DN + (((OverPer1 / 100) * (AgentSplitOver1 / 100)) * OverageTotal)) == 0 ? 0 : (((AgentSplit1 / 100) * (AgentSplitPer1 / 100)) * DN + (((OverPer1 / 100) * (AgentSplitOver1 / 100)) * OverageTotal));
var CTAgComm2 = (((AgentSplit2 / 100) * (AgentSplitPer2 / 100)) * DN + (((OverPer2 / 100) * (AgentSplitOver2 / 100)) * OverageTotal)) == 0 ? 0 : (((AgentSplit2 / 100) * (AgentSplitPer2 / 100)) * DN + (((OverPer2 / 100) * (AgentSplitOver2 / 100)) * OverageTotal));
var CTAgComm3 = (((AgentSplit3 / 100) * (AgentSplitPer3 / 100)) * DN + (((OverPer3 / 100) * (AgentSplitOver3 / 100)) * OverageTotal)) == 0 ? 0 : (((AgentSplit3 / 100) * (AgentSplitPer3 / 100)) * DN + (((OverPer3 / 100) * (AgentSplitOver3 / 100)) * OverageTotal));
//Total Agent Allocation
var CTAgCommTotal = (CTAgComm1 + CTAgComm2 + CTAgComm3);
var AAllocation1 = CTAgCommTotal == 0 ? 0 : CTAgComm1 / (CTAgCommTotal) * 100;
var AAllocation2 = CTAgCommTotal == 0 ? 0 : CTAgComm2 / (CTAgCommTotal) * 100;
var AAllocation3 = CTAgCommTotal == 0 ? 0 : CTAgComm3 / (CTAgCommTotal) * 100;
//Set field for Total Agent Commission
qt.SetUDField<decimal>("TAgComm1_c", CTAgComm1);
qt.SetUDField<decimal>("TAgComm2_c", CTAgComm2);
qt.SetUDField<decimal>("TAgComm3_c", CTAgComm3);
// Set field for Total Agent Allocation
qt.SetUDField<decimal>("AgentAllocation1_c", AAllocation1);
qt.SetUDField<decimal>("AgentAllocation2_c", AAllocation2);
qt.SetUDField<decimal>("AgentAllocation3_c", AAllocation3);
}