diff -bduNr /home/klavs/drupal6/uc_vat-6.x-1.0/uc_vat.ca.inc uc_vat/uc_vat.ca.inc --- /home/klavs/drupal6/uc_vat-6.x-1.0/uc_vat.ca.inc 1970-01-01 01:00:00.000000000 +0100 +++ uc_vat/uc_vat.ca.inc 2010-02-25 11:16:47.000000000 +0100 @@ -0,0 +1,57 @@ + t("Check if an order's shipping country is inside EU"), + '#category' => t('Order: Shipping country'), + '#description' => t('Returns TRUE if the shipping country is inside EU.'), + '#callback' => 'uc_vat_condition_delivery_insideeu', + '#arguments' => array( + 'order' => array('#entity' => 'uc_order', '#title' => t('Order')), + ), + ); + return $conditions; +} + +/****************************************************************************** + * Condition Callbacks and Forms * + ******************************************************************************/ + + + +/** + * Check an order's delivery country. + * + * @see uc_vat_condition_delivery_insideeu_form() + */ +function uc_vat_condition_delivery_insideeu($order, $settings) { + return in_array($order->delivery_country, uc_vat_internal_eucountries()); +} + +/** + * @see uc_vat_condition_delivery_insideeu() + */ +function uc_vat_condition_delivery_insideeu_form($form_state, $settings = array()) { + $form['countries'] = uc_country_select(uc_get_field_name('country')); + $form['countries']['#default_value'] = uc_vat_internal_eucountries(); + $form['countries']['#multiple'] = TRUE; + // $form['countries']['#required'] = TRUE; + + return $form; +} + +#countries in EU - as of Februar 2010 +# 40 Austria, 56 Belgium, 100 Bulgaria, 203 Czech Republic, 208 Denmark, 233 Estonia, 246 Finland, +# 250 France, 276 Germany, 348 Hungary, 372 Ireland, 380 Italy, 428 Latvia, 440 Lithuania, 442 Luxemborg, +# 470 Malta, 528 Netherlands, 616 Poland, 620 Portugal, 642 Romania, 703 Slovakia, 705 Slevenia, 724 Spain, +# 752 Sweden, 826 United Kingdom, 300 Greece, 196 Cyprus +function uc_vat_internal_eucountries() { + return array("40", "56", "100", "196", "203", "208", "233", "246", "250", "276", "300", "348", "372", "380", "428", "440", "442", "470", "528", "616", "620", "642", "703", "705", "724", "752", "826"); +} diff -bduNr /home/klavs/drupal6/uc_vat-6.x-1.0/uc_vat.module uc_vat/uc_vat.module --- /home/klavs/drupal6/uc_vat-6.x-1.0/uc_vat.module 2009-10-14 14:28:20.000000000 +0200 +++ uc_vat/uc_vat.module 2010-02-25 13:06:01.000000000 +0100 @@ -8,6 +8,12 @@ return array('show prices excluding VAT'); } +function uc_vat_init() { + module_load_include('inc', 'uc_vat', 'uc_vat.ca'); + +} + + /** * Implementation of hook_menu(). */ @@ -85,7 +91,7 @@ if (uc_product_is_product_form($form)) { foreach (array('list_price', 'cost', 'sell_price') as $field) { $desc = substr($form['base']['prices'][$field]['#description'], 0, -1) .', '; - $desc .= variable_get('uc_vat_'. $field .'_inclusive', FALSE) ? t('including !tax.', array('!tax' => variable_get('uc_vat_name', 'VAT'))) : t('excluding !tax.', array('!tax' => variable_get('uc_vat_name', 'VAT'))); + $desc .= variable_get('uc_vat_'. $field .'_inclusive', FALSE) ? t('including !tax.', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))) : t('excluding !tax.', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))); $form['base']['prices'][$field]['#description'] = $desc; } } @@ -95,14 +101,14 @@ if (_uc_vat_attribute_fields()) { $form['vat_note'] = array( '#type' => 'markup', - '#value' => '
'. t('Prices shown here are exclusive of !tax. !tax will be added where applicable when these attributes are added to products.', array('!tax' => variable_get('uc_vat_name', 'VAT'))) .'
', + '#value' => ''. t('Prices shown here are exclusive of !tax. !tax will be added where applicable when these attributes are added to products.', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))) .'
', ); } } function uc_vat_form_uc_attribute_option_form_alter(&$form, $form_state) { if (_uc_vat_attribute_fields()) { - $form['adjustments']['#description'] .= ''. t('If the rate is changed, product and attribute prices will be recalculated, so !tax exclusive prices will change but !tax inclusive prices will stay the same. Visit the VAT settings page to change this behaviour.', array('!tax' => variable_get('uc_vat_name', 'VAT'), '!url' => url('admin/store/settings/taxes/vat'))) .'
', + '#value' => ''. t('If the rate is changed, product and attribute prices will be recalculated, so !tax exclusive prices will change but !tax inclusive prices will stay the same. Visit the VAT settings page to change this behaviour.', array('!tax' => t(variable_get('uc_vat_name', 'VAT')), '!url' => url('admin/store/settings/taxes/vat'))) .'
', '#weight' => -10, ); $form['#submit'][] = 'uc_vat_recalculate_prices'; } else { $form['recalculation_note'] = array( - '#value' => ''. t('If the rate is changed, product and attribute prices will not be recalculated, so !tax inclusive prices will change. Visit the VAT settings page to change this behaviour.', array('!tax' => variable_get('uc_vat_name', 'VAT'), '!url' => url('admin/store/settings/taxes/vat'))) .'
', + '#value' => ''. t('If the rate is changed, product and attribute prices will not be recalculated, so !tax inclusive prices will change. Visit the VAT settings page to change this behaviour.', array('!tax' => t(variable_get('uc_vat_name', 'VAT')), '!url' => url('admin/store/settings/taxes/vat'))) .'
', '#weight' => -10, ); } @@ -390,8 +396,39 @@ function uc_vat_product_price_alter(&$price, &$context, &$options, $tax_rates, $node) { $suffixes = array(); + //handle context types of "cart_item" and "product" as well + if ( $context['type'] == "product") { + #if no delivery country is set, or no order object - set a default one + if (!is_array($context['subject']['order'])) { + $context['subject']['order'] = new stdClass(); + } + if ($context['subject']['order']->delivery_country == '') { + #set visitors country from ip2cc module information + $addr = $_SERVER['REMOTE_ADDR']; + $addrl = ip2long($addr); + $valid = true; + #check for valid IP (ie. none-RFC1918) before trying to locate visitors country using ip2country module + $rfc1918 = array( + array('startip' => '192.168.0.0', 'endip' => '192.168.255.255'), + array( 'startip' => '172.16.0.0', 'endip' => '172.32.255.255'), + array( 'startip' => '10.0.0.0', 'endip' => '10.255.255.255') + ); + foreach ($rfc1918 as $ipr) { + if ($addrl >= ip2long($ipr['startip']) && $addrl <= ip2long($ipr['endip'])) + $valid = false; + } + + #if ip wasn't invalidated use that. otherwise use default country + if ($valid) { + $co = module_invoke('ip2cc', 'get_country', $addr); + $context['subject']['order']->delivery_country = $co->country_number; + } + else #no default country code is set in ubercart - needs to be fixed. 208 = denmark :) + $context['subject']['order']->delivery_country = '208'; + } + } // For ordered products, ignore any tax rules that fail the conditional actions tests. - if ($context['type'] == 'order_product') { + if ($context['type'] == 'order_product' || $context['type'] == "product") { $predicates = ca_load_trigger_predicates('calculate_taxes'); $arguments = array( 'order' => array( @@ -433,12 +470,14 @@ } else { $taxed_price = $price['price']; + //if ($context['type'] == "product") { foreach ($tax_rates as $tax) { if (in_array($node->type, $tax->taxed_product_types) && ($tax->shippable == 0 || $node->shippable == 1)) { $price['price'] += $taxed_price * $tax->rate; $suffixes[$tax->id] = $tax->name; } } + //} } if ($context['type'] == 'product') { @@ -447,7 +486,7 @@ $options['suffixes'][] = ' '. t('including !taxes', array('!taxes' => implode(', ', $suffixes))) .''; } else { - $options['suffixes'][] = ' '. t('excluding !tax', array('!tax' => variable_get('uc_vat_name', 'VAT'))) .''; + $options['suffixes'][] = ' '. t('excluding !tax', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))) .''; } } if (variable_get('uc_vat_suffix_shipping', FALSE) && $node->shippable) { @@ -547,14 +586,14 @@ case 'cart-preview': drupal_add_js("if (Drupal.jsEnabled) { \$(document).ready(function() { if (window.set_line_item) { - set_line_item('tax_subtotal', '". t('Subtotal excluding !tax', array('!tax' => variable_get('uc_vat_name', 'VAT'))) ."', ". $amount .", ". variable_get('uc_li_tax_subtotal_weight', 8) ."); + set_line_item('tax_subtotal', '". t('Subtotal excluding !tax', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))) ."', ". $amount .", ". variable_get('uc_li_tax_subtotal_weight', 8) ."); } })};", 'inline'); break; case 'load': return array(array( 'id' => 'tax_subtotal', - 'title' => t('Subtotal excluding !tax', array('!tax' => variable_get('uc_vat_name', 'VAT'))), + 'title' => t('Subtotal excluding !tax', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))), 'amount' => $amount, 'weight' => variable_get('uc_li_tax_subtotal_weight', 7), )); @@ -621,7 +660,7 @@ $taxes = uc_taxes_rate_load(); $subtotal = 0; - $tax_name = variable_get('uc_vat_name', 'VAT'); + $tax_name = t(variable_get('uc_vat_name', 'VAT')); if (count($taxes) == 1) { $tax = reset($taxes); $tax_name = $tax->name; @@ -636,8 +675,8 @@ $header[] = array('data' => t('incl. !tax', array('!tax' => $tax_name)), 'class' => 'price vat', 'style' => 'white-space: nowrap;'); } else { - $header[] = array('data' => t('Price excl. !tax', array('!tax' => variable_get('uc_vat_name', 'VAT'))), 'class' => 'price excl-vat', 'style' => 'white-space: nowrap;'); - $header[] = array('data' => $tax_name, 'class' => 'price vat'); + $header[] = array('data' => t('Price excl. !tax', array('!tax' => t(variable_get('uc_vat_name', 'VAT')))), 'class' => 'price excl-vat', 'style' => 'white-space: nowrap;'); + $header[] = array('data' => t("$tax_name"), 'class' => 'price vat'); } $header[] = array('data' => t('Price'), 'class' => 'price');