I’m still new to programming in Acumatica, so I may have gotten several things wrong here, but I’m trying to get a single value to be returned from this BQL statement which should be the sum of a specific customer’s invoices for the current year for the price of goods only. I’m getting a highlighted error in Visual Studio that says that the entire BQL statement is a type that is not valid in the given context. I’m also not sure if the Convert.ToDecimal function will work with an ARInvoice.curyGoodsTotal object.
namespace PX.Objects.AR
{
public class DateYearStart : PX.Data.BQL.BqlDateTime.Constant<DateYearStart>
{
public DateYearStart()
: base(new DateTime(DateTime.Today.Year, 1, 1))
{
}
}
public class DocTypeString : PX.Data.BQL.BqlString.Constant<DocTypeString>
{
public DocTypeString()
: base("INV")
{
}
}
public class CustomerMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerMaint>
{
protected virtual void YTD_Invoiced_Total_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
if (e.Row == null) return;
BAccount account = (BAccount)e.Row;
BAccountExt accountExt = sender.GetExtension<BAccountExt>(account);
if (accountExt != null)
{
List<ARInvoice.curyGoodsTotal> curyGoodsList = SelectFrom<ARInvoice>
.LeftJoin<ARRegister>
.On<ARInvoice.refNbr.IsEqual<ARRegister.refNbr>>
.Where<
Brackets<ARInvoice.docType.IsEqual<Use<DocTypeString>.AsString>.
And<ARRegister.customerID.IsEqual<Use<Current<Customer.bAccountID>>.AsInt>>.
And<ARRegister.docDate.IsLessEqual<Use<Today>.AsDateTime>>.
And<ARRegister.docDate.IsGreaterEqual<Use<DateYearStart>.AsDateTime>>>>.
AggregateTo<Sum<ARInvoice.curyGoodsTotal>>;
accountExt.UsrYTDInvTotal = Convert.ToDecimal(curyGoodsListu0]);
}
}
}
}