Guy’s i am working on a BPM to close jobs on the job receipt to inventory.
The BPM runs on the Erp.ReceiptsFromMfg.ReceiveMfgPartToInventory Pre and Post Method.
The Pre Method checks if all the ops are complete. Then go onto the Post Method.
The Post Method simply runs the code below.
The messages are just for debugging.
The first step is to get the QtyCompleted from the job.
The 2nd step is to check the PartTran Table for the QtyBooked to Stock.
The 3rd step is to check if the QtyBooked to Stock is equal to the QtyCompleted. If So then close the job.
Erp.Tables.JobHead jh;
var jn = callContextBpmData.ShortChar01;
var ptq = callContextBpmData.Number01;
var message = jn;
decimal jqc = 0;
this.PublishInfoMessage(message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
message = ptq.ToString();
this.PublishInfoMessage(message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
jh = (from JobHead_Row in Db.JobHead where JobHead_Row.Company == Session.CompanyID && JobHead_Row.JobNum == jn select JobHead_Row).FirstOrDefault();
{
jqc=jh.QtyCompleted;
{
//Get the sum of booked parts
decimal qc = (
from pt in Db.PartTran.With(LockHint.NoLock)
where pt.Company == Session.CompanyID &&
pt.JobNum == jn &&
pt.TranType == "MFG-STK"
select pt.TranQty).Sum();
message = qc.ToString();
this.PublishInfoMessage(message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
if (qc == jqc);
using( var jcBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobClosingSvcContract>(Db))
{
try
{
JobClosingTableset jcTS = new JobClosingTableset();
//GetNewJobClosing Method
jcBO.GetNewJobClosing(ref jcTS);
//OnChangeJobNum Method
string pcJobNum = jn;
string pcMessage = "";
jcBO.OnChangeJobNum(pcJobNum, ref jcTS, out pcMessage);
//OnChangeJobClosed Method
jcTS.JobClosing[0].JobClosed = true;
jcTS.JobClosing[0].RowMod = "U";
jcBO.OnChangeJobClosed(ref jcTS);
//PreCloseJob Method
bool RequiresUserInput = false;
jcTS.JobClosing[0].JobClosed = true;
jcTS.JobClosing[0].ClosedDate = DateTime.Today;
jcTS.JobClosing[0].JobComplete = true;
jcTS.JobClosing[0].JobCompletionDate = DateTime.Today;
jcTS.JobClosing[0].QuantityContinue = 1;
jcTS.JobClosing[0].WIPCleared = true;
jcTS.JobClosing[0].RowMod = "U";
jcBO.PreCloseJob(ref jcTS, out RequiresUserInput);
//CloseJob Method
jcBO.CloseJob(ref jcTS, out pcMessage);
}
catch(Exception e){callContextBpmData.Character01 += e.ToString();}
}
}
}