Skip to main content
Solved

Overwrite Fin Period on ReverseandApplytoMemo Action

  • December 11, 2025
  • 2 replies
  • 22 views

Forum|alt.badge.img+1

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;
}
}

 

 

Best answer by aleksandrsechin

Hi ​@keithschm 

In general, your code is fine.

The only thing you missed is that you need to specify IsGreaterEqual instead of IsGreater for the endDate field condition (you have to take into account the last day of the month as well).

Additionally, you can optimize it a little by using SelectSingle instead of the Select method to retrieve only one record.

You can also improve the readability of your code by rewriting it in Fluent BQL instead of traditional BQL.

Here is how your code may look in the end:

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.GL.FinPeriods.TableDefinition;
using System;
using System.Collections;

namespace PX.Objects.AR
{
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)
{
var businessDate = Base.Accessinfo.BusinessDate;
var currentPeriod = new SelectFrom<FinPeriod>
.Where<FinPeriod.startDate.IsLessEqual<@P.AsDateTime>.
And<FinPeriod.endDate.IsGreaterEqual<@P.AsDateTime>>>
.View(Base)
.SelectSingle(Base, businessDate, businessDate)?.FinPeriodID;

if (!string.IsNullOrEmpty(currentPeriod))
{
memo.FinPeriodID = currentPeriod;
memo.TranPeriodID = currentPeriod;

Base.Document.Update(memo);
}
}

return result;
}
}
}

 

2 replies

Forum|alt.badge.img+3

Hi ​@keithschm 

In general, your code is fine.

The only thing you missed is that you need to specify IsGreaterEqual instead of IsGreater for the endDate field condition (you have to take into account the last day of the month as well).

Additionally, you can optimize it a little by using SelectSingle instead of the Select method to retrieve only one record.

You can also improve the readability of your code by rewriting it in Fluent BQL instead of traditional BQL.

Here is how your code may look in the end:

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.GL.FinPeriods.TableDefinition;
using System;
using System.Collections;

namespace PX.Objects.AR
{
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)
{
var businessDate = Base.Accessinfo.BusinessDate;
var currentPeriod = new SelectFrom<FinPeriod>
.Where<FinPeriod.startDate.IsLessEqual<@P.AsDateTime>.
And<FinPeriod.endDate.IsGreaterEqual<@P.AsDateTime>>>
.View(Base)
.SelectSingle(Base, businessDate, businessDate)?.FinPeriodID;

if (!string.IsNullOrEmpty(currentPeriod))
{
memo.FinPeriodID = currentPeriod;
memo.TranPeriodID = currentPeriod;

Base.Document.Update(memo);
}
}

return result;
}
}
}

 


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • December 11, 2025

Thank you so much!!!!!