Come verificare le norme fiscali nella pagina della fattura di Prestashop 1.6
-
21-12-2019 - |
Domanda
Voglio controllare le norme fiscali di ciascun prodotto nella pagina della fattura.
Esiste una variabile che memorizza le regole fiscali come l'8% o il 18%?
Sarebbe qualcosa del genere
{if $order_invoice->tax_rule == "18%"}
...
{/if}
Soluzione
Controlla la variabile giusta
Non troverai questi dati in $order_invoice
.Se desideri ottenere le norme fiscali per ciascun prodotto, dovrai controllare il file $order_detail
var.Estratto da 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>
Puoi trovare l'aliquota fiscale in $order_detail.tax_rate
.Purtroppo ritorna sempre 0.000
.
SÌ...Questi dati non sono compilati...giornata triste...
Creare un OrderDetail
oltrepassare
Crea il OrderDetail.php
file nel override/classes/order/
cartella, contenente questo codice:
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;
}
}
Questa sostituzione ci consente di modificare il file tax_rate
valore.
Ho semplicemente aggiunto queste due righe nel file getProducts()
funzione :
foreach ($products as $row)
{
// Retrieve tax rate
$product = new Product($row['product_id']);
$row['tax_rate'] = $product->getTaxesRate();
// ...
}
Creare un OrderInvoice
oltrepassare
Crea il OrderInvoice.php
file nel override/classes/order/
cartella.
Questa classe conterrà lo stesso codice come il nostro precedente override.Basta cambiare le prime righe:
<?php
class OrderInvoice extends OrderInvoiceCore
{
// Copy/Paste the same code
}
E ora puoi visualizzare l'aliquota fiscale per ciascun prodotto, utilizzando {$order_detail.tax_rate}
!!
(Bonus) Modifica il tuo modello
Cambiamo questo modello (qui: pdf/invoice.tpl
) per aggiungere una colonna "Regola fiscale":
<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>
Altri suggerimenti
Penso che il modo corretto sia quello di sovrascrivere GetPriducts () Funzione in ordineVoice.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";
}
...
}
.
e il valore della velocità di utilizzo in .tpl
...
<td style="text-alig: right; width: 15%">{$order_detail.tax_rate_product}</td>
...
.
Ricordati di eliminare cache / class_index.php
Forse hai una regola fiscale del prodotto a seconda dell'indirizzo di spedizione.Prova
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))
...
.