Hi all, I need to change the Default Fin Period on the Reverse and apply action. Needs to default the the current open Period. I developed this below and it works. Does it look right? I have not made a lot of these changes.
Thank you
using System;
using System.Collections;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.GL;
using PX.Objects.GL.FinPeriods;
using PX.Objects.GL.FinPeriods.TableDefinition;
public class ARInvoiceEntry_Ext : PXGraphExtension<ARInvoiceEntry>
{
[PXOverride]
public virtual IEnumerable ReverseInvoiceAndApplyToMemo(
PXAdapter adapter,
Func<PXAdapter, IEnumerable> baseMethod)
{
var result = baseMethod(adapter);
ARInvoice memo = Base.Document.Current;
if (memo != null
&& memo.DocType == ARDocType.CreditMemo
&& memo.OrigDocType == ARDocType.Invoice)
{
string currentPeriod =
PXSelect<FinPeriod,
Where<
FinPeriod.startDate, LessEqual<Required<AccessInfo.businessDate>>,
And<FinPeriod.endDate, Greater<Required<AccessInfo.businessDate>>>>>
.Select(Base, Base.Accessinfo.BusinessDate, Base.Accessinfo.BusinessDate)
?.TopFirst?.FinPeriodID;
if (!string.IsNullOrEmpty(currentPeriod))
{
memo.FinPeriodID = currentPeriod;
memo.TranPeriodID = currentPeriod;
Base.Document.Update(memo);
}
}
return result;
}
}