Check JobMtl all parts on the basis of Fixed qty

Dear All ,

Can any one correct this below mentioned code?
It is checking one job material but not checking multiple job materials.

foreach (var LaborDtl_iterator in (from LaborDtl_Row in ttLaborDtl
                                       where (string.Equals(LaborDtl_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase))  || (string.Equals(LaborDtl_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase))
                                       select LaborDtl_Row))
  { 
         var  V_LaborDtl = LaborDtl_iterator;
         Company = V_LaborDtl.Company;
         LQty = V_LaborDtl.LaborQty;
       //  this.PublishInfoMessage("LQty"+LQty, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
        
                  
           foreach (var LaborDtl1_iterator in (from LaborDtl_Row in Db.LaborDtl
                                         where LaborDtl_Row.Company  == V_LaborDtl.Company &&   (LaborDtl_Row.JobNum == V_LaborDtl.JobNum )
                                         && LaborDtl_Row.LaborDtlSeq != V_LaborDtl.LaborDtlSeq
                                         select LaborDtl_Row))
                     
                     {
                        LaborDtl1 =  LaborDtl1_iterator; 
                        PLQty = PLQty+LaborDtl1.LaborQty;
                        LS = LaborDtl1.LaborDtlSeq;
                        
                     }  
                 OCQty = LQty+PLQty;   
                 //this.PublishInfoMessage("OCQty"+OCQty, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
       
        JobHead = (from JobHead_Row in Db.JobHead where string.Compare(JobHead_Row.Company,Company, true) == 0 
                  &&  JobHead_Row.JobNum ==  V_LaborDtl.JobNum 
                  select JobHead_Row).FirstOrDefault();
                  
                  if (JobHead != null) 
                  {
                    ProdQty = JobHead.ProdQty; 
                   // LabASQty = PerQty*LQty;
                  
                  foreach (var JobMtl_iterator in (from JobMtl_Row in Db.JobMtl
                                         where JobMtl_Row.Company  == JobHead.Company &&   (JobMtl_Row.JobNum == V_LaborDtl.JobNum )
                                         select JobMtl_Row))
                 
                      {
                                  JobMtl = JobMtl_iterator;  
                                  PerQty = JobMtl.QtyPer;
                                  ReqQty = JobMtl.RequiredQty;
                                  IssueQty = JobMtl.IssuedQty;
                                  LabASQty = PerQty*OCQty;
                                  MtlSeq = JobMtl.MtlSeq;
                                  POSTQ = JobMtl.POST_c;
                                  NEGQ = JobMtl.NEGT_c;
                                  FixedQty = JobMtl.FixedQty;
                                  //this.PublishInfoMessage("Plese ensure to issue the all material of Job."+"MTLSq+m"+MtlSeq+"LQ"+LabASQty+"IQ"+IssueQty, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
                                  
                       
                               
                              if ( POSTQ == 0 ) 
                              {
                                if ( NEGQ == 0 )
                                  {
                                  
                                    if ( FixedQty = true )
                                    
                                      {
                                      
                                        LabASQty22 = (IssueQty * ProdQty );
                                        FFQty = LabASQty22/PerQty;
                                      
                                        
                                        
                                        }
                                      
                                          
                              
                                   if(LabASQty > FFQty )
                                     {
                                         object THROW_PRIVATE = null;
                                         //CallContext.Current.ExceptionManager.AddBLException("JobQty"+PerQty+"LQty"+OCQty+"iss"+IssueQty+"LabASQty"+LabASQty);
                                        CallContext.Current.ExceptionManager.AddBLException("PLease wait , Fixed qty is detected. Labour qty should be equal to "   +  LabASQty22  + ReqQty  +FFQty );
                                         THROW_PRIVATE = null;  
                                         break;
              
                                    }   
                               }
                          
                   }                    
                }      
           }

My above mentioned codes is working for one material but not working for multiple material for the same job.

I formatted your code so I could try to understand it. Someone is trying to report a quantity and you are also adding up previous labor, but I am not sure what POSTQ and NEGQ are doing.

Can you explain what you are trying to stop or force?

Hi ,
scenario is,
When user go for labor entry transaction then system check, whether all material is issued or not related to selected job.
When if Job material is fixed qty marked then required qty is equal to qty per parent qty.

In this scenario, if in Job card, Job material marked as fixed qty and required qty is 2 and FG product qty is 6 , then is user issued 2 qty then system should allow to do time and expense entry for 6 qty .

My code is working correct for one Job material which has fixed qty check box is true , but not working for multiple linked materials.

Code is checking and calculating first material only , not calculating all linked materials of the job entry

foreach (var JobMtl_iterator in (from JobMtl_Row in Db.JobMtl
where JobMtl_Row.Company == JobHead.Company && (JobMtl_Row.JobNum == V_LaborDtl.JobNum ) && JobMtl_Row.FixedQty = true
select JobMtl_Row))

This works well for first linked job material but working for rest of linked material to the job card.

Below code checking fixed qty calculation.
required vs issued qty

if ( FixedQty = true )

                                  {
                                  
                                    LabASQty22 = (IssueQty * ProdQty );
                                    FFQty = LabASQty22/PerQty;

All you really care about is if the fixed qty material is marked as issued complete or not, so you don’t need the quantities.

Checking when the quantity is entered is after the labor has already been done.

Would you not want to not allow the user to start the activity if the material had not been issued?

Yes , all linked material parts should be issued as per required qty and labor qty should be proportionated to quantity per parent.

              foreach (var JobMtl_iterator in (from JobMtl_Row in Db.JobMtl
                                     where JobMtl_Row.Company  == JobHead.Company &&   (JobMtl_Row.JobNum == V_LaborDtl.JobNum )
                                     select JobMtl_Row))

This code is checking first job material and works well but not checking the rest linked materials.

what is the purpose of the break in the if condition? I think if the if is hit then the break stops the loop.

Okay , then please suggest the codes

Only condition is , system should check all the job linked materials, and their required qty and issued qty …

I think , group by logic works here , group by Jobseq but not sure .

From what I gather in your code this should be close. you have LabASQty in the condition and LabASQty22 in the exception so I went with LabASQty22.

This compiles, but I have no way to test it. The code I took this from does a rollup on backflush material on end activity, so it is similar.

/* check labor qty  */


Erp.Tables.LaborDtl LaborDtl;



  Ice.Diagnostics.Log.WriteEntry("starting labor check");
  foreach(var ttLaborDtlRow in ds.LaborDtl.Where(ttLaborDtlRow => !ttLaborDtlRow.Unchanged()))
  {
    
    Ice.Diagnostics.Log.WriteEntry("inside check labor "+ttLaborDtlRow.JobNum+" clockout "+ ttLaborDtlRow.DspClockOutTime);

        var prodQty = Db.JobHead.With(LockHint.NoLock).Where(JobHead_Row => JobHead_Row.Company == Session.CompanyID
                        &&  JobHead_Row.JobNum ==  ttLaborDtlRow.JobNum).Select(s => s.ProdQty).FirstOrDefault();
                        
        var qtyCompletedThisOper = Db.JobOper.With(LockHint.NoLock).Where(jo => jo.Company == ttLaborDtlRow.Company && jo.JobNum == ttLaborDtlRow.JobNum && jo.AssemblySeq == ttLaborDtlRow.AssemblySeq && jo.OprSeq == ttLaborDtlRow.OprSeq).Select(s => s.QtyCompleted).FirstOrDefault();                        

        var jobMtls = Db.JobMtl.Where(jm => jm.Company == ttLaborDtlRow.Company && jm.JobNum == ttLaborDtlRow.JobNum && jm.AssemblySeq == ttLaborDtlRow.AssemblySeq && jm.FixedQty == true).ToList();
        
        foreach(var jobMtl in jobMtls)
        {
        
            var LabASQty22 = (jobMtl.IssuedQty * prodQty );
            var FFQty = LabASQty22/jobMtl.QtyPer;
            
 
          if(LabASQty22  + jobMtl.RequiredQty  + FFQty != ttLaborDtlRow.LaborQty )
             {
                 
                 //CallContext.Current.ExceptionManager.AddBLException("JobQty"+PerQty+"LQty"+OCQty+"iss"+IssueQty+"LabASQty"+LabASQty);
                CallContext.Current.ExceptionManager.AddBLException("PLease wait , Fixed qty is detected. Labour qty should be equal to "   +  LabASQty22  + jobMtl.RequiredQty  + FFQty );
              

            }
        }


}
Ice.Diagnostics.Log.WriteEntry("exiting labor check");


Hi , [gpayne]
above codes work for fully labor qty tran but not working for partial labor tran.

Labour qty = 10 Nos
First labor added with 5 Nos
Second labor needs to be added 5 qty only because previously 5 qty labor has been added but system allowing me to add again 10 Nos for the second time too.

look at the value in qtyCompletedThisOper when this transaction is happening. If it is the value from the first labor add it to the check. if it is the total of both then you will need to subtract the current labor.

So , you mean that operation labour qty should not be more than operation completed qty
Right ?

I don’t know at what point in the write this routine is firing, so completed qty is either still 5 from the first labor or it is already 15 from the first 5 and now 10.

do a write entry or an info message to see what the value is so you know how to address it in your logic.

Hi,
Greg Payne

I think I made it, I applied below written code logic to validate .

if( qtyCompletedThisOper + ttLaborDtlRow.LaborQty > FFQty )

Thanks…

I am checking above condition , let see…

Thanks , [gpayne] ,
Below condition worked.
Thanks,
if( qtyCompletedThisOper + ttLaborDtlRow.LaborQty > FFQty )

1 Like

If this gave you a solution then check the solution checkbox.