Example #1
0
        ///<summary>Creates a bulk estimate currently specifically for the pre-payment tool.  Takes in a special dictionary of procedurecodes mapped
        ///to a list of tuples containing the qty and single item prices for the provided procedure codes, then builds a single transaction to
        ///hold the data.  This method creates its own procedures and adjustments.</summary>
        public static void CreatePrepaymentTransaction(Dictionary <ProcedureCode, List <TransQtyAmt> > dictProcCodes, Patient patCur, List <Procedure> listCompletedProcs)
        {
            Dictionary <Procedure, int> dictProcsToCreate = new Dictionary <Procedure, int>();
            //Build the transaction for all of the items in a single transaction.
            TransactionBuilder builder = SetUpTransaction(DocumentType.SalesOrder, patCur.PatNum);         //Sales Order is AvaTax's way of getting an estimate

            foreach (ProcedureCode procCode in dictProcCodes.Keys)
            {
                Procedure procCur = new Procedure()
                {
                    PatNum       = patCur.PatNum,
                    ProvNum      = 7,             //HQ only this is jordan's provNum.
                    ProcDate     = DateTime.Today,
                    DateEntryC   = DateTime.Now,
                    DateComplete = DateTime.Now,
                    CodeNum      = procCode.CodeNum,
                    ProcStatus   = ProcStat.C
                };
                int totalCount = 0;
                foreach (TransQtyAmt pair in dictProcCodes[procCode])
                {
                    totalCount          += pair.qty;
                    procCur.BillingNote += "Rate: $" + POut.Double(pair.rate) + " Months: " + POut.Int(pair.qty) + "\r\n";
                    builder.WithLine(pair.qty * (decimal)pair.rate, (decimal)pair.qty,
                                     GetTaxOverrideIfNeeded(patCur, procCode), procCode.Descript, procCode.ProcCode);
                }
                //Add note for what day the customer has prepaid through.
                DateTime datePrepaidThrough = DateTimeOD.GetMostRecentValidDate(DateTime.Today.Year, DateTime.Today.Month, patCur.BillingCycleDay)
                                              .AddMonths(totalCount).AddDays(-1);
                if (DateTimeOD.Today.Day >= patCur.BillingCycleDay)
                {
                    datePrepaidThrough = datePrepaidThrough.AddMonths(1);
                }
                procCur.BillingNote += $"Prepaid through: {datePrepaidThrough.Date:MM/dd/yyyy}";
                dictProcsToCreate.Add(procCur, totalCount);
            }
            TransactionModel     result            = Client.CreateTransaction("Lines", builder.GetCreateTransactionModel());
            List <ProcedureCode> listDiscountCodes = AvaTax.ListDiscountProcCodes;

            //Create a single procedure and adjustment for each procCode.
            foreach (KeyValuePair <Procedure, int> entry in dictProcsToCreate)
            {
                //look for previously completed procedures that need to be included on the adjustment calculation.
                List <Procedure> listMatchingCompletedProcs = listCompletedProcs.FindAll(x => x.CodeNum == entry.Key.CodeNum);
                Procedure        procCur = entry.Key;
                int count = entry.Value + listMatchingCompletedProcs.Count();
                List <TransactionLineModel> listLines = result.lines.FindAll(x => x.itemCode.Equals(ProcedureCodes.GetProcCode(procCur.CodeNum).ProcCode));
                procCur.ProcFee = (double)listLines.Sum(x => x.lineAmount.Value);
                procCur.TaxAmt  = (double)listLines.Sum(x => x.tax.Value);
                procCur.ProcNum = Procedures.Insert(procCur, doCalcTax: false);
                if (count > 5 && listDiscountCodes.Exists(x => x.ProcCode == ProcedureCodes.GetProcCode(procCur.CodeNum).ProcCode))
                {
                    //Create a discount adjustment.
                    if (count >= 6 && count <= 11)
                    {
                        CreateDiscountAdjustment(procCur, .05, 255);                      //5% discount.  Hard coded ODHQ defnum.
                    }
                    else if (count >= 12 && count <= 23)
                    {
                        CreateDiscountAdjustment(procCur, .10, 206);                      //10% discount.  Hard coded ODHQ defnum.
                    }
                    else if (count >= 24)
                    {
                        CreateDiscountAdjustment(procCur, .15, 229);                      //15% discount.  Hard coded ODHQ defnum.
                    }
                    //Create adjustments for the previously completed procedures.
                    foreach (Procedure proc in listMatchingCompletedProcs)
                    {
                        if (count >= 6 && count <= 11)
                        {
                            CreateDiscountAdjustment(proc, .05, 255);                          //5% discount.  Hard coded ODHQ defnum.
                        }
                        else if (count >= 12 && count <= 23)
                        {
                            CreateDiscountAdjustment(proc, .10, 206);                          //10% discount.  Hard coded ODHQ defnum.
                        }
                        else if (count >= 24)
                        {
                            CreateDiscountAdjustment(proc, .15, 229);                          //15% discount.  Hard coded ODHQ defnum.
                        }
                    }
                }
            }
        }