diff --git a/uc_tax/config/schema/uc_tax.schema.yml b/uc_tax/config/schema/uc_tax.schema.yml index 07c2505..3dce03b 100644 --- a/uc_tax/config/schema/uc_tax.schema.yml +++ b/uc_tax/config/schema/uc_tax.schema.yml @@ -13,9 +13,6 @@ uc_tax.rate.*: weight: type: integer label: 'Relative weight' - jurisdiction: - type: string - label: 'Jurisdiction' shippable: type: boolean label: 'Shippable' @@ -53,6 +50,9 @@ tax_rate.settings.percentage_rate: rate: type: float label: 'Tax rate (per order rate)' + jurisdiction: + type: string + label: 'Tax jurisdiction' field: type: string label: 'Product field holding override values' diff --git a/uc_tax/src/Controller/TaxRateListBuilder.php b/uc_tax/src/Controller/TaxRateListBuilder.php index 82ae789..41589dc 100644 --- a/uc_tax/src/Controller/TaxRateListBuilder.php +++ b/uc_tax/src/Controller/TaxRateListBuilder.php @@ -22,7 +22,6 @@ class TaxRateListBuilder extends ConfigEntityListBuilder { public function buildHeader() { $header['label'] = $this->t('Name'); $header['rate'] = $this->t('Rate'); - $header['jurisdiction'] = $this->t('Jurisdiction'); $header['shippable'] = $this->t('Taxed products'); $header['product_types'] = $this->t('Taxed product types'); $header['line_item_types'] = $this->t('Taxed line items'); @@ -37,7 +36,6 @@ class TaxRateListBuilder extends ConfigEntityListBuilder { public function buildRow(EntityInterface $entity) { $row['label'] = $this->getLabel($entity); $row['rate'] = ((float) $entity->getRate() * 100) . '%' ; - $row['jurisdiction'] = $entity->getJurisdiction(); $row['shippable'] = $entity->isForShippable() ? $this->t('Shippable products') : $this->t('Any product'); $row['product_types'] = implode(', ', $entity->getProductTypes()); $row['line_item_types'] = implode(', ', $entity->getLineItemTypes()); diff --git a/uc_tax/src/Entity/TaxRate.php b/uc_tax/src/Entity/TaxRate.php index 997f018..6688ff7 100644 --- a/uc_tax/src/Entity/TaxRate.php +++ b/uc_tax/src/Entity/TaxRate.php @@ -34,7 +34,6 @@ use Drupal\uc_tax\TaxRateInterface; * "id", * "label", * "weight", - * "jurisdiction", * "shippable", * "display_include", * "inclusion_text", @@ -86,13 +85,6 @@ class TaxRate extends ConfigEntityBase implements TaxRateInterface { protected $weight = 0; /** - * The taxing authority jurisdiction. - * - * @var string - */ - protected $jurisdiction; - - /** * Whether to display prices including tax. * * @var bool @@ -189,21 +181,6 @@ class TaxRate extends ConfigEntityBase implements TaxRateInterface { /** * {@inheritdoc} */ - public function getJurisdiction() { - return $this->jurisdiction; - } - - /** - * {@inheritdoc} - */ - public function setJurisdiction($jurisdiction) { - $this->jurisdiction = $jurisdiction; - return $this; - } - - /** - * {@inheritdoc} - */ public function getProductTypes() { return $this->product_types; } @@ -291,4 +268,49 @@ class TaxRate extends ConfigEntityBase implements TaxRateInterface { return $this; } + /** + * {@inheritdoc} + */ + public function toLineItem() { + //@todo: needs work! +/* +$order->line_items = array( + line_item_id // primary key, serial + order_id + type // 'tax' or 'shipping', e.g. + title // label to show to customer + amount // $ amount. Where's the currency? + weight // sequence id + data => array('tax' = $rate) // ??? what's in here? +); +*/ +/* + $line_item = (object) array( + 'id' => $tax->id, + 'name' => $tax->name, + 'amount' => $amount, + 'weight' => $tax->weight, + 'summed' => 1, + ); +// These things should be dynamically generated +// by the plugin, not stored in the config entity + $line_item->data = array( + 'tax_rate' => $tax->rate, + 'tax' => $tax, + 'taxable_amount' => $taxable_amount, + 'tax_jurisdiction' => $tax->name, + ); +*/ + $line_item = array( + 'id' => ($this->summed ? 'tax' : 'tax_included'), + 'title' => !empty($this->label()) ? $this->label() : $this->id(), + 'amount' => $this->amount, + 'weight' => \Drupal::config('uc_tax.settings')->get('tax_line_item.weight') + $this->getWeight() / 10, + 'data' => isset($this->data) ? $this->data : array(), + ); + $line_item['data']['tax_id'] = $this->id(); + + return $line_item; + } + } diff --git a/uc_tax/src/Form/TaxRateForm.php b/uc_tax/src/Form/TaxRateForm.php index c9b1bc4..2d1e869 100644 --- a/uc_tax/src/Form/TaxRateForm.php +++ b/uc_tax/src/Form/TaxRateForm.php @@ -70,14 +70,6 @@ class TaxRateForm extends EntityForm { $form['settings'] = $this->plugin->buildConfigurationForm([], $form_state); $form['settings']['#tree'] = TRUE; - $form['jurisdiction'] = array( - '#type' => 'textfield', - '#title' => $this->t('Jurisdiction'), - '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), - '#default_value' => $this->entity->getJurisdiction(), - '#required' => FALSE, - ); - $form['shippable'] = array( '#type' => 'radios', '#title' => $this->t('Taxed products'), diff --git a/uc_tax/src/Form/TaxRateFormBase.php b/uc_tax/src/Form/TaxRateFormBase.php index f657f22..e402c12 100644 --- a/uc_tax/src/Form/TaxRateFormBase.php +++ b/uc_tax/src/Form/TaxRateFormBase.php @@ -62,14 +62,6 @@ class TaxRateFormBase extends EntityForm { '#required' => TRUE, ); - $form['jurisdiction'] = array( - '#type' => 'textfield', - '#title' => $this->t('Jurisdiction'), - '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), - '#default_value' => $rate->getJurisdiction(), - '#required' => FALSE, - ); - $form['shippable'] = array( '#type' => 'radios', '#title' => $this->t('Taxed products'), diff --git a/uc_tax/src/Plugin/Ubercart/TaxRate/PercentageTaxRate.php b/uc_tax/src/Plugin/Ubercart/TaxRate/PercentageTaxRate.php index b77cbd9..4500bca 100644 --- a/uc_tax/src/Plugin/Ubercart/TaxRate/PercentageTaxRate.php +++ b/uc_tax/src/Plugin/Ubercart/TaxRate/PercentageTaxRate.php @@ -29,6 +29,7 @@ class PercentageTaxRate extends TaxRatePluginBase { public function defaultConfiguration() { return array( 'rate' => 0, + 'jurisdiction' => '', 'field' => '', ); } @@ -55,6 +56,14 @@ class PercentageTaxRate extends TaxRatePluginBase { '#field_suffix' => $this->t('% (percent)'), '#required' => TRUE, ); + $form['jurisdiction'] = array( + '#type' => 'textfield', + '#title' => $this->t('Jurisdiction'), + '#description' => $this->t('Administrative label for the taxing authority, used to prepare reports of collected taxes.'), + '#default_value' => $this->configuration['jurisdiction'], + '#required' => FALSE, + ); + $form['field'] = array( '#type' => 'select', '#title' => $this->t('Tax rate override field'), @@ -85,6 +94,7 @@ class PercentageTaxRate extends TaxRatePluginBase { */ public function calculateTax(OrderInterface $order) { $rate = $this->configuration['rate']; + $jurisdiction = $this->configuration['jurisdiction']; $field = $this->configuration['field']; foreach ($order->products as $product) { diff --git a/uc_tax/src/TaxRateInterface.php b/uc_tax/src/TaxRateInterface.php index e056c8f..9f23a7e 100644 --- a/uc_tax/src/TaxRateInterface.php +++ b/uc_tax/src/TaxRateInterface.php @@ -48,38 +48,6 @@ interface TaxRateInterface extends ConfigEntityInterface { public function setLabel($label); /** - * The tax rate. - * - * @return float - */ - public function getRate(); - - /** - * The tax rate. - * - * @param float $rate - * - * @return $this - */ - public function setRate($rate); - - /** - * The taxing authority jurisdiction. - * - * @return string - */ - public function getJurisdiction(); - - /** - * The taxing authority jurisdiction. - * - * @param string $jurisdiction - * - * @return $this - */ - public function setJurisdiction($jurisdiction); - - /** * Product item types subject to this tax rate. * * @return array diff --git a/uc_tax/src/Tests/TaxRateUITest.php b/uc_tax/src/Tests/TaxRateUITest.php index b59c401..1e279a3 100644 --- a/uc_tax/src/Tests/TaxRateUITest.php +++ b/uc_tax/src/Tests/TaxRateUITest.php @@ -29,7 +29,7 @@ class TaxRateUITest extends TaxTestBase { $rate = array( 'label' => $this->randomMachineName(8), 'settings[rate]' => 20, - 'jurisdiction' => 'Uberland', + 'settings[jurisdiction]' => 'Uberland', 'shippable' => 0, 'product_types[product]' => 1, 'product_types[blank-line]' => 1,