Merge branch 'develop' into gli-2941

This commit is contained in:
amit sharma
2026-09-08 14:22:40 +05:30
147 changed files with 10256 additions and 409 deletions

View File

@@ -147,6 +147,28 @@ class OrderInvoiceCore extends ObjectModel
'.($this->id && $this->number ? ' AND od.`id_order_invoice` = '.(int)$this->id : '').' ORDER BY od.`product_name`');
}
/**
* Recompute this invoice's totals live from its own order_detail lines, instead of trusting
* accumulated deltas. Mirrors Order::getOrderTotal()'s formula, scoped to this invoice only.
*
* @return bool
*/
public function recomputeTotalsFromLines()
{
$order = new Order((int) $this->id_order);
$invoiceProducts = $this->getProductsDetail();
$totalProductsTe = $order->getTotalProductsWithoutTaxes($invoiceProducts);
$totalProductsTi = $order->getTotalProductsWithTaxes($invoiceProducts);
$this->total_products = $totalProductsTe;
$this->total_products_wt = $totalProductsTi;
$this->total_paid_tax_excl = max(0, $totalProductsTe + $this->total_shipping_tax_excl + $this->total_wrapping_tax_excl - $this->total_discount_tax_excl);
$this->total_paid_tax_incl = max(0, $totalProductsTi + $this->total_shipping_tax_incl + $this->total_wrapping_tax_incl - $this->total_discount_tax_incl);
return $this->update();
}
public static function getInvoiceByNumber($id_invoice)
{
if (is_numeric($id_invoice)) {
@@ -323,11 +345,12 @@ class OrderInvoiceCore extends ObjectModel
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
FROM `' . _DB_PREFIX_ . 'order_detail_tax` odt
FROM `' . _DB_PREFIX_ . 'order_tax_detail` odt
LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = ' . (int) $this->id_order . '
AND od.`id_order_invoice` = ' . (int) $this->id . '
AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD)
AND od.`tax_computation_method` = ' . (int) TaxCalculator::ONE_AFTER_ANOTHER_METHOD . '
AND NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'tax` tc WHERE tc.`id_tax` = odt.`id_tax` AND tc.`is_tourism_tax` = 1)')
|| Configuration::get('PS_INVOICE_TAXES_BREAKDOWN');
}
@@ -797,6 +820,28 @@ class OrderInvoiceCore extends ObjectModel
return $wrapping_breakdown;
}
/**
* Return tourism tax breakdown grouped by id_tax for invoice display. Collapsed into a single
* combined row when the invoice's tax breakdown display is off — same rule every other tax
* category (rooms, services, ...) already applies via useOneAfterAnotherTaxComputationMethod().
*
* @return array [['tax_name' => string, 'total_amount' => float], ...]
*/
public function getTourismTaxBreakdown()
{
$breakdown = OrderTaxDetail::getBreakdownForInvoice((int) $this->id_order);
if (!$breakdown || $this->useOneAfterAnotherTaxComputationMethod()) {
return $breakdown;
}
$total = 0.0;
foreach ($breakdown as $row) {
$total += (float) $row['total_amount'];
}
return array(array('id_tax' => 0, 'tax_name' => '', 'total_amount' => $total));
}
/**
* Returns the ecotax taxes breakdown
*