From 7a4148c35dc543e4c57b5d404fa0b1384b7ddd99 Mon Sep 17 00:00:00 2001 From: Jason Woods Date: Tue, 2 Feb 2021 08:42:46 +1100 Subject: [PATCH 01/21] Cleanup and fixed JS errors --- .../addons/avatax_tax_calculation/addon.xml | 21 +- .../backend/avatax_tax_calculation.php | 148 +- .../addons/avatax_tax_calculation/func.php | 1735 ++++++++--------- .../design/backend/media/images/Thumbs.db | Bin 77312 -> 0 bytes 4 files changed, 916 insertions(+), 988 deletions(-) delete mode 100644 Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/media/images/Thumbs.db diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/addon.xml b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/addon.xml index 6d7170e..01a02ee 100644 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/addon.xml +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/addon.xml @@ -12,12 +12,11 @@
Sign in - - info - fn_avatax_tax_gen_info - - - + + info + fn_avatax_tax_gen_info + + input Account ID generated by AvaTax Account ID* @@ -47,8 +46,8 @@ info fn_avatax_tax_calculation_testconnection - - Company Name* + + Company Name* selectbox @@ -69,7 +68,7 @@ No - + Send UPC code to AvaTax radiogroup @@ -97,7 +96,7 @@ - + Enable AvaTax address validation radiogroup 0 @@ -138,7 +137,6 @@ - ALTER TABLE `?:status_descriptions` ADD status VARCHAR(1) NOT NULL; ALTER TABLE `?:status_descriptions` ADD type VARCHAR(1) NOT NULL; UPDATE `?:status_descriptions` SET status = 'A' , type = 'G' where description ='Active'; @@ -155,7 +153,6 @@ UPDATE `?:status_descriptions` SET status = 'P' , type = 'O' where description ='Processed'; UPDATE `?:status_descriptions` SET status = 'R' , type = 'R' where description ='Requested'; UPDATE `?:status_descriptions` SET status = 'U' , type = 'G' where description ='Used'; - ALTER TABLE `?:orders` ADD `avatax_paytax_document_id` INT NOT NULL DEFAULT '0', ADD `avatax_paytax_transaction_id` INT NOT NULL DEFAULT '0', ADD `avatax_paytax_document_code` VARCHAR( 40 ) NOT NULL, ADD `avatax_paytax_error_message` TEXT NOT NULL; ALTER TABLE `?:status_descriptions` ADD `avatax_document_status` VARCHAR( 30 ) NOT NULL; UPDATE `?:status_descriptions` SET avatax_document_status = 'Committed' where status ='C' and type = 'O'; diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/controllers/backend/avatax_tax_calculation.php b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/controllers/backend/avatax_tax_calculation.php index fa94757..ef8b477 100644 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/controllers/backend/avatax_tax_calculation.php +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/controllers/backend/avatax_tax_calculation.php @@ -14,85 +14,85 @@ use Tygh\Registry; - if (!defined('BOOTSTRAP')) { die('Access denied'); } -if ($mode == 'connection_test') { - - $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); - require_once($lib_path."AvaTax4PHP/avatax_test_connection.php"); - exit; -} -if ($mode == 'setup_assistant') { - - $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); - - require_once($lib_path."AvaTax4PHP/avatax_accounts.php"); - - if(isset($_REQUEST["from"]) && $_REQUEST["from"]=="AvaTaxFetchCompanies"){ +if ($_SERVER['REQUEST_METHOD'] == 'POST') { - - AccountValidation(); -} - exit; -} -if ($mode == 'config_log') { - $account=$_REQUEST["acc"]; - $license=$_REQUEST["license"]; - $serviceurl=$_REQUEST["serviceurl"]; - $companyCode=$_REQUEST["companyCode"]; - $environment=$_REQUEST["environment"]; - $client=$_REQUEST["client"]; - $isAvataxEnabled=$_REQUEST["isAvataxEnabled"]; - $isUPCOption =$_REQUEST["isUPCOption"]; - $isSaveTransaction=$_REQUEST["isSaveTransaction"]; - $isLogEnabled=$_REQUEST["isLogEnabled"]; - $isAddressValidation=$_REQUEST["isAddressValidation"]; + if ($mode == 'connection_test') { + $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + require_once($lib_path."AvaTax4PHP/avatax_test_connection.php"); + exit; + } + else if ($mode == 'setup_assistant') { - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - require_once($addon_path."/SystemLogger.php"); - // Creating the System Logger Object - $config_log = new SystemLogger; - $msgString='Connector Configuration -Account ID : '.$account.' License Key : '.$license.' ServiceURL : '.$serviceurl.' CompanyCode :'.$companyCode.' Environment : '.$environment.' Client : '.$client.' Is Avatax Enabled : '.$isAvataxEnabled; - $msgString .=' Is UPC Option Enabled: '.$isUPCOption.' Is Save Transaction Enabled: '.$isSaveTransaction.' Is Log Enabled: '.$isLogEnabled.' Is Address Validation Enabled: '.$isAddressValidation; - $timeStamp = new DateTime(); // Create Time Stamp + $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + + require_once($lib_path."AvaTax4PHP/avatax_accounts.php"); + + if(isset($_REQUEST["from"]) && $_REQUEST["from"]=="AvaTaxFetchCompanies"){ + AccountValidation(); + } + exit; + } + else if ($mode == 'config_log') { + $account=$_REQUEST["acc"]; + $license=$_REQUEST["license"]; + $serviceurl=$_REQUEST["serviceurl"]; + $companyCode=$_REQUEST["companyCode"]; + $environment=$_REQUEST["environment"]; + $client=$_REQUEST["client"]; + $isAvataxEnabled=$_REQUEST["isAvataxEnabled"]; + $isUPCOption =$_REQUEST["isUPCOption"]; + $isSaveTransaction=$_REQUEST["isSaveTransaction"]; + $isLogEnabled=$_REQUEST["isLogEnabled"]; + $isAddressValidation=$_REQUEST["isAddressValidation"]; + + + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + require_once($addon_path."/SystemLogger.php"); + // Creating the System Logger Object + $config_log = new SystemLogger; + $msgString='Connector Configuration -Account ID : '.$account.' License Key : '.$license.' ServiceURL : '.$serviceurl.' CompanyCode :'.$companyCode.' Environment : '.$environment.' Client : '.$client.' Is Avatax Enabled : '.$isAvataxEnabled; + $msgString .=' Is UPC Option Enabled: '.$isUPCOption.' Is Save Transaction Enabled: '.$isSaveTransaction.' Is Log Enabled: '.$isLogEnabled.' Is Address Validation Enabled: '.$isAddressValidation; + $timeStamp = new DateTime(); // Create Time Stamp + + $connectorstart=$timeStamp->format('Y-m-d\TH:i:s').".".substr((string)microtime(), 2, 3)." ".$timeStamp->format("P"); + $performance_metrics[] = array("CallerTimeStamp","MessageString","CallerAcctNum","DocCode","Operation","ServiceURL","LogType","LogLevel","ERPName","ERPVersion","ConnectorVersion"); + $performance_metrics[] = array($connectorstart,$msgString,$account,"","Connector Configuration",$serviceurl,"Performance","Informational","CS-Cart",PRODUCT_VERSION,AVALARA_VERSION); + + //Call serviceLog function + $returnServiceLog = $config_log->serviceLog($performance_metrics); + //$config_log->writeConfigLog($account,$license,$serviceurl,$companyCode,$environment,$client,$isAvataxEnabled,$isUPCOption,$isSaveTransaction,$isLogEnabled,$isAddressValidation); + exit; + + } + else if ($mode == 'create_account') { - $connectorstart=$timeStamp->format('Y-m-d\TH:i:s').".".substr((string)microtime(), 2, 3)." ".$timeStamp->format("P"); - $performance_metrics[] = array("CallerTimeStamp","MessageString","CallerAcctNum","DocCode","Operation","ServiceURL","LogType","LogLevel","ERPName","ERPVersion","ConnectorVersion"); - $performance_metrics[] = array($connectorstart,$msgString,$account,"","Connector Configuration",$serviceurl,"Performance","Informational","CS-Cart",PRODUCT_VERSION,AVALARA_VERSION); + $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + include_once($lib_path."AvaTax4PHP/avatax_create_account.php"); + exit; + } + else if ($mode == 'tpa') { - //Call serviceLog function - $returnServiceLog = $config_log->serviceLog($performance_metrics); - //$config_log->writeConfigLog($account,$license,$serviceurl,$companyCode,$environment,$client,$isAvataxEnabled,$isUPCOption,$isSaveTransaction,$isLogEnabled,$isAddressValidation); - exit; + $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + include_once($lib_path."AvaTax4PHP/tpa.php"); + exit; + } + else if ($mode == 'validate_account') { -} -if ($mode == 'create_account') { - - $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); - include_once($lib_path."AvaTax4PHP/avatax_create_account.php"); - exit; -} -if ($mode == 'tpa') { - - $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); - include_once($lib_path."AvaTax4PHP/tpa.php"); - exit; -} -if ($mode == 'validate_account') { - - $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; - $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; - $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); - include_once($lib_path."AvaTax4PHP/avatax_validate_account.php"); - exit; -} + $lib_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation/lib/'; + $addon_path = Registry::get('config.dir.addons') . 'avatax_tax_calculation'; + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + include_once($lib_path."AvaTax4PHP/avatax_validate_account.php"); + exit; + } +} \ No newline at end of file diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/func.php b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/func.php index d77df79..40dacac 100644 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/func.php +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/app/addons/avatax_tax_calculation/func.php @@ -15,9 +15,9 @@ /*************************************************************************** * * * This source file was cleaned-up to meet the requirements for release * - * done by Avalara - on 02/20/2015 * - * File Version : * - * Last Updated On : 05/27/2016 * + * done by Avalara - on 02/20/2015 * + * File Version : * + * Last Updated On : 05/27/2016 * ***************************************************************************/ @@ -36,10 +36,10 @@ /*************************************************************************** * * - * Function Header * - * * - * File Version : * - * Last Updated On : 02/20/2015 * + * Function Header * + * * + * File Version : * + * Last Updated On : 02/20/2015 * * Description : This function allow user to test the connection * * between CS Cart and Avalara Admin Console. This * * action is performed after installing the AvaTax * @@ -48,519 +48,450 @@ function fn_avatax_tax_calculation_testconnection() { - $curPageURL = explode("?", curPageURL()); + $curPageURL = explode("?", curPageURL()); $text = ' - -
+ var accountVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value; + var licenseVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value; + var serviceURLVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value; + + var environment = serviceURLVal.indexOf("development") ? "Development" : "Production"; + var client = "'.CLIENT_NAME.'"; + + $.post("' . $curPageURL[0] . '?dispatch=avatax_tax_calculation.setup_assistant&from=AvaTaxFetchCompanies&acc="+accountVal+"&license="+licenseVal+"&serviceurl="+serviceURLVal+"&environment="+environment+"&client="+ client, {q: ""}, function(data) { + if (data.length > 0) { + var accountsData = JSON.parse(data); + $("[id^=\'addon_option_avatax_tax_calculation_select_codes\']").find("option").remove(); + var _select=""; + _select = $(" +
+ +
+
+ +
+ +
+ +
+
\ No newline at end of file diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/profiles/tax_exempt_number.pre.tpl b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/profiles/tax_exempt_number.pre.tpl deleted file mode 100644 index 26891fb..0000000 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/profiles/tax_exempt_number.pre.tpl +++ /dev/null @@ -1,18 +0,0 @@ -
- - -
- -
-
- -
- -
- -
-
\ No newline at end of file From 942d1585db4c5a01f086e274833a1a578f5296a8 Mon Sep 17 00:00:00 2001 From: Jason Woods Date: Thu, 4 Mar 2021 20:20:40 +1100 Subject: [PATCH 18/21] Fixed CS-Cart version compatibility --- README.md | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6b3af91..163f457 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,15 @@ The CS-Cart connector for AvaTax is a module that integrates the CS-Cart check-o

Compatibility

Avalara AvaTax for CS-Cart Version 00.00.12.00 is compatible with CS-Cart versions: -

-

    4.12.1
-
    4.3.8
-
    4.3.7
-
    4.3.6
-
    4.3.5
-
    4.3.4
-
    4.3.3
-
    4.3.2
-
    4.3.1
-
    4.2.3
-
    4.2.2
-
    4.2.1
-
    4.1.5
-
    4.1.4
-
    4.1.3
-
    4.0.2
-

+
    +
  • 4.12.2
  • +
  • 4.12.1
  • +
  • 4.11.5
  • +
  • 4.11.4
  • +
  • 4.11.3
  • +
  • 4.11.2
  • +
  • 4.11.1
  • +

Documentation

Release notes can be accessed here From c80bb0b84f1911b86ecd406a56fabd33baa4e8a8 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 25 Mar 2021 10:26:10 +1100 Subject: [PATCH 19/21] Set up CI with Azure Pipelines [skip ci] --- azure-pipelines.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..c861bff --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,19 @@ +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: ArchiveFiles@1 + inputs: + rootFolderOrFile: '$(Build.BinariesDirectory)' + includeRootFolder: false + archiveType: 'zip' + archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' + replaceExistingArchive: true +- task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(Build.ArtifactStagingDirectory)' + ArtifactName: 'AvaTax' + publishLocation: 'Container' \ No newline at end of file From c101e857b1abc4ab139600e9902e9fb7ad89d679 Mon Sep 17 00:00:00 2001 From: Jason Woods Date: Sun, 2 Jan 2022 14:31:05 +1100 Subject: [PATCH 20/21] Started moving scripts to external js file --- .../addons/avatax_tax_calculation/addon.xml | 14 +- .../addons/avatax_tax_calculation/func.php | 415 ++++-------------- .../hooks/index/scripts.post.tpl | 3 + .../js/addons/avatax_tax_calculation/index.js | 238 ++++++++++ 4 files changed, 340 insertions(+), 330 deletions(-) create mode 100644 Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/index/scripts.post.tpl create mode 100644 Avalara AvaTax for CS Cart version 00.00.11.00/js/addons/avatax_tax_calculation/index.js diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/addon.xml b/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/addon.xml index fba3243..bdab74f 100644 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/addon.xml +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/addon.xml @@ -45,12 +45,12 @@ - AvaTax Service - info - fn_avatax_tax_calculation_testconnection + AvaTax Service + info + fn_avatax_tax_calculation_testconnection - - Company Name* + + Company Name* selectbox @@ -70,7 +70,7 @@ No - + Send UPC code to AvaTax @@ -110,7 +110,7 @@ No - + Enable Log diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/func.php b/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/func.php index 2b72eaf..db84c17 100644 --- a/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/func.php +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/app/addons/avatax_tax_calculation/func.php @@ -51,247 +51,7 @@ function fn_avatax_tax_calculation_testconnection() $curPageURL = explode("?", curPageURL()); $text = '

@@ -329,92 +89,94 @@ function fn_avatax_tax_gen_info() { function fn_avatax_tax_calculation_TPA_link() { - $text = ' - '; + $("#AvaTaxTpaDialog").html(\'
Work In Progress...
Work In Progress...
\'); + + $.ajax({ + url:"?dispatch=avatax_tax_calculation.validate_account&security_hash="+Tygh.security_hash+"&acc="+accountVal+"&username="+consoleUserName+"&password="+consolePassword, + success: function(result1) { + var jsonValacc=JSON.parse(result1); + if (jsonValacc.Status=="Success") { + $.ajax({ + url:"?dispatch=avatax_tax_calculation.tpa&security_hash="+Tygh.security_hash+"&acc="+accountVal+"&license="+licenseVal+"&serviceurl="+serviceURLVal+"&companyCode="+companyCode+"&username="+consoleUserName+"&password="+consolePassword+"&erp=cscart&environment="+environment, + success: function(result) { + var json=JSON.parse(result); + var msg=""; + window.open( + json, + "_blank" // <- This is what makes it open in a new window. + ); + $("#AvaTaxTpaDialog").dialog( "close" ); + }, + async:false, + type : "POST" + }); + } else { + alert("Invalid AvaTax Username or Password!!!"); + $("#AvaTaxTpaDialog").dialog( "close" ); + } + }, + async: false, + type : "POST" + }); + } + }); + } + }); + '; - $text = $text.'
- -
Click here for AvaTax Tax Profile Assistant
Note: Nexus recommendations are based on the analysis of either your last 1000 transactions or your last 1 year\'s transactional data.
-
'; - $text=$text .'
'; return $text; } @@ -829,6 +591,13 @@ function fn_document_state_committed($order_info, $status_from) function fn_avatax_change_document_status($order_info, $status_to, $status_from, $order_id = 0) { + $log_mode = Registry::get('addons.avatax_tax_calculation.avatax_log_mode'); + if ($log_mode == 1) { + $e = new Exception(); + $application_log->AddSystemLog($timeStamp->format('Y-m-d H:i:s'), __FUNCTION__, __CLASS__, __METHOD__, __FILE__, '', $status_to, $e->getTraceAsString()); + $application_log->WriteSystemLogToFile(); + } + Switch ($status_to) { case 'P': //Processed fn_document_state_committed($order_info, $status_from); diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/index/scripts.post.tpl b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/index/scripts.post.tpl new file mode 100644 index 0000000..1936499 --- /dev/null +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/design/backend/templates/addons/avatax_tax_calculation/hooks/index/scripts.post.tpl @@ -0,0 +1,3 @@ +{if ($runtime.controller == "addons" && $runtime.mode == "update")} + {script src="js/addons/avatax_tax_calculation/index.js"} +{/if} \ No newline at end of file diff --git a/Avalara AvaTax for CS Cart version 00.00.11.00/js/addons/avatax_tax_calculation/index.js b/Avalara AvaTax for CS Cart version 00.00.11.00/js/addons/avatax_tax_calculation/index.js new file mode 100644 index 0000000..d1614a4 --- /dev/null +++ b/Avalara AvaTax for CS Cart version 00.00.11.00/js/addons/avatax_tax_calculation/index.js @@ -0,0 +1,238 @@ +$( document ).ready(function() { + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value != "") { + $("#avatax_tax_calculation_section2").hide(); + $("#signinInfo").hide(); + } + + $(".cm-dialog-closer").click(function() { + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value != "") { + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").hide(); + } + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value != "" + && document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value == "") { + alert("AvaTax Company Code should not be empty.\n Click On Test Connection to get Company Codes"); + return false; + } + }); + + $(".btn-primary").click(function() { + if (!validateFields()) { return false; } + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value == "") { + alert("AvaTax Company Code should not be empty.\n Click On Test Connection to get Company Codes"); + return false; + } else { + var accountVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value; + var licenseVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value; + var serviceURLVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value; + var isAvataxEnabled = $("[id^=\'addon_option_avatax_tax_calculation_avatax_tax_calculation\'] input[type=radio]:checked").val(); + var isUPCOption = $("[id^=\'addon_option_avatax_tax_calculation_avatax_tax_upc\'] input[type=radio]:checked").val(); + var isSaveTransaction = $("[id^=\'addon_option_avatax_tax_calculation_avatax_tax_savedoc\'] input[type=radio]:checked").val(); + var isAddressValidation = $("[id^=\'addon_option_avatax_tax_calculation_avatax_tax_address_validation\'] input[type=radio]:checked").val(); + var isLogEnabled = $("[id^=\'addon_option_avatax_tax_calculation_avatax_log_mode input\'][type=radio]:checked").val(); + var companyCode = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value; + var environment = serviceURLVal.indexOf("development") > 0 ? "Development" : "Production"; + + $.ajax({ + url:"?dispatch=avatax_tax_calculation.config_log&security_hash="+Tygh.security_hash+"&acc="+accountVal+"&license="+licenseVal+"&serviceurl="+serviceURLVal+"&environment="+environment+"&client=" + AVATAX_CLIENT + "&isAvataxEnabled="+isAvataxEnabled+"&isUPCOption="+isUPCOption+"&isSaveTransaction="+isSaveTransaction+"&isLogEnabled="+isLogEnabled+"&companyCode="+companyCode+"&isAddressValidation="+isAddressValidation, + success: function(result) { + //alert(result); + }, + async: false, + type : "POST" + }); + } + }); + + //Hide the company name and and code fields if it is not added + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value == "") { + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").hide(); + } + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").hide(); + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").attr("readonly", "true"); +}); + +if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value != "") { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").on("input", function() { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").val(""); + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").hide(); + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").hide(); + }); +} + +$("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").on("input", function() { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").val(""); + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").hide(); + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").hide(); +}) ; + +document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").addEventListener("change", function () { + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value = ""; + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").hide(); + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").hide(); +}); + +$("[id^=\'addon_option_avatax_tax_calculation_select_codes\']").change( function() { + $(this).find(":selected").each(function () { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").val($(this).val()); + }); +}); + +document.getElementById("variant_avatax_tax_calculation_1").addEventListener("click", function() { + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value == "") { + alert("AvaTax Account ID should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value == "") { + alert("AvaTax License Key should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value == "") { + alert("AvaTax Service URL should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value == "") { + alert("AvaTax Company Code should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").focus(); + } +}); + +document.getElementById("variant_avatax_tax_address_validation_1").addEventListener("click", function() { + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value == "") { + alert("AvaTax Account ID should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value == "") { + alert("AvaTax License Key should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value == "") { + alert("AvaTax Service URL should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").focus(); + } + else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").value == "") { + alert("AvaTax Company Name should not empty."); + document.getElementById("variant_avatax_tax_calculation_0").checked = true; + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").focus(); + } +}); + +var devMode = document.getElementById("addon_option_avatax_tax_calculation_avatax_development_mode"); +if(devMode !== null) { + devMode.addEventListener("click", function() { + var selectedVal = ""; + var selected = $('input[type="radio"][id="variant_avatax_development_mode_1"]:checked'); + if (selected.length > 0) { + selectedValue = selected.val(); + } else { + selected = $('input[type="radio"][id="variant_avatax_development_mode_0"]:checked'); + if (selected.length > 0) + selectedValue = selected.val(); + } + + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").removeAttr("disabled"); + + if (selectedValue == 1) + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").val("https://development.avalara.net/"); + else if (selectedValue == 0) + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").val("https://avatax.avalara.net"); + }); +} + +document.getElementById("AvaTaxTestConnection").addEventListener("click", function() { + if (validateFields()) { + $("#AvaTaxTestConnectionDialog").html('
Work In Progress...
Work In Progress...
'); + $("#AvaTaxTestConnectionDialog").dialog({ + width:350, + height:200, + buttons: { + "OK": function() { + $( this ).dialog( "close" ); + } + }, + open: function( event, ui ) { + if (!$("#AvaTaxTestConnectionDialog").parent().hasClass("ui-dailog-inner")) + $("#AvaTaxTestConnectionDialog").parent().addClass("ui-dailog-inner"); + } + }); + var accountVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value; + var licenseVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value; + var serviceURLVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value; + + var environment = serviceURLVal.indexOf("development") > 0 ? "Development" : "Production"; + + $.post("?dispatch=avatax_tax_calculation.connection_test&security_hash="+Tygh.security_hash+"&from=AvaTaxConnectionTest&acc="+accountVal+"&license="+licenseVal+"&serviceurl="+serviceURLVal+"&environment="+environment+"&client=" + AVATAX_CLIENT, {q: ""}, function(data) { + if (data.length > 0) { + $("#AvaTaxTestConnectionDialog").html(data); + if (!data.match(/Failed/gi)) { + showCompanyFields(); + validateCompany(); + } else { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").val(""); + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").hide(); + } + } + }); + } +}); + +function validateFields() { + if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value == "") { + alert("Please enter AvaTax Account ID!"); + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").focus(); + return false; + } else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value.length!=10) { + alert("AvaTax Account ID should not be less than or greater than 10 digits!"); + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").focus(); + return false; + } else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value == "") { + alert("Please enter AvaTax License Key"); + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").focus(); + return false; + } else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value.length!=16) { + alert("AvaTax License Key should not be less than or greater than 16 chars"); + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").focus(); + return false; + } else if (document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value == "") { + alert("Please enter AvaTax Service URL"); + document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").focus(); + return false; + } + + return true; +} + +function showCompanyFields() { + $("[id^=\'addon_option_avatax_tax_calculation_avatax_company_code\']").attr("readonly", "true"); + $("[id^=\'container_addon_option_avatax_tax_calculation_avatax_company_code\']").show(); + $("[id^=\'container_addon_option_avatax_tax_calculation_select_codes\']").show(); +} + +function validateCompany() { + + var accountVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_account_number\']").value; + var licenseVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_license_key\']").value; + var serviceURLVal = document.querySelector("[id^=\'addon_option_avatax_tax_calculation_avatax_service_url\']").value; + + var environment = serviceURLVal.indexOf("development") ? "Development" : "Production"; + + $.post("?dispatch=avatax_tax_calculation.setup_assistant&security_hash="+Tygh.security_hash+"&from=AvaTaxFetchCompanies&acc="+accountVal+"&license="+licenseVal+"&serviceurl="+serviceURLVal+"&environment="+environment+"&client=" + AVATAX_CLIENT, {q: ""}, function(data) { + if (data.length > 0) { + var accountsData = JSON.parse(data); + $("[id^=\'addon_option_avatax_tax_calculation_select_codes\']").find("option").remove(); + var _select=""; + _select = $("