標籤:
當ERP的財務模組與生產,供應鏈模組整合時,這些模組過帳時會產生會計憑證。如果能在產生會計憑證前可預覽一下憑證,那對使用者而言是一個很友好的設計。如所示,貸項通知單過帳前,可通過預覽憑證,知曉即將產生的會計憑證。
點擊預覽憑證按鈕,可看到即將產生的會計憑證:
為達到此目的,分享一下對系統的修改。
首先是業務單據重寫按鈕事件,
protected override void OnPreviewVoucher(Dictionary<string, VoucherEntity> voucherList)
{
base.OnPreviewVoucher(voucherList);
if (_expenseRemibursementEntity.Amount > 0)
{
VoucherEntity voucher = _expenseRemibursementManager.CreateExpenseRemibursementVoucherForPreview( _expenseRemibursementEntity);
if (voucher != null)
voucherList.Add(VOUCHER_KEY, voucher);
}
}
通過重寫這個方法,基類可擷取當前業務單據產生的會計憑證。產生會計憑證的方法原型如下:
public VoucherEntity CreateExpenseRemibursementVoucherForPreview(ExpenseRemibursementEntity ExpenseRemibursement)
{
VoucherEntity voucher = null;
using (DataAccessAdapter adapter = GetCompanyDataAccessAdapter(sessionId))
{
try
{
adapter.StartTransaction(IsolationLevel.ReadCommitted, "CreateExpenseRemibursementVoucherForPreview");
ExpenseRemibursementEntity clonedAdjustment = (ExpenseRemibursementEntity)Shared.CloneEntity(ExpenseRemibursement);
IFiscalPeriodManager fiscalPeriodManager = ClientProxyFactory.CreateProxyInstance<IFiscalPeriodManager>();
ExcludeIncludeFieldsList fieldsList = new ExcludeIncludeFieldsList(false);
fieldsList.Add(FiscalPeriodFields.Period);
fieldsList.Add(FiscalPeriodFields.FiscalYear);
fieldsList.Add(FiscalPeriodFields.PeriodNo);
FiscalPeriodEntity fiscalPeriod = fiscalPeriodManager.GetValidFiscalPeriod(sessionId, clonedAdjustment.AppliedDate, fieldsList, true);
clonedAdjustment.Period = fiscalPeriod.Period;
clonedAdjustment.FiscalYear = fiscalPeriod.FiscalYear;
clonedAdjustment.PeriodNo = fiscalPeriod.PeriodNo;
voucher=GenerateVoucher(sessionId, clonedAdjustment);
}
finally
{
adapter.Rollback();
}
}
return voucher;
}
這裡有一個細節是並沒有對當前的業務實體(business object)直接操作,而是對它的一個深拷貝進行操作。這樣對這個拷貝的對象進行的操作都不會影響到原來的業務實體。
其次,需要增加一個MDI介面,主介面用於承載會計憑證介面,子表單為會計憑證介面。為達到這個目的,我們將會計憑證介面作為子表單載入到一個新建立的MDI主表單介面中:
standardFunctionForm = null;
Form form = ComponentCommon.MainForm.GetStandardFunctionForm(primaryKeys[0]);
if (form != null)
standardFunctionForm = form as FunctionFormBase;
standardFunctionForm.Owner = this;
standardFunctionForm.TopLevel = false;
standardFunctionForm.AutoScroll = true;
standardFunctionForm.HideBindingNavigator = true;
standardFunctionForm.HideStatusStrip = true;
standardFunctionForm.AllowAdd = false;
standardFunctionForm.AllowDelete = false;
standardFunctionForm.AllowEdit = false;
standardFunctionForm.AllowPost = false;
standardFunctionForm.SupportAdd = false;
standardFunctionForm.SupportDelete = false;
standardFunctionForm.SupportEdit = false;
standardFunctionForm.SupportApproval = false;
standardFunctionForm.SupportPost = false;
standardFunctionForm.SupportImport = false;
standardFunctionForm.SupportExport = false;
standardFunctionForm.Show();
standardFunctionForm.SaveLayoutOnClose = SaveLayouts.Never;
Dictionary<string, string> refNo = new Dictionary<string, string>();
refNo.Add(primaryKeys[1], RefNo);
standardFunctionForm.FindAndLoadData(refNo);
這裡面可以看到,為什麼要用一個MDI主介面來載入會計憑證表單,是為了在不破壞原有功能的情況下,可定製它的部分功能。比如這個預覽憑證表單,不需要儲存資料或過帳等操作,於是看到上面的代碼中,我們將SupportEdit=false表示不需要編輯功能。
最後三句是MDI子表單載入資料,通過傳入索引值對來完成資料的載入。FindAndLoadData方法會調用內部LoadData:
protected override EntityBase2 LoadData(Dictionary<string, string> refNo)
{
base.LoadData(refNo);
string RefNo = string.Empty;
if (refNo.TryGetValue("RefNo", out RefNo))
{
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.ExpenseRemibursementEntity);
prefetchPath.Add(ExpenseRemibursementEntity.PrefetchPathExpenseRemibursementDetail);
_expenseRemibursementEntity = _expenseRemibursementManager.GetExpenseRemibursement(Shared.CurrentUserSessionId, RefNo, prefetchPath);
}
else
{
_expenseRemibursementEntity = new ExpenseRemibursementEntity();
}
return _expenseRemibursementEntity;
}
這樣我們就完成了財務模組的憑證預覽功能。
財務模組功能中的憑證預覽功能