Only returns false

@gpayne This is the code I used. It’s very similar to yours, but I am having one more issue. There was one issue I noticed last night while testing this further. If the operation is asking for 34 and I try to clock 34 it will not Let me. If I clocked 17 it works fine. If I try another 17 it does not work but if I try 10 it won’t either, but if I try 7 it will. It allows me to do random quantities to get to 32, but that’s it.

@josecgomez If you have any insight, I am all ears. Tried doing this myself and nothing seems to be working.

/* Stopping Over Reporting of Production Quantities */
string Customer = string.Empty;
int oldLaborQty = 0;
Erp.Tables.JobHead JobHead;

Erp.Tables.LaborDtl LaborDtl;
Ice.Diagnostics.Log.WriteEntry("DD Labor Update stop over reporting start");

             var orgLaborDtl = (from Old_Row in ttLaborDtl
                                where Old_Row.Unchanged()
                                select Old_Row).FirstOrDefault();
        
            if (orgLaborDtl != null)
            {
              oldLaborQty = System.Convert.ToInt32(orgLaborDtl.LaborQty);
            }
            
            

 foreach(var ttLaborDtlRow in(from ttLaborDtl_Row in ttLaborDtl
 where ttLaborDtl_Row.Updated() && (ttLaborDtl_Row.LaborType == "P")
 select ttLaborDtl_Row))
    {
      
        
//      Ice.Diagnostics.Log.WriteEntry($"Type {ttLaborDtlRow.LaborType}");
      if(ttLaborDtlRow.LaborType == "P")
       {

        
       
//          Ice.Diagnostics.Log.WriteEntry($"before joboper job {ttLaborDtlRow.JobNum} asm {ttLaborDtlRow.AssemblySeq} opr {ttLaborDtlRow.OprSeq}");
            var jo = Db.JobOper.Where(j => j.Company == CompanyID && j.JobNum  == ttLaborDtlRow.JobNum &&  j.AssemblySeq == ttLaborDtlRow.AssemblySeq  &&  j.OprSeq == ttLaborDtlRow.OprSeq).Select(j=> new {j.QtyCompleted,j.RunQty}).FirstOrDefault();
            
//            Ice.Diagnostics.Log.WriteEntry("after read");
            if (jo != null)
            {
            
//            Ice.Diagnostics.Log.WriteEntry($" End Act in JobOper Complete:{jo.QtyCompleted} LaborQ:{ttLaborDtlRow.LaborQty} Total {jo.RunQty} ");
       
     
                
//                   Ice.Diagnostics.Log.WriteEntry($" oldlabor {oldLaborQty}");
      
                   if((jo.QtyCompleted - oldLaborQty) + ttLaborDtlRow.LaborQty > jo.RunQty && ttLaborDtlRow.LaborQty != 0)
                  {
                   throw new Ice.BLException("There are already " + jo.QtyCompleted.ToString("N2")  + " complete. The operation required quantity is " + 
                                                                         jo.RunQty.ToString("N2") + ". You entered a quantity of " +  ttLaborDtlRow.LaborQty.ToString("N2") + " this will result in over reported quantities.");
                    ttLaborDtlRow.LaborQty = 0;
                  }

            }
      
        }
}   

Ice.Diagnostics.Log.WriteEntry("DD Labor Update stop over reporting exit");

Why are you looking at the unchanged labor record here? I didn’t read the whole thread so I’m trying to understand what you are trying to do but if its just over-reporting I’m not sure I understand why you are subtracting the oldquantity?

1 Like

I need what was previously reported, plus what they are trying to report and compare that to the required qty. If it’s more than the required qty, then error.

but what was previously reported will already be in the JobOper.QtyCompleted

1 Like

So I can remove the oldLaborQty and do this:

if((jo.QtyCompleted) + ttLaborDtlRow.LaborQty > jo.RunQty && ttLaborDtlRow.LaborQty != 0)

It was there in my code for previous editing attempts at the LaborQty. I can’t remember why it was put in a long time ago.

After looking into this more, it seems that JO.QtyCompleted is reading as it’s already been completed. So when it’s adding the qty completed with the current labor qty, it’s always over when you try doing the exact qty.

image

I am not sure what this portion means (the underlined) but this maybe the issue:

This is used in our system pre-processing in Update. You are using it in a data directive and it appears that completed is already set at that point so the math is going to be different. RunQty is the total for the operation that is being used to check for over reporting.

You can uncomment the Write Entries and see the values in the server event viewer.

I tried to use it in method but the method is ReportQty and not LaborDtl. Trying to get this done so it works, then go back and fix the coding for the method.

I will do that and see what it says.

This is interesting:

This seemed to fix the issue.
Changed this:

if((jo.QtyCompleted - oldLaborQty) + ttLaborDtlRow.LaborQty > jo.RunQty && ttLaborDtlRow.LaborQty != 0)

to

if((jo.QtyCompleted )  > jo.RunQty)

That makes sense since you are using report quantity and not end activity.