forked from PrestaShopCorp/avalaratax
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathavalaratax.php
executable file
·2143 lines (1870 loc) · 113 KB
/
avalaratax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
// Security
if (!defined('_PS_VERSION_')) {
exit;
}
spl_autoload_register('avalaraAutoload');
class AvalaraTax extends Module
{
/**
* @brief Constructor
*/
public function __construct()
{
$this->name = 'avalaratax';
$this->tab = 'billing_invoicing';
$this->version = '3.5.9';
$this->author = 'NuRelm';
$this->module_key = '4e58b0c0a11bc32e1ad35a1fccc8a1f4';
parent::__construct();
$this->tax_manager_class = "AvalaraTaxManager";
$this->displayName = $this->l('Avalara - AvaTax');
$this->description = $this->l('Sales Tax is complicated. AvaTax makes it easy.');
/** Backward compatibility */
require(_PS_MODULE_DIR_.$this->name.'/backward_compatibility/backward.php');
if (!extension_loaded('soap') || !class_exists('SoapClient')) {
$this->warning = $this->l('SOAP extension should be enabled on your server to use this module.');
}
// Warn if PHP version is less than 5.4.0
if (version_compare(phpversion(), '5.4.0', '<')) {
$this->warning = $this->l('PHP versions below 5.4.0 are NOT supported by this module. Use at your own risk.');
}
// Check Prestashop versions and warn if this module does not support a specific version
if (version_compare(_PS_VERSION_, '1.6.1', '>=')) {
// Do nothing, versions 1.6.1.x are supported
} elseif (version_compare(_PS_VERSION_, '1.5.6', '>=') && version_compare(_PS_VERSION_, '1.6', '<')) {
// Do nothing, versions 1.5.6.x are supported
} elseif (version_compare(_PS_VERSION_, '1.5.4', '>=') && version_compare(_PS_VERSION_, '1.5.6', '<')) {
// Versions 1.5.4.x and 1.5.5.x should work, however, they are not tested or supported
$this->warning = $this->l('This module MAY work on Prestashop 1.5.4.x and 1.5.5.x but it is NOT tested. Please use Prestashop 1.5.6.x if you want support.');
} else {
// All remaining versions are NOT supported and likely will not work.
$this->warning = $this->l('Your version of Prestashop is NOT supported by this module.');
}
}
/**
* @brief Installation method
*/
public function install()
{
Configuration::updateValue('AVALARATAX_URL', 'https://avatax.avalara.net');
Configuration::updateValue('AVALARATAX_ADDRESS_VALIDATION', 1);
Configuration::updateValue('AVALARATAX_TAX_CALCULATION', 1);
Configuration::updateValue('AVALARATAX_TIMEOUT', 300);
// Value possible : Development / Production
Configuration::updateValue('AVALARATAX_MODE', 'Production');
Configuration::updateValue('AVALARATAX_ADDRESS_NORMALIZATION', 1);
Configuration::updateValue('AVALARATAX_COMMIT_ID', (int)Configuration::get('PS_OS_DELIVERED'));
Configuration::updateValue('AVALARATAX_CANCEL_ID', (int)Configuration::get('PS_OS_CANCELED'));
Configuration::updateValue('AVALARATAX_REFUND_ID', (int)Configuration::get('PS_OS_REFUND'));
Configuration::updateValue('AVALARATAX_POST_ID', (int)Configuration::get('PS_OS_PAYMENT'));
Configuration::updateValue('AVALARATAX_STATE', 1);
Configuration::updateValue('PS_TAX_DISPLAY', 1);
Configuration::updateValue('AVALARATAX_COUNTRY', 0);
Configuration::updateValue('AVALARA_CACHE_MAX_LIMIT', 3600); /* The values in cache will be refreshed every 1 minute by default */
// Make sure Avalara Tables don't exist before installation
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_product_cache`');
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_carrier_cache`');
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_address_validation_cache`');
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_returned_products`');
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_temp`');
Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_cart_cache`');
if (!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'avalara_product_cache` (
`id_cache` int(10) unsigned NOT NULL auto_increment,
`id_product` int(10) unsigned NOT NULL,
`tax_rate` float(8, 2) unsigned NOT NULL,
`region` varchar(2) NOT NULL,
`id_address` int(10) unsigned NOT NULL,
`update_date` datetime,
PRIMARY KEY (`id_cache`),
UNIQUE (`id_product`, `region`),
KEY `id_product2` (`id_product`,`region`,`id_address`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'avalara_carrier_cache` (
`id_cache` int(10) unsigned NOT NULL auto_increment,
`id_carrier` int(10) unsigned NOT NULL,
`tax_rate` float(8, 2) unsigned NOT NULL,
`region` varchar(2) NOT NULL,
`amount` float(8, 2) unsigned NOT NULL,
`update_date` datetime,
`id_cart` int(10) unsigned NOT NULL,
`cart_hash` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id_cache`),
KEY `cart_hash` (`cart_hash`),
KEY `cart_idx` (`id_cart`, `id_carrier`, `region`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'avalara_address_validation_cache` (
`id_avalara_address_validation_cache` int(10) unsigned NOT NULL auto_increment,
`id_address` int(10) unsigned NOT NULL,
`date_add` datetime,
PRIMARY KEY (`id_avalara_address_validation_cache`),
UNIQUE (`id_address`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'avalara_returned_products` (
`id_returned_product` int(10) unsigned NOT NULL auto_increment,
`id_order` int(10) unsigned NOT NULL,
`id_product` int(10) unsigned NOT NULL,
`total` float(8, 2) unsigned NOT NULL,
`quantity` int(10) unsigned NOT NULL,
`name` varchar(255) NOT NULL,
`description_short` varchar(255) NULL,
`tax_code` varchar(255) NULL,
PRIMARY KEY (`id_returned_product`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'avalara_temp` (
`id_order` int(10) unsigned NOT NULL,
`id_order_detail` int(10) unsigned NOT NULL)
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'avalara_taxcodes` (
`id_taxcode` int(10) unsigned NOT NULL auto_increment,
`id_product` int(10) unsigned NOT NULL,
`tax_code` varchar(30) NOT NULL,
`taxable` int(2) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (`id_taxcode`),
UNIQUE (`id_product`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') ||
!Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'avalara_cart_cache` (
`cart_id` int(10) unsigned NOT NULL,
`cart_hash` varchar(32) NOT NULL,
`total_tax` float(8,2) unsigned NOT NULL,
`total_products_tax` float(8,2) unsigned NOT NULL,
`total_shipping_tax` float(8,2) unsigned NOT NULL,
PRIMARY KEY (`cart_hash`),
KEY `cart_hash` (`cart_hash`),
KEY `cart_id` (`cart_id`))') ||
!Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'avalara_customer_entity_use_codes` (
`customer_id` int(10) unsigned NOT NULL,
`entity_use_code` varchar(10) NOT NULL,
PRIMARY KEY (`customer_id`))')) {
return false;
}
if (!parent::install()
|| !$this->registerHook('updateOrderStatus')
|| !$this->registerHook('cancelProduct') // Old PS 1.4 hook
|| !$this->registerHook('actionProductCancel') // New PS 1.5 > hook
|| !$this->registerHook('adminOrder')
|| !$this->registerHook('backOfficeTop')
|| !$this->registerHook('header')
|| !$this->registerHook('actionCartSave')
|| !$this->registerHook('actionOrderDetail')
|| !$this->registerHook('actionCartGetOrderTotal')
|| !$this->registerHook('actionCartGetPackageShippingCost')
|| !$this->overrideFiles()) {
return false;
}
return true;
}
public function uninstall()
{
if (!$this->removeOverrideFiles()
|| !parent::uninstall()
|| !Configuration::deleteByName('AVALARATAX_URL')
|| !Configuration::deleteByName('AVALARATAX_ADDRESS_VALIDATION')
|| !Configuration::deleteByName('AVALARATAX_TAX_CALCULATION')
|| !Configuration::deleteByName('AVALARATAX_TIMEOUT')
|| !Configuration::deleteByName('AVALARATAX_MODE')
|| !Configuration::deleteByName('AVALARATAX_ACCOUNT_NUMBER')
|| !Configuration::deleteByName('AVALARATAX_COMPANY_CODE')
|| !Configuration::deleteByName('AVALARATAX_LICENSE_KEY')
|| !Configuration::deleteByName('AVALARATAX_ADDRESS_NORMALIZATION')
|| !Configuration::deleteByName('AVALARATAX_ADDRESS_LINE1')
|| !Configuration::deleteByName('AVALARATAX_ADDRESS_LINE2')
|| !Configuration::deleteByName('AVALARATAX_CITY')
|| !Configuration::deleteByName('AVALARATAX_STATE')
|| !Configuration::deleteByName('AVALARATAX_ZIP_CODE')
|| !Configuration::deleteByName('AVALARATAX_COUNTRY')
|| !Configuration::deleteByName('AVALARATAX_COMMIT_ID')
|| !Configuration::deleteByName('AVALARATAX_CANCEL_ID')
|| !Configuration::deleteByName('AVALARATAX_REFUND_ID')
|| !Configuration::deleteByName('AVALARA_CACHE_MAX_LIMIT')
|| !Configuration::deleteByName('AVALARATAX_POST_ID')
|| !Configuration::deleteByName('AVALARATAX_CONFIGURATION_OK')
|| !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'avalara_product_cache`')
|| !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'avalara_carrier_cache`')
|| !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'avalara_address_validation_cache`')
|| !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'avalara_returned_products`')
|| !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'avalara_temp`')
|| !Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'avalara_cart_cache`')) {
// Remember, we intentionally did not remove taxcode table
return false;
}
return true;
}
/**
* @brief Describe the override schema
*/
protected static function getOverrideInfo()
{
return array(
'Cart.php' => array(
'source' => 'override/classes/Cart.php',
'dest' => 'override/classes/Cart.php',
'md5' => array(
'3.0.2' => 'e4b05425b6dc61f75aad434265f3cac8',
'3.0.3' => 'f7388cb50fbfd300c9f81cc407b7be83',
)
),
'AddressController.php' => array(
'source' => 'override/controllers/front/AddressController.php',
'dest' => 'override/controllers/AddressController.php',
'md5' => array(
'1.1' => 'ebc4f31298395c4b113c7e2d7cc41b4a',
'3.0.2' => 'ff3d9cb2956c35f4229d5277cb2e92e6',
'3.2.1' => 'bc34c1150f7170d3ec7912eb383cd04b',
)
),
'AuthController.php' => array(
'source' => 'override/controllers/front/AuthController.php',
'dest' => 'override/controllers/AuthController.php',
'md5' => array(
'1.1' => '7304d7af971b30f2dcd401b80bbdf805',
'3.0.2' => '3eb86260a7c8d6cfa1d209fb3e8f8bd6',
)
),
);
}
protected function removeOverrideFiles()
{
/** In v1.5, we do not remove override files */
if (version_compare(_PS_VERSION_, '1.5', '<')) {
foreach (self::getOverrideInfo() as $key => $params) {
if (!file_exists(_PS_ROOT_DIR_.'/'.$params['dest'])) {
continue;
}
$md5 = md5_file(_PS_ROOT_DIR_.'/'.$params['dest']);
$removed = false;
foreach ($params['md5'] as $hash) {
if ($md5 == $hash) {
if (unlink(_PS_ROOT_DIR_.'/'.$params['dest'])) {
$removed = true;
}
break;
}
}
if (!$removed) {
$this->_errors[] = $this->l('Error while removing override: ').$key;
}
}
}
return !isset($this->_errors) || !$this->_errors || !count($this->_errors);
}
protected function overrideFiles()
{
/** In v1.5, we do not copy the override files */
if (version_compare(_PS_VERSION_, '1.5', '<') && $this->removeOverrideFiles()) {
/** Check if the override directories exists */
if (!is_dir(_PS_ROOT_DIR_.'/override/classes/')) {
mkdir(_PS_ROOT_DIR_.'/override/classes/', 0777, true);
}
if (!is_dir(_PS_ROOT_DIR_.'/override/controllers/')) {
mkdir(_PS_ROOT_DIR_.'/override/controllers/', 0777, true);
}
foreach (self::getOverrideInfo() as $key => $params) {
if (file_exists(_PS_ROOT_DIR_.'/'.$params['dest'])) {
$this->_errors[] = $this->l('This override file already exists, please merge it manually: ').$key;
} elseif (!copy(_PS_MODULE_DIR_.'avalaratax/'.$params['source'], _PS_ROOT_DIR_.'/'.$params['dest'])) {
$this->_erroors[] = $this->l('Error while copying the override file: ').$key;
}
}
}
return !isset($this->_errors) || !$this->_errors || !count($this->_errors);
}
//*** OrderDetailController.php ************************************
// Hook called after generating OrderDetail
// $params['carrier'] => $carrier
// $params['order'] => $order
public function hookActionOrderDetail($params)
{
// We need to override smarty here to force displaying tax information
// Other pages rely on value of 'use_taxes' but this one expects 'use_tax'
// 'show_taxes' is required on other pages but not this one
// the value of 'group_use_tax' should be left alone
$this->context->smarty->assign(array('use_tax' => 1));
}
//*** End OrderDetailController.php ********************************
//*** AdminOrderController.php *************************************
// Hook is called when a product is cancelled from an Order
// This hook gets called once for each product that has been cancelled
// $params['order'] => Order object
// $params['id_order_detail']
public function hookActionProductCancel($params)
{
if (isset($_POST['cancelProduct'])) {
$order = new Order((int)$_POST['id_order']);
if (!Validate::isLoadedObject($order)) {
return false;
}
if ($order->invoice_number) {
// Get all the cancel product's IDs
$cancelledIdsOrderDetail = array();
foreach ($_POST['cancelQuantity'] as $idOrderDetail => $qty) {
if ($qty > 0) {
$cancelledIdsOrderDetail[] = (int)$idOrderDetail;
}
}
$cancelledIdsOrderDetail = implode(', ', $cancelledIdsOrderDetail);
// Fill temp table
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'avalara_temp (`id_order`, `id_order_detail`)
VALUES ('.(int)$_POST['id_order'].', '.(int)$params['id_order_detail'].')');
// Check if we are at the end of the loop
$totalLoop = Db::getInstance()->ExecuteS('SELECT COUNT(`id_order`) as totalLines
FROM `'._DB_PREFIX_.'avalara_temp`
WHERE `id_order_detail` IN ('.pSQL($cancelledIdsOrderDetail).')');
// We haven't reached the end of the returned products loop, exit this call of the hook early
if ($totalLoop[0]['totalLines'] != count(array_filter($_POST['cancelQuantity']))) {
return false;
}
// We should have reached the last call of this hook (all returned products are in our temp table)
// Clean the temp table because we are at the end of the loop
$this->purgeTempTable();
// Get details for cancelledIdsOrderDetail (Grab the info to post to Avalara in English.)
$cancelledProdIdsDetails = Db::getInstance()->ExecuteS('SELECT od.`product_id` as id_product, od.`id_order_detail`, pl.`name`,
pl.`description_short`, od.`product_price` as price, od.`reduction_percent`,
od.`reduction_amount`, od.`product_quantity` as quantity
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product)
WHERE pl.`id_lang` = '.(int)Configuration::get('PS_LANG_DEFAULT').' AND od.`id_order` = '.(int)$_POST['id_order'].'
AND od.`id_order_detail` IN ('.pSQL($cancelledIdsOrderDetail).')');
// Build the product list
$products = array();
foreach ($cancelledProdIdsDetails as $cancelProd) {
$products[] = array('id_product' => (int)$cancelProd['id_product'],
'quantity' => (int)$_POST['cancelQuantity'][$cancelProd['id_order_detail']],
'total' => pSQL($_POST['cancelQuantity'][$cancelProd['id_order_detail']] * ($cancelProd['price'] - ($cancelProd['price'] * ($cancelProd['reduction_percent'] / 100)) - $cancelProd['reduction_amount'])), // Including those product with discounts
'name' => pSQL(Tools::safeOutput($cancelProd['name'])),
'description_short' => pSQL(Tools::safeOutput($cancelProd['description_short']), true),
'tax_code' => $this->getProductTaxCode($cancelProd['id_product']));
}
// Send to Avalara
$commitResult = $this->getTax($products, array('type' => 'ReturnInvoice', 'DocCode' => (int)$_POST['id_order']));
if ($commitResult['ResultCode'] == 'Warning' || $commitResult['ResultCode'] == 'Error' || $commitResult['ResultCode'] == 'Exception') {
echo $this->_displayConfirmation(
$this->l(
'The following error was generated while cancelling the orders you selected. <br /> - '.
Tools::safeOutput($commitResult['Messages']['Summary'])
),
'error'
);
} else {
// This seems to be causing returns to improperly adjust the commit date of the orignal transaction
// $this->commitToAvalara(array('id_order' => (int)$_POST['id_order']));
echo $this->_displayConfirmation($this->l('The products you selected were cancelled.'));
}
}
}
}
//*** End AdminOrderController.php *********************************
// Cart tax methods
public function getSimplifiedCart($cart)
{
$products = $cart->getProducts();
$s_cart = array(); // Create a simplified cart array with only the information we need
$s_products = array(); // Create a simplified prodcuts array with only the information we need
// In each row of products array we are looking for product id, quantity and
// a pretax total that includes discounts
foreach ($products as $prod) {
$s_products[] = array('id_product' => (int)$prod['id_product'],
'name' => $prod['name'],
'description_short' => $prod['description_short'],
'quantity' => (int)$prod['quantity'],
'pretax_total' => (float)$prod['total'],
'tax_code' => $this->getProductTaxCode((int)$prod['id_product'])
);
}
$s_cart = array('cart_id' => $cart->id,
'customer_id' => (int)$cart->id_customer,
'customer_tax_address_id' => (int)$cart->id_address_delivery,
'discounts' => $this->getOrderedCartRulesIds($cart),
'carrier' => (int)$cart->id_carrier,
'products' => $s_products);
return $s_cart;
}
public function getTaxesForCartHash($cart_hash)
{
$result = Db::getInstance()->ExecuteS('
SELECT acc.`total_tax`, acc.`total_products_tax`, acc.`total_shipping_tax`
FROM `'._DB_PREFIX_.'avalara_cart_cache` acc
WHERE acc.`cart_hash` = \''.$cart_hash.'\'');
// If we have exactly 1 result from the datbase as we expected, assign tax values that we retrieved
if (count($result) == 1 && !empty($result)) {
$row = current($result);
return array('total_tax' => $row['total_tax'],
'total_products_tax' => $row['total_products_tax'],
'total_shipping_tax' => $row['total_shipping_tax']);
} else {
return false;
}
}
//*** Cart Hooks ***************************************************
// Hook is called when attemtping to calculate an order total for a cart
public function hookActionCartGetOrderTotal($params)
{
$new_order_total = 0.0;
$with_taxes = $params['with_taxes'];
$type = $params['type'];
$cart = $params['cart'];
$order_total = $params['order_total'];
$total_tax = 0.00;
$total_products_tax = 0.00;
$total_shipping_tax = 0.00;
// We only need to perform this section for OrderTotal's that ask for tax information
if ($with_taxes == true && ($type==Cart::BOTH || Cart::ONLY_PRODUCTS)) {
$s_cart = $this->getSimplifiedCart($cart);
$cart_hash = md5(serialize($s_cart)); // Construct hash to act as a cache id
// Search avalara_cart_cache table for tax values by cart hash primary key
$tax_array = $this->getTaxesForCartHash($cart_hash);
if (is_array($tax_array)) {
$total_tax = $tax_array['total_tax'];
$total_products_tax = $tax_array['total_products_tax'];
$total_shipping_tax = $tax_array['total_shipping_tax'];
}
}
if ($with_taxes==false) {
$new_order_total = $order_total;
} else {
switch ($type) {
case Cart::BOTH:
// Shipping and shipping tax is already included in this number by hookActionCartGetPackageShippingCost
$new_order_total = $order_total + $total_products_tax;
break;
case Cart::ONLY_PRODUCTS:
case Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING:
$new_order_total = $order_total + $total_products_tax;
break;
case Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING:
$new_order_total = $order_total + $total_products_tax;
break;
case Cart::BOTH_WITHOUT_SHIPPING: // This type is automatically set if asking for Cart::BOTH and entire cart is virtual
$new_order_total = $order_total + $total_products_tax;
break;
case Cart::ONLY_SHIPPING:
// The getOrderTotal method should never call this hook when using this type instead
// Cart::getPackageShippingCost will be returned instead before this hook is ever called
$new_order_total = $order_total + $total_shipping_tax;
break;
case Cart::ONLY_DISCOUNTS:
$new_order_total = $order_total;
break;
case Cart::ONLY_WRAPPING:
$new_order_total = $order_total;
break;
default:
$new_order_total = $order_total; // We could return, or throw an error here
}
}
return array('new_order_total' => $new_order_total);
}
// Hook is called when calculating the total shipping cost for a package
public function hookActionCartGetPackageShippingCost($params)
{
$new_shipping_cost = 0.0;
$with_taxes = $params['with_taxes'];
$cart = $params['cart'];
$shipping_cost = $params['shipping_cost'];
$total_shipping_tax = 0.00;
// We only need to perform this section for OrderTotal's that ask for tax information
if ($with_taxes == true) {
$s_cart = $this->getSimplifiedCart($cart);
$cart_hash = md5(serialize($s_cart)); // Construct hash to act as a cache id
// Search avalara_cart_cache table for tax values by cart hash primary key
$tax_array = $this->getTaxesForCartHash($cart_hash);
if (is_array($tax_array)) {
$total_shipping_tax = $tax_array['total_shipping_tax'];
}
}
if ($with_taxes==false) {
$new_shipping_cost = $shipping_cost;
} else {
$new_shipping_cost = $shipping_cost + $total_shipping_tax;
}
return array('new_shipping_cost' => $new_shipping_cost);
}
// Occurs immediately after a cart is saved
public function hookActionCartSave($args)
{
$cart = $args['cart'];
if (!is_object($cart)) {
return false;
}
$products = $cart->getProducts();
// No point in continuing if we do not have products in the cart
if (empty($products)) {
return false;
}
// Obtain a simplified cart array and construct a hash to act as the primary key for the avalara_cart_cache table
$s_cart = $this->getSimplifiedCart($cart);
$cart_hash = md5(serialize($s_cart));
// Verify that we have all the required information to uniquely identify a cart
if (empty($s_cart['cart_id']) || empty($s_cart['customer_id']) || empty($s_cart['customer_tax_address_id']) || empty($s_cart['carrier'])) {
return false; // Skip everything below because we are missing a cart id, a customer id or a tax_address_id
}
$s_products = $s_cart['products'];
// Obtain pre-tax total discounts and total shipping values
$total_discounts = $cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS);
$total_shipping = $cart->getOrderTotal(false, Cart::ONLY_SHIPPING);
// Attempt to update our cache of taxes for this cart
$this->updateTotalCartTaxes($cart, $s_cart, $cart_hash, $total_discounts, $total_shipping);
}
//
public function updateTotalCartTaxes($cart, $s_cart, $cart_hash, $total_discounts, $total_shipping)
{
// Make sure we don't replace our cart taxes cache if we already have valid values for this cart
if ($this->checkForValidCartCache($cart_hash) == true) {
if (version_compare(_PS_VERSION_, '1.6.1', '>=')) {
return true; // This caching optimization only works for Prestashop 1.6.1 and greater
}
}
$total_products_tax = 0.00;
$total_shipping_tax = 0.00;
$total_tax = 0.00;
// Rename keys of products array for compatibility with old getTax method
$s_products = $s_cart['products'];
foreach ($s_products as $k => $v) {
$s_products[$k]['total'] = $s_products[$k]['pretax_total'];
unset($s_products[$k]['pretax_total']);
}
// Obtain tax information from Avalara for this cart
// Consider swtich on 'taxable' value based on config
$tax_result = $this->getTax($s_products, array('type' => 'SalesOrder', 'DocCode' => 1, 'cart' => $cart, 'taxable' => true));
$total_tax = (float)$tax_result['TotalTax'];
$tax_lines = $tax_result['TaxLines'];
$shipping_line = $tax_lines['Shipping'];
unset($tax_lines['Shipping']);
$total_shipping_tax = (float)$shipping_line['GetTax'];
foreach ($tax_lines as $tax_line) {
$total_products_tax += (float)$tax_line['GetTax'];
}
Db::getInstance()->Execute(
'REPLACE INTO `'._DB_PREFIX_.'avalara_cart_cache` (`cart_id`, `cart_hash`, `total_tax`, `total_products_tax`, `total_shipping_tax`)
VALUES ('.$s_cart['cart_id'].', \''.$cart_hash.'\', '.$total_tax.', '.$total_products_tax.', '.$total_shipping_tax.')'
);
return true;
}
// Return true if we have an unexpired cart cache for the given cart hash, false otherwise
public function checkForValidCartCache($cart_hash)
{
$result = Db::getInstance()->getRow('
SELECT `cart_hash`
FROM `'._DB_PREFIX_.'avalara_cart_cache`
WHERE `cart_hash` = \''.$cart_hash.'\'
');
return !$result ? false : true;
}
// Method originally from Cart.php (1.6.x and greater), extracted out here for backwards compatibility with 1.5.x
public function getOrderedCartRulesIds($cart, $filter = CartRule::FILTER_ACTION_ALL)
{
$cache_key = 'Cart::getCartRules_'.$cart->id.'-'.$filter.'-ids';
if (!Cache::isStored($cache_key)) {
$result = Db::getInstance()->executeS(
'SELECT cr.`id_cart_rule`
FROM `'._DB_PREFIX_.'cart_cart_rule` cd
LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON cd.`id_cart_rule` = cr.`id_cart_rule`
LEFT JOIN `'._DB_PREFIX_.'cart_rule_lang` crl ON (
cd.`id_cart_rule` = crl.`id_cart_rule`
AND crl.id_lang = '.(int)$cart->id_lang.'
)
WHERE `id_cart` = '.(int)$cart->id.'
'.($filter == CartRule::FILTER_ACTION_SHIPPING ? 'AND free_shipping = 1' : '').'
'.($filter == CartRule::FILTER_ACTION_GIFT ? 'AND gift_product != 0' : '').'
'.($filter == CartRule::FILTER_ACTION_REDUCTION ? 'AND (reduction_percent != 0 OR reduction_amount != 0)' : '')
.' ORDER BY cr.priority ASC'
);
Cache::store($cache_key, $result);
} else {
$result = Cache::retrieve($cache_key);
}
}
//*** End Cart Hooks ***********************************************
//******************************************************************
//*** Hook Methods *************************************************
//******************************************************************
public function hookAdminOrder($params)
{
$this->purgeTempTable();
}
// This is the old 1.4 version, we should consider deprecating this in our next release
public function hookCancelProduct($params)
{
// Make sure we don't execute this hook in versions greater than 1.4
if (version_compare(_PS_VERSION_, '1.5', '>')) {
return false;
}
if (isset($_POST['cancelProduct'])) {
$order = new Order((int)$_POST['id_order']);
if (!Validate::isLoadedObject($order)) {
return false;
}
if ($order->invoice_number) {
// Get all the cancel product's IDs
$cancelledIdsOrderDetail = array();
foreach ($_POST['cancelQuantity'] as $idOrderDetail => $qty) {
if ($qty > 0) {
$cancelledIdsOrderDetail[] = (int)$idOrderDetail;
}
}
$cancelledIdsOrderDetail = implode(', ', $cancelledIdsOrderDetail);
// Fill temp table
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'avalara_temp (`id_order`, `id_order_detail`)
VALUES ('.(int)$_POST['id_order'].', '.(int)$params['id_order_detail'].')');
// Check if we are at the end of the loop
$totalLoop = Db::getInstance()->ExecuteS('SELECT COUNT(`id_order`) as totalLines
FROM `'._DB_PREFIX_.'avalara_temp`
WHERE `id_order_detail` IN ('.pSQL($cancelledIdsOrderDetail).')');
if ($totalLoop[0]['totalLines'] != count(array_filter($_POST['cancelQuantity']))) {
return false;
}
// Clean the temp table because we are at the end of the loop
$this->purgeTempTable();
// Get details for cancelledIdsOrderDetail (Grab the info to post to Avalara in English.)
$cancelledProdIdsDetails = Db::getInstance()->ExecuteS('SELECT od.`product_id` as id_product, od.`id_order_detail`, pl.`name`,
pl.`description_short`, od.`product_price` as price, od.`reduction_percent`,
od.`reduction_amount`, od.`product_quantity` as quantity
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product)
WHERE pl.`id_lang` = '.(int)Configuration::get('PS_LANG_DEFAULT').' AND od.`id_order` = '.(int)$_POST['id_order'].'
AND od.`id_order_detail` IN ('.pSQL($cancelledIdsOrderDetail).')');
// Build the product list
$products = array();
foreach ($cancelledProdIdsDetails as $cancelProd) {
$products[] = array('id_product' => (int)$cancelProd['id_product'],
'quantity' => (int)$_POST['cancelQuantity'][$cancelProd['id_order_detail']],
'total' => pSQL($_POST['cancelQuantity'][$cancelProd['id_order_detail']] * ($cancelProd['price'] - ($cancelProd['price'] * ($cancelProd['reduction_percent'] / 100)) - $cancelProd['reduction_amount'])), // Including those product with discounts
'name' => pSQL(Tools::safeOutput($cancelProd['name'])),
'description_short' => pSQL(Tools::safeOutput($cancelProd['description_short']), true),
'tax_code' => $this->getProductTaxCode($cancelProd['id_product']));
}
// Send to Avalara
$commitResult = $this->getTax($products, array('type' => 'ReturnInvoice', 'DocCode' => (int)$_POST['id_order']));
if ($commitResult['ResultCode'] == 'Warning' || $commitResult['ResultCode'] == 'Error' || $commitResult['ResultCode'] == 'Exception') {
echo $this->_displayConfirmation(
$this->l(
'The following error was generated while cancelling the orders you selected. <br /> - '.
Tools::safeOutput($commitResult['Messages']['Summary'])
),
'error'
);
} else {
$this->commitToAvalara(array('id_order' => (int)$_POST['id_order']));
echo $this->_displayConfirmation($this->l('The products you selected were cancelled.'));
}
}
}
}
protected function getDestinationAddress($id_order)
{
$order = new Order((int)$id_order);
if (!Validate::isLoadedObject($order)) {
return false;
}
$address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
if (!Validate::isLoadedObject($address)) {
return false;
}
$state = null;
if (!empty($address->id_state)) {
$state = new State((int)$address->id_state);
if (!Validate::isLoadedObject($state)) {
return false;
}
}
return array($address, $state, $order);
}
public function hookUpdateOrderStatus($params)
{
list($params['address'], $params['state'], $params['order']) = self::getDestinationAddress((int)$params['id_order']);
if ($params['newOrderStatus']->id == (int)Configuration::get('AVALARATAX_COMMIT_ID')) {
return $this->commitToAvalara($params);
} elseif ($params['newOrderStatus']->id == (int)Configuration::get('AVALARATAX_CANCEL_ID')) {
$params['CancelCode'] = 'V';
$this->cancelFromAvalara($params);
return $this->cancelFromAvalara($params);
} elseif ($params['newOrderStatus']->id == (int)Configuration::get('AVALARATAX_POST_ID')) {
return $this->postToAvalara($params);
} elseif ($params['newOrderStatus']->id == (int)Configuration::get('AVALARATAX_REFUND_ID')) {
return $this->commitToAvalara($params);
}
return false;
}
public function hookBackOfficeTop()
{
if (Tools::isSubmit('submitAddproduct') || Tools::isSubmit('submitAddproductAndStay')) {
// Update the value of tax_code when a product page is saved
// isset and $_POST are necessary here because Tools::getIsset() and Tools::getValue() make extra !empty() checks
if (isset($_POST['tax_code'])) {
Db::getInstance()->Execute('REPLACE INTO `'._DB_PREFIX_.'avalara_taxcodes` (`id_product`, `tax_code`)
VALUES ('.(isset($_GET['id_product']) ? (int)$_GET['id_product'] : 0).', \''.pSQL(Tools::safeOutput($_POST['tax_code'])).'\')');
}
} elseif (Tools::isSubmit('submitAddcustomer') && Tools::getValue('id_customer') && Tools::getValue('entity_use_code')) {
// Update Customer Entity Use Code when Customer form is submitted
$this->setEntityUseCode(Tools::getValue('id_customer'), Tools::getValue('entity_use_code'));
}
if ((isset($_GET['updateproduct']) || isset($_GET['addproduct'])) && isset($_GET['id_product']) && (int)$_GET['id_product']) {
$r = Db::getInstance()->getRow('
SELECT `tax_code`
FROM `'._DB_PREFIX_.'avalara_taxcodes` atc
WHERE atc.`id_product` = '.(int)Tools::getValue('id_product'));
if (version_compare(_PS_VERSION_, '1.5', '<')) {
/* v1.4.x an older */
return '
<script type="text/javascript">
$(function() {
// Add the Tax Code field
$(\'<tr><td class="col-left">'.$this->l('Tax Code (Avalara)').':</td><td style="padding-bottom:5px;"><input type="text" style="width: 130px; margin-right: 5px;" value="'.
($r ? Tools::safeOutput($r['tax_code']) : '').'" name="tax_code" maxlength="13" size="55"></td></tr>\').appendTo(\'#product #step1 table:eq(0) tbody\');
// override original tax rules
$(\'span #id_tax_rules_group\').parent().html(\'Avalara\');
});
</script>';
} elseif (version_compare(_PS_VERSION_, '1.6', '<')) {
/* v1.5.x */
return '
<script type="text/javascript">
$(function() {
var done = false;
// Add the Tax Code field
$(\'#link-Informations\').click(function() {
if (done == false) {
done = true;
$(\'<tr><td class="col-left"><label for="tax_code">'.$this->l('Tax Code:').'</label></td><td style="padding-bottom:5px;"><input type="text" style="width: 130px; margin-right: 5px;" value="'.
($r ? Tools::safeOutput($r['tax_code']) : '').'" name="tax_code" maxlength="13" size="55"> <span class="small">(Avalara)</span></td></tr>\').appendTo(\'#step1 table:first tbody\');
}
});
// override original tax rules
$(\'#link-Prices\').click(function() {
$(\'span #id_tax_rules_group\').parent().html(\'Avalara\');
});
});
</script>';
} else {
/* v1.6.x and newer */
return '
<script type="text/javascript">
$(function() {
var done = false;
// Add the Tax Code field
//$(\'#link-Prices\').click(function() {
// $(\'#id_tax_rules_group\').parent().parent().parent().parent().html(\'<div class="form-group"><label class="control-label col-lg-3" for="tax_code"><span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="'.$this->l('Tax rules will be handled by Avalara').'">'.$this->l('Tax Code (Avalara):').'</span></label><div class="input-group col-lg-4"><input type="text" value="'.($r ? Tools::safeOutput($r['tax_code']) : '').'" name="tax_code" maxlength="13" /><div class="alert alert-info" style="margin-top: 40px;">'.$this->l('Tax rules will be handled by Avalara').'</div></div>\');
//});
// Attempt # 2
$(\'#product-tab-content-Prices\').on("displayed", function(){
var $our_node = $(\'#id_tax_rules_group\').parent().parent().parent().parent();
$our_node.hide();
if(!$("#tax-code-input").length){
$our_node.after(\'<div class="form-group"><label class="control-label col-lg-3" for="tax_code"><span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="'.$this->l('Tax rules will be handled by Avalara').'">'.$this->l('Tax Code (Avalara):').'</span></label><div class="input-group col-lg-4"><input type="text" value="'.($r ? Tools::safeOutput($r['tax_code']) : '').'" name="tax_code" id="tax-code-input" maxlength="13" /><div class="alert alert-info" style="margin-top: 40px;">'.$this->l('Tax rules will be handled by Avalara').'</div></div>\');
}
// console.log("test");
// $(\'#id_tax_rules_group\').parent().parent().parent().parent().html(\'<div class="form-group"><label class="control-label col-lg-3" for="tax_code"><span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="'.$this->l('Tax rules will be handled by Avalara').'">'.$this->l('Tax Code (Avalara):').'</span></label><div class="input-group col-lg-4"><input type="text" value="'.($r ? Tools::safeOutput($r['tax_code']) : '').'" name="tax_code" maxlength="13" /><div class="alert alert-info" style="margin-top: 40px;">'.$this->l('Tax rules will be handled by Avalara').'</div></div>\');
});
});
</script>';
}
} elseif ((Tools::isSubmit('updatecarrier') || Tools::isSubmit('addcarrier')) && Tools::getValue('id_carrier')) {
return '<script type="text/javascript">
$(function() {
// override original tax rules
$(\'div #id_tax_rules_group\').parent().html(\'<label class="t">Avalara</label>\');
});
</script>';
} elseif ((Tools::isSubmit('updatecustomer') || Tools::isSubmit('addcustomer')) && Tools::getValue('id_customer')) {
// Add fields for Entity Use Code to Customer edit page
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
$entity_use_code = $this->getEntityUseCode(Tools::getValue('id_customer'));
$eu_select_options = $this->getEntityUseCodesOptions($entity_use_code);
return '<script type="text/javascript">'
. '$(function() {'
. 'var $form_wrapper = $(\'.form-wrapper\');'
. '$form_wrapper.append(\''
. '<div class="form-group">'
. '<label class="control-label col-lg-3" for="entity_use_code">'
. '<span class="label-tooltip" data-toggle="tooltip" title="" data-original-title="'.$this->l('Tax rules will be handled by Avalara').'">'.$this->l('Entity Use Code (Avalara):').'</span>'
. '</label>'
. '<div class="input-group col-lg-3">'
. '<select name="entity_use_code" id="entity-use-code-input">'
. join('', $eu_select_options)
. '</select>'
. '</div>'
. '</div>\');'
. '});'
.'</script>';
} elseif (version_compare(_PS_VERSION_, '1.5', '>=')) {
$entity_use_code = $this->getEntityUseCode(Tools::getValue('id_customer'));
$eu_select_options = $this->getEntityUseCodesOptions($entity_use_code);
return '<script type="text/javascript">'
. '$(function() {'
. 'var $form = $(\'#customer_form\');'
. '$form.append(\''
. '<fieldset id="fieldset_1">'
. '<legend>Avalara Module</legend>'
. '<label for="entity_use_code">Entity Use Code</label>'
. '<div class="margin-form">'
. '<select type="text" name="entity_use_code" id="entity-use-code-input">'
. join('', $eu_select_options)
. '</select>'
. '</div>'
. '</div>\');'
. '});'
.'</script>';
} else {
// The Entity Use Code feature is currently not supported in these versions
}
}
if (Tools::getValue('tab') == 'AdminTaxes' || Tools::getValue('tab') == 'AdminTaxRulesGroup' || Tools::strtolower(Tools::getValue('controller'))== 'admintaxes' || Tools::strtolower(Tools::getValue('controller')) == 'admintaxrulesgroup') {
if (version_compare(_PS_VERSION_, '1.6', '>=')) {
// JS for 1.6
return '<script type="text/javascript">
$(function() {
$("#content #form-tax").hide();
$("#content #form-tax_rules_group").hide();
$("#desc-tax-new").hide();
$(\'#content div:first\').append(\'<div class="warn alert alert-danger">'.$this->l('Tax rules are overwritten by Avalara Tax Module. Please make sure "Enable Tax" and "Use Eco Tax" are set to "No"').'</div>\');
});
</script>';
} elseif (version_compare(_PS_VERSION_, '1.5', '>=')) {
// JS for 1.5
return '<script type="text/javascript">
$(function() {
$(\'#desc-tax-new\').hide();
$("#content form").not("#tax_form").hide();
$("#content #form-tax_rules_group").hide();
$(\'#content div:first\').append(\'<div class="warn alert alert-danger">'.$this->l('Tax rules are overwritten by Avalara Tax Module. Please make sure "Enable Tax" and "Use Eco Tax" are set to "No"').'</div>\');
});
</script>';
} else {
// JS for 1.4
return '<script type="text/javascript">
$(function() {
if ($(\'#Taxes\').size() || $(\'#submitFiltertax_rules_group\').size())