Beispiel #1
0
        private void FormRecurringCharges_Load(object sender, EventArgs e)
        {
            if (Programs.HasMultipleCreditCardProgramsEnabled())
            {
                gridMain.HScrollVisible = true;
            }
            if (!PrefC.IsODHQ)
            {
                checkHideBold.Checked = true;
                checkHideBold.Visible = false;
            }
            Program progCur = null;

            if (Programs.IsEnabled(ProgramName.PaySimple))
            {
                progCur = Programs.GetCur(ProgramName.PaySimple);
                labelUpdated.Visible         = false;
                checkForceDuplicates.Checked = false;
                checkForceDuplicates.Visible = false;              //PaySimple always rejects identical transactions made within 5 minutes of eachother.
            }
            if (Programs.IsEnabled(ProgramName.PayConnect))
            {
                progCur = Programs.GetCur(ProgramName.PayConnect);
                labelUpdated.Visible         = false;
                checkForceDuplicates.Visible = true;
                checkForceDuplicates.Checked = PIn.Bool(ProgramProperties.GetPropValForClinicOrDefault(progCur.ProgramNum,
                                                                                                       PayConnect.ProgramProperties.PayConnectForceRecurringCharge, Clinics.ClinicNum));
            }
            if (Programs.IsEnabled(ProgramName.Xcharge))
            {
                progCur = Programs.GetCur(ProgramName.Xcharge);
                labelUpdated.Visible         = true;
                checkForceDuplicates.Visible = true;
                string xPath = Programs.GetProgramPath(progCur);
                checkForceDuplicates.Checked = PIn.Bool(ProgramProperties.GetPropValForClinicOrDefault(progCur.ProgramNum,
                                                                                                       ProgramProperties.PropertyDescs.XCharge.XChargeForceRecurringCharge, Clinics.ClinicNum));
                if (!File.Exists(xPath))                 //program path is invalid
                //if user has setup permission and they want to edit the program path, show the X-Charge setup window
                {
                    if (Security.IsAuthorized(Permissions.Setup) &&
                        MsgBox.Show(this, MsgBoxButtons.YesNo, "The X-Charge path is not valid.  Would you like to edit the path?"))
                    {
                        FormXchargeSetup FormX = new FormXchargeSetup();
                        FormX.ShowDialog();
                        if (FormX.DialogResult == DialogResult.OK)
                        {
                            //The user could have correctly enabled the X-Charge bridge, we need to update our local _programCur and _xPath variable2
                            progCur = Programs.GetCur(ProgramName.Xcharge);
                            xPath   = Programs.GetProgramPath(progCur);
                        }
                    }
                    //if the program path still does not exist, whether or not they attempted to edit the program link, tell them to edit and close the form
                    if (!File.Exists(xPath))
                    {
                        MsgBox.Show(this, "The X-Charge program path is not valid.  Edit the program link in order to use the CC Recurring Charges feature.");
                        Close();
                        return;
                    }
                }
            }
            if (progCur == null)
            {
                MsgBox.Show(this, "The PayConnect, PaySimple, or X-Charge program link must be enabled in order to use the CC Recurring Charges feature.");
                Close();
                return;
            }
            _isSelecting     = true;
            _listUserClinics = new List <Clinic>();
            if (PrefC.HasClinicsEnabled)
            {
                if (!Security.CurUser.ClinicIsRestricted)
                {
                    _listUserClinics.Add(new Clinic()
                    {
                        Description = Lan.g(this, "Unassigned")
                    });
                }
                Clinics.GetForUserod(Security.CurUser).ForEach(x => _listUserClinics.Add(x));
                for (int i = 0; i < _listUserClinics.Count; i++)
                {
                    listClinics.Items.Add(_listUserClinics[i].Description);
                    listClinics.SetSelected(i, true);
                }
                //checkAllClin.Checked=true;//checked true by default in designer so we don't trigger the event to select all and fill grid
            }
            else
            {
                groupClinics.Visible = false;
            }
            _charger = new RecurringChargerator(new ShowErrors(this), true);
            _charger.SingleCardFinished = new Action(() => {
                this.Invoke(() => {
                    labelCharged.Text = Lans.g(this, "Charged=") + _charger.Success;
                    labelFailed.Text  = Lans.g(this, "Failed=") + _charger.Failed;
                    labelUpdated.Text = Lans.g(this, "Updated=") + _charger.Updated;
                });
            });
            GeneralProgramEvent.Fired += StopRecurringCharges;          //This is so we'll be alerted in case of a shutdown.
            labelCharged.Text          = Lan.g(this, "Charged=") + "0";
            labelFailed.Text           = Lan.g(this, "Failed=") + "0";
            FillGrid(true);
            gridMain.SetSelected(true);
            labelSelected.Text = Lan.g(this, "Selected=") + gridMain.SelectedIndices.Length.ToString();
        }
Beispiel #2
0
        ///<summary>The DataTable used to fill the grid will only be refreshed from the db if isFromDb is true.  Otherwise the grid will be refilled using
        ///the existing table.  Only get from the db on load or if the Refresh button is pressed, not when the user is selecting the clinic(s).</summary>
        private void FillGrid(bool isFromDb = false)
        {
            Cursor = Cursors.WaitCursor;
            if (isFromDb)
            {
                _charger.FillCharges(_listUserClinics);
            }
            List <long> listSelectedClinicNums = listClinics.SelectedIndices.OfType <int>().Select(x => _listUserClinics[x].ClinicNum).ToList();
            List <RecurringChargeData> listChargesCur;

            if (PrefC.HasClinicsEnabled)
            {
                listChargesCur = _charger.ListRecurringChargeData.Where(x => listSelectedClinicNums.Contains(x.RecurringCharge.ClinicNum)).ToList();
            }
            else
            {
                listChargesCur = _charger.ListRecurringChargeData;
            }
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "PatNum"), 55));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Name"), PrefC.HasClinicsEnabled?190:220));
            if (PrefC.HasClinicsEnabled)
            {
                gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Clinic"), 65));
            }
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Date"), PrefC.HasClinicsEnabled?80:80, HorizontalAlignment.Right));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Family Bal"), PrefC.HasClinicsEnabled?70:85, HorizontalAlignment.Right));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "PayPlan Due"), PrefC.HasClinicsEnabled?75:85, HorizontalAlignment.Right));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Total Due"), PrefC.HasClinicsEnabled?65:80, HorizontalAlignment.Right));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Repeat Amt"), PrefC.HasClinicsEnabled?75:90, HorizontalAlignment.Right));         //RptChrgAmt
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g("TableRecurring", "Charge Amt"), PrefC.HasClinicsEnabled?85:100, HorizontalAlignment.Right));
            if (Programs.HasMultipleCreditCardProgramsEnabled())
            {
                if (Programs.IsEnabled(ProgramName.Xcharge))
                {
                    gridMain.ListGridColumns.Add(new GridColumn("X-Charge", PrefC.HasClinicsEnabled ? 70 : 80, HorizontalAlignment.Center));
                }
                if (Programs.IsEnabled(ProgramName.PayConnect))
                {
                    gridMain.ListGridColumns.Add(new GridColumn("PayConnect", PrefC.HasClinicsEnabled ? 85 : 95, HorizontalAlignment.Center));
                }
                if (Programs.IsEnabled(ProgramName.PaySimple))
                {
                    gridMain.ListGridColumns.Add(new GridColumn("PaySimple", PrefC.HasClinicsEnabled ? 80 : 90, HorizontalAlignment.Center));
                }
            }
            gridMain.ListGridRows.Clear();
            GridRow row;

            foreach (RecurringChargeData chargeCur in listChargesCur)
            {
                row = new GridRow();
                double famBalTotal  = chargeCur.RecurringCharge.FamBal;             //pat bal+payplan due, but if pat bal<0 and payplan due>0 then just payplan due
                double payPlanDue   = chargeCur.RecurringCharge.PayPlanDue;
                double chargeAmt    = chargeCur.RecurringCharge.ChargeAmt;
                double rptChargeAmt = chargeCur.RecurringCharge.RepeatAmt;              //includes repeat charge (from procs if ODHQ) and attached payplan
                row.Cells.Add(chargeCur.RecurringCharge.PatNum.ToString());
                row.Cells.Add(chargeCur.PatName);
                if (PrefC.HasClinicsEnabled)
                {
                    Clinic clinicCur = _listUserClinics.FirstOrDefault(x => x.ClinicNum == chargeCur.RecurringCharge.ClinicNum);
                    row.Cells.Add(clinicCur != null?clinicCur.Description:"");                  //get description from cache if clinics are enabled
                }
                int billingDay = 0;
                if (PrefC.GetBool(PrefName.BillingUseBillingCycleDay))
                {
                    billingDay = chargeCur.BillingCycleDay;
                }
                else
                {
                    billingDay = chargeCur.RecurringChargeDate.Day;
                }
                DateTime startBillingCycle = DateTimeOD.GetMostRecentValidDate(DateTime.Today.Year, DateTime.Today.Month, billingDay);
                if (startBillingCycle > DateTime.Today)
                {
                    startBillingCycle = startBillingCycle.AddMonths(-1);             //Won't give a date with incorrect day.  AddMonths will give the end of the month if needed.
                }
                DateTime dateExcludeIfBefore = PIn.Date(textDate.Text);              //If entry is invalid, all charges will be included because this will be MinDate.
                if (startBillingCycle < dateExcludeIfBefore)
                {
                    continue;                    //Don't show row in grid
                }
                row.Cells.Add(startBillingCycle.ToShortDateString());
                row.Cells.Add(famBalTotal.ToString("c"));
                if (!payPlanDue.IsZero())
                {
                    row.Cells.Add(payPlanDue.ToString("c"));
                }
                else
                {
                    row.Cells.Add("");
                }
                row.Cells.Add(chargeCur.RecurringCharge.TotalDue.ToString("c"));
                row.Cells.Add(rptChargeAmt.ToString("c"));
                row.Cells.Add(chargeAmt.ToString("c"));
                if (!checkHideBold.Checked)
                {
                    double diff = (Math.Max(famBalTotal, 0) + Math.Max(payPlanDue, 0)) - rptChargeAmt;
                    if (diff.IsZero() || (diff < 0 && RecurringCharges.CanChargeWhenNoBal(chargeCur.CanChargeWhenNoBal)))
                    {
                        //don't bold anything
                    }
                    else if (diff > 0)
                    {
                        row.Cells[6].Bold = YN.Yes;                      //"Repeating Amt"
                        row.Cells[7].Bold = YN.Yes;                      //"Charge Amt"
                    }
                    else if (diff < 0)
                    {
                        row.Cells[5].Bold = YN.Yes;                      //"Total Due"
                        row.Cells[7].Bold = YN.Yes;                      //"Charge Amt"
                    }
                }
                if (Programs.HasMultipleCreditCardProgramsEnabled())
                {
                    if (Programs.IsEnabled(ProgramName.Xcharge))
                    {
                        row.Cells.Add(!string.IsNullOrEmpty(chargeCur.XChargeToken) ? "X" : "");
                    }
                    if (Programs.IsEnabled(ProgramName.PayConnect))
                    {
                        row.Cells.Add(!string.IsNullOrEmpty(chargeCur.PayConnectToken) ? "X" : "");
                    }
                    if (Programs.IsEnabled(ProgramName.PaySimple))
                    {
                        row.Cells.Add(!string.IsNullOrEmpty(chargeCur.PaySimpleToken) ? "X" : "");
                    }
                }
                row.Tag = chargeCur;
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
            labelTotal.Text    = Lan.g(this, "Total=") + gridMain.ListGridRows.Count.ToString();
            labelSelected.Text = Lan.g(this, "Selected=") + gridMain.SelectedIndices.Length.ToString();
            Cursor             = Cursors.Default;
        }