private void butOK_Click(object sender, System.EventArgs e) { if (textDate.errorProvider1.GetError(textDate) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (SplitList.Count == 0) { MsgBox.Show(this, "Please enter transfers first."); return; } double total = 0; for (int i = 0; i < SplitList.Count; i++) { total += SplitList[i].SplitAmt; } if (total != 0) { MsgBox.Show(this, "Total must equal zero."); return; } PaymentCur.PayNote = textNote.Text; PaymentCur.PayDate = PIn.PDate(textDate.Text); PaymentCur.IsSplit = true; try { Payments.Update(PaymentCur); } catch (ApplicationException ex) { //this catches bad dates. MessageBox.Show(ex.Message); return; } //Set all DatePays the same. for (int i = 0; i < SplitList.Count; i++) { SplitList[i].DatePay = PaymentCur.PayDate; SplitList[i].ProcDate = PaymentCur.PayDate; } PaySplits.UpdateList(SplitListOld, SplitList); if (IsNew) { SecurityLogs.MakeLogEntry(Permissions.PaymentCreate, 0, Lan.g(this, "Prov income transfer.")); } else { SecurityLogs.MakeLogEntry(Permissions.PaymentEdit, 0, Lan.g(this, "Prov income transfer.")); } DialogResult = DialogResult.OK; }
///<summary>Transfers all family balance to the guarantor, balancing the account to the best of our ability. ///Returns a log of what was moved from the family member(s) of the selected guarantor(s)</summary> private string TransferToGuarantor() { string summaryText = ""; //Iterate through every family. foreach (FamilyAccount famAccountCur in _dictCurrentFamilyBatch.Select(x => x.Value)) { double totalTransferAmount = 0; long provNum = famAccountCur.Guarantor.PriProv; Payment payCur = CreatePaymentTransferHelper(famAccountCur.Guarantor); List <PaySplit> listPaySplitsCreated = new List <PaySplit>(); #region Family PaySplits string logText = ""; foreach (Patient pat in famAccountCur.ListFamilyMembers) //Make a counteracting split for each patient. //Don't make a split for the Guarantor yet. { if (pat.PatNum == famAccountCur.Guarantor.PatNum) { continue; } //Check the family member's balance and skip if it is $0.00. double splitAmt = (double)famAccountCur.Account.ListAccountCharges.Where(x => x.PatNum == pat.PatNum).Sum(x => x.AmountEnd); if (splitAmt == 0) { continue; } PaySplit paySplit = new PaySplit(); paySplit.DatePay = datePicker.Value; paySplit.PatNum = pat.PatNum; paySplit.PayNum = payCur.PayNum; paySplit.ProvNum = pat.PriProv; paySplit.ClinicNum = payCur.ClinicNum; //Since we're transferring all family member balances to the guarantor, we set the split amount to their balance. paySplit.SplitAmt = splitAmt; totalTransferAmount += paySplit.SplitAmt; listPaySplitsCreated.Add(paySplit); if (logText != "") { logText += ", "; } logText += paySplit.SplitAmt.ToString("f"); } #endregion Family PaySplits if (listPaySplitsCreated.Count == 0) { //No splits were made, delete payment and skip guarantor. Payments.Delete(payCur); continue; } //Since we skipped the guarantor before, we make one for them now. PaySplit splitGuarantor = new PaySplit(); splitGuarantor.DatePay = datePicker.Value; splitGuarantor.PatNum = famAccountCur.Guarantor.PatNum; splitGuarantor.PayNum = payCur.PayNum; splitGuarantor.ProvNum = provNum; splitGuarantor.ClinicNum = payCur.ClinicNum; splitGuarantor.SplitAmt = 0 - totalTransferAmount; //Split is the opposite amount of the total of the other splits. if (splitGuarantor.SplitAmt != 0) { listPaySplitsCreated.Add(splitGuarantor); } //Insert paysplits all at once for speed. PaySplits.InsertMany(listPaySplitsCreated); List <Patient> listTransferredPats = famAccountCur.ListFamilyMembers.FindAll(x => x.PatNum != famAccountCur.Guarantor.PatNum && listPaySplitsCreated.Select(y => y.PatNum).ToList().Contains(x.PatNum)); payCur.PayNote = "Auto-created by Family Balancer tool " + MiscData.GetNowDateTime().ToString("MM/dd/yyyy") + "\r\n" + "Allocated " + logText + $" transfers from family member{(famAccountCur.ListFamilyMembers.Count>1 ? "s " : " ")}" + string.Join(", ", listTransferredPats.Select(x => x.FName).ToList()) + " to guarantor " + famAccountCur.Guarantor.FName + "."; //Shown after all family members have been processed. summaryText += "PatNum(s):" + string.Join(", ", listTransferredPats.Select(x => x.PatNum).ToList()) + " moved to guarantor: " + famAccountCur.Guarantor.PatNum + "; Amount(s): " + logText + "\r\n"; Payments.Update(payCur, true); } return(summaryText); }
///<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); }
///<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.Date(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.Date(textDate.Text); //amount already handled. DepositCur.BankAccountInfo = PIn.String(textBankAccountInfo.Text); if (IsNew) { if (gridPat.SelectedIndices.Length + gridIns.SelectedIndices.Length > 18) { if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "No more than 18 items will fit on a QuickBooks deposit slip. Continue anyway?")) { return(false); } } Deposits.Insert(DepositCur); if (Accounts.DepositsLinked() && DepositCur.Amount > 0) { if (PrefC.GetInt(PrefName.AccountingSoftware) == (int)AccountingSoftware.QuickBooks) { //Create a deposit within QuickBooks. try { Cursor.Current = Cursors.WaitCursor; QuickBooks.CreateDeposit(DepositAccountsQB[comboDepositAccount.SelectedIndex] , PrefC.GetString(PrefName.QuickBooksIncomeAccount), DepositCur.Amount); Cursor.Current = Cursors.Default; } catch (Exception ex) { Cursor.Current = Cursors.Default; if (MessageBox.Show(ex.Message + "\r\n\r\nA deposit has not been created in QuickBooks, continue anyway?", "QuickBooks Deposit Create Failed", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false); } } } else { //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(PrefC.GetLong(PrefName.AccountingIncomeAccount)); je.TransactionNum = trans.TransactionNum; JournalEntries.Insert(je); //then, the income entry je = new JournalEntry(); je.AccountNum = PrefC.GetLong(PrefName.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]], false); } 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); }