Created
January 13, 2013 18:13
-
-
Save clooth/4525373 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // VAT BREAKDOWN: | |
| $header = array( | |
| t('VAT -%'), | |
| t('Net'), | |
| t('VAT'), | |
| t('Gross'), | |
| ); | |
| // First, product: | |
| // $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item); | |
| // $price = $line_item_wrapper->commerce_total->value(); | |
| // $base_price = commerce_price_component_load($price, 'base_price'); | |
| // $tax = commerce_price_component_load($price, 'tax|vat'); | |
| $price = $order_wrapper->commerce_order_total->value(); | |
| $base_price = commerce_price_component_load($price, 'base_price'); | |
| $shipping = commerce_price_component_load($price, 'shipping'); | |
| // Get VAT: | |
| foreach(array('vat_deluxe', 'vat_food', 'vat_reduced') as $vat_type){ | |
| $vat = commerce_price_component_load($price, 'tax|'.$vat_type); | |
| // Only one kind of VAT is used: | |
| if($vat) break; | |
| } | |
| // $base_price = $base_price[0]['price']; | |
| $shipping = $shipping[0]['price']; | |
| $vat = $vat[0]['price']; | |
| // VAT calculation: | |
| $rows = array(); | |
| $row = array(); | |
| $total_without_vat = 0; | |
| $total_vat = 0; | |
| $total = 0; | |
| // First row: product | |
| $tax_rate = commerce_tax_rate_load($vat['data']['tax_rate']['name']); | |
| $tax_rate = $tax_rate['rate']*100; | |
| $row[] = $tax_rate.'%'; | |
| $total_without_vat += $price['amount'] - $vat['amount']; | |
| $total_vat += $vat['amount']; | |
| $total += $price['amount'] - $shipping['amount']; | |
| $row[] = commerce_currency_format($price['amount'] - $vat['amount'] - $shipping['amount'], $price['currency_code']); | |
| $row[] = commerce_currency_format($vat['amount'], $vat['currency_code']); | |
| $row[] = commerce_currency_format($price['amount'] - $shipping['amount'], $price['currency_code']); | |
| $rows[] = $row; | |
| $row = array(); | |
| // Second row: shipping: Always Deluxe VAT: | |
| $tax_rate = commerce_tax_rate_load('vat_deluxe'); | |
| $tax_rate = $tax_rate['rate']*100; | |
| $row[] = $tax_rate.'%'; | |
| // The price for shipping has the VAT included, so: | |
| // base_price = 100*total/(100 + VAT) | |
| $shipping_base = 100*$shipping['amount']/(100 + $tax_rate); | |
| $total_without_vat += $shipping_base; | |
| $total_vat += $shipping['amount'] - $shipping_base; | |
| $total += $shipping['amount']; | |
| $row[] = commerce_currency_format($shipping_base, $shipping['currency_code']); | |
| $row[] = commerce_currency_format($shipping['amount'] - $shipping_base, $shipping['currency_code']); | |
| $row[] = commerce_currency_format($shipping['amount'], $shipping['currency_code']); | |
| $rows[] = $row; | |
| $row = array(); | |
| //TOTAL: | |
| $row[] = t('Total'); | |
| $row[] = commerce_currency_format($total_without_vat, $price['currency_code']); | |
| $row[] = commerce_currency_format($total_vat, $price['currency_code']); | |
| $row[] = commerce_currency_format($total, $price['currency_code']); | |
| $rows[] = $row; | |
| $tax_breakdown = array( | |
| '#theme' => 'table', | |
| '#empty' => t('There is not any line'), | |
| '#header' => $header, | |
| '#rows' => $rows, | |
| ); | |
| $replacements['[order:summary]'] .= drupal_render($tax_breakdown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment