Batch allocation of stock on SOOrder - acumatica

I am trying to write a process screen to allocate stock on the sales order in FIFO. The Process screen list all the sales order for a period for allocation.
I have gone through the code LSSOLine and not able to figure out the piece of code where allocation is done. anybody knows how to do it?
Update
I have tried the following code and it is working. Is there any better way to do it?
private static void DoStockAllocation(SOLine row, SOOrderEntry grp)
{
try
{
grp.Document.Current = PXSelect<
SOOrder,
Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>,
And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>
.Select(grp, row.OrderType, row.OrderNbr);
if (grp.Document.Current != null && grp.Document.Current.Status == SOOrderStatus.Open)
{
grp.Transactions.Current = row;
PXSelectBase<INLocationStatus> cmd = new PXSelectReadonly2<INLocationStatus,
InnerJoin<INLocation, On<INLocation.locationID, Equal<INLocationStatus.locationID>>,
LeftJoin<INSiteStatus, On<INSiteStatus.inventoryID, Equal<INLocationStatus.inventoryID>,
And<INSiteStatus.subItemID, Equal<INLocationStatus.subItemID>,
And<INSiteStatus.siteID, Equal<INLocationStatus.siteID>>>>>>,
Where<INLocationStatus.inventoryID, Equal<Required<INLocationStatus.inventoryID>>,
And<INLocationStatus.subItemID, Equal<Required<INLocationStatus.subItemID>>,
And<INLocationStatus.siteID, Equal<Required<INLocationStatus.siteID>>,
And<INLocation.salesValid, Equal<boolTrue>,
And<INLocation.inclQtyAvail, Equal<boolTrue>,
And<INLocationStatus.qtyOnHand, Greater<decimal0>>>>>>>>(grp);
foreach (PXResult<INLocationStatus, INLocation, INSiteStatus> ln in cmd.Select(row.InventoryID,row.SubItemID,row.SiteID))
{
INLocationStatus locationStatus = ln;
INSiteStatus siteStatus = ln;
SiteStatus accumsiteavail = new SiteStatus();
PXCache<INSiteStatus>.RestoreCopy(accumsiteavail, siteStatus);
accumsiteavail = (SiteStatus)grp.Caches[typeof(SiteStatus)].Insert(accumsiteavail);
decimal? AvailableQty = 0m;
decimal? SiteAvailableQty = locationStatus.QtyHardAvail;//siteStatus.QtyHardAvail + accumsiteavail.QtyHardAvail;
AvailableQty = SiteAvailableQty;
if (AvailableQty <= 0m)
{
continue;
}
if (row.LocationID == null)
{
row.LocationID = locationStatus.LocationID;
grp.Transactions.Update(row);
}
SOLineSplit split = new SOLineSplit();
if ( grp.splits.Select().Count > 0)
{
split = grp.splits.Select(row.OrderType, row.OrderNbr, row.LineNbr);
}
else
{
split = new SOLineSplit();
split = grp.splits.Insert(split);
split.InventoryID = row.InventoryID;
split.SiteID = row.SiteID;
split.OrderType = row.OrderType;
split.OrderNbr = row.OrderNbr;
split.LineNbr = row.LineNbr;
split.UOM = row.UOM;
split = PXCache<SOLineSplit>.CreateCopy(grp.splits.Update(split));
}
//split.LocationID = locationStatus.LocationID;
split.Qty = (AvailableQty < row.OrderQty) ? AvailableQty : row.OrderQty;
split.IsAllocated = true;
grp.splits.Update(split);
break;
}
grp.Save.Press();
}
}
catch(Exception ex)
{
}
}

You will need to reference the combination of LSSOLine and SOLineSplitPlanID on SOLineSplit.PlanID in your process page. Alternatively you might be able to use an instance of SOOrderEntry to do the updates/mark of allocation.
The following have been copied from the SOOrderEntry graph and are the 2 componenetis from what i can tell that drive the allocation logic. From there you just need to mark the split lines that should be allocated and should be good. Or at least a start. The problem you might have is anything that is looking for current SOOrder. You might have to set the current before marking solines splits as allocated. (assuming i under stand your question correctly)
Manage the allocation records...
public LSSOLine lsselect;
Append the use of SOLineSplitPlanID which drives the INItemPlan records...
[PXMergeAttributes(Method = MergeMethod.Append)]
[SOLineSplitPlanID(typeof(SOOrder.noteID), typeof(SOOrder.hold), typeof(SOOrder.orderDate))]
protected virtual void SOLineSplit_PlanID_CacheAttached(PXCache sender)
{
}

Related

fiscal area in the supplier information tab of the purchase order

Could you help me, I am changing the tax area code by adaptation, however the taxes are not updated, what am I missing or how can I change the related taxes when I change the tax area?
This is my code, through this event that I'm doing.
protected void POLine_SiteID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
var head = Base.Document.Current;
if (head == null) return;
if (row != null && row.OrderType == POOrderType.RegularOrder)
{
POLine line = PXSelect<POLine, Where<POLine.orderType,
Equal<Required<POLine.orderType>>,
And<POLine.orderNbr, Equal<Required<POLine.orderNbr>>>>>.Select(Base, row.OrderType, row.OrderNbr);
bool? xchange = false;
if (line != null)
{
INSite site = PXSelect<INSite, Where<INSite.siteID,
Equal<Required<INSite.siteID>>>>.Select(Base, line.SiteID);
if (site != null && line.SiteID == site.SiteID)
{
var ext = site.GetExtension<INSiteExt>();
if (ext != null)
{
head.TaxZoneID = ext.UsrTaxZone;
xchange = true;
}
}
if (xchange == true)
{
foreach (PEMclTaxZone zone in PXSelect<PEMclTaxZone,
Where<PEMclTaxZone.taxZoneID, Equal<Required<PEMclTaxZone.taxZoneID>>,
And<PEMclTaxZone.taxCategoryID, Equal<Required<PEMclTaxZone.taxCategoryID>>>>>.Select(Base, head.TaxZoneID, line.TaxCategoryID))
{
if (zone != null)
{
foreach (POTaxTran potax in PXSelect<POTaxTran,
Where<POTaxTran.orderType, Equal<Required<POTaxTran.orderType>>,
And<POTaxTran.orderNbr, Equal<Required<POTaxTran.orderNbr>>>>>.Select(Base, head.OrderType, head.OrderNbr))
{
if (potax != null)
{
potax.TaxID = zone.Taxid;
potax.TaxZoneID = zone.TaxZoneID;
Base.Taxes.Cache.Update(potax);
}
}
}
}
}
}
}
}
When I select the tax area manually, two elements are registered in the tax grid, if I do it by event it only updates the last one, I follow it by code and I see that if it updates, however, it does not reflect in the tax grid.
Here I show evidence, with images.
This step is with an event that is not working.
step 1
step 2:
step 3:
manually select the tax area, selected from the same tab.
step 1:
step 2:
That's how it should go, that's what I want the event to do.
Please tell me what I am failing in the event, I hope I have been clear, thanks.
The functions that grab these are the Tax Zone Extensions. You would want to override the GetDefaultTaxZone function of POOrderEntry
[PXOverride]
public virtual string GetDefaultTaxZone(POOrder row,
Func<POOrder, string> baseMethod)
{
//logic before base function
baseMethod(row);
//logic after base function
}
If you do not want any of the code to be run, feel free to copy the initial function and do not call the baseMethod delegate.

Unable to Copy UDF from POLine (PO301000) to POReceiptLine(PO302000) on "Enter PO Receipt" Action

I have created 2 UDF's in POLine and POReceiptLine, I am trying to copy values of those UDF's from POLine to POReceiptLine on "Enter PO Receipt" action in PO Screen(PO301000). My code is getting executed but the values are not getting copied. Please suggest, Thanks
protected void POReceipt_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (POReceipt)e.Row;
POReceiptLine row1 = new POReceiptLine();
if (Base.Document.Current != null)
{
foreach (POReceiptLine tran in Base.transactions.Select())
{
POLine xPOLine = PXSelect<POLine,
Where<POLine.orderNbr, Equal<Current<POLine.orderNbr>>,
And<POLine.orderType, Equal<Current<POLine.orderType>>>>>.Select(Base, tran.PONbr, tran.POType);
if (xPOLine != null)
{
POLineExt poLineExt = PXCache<POLine>.GetExtension<POLineExt>(xPOLine);
POReceiptLineExt poReceiptLineExt = PXCache<POReceiptLine>.GetExtension<POReceiptLineExt>(row1);
poReceiptLineExt.UsrWarrantyTerms = poLineExt.UsrWarrantyTerms;
poReceiptLineExt.UsrVendorWarrantyDate = poLineExt.UsrVendorWarrantyDate;
}
return;
}
}
}
####...Section 2..####### I have tried using this below code as well but No Luck.
protected virtual void _(Events.FieldDefaulting<POReceiptLineExt.usrWarrantyTerms> e)
{
POReceiptLine row = (POReceiptLine)e.Row;
if (row != null)
{
POReceiptLineExt receiptLineExt = row.GetExtension<POReceiptLineExt>();
POLine line = SelectFrom<POLine>
.Where<POLine.pONbr.IsEqual<#P.AsString>
.And<POLine.lineNbr.IsEqual<#P.AsInt>>>
.View.Select(Base, row.PONbr, row.POLineNbr);
POLineExt lineExt = line.GetExtension<POLineExt>();
if (lineExt?.UsrWarrantyTerms != null && receiptLineExt != null)
{
e.NewValue = receiptLineExt.UsrWarrantyTerms;
}
}
}
protected void POReceiptLine_ReceiptNbr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POReceiptLine)e.Row;
if (row == null) return;
cache.SetDefaultExt<POReceiptLineExt.usrWarrantyTerms>(row);
}
Not sure of your version, so I'll answer per version 2020R2 that I am running.
Observations:
You seem to be returning after the 1st POReceiptLine in the transactions view. More importantly, the placement would seem more appropriate on the POReceiptLine_RowPersisting event where you would not have to do the foreach within the RowPersisting. Lastly, off the top of my head, I can't recall if you need to update the cache when doing this in row persisting if you are working on the record being persisted, but you are working on a different record meaning you likely need to update the cache which gets tricky inside RowPersisting events. (For example, you may not know if the other cache was already persisted.)
Flow of the action:
POOrderEntry contains the action CreatePOReceipt which, in turn, initializes POReceiptEntry and creates the receipt from the order via CreateReceiptFrom(...) which then calls AddPOLine(...). Subsequently, the POReceiptLine is created via line = this.transactions.Insert(line);.
Recommendation:
In 2020R2, it seems your code belongs in POReceiptEntry, but you did not specify where you are putting it. If you placed it in POOrderEntry, the event never fires.
Try putting something like this in POReceiptEntry (do similar for the other field also).
protected virtual void _(Events.FieldDefaulting<POReceiptLineExt.UsrWarrantyTerms> e)
{
POReceiptLine row = (POReceiptLine) e.Row;
if(row != null)
{
POReceiptLineExt receiptLineExt = row.GetExtension<POReceiptLineExt>();
POLine line = SelectFrom<POLine>
.Where<POLine.pONbr.IsEqual<#P.AsString>
.And<POLine.lineNbr.IsEqual<#P.AsInt>>>
.View.Select(Base, row.PONbr, row.POLineNbr);
POLineExt lineExt = line.GetExtension<POLineExt>();
if(lineExt?.UsrWarrantyTerms != null && receiptLineExt != null)
{
e.NewValue = receiptLineExt.UsrWarrantyTerms;
}
}
}
Since the PONbr and LineNbr fields may not be set yet, you may need to use SetDefaultExt for those 2 fields at the appropriate place. (I'd suggest maybe trying in the POReceiptLine.POLineNbr FieldUpdated event.) I believe the insert from the action coming from POOrderEntry already has the fields filled in, but that may not be the case in every way the POReceiptLine record is created, so you want to be sure you are setting the values EVERY time that it is warranted.
I have got a solution to this issue i.e. by using field level event and calling the function from a field level event, the below code is working perfectly fine for me. Thanks.
protected void POReceiptLine_POLineNbr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POReceiptLine)e.Row;
CarryForwardFromPO(row);
}
public void CarryForwardFromPO(POReceiptLine row)
{
if (row.PONbr == null || row.POType == null || row.POLineNbr == null)
return;
POReceiptLineExt _polext = PXCache<POReceiptLine>.GetExtension<POReceiptLineExt>(row);
if (row.PONbr != null)
{
POLine xPOLine = PXSelect<POLine,
Where<POLine.orderNbr, Equal<Required<POLine.orderNbr>>,
And<POLine.orderType, Equal<Required<POLine.orderType>>,
And<POLine.lineNbr, Equal<Required<POLine.lineNbr>>>>>>.Select(Base, row.PONbr, row.POType, row.POLineNbr);
if (xPOLine != null)
{
POLineExt xPOLineExt = PXCache<POLine>.GetExtension<POLineExt>(xPOLine);
if (xPOLineExt != null)
{
if (xPOLineExt.UsrVendWarrantyType != null)
{
_polext.UsrVendWarrantyType = xPOLineExt.UsrVendWarrantyType.Trim();
}
if (xPOLineExt.UsrWarrantyTerms != null)
{
_polext.UsrWarrantyTerms = xPOLineExt.UsrWarrantyTerms.Trim();
}
if (xPOLineExt.UsrVendorWarrantyDate != null)
{
_polext.UsrVendorWarrantyDate = xPOLineExt.UsrVendorWarrantyDate;
}
}
}
}
}

Adding filters to data views with IEnumerable functions

I am working on customization to add some filters to the existing data view.
The Activity data view on the Employee Time Activities page.
I have added the Customer property to PMTimeActivity and OwnedFilter.
Now I need to modify the activity method to take into consideration the Customer filter.
The only way to do this is to override the method with one of the following scenarios:
without calling the base method and copying the code and adding the
filter part
with calling the base method and checking the condition on each
returned record.
The first scenario is making this part of customization very problematic because it will require to review this code every time the customization is being upgraded to any other build.
The second scenario is not good from a performance view.
Has anybody faced this issue and how can this be done in an acceptable way?
Below is the code of the activity method:
protected virtual IEnumerable activity()
{
List<object> args = new List<object>();
EmployeeActivitiesEntry.PMTimeActivityFilter filterRow = this.Filter.Current;
if (filterRow == null)
{
return null;
}
BqlCommand cmd = BqlCommand.CreateInstance(new Type[]
{
typeof(Select2<EPActivityApprove, LeftJoin<EPEarningType, On<EPEarningType.typeCD, Equal<PMTimeActivity.earningTypeID>>, LeftJoin<CRActivityLink, On<CRActivityLink.noteID, Equal<PMTimeActivity.refNoteID>>, LeftJoin<CRCase, On<CRCase.noteID, Equal<CRActivityLink.refNoteID>>, LeftJoin<ContractEx, On<CRCase.contractID, Equal<ContractEx.contractID>>>>>>, Where<EPActivityApprove.ownerID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.ownerID>>, And<EPActivityApprove.trackTime, Equal<True>, And<PMTimeActivity.isCorrected, Equal<False>>>>, OrderBy<Desc<EPActivityApprove.date>>>)
});
if (filterRow.ProjectID != null)
{
cmd = cmd.WhereAnd<Where<EPActivityApprove.projectID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectID>>>>();
}
if (filterRow.ProjectTaskID != null)
{
cmd = cmd.WhereAnd<Where<EPActivityApprove.projectTaskID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectTaskID>>>>();
}
if (filterRow.FromWeek != null || filterRow.TillWeek != null)
{
List<Type> cmdList = new List<Type>();
bool? includeReject = filterRow.IncludeReject;
bool flag = true;
if (includeReject.GetValueOrDefault() == flag & includeReject != null)
{
cmdList.Add(typeof(Where<, , >));
cmdList.Add(typeof(EPActivityApprove.approvalStatus));
cmdList.Add(typeof(Equal<ActivityStatusListAttribute.rejected>));
cmdList.Add(typeof(Or<>));
}
if (filterRow.FromWeek != null)
{
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(Where<, , >));
}
else
{
cmdList.Add(typeof(Where<, >));
}
cmdList.Add(typeof(EPActivityApprove.weekID));
cmdList.Add(typeof(GreaterEqual<Required<EmployeeActivitiesEntry.PMTimeActivityFilter.fromWeek>>));
args.Add(filterRow.FromWeek);
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(And<>));
}
}
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(Where<EPActivityApprove.weekID, LessEqual<Required<EmployeeActivitiesEntry.PMTimeActivityFilter.tillWeek>>>));
args.Add(filterRow.TillWeek);
}
cmd = cmd.WhereAnd(BqlCommand.Compose(cmdList.ToArray()));
}
return new PXView(this, false, cmd).SelectMultiBound(new object[]
{
this.Filter.Current
}, args.ToArray());
}
I would consider to try work with PXView, which was described by Sergey here.
In case of Employee activities time card it may look like this:
public class EmployeeExt : PXGraphExtension<EmployeeActivitiesEntry>
{
protected virtual IEnumerable activity()
{
var sel = new PXView(Base, true, Base.Activity.View.BqlSelect);
if(true)
{
sel.WhereAnd<Where<EPActivityApprove.projectID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectID>>>>();
}
int totalRow = 0;
int startRow = PXView.StartRow;
return sel.Select(PXView.Currents, PXView.Parameters,
PXView.Searches, PXView.SortColumns, PXView.Descendings,
PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRow);
}
}

Need help carrying Sales Order user fields to Create Purchase order screen

I have a customization where I have added three user fields to the Sales Order (SO301000) screen transactions grid. I would like to set fields on the 'Create Purchase Order' screen (PO505000). I had used the POFixedDemand's 'RowSelected' event, which works fine - but that causes a problem when anyone tries to modify anything in a row - which re-triggers that event - not a desired outcome.
I've tried the 'RowInserting' and 'RowInserted' events - but they're never triggered. I'm assuming at this point that I'll have to intercept some code in the 'POCreate' BLC that creates the POFixedDemand records in the Create Purchase Order screen - but I don't really know where to start. Would I put it somewhere in the EnumerateAndPrepareFixedDemands method?
Here's the code I created which works for the RowSelected event, but is no good for when a row is modified by a user. Any help is appreciated. Thank you.
protected virtual void POFixedDemand_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var pofd = (POFixedDemand)e.Row;
if (pofd == null) return;
var filter = Base.Filter.Current;
var ordernbr = filter.OrderNbr;
var ordertype = filter.OrderType;
var solinesplit = (SOLineSplit)PXSelect<SOLineSplit, Where<SOLineSplit.planID, Equal<Required<SOLineSplit.planID>>>>.Select(Base, pofd.PlanID);
if (solinesplit != null)
{
var soline = (SOLine)PXSelect<SOLine,
Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
And<SOLine.orderType, Equal<Required<SOLine.orderType>>,
And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>.Select(Base, solinesplit.OrderNbr, solinesplit.OrderType, solinesplit.LineNbr);
if (soline != null)
{
var solineext = PXCache<SOLine>.GetExtension<SOLineExt>(soline);
pofd.VendorID = solineext.UsrVendor;
pofd.EffPrice = solineext.UsrVendorUnitCost;
pofd.ExtCost = solineext.UsrVendorExtendedCost;
//Now set the Vendor location...
var location = (Location)PXSelect<Location,
Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(Base, pofd.VendorID);
if (location != null)
{
pofd.LocationID = location.LocationID;
}
}
}
}
I'm assuming at this point that I'll have to intercept some code in
the 'POCreate' BLC
Yes you need to do something along those lines.
There's a similar answer here for initializing the POLine instead of POFixedDemand:
https://stackoverflow.com/a/37255340/7376238
With some minor adjustments, the general pattern would be:
public class POCreateExt : PXGraphExtension<POCreate>
{
public override void Initialize()
{
PXGraph.InstanceCreated.AddHandler<POOrderEntry>((graph) =>
{
graph.RowInserting.AddHandler<POFixedDemand>((sender, e) =>
{
// Initialize fields when row is inserted
POFixedDemand demand = e.Row as POFixedDemand;
demand.DACField = [initialization value];
});
graph.RowUpdating.AddHandler<POFixedDemand>((sender, e) =>
{
// Sometimes fields are updated so you need to
// hook RowUpdating too and re-initialize
POFixedDemand demand = e.NewRow as POFixedDemand;
demand.DACField = [initialization value];
});
});
}
}
What I came up with after some investigation is to override the 'EnumerateAndPrepareFixedDemands' method to set the values. Code is as follows:
public delegate IEnumerable EnumerateAndPrepareFixedDemandsDelegate(PXResultset<POFixedDemand> fixedDemands);
[PXOverride]
public IEnumerable EnumerateAndPrepareFixedDemands(PXResultset<POFixedDemand> fixedDemands, EnumerateAndPrepareFixedDemandsDelegate baseMethod)
{
foreach (PXResult<POFixedDemand> rec in fixedDemands)
{
POFixedDemand demand = rec;
var solinesplit = (SOLineSplit)PXSelect<SOLineSplit, Where<SOLineSplit.planID, Equal<Required<SOLineSplit.planID>>>>.Select(Base, demand.PlanID);
if (solinesplit != null)
{
var soline = (SOLine)PXSelect<SOLine,
Where<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>,
And<SOLine.orderType, Equal<Required<SOLine.orderType>>,
And<SOLine.lineNbr, Equal<Required<SOLine.lineNbr>>>>>>.Select(Base, solinesplit.OrderNbr, solinesplit.OrderType, solinesplit.LineNbr);
if (soline != null)
{
var solineext = PXCache<SOLine>.GetExtension<SOLineExt>(soline);
demand.VendorID = solineext.UsrVendor;
demand.EffPrice = solineext.UsrVendorUnitCost;
demand.ExtCost = solineext.UsrVendorExtendedCost;
//Now set the Vendor location...
var location = (Location)PXSelect<Location,
Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>.Select(Base, solineext.UsrVendor);
if (location != null)
{
demand.VendorLocationID = location.LocationID;
}
}
}
}
return baseMethod(fixedDemands);
}

How can I save a custom field on ARCashSale after the Release process is complete?

When I release a Cash Sales document, after everything verifies successfully and the GL Batch is created, I execute code which created a second GL Batch that handles other transactions related to the cash sale. After that batch is created, I want to save the second GL Batch's Ref Nbr on the Cash Sales document as well. When I try to save it, I get an error:
Here is my code overriding the normal Release process:
public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
ARCashSale cashSale = Base.Document.Current;
PXGraph.InstanceCreated.AddHandler<JournalEntry>(delegate (JournalEntry oldJournalEntry)
{
oldJournalEntry.RowPersisted.AddHandler<Batch>(delegate (PXCache sender, PXRowPersistedEventArgs e)
{
Batch oldBatch = oldJournalEntry.BatchModule.Current;
if (oldBatch != null && isCreated == false && e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Completed)
{
isCreated = true;
if (CFBSAdjustments.Select().Count > 0)
{
JournalEntry newJournalEntry = PXGraph.CreateInstance<JournalEntry>();
Batch newBatch = new Batch();
newBatch = newJournalEntry.BatchModule.Insert(newBatch);
Customer customer = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, cashSale.CustomerID);
newBatch.Description = "Fund Entry for Cash Sales Reference " + cashSale.RefNbr;
newBatch.FinPeriodID = oldBatch.FinPeriodID;
newBatch.LedgerID = oldBatch.LedgerID;
newBatch.DateEntered = oldBatch.DateEntered;
decimal? debit = 0;
decimal? credit = 0;
foreach (CFBSCashSalesAdjustment row in CFBSAdjustments.Select())
{
GLTran tran = newJournalEntry.GLTranModuleBatNbr.Insert();
tran.SummPost = true;
tran.BranchID = cashSale.BranchID;
tran.TranType = GLTran.tranClass.Normal;
tran.TranClass = GL.Messages.RoundingDiff;
tran.LedgerID = newBatch.LedgerID;
tran.FinPeriodID = newBatch.FinPeriodID;
tran.TranDate = newBatch.DateEntered;
tran.CuryInfoID = Base.currencyinfo.Current.CuryInfoID;
tran.AccountID = row.Account;
tran.SubID = row.Subaccount;
tran.DebitAmt = row.DebitAmt;
tran.CuryDebitAmt = row.DebitAmt;
debit += row.DebitAmt;
tran.CreditAmt = row.CreditAmt;
tran.CuryCreditAmt = row.CreditAmt;
credit += row.CreditAmt;
tran.RefNbr = row.CashSalesRefNbr;
tran.TranDesc = customer.AcctCD + " - " + customer.AcctName;
newJournalEntry.GLTranModuleBatNbr.Update(tran);
}
newBatch = newJournalEntry.BatchModule.Update(newBatch);
if (GLSetup.Current.GetExtension<GLSetupExt>().UsrAutoRelease == true)
{
newJournalEntry.BatchModule.Current.Hold = false;
newJournalEntry.release.Press();
}
newJournalEntry.Save.Press();
if (isCreated)
isCreated = false;
cashSale.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
//Base.Document.Current.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
//Base.dummy_CATran.View.RequestRefresh();
Base.Document.Update(cashSale);
//TODO - Figure out why the fund batch isn't saving to the Cash Sale
Base.Actions.PressSave();
//Base.dummy_CATran.Cache.ClearQueryCache();
//Base.Persist(typeof(ARCashSale), PXDBOperation.Update);
}
}
});
});
return baseMethod(adapter);
}
I left in all of the different methods I've tried to get the ref nbr to save. I've ever tried to add a field updated handler for the BatchNbr field and force the new number in that way, but it did not work.
EDIT: I also noticed that I cannot successfully set an extended field on the Batch DAC. For example, I have the line newBatch.GetExtension<BatchExt>().ExtRefNbr = cashSale.RefNbr; to set the ref nbr in that document as well, but any time I run 'NewJournal.Press.Save()' it changes the set value of the extended field to null. If anyone knows how to set the extension field, I may be able to work with that instead to go down a different path that may do what I need.
I believe the appropriate place to perform your update is in graph ARDocumentRelease. Try something like this....
public class ARDocumentReleaseExtension : PXGraphExtension<ARDocumentRelease>
{
public override void Initialize()
{
ARSetup setup = Base.arsetup.Current;
Base.ARDocumentList.SetProcessDelegate(
delegate (List<BalancedARDocument> list)
{
List<ARRegister> newlist = new List<ARRegister>(list.Count);
foreach (BalancedARDocument doc in list)
{
newlist.Add(doc);
}
ARDocumentRelease.ReleaseDoc(newlist, true);
CreateSecondBatch(newlist);
}
);
Base.ARDocumentList.SetProcessCaption(PX.Objects.AR.Messages.Release);
Base.ARDocumentList.SetProcessAllCaption(PX.Objects.AR.Messages.ReleaseAll);
}
private void CreateSecondBatch(List<ARRegister> docs)
{
foreach(BalancedARDocument register in docs)
{
if (register.DocType == ARDocType.CashSale)
{
//create the second batch and assign the 2nd ref nbr to the cash sale user field
}
}
}
}

Resources