public static PaymentEdit.IncomeTransferData IncomeTransfer(long patNum, Family fam, Payment payCur, List <PayPlanCharge> listPayPlanCredits, bool doIncludeHidden = false) { #region generate charges and credits for account //go through the logic that constructs the charges for the income transfer manager PaymentEdit.ConstructResults results = PaymentEdit.ConstructAndLinkChargeCredits(fam.ListPats.Select(x => x.PatNum).ToList(), patNum, new List <PaySplit>(), payCur, new List <AccountEntry>(), true, false, doShowHiddenSplits: doIncludeHidden); PaymentEdit.IncomeTransferData transfers = new PaymentEdit.IncomeTransferData(); List <AccountEntry> listPosCharges = results.ListAccountCharges.FindAll(x => x.AmountEnd > 0).OrderBy(x => x.Date).ToList(); List <AccountEntry> listNegCharges = results.ListAccountCharges.FindAll(x => x.AmountEnd < 0).OrderBy(x => x.Date).ToList(); List <long> listPatsWithPosCharges = listPosCharges.Select(y => y.PatNum).Distinct().ToList(); List <AccountEntry> listAccountEntries = results.ListAccountCharges.FindAll(x => x.PatNum.In(listPatsWithPosCharges)); #endregion //begin transfer loops #region transfer within payplans first PaymentEdit.IncomeTransferData payPlanResults = PaymentEdit.CreatePayplanLoop(listPosCharges, listNegCharges, listAccountEntries , payCur.PayNum, listPayPlanCredits, DateTimeOD.Today); transfers.MergeIncomeTransferData(payPlanResults); #endregion #region regular transfers PaymentEdit.IncomeTransferData txfrResults = PaymentEdit.CreateTransferLoop(listPosCharges, listNegCharges, listAccountEntries , payCur.PayNum, listPayPlanCredits, DateTimeOD.Today); transfers.MergeIncomeTransferData(txfrResults); #endregion return(transfers); }
public void PaymentEdit_AutoSplitForPayment_NoNegativeAutoSplits() { long provNumA = ProviderT.CreateProvider("provA"); Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure proc1 = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 70); Procedure proc2 = ProcedureT.CreateProcedure(pat, "D0150", ProcStat.C, "", 20); //make an overpayment for one of the procedures so it spills over. DateTime payDate = DateTime.Today; Payment pay = PaymentT.MakePayment(pat.PatNum, 71, payDate, procNum: proc1.ProcNum); //pre-existing payment //attempt to make another payment. Auto splits should not suggest a negative split. Payment newPayment = PaymentT.MakePaymentNoSplits(pat.PatNum, 2, payDate, isNew: true, payType: Defs.GetDefsForCategory(DefCat.PaymentTypes, true)[0].DefNum);//current payment we're trying to make PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, newPayment, new List <long>() { pat.PatNum }, true, false); PaymentEdit.ConstructChargesData chargeData = PaymentEdit.GetConstructChargesData(new List <long> { pat.PatNum }, pat.PatNum, PaySplits.GetForPayment(pay.PayNum), pay.PayNum, false); PaymentEdit.ConstructResults constructResults = PaymentEdit.ConstructAndLinkChargeCredits(new List <long> { pat.PatNum }, pat.PatNum , chargeData.ListPaySplits, newPayment, new List <Procedure> ()); PaymentEdit.AutoSplit autoSplits = PaymentEdit.AutoSplitForPayment(constructResults); Assert.AreEqual(0, autoSplits.ListAutoSplits.FindAll(x => x.SplitAmt < 0).Count); //assert no negative auto splits were made. Assert.AreEqual(0, autoSplits.ListSplitsCur.FindAll(x => x.SplitAmt < 0).Count); //auto splits not catching everything }
///<summary>Performs all of the Load functionality.</summary> private void Init() { _listSplitsCur = new List <PaySplit>(); _listSplitsAssociated = new List <PaySplits.PaySplitAssociated>(); _dictPatients = Patients.GetAssociatedPatients(_patCur.PatNum).ToDictionary(x => x.PatNum, x => x); _results = PaymentEdit.ConstructAndLinkChargeCredits(_famCur.ListPats.Select(x => x.PatNum).ToList(), _patCur.PatNum, new List <PaySplit>(), _paymentCur, new List <AccountEntry>(), true, false); FillGridSplits(); }
///<summary>Only change checked state if there are zero transfer splits.</summary> private void checkIncludeHiddenSplits_Click(object sender, EventArgs e) { if (_listSplitsCur.Count > 0) { MsgBox.Show("You must delete all splits before including or excluding hidden payment splits."); checkIncludeHiddenSplits.Checked = !checkIncludeHiddenSplits.Checked; return; } _results = PaymentEdit.ConstructAndLinkChargeCredits(_famCur.ListPats.Select(x => x.PatNum).ToList(), _patCur.PatNum, new List <PaySplit>(), _paymentCur, new List <AccountEntry>(), true, false, doShowHiddenSplits: checkIncludeHiddenSplits.Checked); FillGridSplits(); }
public void PaymentEdit_AutoSplitForPayment_SplitForPaymentLessThanTotalofProcs() { Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure proc1 = ProcedureT.CreateProcedure(pat, "D1110", ProcStat.C, "", 40); Procedure proc2 = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 40); Payment pay = PaymentT.MakePaymentNoSplits(pat.PatNum, 50); PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, pay, new List <long> { pat.PatNum }, true, false); PaymentEdit.ConstructResults chargeResult = PaymentEdit.ConstructAndLinkChargeCredits(new List <long> { pat.PatNum }, pat.PatNum , loadData.ConstructChargesData.ListPaySplits, pay, new List <Procedure>()); PaymentEdit.AutoSplit autoSplit = PaymentEdit.AutoSplitForPayment(chargeResult); Assert.AreEqual(2, autoSplit.ListAutoSplits.Count); Assert.AreEqual(1, autoSplit.ListAutoSplits.Count(x => x.SplitAmt.IsEqual(40))); Assert.AreEqual(1, autoSplit.ListAutoSplits.Count(x => x.SplitAmt.IsEqual(10))); }
public void PaymentEdit_Init_PayPlanChargesWithUnattachedCredits() { //new payplan Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure proc1 = ProcedureT.CreateProcedure(pat, "D1120", ProcStat.C, "", 135, DateTime.Today.AddMonths(-4)); Procedure proc2 = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 60, DateTime.Today.AddMonths(-4)); PayPlan payplan = PayPlanT.CreatePayPlanWithCredits(pat.PatNum, 30, DateTime.Today.AddMonths(-3), 0, totalAmt: 195); //Go to make a payment for the charges due Payment pay = PaymentT.MakePaymentNoSplits(pat.PatNum, 60, DateTime.Today); PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, pay, new List <long> { pat.PatNum }, true, false); PaymentEdit.ConstructResults constructResults = PaymentEdit.ConstructAndLinkChargeCredits(new List <long> { pat.PatNum }, pat.PatNum , loadData.ConstructChargesData.ListPaySplits, pay, new List <Procedure> (), loadData: loadData); Assert.AreEqual(6, constructResults.ListAccountCharges.Count); //2 procedures and 4 months of charges since unattached credits. Assert.AreEqual(2, constructResults.ListAccountCharges.Count(x => x.Tag.GetType() == typeof(Procedure))); Assert.AreEqual(4, constructResults.ListAccountCharges.Count(x => x.Tag.GetType() == typeof(PayPlanCharge))); }
public void PaymentEdit_Init_PayPlanChargesWithAttachedCredits() { //new payplan Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure proc1 = ProcedureT.CreateProcedure(pat, "D1120", ProcStat.C, "", 135, DateTime.Today.AddMonths(-4)); Procedure proc2 = ProcedureT.CreateProcedure(pat, "D0220", ProcStat.C, "", 60, DateTime.Today.AddMonths(-4)); PayPlan payplan = PayPlanT.CreatePayPlanWithCredits(pat.PatNum, 30, DateTime.Today.AddMonths(-3), 0, new List <Procedure>() { proc1, proc2 }); //Go to make a payment for the charges that are due Payment pay = PaymentT.MakePaymentNoSplits(pat.PatNum, 60, DateTime.Today); PaymentEdit.LoadData loadData = PaymentEdit.GetLoadData(pat, pay, new List <long> { pat.PatNum }, true, false); PaymentEdit.ConstructResults constructResults = PaymentEdit.ConstructAndLinkChargeCredits(new List <long> { pat.PatNum }, pat.PatNum , loadData.ConstructChargesData.ListPaySplits, pay, new List <Procedure> (), loadData: loadData); Assert.AreEqual(4, constructResults.ListAccountCharges.FindAll(x => x.AmountStart > 0).Count); //Procs shouldn't show - only the 4 pay plan charges Assert.AreEqual(4, constructResults.ListAccountCharges.Count(x => x.Tag.GetType() == typeof(PayPlanCharge))); }
///<summary>Fills the main grid. If reload Data is true, account data will be (re)fetched from the database. ///If false then data already in memory is used.</summary> private void FillGridMain() { gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); GridColumn col; col = new GridColumn(Lan.g(this, "Name"), 240); gridMain.ListGridColumns.Add(col); col = new GridColumn(Lan.g(this, "Balance"), 100, GridSortingStrategy.AmountParse); gridMain.ListGridColumns.Add(col); gridMain.ListGridRows.Clear(); GridRow row; PaymentEdit.ConstructResults results; //Make a row for every guarantor that has family members with positive and negative balances. List <long> listPatNumsForBatch = _dictCurrentFamilyBatch.Values.Select(x => x.ListFamilyMembers) .SelectMany(y => y.Select(z => z.PatNum)).ToList(); List <PaySplit> listSplitsForBatch = PaySplits.GetForPats(listPatNumsForBatch); List <ClaimProc> listClaimsPayAsTotalForBatch = ClaimProcs.GetByTotForPats(listPatNumsForBatch); foreach (KeyValuePair <long, FamilyAccount> kvp in _dictCurrentFamilyBatch) { //Get all family members now so we cut down on memory used. FamilyAccount famAccount = kvp.Value; List <Patient> listPatients = famAccount.ListFamilyMembers; List <long> listFamilyPatNums = listPatients.Select(x => x.PatNum).ToList(); long guarantorNum = kvp.Key; List <PaySplit> listSplitsForPats = listSplitsForBatch.FindAll(x => x.PatNum.In(listFamilyPatNums)); long unallocatedTransferPayNum = PaymentEdit.CreateAndInsertUnallocatedPayment(listPatients.First(x => x.PatNum == guarantorNum)); if (!listSplitsForPats.IsNullOrEmpty()) { PaymentEdit.IncomeTransferData txfrResults = PaymentEdit.TransferUnallocatedSplitToUnearned(listSplitsForPats, unallocatedTransferPayNum); foreach (PaySplit split in txfrResults.ListSplitsCur) { split.PayNum = unallocatedTransferPayNum; //Set the PayNum because it was purposefully set to 0 above to save queries. PaySplits.Insert(split); //Need to insert in a loop to get the PrimaryKey } foreach (PaySplits.PaySplitAssociated splitAssociated in txfrResults.ListSplitsAssociated) { if (splitAssociated.PaySplitLinked != null && splitAssociated.PaySplitOrig != null) { PaySplits.UpdateFSplitNum(splitAssociated.PaySplitOrig.SplitNum, splitAssociated.PaySplitLinked.SplitNum); } } } List <ClaimProc> listClaimsAsTotalForPats = listClaimsPayAsTotalForBatch.FindAll(x => x.PatNum.In(listFamilyPatNums)); ClaimProcs.TransferClaimsAsTotalToProcedures(listPatients.Select(x => x.PatNum).ToList(), listClaimsAsTotalForPats); results = PaymentEdit.ConstructAndLinkChargeCredits(listPatients.Select(x => x.PatNum).ToList(), guarantorNum, new List <PaySplit>(), new Payment(), new List <AccountEntry>(), true); famAccount.Account = results; List <AccountEntry> listAccountEntries = results.ListAccountCharges; //Get guarantor info and fill the row/grid Patient guarantor = listPatients.FirstOrDefault(x => x.PatNum == guarantorNum); row = new GridRow(); row.Cells.Add(guarantor.GetNameLFnoPref()); row.Cells.Add((listAccountEntries.Sum(x => x.AmountEnd)).ToString("f")); row.Tag = famAccount; //Store relevant family info in the guarantor row. row.DropDownInitiallyDown = false; row.Bold = true; //Bold parent rows to show it is giving the family balance. gridMain.ListGridRows.Add(row); //Make child rows foreach (Patient p in listPatients) { GridRow rowChild = new GridRow(); rowChild.Cells.Add(p.GetNameLFnoPref()); rowChild.Cells.Add(listAccountEntries.Where(x => x.PatNum == p.PatNum).Sum(x => x.AmountEnd).ToString("f")); rowChild.DropDownParent = row; gridMain.ListGridRows.Add(rowChild); } } gridMain.EndUpdate(); gridMain.Update(); labelBatchCount.Text = $"Current batch: {_batchNum} Total batches: {_listBatches.Count()}"; //Invalidate and update the label to force it to be in sync with the progress bar that is on a separate thread. labelBatchCount.Invalidate(); labelBatchCount.Update(); }