Exemple #1
0
 public static AccountEntry GetAccountEntry(AccountEntry ae)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         return(Meth.GetObject <AccountEntry>(MethodBase.GetCurrentMethod(), ae));
     }
     return(ae);
 }
Exemple #2
0
 ///<summary>Simple sort that sorts based on date.</summary>
 private static int AccountEntrySort(AccountEntry x, AccountEntry y)
 {
     return(x.Date.CompareTo(y.Date));
 }
Exemple #3
0
        public static List <PaySplit> CreateSplitForPayPlan(Payment paymentCur, AccountEntry payPlanEntry, List <PayPlanCharge> listPayPlanCredits,
                                                            List <AccountEntry> listAccountCharges, decimal payAmt, bool isAutoSplit, out decimal paymentCurPayAmt)
        {
            //No remoting role check; no call to db. Plus this method has an out parameter.
            paymentCurPayAmt = (decimal)paymentCur.PayAmt;
            List <PaySplit> listSplits = new List <PaySplit>();
            DateTime        today      = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0, DateTimeKind.Unspecified);
            //if the payAmt is > 0 and it's NOT an autosplit, we only want to pay up to the payAmt.
            bool          isPartial        = (payAmt > 0) && !isAutoSplit;
            PayPlanCharge payPlanChargeCur = (PayPlanCharge)payPlanEntry.Tag;
            //amtUnattached will also include principal payments if those payments are not allocated to a procedure.
            //This is accounted for when creating an unattached split.
            double amtUnattachedAlreadyPaid = (double)payPlanEntry.SplitCollection.Where(x => x.ProcNum == 0).Sum(y => y.SplitAmt);
            double amtAttachedAlreadyPaid   = (double)payPlanEntry.SplitCollection.Where(x => x.ProcNum != 0).Sum(y => y.SplitAmt);

            //Below is the logic of this method: For the passed in charge
            //create a split for the amount of the interest
            //create a split for the amount of the charge, attach it to the procedure if possible.
            //interest split, only create if interest hasn't already been paid.
            if (amtUnattachedAlreadyPaid < payPlanChargeCur.Interest)
            {
                PaySplit interest = new PaySplit();
                interest.DatePay = today;
                //the split should always go to the payplancharge's guarantor.
                interest.PatNum  = payPlanChargeCur.Guarantor;
                interest.ProvNum = payPlanChargeCur.ProvNum;
                if (PrefC.HasClinicsEnabled)                 //Clinics
                {
                    interest.ClinicNum = payPlanChargeCur.ClinicNum;
                }
                interest.PayPlanNum = payPlanChargeCur.PayPlanNum;
                interest.PayNum     = paymentCur.PayNum;
                //if it's an autoSplit, then only use up to the global PaymentAmt.
                //else if it's a partial split, then only use up to payAmt.
                //else it's a manual split, so just add a split for the entire charge.
                if (isAutoSplit)
                {
                    interest.SplitAmt = Math.Min(payPlanChargeCur.Interest - amtUnattachedAlreadyPaid, (double)paymentCurPayAmt);
                    paymentCurPayAmt -= (decimal)interest.SplitAmt;
                }
                else if (isPartial)
                {
                    interest.SplitAmt = Math.Min(payPlanChargeCur.Interest - amtUnattachedAlreadyPaid, (double)payAmt);
                    payAmt           -= (decimal)interest.SplitAmt;
                    paymentCurPayAmt -= (decimal)interest.SplitAmt;
                }
                else
                {
                    interest.SplitAmt = payPlanChargeCur.Interest - amtUnattachedAlreadyPaid;
                }
                //this is so the paysplit says (interest) in the grid.
                interest.IsInterestSplit = true;
                payPlanEntry.AmountEnd  -= (decimal)interest.SplitAmt;
                payPlanEntry.SplitCollection.Add(interest);
                listSplits.Add(interest);
            }
            //get all procs associated to this plan
            List <AccountEntry> listPayPlanProcsEntries = new List <AccountEntry>();

            foreach (PayPlanCharge payPlanCredit in listPayPlanCredits)         //For each credit
            {
                foreach (AccountEntry entry in listAccountCharges)              //Go through account entries
                {
                    if (entry.GetType() != typeof(Procedure))                   //If it's not a proc
                    {
                        continue;
                    }
                    Procedure proc = (Procedure)entry.Tag;
                    if (proc.ProcNum == payPlanCredit.ProcNum)                   //See if the proc has the credit's procnum
                    {
                        listPayPlanProcsEntries.Add(entry);                      //if so, add it so we then have a list of payplan's procs, and we can also show how much is left due for it
                    }
                }
            }
            listPayPlanProcsEntries = listPayPlanProcsEntries.OrderBy(x => x.Date).ToList();
            if (amtAttachedAlreadyPaid < payPlanChargeCur.Principal)
            {
                if (listPayPlanProcsEntries.Count > 0)
                {
                    double amtAvail = (double)payPlanEntry.AmountEnd;
                    foreach (AccountEntry entryProc in listPayPlanProcsEntries)
                    {
                        if (isAutoSplit && paymentCurPayAmt == 0)
                        {
                            break;
                        }
                        Procedure procCur   = (Procedure)entryProc.Tag;
                        PaySplit  procSplit = new PaySplit();
                        //get the amount of this procedure that's attached to this payment plan
                        double maxSplitForCurrentProc = listPayPlanCredits.Where(x => x.ProcNum == procCur.ProcNum).Sum(y => y.Principal);
                        //get the amount of this procedure that's already been paid off in this payment plan.
                        maxSplitForCurrentProc -= entryProc.SplitCollection.Where(x => x.PayPlanNum == payPlanChargeCur.PayPlanNum).Sum(y => y.SplitAmt);
                        if (maxSplitForCurrentProc == 0)
                        {
                            continue;
                        }
                        procSplit.DatePay = today;
                        //the payment should always go to the account of the payplancharge's guarantor.
                        procSplit.PatNum     = payPlanChargeCur.Guarantor;
                        procSplit.PayPlanNum = payPlanChargeCur.PayPlanNum;
                        procSplit.PayNum     = paymentCur.PayNum;
                        if (isAutoSplit)
                        {
                            //make a split for the procedure for no more than the sum of all the credits on the payment plan for that procedure.
                            procSplit.SplitAmt = Math.Min(maxSplitForCurrentProc, Math.Min(amtAvail, (double)paymentCurPayAmt));
                            paymentCurPayAmt  -= (decimal)procSplit.SplitAmt;
                        }
                        else if (isPartial)
                        {
                            if (payAmt == 0)
                            {
                                break;
                            }
                            procSplit.SplitAmt = Math.Min(maxSplitForCurrentProc, Math.Min(amtAvail, (double)payAmt));
                            payAmt            -= (decimal)procSplit.SplitAmt;
                            paymentCurPayAmt  -= (decimal)procSplit.SplitAmt;
                        }
                        else
                        {
                            procSplit.SplitAmt = Math.Min((double)maxSplitForCurrentProc, amtAvail);                          //make a split for the procedure for no more than the sum of all the credits on the payment plan for that procedure.
                        }
                        procSplit.ProvNum   = procCur.ProvNum;
                        procSplit.ClinicNum = procCur.ClinicNum;
                        procSplit.ProcNum   = procCur.ProcNum;
                        amtAvail           -= procSplit.SplitAmt;
                        entryProc.SplitCollection.Add(procSplit);
                        payPlanEntry.AmountEnd -= (decimal)procSplit.SplitAmt;
                        payPlanEntry.SplitCollection.Add(procSplit);
                        listSplits.Add(procSplit);
                    }
                    //if they have a mix of attached and unattached credits: (if there are payplan charges not linked to a procedure)
                    bool doCreateUnattachedSplit = payPlanEntry.AmountEnd > 0 && ((isAutoSplit && Math.Min(amtAvail, (double)paymentCurPayAmt) > 0) ||
                                                                                  (!isAutoSplit && Math.Min(amtAvail, (double)payAmt) > 0));
                    if (doCreateUnattachedSplit)
                    {
                        PaySplit unattachedSplit = new PaySplit();
                        unattachedSplit.DatePay = today;
                        //the payment should always go to the account of the payplancharge's guarantor.
                        unattachedSplit.PatNum     = payPlanChargeCur.Guarantor;
                        unattachedSplit.PayPlanNum = payPlanChargeCur.PayPlanNum;
                        unattachedSplit.PayNum     = paymentCur.PayNum;
                        if (isAutoSplit)
                        {
                            unattachedSplit.SplitAmt = Math.Min(amtAvail, (double)paymentCurPayAmt);
                            paymentCurPayAmt        -= (decimal)unattachedSplit.SplitAmt;
                        }
                        else if (isPartial)
                        {
                            unattachedSplit.SplitAmt = Math.Min(amtAvail, (double)payAmt);
                            payAmt           -= (decimal)unattachedSplit.SplitAmt;
                            paymentCurPayAmt -= (decimal)unattachedSplit.SplitAmt;
                        }
                        else
                        {
                            unattachedSplit.SplitAmt = amtAvail;
                        }
                        unattachedSplit.ProvNum   = payPlanEntry.ProvNum;
                        unattachedSplit.ClinicNum = payPlanEntry.ClinicNum;
                        unattachedSplit.ProcNum   = 0;
                        amtAvail -= unattachedSplit.SplitAmt;
                        payPlanEntry.AmountEnd -= (decimal)unattachedSplit.SplitAmt;
                        payPlanEntry.SplitCollection.Add(unattachedSplit);
                        listSplits.Add(unattachedSplit);
                    }
                }
                else
                {
                    PaySplit unattachedSplit = new PaySplit();
                    //for payplans with no attached procedures, all paysplits would end up in the interestAlreadyPaid amount.
                    //any extra money that was accidentally lumped into interestAlreadyPaid should be included in principleAlreadyPaid here.
                    amtAttachedAlreadyPaid  = (amtUnattachedAlreadyPaid - payPlanChargeCur.Interest > 0) ? amtUnattachedAlreadyPaid - payPlanChargeCur.Interest : 0;
                    unattachedSplit.DatePay = today;
                    //the payment should always go to the account of the payplancharge's guarantor.
                    unattachedSplit.PatNum     = payPlanChargeCur.Guarantor;
                    unattachedSplit.PayPlanNum = payPlanChargeCur.PayPlanNum;
                    unattachedSplit.PayNum     = paymentCur.PayNum;
                    if (isAutoSplit)
                    {
                        unattachedSplit.SplitAmt = Math.Min((double)paymentCurPayAmt, payPlanChargeCur.Principal - amtAttachedAlreadyPaid);
                        paymentCurPayAmt        -= (decimal)unattachedSplit.SplitAmt;
                    }
                    else if (isPartial)
                    {
                        unattachedSplit.SplitAmt = Math.Min((double)payAmt, payPlanChargeCur.Principal - amtAttachedAlreadyPaid);
                        payAmt           -= (decimal)unattachedSplit.SplitAmt;
                        paymentCurPayAmt -= (decimal)unattachedSplit.SplitAmt;
                    }
                    else
                    {
                        unattachedSplit.SplitAmt = payPlanChargeCur.Principal - amtAttachedAlreadyPaid;
                    }
                    unattachedSplit.ProvNum   = payPlanChargeCur.ProvNum;
                    unattachedSplit.ClinicNum = payPlanChargeCur.ClinicNum;
                    payPlanEntry.AmountEnd   -= (decimal)unattachedSplit.SplitAmt;
                    payPlanEntry.SplitCollection.Add(unattachedSplit);
                    listSplits.Add(unattachedSplit);
                }
            }
            return(listSplits);
        }