diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3657ca7f4b6..c3948126b3f 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -564,6 +564,27 @@ if (empty($reshook)) { $line = array('description' => $prod->description, 'price' => $price, 'tva_tx' => $tva_tx, 'locatax1_tx' => $localtax1_tx, 'locatax2_tx' => $localtax2_tx, 'remise_percent' => $customer->remise_percent, 'price_ttc' => $price_ttc, 'array_options' => $array_options); + /* setup of margin calculation */ + if (isset($conf->global->MARGIN_TYPE)) { + if ($conf->global->MARGIN_TYPE == 'pmp' && ! empty($prod->pmp)) { + $line['fk_fournprice'] = null; + $line['pa_ht'] = $prod->pmp; + } elseif ($conf->global->MARGIN_TYPE == 'costprice' && ! empty($prod->cost_price)) { + $line['fk_fournprice'] = null; + $line['pa_ht'] = $prod->cost_price; + } else { + // default is fournprice + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $pf = new ProductFournisseur($db); + if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) { + $line['fk_fournprice'] = $pf->product_fourn_price_id; + $line['pa_ht'] = $pf->fourn_unitprice_with_discount; + if ($pf->fourn_charges > 0) + $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty; + } + } + } + // complete line by hook $parameters = array('prod' => $prod, 'line' => $line); $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks @@ -575,7 +596,7 @@ if (empty($reshook)) { $line = $hookmanager->resArray; } - $idoflineadded = $invoice->addline($line['description'], $line['price'], $qty, $line['tva_tx'], $line['localtax1_tx'], $line['localtax2_tx'], $idproduct, $line['remise_percent'], '', 0, 0, 0, '', $price_base_type, $line['price_ttc'], $prod->type, -1, 0, '', 0, (!empty($parent_line)) ? $parent_line : '', null, '', '', $line['array_options'], 100, '', null, 0); + $idoflineadded = $invoice->addline($line['description'], $line['price'], $qty, $line['tva_tx'], $line['localtax1_tx'], $line['localtax2_tx'], $idproduct, $line['remise_percent'], '', 0, 0, 0, '', $price_base_type, $line['price_ttc'], $prod->type, -1, 0, '', 0, (!empty($parent_line)) ? $parent_line : '', $line['fk_fournprice'], $line['pa_ht'], '', $line['array_options'], 100, '', null, 0); } if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {