Example #1
0
        private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            int acctNum = PIn.PInt(table.Rows[gridMain.GetSelectedIndex()]["AccountNum"].ToString());

            if (acctNum == 0)
            {
                MsgBox.Show(this, "This account is generated automatically, and there is currently no way to view the detail.  It is the sum of all income minus all expenses for all previous years.");
                return;
            }
            DateTime asofDate;

            if (textDate.errorProvider1.GetError(textDate) != "")            //error
            {
                asofDate = DateTime.Today;
            }
            else
            {
                asofDate = PIn.PDate(textDate.Text);
            }
            Account     acct  = Accounts.GetAccount(acctNum);
            FormJournal FormJ = new FormJournal(acct);

            FormJ.InitialAsOfDate = asofDate;
            FormJ.ShowDialog();
            FillGrid();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i]["AccountNum"].ToString() == acctNum.ToString())
                {
                    gridMain.SetSelected(i, true);
                }
            }
        }
Example #2
0
        private void Edit_Click()
        {
            if (gridMain.GetSelectedIndex() == -1)
            {
                MsgBox.Show(this, "Please pick an account first.");
                return;
            }
            int acctNum = PIn.PInt(table.Rows[gridMain.GetSelectedIndex()]["AccountNum"].ToString());

            if (acctNum == 0)
            {
                MsgBox.Show(this, "This account is generated automatically, and cannot be edited.");
                return;
            }
            Account         acct  = Accounts.GetAccount(acctNum);
            FormAccountEdit FormA = new FormAccountEdit(acct);

            FormA.ShowDialog();
            FillGrid();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i]["AccountNum"].ToString() == acctNum.ToString())
                {
                    gridMain.SetSelected(i, true);
                }
            }
        }
Example #3
0
        private MigraDoc.DocumentObjectModel.Document CreatePrintDocument(PrintDocument pd)
        {
            string text;

            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth    = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Width / 100);
            doc.DefaultPageSetup.PageHeight   = Unit.FromInch((double)pd.DefaultPageSettings.PaperSize.Height / 100);
            doc.DefaultPageSetup.TopMargin    = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Top / 100);
            doc.DefaultPageSetup.LeftMargin   = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Left / 100);
            doc.DefaultPageSetup.RightMargin  = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Right / 100);
            doc.DefaultPageSetup.BottomMargin = Unit.FromInch((double)pd.DefaultPageSettings.Margins.Bottom / 100);
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            section.PageSetup.StartingNumber = 1;
            MigraDoc.DocumentObjectModel.Font headingFont = MigraDocHelper.CreateFont(13, true);
            MigraDoc.DocumentObjectModel.Font bodyFontx   = MigraDocHelper.CreateFont(9, false);
            MigraDoc.DocumentObjectModel.Font nameFontx   = MigraDocHelper.CreateFont(9, true);
            MigraDoc.DocumentObjectModel.Font totalFontx  = MigraDocHelper.CreateFont(9, true);
            Paragraph pageNumParag = new Paragraph();

            pageNumParag.AddText(Lan.g(this, "Page") + " ");
            pageNumParag.AddPageField();
            pageNumParag.AddText(" " + Lan.g(this, "of") + " ");
            pageNumParag.AddNumPagesField();
            section.Footers.Primary.Add(pageNumParag);
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Center;
            parformat.Font      = MigraDocHelper.CreateFont(14, true);
            par.Format          = parformat;
            //Render the reconcile grid.
            par = section.AddParagraph();
            par.Format.Alignment = ParagraphAlignment.Center;
            par.AddFormattedText(Lan.g(this, "RECONCILE"), totalFontx);
            par.AddLineBreak();
            text = Accounts.GetAccount(ReconcileCur.AccountNum).Description.ToUpper();
            par.AddFormattedText(text, totalFontx);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticeTitle);
            par.AddText(text);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticePhone);
            if (text.Length == 10 && Application.CurrentCulture.Name == "en-US")
            {
                text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
            }
            par.AddText(text);
            par.AddLineBreak();
            par.AddText(MiscData.GetNowDateTime().ToShortDateString());
            par.AddLineBreak();
            par.AddText(Lan.g(this, "Reconcile Date") + ": " + PIn.Date(textDate.Text).ToShortDateString());
            par.AddLineBreak();
            par.AddText(labelStart.Text + ": " + PIn.Double(textStart.Text).ToString("n"));
            par.AddLineBreak();
            par.AddText(labelEnd.Text + ": " + PIn.Double(textEnd.Text).ToString("n"));
            MigraDocHelper.InsertSpacer(section, 10);
            MigraDocHelper.DrawGrid(section, gridMain);
            return(doc);
        }
        private void FormJournalEntryEdit_Load(object sender, System.EventArgs e)
        {
            if (EntryCur == null)
            {
                MessageBox.Show("Entry cannot be null.");
            }
            AccountPicked = Accounts.GetAccount(EntryCur.AccountNum);          //might be null

            /*
             * for(int i=0;i<Accounts.ListShort.Length;i++) {
             *      comboAccount.Items.Add(Accounts.ListShort[i].Description);
             *      if(Accounts.ListShort[i].AccountNum==EntryCur.AccountNum){
             *              comboAccount.SelectedIndex=i;
             *      }
             * }
             * if(EntryCur.AccountNum !=0 && comboAccount.SelectedIndex==-1){//must be an inactive account
             *
             * }*/
            FillAccount();
            if (EntryCur.DebitAmt > 0)
            {
                textDebit.Text = EntryCur.DebitAmt.ToString("n");
            }
            if (EntryCur.CreditAmt > 0)
            {
                textCredit.Text = EntryCur.CreditAmt.ToString("n");
            }
            textMemo.Text        = EntryCur.Memo;
            textCheckNumber.Text = EntryCur.CheckNumber;
            if (EntryCur.ReconcileNum == 0)          //not attached
            {
                labelReconcile.Visible = false;
                textReconcile.Visible  = false;
            }
            else             //attached
            {
                textReconcile.Text  = Reconciles.GetOne(EntryCur.ReconcileNum).DateReconcile.ToShortDateString();
                textDebit.ReadOnly  = true;
                textCredit.ReadOnly = true;
                butDelete.Enabled   = false;
                butChange.Enabled   = false;
            }
        }
Example #5
0
        private MigraDoc.DocumentObjectModel.Document CreatePrintDocument()
        {
            string text;

            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(8.5);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(11);
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(.5);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(.5);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(.5);
            MigraDoc.DocumentObjectModel.Section section     = doc.AddSection();
            MigraDoc.DocumentObjectModel.Font    headingFont = MigraDocHelper.CreateFont(13, true);
            MigraDoc.DocumentObjectModel.Font    bodyFontx   = MigraDocHelper.CreateFont(9, false);
            MigraDoc.DocumentObjectModel.Font    nameFontx   = MigraDocHelper.CreateFont(9, true);
            MigraDoc.DocumentObjectModel.Font    totalFontx  = MigraDocHelper.CreateFont(9, true);
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Center;
            parformat.Font      = MigraDocHelper.CreateFont(14, true);
            par.Format          = parformat;
            //Render the reconcile grid.
            par = section.AddParagraph();
            par.Format.Alignment = ParagraphAlignment.Center;
            par.AddFormattedText(Lan.g(this, "RECONCILE"), totalFontx);
            par.AddLineBreak();
            text = Accounts.GetAccount(ReconcileCur.AccountNum).Description.ToUpper();
            par.AddFormattedText(text, totalFontx);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticeTitle);
            par.AddText(text);
            par.AddLineBreak();
            text = PrefC.GetString(PrefName.PracticePhone);
            if (text.Length == 10 && Application.CurrentCulture.Name == "en-US")
            {
                text = "(" + text.Substring(0, 3) + ")" + text.Substring(3, 3) + "-" + text.Substring(6);
            }
            par.AddText(text);
            MigraDocHelper.InsertSpacer(section, 10);
            MigraDocHelper.DrawGrid(section, gridMain);
            return(doc);
        }
Example #6
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();
 }
Example #7
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);
        }
Example #8
0
        ///<summary>This does all the validation before calling AlterLinkedEntries.  It had to be separated like this because of the complexity of saving a payment.  Surround with try-catch.  Will throw an exception if user is trying to change, but not allowed.  Will return false if no synch with accounting is needed.  Use -1 for newAcct to indicate no change.</summary>
        public static bool ValidateLinkedEntries(double oldAmt, double newAmt, bool isNew, int payNum, int newAcct)
        {
            if (!Accounts.PaymentsLinked())
            {
                return(false);               //user has not even set up accounting links, so no need to check any of this.
            }
            bool amtChanged = false;

            if (oldAmt != newAmt)
            {
                amtChanged = true;
            }
            Transaction trans = Transactions.GetAttachedToPayment(payNum); //this gives us the oldAcctNum

            if (trans == null && (newAcct == 0 || newAcct == -1))          //if there was no previous link, and there is no attempt to create a link
            {
                return(false);                                             //no synch needed
            }
            if (trans == null)                                             //no previous link, but user is trying to create one. newAcct>0.
            {
                return(true);                                              //new transaction will be required
            }
            //at this point, we have established that there is a previous transaction.
            //If payment is attached to a transaction which is more than 48 hours old, then not allowed to change.
            if (amtChanged && trans.DateTimeEntry < MiscData.GetNowDateTime().AddDays(-2))
            {
                throw new ApplicationException(Lan.g("Payments", "Not allowed to change amount that is more than 48 hours old.  This payment is already attached to an accounting transaction.  You will need to detach it from within the accounting section of the program."));
            }
            if (amtChanged && Transactions.IsReconciled(trans))
            {
                throw new ApplicationException(Lan.g("Payments", "Not allowed to change amount.  This payment is attached to an accounting transaction that has been reconciled.  You will need to detach it from within the accounting section of the program."));
            }
            ArrayList    jeAL     = JournalEntries.GetForTrans(trans.TransactionNum);
            int          oldAcct  = 0;
            JournalEntry jeDebit  = null;
            JournalEntry jeCredit = null;
            double       absOld   = oldAmt;  //the absolute value of the old amount

            if (oldAmt < 0)
            {
                absOld = -oldAmt;
            }
            for (int i = 0; i < jeAL.Count; i++)       //we make sure down below that this count is exactly 2.
            {
                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];
                }
            }
            if (jeCredit == null || jeDebit == null)
            {
                throw new ApplicationException(Lan.g("Payments", "Not able to automatically make changes in the accounting section to match the change made here.  You will need to detach it from within the accounting section."));
            }
            if (oldAcct == 0)          //something must have gone wrong.  But this should never happen
            {
                throw new ApplicationException(Lan.g("Payments", "Could not locate linked transaction.  You will need to detach it manually from within the accounting section of the program."));
            }
            if (newAcct == 0)          //detaching it from a linked transaction.
            //We will delete the transaction
            {
                return(true);
            }
            bool acctChanged = false;

            if (newAcct != -1 && oldAcct != newAcct)
            {
                acctChanged = true;              //changing linked acctNum
            }
            if (!amtChanged && !acctChanged)
            {
                return(false);               //no changes being made to amount or account, so no synch required.
            }
            if (jeAL.Count != 2)
            {
                throw new ApplicationException(Lan.g("Payments", "Not able to automatically change the amount in the accounting section to match the change made here.  You will need to detach it from within the accounting section."));
            }
            //Amount or account changed on an existing linked transaction.
            return(true);
        }