private void Find(int docNum) { try { CancelledLabel.Visibility = Visibility.Collapsed; _currentItems = CashVoucher.WhereDocumentNumberIs(docNum); _currentItems.CollectionChanged += CurrentItemsCollectionChanged; foreach (CashVoucher currentItem in _currentItems) { currentItem.PropertyChanged += CurrentItemOnPropertyChanged; } _voucherNumber = docNum; RefreshDisplay(); DataContext = _currentItems; _hasModified = false; } catch (Exception exception) { MessageWindow.ShowAlertMessage(exception.Message); } }
public ActionResult Create() { CashVoucher cashvoucher = new CashVoucher(); cashvoucher.VoucherNo = "CRV-"; cashvoucher.VoucherTypeID = 1; cashvoucher.EmployeeID = int.Parse(Session["UserID"].ToString()); cashvoucher.AccountHeadID = 1; cashvoucher.VoucherDate = DateTime.Now; cashvoucher.ReferenceNo = ""; cashvoucher.ReferenceDate = DateTime.Now; cashvoucher.Narration = ""; cashvoucher.TotalAmount = 0.00M; cashvoucher.Flag = false; db.CashVouchers.Add(cashvoucher); db.SaveChanges(); cashvoucher.VoucherNo = "CRV-" + cashvoucher.CashVoucherID.ToString("D" + 6); db.Entry(cashvoucher).State = EntityState.Modified; db.SaveChanges(); CashVoucherDetail cashvoucherdetail = new CashVoucherDetail(); cashvoucherdetail.CashVoucherID = cashvoucher.CashVoucherID; cashvoucherdetail.AccountHeadID = 1; cashvoucherdetail.Amount = 0.00M; cashvoucherdetail.Remarks = ""; db.CashVoucherDetails.Add(cashvoucherdetail); db.SaveChanges(); Session["Create"] = "1"; return(RedirectToAction("Edit", new { id = cashvoucher.CashVoucherID })); }
public static void Create(CashVoucher item) { CheckStartRent window = new CheckStartRent(); window.setCashVoucher(item); window.ShowDialog(); }
private async void Button_Clicked(object sender, EventArgs e) { try { var amount = Convert.ToInt32(CashEntry.Text); var category = (string)CategoryPicker.SelectedItem; if (category == "Добавить категорию" || amount == 0) { await DisplayAlert("Внимание", "Данные введены неверно", "ОК"); } else { var cashVoucher = new CashVoucher() { Amount = amount, Date = DateTime.Now, Type = _type }; var categ = App.Database.GetCategoryByName(category); categ.CashVoucher = cashVoucher; cashVoucher.Category = categ; App.Database.AddCashVoucher(cashVoucher); await DisplayAlert("", "Чек добавлен", "ОK"); await Navigation.PopAsync(); } } catch (Exception ex) { await DisplayAlert("Внимание", "Данные введены неверно", "ОК"); } }
public GoNegosyoView(Nfmb member) { InitializeComponent(); _member = member; if (MainController.LoggedUser.TransactionDate != GlobalSettings.DateOfOpenTransaction) { MessageWindow.ShowAlertMessage("Cannot create transactions using current date settings."); btnDetails.IsEnabled = btnPost.IsEnabled = false; return; } var code = GlobalSettings.CodeOfGoNegosyo; if (string.IsNullOrEmpty(code)) { MessageWindow.ShowAlertMessage("Go Negosyo code not set!"); btnDetails.IsEnabled = btnPost.IsEnabled = false; return; } btnPost.Click += (sender, args) => Post(); btnDetails.Click += (sender, args) => ShowDetails(); _loanProduct = LoanProduct.GetList().First(a => a.ProductCode == code); // initialize cash voucher entry for go negosyo _cashVoucher = new CashVoucher { VoucherNo = Voucher.LastDocumentNo(VoucherTypes.CV) + 1, }; DataContext = _cashVoucher; }
private Result PostCashOnHand() { // post cash on hand credit side var member = Nfmb.FindByCode(_accountDetail.MemberCode); var accountCode = GlobalSettings.CodeOfCashOnHand; if (string.IsNullOrWhiteSpace(accountCode)) { return(new Result(false, GenerateCodeOfAccountNotSetMessage("Cash on Hand"))); } var account = Account.FindByCode(accountCode); var amount = _accountDetail.EndingBalance + _accountDetail.TimeDepositDetails.CalculateInterestEarned(_voucherDocument.VoucherDate) - _accountDetail.TimeDepositDetails.CalculateServiceFee(_voucherDocument.VoucherDate); var cv = new CashVoucher { MemberCode = member.MemberCode, MemberName = member.MemberName, AccountCode = account.AccountCode, AccountTitle = account.AccountTitle, Credit = amount, VoucherDate = _voucherDocument.VoucherDate, VoucherNo = _voucherDocument.VoucherNo, Explanation = "Withdrawal of Time Deposit", AmountInWords = Converter.AmountToWords(amount), }; var postResult = cv.Create(); if (!postResult.Success) { Rollback(); } return(postResult); }
private void btnCancelled_Click(object sender, RoutedEventArgs e) { if (!CanModify) { MessageWindow.AlertRecordIsLocked(); return; } if (MessageWindow.ConfirmCancelVoucher() != MessageBoxResult.Yes) { return; } CashVoucher.DeleteAll(_voucherNumber); var cancelledCashVoucher = new CashVoucher(); cancelledCashVoucher.MemberCode = "CANCEL"; cancelledCashVoucher.MemberName = "CANCELLED"; cancelledCashVoucher.AccountCode = "CANCEL"; cancelledCashVoucher.AccountTitle = "CANCELLED"; cancelledCashVoucher.Debit = 0m; cancelledCashVoucher.Credit = 0m; cancelledCashVoucher.VoucherDate = _voucherDate; cancelledCashVoucher.VoucherNo = _voucherNumber; cancelledCashVoucher.VoucherType = VOUCHER_TYPE; cancelledCashVoucher.Create(); Find(_voucherNumber); }
private Result PostServiceFee() { // post service fee credit side var member = Nfmb.FindByCode(_accountDetail.MemberCode); var accountCode = GlobalSettings.CodeOfServiceFee; if (string.IsNullOrWhiteSpace(accountCode)) { return(new Result(false, GenerateCodeOfAccountNotSetMessage("Service Fee"))); } var account = Account.FindByCode(accountCode); var cv = new CashVoucher { MemberCode = member.MemberCode, MemberName = member.MemberName, AccountCode = account.AccountCode, AccountTitle = account.AccountTitle, Credit = _accountDetail.TimeDepositDetails.CalculateServiceFee(_voucherDocument.VoucherDate), VoucherDate = _voucherDocument.VoucherDate, VoucherNo = _voucherDocument.VoucherNo, }; var postResult = cv.Create(); if (!postResult.Success) { Rollback(); } return(postResult); }
private SalaryAdvanceView() { InitializeComponent(); if (MainController.LoggedUser.TransactionDate != GlobalSettings.DateOfOpenTransaction) { MessageWindow.ShowAlertMessage("Cannot create transactions using current date settings."); btnDetails.IsEnabled = btnPost.IsEnabled = false; return; } var code = GlobalSettings.CodeOfSalaryAdvance; if (string.IsNullOrEmpty(code)) { MessageWindow.ShowAlertMessage("Salary Advance code not set!"); btnDetails.IsEnabled = btnPost.IsEnabled = false; return; } btnPost.Click += btnPost_Click; btnDetails.Click += btnDetails_Click; _loanProduct = LoanProduct.GetList().First(a => a.ProductCode == code); // initialize cash voucher entry for salary advance _cashVoucher = new CashVoucher { VoucherNo = Voucher.LastDocumentNo(VoucherTypes.CV) + 1, }; DataContext = _cashVoucher; }
private Result PostTimeDepositEndBalance() { // post time desposit end balance debit side var member = Nfmb.FindByCode(_accountDetail.MemberCode); var account = Account.FindByCode(_accountDetail.AccountCode); var tdDetails = new TimeDepositDetails { CertificateNo = _accountDetail.TimeDepositDetails.CertificateNo }; var cv = new CashVoucher { MemberCode = member.MemberCode, MemberName = member.MemberName, AccountCode = account.AccountCode, AccountTitle = account.AccountTitle, Debit = _accountDetail.EndingBalance, VoucherDate = _voucherDocument.VoucherDate, VoucherNo = _voucherDocument.VoucherNo, TimeDepositDetails = tdDetails, }; var postResult = cv.Create(); if (!postResult.Success) { Rollback(); } return(postResult); }
public ActionResult DeleteDetailConfirm(int id) { Session["err"] = "Error, Please Check Input Fields"; Session["msg"] = ""; CashVoucherDetail cashvoucherdetail = db.CashVoucherDetails.Find(id); try { var cashVoucherdetailallocation = db.CashVoucherDetailAllocations.Where(b => b.CashVoucherDetailID == id).ToList(); foreach (CashVoucherDetailAllocation b in cashVoucherdetailallocation) { db.CashVoucherDetailAllocations.Remove(b); db.SaveChanges(); } db.CashVoucherDetails.Remove(cashvoucherdetail); db.SaveChanges(); } catch { } try { decimal totalamt = db.CashVoucherDetails.Where(u => u.CashVoucherID == cashvoucherdetail.CashVoucherID).Sum(u => (decimal)u.Amount); CashVoucher cashvoucher = db.CashVouchers.Find(cashvoucherdetail.CashVoucherID); cashvoucher.TotalAmount = decimal.Round(Convert.ToDecimal(totalamt.ToString("#.##")), 2, MidpointRounding.AwayFromZero); db.Entry(cashvoucher).State = EntityState.Modified; db.SaveChanges(); Session["err"] = ""; Session["msg"] = "Deleted Successfully"; } catch { } return(RedirectToAction("Edit", new { id = cashvoucherdetail.CashVoucherID })); }
public int writeCashVoucher(CashVoucher cashVoucher) { return(cashVoucherData.AddCashVoucher( cashVoucher.User, cashVoucher.Vehicle, cashVoucher.StartDate, cashVoucher.FinalDate, cashVoucher.Price )); }
public void tryRentVehicle() { Vehicle vehicleObject = mainWindow.serverData.client.getUserVehicle(mainWindow.clientData.account); if (vehicleObject.plate != "none") { MessageBox.Show("Ви вже маєте орендований автомобіль.", "Відмова оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (totalPrice > mainWindow.clientData.account.balance) { MessageBox.Show("Оренда неможлива, поповніть рахунок.", "Відміна оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (vehicle.clientid != 0) { MessageBox.Show("Оренда неможлива, автомобіль вже орендований.", "Відміна оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult answer = MessageBox.Show("Ви дійсно хочите орендувати " + vehicle.name + " " + vehicle.model + "?\n\n" + "Дата початку оренди: " + DateTime.Now.ToShortTimeString() + "\n" + "Дата кінця оренди: " + rentDate.ToShortTimeString(), "Підтвердіть дію", MessageBoxButtons.YesNoCancel); if (answer == DialogResult.Yes) { mainWindow.clientData.account.balance -= totalPrice; vehicle.start_date = DateTime.Now; vehicle.end_date = rentDate; vehicle.clientid = mainWindow.clientData.account.id; CashVoucher voucher = ShowCashVoucher.Collect(mainWindow.clientData.account, vehicle, totalPrice, vehicle.start_date, vehicle.end_date); int Id = mainWindow.serverData.client.writeCashVoucher(voucher); vehicle.rentlogid = mainWindow.serverData.client.log_TakeRent( mainWindow.clientData.account.id, vehicle.VIN, totalPrice, Id, vehicle.start_date, vehicle.end_date); mainWindow.serverData.client.saveVehicle(vehicle); mainWindow.updateAccountData(); mainWindow.main_page1.updateVehicleData(); mainWindow.clientData.ui.CreatePanel(mainWindow.clientData.ui.MAIN_PANEL, mainWindow); ShowCashVoucher.Create(mainWindow.serverData.client.readCashVoucher(Id)); mainWindow.dialogCreate("Ви орендовали автомобіль. Вітаємо!", "Підтвердження оренди", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { if (!CanModify) { MessageWindow.AlertRecordIsLocked(); return; } if (MessageWindow.ConfirmDeleteVoucher() != MessageBoxResult.Yes) { return; } CashVoucher.DeleteAll(_voucherNumber); Find(_voucherNumber); }
public ActionResult DeleteConfirm(int id) { Session["err"] = "Error, Please Check Input Fields"; Session["msg"] = ""; CashVoucher cashvoucher = db.CashVouchers.Find(id); try { var accountjournals = db.AccountJournals.Where(a => a.VoucherNo == cashvoucher.VoucherNo).ToList(); foreach (AccountJournal accountjournal1 in accountjournals) { var accountjournaldetails = db.AccountJournalDetails.Where(a => a.AccountJournalID == accountjournal1.AccountJournalID).ToList(); foreach (AccountJournalDetail accountjournaldetail1 in accountjournaldetails) { db.AccountJournalDetails.Remove(accountjournaldetail1); } db.SaveChanges(); db.AccountJournals.Remove(accountjournal1); } db.SaveChanges(); } catch { } try { var cashVoucherdetail = db.CashVoucherDetails.Where(b => b.CashVoucherID == id).ToList(); foreach (CashVoucherDetail a in cashVoucherdetail) { var cashVoucherdetailallocation = db.CashVoucherDetailAllocations.Where(b => b.CashVoucherDetailID == a.CashVoucherDetailID).ToList(); foreach (CashVoucherDetailAllocation b in cashVoucherdetailallocation) { db.CashVoucherDetailAllocations.Remove(b); db.SaveChanges(); } db.CashVoucherDetails.Remove(a); db.SaveChanges(); } db.CashVouchers.Remove(cashvoucher); db.SaveChanges(); Session["err"] = ""; Session["msg"] = "Deleted Successfully"; } catch { } return(RedirectToAction("Index")); }
public static Result ReBalanceWithdrawals(Voucher voucher, decimal totalWithdrawals) { var sqlBuilder = new StringBuilder(); sqlBuilder.AppendLine("SELECT *"); sqlBuilder.AppendLine("FROM cv"); sqlBuilder.AppendLine("WHERE DOC_NUM = ?DOC_NUM"); sqlBuilder.AppendLine("AND CREDIT > 0"); sqlBuilder.AppendLine("LIMIT 1"); var sqlParam = new SqlParameter("?DOC_NUM", voucher.VoucherNo); DataTable dataTable = DatabaseController.ExecuteSelectQuery(sqlBuilder, sqlParam); var cv = new CashVoucher(); foreach (DataRow dataRow in dataTable.Rows) { cv.SetPropertiesFromDataRow(dataRow); } cv.Credit = totalWithdrawals; cv.Amount = totalWithdrawals; cv.AmountInWords = Utilities.Converter.AmountToWords(totalWithdrawals); if (cv.ID == 0) { var company = Nfmb.FindByCode(GlobalSettings.CodeOfCompany); if (company == null || company.ID == 0) { return(new Result(false, "Company Code is not set. Please consult System Administrator")); } cv.MemberCode = company.MemberCode; cv.MemberName = company.MemberName; var coh = Account.FindByCode(GlobalSettings.CodeOfCashOnHand); cv.AccountCode = coh.AccountCode; cv.AccountTitle = coh.AccountTitle; cv.VoucherNo = voucher.VoucherNo; cv.VoucherDate = voucher.VoucherDate; cv.VoucherType = cv.VoucherType; cv.Explanation = "Daily partial withdrawal from Savings Deposit"; return(cv.Create()); } return(cv.Update()); }
private void RefreshDisplay() { CashVoucher firstItem = _currentItems.FirstOrDefault(); if (firstItem != null) { _voucherDate = firstItem.VoucherDate; CancelledLabel.Visibility = firstItem.MemberCode.ToUpper().Contains("CANCEL") ? Visibility.Visible : Visibility.Collapsed; } else { _voucherDate = _transactionDateUser; } bool allowEdit = CanModify; dgTransactionDetails.ItemsSource = _currentItems; dgTransactionDetails.CanUserAddRows = allowEdit; dgTransactionDetails.IsReadOnly = !allowEdit; txtDocNum.Text = Convert.ToString(_voucherNumber); txtTransactionDate.Text = _voucherDate.ToString("MM/dd/yyyy"); UpdateTotalDebitAndTotalCredit(); lblRecordCount.Content = string.Format("Record Count: {0}", _currentItems.Count); btnSave.IsEnabled = allowEdit; btnDelete.IsEnabled = allowEdit; btnCancelled.IsEnabled = allowEdit; btnPrint.IsEnabled = allowEdit; if (allowEdit) { imgLocked.Visibility = Visibility.Collapsed; imgUnlocked.Visibility = Visibility.Visible; } else { imgLocked.Visibility = Visibility.Visible; imgUnlocked.Visibility = Visibility.Collapsed; } }
private void VoucherFormOnKeyDown(object sender, KeyEventArgs e) { if (!CanModify) { return; } if (e.Key == Key.I && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { var newItem = new CashVoucher(); _currentItems.Add(newItem); } if (e.Key == Key.D && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { var currentItem = (CashVoucher)dgTransactionDetails.SelectedItem; _currentItems.Remove(currentItem); } }
// ReSharper disable DoNotCallOverridableMethodsInConstructor public MainViewModel() { Application.Current.SessionEnding += delegate(object sender, SessionEndingCancelEventArgs args) { //Не вызывается }; Application.Current.Exit += delegate(object sender, ExitEventArgs args) { if (ApplicationStaticHelper.IsValidExit) { var version = Assembly.GetExecutingAssembly().GetName().Version; Log.Info("Работа кассы версии {0} завершена.", version); return; } Log.Debug("Деактивация ленты билетов и закрытие смены вызвано завершением работы процесса приложения! Код завершения {0}", args.ApplicationExitCode); ExtremeCloseShift(); }; AppDomain.CurrentDomain.ProcessExit += delegate(object sender, EventArgs args) { // }; var resultCashVoucher = new CashVoucher <ICashVoucherItem>(); UpdateResultCashVoucher(resultCashVoucher); var dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += delegate { OnPropertyChanged(() => CurrentDateTime); }; dispatcherTimer.Interval = new TimeSpan(0, 0, 30); dispatcherTimer.Start(); }
// GET: /CashVoucherPrint/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CashVoucher cashvoucher = db.CashVouchers.Find(id); if (cashvoucher == null) { return(HttpNotFound()); } VoucherType vouchertypemaster = db.VoucherTypes.Find(cashvoucher.VoucherTypeID); ViewBag.VoucherTypeID = vouchertypemaster.Name; Employee employee = db.Employees.Find(cashvoucher.EmployeeID); ViewBag.EmployeeID = employee.Name; AccountHead accounthead = db.AccountHeads.Find(cashvoucher.AccountHeadID); ViewBag.AccountHeadID = accounthead.Name; return(View(cashvoucher)); }
private Result PostInterestExpense() { // post time desposit end balance debit side var interestEarned = _accountDetail.TimeDepositDetails.CalculateInterestEarned(_voucherDocument.VoucherDate); if (interestEarned == 0) { return(new Result(true, "No interest earned.")); } var member = Nfmb.FindByCode(_accountDetail.MemberCode); var accountCode = GlobalSettings.CodeOfInterestExpenseOnTimeDeposit; if (string.IsNullOrWhiteSpace(accountCode)) { return(new Result(false, GenerateCodeOfAccountNotSetMessage("Interest Expense On Time Deposit"))); } var account = Account.FindByCode(accountCode); var cv = new CashVoucher { MemberCode = member.MemberCode, MemberName = member.MemberName, AccountCode = account.AccountCode, AccountTitle = account.AccountTitle, Debit = interestEarned, VoucherDate = _voucherDocument.VoucherDate, VoucherNo = _voucherDocument.VoucherNo, }; var postResult = cv.Create(); if (!postResult.Success) { Rollback(); } return(postResult); }
public CashVoucher readCashVoucher(int Id) { return(CashVoucher.ReadCashVoucher(Id)); }
private void Post() { var loanAmount = _cashVoucher.Debit; var voucherNo = _cashVoucher.VoucherNo; var voucherDate = MainController.LoggedUser.TransactionDate; var document = new VoucherDocument(VoucherTypes.CV, voucherNo, voucherDate); // is there already a loan product for Go Negosyo? if (_loanProduct == null) { MessageWindow.ShowAlertMessage("No Loan Products found for Go Negosyo."); return; } // does user enter a valid amount? if (loanAmount <= 0) { MessageWindow.ShowAlertMessage("Invalid amount!"); return; } // does the voucher number been used? var collection = CashVoucher.WhereDocumentNumberIs(voucherNo); if (collection.Count > 0) { MessageWindow.ShowAlertMessage("CV No. already in use."); return; } try { // what is the account for Go Negosyo? var goNegosyo = Account.FindByCode(GlobalSettings.CodeOfGoNegosyo); #region --- Finally add entry for the loan applied --- // what will be the loan details? var loanDetails = GenerateLoanDetails(); _cashVoucher.SetMember(_member); _cashVoucher.SetAccount(goNegosyo); _cashVoucher.SetDocument(document); _cashVoucher.Explanation = loanDetails.GenerateExplanation(); _cashVoucher.LoanDetails = loanDetails; Result postResult = _cashVoucher.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } #endregion // NO CHARGES #region --- Add entry for Accounts Payable Merchandise --- var net = new CashVoucher(); net.SetMember(_member); net.SetAccount(Account.FindByCode(GlobalSettings.CodeOfAccountsPayableMerchandise)); net.SetDocument(document); net.Credit = loanAmount; net.Amount = loanAmount; net.AmountInWords = Converter.AmountToWords(loanAmount); postResult = net.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } #endregion #region --- Voucher Log --- var voucherLog = new VoucherLog(); voucherLog.Find("CV", _cashVoucher.VoucherNo); voucherLog.Date = _cashVoucher.VoucherDate; voucherLog.Initials = MainController.LoggedUser.Initials; voucherLog.Save(); #endregion MessageWindow.ShowNotifyMessage("Go Negosyo created. Please check CV# " + voucherNo); DialogResult = true; Close(); } catch (Exception exception) { MessageWindow.ShowAlertMessage(exception.Message); } }
public ActionResult Edit(List <tempCashVoucherDetail> cashVoucherDetailList, List <tempCashVoucher> cashVoucherList, string create) { Session["err"] = "Error, Please Check Input Fields"; Session["msg"] = ""; int cashvoucherid = 0; foreach (tempCashVoucherDetail t in cashVoucherDetailList.ToList()) { cashvoucherid = t.cashvoucherid; if (Convert.ToDecimal(t.amount.Replace(",", "")) > 0) { try { CashVoucherDetail cashvoucherdetail = db.CashVoucherDetails.Find(t.cashvoucherdetailid); if (cashvoucherdetail == null) { CashVoucherDetail cashvoucherdetail1 = new CashVoucherDetail(); cashvoucherdetail1.CashVoucherID = t.cashvoucherid; cashvoucherdetail1.AccountHeadID = t.accountheadid; cashvoucherdetail1.Amount = decimal.Round(Convert.ToDecimal(t.amount.Replace(",", "")), 2, MidpointRounding.AwayFromZero); cashvoucherdetail1.Remarks = t.remarks; db.CashVoucherDetails.Add(cashvoucherdetail1); db.SaveChanges(); } else { cashvoucherdetail.CashVoucherID = t.cashvoucherid; cashvoucherdetail.AccountHeadID = t.accountheadid; cashvoucherdetail.Amount = decimal.Round(Convert.ToDecimal(t.amount.Replace(",", "")), 2, MidpointRounding.AwayFromZero); cashvoucherdetail.Remarks = t.remarks; db.Entry(cashvoucherdetail).State = EntityState.Modified; db.SaveChanges(); } cashvoucherid = t.cashvoucherid; } catch { } } } try { var cashvoucherdetailfinal = db.CashVoucherDetails.Where(b => b.CashVoucherID == cashvoucherid).OrderBy(b => b.CashVoucherDetailID).Skip(1).ToList(); foreach (CashVoucherDetail cvd in cashvoucherdetailfinal) { if (cvd.Amount == 0) { db.CashVoucherDetails.Remove(cvd); db.SaveChanges(); } } } catch {} if (create == "1") { try { CashVoucherDetail cashvoucherdetail1 = new CashVoucherDetail(); cashvoucherdetail1.CashVoucherID = cashvoucherid; cashvoucherdetail1.AccountHeadID = 1; cashvoucherdetail1.Amount = 0.00M; cashvoucherdetail1.Remarks = ""; db.CashVoucherDetails.Add(cashvoucherdetail1); db.SaveChanges(); } catch { } } decimal totalamt = 0; try { totalamt = db.CashVoucherDetails.Where(u => u.CashVoucherID == cashvoucherid).Sum(u => (decimal)u.Amount); } catch { } try { foreach (tempCashVoucher bv in cashVoucherList.ToList()) { CashVoucher cashvoucherfinal = db.CashVouchers.Find(bv.cashvoucherid); if (bv.vouchertypeid == 1) { cashvoucherfinal.VoucherNo = "CRV-" + cashvoucherid.ToString("D" + 6); } else { cashvoucherfinal.VoucherNo = "CPV-" + cashvoucherid.ToString("D" + 6); } cashvoucherfinal.VoucherTypeID = bv.vouchertypeid; cashvoucherfinal.EmployeeID = bv.employeeid; cashvoucherfinal.AccountHeadID = bv.accountheadid; cashvoucherfinal.VoucherDate = bv.voucherdate; cashvoucherfinal.ReferenceNo = bv.referenceno; cashvoucherfinal.ReferenceDate = bv.referencedate; cashvoucherfinal.Narration = bv.narration; cashvoucherfinal.TotalAmount = decimal.Round(Convert.ToDecimal(totalamt.ToString("#.##")), 2, MidpointRounding.AwayFromZero); db.Entry(cashvoucherfinal).State = EntityState.Modified; db.SaveChanges(); if (create == "0" && cashvoucherfinal.TotalAmount > 0) { cashvoucherfinal.Flag = true; db.Entry(cashvoucherfinal).State = EntityState.Modified; db.SaveChanges(); var accountjournals = db.AccountJournals.Where(a => a.VoucherNo == cashvoucherfinal.VoucherNo).ToList(); foreach (AccountJournal accountjournal1 in accountjournals) { var accountjournaldetails = db.AccountJournalDetails.Where(a => a.AccountJournalID == accountjournal1.AccountJournalID).ToList(); foreach (AccountJournalDetail accountjournaldetail1 in accountjournaldetails) { db.AccountJournalDetails.Remove(accountjournaldetail1); } db.SaveChanges(); db.AccountJournals.Remove(accountjournal1); } db.SaveChanges(); AccountJournal accountjournal = new AccountJournal(); accountjournal.VoucherNo = cashvoucherfinal.VoucherNo; accountjournal.VoucherType = cashvoucherfinal.VoucherNo.Substring(0, 2); accountjournal.TransactionDate = cashvoucherfinal.VoucherDate; accountjournal.BranchID = int.Parse(Session["BranchID"].ToString()); accountjournal.FinancialYearID = int.Parse(Session["FinancialYearID"].ToString()); accountjournal.UserID = Session["UserID"].ToString(); accountjournal.Remarks = "Cash Voucher"; db.AccountJournals.Add(accountjournal); db.SaveChanges(); var cashvoucherdetail = db.CashVoucherDetails.Where(d => d.CashVoucherID == cashvoucherfinal.CashVoucherID).ToList(); int voucheracc = 0; foreach (CashVoucherDetail d in cashvoucherdetail) { AccountJournalDetail accountjournaldetail = new AccountJournalDetail(); if (voucheracc == 0) { voucheracc = cashvoucherfinal.AccountHeadID; accountjournaldetail.AccountJournalID = accountjournal.AccountJournalID; accountjournaldetail.AccountHeadID = cashvoucherfinal.AccountHeadID; accountjournaldetail.AnalysisHeadID = 0; if (cashvoucherfinal.VoucherTypeID == 1) { accountjournaldetail.Amount = cashvoucherfinal.TotalAmount * -1; accountjournaldetail.Remarks = "Cash Voucher Receipt"; } else { accountjournaldetail.Amount = cashvoucherfinal.TotalAmount; accountjournaldetail.Remarks = "Cash Voucher Payment"; } db.AccountJournalDetails.Add(accountjournaldetail); db.SaveChanges(); } accountjournaldetail = new AccountJournalDetail(); accountjournaldetail.AccountJournalID = accountjournal.AccountJournalID; accountjournaldetail.AccountHeadID = d.AccountHeadID; accountjournaldetail.AnalysisHeadID = 0; if (cashvoucherfinal.VoucherTypeID == 1) { accountjournaldetail.Amount = d.Amount; accountjournaldetail.Remarks = "Cash Voucher Receipt"; } else { accountjournaldetail.Amount = d.Amount * -1; accountjournaldetail.Remarks = "Cash Voucher Payment"; } db.AccountJournalDetails.Add(accountjournaldetail); db.SaveChanges(); } } Session["msg"] = "Modified Successfully"; Session["err"] = ""; } } catch {} return(Json(Session["err"], JsonRequestBehavior.AllowGet)); }
private void Rollback() { CashVoucher.DeleteAll(_voucherDocument.VoucherNo); }
public static void Show(CashVoucher Item) { Dialog.Receipt = Item; Dialog.ShowDialog(); }
private void onClickRent(object sender, RoutedEventArgs e) { Status = " "; Vehicle Item = Client.Server.ConnectProvider.GetUserVehicle(Client.User); if (_activeVehicle.ClientId != 0) { Status = "Цей транспорт вже орендований."; return; } if (Item.VIN != "null") { Status = "Ви вже маєте орендований автомобіль."; return; } if (date_Picker.Visibility != Visibility.Visible) { date_Picker.Visibility = Visibility.Visible; date_Picker.DisplayDateStart = DateTime.Now.AddDays(1); date_Picker.DisplayDateEnd = DateTime.Now.AddDays(50); return; } else { if (string.IsNullOrEmpty(date_Picker.Text)) { Status = "Виберіть дату."; return; } } float TotalPrice = 0; DateTime Time = date_Picker.SelectedDate ?? DateTime.Now; TimeSpan delta = Time - DateTime.Now; int days = delta.Days; TotalPrice = days * _activeVehicle.Price; //if (TotalPrice > ) string message = $"Ви дійсно хочете орендувати {_activeVehicle.Name} {_activeVehicle.Model} за ₴ {TotalPrice}?"; if (DialogWindow.Show(message, "Підтвердження оренди", DialogButtons.OkNo, DialogStyle.Information) == DialogResult.Ok) { if (TotalPrice > Client.User.Balance) { Status = "Недостатньо грошей на рахунку."; return; } Client.User.Balance -= TotalPrice; _activeVehicle.StartDate = DateTime.Now; _activeVehicle.FinalDate = Time; _activeVehicle.ClientId = Client.User.Id; CashVoucher ReceiptItem = Client.CollectReceipt(Client.User, _activeVehicle, TotalPrice, _activeVehicle.StartDate, _activeVehicle.FinalDate); int Id = Client.Server.ConnectProvider.writeCashVoucher(ReceiptItem); _activeVehicle.RentLogId = Client.Server.ConnectProvider.log_TakeRent( Client.User.Id, _activeVehicle.VIN, TotalPrice, Id, _activeVehicle.StartDate, _activeVehicle.FinalDate ); Client.Server.ConnectProvider.SaveUser(Client.User); Client.Server.ConnectProvider.saveVehicle(_activeVehicle); UiOperation.SetPage(UIPage.Main); } }
private void PostButtonOnClick(object sender, RoutedEventArgs e) { var result = _withdrawal.Validate(); if (!result.Success) { MessageWindow.ShowAlertMessage(result.Message); return; } #region --- Withdrawal Credit Side --- var voucher = new Voucher { VoucherDate = _withdrawal.WithdrawalSettings.TransactionDate, VoucherNo = _withdrawal.WithdrawalSettings.WithdrawalVoucherNo, VoucherType = VoucherTypes.CV }; var totalWithdrawals = Withdrawal.TotalWithdrawals(voucher.VoucherNo) + _withdrawal.WithdrawalAmount; result = Withdrawal.ReBalanceWithdrawals(voucher, totalWithdrawals); if (!result.Success) { MessageWindow.ShowAlertMessage(result.Message); return; } #endregion #region --- Withdrawal Debit Side --- var cv = new CashVoucher(); var member = Nfmb.FindByCode(_withdrawal.AccountInfo.MemberCode); cv.MemberCode = member.MemberCode; cv.MemberName = member.MemberName; var account = Account.FindByCode(_withdrawal.AccountInfo.AccountCode); cv.AccountCode = account.AccountCode; cv.AccountTitle = account.AccountTitle; cv.Debit = _withdrawal.WithdrawalAmount; cv.VoucherDate = voucher.VoucherDate; cv.VoucherNo = voucher.VoucherNo; cv.VoucherType = voucher.VoucherType; cv.WithdrawalSlipNo = _withdrawal.WithdrawalSlipNo; cv.Create(); #endregion #region --- Voucher Log --- var voucherLog = new VoucherLog(); voucherLog.Find("CV", cv.VoucherNo); voucherLog.Date = cv.VoucherDate; voucherLog.Initials = MainController.LoggedUser.Initials; voucherLog.Save(); #endregion var validationBuilder = new StringBuilder(); validationBuilder.AppendFormat("{0} {1} {2} {3} {4} {5:yyyy-MM-dd hh:mm:ss} {6}", cv.MemberCode, cv.AccountCode, cv.VoucherNo, cv.WithdrawalSlipNo, cv.Debit, DateTime.Now, MainController.LoggedUser.Initials); if (MessageWindow.ShowConfirmMessage("Print withdrawal validation?") == MessageBoxResult.Yes) { ReportController.PrintWitdrawalValidation(cv); } DialogResult = true; Close(); }
private Result PostToVoucher() { var postingDetails = new LoanPostingDetails { VoucherType = VoucherTypes.CV, VoucherDate = GlobalSettings.DateOfOpenTransaction }; postingDetails.VoucherNumber = Voucher.LastDocumentNo(postingDetails.VoucherType) + 1; postingDetails.ReleaseNumber = ModelController.Releases.MaxReleaseNumber() + 1; postingDetails.ReleaseDate = postingDetails.VoucherDate; // 1. ask user to enter voucher information var postingWindow = new LoanPostingWindow(postingDetails); if (postingWindow.ShowDialog() != true) { return(new Result(false, "Posting was cancelled by user.")); } // 1.1 Must be open transaction if (postingDetails.VoucherDate != GlobalSettings.DateOfOpenTransaction) { return(new Result(false, "Voucher date is locked!")); } if (postingDetails.VoucherDate != MainController.LoggedUser.TransactionDate) { return(new Result(false, "Transaction Date is not valid or not set!")); } // 2. inform user if voucher information already exist, ask if to overwrite if (postingDetails.VoucherType == VoucherTypes.CV) { ObservableCollection <CashVoucher> cvEntries = CashVoucher.WhereDocumentNumberIs(postingDetails.VoucherNumber); if (cvEntries.Count > 0) { return(new Result(false, string.Format("{0} #{1} already exist!", postingDetails.VoucherType, postingDetails.VoucherNumber))); } } if (postingDetails.VoucherType == VoucherTypes.JV) { ObservableCollection <JournalVoucher> jvEntries = JournalVoucher.WhereDocumentNumberIs(postingDetails.VoucherNumber); if (jvEntries.Count > 0) { return(new Result(false, string.Format("{0} #{1} already exist!", postingDetails.VoucherType, postingDetails.VoucherNumber))); } } // 3. post transaction details _loanDetails.ReleaseNo = postingDetails.ReleaseNumber; _loanDetails.DateReleased = postingDetails.ReleaseDate; //TODO: Loan Application Information //loanDetails.ThisMonth //loanDetails.DateApplied = _loanDetail.DateGranted; //loanDetails.DateApproved //loanDetails.DateCancelled; //loanDetails.DateReleased // net proceeds var netProceeds = new ComputationDetail { AccountCode = _loanComputation.NetProceedsCode, AccountTitle = _loanComputation.NetProceedsTitle, Amount = _loanComputation.NetProceedsAmount }; if (postingDetails.VoucherType == VoucherTypes.JV) { #region --- Add entry for Cash On Hand --- var net = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = netProceeds.AccountCode, AccountTitle = netProceeds.AccountTitle, Credit = netProceeds.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber, }; net.Amount = net.Credit; net.AmountInWords = Converter.AmountToWords(net.Amount); Result postResult = net.Create(); if (!postResult.Success) { JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entries for Charges --- foreach (ComputationDetail computationDetail in _loanComputation.Charges) { if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0) { continue; } var charges = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = computationDetail.AccountCode, AccountTitle = computationDetail.AccountTitle, Credit = computationDetail.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = charges.Create(); if (postResult.Success) { continue; } JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entries for Deductions --- foreach (ComputationDetail computationDetail in _loanComputation.Deductions) { if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0) { continue; } var deductions = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = computationDetail.AccountCode, AccountTitle = computationDetail.AccountTitle, Credit = computationDetail.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = deductions.Create(); if (postResult.Success) { continue; } JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entry for Unearned Income --- Account ui = Account.FindByCode(GlobalSettings.CodeOfUnearnedIncome); var unearnedIncome = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = ui.AccountCode, AccountTitle = ui.AccountTitle, Credit = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.Interest), VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = unearnedIncome.Create(); if (!postResult.Success) { JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entry for Capital Build-Up --- Account cbu = Account.FindByCode(GlobalSettings.CodeOfCapitalBuildUp); var capitalBuildUp = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = cbu.AccountCode, AccountTitle = cbu.AccountTitle, Credit = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.CapitalBuildUp), VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = capitalBuildUp.Create(); if (!postResult.Success) { JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Finally add entry for the loan applied --- var loanVoucherEntry = new JournalVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = _loanDetails.AccountCode, AccountTitle = _loanDetails.AccountTitle, Debit = _loanDetails.LoanAmount + unearnedIncome.Credit + capitalBuildUp.Credit, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber, LoanDetails = _loanDetails, Explanation = _loanDetails.GenerateExplanation() }; postResult = loanVoucherEntry.Create(); if (!postResult.Success) { JournalVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion } else { #region --- Add entry for Cash On Hand --- var net = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = netProceeds.AccountCode, AccountTitle = netProceeds.AccountTitle, Credit = netProceeds.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber, }; net.Amount = net.Credit; net.AmountInWords = Converter.AmountToWords(net.Amount); Result postResult = net.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entries for Charges --- foreach (ComputationDetail computationDetail in _loanComputation.Charges) { if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0) { continue; } var charges = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = computationDetail.AccountCode, AccountTitle = computationDetail.AccountTitle, Credit = computationDetail.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = charges.Create(); if (postResult.Success) { continue; } CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entries for Deductions --- foreach (ComputationDetail computationDetail in _loanComputation.Deductions) { if (string.IsNullOrEmpty(computationDetail.AccountCode) || computationDetail.Amount == 0) { continue; } var deductions = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = computationDetail.AccountCode, AccountTitle = computationDetail.AccountTitle, Credit = computationDetail.Amount, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = deductions.Create(); if (postResult.Success) { continue; } CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entry for Unearned Income --- Account ui = Account.FindByCode(GlobalSettings.CodeOfUnearnedIncome); var unearnedIncome = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = ui.AccountCode, AccountTitle = ui.AccountTitle, Credit = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.Interest), VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = unearnedIncome.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Add entry for Capital Build-Up --- Account cbu = Account.FindByCode(GlobalSettings.CodeOfCapitalBuildUp); var capitalBuildUp = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = cbu.AccountCode, AccountTitle = cbu.AccountTitle, Credit = _loanAmortizationHeader.PaymentSchedules.Sum(sched => sched.CapitalBuildUp), VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber }; postResult = capitalBuildUp.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion #region --- Finally add entry for the loan applied --- var loanVoucherEntry = new CashVoucher { MemberCode = _loanDetails.MemberCode, MemberName = _loanDetails.MemberName, AccountCode = _loanDetails.AccountCode, AccountTitle = _loanDetails.AccountTitle, Debit = _loanDetails.LoanAmount + unearnedIncome.Credit + capitalBuildUp.Credit, VoucherDate = postingDetails.VoucherDate, VoucherNo = postingDetails.VoucherNumber, LoanDetails = _loanDetails, Explanation = _loanDetails.GenerateExplanation() }; postResult = loanVoucherEntry.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(postingDetails.VoucherNumber); return(postResult); } #endregion } #region --- Voucher Log --- var voucherLog = new VoucherLog(); voucherLog.Find(postingDetails.VoucherType.ToString(), postingDetails.VoucherNumber); voucherLog.Date = postingDetails.VoucherDate; voucherLog.Initials = MainController.LoggedUser.Initials; voucherLog.Save(); #endregion return(new Result(true, string.Format("A loan has been created! Please check {0} #{1}.", postingDetails.VoucherType, postingDetails.VoucherNumber))); }
private void btnPost_Click(object sender, EventArgs e) { var loanAmount = _cashVoucher.Debit; var voucherNo = _cashVoucher.VoucherNo; var voucherDate = MainController.LoggedUser.TransactionDate; var document = new VoucherDocument(VoucherTypes.CV, voucherNo, voucherDate); // is there already a loan product for salary advance? if (_loanProduct == null) { MessageWindow.ShowAlertMessage("No Loan Products found for Salary Advance."); return; } // does user enter a valid amount? if (loanAmount <= 0) { MessageWindow.ShowAlertMessage("Invalid amount!"); return; } // does the voucher number been used? var collection = CashVoucher.WhereDocumentNumberIs(voucherNo); if (collection.Count > 0) { MessageWindow.ShowAlertMessage("CV No. already in use."); return; } try { // what is the account for salary advance? var salaryAdvance = Account.FindByCode(GlobalSettings.CodeOfSalaryAdvance); var cashOnHandReceived = loanAmount; #region --- Finally add entry for the loan applied --- // what will be the loan details? var loanDetails = GenerateLoanDetails(); _cashVoucher.SetMember(_member); _cashVoucher.SetAccount(salaryAdvance); _cashVoucher.SetDocument(document); _cashVoucher.Explanation = loanDetails.GenerateExplanation(); _cashVoucher.LoanDetails = loanDetails; Result postResult = _cashVoucher.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } #endregion #region --- Interest Charge --- var interest = new CashVoucher(); interest.SetMember(_member); interest.SetAccount(Account.FindByCode(GlobalSettings.CodeOfMiscellaneousIncome)); interest.SetDocument(document); interest.Credit = loanDetails.InterestAmount; postResult = interest.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } cashOnHandReceived -= interest.Credit; #endregion #region --- Add entries for Charges --- foreach (var charge in _loanProduct.LoanCharges) { var entry = new CashVoucher(); entry.SetMember(_member); entry.SetAccount(Account.FindByCode(charge.AccountCode)); entry.SetDocument(document); entry.Credit = loanAmount * charge.Rate; postResult = entry.Create(); if (postResult.Success) { cashOnHandReceived -= entry.Credit; continue; } CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } #endregion #region --- Add entry for Cash On Hand --- var net = new CashVoucher(); net.SetMember(_member); net.SetAccount(Account.FindByCode(GlobalSettings.CodeOfCashOnHand)); net.SetDocument(document); net.Credit = cashOnHandReceived; net.Amount = cashOnHandReceived; net.AmountInWords = Converter.AmountToWords(cashOnHandReceived); postResult = net.Create(); if (!postResult.Success) { CashVoucher.DeleteAll(document.Number); MessageWindow.ShowAlertMessage(postResult.Message); return; } #endregion #region --- Voucher Log --- var voucherLog = new VoucherLog(); voucherLog.Find("CV", _cashVoucher.VoucherNo); voucherLog.Date = _cashVoucher.VoucherDate; voucherLog.Initials = MainController.LoggedUser.Initials; voucherLog.Save(); #endregion MessageWindow.ShowNotifyMessage("Salary Advance created. Please check CV# " + voucherNo); DialogResult = true; Close(); } catch (Exception exception) { MessageWindow.ShowAlertMessage(exception.Message); } }