dolibarr  7.0.0-beta
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
31 require '../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
42 
43 $langs->load("orders");
44 $langs->load("sendings");
45 $langs->load('deliveries');
46 $langs->load('companies');
47 $langs->load('compta');
48 $langs->load('bills');
49 $langs->load('projects');
50 
51 $action=GETPOST('action','aZ09');
52 $massaction=GETPOST('massaction','alpha');
53 $show_files=GETPOST('show_files','int');
54 $confirm=GETPOST('confirm','alpha');
55 $toselect = GETPOST('toselect', 'array');
56 
57 $orderyear=GETPOST("orderyear","int");
58 $ordermonth=GETPOST("ordermonth","int");
59 $orderday=GETPOST("orderday","int");
60 $deliveryyear=GETPOST("deliveryyear","int");
61 $deliverymonth=GETPOST("deliverymonth","int");
62 $deliveryday=GETPOST("deliveryday","int");
63 
64 $sall=GETPOST('search_all', 'alphanohtml');
65 $search_product_category=GETPOST('search_product_category','int');
66 $search_ref=GETPOST('search_ref');
67 $search_refsupp=GETPOST('search_refsupp');
68 $search_company=GETPOST('search_company','alpha');
69 $search_town=GETPOST('search_town','alpha');
70 $search_zip=GETPOST('search_zip','alpha');
71 $search_state=trim(GETPOST("search_state"));
72 $search_country=GETPOST("search_country",'int');
73 $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
74 $search_user=GETPOST('search_user','int');
75 $search_request_author=GETPOST('search_request_author','alpha');
76 $search_ht=GETPOST('search_ht');
77 $search_ttc=GETPOST('search_ttc');
78 $search_status=(GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha')); // alpha and not intbecause it can be '6,7'
79 $optioncss = GETPOST('optioncss','alpha');
80 $socid = GETPOST('socid','int');
81 $search_sale=GETPOST('search_sale','int');
82 $search_total_ht=GETPOST('search_total_ht','alpha');
83 $search_total_vat=GETPOST('search_total_vat','alpha');
84 $search_total_ttc=GETPOST('search_total_ttc','alpha');
85 $optioncss = GETPOST('optioncss','alpha');
86 $search_billed = GETPOST('search_billed','int');
87 $search_project_ref=GETPOST('search_project_ref','alpha');
88 
89 $status=GETPOST('statut','alpha');
90 $viewstatut=GETPOST('viewstatut');
91 
92 // Security check
93 $orderid = GETPOST('orderid','int');
94 if ($user->societe_id) $socid=$user->societe_id;
95 $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
96 
97 $diroutputmassaction=$conf->fournisseur->commande->dir_output . '/temp/massgeneration/'.$user->id;
98 
99 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
100 $sortfield = GETPOST("sortfield",'alpha');
101 $sortorder = GETPOST("sortorder",'alpha');
102 $page = GETPOST("page",'int');
103 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
104 $offset = $limit * $page;
105 $pageprev = $page - 1;
106 $pagenext = $page + 1;
107 if (! $sortfield) $sortfield='cf.ref';
108 if (! $sortorder) $sortorder='DESC';
109 
110 if ($search_status == '') $search_status=-1;
111 
112 // Initialize technical object to manage context to save list fields
113 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'supplierorderlist';
114 
115 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
116 $hookmanager->initHooks(array($contextpage));
117 $extrafields = new ExtraFields($db);
118 
119 // fetch optionals attributes and labels
120 $extralabels = $extrafields->fetch_name_optionals_label('commande_fournisseur');
121 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
122 
123 // List of fields to search into when doing a "search in all"
124 $fieldstosearchall = array(
125  'cf.ref'=>'Ref',
126  'cf.ref_supplier'=>'RefSupplierOrder',
127  'pd.description'=>'Description',
128  's.nom'=>"ThirdParty",
129  'cf.note_public'=>'NotePublic',
130 );
131 if (empty($user->socid)) $fieldstosearchall["cf.note_private"]="NotePrivate";
132 
133 $checkedtypetiers=0;
134 $arrayfields=array(
135  'cf.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
136  'cf.ref_supplier'=>array('label'=>$langs->trans("RefOrderSupplierShort"), 'checked'=>1, 'enabled'=>1),
137  'p.project_ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0, 'enabled'=>1),
138  'u.login'=>array('label'=>$langs->trans("AuthorRequest"), 'checked'=>1),
139  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
140  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
141  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
142  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
143  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
144  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
145  'cf.date_commande'=>array('label'=>$langs->trans("OrderDateShort"), 'checked'=>1),
146  'cf.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)),
147  'cf.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
148  'cf.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
149  'cf.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
150  'cf.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
151  'cf.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
152  'cf.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
153  'cf.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>1)
154 );
155 // Extra fields
156 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
157 {
158  foreach($extrafields->attribute_label as $key => $val)
159  {
160  if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
161  }
162 }
163 
164 
165 
166 /*
167  * Actions
168  */
169 
170 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
171 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
172 
173 $parameters=array('socid'=>$socid);
174 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
175 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
176 
177 if (empty($reshook))
178 {
179  // Selection of new fields
180  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
181 
182  // Purge search criteria
183  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
184  {
185  $ordermonth='';
186  $orderyear='';
187  $orderday='';
188  $search_categ='';
189  $search_user='';
190  $search_sale='';
191  $search_product_category='';
192  $search_ref='';
193  $search_refsupp='';
194  $search_company='';
195  $search_town='';
196  $search_zip="";
197  $search_state="";
198  $search_type='';
199  $search_country='';
200  $search_type_thirdparty='';
201  $search_request_author='';
202  $search_total_ht='';
203  $search_total_vat='';
204  $search_total_ttc='';
205  $search_project_ref='';
206  $search_status=-1;
207  $orderyear='';
208  $ordermonth='';
209  $orderday='';
210  $deliveryday='';
211  $deliverymonth='';
212  $deliveryyear='';
213  $billed='';
214  $search_billed='';
215  $toselect='';
216  $search_array_options=array();
217  }
218  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
219  || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
220  {
221  $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation
222  }
223 
224  // Mass actions
225  $objectclass='CommandeFournisseur';
226  $objectlabel='SupplierOrders';
227  $permtoread = $user->rights->fournisseur->commande->lire;
228  $permtodelete = $user->rights->fournisseur->commande->supprimer;
229  $uploaddir = $conf->fournisseur->commande->dir_output;
230  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
231 
232  // TODO Move this into mass action include
233  if ($massaction == 'confirm_createbills')
234  {
235  $orders = GETPOST('toselect','array');
236  $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
237  $validate_invoices = GETPOST('valdate_invoices', 'int');
238 
239  $TFact = array();
240  $TFactThird = array();
241 
242  $nb_bills_created = 0;
243 
244  $db->begin();
245 
246  foreach($orders as $id_order) {
247 
248  $cmd = new Commande($db);
249  if($cmd->fetch($id_order) <= 0) continue;
250 
251  $object = new Facture($db);
252  if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
253  else {
254 
255  $object->socid = $cmd->socid;
256  $object->type = Facture::TYPE_STANDARD;
257  $object->cond_reglement_id = $cmd->cond_reglement_id;
258  $object->mode_reglement_id = $cmd->mode_reglement_id;
259  $object->fk_project = $cmd->fk_project;
260 
261  $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
262  if (empty($datefacture))
263  {
264  $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
265  }
266 
267  $object->date = $datefacture;
268  $object->origin = 'commande';
269  $object->origin_id = $id_order;
270 
271  $res = $object->create($user);
272 
273  if($res > 0) $nb_bills_created++;
274 
275  }
276 
277  if ($object->id > 0)
278  {
279  $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
280  $sql.= "fk_source";
281  $sql.= ", sourcetype";
282  $sql.= ", fk_target";
283  $sql.= ", targettype";
284  $sql.= ") VALUES (";
285  $sql.= $id_order;
286  $sql.= ", '".$object->origin."'";
287  $sql.= ", ".$object->id;
288  $sql.= ", '".$object->element."'";
289  $sql.= ")";
290 
291  if (! $db->query($sql))
292  {
293  $erorr++;
294  }
295 
296  if (! $error)
297  {
298  $lines = $cmd->lines;
299  if (empty($lines) && method_exists($cmd, 'fetch_lines'))
300  {
301  $cmd->fetch_lines();
302  $lines = $cmd->lines;
303  }
304 
305  $fk_parent_line=0;
306  $num=count($lines);
307 
308  for ($i=0;$i<$num;$i++)
309  {
310  $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
311  if ($lines[$i]->subprice < 0)
312  {
313  // Negative line, we create a discount line
314  $discount = new DiscountAbsolute($db);
315  $discount->fk_soc=$object->socid;
316  $discount->amount_ht=abs($lines[$i]->total_ht);
317  $discount->amount_tva=abs($lines[$i]->total_tva);
318  $discount->amount_ttc=abs($lines[$i]->total_ttc);
319  $discount->tva_tx=$lines[$i]->tva_tx;
320  $discount->fk_user=$user->id;
321  $discount->description=$desc;
322  $discountid=$discount->create($user);
323  if ($discountid > 0)
324  {
325  $result=$object->insert_discount($discountid);
326  //$result=$discount->link_to_invoice($lineid,$id);
327  }
328  else
329  {
330  setEventMessages($discount->error, $discount->errors, 'errors');
331  $error++;
332  break;
333  }
334  }
335  else
336  {
337  // Positive line
338  $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
339  // Date start
340  $date_start=false;
341  if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
342  if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
343  if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
344  //Date end
345  $date_end=false;
346  if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
347  if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
348  if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
349  // Reset fk_parent_line for no child products and special product
350  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
351  {
352  $fk_parent_line = 0;
353  }
354  $result = $object->addline(
355  $desc,
356  $lines[$i]->subprice,
357  $lines[$i]->qty,
358  $lines[$i]->tva_tx,
359  $lines[$i]->localtax1_tx,
360  $lines[$i]->localtax2_tx,
361  $lines[$i]->fk_product,
362  $lines[$i]->remise_percent,
363  $date_start,
364  $date_end,
365  0,
366  $lines[$i]->info_bits,
367  $lines[$i]->fk_remise_except,
368  'HT',
369  0,
370  $product_type,
371  $ii,
372  $lines[$i]->special_code,
373  $object->origin,
374  $lines[$i]->rowid,
375  $fk_parent_line,
376  $lines[$i]->fk_fournprice,
377  $lines[$i]->pa_ht,
378  $lines[$i]->label
379  );
380  if ($result > 0)
381  {
382  $lineid=$result;
383  }
384  else
385  {
386  $lineid=0;
387  $error++;
388  break;
389  }
390  // Defined the new fk_parent_line
391  if ($result > 0 && $lines[$i]->product_type == 9)
392  {
393  $fk_parent_line = $result;
394  }
395  }
396  }
397  }
398  }
399 
400  $cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders
401 
402  if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object;
403  else $TFact[$object->id] = $object;
404  }
405 
406  // Build doc with all invoices
407  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
408  $toselect = array();
409 
410  if (! $error && $validate_invoices) {
411 
412  $massaction = $action = 'builddoc';
413 
414  foreach($TAllFact as &$object)
415  {
416  $object->validate($user);
417  if ($result <= 0)
418  {
419  $error++;
420  setEventMessages($object->error, $object->errors, 'errors');
421  break;
422  }
423 
424  $id = $object->id; // For builddoc action
425 
426  // Fac builddoc
427  $donotredirect = 1;
428  $upload_dir = $conf->facture->dir_output;
429  $permissioncreate=$user->rights->facture->creer;
430  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
431  }
432 
433  $massaction = $action = 'confirm_createbills';
434  }
435 
436  if (! $error)
437  {
438  $db->commit();
439  setEventMessage($langs->trans('BillCreated', $nb_bills_created));
440  }
441  else
442  {
443  $db->rollback();
444  $action='create';
445  $_GET["origin"]=$_POST["origin"];
446  $_GET["originid"]=$_POST["originid"];
447  setEventMessages($object->error, $object->errors, 'errors');
448  $error++;
449  }
450  }
451 }
452 
453 
454 /*
455  * View
456  */
457 
458 $now=dol_now();
459 
460 $form=new Form($db);
461 $thirdpartytmp = new Fournisseur($db);
462 $commandestatic=new CommandeFournisseur($db);
463 $formfile = new FormFile($db);
464 $formorder = new FormOrder($db);
465 $formother = new FormOther($db);
466 $formcompany=new FormCompany($db);
467 
468 $title = $langs->trans("SuppliersOrders");
469 if ($socid > 0)
470 {
471  $fourn = new Fournisseur($db);
472  $fourn->fetch($socid);
473  $title .= ' - '.$fourn->name;
474 }
475 if ($status)
476 {
477  if ($status == '1,2,3') $title.=' - '.$langs->trans("StatusOrderToProcessShort");
478  if ($status == '6,7') $title.=' - '.$langs->trans("StatusOrderCanceled");
479  else $title.=' - '.$langs->trans($commandestatic->statuts[$status]);
480 }
481 if ($search_billed > 0) $title.=' - '.$langs->trans("Billed");
482 
483 //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
484 $help_url='';
485 llxHeader('',$title,$help_url);
486 
487 $sql = 'SELECT';
488 if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
489 $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
490 $sql.= " typent.code as typent_code,";
491 $sql.= " state.code_departement as state_code, state.nom as state_name,";
492 $sql.= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.tva as total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_delivery,";
493 $sql.= ' cf.date_creation as date_creation, cf.tms as date_update,';
494 $sql.= " p.rowid as project_id, p.ref as project_ref,";
495 $sql.= " u.firstname, u.lastname, u.photo, u.login";
496 // Add fields from extrafields
497 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
498 // Add fields from hooks
499 $parameters=array();
500 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
501 $sql.=$hookmanager->resPrint;
502 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
503 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
504 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
505 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
506 $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
507 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_extrafields as ef on (cf.rowid = ef.fk_object)";
508 if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
509 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
510 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
511 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
512 // We'll need this table joined to the select in order to filter by sale
513 if ($search_sale > 0 || (!$user->rights->societe->client->voir && ! $socid)) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
514 if ($search_user > 0)
515 {
516  $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
517  $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
518 }
519 $sql.= ' WHERE cf.fk_soc = s.rowid';
520 $sql.= ' AND cf.entity IN ('.getEntity('supplier_order').')';
521 if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
522 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
523 if ($search_ref) $sql .= natural_search('cf.ref', $search_ref);
524 if ($search_refsupp) $sql.= natural_search("cf.ref_supplier", $search_refsupp);
525 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
526 if ($search_company) $sql .= natural_search('s.nom', $search_company);
527 if ($search_request_author) $sql.=natural_search(array('u.lastname','u.firstname','u.login'), $search_request_author) ;
528 if ($search_billed != '' && $search_billed >= 0) $sql .= " AND cf.billed = ".$search_billed;
529 
530 //Required triple check because statut=0 means draft filter
531 if (GETPOST('statut', 'intcomma') !== '')
532 {
533  $sql .= " AND cf.fk_statut IN (".$db->escape($db->escape(GETPOST('statut', 'intcomma'))).")";
534 }
535 if ($search_status != '' && $search_status >= 0)
536 {
537  $sql.=" AND cf.fk_statut IN (".$db->escape($search_status).")";
538 }
539 if ($ordermonth > 0)
540 {
541  if ($orderyear > 0 && empty($orderday))
542  $sql.= " AND cf.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,$ordermonth,false))."' AND '".$db->idate(dol_get_last_day($orderyear,$ordermonth,false))."'";
543  else if ($orderyear > 0 && ! empty($orderday))
544  $sql.= " AND cf.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $ordermonth, $orderday, $orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $ordermonth, $orderday, $orderyear))."'";
545  else
546  $sql.= " AND date_format(cf.date_commande, '%m') = '".$ordermonth."'";
547 }
548 else if ($orderyear > 0)
549 {
550  $sql.= " AND cf.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($orderyear,12,false))."'";
551 }
552 if ($deliverymonth > 0)
553 {
554  if ($deliveryyear > 0 && empty($deliveryday))
555  $sql.= " AND cf.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,$deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,$deliverymonth,false))."'";
556  else if ($deliveryyear > 0 && ! empty($deliveryday))
557  $sql.= " AND cf.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $deliverymonth, $deliveryday, $deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $deliverymonth, $deliveryday, $deliveryyear))."'";
558  else
559  $sql.= " AND date_format(cf.date_livraison, '%m') = '".$deliverymonth."'";
560 }
561 else if ($deliveryyear > 0)
562 {
563  $sql.= " AND cf.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,12,false))."'";
564 }
565 if ($search_town) $sql.= natural_search('s.town', $search_town);
566 if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
567 if ($search_state) $sql.= natural_search("state.nom",$search_state);
568 if ($search_country) $sql .= " AND s.fk_pays IN (".$db->escape($search_country).')';
569 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->escape($search_type_thirdparty).')';
570 if ($search_company) $sql .= natural_search('s.nom', $search_company);
571 if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$db->escape($search_sale);
572 if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='supplier_order' AND tc.source='internal' AND ec.element_id = cf.rowid AND ec.fk_socpeople = ".$db->escape($search_user);
573 if ($search_total_ht != '') $sql.= natural_search('cf.total_ht', $search_total_ht, 1);
574 if ($search_total_vat != '') $sql.= natural_search('cf.tva', $search_total_vat, 1);
575 if ($search_total_ttc != '') $sql.= natural_search('cf.total_ttc', $search_total_ttc, 1);
576 if ($search_project_ref != '') $sql.= natural_search("p.ref",$search_project_ref);
577 // Add where from extra fields
578 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
579 // Add where from hooks
580 $parameters=array();
581 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
582 $sql.=$hookmanager->resPrint;
583 
584 $sql.= $db->order($sortfield,$sortorder);
585 
586 $nbtotalofrecords = '';
587 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
588 {
589  $result = $db->query($sql);
590  $nbtotalofrecords = $db->num_rows($result);
591 }
592 
593 $sql.= $db->plimit($limit+1, $offset);
594 
595 $resql = $db->query($sql);
596 if ($resql)
597 {
598  if ($socid > 0)
599  {
600  $soc = new Societe($db);
601  $soc->fetch($socid);
602  $title = $langs->trans('ListOfSupplierOrders') . ' - '.$soc->name;
603  }
604  else
605  {
606  $title = $langs->trans('ListOfSupplierOrders');
607  }
608 
609  $num = $db->num_rows($resql);
610 
611  $arrayofselected=is_array($toselect)?$toselect:array();
612 
613  $param='';
614  if ($socid > 0) $param.='&socid='.$socid;
615  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
616  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
617  if ($sall) $param.="&search_all=".$sall;
618  if ($orderday) $param.='&orderday='.$orderday;
619  if ($ordermonth) $param.='&ordermonth='.$ordermonth;
620  if ($orderyear) $param.='&orderyear='.$orderyear;
621  if ($deliveryday) $param.='&deliveryday='.$deliveryday;
622  if ($deliverymonth) $param.='&deliverymonth='.$deliverymonth;
623  if ($deliveryyear) $param.='&deliveryyear='.$deliveryyear;
624  if ($search_ref) $param.='&search_ref='.$search_ref;
625  if ($search_company) $param.='&search_company='.$search_company;
626  if ($search_user > 0) $param.='&search_user='.$search_user;
627  if ($search_request_author) $param.='&search_request_author='.$search_request_author;
628  if ($search_sale > 0) $param.='&search_sale='.$search_sale;
629  if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht;
630  if ($search_total_ttc != '') $param.="&search_total_ttc=".$search_total_ttc;
631  if ($search_refsupp) $param.="&search_refsupp=".$search_refsupp;
632  if ($search_status >= 0) $param.="&search_status=".$search_status;
633  if ($search_project_ref >= 0) $param.="&search_project_ref=".$search_project_ref;
634  if ($search_billed != '') $param.="&search_billed=".$search_billed;
635  if ($show_files) $param.='&show_files=' .$show_files;
636  if ($optioncss != '') $param.='&optioncss='.$optioncss;
637  // Add $param from extra fields
638  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
639 
640  // List of mass actions available
641  $arrayofmassactions = array(
642  'presend'=>$langs->trans("SendByMail"),
643  'builddoc'=>$langs->trans("PDFMerge"),
644  );
645  //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
646  if ($user->rights->fournisseur->commande->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
647  if (in_array($massaction, array('presend','predelete','createbills'))) $arrayofmassactions=array();
648  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
649 
650  // Lignes des champs de filtre
651  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
652  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
653  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
654  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
655  print '<input type="hidden" name="action" value="list">';
656  print '<input type="hidden" name="page" value="'.$page.'">';
657  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
658  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
659  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
660  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
661 
662  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit);
663 
664  $topicmail="SendOrderRef";
665  $modelmail="order_supplier_send";
666  $objecttmp=new CommandeFournisseur($db);
667  $trackid='sord'.$object->id;
668  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
669 
670  if ($massaction == 'createbills')
671  {
672  //var_dump($_REQUEST);
673  print '<input type="hidden" name="massaction" value="confirm_createbills">';
674 
675  print '<table class="border" width="100%" >';
676  print '<tr>';
677  print '<td class="titlefieldmiddle">';
678  print $langs->trans('DateInvoice');
679  print '</td>';
680  print '<td>';
681  print $form->select_date('', '', '', '', '', '', 1, 1);
682  print '</td>';
683  print '</tr>';
684  print '<tr>';
685  print '<td>';
686  print $langs->trans('CreateOneBillByThird');
687  print '</td>';
688  print '<td>';
689  print $form->selectyesno('createbills_onebythird', '', 1);
690  print '</td>';
691  print '</tr>';
692  print '<tr>';
693  print '<td>';
694  print $langs->trans('ValidateInvoices');
695  print '</td>';
696  print '<td>';
697  print $form->selectyesno('valdate_invoices', 1, 1);
698  print '</td>';
699  print '</tr>';
700  print '</table>';
701 
702  print '<br>';
703  print '<div class="center">';
704  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
705  print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
706  print '</div>';
707  print '<br>';
708  }
709 
710  if ($sall)
711  {
712  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
713  print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
714  }
715 
716  $moreforfilter='';
717 
718  // If the user can view prospects other than his'
719  if ($user->rights->societe->client->voir || $socid)
720  {
721  $langs->load("commercial");
722  $moreforfilter.='<div class="divsearchfield">';
723  $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
724  $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
725  $moreforfilter.='</div>';
726  }
727  // If the user can view other users
728  if ($user->rights->user->user->lire)
729  {
730  $moreforfilter.='<div class="divsearchfield">';
731  $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
732  $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
733  $moreforfilter.='</div>';
734  }
735  // If the user can view prospects other than his'
736  if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
737  {
738  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
739  $moreforfilter.='<div class="divsearchfield">';
740  $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
741  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
742  $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
743  $moreforfilter.='</div>';
744  }
745  $parameters=array();
746  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
747  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
748  else $moreforfilter = $hookmanager->resPrint;
749 
750  if (! empty($moreforfilter))
751  {
752  print '<div class="liste_titre liste_titre_bydiv centpercent">';
753  print $moreforfilter;
754  print '</div>';
755  }
756 
757  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
758  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
759  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
760 
761  print '<div class="div-table-responsive">';
762  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
763 
764  print '<tr class="liste_titre_filter">';
765  // Ref
766  if (! empty($arrayfields['cf.ref']['checked']))
767  {
768  print '<td class="liste_titre"><input size="8" type="text" class="flat" name="search_ref" value="'.$search_ref.'"></td>';
769  }
770  // Ref customer
771  if (! empty($arrayfields['cf.ref_supplier']['checked']))
772  {
773  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_refsupp" value="'.$search_refsupp.'"></td>';
774  }
775  // Project ref
776  if (! empty($arrayfields['p.project_ref']['checked']))
777  {
778  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.$search_project_ref.'"></td>';
779  }
780  // Request author
781  if (! empty($arrayfields['u.login']['checked']))
782  {
783  print '<td class="liste_titre">';
784  print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
785  print '</td>';
786  }
787  // Thirpdarty
788  if (! empty($arrayfields['s.nom']['checked']))
789  {
790  print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
791  }
792  // Town
793  if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
794  // Zip
795  if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
796  // State
797  if (! empty($arrayfields['state.nom']['checked']))
798  {
799  print '<td class="liste_titre">';
800  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
801  print '</td>';
802  }
803  // Country
804  if (! empty($arrayfields['country.code_iso']['checked']))
805  {
806  print '<td class="liste_titre" align="center">';
807  print $form->select_country($search_country,'search_country','',0,'maxwidth100');
808  print '</td>';
809  }
810  // Company type
811  if (! empty($arrayfields['typent.code']['checked']))
812  {
813  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
814  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
815  print '</td>';
816  }
817  // Date order
818  if (! empty($arrayfields['cf.date_commande']['checked']))
819  {
820  print '<td class="liste_titre" align="center">';
821  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="orderday" value="'.$orderday.'">';
822  print '<input class="flat" type="text" size="1" maxlength="2" name="ordermonth" value="'.$ordermonth.'">';
823  $formother->select_year($orderyear?$orderyear:-1,'orderyear',1, 20, 5);
824  print '</td>';
825  }
826  // Date delivery
827  if (! empty($arrayfields['cf.date_delivery']['checked']))
828  {
829  print '<td class="liste_titre" align="center">';
830  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="deliveryday" value="'.$deliveryday.'">';
831  print '<input class="flat" type="text" size="1" maxlength="2" name="deliverymonth" value="'.$deliverymonth.'">';
832  $formother->select_year($deliveryyear?$deliveryyear:-1,'deliveryyear',1, 20, 5);
833  print '</td>';
834  }
835  if (! empty($arrayfields['cf.total_ht']['checked']))
836  {
837  // Amount
838  print '<td class="liste_titre" align="right">';
839  print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
840  print '</td>';
841  }
842  if (! empty($arrayfields['cf.total_vat']['checked']))
843  {
844  // Amount
845  print '<td class="liste_titre" align="right">';
846  print '<input class="flat" type="text" size="5" name="search_total_vat" value="'.$search_total_vat.'">';
847  print '</td>';
848  }
849  if (! empty($arrayfields['cf.total_ttc']['checked']))
850  {
851  // Amount
852  print '<td class="liste_titre" align="right">';
853  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
854  print '</td>';
855  }
856  // Extra fields
857  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
858 
859  // Fields from hook
860  $parameters=array('arrayfields'=>$arrayfields);
861  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
862  print $hookmanager->resPrint;
863  // Date creation
864  if (! empty($arrayfields['cf.datec']['checked']))
865  {
866  print '<td class="liste_titre">';
867  print '</td>';
868  }
869  // Date modification
870  if (! empty($arrayfields['cf.tms']['checked']))
871  {
872  print '<td class="liste_titre">';
873  print '</td>';
874  }
875  // Status
876  if (! empty($arrayfields['cf.fk_statut']['checked']))
877  {
878  print '<td class="liste_titre" align="right">';
879  $formorder->selectSupplierOrderStatus((strstr($search_status, ',')?-1:$search_status),1,'search_status');
880  print '</td>';
881  }
882  // Status billed
883  if (! empty($arrayfields['cf.billed']['checked']))
884  {
885  print '<td class="liste_titre" align="center">';
886  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
887  print '</td>';
888  }
889  // Action column
890  print '<td class="liste_titre" align="middle">';
891  $searchpicto=$form->showFilterButtons();
892  print $searchpicto;
893  print '</td>';
894 
895  print "</tr>\n";
896 
897  print '<tr class="liste_titre">';
898  if (! empty($arrayfields['cf.ref']['checked'])) print_liste_field_titre($arrayfields['cf.ref']['label'],$_SERVER["PHP_SELF"],"cf.ref","",$param,'',$sortfield,$sortorder);
899  if (! empty($arrayfields['cf.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['cf.ref_supplier']['label'],$_SERVER["PHP_SELF"],"cf.ref_supplier","",$param,'',$sortfield,$sortorder);
900  if (! empty($arrayfields['p.project_ref']['checked'])) print_liste_field_titre($arrayfields['p.project_ref']['label'],$_SERVER["PHP_SELF"],"p.ref","",$param,'',$sortfield,$sortorder);
901  if (! empty($arrayfields['u.login']['checked'])) print_liste_field_titre($arrayfields['u.login']['label'],$_SERVER["PHP_SELF"],"u.login","",$param,'',$sortfield,$sortorder);
902  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],"s.nom","",$param,'',$sortfield,$sortorder);
903  if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
904  if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
905  if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
906  if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
907  if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
908  if (! empty($arrayfields['cf.fk_author']['checked'])) print_liste_field_titre($arrayfields['cf.fk_author']['label'],$_SERVER["PHP_SELF"],"cf.fk_author","",$param,'',$sortfield,$sortorder);
909  if (! empty($arrayfields['cf.date_commande']['checked'])) print_liste_field_titre($arrayfields['cf.date_commande']['label'],$_SERVER["PHP_SELF"],"cf.date_commande","",$param,'align="center"',$sortfield,$sortorder);
910  if (! empty($arrayfields['cf.date_delivery']['checked'])) print_liste_field_titre($arrayfields['cf.date_delivery']['label'],$_SERVER["PHP_SELF"],'cf.date_livraison','',$param, 'align="center"',$sortfield,$sortorder);
911  if (! empty($arrayfields['cf.total_ht']['checked'])) print_liste_field_titre($arrayfields['cf.total_ht']['label'],$_SERVER["PHP_SELF"],"cf.total_ht","",$param,'align="right"',$sortfield,$sortorder);
912  if (! empty($arrayfields['cf.total_vat']['checked'])) print_liste_field_titre($arrayfields['cf.total_vat']['label'],$_SERVER["PHP_SELF"],"cf.tva","",$param,'align="right"',$sortfield,$sortorder);
913  if (! empty($arrayfields['cf.total_ttc']['checked'])) print_liste_field_titre($arrayfields['cf.total_ttc']['label'],$_SERVER["PHP_SELF"],"cf.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
914  // Extra fields
915  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
916  // Hook fields
917  $parameters=array('arrayfields'=>$arrayfields);
918  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
919  print $hookmanager->resPrint;
920  if (! empty($arrayfields['cf.datec']['checked'])) print_liste_field_titre($arrayfields['cf.datec']['label'],$_SERVER["PHP_SELF"],"cf.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
921  if (! empty($arrayfields['cf.tms']['checked'])) print_liste_field_titre($arrayfields['cf.tms']['label'],$_SERVER["PHP_SELF"],"cf.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
922  if (! empty($arrayfields['cf.fk_statut']['checked'])) print_liste_field_titre($arrayfields['cf.fk_statut']['label'],$_SERVER["PHP_SELF"],"cf.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
923  if (! empty($arrayfields['cf.billed']['checked'])) print_liste_field_titre($arrayfields['cf.billed']['label'],$_SERVER["PHP_SELF"],'cf.billed','',$param,'align="center"',$sortfield,$sortorder,'');
924  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
925  print "</tr>\n";
926 
927 
928  $total=0;
929  $subtotal=0;
930  $productstat_cache=array();
931 
932  $userstatic = new User($db);
933  $objectstatic=new CommandeFournisseur($db);
934  $projectstatic=new Project($db);
935 
936  $i=0;
937  $var=true;
938  $totalarray=array();
939  while ($i < min($num,$limit))
940  {
941  $obj = $db->fetch_object($resql);
942 
943 
944  $objectstatic->id=$obj->rowid;
945  $objectstatic->ref=$obj->ref;
946  $objectstatic->ref_supplier = $obj->ref_supplier;
947  $objectstatic->total_ht = $obj->total_ht;
948  $objectstatic->total_tva = $obj->total_tva;
949  $objectstatic->total_ttc = $obj->total_ttc;
950  $objectstatic->date_delivery = $db->jdate($obj->date_delivery);
951  $objectstatic->statut = $obj->fk_statut;
952 
953  print '<tr class="oddeven">';
954 
955  // Ref
956  if (! empty($arrayfields['cf.ref']['checked']))
957  {
958  print '<td class="nowrap">';
959 
960  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
961  // Picto + Ref
962  print '<td class="nobordernopadding nowrap">';
963  print $objectstatic->getNomUrl(1);
964  print '</td>';
965  // Warning
966  //print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
967  //print '</td>';
968  // Other picto tool
969  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
970  $filename=dol_sanitizeFileName($obj->ref);
971  $filedir=$conf->fournisseur->commande->dir_output.'/' . dol_sanitizeFileName($obj->ref);
972  print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
973  print '</td></tr></table>';
974 
975  print '</td>'."\n";
976  if (! $i) $totalarray['nbfield']++;
977  }
978  // Ref Supplier
979  if (! empty($arrayfields['cf.ref_supplier']['checked']))
980  {
981  print '<td>'.$obj->ref_supplier.'</td>'."\n";
982  if (! $i) $totalarray['nbfield']++;
983  }
984  // Project
985  if (! empty($arrayfields['p.project_ref']['checked']))
986  {
987  $projectstatic->id=$obj->project_id;
988  $projectstatic->ref=$obj->project_ref;
989  print '<td>';
990  if ($obj->project_id > 0) print $projectstatic->getNomUrl(1);
991  print '</td>';
992  if (! $i) $totalarray['nbfield']++;
993  }
994  // Author
995  $userstatic->id = $obj->fk_user_author;
996  $userstatic->lastname = $obj->lastname;
997  $userstatic->firstname = $obj->firstname;
998  $userstatic->login = $obj->login;
999  $userstatic->photo = $obj->photo;
1000  if (! empty($arrayfields['u.login']['checked']))
1001  {
1002  print "<td>";
1003  if ($userstatic->id) print $userstatic->getNomUrl(1);
1004  else print "&nbsp;";
1005  print "</td>";
1006  if (! $i) $totalarray['nbfield']++;
1007  }
1008  // Thirdparty
1009  if (! empty($arrayfields['s.nom']['checked']))
1010  {
1011  print '<td>';
1012  $thirdpartytmp->id = $obj->socid;
1013  $thirdpartytmp->name = $obj->name;
1014  print $thirdpartytmp->getNomUrl(1,'supplier');
1015  print '</td>'."\n";
1016  if (! $i) $totalarray['nbfield']++;
1017  }
1018  // Town
1019  if (! empty($arrayfields['s.town']['checked']))
1020  {
1021  print '<td class="nocellnopadd">';
1022  print $obj->town;
1023  print '</td>';
1024  if (! $i) $totalarray['nbfield']++;
1025  }
1026  // Zip
1027  if (! empty($arrayfields['s.zip']['checked']))
1028  {
1029  print '<td class="nocellnopadd">';
1030  print $obj->zip;
1031  print '</td>';
1032  if (! $i) $totalarray['nbfield']++;
1033  }
1034  // State
1035  if (! empty($arrayfields['state.nom']['checked']))
1036  {
1037  print "<td>".$obj->state_name."</td>\n";
1038  if (! $i) $totalarray['nbfield']++;
1039  }
1040  // Country
1041  if (! empty($arrayfields['country.code_iso']['checked']))
1042  {
1043  print '<td align="center">';
1044  $tmparray=getCountry($obj->fk_pays,'all');
1045  print $tmparray['label'];
1046  print '</td>';
1047  if (! $i) $totalarray['nbfield']++;
1048  }
1049  // Type ent
1050  if (! empty($arrayfields['typent.code']['checked']))
1051  {
1052  print '<td align="center">';
1053  if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
1054  print $typenArray[$obj->typent_code];
1055  print '</td>';
1056  if (! $i) $totalarray['nbfield']++;
1057  }
1058 
1059  // Order date
1060  if (! empty($arrayfields['cf.date_commande']['checked']))
1061  {
1062  print '<td align="center">';
1063  if ($obj->date_commande) print dol_print_date($db->jdate($obj->date_commande), 'day');
1064  else print '';
1065  print '</td>';
1066  if (! $i) $totalarray['nbfield']++;
1067  }
1068  // Plannned date of delivery
1069  if (! empty($arrayfields['cf.date_delivery']['checked']))
1070  {
1071  print '<td align="center">';
1072  print dol_print_date($db->jdate($obj->date_delivery), 'day');
1073  if ($objectstatic->hasDelay() && ! empty($objectstatic->date_delivery)) {
1074  print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1075  }
1076  print '</td>';
1077  if (! $i) $totalarray['nbfield']++;
1078  }
1079  // Amount HT
1080  if (! empty($arrayfields['cf.total_ht']['checked']))
1081  {
1082  print '<td align="right">'.price($obj->total_ht)."</td>\n";
1083  if (! $i) $totalarray['nbfield']++;
1084  if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
1085  $totalarray['totalht'] += $obj->total_ht;
1086  }
1087  // Amount VAT
1088  if (! empty($arrayfields['cf.total_vat']['checked']))
1089  {
1090  print '<td align="right">'.price($obj->total_tva)."</td>\n";
1091  if (! $i) $totalarray['nbfield']++;
1092  if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
1093  $totalarray['totalvat'] += $obj->total_tva;
1094  }
1095  // Amount TTC
1096  if (! empty($arrayfields['cf.total_ttc']['checked']))
1097  {
1098  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
1099  if (! $i) $totalarray['nbfield']++;
1100  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
1101  $totalarray['totalttc'] += $obj->total_ttc;
1102  }
1103 
1104  // Extra fields
1105  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1106  // Fields from hook
1107  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
1108  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
1109  print $hookmanager->resPrint;
1110  // Date creation
1111  if (! empty($arrayfields['cf.datec']['checked']))
1112  {
1113  print '<td align="center" class="nowrap">';
1114  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1115  print '</td>';
1116  if (! $i) $totalarray['nbfield']++;
1117  }
1118  // Date modification
1119  if (! empty($arrayfields['cf.tms']['checked']))
1120  {
1121  print '<td align="center" class="nowrap">';
1122  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1123  print '</td>';
1124  if (! $i) $totalarray['nbfield']++;
1125  }
1126  // Status
1127  if (! empty($arrayfields['cf.fk_statut']['checked']))
1128  {
1129  print '<td align="right" class="nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed, 1).'</td>';
1130  if (! $i) $totalarray['nbfield']++;
1131  }
1132  // Billed
1133  if (! empty($arrayfields['cf.billed']['checked']))
1134  {
1135  print '<td align="center">'.yn($obj->billed).'</td>';
1136  if (! $i) $totalarray['nbfield']++;
1137  }
1138 
1139  // Action column
1140  print '<td class="nowrap" align="center">';
1141  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1142  {
1143  $selected=0;
1144  if (in_array($obj->rowid, $arrayofselected)) $selected=1;
1145  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
1146  }
1147  print '</td>';
1148  if (! $i) $totalarray['nbfield']++;
1149 
1150  print "</tr>\n";
1151  $i++;
1152  }
1153  print "</table>\n";
1154  print '</div>';
1155  print "</form>\n";
1156 
1157  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
1158  {
1159  /*
1160  * Show list of available documents
1161  */
1162  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1163  $urlsource.=str_replace('&amp;','&',$param);
1164 
1165  $filedir=$diroutputmassaction;
1166  $genallowed=$user->rights->fournisseur->commande->lire;
1167  $delallowed=$user->rights->fournisseur->commande->creer;
1168 
1169  print $formfile->showdocuments('massfilesarea_supplier_order','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
1170  }
1171  else
1172  {
1173  print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
1174  }
1175 
1176  $db->free($resql);
1177 }
1178 else
1179 {
1180  dol_print_error($db);
1181 }
1182 
1183 
1184 llxFooter();
1185 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
const TYPE_STANDARD
Standard invoice.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
Class to build HTML component for third parties management Only common components are here...
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.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
Class to manage HTML output components for orders Before adding component here, check they are not in...
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
Class to manage customers orders.
Classe permettant la generation de composants html autre Only common components are here...
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...
dol_now($mode='gmt')
Return date for now.
Class to manage predefined suppliers products.
Class to offer components to list and upload files.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
print
Draft customers invoices.
Definition: index.php:91
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
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
Class to manage absolute discounts.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage invoices.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.