protected void Page_Load(object sender, EventArgs e) { try { bool success = false; string reason = String.Empty; if (!AppLogic.AppConfigBool("AvalaraTax.Enabled")) { ResultLabel.Text = "AvaTax is not enabled. Enable AvaTax by setting the AvalaraTax.Enabled AppConfig to True."; } else { AvaTax avaTax = new AvaTax(); success = avaTax.TestAddin(out reason); if (success) { ResultLabel.Text = "Successfully connected to AvaTax."; } else if (String.IsNullOrEmpty(reason)) { ResultLabel.Text = "AvaTax connection was not successful. Please review your configuration."; } else { ResultLabel.Text = String.Format("AvaTax connection was not successful. AvaTax returned the following message: {0}", reason); } } } catch (Exception exception) { ResultLabel.Text = "Connection test failed due to an exception:<br />" + exception.ToString().Replace("\n", "<br />"); } }
private void butOK_Click(object sender, EventArgs e) { if (!CheckBeginDateTime()) { return; } //If the AvaTax API is not available at HQ show popup and return. if (AvaTax.IsEnabled() && !AvaTax.PingAvaTax()) { MsgBox.Show(this, "Unable to connect to AvaTax API."); return; } Cursor = Cursors.WaitCursor; RepeatChargeResult result = RepeatCharges.RunRepeatingCharges(MiscData.GetNowDateTime(), checkRunAging.Checked); string metrics = result.ProceduresAddedCount + " " + Lan.g(this, "procedures added.") + "\r\n" + result.ClaimsAddedCount + " " + Lan.g(this, "claims added."); SecurityLogs.MakeLogEntry(Permissions.RepeatChargeTool, 0, "Repeat Charge Tool ran.\r\n" + metrics); Cursor = Cursors.Default; MessageBox.Show(metrics); if (!string.IsNullOrEmpty(result.ErrorMsg)) { SecurityLogs.MakeLogEntry(Permissions.RepeatChargeTool, 0, "Repeat Charge Tool Error: " + result.ErrorMsg); MessageBox.Show(result.ErrorMsg); } DialogResult = DialogResult.OK; }
AvaTaxRate ObjectBuilder(AvaTaxRateCacheContext objectContext) { var cart = CachedShoppingCartProvider.Get(objectContext.Customer, CartTypeEnum.ShoppingCart, objectContext.StoreId); var taxRate = new AvaTax().GetTaxRate(objectContext.Customer, cart.CartItems, cart.OrderOptions); return(new AvaTaxRate(objectContext.Customer, objectContext.StoreId, objectContext.CartType, taxRate)); }
private void butPing_Click(object sender, EventArgs e) { if (AvaTax.IsApiAvailable(radioProdEnv.Checked, textUsername.Text, textPassword.Text)) { MsgBox.Show(this, "Success connecting to API."); } else { MsgBox.Show(this, "Failure connecting to API. Check that username and password are correct."); } }
///<summary>Calls Avalara to get an estimated sales tax for each charge.</summary> private void GetTaxEstimates(List <ProcedureCharge> listCharges, bool isPrepaymentList = true) { foreach (ProcedureCharge procCharge in listCharges) { //Prevents getting tax estimates on previously completed procedures that were not taxed in the first place. if (isPrepaymentList || procCharge.HasTaxAdjustment) { procCharge.EstTax = (double)AvaTax.GetEstimate(procCharge.ProcCode.CodeNum, _patCur.PatNum, procCharge.ProcFee - procCharge.ProcDiscount); procCharge.Calc(); } } }
public AddressValidationResult Validate(Address address, AddressTypes addressType = AddressTypes.Unknown) { if (address.Country != "United States") // Avalara doesn't validate other countries { return(new AddressValidationResult()); } var correctedAddress = new Address(); correctedAddress.LoadFromDB(address.AddressID); try { var result = new AvaTax() .ValidateAddress( customer: AppLogic.GetCurrentCustomer(), inputAddress: address, ResultAddress: out correctedAddress); if (string.IsNullOrEmpty(result)) { return(new AddressValidationResult( correctedAddresses: new[] { correctedAddress })); } else { return(new AddressValidationResult( status: AddressValidationStatus.Failure, message: result, correctedAddresses: new[] { correctedAddress })); } } catch (Exception exception) { return(new AddressValidationResult( status: AddressValidationStatus.Failure, message: exception.Message)); } }
/// <summary> /// Validate Address using Avalara Validation. /// </summary> /// <param name="EnteredAddress">The address as entered by a customer</param> /// <param name="ResultAddress">The resulting validated address</param> /// <returns>String, /// ro_OK => ResultAddress = EnteredAddress proceed with no further user review, /// 'some message' => address requires edit or verification by customer /// </returns> public String avalaraValidate(Address EnteredAddress, out Address ResultAddress) { string result = AppLogic.ro_OK; ResultAddress = new Address(); ResultAddress.LoadFromDB(EnteredAddress.AddressID); if (EnteredAddress.Country != "United States") { // Avalara doesn't validate other countries return(AppLogic.ro_OK); } Customer thisCustomer = AppLogic.GetCurrentCustomer(); var AvalaraValidate = new AvaTax(); result = AvalaraValidate.ValidateAddress(thisCustomer, EnteredAddress, out ResultAddress); return(result == String.Empty ? AppLogic.ro_OK : result); }
protected void Page_Load(object sender, EventArgs e) { btnCloseTop.DataBind(); if (!Page.IsPostBack) { try { var success = false; var reason = string.Empty; if (!AppLogic.AppConfigBool("AvalaraTax.Enabled")) { ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.avalara.NotEnabled"), AlertMessage.AlertType.Warning); } else { var avaTax = new AvaTax(); success = avaTax.TestAddin(out reason); if (success) { ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.avalara.TestSuccess"), AlertMessage.AlertType.Success); } else if (string.IsNullOrEmpty(reason)) { ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.avalara.TestFailureGeneric"), AlertMessage.AlertType.Error); } else { ctlAlertMessage.PushAlertMessage(string.Format(AppLogic.GetString("admin.avalara.TestFailureError"), reason), AlertMessage.AlertType.Error); } } } catch (Exception exception) { ctlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.avalara.TestFailureException") + exception.ToString().Replace("\n", "<br />"), AlertMessage.AlertType.Error); } } }
private void FormAdjust_Load(object sender, System.EventArgs e) { if (AvaTax.IsEnabled()) { //We do not want to allow the user to make edits or delete SalesTax and SalesTaxReturn Adjustments. Popup if no permission so user knows why disabled. if (AvaTax.IsEnabled() && (_adjustmentCur.AdjType == AvaTax.SalesTaxAdjType || _adjustmentCur.AdjType == AvaTax.SalesTaxReturnAdjType) && !Security.IsAuthorized(Permissions.SalesTaxAdjEdit)) { DisableForm(textNote, butCancel); textNote.ReadOnly = true; //This will allow the user to copy the note if desired. } } if (IsNew) { if (!Security.IsAuthorized(Permissions.AdjustmentCreate, true)) //Date not checked here. Message will show later. { if (!Security.IsAuthorized(Permissions.AdjustmentEditZero, true)) //Let user create an adjustment of zero if they have this perm. { MessageBox.Show(Lans.g("Security", "Not authorized for") + "\r\n" + GroupPermissions.GetDesc(Permissions.AdjustmentCreate)); DialogResult = DialogResult.Cancel; return; } //Make sure amount is 0 after OK click. _checkZeroAmount = true; } } else { if (!Security.IsAuthorized(Permissions.AdjustmentEdit, _adjustmentCur.AdjDate)) { butOK.Enabled = false; butDelete.Enabled = false; //User can't edit but has edit zero amount perm. Allow delete only if date is today. if (Security.IsAuthorized(Permissions.AdjustmentEditZero, true) && _adjustmentCur.AdjAmt == 0 && _adjustmentCur.DateEntry.Date == MiscData.GetNowDateTime().Date) { butDelete.Enabled = true; } } bool isAttachedToPayPlan = PayPlanLinks.GetForFKeyAndLinkType(_adjustmentCur.AdjNum, PayPlanLinkType.Adjustment).Count > 0; _listSplitsForAdjustment = PaySplits.GetForAdjustments(new List <long>() { _adjustmentCur.AdjNum }); if (_listSplitsForAdjustment.Count > 0 || isAttachedToPayPlan) { butAttachProc.Enabled = false; butDetachProc.Enabled = false; labelProcDisabled.Visible = true; } //Do not let the user change the adjustment type if the current adjustment is a "discount plan" adjustment type. if (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "dp") { labelAdditions.Text = Lan.g(this, "Discount Plan") + ": " + Defs.GetName(DefCat.AdjTypes, _adjustmentCur.AdjType); labelSubtractions.Visible = false; listTypePos.Visible = false; listTypeNeg.Visible = false; } } textDateEntry.Text = _adjustmentCur.DateEntry.ToShortDateString(); textAdjDate.Text = _adjustmentCur.AdjDate.ToShortDateString(); textProcDate.Text = _adjustmentCur.ProcDate.ToShortDateString(); if (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "+") //pos { textAmount.Text = _adjustmentCur.AdjAmt.ToString("F"); } else if (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "-") //neg { textAmount.Text = (-_adjustmentCur.AdjAmt).ToString("F"); //shows without the neg sign } else if (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "dp") //Discount Plan (neg) { textAmount.Text = (-_adjustmentCur.AdjAmt).ToString("F"); //shows without the neg sign } comboClinic.SelectedClinicNum = _adjustmentCur.ClinicNum; comboProv.SetSelectedProvNum(_adjustmentCur.ProvNum); FillComboProv(); if (_adjustmentCur.ProcNum != 0 && PrefC.GetInt(PrefName.RigorousAdjustments) == (int)RigorousAdjustments.EnforceFully) { comboProv.Enabled = false; butPickProv.Enabled = false; comboClinic.Enabled = false; if (Security.IsAuthorized(Permissions.Setup, true)) { labelEditAnyway.Visible = true; butEditAnyway.Visible = true; } } //prevents FillProcedure from being called too many times. Event handlers hooked back up after the lists are filled. listTypeNeg.SelectedIndexChanged -= listTypeNeg_SelectedIndexChanged; listTypePos.SelectedIndexChanged -= listTypePos_SelectedIndexChanged; List <Def> adjCat = Defs.GetDefsForCategory(DefCat.AdjTypes, true); //Positive adjustment types _listAdjPosCats = adjCat.FindAll(x => x.ItemValue == "+"); _listAdjPosCats.ForEach(x => listTypePos.Items.Add(x.ItemName)); listTypePos.SelectedIndex = _listAdjPosCats.FindIndex(x => x.DefNum == _adjustmentCur.AdjType); //can be -1 //Negative adjustment types _listAdjNegCats = adjCat.FindAll(x => x.ItemValue == "-"); _listAdjNegCats.ForEach(x => listTypeNeg.Items.Add(x.ItemName)); listTypeNeg.SelectedIndex = _listAdjNegCats.FindIndex(x => x.DefNum == _adjustmentCur.AdjType);//can be -1 listTypeNeg.SelectedIndexChanged += listTypeNeg_SelectedIndexChanged; listTypePos.SelectedIndexChanged += listTypePos_SelectedIndexChanged; FillProcedure(); textNote.Text = _adjustmentCur.AdjNote; }
private void butOK_Click(object sender, System.EventArgs e) { bool isDiscountPlanAdj = (Defs.GetValue(DefCat.AdjTypes, _adjustmentCur.AdjType) == "dp"); if (textAdjDate.errorProvider1.GetError(textAdjDate) != "" || textProcDate.errorProvider1.GetError(textProcDate) != "" || textAmount.errorProvider1.GetError(textAmount) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } if (PIn.Date(textAdjDate.Text).Date > DateTime.Today.Date && !PrefC.GetBool(PrefName.FutureTransDatesAllowed)) { MsgBox.Show(this, "Adjustment date can not be in the future."); return; } if (textAmount.Text == "") { MessageBox.Show(Lan.g(this, "Please enter an amount.")); return; } if (!isDiscountPlanAdj && listTypeNeg.SelectedIndex == -1 && listTypePos.SelectedIndex == -1) { MsgBox.Show(this, "Please select a type first."); return; } if (IsNew && AvaTax.IsEnabled() && listTypePos.SelectedIndex > -1 && (_listAdjPosCats[listTypePos.SelectedIndex].DefNum == AvaTax.SalesTaxAdjType || _listAdjPosCats[listTypePos.SelectedIndex].DefNum == AvaTax.SalesTaxReturnAdjType) && !Security.IsAuthorized(Permissions.SalesTaxAdjEdit)) { return; } if (PrefC.GetInt(PrefName.RigorousAdjustments) == 0 && _adjustmentCur.ProcNum == 0) { MsgBox.Show(this, "You must attach a procedure to the adjustment."); return; } if (_adjRemAmt < 0) { if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "Remaining amount is negative. Continue?", "Overpaid Procedure Warning")) { return; } } bool changeAdjSplit = false; List <PaySplit> listPaySplitsForAdjust = new List <PaySplit>(); if (IsNew) { //prevents backdating of initial adjustment if (!Security.IsAuthorized(Permissions.AdjustmentCreate, PIn.Date(textAdjDate.Text), true)) //Give message later. { if (!_checkZeroAmount) //Let user create as long as Amount is zero and has edit zero permissions. This was checked on load. { MessageBox.Show(Lans.g("Security", "Not authorized for") + "\r\n" + GroupPermissions.GetDesc(Permissions.AdjustmentCreate)); return; } } } else { //Editing an old entry will already be blocked if the date was too old, and user will not be able to click OK button //This catches it if user changed the date to be older. if (!Security.IsAuthorized(Permissions.AdjustmentEdit, PIn.Date(textAdjDate.Text))) { return; } if (_adjustmentCur.ProvNum != comboProv.GetSelectedProvNum()) { listPaySplitsForAdjust = PaySplits.GetForAdjustments(new List <long>() { _adjustmentCur.AdjNum }); foreach (PaySplit paySplit in listPaySplitsForAdjust) { if (!Security.IsAuthorized(Permissions.PaymentEdit, Payments.GetPayment(paySplit.PayNum).PayDate)) { return; } if (comboProv.GetSelectedProvNum() != paySplit.ProvNum && PrefC.GetInt(PrefName.RigorousAccounting) == (int)RigorousAdjustments.EnforceFully) { changeAdjSplit = true; break; } } if (changeAdjSplit && !MsgBox.Show(this, MsgBoxButtons.OKCancel, "The provider for the associated payment splits will be changed to match the provider on the " + "adjustment.")) { return; } } } //DateEntry not allowed to change DateTime datePreviousChange = _adjustmentCur.SecDateTEdit; _adjustmentCur.AdjDate = PIn.Date(textAdjDate.Text); _adjustmentCur.ProcDate = PIn.Date(textProcDate.Text); _adjustmentCur.ProvNum = comboProv.GetSelectedProvNum(); _adjustmentCur.ClinicNum = comboClinic.SelectedClinicNum; if (listTypePos.SelectedIndex != -1) { _adjustmentCur.AdjType = _listAdjPosCats[listTypePos.SelectedIndex].DefNum; _adjustmentCur.AdjAmt = PIn.Double(textAmount.Text); } if (listTypeNeg.SelectedIndex != -1) { _adjustmentCur.AdjType = _listAdjNegCats[listTypeNeg.SelectedIndex].DefNum; _adjustmentCur.AdjAmt = -PIn.Double(textAmount.Text); } if (isDiscountPlanAdj) { //AdjustmentCur.AdjType is already set to a "discount plan" adj type. _adjustmentCur.AdjAmt = -PIn.Double(textAmount.Text); } if (_checkZeroAmount && _adjustmentCur.AdjAmt != 0) { MsgBox.Show(this, "Amount has to be 0.00 due to security permission."); return; } _adjustmentCur.AdjNote = textNote.Text; try{ if (IsNew) { Adjustments.Insert(_adjustmentCur); SecurityLogs.MakeLogEntry(Permissions.AdjustmentCreate, _adjustmentCur.PatNum, _patCur.GetNameLF() + ", " + _adjustmentCur.AdjAmt.ToString("c")); TsiTransLogs.CheckAndInsertLogsIfAdjTypeExcluded(_adjustmentCur, _isTsiAdj); } else { Adjustments.Update(_adjustmentCur); SecurityLogs.MakeLogEntry(Permissions.AdjustmentEdit, _adjustmentCur.PatNum, _patCur.GetNameLF() + ", " + _adjustmentCur.AdjAmt.ToString("c"), 0 , datePreviousChange); } } catch (Exception ex) { //even though it doesn't currently throw any exceptions MessageBox.Show(ex.Message); return; } if (changeAdjSplit) { PaySplits.UpdateProvForAdjust(_adjustmentCur, listPaySplitsForAdjust); } DialogResult = DialogResult.OK; }
///<summary>Create completed ProcedureLogs from prepayment grid.</summary> private void CreateProcedureLogs() { Dictionary <ProcedureCode, List <AvaTax.TransQtyAmt> > dictTransactions = new Dictionary <ProcedureCode, List <AvaTax.TransQtyAmt> >(); List <ProcedureCharge> listMatchingProcCharges = new List <ProcedureCharge>(); //Go through our list of support codes and get all procedurecharges relating to the given code. foreach (ProcedureCode ProcCode in _listPrePaySupportCodes) { listMatchingProcCharges = _listProcedureCharge.FindAll(x => x.ProcCode == ProcCode); if (listMatchingProcCharges.Count == 0) { continue; } List <AvaTax.TransQtyAmt> listTransQtyAmt = new List <AvaTax.TransQtyAmt>(); foreach (ProcedureCharge procCharge in listMatchingProcCharges) { listTransQtyAmt.Add(new AvaTax.TransQtyAmt(procCharge.ProcCount, procCharge.BaseFee)); } dictTransactions.Add(ProcCode, listTransQtyAmt); //Zero out related repeat charges. ZeroOutRepeatingCharge(ProcCode, listTransQtyAmt); //Create procedures and adjustments without calling AvaTax API if the current patient is not taxable. if (!AvaTax.IsTaxable(_patCur.PatNum)) { 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 }; foreach (ProcedureCharge procCharge in listMatchingProcCharges) { procCur.BillingNote += $"Rate: ${POut.Double(procCharge.BaseFee)} Months: {POut.Int(procCharge.ProcCount)}\r\n"; } procCur.BillingNote += _prepaidThroughNote; List <Procedure> listMatchingCompletedProcs = _listCompletedProcs.FindAll(x => x.CodeNum == ProcCode.CodeNum); int monthsPrepayed = listMatchingProcCharges.Sum(x => x.ProcCount) + listMatchingCompletedProcs.Count(); procCur.ProcFee = listMatchingProcCharges.Sum(x => x.ProcFee); procCur.ProcNum = Procedures.Insert(procCur); if (monthsPrepayed >= 6 && AvaTax.ListDiscountProcCodes.Exists(x => x.ProcCode == ProcedureCodes.GetProcCode(procCur.CodeNum).ProcCode)) { //Create a discount adjustment for prepayments. if (monthsPrepayed >= 6 && monthsPrepayed <= 11) { AvaTax.CreateDiscountAdjustment(procCur, .05, 255); //5% discount. Hard coded ODHQ defnum. } else if (monthsPrepayed >= 12 && monthsPrepayed <= 23) { AvaTax.CreateDiscountAdjustment(procCur, .10, 206); //10% discount. Hard coded ODHQ defnum. } else if (monthsPrepayed >= 24) { AvaTax.CreateDiscountAdjustment(procCur, .15, 229); //15% discount. Hard coded ODHQ defnum. } //Create adjustments for the previously completed procedures. foreach (Procedure proc in listMatchingCompletedProcs) { if (monthsPrepayed >= 6 && monthsPrepayed <= 11) { AvaTax.CreateDiscountAdjustment(proc, .05, 255); //5% discount. Hard coded ODHQ defnum. } else if (monthsPrepayed >= 12 && monthsPrepayed <= 23) { AvaTax.CreateDiscountAdjustment(proc, .10, 206); //10% discount. Hard coded ODHQ defnum. } else if (monthsPrepayed >= 24) { AvaTax.CreateDiscountAdjustment(proc, .15, 229); //15% discount. Hard coded ODHQ defnum. } } } } } if (AvaTax.IsTaxable(_patCur.PatNum)) { try { AvaTax.CreatePrepaymentTransaction(dictTransactions, _patCur, _listCompletedProcs); } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Error sending procedures to AvaTax.") + "\r\n" + ex.ToString()); } } }