diff --git uc_vat.admin.inc uc_vat.admin.inc index c1d0aa5..216aa84 100644 --- uc_vat.admin.inc +++ uc_vat.admin.inc @@ -39,24 +39,40 @@ function uc_vat_settings_form($form_state) { $form['edit'] = array( '#type' => 'fieldset', '#title' => t('Price editing options'), + '#collapsible' => TRUE, + ); + $form['edit']['prices'] = array( + '#type' => 'fieldset', + '#title' => t('Prices'), '#description' => t('Select the price fields below that you will enter inclusive of !tax.', array('!tax' => $tax)), '#collapsible' => TRUE, ); - $form['edit']['uc_vat_list_price_inclusive'] = array( + $form['edit']['prices']['uc_vat_list_price_inclusive'] = array( '#type' => 'checkbox', '#title' => t('List price'), '#default_value' => variable_get('uc_vat_list_price_inclusive', FALSE), ); - $form['edit']['uc_vat_cost_inclusive'] = array( + $form['edit']['prices']['uc_vat_cost_inclusive'] = array( '#type' => 'checkbox', '#title' => t('Cost'), '#default_value' => variable_get('uc_vat_cost_inclusive', FALSE), ); - $form['edit']['uc_vat_sell_price_inclusive'] = array( + $form['edit']['prices']['uc_vat_sell_price_inclusive'] = array( '#type' => 'checkbox', '#title' => t('Sell price'), '#default_value' => variable_get('uc_vat_sell_price_inclusive', FALSE), ); + $form['edit']['attributes'] = array( + '#type' => 'fieldset', + '#title' => t('Attributes'), + '#collapsible' => TRUE, + ); + $form['edit']['attributes']['uc_vat_default_attributes_inclusive'] = array( + '#type' => 'checkbox', + '#title' => t('Enter default attributes inclusive of !tax.', array('!tax' => $tax)), + '#description' => t('Only applicable if Cost and or Sell price are enabled as !tax inclusive above. This should only be enabled in stores where all products will be taxed at a single tax rate.', array('!tax' => $tax)), + '#default_value' => variable_get('uc_vat_default_attributes_inclusive', FALSE), + ); $form['checkout'] = array( '#type' => 'fieldset', diff --git uc_vat.install uc_vat.install index 65087c0..9463ede 100644 --- uc_vat.install +++ uc_vat.install @@ -2,6 +2,13 @@ // $Id: uc_vat.install,v 1.1 2009/10/05 15:34:08 longwave Exp $ /** + * Implementation of hook_uninstall(). + */ +function uc_vat_uninstall() { + db_query("DELETE FROM {variable} WHERE name LIKE 'uc_vat_%%'"); +} + +/** * Split "enter prices inclusive of VAT" option. */ function uc_vat_update_6000() { diff --git uc_vat.module uc_vat.module index 5ffb594..83e65b6 100644 --- uc_vat.module +++ uc_vat.module @@ -230,18 +230,104 @@ function _uc_vat_uc_order_edit_products_submit() { } } +/** + * Alter default attribute options overview form to add VAT if necessary. + */ function uc_vat_form_uc_attribute_options_form_alter(&$form, $form_state) { - if (_uc_vat_attribute_fields()) { + if ($fields = _uc_vat_attribute_fields()) { + if (variable_get('uc_vat_default_attributes_inclusive', FALSE)) { + $attribute = uc_attribute_load($form['aid']['#value']); + $context = array( + 'revision' => 'themed', + 'type' => 'attribute_option', + 'subject' => array( + 'attribute' => $attribute, + ), + ); + $taxes = uc_taxes_rate_load(); + + foreach ($attribute->options as $oid => $option) { + foreach ($fields as $field) { + $value = $option->$field; + // Apply all taxes as this is a default attribute and product type is + // not yet known. + foreach ($taxes as $tax) { + $value *= (1 + $tax->rate); + } + $context['subject']['option'] = $option; + $context['field'] = $field; + $form['options'][$oid][$field]['#value'] = uc_price($value, $context); + } + } + + $name = variable_get('uc_vat_name', 'VAT'); + $message = variable_get('uc_vat_cost_inclusive', FALSE) ? t('"Default cost" column includes !tax.', array('!tax' => $name)) : t('"Default cost" column excludes !tax.', array('!tax' => $name)); + $message .= ' '; + $message .= variable_get('uc_vat_sell_price_inclusive', FALSE) ? t('"Default price" column includes !tax.', array('!tax' => $name)) : t('"Default price" column excludes !tax.', array('!tax' => $name)); + } + + else { + $message = 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'))); + } + $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' => ''. $message .'
', ); } } +/** + * Alter default attribute options edit form to add VAT if necessary. + */ function uc_vat_form_uc_attribute_option_form_alter(&$form, $form_state) { - if (_uc_vat_attribute_fields()) { - $form['adjustments']['#description'] .= '