How to set actual job output quantity do not exceed production quantity

Hi,
how to i set the actual output quantity cannot exceed job production quantity with condition that the job number prefix start with ‘P’?

At one site we added a customization to the MES End Activity form.
used the JobOperSearchAdapter to get the RunQty and the PreviousQuantityReported
and then compare the previous + proposed qtys with the run qty

  • warning message if less than run qty
  • error message if over the run qty

Note they only used the End Activity form, TBD if you are also using Report Qtys button/form.
And… I’m guessing you could do something similar in a BPM instead of a form customization but… have not actually tried it yet.

@john19 This is how we do it in a bpm on end Activity. We have somethnig similar on report quantity.

/* 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("MD 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 ttLaborDtl.Where( ttLaborDtl_Row => ttLaborDtl_Row.Updated() && ttLaborDtl_Row.LaborType == "P" || ttLaborDtl_Row.LaborType == "S"))
    {
      //var ttLaborDtlRow = ttLaborDtl_iterator;
        
//      Ice.Diagnostics.Log.WriteEntry($"Type {ttLaborDtlRow.LaborType}");
      if(string.Compare(ttLaborDtlRow.LaborType,"P",true)== 0)
       {

        
       
//          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("missed P");
      
        if(ttLaborDtlRow.LaborType == "S" && ttLaborDtlRow.LaborQty > 0)
         {
         throw new Ice.BLException("Quantity not allowed on Setup activity. Change Current Quantity to zero.");
         ttLaborDtlRow.LaborQty = 0;
         }

}   

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