Default Branch on Payments and Applications (AR302000) - acumatica

I want to display the 'Default Branch' (screenshot 1) from the Customers' (AR303000) Shipping tab to the Payment and Applications'(AR302000) 'LOAD DOCUMENTS' dialog box's, 'Company Branch'(screenshot 2)
Screenshot 1: Customers Default Branch
Screenshot 2: Load Document Company Branch (Payments and Applications)
The code I have does not seem to be displaying the Default Branch from the Customers Shipping tab to the Payments and Applications Company Branch.
Code snippet:
public class ARPaymentEntry_Extension : PXGraphExtension<PX.Objects.AR.ARPaymentEntry>
{
#region Event Handlers
protected void LoadOptions_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (LoadOptions)e.Row;
if (row == null)
{
return;
}
ARPayment aRPayment = Base.Document.Current;
if (aRPayment == null)
{
return;
}
Customer customer = PXSelect<Customer,
Where<Customer.bAccountID, Equal<Required<ARPayment.customerID>>>>
.Select(Base, aRPayment.CustomerID);
if (customer == null)
{
return;
}
Location location = PXSelect<Location,
Where<Location.bAccountID, Equal<Required<ARPayment.customerID>>,
And<Location.locationID, Equal<Required<Customer.defLocationID>>>>>
.Select(Base, aRPayment.CustomerID, customer.DefLocationID);
if (location == null)
{
return;
}
row.BranchID = location.CBranchID;
}
[PXMergeAttributes(Method = MergeMethod.Replace)]
// [OrganizationTree(typeof(organizationID), typeof(branchID), onlyActive: true)]
protected virtual void LoadOptions_OrgBAccountID_CacheAttached(PXCache cache)
{
}

I would move your code into FieldDefaulting for the LoadOptions, rather than row selected.
protected virtual void LoadOptions_OrgBAccountID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs args, PXFieldDefaulting del)
{
var row = (LoadOptions)e.Row;
if (row == null)
{
return;
}
ARPayment aRPayment = Base.Document.Current;
if (aRPayment == null)
{
return;
}
Customer customer = PXSelect<Customer,
Where<Customer.bAccountID, Equal<Required<ARPayment.customerID>>>>
.Select(Base, aRPayment.CustomerID);
if (customer == null)
{
return;
}
Location location = PXSelect<Location,
Where<Location.bAccountID, Equal<Required<ARPayment.customerID>>,
And<Location.locationID, Equal<Required<Customer.defLocationID>>>>>
.Select(Base, aRPayment.CustomerID, customer.DefLocationID);
if (location == null)
{
return;
}
//set the default with customers branch
args.NewValue = location.CBranchID;
}

Related

Changing the Freight Tax Category in Sales order screen is not re- calculating the freight tax

I am changing Freight tax category pragmatically based on the tax category of the item selected in the detail tab
protected virtual void SOOrder_CustomerLocationID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e, PXFieldUpdated del)
{
if (del != null)
del(sender, e);
var row = (SOOrder)e.Row;
Location location = PXSelect<Location, Where<Location.locationID, Equal<Required<Location.locationID>>>>.Select(Base, Base.Document.Current.CustomerLocationID);
if (location != null)
{
string custtaxzone = location.CTaxZoneID;
bool taxableitem = false;
if (custtaxzone == "TAXABLE")
{
foreach (SOLine line in Base.Transactions.Select())
{
if (line.TaxCategoryID == "PATAX")
{
taxableitem = true;
break;
}
}
if (taxableitem)
Base.Document.Current.FreightTaxCategoryID = "PATAX";
else
Base.Document.Current.FreightTaxCategoryID = null;
}
}
}
The value is properly updating but the freight tax is not calculating.
In RowUpdated event, update the DataView after changing the value and invoke calculation of the tax attribute:
public void SOOrder_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
SOOrder row = e.Row as SOOrder;
if (!sender.ObjectsEqual<SOOrder.customerLocationID, SOOrder.customerLocationID>(e.OldRow, e.Row))
{
Base.Document.Current.FreightTaxCategoryID = "PATAX";
Base.Document.Update(Document.Current);
SOOrderTaxAttribute.Calculate<SOOrder.freightTaxCategoryID>(sender, e);
}
}
Invoke the Default attribute to clear the freight tax:
Base.Document.Current.FreightTaxCategoryID = null;
Base.Document.Update(Document.Current);
sender.SetDefaultExt<SOOrder.freightTaxCategoryID>(e.Row);

Acumatica-sales order default customer

Am trying to set a default customer for CS but am am getting an error "RevisionID' cannot be empty" please assist
protected void SOOrder_CustomerID_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
{
SOOrder row = (SOOrder)e.Row;
if(row == null) return;
if (row.OrderType == "CS" || row.OrderType == "SS")
{
row.CustomerID = 7211;
}
else
{
row.CustomerID = null;
}
}
In your specific case FieldDefaulting event must be used instead of FieldUpdating to generate default value for the Customer ID field. According to the API Reference, in FieldDefaulting event handlers the new value must be assigned to the NewValue property of PXFieldDefaultingEventArgs and never directly to the DAC field:
protected void SOOrder_CustomerID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
SOOrder row = (SOOrder)e.Row;
if(row == null) return;
if (row.OrderType == "CS" || row.OrderType == "SS")
{
e.NewValue = 7211;
}
}

RequestDate not update event I use RowUpdate event on SOLine

I just created QT on 28-08-2016 and then change the businessDate to 30-08-2016 and copy it to SOOrder so after copy to SOOrder, I open the QT again and status will change to Completed. But RequestDate on SOLine didn't update.
protected void SOOrder_Status_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (SOOrder)e.Row;
SOOrderExt rowExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);
if(row != null)
{
if(row.OrderType == "QT" && row.Status == "C")
{
rowExt.UsrRequestDate = Base.Accessinfo.BusinessDate;
}
else
{
rowExt.UsrRequestDate = row.OrderDate;
}
}
}
protected void SOOrder_OrderDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (SOOrder)e.Row;
SOOrderExt rowExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);
if(row != null)
{
rowExt.UsrRequestDate = row.OrderDate;
}
}
I think your problem is in the wrong event. You have subscribed to SOLine_RowUpdated, which is event for details. But copy order function will update only document (SOOrder) and will not touch details. You should little bit rethink your flow.
But actually my questions is - why you do not what to use standard logic (as shown on image) that updates requested date for details?
protected void SOOrder_Status_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (SOOrder)e.Row;
SOOrderExt rowExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);
if(row != null)
{
if(row.OrderType == "QT" && row.Status == "C")
{
rowExt.UsrRequestDate = Base.Accessinfo.BusinessDate;
}
else
{
rowExt.UsrRequestDate = row.OrderDate;
}
}
}
protected void SOOrder_OrderDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (SOOrder)e.Row;
SOOrderExt rowExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);
if(row != null)
{
rowExt.UsrRequestDate = row.OrderDate;
}
}

What's the event for changing Severity on screen Case (ScreenID: CR306000)?

After I customized the code below and I want to update SLA by AssignDateTime. But with the Severity changed then my SLA has changed to get datetime from createdDateTime also. I think it should have other event that need to customize.
protected virtual void CRCase_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = e.Row as CRCase;
var oldRow = e.OldRow as CRCase;
CRCaseExt rowExt = PXCache<CRCase>.GetExtension<CRCaseExt>(row);
if (row == null || oldRow == null) return;
if (row.OwnerID == null)
{
row.AssignDate = null;
row.SLAETA = null;
}
else if (oldRow.OwnerID == null)
{
row.AssignDate = PXTimeZoneInfo.Now;
if (row == null || row.AssignDate == null) return;
if (row.ClassID != null && row.Severity != null)
{
var severity = (CRClassSeverityTime)PXSelect<CRClassSeverityTime,
Where<CRClassSeverityTime.caseClassID, Equal<Required<CRClassSeverityTime.caseClassID>>,
And<CRClassSeverityTime.severity, Equal<Required<CRClassSeverityTime.severity>>>>>
.Select(Base, row.ClassID, row.Severity);
if (severity != null && severity.TimeReaction != null)
{
row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)severity.TimeReaction);
}
}
if (row.Severity != null && row.ContractID != null)
{
var template = (Contract)PXSelect<Contract, Where<Contract.contractID, Equal<Required<CRCase.contractID>>>>.Select(Base, row.ContractID);
if (template == null) return;
var sla = (ContractSLAMapping)PXSelect<ContractSLAMapping,
Where<ContractSLAMapping.severity, Equal<Required<CRCase.severity>>,
And<ContractSLAMapping.contractID, Equal<Required<CRCase.contractID>>>>>
.Select(Base, row.Severity, template.TemplateID);
if (sla != null && sla.Period != null)
{
row.SLAETA = ((DateTime)row.AssignDate).AddMinutes((int)sla.Period);
}
}
}
}
SLAETA field is decorated with PXFormulaAttribute to raise FieldDefaulting event every time change is made to one of the following fields:
CRCase.contractID
CRCase.severity
CRCase.caseClassID
public partial class CRCase : IBqlTable, IAssign, IAttributeSupport, IPXSelectable
{
...
#region SLAETA
public abstract class sLAETA : IBqlField { }
[PXDBDate(PreserveTime = true, DisplayMask = "g")]
[PXUIField(DisplayName = "SLA")]
[PXFormula(typeof(Default<CRCase.contractID, CRCase.severity, CRCase.caseClassID>))]
public virtual DateTime? SLAETA { get; set; }
#endregion
...
}
It’s a way better to only customize CRCase_SLAETA_FieldDefaulting handler in the CRCaseMaint BLC extension instead of implementing CRCase_RowUpdated:
public class CRCaseMaint : PXGraph<CRCaseMaint, CRCase>
{
...
protected virtual void CRCase_SLAETA_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
CRCase row = e.Row as CRCase;
if (row == null || row.CreatedDateTime == null) return;
if (row.ClassID != null && row.Severity != null)
{
var severity = (CRClassSeverityTime)PXSelect<CRClassSeverityTime,
Where<CRClassSeverityTime.caseClassID, Equal<Required<CRClassSeverityTime.caseClassID>>,
And<CRClassSeverityTime.severity, Equal<Required<CRClassSeverityTime.severity>>>>>.
Select(this, row.ClassID, row.Severity);
if (severity != null && severity.TimeReaction != null)
{
e.NewValue = ((DateTime)row.CreatedDateTime).AddMinutes((int)severity.TimeReaction);
e.Cancel = true;
}
}
if (row.Severity != null && row.ContractID != null)
{
var template = (Contract)PXSelect<Contract, Where<Contract.contractID, Equal<Required<CRCase.contractID>>>>.Select(this, row.ContractID);
if (template == null) return;
var sla = (ContractSLAMapping)PXSelect<ContractSLAMapping,
Where<ContractSLAMapping.severity, Equal<Required<CRCase.severity>>,
And<ContractSLAMapping.contractID, Equal<Required<CRCase.contractID>>>>>.
Select(this, row.Severity, template.TemplateID);
if (sla != null && sla.Period != null)
{
e.NewValue = ((DateTime)row.CreatedDateTime).AddMinutes((int)sla.Period);
e.Cancel = true;
}
}
}
...
}
You can either use the FieldUpdated Event or in the row updated event you can look for the change of your field.
Eg: row.Severity != oldRow.Severity

Payment Ref(Payment Settings tab) got blocked after customized on SOOrderEntry (Sales Orders)

My coding here after I added it on Code Editor: SOOrderEntry (Sales Orders) the Payment Ref(Payment Settings tab) got blocked.
protected void SOOrder_OrderType_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
SOOrder row = (SOOrder)e.Row;
if(row != null)
{
if(user != null)
{
PX.SM.UsersInRoles role = user;
if(role.Rolename == "Administrator")
{
e.NewValue = "CS";
e.Cancel = true;
}
else
if(role.Rolename == "Sales 01Ao")
{
e.NewValue = "C1";
e.Cancel = true;
}
if(role.Rolename == "Sales 01Do")
{
e.NewValue = "C2";
e.Cancel = true;
}
}
}
}
Payment Ref is enabled only for Order Types of the Cash Sale or the Cash Return AR Document Type:
Please make sure to accordingly set up your C1 and C2 order types.

Resources