Skip to content

Instantly share code, notes, and snippets.

@smarenich
Last active July 19, 2018 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarenich/d0b84b80267cdbd75338409c9b48cd42 to your computer and use it in GitHub Desktop.
Save smarenich/d0b84b80267cdbd75338409c9b48cd42 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.GL;
using PX.Objects.CS;
using PX.Objects.CR;
using PX.Objects.SO;
namespace MergedDAC
{
[Serializable]
public class CustomerOverviewFilter : IBqlTable
{
#region CustomerID
[Customer(DescriptionField = typeof(Customer.acctName), /*IsDBField = false,*/ DisplayName = "Customer ID")]
public virtual Int32? CustomerID { get; set; }
public abstract class customerID : IBqlField { }
#endregion
}
public class AnyDocument : IBqlTable
{
#region Paid
[PXDBBool()]
[PXUIField(DisplayName = "Applied")]
public bool? Paid { get; set; }
public abstract class paid : IBqlField { }
#endregion
#region Module
[PXString(2, IsKey = true, IsFixed = true)]
[PXUIField(DisplayName = "Module", Enabled = false)]
[PXStringList(new string[] { arModule.value, soModule.value }, new String[] { arModule.value, soModule.value })]
public string Module { get; set; }
public abstract class module : IBqlField { }
#endregion
#region DocType
[PXString(3, IsKey = true, IsFixed = false)]
[PXUIField(DisplayName = "Doc Type", Enabled = false)]
public string DocType { get; set; }
public abstract class docType : IBqlField { }
#endregion
#region RefNbr
[PXString(20, IsKey = true, IsUnicode = true)]
[PXUIField(DisplayName = "Ref Nbr", Enabled = false)]
public string RefNbr { get; set; }
public abstract class refNbr : IBqlField { }
#endregion
#region CustomerID
[Customer(DescriptionField = typeof(Customer.acctCD), IsDBField = false, DisplayName = "Customer ID")]
public virtual Int32? CustomerID { get; set; }
public abstract class customerID : IBqlField { }
#endregion
#region CustomerName
[PXString()]
[PXUIField(DisplayName = "Customer Name", Enabled = false)]
public virtual string CustomerName { get; set; }
public abstract class customerName : IBqlField { }
#endregion
#region InvoiceNbr
public abstract class invoiceNbr : PX.Data.IBqlField
{
}
[PXString(15, IsKey = true, IsUnicode = true)]
public virtual String InvoiceNbr
{
get;
set;
}
#endregion
#region DocDate
public abstract class docDate : PX.Data.IBqlField
{
}
protected DateTime? _DocDate;
[PXDate()]
[PXDefault(typeof(AccessInfo.businessDate))]
[PXUIField(DisplayName = "Date", Visibility = PXUIVisibility.SelectorVisible)]
public virtual DateTime? DocDate
{
get
{
return this._DocDate;
}
set
{
this._DocDate = value;
}
}
#endregion
#region DueDate
public abstract class dueDate : PX.Data.IBqlField
{
}
protected DateTime? _DueDate;
[PXDate()]
[PXUIField(DisplayName = "Due Date", Visibility = PXUIVisibility.SelectorVisible)]
public virtual DateTime? DueDate
{
get
{
return this._DueDate;
}
set
{
this._DueDate = value;
}
}
#endregion
#region CuryOrigDocAmt
public abstract class curyOrigDocAmt : PX.Data.IBqlField
{
}
protected Decimal? _CuryOrigDocAmt;
[PXDefault(TypeCode.Decimal, "0.0")]
[PXDBBaseCury()]
[PXUIField(DisplayName = "Amount", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? CuryOrigDocAmt
{
get
{
return this._CuryOrigDocAmt;
}
set
{
this._CuryOrigDocAmt = value;
}
}
#endregion
#region CuryDocBal
public abstract class curyDocBal : PX.Data.IBqlField
{
}
protected Decimal? _CuryDocBal;
[PXDefault(TypeCode.Decimal, "0.0")]
[PXBaseCury()]
[PXUIField(DisplayName = "Balance", Visibility = PXUIVisibility.SelectorVisible, Enabled = false)]
public virtual Decimal? CuryDocBal
{
get
{
return this._CuryDocBal;
}
set
{
this._CuryDocBal = value;
}
}
#endregion
#region DocDesc
public abstract class docDesc : PX.Data.IBqlField
{
}
protected String _DocDesc;
[PXString(150, IsUnicode = true)]
[PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.SelectorVisible)]
public virtual String DocDesc
{
get
{
return this._DocDesc;
}
set
{
this._DocDesc = value;
}
}
#endregion
#region Status
public abstract class status : IBqlField { }
protected string _Status;
[PXDBString(1, IsFixed = true)]
[PXDefault(ARDocStatus.Hold)]
[PXUIField(DisplayName = "Status", Visibility = PXUIVisibility.SelectorVisible, Enabled = false)]
[ARDocStatus.List]
public virtual string Status
{
get
{
return this._Status;
}
set
{
this._Status = value;
}
}
#endregion
#region PaymentMethodID
[PXDBString(10, IsUnicode = true)]
[PXSelector(typeof(Search<PaymentMethod.paymentMethodID,
Where<PaymentMethod.isActive, Equal<True>,
And<PaymentMethod.useForAR, Equal<True>>>>),
DescriptionField = typeof(PaymentMethod.descr))]
[PXDefault(typeof(Search<PaymentMethod.paymentMethodID,
Where<PaymentMethod.isActive, Equal<True>,
And<PaymentMethod.useForAR, Equal<True>>>>))]
[PXUIFieldAttribute(DisplayName = "Payment Method", Required = true)]
public virtual String PaymentMethodID { get; set; }
public abstract class paymentMethodID : PX.Data.IBqlField { }
#endregion
#region Terms
[PXString(50, IsUnicode = true)]
[PXUIField(DisplayName = "Payment Terms", Enabled = false, IsReadOnly = true)]
public virtual string Terms { get; set; }
public abstract class terms : IBqlField { }
#endregion
#region LastModifiedByID
public abstract class lastModifiedByID : PX.Data.IBqlField
{
}
protected Guid? _LastModifiedByID;
[PXDBLastModifiedByID(DisplayName = "Officer")]
public virtual Guid? LastModifiedByID
{
get
{
return this._LastModifiedByID;
}
set
{
this._LastModifiedByID = value;
}
}
#endregion
}
public class CustomerOverview : PXGraph<CustomerOverview>
{
public PXFilter<CustomerOverviewFilter> MasterView;
public PXCancel<CustomerOverviewFilter> Cancel;
public override bool IsDirty { get { return false; } }
[PXVirtualDAC]
public PXSelectOrderBy<AnyDocument, OrderBy<Desc<AnyDocument.docDate>>> AllDocuments;
public IEnumerable allDocuments()
{
CustomerOverviewFilter filter = MasterView.Current;
if (filter.CustomerID == null) yield break;
int?[] relevantCustomerIDs = CustomerFamilyHelper
.GetCustomerFamily<PX.Objects.AR.Override.BAccount.consolidatingBAccountID>(this, filter.CustomerID)
.Where(customerInfo => customerInfo.BusinessAccount.BAccountID != null)
.Select(customerInfo => customerInfo.BusinessAccount.BAccountID)
.ToArray();
foreach (AnyDocument doc in GetInvoices(relevantCustomerIDs, false))
{
yield return doc;
}
foreach (AnyDocument doc in GetPayments(relevantCustomerIDs, false))
{
yield return doc;
}
foreach (AnyDocument doc in GetOrders(relevantCustomerIDs, false))
{
yield return doc;
}
}
public PXAction<CustomerOverviewFilter> NavigateToDocument;
[PXButton()]
[PXUIField(DisplayName = "Navigate to Document")]
public void navigateToDocument()
{
AnyDocument row = (AnyDocument)AllDocuments.Cache.Current;
if(row.Module == soModule.value)
{
SOOrder doc = PXSelect<SOOrder,
Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>,
And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>.Select(this, row.DocType, row.RefNbr);
if(doc != null)
{
SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();
graph.Document.Current = doc;
throw new PXRedirectRequiredException(graph, true, "View Doc");
}
}
if (row.Module == arModule.value)
{
ARInvoice inv = PXSelect<ARInvoice,
Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>.Select(this, row.DocType, row.RefNbr);
if (inv != null)
{
ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();
graph.Document.Current = inv;
throw new PXRedirectRequiredException(graph, true, "View Doc");
}
ARPayment pmt = PXSelect<ARPayment,
Where<ARPayment.docType, Equal<Required<ARPayment.docType>>,
And<ARPayment.refNbr, Equal<Required<ARPayment.refNbr>>>>>.Select(this, row.DocType, row.RefNbr);
if (pmt != null)
{
ARPaymentEntry graph = PXGraph.CreateInstance<ARPaymentEntry>();
graph.Document.Current = pmt;
throw new PXRedirectRequiredException(graph, true, "View Doc");
}
}
}
public IEnumerable GetPayments(int?[] customers, bool onlyOpen)
{
foreach (PXResult<ARPayment> res in PXSelectReadonly2<ARPayment,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<ARPayment.customerID>>>,
Where<ARPayment.customerID, In<Required<ARPayment.customerID>>,
And<ARPayment.released, Equal<True>,
And <Where<ARPayment.openDoc, Equal<Required<ARPayment.openDoc>>,
Or<Required<ARPayment.openDoc>, Equal<False>>>>>>>.Select(this, customers, onlyOpen, onlyOpen))
{
ARPayment row = res.GetItem<ARPayment>();
BAccount bac = res.GetItem<BAccount>();
AnyDocument doc = new AnyDocument();
doc.Module = "AR";
doc.DocType = row.DocType;
doc.RefNbr = row.RefNbr;
doc.CustomerID = row.CustomerID;
doc.CustomerName = bac.AcctName;
doc.InvoiceNbr = row.ExtRefNbr;
doc.DocDate = row.DocDate;
doc.DueDate = row.DueDate;
doc.DocDesc = row.DocDesc;
doc.CuryOrigDocAmt = row.CuryOrigDocAmt;
doc.CuryDocBal = row.CuryDocBal;
doc.Status = row.Status;
doc.PaymentMethodID = row.PaymentMethodID;
doc.LastModifiedByID = row.LastModifiedByID;
doc.Paid = false;
yield return doc;
}
}
public IEnumerable GetInvoices(int?[] customers, bool onlyOpen)
{
foreach (PXResult<ARInvoice> res in PXSelectReadonly2<ARInvoice,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<ARInvoice.customerID>>>,
Where<ARInvoice.customerID, In< Required <ARInvoice.customerID>>,
And<ARInvoice.released, Equal<True>,
And<Where<ARInvoice.openDoc, Equal<Required<ARInvoice.openDoc>>,
Or<Required<ARInvoice.openDoc>, Equal<False>>>>>>>.Select(this, customers, onlyOpen, onlyOpen))
{
ARInvoice row = res.GetItem<ARInvoice>();
BAccount bac = res.GetItem<BAccount>();
AnyDocument doc = new AnyDocument();
doc.Module = "AR";
doc.DocType = row.DocType;
doc.RefNbr = row.RefNbr;
doc.CustomerID = row.CustomerID;
doc.CustomerName = bac.AcctName;
doc.InvoiceNbr = row.InvoiceNbr;
doc.DocDate = row.DocDate;
doc.DueDate = row.DueDate;
doc.DocDesc = row.DocDesc;
doc.CuryOrigDocAmt = row.CuryOrigDocAmt;
doc.CuryDocBal = row.CuryDocBal;
doc.Status = row.Status;
doc.PaymentMethodID = row.PaymentMethodID;
doc.Terms = row.TermsID;
doc.LastModifiedByID = row.LastModifiedByID;
doc.Paid = false;
yield return doc;
}
}
public IEnumerable GetOrders(int?[] customers, bool onlyOpen)
{
foreach (PXResult<SOOrder> res in PXSelectReadonly2<SOOrder,
InnerJoin<BAccount, On<BAccount.bAccountID, Equal<SOOrder.customerID>>>,
Where<SOOrder.customerID, In<Required<SOOrder.customerID>>,
And<SOOrder.approved, Equal<True>,
And<Where<SOOrder.openDoc, Equal<Required<SOOrder.openDoc>>,
Or<Required<SOOrder.openDoc>, Equal<False>>>>>>>.Select(this, customers, onlyOpen, onlyOpen))
{
SOOrder row = res.GetItem<SOOrder>();
BAccount bac = res.GetItem<BAccount>();
AnyDocument doc = new AnyDocument();
doc.Module = "SO";
doc.DocType = row.OrderType;
doc.RefNbr = row.OrderNbr;
doc.CustomerID = row.CustomerID;
doc.CustomerName = bac.AcctName;
doc.InvoiceNbr = row.InvoiceNbr;
doc.DocDate = row.OrderDate;
doc.DueDate = row.DueDate;
doc.DocDesc = row.DocDesc;
doc.CuryOrigDocAmt = row.CuryOrderTotal;
doc.CuryDocBal = row.CuryUnpaidBalance;
doc.Status = row.Status;
doc.PaymentMethodID = row.PaymentMethodID;
doc.Terms = row.TermsID;
doc.LastModifiedByID = row.LastModifiedByID;
doc.Paid = false;
yield return doc;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment