public function __construct($taxable) { $Tax = ShoppOrder()->Tax; $taxes = array(); $Tax->rates($taxes); $firstrate = reset($taxes); if ($firstrate) { $this->rate = $firstrate->rate; } $this->id = 'shipping'; $this->amount = ShoppTax::calculate($taxes, $taxable); $this->label = Shopp::__('Shipping Tax'); }
/** * Helper to apply or exclude taxes from a single amount based on inclusive tax settings and the tax option * * @author Jonathan Davis * @since 1.3 * * @param float $amount The amount to add taxes to, or exclude taxes from * @param ShoppProduct $O The product to get properties from * @param boolean $istaxed Whether the amount can be taxed * @param boolean $taxoption The Theme API tax option given the the tag * @param array $taxrates A list of taxrates that apply to the product and amount * @return float The amount with tax added or tax excluded **/ private static function _taxed($amount, ShoppProduct $O, $istaxed, $taxoption = null, array $taxrates = array()) { if (!$istaxed) { return $amount; } if (empty($taxrates)) { $taxrates = Shopp::taxrates($O); } if (isset($taxoption)) { $taxoption = Shopp::str_true($taxoption); } $inclusivetax = self::_inclusive_taxes($O); if ($inclusivetax) { $adjustment = ShoppTax::adjustment($taxrates); if (1 != $adjustment && false !== $taxoption) { // Only adjust when taxes are not excluded @see #3041 return (double) ($amount / $adjustment); } } // Handle inclusive/exclusive tax presentation options (product editor setting or api option) // If the 'taxes' option is specified and the item either has inclusive taxes that apply, // or the 'taxes' option is forced on (but not both) then handle taxes by either adding or excluding taxes // This is an exclusive or known as XOR, the lesser known brother of Thor that gets left out of the family get togethers if (isset($taxoption) && $inclusivetax ^ $taxoption) { if ($taxoption) { return ShoppTax::calculate($taxrates, (double) $amount); } else { return ShoppTax::exclusive($taxrates, (double) $amount); } } return $amount; }
/** * Calculate taxes that apply to the item * * @author Jonathan Davis * @since 1.3 * * @param integer $quantity The taxable quantity of items * @return void **/ public function taxes($quantity = 1) { if (!$this->istaxed) { return do_action('shopp_cart_item_taxes', $this); } $Tax = ShoppOrder()->Tax; if (empty($Tax)) { $Tax = new ShoppTax(); } // ShoppTax support for Dev API calls // For all the price units (base product and any addons), // distribute discounts across taxable amounts using weighted averages $_ = array(); if ($this->unitprice > 0) { $taxable = 0; foreach ($this->taxable as $amount) { $_[] = $amount - $amount / $this->unitprice * $this->discount; } } $taxable = (double) array_sum($_); $taxableqty = $this->bogof && $this->bogof != $this->quantity ? $this->quantity - $this->bogof : $this->quantity; $Tax->rates($this->taxes, $Tax->item($this)); $this->unittax = ShoppTax::calculate($this->taxes, $taxable); $this->tax = $Tax->total($this->taxes, (int) $taxableqty); // Handle inclusive tax price adjustments for non-EU markets or alternate tax rate markets $adjustment = ShoppTax::adjustment($this->taxes); if (1 != $adjustment) { if (!isset($this->taxprice)) { $this->taxprice = $this->unitprice; } // Modify the unitprice from the original tax inclusive price and update the discounted price $this->unitprice = $this->taxprice / $adjustment; $this->priced = $this->unitprice - $this->discount; } elseif (isset($this->taxprice)) { // Undo tax price adjustments $this->unitprice = $this->taxprice; unset($this->taxprice); } do_action('shopp_cart_item_taxes', $this); }
/** * Determines the effective tax rate (a single rate) for the store or an item based * * @author Jonathan Davis * @since 1.0 * @version 1.3 * * @param Object $Item (optional) The ShoppProduct, ShoppCartItem or ShoppPurchased object to find tax rates for * @return float The determined tax rate **/ public static function taxrate($Item = null) { $taxes = self::taxrates($Item); if (empty($taxes)) { $taxrate = 0.0; } // No rates given if (count($taxes) == 1) { $TaxRate = current($taxes); $taxrate = (double) $TaxRate->rate; // Use the given rate } else { $taxrate = (double) ShoppTax::calculate($taxes, 100) / 100; } // Calculate the "effective" rate (note: won't work with compound taxes) return apply_filters('shopp_taxrate', $taxrate); }