Hi,
I am trying to add a Data Directive BPM that creates a LaborDtl on a job when it is shipped to complete the final operation (and trigger the operation and material backflushes on that job). The code I have is at the bottom here, but I’ll explain how I arrived at it first.
I went through the process of manually creating the LaborDtl using the Time and Expense Entry screen with my trace on (including full datasets). It worked fine, the operation was marked as completed and the backflush processed. I then wrote the below code based on that trace, including each LaborImpl method that was triggered in the trace. I also compared the LaborTableset as it was returned from each method to what it looked like when it was passed to the next method, and made the same changes using set statements.
It compiles fine and gives no errors when it runs, and it creates and approves the LaborDtl as expected. It can be viewed in the Time and Expense Entry form and looks normal when compared to manually input one (including having Operation Complete checked) However, when I open the related job in Job Entry, that operation is not marked as complete and the backflush doesn’t take place. I can even recall and resubmit the LaborDtl through the Time and Expense Entry form and nothing happens (no errors and no changes).
Is anyone familiar with this able to give me any pointers? I’ve been banging my head against this for a few days and rewritten it three times, and it always gives me the same results.
string msg;
bool errorBool;
foreach(var jOper in JobOper)
{
//Get Default Employee for operations
var EmpBasic = (from EmpBasic_Row in Db.EmpBasic.With(LockHint.NoLock)
where EmpBasic_Row.EmpID == jOper.OpCode && jOper.Company == EmpBasic_Row.Company
select EmpBasic_Row).ToList();
string empExpenseCode = "VICLAM"; //Default
if(EmpBasic != null){
//Get Expense Code
empExpenseCode = EmpBasic[0].ExpenseCode;
}
using(var laborBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.LaborSvcContract>(this.Db))
{
//Find LaborHed and create new detail
string whereClauseLaborHed = "EmployeeNum = '" + jOper.OpCode + "' AND PayrollDate = '" + DateTime.Now.ToString("MM/dd/yyyy") + "'";
LaborTableset lds = laborBO.GetRowsCalendarView(whereClauseLaborHed, "ActiveTrans = 0", "", "", "", "", "", "", "", "", "", "", 0, 0, jOper.OpCode, DateTime.Now, DateTime.Now, out errorBool);
laborBO.GetNewLaborDtlNoHdr(ref lds,jOper.OpCode, false, DateTime.Now, 0, DateTime.Now, jOper.EstProdHours);
//Find added row
int rowNum = 0;
for(int i = 0; i < lds.LaborDtl.Count; i++){
if (lds.LaborDtl[i].RowMod == "A"){
rowNum = i;
}
}
//Follow update path in Time and Expense Entry Trace
lds.LaborDtl[rowNum].DtClockIn = DateTime.Now;
lds.LaborDtl[rowNum].DtClockOut = DateTime.Now;
laborBO.DefaultJobNum(ref lds, jOper.JobNum);
laborBO.LaborRateCalc(ref lds);
laborBO.DefaultOprSeq(ref lds,jOper.OprSeq, out msg);
laborBO.LaborRateCalc(ref lds);
laborBO.DefaultLaborQty(ref lds, jOper.RunQty, out msg);
lds.LaborDtl[rowNum].NewDifDateFlag = 2;
laborBO.CheckWarnings(ref lds, out msg);
laborBO.Update(ref lds);
lds.LaborDtl[rowNum].RowMod = "U";
laborBO.ValidateChargeRateForTimeType(ref lds, out msg);
laborBO.SubmitForApproval(ref lds, false, out msg);
}
}