///<summary>Will delete all PayPlanCharges associated to the passed-in procNum from the database. Does nothing if the procNum = 0.</summary> public static void DeleteForProc(long procNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), procNum); return; } if (procNum == 0) { return; } List <PayPlan> listPayPlans = PayPlans.GetAllForCharges(GetFromProc(procNum)); string command = "DELETE FROM payplancharge WHERE ProcNum=" + POut.Long(procNum); Db.NonQ(command); PayPlans.UpdateTreatmentCompletedAmt(listPayPlans); }
///<summary>Takes a procNum and updates all of the dates of the payment plan charge credits associated to it. ///If a completed procedure is passed in, it will update all of the payment plan charges associated to it to the ProcDate. ///If a non-complete procedure is passed in, it will update the charges associated to MaxValue. ///Does nothing if there are no charges attached to the passed-in procedure.</summary> public static void UpdateAttachedPayPlanCharges(Procedure proc) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), proc); return; } List <PayPlanCharge> listCharges = GetFromProc(proc.ProcNum); foreach (PayPlanCharge chargeCur in listCharges) { chargeCur.ChargeDate = DateTime.MaxValue; if (proc.ProcStatus == ProcStat.C) { chargeCur.ChargeDate = proc.ProcDate; } Update(chargeCur); //one update statement for each payplancharge. } List <PayPlan> listPayPlans = PayPlans.GetAllForCharges(listCharges); PayPlans.UpdateTreatmentCompletedAmt(listPayPlans); }
///<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); }