Esempio n. 1
0
        ///<summary></summary>
        public static double GetTotTaxForProc(Procedure proc)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetDouble(MethodBase.GetCurrentMethod(), proc));
            }
            if (!AvaTax.DoSendProcToAvalara(proc))
            {
                return(0);
            }
            string command = "SELECT SUM(AdjAmt) FROM adjustment"
                             + " WHERE ProcNum=" + POut.Long(proc.ProcNum)
                             + " AND AdjType IN (" + string.Join(",", POut.Long(AvaTax.SalesTaxAdjType), POut.Long(AvaTax.SalesTaxReturnAdjType)) + ")";

            return(PIn.Double(Db.GetScalar(command)));
        }
Esempio n. 2
0
 ///<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);
 }