Cómo comprobar las reglas fiscales en la página de factura de Prestashop 1.6
-
21-12-2019 - |
Pregunta
Quiero verificar las reglas fiscales de cada producto en la página de factura.
¿Existe alguna variable que almacene reglas impositivas como el 8% o el 18%?
Seria algo asi
{if $order_invoice->tax_rule == "18%"}
...
{/if}
Solución
Verifique la variable correcta
No encontrarás estos datos en $order_invoice
.Si desea obtener reglas impositivas para cada producto, deberá verificar el $order_detail
var.Extraer de invoice.tpl
:
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Here we've got one line, for one product -->
<!-- This product's datas are stored in $order_detail -->
</tr>
Puede encontrar la tasa impositiva en $order_detail.tax_rate
.Desafortunadamente, siempre regresa. 0.000
.
Sí...Estos datos no están completos...día triste...
Crear un OrderDetail
anular
Crea el OrderDetail.php
archivo en el override/classes/order/
carpeta que contiene este código:
class OrderDetail extends OrderDetailCore
{
/**
* Get order products
*
* @return array Products with price, quantity (with taxe and without)
*/
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
{
if (!$products)
$products = $this->getProductsDetail();
$order = new Order($this->id_order);
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
$resultArray = array();
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// Change qty if selected
if ($selectedQty)
{
$row['product_quantity'] = 0;
foreach ($selectedProducts as $key => $id_product)
if ($row['id_order_detail'] == $id_product)
$row['product_quantity'] = (int)($selectedQty[$key]);
if (!$row['product_quantity'])
continue;
}
$this->setProductImageInformations($row);
$this->setProductCurrentStock($row);
$this->setProductCustomizedDatas($row, $customized_datas);
// Add information for virtual product
if ($row['download_hash'] && !empty($row['download_hash']))
{
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
// Get the display filename
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
}
$row['id_address_delivery'] = $order->id_address_delivery;
/* Stock product */
$resultArray[(int)$row['id_order_detail']] = $row;
}
if ($customized_datas)
Product::addCustomizationPrice($resultArray, $customized_datas);
return $resultArray;
}
}
Esta anulación nos permite editar el tax_rate
valor.
Simplemente agregué estas dos líneas en el getProducts()
función :
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// ...
}
Crear un OrderInvoice
anular
Crea el OrderInvoice.php
archivo en el override/classes/order/
carpeta.
Esta clase contendrá el mismo codigo como nuestra anulación anterior.Simplemente cambie las primeras líneas:
<?php
class OrderInvoice extends OrderInvoiceCore
{
// Copy/Paste the same code
}
Y ahora, puede mostrar la tasa impositiva para cada producto, usando {$order_detail.tax_rate}
!!
(Bonificación) Edita tu plantilla
Cambiemos esta plantilla (aquí: pdf/invoice.tpl
) para agregar una columna "Regla fiscal":
<tr style="line-height:4px;">
<!-- Remove 10% from the first column header width -->
<td style="text-align: left; background-color: #4D4D4D; color: #FFF; padding-left: 10px; font-weight: bold; width: {if !$tax_excluded_display}25%{else}35%{/if}">{l s='Product / Reference' pdf='true'}</td>
...
<!-- Add our new column header, 10% width -->
<td style="background-color: #4D4D4D; color: #FFF; text-align: right; font-weight: bold; width: 10%; white-space: nowrap;">{l s='Tax rate' pdf='true'}</td>
...
</tr>
<!-- PRODUCTS -->
{foreach $order_details as $order_detail}
{cycle values='#FFF,#DDD' assign=bgcolor}
<tr style="line-height:6px;background-color:{$bgcolor};">
<!-- Remove 10% from the first column width -->
<td style="text-align: left; width: {if !$tax_excluded_display}25%{else}35%{/if}">{$order_detail.product_name}{if isset($order_detail.product_reference) && !empty($order_detail.product_reference)} ({l s='Reference:' pdf='true'} {$order_detail.product_reference}){/if}</td>
...
<!-- Add our new column, 10% width -->
<td style="text-align: right; width: 10%; white-space: nowrap;">
{$order_detail.tax_rate}
</td>
...
</tr>
Otros consejos
Creo que la forma correcta es anular la función GETRPRIDUCTS () en ordenInvoice.php
foreach ($products as $row)
{
...
$sql = "SELECT tax.rate FROM ps_tax as tax join `ps_order_detail_tax` on ps_order_detail_tax.id_tax = tax.id_tax WHERE ps_order_detail_tax.id_order_detail = " .(int)$row['id_order_detail'] ;
$result = Db::getInstance()->executeS($sql);
$tmp = $result[0];
if (isset($tmp['rate'])){
$row['tax_rate_product'] = $tmp['rate'];
}
else { //No Tax
$row['tax_rate_product'] = "0.000";
}
...
}
y use el valor de la tasa en .tpl
...
<td style="text-alig: right; width: 15%">{$order_detail.tax_rate_product}</td>
...
Recuerde eliminar cache / class_index.php
Tal vez usted tiene una regla de impuesto sobre el producto según la dirección del envío.Prueba
foreach ($products as $row)
{
...
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate(new Address((int)$order->id_address_delivery))
...