Hi there,
I have a requirement to default the Invoice Date and Post Period in SO Invoice as the current date and period and was able to achieve it as shown below:
protected void ARInvoice_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
ARInvoice doc = e.Row as ARInvoice;
if (doc == null) return;
// Ensure it's a Credit Memo created from a Sales Order
if (doc.DocType == ARDocType.CreditMemo && doc.OrigModule == "SO")
{
doc.DocDate = PXTimeZoneInfo.Now.Date;
FinPeriod currentFinPeriodID = PXSelect<FinPeriod,
Where<FinPeriod.startDate, LessEqual<Required<FinPeriod.startDate>>,
And<FinPeriod.endDate, Greater<Required<FinPeriod.endDate>>,
And<FinPeriod.active, Equal<True>>>>>
.Select(Base, doc.DocDate, doc.DocDate);
if (currentFinPeriodID != null)
{
string month = currentFinPeriodID.FinPeriodID.Substring(4, 2);
string year = currentFinPeriodID.FinPeriodID.Substring(0, 4);
string finPeriodID = string.Concat(month, year);
sender.SetValueExt<ARInvoice.finPeriodID>(doc, finPeriodID);
}
}
}
The issue lies with the Invoice Date and Post Period in the original SO itself - it will follow the date and period based on the Order Date when Prepare Invoice button is pressed:

This will prevent the invoice from being saved if the previous period is already closed.
How do I ensure that the Invoice Date and Post Period will reflect the same value as the one in SO Invoice?