///<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 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); }