private void FormDepositEdit_Load(object sender, System.EventArgs e) { if (IsNew) { if (!Security.IsAuthorized(Permissions.DepositSlips, DateTime.Today)) { //we will check the date again when saving DialogResult = DialogResult.Cancel; return; } } else { //We enforce security here based on date displayed, not date entered if (!Security.IsAuthorized(Permissions.DepositSlips, DepositCur.DateDeposit)) { butOK.Enabled = false; butDelete.Enabled = false; } } if (IsNew) { textDateStart.Text = PIn.PDate(PrefB.GetString("DateDepositsStarted")).ToShortDateString(); if (PrefB.GetBool("EasyNoClinics")) { comboClinic.Visible = false; labelClinic.Visible = false; } comboClinic.Items.Clear(); comboClinic.Items.Add(Lan.g(this, "all")); comboClinic.SelectedIndex = 0; for (int i = 0; i < Clinics.List.Length; i++) { comboClinic.Items.Add(Clinics.List[i].Description); } for (int i = 0; i < DefB.Short[(int)DefCat.PaymentTypes].Length; i++) { listPayType.Items.Add(DefB.Short[(int)DefCat.PaymentTypes][i].ItemName); listPayType.SetSelected(i, true); } textDepositAccount.Visible = false; //this is never visible for new. It's a description if already attached. if (Accounts.DepositsLinked()) { DepositAccounts = Accounts.GetDepositAccounts(); for (int i = 0; i < DepositAccounts.Length; i++) { comboDepositAccount.Items.Add(Accounts.GetDescript(DepositAccounts[i])); } comboDepositAccount.SelectedIndex = 0; } else { labelDepositAccount.Visible = false; comboDepositAccount.Visible = false; } } else { groupSelect.Visible = false; gridIns.SelectionMode = SelectionMode.None; gridPat.SelectionMode = SelectionMode.None; //we never again let user change the deposit linking again from here. //They need to detach it from within the transaction //Might be enhanced later to allow, but that's very complex. Transaction trans = Transactions.GetAttachedToDeposit(DepositCur.DepositNum); if (trans == null) { labelDepositAccount.Visible = false; comboDepositAccount.Visible = false; textDepositAccount.Visible = false; } else { comboDepositAccount.Enabled = false; labelDepositAccount.Text = Lan.g(this, "Deposited into Account"); ArrayList jeAL = JournalEntries.GetForTrans(trans.TransactionNum); for (int i = 0; i < jeAL.Count; i++) { if (Accounts.GetAccount(((JournalEntry)jeAL[i]).AccountNum).AcctType == AccountType.Asset) { comboDepositAccount.Items.Add(Accounts.GetDescript(((JournalEntry)jeAL[i]).AccountNum)); comboDepositAccount.SelectedIndex = 0; textDepositAccount.Text = ((JournalEntry)jeAL[i]).DateDisplayed.ToShortDateString() + " " + ((JournalEntry)jeAL[i]).DebitAmt.ToString("c"); break; } } } } textDate.Text = DepositCur.DateDeposit.ToShortDateString(); textAmount.Text = DepositCur.Amount.ToString("F"); textBankAccountInfo.Text = DepositCur.BankAccountInfo; FillGrids(); if (IsNew) { gridPat.SetSelected(true); gridIns.SetSelected(true); } ComputeAmt(); }
///<summary>Saves the selected rows to database. MUST close window after this.</summary> private bool SaveToDB() { if (textDate.errorProvider1.GetError(textDate) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return(false); } //Prevent backdating---------------------------------------------------------------------------------------- DateTime date = PIn.PDate(textDate.Text); if (IsNew) { if (!Security.IsAuthorized(Permissions.DepositSlips, date)) { return(false); } } else { //We enforce security here based on date displayed, not date entered if (!Security.IsAuthorized(Permissions.DepositSlips, date)) { return(false); } } DepositCur.DateDeposit = PIn.PDate(textDate.Text); //amount already handled. DepositCur.BankAccountInfo = PIn.PString(textBankAccountInfo.Text); if (IsNew) { Deposits.Insert(DepositCur); if (Accounts.DepositsLinked() && DepositCur.Amount > 0) { //create a transaction here Transaction trans = new Transaction(); trans.DepositNum = DepositCur.DepositNum; trans.UserNum = Security.CurUser.UserNum; Transactions.Insert(trans); //first the deposit entry JournalEntry je = new JournalEntry(); je.AccountNum = DepositAccounts[comboDepositAccount.SelectedIndex]; je.CheckNumber = Lan.g(this, "DEP"); je.DateDisplayed = DepositCur.DateDeposit; //it would be nice to add security here. je.DebitAmt = DepositCur.Amount; je.Memo = Lan.g(this, "Deposit"); je.Splits = Accounts.GetDescript(PrefB.GetInt("AccountingIncomeAccount")); je.TransactionNum = trans.TransactionNum; JournalEntries.Insert(je); //then, the income entry je = new JournalEntry(); je.AccountNum = PrefB.GetInt("AccountingIncomeAccount"); //je.CheckNumber=; je.DateDisplayed = DepositCur.DateDeposit; //it would be nice to add security here. je.CreditAmt = DepositCur.Amount; je.Memo = Lan.g(this, "Deposit"); je.Splits = Accounts.GetDescript(DepositAccounts[comboDepositAccount.SelectedIndex]); je.TransactionNum = trans.TransactionNum; JournalEntries.Insert(je); } } else { Deposits.Update(DepositCur); } if (IsNew) //never allowed to change or attach more checks after initial creation of deposit slip { for (int i = 0; i < gridPat.SelectedIndices.Length; i++) { PatPayList[gridPat.SelectedIndices[i]].DepositNum = DepositCur.DepositNum; Payments.Update(PatPayList[gridPat.SelectedIndices[i]]); } for (int i = 0; i < gridIns.SelectedIndices.Length; i++) { ClaimPayList[gridIns.SelectedIndices[i]].DepositNum = DepositCur.DepositNum; ClaimPayments.Update(ClaimPayList[gridIns.SelectedIndices[i]]); } } if (IsNew) { SecurityLogs.MakeLogEntry(Permissions.DepositSlips, 0, DepositCur.DateDeposit.ToShortDateString() + " New " + DepositCur.Amount.ToString("c")); } else { SecurityLogs.MakeLogEntry(Permissions.AdjustmentEdit, 0, DepositCur.DateDeposit.ToShortDateString() + " " + DepositCur.Amount.ToString("c")); } return(true); }
private void FillGrid(bool isPrinting = false, bool isResizing = false) { if (textDateFrom.errorProvider1.GetError(textDateFrom) != "" || textDateTo.errorProvider1.GetError(textDateTo) != "") { return; } ODGrid gridToFill = isPrinting?gridMainPrint:gridMain; long firstVisibleTransNum = 0; if (!isPrinting && gridToFill.VisibleRows.Count > 0) //don't scroll into view if printing { firstVisibleTransNum = (long)gridToFill.VisibleRows[0].Tag; } long selectedTransNum = 0; if (!isPrinting && gridToFill.GetSelectedIndex() > -1) //no need to reselect an index if printing { selectedTransNum = gridToFill.SelectedTag <long>(); } //Resize grid to fit, important for later resizing gridToFill.BeginUpdate(); gridToFill.Title = _acctCur.Description + " (" + Lan.g("enumAccountType", _acctCur.AcctType.ToString()) + ")"; FillColumns(isPrinting, isResizing); DateTime dateFrom = PIn.Date(textDateFrom.Text); DateTime dateTo = string.IsNullOrEmpty(textDateTo.Text)?DateTime.MaxValue:PIn.Date(textDateTo.Text); double filterAmt = string.IsNullOrEmpty(textAmt.errorProvider1.GetError(textAmt))?PIn.Double(textAmt.Text):0; if (!isResizing || _listJEntries == null || _dictTransUsers == null) { _listJEntries = JournalEntries.GetForAccount(_acctCur.AccountNum); _dictTransUsers = Transactions.GetManyTrans(_listJEntries.Select(x => x.TransactionNum).ToList()) .ToDictionary(x => x.TransactionNum, x => x.UserNum); } gridToFill.ListGridRows.Clear(); GridRow row; decimal bal = 0; int firstVisibleRowIndex = -1; int selectedIndex = -1; foreach (JournalEntry jeCur in _listJEntries) { if (jeCur.DateDisplayed > dateTo) { break; } if (new[] { AccountType.Income, AccountType.Expense }.Contains(_acctCur.AcctType) && jeCur.DateDisplayed < dateFrom) { continue; //for income and expense accounts, previous balances are not included. Only the current timespan. } //DebitIsPos=true for checking acct, bal+=DebitAmt-CreditAmt bal += (Accounts.DebitIsPos(_acctCur.AcctType)?1:-1) * ((decimal)jeCur.DebitAmt - (decimal)jeCur.CreditAmt); if (new[] { AccountType.Asset, AccountType.Liability, AccountType.Equity }.Contains(_acctCur.AcctType) && jeCur.DateDisplayed < dateFrom) { continue; //for asset, liability, and equity accounts, older entries do affect the current balance. } if (filterAmt != 0 && filterAmt != jeCur.CreditAmt && filterAmt != jeCur.DebitAmt) { continue; } if (textFindText.Text != "" && new[] { jeCur.Memo, jeCur.CheckNumber, jeCur.Splits }.All(x => !x.ToUpper().Contains(textFindText.Text.ToUpper()))) { continue; } row = new GridRow(); row.Cells.Add(jeCur.CheckNumber); row.Cells.Add(jeCur.DateDisplayed.ToShortDateString()); row.Cells.Add(jeCur.Memo); row.Cells.Add(jeCur.Splits); row.Cells.Add(jeCur.DebitAmt == 0?"":jeCur.DebitAmt.ToString("n")); row.Cells.Add(jeCur.CreditAmt == 0?"":jeCur.CreditAmt.ToString("n")); row.Cells.Add(bal.ToString("n")); long userNum; row.Cells.Add(Userods.GetName(_dictTransUsers.TryGetValue(jeCur.TransactionNum, out userNum)?userNum:0)); row.Cells.Add(Userods.GetName(jeCur.SecUserNumEdit)); row.Cells.Add(jeCur.ReconcileNum == 0?"":"X"); row.Tag = jeCur.TransactionNum; gridToFill.ListGridRows.Add(row); if (firstVisibleTransNum > 0 && jeCur.TransactionNum == firstVisibleTransNum) { firstVisibleRowIndex = gridToFill.ListGridRows.Count - 1; } if (selectedTransNum > 0 && jeCur.TransactionNum == selectedTransNum) { selectedIndex = gridToFill.ListGridRows.Count - 1; } } gridToFill.EndUpdate(); if (selectedIndex > -1) { gridToFill.SetSelected(selectedIndex, true); } if (firstVisibleRowIndex > -1) { gridToFill.ScrollToIndex(firstVisibleRowIndex); } else { gridToFill.ScrollToEnd(); } }