Ejemplo n.º 1
0
        ///<summary>Changes the window visually for Open Dental accounting users.</summary>
        private void PanelLayoutOD()
        {
            groupAutomaticPayment.Visible = true;
            panelQB.Visible  = false;
            panelOD.Visible  = true;
            panelOD.Location = new Point(27, 27);
            panelOD.Size     = new Size(519, 222);
            groupAutomaticPayment.Visible = true;
            //Update the grids for this layout.
            string depStr = PrefC.GetString(PrefName.AccountingDepositAccounts);

            string[] depStrArray = depStr.Split(new char[] { ',' });
            depAL = new ArrayList();
            for (int i = 0; i < depStrArray.Length; i++)
            {
                if (depStrArray[i] == "")
                {
                    continue;
                }
                depAL.Add(PIn.Long(depStrArray[i]));
            }
            FillDepList();
            PickedDepAccountNum = PrefC.GetLong(PrefName.AccountingIncomeAccount);
            textAccountInc.Text = Accounts.GetDescript(PickedDepAccountNum);
            //pay----------------------------------------------------------
            payList = new List <AccountingAutoPay>();
            payList.AddRange(AccountingAutoPays.Listt);            //Count might be 0
            FillPayGrid();
            PickedPayAccountNum     = PrefC.GetLong(PrefName.AccountingCashIncomeAccount);
            textAccountCashInc.Text = Accounts.GetDescript(PickedPayAccountNum);
        }
Ejemplo n.º 2
0
 private void FillList()
 {
     listAccounts.Items.Clear();
     for (int i = 0; i < accountAL.Count; i++)
     {
         listAccounts.Items.Add(Accounts.GetDescript((int)accountAL[i]));
     }
 }
 private void FillDepList()
 {
     listAccountsDep.Items.Clear();
     for (int i = 0; i < depAL.Count; i++)
     {
         listAccountsDep.Items.Add(Accounts.GetDescript((int)depAL[i]));
     }
 }
        private void butChangeCash_Click(object sender, EventArgs e)
        {
            FormAccountPick FormA = new FormAccountPick();

            FormA.ShowDialog();
            if (FormA.DialogResult != DialogResult.OK)
            {
                return;
            }
            PickedPayAccountNum     = FormA.SelectedAccount.AccountNum;
            textAccountCashInc.Text = Accounts.GetDescript(PickedPayAccountNum);
        }
Ejemplo n.º 5
0
        ///<summary>Converts the comma delimited list of AccountNums into full descriptions separated by carriage returns.</summary>
        public static string GetPickListDesc(AccountingAutoPay pay)
        {
            string[] numArray = pay.PickList.Split(new char[] { ',' });
            string   retVal   = "";

            for (int i = 0; i < numArray.Length; i++)
            {
                if (numArray[i] == "")
                {
                    continue;
                }
                if (retVal != "")
                {
                    retVal += "\r\n";
                }
                retVal += Accounts.GetDescript(PIn.PInt(numArray[i]));
            }
            return(retVal);
        }
        private void FormAccountingSetup_Load(object sender, EventArgs e)
        {
            string depStr = PrefB.GetString("AccountingDepositAccounts");

            string[] depStrArray = depStr.Split(new char[] { ',' });
            depAL = new ArrayList();
            for (int i = 0; i < depStrArray.Length; i++)
            {
                if (depStrArray[i] == "")
                {
                    continue;
                }
                depAL.Add(PIn.PInt(depStrArray[i]));
            }
            FillDepList();
            PickedDepAccountNum = PrefB.GetInt("AccountingIncomeAccount");
            textAccountInc.Text = Accounts.GetDescript(PickedDepAccountNum);
            //pay----------------------------------------------------------
            payAL = AccountingAutoPays.AList;          //Count might be 0
            FillPayGrid();
            PickedPayAccountNum     = PrefB.GetInt("AccountingCashIncomeAccount");
            textAccountCashInc.Text = Accounts.GetDescript(PickedPayAccountNum);
        }
Ejemplo n.º 7
0
        ///<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);
        }
Ejemplo n.º 8
0
 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 = GridSelectionMode.None;
         gridPat.SelectionMode = GridSelectionMode.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();
 }
Ejemplo n.º 9
0
        ///<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);
        }
Ejemplo n.º 10
0
        ///<summary>Only called once from FormPayment when trying to change an amount or an account on a payment that's already linked to the Accounting section or when trying to create a new link.  This automates updating the Accounting section.  Do not surround with try-catch, because it was already validated in ValidateLinkedEntries above.  Use -1 for newAcct to indicate no changed. The name is required to give descriptions to new entries.</summary>
        public static void AlterLinkedEntries(double oldAmt, double newAmt, bool isNew, int payNum, int newAcct, DateTime payDate,
                                              string patName)
        {
            if (!Accounts.PaymentsLinked())
            {
                return;                //user has not even set up accounting links.
            }
            bool amtChanged = false;

            if (oldAmt != newAmt)
            {
                amtChanged = true;
            }
            Transaction trans  = Transactions.GetAttachedToPayment(payNum); //this gives us the oldAcctNum
            double      absNew = newAmt;                                    //absolute value of the new amount

            if (newAmt < 0)
            {
                absNew = -newAmt;
            }
            //if(trans==null && (newAcct==0 || newAcct==-1)) {//then this method will not even be called
            if (trans == null)           //no previous link, but user is trying to create one.
            //this is the only case where a new trans is required.
            {
                trans         = new Transaction();
                trans.PayNum  = payNum;
                trans.UserNum = Security.CurUser.UserNum;
                Transactions.Insert(trans);                //sets entry date
                //first the deposit entry
                JournalEntry je = new JournalEntry();
                je.AccountNum    = newAcct;        //DepositAccounts[comboDepositAccount.SelectedIndex];
                je.CheckNumber   = Lan.g("Payments", "DEP");
                je.DateDisplayed = payDate;        //it would be nice to add security here.
                if (absNew == newAmt)              //amount is positive
                {
                    je.DebitAmt = newAmt;
                }
                else
                {
                    je.CreditAmt = absNew;
                }
                je.Memo           = Lan.g("Payments", "Payment -") + " " + patName;
                je.Splits         = Accounts.GetDescript(PrefB.GetInt("AccountingCashIncomeAccount"));
                je.TransactionNum = trans.TransactionNum;
                JournalEntries.Insert(je);
                //then, the income entry
                je            = new JournalEntry();
                je.AccountNum = PrefB.GetInt("AccountingCashIncomeAccount");
                //je.CheckNumber=;
                je.DateDisplayed = payDate;         //it would be nice to add security here.
                if (absNew == newAmt)               //amount is positive
                {
                    je.CreditAmt = newAmt;
                }
                else
                {
                    je.DebitAmt = absNew;
                }
                je.Memo           = Lan.g("Payments", "Payment -") + " " + patName;
                je.Splits         = Accounts.GetDescript(newAcct);
                je.TransactionNum = trans.TransactionNum;
                JournalEntries.Insert(je);
                return;
            }
            //at this point, we have established that there is a previous transaction.
            ArrayList    jeAL        = JournalEntries.GetForTrans(trans.TransactionNum);
            int          oldAcct     = 0;
            JournalEntry jeDebit     = null;
            JournalEntry jeCredit    = null;
            bool         signChanged = false;
            double       absOld      = oldAmt;//the absolute value of the old amount

            if (oldAmt < 0)
            {
                absOld = -oldAmt;
            }
            if (oldAmt < 0 && newAmt > 0)
            {
                signChanged = true;
            }
            if (oldAmt > 0 && newAmt < 0)
            {
                signChanged = true;
            }
            for (int i = 0; i < 2; i++)
            {
                if (Accounts.GetAccount(((JournalEntry)jeAL[i]).AccountNum).AcctType == AccountType.Asset)
                {
                    oldAcct = ((JournalEntry)jeAL[i]).AccountNum;
                }
                if (((JournalEntry)jeAL[i]).DebitAmt == absOld)
                {
                    jeDebit = (JournalEntry)jeAL[i];
                }
                //old credit entry
                if (((JournalEntry)jeAL[i]).CreditAmt == absOld)
                {
                    jeCredit = (JournalEntry)jeAL[i];
                }
            }
            //Already validated that both je's are not null, and that oldAcct is not 0.
            if (newAcct == 0)          //detaching it from a linked transaction. We will delete the transaction
            //we don't care about the amount
            {
                Transactions.Delete(trans);                //we need to make sure this doesn't throw any exceptions by carefully checking all
                //possibilities in the validation routine above.
                return;
            }
            //Either the amount or the account changed on an existing linked transaction.
            bool acctChanged = false;

            if (newAcct != -1 && oldAcct != newAcct)
            {
                acctChanged = true;              //changing linked acctNum
            }
            if (amtChanged)
            {
                if (signChanged)
                {
                    jeDebit.DebitAmt   = 0;
                    jeDebit.CreditAmt  = absNew;
                    jeCredit.DebitAmt  = absNew;
                    jeCredit.CreditAmt = 0;
                }
                else
                {
                    jeDebit.DebitAmt   = absNew;
                    jeCredit.CreditAmt = absNew;
                }
            }
            if (acctChanged)
            {
                if (jeDebit.AccountNum == oldAcct)
                {
                    jeDebit.AccountNum = newAcct;
                }
                if (jeCredit.AccountNum == oldAcct)
                {
                    jeCredit.AccountNum = newAcct;
                }
            }
            JournalEntries.Update(jeDebit);
            JournalEntries.Update(jeCredit);
        }