VertexSMB_TaxCE - Version 1.0.0

Version Notes

Stable Release

Download this release

Release Info

Developer Vertex SMB
Extension VertexSMB_TaxCE
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (38) hide show
  1. app/code/local/VertexSMB/TaxCE/Block/Adminhtml/Order/View.php +28 -0
  2. app/code/local/VertexSMB/TaxCE/Block/Adminhtml/System/Config/Form/Field/ShippingCodes.php +63 -0
  3. app/code/local/VertexSMB/TaxCE/Block/Adminhtml/System/Config/Form/Field/TaxceStatus.php +22 -0
  4. app/code/local/VertexSMB/TaxCE/Helper/Config.php +46 -0
  5. app/code/local/VertexSMB/TaxCE/Helper/Data.php +545 -0
  6. app/code/local/VertexSMB/TaxCE/Model/Observer.php +139 -0
  7. app/code/local/VertexSMB/TaxCE/Model/RequestItem.php +79 -0
  8. app/code/local/VertexSMB/TaxCE/Model/Resource/Setup.php +15 -0
  9. app/code/local/VertexSMB/TaxCE/Model/Resource/TaxRequest.php +14 -0
  10. app/code/local/VertexSMB/TaxCE/Model/Resource/TaxRequest/Collection.php +22 -0
  11. app/code/local/VertexSMB/TaxCE/Model/Source/Taxinvoice.php +15 -0
  12. app/code/local/VertexSMB/TaxCE/Model/Source/Usregions.php +42 -0
  13. app/code/local/VertexSMB/TaxCE/Model/Tax/Sales/Total/Quote/Tax.php +257 -0
  14. app/code/local/VertexSMB/TaxCE/Model/TaxInvoice.php +167 -0
  15. app/code/local/VertexSMB/TaxCE/Model/TaxQuote.php +158 -0
  16. app/code/local/VertexSMB/TaxCE/Model/TaxRequest.php +46 -0
  17. app/code/local/VertexSMB/TaxCE/Model/Taxce.php +102 -0
  18. app/code/local/VertexSMB/TaxCE/controllers/OnepageController.php +230 -0
  19. app/code/local/VertexSMB/TaxCE/controllers/TaxceController.php +151 -0
  20. app/code/local/VertexSMB/TaxCE/data/taxce_setup/data-install-0.1.1.php +19 -0
  21. app/code/local/VertexSMB/TaxCE/data/taxce_setup/data-upgrade-0.1.4-0.1.5.php +17 -0
  22. app/code/local/VertexSMB/TaxCE/etc/adminhtml.xml +20 -0
  23. app/code/local/VertexSMB/TaxCE/etc/config.xml +205 -0
  24. app/code/local/VertexSMB/TaxCE/etc/system.xml +345 -0
  25. app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-install-0.1.1.php +63 -0
  26. app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.3-0.1.4.php +21 -0
  27. app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.6-0.1.7.php +21 -0
  28. app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.7-0.1.8.php +30 -0
  29. app/design/adminhtml/default/default/layout/taxce.xml +12 -0
  30. app/design/adminhtml/default/default/template/taxce/addresschange-popup-content.phtml +56 -0
  31. app/design/adminhtml/default/default/template/taxce/popup-content.phtml +66 -0
  32. app/design/adminhtml/default/default/template/taxce/popup.phtml +115 -0
  33. app/design/frontend/base/default/layout/taxce.xml +12 -0
  34. app/design/frontend/base/default/template/taxce/addresschange-popup-content.phtml +71 -0
  35. app/design/frontend/base/default/template/taxce/popup-content.phtml +81 -0
  36. app/design/frontend/base/default/template/taxce/popup.phtml +14 -0
  37. app/etc/modules/VertexSMB_TaxCE.xml +13 -0
  38. package.xml +18 -0
app/code/local/VertexSMB/TaxCE/Block/Adminhtml/Order/View.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Block_Adminhtml_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
4
+
5
+
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+
11
+ if (Mage::Helper('taxce')->IsVertexActive()) {
12
+ $TotalInvoicedTax=Mage::getModel('taxce/taxRequest')->getTotalInvoicedTax( $this->getOrder()->getId());
13
+ if ($TotalInvoicedTax || !Mage::helper('taxce')->ShowManualInvoiceButton())
14
+ return $this;
15
+ $this->_addButton('taxce_invoice', array(
16
+ 'label' => Mage::helper('taxce')->__("VertexSMB Invoice"),
17
+ 'onclick' => 'setLocation(\'' . $this->getVertexInvoiceUrl() . '\')',
18
+ 'class' => 'go'
19
+ ));
20
+
21
+ }
22
+ }
23
+
24
+ public function getVertexInvoiceUrl(){
25
+ return $this->getUrl('*/taxce/invoicetax');
26
+ }
27
+
28
+ }
app/code/local/VertexSMB/TaxCE/Block/Adminhtml/System/Config/Form/Field/ShippingCodes.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Block_Adminhtml_System_Config_Form_Field_ShippingCodes extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $helper=Mage::helper('taxce');
8
+ $html='<table cellspacing="0" class="form-list"><colgroup class="label"></colgroup><colgroup class="value"></colgroup><tbody>';
9
+ $html.='<tr><td class="label">Shipping Method</td><td class="value">Product Code</td></tr>';
10
+ $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
11
+ foreach($methods as $_ccode => $_carrier)
12
+ {
13
+
14
+ $_methodOptions = array();
15
+ if($_methods = $_carrier->getAllowedMethods())
16
+ {
17
+
18
+ if(!$_title = Mage::getStoreConfig("carriers/$_ccode/title"))
19
+ $_title = $_ccode;
20
+ $html.='<tr><td class="label" colspan="2"><b>'.$_title.'</b></td></tr>';
21
+ foreach($_methods as $_mcode => $_method)
22
+ {
23
+ $_code = $_ccode . '_' . $_mcode;
24
+ $_methodOptions[] = array('value' => $_code, 'label' => $_method);
25
+ }
26
+ $html.='<tr><td class="label">'.$_method.': </td><td class="value"> '.$_code.'</td></tr>';
27
+ }
28
+ if ($_ccode=='ups' && $ups = Mage::getSingleton('usa/shipping_carrier_ups') )
29
+ foreach ($ups->getCode('method') as $k=>$v)
30
+ $html.='<tr><td class="label">'.Mage::helper('usa')->__($v).': </td><td class="value"> '.$_ccode . '_' .$k.'</td></tr>';
31
+
32
+ if ($_ccode=='usps' && $usps = Mage::getSingleton('usa/shipping_carrier_usps') )
33
+ foreach ($usps->getCode('method') as $k=>$v)
34
+ $html.='<tr><td class="label">'.$usps->getMethodLabel($v).': </td><td class="value"> '.$_ccode . '_' .$k.'</td></tr>';
35
+
36
+ if ($_ccode=='fedex' && $fedex = Mage::getSingleton('usa/shipping_carrier_fedex') )
37
+ foreach ($fedex->getCode('method') as $k=>$v)
38
+ $html.='<tr><td class="label">'.$v.': </td><td class="value"> '.$_ccode . '_' .$k.'</td></tr>';
39
+
40
+ if ($_ccode=='dhl' && $dhl = Mage::getSingleton('usa/shipping_carrier_dhl') )
41
+ foreach ($dhl->getCode('service') as $k=>$v)
42
+ $html.='<tr><td class="label">'.$v.': </td><td class="value"> '.$_ccode . '_' .$k.'</td></tr>';
43
+
44
+ if ($_ccode=='dhlint' && $dhlint = Mage::getSingleton('usa/shipping_carrier_dhl_international') )
45
+ foreach ($dhlint->getDhlProducts($this->_contentType) as $k=>$v)
46
+ $html.='<tr><td class="label">'.$v.': </td><td class="value"> '.$_ccode . '_' .$k.'</td></tr>';
47
+
48
+ }
49
+ $html.='</tbody></table>';
50
+ return $html;
51
+ }
52
+
53
+ public function render(Varien_Data_Form_Element_Abstract $element)
54
+ {
55
+ $id = $element->getHtmlId();
56
+ $html='<td>';
57
+ $html .= $this->_getElementHtml($element);
58
+ $html.= '</td>';
59
+ return $this->_decorateRowHtml($element, $html);
60
+ }
61
+
62
+ }
63
+
app/code/local/VertexSMB/TaxCE/Block/Adminhtml/System/Config/Form/Field/TaxceStatus.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Block_Adminhtml_System_Config_Form_Field_TaxceStatus extends Mage_Adminhtml_Block_System_Config_Form_Field
4
+ {
5
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $helper=Mage::helper('taxce');
8
+ if (!$helper->IsVertexActive()) {
9
+ $status="Disabled";
10
+ $state="critical";
11
+ }else{
12
+ $status=$helper->CheckCredentials();
13
+ if ($status=='Valid')
14
+ $state="notice";
15
+ else
16
+ $state="minor";
17
+ }
18
+
19
+ return '<span class="grid-severity-'.$state.'"><span style=" background-color: #FAFAFA;">'.$status.'</span></span>';
20
+ }
21
+ }
22
+
app/code/local/VertexSMB/TaxCE/Helper/Config.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class VertexSMB_TaxCE_Helper_Config extends Mage_Core_Helper_Abstract {
5
+
6
+ const CONFIG_XML_PATH_ENABLE_VERTEX='tax/taxce_settings/enable_taxce';
7
+ const CONFIG_XML_PATH_DEFAULT_TAX_CALCULATION_ADDRESS_TYPE='tax/calculation/based_on';
8
+ const CONFIG_XML_PATH_DEFAULT_CUSTOMER_CODE = 'tax/classes/default_customer_code';
9
+ const VERTEX_API_HOST='tax/taxce_settings/api_url';
10
+
11
+ const CONFIG_XML_PATH_VERTEX_API_USER = 'tax/taxce_settings/login';
12
+ const CONFIG_XML_PATH_VERTEX_API_KEY = 'tax/taxce_settings/password';
13
+ const CONFIG_XML_PATH_VERTEX_API_TRUSTED_ID = 'tax/taxce_settings/trustedId';
14
+ const CONFIG_XML_PATH_VERTEX_COMPANY_CODE = 'tax/taxce_seller_info/company';
15
+ const CONFIG_XML_PATH_VERTEX_LOCATION_CODE = 'tax/taxce_seller_info/location_code';
16
+ const CONFIG_XML_PATH_VERTEX_STREET1 = 'tax/taxce_seller_info/streetAddress1';
17
+ const CONFIG_XML_PATH_VERTEX_STREET2 = 'tax/taxce_seller_info/streetAddress2';
18
+ const CONFIG_XML_PATH_VERTEX_CITY = 'tax/taxce_seller_info/city';
19
+ const CONFIG_XML_PATH_VERTEX_COUNTRY = 'tax/taxce_seller_info/country_id';
20
+ const CONFIG_XML_PATH_VERTEX_REGION = 'tax/taxce_seller_info/region_id';
21
+ const CONFIG_XML_PATH_VERTEX_POSTAL_CODE = 'tax/taxce_seller_info/postalCode';
22
+ const CONFIG_XML_PATH_VERTEX_INVOICE_DATE = 'tax/taxce_settings/invoice_tax_date';
23
+ const CONFIG_XML_PATH_VERTEX_TRANSACTION_TYPE = 'SALE'; /* SALE,RENTAl,LEASE*/
24
+ const CONFIG_XML_PATH_VERTEX_INVOICE_ORDER = 'tax/taxce_settings/invoice_order';
25
+ const CONFIG_XML_PATH_VERTEX_INVOICE_ORDER_STATUS = 'tax/taxce_settings/invoice_order_status';
26
+ const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
27
+ const VERTEX_ADDRESS_API_HOST='tax/taxce_settings/address_api_url';
28
+
29
+ const VERTEX_CREDITMEMO_ADJUSTMENT_CLASS='tax/classes/creditmemo_adjustment_class';
30
+ const VERTEX_CREDITMEMO_ADJUSTMENT_NEGATIVE_CODE='tax/classes/creditmemo_adjustment_negative_code';
31
+ const VERTEX_CREDITMEMO_ADJUSTMENT_POSITIVE_CODE='tax/classes/creditmemo_adjustment_positive_code';
32
+ const VERTEX_GIFTWRAP_ORDER_CLASS='tax/classes/giftwrap_order_class';
33
+ const VERTEX_GIFTWRAP_ORDER_CODE='tax/classes/giftwrap_order_code';
34
+ const VERTEX_GIFTWRAP_ITEM_CLASS='tax/classes/giftwrap_item_class';
35
+ const VERTEX_GIFTWRAP_ITEM_CODE_PREFIX='tax/classes/giftwrap_item_code';
36
+ const VERTEX_PRINTED_GIFTCARD_CLASS='tax/classes/printed_giftcard_class';
37
+ const VERTEX_PRINTED_GIFTCARD_CODE='tax/classes/printed_giftcard_code';
38
+ const CONFIG_XML_PATH_VERTEX_ALLOW_CART_QUOTE = 'tax/taxce_settings/allow_cart_request';
39
+ const CONFIG_XML_PATH_VERTEX_SHOW_MANUAL_BUTTON = 'tax/taxce_settings/show_manual_button';
40
+ const CONFIG_XML_PATH_VERTEX_SHOW_POPUP= 'tax/taxce_settings/show_tarequest_popup';
41
+
42
+ public function getQuoteAllowedControllers(){
43
+ $_quote_allowed_controllers=array('onepage','multishipping','sales_order_create');
44
+ return $_quote_allowed_controllers;
45
+ }
46
+ }
app/code/local/VertexSMB/TaxCE/Helper/Data.php ADDED
@@ -0,0 +1,545 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ public function IsVertexActive(){
6
+ if (Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_ENABLE_VERTEX, Mage::app()->getStore()->getId()))
7
+ return true;
8
+ return false;
9
+ }
10
+ public function getLocationCode(){
11
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_LOCATION_CODE, Mage::app()->getStore()->getId());
12
+ }
13
+ public function getCompanyCode(){
14
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_COMPANY_CODE, Mage::app()->getStore()->getId());
15
+ }
16
+ public function getCompanyStreet1(){
17
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_STREET1, Mage::app()->getStore()->getId());
18
+ }
19
+ public function getCompanyStreet2(){
20
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_STREET2, Mage::app()->getStore()->getId());
21
+ }
22
+ public function getCompanyCity(){
23
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_CITY, Mage::app()->getStore()->getId());
24
+ }
25
+ public function getCompanyRegionId(){
26
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_REGION, Mage::app()->getStore()->getId());
27
+ }
28
+ public function getCompanyPostalCode(){
29
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_POSTAL_CODE, Mage::app()->getStore()->getId());
30
+ }
31
+ public function getShippingTaxClassId(){
32
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, Mage::app()->getStore()->getId());
33
+ }
34
+ public function getTrustedId(){
35
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_API_TRUSTED_ID, Mage::app()->getStore()->getId());
36
+ }
37
+ public function getTransactionType(){
38
+ return VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_TRANSACTION_TYPE;
39
+ }
40
+ public function getVertexHost(){
41
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_API_HOST, Mage::app()->getStore()->getId());
42
+ }
43
+ public function getVertexAddressHost(){
44
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_ADDRESS_API_HOST, Mage::app()->getStore()->getId());
45
+ }
46
+ public function getDefaultCustomerCode(){
47
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_DEFAULT_CUSTOMER_CODE, Mage::app()->getStore()->getId());
48
+ }
49
+ public function getCreditmemoAdjustmentFeeCode(){
50
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_CREDITMEMO_ADJUSTMENT_NEGATIVE_CODE, Mage::app()->getStore()->getId());
51
+ }
52
+ public function getCreditmemoAdjustmentFeeClass(){
53
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_CREDITMEMO_ADJUSTMENT_CLASS, Mage::app()->getStore()->getId());
54
+ }
55
+ public function getCreditmemoAdjustmentPositiveCode(){
56
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_CREDITMEMO_ADJUSTMENT_POSITIVE_CODE, Mage::app()->getStore()->getId());
57
+ }
58
+ public function getCreditmemoAdjustmentPositiveClass(){
59
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_CREDITMEMO_ADJUSTMENT_CLASS, Mage::app()->getStore()->getId());
60
+ }
61
+ public function AllowCartQuote(){
62
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_ALLOW_CART_QUOTE, Mage::app()->getStore()->getId());
63
+ }
64
+ public function getGiftWrappingOrderClass(){
65
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_GIFTWRAP_ORDER_CLASS, Mage::app()->getStore()->getId());
66
+ }
67
+ public function getGiftWrappingOrderCode(){
68
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_GIFTWRAP_ORDER_CODE, Mage::app()->getStore()->getId());
69
+ }
70
+ public function getGiftWrappingItemClass(){
71
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_GIFTWRAP_ITEM_CLASS, Mage::app()->getStore()->getId());
72
+ }
73
+ public function getGiftWrappingItemCodePrefix(){
74
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_GIFTWRAP_ITEM_CODE_PREFIX, Mage::app()->getStore()->getId());
75
+ }
76
+ public function getPrintedGiftcardClass(){
77
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_PRINTED_GIFTCARD_CLASS, Mage::app()->getStore()->getId());
78
+ }
79
+ public function getPrintedGiftcardCode(){
80
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::VERTEX_PRINTED_GIFTCARD_CODE, Mage::app()->getStore()->getId());
81
+ }
82
+ public function IsAllowedQuote() {
83
+ $quote_allowed_controllers=VertexSMB_TaxCE_Helper_Config::getQuoteAllowedControllers();
84
+ if ($this->AllowCartQuote())
85
+ $quote_allowed_controllers[]='cart';
86
+
87
+ if (in_array( Mage::app()->getRequest()->getControllerName(), $quote_allowed_controllers))
88
+ return true;
89
+
90
+ return false;
91
+ }
92
+
93
+ public function ShowManualInvoiceButton(){
94
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_SHOW_MANUAL_BUTTON, Mage::app()->getStore()->getId());
95
+ }
96
+
97
+ public function ShowPopup(){
98
+ return Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_SHOW_POPUP, Mage::app()->getStore()->getId());
99
+ }
100
+
101
+ public function RequestbyInvoiceCreation(){
102
+ $vertex_invoice_event=Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER, Mage::app()->getStore()->getId());
103
+ if ($vertex_invoice_event=='invoice_created')
104
+ return true;
105
+ return false;
106
+ }
107
+
108
+ public function RequestbyOrderStatus($status){
109
+ $vertex_invoice_event=Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER, Mage::app()->getStore()->getId());
110
+ $vertex_invoice_order_status=Mage::getStoreConfig(VertexSMB_TaxCE_Helper_Config::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER_STATUS, Mage::app()->getStore()->getId());
111
+ if ($vertex_invoice_event=='order_status' && $vertex_invoice_order_status==$status)
112
+ return true;
113
+ return false;
114
+ }
115
+
116
+ public function TaxClassNameByClassId($class_id) {
117
+
118
+ $tax_class_name = Mage::getModel('tax/class')->load($class_id)->getClassName();
119
+ if ($class_id == 0 && !$tax_class_name)
120
+ $tax_class_name = "None";
121
+ return $tax_class_name;
122
+ }
123
+
124
+ public function getSourcePath(){
125
+ $controller=Mage::app()->getRequest()->getControllerName();
126
+ $module=Mage::app()->getRequest()->getModuleName();
127
+ $action=Mage::app()->getRequest()->getActionName();
128
+ $source_path="";
129
+ if ($controller)
130
+ $source_path.=$controller;
131
+ if ($module)
132
+ $source_path.="_".$module;
133
+ if ($action)
134
+ $source_path.="_".$action;
135
+
136
+ return $source_path;
137
+ }
138
+
139
+ public function TaxClassNameByCustomerGroupId($group_id) {
140
+ $classId = Mage::getModel('customer/group')->getTaxClassId($group_id);
141
+ return $this->TaxClassNameByClassId($classId);
142
+ }
143
+
144
+ public function getCustomerCodeById($customer_id=0) {
145
+ $customer_code = $this->getDefaultCustomerCode();
146
+ if ($customer_id)
147
+ $customer_code = Mage::getModel('customer/customer')->load($customer_id)->getCustomerCode();
148
+
149
+ if (empty($customer_code))
150
+ $customer_code=$this->getDefaultCustomerCode();
151
+
152
+ return $customer_code;
153
+ }
154
+
155
+ public function CheckCredentials() {
156
+
157
+ if (!$this->getVertexHost())
158
+ return "Not Valid: Missing Api Url";
159
+ if (!$this->getVertexAddressHost())
160
+ return "Not Valid: Missing Address Validation Api Url";
161
+ if (!$this->getTrustedId())
162
+ return "Not Valid: Missing Trusted Id";
163
+ if (!$this->getCompanyRegionId())
164
+ return "Not Valid: Missing Company State";
165
+ if (!$this->getCompanyStreet1())
166
+ return "Not Valid: Missing Company Street Address";
167
+ if (!$this->getCompanyCity())
168
+ return "Not Valid: Missing Company City";
169
+ if (!$this->getCompanyPostalCode())
170
+ return "Not Valid: Missing Company Postal Code";
171
+
172
+ $region_id=$this->getCompanyRegionId();
173
+ $regionModel = Mage::getModel('directory/region')->load($region_id);
174
+ $company_state=$regionModel->getCode();
175
+
176
+ $address=new Varien_Object();
177
+ $address->setStreet1($this->getCompanyStreet1());
178
+ $address->setStreet2($this->getCompanyStreet2());
179
+ $address->setCity($this->getCompanyCity());
180
+ $address->setRegionCode($company_state);
181
+ $address->setPostcode($this->getCompanyPostalCode());
182
+
183
+ $request_result=$this->LookupAreaRequest($address);
184
+ if ($request_result instanceof Exception) {
185
+ Mage::log("Tax Area Lookup Error: ".$request_result->getMessage(), null, 'taxce.log');
186
+ return "Validation Error: Please check settings";
187
+ }
188
+ return "Valid";
189
+ }
190
+
191
+ public function LookupAreaRequest($address){
192
+
193
+ $request=array(
194
+ 'Login'=>array('TrustedId'=>$this->getTrustedId()),
195
+ 'TaxAreaRequest'=>array(
196
+ 'TaxAreaLookup'=> array(
197
+ 'PostalAddress'=>array(
198
+ 'StreetAddress1'=>$address->getStreet1(),
199
+ 'StreetAddress2'=>$address->getStreet2(),
200
+ 'City'=>$address->getCity(),
201
+ 'MainDivision'=>$address->getRegionCode(),
202
+ 'PostalCode'=>$address->getPostcode(),
203
+ )
204
+ )
205
+ )
206
+ );
207
+
208
+ $request_result=Mage::getModel('taxce/taxce')->SendApiRequest($request,null, 'tax_area_lookup');
209
+ if ($request_result instanceof Exception) {
210
+ Mage::log("Tax Area Lookup Error: ".$request_result->getMessage(), null, 'taxce.log');
211
+ return $request_result;
212
+ }
213
+ return $request_result;
214
+ }
215
+
216
+ /* Company Information */
217
+ public function AddSellerInformation($data){
218
+
219
+ $region_id=$this->getCompanyRegionId();
220
+ $regionModel = Mage::getModel('directory/region')->load($region_id);
221
+ $company_state=$regionModel->getCode();
222
+
223
+ $data['location_code']=$this->getLocationCode();
224
+ $data['transaction_type']=$this->getTransactionType();
225
+ $data['company_id']=$this->getCompanyCode();
226
+ $data['company_street_1']=$this->getCompanyStreet1();
227
+ $data['company_street_2']=$this->getCompanyStreet2();
228
+ $data['company_city']=$this->getCompanyCity();
229
+ $data['company_state']=$company_state;
230
+ $data['company_postcode']=$this->getCompanyPostalCode();
231
+ $data['trusted_id']= $this->getTrustedId();
232
+
233
+ return $data;
234
+ }
235
+
236
+ public function AddAddressInformation($data,$address) {
237
+ $data['customer_street1'] = $address->getStreet1();
238
+ $data['customer_street2'] = $address->getStreet2();
239
+ $data['customer_city'] = $address->getCity();
240
+ $data['customer_region'] = $address->getRegionCode();
241
+ $data['customer_postcode'] = $address->getPostcode();
242
+ $data['tax_area_id'] = $address->getTaxAreaId();
243
+ return $data;
244
+ }
245
+
246
+ public function IsFirstOfPartial($order_address,$original_entity){
247
+
248
+ /* Invoice Shipping with first partial invoice */
249
+ if ($original_entity instanceof Mage_Sales_Model_Order_Invoice) {
250
+ if (!$original_entity->getShippingTaxAmount())
251
+ return false;
252
+ }
253
+ /* Not invoice shipping if there is partial invoice */
254
+ if ($this->RequestbyInvoiceCreation() && $original_entity instanceof Mage_Sales_Model_Order && $original_entity->getShippingInvoiced())
255
+ return false;
256
+
257
+ if ($original_entity instanceof Mage_Sales_Model_Order_Creditmemo) {
258
+ if (!$original_entity->getShippingAMount())
259
+ return false;
260
+ }
261
+
262
+ return true;
263
+ }
264
+
265
+ public function AddRefundAdjustments($info, $creditmemo_model){
266
+
267
+ if ($creditmemo_model->getAdjustmentPositive()) {
268
+ $item_data=array();
269
+ $item_data['product_class']=$this->getCreditmemoAdjustmentPositiveClass();
270
+ $item_data['product_code']=$this->getCreditmemoAdjustmentPositiveCode();
271
+ $item_data['qty']=1;
272
+ $item_data['price']=-1*$creditmemo_model->getAdjustmentPositive();
273
+ $item_data['extended_price']=-1*$creditmemo_model->getAdjustmentPositive();
274
+ $info[]=$item_data;
275
+ }
276
+ if ($creditmemo_model->getAdjustmentNegative()) {
277
+ $item_data=array();
278
+ $item_data['product_class']=$this->getCreditmemoAdjustmentFeeClass();
279
+ $item_data['product_code']=$this->getCreditmemoAdjustmentFeeCode();
280
+ $item_data['qty']=1;
281
+ $item_data['price']=$creditmemo_model->getAdjustmentNegative();
282
+ $item_data['extended_price']=$creditmemo_model->getAdjustmentNegative();
283
+ $info[]=$item_data;
284
+ }
285
+ return $info;
286
+ }
287
+
288
+ public function AddOrderGiftWrap($order_address, $original_entity=null,$event=null) {
289
+ $item_data=array();
290
+ if (!$this->IsFirstOfPartial($order_address,$original_entity)) {
291
+ return $item_data;
292
+ }
293
+
294
+ $item_data['product_class']=$this->getGiftWrappingOrderClass();
295
+ $item_data['product_code']=$this->getGiftWrappingOrderCode();
296
+ $item_data['qty']=1;
297
+ $item_data['price']=$order_address->getGwPrice();
298
+ $item_data['extended_price']=$item_data['qty']*$item_data['price'];
299
+
300
+ /* Negative amounts */
301
+ if ($event=='cancel' || $event=='refund' ){
302
+ $item_data['price']=-1*$item_data['price'];
303
+ $item_data['extended_price']=-1*$item_data['extended_price'];
304
+ }
305
+ /* Negative amounts */
306
+
307
+ return $item_data;
308
+ }
309
+
310
+ public function AddOrderPrintCard($order_address, $original_entity=null,$event=null) {
311
+ $item_data=array();
312
+ if (!$this->IsFirstOfPartial($order_address,$original_entity)) {
313
+ return $item_data;
314
+ }
315
+ $item_data['product_class']=$this->getPrintedGiftcardClass();
316
+ $item_data['product_code']=$this->getPrintedGiftcardCode();
317
+ $item_data['qty']=1;
318
+ $item_data['price']=$order_address->getGwCardPrice();
319
+ $item_data['extended_price']=$order_address->getGwCardPrice();
320
+
321
+ /* Negative amounts */
322
+ if ($event=='cancel' || $event=='refund' ){
323
+ $item_data['price']=-1*$item_data['price'];
324
+ $item_data['extended_price']=-1*$item_data['extended_price'];
325
+ }
326
+ /* Negative amounts */
327
+
328
+ return $item_data;
329
+ }
330
+
331
+
332
+
333
+ public function AddShippingInfo($order_address, $original_entity=null,$event=null) {
334
+ $item_data=array();
335
+ if ($order_address->getShippingMethod() && $this->IsFirstOfPartial($order_address,$original_entity)) {
336
+
337
+ $item_data['product_class']=$this->TaxClassNameByClassId($this->getShippingTaxClassId());
338
+ $item_data['product_code']=$order_address->getShippingMethod();
339
+ $item_data['price']=$order_address->getShippingAmount()-$order_address->getShippingDiscountAmount();
340
+ $item_data['qty']=1;
341
+ $item_data['extended_price']=$item_data['price'];
342
+
343
+ if ($original_entity instanceof Mage_Sales_Model_Order_Creditmemo) {
344
+ $item_data['price']=$original_entity->getShippingAmount();
345
+ $item_data['extended_price']=$item_data['price'];
346
+ }
347
+ /* Negative amounts */
348
+ if ($event=='cancel' || $event=='refund' ){
349
+ $item_data['price']=-1*$item_data['price'];
350
+ $item_data['extended_price']=-1*$item_data['extended_price'];
351
+ }
352
+ /* Negative amounts */
353
+ }
354
+ return $item_data;
355
+ }
356
+
357
+ /* Tax Quote Calculation*/
358
+ public function UpdateQuote($address) {
359
+
360
+ $information_array = Mage::getModel('taxce/taxQuote')->collectQuotedata($address);
361
+ /* Compliance withh Request Item Model*/
362
+ $information= new Varien_Object($information_array);
363
+ $session=$this->getSession();
364
+
365
+ if (!$this->IsAllowedQuote() )
366
+ return false;
367
+
368
+ /* disable for index page. */
369
+ if ($this->getSourcePath()=='onepage_checkout_index')
370
+ return false;
371
+
372
+ if ($session->getVertexTQ()) {
373
+ /*Compare seession vs current data*/
374
+ if($this->CompareSessionQuotedData($information)) {
375
+ $session->setVertexD($information);
376
+ Mage::getModel('taxce/taxQuote')->getTaxQuote($information_array);
377
+ }
378
+ }else {
379
+ $session->setVertexTQ(1);
380
+ $session->setVertexD($information);
381
+ Mage::getModel('taxce/taxQuote')->getTaxQuote($information_array);
382
+ }
383
+ /*Calculate*/
384
+
385
+ return true;
386
+ }
387
+
388
+ public function CompareSessionQuotedData($current_information_obj) {
389
+
390
+ $need_quote = false; // Dont need any update
391
+
392
+ $stored_information_obj = $this->getSession()->getVertexD();
393
+ $stored_information = $stored_information_obj->getData();
394
+ $current_information = $current_information_obj->getData();
395
+ $difference = $this->multi_diff($current_information, $stored_information);
396
+
397
+ $count_changes_fields=count($difference);
398
+
399
+ if ($count_changes_fields){
400
+ $need_quote = true;
401
+
402
+ }
403
+ if ($count_changes_fields && ( isset($difference['customer_street1'])
404
+ || isset($difference['customer_street2'])
405
+ || isset($difference['customer_city'])
406
+ || isset($difference['customer_region'])
407
+ || isset($difference['customer_postcode'])
408
+ ) )
409
+ $current_information_obj->setTaxAreaId();
410
+
411
+ /*$need_quote=true; Always udate quote */
412
+ return $need_quote;
413
+ }
414
+
415
+ public function multi_diff($arr1, $arr2) {
416
+ $result = array();
417
+ foreach ($arr1 as $k => $v) {
418
+ if (!array_key_exists($k, $arr2)) {
419
+ $result[$k] = $v;
420
+ } else {
421
+ if (is_array($v) && is_array($arr2[$k])) {
422
+ $diff = $this->multi_diff($v, $arr2[$k]);
423
+ if (count($diff))
424
+ $result[$k] = $diff;
425
+ }elseif ($arr2[$k] != $v) {
426
+ $result[$k] = $v;
427
+ }
428
+ }
429
+ }
430
+ foreach ($arr2 as $k => $v) {
431
+ if (!array_key_exists($k, $arr1)) {
432
+ $result[$k] = $v;
433
+ } else {
434
+ if (is_array($v) && is_array($arr1[$k])) {
435
+ $diff = $this->multi_diff($v, $arr1[$k]);
436
+ if (count($diff))
437
+ $result[$k] = $diff;
438
+ }elseif ($arr1[$k] != $v) {
439
+ $result[$k] = $v;
440
+ }
441
+ }
442
+ }
443
+ return $result;
444
+ }
445
+
446
+ /* Common function for item preparation */
447
+ public function PrepareItem($item, $type='ordered', $original_entity_item=null,$event=null){
448
+ $item_data=array();
449
+
450
+ $item_data['product_class']=$this->TaxClassNameByClassId($item->getProduct()->getTaxClassId());
451
+ $item_data['product_code']=$item->getSku();
452
+
453
+ /* Price */
454
+ if ($type=='invoiced')
455
+ $price=$original_entity_item->getPrice();
456
+ else
457
+ $price=$item->getPrice();//-$item->getDiscountAmount();
458
+ /* Price */
459
+
460
+ $item_data['price']=$price;
461
+ if ($type=='ordered' && $this->RequestbyInvoiceCreation() ) /*In case order partically being invoiced*/
462
+ $item_data['qty']=$item->getQtyOrdered()-$item->getQtyInvoiced();
463
+ elseif ($type=='ordered')
464
+ $item_data['qty']=$item->getQtyOrdered();
465
+ elseif ($type=='invoiced')
466
+ $item_data['qty']=$original_entity_item->getQty();
467
+ elseif ($type=='quote')
468
+ $item_data['qty']=$item->getQty();
469
+
470
+ /* Always send discounted. Discount on TotalRowAmount*/
471
+ if ($type=='invoiced')
472
+ $item_data['extended_price']=$original_entity_item->getRowTotal()-$original_entity_item->getDiscountAmount();
473
+ else if ($type=='ordered' && $this->RequestbyInvoiceCreation() ) /*In case order partically being invoiced*/
474
+ $item_data['extended_price']=$item->getRowTotal()-$item->getRowInvoiced()-$item->getDiscountAmount()+$item->getDiscountInvoiced();
475
+ else
476
+ $item_data['extended_price']=$item->getRowTotal()-$item->getDiscountAmount();
477
+
478
+ /* Negative amounts */
479
+ if ($event=='cancel' || $event=='refund'){
480
+ $item_data['price']=-1*$item_data['price'];
481
+ $item_data['extended_price']=-1*$item_data['extended_price'];
482
+ }
483
+ return $item_data;
484
+ }
485
+
486
+ public function PrepareGiftWrapItem($item, $type='ordered', $original_entity_item=null,$event=null){
487
+ $item_data=array();
488
+
489
+ /* @todo move to config */
490
+ $item_data['product_class']=$this->getGiftWrappingItemClass();
491
+ $item_data['product_code']=$this->getGiftWrappingItemCodePrefix().'-'.$item->getSku();
492
+
493
+ /* Price */
494
+ if ($type=='invoiced')
495
+ $price=$item->getGwPriceInvoiced();
496
+ else
497
+ $price=$item->getGwPrice();
498
+ /* Price */
499
+
500
+ $item_data['price']=$price;
501
+ if ($type=='ordered' && $this->RequestbyInvoiceCreation() ) /*In case order partically being invoiced*/
502
+ $item_data['qty']=$item->getQtyOrdered()-$item->getQtyInvoiced();
503
+ elseif ($type=='ordered')
504
+ $item_data['qty']=$item->getQtyOrdered();
505
+ elseif ($type=='invoiced')
506
+ $item_data['qty']=$original_entity_item->getQty();
507
+ elseif ($type=='quote')
508
+ $item_data['qty']=$item->getQty();
509
+
510
+ if ($type=='invoiced')
511
+ $item_data['extended_price']= $item_data['qty']*$item_data['price'];
512
+ else if ($type=='ordered' && $this->RequestbyInvoiceCreation() ) /*In case order partically being invoiced*/
513
+ $item_data['extended_price']= $item_data['qty']*$item_data['price'];
514
+ else
515
+ $item_data['extended_price']= $item_data['qty']*($item->getGwPrice());
516
+
517
+ /* Negative amounts */
518
+ if ($event=='cancel' || $event=='refund'){
519
+ $item_data['price']=-1*$item_data['price'];
520
+ $item_data['extended_price']=-1*$item_data['extended_price'];
521
+ }
522
+
523
+ return $item_data;
524
+ }
525
+
526
+
527
+ public function getSession(){
528
+ if (Mage::app()->getRequest()->getControllerName()!='sales_order_create')
529
+ return Mage::getSingleton('checkout/session');
530
+ else
531
+ return Mage::getSingleton('adminhtml/session_quote');
532
+ }
533
+
534
+ public function getTaxByQuoteItemId($item_quote_id){
535
+ $session=$this->getSession();
536
+ $ItemsTaxQuoteId=$session->getItemsTaxQuoteId();
537
+
538
+ if (isset($ItemsTaxQuoteId[$item_quote_id])) {
539
+ return $ItemsTaxQuoteId[$item_quote_id];
540
+ }
541
+
542
+ return 0;
543
+ }
544
+
545
+ }
app/code/local/VertexSMB/TaxCE/Model/Observer.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ /**
5
+ * Description of Observer
6
+ *
7
+ * @author al
8
+ */
9
+ class VertexSMB_TaxCE_Model_Observer {
10
+
11
+ public function InvoiceCreated(Varien_Event_Observer $observer) {
12
+ if (!$this->_getHelper()->IsVertexActive() || !$this->_getHelper()->RequestbyInvoiceCreation())
13
+ return $this;
14
+
15
+ /* @var $order Magento_Sales_Model_Order_Invoice */
16
+ $invoice = $observer->getEvent()->getInvoice();
17
+ $invoice_request_data=Mage::getModel('vertex/taxInvoice')->PrepareInvoiceData($invoice,'invoice');
18
+
19
+ if ($invoice_request_data && Mage::getModel('taxce/taxInvoice')->SendInvoiceRequest($invoice_request_data,$invoice->getOrder()))
20
+ $this->_getSession()->addSuccess( $this->_getHelper()->__('The Vertex invoice has been sent.'));
21
+
22
+ return $this;
23
+ }
24
+
25
+ public function OrderSaved(Varien_Event_Observer $observer) {
26
+ $order = $observer->getEvent()->getOrder();
27
+ if (!$this->_getHelper()->IsVertexActive() || !$this->_getHelper()->RequestbyOrderStatus($order->getStatus()))
28
+ return $this;
29
+
30
+ $invoice_request_data=Mage::getModel('taxce/taxInvoice')->PrepareInvoiceData($order);
31
+ if ($invoice_request_data && Mage::getModel('taxce/taxInvoice')->SendInvoiceRequest($invoice_request_data,$order))
32
+ $this->_getSession()->addSuccess( $this->_getHelper()->__('The Vertex invoice has been sent.'));
33
+ return $this;
34
+ }
35
+
36
+ public function OrderCancelled(Varien_Event_Observer $observer) {
37
+ /* Commented upon new logic
38
+ * $order = $observer->getEvent()->getOrder();
39
+ $invoiced_tax= Mage::getModel('taxce/taxRequest')->getTotalInvoicedTax($order->getId());
40
+ if (!$this->_getHelper()->IsVertexActive() || !$invoiced_tax)
41
+ return $this;
42
+ $cancel_request_data=Mage::getModel('taxce/taxInvoice')->PrepareInvoiceData($order,'cancel');
43
+ if ($cancel_request_data && Mage::getModel('taxce/taxInvoice')->SendCancelRequest($cancel_request_data,$order))
44
+ $this->_getSession()->addSuccess( $this->_getHelper()->__('The Vertex invoice has been canceled.'));
45
+ */
46
+ return $this;
47
+ }
48
+
49
+ public function OrderCreditmemoRefund(Varien_Event_Observer $observer){
50
+ $credit_memo= $observer->getCreditmemo();
51
+ $order=$credit_memo->getOrder();
52
+ $invoiced_tax= Mage::getModel('taxce/taxRequest')->getTotalInvoicedTax($order->getId());
53
+ if (!$this->_getHelper()->IsVertexActive() || !$invoiced_tax)
54
+ return $this;
55
+ $creditmemo_request_data=Mage::getModel('taxce/taxInvoice')->PrepareInvoiceData($credit_memo,'refund');
56
+ if ($creditmemo_request_data && Mage::getModel('taxce/taxInvoice')->SendRefundRequest($creditmemo_request_data,$order))
57
+ $this->_getSession()->addSuccess( $this->_getHelper()->__('The Vertex invoice has been refunded.'));
58
+
59
+ return $this;
60
+ }
61
+
62
+ public function changeSystemConfig(Varien_Event_Observer $observer) {
63
+ $config = $observer->getConfig();
64
+ $config->getNode('sections/tax/groups/calculation/fields/algorithm')->show_in_website=0;
65
+ $config->getNode('sections/tax/groups/calculation/fields/algorithm')->show_in_default=0;
66
+ $config->getNode('sections/tax/groups/calculation/fields/algorithm')->show_in_store=0;
67
+
68
+ $config->getNode('sections/tax/groups/calculation/fields/based_on')->show_in_website=0;
69
+ $config->getNode('sections/tax/groups/calculation/fields/based_on')->show_in_default=0;
70
+ $config->getNode('sections/tax/groups/calculation/fields/based_on')->show_in_store=0;
71
+
72
+ $config->getNode('sections/tax/groups/calculation/fields/discount_tax')->show_in_website=0;
73
+ $config->getNode('sections/tax/groups/calculation/fields/discount_tax')->show_in_default=0;
74
+ $config->getNode('sections/tax/groups/calculation/fields/discount_tax')->show_in_store=0;
75
+
76
+ $config->getNode('sections/tax/groups/calculation/fields/apply_tax_on')->show_in_website=0;
77
+ $config->getNode('sections/tax/groups/calculation/fields/apply_tax_on')->show_in_default=0;
78
+ $config->getNode('sections/tax/groups/calculation/fields/apply_tax_on')->show_in_store=0;
79
+
80
+ $config->getNode('sections/tax/groups/weee')->show_in_website=0;
81
+ $config->getNode('sections/tax/groups/weee')->show_in_default=0;
82
+ $config->getNode('sections/tax/groups/weee')->show_in_store=0;
83
+
84
+ $config->getNode('sections/tax/groups/defaults')->show_in_website=0;
85
+ $config->getNode('sections/tax/groups/defaults')->show_in_default=0;
86
+ $config->getNode('sections/tax/groups/defaults')->show_in_store=0;
87
+
88
+ if (!Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' )
89
+ || !Mage::getConfig ()->getModuleConfig ( 'Enterprise_Enterprise' )->is('active', 'true')) {
90
+
91
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_class')->show_in_website=0;
92
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_class')->show_in_default=0;
93
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_class')->show_in_store=0;
94
+
95
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_code')->show_in_website=0;
96
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_code')->show_in_default=0;
97
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_order_code')->show_in_store=0;
98
+
99
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_class')->show_in_website=0;
100
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_class')->show_in_default=0;
101
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_class')->show_in_store=0;
102
+
103
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_code')->show_in_website=0;
104
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_code')->show_in_default=0;
105
+ $config->getNode('sections/tax/groups/classes/fields/giftwrap_item_code')->show_in_store=0;
106
+
107
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_class')->show_in_website=0;
108
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_class')->show_in_default=0;
109
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_class')->show_in_store=0;
110
+
111
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_code')->show_in_website=0;
112
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_code')->show_in_default=0;
113
+ $config->getNode('sections/tax/groups/classes/fields/printed_giftcard_code')->show_in_store=0;
114
+
115
+ }
116
+
117
+ return $this;
118
+ }
119
+
120
+ public function CleanLogs($schedule){
121
+ $request_model = Mage::getModel('taxce/taxRequest');
122
+ $request_model->RemoveQuotesLookupRequests();
123
+ $request_model->RemoveInvoicesforCompletedOrders();
124
+ return $this;
125
+ }
126
+
127
+ public function _getHelper() {
128
+ return Mage::helper('taxce');
129
+ }
130
+ /**
131
+ * Retrieve adminhtml session model object
132
+ *
133
+ * @return Mage_Adminhtml_Model_Session
134
+ */
135
+ protected function _getSession()
136
+ {
137
+ return Mage::getSingleton('adminhtml/session');
138
+ }
139
+ }
app/code/local/VertexSMB/TaxCE/Model/RequestItem.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_RequestItem extends Mage_Core_Model_Abstract {
4
+
5
+ public function _construct()
6
+ {
7
+ $this->_init('taxce/requestItem');
8
+ }
9
+
10
+ public function getHelper() {
11
+ return Mage::helper('taxce');
12
+ }
13
+ /* RequestType:
14
+ * TaxAreaRequest
15
+ * InvoiceRequest
16
+ * QuotationRequest
17
+ */
18
+ public function exportAsArray(){
19
+ $request=array(
20
+ 'Login'=>array('TrustedId'=>$this->getTrustedId()),
21
+ $this->getRequestType()=>array(
22
+ 'documentDate'=>$this->getDocumentDate(),
23
+ 'postingDate'=>$this->getPostingDate(),
24
+ 'transactionType'=>$this->getTransactionType(),
25
+ 'documentNumber' => $this->getDocumentNumber(),
26
+ 'LineItem'=> array()
27
+ )
28
+ );
29
+ if ($this->getDocumentNumber())
30
+ $request[$this->getRequestType()]['documentNumber']=$this->getDocumentNumber();
31
+
32
+ $order_items=$this->getOrderItems();
33
+ $request[$this->getRequestType()]['LineItem']=$this->AddItems($order_items);
34
+
35
+ return $request;
36
+
37
+ }
38
+
39
+ public function AddItems($items){
40
+
41
+ $query_items=array();
42
+ $i=1; /* lineItemNumber */
43
+ foreach($items as $key=>$item){
44
+ /* $key - quote_item_id */
45
+ $tmp_item=array('lineItemNumber'=>$i, 'locationCode'=>$this->getLocationCode(),
46
+ 'Seller'=> array (
47
+ 'Company'=> $this->getCompanyId(),
48
+ 'PhysicalOrigin'=>array(
49
+ 'StreetAddress1'=>$this->getData('company_street_1'),
50
+ 'StreetAddress2'=>$this->getData('company_street_2'),
51
+ 'City'=>$this->getCompanyCity(),
52
+ 'MainDivision'=>$this->getCompanyState(),
53
+ 'PostalCode'=>$this->getCompanyPostcode())
54
+ ),
55
+ 'Customer'=> array('CustomerCode'=>array('classCode'=>$this->getCustomerClass(),'_'=>$this->getCustomerCode()),
56
+ 'Destination'=>
57
+ array(
58
+ 'StreetAddress1'=>$this->getCustomerStreet1(),
59
+ 'StreetAddress2'=>$this->getCustomerStreet2(),
60
+ 'City'=>$this->getCustomerCity(),
61
+ 'MainDivision'=>$this->getCustomerRegion(),
62
+ 'PostalCode'=>$this->getCustomerPostcode())
63
+
64
+ ),
65
+ 'Product' => array ('productClass'=>$item['product_class'],'_'=>$item['product_code']),
66
+ 'UnitPrice' => array('_'=>$item['price']),
67
+ 'Quantity' => array('_'=>$item['qty']),
68
+ 'ExtendedPrice'=> array('_'=>$item['extended_price']),
69
+ );
70
+
71
+ if ($this->getTaxAreaId())
72
+ $tmp_item['Customer']['Destination']['taxAreaId']=$this->getTaxAreaId();
73
+
74
+ $query_items[]=$tmp_item;
75
+ $i++;
76
+ }
77
+ return $query_items;
78
+ }
79
+ }
app/code/local/VertexSMB/TaxCE/Model/Resource/Setup.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {
4
+
5
+ public function attributeExists($entityTypeId, $attributeId) {
6
+ try {
7
+ $entityTypeId = $this->getEntityTypeId($entityTypeId);
8
+ $attributeId = $this->getAttributeId($entityTypeId, $attributeId);
9
+ return !empty($attributeId);
10
+ } catch (Exception $e) {
11
+ return FALSE;
12
+ }
13
+ }
14
+ }
15
+
app/code/local/VertexSMB/TaxCE/Model/Resource/TaxRequest.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_Resource_TaxRequest extends Mage_Core_Model_Resource_Db_Abstract {
4
+
5
+ /**
6
+ * Resource initialization
7
+ *
8
+ */
9
+ public function _construct()
10
+ {
11
+ $this->_init('taxce/taxrequest', 'request_id');
12
+ }
13
+
14
+ }
app/code/local/VertexSMB/TaxCE/Model/Resource/TaxRequest/Collection.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_Resource_TaxRequest_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
4
+
5
+ /**
6
+ * Resource initialization
7
+ */
8
+ public function _construct()
9
+ {
10
+ $this->_init('taxce/taxRequest');
11
+ }
12
+
13
+ /**
14
+ * Add request type filter to result
15
+ *
16
+ */
17
+ public function setRequestTypeFilter($requestType)
18
+ {
19
+ return $this->addFieldToFilter('main_table.request_type', $requestType);
20
+ }
21
+
22
+ }
app/code/local/VertexSMB/TaxCE/Model/Source/Taxinvoice.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_Source_Taxinvoice {
4
+ protected $_options;
5
+
6
+ public function toOptionArray($isMultiselect=false)
7
+ {
8
+ if (!$this->_options) {
9
+ $this->_options[]=array('label'=>"When Invoice Created", 'value'=>'invoice_created');
10
+ $this->_options[]=array('label'=>"When Order Status Is", 'value'=>'order_status');
11
+ }
12
+ $options = $this->_options;
13
+ return $options;
14
+ }
15
+ }
app/code/local/VertexSMB/TaxCE/Model/Source/Usregions.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_Source_Usregions {
4
+
5
+ protected $_countries;
6
+ protected $_options;
7
+
8
+ public function toOptionArray($isMultiselect=false)
9
+ {
10
+ if (!$this->_options) {
11
+ $countriesArray = Mage::getResourceModel('directory/country_collection')->addCountryIdFilter('US')->load()
12
+ ->toOptionArray(false);
13
+
14
+ $this->_countries = array();
15
+ foreach ($countriesArray as $a) {
16
+ $this->_countries[$a['value']] = $a['label'];
17
+ }
18
+
19
+ $countryRegions = array();
20
+ $regionsCollection = Mage::getResourceModel('directory/region_collection')->addCountryFilter('US')->load();
21
+ foreach ($regionsCollection as $region) {
22
+ $countryRegions[$region->getCountryId()][$region->getId()] = $region->getDefaultName();
23
+ }
24
+ uksort($countryRegions, array($this, 'sortRegionCountries'));
25
+
26
+ $this->_options = array();
27
+ foreach ($countryRegions as $countryId=>$regions) {
28
+ $regionOptions = array();
29
+ foreach ($regions as $regionId=>$regionName) {
30
+ $regionOptions[] = array('label'=>$regionName, 'value'=>$regionId);
31
+ }
32
+ $this->_options[] = array('label'=>$this->_countries[$countryId], 'value'=>$regionOptions);
33
+ }
34
+ }
35
+ $options = $this->_options;
36
+ if(!$isMultiselect){
37
+ array_unshift($options);
38
+ }
39
+
40
+ return $options;
41
+ }
42
+ }
app/code/local/VertexSMB/TaxCE/Model/Tax/Sales/Total/Quote/Tax.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class VertexSMB_TaxCE_Model_Tax_Sales_Total_Quote_Tax extends Mage_Tax_Model_Sales_Total_Quote_Tax {
5
+
6
+ /**
7
+ * Collect tax totals for quote address
8
+ *
9
+ * @param Mage_Sales_Model_Quote_Address $address
10
+ * @return Mage_Tax_Model_Sales_Total_Quote
11
+ */
12
+ public function collect(Mage_Sales_Model_Quote_Address $address)
13
+ {
14
+ if (!Mage::helper('taxce')->IsVertexActive()) {
15
+ parent::collect($address);
16
+ return $this;
17
+ }
18
+ /*Limit tax quote amounts*/
19
+ $address_type=$address->getAddressType();
20
+
21
+
22
+ if ($address->getQuote()->isVirtual() && $address_type=='shipping'){
23
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
24
+ Mage::log("Quote request was not sent. Address Type: ".$address_type.", Order is virtual. ", null, 'taxce.log');
25
+ return $this;
26
+ }
27
+ if (!$address->getQuote()->isVirtual() && !$address->getShippingMethod()) {
28
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
29
+ Mage::log("Quote request was not sent. Order is not virtual and doesnt have shipping address. ", null, 'taxce.log');
30
+ return $this;
31
+ }
32
+ /* Commented before */
33
+ /*if($address_type!=$based_on && ($address_type=='billing' && !$address->getQuote()->isVirtual()) ){
34
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
35
+ return $this;
36
+ } */
37
+ if ( !$address->getStreet1() && !Mage::helper('taxce')->AllowCartQuote() ) {
38
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
39
+ Mage::log("Quote request was not sent. Address Street not specified. ", null, 'taxce.log');
40
+ return $this;
41
+ }
42
+
43
+ if (!$address->getCountryId() || !$address->getRegionId() || !$address->getPostcode() || !count($address->getAllNonNominalItems())) {
44
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
45
+ Mage::log("Quote request was not sent. Address not specified. ", null, 'taxce.log');
46
+ return $this;
47
+ }
48
+
49
+ if (!$address->getTaxAreaId() && !Mage::helper('taxce')->AllowCartQuote()) {
50
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
51
+ Mage::log("Quote request was not sent. Address area id not specified yet. ", null, 'taxce.log');
52
+ return $this;
53
+ }
54
+
55
+ /*Vertex*/
56
+ if (!Mage::helper('taxce')->UpdateQuote($address)) {
57
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
58
+ Mage::log("Quote request was not sent. Items Information not changed. ", null, 'taxce.log');
59
+ return $this;
60
+ }
61
+ /*Vertex*/
62
+
63
+ Mage_Sales_Model_Quote_Address_Total_Abstract::collect($address);
64
+ $this->_roundingDeltas = array();
65
+ $this->_baseRoundingDeltas = array();
66
+ $this->_hiddenTaxes = array();
67
+ $address->setShippingTaxAmount(0);
68
+ $address->setBaseShippingTaxAmount(0);
69
+
70
+ $this->_store = $address->getQuote()->getStore();
71
+ $customer = $address->getQuote()->getCustomer();
72
+ if ($customer) {
73
+ $this->_calculator->setCustomer($customer);
74
+ }
75
+
76
+ if (!$address->getAppliedTaxesReset()) {
77
+ $address->setAppliedTaxes(array());
78
+ }
79
+
80
+ $items = $this->_getAddressItems($address);
81
+ if (!count($items)) {
82
+ return $this;
83
+ }
84
+
85
+ $request = new Varien_Object();
86
+ /* Removed to not match any of rules */
87
+ /* $request->setCountryId($address->getCountryId())
88
+ ->setRegionId($address->getRegionId())
89
+ ->setPostcode($address->getPostcode())
90
+ ->setStore($address->getQuote()->getStore())
91
+ ->setCustomerClassId($address->getQuote()->getCustomerTaxClassId());
92
+ */
93
+ if ($this->_config->priceIncludesTax($this->_store)) {
94
+ $this->_areTaxRequestsSimilar = $this->_calculator->compareRequests(
95
+ $this->_calculator->getRateOriginRequest($this->_store),
96
+ $request
97
+ );
98
+ }
99
+
100
+ $this->_rowBaseCalculation($address, $request);
101
+ $this->_addAmount($address->getExtraTaxAmount());
102
+ $this->_addBaseAmount($address->getBaseExtraTaxAmount());
103
+ /* Shipping Tax */
104
+ $this->_calculateShippingTax($address,$request);
105
+ /* Shipping Tax */
106
+
107
+ $this->_processHiddenTaxes();
108
+ //round total amounts in address
109
+ $this->_roundTotals($address);
110
+ return $this;
111
+ }
112
+
113
+
114
+ protected function _rowBaseCalculation(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
115
+ {
116
+ if (!Mage::helper('taxce')->IsVertexActive()) {
117
+ parent::_rowBaseCalculation( $address, $taxRateRequest);
118
+ return $this;
119
+ }
120
+
121
+ $items = $this->_getAddressItems($address);
122
+ $itemTaxGroups = array();
123
+
124
+ foreach ($items as $item) {
125
+ if ($item->getParentItem()) {
126
+ continue;
127
+ }
128
+ if ($item->getHasChildren() && $item->isChildrenCalculated()) {
129
+ foreach ($item->getChildren() as $child) {
130
+ $taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId());
131
+ $rate = $this->_calculator->getRate($taxRateRequest);
132
+ $this->_calcRowTaxAmount($child, $rate);
133
+ $this->_addAmount($child->getTaxAmount());
134
+ $this->_addBaseAmount($child->getBaseTaxAmount());
135
+ $applied = $this->_calculator->getAppliedRates($taxRateRequest);
136
+ if ($rate > 0) {
137
+ $itemTaxGroups[$child->getId()] = $applied;
138
+ }
139
+ $this->_saveAppliedTaxes(
140
+ $address,
141
+ $applied,
142
+ $child->getTaxAmount(),
143
+ $child->getBaseTaxAmount(),
144
+ $rate
145
+ );
146
+ $child->setTaxRates($applied);
147
+ }
148
+ $this->_recalculateParent($item);
149
+ }
150
+ else {
151
+ $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId());
152
+ $rate = $this->_calculator->getRate($taxRateRequest);
153
+ $this->_calcRowTaxAmount($item, $rate);
154
+ $this->_addAmount($item->getTaxAmount());
155
+ $this->_addBaseAmount($item->getBaseTaxAmount());
156
+ $applied = $this->_calculator->getAppliedRates($taxRateRequest);
157
+ if ($rate > 0) {
158
+ $itemTaxGroups[$item->getId()] = $applied;
159
+ }
160
+ $this->_saveAppliedTaxes(
161
+ $address,
162
+ $applied,
163
+ $item->getTaxAmount(),
164
+ $item->getBaseTaxAmount(),
165
+ $rate
166
+ );
167
+ $item->setTaxRates($applied);
168
+ }
169
+ }
170
+
171
+ if ($address->getQuote()->getTaxesForItems()) {
172
+ $itemTaxGroups += $address->getQuote()->getTaxesForItems();
173
+ }
174
+ $address->getQuote()->setTaxesForItems($itemTaxGroups);
175
+ return $this;
176
+ }
177
+
178
+
179
+ protected function _calcRowTaxAmount($item, $rate)
180
+ {
181
+ /* Vertex */
182
+ if (!Mage::helper('taxce')->IsVertexActive()) {
183
+ parent::_calcRowTaxAmount($item, $rate);
184
+ return $this;
185
+ }
186
+
187
+ $subtotal = $taxSubtotal = $item->getTaxableAmount();
188
+ $baseSubtotal = $baseTaxSubtotal = $item->getBaseTaxableAmount();
189
+
190
+ $ItemTax= Mage::helper('taxce')->getTaxByQuoteItemId($item->getId());
191
+ if ($ItemTax instanceof Varien_Object ){
192
+ $rowTax=$ItemTax->getTaxAmount();
193
+ $baseRowTax=$ItemTax->getBaseTaxAmount();
194
+ $rate=$ItemTax->getTaxPercent();
195
+
196
+ }else {
197
+ Mage::log("ItemTax is not instance of Varien_Object. ", null, 'taxce.log');
198
+ $rowTax=0;
199
+ $baseRowTax=0;
200
+ $rate=0;
201
+ }
202
+ /* Vertex */
203
+
204
+ $item->setTaxPercent($rate);
205
+ $item->setTaxAmount(max(0, $rowTax));
206
+ $item->setBaseTaxAmount(max(0, $baseRowTax));
207
+ $rowTotalInclTax = $item->getRowTotalInclTax();
208
+
209
+ if (!isset($rowTotalInclTax)) {
210
+ $weeeTaxBeforeDiscount = 0;
211
+ $baseWeeeTaxBeforeDiscount = 0;
212
+
213
+ if ($this->_config->priceIncludesTax($this->_store)) {
214
+ $item->setRowTotalInclTax($subtotal + $weeeTaxBeforeDiscount);
215
+ $item->setBaseRowTotalInclTax($baseSubtotal + $baseWeeeTaxBeforeDiscount);
216
+ } else {
217
+ $taxCompensation = $item->getDiscountTaxCompensation() ? $item->getDiscountTaxCompensation() : 0;
218
+ $item->setRowTotalInclTax($subtotal + $rowTax + $taxCompensation);
219
+ $item->setBaseRowTotalInclTax($baseSubtotal + $baseRowTax + $item->getBaseDiscountTaxCompensation());
220
+ }
221
+ }
222
+
223
+ return $this;
224
+ }
225
+
226
+ protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
227
+ {
228
+ if (!Mage::helper('taxce')->IsVertexActive()) {
229
+ parent::_calculateShippingTax($address, $taxRateRequest);
230
+ return $this;
231
+ }
232
+ $taxRateRequest->setProductClassId($this->_config->getShippingTaxClass($this->_store));
233
+ $shipping_tax=Mage::helper('taxce')->getTaxByQuoteItemId('shipping');
234
+ if ($shipping_tax instanceof Varien_Object ){
235
+ $tax=$shipping_tax->getTaxAmount();
236
+ $baseTax=$shipping_tax->getBaseTaxAmount();
237
+ $rate=$shipping_tax->getTaxPercent();
238
+ }else {
239
+ Mage::log("shipping_tax is not instance of Varien_Object. ", null, 'taxce.log');
240
+ $tax=0;
241
+ $baseTax=0;
242
+ $rate=0;
243
+ }
244
+ $this->_addAmount(max(0, $tax));
245
+ $this->_addBaseAmount(max(0, $baseTax));
246
+ $address->setShippingTaxAmount(max(0, $tax));
247
+ $address->setBaseShippingTaxAmount(max(0, $baseTax));
248
+
249
+
250
+
251
+ $applied = $this->_calculator->getAppliedRates($taxRateRequest);
252
+ $this->_saveAppliedTaxes($address, $applied, $tax, $baseTax, $rate);
253
+
254
+ return $this;
255
+ }
256
+
257
+ }
app/code/local/VertexSMB/TaxCE/Model/TaxInvoice.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Description of TaxInvoice
6
+ *
7
+ * @author alukyanau
8
+ */
9
+ class VertexSMB_TaxCE_Model_TaxInvoice extends Mage_Core_Model_Abstract {
10
+
11
+ public function _construct()
12
+ {
13
+ $this->_init('taxce/taxinvoice');
14
+ }
15
+
16
+ public function getHelper() {
17
+ return Mage::helper('taxce');
18
+ }
19
+
20
+ /* Prepare Invoice Request Data (Order|Invoice)
21
+ * @todo Add event names
22
+ *
23
+ */
24
+ public function PrepareInvoiceData($entity_item, $event=null){
25
+
26
+ $info=array();
27
+ $info=$this->getHelper()->AddSellerInformation($info);
28
+
29
+ if ($entity_item instanceof Mage_Sales_Model_Order) {
30
+ $order=$entity_item;
31
+ }elseif($entity_item instanceof Mage_Sales_Model_Order_Invoice) {
32
+ $order=$entity_item->getOrder();
33
+ }elseif($entity_item instanceof Mage_Sales_Model_Order_Creditmemo) {
34
+ $order=$entity_item->getOrder();
35
+ }
36
+ $info['order_id']=$order->getIncrementId();
37
+ $info['document_number']=$order->getIncrementId();
38
+ $info['document_date']=date("Y-m-d", strtotime($order->getCreatedAt()));
39
+ $info['posting_date']=date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
40
+
41
+ $customer_class = $this->getHelper()->TaxClassNameByCustomerGroupId($order->getCustomerGroupId());
42
+ $customer_code = $this->getHelper()->getCustomerCodeById($order->getCustomerId());
43
+
44
+ $info['customer_class']=$customer_class;
45
+ $info['customer_code']=$customer_code;
46
+
47
+ if ($order->getIsVirtual())
48
+ $address=$order->getBillingAddress();
49
+ else
50
+ $address=$order->getShippingAddress();
51
+
52
+ $info=$this->getHelper()->AddAddressInformation($info,$address);
53
+
54
+ /* Get Items Information*/
55
+ $order_items=array();
56
+ $ordered_items = $entity_item->getAllItems();
57
+
58
+ foreach($ordered_items as $item){
59
+ $original_item=$item;
60
+ if ($entity_item instanceof Mage_Sales_Model_Order_Invoice)
61
+ $item=$item->getOrderItem();
62
+ elseif ($entity_item instanceof Mage_Sales_Model_Order_Creditmemo)
63
+ $item=$item->getOrderItem();
64
+
65
+ if ($item->getParentItem())
66
+ continue;
67
+
68
+ if ($item->getHasChildren() && $item->getProduct()->getPriceType()!==null
69
+ && (int)$item->getProduct()->getPriceType()===Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD)
70
+ foreach ($item->getChildrenItems() as $child) {
71
+ if ( $entity_item instanceof Mage_Sales_Model_Order_Invoice || $entity_item instanceof Mage_Sales_Model_Order_Creditmemo ) {
72
+ $order_items[]=$this->getHelper()->PrepareItem($child,'invoiced',$original_item,$event);
73
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
74
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $child->getGwId())
75
+ $order_items[] = $this->getHelper()->PrepareGiftWrapItem($child,'invoiced',$original_item,$event);
76
+ }elseif ($entity_item instanceof Mage_Sales_Model_Order) {
77
+ $order_items[]=$this->getHelper()->PrepareItem($child,'ordered',$original_item,$event);
78
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
79
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $child->getGwId())
80
+ $order_items[] = $this->getHelper()->PrepareGiftWrapItem($child,'ordered',$original_item,$event);
81
+ }
82
+ }
83
+ else {
84
+ if ( $entity_item instanceof Mage_Sales_Model_Order_Invoice || $entity_item instanceof Mage_Sales_Model_Order_Creditmemo ) {
85
+ $order_items[]=$this->getHelper()->PrepareItem($item,'invoiced',$original_item,$event);
86
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
87
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $item->getGwId())
88
+ $order_items[] = $this->getHelper()->PrepareGiftWrapItem($item,'invoiced',$original_item,$event);
89
+ }elseif ($entity_item instanceof Mage_Sales_Model_Order) {
90
+ $order_items[]=$this->getHelper()->PrepareItem($item,'ordered',$original_item,$event);
91
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
92
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $item->getGwId())
93
+ $order_items[] = $this->getHelper()->PrepareGiftWrapItem($item,'ordered',$original_item,$event);
94
+ }
95
+ }
96
+ }
97
+
98
+ if (!$order->getIsVirtual() && count($this->getHelper()->AddShippingInfo($order,$entity_item,$event)))
99
+ $order_items[]=$this->getHelper()->AddShippingInfo($order,$entity_item,$event);
100
+
101
+ if ($entity_item instanceof Mage_Sales_Model_Order_Creditmemo )
102
+ $order_items=$this->getHelper()->AddRefundAdjustments($order_items,$entity_item);
103
+
104
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
105
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') ) {
106
+ if ($original_item->getGwPrice() && count($this->getHelper()->AddOrderGiftWrap($order,$entity_item,$event)))
107
+ $order_items[]=$this->getHelper()->AddOrderGiftWrap($order,$entity_item,$event);
108
+ if ($original_item->getGwCardPrice() && count($this->getHelper()->AddOrderPrintCard($order,$entity_item,$event)))
109
+ $order_items[]=$this->getHelper()->AddOrderPrintCard($order,$entity_item,$event);
110
+ }
111
+ /* Get Items Information*/
112
+ /* Making Request Array*/
113
+ $info['request_type']='InvoiceRequest';
114
+ $info['order_items']=$order_items;
115
+ $request=Mage::getModel('taxce/requestItem')->setData($info)->exportAsArray();
116
+
117
+ /* Making Request Array*/
118
+ return $request;
119
+ }
120
+
121
+ /* Invoice Request Preparation*/
122
+ public function SendInvoiceRequest($data,$order=null){
123
+ if ($order==null)
124
+ $order=Mage::registry('current_order');
125
+
126
+ $request_result=Mage::getModel('taxce/taxce')->SendApiRequest($data,$order,'invoice');
127
+ if ($request_result instanceof Exception) {
128
+ Mage::log("Invoice Request Error: ".$request_result->getMessage(), null, 'taxce.log');
129
+ Mage::getSingleton('adminhtml/session')->addError($request_result->getMessage());
130
+ return false;
131
+ }
132
+
133
+ $order->addStatusHistoryComment('Vertex Invoice sent successfully. Amount: $'.$request_result->InvoiceResponse->TotalTax->_, false)->save();
134
+ return true;
135
+ }
136
+
137
+ /* Cancel Request Preparation*/
138
+ public function SendCancelRequest($data,$order=null){
139
+ if ($order==null)
140
+ $order=Mage::registry('current_order');
141
+
142
+ $request_result=Mage::getModel('taxce/taxce')->SendApiRequest($data,$order,'invoice_cancel');
143
+ if ($request_result instanceof Exception) {
144
+ Mage::log("Cancel Request Error: ".$request_result->getMessage(), null, 'taxce.log');
145
+ Mage::getSingleton('adminhtml/session')->addError($request_result->getMessage());
146
+ return false;
147
+ }
148
+
149
+ $order->addStatusHistoryComment('Vertex Invoice canceled successfully. Amount: $'.$request_result->InvoiceResponse->TotalTax->_, false)->save();
150
+ return true;
151
+ }
152
+ /* Cancel Request Preparation*/
153
+ public function SendRefundRequest($data,$order=null){
154
+ if ($order==null)
155
+ $order=Mage::registry('current_order');
156
+ $request_result=Mage::getModel('taxce/taxce')->SendApiRequest($data,$order,'invoice_refund');
157
+ if ($request_result instanceof Exception) {
158
+ Mage::log("Refund Request Error: ".$request_result->getMessage(), null, 'taxce.log');
159
+ Mage::getSingleton('adminhtml/session')->addError($request_result->getMessage());
160
+ return false;
161
+ }
162
+ $order->addStatusHistoryComment('Vertex Invoice refunded successfully. Amount: $'.$request_result->InvoiceResponse->TotalTax->_, false)->save();
163
+ return true;
164
+ }
165
+
166
+
167
+ }
app/code/local/VertexSMB/TaxCE/Model/TaxQuote.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_TaxQuote extends Mage_Core_Model_Abstract {
4
+
5
+ private $_ItemsTaxLines=array();
6
+ private $_ItemsTaxQuoteId=array();
7
+
8
+ public function _construct()
9
+ {
10
+ $this->_init('taxce/taxquote');
11
+ }
12
+
13
+ public function getHelper() {
14
+ return Mage::helper('taxce');
15
+ }
16
+
17
+ public function getTaxQuote($information) {
18
+ $session=$this->getHelper()->getSession();
19
+ $this->_ItemsTaxQuoteId=array();
20
+ $this->_ItemsTaxLines=array();
21
+
22
+ /* Prevent multiple query when id updated */
23
+ if (!$information['tax_area_id'] && !$this->getHelper()->AllowCartQuote())
24
+ return false;
25
+ /* Automatically decide tax area id */
26
+
27
+ if ($this->getHelper()->getSourcePath()=='cart_checkout_index' || $this->getHelper()->getSourcePath()=='cart_checkout_couponPost') {
28
+ $information['tax_area_id']='';
29
+ $information['customer_street1']='';
30
+ $information['customer_street2']='';
31
+ }
32
+
33
+ /* Quotation Request Array*/
34
+ $information['request_type']='QuotationRequest';
35
+ $request=Mage::getModel('taxce/requestItem')->setData($information)->exportAsArray();
36
+ /* Quotation Request Array*/
37
+
38
+ /*Some special magic for quote*/
39
+ $i=1; /* lineItemNumber */
40
+ foreach($information['order_items'] as $key=>$item){
41
+ $item_tax_info=array();
42
+ $item_tax_info['lineItemNumber']=$i;
43
+ $item_tax_info['quote_item_id']=$key;
44
+ $this->_ItemsTaxLines[$i]= new Varien_Object($item_tax_info);
45
+ $i++;
46
+ }
47
+ /*Some special magic for quote*/
48
+
49
+
50
+ $tax_quote_result=Mage::getModel('taxce/taxce')->SendApiRequest($request,null,'quote');
51
+ if ($tax_quote_result instanceof Exception) {
52
+ /*@info error handles for different page types */
53
+ if (Mage::app()->getRequest()->getControllerName()=='onepage' || Mage::app()->getRequest()->getControllerName()=='sales_order_create') {
54
+ Mage::log("Quote Request Error: ".$tax_quote_result->getMessage()."Controller: ".$this->getHelper()->getSourcePath(), null, 'taxce.log');
55
+ $result=array('error' => 1, 'message' => "Tax Calculation Request Error. Please check your address");
56
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
57
+ exit();
58
+ }
59
+ if ($this->getHelper()->getSourcePath()=='cart_checkout_index' || $this->getHelper()->getSourcePath()=='cart_checkout_couponPost') {
60
+ $this->getHelper()->getSession()->setVertexTQ(0);
61
+ $this->getHelper()->getSession()->addError(Mage::helper('core')->escapeHtml("Tax Calculation Request Error. Please check your address"));
62
+ }
63
+ $session->setItemsTaxQuoteId();
64
+ return false;
65
+ }
66
+
67
+ if (is_array($tax_quote_result->QuotationResponse->LineItem))
68
+ $items_tax=$tax_quote_result->QuotationResponse->LineItem;
69
+ else
70
+ $items_tax[]=$tax_quote_result->QuotationResponse->LineItem;
71
+
72
+
73
+ foreach ($items_tax as $item) {
74
+ $lineItemNumber=$item->lineItemNumber;
75
+ $ItemTotaltax=$item->TotalTax->_;
76
+ /* SUMM Percents For Jurisdictions */
77
+ $TaxPercent=0;
78
+ foreach ($item->Taxes as $key=>$tax_value)
79
+ if ($key=="EffectiveRate")
80
+ $TaxPercent+=$tax_value;
81
+
82
+ $TaxPercent=$TaxPercent*100;
83
+
84
+ /* SUMM Percents For Jurisdictions */
85
+ $items_tax_lines_data=$this->_ItemsTaxLines[$lineItemNumber]->getData();
86
+ $items_tax_lines_data['tax_amount']=$ItemTotaltax;
87
+ $items_tax_lines_data['base_tax_amount']=$ItemTotaltax;
88
+ $items_tax_lines_data['tax_percent']=$TaxPercent;
89
+ $this->_ItemsTaxLines[$lineItemNumber]->setData($items_tax_lines_data);
90
+
91
+ $quote_item_id=$this->_ItemsTaxLines[$lineItemNumber]->getQuoteItemId();
92
+ $this->_ItemsTaxQuoteId[$quote_item_id]=$this->_ItemsTaxLines[$lineItemNumber];
93
+ }
94
+ $session->setItemsTaxQuoteId($this->_ItemsTaxQuoteId);
95
+ }
96
+
97
+ /* Collect Quote Information */
98
+ public function collectQuotedata(Mage_Sales_Model_Quote_Address $address) {
99
+
100
+ $information = array();
101
+ $information=$this->getHelper()->AddSellerInformation($information);
102
+
103
+ $customer_class_name =$this->getHelper()->TaxClassNameByClassId($address->getQuote()->getCustomerTaxClassId());
104
+ $customer_code = $this->getHelper()->getCustomerCodeById($address->getQuote()->getCustomer()->getId());
105
+
106
+ $information['customer_code'] = $customer_code;
107
+ $information['customer_class'] = $customer_class_name;
108
+
109
+ $information=$this->getHelper()->AddAddressInformation($information, $address);
110
+
111
+ $information['store_id'] = $address->getQuote()->getStore()->getId();
112
+ $date=date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
113
+ $information['posting_date']=$date;
114
+ $information['document_date']=$date;
115
+
116
+ $information['order_items'] = array();
117
+ $items = $address->getAllNonNominalItems();
118
+ foreach ($items as $item) {
119
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_CatalogPermissions' )
120
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_CatalogPermissions' )->is('active', 'true'))
121
+ if ($item->getDisableAddToCart() && !$item->isDeleted())
122
+ continue;
123
+
124
+ if ($item->getParentItem())
125
+ continue;
126
+
127
+ if ($item->getHasChildren() && $item->isChildrenCalculated()) {
128
+ foreach ($item->getChildren() as $child) {
129
+ $information['order_items'][$child->getId()] = $this->getHelper()->PrepareItem($child,'quote');
130
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
131
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $child->getGwId())
132
+ $information['order_items']['gift_wrap_'.$child->getId()] = $this->getHelper()->PrepareGiftWrapItem($child,'quote');
133
+ }
134
+ } else {
135
+ $information['order_items'][$item->getId()] = $this->getHelper()->PrepareItem($item,'quote');
136
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
137
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true') && $item->getGwId())
138
+ $information['order_items']['gift_wrap_'.$item->getId()] = $this->getHelper()->PrepareGiftWrapItem($item,'quote');
139
+ }
140
+ }
141
+ if(count($this->getHelper()->AddShippingInfo($address)))
142
+ $information['order_items']['shipping']=$this->getHelper()->AddShippingInfo($address);
143
+
144
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )
145
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_GiftWrapping' )->is('active', 'true')) {
146
+ if ($address->getGwPrice())
147
+ $information['order_items']['gift_wrapping']=$this->getHelper()->AddOrderGiftWrap($address);
148
+ if ($address->getGwCardPrice())
149
+ $information['order_items']['gift_print_card']=$this->getHelper()->AddOrderPrintCard($address);
150
+ }
151
+
152
+ /* return new Varien_Object($information); */
153
+ return $information;
154
+ }
155
+
156
+
157
+
158
+ }
app/code/local/VertexSMB/TaxCE/Model/TaxRequest.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VertexSMB_TaxCE_Model_TaxRequest extends Mage_Core_Model_Abstract {
4
+
5
+ public function _construct()
6
+ {
7
+ $this->_init('taxce/taxRequest');
8
+ }
9
+
10
+ public function getTotalInvoicedTax($orderId){
11
+ $TotalTax=0;
12
+ $invoices=$this->getCollection()->addFieldToSelect('total_tax')->addFieldToFilter('order_id',$orderId)->addFieldToFilter('request_type','invoice');
13
+ foreach ($invoices as $invoice) {
14
+
15
+ $TotalTax+=$invoice->getTotalTax();
16
+ }
17
+ return $TotalTax;
18
+ }
19
+
20
+ public function RemoveQuotesLookupRequests(){
21
+ $quotes=$this->getCollection()->addFieldToSelect('request_id')->addFieldToFilter('request_type',array('in'=>array('quote','tax_area_lookup')));
22
+
23
+ foreach ($quotes as $quote)
24
+ $quote->delete();
25
+
26
+ return $this;
27
+ }
28
+
29
+ public function RemoveInvoicesforCompletedOrders(){
30
+ $invoices=$this->getCollection()->addFieldToSelect('order_id')->addFieldToFilter('request_type','invoice');
31
+
32
+ $invoices->getSelect()->join( array('order'=> 'sales_flat_order'), 'order.entity_id = main_table.order_id', array('order.state'));
33
+ $invoices->addFieldToFilter('order.state',array('in'=>array('complete','canceled','closed')));
34
+
35
+ $completed_order_ids=array();
36
+ foreach ($invoices as $invoice)
37
+ $completed_order_ids[]=$invoice->getOrderId();
38
+
39
+ $completed_invoices=$this->getCollection()->addFieldToSelect('request_id')->addFieldToFilter('order_id',array('in'=>$completed_order_ids));
40
+ foreach ($completed_invoices as $completeted_invoice)
41
+ $completeted_invoice->delete();
42
+
43
+
44
+ return $this;
45
+ }
46
+ }
app/code/local/VertexSMB/TaxCE/Model/Taxce.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of Vertex
5
+ *
6
+ * @author alukyanau
7
+ */
8
+ class VertexSMB_TaxCE_Model_Taxce extends Mage_Core_Model_Abstract {
9
+
10
+ public function getHelper() {
11
+ return Mage::helper('taxce');
12
+ }
13
+
14
+ /* New Request Adapter */
15
+ public function SendApiRequest($request,$order=null, $type) {
16
+
17
+ $object_id=null;
18
+ if (strpos($type,'invoice')===0)
19
+ $object_id=$order->getId();
20
+ elseif ($type=='quote')
21
+ $object_id=$this->getHelper()->getSession()->getQuote()->getId();
22
+ elseif ($type=='tax_area_lookup'){
23
+ $object_id=0;
24
+ if (is_object($this->getHelper()->getSession()->getQuote()))
25
+ $object_id=$this->getHelper()->getSession()->getQuote()->getId();
26
+ }
27
+ try {
28
+ $api_url=$this->getHelper()->getVertexHost();
29
+ if ($type=='tax_area_lookup')
30
+ $api_url=$this->getHelper()->getVertexAddressHost();
31
+ $client = new SoapClient($api_url, array('connection_timeout' => 300,
32
+ 'trace' => true, 'soap_version' => SOAP_1_1));
33
+ if ($type=='tax_area_lookup')
34
+ $tax_request_result = $client->LookupTaxAreas60($request);
35
+ else
36
+ $tax_request_result = $client->calculateTax60($request);
37
+ } catch (Exception $e) {
38
+ if ($client)
39
+ $this->LogRequest($type,$object_id, $client->__getLastRequest(), $client->__getLastResponse());
40
+ else
41
+ $this->LogRequest($type,$object_id, $e->getMessage (), $e->getMessage ());
42
+ return $e;
43
+ }
44
+ $Total_Tax=0;
45
+ $tax_area_id=0;
46
+ if (strpos($type,'invoice')===0){
47
+ $Total_Tax=$tax_request_result->InvoiceResponse->TotalTax->_;
48
+ $line_item=$tax_request_result->InvoiceResponse->LineItem;
49
+ if (is_array($line_item))
50
+ $tax_area_id=$line_item[0]->Customer->Destination->taxAreaId;
51
+ else
52
+ $tax_area_id=$line_item->Customer->Destination->taxAreaId;
53
+ } elseif ($type=='quote') {
54
+ $Total_Tax=$tax_request_result->QuotationResponse->TotalTax->_;
55
+ $line_item=$tax_request_result->QuotationResponse->LineItem;
56
+ if (is_array($line_item))
57
+ $tax_area_id=$line_item[0]->Customer->Destination->taxAreaId;
58
+ else
59
+ $tax_area_id=$line_item->Customer->Destination->taxAreaId;
60
+ }elseif ($type=='tax_area_lookup') {
61
+ $tax_area_results=$tax_request_result->TaxAreaResponse->TaxAreaResult;
62
+ if (is_array($tax_area_results)) {
63
+ $tax_area_res_ids=array();
64
+ foreach ($tax_area_results as $tax_area_res) {
65
+ $tax_area_res_ids[]=$tax_area_res->taxAreaId;
66
+ }
67
+ $tax_area_id=implode(',',$tax_area_res_ids);
68
+ }else
69
+ $tax_area_id=$tax_area_results->taxAreaId;
70
+ }
71
+
72
+
73
+
74
+ $this->LogRequest($type, $object_id, $client->__getLastRequest(), $client->__getLastResponse(),$Total_Tax,$tax_area_id);
75
+
76
+ return $tax_request_result;
77
+
78
+ }
79
+
80
+ /* Log Save Logic*/
81
+ public function LogRequest($type,$object_id,$request_xml,$response_xml, $total_tax=0, $tax_area_id=0) {
82
+ $taxrequest = Mage::getModel('taxce/taxRequest');
83
+ $taxrequest->setRequestType($type)->setRequestDate(date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())));
84
+ if (strpos($type,'invoice')===0)
85
+ $taxrequest->setOrderId($object_id);
86
+ elseif ($type=='quote' || $type='tax_area_lookup')
87
+ $taxrequest->setQuoteId($object_id);
88
+
89
+
90
+ $source_path=$this->getHelper()->getSourcePath();
91
+ $taxrequest->setSourcePath($source_path);
92
+ $taxrequest->setTotalTax($total_tax);
93
+ $taxrequest->setRequestXml($request_xml);
94
+ $taxrequest->setResponseXml($response_xml);
95
+ $taxrequest->setTaxAreaId($tax_area_id);
96
+ $taxrequest->save();
97
+ Mage::log($taxrequest->getData(), null, 'taxce.log');
98
+ }
99
+
100
+ }
101
+
102
+
app/code/local/VertexSMB/TaxCE/controllers/OnepageController.php ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require Mage::getModuleDir('controllers', 'Mage_Checkout') . DS . 'OnepageController.php';
3
+ class VertexSMB_TaxCE_OnepageController extends Mage_Checkout_OnepageController {
4
+
5
+ /**
6
+ * Shipping address save action
7
+ */
8
+ public function saveShippingAction()
9
+ {
10
+ if (!Mage::helper('taxce')->IsVertexActive()) {
11
+ parent::saveShippingAction();
12
+ return $this;
13
+ }
14
+ if ($this->_expireAjax()) {
15
+ return;
16
+ }
17
+ if ($this->getRequest()->isPost()) {
18
+ $data = $this->getRequest()->getPost('shipping', array());
19
+ $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
20
+ $data['tax_area_id']="";
21
+ $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
22
+
23
+ /*taxce*/
24
+ $address=$this->getOnepage()->getQuote()->getShippingAddress();
25
+ $address->setTaxAreaId()->save();
26
+ if ($this->saveTaxAreaId($address)){
27
+ $result['goto_section'] = 'shipping_method';
28
+ $result['update_section'] = array(
29
+ 'name' => 'shipping-method',
30
+ 'html' => $this->_getShippingMethodsHtml()
31
+ );
32
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
33
+ }
34
+ }
35
+ }
36
+
37
+ public function saveBillingAction()
38
+ {
39
+ if (!Mage::helper('taxce')->IsVertexActive()) {
40
+ parent::saveBillingAction();
41
+ return $this;
42
+ }
43
+ if ($this->_expireAjax()) {
44
+ return;
45
+ }
46
+ if ($this->getRequest()->isPost()) {
47
+ $data = $this->getRequest()->getPost('billing', array());
48
+ $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
49
+
50
+ if (isset($data['email'])) {
51
+ $data['email'] = trim($data['email']);
52
+ }
53
+ $data['tax_area_id']="";
54
+ $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
55
+
56
+
57
+ $address=$this->getOnepage()->getQuote()->getBillingAddress();
58
+ $address->setTaxAreaId()->save();
59
+
60
+ $tax_area_result=true;
61
+ if (!isset($result['error'])) {
62
+ if ($this->getOnepage()->getQuote()->isVirtual()) {
63
+ $result['goto_section'] = 'payment';
64
+ $result['update_section'] = array(
65
+ 'name' => 'payment-method',
66
+ 'html' => $this->_getPaymentMethodsHtml()
67
+ );
68
+ $tax_area_result=$this->saveTaxAreaId($address);
69
+ } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
70
+ $tax_area_result=$this->saveTaxAreaId($address);
71
+
72
+ $result['goto_section'] = 'shipping_method';
73
+ $result['update_section'] = array(
74
+ 'name' => 'shipping-method',
75
+ 'html' => $this->_getShippingMethodsHtml()
76
+ );
77
+
78
+ $result['allow_sections'] = array('shipping');
79
+ $result['duplicateBillingInfo'] = 'true';
80
+ } else {
81
+ $result['goto_section'] = 'shipping';
82
+ }
83
+ }
84
+ if ($tax_area_result) {
85
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
86
+ }
87
+
88
+ }
89
+ }
90
+
91
+
92
+ public function saveTaxAreaAction()
93
+ {
94
+ if ($this->_expireAjax()) {
95
+ return;
96
+ }
97
+ if ($this->getRequest()->isPost()) {
98
+ $tax_area_id = $this->getRequest()->getPost('tax_area_id', 0);
99
+ $new_city = $this->getRequest()->getPost('tax_new_city', 0);
100
+
101
+
102
+
103
+ if ($this->getOnepage()->getQuote()->isVirtual()) {
104
+ $address=$this->getOnepage()->getQuote()->getBillingAddress();
105
+ $result['goto_section'] = 'payment';
106
+ $result['update_section'] = array(
107
+ 'name' => 'payment-method',
108
+ 'html' => $this->_getPaymentMethodsHtml()
109
+ );
110
+ $shipping_address=$this->getOnepage()->getQuote()->getShippingAddress();
111
+ $old_city=$shipping_address->getCity();
112
+ if (strtolower($old_city)!=strtolower($new_city))
113
+ $shipping_address->setCity($new_city);
114
+
115
+ $shipping_address->setTaxAreaId($tax_area_id)->save();
116
+ } else {
117
+ $address=$this->getOnepage()->getQuote()->getShippingAddress();
118
+ $result['goto_section'] = 'shipping_method';
119
+ $result['update_section'] = array(
120
+ 'name' => 'shipping-method',
121
+ 'html' => $this->_getShippingMethodsHtml()
122
+ );
123
+
124
+ $old_city=$address->getCity();
125
+ if (strtolower($old_city)!=strtolower($new_city))
126
+ $address->setCity($new_city);
127
+ }
128
+ $address->setTaxAreaId($tax_area_id)->save();
129
+ $this->getOnepage()->getQuote()->collectTotals()->save();
130
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
131
+ }
132
+ }
133
+
134
+ public function progressAction()
135
+ {
136
+ // previous step should never be null. We always start with billing and go forward
137
+ $prevStep = $this->getRequest()->getParam('prevStep', false);
138
+
139
+ if ($this->_expireAjax() || !$prevStep) {
140
+ return null;
141
+ }
142
+ if ($prevStep=='selectaddress')
143
+ $prevStep='shipping';
144
+
145
+ if ($prevStep=='selectaddress' && $this->getOnepage()->getQuote()->isVirtual())
146
+ $prevStep='billing';
147
+
148
+ $layout = $this->getLayout();
149
+ $update = $layout->getUpdate();
150
+ /* Load the block belonging to the current step*/
151
+ $update->load('checkout_onepage_progress_' . $prevStep);
152
+ $layout->generateXml();
153
+ $layout->generateBlocks();
154
+ $output = $layout->getOutput();
155
+ $this->getResponse()->setBody($output);
156
+ return $output;
157
+ }
158
+
159
+ public function saveTaxAreaId($address){
160
+ $request_result=Mage::Helper('taxce')->LookupAreaRequest($address);
161
+ if ($request_result instanceof Exception) {
162
+ Mage::log("Tax Area Lookup Error: ".$request_result->getMessage(), null, 'taxce.log');
163
+ if (Mage::app()->getRequest()->getControllerName()=='onepage' || Mage::app()->getRequest()->getControllerName()=='sales_order_create') {
164
+ Mage::log("Quote Request Error: ".$request_result->getMessage()."Controller: ".Mage::helper('taxce')->getSourcePath(), null, 'taxce.log');
165
+ $result=array('error' => 1, 'message' => "Tax Calculation Request Error. Please check your address");
166
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
167
+ exit();
168
+ }
169
+ if (Mage::helper('taxce')->getSourcePath()=='cart_checkout_index' || Mage::helper('taxce')->getSourcePath()=='cart_checkout_couponPost') {
170
+ Mage::helper('taxce')->getSession()->setVertexTQ(0);
171
+ Mage::helper('taxce')->getSession()->addError(Mage::helper('core')->escapeHtml("Tax Calculation Request Error. Please check your address"));
172
+ }
173
+ return false;
174
+ }
175
+
176
+ $tax_area_results=$request_result->TaxAreaResponse->TaxAreaResult;
177
+
178
+
179
+ if (is_array($tax_area_results) && Mage::helper('taxce')->ShowPopup()) {
180
+ $block=Mage::app()->getLayout()->createBlock('page/html')->setTemplate('taxce/popup-content.phtml')
181
+ ->setData('response',$request_result)->toHtml();
182
+ $result['goto_section'] = 'selectaddress';
183
+ $result['update_section'] = array(
184
+ 'name' => 'selectaddress',
185
+ 'html' => $block
186
+ );
187
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
188
+ return false;
189
+ } elseif(is_array($tax_area_results) && !Mage::helper('taxce')->ShowPopup()){
190
+ $tax_area_id=$tax_area_results[0]->taxAreaId;
191
+
192
+ $address->setTaxAreaId($tax_area_id)->save();
193
+ $this->getOnepage()->getQuote()->collectTotals()->save();
194
+ /* When tax_area_id stored replace */
195
+ if ($address->getAddressType()=='billing' && $this->getOnepage()->getQuote()->getShippingAddress()->getSameAsBilling())
196
+ $this->getOnepage()->getQuote()->getShippingAddress()->setTaxAreaId($tax_area_id)->save();
197
+ } else {
198
+ $tax_area_id=$request_result->TaxAreaResponse->TaxAreaResult->taxAreaId;
199
+
200
+ $address->setTaxAreaId($tax_area_id)->save();
201
+ $this->getOnepage()->getQuote()->collectTotals()->save();
202
+ /* When tax_area_id stored replace */
203
+ if ($address->getAddressType()=='billing' && $this->getOnepage()->getQuote()->getShippingAddress()->getSameAsBilling())
204
+ $this->getOnepage()->getQuote()->getShippingAddress()->setTaxAreaId($tax_area_id)->save();
205
+
206
+ /* Chack if city differs */
207
+ $address_changed=false;
208
+ if (strtolower($address->getCity())!=strtolower($request_result->TaxAreaResponse->TaxAreaResult->PostalAddress->City)) {
209
+ $old_city=$address->getCity();
210
+ $new_city=$request_result->TaxAreaResponse->TaxAreaResult->PostalAddress->City;
211
+ $address_changed=true;
212
+ }
213
+ /*Check if city differs */
214
+
215
+ if ($address_changed && !$this->getOnepage()->getQuote()->isVirtual()) {
216
+ $block=Mage::app()->getLayout()->createBlock('page/html')->setTemplate('taxce/addresschange-popup-content.phtml')
217
+ ->setOldCity($old_city)->setNewCity($new_city)->setTaxAreaId($tax_area_id)->toHtml();
218
+ $result['goto_section'] = 'selectaddress';
219
+ $result['update_section'] = array(
220
+ 'name' => 'selectaddress',
221
+ 'html' => $block
222
+ );
223
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
224
+ return false;
225
+ }
226
+ }
227
+ return true;
228
+ /*taxce*/
229
+ }
230
+ }
app/code/local/VertexSMB/TaxCE/controllers/TaxceController.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Description of Vertex
5
+ *
6
+ * @author alukyanau
7
+ */
8
+ class VertexSMB_TaxCE_TaxceController extends Mage_Adminhtml_Controller_Action {
9
+
10
+ protected function _construct() {
11
+ $this->setUsedModuleName('VertexSMB_TaxCE');
12
+ }
13
+
14
+ protected function _isAllowed() {
15
+ return Mage::getSingleton('admin/session')->isAllowed('sales/order/view');
16
+ }
17
+
18
+ /**
19
+ * Initialize order model instance
20
+ *
21
+ * @return Mage_Sales_Model_Order || false
22
+ */
23
+ protected function _initOrder()
24
+ {
25
+ $id = $this->getRequest()->getParam('order_id');
26
+ $order = Mage::getModel('sales/order')->load($id);
27
+
28
+ if (!$order->getId()) {
29
+ $this->_getSession()->addError($this->__('This order no longer exists.'));
30
+ $this->_redirect('*/*/');
31
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
32
+ return false;
33
+ }
34
+ Mage::register('sales_order', $order);
35
+ Mage::register('current_order', $order);
36
+ return $order;
37
+ }
38
+
39
+ public function InvoicetaxAction() {
40
+ if ($order = $this->_initOrder()) {
41
+ $invoice_request_data=Mage::getModel('taxce/taxInvoice')->PrepareInvoiceData($order);
42
+ if ($invoice_request_data && Mage::getModel('taxce/taxInvoice')->SendInvoiceRequest($invoice_request_data))
43
+ $this->_getSession()->addSuccess( $this->__('The Vertex invoice has been sent.'));
44
+ }
45
+ $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
46
+ }
47
+
48
+ public function TaxAreaAction(){
49
+ $orderCreateModel=Mage::getSingleton('adminhtml/sales_order_create');
50
+
51
+ if ($orderCreateModel->getQuote()->isVirtual() || $orderCreateModel->getQuote()->getShippingAddress()->getSameAsBilling() )
52
+ $address=$orderCreateModel->getQuote()->getBillingAddress();
53
+ else
54
+ $address=$orderCreateModel->getQuote()->getShippingAddress();
55
+
56
+ if (!$address->getStreet1() || !$address->getCity() || !$address->getRegion() || !$address->getPostcode() ) {
57
+ $result['message']='address not completed';
58
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
59
+ exit();
60
+ }
61
+
62
+ $order_post=$this->getRequest()->getPost('order');
63
+ /*if ( $address->getTaxAreaId() && !isset($order_post['billing_address']) && !isset($order_post['shipping_address']) ) {
64
+ $result['message']='address not changed';
65
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
66
+ exit();
67
+ } */
68
+
69
+ $request_result=Mage::Helper('taxce')->LookupAreaRequest($address);
70
+ if ($request_result instanceof Exception) {
71
+ Mage::log("Tax Area Lookup Error: ".$request_result->getMessage(), null, 'taxce.log');
72
+ $result['message'] = $request_result->getMessage();
73
+ }
74
+
75
+ $tax_area_results=$request_result->TaxAreaResponse->TaxAreaResult;
76
+ if (is_array($tax_area_results) && Mage::helper('taxce')->ShowPopup()) {
77
+ $block=Mage::app()->getLayout()->createBlock('page/html')->setTemplate('taxce/popup-content.phtml')
78
+ ->setData('response',$request_result)->toHtml();
79
+ $result['message'] ="show_popup";
80
+ $result['html'] =$block;
81
+ }elseif (is_array($tax_area_results) && !Mage::helper('taxce')->ShowPopup()) {
82
+ $tax_area_id=$tax_area_results[0]->taxAreaId;
83
+ $address->setTaxAreaId($tax_area_id);
84
+ $result['message']='tax_area_id_found';
85
+ $orderCreateModel->saveQuote();
86
+ }else {
87
+ $tax_area_id=$request_result->TaxAreaResponse->TaxAreaResult->taxAreaId;
88
+ $address->setTaxAreaId($tax_area_id);//->save();
89
+ $result['message']='tax_area_id_found';
90
+ /* Chack if city differs */
91
+ $address_changed=false;
92
+ if (strtolower($address->getCity())!=strtolower($request_result->TaxAreaResponse->TaxAreaResult->PostalAddress->City)) {
93
+ $old_city=$address->getCity();
94
+ $new_city=$request_result->TaxAreaResponse->TaxAreaResult->PostalAddress->City;
95
+ $address_changed=true;
96
+ }
97
+ /*Check if city differs */
98
+
99
+ if ($address_changed && !$address->getQuote()->isVirtual()) {
100
+ $block=Mage::app()->getLayout()->createBlock('page/html')->setTemplate('taxce/addresschange-popup-content.phtml')
101
+ ->setOldCity($old_city)->setNewCity($new_city)->setTaxAreaId($tax_area_id)->toHtml();
102
+ $result['message'] ="show_popup";
103
+ $result['html'] =$block;
104
+ }
105
+
106
+
107
+
108
+ /*$result['billing_address']=$address->getData();
109
+ $result['shipping_address']=$orderCreateModel->getQuote()->getShippingAddress()->getData();
110
+ $result['same_as_billing']=$orderCreateModel->getQuote()->getData();
111
+ */
112
+ $orderCreateModel->saveQuote();
113
+ }
114
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
115
+ exit();
116
+ }
117
+
118
+ public function saveTaxAreaAction() {
119
+ $orderCreateModel=Mage::getSingleton('adminhtml/sales_order_create');
120
+
121
+ if ($orderCreateModel->getQuote()->isVirtual() || $orderCreateModel->getQuote()->getShippingAddress()->getSameAsBilling() )
122
+ $address=$orderCreateModel->getQuote()->getBillingAddress();
123
+ else
124
+ $address=$orderCreateModel->getQuote()->getShippingAddress();
125
+
126
+ $tax_area_id=$this->getRequest()->getParam('tax_area_id');
127
+ $new_city = $this->getRequest()->getPost('new_city', 0);
128
+
129
+ $address->setTaxAreaId($tax_area_id);
130
+ $old_city=$address->getCity();
131
+ if (strtolower($old_city)!=strtolower($new_city))
132
+ $address->setCity($new_city);
133
+
134
+ $orderCreateModel->saveQuote();
135
+ $result['message']='ok';
136
+
137
+ echo Mage::app()->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
138
+ exit();
139
+ }
140
+
141
+ /**
142
+ * Retrieve adminhtml session model object
143
+ *
144
+ * @return Mage_Adminhtml_Model_Session
145
+ */
146
+ protected function _getSession()
147
+ {
148
+ return Mage::getSingleton('adminhtml/session');
149
+ }
150
+
151
+ }
app/code/local/VertexSMB/TaxCE/data/taxce_setup/data-install-0.1.1.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $data = array(
5
+ array(
6
+ 'class_name' => 'Refund Adjustments',
7
+ 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT
8
+ ),
9
+ array(
10
+ 'class_name' => 'Gift Options',
11
+ 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT
12
+ )
13
+ );
14
+
15
+
16
+ foreach ($data as $row) {
17
+ $installer->getConnection()->insertForce($installer->getTable('tax/tax_class'), $row);
18
+ }
19
+
app/code/local/VertexSMB/TaxCE/data/taxce_setup/data-upgrade-0.1.4-0.1.5.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $data = array(
5
+ array(
6
+ 'class_name' => 'Reward Points',
7
+ 'class_type' => Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT
8
+ )
9
+ );
10
+
11
+ if (Mage::getConfig ()->getModuleConfig ( 'Enterprise_Reward' )
12
+ && Mage::getConfig ()->getModuleConfig ( 'Enterprise_Reward' )->is('active', 'true')) {
13
+ foreach ($data as $row) {
14
+ $installer->getConnection()->insertForce($installer->getTable('tax/tax_class'), $row);
15
+ }
16
+ }
17
+
app/code/local/VertexSMB/TaxCE/etc/adminhtml.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <tax translate="title">
11
+ <title>Tax Section</title>
12
+ </tax>
13
+ </config>
14
+ </children>
15
+ </system>
16
+ </children>
17
+ </admin>
18
+ </resources>
19
+ </acl>
20
+ </config>
app/code/local/VertexSMB/TaxCE/etc/config.xml ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <VertexSMB_TaxCE>
5
+ <version>1.0.0</version>
6
+ </VertexSMB_TaxCE>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <taxce>
11
+ <class>VertexSMB_TaxCE_Block</class>
12
+ </taxce>
13
+ <adminhtml>
14
+ <rewrite>
15
+ <sales_order_view>VertexSMB_TaxCE_Block_Adminhtml_Order_View</sales_order_view>
16
+ </rewrite>
17
+ </adminhtml>
18
+ </blocks>
19
+ <models>
20
+ <taxce>
21
+ <class>VertexSMB_TaxCE_Model</class>
22
+ <resourceModel>taxce_resource</resourceModel>
23
+ </taxce>
24
+ <tax>
25
+ <rewrite>
26
+ <sales_total_quote_tax>VertexSMB_TaxCE_Model_Tax_Sales_Total_Quote_Tax</sales_total_quote_tax>
27
+ </rewrite>
28
+ </tax>
29
+ <taxce_resource>
30
+ <class>VertexSMB_TaxCE_Model_Resource</class>
31
+ <entities>
32
+ <taxrequest>
33
+ <table>taxce_taxrequest</table>
34
+ </taxrequest>
35
+ </entities>
36
+ </taxce_resource>
37
+ </models>
38
+ <helpers>
39
+ <taxce>
40
+ <class>VertexSMB_TaxCE_Helper</class>
41
+ </taxce>
42
+ </helpers>
43
+ <resources>
44
+ <taxce_setup>
45
+ <setup>
46
+ <module>VertexSMB_TaxCE</module>
47
+ <class>VertexSMB_TaxCE_Model_Resource_Setup</class>
48
+ </setup>
49
+ <connection>
50
+ <use>core_setup</use>
51
+ </connection>
52
+ </taxce_setup>
53
+ <taxce_write>
54
+ <connection>
55
+ <use>core_write</use>
56
+ </connection>
57
+ </taxce_write>
58
+ <taxce_read>
59
+ <connection>
60
+ <use>core_read</use>
61
+ </connection>
62
+ </taxce_read>
63
+ </resources>
64
+ <events>
65
+ <sales_order_invoice_save_after>
66
+ <observers>
67
+ <taxce_invoice_created_observer>
68
+ <type>singleton</type>
69
+ <class>VertexSMB_TaxCE_Model_Observer</class>
70
+ <method>InvoiceCreated</method>
71
+ </taxce_invoice_created_observer>
72
+ </observers>
73
+ </sales_order_invoice_save_after>
74
+ <sales_order_save_after>
75
+ <observers>
76
+ <taxce_order_saved_observer>
77
+ <type>singleton</type>
78
+ <class>VertexSMB_TaxCE_Model_Observer</class>
79
+ <method>OrderSaved</method>
80
+ </taxce_order_saved_observer>
81
+ </observers>
82
+ </sales_order_save_after>
83
+ <order_cancel_after>
84
+ <observers>
85
+ <taxce_order_cancel_observer>
86
+ <type>singleton</type>
87
+ <class>VertexSMB_TaxCE_Model_Observer</class>
88
+ <method>OrderCancelled</method>
89
+ </taxce_order_cancel_observer>
90
+ </observers>
91
+ </order_cancel_after>
92
+ <sales_order_creditmemo_refund>
93
+ <observers>
94
+ <taxce_order_creditmemo_observer>
95
+ <type>singleton</type>
96
+ <class>VertexSMB_TaxCE_Model_Observer</class>
97
+ <method>OrderCreditmemoRefund</method>
98
+ </taxce_order_creditmemo_observer>
99
+ </observers>
100
+ </sales_order_creditmemo_refund>
101
+ <adminhtml_init_system_config>
102
+ <observers>
103
+ <taxce_init_system_config>
104
+ <class>VertexSMB_TaxCE_Model_Observer</class>
105
+ <method>changeSystemConfig</method>
106
+ </taxce_init_system_config>
107
+ </observers>
108
+ </adminhtml_init_system_config>
109
+ </events>
110
+ <fieldsets>
111
+ <sales_convert_quote_address>
112
+ <tax_area_id>
113
+ <to_order_address>*</to_order_address>
114
+ </tax_area_id>
115
+ </sales_convert_quote_address>
116
+ </fieldsets>
117
+ </global>
118
+ <admin>
119
+ <routers>
120
+ <taxce>
121
+ <use>admin</use>
122
+ <args>
123
+ <module>VertexSMB_TaxCE</module>
124
+ <frontName>taxce</frontName>
125
+ </args>
126
+ </taxce>
127
+ <adminhtml>
128
+ <args>
129
+ <modules>
130
+ <VertexSMB_TaxCE before="Mage_Adminhtml">VertexSMB_TaxCE</VertexSMB_TaxCE>
131
+ </modules>
132
+ </args>
133
+ </adminhtml>
134
+ </routers>
135
+ </admin>
136
+ <adminhtml>
137
+ <layout>
138
+ <updates>
139
+ <taxce>
140
+ <file>taxce.xml</file>
141
+ </taxce>
142
+ </updates>
143
+ </layout>
144
+ </adminhtml>
145
+ <frontend>
146
+ <layout>
147
+ <updates>
148
+ <taxce>
149
+ <file>taxce.xml</file>
150
+ </taxce>
151
+ </updates>
152
+ </layout>
153
+ <routers>
154
+ <checkout>
155
+ <args>
156
+ <modules>
157
+ <VertexSMB_TaxCE before="Mage_Checkout">VertexSMB_TaxCE</VertexSMB_TaxCE>
158
+ </modules>
159
+ </args>
160
+ </checkout>
161
+ <taxce>
162
+ <use>standard</use>
163
+ <args>
164
+ <module>VertexSMB_TaxCE</module>
165
+ <frontName>taxce</frontName>
166
+ </args>
167
+ </taxce>
168
+ </routers>
169
+ </frontend>
170
+ <default>
171
+ <tax>
172
+ <taxce_settings>
173
+ <enable_taxce><![CDATA[0]]></enable_taxce>
174
+ <trustedId><![CDATA[]]></trustedId>
175
+ <invoice_order><![CDATA[invoice_created]]></invoice_order>
176
+ <api_url><![CDATA[]]></api_url>
177
+ <address_api_url><![CDATA[]]></address_api_url>
178
+ <show_manual_button><![CDATA[0]]></show_manual_button>
179
+ <show_tarequest_popup><![CDATA[1]]></show_tarequest_popup>
180
+ </taxce_settings>
181
+ <classes>
182
+ <default_customer_code><![CDATA[General]]></default_customer_code>
183
+ <creditmemo_adjustment_negative_code><![CDATA[adjustment-negative]]></creditmemo_adjustment_negative_code>
184
+ <creditmemo_adjustment_positive_code><![CDATA[adjustment-positive]]></creditmemo_adjustment_positive_code>
185
+ <giftwrap_order_code><![CDATA[order-gift-wrapping]]></giftwrap_order_code>
186
+ <giftwrap_item_code><![CDATA[giftwrap-]]></giftwrap_item_code>
187
+ <printed_giftcard_code><![CDATA[printed-giftcard]]></printed_giftcard_code>
188
+ </classes>
189
+ </tax>
190
+ </default>
191
+ <crontab>
192
+ <jobs>
193
+ <taxce_log_cleanup>
194
+ <schedule>
195
+ <cron_expr>00 2 * * *</cron_expr>
196
+ </schedule>
197
+ <run>
198
+ <model>taxce/observer::CleanLogs</model>
199
+ </run>
200
+ </taxce_log_cleanup>
201
+ </jobs>
202
+ </crontab>
203
+ </config>
204
+
205
+
app/code/local/VertexSMB/TaxCE/etc/system.xml ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <tax translate="label" module="tax">
5
+ <groups>
6
+ <taxce_settings translate="label">
7
+ <label>Vertex SMB Settings</label>
8
+ <sort_order>2</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <comment><![CDATA[<p class="switcher">You can find settings at <a href="https://csportal.vertexsmb.com/" target="_blank">Vertex SMB TaxCentral</a></p>]]></comment>
13
+ <fields>
14
+ <enable_taxce translate="label">
15
+ <label>Enable Vertex SMB Tax Calculation</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <comment><![CDATA[Enable/Disable Extension]]></comment>
19
+ <sort_order>10</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </enable_taxce>
24
+ <taxce_status translate="label">
25
+ <label>Vertex SMB API Status</label>
26
+ <frontend_type>text</frontend_type>
27
+ <frontend_model>taxce/adminhtml_system_config_form_field_taxceStatus</frontend_model>
28
+ <comment><![CDATA[API credentials status]]></comment>
29
+ <sort_order>10</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </taxce_status>
34
+ <api_url translate="label">
35
+ <label>Vertex SMB Calculation API Url</label>
36
+ <frontend_type>text</frontend_type>
37
+ <sort_order>15</sort_order>
38
+ <validate>required-entry</validate>
39
+ <depends>
40
+ <enable_taxce>1</enable_taxce>
41
+ </depends>
42
+ <comment><![CDATA[Vertex SMB Calculation API Url.]]></comment>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ </api_url>
47
+ <address_api_url translate="label">
48
+ <label>Vertex SMB Address Validation API Url</label>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>17</sort_order>
51
+ <validate>required-entry</validate>
52
+ <depends>
53
+ <enable_taxce>1</enable_taxce>
54
+ </depends>
55
+ <comment><![CDATA[Vertex SMB Address Validation API Url.]]></comment>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ </address_api_url>
60
+ <trustedId translate="label">
61
+ <label>Vertex SMB Trusted Id</label>
62
+ <frontend_type>text</frontend_type>
63
+ <sort_order>20</sort_order>
64
+ <validate>required-entry</validate>
65
+ <depends>
66
+ <enable_taxce>1</enable_taxce>
67
+ </depends>
68
+ <comment><![CDATA[An identifier supplied by an ERP.]]></comment>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>1</show_in_store>
72
+ </trustedId>
73
+ <invoice_order translate="label">
74
+ <label>Invoice Tax</label>
75
+ <source_model>taxce/source_taxinvoice</source_model>
76
+ <frontend_type>select</frontend_type>
77
+ <sort_order>40</sort_order>
78
+ <depends>
79
+ <enable_taxce>1</enable_taxce>
80
+ </depends>
81
+ <comment><![CDATA[Please select when tax should be invoiced to Vertex SMB]]></comment>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>1</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ </invoice_order>
86
+ <invoice_order_status translate="label">
87
+ <label>Invoice When Order Status</label>
88
+ <source_model>adminhtml/system_config_source_order_status</source_model>
89
+ <frontend_type>select</frontend_type>
90
+ <sort_order>50</sort_order>
91
+ <depends>
92
+ <enable_taxce>1</enable_taxce>
93
+ <invoice_order><![CDATA[order_status]]></invoice_order>
94
+ </depends>
95
+ <comment><![CDATA[Please select order status]]></comment>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ </invoice_order_status>
100
+ <allow_cart_request translate="label">
101
+ <label>Allow tax quote request at shopping cart page</label>
102
+ <source_model>adminhtml/system_config_source_yesno</source_model>
103
+ <frontend_type>select</frontend_type>
104
+ <sort_order>70</sort_order>
105
+ <depends>
106
+ <enable_taxce>1</enable_taxce>
107
+ </depends>
108
+ <comment><![CDATA[Allowing quote request on cart page may affect number of requests.]]></comment>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ </allow_cart_request>
113
+ <show_manual_button translate="label">
114
+ <label>Show Manual Invoice Button</label>
115
+ <source_model>adminhtml/system_config_source_yesno</source_model>
116
+ <frontend_type>select</frontend_type>
117
+ <sort_order>80</sort_order>
118
+ <depends>
119
+ <enable_taxce>1</enable_taxce>
120
+ </depends>
121
+ <comment><![CDATA[Enabeling this option may affect usual invoice workflow. Please use it only for debug/development purposes.]]></comment>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ </show_manual_button>
126
+ <show_tarequest_popup translate="label">
127
+ <label>Show Tax Jurisdiction(s) Popup</label>
128
+ <source_model>adminhtml/system_config_source_yesno</source_model>
129
+ <frontend_type>select</frontend_type>
130
+ <sort_order>100</sort_order>
131
+ <depends>
132
+ <enable_taxce>1</enable_taxce>
133
+ </depends>
134
+ <comment><![CDATA[Enable/Disable Tax Jurisdiction(s) popup window on checkout and admin create order page]]></comment>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </show_tarequest_popup>
139
+ </fields>
140
+ </taxce_settings>
141
+ <taxce_seller_info translate="label">
142
+ <label>Vertex SMB Company Information</label>
143
+ <sort_order>3</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ <fields>
148
+ <company translate="label">
149
+ <label>Company Code</label>
150
+ <frontend_type>text</frontend_type>
151
+ <sort_order>10</sort_order>
152
+ <comment><![CDATA[ The Vertex SMB TaxCentral user interface is used to set up any taxability rules that apply at this level. This should be a parameter that is configurable to data from the host system based on an individual company's legal and tax requirements.]]></comment>
153
+ <show_in_default>1</show_in_default>
154
+ <show_in_website>1</show_in_website>
155
+ <show_in_store>1</show_in_store>
156
+ </company>
157
+ <location_code translate="label">
158
+ <label>Location Code</label>
159
+ <frontend_type>text</frontend_type>
160
+ <sort_order>15</sort_order>
161
+ <comment><![CDATA[The locationCode attribute on the line item represents the store location code that is used for returns filing]]></comment>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>1</show_in_store>
165
+ </location_code>
166
+ <streetAddress1 translate="label">
167
+ <label>Company Street Address</label>
168
+ <frontend_type>text</frontend_type>
169
+ <sort_order>20</sort_order>
170
+ <comment><![CDATA[The first line of the street address.]]></comment>
171
+ <show_in_default>1</show_in_default>
172
+ <show_in_website>1</show_in_website>
173
+ <show_in_store>1</show_in_store>
174
+ </streetAddress1>
175
+ <streetAddress2 translate="label">
176
+ <label>Company Street Address 2</label>
177
+ <frontend_type>text</frontend_type>
178
+ <sort_order>30</sort_order>
179
+ <comment><![CDATA[The second line of the street address.]]></comment>
180
+ <show_in_default>1</show_in_default>
181
+ <show_in_website>1</show_in_website>
182
+ <show_in_store>1</show_in_store>
183
+ </streetAddress2>
184
+ <city translate="label">
185
+ <label>Company City</label>
186
+ <frontend_type>text</frontend_type>
187
+ <sort_order>40</sort_order>
188
+ <comment><![CDATA[The proper name of the city used to determine Tax Jurisdiction(s)]]></comment>
189
+ <show_in_default>1</show_in_default>
190
+ <show_in_website>1</show_in_website>
191
+ <show_in_store>1</show_in_store>
192
+ </city>
193
+ <region_id translate="label">
194
+ <label>Company State</label>
195
+ <frontend_type>select</frontend_type>
196
+ <source_model>taxce/source_usregions</source_model>
197
+ <sort_order>60</sort_order>
198
+ <comment><![CDATA[The proper name or the postal abbreviation of the state, province, or territory used to determine Tax Jurisdiction(s)]]></comment>
199
+ <show_in_default>1</show_in_default>
200
+ <show_in_website>1</show_in_website>
201
+ <show_in_store>1</show_in_store>
202
+ </region_id>
203
+ <postalCode translate="label">
204
+ <label>Company Postal Code</label>
205
+ <frontend_type>text</frontend_type>
206
+ <sort_order>70</sort_order>
207
+ <comment><![CDATA[The postal code used to determine Tax Jurisdiction(s)]]></comment>
208
+ <show_in_default>1</show_in_default>
209
+ <show_in_website>1</show_in_website>
210
+ <show_in_store>1</show_in_store>
211
+ </postalCode>
212
+ </fields>
213
+ </taxce_seller_info>
214
+ <avaiable_shipping_product_codes>
215
+ <label>Shipping Product Codes</label>
216
+ <sort_order>3</sort_order>
217
+ <show_in_default>1</show_in_default>
218
+ <show_in_website>1</show_in_website>
219
+ <show_in_store>1</show_in_store>
220
+ <comment><![CDATA[<p class="switcher">List of avaiable shipping methods for Vertex SMB TaxCentral mapping</p>]]></comment>
221
+ <fields>
222
+ <shipping_codes translate="label">
223
+ <frontend_type>text</frontend_type>
224
+ <frontend_model>taxce/adminhtml_system_config_form_field_shippingCodes</frontend_model>
225
+ <sort_order>10</sort_order>
226
+ <show_in_default>1</show_in_default>
227
+ <show_in_website>1</show_in_website>
228
+ <show_in_store>1</show_in_store>
229
+ </shipping_codes>
230
+ </fields>
231
+ </avaiable_shipping_product_codes>
232
+ <classes translate="label">>
233
+ <label> Vertex SMB Tax Classes</label>
234
+ <comment><![CDATA[<p class="switcher">You can manage customer and product tax classes at Sales->Tax menu</p>]]></comment>
235
+ <fields>
236
+ <default_customer_code>
237
+ <label>Default Customer Code</label>
238
+ <validate>required-entry</validate>
239
+ <frontend_type>text</frontend_type>
240
+ <sort_order>30</sort_order>
241
+ <comment><![CDATA[Customer code which will be used for unregistered users and for customers without customer code value]]></comment>
242
+ <show_in_default>1</show_in_default>
243
+ <show_in_website>1</show_in_website>
244
+ <show_in_store>1</show_in_store>
245
+ </default_customer_code>
246
+ <creditmemo_adjustment_class>
247
+ <label>Refund Adjustments Class</label>
248
+ <validate>required-entry</validate>
249
+ <frontend_type>select</frontend_type>
250
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
251
+ <sort_order>32</sort_order>
252
+ <comment><![CDATA[Class which will be used for creditmemo adjustments]]></comment>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_website>1</show_in_website>
255
+ <show_in_store>1</show_in_store>
256
+ </creditmemo_adjustment_class>
257
+ <creditmemo_adjustment_negative_code>
258
+ <label>Adjustment Fee Code</label>
259
+ <validate>required-entry</validate>
260
+ <frontend_type>text</frontend_type>
261
+ <sort_order>34</sort_order>
262
+ <comment><![CDATA[Product code which will be used for creditmemo adjustment fee]]></comment>
263
+ <show_in_default>1</show_in_default>
264
+ <show_in_website>1</show_in_website>
265
+ <show_in_store>1</show_in_store>
266
+ </creditmemo_adjustment_negative_code>
267
+ <creditmemo_adjustment_positive_code>
268
+ <label>Adjustment Refund Code</label>
269
+ <validate>required-entry</validate>
270
+ <frontend_type>text</frontend_type>
271
+ <sort_order>38</sort_order>
272
+ <comment><![CDATA[Product code which will be used for creditmemo adjustment]]></comment>
273
+ <show_in_default>1</show_in_default>
274
+ <show_in_website>1</show_in_website>
275
+ <show_in_store>1</show_in_store>
276
+ </creditmemo_adjustment_positive_code>
277
+ <giftwrap_order_class>
278
+ <label>Gift Wrap For Order Class</label>
279
+ <validate>required-entry</validate>
280
+ <frontend_type>select</frontend_type>
281
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
282
+ <sort_order>50</sort_order>
283
+ <comment><![CDATA[Product class which will be used for order gift wrap]]></comment>
284
+ <show_in_default>1</show_in_default>
285
+ <show_in_website>1</show_in_website>
286
+ <show_in_store>1</show_in_store>
287
+ </giftwrap_order_class>
288
+ <giftwrap_order_code>
289
+ <label>Gift Wrap For Order Code</label>
290
+ <validate>required-entry</validate>
291
+ <frontend_type>text</frontend_type>
292
+ <sort_order>60</sort_order>
293
+ <comment><![CDATA[Product code which will be used for order gift wrap]]></comment>
294
+ <show_in_default>1</show_in_default>
295
+ <show_in_website>1</show_in_website>
296
+ <show_in_store>1</show_in_store>
297
+ </giftwrap_order_code>
298
+ <giftwrap_item_class>
299
+ <label>Gift Wrap Class For Single Product</label>
300
+ <validate>required-entry</validate>
301
+ <frontend_type>select</frontend_type>
302
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
303
+ <sort_order>70</sort_order>
304
+ <comment><![CDATA[Class for gift wrap of single product]]></comment>
305
+ <show_in_default>1</show_in_default>
306
+ <show_in_website>1</show_in_website>
307
+ <show_in_store>1</show_in_store>
308
+ </giftwrap_item_class>
309
+ <giftwrap_item_code>
310
+ <label>Gift Wrap Code Prefix For Single Product</label>
311
+ <validate>required-entry</validate>
312
+ <frontend_type>text</frontend_type>
313
+ <sort_order>80</sort_order>
314
+ <comment><![CDATA[Prefix will be used for giftwrap item. Each code will be {{prefix}}-{{sku}}]]></comment>
315
+ <show_in_default>1</show_in_default>
316
+ <show_in_website>1</show_in_website>
317
+ <show_in_store>1</show_in_store>
318
+ </giftwrap_item_code>
319
+ <printed_giftcard_class>
320
+ <label>Item Line Class For Printed Gift Card</label>
321
+ <validate>required-entry</validate>
322
+ <frontend_type>select</frontend_type>
323
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
324
+ <sort_order>90</sort_order>
325
+ <comment><![CDATA[Product Class for printed giftcard line item]]></comment>
326
+ <show_in_default>1</show_in_default>
327
+ <show_in_website>1</show_in_website>
328
+ <show_in_store>1</show_in_store>
329
+ </printed_giftcard_class>
330
+ <printed_giftcard_code>
331
+ <label>Item Line Code For Printed Gift Card</label>
332
+ <validate>required-entry</validate>
333
+ <frontend_type>text</frontend_type>
334
+ <sort_order>100</sort_order>
335
+ <comment><![CDATA[Product code for printed giftcard line item]]></comment>
336
+ <show_in_default>1</show_in_default>
337
+ <show_in_website>1</show_in_website>
338
+ <show_in_store>1</show_in_store>
339
+ </printed_giftcard_code>
340
+ </fields>
341
+ </classes>
342
+ </groups>
343
+ </tax>
344
+ </sections>
345
+ </config>
app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-install-0.1.1.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ if ($installer->getConnection()->isTableExists($installer->getTable('taxce/taxrequest')) != true) {
5
+ /**
6
+ * Create table 'taxce/taxrequest'
7
+ */
8
+ $table = $installer->getConnection()
9
+ ->newTable($installer->getTable('taxce/taxrequest'))
10
+ ->addColumn('request_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
11
+ 'identity' => true,
12
+ 'nullable' => false,
13
+ 'primary' => true,
14
+ ), 'Request Id')
15
+ ->addColumn('request_type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
16
+ 'nullable' => false,
17
+ 'default' => NULL,
18
+ ), 'Request Type')
19
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
20
+ 'nullable' => false,
21
+ ), 'Quote Id')
22
+ ->addColumn('order_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
23
+ 'nullable' => false,
24
+ 'default' => 0,
25
+ ), 'Order Id')
26
+ ->addColumn('total_tax', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
27
+ 'nullable' => false,
28
+ 'default' => NULL,
29
+ ), 'Total Tax')
30
+ ->addColumn('request_date', Varien_Db_Ddl_Table::TYPE_DATETIME, 0, array(
31
+ 'nullable' => false
32
+ ), 'Request Date')
33
+ ->addColumn('request_xml', Varien_Db_Ddl_Table::TYPE_TEXT, 0, array(
34
+ 'nullable' => false,
35
+ 'default' => NULL,
36
+ ), 'Request XML')
37
+ ->addColumn('response_xml', Varien_Db_Ddl_Table::TYPE_TEXT, 0, array(
38
+ 'nullable' => false,
39
+ 'default' => NULL,
40
+ ), 'Response XML')
41
+ ->setComment('Log of requests to taxce');
42
+ $installer->getConnection()->createTable($table);
43
+ }
44
+ /*Customer Attribute*/
45
+ $entity = $this->getEntityTypeId('customer');
46
+ if(!$this->attributeExists($entity, 'customer_code'))
47
+ {
48
+ $this->addAttribute($entity, 'customer_code', array(
49
+ 'type' => 'text',
50
+ 'label' => 'Vertex SMB Customer Code',
51
+ 'input' => 'text',
52
+ 'visible' => TRUE,
53
+ 'required' => FALSE,
54
+ 'default_value' => '',
55
+ /* 'adminhtml_only' => '1',*/
56
+ 'user_defined' => true,
57
+ /* 'used_in_forms' => array('adminhtml_customer')*/
58
+ ));
59
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'customer_code');
60
+ $attribute->setData('used_in_forms', array('adminhtml_customer'))->save();
61
+ }
62
+
63
+ $this->endSetup();
app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.3-0.1.4.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ if ($installer->getConnection()->isTableExists($installer->getTable('taxce/taxrequest')) == true) {
7
+
8
+ $installer->getConnection()->addColumn($installer->getTable('taxce/taxrequest'),
9
+ 'source_path',
10
+ array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
12
+ 'nullable' => false,
13
+ 'default' => null,
14
+ 'length' => 255,
15
+ 'comment' => 'Source path controller_module_action'
16
+ )
17
+ );
18
+
19
+ }
20
+
21
+ $this->endSetup();
app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.6-0.1.7.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ if ($installer->getConnection()->isTableExists($installer->getTable('taxce/taxrequest')) == true) {
7
+
8
+ $installer->getConnection()->addColumn($installer->getTable('taxce/taxrequest'),
9
+ 'tax_area_id',
10
+ array(
11
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
12
+ 'nullable' => false,
13
+ 'default' => null,
14
+ 'length' => 255,
15
+ 'comment' => 'Tax Jurisdictions Id'
16
+ )
17
+ );
18
+
19
+ }
20
+
21
+ $this->endSetup();
app/code/local/VertexSMB/TaxCE/sql/taxce_setup/mysql4-upgrade-0.1.7-0.1.8.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+
7
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote_address'),
8
+ 'tax_area_id',
9
+ array(
10
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
11
+ 'nullable' => false,
12
+ 'default' => null,
13
+ 'length' => 255,
14
+ 'comment' => 'Tax Jurisdictions Id'
15
+ )
16
+ );
17
+
18
+
19
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_address'),
20
+ 'tax_area_id',
21
+ array(
22
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
23
+ 'nullable' => false,
24
+ 'default' => null,
25
+ 'length' => 255,
26
+ 'comment' => 'Tax Jurisdictions Id'
27
+ )
28
+ );
29
+
30
+ $this->endSetup();
app/design/adminhtml/default/default/layout/taxce.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_sales_order_create_index>
4
+ <update handle="taxce_popup" />
5
+ </adminhtml_sales_order_create_index>
6
+
7
+ <taxce_popup>
8
+ <reference name="before_body_end">
9
+ <block type="page/html" template="taxce/popup.phtml"/>
10
+ </reference>
11
+ </taxce_popup>
12
+ </layout>
app/design/adminhtml/default/default/template/taxce/addresschange-popup-content.phtml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $old_city = $this->getOldCity(); ?>
2
+ <?php $new_city = $this->getNewCity(); ?>
3
+ <?php $tax_area_id=$this->getTaxAreaId(); ?>
4
+ <div class="selectaddress-container step a-item" >
5
+ <div lass="col1-set">
6
+ <h3><?php echo $this->__('Your shipping address has been updated'); ?></h3>
7
+ <ul class="form-list">
8
+
9
+ <li class="control">
10
+ <label><?php echo $this->__('Original City: %s',ucwords(strtolower($old_city)) ); ?></label>
11
+ </li>
12
+ <li class="control">
13
+ <label><?php echo $this->__('Validated City: %s',ucwords(strtolower($new_city)) ); ?></label>
14
+ </li>
15
+ </ul>
16
+ <div class="buttons-set">
17
+ <p class="required">&nbsp;</p>
18
+ <button onclick="javascript:void(0);" class="button" type="button" id="select-tax-area-button"><span><span><?php echo $this->__('Continue'); ?></span></span></button>
19
+ </div>
20
+ </div>
21
+ </div>
22
+
23
+ <script type="text/javascript">
24
+ $("popup-shadow").style.height=$("html-body").getHeight()+'px';
25
+ $('select-tax-area-id').style.display = "block";
26
+ $('popup-shadow').style.display = "block";
27
+ $('select-tax-area-button').observe('click', select_address);
28
+
29
+ function select_address(){
30
+ var tax_area_id="<?php echo $tax_area_id ?>";
31
+ if (tax_area_id=="undefined" || tax_area_id.length==0) {
32
+ alert('Please change address');
33
+ return false;
34
+ }
35
+ var new_city="<?php echo $new_city; ?>";
36
+
37
+ $('select-tax-area-id').style.display = "none";
38
+ $('popup-shadow').style.display = "none";
39
+
40
+ var request = new Ajax.Request(
41
+ '<?php echo Mage::getUrl('taxce/taxce/saveTaxArea');?>' ,
42
+ {
43
+ method:'post',
44
+ onComplete: SelectAddressComplete,
45
+ parameters: {tax_area_id:tax_area_id, new_city:new_city},
46
+ }
47
+ );
48
+
49
+
50
+ }
51
+
52
+ function SelectAddressComplete(){
53
+ order.loadArea(['totals','shipping_address'], true, {} );
54
+ }
55
+
56
+ </script>
app/design/adminhtml/default/default/template/taxce/popup-content.phtml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $tax_area_responses = $this->getResponse(); ?>
2
+ <?php $tax_area_responses_array=$tax_area_responses->TaxAreaResponse->TaxAreaResult; ?>
3
+ <div class="selectaddress-container step a-item" >
4
+ <div lass="col1-set">
5
+
6
+ <h3><?php echo $this->__('Please verify your address'); ?></h3>
7
+ <ul class="form-list">
8
+ <li class="control"><?php echo $this->__('Your shipping address may be updated according to selection'); ?></li>
9
+ <?php foreach ($tax_area_responses_array as $tax_response): ?>
10
+ <li class="control">
11
+ <input type="radio" class="radio" id="tax_area_id_<?php echo $tax_response->taxAreaId; ?>" value="<?php echo $tax_response->taxAreaId; ?>" name="tax_area_id">
12
+ <?php
13
+ $tax_jurisdictions=$tax_response->Jurisdiction;
14
+ krsort($tax_jurisdictions);
15
+ $area_names=array();
16
+ foreach ($tax_jurisdictions as $area_jursdiction )
17
+ $area_names[]=$area_jursdiction->_;
18
+
19
+ $area_name=implode(', ', $area_names);
20
+ ?>
21
+ <label for="tax_area_id_<?php echo $tax_response->taxAreaId; ?>"><?php echo ucwords(strtolower($area_name)); ?></label>
22
+ <input type="hidden" name="city_<?php echo $tax_response->taxAreaId; ?>" id="tax_city_<?php echo $tax_response->taxAreaId; ?>" value="<?php echo $tax_response->PostalAddress->City; ?>" />
23
+ </li>
24
+ <?php endforeach; ?>
25
+ </ul>
26
+ <div class="buttons-set">
27
+ <p class="required">&nbsp;</p>
28
+ <button onclick="javascript:void(0);" class="button" type="button" id="select-tax-area-button"><span><span><?php echo $this->__('Continue'); ?></span></span></button>
29
+ </div>
30
+ </div>
31
+ </div>
32
+
33
+ <script type="text/javascript">
34
+ $("popup-shadow").style.height=$("html-body").getHeight()+'px';
35
+ $('select-tax-area-id').style.display = "block";
36
+ $('popup-shadow').style.display = "block";
37
+ $('select-tax-area-button').observe('click', select_address);
38
+
39
+ function select_address(){
40
+ var tax_area_id=$$('input:checked[type="radio"][name="tax_area_id"]').pluck('value');
41
+ if (tax_area_id=="undefined" || tax_area_id.length==0) {
42
+ alert('Please select address');
43
+ return false;
44
+ }
45
+ var new_city=$('tax_city_'+tax_area_id).value;
46
+
47
+ $('select-tax-area-id').style.display = "none";
48
+ $('popup-shadow').style.display = "none";
49
+
50
+
51
+ var request = new Ajax.Request(
52
+ '<?php echo Mage::getUrl('taxce/taxce/saveTaxArea');?>' ,
53
+ {
54
+ method:'post',
55
+ onComplete: SelectAddressComplete,
56
+ parameters: {tax_area_id:tax_area_id, new_city:new_city}
57
+ }
58
+ );
59
+ /* console.log(tax_area_id); */
60
+ }
61
+
62
+ function SelectAddressComplete(){
63
+ order.loadArea(['totals','shipping_address'], true, {} );
64
+ }
65
+
66
+ </script>
app/design/adminhtml/default/default/template/taxce/popup.phtml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (Mage::helper('taxce')->IsVertexActive()): ?>
2
+
3
+ <style>
4
+ .address-window {z-index:9999; background: #fff; position:absolute; width:500px; height:auto; border: 1px solid #ccc; top: 55%; left:30%; display:none; }
5
+ .selectaddress-container { margin:auto; padding: 25px;}
6
+ .selectaddress-container h3 {text-align:center;}
7
+ .selectaddress-container .form-list .control label, .selectaddress-container .form-list .control label:hover {background-color: #fff;}
8
+ .bg-shadow {z-index: 999; position: absolute; top: 0; width: 100%; height:100%; display:none; background-color: #000; opacity: 0.5;}
9
+ </style>
10
+
11
+ <div id="select-tax-area-id" class="popup address-window">
12
+ <div id="order-tax-area-load"></div>
13
+ </div>
14
+ <div id="popup-shadow" class="bg-shadow">&nbsp;</div>
15
+ <script type="text/javascript">
16
+
17
+ order.loadArea= function(area, indicator, params){
18
+ var url = this.loadBaseUrl;
19
+ if (area) {
20
+ area = this.prepareArea(area);
21
+ url += 'block/' + area;
22
+ }
23
+ if (indicator === true) indicator = 'html-body';
24
+ params = this.prepareParams(params);
25
+ params.json = true;
26
+ if (!this.loadingAreas) this.loadingAreas = [];
27
+
28
+ if (indicator) {
29
+ this.loadingAreas = area;
30
+
31
+ new Ajax.Request(url, {
32
+ parameters:params,
33
+ loaderArea: indicator,
34
+ onSuccess: function(transport) {
35
+ var response = transport.responseText.evalJSON();
36
+ this.loadAreaResponseHandler(response);
37
+
38
+ }.bind(this),
39
+
40
+ onComplete: function() {
41
+ console.log(params['order[billing_address][city]']);
42
+ if ( ( typeof area === 'string' && area!='header' && area!='totals' ) ||
43
+ ( typeof area === 'object' && area[0]!='totals' && area[0]!='header' ) ||
44
+ (typeof params['order[billing_address][city]']!='undefined' || typeof params['order[shipping_address][city]']!='undefined') )
45
+ getTaxAreaId(params);
46
+ }.bind(this),
47
+ });
48
+ }
49
+ else {
50
+ new Ajax.Request(url, {parameters:params,loaderArea: indicator,
51
+ onComplete: function() {
52
+
53
+ /* Add more handlers to update tax area depend of parameters shipping & billing*/
54
+ if ( ( typeof area === 'string' && area!='header' && area!='totals' ) ||
55
+ ( typeof area === 'object' && area[0]!='totals' && area[0]!='header' ) ||
56
+ (typeof params['order[billing_address][city]']!='undefined' || typeof params['order[shipping_address][city]']!='undefined') ) {
57
+ getTaxAreaId(params);
58
+ }
59
+ }.bind(this)
60
+ });
61
+
62
+
63
+ }
64
+ if (typeof productConfigure != 'undefined' && area instanceof Array && area.indexOf('items') != -1) {
65
+ productConfigure.clean('quote_items');
66
+ }
67
+ }
68
+
69
+
70
+ function getTaxAreaId(params){
71
+ var request = new Ajax.Request(
72
+ '<?php echo Mage::getUrl('*/taxce/TaxArea');?>' ,
73
+ {
74
+ method:'post',
75
+ /* onComplete: SelectAddressComplete, */
76
+ onSuccess: SelectAddressSucess,
77
+ parameters: params
78
+ }
79
+ );
80
+
81
+ }
82
+
83
+ function SelectAddressSucess(transport){
84
+
85
+ if (transport && transport.responseText){
86
+ try{
87
+ response = eval('(' + transport.responseText + ')');
88
+ }
89
+ catch (e) {
90
+ response = {};
91
+ }
92
+ }
93
+
94
+ if (response.error){
95
+ if ((typeof response.message) == 'string') {
96
+ alert(response.message);
97
+ } else {
98
+ alert(response.message.join("\n"));
99
+ }
100
+
101
+ return false;
102
+ }
103
+ if (response.message=='show_popup') {
104
+
105
+ $('order-tax-area-load').update(response.html);
106
+
107
+ } else {
108
+ order.loadArea(['totals','shipping_address'], true, {} );
109
+ }
110
+
111
+ }
112
+
113
+
114
+ </script>
115
+ <?php endif; ?>
app/design/frontend/base/default/layout/taxce.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_index>
4
+ <update handle="taxce_popup" />
5
+ </checkout_onepage_index>
6
+
7
+ <taxce_popup>
8
+ <reference name="before_body_end">
9
+ <block type="page/html" template="taxce/popup.phtml"/>
10
+ </reference>
11
+ </taxce_popup>
12
+ </layout>
app/design/frontend/base/default/template/taxce/addresschange-popup-content.phtml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $old_city = $this->getOldCity(); ?>
2
+ <?php $new_city = $this->getNewCity(); ?>
3
+ <?php $tax_area_id=$this->getTaxAreaId(); ?>
4
+ <div class="selectaddress-container step a-item" >
5
+ <div lass="col1-set">
6
+ <h3><?php echo $this->__('Your shipping address has been updated'); ?></h3>
7
+ <ul class="form-list">
8
+
9
+ <li class="control">
10
+ <label><?php echo $this->__('Original City: %s',ucwords(strtolower($old_city)) ); ?></label>
11
+ </li>
12
+ <li class="control">
13
+ <label><?php echo $this->__('Validated City: %s',ucwords(strtolower($new_city)) ); ?></label>
14
+ </li>
15
+ </ul>
16
+ <div class="buttons-set">
17
+ <p class="required">&nbsp;</p>
18
+ <button onclick="javascript:void(0);" class="button" type="button" id="onepage-select-tax-area-button"><span><span><?php echo $this->__('Continue'); ?></span></span></button>
19
+ </div>
20
+ </div>
21
+ </div>
22
+
23
+ <script type="text/javascript">
24
+
25
+ $('opc-selectaddress').style.display = "block";
26
+ $('popup-shadow').style.display = "block";
27
+ $('onepage-select-tax-area-button').observe('click', select_address);
28
+
29
+ function select_address(){
30
+ var tax_area_id="<?php echo $tax_area_id ?>";
31
+ if (tax_area_id=="undefined" || tax_area_id.length==0) {
32
+ alert('Please change address');
33
+ return false;
34
+ }
35
+ var new_city="<?php echo $new_city; ?>";
36
+
37
+ $('opc-selectaddress').style.display = "none";
38
+ $('popup-shadow').style.display = "none";
39
+ if ( typeof shipping !== 'undefined' ) {
40
+ var success_event=shipping;
41
+ var form_object=$('co-shipping-form');
42
+ }else {
43
+ var success_event=billing;
44
+ var form_object=$('co-billing-form');
45
+ }
46
+ form_object.innerHTML +='<input id="tax_area_id_el" type="hidden" name="tax_area_id" value="'+tax_area_id+'" />\n\
47
+ <input id="tax_new_city_el" type="hidden" name="tax_new_city" value="'+new_city+'" />';
48
+
49
+
50
+ var request = new Ajax.Request(
51
+ '<?php echo Mage::getUrl('checkout/onepage/saveTaxArea');?>' ,
52
+ {
53
+ method:'post',
54
+ onComplete: SelectAddressComplete,
55
+ onSuccess: success_event.onSave,
56
+ parameters: form_object.serialize(true)
57
+ }
58
+ );
59
+ console.log(tax_area_id);
60
+ }
61
+
62
+ function SelectAddressComplete(){
63
+ $('tax_area_id_el').remove();
64
+ $('tax_new_city_el').remove();
65
+ checkout.reloadProgressBlock('billing');
66
+ checkout.reloadProgressBlock('shipping');
67
+ checkout.reloadProgressBlock('shipping_method');
68
+ checkout.reloadProgressBlock('payment_method');
69
+ }
70
+
71
+ </script>
app/design/frontend/base/default/template/taxce/popup-content.phtml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $tax_area_responses = $this->getResponse(); ?>
2
+ <?php $tax_area_responses_array=$tax_area_responses->TaxAreaResponse->TaxAreaResult; ?>
3
+ <div class="selectaddress-container step a-item" >
4
+ <div lass="col1-set">
5
+
6
+ <h3><?php echo $this->__('Please verify your address'); ?></h3>
7
+ <ul class="form-list">
8
+ <li class="control"><?php echo $this->__('Your shipping address may be updated according to selection'); ?></li>
9
+ <?php foreach ($tax_area_responses_array as $tax_response): ?>
10
+ <li class="control">
11
+ <input type="radio" class="radio" id="tax_area_id_<?php echo $tax_response->taxAreaId; ?>" value="<?php echo $tax_response->taxAreaId; ?>" name="tax_area_id">
12
+ <?php
13
+ $tax_jurisdictions=$tax_response->Jurisdiction;
14
+ krsort($tax_jurisdictions);
15
+ $area_names=array();
16
+ foreach ($tax_jurisdictions as $area_jursdiction )
17
+ $area_names[]=$area_jursdiction->_;
18
+
19
+ $area_name=implode(', ', $area_names);
20
+ ?>
21
+ <label for="tax_area_id_<?php echo $tax_response->taxAreaId; ?>"><?php echo ucwords(strtolower($area_name)); ?></label>
22
+ <input type="hidden" name="city_<?php echo $tax_response->taxAreaId; ?>" id="tax_city_<?php echo $tax_response->taxAreaId; ?>" value="<?php echo $tax_response->PostalAddress->City; ?>" />
23
+ </li>
24
+ <?php endforeach; ?>
25
+ </ul>
26
+ <div class="buttons-set">
27
+ <p class="required">&nbsp;</p>
28
+ <button onclick="javascript:void(0);" class="button" type="button" id="onepage-select-tax-area-button"><span><span><?php echo $this->__('Continue'); ?></span></span></button>
29
+ </div>
30
+ </div>
31
+ </div>
32
+
33
+ <script type="text/javascript">
34
+
35
+ $('opc-selectaddress').style.display = "block";
36
+ $('popup-shadow').style.display = "block";
37
+ $('onepage-select-tax-area-button').observe('click', select_address);
38
+
39
+ function select_address(){
40
+ var tax_area_id=$$('input:checked[type="radio"][name="tax_area_id"]').pluck('value');
41
+ if (tax_area_id=="undefined" || tax_area_id.length==0) {
42
+ alert('Please select address');
43
+ return false;
44
+ }
45
+ var new_city=$('tax_city_'+tax_area_id).value;
46
+
47
+ $('opc-selectaddress').style.display = "none";
48
+ $('popup-shadow').style.display = "none";
49
+ if ( typeof shipping !== 'undefined' ) {
50
+ var success_event=shipping;
51
+ var form_object=$('co-shipping-form');
52
+ }else {
53
+ var success_event=billing;
54
+ var form_object=$('co-billing-form');
55
+ }
56
+ form_object.innerHTML +='<input id="tax_area_id_el" type="hidden" name="tax_area_id" value="'+tax_area_id+'" />\n\
57
+ <input id="tax_new_city_el" type="hidden" name="tax_new_city" value="'+new_city+'" />';
58
+
59
+
60
+ var request = new Ajax.Request(
61
+ '<?php echo Mage::getUrl('checkout/onepage/saveTaxArea');?>' ,
62
+ {
63
+ method:'post',
64
+ onComplete: SelectAddressComplete,
65
+ onSuccess: success_event.onSave,
66
+ parameters: form_object.serialize(true)
67
+ }
68
+ );
69
+ /* console.log(tax_area_id); */
70
+ }
71
+
72
+ function SelectAddressComplete(){
73
+ $('tax_area_id_el').remove();
74
+ $('tax_new_city_el').remove();
75
+ checkout.reloadProgressBlock('billing');
76
+ checkout.reloadProgressBlock('shipping');
77
+ checkout.reloadProgressBlock('shipping_method');
78
+ checkout.reloadProgressBlock('payment_method');
79
+ }
80
+
81
+ </script>
app/design/frontend/base/default/template/taxce/popup.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (Mage::helper('taxce')->IsVertexActive()): ?>
2
+ <style>
3
+ .address-window {z-index:9999; background: #fff; position:absolute; width:500px; height:auto; border: 1px solid #ccc; top: 40%; left:30%; display:none; }
4
+ .selectaddress-container { margin:auto; padding: 25px;}
5
+ .selectaddress-container h3 {text-align:center;}
6
+ .selectaddress-container .form-list .control label, .selectaddress-container .form-list .control label:hover {background-color: #fff;}
7
+ .bg-shadow {z-index: 999; position: absolute; top: 0; width: 100%; height:100%; display:none; background-color: #000; opacity: 0.5;}
8
+ </style>
9
+
10
+ <div id="opc-selectaddress" class="popup address-window">
11
+ <div id="checkout-selectaddress-load"></div>
12
+ </div>
13
+ <div id="popup-shadow" class="bg-shadow">&nbsp;</div>
14
+ <?php endif; ?>
app/etc/modules/VertexSMB_TaxCE.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <VertexSMB_TaxCE>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Core/>
9
+ <Mage_Tax/>
10
+ </depends>
11
+ </VertexSMB_TaxCE>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>VertexSMB_TaxCE</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/OSL-3.0">OSL 3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Sales and Use Tax Automation</summary>
10
+ <description>Built on industry-leading Vertex software, Vertex SMB offers a proven, accurate, and simple sales and use tax solution for small to medium-sized businesses that integrates directly with Magento. This cloud-based, scalable solution allows customers to manage complex sales and use tax across multiple jurisdictions and states. Vertex SMB runs on a pay-as-you-go pricing model with no upfront fees, and provides tax calculations and returns in one comprehensive solution, resulting in signature-ready PDF returns at no additional charge.</description>
11
+ <notes>Stable Release</notes>
12
+ <authors><author><name>Vertex SMB</name><user>VertexSMB</user><email>support@vertexSMB.com</email></author></authors>
13
+ <date>2015-04-16</date>
14
+ <time>17:43:00</time>
15
+ <contents><target name="magelocal"><dir name="VertexSMB"><dir name="TaxCE"><dir name="Block"><dir name="Adminhtml"><dir name="Order"><file name="View.php" hash="b37e3262da8f41c02171f6ca5d1d77ea"/></dir><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="ShippingCodes.php" hash="eda855c4d90812852de61f89bc0ef4ab"/><file name="TaxceStatus.php" hash="570af18ddcf08992578fb6db1142a4ca"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Config.php" hash="cebaba79d97ede017cc02b41b1980586"/><file name="Data.php" hash="81ad02510b2eff88c1596328ebee32d2"/></dir><dir name="Model"><file name="Observer.php" hash="7961fdb184e0eea76142e3776fb1a123"/><file name="RequestItem.php" hash="825fea8ce8a67cfad0990a17c4a28dfe"/><dir name="Resource"><file name="Setup.php" hash="2fae1030777ac63eb9505e6ffd100e57"/><dir name="TaxRequest"><file name="Collection.php" hash="1527070213a2f4d9d2878ad963151edb"/></dir><file name="TaxRequest.php" hash="46d2bdb0775fa082d8cd8a0a13305a97"/></dir><dir name="Source"><file name="Taxinvoice.php" hash="da4910b41e1a5489920d8fd5845b500e"/><file name="Usregions.php" hash="4e5fdea88b84099c9c092e6eb50a3257"/></dir><dir name="Tax"><dir name="Sales"><dir name="Total"><dir name="Quote"><file name="Tax.php" hash="c1d3112d1b9eeeb3325a46c43cfa7ec8"/></dir></dir></dir></dir><file name="TaxInvoice.php" hash="8f139674bb12e94f3b3b902036fe9c30"/><file name="TaxQuote.php" hash="37929aa298813e57da4b3103c16ab21b"/><file name="TaxRequest.php" hash="46dd8d84aa55c078dbf3e9bcbe317bc9"/><file name="Taxce.php" hash="31eb040c740787168b81493105de45e3"/></dir><dir name="controllers"><file name="OnepageController.php" hash="cef1529a439b7295a57079998cce9c6d"/><file name="TaxceController.php" hash="86ece29dba777c4b357b2087c8d56c94"/></dir><dir name="data"><dir name="taxce_setup"><file name="data-install-0.1.1.php" hash="88a2bebac3a6461479ce2d625ffde4eb"/><file name="data-upgrade-0.1.4-0.1.5.php" hash="71770296fd81b2dc0e3602d55e72ecea"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="174be75c93790e5f8a2ce7863f830b99"/><file name="config.xml" hash="9c0a6b7be4386da2fe02f102013b0268"/><file name="system.xml" hash="7039033a25516babe991e0682887cec4"/></dir><dir name="sql"><dir name="taxce_setup"><file name="mysql4-install-0.1.1.php" hash="5b34787cfa72b3b92d11c3a2fd6cd5bc"/><file name="mysql4-upgrade-0.1.3-0.1.4.php" hash="95ce569310af53c4c08fa6f7a1ff6d65"/><file name="mysql4-upgrade-0.1.6-0.1.7.php" hash="2cc8a2f38b5d497fe4f27a27306f5df0"/><file name="mysql4-upgrade-0.1.7-0.1.8.php" hash="cad743984e1845b2f400482a7ba5fa2a"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="VertexSMB_TaxCE.xml" hash="6320afa48760594e2077bdc27d00b87f"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="taxce.xml" hash="e7a7867f27a1823b0fe8b22fed312dd2"/></dir><dir name="template"><dir name="taxce"><file name="addresschange-popup-content.phtml" hash="9ed5b55d9f0914c2dbf0ef3a0d039573"/><file name="popup-content.phtml" hash="e88fdafe83564201a0f5b860c15e8adc"/><file name="popup.phtml" hash="9e14e0c03b3cd6719a06dba5e3324a1c"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="taxce.xml" hash="c071b9fc9fa7b281a05f957e3e3bebcf"/></dir><dir name="template"><dir name="taxce"><file name="addresschange-popup-content.phtml" hash="59cf0c14a93a179dfa4bfcb23f276222"/><file name="popup-content.phtml" hash="6fae518392ed3a5e9769045c567be7a8"/><file name="popup.phtml" hash="150df8f3b19e4e25d9ffc6a8aa344d70"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>