Restrict our qty of job material PO based on job material required qty

,

Dear Team,
I want to restrict / validate PO detail our qty based on job material required qty.
PO is job material based po.
Example ,
If Job required qty is 10 then PO our qty should be 10 only for that particular job based po

I have applied the code and that code is working correctly on added qty and updated qty but not working on changed qty.

Here is my code …

---------------------------------------------------------------------------------------------------------
Erp.Tables.PORel PORel;
Erp.Tables.JobMtl JobMtl;
string Company ="";
string CalcJobNum = "";
int CalcAssemblySeq = 0;
int CalcJobSeq = 0;
string EquipID = "";
DateTime? ReqDueDate = null;
DateTime? WarrantyExpDate = null;
decimal POQty = 0.0m;
decimal OldPOQty = 0.0m;
decimal JobQtty = 0.0m;
decimal TTL = 0.0m;
decimal Remaining = 0.0m;
string Part = "";
foreach (var PODetail_ITR in (from PODetail_Row in ttPODetail where (string.Equals(PODetail_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase) ||
                                                                   (string.Equals(PODetail_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase)))
 select PODetail_Row ))
    {
      var PODetail = PODetail_ITR;    
      Company = PODetail.Company;
      CalcJobNum = PODetail.CalcJobNum;
      CalcAssemblySeq = PODetail.CalcAssemblySeq;
      CalcJobSeq = PODetail.CalcJobSeq;
      POQty = PODetail.CalcOurQty;
      Part = PODetail.PartNum;
      foreach (var PORel_iterator in (from PORel_Row in Db.PORel
              where string.Compare(PORel_Row.Company,Company, true) == 0 &&  PORel_Row.JobNum ==  CalcJobNum && PORel_Row.JobSeq == CalcJobSeq && PORel_Row.AssemblySeq ==  CalcAssemblySeq
                       select PORel_Row))
                           {
                               PORel = PORel_iterator; 
                               OldPOQty =OldPOQty + PORel.XRelQty;
                               
                           }           
              JobMtl = (from JobMtl_Row in Db.JobMtl
                       where string.Compare(JobMtl_Row.Company,Company, true) == 0 &&  JobMtl_Row.JobNum ==  CalcJobNum && JobMtl_Row.MtlSeq == CalcJobSeq && JobMtl_Row.AssemblySeq == CalcAssemblySeq
                       select JobMtl_Row).FirstOrDefault();
                
                          if (JobMtl != null )
                              {
                                 JobQtty = JobMtl.RequiredQty;
                                        this.PublishInfoMessage("Message Text2", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

                              }    
                
  TTL = OldPOQty + POQty;
  Remaining = JobQtty - OldPOQty;
  
                                     if (TTL > JobQtty)
                                        {
                                           object THROW_PRIVATE = null;
                                           CallContext.Current.ExceptionManager.AddBLException("You can not use PO Qty more than Job Qty." +"(Remaining Quantity "+" " + Remaining.ToString("0.00") + " " +")"+" "+"For Part Num"+" "+" = "+Part);
                                           THROW_PRIVATE = null;
                                        }
    }
           
------------------------------------------------------------------------------------------------------------

This above mentioned codes work for added and update but not working for changed
It means ,
If my job mtl required qty is 10 and PO qty is 10 then working fine but when I add 5 and save then if I change it from 5 to 7 then not working because initially added 5 , so they took it and do sum of 5+7 and restrict it.

Working for added and update but notworking for change.

I put at
PO >> Method directive >> Update

It would be great if someone can help me in this.

Help you out for next time:

Code Syntax Highlighting in Posts

Hi , @klincecum
Okay, I have resolved this, I have checked it to database validation instead of business object validation and done some code changes. Now, it is working.

1 Like

Great!

Sorry nobody helped ya. Sometimes stuff slips through.