Пример #1
0
        ///<summary>Gets the current balance of the passed in payment plan num.
        ///Performs the same calculation as the "balance" column in the payment plans grid in ContrAccount.
        ///Optionally pass in the list of PayPlanCharges and list of PaySplits to avoid unneccesary database calls.
        ///Will filter out paysplits and charges associated to different payplans as well as payplan charges that are for the future or have a charge type of debit. </summary>
        public static double GetBalance(long payPlanNum, List <PayPlanCharge> listPayPlanCharges = null, List <PaySplit> listPaySplits = null)
        {
            //No need to check RemotingRole; no call to db.
            double amtBal = 0;

            if (listPayPlanCharges == null)
            {
                listPayPlanCharges = PayPlanCharges.GetForPayPlan(payPlanNum);
            }
            if (listPaySplits == null)
            {
                listPaySplits = PaySplits.GetFromBundled(PaySplits.GetForPayPlan(payPlanNum));
            }
            foreach (PayPlanCharge chargeCur in listPayPlanCharges)
            {
                if (chargeCur.PayPlanNum == payPlanNum &&
                    chargeCur.ChargeType == PayPlanChargeType.Debit)
                {
                    amtBal += chargeCur.Principal;
                    if (chargeCur.ChargeDate <= DateTime.Today)
                    {
                        amtBal += chargeCur.Interest;
                    }
                }
            }
            foreach (PaySplit splitCur in listPaySplits)
            {
                if (splitCur.PayPlanNum == payPlanNum)
                {
                    amtBal -= splitCur.SplitAmt;
                }
            }
            return(amtBal);
        }
Пример #2
0
        ///<summary>Inserts, updates, or deletes database rows to match supplied list.  Must always pass in payPlanNum.</summary>
        public static void Sync(List <PayPlanCharge> listPayPlanCharges, long payPlanNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), listPayPlanCharges, payPlanNum);
                return;
            }
            List <PayPlanCharge> listDB = PayPlanCharges.GetForPayPlan(payPlanNum);

            Crud.PayPlanChargeCrud.Sync(listPayPlanCharges, listDB);
        }
Пример #3
0
 ///<summary>Updates the TreatmentCompletedAmt field of the passed in payplans in the database.
 ///Used when a procedure attached to a payment plan charge is set complete or deleted.
 ///The treatment completed amount only takes into account payplancharge credits that have already occurred
 ///(no charges attached to TP'd procs).</summary>
 public static void UpdateTreatmentCompletedAmt(List <PayPlan> listPayPlans)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), listPayPlans);
         return;
     }
     foreach (PayPlan payPlanCur in listPayPlans)
     {
         double completedAmt = 0;
         List <PayPlanCharge> listCharges = PayPlanCharges.GetForPayPlan(payPlanCur.PayPlanNum);
         completedAmt = listCharges.Where(x => x.ChargeType == PayPlanChargeType.Credit)
                        .Where(x => x.ChargeDate.Date <= DateTime.Today.Date)
                        .Select(x => x.Principal)
                        .Sum();
         payPlanCur.CompletedAmt = completedAmt;
         Update(payPlanCur);
     }
 }
Пример #4
0
        ///<summary>Gets the total cost now of the passed in payment plan num.
        ///Optionally pass in the list of PayPlanCharges to avoid unneccesary database calls.
        ///Will filter out charges associated to different payplans as well as payplan charges that are for the future or have a charge type of debit. </summary>
        public static double GetTotalCost(long payPlanNum, List <PayPlanCharge> listPayPlanCharges = null)
        {
            //No need to check RemotingRole; no call to db.
            double amtTotal = 0;

            if (listPayPlanCharges == null)
            {
                listPayPlanCharges = PayPlanCharges.GetForPayPlan(payPlanNum);
            }
            foreach (PayPlanCharge chargeCur in listPayPlanCharges)
            {
                if (chargeCur.PayPlanNum == payPlanNum &&
                    chargeCur.ChargeType == PayPlanChargeType.Debit)
                {
                    amtTotal += chargeCur.Principal + chargeCur.Interest;
                }
            }
            return(amtTotal);
        }
Пример #5
0
        ///<summary>Returns a list of overcharged payplans from the listPayPlanNums. Only necessary for Dynamic Payment Plans.
        ///Returns an empty list if none are overcharged.</summary>
        public static List <PayPlan> GetOverchargedPayPlans(List <long> listPayPlanNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <PayPlan> >(MethodBase.GetCurrentMethod(), listPayPlanNums));
            }
            List <PayPlan> listDynamicPayPlansForPatient = new List <PayPlan>();

            foreach (long payPlanNum in listPayPlanNums)
            {
                if (payPlanNum == 0)
                {
                    continue;                    //do not include installment plans
                }
                PayPlan payPlanCur = PayPlans.GetOne(payPlanNum);
                if (payPlanCur.IsDynamic)                 //Only add Dynamic PayPlans to the list since they are all we care about
                {
                    listDynamicPayPlansForPatient.Add(payPlanCur);
                }
            }
            #region Get Data
            List <PayPlanLink>   listPayPlanLinksAll        = PayPlanLinks.GetForPayPlans(listPayPlanNums);
            List <long>          listProcedureLinkFKeys     = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList();
            List <long>          listAdjustmentLinkFKeys    = listPayPlanLinksAll.Where(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList();
            List <PayPlanCharge> listPayPlanCharges         = PayPlanCharges.GetForPayPlans(listPayPlanNums);
            List <Procedure>     listProcsAttachedToPayPlan = Procedures.GetManyProc(listProcedureLinkFKeys, false);
            List <Adjustment>    listAdjsAttachedToPayPlan  = Adjustments.GetMany(listAdjustmentLinkFKeys);
            List <ClaimProc>     listClaimProcsForProcs     = ClaimProcs.GetForProcs(listProcedureLinkFKeys);
            List <Adjustment>    listAdjForProcs            = Adjustments.GetForProcs(listProcedureLinkFKeys);
            #endregion Get Data
            List <PayPlan> listPayPlansOvercharged = new List <PayPlan>();
            foreach (PayPlan payPlanCur in listDynamicPayPlansForPatient)
            {
                List <PayPlanLink> listLinksForPayPlan = listPayPlanLinksAll.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum);
                //Get total amount that has been debited for the current pay plan thus far.
                decimal amtDebitedTotal = listPayPlanCharges.FindAll(x => x.PayPlanNum == payPlanCur.PayPlanNum && x.ChargeType == PayPlanChargeType.Debit)
                                          .Sum(x => (decimal)x.Principal);
                #region Sum Linked Production
                decimal totalPrincipalForPayPlan = 0;
                foreach (PayPlanLink payPlanLink in listLinksForPayPlan)
                {
                    PayPlanProductionEntry productionEntry = null;
                    if (payPlanLink.LinkType == PayPlanLinkType.Procedure)
                    {
                        Procedure proc = listProcsAttachedToPayPlan.FirstOrDefault(x => x.ProcNum == payPlanLink.FKey);
                        if (proc != null)
                        {
                            productionEntry = new PayPlanProductionEntry(proc, payPlanLink, listClaimProcsForProcs, listAdjForProcs);
                        }
                    }
                    else if (payPlanLink.LinkType == PayPlanLinkType.Adjustment)
                    {
                        Adjustment adj = listAdjsAttachedToPayPlan.FirstOrDefault(x => x.AdjNum == payPlanLink.FKey);
                        if (adj != null)
                        {
                            productionEntry = new PayPlanProductionEntry(adj, payPlanLink);
                        }
                    }
                    if (productionEntry != null)
                    {
                        if (productionEntry.AmountOverride == 0)
                        {
                            totalPrincipalForPayPlan += productionEntry.AmountOriginal;
                        }
                        else
                        {
                            totalPrincipalForPayPlan += productionEntry.AmountOverride;
                        }
                    }
                }
                #endregion Sum Linked Production
                //If the total that has been debited thus far exceeds the total principal for the pay plan, it is overcharged.
                if (amtDebitedTotal.IsGreaterThan(totalPrincipalForPayPlan))
                {
                    listPayPlansOvercharged.Add(payPlanCur);
                }
            }
            return(listPayPlansOvercharged);
        }