public bool DeleteLogical(Guid voucherId) { Session session = null; try { session = XpoHelper.GetNewSession(); NAS.DAL.Vouches.Vouches voucher = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(voucherId); if (voucher == null) { throw new Exception("The voucher does not exist"); } if (voucher.RowStatus.Equals(Utility.Constant.ROWSTATUS_BOOKED_ENTRY)) { throw new Exception( String.Format("Không thể xóa phiếu thu '{0}' vì đã được hạch toán", voucher.Code)); } voucher.RowStatus = Utility.Constant.ROWSTATUS_DELETED; voucher.Save(); return(true); } catch (Exception) { throw; } finally { if (session != null) { session.Dispose(); } } }
protected void cpVoucherBookingEntry_OnCallback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { string[] para = e.Parameter.Split(','); string trs = para[0]; switch (trs) { case "open": NAS.DAL.Vouches.Vouches v = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VoucherId); if (v == null) { throw new Exception("The Voucher is not exist"); } if (v.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY) { GUIContext.State = new ReadyBookingVoucherState(this); } else { GUIContext.State = new BookedVoucherState(this); } break; default: GUIContext.Request(trs, this); break; } //if (trs.Equals("Book")) // cpVoucherBookingEntry.JSProperties.Add("cp" }
public bool DeleteTempObject(Guid voucherId) { UnitOfWork uow = null; try { uow = XpoHelper.GetNewUnitOfWork(); NAS.DAL.Vouches.Vouches voucher = uow.GetObjectByKey <NAS.DAL.Vouches.Vouches>(voucherId); if (voucher == null) { throw new Exception("The voucher does not exist"); } if (!voucher.RowStatus.Equals(Utility.Constant.ROWSTATUS_TEMP)) { throw new Exception("The object is not a temp object"); } voucher.Delete(); uow.CommitChanges(); return(true); } catch (Exception) { throw; } finally { if (uow != null) { uow.Dispose(); } } }
public void UpdateGUI_ReadyBookingVoucherState() { NAS.DAL.Vouches.Vouches v = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VoucherId); popCosting.ShowOnPageLoad = true; ButtonApproveCosting.ClientVisible = true; lblIsApprovedCosting.Text = "Chưa hạch toán"; lblSumOfDebit.Text = v.SumOfCredit.ToString(); }
public void CRUD_BookedVoucherState() { NAS.DAL.Vouches.Vouches v = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VoucherId); if (v.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY) { v.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY; v.Save(); } }
public bool CanBookingEntry(Guid voucherId) { Session session = null; try { session = XpoHelper.GetNewSession(); NAS.DAL.Vouches.Vouches voucher = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(voucherId); if (voucher == null) { throw new Exception("The voucher does not exist"); } if (voucher.RowStatus.Equals(Utility.Constant.ROWSTATUS_TEMP)) { return(false); } //2013-12-12 ERP-951 Khoa.Truong MOD START //double sumOfAllocationAmount = voucher.VoucherAllocations.Sum(r => r.Amount); double sumOfAllocationAmount = double.MinValue; if (voucher is NAS.DAL.Vouches.ReceiptVouches) { sumOfAllocationAmount = ((NAS.DAL.Vouches.ReceiptVouches)voucher) .ReceiptVouchesTransactions .Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE) .Sum(r => r.Amount); } else if (voucher is NAS.DAL.Vouches.PaymentVouches) { sumOfAllocationAmount = ((NAS.DAL.Vouches.PaymentVouches)voucher) .PaymentVouchesTransactions .Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE) .Sum(r => r.Amount); } //2013-12-12 ERP-951 Khoa.Truong MOD END double voucherAmount = voucher.SumOfCredit + voucher.SumOfDebit; if (sumOfAllocationAmount != voucherAmount) { return(false); } return(true); } catch (Exception) { return(false); } finally { if (session != null) { session.Dispose(); } } }
protected void grdDetailEntry_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { NAS.DAL.Vouches.Vouches v = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VoucherId); if (v == null) { throw new Exception("The Voucher is not exist"); } if (v.RowStatus == Utility.Constant.ROWSTATUS_BOOKED_ENTRY) { throw new Exception("Phiếu đã đã được duyệt. Không thể xóa thông tin!"); } }
public bool CheckIsExistedCustomerInVouche(Session session, Guid CustomerId) { CriteriaOperator criteria = CriteriaOperator.And( new BinaryOperator("SourceOrganizationId", CustomerId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater) ); NAS.DAL.Vouches.Vouches vouche = session.FindObject <NAS.DAL.Vouches.Vouches>(criteria); if (vouche == null) { return(false); } return(true); }
protected void grdDetailEntry_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { NAS.DAL.Vouches.Vouches v = session.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VoucherId); if (v == null) { throw new Exception("The Voucher is not exist"); } if (v.RowStatus == Utility.Constant.ROWSTATUS_BOOKED_ENTRY) { throw new Exception("Phiếu đã đã được duyệt. Không thể thêm thông tin!"); } ASPxGridView grid = sender as ASPxGridView; e.NewValues["VoucherAllocationId!Key"] = grid.GetMasterRowKeyValue().ToString(); }
public bool VoucherLockedBookingdEntries_UpdateGUI() { popupVoucherBookingEntriesForm.ShowOnPageLoad = true; gridviewVoucherBookingEntries.Enabled = true; Button_BookEntries.Visible = false; //Set popup header text NAS.DAL.Vouches.Vouches voucher = GetCurrentVoucher(session); if (voucher is NAS.DAL.Vouches.ReceiptVouches) { popupVoucherBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu thu - {0}", voucher.Code); } else if (voucher is NAS.DAL.Vouches.PaymentVouches) { popupVoucherBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu chi - {0}", voucher.Code); } return(true); }
public bool VoucherCanNotBookingEntries_UpdateGUI() { popupVoucherBookingEntriesForm.ShowOnPageLoad = true; gridviewVoucherBookingEntries.Enabled = true; Button_BookEntries.Enabled = true; Button_BookEntries.ClientSideEvents.Click = "function(s, e) { alert('Không thể ghi sổ được vì số tiền chưa được cân đối. Vui lòng kiểm tra lại.'); }"; //Set popup header text NAS.DAL.Vouches.Vouches voucher = GetCurrentVoucher(session); if (voucher is NAS.DAL.Vouches.ReceiptVouches) { popupVoucherBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu thu - {0}", voucher.Code); } else if (voucher is NAS.DAL.Vouches.PaymentVouches) { popupVoucherBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu chi - {0}", voucher.Code); } return(true); }
public bool GenerateTemplateVoucherForBookingEntry(Guid VouchesId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Vouches.Vouches voucher = uow.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VouchesId); if (voucher == null) { throw new Exception("The Vouches is not exist in db"); } string AllocationTypeCode = string.Empty; if (voucher is NAS.DAL.Vouches.PaymentVouches) { AllocationTypeCode = "VOUCHER_PAYMENT"; } if (voucher is NAS.DAL.Vouches.ReceiptVouches) { AllocationTypeCode = "VOUCHER_RECEIPT"; } XPCollection <VoucherAllocation> voucherAllocationLst = new XPCollection <VoucherAllocation>(uow, new BinaryOperator("VouchesId", voucher, BinaryOperatorType.Equal)); XPCollection <Allocation> allocationsTemplate = new XPCollection <Allocation>(uow, new BinaryOperator("AllocationTypeId.Code", AllocationTypeCode, BinaryOperatorType.Equal)); if (voucherAllocationLst != null && voucherAllocationLst.Count > 0) { foreach (VoucherAllocation va in voucherAllocationLst) { IEnumerable <Allocation> allocations = allocationsTemplate.Where(t => t == va.AllocationId); if (allocations != null && allocations.Count <Allocation>() <= 0) { continue; } if (va.VoucherAllocationBookingAccounts != null && va.VoucherAllocationBookingAccounts.Count > 0) { continue; } foreach (AllocationAccountTemplate aat in va.AllocationId.AllocationTemplates) { VoucherAllocationBookingAccount vaba = new VoucherAllocationBookingAccount(uow); vaba.AccountId = aat.AccountId; vaba.VoucherAllocationId = va; } } } uow.CommitChanges(); return(true); } catch { //uow.ExplicitRollbackTransaction(); throw; } } }
public void ValidateVoucherForBookingEntry(Guid VouchesId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Vouches.Vouches voucher = uow.GetObjectByKey <NAS.DAL.Vouches.Vouches>(VouchesId); if (voucher == null) { throw new Exception("The Vouches is not exist in db"); } string AllocationTypeCode = string.Empty; if (voucher is NAS.DAL.Vouches.PaymentVouches) { AllocationTypeCode = "VOUCHER_PAYMENT"; } if (voucher is NAS.DAL.Vouches.ReceiptVouches) { AllocationTypeCode = "VOUCHER_RECEIPT"; } XPCollection <VoucherAllocation> voucherAllocationLst = new XPCollection <VoucherAllocation>(uow, new BinaryOperator("VouchesId", voucher, BinaryOperatorType.Equal)); if (voucherAllocationLst == null || voucherAllocationLst.Count == 0) { throw new Exception(string.Format("Thông tin hạch toán của phiếu {0} '{1}' chưa có dòng bút toán nào nên không thể hạch toán", AllocationTypeCode.Equals("VOUCHER_PAYMENT") ? "Chi" : "Thu", voucher.Code)); } foreach (VoucherAllocation va in voucherAllocationLst) { double sumOfDebit = 0; double sumOfCredit = 0; foreach (VoucherAllocationBookingAccount vaba in va.VoucherAllocationBookingAccounts) { sumOfDebit += vaba.Debit; sumOfCredit += vaba.Credit; } if (sumOfDebit != sumOfCredit) { throw new Exception(string.Format("Thông tin hạch toán của phiếu {0} '{1}' chưa cân đối ở mã bút toán '{2}'", AllocationTypeCode.Equals("VOUCHER_PAYMENT") ? "Chi" : "Thu", voucher.Code, va.Code)); } if (va.Amount != sumOfDebit || va.Amount != sumOfCredit) { throw new Exception(string.Format("Thông tin hạch toán của phiếu {0} '{1}' chưa phân bổ đủ tại mã bút toán '{2}'", AllocationTypeCode.Equals("VOUCHER_PAYMENT") ? "Chi" : "Thu", voucher.Code, va.Code)); } } } catch { //uow.ExplicitRollbackTransaction(); throw; } } }