25 if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL',
'1');
28 if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31 if (!defined(
'NOREQUIREAJAX')) {
32 define(
'NOREQUIREAJAX',
'1');
34 if (!defined(
'NOREQUIRESOC')) {
35 define(
'NOREQUIRESOC',
'1');
38 require
'../../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
41 $idprod =
GETPOST(
'idprod',
'int');
46 $langs->loadLangs(array(
"stocks",
"margins",
"products"));
59 $producttmp->fetch($idprod);
61 $sorttouse =
's.nom, pfp.quantity, pfp.price';
62 if (
GETPOST(
'bestpricefirst')) {
63 $sorttouse =
'pfp.unitprice, s.nom, pfp.quantity, pfp.price';
66 $productSupplierArray = $producttmp->list_product_fournisseur_price($idprod, $sorttouse);
67 if (is_array($productSupplierArray)) {
68 foreach ($productSupplierArray as $productSupplier) {
69 $price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100);
70 $unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100);
72 $title = $productSupplier->fourn_name.
' - '.$productSupplier->fourn_ref.
' - ';
74 if ($productSupplier->fourn_qty == 1) {
75 $title .=
price($price, 0, $langs, 0, 0, -1, $conf->currency).
"/";
77 $title .= $productSupplier->fourn_qty.
' '.($productSupplier->fourn_qty == 1 ? $langs->trans(
"Unit") : $langs->trans(
"Units"));
79 if ($productSupplier->fourn_qty > 1) {
81 $title .=
price($unitprice, 0, $langs, 0, 0, -1, $conf->currency).
"/".$langs->trans(
"Unit");
85 $label =
price($price, 0, $langs, 0, 0, -1, $conf->currency).
"/".$langs->trans(
"Unit");
86 if ($productSupplier->fourn_ref) {
87 $label .=
' ('.$productSupplier->fourn_ref.
')';
90 $prices[] = array(
"id" => $productSupplier->product_fourn_price_id,
"price" =>
price2num($price, 0,
'', 0),
"label" => $label,
"title" => $title);
95 if (!empty($conf->stock->enabled)) {
97 $price = $producttmp->pmp;
98 if (empty($price) && !empty($conf->global->PRODUCT_USE_SUB_COST_PRICES_IF_COST_PRICE_EMPTY)) {
100 $producttmp->get_sousproduits_arbo();
101 $prods_arbo=$producttmp->get_arbo_each_prod();
102 if (!empty($prods_arbo)) {
104 foreach ($prods_arbo as $child) {
106 $sousprod->fetch($child[
'id']);
107 $price += $sousprod->pmp;
112 $prices[] = array(
"id" =>
'pmpprice',
"price" =>
price2num($price),
"label" => $langs->trans(
"PMPValueShort").
': '.
price($price, 0, $langs, 0, 0, -1, $conf->currency),
"title" => $langs->trans(
"PMPValueShort").
': '.
price($price, 0, $langs, 0, 0, -1, $conf->currency));
116 $price = $producttmp->cost_price;
117 if (empty($price) && ! empty($conf->global->PRODUCT_USE_SUB_COST_PRICES_IF_COST_PRICE_EMPTY)) {
119 $producttmp->get_sousproduits_arbo();
120 $prods_arbo=$producttmp->get_arbo_each_prod();
121 if (!empty($prods_arbo)) {
123 foreach ($prods_arbo as $child) {
125 $sousprod->fetch($child[
'id']);
126 $price += $sousprod->cost_price;
131 $prices[] = array(
"id" =>
'costprice',
"price" =>
price2num($price),
"label" => $langs->trans(
"CostPrice").
': '.
price($price, 0, $langs, 0, 0, -1, $conf->currency),
"title" => $langs->trans(
"PMPValueShort").
': '.
price($price, 0, $langs, 0, 0, -1, $conf->currency));
134 echo json_encode($prices);