private void butSend_Click(object sender, EventArgs e)
        {
            //Assuming the use of XCharge.  If adding another vendor (PayConnect for example)
            //make sure to move XCharge validation in FillGrid() to here.
            if (prog == null)           //Gets filled in FillGrid()
            {
                return;
            }
            if (gridMain.SelectedIndices.Length < 1)
            {
                MsgBox.Show(this, "Must select at least one recurring charge.");
                return;
            }
            if (!PaymentsWithinLockDate())
            {
                return;
            }
            string recurringResultFile = "Recurring charge results for " + DateTime.Now.ToShortDateString() + " ran at " + DateTime.Now.ToShortTimeString() + "\r\n\r\n";
            int    failed   = 0;
            int    success  = 0;
            string user     = ProgramProperties.GetPropVal(prog.ProgramNum, "Username");
            string password = ProgramProperties.GetPropVal(prog.ProgramNum, "Password");

            #region Card Charge Loop
            for (int i = 0; i < gridMain.SelectedIndices.Length; i++)
            {
                #region X-Charge
                if (table.Rows[gridMain.SelectedIndices[i]]["XChargeToken"].ToString() != "" &&
                    CreditCards.IsDuplicateXChargeToken(table.Rows[gridMain.SelectedIndices[i]]["XChargeToken"].ToString()))
                {
                    MessageBox.Show(Lan.g(this, "A duplicate token was found, the card cannot be charged for customer: ") + table.Rows[i]["PatName"].ToString());
                    continue;
                }
                insertPayment = false;
                ProcessStartInfo info       = new ProcessStartInfo(xPath);
                long             patNum     = PIn.Long(table.Rows[gridMain.SelectedIndices[i]]["PatNum"].ToString());
                string           resultfile = Path.Combine(Path.GetDirectoryName(xPath), "XResult.txt");
                File.Delete(resultfile);                //delete the old result file.
                info.Arguments = "";
                double   amt        = PIn.Double(table.Rows[gridMain.SelectedIndices[i]]["ChargeAmt"].ToString());
                DateTime exp        = PIn.Date(table.Rows[gridMain.SelectedIndices[i]]["CCExpiration"].ToString());
                string   address    = PIn.String(table.Rows[gridMain.SelectedIndices[i]]["Address"].ToString());
                string   addressPat = PIn.String(table.Rows[gridMain.SelectedIndices[i]]["AddressPat"].ToString());
                string   zip        = PIn.String(table.Rows[gridMain.SelectedIndices[i]]["Zip"].ToString());
                string   zipPat     = PIn.String(table.Rows[gridMain.SelectedIndices[i]]["ZipPat"].ToString());
                info.Arguments += "/AMOUNT:" + amt.ToString("F2") + " /LOCKAMOUNT ";
                info.Arguments += "/TRANSACTIONTYPE:PURCHASE /LOCKTRANTYPE ";
                if (table.Rows[gridMain.SelectedIndices[i]]["XChargeToken"].ToString() != "")
                {
                    info.Arguments += "/XCACCOUNTID:" + table.Rows[gridMain.SelectedIndices[i]]["XChargeToken"].ToString() + " ";
                    info.Arguments += "/RECURRING ";
                }
                else
                {
                    info.Arguments += "/ACCOUNT:" + table.Rows[gridMain.SelectedIndices[i]]["CCNumberMasked"].ToString() + " ";
                }
                if (exp.Year > 1880)
                {
                    info.Arguments += "/EXP:" + exp.ToString("MMyy") + " ";
                }
                if (address != "")
                {
                    info.Arguments += "\"/ADDRESS:" + address + "\" ";
                }
                else if (addressPat != "")
                {
                    info.Arguments += "\"/ADDRESS:" + addressPat + "\" ";
                }
                if (zip != "")
                {
                    info.Arguments += "\"/ZIP:" + zip + "\" ";
                }
                else if (zipPat != "")
                {
                    info.Arguments += "\"/ZIP:" + zipPat + "\" ";
                }
                info.Arguments += "/RECEIPT:Pat" + patNum + " ";          //aka invoice#
                info.Arguments += "\"/CLERK:" + Security.CurUser.UserName + " R\" /LOCKCLERK ";
                info.Arguments += "/RESULTFILE:\"" + resultfile + "\" ";
                info.Arguments += "/USERID:" + user + " ";
                info.Arguments += "/PASSWORD:"******" ";
                info.Arguments += "/HIDEMAINWINDOW ";
                info.Arguments += "/AUTOPROCESS ";
                info.Arguments += "/SMALLWINDOW ";
                info.Arguments += "/AUTOCLOSE ";
                info.Arguments += "/NORESULTDIALOG ";
                Cursor          = Cursors.WaitCursor;
                Process process = new Process();
                process.StartInfo           = info;
                process.EnableRaisingEvents = true;
                process.Start();
                while (!process.HasExited)
                {
                    Application.DoEvents();
                }
                Thread.Sleep(200);                //Wait 2/10 second to give time for file to be created.
                Cursor = Cursors.Default;
                string line       = "";
                string resultText = "";
                recurringResultFile += "PatNum: " + patNum + " Name: " + table.Rows[i]["PatName"].ToString() + "\r\n";
                using (TextReader reader = new StreamReader(resultfile)) {
                    line = reader.ReadLine();
                    while (line != null)
                    {
                        if (resultText != "")
                        {
                            resultText += "\r\n";
                        }
                        resultText += line;
                        if (line.StartsWith("RESULT="))
                        {
                            if (line == "RESULT=SUCCESS")
                            {
                                success++;
                                labelCharged.Text = Lan.g(this, "Charged=") + success;
                                insertPayment     = true;
                            }
                            else
                            {
                                failed++;
                                labelFailed.Text = Lan.g(this, "Failed=") + failed;
                            }
                        }
                        line = reader.ReadLine();
                    }
                    recurringResultFile += resultText + "\r\n\r\n";
                }
                #endregion
                if (insertPayment)
                {
                    Patient patCur     = Patients.GetPat(patNum);
                    Payment paymentCur = new Payment();
                    paymentCur.DateEntry = nowDateTime.Date;
                    paymentCur.PayDate   = GetPayDate(PIn.Date(table.Rows[gridMain.SelectedIndices[i]]["LatestPayment"].ToString()),
                                                      PIn.Date(table.Rows[gridMain.SelectedIndices[i]]["DateStart"].ToString()));
                    paymentCur.PatNum        = patCur.PatNum;
                    paymentCur.ClinicNum     = PIn.Long(table.Rows[gridMain.SelectedIndices[i]]["ClinicNum"].ToString());
                    paymentCur.PayType       = PIn.Int(ProgramProperties.GetPropVal(prog.ProgramNum, "PaymentType"));
                    paymentCur.PayAmt        = amt;
                    paymentCur.PayNote       = resultText;
                    paymentCur.IsRecurringCC = true;
                    Payments.Insert(paymentCur);
                    long provNum = PIn.Long(table.Rows[gridMain.SelectedIndices[i]]["ProvNum"].ToString()); //for payment plans only
                    if (provNum == 0)                                                                       //Regular payments need to apply to the provider that the family owes the most money to.
                    {
                        DataTable dt         = Patients.GetPaymentStartingBalances(patCur.Guarantor, paymentCur.PayNum);
                        double    highestAmt = 0;
                        for (int j = 0; j < dt.Rows.Count; j++)
                        {
                            double afterIns = PIn.Double(dt.Rows[j]["AfterIns"].ToString());
                            if (highestAmt >= afterIns)
                            {
                                continue;
                            }
                            highestAmt = afterIns;
                            provNum    = PIn.Long(dt.Rows[j]["ProvNum"].ToString());
                        }
                    }
                    PaySplit split = new PaySplit();
                    split.PatNum     = paymentCur.PatNum;
                    split.ClinicNum  = paymentCur.ClinicNum;
                    split.PayNum     = paymentCur.PayNum;
                    split.ProcDate   = paymentCur.PayDate;
                    split.DatePay    = paymentCur.PayDate;
                    split.ProvNum    = provNum;
                    split.SplitAmt   = paymentCur.PayAmt;
                    split.PayPlanNum = PIn.Long(table.Rows[gridMain.SelectedIndices[i]]["PayPlanNum"].ToString());
                    PaySplits.Insert(split);
                    if (PrefC.GetBool(PrefName.AgingCalculatedMonthlyInsteadOfDaily))
                    {
                        Ledgers.ComputeAging(patCur.Guarantor, PrefC.GetDate(PrefName.DateLastAging), false);
                    }
                    else
                    {
                        Ledgers.ComputeAging(patCur.Guarantor, DateTimeOD.Today, false);
                        if (PrefC.GetDate(PrefName.DateLastAging) != DateTime.Today)
                        {
                            Prefs.UpdateString(PrefName.DateLastAging, POut.Date(DateTime.Today, false));
                            //Since this is always called from UI, the above line works fine to keep the prefs cache current.
                        }
                    }
                }
            }
            #endregion
            try {
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(xPath), "RecurringChargeResult.txt"), recurringResultFile);
            }
            catch { }             //Do nothing cause this is just for internal use.
            FillGrid();
            labelCharged.Text = Lan.g(this, "Charged=") + success;
            labelFailed.Text  = Lan.g(this, "Failed=") + failed;
            MsgBox.Show(this, "Done charging cards.\r\nIf there are any patients remaining in list, print the list and handle each one manually.");
        }
예제 #2
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
            if (textDate.errorProvider1.GetError(textDate) != "")
            {
                MsgBox.Show(this, "Please fix data entry errors first.");
                return;
            }
            if (IsNew)
            {
                if (!SaveToDB())
                {
                    return;
                }
            }
            else             //not new
                             //Only allowed to change date and bank account info, NOT attached checks.
                             //We enforce security here based on date displayed, not date entered.
                             //If user is trying to change date without permission:
            {
                DateTime date = PIn.PDate(textDate.Text);
                if (Security.IsAuthorized(Permissions.DepositSlips, date, true))
                {
                    if (!SaveToDB())
                    {
                        return;
                    }
                }
                //if security.NotAuthorized, then it simply skips the save process before printing
            }
            //refresh the lists because some items may not be highlighted
            PatPayList     = Payments.GetForDeposit(DepositCur.DepositNum);
            ClaimPayList   = ClaimPayments.GetForDeposit(DepositCur.DepositNum);
            Queries.TableQ = new DataTable();
            for (int i = 0; i < 5; i++)                                   //add 5 columns
            {
                Queries.TableQ.Columns.Add(new System.Data.DataColumn()); //blank columns
            }
            Queries.CurReport          = new ReportOld();
            Queries.CurReport.ColTotal = new double[Queries.TableQ.Columns.Count];
            DataRow   row;
            ArrayList patNumAL = new ArrayList();

            for (int i = 0; i < PatPayList.Length; i++)
            {
                patNumAL.Add(PatPayList[i].PatNum);
            }
            int[] patNums = new int[patNumAL.Count];
            patNumAL.CopyTo(patNums);
            Patient[] pats = Patients.GetMultPats(patNums);
            for (int i = 0; i < PatPayList.Length; i++)
            {
                row    = Queries.TableQ.NewRow();
                row[0] = PatPayList[i].PayDate.ToShortDateString();
                row[1] = Patients.GetOnePat(pats, PatPayList[i].PatNum).GetNameLF();
                row[2] = PatPayList[i].CheckNum;
                row[3] = PatPayList[i].BankBranch;
                row[4] = PatPayList[i].PayAmt.ToString("F");
                Queries.TableQ.Rows.Add(row);
                Queries.CurReport.ColTotal[4] += PatPayList[i].PayAmt;
            }
            for (int i = 0; i < ClaimPayList.Length; i++)
            {
                row    = Queries.TableQ.NewRow();
                row[0] = ClaimPayList[i].CheckDate.ToShortDateString();
                row[1] = ClaimPayList[i].CarrierName;
                row[2] = ClaimPayList[i].CheckNum;
                row[3] = ClaimPayList[i].BankBranch;
                row[4] = ClaimPayList[i].CheckAmt.ToString("F");
                Queries.TableQ.Rows.Add(row);
                Queries.CurReport.ColTotal[4] += ClaimPayList[i].CheckAmt;
            }
            //done filling now set up table
            Queries.CurReport.ColWidth   = new int[Queries.TableQ.Columns.Count];
            Queries.CurReport.ColPos     = new int[Queries.TableQ.Columns.Count + 1];
            Queries.CurReport.ColPos[0]  = 0;
            Queries.CurReport.ColCaption = new string[Queries.TableQ.Columns.Count];
            Queries.CurReport.ColAlign   = new HorizontalAlignment[Queries.TableQ.Columns.Count];
            FormQuery FormQuery2 = new FormQuery();

            FormQuery2.IsReport = true;
            FormQuery2.ResetGrid();            //necessary won't work without
            Queries.CurReport.Title         = "Deposit Slip";
            Queries.CurReport.SubTitle      = new string[2];
            Queries.CurReport.SubTitle[0]   = ((Pref)PrefB.HList["PracticeTitle"]).ValueString;
            Queries.CurReport.SubTitle[1]   = DepositCur.DateDeposit.ToShortDateString();
            Queries.CurReport.Summary       = new string[1];
            Queries.CurReport.Summary[0]    = DepositCur.BankAccountInfo;
            Queries.CurReport.ColPos[0]     = 20;
            Queries.CurReport.ColPos[1]     = 110;
            Queries.CurReport.ColPos[2]     = 260;
            Queries.CurReport.ColPos[3]     = 350;
            Queries.CurReport.ColPos[4]     = 440;
            Queries.CurReport.ColPos[5]     = 530;
            Queries.CurReport.ColCaption[0] = "Date";
            Queries.CurReport.ColCaption[1] = "Name";
            Queries.CurReport.ColCaption[2] = "Check Number";
            Queries.CurReport.ColCaption[3] = "Bank-Branch";
            Queries.CurReport.ColCaption[4] = "Amount";
            Queries.CurReport.ColAlign[4]   = HorizontalAlignment.Right;
            FormQuery2.ShowDialog();
            DialogResult = DialogResult.OK;          //this is imporant, since we don't want to insert the deposit slip twice.
        }
예제 #3
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);
        }
예제 #4
0
        ///<summary></summary>
        private void FillGrids()
        {
            if (IsNew)
            {
                DateTime dateStart = PIn.PDate(textDateStart.Text);
                int      clinicNum = 0;
                if (comboClinic.SelectedIndex != 0)
                {
                    clinicNum = Clinics.List[comboClinic.SelectedIndex - 1].ClinicNum;
                }
                int[] payTypes = new int[listPayType.SelectedIndices.Count];
                for (int i = 0; i < payTypes.Length; i++)
                {
                    payTypes[i] = DefB.Short[(int)DefCat.PaymentTypes][listPayType.SelectedIndices[i]].DefNum;
                }
                PatPayList   = Payments.GetForDeposit(dateStart, clinicNum, payTypes);
                ClaimPayList = ClaimPayments.GetForDeposit(dateStart, clinicNum);
            }
            else
            {
                PatPayList   = Payments.GetForDeposit(DepositCur.DepositNum);
                ClaimPayList = ClaimPayments.GetForDeposit(DepositCur.DepositNum);
            }
            //Fill Patient Payment Grid---------------------------------------
            ArrayList patNumAL = new ArrayList();

            for (int i = 0; i < PatPayList.Length; i++)
            {
                patNumAL.Add(PatPayList[i].PatNum);
            }
            int[] patNums = new int[patNumAL.Count];
            patNumAL.CopyTo(patNums);
            Patient[] pats = Patients.GetMultPats(patNums);
            gridPat.BeginUpdate();
            gridPat.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Date"), 80);

            gridPat.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Patient"), 130);
            gridPat.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Type"), 90);
            gridPat.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Check Number"), 95);
            gridPat.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Bank-Branch"), 80);
            gridPat.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipPat", "Amount"), 80);
            gridPat.Columns.Add(col);
            gridPat.Rows.Clear();
            OpenDental.UI.ODGridRow row;
            for (int i = 0; i < PatPayList.Length; i++)
            {
                row = new OpenDental.UI.ODGridRow();
                row.Cells.Add(PatPayList[i].PayDate.ToShortDateString());
                row.Cells.Add(Patients.GetOnePat(pats, PatPayList[i].PatNum).GetNameLF());
                row.Cells.Add(DefB.GetName(DefCat.PaymentTypes, PatPayList[i].PayType));
                row.Cells.Add(PatPayList[i].CheckNum);
                row.Cells.Add(PatPayList[i].BankBranch);
                row.Cells.Add(PatPayList[i].PayAmt.ToString("F"));
                gridPat.Rows.Add(row);
            }
            gridPat.EndUpdate();
            //Fill Insurance Payment Grid-------------------------------------
            gridIns.BeginUpdate();
            gridIns.Columns.Clear();
            col = new ODGridColumn(Lan.g("TableDepositSlipIns", "Date"), 80);
            gridIns.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipIns", "Carrier"), 220);
            gridIns.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipIns", "Check Number"), 95);
            gridIns.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipIns", "Bank-Branch"), 80);
            gridIns.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableDepositSlipIns", "Amount"), 90);
            gridIns.Columns.Add(col);
            gridIns.Rows.Clear();
            for (int i = 0; i < ClaimPayList.Length; i++)
            {
                row = new OpenDental.UI.ODGridRow();
                row.Cells.Add(ClaimPayList[i].CheckDate.ToShortDateString());
                row.Cells.Add(ClaimPayList[i].CarrierName);
                row.Cells.Add(ClaimPayList[i].CheckNum);
                row.Cells.Add(ClaimPayList[i].BankBranch);
                row.Cells.Add(ClaimPayList[i].CheckAmt.ToString("F"));
                gridIns.Rows.Add(row);
            }
            gridIns.EndUpdate();
        }