///<summary>Gets the data necessary to load FormProcEdit.</summary> public static LoadData GetLoadData(Procedure proc, Patient pat, Family fam) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), proc, pat, fam)); } LoadData data = new LoadData(); data.ListPatPlans = PatPlans.Refresh(pat.PatNum); if (!PatPlans.IsPatPlanListValid(data.ListPatPlans)) //PatPlans had invalid references and need to be refreshed. { data.ListPatPlans = PatPlans.Refresh(pat.PatNum); } data.ListInsSubs = InsSubs.RefreshForFam(fam); data.ListInsPlans = InsPlans.RefreshForSubList(data.ListInsSubs); data.ListClaims = Claims.Refresh(pat.PatNum); data.ListClaimProcsForProc = ClaimProcs.RefreshForProc(proc.ProcNum); data.ListBenefits = Benefits.Refresh(data.ListPatPlans, data.ListInsSubs); data.ListRefAttaches = RefAttaches.RefreshFiltered(proc.PatNum, false, proc.ProcNum); data.ArrPaySplits = PaySplits.Refresh(proc.PatNum); List <long> listPayNums = data.ArrPaySplits.Where(x => x.ProcNum == proc.ProcNum).Select(x => x.PayNum).ToList(); data.ListPaymentsForProc = Payments.GetPayments(listPayNums); data.ArrAdjustments = Adjustments.Refresh(proc.PatNum); data.OrthoProcedureLink = OrthoProcLinks.GetByProcNum(proc.ProcNum); return(data); }
///<summary>Returns true if the passed in adjustment needs to be subsequently saved to the database. Returns false otherwise. ///Takes in a procedure and a potential sales tax adjustment and gets the expected tax amount for the procedure. If there is not tax ///and the adjustment has not been inserted into the database, then we do not create an adjustment. Otherwise, we save the sax and insert the ///adjustment (even if there is an existing tax, and we are setting adjustment amount to 0). Finally all errors encountered are logged in the ///adjustment note and on the machine's local logs.</summary> public static bool DidUpdateAdjustment(Procedure proc, Adjustment adj) { string message = ""; try { //Get the new sum of all adjustments attached to the proc, excluding sales tax and including the new adjustment amount if applicable double procTotal = proc.ProcFeeTotal + Adjustments.GetTotForProc(proc.ProcNum, canIncludeTax: false); decimal taxAmt = GetEstimate(proc.CodeNum, proc.PatNum, procTotal, hasExceptions: true); if (taxAmt == 0 && adj.AdjNum == 0) //We could be modifying an existing adjustment, in which case we would want to set the 0 value { return(false); } adj.AdjAmt = (double)taxAmt; return(true); } catch (AvaTaxError at) { _logger.WriteLine("Encountered an Avatax error: " + JsonConvert.SerializeObject(at.error.error), LogLevel.Error); message = at.error.error.message; } catch (Exception ex) { _logger.WriteLine("Unable to send or receive transaction: " + JsonConvert.SerializeObject(ex), LogLevel.Error); message = ex.Message; } adj.AdjNote = AddNote(adj.AdjNote, "An error occurred processing the transaction: " + message + " See local logs for more details."); adj.AdjAmt = 0; return(true); }
public static List <PayPlanProductionEntry> GetProductionForLinks(List <PayPlanLink> listCredits) { //No remoting role check; no call to db List <long> listProcNums = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Procedure).Select(x => x.FKey).ToList(); List <long> listAdjNumsForCredits = listCredits.FindAll(x => x.LinkType == PayPlanLinkType.Adjustment).Select(x => x.FKey).ToList(); List <PayPlanProductionEntry> listPayPlanProductionEntries = new List <PayPlanProductionEntry>(); //ortho cases to be implemented later. List <Procedure> listProcedures = Procedures.GetManyProc(listProcNums, false); List <Adjustment> listCreditAdjustments = Adjustments.GetMany(listAdjNumsForCredits); List <Adjustment> listProcAdjustments = Adjustments.GetForProcs(listProcNums); List <ClaimProc> listClaimProcs = ClaimProcs.GetForProcs(listProcNums); //used for calculating patient porition foreach (PayPlanLink credit in listCredits) { if (credit.LinkType == PayPlanLinkType.Procedure) { Procedure proc = listProcedures.FirstOrDefault(x => x.ProcNum == credit.FKey); if (proc != null) { listPayPlanProductionEntries.Add(new PayPlanProductionEntry(proc, credit, listClaimProcs, listProcAdjustments)); } } else if (credit.LinkType == PayPlanLinkType.Adjustment) { Adjustment adj = listCreditAdjustments.FirstOrDefault(x => x.AdjNum == credit.FKey); if (adj != null) { listPayPlanProductionEntries.Add(new PayPlanProductionEntry(adj, credit)); } } } return(listPayPlanProductionEntries); }
///<summary>Gets the data necesary to load FormApptEdit.</summary> public static LoadData GetLoadData(Appointment AptCur, bool IsNew) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetObject <LoadData>(MethodBase.GetCurrentMethod(), AptCur, IsNew)); } LoadData data = new LoadData(); data.ListProcsForAppt = Procedures.GetProcsForApptEdit(AptCur); data.ListAppointments = Appointments.GetAppointmentsForProcs(data.ListProcsForAppt); data.Family = Patients.GetFamily(AptCur.PatNum); data.ListPatPlans = PatPlans.Refresh(AptCur.PatNum); data.ListInsSubs = InsSubs.RefreshForFam(data.Family); data.ListBenefits = Benefits.Refresh(data.ListPatPlans, data.ListInsSubs); data.ListInsPlans = InsPlans.RefreshForSubList(data.ListInsSubs); data.TableApptFields = Appointments.GetApptFields(AptCur.AptNum); data.TableComms = Appointments.GetCommTable(AptCur.PatNum.ToString(), AptCur.AptNum); data.Lab = (IsNew ? null : LabCases.GetForApt(AptCur)); data.PatientTable = Appointments.GetPatTable(AptCur.PatNum.ToString(), AptCur); data.ListClaimProcs = ClaimProcs.RefreshForProcs(data.ListProcsForAppt.Select(x => x.ProcNum).ToList()); data.ListAdjustments = Adjustments.GetForProcs(data.ListProcsForAppt.Select(x => x.ProcNum).ToList()); if (!PrefC.GetBool(PrefName.EasyHideDentalSchools)) { data.ListStudents = ReqStudents.GetForAppt(AptCur.AptNum); } return(data); }
///<summary>Creates a new discount adjustment for the given procedure.</summary> public static void CreateAdjustmentForDiscount(Procedure procedure) { //No need to check RemotingRole; no call to db. Adjustment AdjustmentCur = new Adjustment(); AdjustmentCur.DateEntry = DateTime.Today; AdjustmentCur.AdjDate = DateTime.Today; AdjustmentCur.ProcDate = procedure.ProcDate; AdjustmentCur.ProvNum = procedure.ProvNum; AdjustmentCur.PatNum = procedure.PatNum; AdjustmentCur.AdjType = PrefC.GetLong(PrefName.TreatPlanDiscountAdjustmentType); AdjustmentCur.ClinicNum = procedure.ClinicNum; AdjustmentCur.AdjAmt = -procedure.Discount; //Discount must be negative here. AdjustmentCur.ProcNum = procedure.ProcNum; Adjustments.Insert(AdjustmentCur); }
public static bool DoCreateReturnAdjustment(Procedure procedure, Adjustment lockedAdj, Adjustment returnAdj) { try { double procTotal = procedure.ProcFeeTotal + Adjustments.GetTotForProc(procedure.ProcNum, canIncludeTax: false); decimal taxEstNew = AvaTax.GetEstimate(procedure.CodeNum, procedure.PatNum, procTotal, hasExceptions: true); returnAdj.AdjAmt = (Adjustments.GetTotTaxForProc(procedure) - (double)taxEstNew) * (-1); if (returnAdj.AdjAmt == 0) { return(false); //no error and we would be refunding $0 to the customer, so no need to create a return adjustment } } catch (Exception e) { returnAdj.AdjNote = AvaTax.AddNote(returnAdj.AdjNote, "An error occurred processing the transaction: " + e.Message + " See local logs for more details."); } return(true); }
///<summary>Creates and inserts a discount adjustment for the passed in procedure. Used by prepayment tool.</summary> public static void CreateDiscountAdjustment(Procedure proc, double discountPercentage, long adjType) { Adjustment adj = new Adjustment { DateEntry = DateTime.Today, AdjDate = DateTime.Today, ProcDate = proc.ProcDate, ProvNum = proc.ProvNum, ProcNum = proc.ProcNum, ClinicNum = proc.ClinicNum, PatNum = proc.PatNum, AdjType = adjType, AdjAmt = -(proc.ProcFee * discountPercentage) //Flip the sign to make it a negative adjustment. }; Adjustments.Insert(adj); TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(adj); }
///<summary>Creates a new discount adjustment for the given procedure using the discount plan fee.</summary> public static void CreateAdjustmentForDiscountPlan(Procedure procedure) { //No need to check RemotingRole; no call to db. DiscountPlan discountPlan = DiscountPlans.GetPlan(Patients.GetPat(procedure.PatNum).DiscountPlanNum); if (discountPlan == null) { return; //No discount plan. } //Figure out how much the patient saved and make an adjustment for the difference so that the office find how much money they wrote off. double discountAmt = Fees.GetAmount(procedure.CodeNum, discountPlan.FeeSchedNum, procedure.ClinicNum, procedure.ProvNum); if (discountAmt == -1) { return; //No fee entered, don't make adjustment. } double adjAmt = procedure.ProcFee - discountAmt; if (adjAmt <= 0) { return; //We do not need to create adjustments for 0 dollars. } Adjustment adjustmentCur = new Adjustment(); adjustmentCur.DateEntry = DateTime.Today; adjustmentCur.AdjDate = DateTime.Today; adjustmentCur.ProcDate = procedure.ProcDate; adjustmentCur.ProvNum = procedure.ProvNum; adjustmentCur.PatNum = procedure.PatNum; adjustmentCur.AdjType = discountPlan.DefNum; adjustmentCur.ClinicNum = procedure.ClinicNum; adjustmentCur.AdjAmt = (-adjAmt); adjustmentCur.ProcNum = procedure.ProcNum; Adjustments.Insert(adjustmentCur); SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, procedure.PatNum, "Adjustment made for discount plan: " + adjustmentCur.AdjAmt.ToString("f")); }
///<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); }
private static List <TreatPlanPresenterEntry> GetListTreatPlanPresenterEntries(List <long> listClinicNums, bool isFirstPresenter, bool isPresenter , DateTime dateStart, DateTime dateEnd) { //No need to check RemotingRole; private method. List <Procedure> listProcsComplete = ReportsComplex.RunFuncOnReportServer(() => Procedures.GetCompletedForDateRangeLimited(dateStart, dateEnd, listClinicNums)); List <ProcTP> listProcTPs = ReportsComplex.RunFuncOnReportServer(() => ProcTPs.GetForProcs(listProcsComplete.Select(x => x.ProcNum).ToList())); List <Procedure> listTreatPlanProcs = listProcsComplete.Where(x => listProcTPs.Select(y => y.ProcNumOrig).Contains(x.ProcNum)).ToList(); List <TreatPlan> listSavedTreatPlans = ReportsComplex.RunFuncOnReportServer(() => TreatPlans.GetFromProcTPs(listProcTPs)); // attached proctps to treatment plans. List <ClaimProc> listClaimProcs = ReportsComplex.RunFuncOnReportServer(() => ClaimProcs.GetForProcsLimited(listTreatPlanProcs.Select(x => x.ProcNum).ToList(), ClaimProcStatus.Received, ClaimProcStatus.Supplemental, ClaimProcStatus.CapComplete, ClaimProcStatus.NotReceived)); List <Adjustment> listAdjustments = ReportsComplex.RunFuncOnReportServer(() => Adjustments.GetForProcs(listTreatPlanProcs.Select(x => x.ProcNum).ToList())); List <Userod> listUserods = ReportsComplex.RunFuncOnReportServer(() => Userods.GetAll()); List <TreatPlanPresenterEntry> listTreatPlanPresenterEntries = new List <TreatPlanPresenterEntry>(); List <ProcedureCode> listProcCodes = ProcedureCodes.GetCodesForCodeNums(listTreatPlanProcs.Select(x => x.CodeNum).ToList()); foreach (Procedure procCur in listTreatPlanProcs) { double grossProd = procCur.ProcFeeTotal; double writeOffs = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum) .Where(x => x.Status == ClaimProcStatus.CapComplete) .Sum(x => x.WriteOff); grossProd -= writeOffs; writeOffs = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum) .Where(x => x.Status == ClaimProcStatus.NotReceived || x.Status == ClaimProcStatus.Received || x.Status == ClaimProcStatus.Supplemental) .Sum(x => x.WriteOff); double adjustments = listAdjustments.Where(x => x.ProcNum == procCur.ProcNum).Sum(x => x.AdjAmt); double netProd = grossProd - writeOffs + adjustments; TreatPlan treatPlanCur; if (isFirstPresenter) { treatPlanCur = listSavedTreatPlans.Where(x => x.ListProcTPs.Any(y => y.ProcNumOrig == procCur.ProcNum)).OrderBy(x => x.DateTP).First(); } else //radioLastPresented { treatPlanCur = listSavedTreatPlans.Where(x => x.ListProcTPs.Any(y => y.ProcNumOrig == procCur.ProcNum)).OrderByDescending(x => x.DateTP).First(); } Userod userPresenter; if (isPresenter) { userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.UserNumPresenter); } else //radioEntryUser { userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.SecUserNumEntry); } ProcedureCode procCode = listProcCodes.First(x => x.CodeNum == procCur.CodeNum); listTreatPlanPresenterEntries.Add(new TreatPlanPresenterEntry() { Presenter = userPresenter == null?"":userPresenter.UserName, DatePresented = treatPlanCur.DateTP, DateCompleted = procCur.ProcDate, ProcDescript = procCode.Descript, GrossProd = grossProd, Adjustments = adjustments, WriteOffs = writeOffs, NetProd = netProd, UserNumPresenter = userPresenter == null?0:userPresenter.UserNum, PresentedClinic = procCur.ClinicNum }); } return(listTreatPlanPresenterEntries); }
///<summary>If not using clinics then supply an empty list of clinicNums.</summary> public static DataTable GetTreatPlanPresentationStatistics(DateTime dateStart, DateTime dateEnd, bool isFirstPresented, bool hasAllClinics , bool hasClinicsEnabled, bool isPresenter, bool isGross, bool hasAllUsers, List <long> listUserNums, List <long> listClinicNums) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetTable(MethodBase.GetCurrentMethod(), dateStart, dateEnd, isFirstPresented, hasAllClinics, hasClinicsEnabled, isPresenter, isGross , hasAllUsers, listUserNums, listClinicNums)); } List <ProcTP> listProcTPsAll = ReportsComplex.RunFuncOnReportServer(() => ProcTPs.GetAllLim()); List <TreatPlan> listSavedTreatPlans = ReportsComplex.RunFuncOnReportServer(() => TreatPlans.GetAllSavedLim()); List <ProcTpTreatPlan> listProcTPTreatPlans = new List <ProcTpTreatPlan>(); listProcTPsAll.ForEach(x => { listProcTPTreatPlans.Add(new ProcTpTreatPlan() { TreatPlanCur = listSavedTreatPlans.First(y => y.TreatPlanNum == x.TreatPlanNum), ProcTPCur = x }); }); //get one entry per procedure with their first/last date of presentation based on radio buttons. if (isFirstPresented) { listProcTPTreatPlans = listProcTPTreatPlans .OrderBy(x => x.ProcTPCur.ProcNumOrig) .ThenBy(x => x.TreatPlanCur.DateTP) .ThenBy(x => x.TreatPlanCur.TreatPlanNum) .GroupBy(x => x.ProcTPCur.ProcNumOrig) .Select(x => x.First()) .ToList(); } else { listProcTPTreatPlans = listProcTPTreatPlans .OrderBy(x => x.ProcTPCur.ProcNumOrig) .ThenByDescending(x => x.TreatPlanCur.DateTP) .ThenBy(x => x.TreatPlanCur.TreatPlanNum) .GroupBy(x => x.ProcTPCur.ProcNumOrig) .Select(x => x.First()) .ToList(); } //get rid of any entries that are outside the range selected. listProcTPTreatPlans = listProcTPTreatPlans.Where(x => x.TreatPlanCur.DateTP.Date >= dateStart && x.TreatPlanCur.DateTP.Date <= dateEnd).ToList(); //Get the associated procedures, claimprocs, adjustments, users, appointments. List <Procedure> listProcsForTreatPlans = ReportsComplex.RunFuncOnReportServer(() => Procedures.GetForProcTPs(listProcTPTreatPlans.Select(x => x.ProcTPCur).ToList(), ProcStat.C, ProcStat.TP)); if (hasClinicsEnabled && !hasAllClinics) { listProcsForTreatPlans = listProcsForTreatPlans.FindAll(x => listClinicNums.Contains(x.ClinicNum)); } List <ClaimProc> listClaimProcs = ReportsComplex.RunFuncOnReportServer(() => ClaimProcs.GetForProcsLimited(listProcsForTreatPlans.Select(x => x.ProcNum).ToList(), ClaimProcStatus.CapComplete, ClaimProcStatus.NotReceived, ClaimProcStatus.Received, ClaimProcStatus.Supplemental, ClaimProcStatus.Estimate)); List <Adjustment> listAdjustments = ReportsComplex.RunFuncOnReportServer(() => Adjustments.GetForProcs(listProcsForTreatPlans.Select(x => x.ProcNum).ToList())); List <Userod> listUserods = ReportsComplex.RunFuncOnReportServer(() => Userods.GetAll()); List <TreatPlanPresenterEntry> listTreatPlanPresenterEntries = new List <TreatPlanPresenterEntry>(); List <ProcedureCode> listProcCodes = ReportsComplex.RunFuncOnReportServer(() => ProcedureCodes.GetCodesForCodeNums(listProcsForTreatPlans.Select(x => x.CodeNum).ToList())); List <Appointment> listApts = ReportsComplex.RunFuncOnReportServer(() => Appointments.GetMultApts(listProcsForTreatPlans.Select(x => x.AptNum).ToList())); double amt = listProcsForTreatPlans.Sum(x => x.ProcFee); foreach (Procedure procCur in listProcsForTreatPlans) { double grossProd = procCur.ProcFeeTotal; double writeOffs = listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum) .Where(x => x.Status == ClaimProcStatus.CapComplete) .Sum(x => x.WriteOff); grossProd -= writeOffs; if (procCur.ProcStatus == ProcStat.C) { writeOffs += listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum) .Where(x => x.Status.In(ClaimProcStatus.NotReceived, ClaimProcStatus.Received, ClaimProcStatus.Supplemental)) .Sum(x => x.WriteOff); } else { foreach (ClaimProc claimProcCur in listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum).Where(x => x.Status == ClaimProcStatus.Estimate)) { if (claimProcCur.WriteOffEstOverride == -1) { if (claimProcCur.WriteOffEst != -1) { writeOffs += claimProcCur.WriteOffEst; } } else { writeOffs += claimProcCur.WriteOffEstOverride; } } //writeOffs += listClaimProcs.Where(x => x.ProcNum == procCur.ProcNum) // .Where(x => x.Status == ClaimProcStatus.Estimate) // .Sum(x => x.WriteOffEstOverride == -1 ? (x.WriteOffEst == -1 ? 0 : x.WriteOffEst) : x.WriteOffEstOverride); //Allen won't let me commit this nested ternary :( } double adjustments = listAdjustments.Where(x => x.ProcNum == procCur.ProcNum).Sum(x => x.AdjAmt); double netProd = grossProd - writeOffs + adjustments; TreatPlan treatPlanCur = listProcTPTreatPlans.Where(x => x.ProcTPCur.ProcNumOrig == procCur.ProcNum).First().TreatPlanCur; Userod userPresenter; if (isPresenter) { userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.UserNumPresenter); } else //radioEntryUser { userPresenter = listUserods.FirstOrDefault(x => x.UserNum == treatPlanCur.SecUserNumEntry); } ProcedureCode procCode = listProcCodes.First(x => x.CodeNum == procCur.CodeNum); Appointment aptCur = listApts.FirstOrDefault(x => x.AptNum == procCur.AptNum); listTreatPlanPresenterEntries.Add(new TreatPlanPresenterEntry() { Presenter = userPresenter == null ? "" : userPresenter.UserName, DatePresented = treatPlanCur.DateTP, DateCompleted = procCur.ProcDate, ProcDescript = procCode.Descript, GrossProd = grossProd, Adjustments = adjustments, WriteOffs = writeOffs, NetProd = netProd, UserNumPresenter = userPresenter == null?0:userPresenter.UserNum, PresentedClinic = procCur.ClinicNum, ProcStatus = procCur.ProcStatus, TreatPlanNum = treatPlanCur.TreatPlanNum, AptNum = procCur.AptNum, AptStatus = aptCur == null?ApptStatus.None:aptCur.AptStatus }); } DataTable table = new DataTable(); table.Columns.Add("Presenter"); table.Columns.Add("# of Plans"); table.Columns.Add("# of Procs"); table.Columns.Add("# of ProcsSched"); table.Columns.Add("# of ProcsComp"); if (isGross) { table.Columns.Add("GrossTPAmt"); table.Columns.Add("GrossSchedAmt"); table.Columns.Add("GrossCompAmt"); } else { table.Columns.Add("NetTpAmt"); table.Columns.Add("NetSchedAmt"); table.Columns.Add("NetCompAmt"); } if (!hasAllUsers) { listTreatPlanPresenterEntries = listTreatPlanPresenterEntries.Where(x => listUserNums.Contains(x.UserNumPresenter)).ToList(); } listTreatPlanPresenterEntries = listTreatPlanPresenterEntries.OrderBy(x => x.Presenter).ToList(); listTreatPlanPresenterEntries .GroupBy(x => x.Presenter).ToList().ForEach(x => { DataRow row = table.NewRow(); row["Presenter"] = x.First().Presenter == "" ? "None" : x.First().Presenter; row["# of Plans"] = x.GroupBy(y => y.TreatPlanNum).Count(); row["# of Procs"] = x.Count(); row["# of ProcsSched"] = x.Count(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled); row["# of ProcsComp"] = x.Count(y => y.ProcStatus == ProcStat.C); if (isGross) { row["GrossTpAmt"] = x.Sum(y => y.GrossProd); row["GrossSchedAmt"] = x.Where(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled).Sum(y => y.GrossProd); row["GrossCompAmt"] = x.Where(y => y.ProcStatus == ProcStat.C).Sum(y => y.GrossProd); } else { row["NetTpAmt"] = x.Sum(y => y.NetProd); row["NetSchedAmt"] = x.Where(y => y.ProcStatus == ProcStat.TP && y.AptNum != 0 && y.AptStatus == ApptStatus.Scheduled).Sum(y => y.NetProd); row["NetCompAmt"] = x.Where(y => y.ProcStatus == ProcStat.C).Sum(y => y.NetProd); } table.Rows.Add(row); }); //DataTable table=ReportsComplex.RunFuncOnReportServer(() => ReportsComplex.GetTable(query)); return(table); }
///<summary>(HQ Only) Automatically creates or updates a sales tax adjustment for the passted in procedure. If an adjustment is passed in, we go ///ahead and update that adjustment, otherwise we check if there is already a sales tax adjustment for the given procedure and if not, we create ///a new one. Pass in false to doCalcTax if we have already called the AvaTax API to get the tax estimate recently to avoid redundant calls ///(currently only pre-payments uses this flag). ///isRepeatCharge indicates if the adjustment is being inserted by the repeat charge tool, currently only used to supress error messages ///in the Avatax API.</summary> public static void CreateOrUpdateSalesTaxIfNeeded(Procedure procedure, Adjustment salesTaxAdj = null, bool doCalcTax = true, bool isRepeatCharge = false) { if (!AvaTax.DoSendProcToAvalara(procedure, isRepeatCharge)) //tests isHQ { return; } //Check for middle tier as crud is called below if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), procedure, salesTaxAdj, doCalcTax, isRepeatCharge); return; } if (salesTaxAdj == null) { salesTaxAdj = Adjustments.GetSalesTaxForProc(procedure.ProcNum); } //If we didn't find any existing adjustments to modify, create an adjustment instead if (salesTaxAdj == null) { salesTaxAdj = new Adjustment(); salesTaxAdj.DateEntry = DateTime.Today; salesTaxAdj.AdjDate = procedure.ProcDate; salesTaxAdj.ProcDate = procedure.ProcDate; salesTaxAdj.ProvNum = procedure.ProvNum; salesTaxAdj.PatNum = procedure.PatNum; salesTaxAdj.AdjType = AvaTax.SalesTaxAdjType; salesTaxAdj.ClinicNum = procedure.ClinicNum; salesTaxAdj.ProcNum = procedure.ProcNum; } //if the sales tax adjustment is locked, create a sales tax refund adjustment instead if (procedure.ProcDate <= AvaTax.TaxLockDate) { CreateSalesTaxRefundIfNeeded(procedure, salesTaxAdj); return; } if (!doCalcTax) //Should only ever happen for pre-payments, where we've already called the api to get the tax amount { salesTaxAdj.AdjAmt = procedure.TaxAmt; Insert(salesTaxAdj); } else if (AvaTax.DidUpdateAdjustment(procedure, salesTaxAdj)) { string note = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ": Tax amount changed from $" + procedure.TaxAmt.ToString("f2") + " to $" + salesTaxAdj.AdjAmt.ToString("f2"); if (!(procedure.TaxAmt - salesTaxAdj.AdjAmt).IsZero()) { procedure.TaxAmt = salesTaxAdj.AdjAmt; Crud.ProcedureCrud.Update(procedure); } if (salesTaxAdj.AdjNum == 0) { //The only way to get salesTaxAdj.AdjAmt=0 when AvaTax.DidUpdateAdjustment() returns true is if there was an error. if (isRepeatCharge && salesTaxAdj.AdjAmt == 0) //this is an error; we would normally not save a new adjustment with amt $0 { throw new ODException("Encountered an error communicating with AvaTax. Skip for repeating charges only. " + salesTaxAdj.AdjNote); } Insert(salesTaxAdj); //This could be an error or a new adjustment/repeating charge, either way we want to insert } else //updating an existing adjustment. We don't need to check isRepeatCharge because of { if (!string.IsNullOrWhiteSpace(salesTaxAdj.AdjNote)) { salesTaxAdj.AdjNote += Environment.NewLine; } salesTaxAdj.AdjNote += note; //If we are updating this adjustment, leave a note indicating what changed Update(salesTaxAdj); } } TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(salesTaxAdj); }