SalesTax_Connector - Version 4.1.1

Version Notes

Simplify sales and use tax calculation, compliance, and management in the cloud!

Download this release

Release Info

Developer Ken Nunes
Extension SalesTax_Connector
Version 4.1.1
Comparing to
See all releases


Code changes from version 3.2.1 to 4.1.1

Files changed (32) hide show
  1. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/All/Index.php +37 -37
  2. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/All/Index/Grid.php +123 -123
  3. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Failsafe/Index.php +31 -31
  4. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Failsafe/Index/Grid.php +49 -49
  5. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Rateverification/Index.php +31 -31
  6. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Rateverification/Index/Grid.php +61 -61
  7. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Notification.php +44 -44
  8. app/code/community/Harapartners/SpeedTax/Block/Adminhtml/System/Config/Form/Field/Authentication.php +76 -76
  9. app/code/community/Harapartners/SpeedTax/Helper/Connector/Data.php +299 -261
  10. app/code/community/Harapartners/SpeedTax/Helper/Connector/Speedtax.php +184 -184
  11. app/code/community/Harapartners/SpeedTax/Helper/Data.php +49 -49
  12. app/code/community/Harapartners/SpeedTax/Helper/Failsafe.php +72 -72
  13. app/code/community/Harapartners/SpeedTax/Helper/Processor.php +240 -192
  14. app/code/community/Harapartners/SpeedTax/Model/Failsafe/Calculation.php +41 -41
  15. app/code/community/Harapartners/SpeedTax/Model/Failsafe/Calculation/Rate.php +38 -38
  16. app/code/community/Harapartners/SpeedTax/Model/Failsafe/Sales/Total/Quote/Tax.php +26 -26
  17. app/code/community/Harapartners/SpeedTax/Model/Observer.php +167 -163
  18. app/code/community/Harapartners/SpeedTax/Model/Resource/Failsafe/Calculation/Rate.php +46 -46
  19. app/code/community/Harapartners/SpeedTax/Model/Resource/Failsafe/Calculation/Rate/Collection.php +19 -19
  20. app/code/community/Harapartners/SpeedTax/Model/Rewrite/Tax/Sales/Total/Quote/Tax.php +69 -69
  21. app/code/community/Harapartners/SpeedTax/Model/Session.php +63 -63
  22. app/code/community/Harapartners/SpeedTax/Model/Source/Usregions.php +35 -35
  23. app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/InvoiceController.php +80 -80
  24. app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/NotificationController.php +32 -32
  25. app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/System/Config/AjaxController.php +62 -62
  26. app/code/community/Harapartners/SpeedTax/etc/adminhtml.xml +71 -71
  27. app/code/community/Harapartners/SpeedTax/etc/config.xml +169 -166
  28. app/code/community/Harapartners/SpeedTax/etc/system.xml +299 -218
  29. app/code/community/Harapartners/SpeedTax/sql/speedtax_setup/mysql4-upgrade-3.0.9-3.1.0.php +49 -49
  30. app/code/community/Harapartners/SpeedTax/sql/speedtax_setup/mysql4-upgrade-3.9.9-4.0.0.php +100 -100
  31. app/etc/modules/Harapartners_SpeedTax.xml +25 -25
  32. package.xml +6 -5
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/All/Index.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index extends Mage_Adminhtml_Block_Widget_Grid_Container {
14
-
15
- public function __construct() {
16
- parent::__construct ();
17
- $this->_blockGroup = 'speedtax';
18
- $this->_controller = 'adminhtml_invoice_all_index';
19
- $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'SalesTax Invoices' );
20
- $this->_removeButton('add');
21
- }
22
-
23
- public function getGridHtml() {
24
- return $this->getHeaderInfoHtml() . parent::getGridHtml();
25
- }
26
-
27
- public function getHeaderInfoHtml(){
28
- $headerInfoHtml = <<< INFO_HTML
29
- <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
30
- <p>By default Magento invoices will be posted to SalesTax when paid; and most orders should be in the <b>Posted</b> status.</p>
31
- <p>The <b>Failsafe</b> status is for invoices that are paid but cannot be posted to SalesTax. These invoices can be processed in batch by either 1) system cronjobs or 2) the <b><i>Post To SalesTax</i></b> action.</p>
32
- <p>The <b>Pending</b> status is for invoices that are paid, and by default not to be posted to SalesTax. These invoices are probably from historical orders before the SalesTax integration.</p>
33
- </div>
34
- INFO_HTML;
35
- return $headerInfoHtml;
36
- }
37
-
38
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index extends Mage_Adminhtml_Block_Widget_Grid_Container {
14
+
15
+ public function __construct() {
16
+ parent::__construct ();
17
+ $this->_blockGroup = 'speedtax';
18
+ $this->_controller = 'adminhtml_invoice_all_index';
19
+ $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'SalesTax Invoices' );
20
+ $this->_removeButton('add');
21
+ }
22
+
23
+ public function getGridHtml() {
24
+ return $this->getHeaderInfoHtml() . parent::getGridHtml();
25
+ }
26
+
27
+ public function getHeaderInfoHtml(){
28
+ $headerInfoHtml = <<< INFO_HTML
29
+ <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
30
+ <p>By default Magento invoices will be posted to SalesTax when paid; and most orders should be in the <b>Posted</b> status.</p>
31
+ <p>The <b>Failsafe</b> status is for invoices that are paid but cannot be posted to SalesTax. These invoices can be processed in batch by either 1) system cronjobs or 2) the <b><i>Post To SalesTax</i></b> action.</p>
32
+ <p>The <b>Pending</b> status is for invoices that are paid, and by default not to be posted to SalesTax. These invoices are probably from historical orders before the SalesTax integration.</p>
33
+ </div>
34
+ INFO_HTML;
35
+ return $headerInfoHtml;
36
+ }
37
+
38
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/All/Index/Grid.php CHANGED
@@ -1,124 +1,124 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid extends Mage_Adminhtml_Block_Widget_Grid {
14
-
15
- public function __construct(){
16
- parent::__construct();
17
- $this->setId('speedtaxInvoiceAllGrid');
18
- }
19
-
20
- protected function _prepareCollection(){
21
- $collection = Mage::getModel('sales/order_invoice')->getCollection();
22
- $this->setCollection($collection);
23
- $this->setDefaultSort('created_at');
24
- $this->setDefaultDir('desc');
25
- return parent::_prepareCollection();
26
- }
27
-
28
- protected function _prepareColumns()
29
- {
30
- $this->addColumn('increment_id', array(
31
- 'header' => Mage::helper('speedtax')->__('Magento Invoice #'),
32
- 'index' => 'increment_id',
33
- 'type' => 'text',
34
- 'align' => 'right',
35
- ));
36
-
37
- $this->addColumn('action',
38
- array(
39
- 'header' => Mage::helper('sales')->__('Invoice Details'),
40
- 'width' => '100px',
41
- 'type' => 'action',
42
- 'align' => 'right',
43
- 'getter' => 'getId',
44
- 'actions' => array(
45
- array(
46
- 'caption' => Mage::helper('sales')->__('View'),
47
- 'url' => array('base'=>'adminhtml/sales_invoice/view'),
48
- 'field' => 'invoice_id'
49
- )
50
- ),
51
- 'filter' => false,
52
- 'sortable' => false,
53
- 'is_system' => true
54
- ));
55
-
56
- $this->addColumn('created_at', array(
57
- 'header' => Mage::helper('speedtax')->__('Magento Invoice Date'),
58
- 'index' => 'created_at',
59
- 'type' => 'datetime',
60
- 'align' => 'right',
61
- ));
62
-
63
- $this->addColumn('speedtax_invoice_number', array(
64
- 'header' => Mage::helper('speedtax')->__('SalesTax Invoice #'),
65
- 'index' => 'speedtax_invoice_number',
66
- 'type' => 'text',
67
- 'align' => 'right',
68
- ));
69
-
70
- $this->addColumn('speedtax_transaction_id', array(
71
- 'header' => Mage::helper('speedtax')->__('SalesTax Transaction ID'),
72
- 'index' => 'speedtax_transaction_id',
73
- 'type' => 'text',
74
- 'align' => 'right',
75
- ));
76
-
77
- $this->addColumn('tax_amount', array(
78
- 'header' => Mage::helper('speedtax')->__('Magento Tax Amount'),
79
- 'index' => 'tax_amount',
80
- 'type' => 'currency',
81
- 'align' => 'right',
82
- 'currency' => 'order_currency_code',
83
- ));
84
-
85
- $this->addColumn('speedtax_tax_amount', array(
86
- 'header' => Mage::helper('speedtax')->__('SalesTax Tax Amount'),
87
- 'index' => 'speedtax_tax_amount',
88
- 'type' => 'currency',
89
- 'align' => 'right',
90
- 'currency' => 'order_currency_code',
91
- ));
92
-
93
- $this->addColumn('speedtax_invoice_status', array(
94
- 'header' => Mage::helper('speedtax')->__('SalesTax Invoice Status'),
95
- 'width' => '100px',
96
- 'index' => 'speedtax_invoice_status',
97
- 'type' => 'options',
98
- 'align' => 'right',
99
- 'options' => Mage::helper('speedtax')->getSpeedtaxInvoiceStatusValues(),
100
- ));
101
-
102
- return parent::_prepareColumns();
103
- }
104
-
105
- protected function _prepareMassaction()
106
- {
107
- $this->setMassactionIdField('entity_id');
108
- $this->getMassactionBlock()->setFormFieldName('invoice_ids');
109
- $this->getMassactionBlock()->setUseSelectAll(false);
110
-
111
- $this->getMassactionBlock()->addItem('post_selected', array(
112
- 'label' => Mage::helper('sales')->__('Post To SalesTax'),
113
- 'url' => $this->getUrl('*/*/massPostToSpeedtax'),
114
- ));
115
-
116
- return $this;
117
- }
118
-
119
- //No row editing
120
- public function getRowUrl($row){
121
- return false;
122
- }
123
-
124
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid extends Mage_Adminhtml_Block_Widget_Grid {
14
+
15
+ public function __construct(){
16
+ parent::__construct();
17
+ $this->setId('speedtaxInvoiceAllGrid');
18
+ }
19
+
20
+ protected function _prepareCollection(){
21
+ $collection = Mage::getModel('sales/order_invoice')->getCollection();
22
+ $this->setCollection($collection);
23
+ $this->setDefaultSort('created_at');
24
+ $this->setDefaultDir('desc');
25
+ return parent::_prepareCollection();
26
+ }
27
+
28
+ protected function _prepareColumns()
29
+ {
30
+ $this->addColumn('increment_id', array(
31
+ 'header' => Mage::helper('speedtax')->__('Magento Invoice #'),
32
+ 'index' => 'increment_id',
33
+ 'type' => 'text',
34
+ 'align' => 'right',
35
+ ));
36
+
37
+ $this->addColumn('action',
38
+ array(
39
+ 'header' => Mage::helper('sales')->__('Invoice Details'),
40
+ 'width' => '100px',
41
+ 'type' => 'action',
42
+ 'align' => 'right',
43
+ 'getter' => 'getId',
44
+ 'actions' => array(
45
+ array(
46
+ 'caption' => Mage::helper('sales')->__('View'),
47
+ 'url' => array('base'=>'adminhtml/sales_invoice/view'),
48
+ 'field' => 'invoice_id'
49
+ )
50
+ ),
51
+ 'filter' => false,
52
+ 'sortable' => false,
53
+ 'is_system' => true
54
+ ));
55
+
56
+ $this->addColumn('created_at', array(
57
+ 'header' => Mage::helper('speedtax')->__('Magento Invoice Date'),
58
+ 'index' => 'created_at',
59
+ 'type' => 'datetime',
60
+ 'align' => 'right',
61
+ ));
62
+
63
+ $this->addColumn('speedtax_invoice_number', array(
64
+ 'header' => Mage::helper('speedtax')->__('SalesTax Invoice #'),
65
+ 'index' => 'speedtax_invoice_number',
66
+ 'type' => 'text',
67
+ 'align' => 'right',
68
+ ));
69
+
70
+ $this->addColumn('speedtax_transaction_id', array(
71
+ 'header' => Mage::helper('speedtax')->__('SalesTax Transaction ID'),
72
+ 'index' => 'speedtax_transaction_id',
73
+ 'type' => 'text',
74
+ 'align' => 'right',
75
+ ));
76
+
77
+ $this->addColumn('tax_amount', array(
78
+ 'header' => Mage::helper('speedtax')->__('Magento Tax Amount'),
79
+ 'index' => 'tax_amount',
80
+ 'type' => 'currency',
81
+ 'align' => 'right',
82
+ 'currency' => 'order_currency_code',
83
+ ));
84
+
85
+ $this->addColumn('speedtax_tax_amount', array(
86
+ 'header' => Mage::helper('speedtax')->__('SalesTax Tax Amount'),
87
+ 'index' => 'speedtax_tax_amount',
88
+ 'type' => 'currency',
89
+ 'align' => 'right',
90
+ 'currency' => 'order_currency_code',
91
+ ));
92
+
93
+ $this->addColumn('speedtax_invoice_status', array(
94
+ 'header' => Mage::helper('speedtax')->__('SalesTax Invoice Status'),
95
+ 'width' => '100px',
96
+ 'index' => 'speedtax_invoice_status',
97
+ 'type' => 'options',
98
+ 'align' => 'right',
99
+ 'options' => Mage::helper('speedtax')->getSpeedtaxInvoiceStatusValues(),
100
+ ));
101
+
102
+ return parent::_prepareColumns();
103
+ }
104
+
105
+ protected function _prepareMassaction()
106
+ {
107
+ $this->setMassactionIdField('entity_id');
108
+ $this->getMassactionBlock()->setFormFieldName('invoice_ids');
109
+ $this->getMassactionBlock()->setUseSelectAll(false);
110
+
111
+ $this->getMassactionBlock()->addItem('post_selected', array(
112
+ 'label' => Mage::helper('sales')->__('Post To SalesTax'),
113
+ 'url' => $this->getUrl('*/*/massPostToSpeedtax'),
114
+ ));
115
+
116
+ return $this;
117
+ }
118
+
119
+ //No row editing
120
+ public function getRowUrl($row){
121
+ return false;
122
+ }
123
+
124
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Failsafe/Index.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Failsafe_Index extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index {
14
-
15
- public function __construct() {
16
- parent::__construct ();
17
- $this->_blockGroup = 'speedtax';
18
- $this->_controller = 'adminhtml_invoice_failsafe_index';
19
- $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'Failsafe Invoices' );
20
- $this->_removeButton('add');
21
- }
22
-
23
- public function getHeaderInfoHtml(){
24
- $headerInfoHtml = <<< INFO_HTML
25
- <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
26
- <p>Failsafe invoices are paid Magento invoices that are not yet posted to SalesTax. These invoices can be processed in batch either 1) by system cronjobs automatically or 2) by running <b><i>Post To SalesTax</i></b> via the "Actions" dropdown menu next to the "Submit" button.</p>
27
- </div>
28
- INFO_HTML;
29
- return $headerInfoHtml;
30
- }
31
-
32
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Failsafe_Index extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index {
14
+
15
+ public function __construct() {
16
+ parent::__construct ();
17
+ $this->_blockGroup = 'speedtax';
18
+ $this->_controller = 'adminhtml_invoice_failsafe_index';
19
+ $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'Failsafe Invoices' );
20
+ $this->_removeButton('add');
21
+ }
22
+
23
+ public function getHeaderInfoHtml(){
24
+ $headerInfoHtml = <<< INFO_HTML
25
+ <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
26
+ <p>Failsafe invoices are paid Magento invoices that are not yet posted to SalesTax. These invoices can be processed in batch either 1) by system cronjobs automatically or 2) by running <b><i>Post To SalesTax</i></b> via the "Actions" dropdown menu next to the "Submit" button.</p>
27
+ </div>
28
+ INFO_HTML;
29
+ return $headerInfoHtml;
30
+ }
31
+
32
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Failsafe/Index/Grid.php CHANGED
@@ -1,50 +1,50 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Failsafe_Index_Grid extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid {
14
-
15
- public function __construct(){
16
- parent::__construct();
17
- $this->setId('speedtaxInvoiceFailsafeGrid');
18
- }
19
-
20
- public function setCollection($collection){
21
- $collection->addAttributeToFilter('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
22
- return parent::setCollection($collection);
23
- }
24
-
25
- protected function _prepareColumns(){
26
- parent::_prepareColumns();
27
- $this->removeColumn('speedtax_invoice_status');
28
- return $this;
29
- }
30
-
31
- protected function _prepareMassaction()
32
- {
33
- $this->setMassactionIdField('entity_id');
34
- $this->getMassactionBlock()->setFormFieldName('invoice_ids');
35
- $this->getMassactionBlock()->setUseSelectAll(false);
36
-
37
- $this->getMassactionBlock()->addItem('post_selected', array(
38
- 'label' => Mage::helper('sales')->__('Post To SalesTax'),
39
- 'url' => $this->getUrl('*/*/massPostToSpeedtax'),
40
- ));
41
-
42
- return $this;
43
- }
44
-
45
- //No row editing
46
- public function getRowUrl($row){
47
- return false;
48
- }
49
-
50
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Failsafe_Index_Grid extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid {
14
+
15
+ public function __construct(){
16
+ parent::__construct();
17
+ $this->setId('speedtaxInvoiceFailsafeGrid');
18
+ }
19
+
20
+ public function setCollection($collection){
21
+ $collection->addAttributeToFilter('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
22
+ return parent::setCollection($collection);
23
+ }
24
+
25
+ protected function _prepareColumns(){
26
+ parent::_prepareColumns();
27
+ $this->removeColumn('speedtax_invoice_status');
28
+ return $this;
29
+ }
30
+
31
+ protected function _prepareMassaction()
32
+ {
33
+ $this->setMassactionIdField('entity_id');
34
+ $this->getMassactionBlock()->setFormFieldName('invoice_ids');
35
+ $this->getMassactionBlock()->setUseSelectAll(false);
36
+
37
+ $this->getMassactionBlock()->addItem('post_selected', array(
38
+ 'label' => Mage::helper('sales')->__('Post To SalesTax'),
39
+ 'url' => $this->getUrl('*/*/massPostToSpeedtax'),
40
+ ));
41
+
42
+ return $this;
43
+ }
44
+
45
+ //No row editing
46
+ public function getRowUrl($row){
47
+ return false;
48
+ }
49
+
50
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Rateverification/Index.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Rateverification_Index extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index {
14
-
15
- public function __construct() {
16
- parent::__construct ();
17
- $this->_blockGroup = 'speedtax';
18
- $this->_controller = 'adminhtml_invoice_rateverification_index';
19
- $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'Verify Invoices with Failsafe Tax Rates' );
20
- $this->_removeButton('add');
21
- }
22
-
23
- public function getHeaderInfoHtml(){
24
- $headerInfoHtml = <<< INFO_HTML
25
- <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
26
- <p>Invoices in this panel are paid using failsafe rate. For some invoices failsafe rate may be different from the SalesTax rate. In such cases, please reconciliate the difference in SalesTax management panel if necessary.</p>
27
- </div>
28
- INFO_HTML;
29
- return $headerInfoHtml;
30
- }
31
-
32
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Rateverification_Index extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index {
14
+
15
+ public function __construct() {
16
+ parent::__construct ();
17
+ $this->_blockGroup = 'speedtax';
18
+ $this->_controller = 'adminhtml_invoice_rateverification_index';
19
+ $this->_headerText = Mage::helper ( 'speedtax' )->__ ( 'Verify Invoices with Failsafe Tax Rates' );
20
+ $this->_removeButton('add');
21
+ }
22
+
23
+ public function getHeaderInfoHtml(){
24
+ $headerInfoHtml = <<< INFO_HTML
25
+ <div class="grid-top-info" style="background: none repeat scroll 0 0 #E7EFEF; border: 1px solid #CDDDDD; padding: 10px 20px 10px 20px; margin-bottom: 20px;">
26
+ <p>Invoices in this panel are paid using failsafe rate. For some invoices failsafe rate may be different from the SalesTax rate. In such cases, please reconciliate the difference in SalesTax management panel if necessary.</p>
27
+ </div>
28
+ INFO_HTML;
29
+ return $headerInfoHtml;
30
+ }
31
+
32
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Invoice/Rateverification/Index/Grid.php CHANGED
@@ -1,62 +1,62 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Rateverification_Index_Grid extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid {
14
-
15
- public function __construct(){
16
- parent::__construct();
17
- $this->setId('speedtaxInvoiceRateVerificationGrid');
18
- }
19
-
20
- public function setCollection($collection){
21
- $collection->addAttributeToFilter('is_speedtax_failsafe_calculation', 1);
22
- $collection->getSelect()->columns(array(
23
- 'tax_amount_difference' => new Zend_Db_Expr("IFNULL(`main_table`.`speedtax_tax_amount`, 0) - IFNULL(`main_table`.`tax_amount`, 0)"),
24
- 'has_tax_amount_difference' => new Zend_Db_Expr("IF(IFNULL(`main_table`.`speedtax_tax_amount`, 0) - IFNULL(`main_table`.`tax_amount`, 0) = 0, 0, 1)"),
25
- ));
26
-
27
- //Re-wrap the collection to support generic form sort and filter
28
- $outerCollection = Mage::getModel('sales/order_invoice')->getCollection();
29
- $outerCollection->getSelect()->reset();
30
- $outerCollection->getSelect()->from(array('main_table' => $collection->getSelect()));
31
- return parent::setCollection($outerCollection);
32
- }
33
-
34
- protected function _prepareColumns(){
35
- parent::_prepareColumns();
36
- $this->addColumn('tax_amount_difference', array(
37
- 'header' => Mage::helper('speedtax')->__('Tax Difference (SalesTax - Magento)'),
38
- 'index' => 'tax_amount_difference',
39
- 'type' => 'currency',
40
- 'align' => 'right',
41
- 'currency' => 'order_currency_code',
42
- ));
43
- $this->addColumn('has_tax_amount_difference', array(
44
- 'header' => Mage::helper('speedtax')->__('Has Tax Difference'),
45
- 'index' => 'has_tax_amount_difference',
46
- 'type' => 'options',
47
- 'align' => 'right',
48
- 'options' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray(),
49
- ));
50
- return $this;
51
- }
52
-
53
- protected function _prepareMassaction(){
54
- return $this;
55
- }
56
-
57
- //No row editing
58
- public function getRowUrl($row){
59
- return false;
60
- }
61
-
62
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Block_Adminhtml_Invoice_Rateverification_Index_Grid extends Harapartners_SpeedTax_Block_Adminhtml_Invoice_All_Index_Grid {
14
+
15
+ public function __construct(){
16
+ parent::__construct();
17
+ $this->setId('speedtaxInvoiceRateVerificationGrid');
18
+ }
19
+
20
+ public function setCollection($collection){
21
+ $collection->addAttributeToFilter('is_speedtax_failsafe_calculation', 1);
22
+ $collection->getSelect()->columns(array(
23
+ 'tax_amount_difference' => new Zend_Db_Expr("IFNULL(`main_table`.`speedtax_tax_amount`, 0) - IFNULL(`main_table`.`tax_amount`, 0)"),
24
+ 'has_tax_amount_difference' => new Zend_Db_Expr("IF(IFNULL(`main_table`.`speedtax_tax_amount`, 0) - IFNULL(`main_table`.`tax_amount`, 0) = 0, 0, 1)"),
25
+ ));
26
+
27
+ //Re-wrap the collection to support generic form sort and filter
28
+ $outerCollection = Mage::getModel('sales/order_invoice')->getCollection();
29
+ $outerCollection->getSelect()->reset();
30
+ $outerCollection->getSelect()->from(array('main_table' => $collection->getSelect()));
31
+ return parent::setCollection($outerCollection);
32
+ }
33
+
34
+ protected function _prepareColumns(){
35
+ parent::_prepareColumns();
36
+ $this->addColumn('tax_amount_difference', array(
37
+ 'header' => Mage::helper('speedtax')->__('Tax Difference (SalesTax - Magento)'),
38
+ 'index' => 'tax_amount_difference',
39
+ 'type' => 'currency',
40
+ 'align' => 'right',
41
+ 'currency' => 'order_currency_code',
42
+ ));
43
+ $this->addColumn('has_tax_amount_difference', array(
44
+ 'header' => Mage::helper('speedtax')->__('Has Tax Difference'),
45
+ 'index' => 'has_tax_amount_difference',
46
+ 'type' => 'options',
47
+ 'align' => 'right',
48
+ 'options' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray(),
49
+ ));
50
+ return $this;
51
+ }
52
+
53
+ protected function _prepareMassaction(){
54
+ return $this;
55
+ }
56
+
57
+ //No row editing
58
+ public function getRowUrl($row){
59
+ return false;
60
+ }
61
+
62
  }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/Notification.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
-
14
- class Harapartners_SpeedTax_Block_Adminhtml_Notification extends Mage_Adminhtml_Block_Template {
15
-
16
- protected function _toHtml() {
17
- $htmlContent = "";
18
- $notificationDisabled = json_decode(Mage::getStoreConfig(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS), 1);
19
-
20
- //TODO: add ACL restriction to screen some messages
21
- $speedtaxMessages = array();
22
-
23
- // ---------------- Tax on Discount ---------------- //
24
- if(!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT)
25
- && empty($notificationDisabled[Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT])
26
- ){
27
- $speedtaxMessages[Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT] = '
28
- Your tax configuration "Calculation Setting >> Apply Customer Tax" is set to <strong class="label">Before Discount</strong>, which is the default value.
29
- If your business logic requires tax <strong class="label">After Discount</strong>, please click <a href="' . Mage::helper("adminhtml")->getUrl("adminhtml/system_config/edit", array("section" => "tax")). '">HERE</a> to update the setting.
30
- <i><a href="' . Mage::helper("adminhtml")->getUrl("speedtax_adminhtml/notification/disable", array("notification_key" => Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT)) . '">Dismiss this message</a></i>';
31
- }
32
-
33
- // ---------------- Output ---------------- //
34
- foreach($speedtaxMessages as $messageKey => $messageContent){
35
- $htmlContent .= <<< HTML_CONTENT
36
- <div class="notification-global">
37
- <strong class="label">SalesTax notification:</strong> $messageContent
38
- </div>
39
- HTML_CONTENT;
40
- }
41
- return $htmlContent;
42
- }
43
-
44
- }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+
14
+ class Harapartners_SpeedTax_Block_Adminhtml_Notification extends Mage_Adminhtml_Block_Template {
15
+
16
+ protected function _toHtml() {
17
+ $htmlContent = "";
18
+ $notificationDisabled = json_decode(Mage::getStoreConfig(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS), 1);
19
+
20
+ //TODO: add ACL restriction to screen some messages
21
+ $speedtaxMessages = array();
22
+
23
+ // ---------------- Tax on Discount ---------------- //
24
+ if(!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT)
25
+ && empty($notificationDisabled[Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT])
26
+ ){
27
+ $speedtaxMessages[Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT] = '
28
+ Your tax configuration "Calculation Setting >> Apply Customer Tax" is set to <strong class="label">Before Discount</strong>, which is the default value.
29
+ If your business logic requires tax <strong class="label">After Discount</strong>, please click <a href="' . Mage::helper("adminhtml")->getUrl("adminhtml/system_config/edit", array("section" => "tax")). '">HERE</a> to update the setting.
30
+ <i><a href="' . Mage::helper("adminhtml")->getUrl("speedtax_adminhtml/notification/disable", array("notification_key" => Harapartners_SpeedTax_Helper_Data::NOTIFICATION_KEY_TAX_ON_DISCOUNT)) . '">Dismiss this message</a></i>';
31
+ }
32
+
33
+ // ---------------- Output ---------------- //
34
+ foreach($speedtaxMessages as $messageKey => $messageContent){
35
+ $htmlContent .= <<< HTML_CONTENT
36
+ <div class="notification-global">
37
+ <strong class="label">SalesTax notification:</strong> $messageContent
38
+ </div>
39
+ HTML_CONTENT;
40
+ }
41
+ return $htmlContent;
42
+ }
43
+
44
+ }
app/code/community/Harapartners/SpeedTax/Block/Adminhtml/System/Config/Form/Field/Authentication.php CHANGED
@@ -1,77 +1,77 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
-
14
- class Harapartners_SpeedTax_Block_Adminhtml_System_Config_Form_Field_Authentication extends Mage_Adminhtml_Block_System_Config_Form_Field {
15
-
16
- protected function _toHtml() {
17
- $htmlId = $this->getHtmlId();
18
- $ajaxUrl = $this->getAjaxUrl();
19
- $buttonLabel = $this->escapeHtml($this->getButtonLabel());
20
-
21
- $htmlContent = <<< HTML_CONTENT
22
- <script type="text/javascript">
23
- function ajaxLogin() {
24
- var elem = $('$htmlId');
25
-
26
- params = {
27
- username: $('speedtax_speedtax_username').value,
28
- password: $('speedtax_speedtax_password').value,
29
- company_code: $('speedtax_speedtax_company_code').value,
30
- is_test_mode: $('speedtax_speedtax_is_test_mode').value
31
- };
32
-
33
- new Ajax.Request('$ajaxUrl', {
34
- parameters: params,
35
- onSuccess: function(response) {
36
- result = 'Login failed!';
37
- try {
38
- response = JSON.parse(response.responseText);
39
- result = response.message;
40
- if (response.status == 1) {
41
- elem.removeClassName('fail').addClassName('success');
42
- } else {
43
- elem.removeClassName('success').addClassName('fail');
44
- }
45
- } catch (e) {
46
- elem.removeClassName('success').addClassName('fail');
47
- }
48
- $('ajax_login_result').update(result);
49
- }
50
- });
51
- }
52
- </script>
53
- <button onclick="javascript:ajaxLogin(); return false;" class="scalable" type="button" id="$htmlId">
54
- <span><span><span id="ajax_login_result">$buttonLabel</span></span></span>
55
- </button>
56
- HTML_CONTENT;
57
-
58
- return $htmlContent;
59
- }
60
-
61
- public function render(Varien_Data_Form_Element_Abstract $element){
62
- $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
63
- return parent::render($element);
64
- }
65
-
66
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
67
- $originalData = $element->getOriginalData();
68
- $this->addData(array(
69
- 'button_label' => Mage::helper('speedtax')->__($originalData['button_label']),
70
- 'html_id' => $element->getHtmlId(),
71
- 'ajax_url' => Mage::getSingleton('adminhtml/url')->getUrl('speedtax_adminhtml/system_config_ajax/authentication')
72
- ));
73
-
74
- return $this->_toHtml();
75
- }
76
-
77
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+
14
+ class Harapartners_SpeedTax_Block_Adminhtml_System_Config_Form_Field_Authentication extends Mage_Adminhtml_Block_System_Config_Form_Field {
15
+
16
+ protected function _toHtml() {
17
+ $htmlId = $this->getHtmlId();
18
+ $ajaxUrl = $this->getAjaxUrl();
19
+ $buttonLabel = $this->escapeHtml($this->getButtonLabel());
20
+
21
+ $htmlContent = <<< HTML_CONTENT
22
+ <script type="text/javascript">
23
+ function ajaxLogin() {
24
+ var elem = $('$htmlId');
25
+
26
+ params = {
27
+ username: $('speedtax_speedtax_username').value,
28
+ password: $('speedtax_speedtax_password').value,
29
+ company_code: $('speedtax_speedtax_company_code').value,
30
+ is_test_mode: $('speedtax_speedtax_is_test_mode').value
31
+ };
32
+
33
+ new Ajax.Request('$ajaxUrl', {
34
+ parameters: params,
35
+ onSuccess: function(response) {
36
+ result = 'Login failed!';
37
+ try {
38
+ response = JSON.parse(response.responseText);
39
+ result = response.message;
40
+ if (response.status == 1) {
41
+ elem.removeClassName('fail').addClassName('success');
42
+ } else {
43
+ elem.removeClassName('success').addClassName('fail');
44
+ }
45
+ } catch (e) {
46
+ elem.removeClassName('success').addClassName('fail');
47
+ }
48
+ $('ajax_login_result').update(result);
49
+ }
50
+ });
51
+ }
52
+ </script>
53
+ <button onclick="javascript:ajaxLogin(); return false;" class="scalable" type="button" id="$htmlId">
54
+ <span><span><span id="ajax_login_result">$buttonLabel</span></span></span>
55
+ </button>
56
+ HTML_CONTENT;
57
+
58
+ return $htmlContent;
59
+ }
60
+
61
+ public function render(Varien_Data_Form_Element_Abstract $element){
62
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
63
+ return parent::render($element);
64
+ }
65
+
66
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
67
+ $originalData = $element->getOriginalData();
68
+ $this->addData(array(
69
+ 'button_label' => Mage::helper('speedtax')->__($originalData['button_label']),
70
+ 'html_id' => $element->getHtmlId(),
71
+ 'ajax_url' => Mage::getSingleton('adminhtml/url')->getUrl('speedtax_adminhtml/system_config_ajax/authentication')
72
+ ));
73
+
74
+ return $this->_toHtml();
75
+ }
76
+
77
  }
app/code/community/Harapartners/SpeedTax/Helper/Connector/Data.php CHANGED
@@ -1,262 +1,300 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Helper_Connector_Data extends Mage_Core_Helper_Abstract {
14
-
15
- const TAX_SHIPPING_LINEITEM_TAX_CLASS = 'TAX_SHIPPING';
16
- const TAX_SHIPPING_LINEITEM_REFERNCE_NAME = 'TAX_SHIPPING';
17
-
18
- protected $_productTaxClassNoneTaxableId = 0; //Magento default
19
- // protected $_allowedCountryIds = array('US', 'CA');
20
-
21
- protected $_shipFromAddress = null;
22
- protected $_shipToAddress = null;
23
-
24
- // ========================== Main entry points ========================== //
25
- public function prepareSpeedTaxInvoiceByMageQuoteAddress(Mage_Sales_Model_Quote_Address $mageQuoteAddress) {
26
- $sptxInvoice = new stdClass();
27
- $sptxInvoice->lineItems = array();
28
- $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
29
-
30
- foreach ( $mageQuoteAddress->getAllItems () as $mageQuoteItem ) {
31
- if(!!$mageQuoteItem->getParentItemId()){
32
- continue;
33
- }
34
- //Multiple shipping checkout, $mageQuoteItem is instance of Mage_Sales_Model_Quote_Address_Item, not a sub-class of Mage_Sales_Model_Quote_Item
35
- //Many product related fields must be obtained from the product object directly
36
- if($mageQuoteItem->getProduct()->getTaxClassId() == $this->_productTaxClassNoneTaxableId){
37
- continue;
38
- }
39
-
40
- //Respect Magento tax/discount config
41
- $taxableAmount = $mageQuoteItem->getRowTotal();
42
- if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageQuoteItem->getStoreId())){
43
- $taxableAmount = $taxableAmount - $mageQuoteItem->getDiscountAmount() + $mageQuoteItem->getHiddenTaxAmount();
44
- }
45
- if($taxableAmount <= 0){
46
- continue;
47
- }
48
-
49
- $lineItem = new stdClass();
50
- $lineItem->productCode = $this->_getProductCode($mageQuoteItem);
51
- $lineItem->customReference = $mageQuoteItem->getId();
52
- $lineItem->quantity = $mageQuoteItem->getQty();
53
- $lineItem->shipFromAddress = $this->_getShipFromAddress();
54
- $lineItem->shipToAddress = $this->_getShippingToAddress($mageQuoteAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
55
-
56
- //Price of row total, not unit price
57
- $lineItemPrice = new stdClass();
58
- $lineItemPrice->decimalValue = $taxableAmount;
59
- $lineItem->salesAmount = $lineItemPrice;
60
-
61
- $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
62
- $sptxInvoice->lineItems[] = $lineItem;
63
- }
64
-
65
- // ----- Other line items ----- //
66
- //If global store config specifies: "tax_shipping", then create shipping cost line item. Note this is different from "Tax_Shipping" tax class of a product
67
- $shipingAmount = $mageQuoteAddress->getShippingAmount();
68
- if(!!Mage::getStoreConfig("speedtax/speedtax/tax_shipping") && $shipingAmount > 0.0){
69
- $shippingLineItem = $this->_generateLineItemFromShippingCost($mageQuoteAddress, $shipingAmount);
70
- $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
71
- $sptxInvoice->lineItems[] = $shippingLineItem;
72
- }
73
-
74
- $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
75
- return $sptxInvoice;
76
- }
77
-
78
- public function prepareSpeedTaxInvoiceByMageOrderInvoice(Mage_Sales_Model_Order_Invoice $mageOrderInvoice) {
79
- //Clear the invoice number so that the request is just a query
80
- $mageOrderAddress = $mageOrderInvoice->getShippingAddress();
81
- $sptxInvoice = new stdClass();
82
- $sptxInvoice->lineItems = array();
83
- //Important to keep unique, invoice should already be attached to the order, count starts from 1
84
- $sptxInvoice->invoiceNumber =
85
- $mageOrderInvoice->getOrder()->getIncrementId()
86
- . '-INV-' . ($mageOrderInvoice->getOrder()->getInvoiceCollection()->count());
87
- $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
88
-
89
- foreach ( $mageOrderInvoice->getAllItems() as $mageItem ) {
90
- if(!$mageItem->getTaxAmount() || $mageItem->getTaxAmount() <= 0.0){
91
- continue;
92
- }
93
-
94
- //Respect Magento tax/discount config
95
- $taxableAmount = $mageItem->getRowTotal();
96
- if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageItem->getStoreId())){
97
- $taxableAmount = $taxableAmount - $mageItem->getDiscountAmount() + $mageItem->getHiddenTaxAmount();
98
- }
99
-
100
- $lineItem = new stdClass();
101
- $lineItem->productCode = $this->_getProductCode($mageItem);
102
- $lineItem->customReference = $mageItem->getOrderItemId(); //This is during invoice creation, no ID available
103
- $lineItem->quantity = $mageItem->getQty();
104
- $lineItem->shipFromAddress = $this->_getShipFromAddress();
105
- $lineItem->shipToAddress = $this->_getShippingToAddress($mageOrderAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
106
-
107
- //Price of row total, not unit price
108
- $lineItemPrice = new stdClass();
109
- $lineItemPrice->decimalValue = $taxableAmount;
110
- $lineItem->salesAmount = $lineItemPrice;
111
-
112
- $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
113
- $sptxInvoice->lineItems[] = $lineItem;
114
- }
115
-
116
- // ----- Other line items ----- //
117
- //If global store config specifies: "tax_shipping", then create shipping cost line item. Note this is different from "Tax_Shipping" tax class of a product
118
- if($mageOrderInvoice->getShippingAmount() === null){
119
- $mageOrderInvoice->collectTotals();
120
- }
121
- $shipingAmount = $mageOrderInvoice->getShippingAmount();
122
- if(!!Mage::getStoreConfig("speedtax/speedtax/tax_shipping") && $shipingAmount > 0.0){
123
- $shippingLineItem = $this->_generateLineItemFromShippingCost($mageOrderAddress, $shipingAmount);
124
- $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
125
- $sptxInvoice->lineItems[] = $shippingLineItem;
126
- }
127
-
128
- $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
129
- return $sptxInvoice;
130
- }
131
-
132
- public function prepareSpeedTaxInvoiceByMageOrderCreditmemo(Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo) {
133
- //Clear the invoice number so that the request is just a query
134
- $mageOrderAddress = $mageOrderCreditmemo->getShippingAddress();
135
- $sptxInvoice = new stdClass();
136
- $sptxInvoice->lineItems = array();
137
-
138
- //Important to keep unique, credit memo not yet attached to the order, count ++ so that it starts from 1
139
- $sptxInvoice->invoiceNumber =
140
- $mageOrderCreditmemo->getOrder()->getIncrementId()
141
- . '-CR-' . ($mageOrderCreditmemo->getOrder()->getCreditmemosCollection()->count() + 1);
142
- $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
143
-
144
- foreach ( $mageOrderCreditmemo->getAllItems() as $mageItem ) {
145
- if(!$mageItem->getTaxAmount() || $mageItem->getTaxAmount() <= 0.0){
146
- continue;
147
- }
148
-
149
- //Respect Magento tax/discount config
150
- $taxableAmount = $mageItem->getRowTotal();
151
- if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageItem->getStoreId())){
152
- $taxableAmount = $taxableAmount - $mageItem->getDiscountAmount() + $mageItem->getHiddenTaxAmount();
153
- }
154
-
155
- $lineItem = new stdClass();
156
- $lineItem->productCode = $this->_getProductCode($mageItem);
157
- $lineItem->customReference = $mageItem->getOrderItemId(); //This is during credit memo creation, no ID available
158
- $lineItem->quantity = $mageItem->getQty();
159
- $lineItem->shipFromAddress = $this->_getShipFromAddress();
160
- $lineItem->shipToAddress = $this->_getShippingToAddress($mageOrderAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
161
-
162
- //Price of row total, not unit price
163
- $lineItemPrice = new stdClass();
164
- $lineItemPrice->decimalValue = $taxableAmount;
165
- $lineItem->salesAmount = $lineItemPrice;
166
-
167
- $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
168
- $sptxInvoice->lineItems[] = $lineItem;
169
- }
170
-
171
- // ----- Other line items ----- //
172
- //If global store config specifies: "tax_shipping", then create shipping cost line item. Note this is different from "Tax_Shipping" tax class of a product
173
- if($mageOrderCreditmemo->getShippingAmount() === null){
174
- $mageOrderCreditmemo->collectTotals();
175
- }
176
- $shipingAmount = $mageOrderCreditmemo->getShippingAmount();
177
- if(!!Mage::getStoreConfig("speedtax/speedtax/tax_shipping") && $shipingAmount > 0.0){
178
- $shippingLineItem = $this->_generateLineItemFromShippingCost($mageOrderAddress, $shipingAmount);
179
- $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
180
- $sptxInvoice->lineItems[] = $shippingLineItem;
181
- }
182
-
183
- $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
184
- return $sptxInvoice;
185
- }
186
-
187
- // ========================== Utilities ========================== //
188
- protected function _generateLineItemFromShippingCost($mageAddress, $shipingAmount) {
189
- $shippingLineItem = new stdClass();
190
- $shippingLineItem->productCode = self::TAX_SHIPPING_LINEITEM_TAX_CLASS;
191
- $shippingLineItem->customReference = self::TAX_SHIPPING_LINEITEM_REFERNCE_NAME;
192
- $shippingLineItem->quantity = 1;
193
- $shippingLineItem->shipFromAddress = $this->_getShipFromAddress ();
194
- $shippingLineItem->shipToAddress = $this->_getShippingToAddress ($mageAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
195
-
196
- $shippingPrice = new stdClass();
197
- $shippingPrice->decimalValue = $shipingAmount;
198
- $shippingLineItem->salesAmount = $shippingPrice;
199
-
200
- return $shippingLineItem;
201
- }
202
-
203
- //Shipping Origin Address
204
- protected function _getShipFromAddress() {
205
- if($this->_shipFromAddress === null){
206
- $this->_shipFromAddress = new stdClass();
207
- $countryId = Mage::getStoreConfig ( 'shipping/origin/country_id');
208
- $zip = Mage::getStoreConfig ('shipping/origin/postcode');
209
- $regionId = Mage::getStoreConfig ( 'shipping/origin/region_id');
210
- $state = Mage::getModel('directory/region')->load($regionId)->getName();
211
- $city = Mage::getStoreConfig ('shipping/origin/city');
212
- $street = Mage::getStoreConfig ('shipping/origin/street');
213
-
214
- $this->_shipFromAddress->address1 = $street;
215
- $this->_shipFromAddress->address2 = $city . ", " . $state . " " . $zip; //. ", " . $countryId;
216
- }
217
- return $this->_shipFromAddress;
218
- }
219
-
220
- //Shipping Destination Address
221
- protected function _getShippingToAddress($address) {
222
- if($this->_shipToAddress === null){
223
- $this->_shipToAddress = new stdClass();
224
- $country = $address->getCountry();
225
- $zip = $address->getPostcode(); //$zip = preg_replace('/[^0-9\-]*/', '', $address->getPostcode()); //US zip code clean up
226
- $state = $address->getRegion(); //No region resolution needed, $this->_getStateCodeByRegionId($address->getState());
227
- $city = $address->getCity();
228
- $street = implode(' ', $address->getStreet()); //In case of multiple line address
229
-
230
- $this->_shipToAddress->address1 = $street;
231
- $this->_shipToAddress->address2 = $city . ", " . $state . " " . $zip; //. ", " . $county;
232
- }
233
- return $this->_shipToAddress;
234
- }
235
-
236
-
237
- //In a standard setup, tax is calculated by tax class (i.e. product code), if empty use default
238
- //Advanced calculation by product SKU is also possible. Please contact SpeedTax support to setup advanced service
239
- protected function _getProductCode($item){
240
- $useTaxCode = Mage::helper('speedtax')->useTaxClass();
241
- if(!$useTaxCode){
242
- return $item->getSku();
243
- }
244
- if($taxCode = $this->_getTaxClassByItem($item)){
245
- return $taxCode;
246
- }else{
247
- return $item->getSku();
248
- }
249
- }
250
-
251
- protected function _getTaxClassByItem($item){
252
- $storeId = Mage::app()->getStore()->getId();
253
- $taxClassId = Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getProductId(), 'tax_class_id', $storeId);
254
- if($taxClassId){
255
- $taxClassCode = Mage::getModel('tax/class_source_product')->getOptionText($taxClassId);
256
- }else{
257
- $taxClassCode = null;
258
- }
259
- return $taxClassCode;
260
- }
261
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Helper_Connector_Data extends Mage_Core_Helper_Abstract {
14
+
15
+ protected $_productTaxClassNoneTaxableId = 0; //Magento default
16
+ // protected $_allowedCountryIds = array('US', 'CA');
17
+
18
+ protected $_shipFromAddress = null;
19
+ protected $_shipToAddress = null;
20
+
21
+ // ========================== Main entry points ========================== //
22
+ public function prepareSpeedTaxInvoiceByMageQuoteAddress(Mage_Sales_Model_Quote_Address $mageQuoteAddress) {
23
+ $sptxInvoice = new stdClass();
24
+ $sptxInvoice->lineItems = array();
25
+ $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
26
+
27
+ foreach ( $mageQuoteAddress->getAllItems () as $mageQuoteItem ) {
28
+ if(!!$mageQuoteItem->getParentItemId()){
29
+ continue;
30
+ }
31
+ //Multiple shipping checkout, $mageQuoteItem is instance of Mage_Sales_Model_Quote_Address_Item, not a sub-class of Mage_Sales_Model_Quote_Item
32
+ //Many product related fields must be obtained from the product object directly
33
+ if($mageQuoteItem->getProduct()->getTaxClassId() == $this->_productTaxClassNoneTaxableId){
34
+ continue;
35
+ }
36
+
37
+ //Respect Magento tax/discount config
38
+ $taxableAmount = $mageQuoteItem->getRowTotal();
39
+ if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageQuoteItem->getStoreId())){
40
+ $taxableAmount = $taxableAmount - $mageQuoteItem->getDiscountAmount() + $mageQuoteItem->getHiddenTaxAmount();
41
+ }
42
+ if($taxableAmount <= 0){
43
+ continue;
44
+ }
45
+
46
+ $lineItem = new stdClass();
47
+ $lineItem->productCode = $this->_getProductCode($mageQuoteItem);
48
+ $lineItem->customReference = $mageQuoteItem->getId();
49
+ $lineItem->quantity = $mageQuoteItem->getQty();
50
+ $lineItem->shipFromAddress = $this->_getShipFromAddress();
51
+ $lineItem->shipToAddress = $this->_getShippingToAddress($mageQuoteAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
52
+
53
+ //Price of row total, not unit price
54
+ $lineItemPrice = new stdClass();
55
+ $lineItemPrice->decimalValue = $taxableAmount;
56
+ $lineItem->salesAmount = $lineItemPrice;
57
+
58
+ $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
59
+ $sptxInvoice->lineItems[] = $lineItem;
60
+ }
61
+
62
+ // ----- Other line items ----- //
63
+ //If global store config specifies: "is_tax_shipping", then create shipping cost line item.
64
+ //The tax code of this line item is specified by system config
65
+ $shipingAmount = $mageQuoteAddress->getShippingAmount();
66
+ if(!!Mage::getStoreConfig("speedtax/speedtax/is_tax_shipping") && $shipingAmount > 0.0){
67
+ $shippingLineItem = $this->_generateLineItemFromShippingCost($mageQuoteAddress, $shipingAmount);
68
+ $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
69
+ $sptxInvoice->lineItems[] = $shippingLineItem;
70
+ }
71
+
72
+ $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
73
+ return $sptxInvoice;
74
+ }
75
+
76
+ public function prepareSpeedTaxInvoiceByMageOrderInvoice(Mage_Sales_Model_Order_Invoice $mageOrderInvoice) {
77
+ //Clear the invoice number so that the request is just a query
78
+ $mageOrderAddress = $mageOrderInvoice->getShippingAddress();
79
+ $sptxInvoice = new stdClass();
80
+ $sptxInvoice->lineItems = array();
81
+ //Important to keep unique, invoice should already be attached to the order, count starts from 1
82
+ $sptxInvoice->invoiceNumber =
83
+ $mageOrderInvoice->getOrder()->getIncrementId()
84
+ . '-INV-' . ($mageOrderInvoice->getOrder()->getInvoiceCollection()->count());
85
+ $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
86
+
87
+ foreach ( $mageOrderInvoice->getAllItems() as $mageItem ) {
88
+ if(!$mageItem->getTaxAmount() || $mageItem->getTaxAmount() <= 0.0){
89
+ continue;
90
+ }
91
+
92
+ //Respect Magento tax/discount config
93
+ $taxableAmount = $mageItem->getRowTotal();
94
+ if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageItem->getStoreId())){
95
+ $taxableAmount = $taxableAmount - $mageItem->getDiscountAmount() + $mageItem->getHiddenTaxAmount();
96
+ }
97
+
98
+ $lineItem = new stdClass();
99
+ $lineItem->productCode = $this->_getProductCode($mageItem);
100
+ $lineItem->customReference = $mageItem->getOrderItemId(); //This is during invoice creation, no ID available
101
+ $lineItem->quantity = $mageItem->getQty();
102
+ $lineItem->shipFromAddress = $this->_getShipFromAddress();
103
+ $lineItem->shipToAddress = $this->_getShippingToAddress($mageOrderAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
104
+
105
+ //Price of row total, not unit price
106
+ $lineItemPrice = new stdClass();
107
+ $lineItemPrice->decimalValue = $taxableAmount;
108
+ $lineItem->salesAmount = $lineItemPrice;
109
+
110
+ $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
111
+ $sptxInvoice->lineItems[] = $lineItem;
112
+ }
113
+
114
+ // ----- Other line items ----- //
115
+ //If global store config specifies: "is_tax_shipping", then create shipping cost line item.
116
+ //The tax code of this line item is specified by system config
117
+ if($mageOrderInvoice->getShippingAmount() === null){
118
+ $mageOrderInvoice->collectTotals();
119
+ }
120
+ $shipingAmount = $mageOrderInvoice->getShippingAmount();
121
+ $shipingTaxAmount = $mageOrderInvoice->getShippingTaxAmount();
122
+ // Must check shipping tax amount is NOT forced to 0 by Magento
123
+ if(!!Mage::getStoreConfig("speedtax/speedtax/is_tax_shipping") && $shipingAmount > 0.0 && $shipingTaxAmount > 0.0){
124
+ $shippingLineItem = $this->_generateLineItemFromShippingCost($mageOrderAddress, $shipingAmount);
125
+ $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
126
+ $sptxInvoice->lineItems[] = $shippingLineItem;
127
+ }
128
+
129
+ $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
130
+ return $sptxInvoice;
131
+ }
132
+
133
+ public function prepareSpeedTaxInvoiceByMageOrderCreditmemo(Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo) {
134
+ //Clear the invoice number so that the request is just a query
135
+ $mageOrderAddress = $mageOrderCreditmemo->getShippingAddress();
136
+ $sptxInvoice = new stdClass();
137
+ $sptxInvoice->lineItems = array();
138
+
139
+ //Important to keep unique, credit memo not yet attached to the order, count ++ so that it starts from 1
140
+ $sptxInvoice->invoiceNumber =
141
+ $mageOrderCreditmemo->getOrder()->getIncrementId()
142
+ . '-CR-' . ($mageOrderCreditmemo->getOrder()->getCreditmemosCollection()->count() + 1);
143
+ $sptxInvoice->customerIdentifier = Mage::getStoreConfig ( 'speedtax/speedtax/username' );
144
+
145
+ foreach ( $mageOrderCreditmemo->getAllItems() as $mageItem ) {
146
+ if(!$mageItem->getTaxAmount() || $mageItem->getTaxAmount() <= 0.0){
147
+ continue;
148
+ }
149
+
150
+ //Respect Magento tax/discount config
151
+ $taxableAmount = $mageItem->getRowTotal();
152
+ if(!!Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $mageItem->getStoreId())){
153
+ $taxableAmount = $taxableAmount - $mageItem->getDiscountAmount() + $mageItem->getHiddenTaxAmount();
154
+ }
155
+
156
+ $lineItem = new stdClass();
157
+ $lineItem->productCode = $this->_getProductCode($mageItem);
158
+ $lineItem->customReference = $mageItem->getOrderItemId(); //This is during credit memo creation, no ID available
159
+ $lineItem->quantity = $mageItem->getQty();
160
+ $lineItem->shipFromAddress = $this->_getShipFromAddress();
161
+ $lineItem->shipToAddress = $this->_getShippingToAddress($mageOrderAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
162
+
163
+ //Price of row total, not unit price
164
+ $lineItemPrice = new stdClass();
165
+ $lineItemPrice->decimalValue = $taxableAmount;
166
+ $lineItem->salesAmount = $lineItemPrice;
167
+
168
+ $lineItem->lineItemNumber = count( $sptxInvoice->lineItems );
169
+ $sptxInvoice->lineItems[] = $lineItem;
170
+ }
171
+
172
+ // ----- Other line items ----- //
173
+ //If global store config specifies: "is_tax_shipping", then create shipping cost line item.
174
+ //The tax code of this line item is specified by system config
175
+ if($mageOrderCreditmemo->getShippingAmount() === null){
176
+ $mageOrderCreditmemo->collectTotals();
177
+ }
178
+ $shipingAmount = $mageOrderCreditmemo->getShippingAmount();
179
+ $shipingTaxAmount = $mageOrderInvoice->getShippingTaxAmount();
180
+ // Must check shipping tax amount is NOT forced to 0 by Magento
181
+ if(!!Mage::getStoreConfig("speedtax/speedtax/is_tax_shipping") && $shipingAmount > 0.0 && $shipingTaxAmount > 0.0){
182
+ $shippingLineItem = $this->_generateLineItemFromShippingCost($mageOrderAddress, $shipingAmount);
183
+ $shippingLineItem->lineItemNumber = count( $sptxInvoice->lineItems );
184
+ $sptxInvoice->lineItems[] = $shippingLineItem;
185
+ }
186
+
187
+ $sptxInvoice->invoiceDate = date('Y-m-d H:i:s');
188
+ return $sptxInvoice;
189
+ }
190
+
191
+ // ========================== Utilities ========================== //
192
+ public function mapAddressExceptions($sourceAddress){
193
+ //By default the we take the source address as the ship to address for tax calculation
194
+ $mappedAddress = $sourceAddress;
195
+
196
+ //However, we also allow exceptions where billing address is used for calculation, if:
197
+ //1) The source address in NOT in the exception list, and
198
+ //2) The billing address (of the corresponding order or quote) is in the exception list
199
+ $isExceptionEnabled = Mage::getStoreConfig('speedtax/tax_by_billing/is_enabled');
200
+ $exceptionOrigin = explode(',', Mage::getStoreConfig('speedtax/tax_by_billing/billing_origins'));
201
+ if($isExceptionEnabled && !in_array($sourceAddress->getRegionId(), $exceptionOrigin)){
202
+ //Seach for billing address
203
+ $billingAddress = null;
204
+ if($sourceAddress instanceof Mage_Sales_Model_Quote_Address){
205
+ $quote = $sourceAddress->getQuote();
206
+ if(!!$quote && !!$quote->getBillingAddress()
207
+ && in_array($quote->getBillingAddress()->getRegionId(), $exceptionOrigin)
208
+ ){
209
+ $mappedAddress = $quote->getBillingAddress();
210
+ }
211
+ }elseif($sourceAddress instanceof Mage_Sales_Model_Order_Address){
212
+ $order = $sourceAddress->getOrder();
213
+ if(!!$order && !!$order->getBillingAddress()
214
+ && in_array($order->getBillingAddress()->getRegionId(), $exceptionOrigin)
215
+ ){
216
+ $mappedAddress = $order->getBillingAddress();
217
+ }
218
+ }
219
+ }
220
+ return $mappedAddress;
221
+ }
222
+
223
+ protected function _generateLineItemFromShippingCost($mageAddress, $shipingAmount) {
224
+ $shippingLineItem = new stdClass();
225
+ $shippingLineItem->productCode = Mage::getStoreConfig("speedtax/speedtax/shipping_tax_code");
226
+ $shippingLineItem->customReference = Mage::getStoreConfig("speedtax/speedtax/shipping_tax_code");
227
+ $shippingLineItem->quantity = 1;
228
+ $shippingLineItem->shipFromAddress = $this->_getShipFromAddress();
229
+ $shippingLineItem->shipToAddress = $this->_getShippingToAddress($mageAddress); //Note, address type is validated at the entry point 'queryQuoteAddress'
230
+
231
+ $shippingPrice = new stdClass();
232
+ $shippingPrice->decimalValue = $shipingAmount;
233
+ $shippingLineItem->salesAmount = $shippingPrice;
234
+
235
+ return $shippingLineItem;
236
+ }
237
+
238
+ //Shipping Origin Address
239
+ protected function _getShipFromAddress() {
240
+ if($this->_shipFromAddress === null){
241
+ $this->_shipFromAddress = new stdClass();
242
+ $countryId = Mage::getStoreConfig('shipping/origin/country_id');
243
+ $zip = Mage::getStoreConfig('shipping/origin/postcode');
244
+ $regionId = Mage::getStoreConfig('shipping/origin/region_id');
245
+ $state = Mage::getModel('directory/region')->load($regionId)->getName();
246
+ $city = Mage::getStoreConfig('shipping/origin/city');
247
+ $street = Mage::getStoreConfig('shipping/origin/street');
248
+
249
+ $this->_shipFromAddress->address1 = $street;
250
+ $this->_shipFromAddress->address2 = $city . ", " . $state . " " . $zip; //. ", " . $countryId;
251
+ }
252
+ return $this->_shipFromAddress;
253
+ }
254
+
255
+ //Shipping Destination Address
256
+ protected function _getShippingToAddress($sourceAddress) {
257
+ if($this->_shipToAddress === null){
258
+
259
+ //We need to test for exceptions where billing address is used for calculation
260
+ $mappedAddress = $this->mapAddressExceptions($sourceAddress);
261
+
262
+ $this->_shipToAddress = new stdClass();
263
+ $country = $mappedAddress->getCountry();
264
+ $zip = $mappedAddress->getPostcode(); //$zip = preg_replace('/[^0-9\-]*/', '', $mappedAddress->getPostcode()); //US zip code clean up
265
+ $state = $mappedAddress->getRegion(); //No region resolution needed, $this->_getStateCodeByRegionId($mappedAddress->getState());
266
+ $city = $mappedAddress->getCity();
267
+ $street = implode(' ', $mappedAddress->getStreet()); //In case of multiple line address
268
+
269
+ $this->_shipToAddress->address1 = $street;
270
+ $this->_shipToAddress->address2 = $city . ", " . $state . " " . $zip; //. ", " . $county;
271
+ }
272
+ return $this->_shipToAddress;
273
+ }
274
+
275
+
276
+ //In a standard setup, tax is calculated by tax class (i.e. product code), if empty use default
277
+ //Advanced calculation by product SKU is also possible. Please contact SpeedTax support to setup advanced service
278
+ protected function _getProductCode($item){
279
+ if(!Mage::helper('speedtax')->isUseProductTaxClass()){
280
+ return $item->getSku();
281
+ }
282
+ $taxCode = $this->_getTaxClassByItem($item);
283
+ if(!$taxCode){
284
+ $taxCode = $item->getSku();
285
+ }
286
+ return $taxCode;
287
+ }
288
+
289
+ protected function _getTaxClassByItem($item){
290
+ $storeId = Mage::app()->getStore()->getId();
291
+ $taxClassId = Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getProductId(), 'tax_class_id', $storeId);
292
+ if($taxClassId){
293
+ $taxClassCode = Mage::getModel('tax/class_source_product')->getOptionText($taxClassId);
294
+ }else{
295
+ $taxClassCode = null;
296
+ }
297
+ return $taxClassCode;
298
+ }
299
+
300
  }
app/code/community/Harapartners/SpeedTax/Helper/Connector/Speedtax.php CHANGED
@@ -1,185 +1,185 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Helper_Connector_Speedtax extends Harapartners_ConnectorHub_Helper_Connector_Core {
14
-
15
- const REQUEST_ACTION_CALCULATE_INVOICE = 'CalculateInvoice';
16
- const REQUEST_ACTION_POST_INVOICE = 'PostInvoice';
17
- const REQUEST_ACTION_POST_CREDITMEMO = 'PostCreditmemo';
18
- const REQUEST_ACTION_VOID_INVOICE = 'VoidInvoice';
19
- const REQUEST_ACTION_BATCH_VOID_INVOICES = 'BatchVoidInvoices';
20
-
21
- const RESPONSE_TYPE_SUCCESS = 'SUCCESS';
22
- const RESPONSE_TYPE_FAILED_WITH_ERRORS = 'FAILED_WITH_ERRORS';
23
- const RESPONSE_TYPE_FAILED_INVOICE_NUMBER = 'FAILED_INVOICE_NUMBER';
24
-
25
- protected $_serviceType = 'speedtax';
26
-
27
- // ======================= Essential overrides ======================= //
28
- public function getServiceMode($request = null){
29
- //Always default to production for safety
30
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
31
-
32
- //Check from request first (in case it's a new authorization), default to last saved config value
33
- if(!!Mage::getStoreConfig($this->_getConfigDataBasePath('is_test_mode'))){
34
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
35
- }
36
- if(isset($request['meta']['credentials']['service_mode'])){
37
- $serviceMode = $request['meta']['credentials']['service_mode']; //Allow 0 and other empty values
38
- }
39
-
40
- return $serviceMode;
41
- }
42
-
43
- public function getIsDebugMode(){
44
- return Mage::getStoreConfig($this->_getConfigDataBasePath('is_debug_transaction'));
45
- }
46
-
47
- protected function _getConnectorHubUrl(){
48
- return $this->_getConnectorHubRootUrl() . 'SpeedTax.php';
49
- }
50
-
51
- protected function _getConfigDataBasePath($key){
52
- return 'speedtax/speedtax/' . $key;
53
- }
54
-
55
- protected function _prepareCredentials(){
56
- $username = Mage::getStoreConfig($this->_getConfigDataBasePath('username'));
57
- $password = Mage::helper('core')->decrypt(Mage::getStoreConfig($this->_getConfigDataBasePath('password')));
58
- $companyCode = Mage::getStoreConfig($this->_getConfigDataBasePath('company_code'));
59
- $isTestMode = Mage::getStoreConfig($this->_getConfigDataBasePath('is_test_mode'));
60
- if(!!$isTestMode){
61
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
62
- }else{
63
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
64
- }
65
-
66
- $credentials = array(
67
- 'username' => $username,
68
- 'password' => $password,
69
- 'company_code' => $companyCode,
70
- 'service_mode' => $serviceMode
71
- );
72
- return $credentials;
73
- }
74
-
75
- // ====================== Requests ====================== //
76
- public function calculateInvoiceRequest($sptxInvoice){
77
- $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_CALCULATE_INVOICE);
78
- return $response->data->result;
79
- }
80
-
81
- public function postInvoiceRequest($sptxInvoice){
82
- $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_POST_INVOICE);
83
- return $response->data->result;
84
- }
85
-
86
- public function postCreditmemoRequest($sptxInvoice){
87
- $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_POST_CREDITMEMO);
88
- return $response->data->result;
89
- }
90
-
91
- public function batchVoidInvoices($invoiceNumbers){
92
- $credentials = $this->_prepareCredentials();
93
- $request = array(
94
- 'meta' => array(
95
- 'action' => self::REQUEST_ACTION_BATCH_VOID_INVOICES
96
- ),
97
- 'data' => array(
98
- 'credentials' => $credentials,
99
- 'invoice_numbers' => $invoiceNumbers
100
- )
101
- );
102
- $response = $this->_processRequest($request);
103
- $this->_validateResponse($response);
104
- return $response;
105
- }
106
-
107
- protected function _doInvoiceRequest($sptxInvoice, $actionType){
108
- $credentials = $this->_prepareCredentials();
109
- $request = array(
110
- 'meta' => array(
111
- 'action' => $actionType
112
- ),
113
- 'data' => array(
114
- 'credentials' => $credentials,
115
- 'invoice' => $sptxInvoice
116
- )
117
- );
118
-
119
- $response = $this->_loadCachedInvoiceResponse($sptxInvoice, $actionType);
120
- if(!$response){
121
- $response = $this->_processRequest($request);
122
- //Save cache upon successful transactions only
123
- if(isset($response->meta->status) && $response->meta->status == Harapartners_ConnectorHub_Helper_Connector_Core::RESPONSE_STATUS_SUCCESS){
124
- $this->_saveCachedInvoiceResponse($response, $sptxInvoice, $actionType);
125
- }
126
- }
127
- $this->_validateResponse($response);
128
- return $response;
129
- }
130
-
131
- protected function _loadCachedInvoiceResponse($sptxInvoice, $actionType){
132
- if(!$this->_isCacheRequestAllowed($actionType)){
133
- return false;
134
- }
135
- $sptxInvoiceCacheKey = $this->_generateInvoiceCacheKey($sptxInvoice);
136
- $response = Mage::getSingleton('speedtax/session')->loadCachedResponse($sptxInvoiceCacheKey);
137
- return $response;
138
- }
139
-
140
- protected function _saveCachedInvoiceResponse($response, $sptxInvoice, $actionType){
141
- if(!$this->_isCacheRequestAllowed($actionType)){
142
- return false;
143
- }
144
- $sptxInvoiceCacheKey = $this->_generateInvoiceCacheKey($sptxInvoice);
145
- $response = Mage::getSingleton('speedtax/session')->saveCachedResponse($sptxInvoiceCacheKey, $response);
146
- return true;
147
- }
148
-
149
- protected function _validateResponse($response){
150
- //Essential validation for SpeedTax response data structure
151
- if(empty($response->data->result->resultType)){
152
- Mage::throwException('Invalid tax response');
153
- }
154
- switch ($response->data->result->resultType) {
155
- case self::RESPONSE_TYPE_SUCCESS:
156
- break;
157
- case self::RESPONSE_TYPE_FAILED_WITH_ERRORS:
158
- case self::RESPONSE_TYPE_FAILED_INVOICE_NUMBER:
159
- default :
160
- Mage::throwException('Tax request failed');
161
- break;
162
- }
163
- return $this;
164
- }
165
-
166
- protected function _isCacheRequestAllowed($actionType){
167
- $allRequestCache = false;
168
- switch($actionType){
169
- case self::REQUEST_ACTION_CALCULATE_INVOICE:
170
- $allRequestCache = true;
171
- break;
172
- default:
173
- $allRequestCache = false;
174
- break;
175
- }
176
- return $allRequestCache;
177
- }
178
-
179
- protected function _generateInvoiceCacheKey($sptxInvoice){
180
- $sptxInvoice = clone $sptxInvoice;
181
- $sptxInvoice->invoiceDate = null;
182
- return md5(json_encode($sptxInvoice));
183
- }
184
-
185
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Helper_Connector_Speedtax extends Harapartners_ConnectorHub_Helper_Connector_Core {
14
+
15
+ const REQUEST_ACTION_CALCULATE_INVOICE = 'CalculateInvoice';
16
+ const REQUEST_ACTION_POST_INVOICE = 'PostInvoice';
17
+ const REQUEST_ACTION_POST_CREDITMEMO = 'PostCreditmemo';
18
+ const REQUEST_ACTION_VOID_INVOICE = 'VoidInvoice';
19
+ const REQUEST_ACTION_BATCH_VOID_INVOICES = 'BatchVoidInvoices';
20
+
21
+ const RESPONSE_TYPE_SUCCESS = 'SUCCESS';
22
+ const RESPONSE_TYPE_FAILED_WITH_ERRORS = 'FAILED_WITH_ERRORS';
23
+ const RESPONSE_TYPE_FAILED_INVOICE_NUMBER = 'FAILED_INVOICE_NUMBER';
24
+
25
+ protected $_serviceType = 'speedtax';
26
+
27
+ // ======================= Essential overrides ======================= //
28
+ public function getServiceMode($request = null){
29
+ //Always default to production for safety
30
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
31
+
32
+ //Check from request first (in case it's a new authorization), default to last saved config value
33
+ if(!!Mage::getStoreConfig($this->_getConfigDataBasePath('is_test_mode'))){
34
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
35
+ }
36
+ if(isset($request['meta']['credentials']['service_mode'])){
37
+ $serviceMode = $request['meta']['credentials']['service_mode']; //Allow 0 and other empty values
38
+ }
39
+
40
+ return $serviceMode;
41
+ }
42
+
43
+ public function getIsDebugMode(){
44
+ return Mage::getStoreConfig($this->_getConfigDataBasePath('is_debug_transaction'));
45
+ }
46
+
47
+ protected function _getConnectorHubUrl(){
48
+ return $this->_getConnectorHubRootUrl() . 'SpeedTax.php';
49
+ }
50
+
51
+ protected function _getConfigDataBasePath($key){
52
+ return 'speedtax/speedtax/' . $key;
53
+ }
54
+
55
+ protected function _prepareCredentials(){
56
+ $username = Mage::getStoreConfig($this->_getConfigDataBasePath('username'));
57
+ $password = Mage::helper('core')->decrypt(Mage::getStoreConfig($this->_getConfigDataBasePath('password')));
58
+ $companyCode = Mage::getStoreConfig($this->_getConfigDataBasePath('company_code'));
59
+ $isTestMode = Mage::getStoreConfig($this->_getConfigDataBasePath('is_test_mode'));
60
+ if(!!$isTestMode){
61
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
62
+ }else{
63
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
64
+ }
65
+
66
+ $credentials = array(
67
+ 'username' => $username,
68
+ 'password' => $password,
69
+ 'company_code' => $companyCode,
70
+ 'service_mode' => $serviceMode
71
+ );
72
+ return $credentials;
73
+ }
74
+
75
+ // ====================== Requests ====================== //
76
+ public function calculateInvoiceRequest($sptxInvoice){
77
+ $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_CALCULATE_INVOICE);
78
+ return $response->data->result;
79
+ }
80
+
81
+ public function postInvoiceRequest($sptxInvoice){
82
+ $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_POST_INVOICE);
83
+ return $response->data->result;
84
+ }
85
+
86
+ public function postCreditmemoRequest($sptxInvoice){
87
+ $response = $this->_doInvoiceRequest($sptxInvoice, self::REQUEST_ACTION_POST_CREDITMEMO);
88
+ return $response->data->result;
89
+ }
90
+
91
+ public function batchVoidInvoices($invoiceNumbers){
92
+ $credentials = $this->_prepareCredentials();
93
+ $request = array(
94
+ 'meta' => array(
95
+ 'action' => self::REQUEST_ACTION_BATCH_VOID_INVOICES
96
+ ),
97
+ 'data' => array(
98
+ 'credentials' => $credentials,
99
+ 'invoice_numbers' => $invoiceNumbers
100
+ )
101
+ );
102
+ $response = $this->_processRequest($request);
103
+ $this->_validateResponse($response);
104
+ return $response;
105
+ }
106
+
107
+ protected function _doInvoiceRequest($sptxInvoice, $actionType){
108
+ $credentials = $this->_prepareCredentials();
109
+ $request = array(
110
+ 'meta' => array(
111
+ 'action' => $actionType
112
+ ),
113
+ 'data' => array(
114
+ 'credentials' => $credentials,
115
+ 'invoice' => $sptxInvoice
116
+ )
117
+ );
118
+
119
+ $response = $this->_loadCachedInvoiceResponse($sptxInvoice, $actionType);
120
+ if(!$response){
121
+ $response = $this->_processRequest($request);
122
+ //Save cache upon successful transactions only
123
+ if(isset($response->meta->status) && $response->meta->status == Harapartners_ConnectorHub_Helper_Connector_Core::RESPONSE_STATUS_SUCCESS){
124
+ $this->_saveCachedInvoiceResponse($response, $sptxInvoice, $actionType);
125
+ }
126
+ }
127
+ $this->_validateResponse($response);
128
+ return $response;
129
+ }
130
+
131
+ protected function _loadCachedInvoiceResponse($sptxInvoice, $actionType){
132
+ if(!$this->_isCacheRequestAllowed($actionType)){
133
+ return false;
134
+ }
135
+ $sptxInvoiceCacheKey = $this->_generateInvoiceCacheKey($sptxInvoice);
136
+ $response = Mage::getSingleton('speedtax/session')->loadCachedResponse($sptxInvoiceCacheKey);
137
+ return $response;
138
+ }
139
+
140
+ protected function _saveCachedInvoiceResponse($response, $sptxInvoice, $actionType){
141
+ if(!$this->_isCacheRequestAllowed($actionType)){
142
+ return false;
143
+ }
144
+ $sptxInvoiceCacheKey = $this->_generateInvoiceCacheKey($sptxInvoice);
145
+ $response = Mage::getSingleton('speedtax/session')->saveCachedResponse($sptxInvoiceCacheKey, $response);
146
+ return true;
147
+ }
148
+
149
+ protected function _validateResponse($response){
150
+ //Essential validation for SpeedTax response data structure
151
+ if(empty($response->data->result->resultType)){
152
+ Mage::throwException('Invalid tax response');
153
+ }
154
+ switch ($response->data->result->resultType) {
155
+ case self::RESPONSE_TYPE_SUCCESS:
156
+ break;
157
+ case self::RESPONSE_TYPE_FAILED_WITH_ERRORS:
158
+ case self::RESPONSE_TYPE_FAILED_INVOICE_NUMBER:
159
+ default :
160
+ Mage::throwException('Tax request failed');
161
+ break;
162
+ }
163
+ return $this;
164
+ }
165
+
166
+ protected function _isCacheRequestAllowed($actionType){
167
+ $allRequestCache = false;
168
+ switch($actionType){
169
+ case self::REQUEST_ACTION_CALCULATE_INVOICE:
170
+ $allRequestCache = true;
171
+ break;
172
+ default:
173
+ $allRequestCache = false;
174
+ break;
175
+ }
176
+ return $allRequestCache;
177
+ }
178
+
179
+ protected function _generateInvoiceCacheKey($sptxInvoice){
180
+ $sptxInvoice = clone $sptxInvoice;
181
+ $sptxInvoice->invoiceDate = null;
182
+ return md5(json_encode($sptxInvoice));
183
+ }
184
+
185
  }
app/code/community/Harapartners/SpeedTax/Helper/Data.php CHANGED
@@ -1,50 +1,50 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Helper_Data extends Mage_Core_Helper_Abstract {
14
-
15
- // Notification settings
16
- const XML_PATH_NOTIFICATION_DISABLED_COMPRESS = 'speedtax/notification/disabled_compress';
17
- const NOTIFICATION_KEY_TAX_ON_DISCOUNT = 'tax_on_discount';
18
- const ERROR_LOG_FILE = 'speedtax_error.log';
19
- const DEFAULT_MAGENTO_COLLECTION_PAGE_SIZE = 50;
20
-
21
- protected $_xmlPathPrefix = 'speedtax/speedtax/';
22
-
23
- // =========================== config and essential flags =========================== //
24
- public function isSpeedTaxEnabled(){
25
- return Mage::getStoreConfig ( $this->_xmlPathPrefix . 'is_enabled' );
26
- }
27
-
28
- public function useTaxClass(){
29
- return Mage::getStoreConfig ( $this->_xmlPathPrefix . 'customized_tax_class' );
30
- }
31
-
32
- public function isAddressValidationOn($address, $storeId) {
33
- return Mage::getStoreConfig( $this->_xmlPathPrefix . 'validate_address', $storeId);
34
- }
35
-
36
- public function isFailsafeEnabled(){
37
- return Mage::getStoreConfig ( 'speedtax/failsafe/is_enabled' );
38
- }
39
-
40
- public function getSpeedtaxInvoiceStatusValues() {
41
- return array(
42
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_PENDING => Mage::helper('speedtax')->__('Pending'),
43
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_POSTED => Mage::helper('speedtax')->__('Posted'),
44
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_VOID => Mage::helper('speedtax')->__('Void'),
45
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_ERROR => Mage::helper('speedtax')->__('Error'),
46
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE => Mage::helper('speedtax')->__('Failsafe'),
47
- );
48
- }
49
-
50
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Helper_Data extends Mage_Core_Helper_Abstract {
14
+
15
+ // Notification settings
16
+ const XML_PATH_NOTIFICATION_DISABLED_COMPRESS = 'speedtax/notification/disabled_compress';
17
+ const NOTIFICATION_KEY_TAX_ON_DISCOUNT = 'tax_on_discount';
18
+ const ERROR_LOG_FILE = 'speedtax_error.log';
19
+ const DEFAULT_MAGENTO_COLLECTION_PAGE_SIZE = 50;
20
+
21
+ protected $_xmlPathPrefix = 'speedtax/speedtax/';
22
+
23
+ // =========================== config and essential flags =========================== //
24
+ public function isSpeedTaxEnabled(){
25
+ return Mage::getStoreConfig ( $this->_xmlPathPrefix . 'is_enabled' );
26
+ }
27
+
28
+ public function isUseProductTaxClass(){
29
+ return Mage::getStoreConfig ( $this->_xmlPathPrefix . 'is_use_product_tax_class' );
30
+ }
31
+
32
+ public function isAddressValidationOn($address, $storeId) {
33
+ return Mage::getStoreConfig( $this->_xmlPathPrefix . 'validate_address', $storeId);
34
+ }
35
+
36
+ public function isFailsafeEnabled(){
37
+ return Mage::getStoreConfig ( 'speedtax/failsafe/is_enabled' );
38
+ }
39
+
40
+ public function getSpeedtaxInvoiceStatusValues() {
41
+ return array(
42
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_PENDING => Mage::helper('speedtax')->__('Pending'),
43
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_POSTED => Mage::helper('speedtax')->__('Posted'),
44
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_VOID => Mage::helper('speedtax')->__('Void'),
45
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_ERROR => Mage::helper('speedtax')->__('Error'),
46
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE => Mage::helper('speedtax')->__('Failsafe'),
47
+ );
48
+ }
49
+
50
  }
app/code/community/Harapartners/SpeedTax/Helper/Failsafe.php CHANGED
@@ -1,73 +1,73 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Helper_Failsafe extends Mage_Core_Helper_Abstract {
14
-
15
- const FALLBACK_CALCULATION_PRECISION = 4;
16
-
17
- public function updateFailsafeRate(Mage_Sales_Model_Quote_Address $mageQuoteAddress, $responseResult){
18
- if(!$mageQuoteAddress || !$responseResult){
19
- return;
20
- }
21
-
22
- $decPrecision = pow(0.1, Harapartners_SpeedTax_Helper_Failsafe::FALLBACK_CALCULATION_PRECISION);
23
- $requestData = array();
24
- $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageQuoteAddress($mageQuoteAddress);
25
- if(!empty($sptxInvoice->lineItems)){
26
- foreach($sptxInvoice->lineItems as $lineItem){
27
- if(!empty($lineItem->customReference) && !empty($lineItem->salesAmount->decimalValue)){
28
- $requestData[$lineItem->customReference] = $lineItem->salesAmount->decimalValue;
29
- }
30
- }
31
- }
32
- $responseData = array();
33
- if(!empty($responseResult->lineItemBundles->lineItems)){
34
- foreach($responseResult->lineItemBundles->lineItems as $lineItem){
35
- if(!empty($lineItem->customReference) && !empty($lineItem->taxAmount->decimalValue)){
36
- $responseData[$lineItem->customReference] = $lineItem->taxAmount->decimalValue;
37
- }
38
- }
39
- }
40
-
41
- $taxRate = 0.0; //This is a percentage
42
- foreach($requestData as $customReference => $salesAmount){
43
- if($salesAmount > $decPrecision && isset($responseData[$customReference])) {
44
- $taxRate = round($responseData[$customReference] / $salesAmount * 100.0, Harapartners_SpeedTax_Helper_Failsafe::FALLBACK_CALCULATION_PRECISION);
45
- break;
46
- }
47
- }
48
-
49
- //Do not update zero tax rates
50
- if($taxRate <= $decPrecision){
51
- return;
52
- }
53
-
54
- $countryId = $mageQuoteAddress->getCountryId();
55
- $regionId = $mageQuoteAddress->getRegionId();
56
- $postcode = $mageQuoteAddress->getPostcode(); //$postcode = preg_replace('/[^0-9\-]*/', '', $address->getPostcode()); //US zip code clean up
57
- $failsafeCalRate = Mage::getModel('speedtax/failsafe_calculation_rate');
58
- $failsafeCalRate->loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode);
59
-
60
- if($failsafeCalRate->getTaxRate() != $taxRate){
61
- $failsafeCalRate->setData(array(
62
- 'country_id' => $countryId,
63
- 'region_id' => $regionId,
64
- 'postcode' => $postcode,
65
- 'tax_rate' => $taxRate
66
- ));
67
- $failsafeCalRate->save();
68
- }
69
-
70
- return null;
71
- }
72
-
73
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Helper_Failsafe extends Mage_Core_Helper_Abstract {
14
+
15
+ const FALLBACK_CALCULATION_PRECISION = 4;
16
+
17
+ public function updateFailsafeRate(Mage_Sales_Model_Quote_Address $mageQuoteAddress, $responseResult){
18
+ if(!$mageQuoteAddress || !$responseResult){
19
+ return;
20
+ }
21
+
22
+ $decPrecision = pow(0.1, Harapartners_SpeedTax_Helper_Failsafe::FALLBACK_CALCULATION_PRECISION);
23
+ $requestData = array();
24
+ $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageQuoteAddress($mageQuoteAddress);
25
+ if(!empty($sptxInvoice->lineItems)){
26
+ foreach($sptxInvoice->lineItems as $lineItem){
27
+ if(!empty($lineItem->customReference) && !empty($lineItem->salesAmount->decimalValue)){
28
+ $requestData[$lineItem->customReference] = $lineItem->salesAmount->decimalValue;
29
+ }
30
+ }
31
+ }
32
+ $responseData = array();
33
+ if(!empty($responseResult->lineItemBundles->lineItems)){
34
+ foreach($responseResult->lineItemBundles->lineItems as $lineItem){
35
+ if(!empty($lineItem->customReference) && !empty($lineItem->taxAmount->decimalValue)){
36
+ $responseData[$lineItem->customReference] = $lineItem->taxAmount->decimalValue;
37
+ }
38
+ }
39
+ }
40
+
41
+ $taxRate = 0.0; //This is a percentage
42
+ foreach($requestData as $customReference => $salesAmount){
43
+ if($salesAmount > $decPrecision && isset($responseData[$customReference])) {
44
+ $taxRate = round($responseData[$customReference] / $salesAmount * 100.0, Harapartners_SpeedTax_Helper_Failsafe::FALLBACK_CALCULATION_PRECISION);
45
+ break;
46
+ }
47
+ }
48
+
49
+ //Do not update zero tax rates
50
+ if($taxRate <= $decPrecision){
51
+ return;
52
+ }
53
+
54
+ $countryId = $mageQuoteAddress->getCountryId();
55
+ $regionId = $mageQuoteAddress->getRegionId();
56
+ $postcode = $mageQuoteAddress->getPostcode(); //$postcode = preg_replace('/[^0-9\-]*/', '', $address->getPostcode()); //US zip code clean up
57
+ $failsafeCalRate = Mage::getModel('speedtax/failsafe_calculation_rate');
58
+ $failsafeCalRate->loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode);
59
+
60
+ if($failsafeCalRate->getTaxRate() != $taxRate){
61
+ $failsafeCalRate->setData(array(
62
+ 'country_id' => $countryId,
63
+ 'region_id' => $regionId,
64
+ 'postcode' => $postcode,
65
+ 'tax_rate' => $taxRate
66
+ ));
67
+ $failsafeCalRate->save();
68
+ }
69
+
70
+ return null;
71
+ }
72
+
73
  }
app/code/community/Harapartners/SpeedTax/Helper/Processor.php CHANGED
@@ -1,193 +1,241 @@
1
- <?php
2
-
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license [^]
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
-
15
- class Harapartners_SpeedTax_Helper_Processor extends Mage_Core_Helper_Abstract {
16
-
17
- const SPEEDTAX_INVOICE_STATUS_PENDING = 0;
18
- const SPEEDTAX_INVOICE_STATUS_POSTED = 100;
19
- const SPEEDTAX_INVOICE_STATUS_VOID = 200;
20
- const SPEEDTAX_INVOICE_STATUS_ERROR = 300;
21
- const SPEEDTAX_INVOICE_STATUS_FAILSAFE = 900;
22
-
23
- // ========================== Actions ========================== //
24
- public function queryQuoteAddress(Mage_Sales_Model_Quote_Address $mageQuoteAddress){
25
- if (!$this->_isTaxable($mageQuoteAddress)){
26
- return false;
27
- }
28
- $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageQuoteAddress($mageQuoteAddress);
29
- if(!$sptxInvoice|| !$sptxInvoice->lineItems){
30
- return false;
31
- }
32
- $responseResult = Mage::helper('speedtax/connector_speedtax')->calculateInvoiceRequest($sptxInvoice);
33
- $this->_applyResponseToQuote($responseResult, $mageQuoteAddress);
34
- return $responseResult;
35
- }
36
-
37
- public function postOrderInvoice(Mage_Sales_Model_Order_Invoice $mageOrderInvoice){
38
- if(!!$mageOrderInvoice->getData('speedtax_transaction_id')){
39
- Mage::throwException('This invoice was already posted through SalesTax.');
40
- }
41
-
42
- $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageOrderInvoice($mageOrderInvoice);
43
- if(!$sptxInvoice || !$sptxInvoice->lineItems){
44
- return false;
45
- }
46
- //No caching allowed for order invoice
47
- $responseResult = Mage::helper('speedtax/connector_speedtax')->postInvoiceRequest($sptxInvoice);
48
- $this->_applyResponseToInvoice($responseResult, $mageOrderInvoice);
49
-
50
- return $responseResult;
51
- }
52
-
53
- public function postOrderCreditmemo(Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo) {
54
- if(!!$mageOrderCreditmemo->getData('speedtax_transaction_id')){
55
- Mage::throwException('This credit memo was already posted through SalesTax.');
56
- }
57
-
58
- $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageOrderCreditmemo($mageOrderCreditmemo);
59
- if(!$sptxInvoice || !$sptxInvoice->lineItems){
60
- return false;
61
- }
62
- //No caching allowed for order invoice
63
- $responseResult = Mage::helper('speedtax/connector_speedtax')->postCreditmemoRequest($sptxInvoice);
64
- $this->_applyResponseToCreditmemo($responseResult, $mageOrderCreditmemo);
65
-
66
- return $responseResult;
67
- }
68
-
69
- public function cancelAllOrderTransactions(Mage_Sales_Model_Order $mageOrder) {
70
- $invoiceNumbers = array();
71
- $updateObjectArray = array();
72
- foreach($mageOrder->getInvoiceCollection() as $mageOrderInvoice){
73
- if(!!$mageOrderInvoice->getData('speedtax_invoice_number')
74
- && $mageOrderInvoice->getData('speedtax_invoice_status') == self::SPEEDTAX_INVOICE_STATUS_POSTED ){
75
- $invoiceNumbers[] = $mageOrderInvoice->getData('speedtax_invoice_number');
76
- $updateObjectArray[$mageOrderInvoice->getData('speedtax_invoice_number')] = $mageOrderInvoice;
77
- }
78
- }
79
- foreach($mageOrder->getCreditmemosCollection() as $mageOrderCreditmemo){
80
- if(!!$mageOrderCreditmemo->getData('speedtax_invoice_number')
81
- && $mageOrderCreditmemo->getData('speedtax_invoice_status') == self::SPEEDTAX_INVOICE_STATUS_POSTED ){
82
- $invoiceNumbers[] = $mageOrderCreditmemo->getData('speedtax_invoice_number');
83
- $updateObjectArray[$mageOrderCreditmemo->getData('speedtax_invoice_number')] = $mageOrderCreditmemo;
84
- }
85
- }
86
-
87
- if(!$invoiceNumbers){
88
- return false;
89
- }
90
- //No caching allowed for order invoice
91
- $responseResult = Mage::helper('speedtax/connector_speedtax')->batchVoidInvoices($invoiceNumbers);
92
-
93
- //Update status
94
- $batchVoidResults = json_decode($responseResult->data->result->batchVoidResults, 1);
95
- foreach($batchVoidResults as $invoiceNumber => $voidResult){
96
- $updateObject = $updateObjectArray[$invoiceNumber];
97
- if($voidResult == Harapartners_SpeedTax_Helper_Connector_Speedtax::RESPONSE_TYPE_SUCCESS){
98
- $updateObject->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_VOID);
99
- }else{
100
- $updateObject->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_ERROR);
101
- }
102
- $updateObject->save();
103
- }
104
-
105
- return $responseResult;
106
- }
107
-
108
-
109
- // ========================== Utility Functions ========================== //
110
- //Mage_Sales_Model_Quote_Address or Mage_Sales_Model_Order_Address
111
- protected function _isTaxable($mageAddress) {
112
- //$mageAddress can be quote of order address, or null for virtual product
113
- if(!($mageAddress instanceof Varien_Object)
114
- || $mageAddress->getAddressType() != Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
115
- ){
116
- return false;
117
- }
118
- //Nexus test
119
- $originsString = Mage::getStoreConfig('speedtax/speedtax/origins');
120
- return in_array($mageAddress->getRegionId(), explode(',', $originsString));
121
- }
122
-
123
- //Mage_Sales_Model_Quote_Address ONLY
124
- protected function _applyResponseToQuote($responseResult, Mage_Sales_Model_Quote_Address $mageQuoteAddress){
125
- foreach ( $mageQuoteAddress->getAllItems() as $mageQuoteItem ) {
126
- $taxAmount = $this->_getLineItemTaxAmountByItemId($responseResult, $mageQuoteItem->getId());
127
- $mageQuoteItem->setTaxAmount($taxAmount);
128
- $mageQuoteItem->setBaseTaxAmount($taxAmount);
129
- if(($mageQuoteItem->getRowTotal() - $mageQuoteItem->getDiscountAmount()) > 0){
130
- $mageQuoteItem->setTaxPercent (sprintf("%.4f", 100*$taxAmount/($mageQuoteItem->getRowTotal() - $mageQuoteItem->getDiscountAmount())));
131
- }
132
- }
133
- $taxShippingAmount = $this->_getTaxShippingAmount($responseResult);
134
- if(!!$taxShippingAmount){
135
- $mageQuoteAddress->setShippingTaxAmount($taxShippingAmount);
136
- $mageQuoteAddress->setBaseShippingTaxAmount($taxShippingAmount);
137
- }
138
- return;
139
- }
140
-
141
- protected function _applyResponseToInvoice($responseResult, Mage_Sales_Model_Order_Invoice $mageOrderInvoice){
142
- $mageOrderInvoice->setData('speedtax_transaction_id', $responseResult->transactionId);
143
- $mageOrderInvoice->setData('speedtax_invoice_number', $responseResult->invoiceNumber);
144
- $mageOrderInvoice->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_POSTED);
145
- $mageOrderInvoice->save();
146
- return;
147
- }
148
-
149
- protected function _applyResponseToCreditmemo($responseResult, Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo){
150
- $mageOrderCreditmemo->setData('speedtax_transaction_id', $responseResult->transactionId);
151
- $mageOrderCreditmemo->setData('speedtax_invoice_number', $responseResult->invoiceNumber);
152
- $mageOrderCreditmemo->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_POSTED);
153
- $mageOrderCreditmemo->save();
154
- return;
155
- }
156
-
157
- public function getTotalTax($responseResult) {
158
- return $responseResult->totalTax->decimalValue;
159
- }
160
-
161
- protected function _getLineItemTaxAmountByItemId($responseResult, $itemId) {
162
- foreach($responseResult->lineItemBundles->lineItems as $responseLineItem){
163
- if($responseLineItem->customReference == $itemId){
164
- return $responseLineItem->taxAmount->decimalValue;
165
- }
166
- }
167
- return 0.0;
168
- }
169
-
170
- protected function _getTaxShippingAmount($responseResult) {
171
- if(isset($responseResult->lineItemBundles->lineItems)){
172
- foreach($responseResult->lineItemBundles->lineItems as $responseLineItem){
173
- if($responseLineItem->productCode == Harapartners_SpeedTax_Helper_Connector_Data::TAX_SHIPPING_LINEITEM_TAX_CLASS){
174
- return $responseLineItem->taxAmount->decimalValue;
175
- }
176
- }
177
- }
178
- return 0.0;
179
- }
180
-
181
-
182
- //Adds a comment to order history. Method choosen based on Magento version.
183
- // protected function _addStatusHistoryComment($order, $comment) {
184
- // if(method_exists($order, 'addStatusHistoryComment')) {
185
- // $order->addStatusHistoryComment($comment)->save();;
186
- // } elseif(method_exists($order, 'addStatusToHistory')) {
187
- // $order->addStatusToHistory($order->getStatus(), $comment, false)->save();;
188
- // }
189
- // return $this;
190
- // }
191
-
192
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
1
+ <?php
2
+
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license [^]
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+
15
+ class Harapartners_SpeedTax_Helper_Processor extends Mage_Core_Helper_Abstract {
16
+
17
+ const SPEEDTAX_INVOICE_STATUS_PENDING = 0;
18
+ const SPEEDTAX_INVOICE_STATUS_POSTED = 100;
19
+ const SPEEDTAX_INVOICE_STATUS_VOID = 200;
20
+ const SPEEDTAX_INVOICE_STATUS_ERROR = 300;
21
+ const SPEEDTAX_INVOICE_STATUS_FAILSAFE = 900;
22
+
23
+ // ========================== Actions ========================== //
24
+ public function queryQuoteAddress(Mage_Sales_Model_Quote_Address $mageQuoteAddress){
25
+ if (!$this->_isTaxable($mageQuoteAddress)){
26
+ $this->_clearQuoteAddressTax($mageQuoteAddress);
27
+ return false;
28
+ }
29
+ $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageQuoteAddress($mageQuoteAddress);
30
+ if(!$sptxInvoice|| !$sptxInvoice->lineItems){
31
+ $this->_clearQuoteAddressTax($mageQuoteAddress);
32
+ return false;
33
+ }
34
+ $responseResult = Mage::helper('speedtax/connector_speedtax')->calculateInvoiceRequest($sptxInvoice);
35
+ $this->_applyResponseToQuote($responseResult, $mageQuoteAddress);
36
+ return $responseResult;
37
+ }
38
+
39
+ public function postOrderInvoice(Mage_Sales_Model_Order_Invoice $mageOrderInvoice){
40
+ if(!!$mageOrderInvoice->getData('speedtax_transaction_id')){
41
+ Mage::throwException('This invoice was already posted through SalesTax.');
42
+ }
43
+
44
+ $customerGroupId = $mageOrderInvoice->getOrder()->getCustomerGroupId();
45
+ if($this->_isCustomerGroupTaxExempt($customerGroupId)){
46
+ return false;
47
+ }
48
+
49
+ $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageOrderInvoice($mageOrderInvoice);
50
+ if(!$sptxInvoice || !$sptxInvoice->lineItems){
51
+ return false;
52
+ }
53
+ //No caching allowed for order invoice
54
+ $responseResult = Mage::helper('speedtax/connector_speedtax')->postInvoiceRequest($sptxInvoice);
55
+ $this->_applyResponseToInvoice($responseResult, $mageOrderInvoice);
56
+
57
+ return $responseResult;
58
+ }
59
+
60
+ public function postOrderCreditmemo(Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo) {
61
+ if(!!$mageOrderCreditmemo->getData('speedtax_transaction_id')){
62
+ Mage::throwException('This credit memo was already posted through SalesTax.');
63
+ }
64
+
65
+ $customerGroupId = $mageOrderCreditmemo->getOrder()->getCustomerGroupId();
66
+ if($this->_isCustomerGroupTaxExempt($customerGroupId)){
67
+ return false;
68
+ }
69
+
70
+ $sptxInvoice = Mage::helper('speedtax/connector_data')->prepareSpeedTaxInvoiceByMageOrderCreditmemo($mageOrderCreditmemo);
71
+ if(!$sptxInvoice || !$sptxInvoice->lineItems){
72
+ return false;
73
+ }
74
+ //No caching allowed for order invoice
75
+ $responseResult = Mage::helper('speedtax/connector_speedtax')->postCreditmemoRequest($sptxInvoice);
76
+ $this->_applyResponseToCreditmemo($responseResult, $mageOrderCreditmemo);
77
+
78
+ return $responseResult;
79
+ }
80
+
81
+ public function cancelAllOrderTransactions(Mage_Sales_Model_Order $mageOrder) {
82
+ $invoiceNumbers = array();
83
+ $updateObjectArray = array();
84
+ foreach($mageOrder->getInvoiceCollection() as $mageOrderInvoice){
85
+ if(!!$mageOrderInvoice->getData('speedtax_invoice_number')
86
+ && $mageOrderInvoice->getData('speedtax_invoice_status') == self::SPEEDTAX_INVOICE_STATUS_POSTED ){
87
+ $invoiceNumbers[] = $mageOrderInvoice->getData('speedtax_invoice_number');
88
+ $updateObjectArray[$mageOrderInvoice->getData('speedtax_invoice_number')] = $mageOrderInvoice;
89
+ }
90
+ }
91
+ foreach($mageOrder->getCreditmemosCollection() as $mageOrderCreditmemo){
92
+ if(!!$mageOrderCreditmemo->getData('speedtax_invoice_number')
93
+ && $mageOrderCreditmemo->getData('speedtax_invoice_status') == self::SPEEDTAX_INVOICE_STATUS_POSTED ){
94
+ $invoiceNumbers[] = $mageOrderCreditmemo->getData('speedtax_invoice_number');
95
+ $updateObjectArray[$mageOrderCreditmemo->getData('speedtax_invoice_number')] = $mageOrderCreditmemo;
96
+ }
97
+ }
98
+
99
+ if(!$invoiceNumbers){
100
+ return false;
101
+ }
102
+ //No caching allowed for order invoice
103
+ $responseResult = Mage::helper('speedtax/connector_speedtax')->batchVoidInvoices($invoiceNumbers);
104
+
105
+ //Update status
106
+ $batchVoidResults = json_decode($responseResult->data->result->batchVoidResults, 1);
107
+ foreach($batchVoidResults as $invoiceNumber => $voidResult){
108
+ $updateObject = $updateObjectArray[$invoiceNumber];
109
+ if($voidResult == Harapartners_SpeedTax_Helper_Connector_Speedtax::RESPONSE_TYPE_SUCCESS){
110
+ $updateObject->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_VOID);
111
+ }else{
112
+ $updateObject->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_ERROR);
113
+ }
114
+ $updateObject->save();
115
+ }
116
+
117
+ return $responseResult;
118
+ }
119
+
120
+
121
+ // ========================== Utility Functions ========================== //
122
+ //Mage_Sales_Model_Quote_Address or Mage_Sales_Model_Order_Address
123
+ protected function _isTaxable($mageAddress) {
124
+ //$mageAddress can be quote of order address, or null for virtual product
125
+ //Note: only check shipping to avoid double tax calculation
126
+ if(!($mageAddress instanceof Varien_Object)
127
+ || $mageAddress->getAddressType() != Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
128
+ ){
129
+ return false;
130
+ }
131
+
132
+ //Check tax exempt customer group
133
+ //Only for quote, order/inovice will always reports the amount the tax captured
134
+ if($mageAddress instanceof Mage_Sales_Model_Quote_Address && !!$mageAddress->getQuote()){
135
+ //Note, 0 for guest group
136
+ $customerGroupId = $mageAddress->getQuote()->getCustomerGroupId();
137
+ if($this->_isCustomerGroupTaxExempt($customerGroupId)){
138
+ return false;
139
+ }
140
+ }
141
+
142
+ //Nexus test
143
+ //We need to test for exceptions where billing address is used for calculation
144
+ //Note this is after the address type test to avoid double tax calculation
145
+ $mappedAddress = Mage::helper('speedtax/connector_data')->mapAddressExceptions($mageAddress);
146
+ $originsString = Mage::getStoreConfig('speedtax/speedtax/origins');
147
+ if(!in_array($mappedAddress->getRegionId(), explode(',', $originsString))){
148
+ return false;
149
+ }
150
+
151
+ //By default, calculation tax
152
+ return true;
153
+ }
154
+
155
+ protected function _isCustomerGroupTaxExempt($customerGroupId) {
156
+ $taxExemptCustomerGroupString = Mage::getStoreConfig('speedtax/speedtax/tax_exempt_customer_group');
157
+ return in_array($customerGroupId, explode(',', $taxExemptCustomerGroupString));
158
+ }
159
+
160
+ //Mage_Sales_Model_Quote_Address ONLY
161
+ protected function _applyResponseToQuote($responseResult, Mage_Sales_Model_Quote_Address $mageQuoteAddress){
162
+ foreach ( $mageQuoteAddress->getAllItems() as $mageQuoteItem ) {
163
+ $taxAmount = $this->_getLineItemTaxAmountByItemId($responseResult, $mageQuoteItem->getId());
164
+ $mageQuoteItem->setTaxAmount($taxAmount);
165
+ $mageQuoteItem->setBaseTaxAmount($taxAmount);
166
+ if(($mageQuoteItem->getRowTotal() - $mageQuoteItem->getDiscountAmount()) > 0){
167
+ $mageQuoteItem->setTaxPercent (sprintf("%.4f", 100*$taxAmount/($mageQuoteItem->getRowTotal() - $mageQuoteItem->getDiscountAmount())));
168
+ }
169
+ }
170
+ $taxShippingAmount = $this->_getTaxShippingAmount($responseResult);
171
+ if(!!$taxShippingAmount){
172
+ $mageQuoteAddress->setShippingTaxAmount($taxShippingAmount);
173
+ $mageQuoteAddress->setBaseShippingTaxAmount($taxShippingAmount);
174
+ }
175
+ return;
176
+ }
177
+
178
+ protected function _clearQuoteAddressTax(Mage_Sales_Model_Quote_Address $mageQuoteAddress){
179
+ //Only clear tax related to this quote address
180
+ foreach ( $mageQuoteAddress->getAllItems() as $mageQuoteItem ) {
181
+ $mageQuoteItem->setTaxAmount(0.0);
182
+ $mageQuoteItem->setBaseTaxAmount(0.0);
183
+ $mageQuoteItem->setTaxPercent(0.0);
184
+ }
185
+ $mageQuoteAddress->setShippingTaxAmount(0.0);
186
+ $mageQuoteAddress->setBaseShippingTaxAmount(0.0);
187
+ return;
188
+ }
189
+
190
+ protected function _applyResponseToInvoice($responseResult, Mage_Sales_Model_Order_Invoice $mageOrderInvoice){
191
+ $mageOrderInvoice->setData('speedtax_transaction_id', $responseResult->transactionId);
192
+ $mageOrderInvoice->setData('speedtax_invoice_number', $responseResult->invoiceNumber);
193
+ $mageOrderInvoice->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_POSTED);
194
+ $mageOrderInvoice->save();
195
+ return;
196
+ }
197
+
198
+ protected function _applyResponseToCreditmemo($responseResult, Mage_Sales_Model_Order_Creditmemo $mageOrderCreditmemo){
199
+ $mageOrderCreditmemo->setData('speedtax_transaction_id', $responseResult->transactionId);
200
+ $mageOrderCreditmemo->setData('speedtax_invoice_number', $responseResult->invoiceNumber);
201
+ $mageOrderCreditmemo->setData('speedtax_invoice_status', self::SPEEDTAX_INVOICE_STATUS_POSTED);
202
+ $mageOrderCreditmemo->save();
203
+ return;
204
+ }
205
+
206
+ public function getTotalTax($responseResult) {
207
+ return $responseResult->totalTax->decimalValue;
208
+ }
209
+
210
+ protected function _getLineItemTaxAmountByItemId($responseResult, $itemId) {
211
+ foreach($responseResult->lineItemBundles->lineItems as $responseLineItem){
212
+ if($responseLineItem->customReference == $itemId){
213
+ return $responseLineItem->taxAmount->decimalValue;
214
+ }
215
+ }
216
+ return 0.0;
217
+ }
218
+
219
+ protected function _getTaxShippingAmount($responseResult) {
220
+ if(isset($responseResult->lineItemBundles->lineItems)){
221
+ foreach($responseResult->lineItemBundles->lineItems as $responseLineItem){
222
+ if($responseLineItem->productCode == Mage::getStoreConfig("speedtax/speedtax/shipping_tax_code")){
223
+ return $responseLineItem->taxAmount->decimalValue;
224
+ }
225
+ }
226
+ }
227
+ return 0.0;
228
+ }
229
+
230
+
231
+ //Adds a comment to order history. Method choosen based on Magento version.
232
+ // protected function _addStatusHistoryComment($order, $comment) {
233
+ // if(method_exists($order, 'addStatusHistoryComment')) {
234
+ // $order->addStatusHistoryComment($comment)->save();;
235
+ // } elseif(method_exists($order, 'addStatusToHistory')) {
236
+ // $order->addStatusToHistory($order->getStatus(), $comment, false)->save();;
237
+ // }
238
+ // return $this;
239
+ // }
240
+
241
  }
app/code/community/Harapartners/SpeedTax/Model/Failsafe/Calculation.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Model_Failsafe_Calculation extends Mage_Tax_Model_Calculation {
14
-
15
- public function getRate($request)
16
- {
17
- if (!$request->getCountryId() || !$request->getRegionId() || !$request->getPostcode()) {
18
- return 0;
19
- }
20
-
21
- //Ignore default non-taxable goods, product_class_id = 0 or missing
22
- if(!$request->getData('product_class_id')){
23
- return 0.0;
24
- }
25
-
26
- $failsafeCalRate = Mage::getModel('speedtax/failsafe_calculation_rate');
27
- // Level 1: exact match
28
- $failsafeCalRate->loadByCountryIdRegionIdPostcode($request->getCountryId(), $request->getRegionId(), $request->getPostcode());
29
- if(!!$failsafeCalRate->getId() && !!$failsafeCalRate->getTaxRate()){
30
- return $failsafeCalRate->getTaxRate();
31
- }
32
- // Level 2: partial match
33
- $failsafeCalRate->loadByCountryIdRegionId($request->getCountryId(), $request->getRegionId());
34
- if(!!$failsafeCalRate->getId() && !!$failsafeCalRate->getTaxRate()){
35
- return $failsafeCalRate->getTaxRate();
36
- }
37
-
38
- // Default
39
- return 0.0;
40
- }
41
-
42
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Model_Failsafe_Calculation extends Mage_Tax_Model_Calculation {
14
+
15
+ public function getRate($request)
16
+ {
17
+ if (!$request->getCountryId() || !$request->getRegionId() || !$request->getPostcode()) {
18
+ return 0;
19
+ }
20
+
21
+ //Ignore default non-taxable goods, product_class_id = 0 or missing
22
+ if(!$request->getData('product_class_id')){
23
+ return 0.0;
24
+ }
25
+
26
+ $failsafeCalRate = Mage::getModel('speedtax/failsafe_calculation_rate');
27
+ // Level 1: exact match
28
+ $failsafeCalRate->loadByCountryIdRegionIdPostcode($request->getCountryId(), $request->getRegionId(), $request->getPostcode());
29
+ if(!!$failsafeCalRate->getId() && !!$failsafeCalRate->getTaxRate()){
30
+ return $failsafeCalRate->getTaxRate();
31
+ }
32
+ // Level 2: partial match
33
+ $failsafeCalRate->loadByCountryIdRegionId($request->getCountryId(), $request->getRegionId());
34
+ if(!!$failsafeCalRate->getId() && !!$failsafeCalRate->getTaxRate()){
35
+ return $failsafeCalRate->getTaxRate();
36
+ }
37
+
38
+ // Default
39
+ return 0.0;
40
+ }
41
+
42
  }
app/code/community/Harapartners/SpeedTax/Model/Failsafe/Calculation/Rate.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
-
14
- class Harapartners_SpeedTax_Model_Failsafe_Calculation_Rate extends Mage_Core_Model_Abstract {
15
-
16
- protected function _construct() {
17
- $this->_init('speedtax/failsafe_calculation_rate');
18
- }
19
-
20
- public function loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode){
21
- $this->addData($this->getResource()->loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode));
22
- return $this;
23
- }
24
-
25
- public function loadByCountryIdRegionId($countryId, $regionId){
26
- $this->addData($this->getResource()->loadByCountryIdRegionId($countryId, $regionId));
27
- return $this;
28
- }
29
-
30
- protected function _beforeSave(){
31
- $datetime = date('Y-m-d H:i:s');
32
- if(!$this->getId()){
33
- $this->setData('created_at', $datetime);
34
- }
35
- $this->setData('updated_at', $datetime);
36
- parent::_beforeSave();
37
- }
38
-
39
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+
14
+ class Harapartners_SpeedTax_Model_Failsafe_Calculation_Rate extends Mage_Core_Model_Abstract {
15
+
16
+ protected function _construct() {
17
+ $this->_init('speedtax/failsafe_calculation_rate');
18
+ }
19
+
20
+ public function loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode){
21
+ $this->addData($this->getResource()->loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode));
22
+ return $this;
23
+ }
24
+
25
+ public function loadByCountryIdRegionId($countryId, $regionId){
26
+ $this->addData($this->getResource()->loadByCountryIdRegionId($countryId, $regionId));
27
+ return $this;
28
+ }
29
+
30
+ protected function _beforeSave(){
31
+ $datetime = date('Y-m-d H:i:s');
32
+ if(!$this->getId()){
33
+ $this->setData('created_at', $datetime);
34
+ }
35
+ $this->setData('updated_at', $datetime);
36
+ parent::_beforeSave();
37
+ }
38
+
39
  }
app/code/community/Harapartners/SpeedTax/Model/Failsafe/Sales/Total/Quote/Tax.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Model_Failsafe_Sales_Total_Quote_Tax extends Mage_Tax_Model_Sales_Total_Quote_Tax {
14
-
15
- public function __construct(){
16
- parent::__construct();
17
- $this->_calculator = Mage::getSingleton('speedtax/failsafe_calculation');
18
- }
19
-
20
- protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest){
21
- if(!Mage::getStoreConfig("speedtax/speedtax/tax_shipping")){
22
- return $this;
23
- }
24
- return parent::_calculateShippingTax($address, $taxRateRequest);
25
- }
26
-
27
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Model_Failsafe_Sales_Total_Quote_Tax extends Mage_Tax_Model_Sales_Total_Quote_Tax {
14
+
15
+ public function __construct(){
16
+ parent::__construct();
17
+ $this->_calculator = Mage::getSingleton('speedtax/failsafe_calculation');
18
+ }
19
+
20
+ protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest){
21
+ if(!Mage::getStoreConfig("speedtax/speedtax/is_tax_shipping")){
22
+ return $this;
23
+ }
24
+ return parent::_calculateShippingTax($address, $taxRateRequest);
25
+ }
26
+
27
  }
app/code/community/Harapartners/SpeedTax/Model/Observer.php CHANGED
@@ -1,164 +1,168 @@
1
- <?php
2
-
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license [^]
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
-
15
- class Harapartners_SpeedTax_Model_Observer extends Mage_Core_Model_Abstract {
16
-
17
- // ============================== Checkout process, failsafe calculation can be enabled ============================== //
18
- public function saleOrderSaveBefore(Varien_Event_Observer $observer) {
19
- //Flag orders with speedtax failsafe calculation
20
- if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
21
- return;
22
- }
23
- $order = $observer->getEvent()->getOrder();
24
- if (Mage::helper('speedtax')->isFailsafeEnabled()){
25
- if(Mage::registry('is_speedtax_failsafe_calculation')){
26
- $order->setData('is_speedtax_failsafe_calculation', 1);
27
- Mage::unregister('is_speedtax_failsafe_calculation');
28
- }
29
- }
30
- }
31
-
32
- // ============================== Post invoices to SpeedTax (failsafe can be enabled) ============================== //
33
- public function saleOrderInvoicePay(Varien_Event_Observer $observer) {
34
- if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
35
- return;
36
- }
37
- $invoice = $observer->getEvent()->getInvoice();
38
- if (Mage::helper('speedtax')->isFailsafeEnabled()){
39
- if(!!$invoice->getOrder()){
40
- $invoice->setData('is_speedtax_failsafe_calculation', $invoice->getOrder()->getData('is_speedtax_failsafe_calculation'));
41
- }
42
- }
43
- try {
44
- $processor = Mage::helper('speedtax/processor');
45
- $responseResult = $processor->postOrderInvoice($invoice);
46
- if(isset($responseResult->totalTax->decimalValue)){
47
- $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
48
- $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
49
- $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
50
- }
51
- } catch( Exception $e ) {
52
- //Suppress exception so that the transaction is not reverted (payment already processed)
53
- //Mage::logException($e);
54
- Mage::log("Cannot post order invoice: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
55
- if (Mage::helper('speedtax')->isFailsafeEnabled()) {
56
- //Failsafe logic: mark invoice for "post invoice failsafe"
57
- $invoice->setData('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
58
- }else{
59
- $maskedErrorMessage = 'There is an error processing tax information.';
60
- Mage::getSingleton('core/session')->addError($maskedErrorMessage);
61
- }
62
- }
63
- }
64
-
65
- // ============================== Cancel invoices in SpeedTax ============================== //
66
- public function salesOrderCreditmemoRefund(Varien_Event_Observer $observer) {
67
- if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
68
- return;
69
- }
70
- $creditmemo = $observer->getEvent()->getCreditmemo();
71
- try {
72
- $processor = Mage::helper('speedtax/processor');
73
- $responseResult = $processor->postOrderCreditmemo($creditmemo);
74
- } catch( Exception $e ) {
75
- //Suppress exception so that the transaction is not reverted (payment already processed)
76
- //Mage::logException($e);
77
- Mage::log("Cannot post order credit memo: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
78
- $maskedErrorMessage = 'There is an error processing tax information for order credit memo.';
79
-
80
- //This is backend only activity, do NOT suppress exceptions
81
- //Mage::getSingleton('core/session')->addError($maskedErrorMessage);
82
- Mage::throwException($maskedErrorMessage);
83
- }
84
- }
85
-
86
- //Upon order cancel/edit, credit memo must be created manually for existing invoices, SpeedTax invoices will NOT be voided
87
- public function orderCancelAfter(Varien_Event_Observer $observer) {
88
- return;
89
- // if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
90
- // return;
91
- // }
92
- // $order = $observer->getEvent()->getOrder();
93
- // try {
94
- // $processor = Mage::helper('speedtax/processor');
95
- // $responseResult = $processor->cancelAllOrderTransactions($order);
96
- // } catch( Exception $e ) {
97
- // //Suppress exception so that the transaction is not reverted (payment already processed)
98
- // //Mage::logException($e);
99
- // Mage::log("Cannot cancel all order transactions: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
100
- // $maskedErrorMessage = 'There is an error processing tax information for all order transactions.';
101
- //
102
- // //This is backend only activity, do NOT suppress exceptions
103
- // //Mage::getSingleton('core/session')->addError($maskedErrorMessage);
104
- // Mage::throwException($maskedErrorMessage);
105
- // }
106
- }
107
-
108
- // ============================================================================================ //
109
- // ---------------------------------------- Admin only ---------------------------------------- //
110
- /**
111
- * Prepare important admin panel messages, set data in session
112
- *
113
- * @param Varien_Event_Observer $observer
114
- */
115
- public function adminhtmlOnlyLayoutGenerateBlocksAfter(Varien_Event_Observer $observer){
116
- $controllerAction = $observer->getEvent()->getData('action');
117
- $layout = $observer->getEvent()->getData('layout');
118
-
119
- //Only add message for administrator who already logged in
120
- if(!!Mage::getSingleton('admin/session')->getUser() && !!Mage::getSingleton('admin/session')->getUser()->getId()){
121
- $notificationsBlock = $layout->getBlock('notifications');
122
- if(!!$notificationsBlock && !!($notificationsBlock instanceof Mage_Core_Block_Abstract)){
123
- $nsNotificationBlock = $layout->createBlock('speedtax/adminhtml_notification');
124
- $notificationsBlock->append($nsNotificationBlock, 'speedtax_notification');
125
- }
126
- }
127
- return;
128
- }
129
-
130
- // ============================================================================================ //
131
- // ---------------------------------------- CRON jobs ---------------------------------------- //
132
- public function batchPostFailsafeInvoice(){
133
- if(!Mage::getStoreConfig ( 'speedtax/failsafe/is_auto_post_failsafe_invoice' )){
134
- return;
135
- }
136
- $sptxProcessor = Mage::helper('speedtax/processor');
137
- $invoicCollection = Mage::getModel('sales/order_invoice')->getCollection();
138
- $invoicCollection->addAttributeToFilter('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
139
- $invoicCollection->setPageSize(Harapartners_SpeedTax_Helper_Data::DEFAULT_MAGENTO_COLLECTION_PAGE_SIZE);
140
- $currentPage = 1;
141
- $totalNumPages = $invoicCollection->getLastPageNumber();
142
- do {
143
- $invoicCollection->setCurPage($currentPage);
144
- foreach ($invoicCollection as $invoice) {
145
- try{
146
- $responseResult = $sptxProcessor->postOrderInvoice($invoice);
147
- if(isset($responseResult->totalTax->decimalValue)){
148
- $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
149
- $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
150
- $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
151
- $invoice->save();
152
- }
153
- }catch (Exception $ex){
154
- //Suppress errors in cronjob
155
- }
156
- unset($invoice);
157
- }
158
- // Pagination Loop Control
159
- $currentPage ++;
160
- $invoicCollection->clear();
161
- } while ($currentPage <= $totalNumPages);
162
- }
163
-
 
 
 
 
164
  }
1
+ <?php
2
+
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license [^]
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+
15
+ class Harapartners_SpeedTax_Model_Observer extends Mage_Core_Model_Abstract {
16
+
17
+ // ============================== Checkout process, failsafe calculation can be enabled ============================== //
18
+ public function saleOrderSaveBefore(Varien_Event_Observer $observer) {
19
+ //Flag orders with speedtax failsafe calculation
20
+ if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
21
+ return;
22
+ }
23
+ $order = $observer->getEvent()->getOrder();
24
+ if (Mage::helper('speedtax')->isFailsafeEnabled()){
25
+ if(Mage::registry('is_speedtax_failsafe_calculation')){
26
+ $order->setData('is_speedtax_failsafe_calculation', 1);
27
+ Mage::unregister('is_speedtax_failsafe_calculation');
28
+ }
29
+ }
30
+ }
31
+
32
+ // ============================== Post invoices to SpeedTax (failsafe can be enabled) ============================== //
33
+ public function saleOrderInvoicePay(Varien_Event_Observer $observer) {
34
+ if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
35
+ return;
36
+ }
37
+ $invoice = $observer->getEvent()->getInvoice();
38
+ if (Mage::helper('speedtax')->isFailsafeEnabled()){
39
+ if(!!$invoice->getOrder()){
40
+ $invoice->setData('is_speedtax_failsafe_calculation', $invoice->getOrder()->getData('is_speedtax_failsafe_calculation'));
41
+ }
42
+ }
43
+ try {
44
+ $processor = Mage::helper('speedtax/processor');
45
+ $responseResult = $processor->postOrderInvoice($invoice);
46
+ if(isset($responseResult->totalTax->decimalValue)){
47
+ $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
48
+ $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
49
+ $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
50
+ }
51
+ } catch( Exception $e ) {
52
+ //Suppress exception so that the transaction is not reverted (payment already processed)
53
+ //Mage::logException($e);
54
+ Mage::log("Cannot post order invoice: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
55
+ if (Mage::helper('speedtax')->isFailsafeEnabled()) {
56
+ //Failsafe logic: mark invoice for "post invoice failsafe"
57
+ $invoice->setData('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
58
+ }else{
59
+ $maskedErrorMessage = 'There is an error processing tax information.';
60
+ if (Mage::app()->getStore()->isAdmin()) {
61
+ Mage::getSingleton('adminhtml/session')->addError($maskedErrorMessage);
62
+ }else{
63
+ Mage::getSingleton('core/session')->addError($maskedErrorMessage);
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ // ============================== Cancel invoices in SpeedTax ============================== //
70
+ public function salesOrderCreditmemoRefund(Varien_Event_Observer $observer) {
71
+ if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
72
+ return;
73
+ }
74
+ $creditmemo = $observer->getEvent()->getCreditmemo();
75
+ try {
76
+ $processor = Mage::helper('speedtax/processor');
77
+ $responseResult = $processor->postOrderCreditmemo($creditmemo);
78
+ } catch( Exception $e ) {
79
+ //Suppress exception so that the transaction is not reverted (payment already processed)
80
+ //Mage::logException($e);
81
+ Mage::log("Cannot post order credit memo: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
82
+ $maskedErrorMessage = 'There is an error processing tax information for order credit memo.';
83
+
84
+ //This is backend only activity, do NOT suppress exceptions
85
+ //Mage::getSingleton('core/session')->addError($maskedErrorMessage);
86
+ Mage::throwException($maskedErrorMessage);
87
+ }
88
+ }
89
+
90
+ //Upon order cancel/edit, credit memo must be created manually for existing invoices, SpeedTax invoices will NOT be voided
91
+ public function orderCancelAfter(Varien_Event_Observer $observer) {
92
+ return;
93
+ // if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
94
+ // return;
95
+ // }
96
+ // $order = $observer->getEvent()->getOrder();
97
+ // try {
98
+ // $processor = Mage::helper('speedtax/processor');
99
+ // $responseResult = $processor->cancelAllOrderTransactions($order);
100
+ // } catch( Exception $e ) {
101
+ // //Suppress exception so that the transaction is not reverted (payment already processed)
102
+ // //Mage::logException($e);
103
+ // Mage::log("Cannot cancel all order transactions: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
104
+ // $maskedErrorMessage = 'There is an error processing tax information for all order transactions.';
105
+ //
106
+ // //This is backend only activity, do NOT suppress exceptions
107
+ // //Mage::getSingleton('core/session')->addError($maskedErrorMessage);
108
+ // Mage::throwException($maskedErrorMessage);
109
+ // }
110
+ }
111
+
112
+ // ============================================================================================ //
113
+ // ---------------------------------------- Admin only ---------------------------------------- //
114
+ /**
115
+ * Prepare important admin panel messages, set data in session
116
+ *
117
+ * @param Varien_Event_Observer $observer
118
+ */
119
+ public function adminhtmlOnlyLayoutGenerateBlocksAfter(Varien_Event_Observer $observer){
120
+ $controllerAction = $observer->getEvent()->getData('action');
121
+ $layout = $observer->getEvent()->getData('layout');
122
+
123
+ //Only add message for administrator who already logged in
124
+ if(!!Mage::getSingleton('admin/session')->getUser() && !!Mage::getSingleton('admin/session')->getUser()->getId()){
125
+ $notificationsBlock = $layout->getBlock('notifications');
126
+ if(!!$notificationsBlock && !!($notificationsBlock instanceof Mage_Core_Block_Abstract)){
127
+ $nsNotificationBlock = $layout->createBlock('speedtax/adminhtml_notification');
128
+ $notificationsBlock->append($nsNotificationBlock, 'speedtax_notification');
129
+ }
130
+ }
131
+ return;
132
+ }
133
+
134
+ // ============================================================================================ //
135
+ // ---------------------------------------- CRON jobs ---------------------------------------- //
136
+ public function batchPostFailsafeInvoice(){
137
+ if(!Mage::getStoreConfig ( 'speedtax/failsafe/is_auto_post_failsafe_invoice' )){
138
+ return;
139
+ }
140
+ $sptxProcessor = Mage::helper('speedtax/processor');
141
+ $invoicCollection = Mage::getModel('sales/order_invoice')->getCollection();
142
+ $invoicCollection->addAttributeToFilter('speedtax_invoice_status', Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE);
143
+ $invoicCollection->setPageSize(Harapartners_SpeedTax_Helper_Data::DEFAULT_MAGENTO_COLLECTION_PAGE_SIZE);
144
+ $currentPage = 1;
145
+ $totalNumPages = $invoicCollection->getLastPageNumber();
146
+ do {
147
+ $invoicCollection->setCurPage($currentPage);
148
+ foreach ($invoicCollection as $invoice) {
149
+ try{
150
+ $responseResult = $sptxProcessor->postOrderInvoice($invoice);
151
+ if(isset($responseResult->totalTax->decimalValue)){
152
+ $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
153
+ $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
154
+ $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
155
+ $invoice->save();
156
+ }
157
+ }catch (Exception $ex){
158
+ //Suppress errors in cronjob
159
+ }
160
+ unset($invoice);
161
+ }
162
+ // Pagination Loop Control
163
+ $currentPage ++;
164
+ $invoicCollection->clear();
165
+ } while ($currentPage <= $totalNumPages);
166
+ }
167
+
168
  }
app/code/community/Harapartners/SpeedTax/Model/Resource/Failsafe/Calculation/Rate.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
-
14
- class Harapartners_SpeedTax_Model_Resource_Failsafe_Calculation_Rate extends Mage_Core_Model_Resource_Db_Abstract {
15
-
16
- protected function _construct() {
17
- $this->_init('speedtax/failsafe_calculation_rate', 'rate_id');
18
- }
19
-
20
- public function loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode){
21
- $readAdapter = $this->_getReadAdapter();
22
- $select = $readAdapter->select()
23
- ->from($this->getMainTable())
24
- ->where('country_id=:country_id')
25
- ->where('region_id=:region_id')
26
- ->where('postcode=:postcode');
27
- $result = $readAdapter->fetchRow($select, array('country_id' => $countryId, 'region_id' => $regionId, 'postcode' => $postcode));
28
- if (!$result) {
29
- $result = array();
30
- }
31
- return $result;
32
- }
33
-
34
- public function loadByCountryIdRegionId($countryId, $regionId){
35
- $readAdapter = $this->_getReadAdapter();
36
- $select = $readAdapter->select()
37
- ->from($this->getMainTable())
38
- ->where('country_id=:country_id')
39
- ->where('region_id=:region_id');
40
- $result = $readAdapter->fetchRow($select, array('country_id' => $countryId, 'region_id' => $regionId));
41
- if (!$result) {
42
- $result = array();
43
- }
44
- return $result;
45
- }
46
-
47
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+
14
+ class Harapartners_SpeedTax_Model_Resource_Failsafe_Calculation_Rate extends Mage_Core_Model_Resource_Db_Abstract {
15
+
16
+ protected function _construct() {
17
+ $this->_init('speedtax/failsafe_calculation_rate', 'rate_id');
18
+ }
19
+
20
+ public function loadByCountryIdRegionIdPostcode($countryId, $regionId, $postcode){
21
+ $readAdapter = $this->_getReadAdapter();
22
+ $select = $readAdapter->select()
23
+ ->from($this->getMainTable())
24
+ ->where('country_id=:country_id')
25
+ ->where('region_id=:region_id')
26
+ ->where('postcode=:postcode');
27
+ $result = $readAdapter->fetchRow($select, array('country_id' => $countryId, 'region_id' => $regionId, 'postcode' => $postcode));
28
+ if (!$result) {
29
+ $result = array();
30
+ }
31
+ return $result;
32
+ }
33
+
34
+ public function loadByCountryIdRegionId($countryId, $regionId){
35
+ $readAdapter = $this->_getReadAdapter();
36
+ $select = $readAdapter->select()
37
+ ->from($this->getMainTable())
38
+ ->where('country_id=:country_id')
39
+ ->where('region_id=:region_id');
40
+ $result = $readAdapter->fetchRow($select, array('country_id' => $countryId, 'region_id' => $regionId));
41
+ if (!$result) {
42
+ $result = array();
43
+ }
44
+ return $result;
45
+ }
46
+
47
  }
app/code/community/Harapartners/SpeedTax/Model/Resource/Failsafe/Calculation/Rate/Collection.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
-
14
- class Harapartners_SpeedTax_Model_Resource_Failsafe_Calculation_Rate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
15
-
16
- public function _construct(){
17
- $this->_init('speedtax/failsafe_calculation_rate');
18
- }
19
-
20
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+
14
+ class Harapartners_SpeedTax_Model_Resource_Failsafe_Calculation_Rate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
15
+
16
+ public function _construct(){
17
+ $this->_init('speedtax/failsafe_calculation_rate');
18
+ }
19
+
20
  }
app/code/community/Harapartners/SpeedTax/Model/Rewrite/Tax/Sales/Total/Quote/Tax.php CHANGED
@@ -1,70 +1,70 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_SpeedTax_Model_Rewrite_Tax_Sales_Total_Quote_Tax extends Mage_Tax_Model_Sales_Total_Quote_Tax {
14
-
15
- public function collect(Mage_Sales_Model_Quote_Address $address) {
16
- if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
17
- return parent::collect($address);
18
- }
19
-
20
- $store = $address->getQuote()->getStore();
21
- $customer = $address->getQuote()->getCustomer();
22
-
23
- $address->setTotalAmount($this->getCode(), 0);
24
- $address->setBaseTotalAmount($this->getCode(), 0);
25
-
26
- $address->setTaxAmount(0);
27
- $address->setBaseTaxAmount(0);
28
- $address->setShippingTaxAmount(0);
29
- $address->setBaseShippingTaxAmount(0);
30
-
31
- //Init
32
- $this->_setAddress($address);
33
- $this->_setAmount(0);
34
- $this->_setBaseAmount(0);
35
-
36
- try {
37
- $processor = Mage::helper('speedtax/processor');
38
- $responseResult = $processor->queryQuoteAddress($address);
39
- //Address line item amount and shipping tax amount are updated within the query
40
- if (!!$responseResult) {
41
- $taxAmount = $processor->getTotalTax($responseResult);
42
- $this->_addAmount(Mage::app()->getStore()->convertPrice($taxAmount, false));
43
- $this->_addBaseAmount($taxAmount);
44
- if (Mage::helper('speedtax')->isFailsafeEnabled()) {
45
- //Failsafe logic: accumuate rates in preparation of future failure
46
- Mage::helper('speedtax/failsafe')->updateFailsafeRate($address, $responseResult);
47
- }
48
- }
49
- } catch(Exception $e) {
50
- //Tax collecting is very important, this is within the collect total (cannot bubble exceptions), force a redirect
51
- //Mage::logException($e);
52
- Mage::log("Cannot collect quote tax total: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
53
- if (Mage::helper('speedtax')->isFailsafeEnabled()) {
54
- //Failsafe logic: mark "calculate by failsafe rates" in case the order is placed
55
- Mage::unregister('is_speedtax_failsafe_calculation');
56
- Mage::register('is_speedtax_failsafe_calculation', true);
57
- //Failsafe logic: calculate by failsafe rates
58
- $taxFailsafe = Mage::getModel('speedtax/failsafe_sales_total_quote_tax');
59
- return $taxFailsafe->collect($address);
60
- }else{
61
- $maskedErrorMessage = 'There is an error calculating tax.';
62
- Mage::getSingleton('core/session')->addError($maskedErrorMessage);
63
- throw new Mage_Core_Model_Session_Exception($maskedErrorMessage); //Session exceptions will be redirected to base URL
64
- }
65
- }
66
-
67
- return $this;
68
- }
69
-
70
  }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_SpeedTax_Model_Rewrite_Tax_Sales_Total_Quote_Tax extends Mage_Tax_Model_Sales_Total_Quote_Tax {
14
+
15
+ public function collect(Mage_Sales_Model_Quote_Address $address) {
16
+ if (!Mage::helper('speedtax')->isSpeedTaxEnabled()) {
17
+ return parent::collect($address);
18
+ }
19
+
20
+ $store = $address->getQuote()->getStore();
21
+ $customer = $address->getQuote()->getCustomer();
22
+
23
+ $address->setTotalAmount($this->getCode(), 0);
24
+ $address->setBaseTotalAmount($this->getCode(), 0);
25
+
26
+ $address->setTaxAmount(0);
27
+ $address->setBaseTaxAmount(0);
28
+ $address->setShippingTaxAmount(0);
29
+ $address->setBaseShippingTaxAmount(0);
30
+
31
+ //Init
32
+ $this->_setAddress($address);
33
+ $this->_setAmount(0);
34
+ $this->_setBaseAmount(0);
35
+
36
+ try {
37
+ $processor = Mage::helper('speedtax/processor');
38
+ $responseResult = $processor->queryQuoteAddress($address);
39
+ //Address line item amount and shipping tax amount are updated within the query
40
+ if (!!$responseResult) {
41
+ $taxAmount = $processor->getTotalTax($responseResult);
42
+ $this->_addAmount(Mage::app()->getStore()->convertPrice($taxAmount, false));
43
+ $this->_addBaseAmount($taxAmount);
44
+ if (Mage::helper('speedtax')->isFailsafeEnabled()) {
45
+ //Failsafe logic: accumuate rates in preparation of future failure
46
+ Mage::helper('speedtax/failsafe')->updateFailsafeRate($address, $responseResult);
47
+ }
48
+ }
49
+ } catch(Exception $e) {
50
+ //Tax collecting is very important, this is within the collect total (cannot bubble exceptions), force a redirect
51
+ //Mage::logException($e);
52
+ Mage::log("Cannot collect quote tax total: {$e->getMessage()}\r\n{$e->getTraceAsString()}", null, Harapartners_SpeedTax_Helper_Data::ERROR_LOG_FILE, true);
53
+ if (Mage::helper('speedtax')->isFailsafeEnabled()) {
54
+ //Failsafe logic: mark "calculate by failsafe rates" in case the order is placed
55
+ Mage::unregister('is_speedtax_failsafe_calculation');
56
+ Mage::register('is_speedtax_failsafe_calculation', true);
57
+ //Failsafe logic: calculate by failsafe rates
58
+ $taxFailsafe = Mage::getModel('speedtax/failsafe_sales_total_quote_tax');
59
+ return $taxFailsafe->collect($address);
60
+ }else{
61
+ $maskedErrorMessage = 'There is an error calculating tax.';
62
+ Mage::getSingleton('core/session')->addError($maskedErrorMessage);
63
+ throw new Mage_Core_Model_Session_Exception($maskedErrorMessage); //Session exceptions will be redirected to base URL
64
+ }
65
+ }
66
+
67
+ return $this;
68
+ }
69
+
70
  }
app/code/community/Harapartners/SpeedTax/Model/Session.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
-
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license [^]
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
-
15
- class Harapartners_SpeedTax_Model_Session extends Mage_Core_Model_Session_Abstract {
16
-
17
- const REQUEST_CACHE_TTL = 600;
18
-
19
- public function __construct() {
20
- $this->init('speedtax');
21
- }
22
-
23
- public function loadCachedResponse($sptxInvoiceCacheKey){
24
- $cacheStorage = $this->getData('cache_storage');
25
- if(!isset($cacheStorage[$sptxInvoiceCacheKey])){
26
- return false;
27
- }
28
- $cacheEntry = $cacheStorage[$sptxInvoiceCacheKey];
29
- if($this->_isCacheEntryValid($cacheEntry)){
30
- return json_decode($cacheEntry['response_json']);
31
- }
32
- return false;
33
- }
34
-
35
- public function saveCachedResponse($sptxInvoiceCacheKey, $response){
36
- $cacheStorage = $this->getData('cache_storage');
37
- if(!$cacheStorage){
38
- $cacheStorage = array();
39
- }
40
- $cacheStorage[$sptxInvoiceCacheKey] = array(
41
- 'timestamp' => time(),
42
- 'response_json' => json_encode($response)
43
- );
44
- $cacheStorage = $this->_clearExpiredEnties($cacheStorage);
45
- $this->setData('cache_storage', $cacheStorage);
46
- return true;
47
- }
48
-
49
- protected function _clearExpiredEnties($cacheStorage){
50
- foreach($cacheStorage as $sptxInvoiceCacheKey => $cacheEntry){
51
- if(!$this->_isCacheEntryValid($cacheEntry)){
52
- unset($cacheStorage[$sptxInvoiceCacheKey]);
53
- }
54
- }
55
- return $cacheStorage;
56
- }
57
-
58
- protected function _isCacheEntryValid($cacheEntry){
59
- return isset($cacheEntry['timestamp'])
60
- && $cacheEntry['timestamp'] + self::REQUEST_CACHE_TTL > time()
61
- && isset($cacheEntry['response_json']);
62
- }
63
-
64
  }
1
+ <?php
2
+
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license [^]
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+
15
+ class Harapartners_SpeedTax_Model_Session extends Mage_Core_Model_Session_Abstract {
16
+
17
+ const REQUEST_CACHE_TTL = 600;
18
+
19
+ public function __construct() {
20
+ $this->init('speedtax');
21
+ }
22
+
23
+ public function loadCachedResponse($sptxInvoiceCacheKey){
24
+ $cacheStorage = $this->getData('cache_storage');
25
+ if(!isset($cacheStorage[$sptxInvoiceCacheKey])){
26
+ return false;
27
+ }
28
+ $cacheEntry = $cacheStorage[$sptxInvoiceCacheKey];
29
+ if($this->_isCacheEntryValid($cacheEntry)){
30
+ return json_decode($cacheEntry['response_json']);
31
+ }
32
+ return false;
33
+ }
34
+
35
+ public function saveCachedResponse($sptxInvoiceCacheKey, $response){
36
+ $cacheStorage = $this->getData('cache_storage');
37
+ if(!$cacheStorage){
38
+ $cacheStorage = array();
39
+ }
40
+ $cacheStorage[$sptxInvoiceCacheKey] = array(
41
+ 'timestamp' => time(),
42
+ 'response_json' => json_encode($response)
43
+ );
44
+ $cacheStorage = $this->_clearExpiredEnties($cacheStorage);
45
+ $this->setData('cache_storage', $cacheStorage);
46
+ return true;
47
+ }
48
+
49
+ protected function _clearExpiredEnties($cacheStorage){
50
+ foreach($cacheStorage as $sptxInvoiceCacheKey => $cacheEntry){
51
+ if(!$this->_isCacheEntryValid($cacheEntry)){
52
+ unset($cacheStorage[$sptxInvoiceCacheKey]);
53
+ }
54
+ }
55
+ return $cacheStorage;
56
+ }
57
+
58
+ protected function _isCacheEntryValid($cacheEntry){
59
+ return isset($cacheEntry['timestamp'])
60
+ && $cacheEntry['timestamp'] + self::REQUEST_CACHE_TTL > time()
61
+ && isset($cacheEntry['response_json']);
62
+ }
63
+
64
  }
app/code/community/Harapartners/SpeedTax/Model/Source/Usregions.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- class Harapartners_Speedtax_Model_Source_Usregions
14
- {
15
- protected $_options;
16
-
17
- public function toOptionArray($isMultiselect=false)
18
- {
19
- if (!$this->_options) {
20
- $regionCollection = Mage::getModel( 'directory/region' )->getCollection();
21
- $regionCollection->getSelect()->where( 'country_id = ?', 'US' );
22
- $regionOptions = array();
23
- foreach( $regionCollection as $region ) {
24
- $regionOptions[] = array( 'label' => $region->getDefaultName(), 'value' => $region->getId() );
25
- }
26
- $this->_options = $regionOptions;
27
- }
28
- $options = $this->_options;
29
- if(!$isMultiselect){
30
- array_unshift($options, array('value'=>'', 'label'=>''));
31
- }
32
-
33
- return $options;
34
- }
35
- }
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ class Harapartners_Speedtax_Model_Source_Usregions
14
+ {
15
+ protected $_options;
16
+
17
+ public function toOptionArray($isMultiselect=false)
18
+ {
19
+ if (!$this->_options) {
20
+ $regionCollection = Mage::getModel( 'directory/region' )->getCollection();
21
+ $regionCollection->getSelect()->where( 'country_id = ?', 'US' );
22
+ $regionOptions = array();
23
+ foreach( $regionCollection as $region ) {
24
+ $regionOptions[] = array( 'label' => $region->getDefaultName(), 'value' => $region->getId() );
25
+ }
26
+ $this->_options = $regionOptions;
27
+ }
28
+ $options = $this->_options;
29
+ if(!$isMultiselect){
30
+ array_unshift($options, array('value'=>'', 'label'=>''));
31
+ }
32
+
33
+ return $options;
34
+ }
35
+ }
app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/InvoiceController.php CHANGED
@@ -1,80 +1,80 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Adminhtml_InvoiceController extends Mage_Adminhtml_Controller_Action {
14
-
15
- public function indexAction() {
16
- $this->loadLayout ();
17
- $this->_setActiveMenu ( 'speedtax/invoice' );
18
- $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_all_index' ) );
19
- $this->renderLayout ();
20
- }
21
-
22
- public function failsafeIndexAction() {
23
- $this->loadLayout ();
24
- $this->_setActiveMenu ( 'speedtax/invoice' );
25
- $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_failsafe_index' ) );
26
- $this->renderLayout ();
27
- }
28
-
29
- public function rateVerificationIndexAction() {
30
- $this->loadLayout ();
31
- $this->_setActiveMenu ( 'speedtax/invoice' );
32
- $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_rateverification_index' ) );
33
- $this->renderLayout ();
34
- }
35
-
36
- public function massPostToSpeedtaxAction(){
37
- $invoiceIds = $this->getRequest()->getPost('invoice_ids', array());
38
- $sptxProcessor = Mage::helper('speedtax/processor');
39
- $successInvoiceIds = array();
40
- $noticeInvoiceIds = array();
41
- $errorInvoiceIds = array();
42
- $allowedInovicePostStatusArray = array(
43
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_PENDING,
44
- Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE
45
- );
46
- foreach ($invoiceIds as $invoiceId) {
47
- $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
48
- if(!in_array($invoice->getData('speedtax_invoice_status'), $allowedInovicePostStatusArray)){
49
- $noticeInvoiceIds[] = $invoice->getData('increment_id');
50
- continue;
51
- }
52
- try{
53
- $responseResult = $sptxProcessor->postOrderInvoice($invoice);
54
- if(isset($responseResult->totalTax->decimalValue)){
55
- $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
56
- $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
57
- $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
58
- $invoice->save();
59
- }
60
- $successInvoiceIds[] = $invoice->getData('increment_id');
61
- }catch (Exception $ex){
62
- $errorInvoiceIds[] = $invoice->getData('increment_id');
63
- }
64
- unset($invoice);
65
- }
66
-
67
- if(count($successInvoiceIds)){
68
- Mage::getSingleton('adminhtml/session')->addSuccess("Invoice posted to SalesTax. Invoice #" . implode(", #", $successInvoiceIds));
69
- }
70
- if(count($noticeInvoiceIds)){
71
- Mage::getSingleton('adminhtml/session')->addNotice("Only inovices with Failsafe or Pending status can be posted. Invoice #" . implode(", #", $noticeInvoiceIds));
72
- }
73
- if(count($errorInvoiceIds)){
74
- Mage::getSingleton('adminhtml/session')->addError("Cannot post invoices to SalesTax. Invoice: #" . implode(", #", $errorInvoiceIds));
75
- }
76
-
77
- $this->_redirectReferer();
78
- }
79
-
80
- }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Adminhtml_InvoiceController extends Mage_Adminhtml_Controller_Action {
14
+
15
+ public function indexAction() {
16
+ $this->loadLayout ();
17
+ $this->_setActiveMenu ( 'speedtax/invoice' );
18
+ $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_all_index' ) );
19
+ $this->renderLayout ();
20
+ }
21
+
22
+ public function failsafeIndexAction() {
23
+ $this->loadLayout ();
24
+ $this->_setActiveMenu ( 'speedtax/invoice' );
25
+ $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_failsafe_index' ) );
26
+ $this->renderLayout ();
27
+ }
28
+
29
+ public function rateVerificationIndexAction() {
30
+ $this->loadLayout ();
31
+ $this->_setActiveMenu ( 'speedtax/invoice' );
32
+ $this->_addContent ( $this->getLayout ()->createBlock ( 'speedtax/adminhtml_invoice_rateverification_index' ) );
33
+ $this->renderLayout ();
34
+ }
35
+
36
+ public function massPostToSpeedtaxAction(){
37
+ $invoiceIds = $this->getRequest()->getPost('invoice_ids', array());
38
+ $sptxProcessor = Mage::helper('speedtax/processor');
39
+ $successInvoiceIds = array();
40
+ $noticeInvoiceIds = array();
41
+ $errorInvoiceIds = array();
42
+ $allowedInovicePostStatusArray = array(
43
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_PENDING,
44
+ Harapartners_SpeedTax_Helper_Processor::SPEEDTAX_INVOICE_STATUS_FAILSAFE
45
+ );
46
+ foreach ($invoiceIds as $invoiceId) {
47
+ $invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
48
+ if(!in_array($invoice->getData('speedtax_invoice_status'), $allowedInovicePostStatusArray)){
49
+ $noticeInvoiceIds[] = $invoice->getData('increment_id');
50
+ continue;
51
+ }
52
+ try{
53
+ $responseResult = $sptxProcessor->postOrderInvoice($invoice);
54
+ if(isset($responseResult->totalTax->decimalValue)){
55
+ $baseSpeedTaxTaxAmount = $responseResult->totalTax->decimalValue;
56
+ $invoice->setData('base_speedtax_tax_amount', $baseSpeedTaxTaxAmount);
57
+ $invoice->setData('speedtax_tax_amount', Mage::app()->getStore()->convertPrice($baseSpeedTaxTaxAmount, false));
58
+ $invoice->save();
59
+ }
60
+ $successInvoiceIds[] = $invoice->getData('increment_id');
61
+ }catch (Exception $ex){
62
+ $errorInvoiceIds[] = $invoice->getData('increment_id');
63
+ }
64
+ unset($invoice);
65
+ }
66
+
67
+ if(count($successInvoiceIds)){
68
+ Mage::getSingleton('adminhtml/session')->addSuccess("Invoice posted to SalesTax. Invoice #" . implode(", #", $successInvoiceIds));
69
+ }
70
+ if(count($noticeInvoiceIds)){
71
+ Mage::getSingleton('adminhtml/session')->addNotice("Only inovices with Failsafe or Pending status can be posted. Invoice #" . implode(", #", $noticeInvoiceIds));
72
+ }
73
+ if(count($errorInvoiceIds)){
74
+ Mage::getSingleton('adminhtml/session')->addError("Cannot post invoices to SalesTax. Invoice: #" . implode(", #", $errorInvoiceIds));
75
+ }
76
+
77
+ $this->_redirectReferer();
78
+ }
79
+
80
+ }
app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/NotificationController.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Adminhtml_NotificationController extends Mage_Adminhtml_Controller_Action {
14
-
15
- public function disableAction() {
16
- try{
17
- $notificationkey = $this->getRequest()->getParam('notification_key');
18
- $coreConfigData = Mage::getModel('core/config_data')->load(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS, 'path');
19
- //In case the first time save
20
- $coreConfigData->setpath(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS);
21
- $notificationDisabled = json_decode($coreConfigData->getValue(), 1);
22
- $notificationDisabled[$notificationkey] = 1;
23
- $coreConfigData->setValue(json_encode($notificationDisabled));
24
- $coreConfigData->save();
25
- }catch (Exception $ex){
26
- //Silence
27
- }
28
- $this->_redirectReferer();
29
- }
30
-
31
-
32
- }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Adminhtml_NotificationController extends Mage_Adminhtml_Controller_Action {
14
+
15
+ public function disableAction() {
16
+ try{
17
+ $notificationkey = $this->getRequest()->getParam('notification_key');
18
+ $coreConfigData = Mage::getModel('core/config_data')->load(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS, 'path');
19
+ //In case the first time save
20
+ $coreConfigData->setpath(Harapartners_SpeedTax_Helper_Data::XML_PATH_NOTIFICATION_DISABLED_COMPRESS);
21
+ $notificationDisabled = json_decode($coreConfigData->getValue(), 1);
22
+ $notificationDisabled[$notificationkey] = 1;
23
+ $coreConfigData->setValue(json_encode($notificationDisabled));
24
+ $coreConfigData->save();
25
+ }catch (Exception $ex){
26
+ //Silence
27
+ }
28
+ $this->_redirectReferer();
29
+ }
30
+
31
+
32
+ }
app/code/community/Harapartners/SpeedTax/controllers/Adminhtml/System/Config/AjaxController.php CHANGED
@@ -1,63 +1,63 @@
1
- <?php
2
- /**
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- */
12
-
13
- class Harapartners_SpeedTax_Adminhtml_System_Config_AjaxController extends Mage_Adminhtml_Controller_Action {
14
-
15
- public function authenticationAction() {
16
-
17
- try{
18
- $username = $this->getRequest()->getParam('username');
19
- $password = $this->getRequest()->getParam('password');
20
- $companyCode = $this->getRequest()->getParam('company_code');
21
- $isTestMode = $this->getRequest()->getParam('is_test_mode');
22
-
23
- //Check encrypted config
24
- if (preg_match('/^\*+$/', $password)) {
25
- $password = Mage::helper('core')->decrypt(Mage::getStoreConfig('speedtax/speedtax/password'));
26
- }
27
-
28
- if(!!$isTestMode){
29
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
30
- }else{
31
- $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
32
- }
33
-
34
- $credentials = array(
35
- 'username' => $username,
36
- 'password' => $password,
37
- 'company_code' => $companyCode,
38
- 'service_mode' => $serviceMode
39
- );
40
-
41
- //auth_token and data_token are handled within
42
- $result = Mage::helper ('speedtax/connector_speedtax')->authenticationRequest($credentials);
43
-
44
- }catch(Exception $e){
45
- $errorMessage = $e->getMessage();
46
- if(!$errorMessage){
47
- $errorMessage = 'Connection failed.';
48
- }
49
- echo json_encode(array(
50
- 'status' => 0,
51
- 'message' => $errorMessage
52
- )); //Json error
53
- exit;
54
- }
55
- //Need to send $websiteResultJson, the store config is still the cache value, not our new value
56
- echo json_encode(array(
57
- 'status' => 1,
58
- 'message' => 'Validation successful!'
59
- )); //Json success
60
- exit;
61
- }
62
-
63
  }
1
+ <?php
2
+ /**
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ */
12
+
13
+ class Harapartners_SpeedTax_Adminhtml_System_Config_AjaxController extends Mage_Adminhtml_Controller_Action {
14
+
15
+ public function authenticationAction() {
16
+
17
+ try{
18
+ $username = $this->getRequest()->getParam('username');
19
+ $password = $this->getRequest()->getParam('password');
20
+ $companyCode = $this->getRequest()->getParam('company_code');
21
+ $isTestMode = $this->getRequest()->getParam('is_test_mode');
22
+
23
+ //Check encrypted config
24
+ if (preg_match('/^\*+$/', $password)) {
25
+ $password = Mage::helper('core')->decrypt(Mage::getStoreConfig('speedtax/speedtax/password'));
26
+ }
27
+
28
+ if(!!$isTestMode){
29
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_TEST;
30
+ }else{
31
+ $serviceMode = Harapartners_ConnectorHub_Helper_Connector_Core::REQUEST_SERVICE_MODE_PRODUCTION;
32
+ }
33
+
34
+ $credentials = array(
35
+ 'username' => $username,
36
+ 'password' => $password,
37
+ 'company_code' => $companyCode,
38
+ 'service_mode' => $serviceMode
39
+ );
40
+
41
+ //auth_token and data_token are handled within
42
+ $result = Mage::helper ('speedtax/connector_speedtax')->authenticationRequest($credentials);
43
+
44
+ }catch(Exception $e){
45
+ $errorMessage = $e->getMessage();
46
+ if(!$errorMessage){
47
+ $errorMessage = 'Connection failed.';
48
+ }
49
+ echo json_encode(array(
50
+ 'status' => 0,
51
+ 'message' => $errorMessage
52
+ )); //Json error
53
+ exit;
54
+ }
55
+ //Need to send $websiteResultJson, the store config is still the cache value, not our new value
56
+ echo json_encode(array(
57
+ 'status' => 1,
58
+ 'message' => 'Validation successful!'
59
+ )); //Json success
60
+ exit;
61
+ }
62
+
63
  }
app/code/community/Harapartners/SpeedTax/etc/adminhtml.xml CHANGED
@@ -1,71 +1,71 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- *
13
- -->
14
- <config>
15
- <acl>
16
- <resources>
17
- <admin>
18
- <children>
19
- <speedtax translate="title" module="speedtax">
20
- <title>SalesTax</title>
21
- <children>
22
- <invoice>
23
- <title>Manage Invoices</title>
24
- </invoice>
25
- </children>
26
- </speedtax>
27
- <system>
28
- <children>
29
- <config>
30
- <children>
31
- <speedtax translate="title" module="speedtax">
32
- <title>SpeedTax Configuration</title>
33
- </speedtax>
34
- </children>
35
- </config>
36
- </children>
37
- </system>
38
- </children>
39
- </admin>
40
- </resources>
41
- </acl>
42
- <menu>
43
- <speedtax translate="title" module="speedtax">
44
- <title>SalesTax</title>
45
- <sort_order>900</sort_order>
46
- <children>
47
- <!-- Core -->
48
- <config translate="title" module="speedtax">
49
- <title>SalesTax Config</title>
50
- <sort_order>10</sort_order>
51
- <action>adminhtml/system_config/edit/section/speedtax</action>
52
- </config>
53
- <invoice_index translate="title" module="speedtax">
54
- <title>All Invoices</title>
55
- <sort_order>100</sort_order>
56
- <action>speedtax_adminhtml/invoice/index</action>
57
- </invoice_index>
58
- <invoice_failsafe_index translate="title" module="speedtax">
59
- <title>Failsafe Invoices</title>
60
- <sort_order>200</sort_order>
61
- <action>speedtax_adminhtml/invoice/failsafeIndex</action>
62
- </invoice_failsafe_index>
63
- <invoice_ratevalidation_index translate="title" module="speedtax">
64
- <title>Failsafe Rate Verification</title>
65
- <sort_order>300</sort_order>
66
- <action>speedtax_adminhtml/invoice/rateVerificationIndex</action>
67
- </invoice_ratevalidation_index>
68
- </children>
69
- </speedtax>
70
- </menu>
71
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ *
13
+ -->
14
+ <config>
15
+ <acl>
16
+ <resources>
17
+ <admin>
18
+ <children>
19
+ <speedtax translate="title" module="speedtax">
20
+ <title>SalesTax</title>
21
+ <children>
22
+ <invoice>
23
+ <title>Manage Invoices</title>
24
+ </invoice>
25
+ </children>
26
+ </speedtax>
27
+ <system>
28
+ <children>
29
+ <config>
30
+ <children>
31
+ <speedtax translate="title" module="speedtax">
32
+ <title>SpeedTax Configuration</title>
33
+ </speedtax>
34
+ </children>
35
+ </config>
36
+ </children>
37
+ </system>
38
+ </children>
39
+ </admin>
40
+ </resources>
41
+ </acl>
42
+ <menu>
43
+ <speedtax translate="title" module="speedtax">
44
+ <title>SalesTax</title>
45
+ <sort_order>900</sort_order>
46
+ <children>
47
+ <!-- Core -->
48
+ <config translate="title" module="speedtax">
49
+ <title>SalesTax Config</title>
50
+ <sort_order>10</sort_order>
51
+ <action>adminhtml/system_config/edit/section/speedtax</action>
52
+ </config>
53
+ <invoice_index translate="title" module="speedtax">
54
+ <title>All Invoices</title>
55
+ <sort_order>100</sort_order>
56
+ <action>speedtax_adminhtml/invoice/index</action>
57
+ </invoice_index>
58
+ <invoice_failsafe_index translate="title" module="speedtax">
59
+ <title>Failsafe Invoices</title>
60
+ <sort_order>200</sort_order>
61
+ <action>speedtax_adminhtml/invoice/failsafeIndex</action>
62
+ </invoice_failsafe_index>
63
+ <invoice_ratevalidation_index translate="title" module="speedtax">
64
+ <title>Failsafe Rate Verification</title>
65
+ <sort_order>300</sort_order>
66
+ <action>speedtax_adminhtml/invoice/rateVerificationIndex</action>
67
+ </invoice_ratevalidation_index>
68
+ </children>
69
+ </speedtax>
70
+ </menu>
71
+ </config>
app/code/community/Harapartners/SpeedTax/etc/config.xml CHANGED
@@ -1,167 +1,170 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
- -->
15
- <config>
16
- <modules>
17
- <Harapartners_SpeedTax>
18
- <version>4.1.0</version>
19
- </Harapartners_SpeedTax>
20
- </modules>
21
- <global>
22
- <blocks>
23
- <speedtax>
24
- <class>Harapartners_SpeedTax_Block</class>
25
- </speedtax>
26
- </blocks>
27
- <models>
28
- <speedtax>
29
- <class>Harapartners_SpeedTax_Model</class>
30
- <resourceModel>speedtax_resource</resourceModel>
31
- </speedtax>
32
- <speedtax_resource>
33
- <class>Harapartners_SpeedTax_Model_Resource</class>
34
- <entities>
35
- <failsafe_calculation_rate>
36
- <table>speedtax_failsafe_calculation_rate</table>
37
- </failsafe_calculation_rate>
38
- </entities>
39
- </speedtax_resource>
40
- <tax>
41
- <rewrite>
42
- <sales_total_quote_tax>Harapartners_SpeedTax_Model_Rewrite_Tax_Sales_Total_Quote_Tax</sales_total_quote_tax>
43
- </rewrite>
44
- </tax>
45
- </models>
46
- <helpers>
47
- <speedtax>
48
- <class>Harapartners_SpeedTax_Helper</class>
49
- </speedtax>
50
- </helpers>
51
- <resources>
52
- <speedtax_setup>
53
- <setup>
54
- <module>Harapartners_SpeedTax</module>
55
- </setup>
56
- <connection>
57
- <use>core_setup</use>
58
- </connection>
59
- </speedtax_setup>
60
- </resources>
61
- <events>
62
- <!-- Checkout process, (failsafe calculation can be enabled) -->
63
- <sales_order_save_before>
64
- <observers>
65
- <speedtax>
66
- <type>singleton</type>
67
- <class>speedtax/observer</class>
68
- <method>saleOrderSaveBefore</method>
69
- </speedtax>
70
- </observers>
71
- </sales_order_save_before>
72
-
73
- <!-- Post invoices to SpeedTax (failsafe delayed invoice post can be enabled) -->
74
- <sales_order_invoice_pay>
75
- <observers>
76
- <speedtax>
77
- <type>singleton</type>
78
- <class>speedtax/observer</class>
79
- <method>saleOrderInvoicePay</method>
80
- </speedtax>
81
- </observers>
82
- </sales_order_invoice_pay>
83
-
84
- <!-- Post credit memo to SpeedTax (admin only function, no failsafe needed) -->
85
- <sales_order_creditmemo_refund>
86
- <observers>
87
- <speedtax>
88
- <type>singleton</type>
89
- <class>speedtax/observer</class>
90
- <method>salesOrderCreditmemoRefund</method>
91
- </speedtax>
92
- </observers>
93
- </sales_order_creditmemo_refund>
94
-
95
- <!-- Upon order cancel/edit, credit memo must be created manually for existing invoices, SpeedTax invoices will NOT be voided -->
96
- <!--order_cancel_after>
97
- <observers>
98
- <speedtax>
99
- <type>singleton</type>
100
- <class>speedtax/observer</class>
101
- <method>orderCancelAfter</method>
102
- </speedtax>
103
- </observers>
104
- </order_cancel_after-->
105
- </events>
106
- </global>
107
- <adminhtml>
108
- <events>
109
- <controller_action_layout_generate_blocks_after>
110
- <!-- Global layout modifications -->
111
- <!-- Prepare and render important admin panel messages -->
112
- <observers>
113
- <speedtax_adminhtml_only_layout_generate_blocks_after>
114
- <type>singleton</type>
115
- <class>speedtax/observer</class>
116
- <method>adminhtmlOnlyLayoutGenerateBlocksAfter</method>
117
- </speedtax_adminhtml_only_layout_generate_blocks_after>
118
- </observers>
119
- </controller_action_layout_generate_blocks_after>
120
- </events>
121
- </adminhtml>
122
- <admin>
123
- <routers>
124
- <speedtax_adminhtml>
125
- <use>admin</use>
126
- <args>
127
- <module>Harapartners_SpeedTax_Adminhtml</module>
128
- <frontName>speedtax_adminhtml</frontName>
129
- </args>
130
- </speedtax_adminhtml>
131
- </routers>
132
- </admin>
133
- <crontab>
134
- <jobs>
135
- <speedtax_batch_post_failsafe_invoice>
136
- <schedule>
137
- <cron_expr>23 * * * *</cron_expr>
138
- </schedule>
139
- <run>
140
- <model>speedtax/observer::batchPostFailsafeInvoice</model>
141
- </run>
142
- </speedtax_batch_post_failsafe_invoice>
143
- </jobs>
144
- </crontab>
145
- <default>
146
- <speedtax>
147
- <speedtax>
148
- <action>0</action>
149
- <url>https://www.speedtax.com/</url>
150
- <shipping_sku>Shipping</shipping_sku>
151
- <adjustment_positive_sku>Adjustment</adjustment_positive_sku>
152
- <adjustment_negative_sku>Adjustment</adjustment_negative_sku>
153
- <sales_person_code>Magento</sales_person_code>
154
- <error_full_stop>1</error_full_stop>
155
- <error_frontend_action>2</error_frontend_action>
156
- <error_frontend_message>Unfortunately, we could not calculate tax for your order. Please try again with a different address or contact us to complete your order.</error_frontend_message>
157
- <error_backend_message>There was an error getting tax rates from Speedtax. Please see the error log for details.</error_backend_message>
158
- <error_notification_toolbar>1</error_notification_toolbar>
159
- <onepage_normalize_message>Your shipping address has been modified during our validation process. Please confirm the address to the right is accurate.</onepage_normalize_message>
160
- </speedtax>
161
- <failsafe>
162
- <is_enabled>1</is_enabled>
163
- <is_auto_post_failsafe_invoice>1</is_auto_post_failsafe_invoice>
164
- </failsafe>
165
- </speedtax>
166
- </default>
 
 
 
167
  </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+ -->
15
+ <config>
16
+ <modules>
17
+ <Harapartners_SpeedTax>
18
+ <version>4.1.1</version>
19
+ </Harapartners_SpeedTax>
20
+ </modules>
21
+ <global>
22
+ <blocks>
23
+ <speedtax>
24
+ <class>Harapartners_SpeedTax_Block</class>
25
+ </speedtax>
26
+ </blocks>
27
+ <models>
28
+ <speedtax>
29
+ <class>Harapartners_SpeedTax_Model</class>
30
+ <resourceModel>speedtax_resource</resourceModel>
31
+ </speedtax>
32
+ <speedtax_resource>
33
+ <class>Harapartners_SpeedTax_Model_Resource</class>
34
+ <entities>
35
+ <failsafe_calculation_rate>
36
+ <table>speedtax_failsafe_calculation_rate</table>
37
+ </failsafe_calculation_rate>
38
+ </entities>
39
+ </speedtax_resource>
40
+ <tax>
41
+ <rewrite>
42
+ <sales_total_quote_tax>Harapartners_SpeedTax_Model_Rewrite_Tax_Sales_Total_Quote_Tax</sales_total_quote_tax>
43
+ </rewrite>
44
+ </tax>
45
+ </models>
46
+ <helpers>
47
+ <speedtax>
48
+ <class>Harapartners_SpeedTax_Helper</class>
49
+ </speedtax>
50
+ </helpers>
51
+ <resources>
52
+ <speedtax_setup>
53
+ <setup>
54
+ <module>Harapartners_SpeedTax</module>
55
+ </setup>
56
+ <connection>
57
+ <use>core_setup</use>
58
+ </connection>
59
+ </speedtax_setup>
60
+ </resources>
61
+ <events>
62
+ <!-- Checkout process, (failsafe calculation can be enabled) -->
63
+ <sales_order_save_before>
64
+ <observers>
65
+ <speedtax>
66
+ <type>singleton</type>
67
+ <class>speedtax/observer</class>
68
+ <method>saleOrderSaveBefore</method>
69
+ </speedtax>
70
+ </observers>
71
+ </sales_order_save_before>
72
+
73
+ <!-- Post invoices to SpeedTax (failsafe delayed invoice post can be enabled) -->
74
+ <sales_order_invoice_pay>
75
+ <observers>
76
+ <speedtax>
77
+ <type>singleton</type>
78
+ <class>speedtax/observer</class>
79
+ <method>saleOrderInvoicePay</method>
80
+ </speedtax>
81
+ </observers>
82
+ </sales_order_invoice_pay>
83
+
84
+ <!-- Post credit memo to SpeedTax (admin only function, no failsafe needed) -->
85
+ <sales_order_creditmemo_refund>
86
+ <observers>
87
+ <speedtax>
88
+ <type>singleton</type>
89
+ <class>speedtax/observer</class>
90
+ <method>salesOrderCreditmemoRefund</method>
91
+ </speedtax>
92
+ </observers>
93
+ </sales_order_creditmemo_refund>
94
+
95
+ <!-- Upon order cancel/edit, credit memo must be created manually for existing invoices, SpeedTax invoices will NOT be voided -->
96
+ <!--order_cancel_after>
97
+ <observers>
98
+ <speedtax>
99
+ <type>singleton</type>
100
+ <class>speedtax/observer</class>
101
+ <method>orderCancelAfter</method>
102
+ </speedtax>
103
+ </observers>
104
+ </order_cancel_after-->
105
+ </events>
106
+ </global>
107
+ <adminhtml>
108
+ <events>
109
+ <controller_action_layout_generate_blocks_after>
110
+ <!-- Global layout modifications -->
111
+ <!-- Prepare and render important admin panel messages -->
112
+ <observers>
113
+ <speedtax_adminhtml_only_layout_generate_blocks_after>
114
+ <type>singleton</type>
115
+ <class>speedtax/observer</class>
116
+ <method>adminhtmlOnlyLayoutGenerateBlocksAfter</method>
117
+ </speedtax_adminhtml_only_layout_generate_blocks_after>
118
+ </observers>
119
+ </controller_action_layout_generate_blocks_after>
120
+ </events>
121
+ </adminhtml>
122
+ <admin>
123
+ <routers>
124
+ <speedtax_adminhtml>
125
+ <use>admin</use>
126
+ <args>
127
+ <module>Harapartners_SpeedTax_Adminhtml</module>
128
+ <frontName>speedtax_adminhtml</frontName>
129
+ </args>
130
+ </speedtax_adminhtml>
131
+ </routers>
132
+ </admin>
133
+ <crontab>
134
+ <jobs>
135
+ <speedtax_batch_post_failsafe_invoice>
136
+ <schedule>
137
+ <cron_expr>23 * * * *</cron_expr>
138
+ </schedule>
139
+ <run>
140
+ <model>speedtax/observer::batchPostFailsafeInvoice</model>
141
+ </run>
142
+ </speedtax_batch_post_failsafe_invoice>
143
+ </jobs>
144
+ </crontab>
145
+ <default>
146
+ <speedtax>
147
+ <speedtax>
148
+ <action>0</action>
149
+ <is_tax_shipping>0</is_tax_shipping>
150
+ <shipping_tax_code>Shipping</shipping_tax_code>
151
+ <is_use_product_tax_class>0</is_use_product_tax_class>
152
+ <url>https://www.speedtax.com/</url>
153
+ <shipping_sku>Shipping</shipping_sku>
154
+ <adjustment_positive_sku>Adjustment</adjustment_positive_sku>
155
+ <adjustment_negative_sku>Adjustment</adjustment_negative_sku>
156
+ <sales_person_code>Magento</sales_person_code>
157
+ <error_full_stop>1</error_full_stop>
158
+ <error_frontend_action>2</error_frontend_action>
159
+ <error_frontend_message>Unfortunately, we could not calculate tax for your order. Please try again with a different address or contact us to complete your order.</error_frontend_message>
160
+ <error_backend_message>There was an error getting tax rates from Speedtax. Please see the error log for details.</error_backend_message>
161
+ <error_notification_toolbar>1</error_notification_toolbar>
162
+ <onepage_normalize_message>Your shipping address has been modified during our validation process. Please confirm the address to the right is accurate.</onepage_normalize_message>
163
+ </speedtax>
164
+ <failsafe>
165
+ <is_enabled>1</is_enabled>
166
+ <is_auto_post_failsafe_invoice>1</is_auto_post_failsafe_invoice>
167
+ </failsafe>
168
+ </speedtax>
169
+ </default>
170
  </config>
app/code/community/Harapartners/SpeedTax/etc/system.xml CHANGED
@@ -1,218 +1,299 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
- -->
15
- <config>
16
- <sections>
17
- <speedtax translate="label" module="speedtax">
18
- <class>speedtax-section</class>
19
- <label><![CDATA[SalesTax.com by <br/><img src="https://www.harapartners.com/skin/frontend/enterprise/harapartners/images/hp/HP2.0Logo.png" alt="HaraPartners" width="100" height="20">]]></label>
20
- <header_css>speedtax-header</header_css>
21
- <tab>sales</tab>
22
- <sort_order>304</sort_order>
23
- <show_in_default>1</show_in_default>
24
- <show_in_website>1</show_in_website>
25
- <show_in_store>0</show_in_store>
26
- <groups>
27
- <signup>
28
- <label>Sign up for SalesTax.com</label>
29
- <comment><![CDATA[
30
- <p class="switcher">
31
- Sign up for a <a href="http://harapartners.com/solutions/salestax/30daytrial" target="_blank" style="color: #00C3FF;">Free 30 Day Trial</a>.<br/>
32
- <a href="http://www.harapartners.com/solutions/salestax/signup" target="_blank" style="color: #00C3FF;">Sign up for SalesTax.com to process your Sales Taxes.</a>.<br/>
33
- Call with questions at <b>646-663-5672</b> or find more information under <a href="http://www.harapartners.com/salestax" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax</a>.
34
- </p>
35
- ]]></comment>
36
- <sort_order>0</sort_order>
37
- <show_in_default>1</show_in_default>
38
- <show_in_website>1</show_in_website>
39
- <show_in_store>0</show_in_store>
40
- <expanded>1</expanded>
41
- </signup>
42
- <speedtax>
43
- <label>SalesTax.com Configuration</label>
44
- <sort_order>100</sort_order>
45
- <show_in_default>1</show_in_default>
46
- <show_in_website>1</show_in_website>
47
- <show_in_store>0</show_in_store>
48
- <fields>
49
- <is_enabled translate="label">
50
- <label>Status</label>
51
- <comment>If the Status is set to "Disable", default Magento tax calculations will be used.</comment>
52
- <frontend_type>select</frontend_type>
53
- <source_model>adminhtml/system_config_source_enabledisable</source_model>
54
- <sort_order>100</sort_order>
55
- <show_in_default>1</show_in_default>
56
- <show_in_website>1</show_in_website>
57
- <show_in_store>0</show_in_store>
58
- </is_enabled>
59
- <username translate="label">
60
- <label>Username</label>
61
- <comment>Should have been provided in your sign up email.</comment>
62
- <frontend_type>text</frontend_type>
63
- <sort_order>110</sort_order>
64
- <show_in_default>1</show_in_default>
65
- <show_in_website>1</show_in_website>
66
- <show_in_store>0</show_in_store>
67
- <validate>required-entry</validate>
68
- </username>
69
- <password translate="label">
70
- <label>Password</label>
71
- <comment>Should have been provided in your sign up email.</comment>
72
- <frontend_type>obscure</frontend_type>
73
- <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
74
- <sort_order>115</sort_order>
75
- <show_in_default>1</show_in_default>
76
- <show_in_website>1</show_in_website>
77
- <show_in_store>0</show_in_store>
78
- <validate>required-entry</validate>
79
- </password>
80
- <company_code translate="label">
81
- <label>Company Code</label>
82
- <comment>Should have been provided in your sign up email.</comment>
83
- <frontend_type>text</frontend_type>
84
- <sort_order>120</sort_order>
85
- <show_in_default>1</show_in_default>
86
- <show_in_website>1</show_in_website>
87
- <show_in_store>0</show_in_store>
88
- <validate>required-entry</validate>
89
- </company_code>
90
- <is_test_mode translate="label">
91
- <label>Test Mode</label>
92
- <comment><![CDATA[Switching between test and production accounts.<br/> Please make sure to select the correct account with your credentials.]]></comment>
93
- <frontend_type>select</frontend_type>
94
- <source_model>adminhtml/system_config_source_yesno</source_model>
95
- <sort_order>125</sort_order>
96
- <show_in_default>1</show_in_default>
97
- <show_in_website>1</show_in_website>
98
- <show_in_store>0</show_in_store>
99
- </is_test_mode>
100
- <authentication_wizard translate="button_label">
101
- <label></label>
102
- <comment><![CDATA[Please <b style="color: red;">save</b> the configuration after validating your login credentials.]]></comment>
103
- <button_label>Validate login credentials</button_label>
104
- <frontend_model>speedtax/adminhtml_system_config_form_field_authentication</frontend_model>
105
- <sort_order>150</sort_order>
106
- <show_in_default>1</show_in_default>
107
- <show_in_website>1</show_in_website>
108
- <show_in_store>0</show_in_store>
109
- </authentication_wizard>
110
- <tax_shipping translate="label">
111
- <label>Calculate Taxes On Shipping</label>
112
- <comment>This will send a line item for SHIPPING to be taxed.</comment>
113
- <frontend_type>select</frontend_type>
114
- <source_model>adminhtml/system_config_source_enabledisable</source_model>
115
- <sort_order>311</sort_order>
116
- <show_in_default>1</show_in_default>
117
- <show_in_website>1</show_in_website>
118
- <show_in_store>0</show_in_store>
119
- </tax_shipping>
120
- <origins translate="label">
121
- <label>Nexus</label>
122
- <comment><![CDATA[Multiple-select. Select <b style="color: red;">all states</b> where you have nexus and want sales taxes to be used for.]]></comment>
123
- <frontend_type>multiselect</frontend_type>
124
- <sort_order>350</sort_order>
125
- <source_model>speedtax/source_usregions</source_model>
126
- <show_in_default>1</show_in_default>
127
- <show_in_website>1</show_in_website>
128
- <show_in_store>0</show_in_store>
129
- <validate>required-entry</validate>
130
- </origins>
131
- <is_debug_transaction translate="label">
132
- <label>Debug transactions</label>
133
- <comment><![CDATA[If "Yes", transactions will be logged.]]></comment>
134
- <frontend_type>select</frontend_type>
135
- <source_model>adminhtml/system_config_source_yesno</source_model>
136
- <sort_order>900</sort_order>
137
- <show_in_default>1</show_in_default>
138
- <show_in_website>1</show_in_website>
139
- <show_in_store>0</show_in_store>
140
- </is_debug_transaction>
141
- </fields>
142
- </speedtax>
143
- <failsafe>
144
- <label>Fail Safe Configuration</label>
145
- <comment><![CDATA[
146
- <p class="switcher">
147
- Fail safe logic provides an additional layer of robustness to the tax integration.<br/>
148
- This mechanism allows the customer to complete checkout in case the SalesTax service is unreachable.<br/>
149
- Magento processes supported for fail safe: checkout, place order and invoice pay.<br/>
150
- 1) During tax calculation, state level tax rates for default taxable goods are stored in Magento in case of a future failure.<br/>
151
- 2) If the invoice cannot be posted to SalesTax, the invoice processing workflow can continue. The problematic invoices can be posted to SalesTax later.
152
- </p>
153
- ]]></comment>
154
- <sort_order>200</sort_order>
155
- <show_in_default>1</show_in_default>
156
- <show_in_website>1</show_in_website>
157
- <show_in_store>0</show_in_store>
158
- <fields>
159
- <is_enabled translate="label">
160
- <label>Is Enabled</label>
161
- <comment><![CDATA[]]></comment>
162
- <frontend_type>select</frontend_type>
163
- <source_model>adminhtml/system_config_source_yesno</source_model>
164
- <sort_order>100</sort_order>
165
- <show_in_default>1</show_in_default>
166
- <show_in_website>1</show_in_website>
167
- <show_in_store>0</show_in_store>
168
- </is_enabled>
169
- <is_auto_post_failsafe_invoice translate="label">
170
- <label>Auto Post Fail Safe Invoice</label>
171
- <comment><![CDATA[
172
- If "Yes", fail safe invoice can be posted to SalesTax automatically.<br/>
173
- Please make sure Magento cron job is running.
174
- ]]></comment>
175
- <frontend_type>select</frontend_type>
176
- <source_model>adminhtml/system_config_source_yesno</source_model>
177
- <sort_order>200</sort_order>
178
- <show_in_default>1</show_in_default>
179
- <show_in_website>1</show_in_website>
180
- <show_in_store>0</show_in_store>
181
- </is_auto_post_failsafe_invoice>
182
- </fields>
183
- </failsafe>
184
- <help_extra>
185
- <label>SalesTax.com Help</label>
186
- <comment><![CDATA[
187
- <p class="switcher">
188
- Get help with configuring and setting up the SalesTax.com module at <a href="http://www.harapartners.com/salestax/help#configuration" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax/help#configuration</a>.<br/>
189
- Find more information at <a href="http://www.harapartners.com/salestax/help" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax/help</a>.<br/>
190
- Learn more about the SalesTax.com solution, additional features, updates and help at <a href="http://www.harapartners.com/salestax" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax</a>.
191
- </p>
192
- ]]></comment>
193
- <sort_order>300</sort_order>
194
- <show_in_default>1</show_in_default>
195
- <show_in_website>1</show_in_website>
196
- <show_in_store>0</show_in_store>
197
- <expanded>1</expanded>
198
- </help_extra>
199
- </groups>
200
- </speedtax>
201
- <shipping>
202
- <groups>
203
- <origin>
204
- <fields>
205
- <street translate="label">
206
- <label><![CDATA[Number & Street]]></label>
207
- <frontend_type>text</frontend_type>
208
- <sort_order>99</sort_order>
209
- <show_in_default>1</show_in_default>
210
- <show_in_website>1</show_in_website>
211
- <show_in_store>0</show_in_store>
212
- </street>
213
- </fields>
214
- </origin>
215
- </groups>
216
- </shipping>
217
- </sections>
218
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+ -->
15
+ <config>
16
+ <sections>
17
+ <speedtax translate="label" module="speedtax">
18
+ <class>speedtax-section</class>
19
+ <label><![CDATA[SalesTax.com by <br/><img src="https://www.harapartners.com/skin/frontend/enterprise/harapartners/images/hp/HP2.0Logo.png" alt="HaraPartners" width="100" height="20">]]></label>
20
+ <header_css>speedtax-header</header_css>
21
+ <tab>sales</tab>
22
+ <sort_order>304</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <groups>
27
+ <signup>
28
+ <label>Sign up for SalesTax.com</label>
29
+ <comment><![CDATA[
30
+ <p class="switcher">
31
+ Sign up for a <a href="http://harapartners.com/solutions/salestax/30daytrial" target="_blank" style="color: #00C3FF;">Free 30 Day Trial</a>.<br/>
32
+ <a href="http://www.harapartners.com/solutions/salestax/signup" target="_blank" style="color: #00C3FF;">Sign up for SalesTax.com to process your Sales Taxes.</a>.<br/>
33
+ Call with questions at <b>646-663-5672</b> or find more information under <a href="http://www.harapartners.com/salestax" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax</a>.
34
+ </p>
35
+ ]]></comment>
36
+ <sort_order>0</sort_order>
37
+ <show_in_default>1</show_in_default>
38
+ <show_in_website>1</show_in_website>
39
+ <show_in_store>0</show_in_store>
40
+ <expanded>1</expanded>
41
+ </signup>
42
+ <speedtax>
43
+ <label>SalesTax.com Configuration</label>
44
+ <sort_order>100</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ <fields>
49
+ <is_enabled translate="label">
50
+ <label>Status</label>
51
+ <comment><![CDATA[If "No", default Magento tax calculations will be used.]]></comment>
52
+ <frontend_type>select</frontend_type>
53
+ <source_model>adminhtml/system_config_source_yesno</source_model>
54
+ <sort_order>100</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </is_enabled>
59
+ <username translate="label">
60
+ <label>Username</label>
61
+ <comment><![CDATA[Please check the credentials in the sign up email.]]></comment>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>110</sort_order>
64
+ <show_in_default>1</show_in_default>
65
+ <show_in_website>1</show_in_website>
66
+ <show_in_store>0</show_in_store>
67
+ <validate>required-entry</validate>
68
+ </username>
69
+ <password translate="label">
70
+ <label>Password</label>
71
+ <comment><![CDATA[Please check the credentials in the sign up email.]]></comment>
72
+ <frontend_type>obscure</frontend_type>
73
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
74
+ <sort_order>115</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>0</show_in_store>
78
+ <validate>required-entry</validate>
79
+ </password>
80
+ <company_code translate="label">
81
+ <label>Company Code</label>
82
+ <comment><![CDATA[Please check the credentials in the sign up email.]]></comment>
83
+ <frontend_type>text</frontend_type>
84
+ <sort_order>120</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ <validate>required-entry</validate>
89
+ </company_code>
90
+ <is_test_mode translate="label">
91
+ <label>Test Mode</label>
92
+ <comment><![CDATA[
93
+ Switching between test and production accounts.<br/>
94
+ Please make sure to select the correct account with your credentials.]]>
95
+ </comment>
96
+ <frontend_type>select</frontend_type>
97
+ <source_model>adminhtml/system_config_source_yesno</source_model>
98
+ <sort_order>125</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>0</show_in_store>
102
+ </is_test_mode>
103
+ <authentication_wizard translate="button_label">
104
+ <label></label>
105
+ <comment><![CDATA[
106
+ Please <b style="color: red;">save</b> the configuration after validating your login credentials.
107
+ ]]></comment>
108
+ <button_label>Validate login credentials</button_label>
109
+ <frontend_model>speedtax/adminhtml_system_config_form_field_authentication</frontend_model>
110
+ <sort_order>150</sort_order>
111
+ <show_in_default>1</show_in_default>
112
+ <show_in_website>1</show_in_website>
113
+ <show_in_store>0</show_in_store>
114
+ </authentication_wizard>
115
+ <is_tax_shipping translate="label">
116
+ <label>Calculate Taxes On Shipping/Handling Cost</label>
117
+ <comment><![CDATA[
118
+ If "Yes", a separate shipping line item will be used to calculate the shipping tax.<br/>
119
+ The tax code of this line item can be specified below.
120
+ ]]></comment>
121
+ <frontend_type>select</frontend_type>
122
+ <source_model>adminhtml/system_config_source_yesno</source_model>
123
+ <sort_order>300</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>0</show_in_store>
127
+ </is_tax_shipping>
128
+ <shipping_tax_code translate="label">
129
+ <label>Shipping Tax Code</label>
130
+ <comment><![CDATA[Default value: "Shipping"]]></comment>
131
+ <frontend_type>text</frontend_type>
132
+ <sort_order>310</sort_order>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>0</show_in_store>
136
+ </shipping_tax_code>
137
+ <is_use_product_tax_class translate="label">
138
+ <label>Use Product Tax Class as Tax Code</label>
139
+ <comment><![CDATA[
140
+ Default value: "No", where SKU will be used for product tax code.<br/>
141
+ If "Yes", product tax class name will be used instead.
142
+ ]]></comment>
143
+ <frontend_type>select</frontend_type>
144
+ <source_model>adminhtml/system_config_source_yesno</source_model>
145
+ <sort_order>320</sort_order>
146
+ <show_in_default>1</show_in_default>
147
+ <show_in_website>1</show_in_website>
148
+ <show_in_store>0</show_in_store>
149
+ </is_use_product_tax_class>
150
+ <origins translate="label">
151
+ <label>Nexus</label>
152
+ <comment><![CDATA[
153
+ Multi-select. Select <b style="color: red;">all states</b> where you have nexus and want sales taxes to be used for.
154
+ ]]></comment>
155
+ <frontend_type>multiselect</frontend_type>
156
+ <sort_order>350</sort_order>
157
+ <source_model>speedtax/source_usregions</source_model>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>0</show_in_store>
161
+ <validate>required-entry</validate>
162
+ </origins>
163
+ <tax_exempt_customer_group translate="label">
164
+ <label>Tax Exempt Customer Group</label>
165
+ <comment><![CDATA[
166
+ Multi-select.
167
+ ]]></comment>
168
+ <frontend_type>multiselect</frontend_type>
169
+ <source_model>adminhtml/system_config_source_customer_group</source_model>
170
+ <sort_order>400</sort_order>
171
+ <show_in_default>1</show_in_default>
172
+ <show_in_website>1</show_in_website>
173
+ <show_in_store>0</show_in_store>
174
+ <can_be_empty>1</can_be_empty>
175
+ </tax_exempt_customer_group>
176
+ <is_debug_transaction translate="label">
177
+ <label>Debug Transactions</label>
178
+ <comment><![CDATA[If "Yes", transactions will be logged.]]></comment>
179
+ <frontend_type>select</frontend_type>
180
+ <source_model>adminhtml/system_config_source_yesno</source_model>
181
+ <sort_order>900</sort_order>
182
+ <show_in_default>1</show_in_default>
183
+ <show_in_website>1</show_in_website>
184
+ <show_in_store>0</show_in_store>
185
+ </is_debug_transaction>
186
+ </fields>
187
+ </speedtax>
188
+ <tax_by_billing>
189
+ <label>Tax By Billing Address Exceptions</label>
190
+ <sort_order>200</sort_order>
191
+ <show_in_default>1</show_in_default>
192
+ <show_in_website>1</show_in_website>
193
+ <show_in_store>0</show_in_store>
194
+ <comment><![CDATA[
195
+ <p class="switcher">
196
+ Exceptions can be created to allow tax calculated by billing address (instead of by shipping address), if:<br/>
197
+ 1) The order is billed from a state listed in the "Billing Orgin States" section; and<br/>
198
+ 2) The order is <b>NOT</b> shipped to any state listed in the "Billing Orgin States" section.
199
+ </p>
200
+ ]]></comment>
201
+ <fields>
202
+ <is_enabled translate="label">
203
+ <label>Is Enabled</label>
204
+ <comment><![CDATA[]]></comment>
205
+ <frontend_type>select</frontend_type>
206
+ <source_model>adminhtml/system_config_source_yesno</source_model>
207
+ <sort_order>100</sort_order>
208
+ <show_in_default>1</show_in_default>
209
+ <show_in_website>1</show_in_website>
210
+ <show_in_store>0</show_in_store>
211
+ </is_enabled>
212
+ <billing_origins translate="label">
213
+ <label>Billing Orgin States</label>
214
+ <comment><![CDATA[Multiple-select. Please make sure the selected state(s) is in the list of your nexus.]]></comment>
215
+ <frontend_type>multiselect</frontend_type>
216
+ <sort_order>200</sort_order>
217
+ <source_model>speedtax/source_usregions</source_model>
218
+ <show_in_default>1</show_in_default>
219
+ <show_in_website>1</show_in_website>
220
+ <show_in_store>0</show_in_store>
221
+ </billing_origins>
222
+ </fields>
223
+ </tax_by_billing>
224
+ <failsafe>
225
+ <label>Fail Safe Configuration</label>
226
+ <comment><![CDATA[
227
+ <p class="switcher">
228
+ Fail safe logic provides an additional layer of robustness to the tax integration.<br/>
229
+ This mechanism allows the customer to complete checkout in case the SalesTax service is unreachable.<br/>
230
+ Magento processes supported for fail safe: checkout, place order and invoice pay.<br/>
231
+ 1) During tax calculation, state level tax rates for default taxable goods are stored in Magento in case of a future failure.<br/>
232
+ 2) If the invoice cannot be posted to SalesTax, the invoice processing workflow can continue. The problematic invoices can be posted to SalesTax later.
233
+ </p>
234
+ ]]></comment>
235
+ <sort_order>200</sort_order>
236
+ <show_in_default>1</show_in_default>
237
+ <show_in_website>1</show_in_website>
238
+ <show_in_store>0</show_in_store>
239
+ <fields>
240
+ <is_enabled translate="label">
241
+ <label>Is Enabled</label>
242
+ <comment><![CDATA[]]></comment>
243
+ <frontend_type>select</frontend_type>
244
+ <source_model>adminhtml/system_config_source_yesno</source_model>
245
+ <sort_order>100</sort_order>
246
+ <show_in_default>1</show_in_default>
247
+ <show_in_website>1</show_in_website>
248
+ <show_in_store>0</show_in_store>
249
+ </is_enabled>
250
+ <is_auto_post_failsafe_invoice translate="label">
251
+ <label>Auto Post Fail Safe Invoice</label>
252
+ <comment><![CDATA[
253
+ If "Yes", fail safe invoice can be posted to SalesTax automatically.<br/>
254
+ Please make sure Magento cron job is running.
255
+ ]]></comment>
256
+ <frontend_type>select</frontend_type>
257
+ <source_model>adminhtml/system_config_source_yesno</source_model>
258
+ <sort_order>200</sort_order>
259
+ <show_in_default>1</show_in_default>
260
+ <show_in_website>1</show_in_website>
261
+ <show_in_store>0</show_in_store>
262
+ </is_auto_post_failsafe_invoice>
263
+ </fields>
264
+ </failsafe>
265
+ <help_extra>
266
+ <label>SalesTax.com Help</label>
267
+ <comment><![CDATA[
268
+ <p class="switcher">
269
+ Get help with configuring and setting up the SalesTax.com module at <a href="http://www.harapartners.com/salestax/help#configuration" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax/help#configuration</a>.<br/>
270
+ Find more information at <a href="http://www.harapartners.com/salestax/help" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax/help</a>.<br/>
271
+ Learn more about the SalesTax.com solution, additional features, updates and help at <a href="http://www.harapartners.com/salestax" target="_blank" style="color: #00C3FF;">http://www.harapartners.com/salestax</a>.
272
+ </p>
273
+ ]]></comment>
274
+ <sort_order>300</sort_order>
275
+ <show_in_default>1</show_in_default>
276
+ <show_in_website>1</show_in_website>
277
+ <show_in_store>0</show_in_store>
278
+ <expanded>1</expanded>
279
+ </help_extra>
280
+ </groups>
281
+ </speedtax>
282
+ <shipping>
283
+ <groups>
284
+ <origin>
285
+ <fields>
286
+ <street translate="label">
287
+ <label><![CDATA[Number & Street]]></label>
288
+ <frontend_type>text</frontend_type>
289
+ <sort_order>99</sort_order>
290
+ <show_in_default>1</show_in_default>
291
+ <show_in_website>1</show_in_website>
292
+ <show_in_store>0</show_in_store>
293
+ </street>
294
+ </fields>
295
+ </origin>
296
+ </groups>
297
+ </shipping>
298
+ </sections>
299
+ </config>
app/code/community/Harapartners/SpeedTax/sql/speedtax_setup/mysql4-upgrade-3.0.9-3.1.0.php CHANGED
@@ -1,50 +1,50 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- $installer = $this;
14
- $installer->startSetup();
15
-
16
- // ================ Invoice ================ //
17
- $installer->getConnection()->addColumn(
18
- $installer->getTable('sales/invoice'),
19
- "speedtax_invoice_number",
20
- "VARCHAR(255) COMMENT 'SpeedTax Invoice Number'"
21
- );
22
- $installer->getConnection()->addColumn(
23
- $installer->getTable('sales/invoice'),
24
- "speedtax_invoice_status",
25
- "SMALLINT(5) DEFAULT '0' COMMENT 'SpeedTax Invoice Status'"
26
- );
27
- $installer->getConnection()->addColumn(
28
- $installer->getTable('sales/invoice'),
29
- "speedtax_transaction_id",
30
- "VARCHAR(255) COMMENT 'SpeedTax Transaction ID'"
31
- );
32
-
33
- // ================ Credit Memo ================ //
34
- $installer->getConnection()->addColumn(
35
- $installer->getTable('sales/creditmemo'),
36
- "speedtax_invoice_number",
37
- "VARCHAR(255) COMMENT 'SpeedTax Invoice Number'"
38
- );
39
- $installer->getConnection()->addColumn(
40
- $installer->getTable('sales/creditmemo'),
41
- "speedtax_invoice_status",
42
- "SMALLINT(5) DEFAULT '0' COMMENT 'SpeedTax Invoice Status'"
43
- );
44
- $installer->getConnection()->addColumn(
45
- $installer->getTable('sales/creditmemo'),
46
- "speedtax_transaction_id",
47
- "VARCHAR(255) COMMENT 'SpeedTax Transaction ID'"
48
- );
49
-
50
  $installer->endSetup();
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ $installer = $this;
14
+ $installer->startSetup();
15
+
16
+ // ================ Invoice ================ //
17
+ $installer->getConnection()->addColumn(
18
+ $installer->getTable('sales/invoice'),
19
+ "speedtax_invoice_number",
20
+ "VARCHAR(255) COMMENT 'SpeedTax Invoice Number'"
21
+ );
22
+ $installer->getConnection()->addColumn(
23
+ $installer->getTable('sales/invoice'),
24
+ "speedtax_invoice_status",
25
+ "SMALLINT(5) DEFAULT '0' COMMENT 'SpeedTax Invoice Status'"
26
+ );
27
+ $installer->getConnection()->addColumn(
28
+ $installer->getTable('sales/invoice'),
29
+ "speedtax_transaction_id",
30
+ "VARCHAR(255) COMMENT 'SpeedTax Transaction ID'"
31
+ );
32
+
33
+ // ================ Credit Memo ================ //
34
+ $installer->getConnection()->addColumn(
35
+ $installer->getTable('sales/creditmemo'),
36
+ "speedtax_invoice_number",
37
+ "VARCHAR(255) COMMENT 'SpeedTax Invoice Number'"
38
+ );
39
+ $installer->getConnection()->addColumn(
40
+ $installer->getTable('sales/creditmemo'),
41
+ "speedtax_invoice_status",
42
+ "SMALLINT(5) DEFAULT '0' COMMENT 'SpeedTax Invoice Status'"
43
+ );
44
+ $installer->getConnection()->addColumn(
45
+ $installer->getTable('sales/creditmemo'),
46
+ "speedtax_transaction_id",
47
+ "VARCHAR(255) COMMENT 'SpeedTax Transaction ID'"
48
+ );
49
+
50
  $installer->endSetup();
app/code/community/Harapartners/SpeedTax/sql/speedtax_setup/mysql4-upgrade-3.9.9-4.0.0.php CHANGED
@@ -1,101 +1,101 @@
1
- <?php
2
- /*
3
- * NOTICE OF LICENSE
4
- *
5
- * This source file is subject to the End User Software Agreement (EULA).
6
- * It is also available through the world-wide-web at this URL:
7
- * http://www.harapartners.com/license [^]
8
- * If you did not receive a copy of the license and are unable to
9
- * obtain it through the world-wide-web, please send an email
10
- * to eula@harapartners.com so we can send you a copy immediately.
11
- *
12
- */
13
- $installer = $this;
14
- $installer->startSetup();
15
-
16
- // ================= Calculation Table ================= //
17
- $calculationTable = $installer->getConnection()
18
- ->newTable($installer->getTable('speedtax/failsafe_calculation_rate'))
19
- ->addColumn('rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
20
- 'identity' => true,
21
- 'unsigned' => true,
22
- 'nullable' => false,
23
- 'primary' => true,
24
- ), 'Auto Increment Calculation Rate ID')
25
- ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
26
- 'nullable' => true,
27
- ), 'Country ID')
28
- ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
29
- 'nullable' => true,
30
- ), 'Region ID')
31
- ->addColumn('postcode', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
32
- 'nullable' => true,
33
- ), 'Postcode')
34
- ->addColumn('customer_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
35
- 'unsigned' => true,
36
- 'nullable' => true,
37
- ), 'Customer Class ID')
38
- ->addColumn('product_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
39
- 'unsigned' => true,
40
- 'nullable' => true,
41
- ), 'Product Class ID')
42
- ->addColumn('tax_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
43
- 'nullable' => true,
44
- ), 'Tax Rate')
45
- ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
46
- 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
47
- ), 'Created At')
48
- ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
49
- 'nullable' => true,
50
- ), 'Updated At')
51
- ->addIndex(
52
- $installer->getIdxName('speedtax/failsafe_calculation_rate', array('country_id')),
53
- array('country_id'),
54
- array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
55
- )
56
- ->addIndex(
57
- $installer->getIdxName('speedtax/failsafe_calculation_rate', array('region_id')),
58
- array('region_id'),
59
- array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
60
- )
61
- ->addIndex(
62
- $installer->getIdxName('speedtax/failsafe_calculation_rate', array('postcode')),
63
- array('postcode'),
64
- array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
65
- )
66
- ->addIndex(
67
- $installer->getIdxName('speedtax/failsafe_calculation_rate', array('customer_class_id')),
68
- array('customer_class_id'),
69
- array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
70
- )
71
- ->addIndex(
72
- $installer->getIdxName('speedtax/failsafe_calculation_rate', array('product_class_id')),
73
- array('product_class_id'),
74
- array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
75
- )
76
- ->setComment('SpeedTax Failsafe Calculation Rate');
77
- $installer->getConnection()->createTable( $calculationTable );
78
-
79
- $installer->getConnection()->addColumn(
80
- $installer->getTable('sales/order'),
81
- "is_speedtax_failsafe_calculation",
82
- "SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Is SpeedTax Failsafe Calculation'"
83
- );
84
-
85
- $installer->getConnection()->addColumn(
86
- $installer->getTable('sales/invoice'),
87
- "is_speedtax_failsafe_calculation",
88
- "SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Is SpeedTax Failsafe Calculation'"
89
- );
90
- $installer->getConnection()->addColumn(
91
- $installer->getTable('sales/invoice'),
92
- "base_speedtax_tax_amount",
93
- "DECIMAL(12,4) DEFAULT NULL COMMENT 'Base SpeedTax Tax Amount'"
94
- );
95
- $installer->getConnection()->addColumn(
96
- $installer->getTable('sales/invoice'),
97
- "speedtax_tax_amount",
98
- "DECIMAL(12,4) DEFAULT NULL COMMENT 'SpeedTax Tax Amount'"
99
- );
100
-
101
  $installer->endSetup();
1
+ <?php
2
+ /*
3
+ * NOTICE OF LICENSE
4
+ *
5
+ * This source file is subject to the End User Software Agreement (EULA).
6
+ * It is also available through the world-wide-web at this URL:
7
+ * http://www.harapartners.com/license [^]
8
+ * If you did not receive a copy of the license and are unable to
9
+ * obtain it through the world-wide-web, please send an email
10
+ * to eula@harapartners.com so we can send you a copy immediately.
11
+ *
12
+ */
13
+ $installer = $this;
14
+ $installer->startSetup();
15
+
16
+ // ================= Calculation Table ================= //
17
+ $calculationTable = $installer->getConnection()
18
+ ->newTable($installer->getTable('speedtax/failsafe_calculation_rate'))
19
+ ->addColumn('rate_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
20
+ 'identity' => true,
21
+ 'unsigned' => true,
22
+ 'nullable' => false,
23
+ 'primary' => true,
24
+ ), 'Auto Increment Calculation Rate ID')
25
+ ->addColumn('country_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
26
+ 'nullable' => true,
27
+ ), 'Country ID')
28
+ ->addColumn('region_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
29
+ 'nullable' => true,
30
+ ), 'Region ID')
31
+ ->addColumn('postcode', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
32
+ 'nullable' => true,
33
+ ), 'Postcode')
34
+ ->addColumn('customer_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
35
+ 'unsigned' => true,
36
+ 'nullable' => true,
37
+ ), 'Customer Class ID')
38
+ ->addColumn('product_class_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
39
+ 'unsigned' => true,
40
+ 'nullable' => true,
41
+ ), 'Product Class ID')
42
+ ->addColumn('tax_rate', Varien_Db_Ddl_Table::TYPE_DECIMAL, '12,4', array(
43
+ 'nullable' => true,
44
+ ), 'Tax Rate')
45
+ ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
46
+ 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
47
+ ), 'Created At')
48
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
49
+ 'nullable' => true,
50
+ ), 'Updated At')
51
+ ->addIndex(
52
+ $installer->getIdxName('speedtax/failsafe_calculation_rate', array('country_id')),
53
+ array('country_id'),
54
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
55
+ )
56
+ ->addIndex(
57
+ $installer->getIdxName('speedtax/failsafe_calculation_rate', array('region_id')),
58
+ array('region_id'),
59
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
60
+ )
61
+ ->addIndex(
62
+ $installer->getIdxName('speedtax/failsafe_calculation_rate', array('postcode')),
63
+ array('postcode'),
64
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
65
+ )
66
+ ->addIndex(
67
+ $installer->getIdxName('speedtax/failsafe_calculation_rate', array('customer_class_id')),
68
+ array('customer_class_id'),
69
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
70
+ )
71
+ ->addIndex(
72
+ $installer->getIdxName('speedtax/failsafe_calculation_rate', array('product_class_id')),
73
+ array('product_class_id'),
74
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
75
+ )
76
+ ->setComment('SpeedTax Failsafe Calculation Rate');
77
+ $installer->getConnection()->createTable( $calculationTable );
78
+
79
+ $installer->getConnection()->addColumn(
80
+ $installer->getTable('sales/order'),
81
+ "is_speedtax_failsafe_calculation",
82
+ "SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Is SpeedTax Failsafe Calculation'"
83
+ );
84
+
85
+ $installer->getConnection()->addColumn(
86
+ $installer->getTable('sales/invoice'),
87
+ "is_speedtax_failsafe_calculation",
88
+ "SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Is SpeedTax Failsafe Calculation'"
89
+ );
90
+ $installer->getConnection()->addColumn(
91
+ $installer->getTable('sales/invoice'),
92
+ "base_speedtax_tax_amount",
93
+ "DECIMAL(12,4) DEFAULT NULL COMMENT 'Base SpeedTax Tax Amount'"
94
+ );
95
+ $installer->getConnection()->addColumn(
96
+ $installer->getTable('sales/invoice'),
97
+ "speedtax_tax_amount",
98
+ "DECIMAL(12,4) DEFAULT NULL COMMENT 'SpeedTax Tax Amount'"
99
+ );
100
+
101
  $installer->endSetup();
app/etc/modules/Harapartners_SpeedTax.xml CHANGED
@@ -1,25 +1,25 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /*
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the End User Software Agreement (EULA).
7
- * It is also available through the world-wide-web at this URL:
8
- * http://www.harapartners.com/license
9
- * If you did not receive a copy of the license and are unable to
10
- * obtain it through the world-wide-web, please send an email
11
- * to eula@harapartners.com so we can send you a copy immediately.
12
- *
13
- */
14
- -->
15
- <config>
16
- <modules>
17
- <Harapartners_SpeedTax>
18
- <active>true</active>
19
- <codePool>community</codePool>
20
- <depends>
21
- <Harapartners_ConnectorHub/>
22
- </depends>
23
- </Harapartners_SpeedTax>
24
- </modules>
25
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /*
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the End User Software Agreement (EULA).
7
+ * It is also available through the world-wide-web at this URL:
8
+ * http://www.harapartners.com/license
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to eula@harapartners.com so we can send you a copy immediately.
12
+ *
13
+ */
14
+ -->
15
+ <config>
16
+ <modules>
17
+ <Harapartners_SpeedTax>
18
+ <active>true</active>
19
+ <codePool>community</codePool>
20
+ <depends>
21
+ <Harapartners_ConnectorHub/>
22
+ </depends>
23
+ </Harapartners_SpeedTax>
24
+ </modules>
25
+ </config>
package.xml CHANGED
@@ -1,18 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SalesTax_Connector</name>
4
- <version>3.2.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.harapartners.com/terms/eula">Hara Partners End User License Agreement</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Simplify sales and use tax calculation, compliance, and management in the cloud! </summary>
10
  <description>Simplify sales and use tax calculation, compliance, and management in the cloud! </description>
11
- <notes>Simplify sales and use tax calculation, compliance, and management in the cloud! </notes>
 
12
  <authors><author><name>Ken Nunes</name><user>kennuneswo</user><email>ken.nunes@wolterskluwer.com</email></author></authors>
13
- <date>2014-07-25</date>
14
- <time>21:46:36</time>
15
- <contents><target name="magecommunity"><dir name="Harapartners"><dir name="SpeedTax"><dir name="Block"><dir name="Adminhtml"><dir name="Invoice"><dir name="All"><dir name="Index"><file name="Grid.php" hash="9e30ba4540d93b90931653a26be84ca5"/></dir><file name="Index.php" hash="3bd888b08743237ba8cd5a3366b82487"/></dir><dir name="Failsafe"><dir name="Index"><file name="Grid.php" hash="8f8e68705a3f7abab5e93d114df741ca"/></dir><file name="Index.php" hash="a96810237abda83a9a6d6f7397a4847d"/></dir><dir name="Rateverification"><dir name="Index"><file name="Grid.php" hash="890971679f6eb41955ff0bd5ed7dac70"/></dir><file name="Index.php" hash="1c4345559aa6ed8e648e5ffd3d57f4bb"/></dir></dir><file name="Notification.php" hash="3b0541ce8d61c567ef5431c23f078e13"/><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Authentication.php" hash="8be5a91c0aa3d23ced5a2852b940dac3"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><dir name="Connector"><file name="Data.php" hash="ec2d5c31c759d72834c4d1664b29de2f"/><file name="Speedtax.php" hash="5ab1b418b258cc574eef0542490a096e"/></dir><file name="Data.php" hash="b5f093dcc4a15f65ac0ba4decbf1f21b"/><file name="Failsafe.php" hash="f41b5e97350fe47b1b6fa73653b49871"/><file name="Processor.php" hash="1db8a77649751e8002d7779d80a145f3"/></dir><dir name="Model"><dir name="Failsafe"><dir name="Calculation"><file name="Rate.php" hash="811902f52d9fe42c71f5834b5f78fba9"/></dir><file name="Calculation.php" hash="892f32e0082bff2700ac7a8d98fe4a5a"/><dir name="Sales"><dir name="Total"><dir name="Quote"><file name="Tax.php" hash="c367a1e87a3d59299ad2d4ef6d3b8865"/></dir></dir></dir></dir><file name="Observer.php" hash="2319c1c9d941ef00935cb71b52921030"/><dir name="Resource"><dir name="Failsafe"><dir name="Calculation"><dir name="Rate"><file name="Collection.php" hash="2a1c5730b4be51104a27009300eb13c1"/></dir><file name="Rate.php" hash="59a6d553ad7544d431b7952aeeb6b8e7"/></dir></dir></dir><dir name="Rewrite"><dir name="Tax"><dir name="Sales"><dir name="Total"><dir name="Quote"><file name="Tax.php" hash="266bcbb46c333e594869ce3fb51b9a49"/></dir></dir></dir></dir></dir><file name="Session.php" hash="46175fe01434d91757499d5c0f7f2bee"/><dir name="Source"><file name="Usregions.php" hash="2ab7713b5b46f142e133459952cd1ef5"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="InvoiceController.php" hash="ad4c95583b2f36a2b9b3715cdb96440e"/><file name="NotificationController.php" hash="1221b23c9a8612fb9913a40c7fd639a8"/><dir name="System"><dir name="Config"><file name="AjaxController.php" hash="83fad83760a495f4915d4d369c4550b1"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="9489898787655e78c390e036b4897aa5"/><file name="config.xml" hash="2f31e4d26f232a2c94d7677beacbffcb"/><file name="system.xml" hash="a9e26cb879487f522a18d2b7b4e212a7"/></dir><dir name="sql"><dir name="speedtax_setup"><file name="mysql4-upgrade-3.0.9-3.1.0.php" hash="c3f6ae6b94d838d019c1ffa86f4fb2cc"/><file name="mysql4-upgrade-3.9.9-4.0.0.php" hash="8603060cf362ca9303c3e28c5c00c0da"/></dir></dir></dir><dir name="ConnectorHub"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Json.php" hash="f6df5fa48d5e7daa0f5d646fe8572402"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><dir name="Connector"><file name="Config.php" hash="7602770c8362d6edad15e2ed9d0419d1"/><file name="Core.php" hash="edcc593b8e8fd8d079182adc1bca99b8"/></dir><file name="Mcrypt.php" hash="928572b4884d60f03ecde04b63186ea2"/><file name="Object.php" hash="487cd77c21c8bb9dec6189cc19d8c6a5"/></dir><dir name="Model"><file name="Observer.php" hash="d6d7f852fbde7e14e6fdd5f7c75e77cd"/><dir name="Rewrite"><dir name="Paypal"><dir name="Api"><file name="Nvp.php" hash="e260f23f4093e7932286f81bf48f855a"/></dir><file name="Config.php" hash="642ee9fdd6ec30b8b18f9becab5b0682"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="4e0fc6a2496f4f7b871b8e389ff11b39"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Harapartners_SpeedTax.xml" hash="fc395d2c5a12e41f920f032c1541bd08"/><file name="Harapartners_ConnectorHub.xml" hash="f553017467b4b32a76b1af8d32765049"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SalesTax_Connector</name>
4
+ <version>4.1.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.harapartners.com/terms/eula">Hara Partners End User License Agreement</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Simplify sales and use tax calculation, compliance, and management in the cloud! </summary>
10
  <description>Simplify sales and use tax calculation, compliance, and management in the cloud! </description>
11
+ <notes>Simplify sales and use tax calculation, compliance, and management in the cloud!&#xD;
12
+ </notes>
13
  <authors><author><name>Ken Nunes</name><user>kennuneswo</user><email>ken.nunes@wolterskluwer.com</email></author></authors>
14
+ <date>2014-12-29</date>
15
+ <time>18:29:17</time>
16
+ <contents><target name="magecommunity"><dir name="Harapartners"><dir name="SpeedTax"><dir name="Block"><dir name="Adminhtml"><dir name="Invoice"><dir name="All"><dir name="Index"><file name="Grid.php" hash="bc4efb092acd357112515822cc4df102"/></dir><file name="Index.php" hash="b425f98fb3735945413260b7b22037db"/></dir><dir name="Failsafe"><dir name="Index"><file name="Grid.php" hash="bfdb934090cf15c5832fe156ffb04876"/></dir><file name="Index.php" hash="09180c24b3c6cd160457437df71dfbdb"/></dir><dir name="Rateverification"><dir name="Index"><file name="Grid.php" hash="d48f72f59318fb7f8a027efd1d8d9278"/></dir><file name="Index.php" hash="2dff07e6e5f74062c6868045f8ffd9a2"/></dir></dir><file name="Notification.php" hash="edcd5206299cb0137ef11db7f14b30e2"/><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Authentication.php" hash="3d271c4512536e6b5bacd3047f04d2a7"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><dir name="Connector"><file name="Data.php" hash="2c3335021ec1bd981c13ed3fc09ec31d"/><file name="Speedtax.php" hash="a2157ce10b53173ad3ee66894e417cee"/></dir><file name="Data.php" hash="14c2e06f78ea2a2ebf19f3e2003d1940"/><file name="Failsafe.php" hash="dead32b5aced32d4fc539d9a356cc822"/><file name="Processor.php" hash="f38e5b91141e1004ca104eacb3ae1007"/></dir><dir name="Model"><dir name="Failsafe"><dir name="Calculation"><file name="Rate.php" hash="81d5f52014a082d526909150fd465c9f"/></dir><file name="Calculation.php" hash="c0bbe523fc956e97946156b8b3ba62ed"/><dir name="Sales"><dir name="Total"><dir name="Quote"><file name="Tax.php" hash="3ec837de48e10b6053b278131c3a0551"/></dir></dir></dir></dir><file name="Observer.php" hash="e4a295b640a5d091362144d089fbd1c9"/><dir name="Resource"><dir name="Failsafe"><dir name="Calculation"><dir name="Rate"><file name="Collection.php" hash="749a25167293238a9d1037b9ba1ba9dd"/></dir><file name="Rate.php" hash="b0912149b4a497b2c6ca2e31389947d0"/></dir></dir></dir><dir name="Rewrite"><dir name="Tax"><dir name="Sales"><dir name="Total"><dir name="Quote"><file name="Tax.php" hash="aa37967e25be164a18f5af3d5c92d92c"/></dir></dir></dir></dir></dir><file name="Session.php" hash="2c4ddd3a8efa79510e59e97e131b3d57"/><dir name="Source"><file name="Usregions.php" hash="886f87d20546acb4a1bcf79615aac1ed"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="InvoiceController.php" hash="99721ea774c353f45dd6adc8c328b172"/><file name="NotificationController.php" hash="2c2a9cd20628ac63d87870de29fd39bd"/><dir name="System"><dir name="Config"><file name="AjaxController.php" hash="71c1e2ccd4cc46ba97c69daff65022a0"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f2f8578853a57fea9b08ef7d1573f11f"/><file name="config.xml" hash="35217e82f0481e1997fb1f55f5a5c2c7"/><file name="system.xml" hash="16830a3aabbe5fdd8641c0d32cdaa93f"/></dir><dir name="sql"><dir name="speedtax_setup"><file name="mysql4-upgrade-3.0.9-3.1.0.php" hash="5a30e5ad0fdcb069e2a6facbe7c2a1b4"/><file name="mysql4-upgrade-3.9.9-4.0.0.php" hash="6039fcf243a4b1d5d97f62b0f06457ba"/></dir></dir></dir><dir name="ConnectorHub"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Json.php" hash="f6df5fa48d5e7daa0f5d646fe8572402"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><dir name="Connector"><file name="Config.php" hash="7602770c8362d6edad15e2ed9d0419d1"/><file name="Core.php" hash="edcc593b8e8fd8d079182adc1bca99b8"/></dir><file name="Mcrypt.php" hash="928572b4884d60f03ecde04b63186ea2"/><file name="Object.php" hash="487cd77c21c8bb9dec6189cc19d8c6a5"/></dir><dir name="Model"><file name="Observer.php" hash="d6d7f852fbde7e14e6fdd5f7c75e77cd"/><dir name="Rewrite"><dir name="Paypal"><dir name="Api"><file name="Nvp.php" hash="e260f23f4093e7932286f81bf48f855a"/></dir><file name="Config.php" hash="642ee9fdd6ec30b8b18f9becab5b0682"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="4e0fc6a2496f4f7b871b8e389ff11b39"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Harapartners_SpeedTax.xml" hash="2d4196e38996a41cc79c425519053759"/><file name="Harapartners_ConnectorHub.xml" hash="f553017467b4b32a76b1af8d32765049"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>