РЕЗЮМЕ
Я создал расширение графика для графика APInvoiceEntry
(экран AP301000), которое называется APInvoiceEntry_Extension
.
Я создал новую таблицу БДс именем APRegisterException
, в котором хранится информация об исключениях для ошибок SalesTax, Freight, Price и Qty. Между APRegister
и APRegisterException
существует отношение 1 ко многим, что указывает на то, что в счете может быть много различных типов исключений.Для каждого из этих исключений я создал кнопку и действие, чтобы добавить исключения в DAC в моем графике расширений.
ПРОБЛЕМА
Я могу добавить только 1 новую запись APRegisterExcetion
в ЦАП.ЦАП не обновляется для нескольких нажатий кнопок.Каждое из следующих действий должно создать новую запись APRegisterException
и добавить их в DAC Исключений в моем графике.
public PXAction<APInvoice> ApplyPriceException;
public PXAction<APInvoice> ApplyQtyException;
public PXAction<PX.Objects.AP.APInvoice> ApplyFreightException;
public PXAction<PX.Objects.AP.APInvoice> ApplySalesTaxException;
примечание: действия выполняются, просто ЦАП не обновляется.
КОД
APREgisterException ЦАП
namespace BillsAndAdjustmentsExt
{
[Serializable]
public class APRegisterException : IBqlTable
{
#region APRegisterRefNbr
[PXDBString(15, IsKey = true, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Ref Nbr")]
public virtual string APRegisterRefNbr { get; set; }
public abstract class aPRegisterRefNbr : IBqlField { }
#endregion
#region APTranLineNbr
[PXDBInt()]
[PXUIField(DisplayName = "Line Nbr")]
public virtual int? APTranLineNbr { get; set; }
public abstract class aPTranLineNbr : IBqlField { }
#endregion
#region ExceptionDesc
[PXDBString(150, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Description")]
public virtual string ExceptionDesc { get; set; }
public abstract class exceptionDesc : IBqlField { }
#endregion
#region ExceptionType
[PXDBString(3, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Exc. Type")]
public virtual string ExceptionType { get; set; }
public abstract class exceptionType : IBqlField { }
#endregion
#region ApprovedByID
[PXDBString(15, IsUnicode = true, InputMask = "")]
[PXUIField(DisplayName = "Approved By")]
public virtual string ApprovedByID { get; set; }
public abstract class approvedByID : IBqlField { }
#endregion
#region ApprovedDate
[PXDBDate()]
[PXUIField(DisplayName = "Approval Date")]
public virtual DateTime? ApprovedDate { get; set; }
public abstract class approvedDate : IBqlField { }
#endregion
}
}
РАСШИРЕНИЕ ГРАФ:
namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
#region properties
public APRegister _currentDoc
{
get
{
return Base.Document.Current;
}
}
#endregion
// note
#region selects
public PXSelectJoin<
APRegisterException,
LeftJoin<APInvoice,
On<APRegisterException.aPRegisterRefNbr, Equal<APInvoice.refNbr>>>,
Where<APRegisterException.aPRegisterRefNbr, Equal<Current<APInvoice.refNbr>>>> Exceptions;
#endregion
#region Event Handlers
#endregion
#region Actions
public PXAction<APRegisterException> AdjustSalesTax;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Adj. Sales Tax")]
protected void adjustSalesTax()
{
// put code here to adjust sales tax
}
public PXAction<APInvoice> ApplyPriceException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Price Exc.")]
protected void applyPriceException()
{
APTran row = Base.Transactions.Current;
if(row == null)
{
throw new PXException("No rows selected");
}
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = row.RefNbr;
rException.APTranLineNbr = row.LineNbr;
rException.ExceptionDesc = row.TranDesc;
rException.ExceptionType = "PRC";
Exceptions.Insert(rException);
}
public PXAction<APInvoice> ApplyQtyException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Qty Exc.")]
protected void applyQtyException()
{
APTran row = Base.Transactions.Current;
if(row == null)
{
throw new PXException("No rows selected");
}
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = row.RefNbr;
rException.APTranLineNbr = row.LineNbr;
rException.ExceptionDesc = row.TranDesc;
rException.ExceptionType = "QTY";
Exceptions.Insert(rException);
}
public PXAction<PX.Objects.AP.APInvoice> ApplyFreightException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Freight Exc.")]
protected void applyFreightException()
{
string exceptionMessage = string.Empty;
// insert freight exception code here
if(_currentDoc.DocType != "INV" ) { exceptionMessage += "Document type must be 'Bill' to apply a freight exception. \n"; }
if(!string.IsNullOrEmpty(exceptionMessage))
{
throw new PXException("One or more errors occured trying to save this record. \n" + exceptionMessage);
}
// set the current document to hold
_currentDoc.Hold = true;
// create the exception record and store it in cache
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = _currentDoc.RefNbr;
rException.ExceptionDesc = "FREIGHT";
rException.ExceptionType = "FRT";
Exceptions.Insert(rException);
// Base.Actions.PressSave();
}
public PXAction<PX.Objects.AP.APInvoice> ApplySalesTaxException;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Apply Sales Tax Exc.")]
protected void applySalesTaxException()
{
string exceptionMessage = string.Empty;
if(_currentDoc.RefNbr == "<NEW>") { exceptionMessage += "Please save the invoice before applying a sales tax exception. \n"; }
if(_currentDoc.DocType != "INV" ) { exceptionMessage += "Document type must be 'Bill' to apply a sales tax exception. \n"; }
//if(((APInvoice)_currentDoc).CuryTaxTotal == 0) { exceptionMessage += "Tax total must be greate than $0.00 to apply a sales tax exception. \n"; }
if(!string.IsNullOrEmpty(exceptionMessage))
{
throw new PXException("One or more errors occured trying to save this record. \n" + exceptionMessage);
}
// set the current document to hold
_currentDoc.Hold = true;
// create the exception record and store it in cache
APRegisterException rException = new APRegisterException();
rException.APRegisterRefNbr = _currentDoc.RefNbr;
rException.ExceptionDesc = "SALES TAX";
rException.ExceptionType = "TAX";
Exceptions.Insert(rException);
// Base.Actions.PressSave();
}
#endregion
}
}