private void CreatePayPlanEntries(bool showImplicitlyPaidOffProcs = false)
 {
     _listAccountCharges = AccountEntry.GetAccountCharges(_listPayPlanCharges, _listAdjustments, _listProcs);
     if (showImplicitlyPaidOffProcs)
     {
         _accountCredits = 0;
     }
     else
     {
         _accountCredits = PayPlanEdit.GetAccountCredits(_listAdjustments, _listPaySplits, _listPayments, _listInsPayAsTotal, _listPayPlanCharges);
     }
     LinkChargesToCredits();
     _listPayPlanEntries = new List <PayPlanEdit.PayPlanEntry>();
     _listPayPlanEntries.AddRange(PayPlanEdit.CreatePayPlanEntriesForAccountCharges(_listAccountCharges, _patCur));
     ListPayPlanCreditsCur = ListPayPlanCreditsCur.OrderBy(x => x.ChargeDate).ToList();
     _listPayPlanEntries.AddRange(PayPlanEdit.CreatePayPlanEntriesForPayPlanCredits(_listAccountCharges, ListPayPlanCreditsCur));
     if (ListPayPlanCreditsCur.Exists(x => x.ProcNum == 0))           //only add "Unattached" if there is a credit without a procedure.
     {
         _listPayPlanEntries.Add(PayPlanEdit.CreatePayPlanEntryForUnattachedProcs(ListPayPlanCreditsCur, _patCur.FName));
     }
     _listPayPlanEntries = _listPayPlanEntries
                           .OrderByDescending(x => x.ProcStatOrd)
                           .ThenByDescending(x => x.ProcNumOrd)
                           .ThenBy(x => x.IsChargeOrd)
                           .ThenBy(x => x.DateOrd).ToList();
 }
 ///<summary>Links charges to credits explicitly based on FKs first, then implicitly based on Date.</summary>
 private void LinkChargesToCredits()
 {
     PayPlanEdit.PayPlanLinked linkData = PayPlanEdit.LinkChargesToCredits(_listAccountCharges, _listPaySplits, _listAdjustments, _listPayPlanCharges
                                                                           , _listClaimProcs, _payPlanCur.PayPlanNum, _accountCredits);
     _listAccountCharges = linkData.ListAccountCharges;
     _accountCredits     = linkData.AccountCredits;
 }
Example #3
0
        public void LedgersTests_ComputeAging_PayPlanDynamicCreditsWithClaimProcs()
        {
            List <Procedure>  listProcs = new List <Procedure>();
            List <Adjustment> listAdjs  = new List <Adjustment>();
            long          provNum       = ProviderT.CreateProvider("Aging_PayPlanDynamic");
            string        suffix        = MethodBase.GetCurrentMethod().Name;
            Patient       pat           = PatientT.CreatePatient(fName: "Aging_PayPlanDynamic", suffix: suffix);
            Family        fam           = Patients.GetFamily(pat.PatNum);
            Procedure     proc45        = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 45, DateTime.Today.AddDays(-61), provNum: provNum);
            ClaimProc     cp45          = new ClaimProc();
            InsuranceInfo insInfo       = InsuranceT.AddInsurance(pat, "DynPayPlan");

            ClaimProcs.CreateEst(cp45, proc45, insInfo.PriInsPlan, insInfo.PriInsSub);
            cp45.Status      = ClaimProcStatus.NotReceived;
            cp45.InsEstTotal = -1;
            cp45.InsPayEst   = 15;
            cp45.WriteOffEst = 0;
            cp45.WriteOff    = 0;
            ClaimProcs.Update(cp45);
            listProcs.AddRange(new List <Procedure> {
                proc45
            });
            PayPlan payPlan = PayPlanT.CreateDynamicPaymentPlan(pat.PatNum, pat.PatNum, DateTime.Today.AddDays(-1), 0, 0, 30, listProcs, listAdjs);
            //make two non payplan productions to put on the account
            Procedure procUnattached = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 35, DateTime.Today.AddDays(-91), provNum: provNum);
            //Run pay plan logic to generate first set of charges
            List <PayPlanCharge> listChargesDb = PayPlanCharges.GetForPayPlan(payPlan.PayPlanNum);
            List <PayPlanLink>   listEntries   = PayPlanLinks.GetForPayPlans(new List <long> {
                payPlan.PayPlanNum
            });
            PayPlanTerms         terms = PayPlanT.GetTerms(payPlan, listEntries);
            List <PayPlanCharge> listChargesThisPeriod = PayPlanEdit.GetListExpectedCharges(listChargesDb, terms, fam, listEntries, payPlan, true);

            Assert.AreEqual(30, listChargesThisPeriod.Sum(x => x.Principal));
            foreach (PayPlanCharge charge in listChargesThisPeriod)
            {
                PayPlanCharges.Insert(charge);
            }
            int payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 30, 0, 15, 35, 30, YN.Yes);        //new - pay plan credit of $30 gets applied to cooresponding procedure
                CheckAgingProcLifo(pat.PatNum, 30, 0, 45, 5, 30, YN.No);          //old - pay plan credit gets applied to oldest production on the account
                CheckAgingProcLifo(pat.PatNum, 30, 0, 45, 5, 30, YN.Unknown);
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
Example #4
0
        public void LedgersTests_ComputeAging_PayPlanDynamic()
        {
            List <Procedure>  listProcs = new List <Procedure>();
            List <Adjustment> listAdjs  = new List <Adjustment>();
            long       provNum          = ProviderT.CreateProvider("Aging_PayPlanDynamic");
            string     suffix           = MethodBase.GetCurrentMethod().Name;
            Patient    pat      = PatientT.CreatePatient(fName: "Aging_PayPlanDynamic", suffix: suffix);
            Family     fam      = Patients.GetFamily(pat.PatNum);
            Procedure  proc1    = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 45, DateTime.Today.AddDays(-61), provNum: provNum);
            Procedure  proc2    = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 55, DateTime.Today.AddDays(-32), provNum: provNum);
            Procedure  proc3    = ProcedureT.CreateProcedure(pat, "D0270", ProcStat.C, "", 65, DateTime.Today.AddDays(-15), provNum: provNum);
            Adjustment adjProc2 = AdjustmentT.MakeAdjustment(pat.PatNum, 10, proc2.ProcDate, proc2.ProcDate, proc2.ProcNum, provNum);
            Adjustment adjProc3 = AdjustmentT.MakeAdjustment(pat.PatNum, 20, proc3.ProcDate, proc3.ProcDate, proc3.ProcNum, provNum);
            Adjustment adj      = AdjustmentT.MakeAdjustment(pat.PatNum, 30, DateTime.Today.AddDays(-5), provNum: provNum);

            listProcs.AddRange(new List <Procedure> {
                proc1, proc2, proc3
            });
            listAdjs.AddRange(new List <Adjustment> {
                adj
            });
            PayPlan payPlan = PayPlanT.CreateDynamicPaymentPlan(pat.PatNum, pat.PatNum, DateTime.Today.AddDays(-1), 0, 0, 40, listProcs, listAdjs);
            //PayPlan payplan=PayPlanT.CreatePayPlanWithCredits(pat.PatNum,40,DateTime.Today,provNum:provNum,listProcs,195,pat.PatNum);
            //make two non payplan productions to put on the account
            Procedure procUnattached = ProcedureT.CreateProcedure(pat, "D0210", ProcStat.C, "", 35, DateTime.Today.AddDays(-91), provNum: provNum);
            //Run pay plan logic to generate first set of charges
            List <PayPlanCharge> listChargesDb = PayPlanCharges.GetForPayPlan(payPlan.PayPlanNum);
            List <PayPlanLink>   listEntries   = PayPlanLinks.GetForPayPlans(new List <long> {
                payPlan.PayPlanNum
            });
            PayPlanTerms         terms = PayPlanT.GetTerms(payPlan, listEntries);
            List <PayPlanCharge> listChargesThisPeriod = PayPlanEdit.GetListExpectedCharges(listChargesDb, terms, fam, listEntries, payPlan, true);

            Assert.AreEqual(40, listChargesThisPeriod.Sum(x => x.Principal));
            foreach (PayPlanCharge charge in listChargesThisPeriod)
            {
                PayPlanCharges.Insert(charge);
            }
            int payPlansVersionPrev = PrefC.GetInt(PrefName.PayPlansVersion);

            try {
                PrefT.UpdateInt(PrefName.PayPlansVersion, (int)PayPlanVersions.AgeCreditsAndDebits);
                CheckAgingProcLifo(pat.PatNum, 70, 0, 0, 5, 40, YN.Yes);         //new
                CheckAgingProcLifo(pat.PatNum, 75, 0, 0, 0, 40, YN.No);          //old
                CheckAgingProcLifo(pat.PatNum, 75, 0, 0, 0, 40, YN.Unknown);
            }
            finally {
                PrefT.UpdateInt(PrefName.PayPlansVersion, payPlansVersionPrev);
            }
        }
 private void FormPayPlanCredits_Load(object sender, EventArgs e)
 {
     PayPlanEdit.PayPlanCreditLoadData loadData = PayPlanEdit.GetLoadDataForPayPlanCredits(_patCur.PatNum, _payPlanCur.PayPlanNum);
     _listAdjustments          = loadData.ListAdjustments;
     _listProcs                = loadData.ListProcs;
     _listPayPlanLinksForProcs = loadData.ListPayPlanLinksForProcs;
     _listPayPlanCharges       = loadData.ListPayPlanCharges;
     _listPaySplits            = loadData.ListTempPaySplit;
     _listPayments             = loadData.ListPayments;
     _listInsPayAsTotal        = loadData.ListInsPayAsTotal;
     _listClaimProcs           = loadData.ListClaimProcs;
     textCode.Text             = Lan.g(this, "None");
     FillGrid();
     if (!Security.IsAuthorized(Permissions.PayPlanEdit, true))
     {
         this.DisableForm(butCancel, checkHideUnattached, checkShowImplicit, butPrint, gridMain);
     }
 }
Example #6
0
        ///<summary></summary>
        public static List <PayPlanCharge> GetForDownPayment(PayPlanTerms terms, Family family, List <PayPlanLink> listPayPlanLinks, PayPlan payplan)
        {
            //No remoting role check; no call to db
            //Create a temporary variable to keep track of the original PeriodPayment.
            decimal periodPaymentTemp = terms.PeriodPayment;
            double  aprTemp           = terms.APR;

            //Set the PeriodPayment to the current DownPayment so that the full amount of the down payment gets generated.
            //E.g. there are several procedures attached to the payment plan and the down payment only covers one and a half (partial proc).
            terms.PeriodPayment = (decimal)terms.DownPayment;
            terms.APR           = 0;//downpayments should pay on principal only
            List <PayPlanCharge> listDownPayments = PayPlanEdit.GetListExpectedCharges(new List <PayPlanCharge>(), terms, family, listPayPlanLinks, payplan, true
                                                                                       , true, new List <PaySplit>());

            listDownPayments.ForEach(x => {
                x.Note       = "Down Payment";
                x.ChargeDate = DateTime.Today.Date;
                x.Interest   = 0;
            });
            //Put the PeriodPayment back to the way it was upon entry.
            terms.PeriodPayment = periodPaymentTemp;
            terms.APR           = aprTemp;
            return(listDownPayments);
        }
        private void butAddOrUpdate_Click(object sender, EventArgs e)
        {
            List <PayPlanEdit.PayPlanEntry> listSelectedEntries = new List <PayPlanEdit.PayPlanEntry>();

            for (int i = 0; i < gridMain.SelectedIndices.Count(); i++)          //add all of the currently selected entries to this list.
            {
                listSelectedEntries.Add((PayPlanEdit.PayPlanEntry)(gridMain.ListGridRows[gridMain.SelectedIndices[i]].Tag));
            }
            if (listSelectedEntries.Count <= 1)            //validation (doesn't matter if multiple are selected)
            {
                if (string.IsNullOrEmpty(textAmt.Text) || textAmt.errorProvider1.GetError(textAmt) != "" || PIn.Double(textAmt.Text) == 0)
                {
                    MsgBox.Show(this, "Please enter a valid amount.");
                    return;
                }
                if (textDate.Text != "" && textDate.errorProvider1.GetError(textDate) != "")
                {
                    MsgBox.Show(this, "Please enter a valid date.");
                    return;
                }
            }
            if (textDate.Text == "")
            {
                textDate.Text = DateTime.Today.ToShortDateString();
            }
            if (Security.IsGlobalDateLock(Permissions.PayPlanEdit, PIn.Date(textDate.Text)))
            {
                return;
            }
            if (listSelectedEntries.Count == 0)
            {
                if (PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAccounting.EnforceFully)                //if they have none selected
                {
                    MsgBox.Show(this, "All treatment credits (excluding adjustments) must have a procedure.");
                    return;
                }
                //add an unattached charge only if not on enforce fully
                PayPlanCharge addCharge = PayPlanEdit.CreateUnattachedCredit(textDate.Text, _patCur.PatNum, textNote.Text, _payPlanCur.PayPlanNum,
                                                                             PIn.Double(textAmt.Text));
                ListPayPlanCreditsCur.Add(addCharge);
            }
            else if (listSelectedEntries.Count == 1)            //if they have one selected
            {
                PayPlanEdit.PayPlanEntry selectedEntry = listSelectedEntries[0];
                if (selectedEntry.Proc != null && _listPayPlanLinksForProcs.Select(x => x.FKey).Contains(selectedEntry.Proc.ProcNum))
                {
                    MsgBox.Show(this, "This procedure is already linked to a dynamic payment plan.");
                    return;
                }
                if (PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAccounting.EnforceFully)
                {
                    if ((selectedEntry.Proc == null || selectedEntry.Proc.ProcNum == 0) &&
                        !(selectedEntry.Charge != null && selectedEntry.Charge.IsCreditAdjustment))
                    {
                        MsgBox.Show(this, "All treatment credits (excluding adjustments) must have a procedure.");
                        return;
                    }
                }
                PayPlanCharge selectedCharge = new PayPlanCharge();
                if (selectedEntry.IsChargeOrd)
                {
                    //get the charge from the grid.
                    //DO NOT use PayPlanChargeNum. They are not pre-inserted so they will all be 0 if new.
                    selectedCharge = ((PayPlanEdit.PayPlanEntry)(gridMain.ListGridRows[gridMain.SelectedIndices[0]].Tag)).Charge;
                }
                ListPayPlanCreditsCur = PayPlanEdit.CreateOrUpdateChargeForSelectedEntry(selectedEntry, ListPayPlanCreditsCur, PIn.Double(textAmt.Text), textNote.Text, textDate.Text
                                                                                         , _patCur.PatNum, _payPlanCur.PayPlanNum, selectedCharge);
            }
            else if (listSelectedEntries.Count > 1)            //if they have more than one entry selected
            //remove everythig that doesn't have a procnum from the list
            {
                List <PayPlanEdit.PayPlanEntry> listSelectedProcs = listSelectedEntries.Where(x => !x.IsChargeOrd).Where(x => x.Proc != null).ToList();
                if (listSelectedEntries.Count == 0)                //if the list is then empty, there's nothing to do.
                {
                    MsgBox.Show(this, "You must have at least one procedure selected.");
                    return;
                }
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel,
                                 "Add a payment plan credit for each of the selected procedure's remaining amount?  Selected credits will be ignored."))
                {
                    return;
                }
                List <PayPlanEdit.PayPlanEntry> listValidSelectedProcs =
                    listSelectedProcs.FindAll(x => !_listPayPlanLinksForProcs.Select(y => y.FKey).Contains(x.Proc.ProcNum));
                int countProcsSkipped = listSelectedProcs.Count - listValidSelectedProcs.Count;
                ListPayPlanCreditsCur = PayPlanEdit.CreateCreditsForAllSelectedEntries(listValidSelectedProcs, _listPayPlanEntries, DateTimeOD.Today
                                                                                       , _patCur.PatNum, _payPlanCur.PayPlanNum, ListPayPlanCreditsCur);
                if (countProcsSkipped > 0)
                {
                    MsgBox.Show(this, "Credits were not made for " + countProcsSkipped + " procedure(s) because they are linked to one or more dynamic payment plans.");
                }
            }
            textAmt.Text  = "";
            textDate.Text = "";
            textNote.Text = "";
            FillGrid();
            SetTextBoxes();
        }