dolibarr  7.0.0-beta
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2013 C├ędric Salvador <csalvador@gpcsolutions.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
33 
34 $langs->loadLangs(array("products","suppliers"));
35 
36 if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
37 
38 $sref = GETPOST('sref');
39 $sRefSupplier = GETPOST('srefsupplier');
40 $snom = GETPOST('snom');
41 $type = GETPOST('type');
42 $optioncss = GETPOST('optioncss','alpha');
43 
44 // Load variable for pagination
45 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
46 $sortfield = GETPOST('sortfield','alpha');
47 $sortorder = GETPOST('sortorder','alpha');
48 $page = GETPOST('page','int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortfield) $sortfield="p.ref"; // Set here default search field
54 if (! $sortorder) $sortorder="ASC";
55 
56 $fourn_id = GETPOST('fourn_id', 'intcomma');
57 if ($user->societe_id) $fourn_id=$user->societe_id;
58 
59 $catid = GETPOST('catid', 'intcomma');
60 
61 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
62 $hookmanager->initHooks(array('supplierpricelist'));
63 $extrafields = new ExtraFields($db);
64 
65 
66 
67 
68 /*
69  * ACTIONS
70  *
71  * Put here all code to do according to value of "action" parameter
72  */
73 
74 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
75 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
76 
77 $parameters=array();
78 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
79 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80 
81 if (empty($reshook))
82 {
83  // Selection of new fields
84  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
85 
86  // Purge search criteria
87  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
88  {
89  $sref = '';
90  $sRefSupplier = '';
91  $snom = '';
92  $search_field1='';
93  $search_field2='';
94  $search_date_creation='';
95  $search_date_update='';
96  $toselect='';
97  $search_array_options=array();
98  }
99 }
100 
101 /*
102  * View
103  */
104 
105 $form = new Form($db);
106 $productstatic = new Product($db);
107 $companystatic = new Societe($db);
108 
109 $title=$langs->trans("ProductsAndServices");
110 
111 if ($fourn_id)
112 {
113  $supplier = new Fournisseur($db);
114  $supplier->fetch($fourn_id);
115 }
116 
117 
118 
119 $arrayofmassactions = array(
120  'presend'=>$langs->trans("SendByMail"),
121  'builddoc'=>$langs->trans("PDFMerge"),
122 );
123 if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
124 if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
125 $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
126 
127 
128 $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity,";
129 $sql.= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
130 $sql.= " s.rowid as socid, s.nom as name";
131 $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
132 if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
133 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
134 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
135 $sql.= " WHERE p.entity IN (".getEntity('product').")";
136 if ($sRefSupplier)
137 {
138  $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
139 }
140 if (GETPOST('type'))
141 {
142  $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
143 }
144 if ($sref)
145 {
146  $sql .= natural_search('p.ref', $sref);
147 }
148 if ($snom)
149 {
150  $sql .= natural_search('p.label', $snom);
151 }
152 if($catid)
153 {
154  $sql .= " AND cp.fk_categorie = ".$catid;
155 }
156 if ($fourn_id > 0)
157 {
158  $sql .= " AND ppf.fk_soc = ".$fourn_id;
159 }
160 // Count total nb of records without orderby and limit
161 $nbtotalofrecords = '';
162 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
163 {
164  $result = $db->query($sql);
165  $nbtotalofrecords = $db->num_rows($result);
166 }
167 $sql .= $db->order($sortfield,$sortorder);
168 $sql .= $db->plimit($limit + 1, $offset);
169 
170 dol_syslog("fourn/product/list.php:", LOG_DEBUG);
171 $resql = $db->query($sql);
172 if ($resql)
173 {
174  $num = $db->num_rows($resql);
175 
176  $i = 0;
177 
178  if ($num == 1 && (GETPOST("mode") == 'search'))
179  {
180  $objp = $db->fetch_object($resql);
181  header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid);
182  exit;
183  }
184 
185  if (! empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier",$supplier->name);
186  else $texte = $langs->trans("List");
187 
188  llxHeader("","",$texte);
189 
190 
191  $param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&amp;type=".$type:"").(empty($sRefSupplier)?"":"&amp;srefsupplier=".$sRefSupplier);
192  if ($optioncss != '') $param.='&optioncss='.$optioncss;
193  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
194 
195 
196  if (! empty($catid))
197  {
198  print "<div id='ways'>";
199  $c = new Categorie($db);
200  $ways = $c->print_all_ways(' &gt; ','fourn/product/list.php');
201  print " &gt; ".$ways[0]."<br>\n";
202  print "</div><br>";
203  }
204 
205  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
206  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
207  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
208  if ($fourn_id > 0) print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
209  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
210  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
211  print '<input type="hidden" name="page" value="'.$page.'">';
212  print '<input type="hidden" name="type" value="'.$type.'">';
213 
214  $topicmail="Information";
215  $modelmail="product";
216  $objecttmp=new Product($db);
217  $trackid='prod'.$object->id;
218  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
219 
220  print '<table class="liste" width="100%">';
221 
222  // Lignes des champs de filtre
223  print '<tr class="liste_titre">';
224  print '<td class="liste_titre">';
225  print '<input class="flat" type="text" name="sref" value="'.$sref.'" size="12">';
226  print '</td>';
227  print '<td class="liste_titre">';
228  print '<input class="flat" type="text" name="srefsupplier" value="'.$sRefSupplier.'" size="12">';
229  print '</td>';
230  print '<td class="liste_titre">';
231  print '<input class="flat" type="text" name="snom" value="'.$snom.'">';
232  print '</td>';
233  print '<td></td>';
234  print '<td></td>';
235  print '<td></td>';
236  print '<td></td>';
237  print '<td class="liste_titre" align="right">';
238  $searchpicto=$form->showFilterButtons();
239  print $searchpicto;
240  print '</td>';
241  print '</tr>';
242 
243  // Lignes des titres
244  print '<tr class="liste_titre">';
245  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder);
246  print_liste_field_titre("RefSupplierShort",$_SERVER["PHP_SELF"], "ppf.ref_fourn",$param,"","",$sortfield,$sortorder);
247  print_liste_field_titre("Label",$_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder);
248  print_liste_field_titre("Supplier",$_SERVER["PHP_SELF"], "ppf.fk_soc",$param,"","",$sortfield,$sortorder);
249  print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"], "ppf.price",$param,"",'align="right"',$sortfield,$sortorder);
250  print_liste_field_titre("QtyMin",$_SERVER["PHP_SELF"], "ppf.quantity",$param,"",'align="right"',$sortfield,$sortorder);
251  print_liste_field_titre("UnitPrice",$_SERVER["PHP_SELF"], "ppf.unitprice",$param,"",'align="right"',$sortfield,$sortorder);
252  print_liste_field_titre('',$_SERVER["PHP_SELF"]);
253  print "</tr>\n";
254 
255  $oldid = '';
256  $var=True;
257  while ($i < min($num,$limit))
258  {
259  $objp = $db->fetch_object($resql);
260 
261  print '<tr class="oddeven">';
262 
263  print '<td>';
264  $productstatic->id=$objp->rowid;
265  $productstatic->ref=$objp->ref;
266  $productstatic->type=$objp->fk_product_type;
267  $productstatic->entity=$objp->entity;
268  print $productstatic->getNomUrl(1,'supplier');
269  print '</td>';
270 
271  print '<td>'.$objp->ref_fourn.'</td>';
272 
273  print '<td>'.$objp->label.'</td>'."\n";
274 
275  $companystatic->name=$objp->name;
276  $companystatic->id=$objp->socid;
277  print '<td>';
278  if ($companystatic->id > 0) print $companystatic->getNomUrl(1,'supplier');
279  print '</td>';
280 
281  print '<td align="right">'.(isset($objp->price) ? price($objp->price) : '').'</td>';
282 
283  print '<td align="right">'.$objp->qty.'</td>';
284 
285  print '<td align="right">'.(isset($objp->unitprice) ? price($objp->unitprice) : '').'</td>';
286 
287  print '<td align="right"></td>';
288 
289  print "</tr>\n";
290  $i++;
291  }
292  $db->free($resql);
293 
294  print "</table>";
295 
296  print '</form>';
297 }
298 else
299 {
300  dol_print_error($db);
301 }
302 
303 llxFooter();
304 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage products or services.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class to manage suppliers.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
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
llxHeader()
Empty header.
Definition: wrapper.php:46
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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...
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.