I am trying to create a new processing screen which only shows sales orders with specific criteria.
I have the following at the moment which works and allows me to process sales orders to assign the current user as owner. This is the start of a more complex process but I just need to get the basics working currently:
using System;
using PX.Data;
using PX.Objects.SO;
using PX.Data.BQL.Fluent;
using PX.TM;
namespace PPCustomOrderProcess
{
public class AIProcessOrdersCust : PXGraph<AIProcessOrdersCust>
{
public class wOOrderType: PX.Data.Constant<string> {
public wOOrderType() : base("WO") { }
}
public class paymentMethodAFFIRM: PX.Data.Constant<string> {
public paymentMethodAFFIRM() : base("AFFIRM") { }
}
public class paymentMethodAFTERPAY: PX.Data.Constant<string> {
public paymentMethodAFTERPAY() : base("AFTERPAY") { }
}
public class paymentMethodPAYPAL: PX.Data.Constant<string> {
public paymentMethodPAYPAL() : base("PAYPAL") { }
}
public class paymentMethodCCARD: PX.Data.Constant<string> {
public paymentMethodCCARD() : base("CCARD") { }
}
public PXCancel<SOOrder> Cancel;
public PXProcessing<SOOrder,
Where<SOOrder.orderType, Equal<wOOrderType>,
And<
Where<
SOOrder.paymentMethodID, Equal<paymentMethodAFFIRM>,
Or<SOOrder.paymentMethodID, Equal<paymentMethodPAYPAL>,
Or<SOOrder.paymentMethodID, Equal<paymentMethodAFTERPAY>,
Or<SOOrder.paymentMethodID, Equal<paymentMethodCCARD>
>
>
>
>
>
>
> AISOOrder;
public AIProcessOrdersCust()
{
AISOOrder.SetProcessCaption("Assign");
AISOOrder.SetProcessAllCaption("Assign All");
AISOOrder.SetProcessDelegate(ProcessOrder);
}
public PXFilter<DetailsTable> DetailsView;
[Serializable]
public class DetailsTable : IBqlTable
{
}
private static void ProcessOrder(SOOrder order)
{
var graph = PXGraph.CreateInstance<SOOrderEntry>();
// Select the order
graph.Document.Current = graph.Document.Search<SOOrder.orderNbr>(order.OrderNbr, order.OrderType);
if (graph.Document.Current != null)
{
int? currentUserContactID = PXAccess.GetContactID();
if (currentUserContactID != null)
{
graph.Document.Cache.SetValueExt<SOOrder.ownerID>(graph.Document.Current, currentUserContactID);
graph.Document.Cache.MarkUpdated(graph.Document.Current);
// Log the new OwnerID for verification
PXTrace.WriteInformation($"Setting OwnerID to {currentUserContactID} for Order {order.OrderNbr}");
// Save the changes
graph.Actions.PressSave();
PXProcessing<SOOrder>.SetInfo($"Order {order.OrderNbr} successfully assigned to user with ContactID: {currentUserContactID}");
}
else
{
PXProcessing<SOOrder>.SetError($"Failed to assign OwnerID: No ContactID found for current user.");
}
}
else
{
PXProcessing<SOOrder>.SetError($"Order {order.OrderNbr} not found.");
}
}
}
}If the paymentMethodID = CCARD I only want to include records where the Customer has 1 or more sales orders with CCARD as PaymentMethodID and order status is completed.
I have been trying various methods but haven’t worked out how to structure the query to achieve that result.
If anyone is able to advise I would really appreciate it.
Thanks,
Phil