dolibarr  7.0.0-beta
getSupplierPrices.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
3  * Copyright (C) 2015 Francis Appels <francis.appels@z-application.com>
4  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
26 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
27 //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
28 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
29 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
30 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
31 
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
34 
35 $idprod=GETPOST('idprod','int');
36 
37 $prices = array();
38 
39 $langs->load('stocks');
40 $langs->load('margins');
41 
42 
43 /*
44  * View
45  */
46 
47 top_httphead();
48 
49 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
50 
51 if ($idprod > 0)
52 {
53  $producttmp=new ProductFournisseur($db);
54  $producttmp->fetch($idprod);
55 
56  $sorttouse = 's.nom, pfp.quantity, pfp.price';
57  if (GETPOST('bestpricefirst')) $sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price';
58 
59  $productSupplierArray = $producttmp->list_product_fournisseur_price($idprod, $sorttouse); // We list all price per supplier, and then firstly with the lower quantity. So we can choose first one with enough quantity into list.
60  if ( is_array($productSupplierArray))
61  {
62  foreach ($productSupplierArray as $productSupplier)
63  {
64  $price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100);
65  $unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100);
66 
67  $title = $productSupplier->fourn_name.' - '.$productSupplier->fourn_ref.' - ';
68 
69  if ($productSupplier->fourn_qty == 1)
70  {
71  $title.= price($price,0,$langs,0,0,-1,$conf->currency)."/";
72  }
73  $title.= $productSupplier->fourn_qty.' '.($productSupplier->fourn_qty == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
74 
75  if ($productSupplier->fourn_qty > 1)
76  {
77  $title.=" - ";
78  $title.= price($unitprice,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
79  $price = $unitprice;
80  }
81 
82  $label = price($price,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
83  if ($productSupplier->fourn_ref) $label.=' ('.$productSupplier->fourn_ref.')';
84 
85  $prices[] = array("id" => $productSupplier->product_fourn_price_id, "price" => price2num($price,0,'',0), "label" => $label, "title" => $title); // For price field, we must use price2num(), for label or title, price()
86  }
87  }
88 
89  // Add price for costprice
90  $price=$producttmp->cost_price;
91  $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)); // For price field, we must use price2num(), for label or title, price()
92 
93  if(!empty($conf->stock->enabled))
94  {
95  // Add price for pmp
96  $price=$producttmp->pmp;
97  $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)); // For price field, we must use price2num(), for label or title, price()
98  }
99 }
100 
101 echo json_encode($prices);
102 
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage predefined suppliers products.