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