dolibarr  9.0.0
orderstoinvoice.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2012 Andreu Bisquerra Gaya <jove@bisquerra.com>
7  * Copyright (C) 2012 David Rodriguez Martinez <davidrm146@gmail.com>
8  * Copyright (C) 2012-2018 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
39 if (! empty($conf->projet->enabled)) {
40  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
41 }
42 
43 // Load translation files required by the page
44 $langs->loadLangs(array("orders", "deliveries", "companies"));
45 
46 if (! $user->rights->facture->creer)
48 
49 $id = (GETPOST('id')?GETPOST('id','int'):GETPOST("facid","int")); // For backward compatibility
50 $ref = GETPOST('ref','alpha');
51 $action = GETPOST('action','alpha');
52 $confirm = GETPOST('confirm','alpha');
53 $sref = GETPOST('sref');
54 $sref_client = GETPOST('sref_client');
55 $sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
56 $socid = GETPOST('socid','int');
57 $selected = GETPOST('orders_to_invoice');
58 $sortfield = GETPOST("sortfield",'alpha');
59 $sortorder = GETPOST("sortorder",'alpha');
60 $viewstatut = GETPOST('viewstatut');
61 
62 $error = 0;
63 
64 if (! $sortfield) $sortfield='c.rowid';
65 if (! $sortorder) $sortorder='DESC';
66 
67 $now = dol_now();
68 $date_start = dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); // Date for local PHP server
69 $date_end = dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
70 $date_starty = dol_mktime(0,0,0,$_REQUEST["date_start_delymonth"],$_REQUEST["date_start_delyday"],$_REQUEST["date_start_delyyear"]); // Date for local PHP server
71 $date_endy = dol_mktime(23,59,59,$_REQUEST["date_end_delymonth"],$_REQUEST["date_end_delyday"],$_REQUEST["date_end_delyyear"]);
72 
73 $extrafields = new ExtraFields($db);
74 
75 // fetch optionals attributes and labels
76 $extralabels=$extrafields->fetch_name_optionals_label('facture');
77 
78 if ($action == 'create')
79 {
80  if (! is_array($selected))
81  {
82  $error++;
83  setEventMessages($langs->trans('Error_OrderNotChecked'), null, 'errors');
84  }
85  else
86  {
87  $origin = GETPOST('origin');
88  $originid = GETPOST('originid');
89  }
90 }
91 
92 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
93 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
94 $hookmanager=new HookManager($db);
95 $hookmanager->initHooks(array('orderstoinvoice'));
96 
97 
98 /*
99  * Actions
100  */
101 
102 if (($action == 'create' || $action == 'add') && !$error)
103 {
104  require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
105  require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
106  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
107  require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
108  if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
109 
110  $langs->load('bills');
111  $langs->load('products');
112  $langs->load('main');
113  if (isset($_GET['orders_to_invoice']))
114  {
115  $orders_id = GETPOST('orders_to_invoice','',1);
116  $n = count($orders_id);
117  $i = 0;
118 
119  $originid=$orders_id[0];
120  $_GET['originid']=$orders_id[0];
121  }
122  if (isset($_POST['orders_to_invoice']))
123  {
124  $orders_id = GETPOST('orders_to_invoice','',2);
125  $nn = count($orders_id);
126  $ii = 0;
127 
128  $originid=$orders_id[0];
129  $_POST['originid']=$orders_id[0];
130  }
131 
132  $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
133  $lineid = GETPOST('lineid','int');
134  $userid = GETPOST('userid','int');
135  $search_ref = GETPOST('sf_ref')?GETPOST('sf_ref'):GETPOST('search_ref');
136  $closeOrders = GETPOST('autocloseorders') ? true : false;
137 
138  // Security check
139  $fieldid = GETPOST('ref','alpha')?'facnumber':'rowid';
140  if ($user->societe_id) $socid=$user->societe_id;
141  $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
142 
143  $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
144  $object=new Facture($db);
145 
146  // Insert new invoice in database
147  if ($action == 'add' && $user->rights->facture->creer)
148  {
149  $object->socid=GETPOST('socid');
150  $db->begin();
151  $error=0;
152 
153  // Standard or deposit or proforma invoice
154  if ($_POST['type'] == 0 )
155  {
156  $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
157  if (empty($datefacture))
158  {
159  $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
160  }
161  if (! $error)
162  {
163  // Si facture standard
164  $object->socid = $_POST['socid'];
165  $object->type = $_POST['type'];
166  $object->number = $_POST['facnumber'];
167  $object->date = $datefacture;
168  $object->note_public = trim($_POST['note_public']);
169  $object->note = trim($_POST['note']);
170  $object->ref_client = $_POST['ref_client'];
171  $object->ref_int = $_POST['ref_int'];
172  $object->modelpdf = $_POST['model'];
173  $object->fk_project = $_POST['projectid'];
174  $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
175  $object->mode_reglement_id = $_POST['mode_reglement_id'];
176  $object->amount = $_POST['amount'];
177  $object->remise_absolue = $_POST['remise_absolue'];
178  $object->remise_percent = $_POST['remise_percent'];
179 
180  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
181  if ($ret < 0) $error++;
182 
183  if ($_POST['origin'] && $_POST['originid'])
184  {
185  $object->origin = $_POST['origin'];
186  $object->origin_id = $orders_id[$ii];
187  $object->linked_objects = $orders_id;
188  $id = $object->create($user);
189  $object->fetch_thirdparty();
190 
191  if ($id>0)
192  {
193  foreach($orders_id as $origin => $origin_id)
194  {
195  $origin_id = (! empty($origin_id) ? $origin_id : $object->origin_id);
196  $db->begin();
197  $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
198  $sql.= "fk_source";
199  $sql.= ", sourcetype";
200  $sql.= ", fk_target";
201  $sql.= ", targettype";
202  $sql.= ") VALUES (";
203  $sql.= $origin_id;
204  $sql.= ", '".$object->origin."'";
205  $sql.= ", ".$id;
206  $sql.= ", '".$object->element."'";
207  $sql.= ")";
208 
209  if ($db->query($sql))
210  {
211  $db->commit();
212  }
213  else
214  {
215  $db->rollback();
216  }
217  }
218 
219  while ($ii < $nn)
220  {
221  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
222  $objectsrc = new Commande($db);
223  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
224  $result=$objectsrc->fetch($orders_id[$ii]);
225  if ($result > 0)
226  {
227  if ($closeOrders)
228  {
229  $objectsrc->classifyBilled($user);
230  $objectsrc->setStatut(3);
231  }
232  $lines = $objectsrc->lines;
233  if (empty($lines) && method_exists($objectsrc, 'fetch_lines'))
234  {
235  $objectsrc->fetch_lines();
236  $lines = $objectsrc->lines;
237  }
238  $fk_parent_line=0;
239  $num=count($lines);
240  for ($i=0;$i<$num;$i++)
241  {
242  $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
243  if ($lines[$i]->subprice < 0)
244  {
245  // Negative line, we create a discount line
246  $discount = new DiscountAbsolute($db);
247  $discount->fk_soc=$object->socid;
248  $discount->amount_ht=abs($lines[$i]->total_ht);
249  $discount->amount_tva=abs($lines[$i]->total_tva);
250  $discount->amount_ttc=abs($lines[$i]->total_ttc);
251  $discount->tva_tx=$lines[$i]->tva_tx;
252  $discount->fk_user=$user->id;
253  $discount->description=$desc;
254  $discountid=$discount->create($user);
255  if ($discountid > 0)
256  {
257  $result=$object->insert_discount($discountid);
258  //$result=$discount->link_to_invoice($lineid,$id);
259  }
260  else
261  {
262  setEventMessages($discount->error, $discount->errors, 'errors');
263  $error++;
264  break;
265  }
266  }
267  else
268  {
269  // Positive line
270  $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
271  // Date start
272  $date_start=false;
273  if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
274  if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
275  if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
276  //Date end
277  $date_end=false;
278  if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
279  if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
280  if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
281  // Reset fk_parent_line for no child products and special product
282  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
283  {
284  $fk_parent_line = 0;
285  }
286 
287  // Extrafields
288  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
289  $lines[$i]->fetch_optionals($lines[$i]->rowid);
290  $array_options = $lines[$i]->array_options;
291  }
292 
293  $result = $object->addline(
294  $desc,
295  $lines[$i]->subprice,
296  $lines[$i]->qty,
297  $lines[$i]->tva_tx,
298  $lines[$i]->localtax1_tx,
299  $lines[$i]->localtax2_tx,
300  $lines[$i]->fk_product,
301  $lines[$i]->remise_percent,
302  $date_start,
303  $date_end,
304  0,
305  $lines[$i]->info_bits,
306  $lines[$i]->fk_remise_except,
307  'HT',
308  0,
309  $product_type,
310  $ii,
311  $lines[$i]->special_code,
312  $object->origin,
313  $lines[$i]->rowid,
314  $fk_parent_line,
315  $lines[$i]->fk_fournprice,
316  $lines[$i]->pa_ht,
317  $lines[$i]->label,
318  $array_options
319  );
320  if ($result > 0)
321  {
322  $lineid=$result;
323  }
324  else
325  {
326  $lineid=0;
327  $error++;
328  break;
329  }
330  // Defined the new fk_parent_line
331  if ($result > 0 && $lines[$i]->product_type == 9)
332  {
333  $fk_parent_line = $result;
334  }
335  }
336  }
337  }
338  else
339  {
340  setEventMessages($objectsrc->error, $objectsrc->errors, 'errors');
341  $error++;
342  }
343  $ii++;
344  }
345  }
346  else
347  {
348  setEventMessages($object->error, $object->errors, 'errors');
349  $error++;
350  }
351  }
352  }
353  }
354 
355  // End of object creation, we show it
356  if ($id > 0 && ! $error)
357  {
358  $db->commit();
359  header('Location: '.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$id);
360  exit;
361  }
362  else
363  {
364  $db->rollback();
365  $action='create';
366  $_GET["origin"]=$_POST["origin"];
367  $_GET["originid"]=$_POST["originid"];
368  setEventMessages($object->error, $object->errors, 'errors');
369  $error++;
370  }
371  }
372 }
373 
374 
375 /*
376  * View
377  */
378 
379 $html = new Form($db);
380 $htmlother = new FormOther($db);
381 $formfile = new FormFile($db);
382 $companystatic = new Societe($db);
383 
384 // Mode creation
385 if ($action == 'create' && !$error)
386 {
387  $facturestatic=new Facture($db);
388 
389  llxHeader();
390  print load_fiche_titre($langs->trans('NewBill'));
391 
392  $soc = new Societe($db);
393  if ($socid) $res=$soc->fetch($socid);
394  if ($res)
395  {
396  $cond_reglement_id = $soc->cond_reglement_id;
397  $mode_reglement_id = $soc->mode_reglement_id;
398  $remise_percent = $soc->remise_percent;
399  }
400  $remise_absolue = 0;
401  $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:'';
402 
403  $absolute_discount=$soc->getAvailableDiscounts();
404  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
405  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
406  print '<input type="hidden" name="action" value="add">';
407  print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
408  print '<input name="facnumber" type="hidden" value="provisoire">';
409  print '<input name="ref_client" type="hidden" value="'.$ref_client.'">';
410  print '<input name="ref_int" type="hidden" value="'.$ref_int.'">';
411  print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
412  print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
413  print '<input type="hidden" name="autocloseorders" value="'.GETPOST('autocloseorders').'">';
414 
415  dol_fiche_head();
416 
417  print '<table class="border" width="100%">';
418 
419  // Ref
420  print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
421 
422  // Third party
423  print '<tr><td class="fieldrequired">'.$langs->trans('Customer').'</td><td>';
424  print $soc->getNomUrl(1);
425  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
426  print '</td>';
427  print '</tr>'."\n";
428 
429  // Type
430  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Type').'</td><td>';
431  print '<table class="nobordernopadding">'."\n";
432 
433  // Standard invoice
434  print '<tr height="18"><td width="16px" valign="middle">';
435  print '<input type="radio" name="type" value="0"'.(GETPOST('type')==0?' checked':'').'>';
436  print '</td><td valign="middle">';
437  $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
438  print $desc;
439  print '</td></tr>'."\n";
440  print '</table>';
441 
442  // Date invoice
443  print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
444  print $html->selectDate('', '', '', '', '', "add", 1, 1);
445  print '</td></tr>';
446  // Payment term
447  print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
448  $html->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
449  print '</td></tr>';
450  // Payment mode
451  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
452  $html->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
453  print '</td></tr>';
454  // Project
455  if (! empty($conf->projet->enabled))
456  {
457  $formproject=new FormProjets($db);
458 
459  $langs->load('projects');
460  print '<tr><td>'.$langs->trans('Project').'</td><td>';
461  $formproject->select_projects($soc->id, $projectid, 'projectid');
462  print '</td></tr>';
463  }
464 
465  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
466  $objectsrc = new Commande($db);
467  $listoforders = array();
468  foreach ($selected as $sel)
469  {
470  $result=$objectsrc->fetch($sel);
471  if ($result > 0)
472  {
473  $listoforders[] = $objectsrc->ref;
474  }
475  }
476 
477  // Other attributes
478  $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders);
479  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
480  print $hookmanager->resPrint;
481  if (empty($reshook))
482  {
483  $object=new Facture($db);
484  print $object->showOptionals($extrafields,'edit');
485  }
486 
487  // Modele PDF
488  print '<tr><td>'.$langs->trans('Model').'</td>';
489  print '<td>';
490  include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
492  print $html->selectarray('model',$liste,$conf->global->FACTURE_ADDON_PDF);
493  print "</td></tr>";
494 
495  // Public note
496  print '<tr>';
497  print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
498  print '<td valign="top">';
499  print '<textarea name="note_public" class="quatrevingtpercent" rows="'.ROWS_3.'">';
500 
501  print $langs->trans("Orders").": ".implode(', ', $listoforders);
502 
503  print '</textarea></td></tr>';
504  // Private note
505  if (empty($user->societe_id))
506  {
507  print '<tr>';
508  print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
509  print '<td valign="top">';
510  print '<textarea name="note" class="quatrevingtpercent" rows="'.ROWS_3.'">';
511 
512  print '</textarea></td></tr>';
513  }
514 
515  print '</table>';
516 
517  while ($i < $n)
518  {
519  print '<input type="hidden" name="orders_to_invoice[]" value="'.$orders_id[$i].'">';
520 
521  $i++;
522  }
523 
524  dol_fiche_end();
525 
526  // Button "Create Draft"
527  print '<div class="center"><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'" /></div>';
528  print "</form>\n";
529 
530  print '</td></tr>';
531  print "</table>\n";
532 }
533 
534 // Mode liste
535 if (($action != 'create' && $action != 'add') || ($action == 'create' && $error))
536 {
537  llxHeader();
538  ?>
539  <script type="text/javascript">
540  jQuery(document).ready(function() {
541  jQuery("#checkall").click(function() {
542  jQuery(".checkformerge").prop('checked', true);
543  });
544  jQuery("#checknone").click(function() {
545  jQuery(".checkformerge").prop('checked', false);
546  });
547  });
548  </script>
549  <?php
550 
551  $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
552  $sql.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
553  $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
554  $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
555  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
556  $sql.= ' WHERE c.entity IN ('.getEntity('commande').')';
557  $sql.= ' AND c.fk_soc = s.rowid';
558 
559  // Show orders with status validated, shipping started and delivered (well any order we can bill)
560  $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
561 
562  if ($socid) $sql.= ' AND s.rowid = '.$socid;
563  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
564  if ($sref)
565  {
566  $sql.= " AND c.ref LIKE '%".$db->escape($sref)."%'";
567  }
568  if ($sall)
569  {
570  $sql.= " AND (c.ref LIKE '%".$db->escape($sall)."%' OR c.note LIKE '%".$db->escape($sall)."%')";
571  }
572 
573  //Date filter
574  if ($date_start && $date_end) $sql.= " AND c.date_commande >= '".$db->idate($date_start)."' AND c.date_commande <= '".$db->idate($date_end)."'";
575  if ($date_starty && $date_endy) $sql.= " AND c.date_livraison >= '".$db->idate($date_starty)."' AND c.date_livraison <= '".$db->idate($date_endy)."'";
576 
577  if (!empty($sref_client))
578  {
579  $sql.= ' AND c.ref_client LIKE \'%'.$db->escape($sref_client).'%\'';
580  }
581  $sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
582  $resql = $db->query($sql);
583 
584  if ($resql)
585  {
586  if ($socid)
587  {
588  $soc = new Societe($db);
589  $soc->fetch($socid);
590  }
591  $title = $langs->trans('ListOfOrders');
592  $title.=' - '.$langs->trans('StatusOrderValidated').', '.$langs->trans("StatusOrderSent").', '.$langs->trans('StatusOrderToBill');
593  $num = $db->num_rows($resql);
594  print load_fiche_titre($title);
595  $i = 0;
596  $period=$html->selectDate($date_start,'date_start',0,0,1,'',1,0).' - '.$html->selectDate($date_end,'date_end',0,0,1,'',1,0);
597  $periodely=$html->selectDate($date_starty,'date_start_dely',0,0,1,'',1,0).' - '.$html->selectDate($date_endy,'date_end_dely',0,0,1,'',1,0);
598 
599  if (! empty($socid))
600  {
601  // Company
602  $companystatic->id=$socid;
603  $companystatic->name=$soc->name;
604  print '<h3>'.$companystatic->getNomUrl(1,'customer').'</h3>';
605  }
606 
607  print '<table class="noborder" width="100%">';
608  print '<tr class="liste_titre">';
609  print_liste_field_titre('Ref',$_SERVER["PHP_SELF"],'c.ref','','&amp;socid='.$socid,'',$sortfield,$sortorder);
610  print_liste_field_titre('RefCustomerOrder',$_SERVER["PHP_SELF"],'c.ref_client','','&amp;socid='.$socid,'',$sortfield,$sortorder);
611  print_liste_field_titre('OrderDate',$_SERVER["PHP_SELF"],'c.date_commande','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
612  print_liste_field_titre('DeliveryDate',$_SERVER["PHP_SELF"],'c.date_livraison','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
613  print_liste_field_titre('Status','','','','','align="right"');
614  print_liste_field_titre('GenerateBill','','','','','align="center"');
615  print '</tr>';
616 
617  // Lignes des champs de filtre
618  print '<form method="get" action="orderstoinvoice.php">';
619  print '<input type="hidden" name="socid" value="'.$socid.'">';
620  print '<tr class="liste_titre">';
621  print '<td class="liste_titre">';
622  //REF
623  print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
624  print '</td>';
625 
626  print '<td class="liste_titre" align="left">';
627  print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
628  print '</td>';
629 
630  //DATE ORDER
631  print '<td class="liste_titre" align="center">';
632  print $period;
633  print '</td>';
634 
635  //DATE DELIVERY
636  print '<td class="liste_titre" align="center">';
637  print $periodely;
638  print '</td>';
639 
640  //SEARCH BUTTON
641  print '<td align="right" class="liste_titre">';
642  print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
643  print '</td>';
644 
645  //ALL/NONE
646  print '<td align="center" class="liste_titre">';
647  if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a>';
648  print '</td>';
649 
650  print '</tr>';
651  print '</form>';
652 
653  print '<form name="orders2invoice" action="orderstoinvoice.php" method="GET">';
654 
655  $generic_commande = new Commande($db);
656 
657  while ($i < $num)
658  {
659  $objp = $db->fetch_object($resql);
660 
661  print '<tr class="oddeven">';
662  print '<td class="nowrap">';
663 
664  $generic_commande->id=$objp->rowid;
665  $generic_commande->ref=$objp->ref;
666  $generic_commande->statut = $objp->fk_statut;
667  $generic_commande->date_commande = $db->jdate($objp->date_commande);
668  $generic_commande->date_livraison = $db->jdate($objp->date_livraison);
669 
670  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
671  print '<td class="nobordernopadding nowrap">';
672  print $generic_commande->getNomUrl(1,0);
673  print '</td>';
674 
675  print '<td width="20" class="nobordernopadding nowrap">';
676  if ($generic_commande->hasDelay()) {
677  print img_picto($langs->trans("Late"),"warning");
678  }
679  print '</td>';
680 
681  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
682  $filename=dol_sanitizeFileName($objp->ref);
683  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
684  $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->rowid;
685  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
686  print '</td></tr></table>';
687  print '</td>';
688 
689  print '<td>'.$objp->ref_client.'</td>';
690 
691  // Order date
692  print '<td align="center" class="nowrap">';
693  print dol_print_date($db->jdate($objp->date_commande),'day');
694  print '</td>';
695 
696  //Delivery date
697  print '<td align="center" class="nowrap">';
698  print dol_print_date($db->jdate($objp->date_livraison),'day');
699  print '</td>';
700 
701  // Statut
702  print '<td align="right" class="nowrap">'.$generic_commande->LibStatut($objp->fk_statut,$objp->billed,5).'</td>';
703 
704  // Checkbox
705  print '<td align="center">';
706  print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="'.$objp->rowid.'">';
707  print '</td>' ;
708 
709  print '</tr>';
710 
711  $total = $total + $objp->price;
712  $subtotal = $subtotal + $objp->price;
713  $i++;
714  }
715  print '</table>';
716 
717  /*
718  * Boutons actions
719  */
720  print '<br><div class="center"><input type="checkbox" '.(empty($conf->global->INVOICE_CLOSE_ORDERS_OFF_BY_DEFAULT_FORMASSINVOICE)?' checked="checked"':'').' name="autocloseorders"> '.$langs->trans("CloseProcessedOrdersAutomatically");
721  print '<div align="right">';
722  print '<input type="hidden" name="socid" value="'.$socid.'">';
723  print '<input type="hidden" name="action" value="create">';
724  print '<input type="hidden" name="origin" value="commande"><br>';
725  //print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
726  print '<input type="submit" class="butAction" value="'.$langs->trans("GenerateBill").'">';
727  print '</div>';
728  print '</div>';
729  print '</form>';
730  $db->free($resql);
731  }
732  else
733  {
734  dol_print_error($db);
735  }
736 }
737 
738 // End of page
739 llxFooter();
740 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage hooks.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
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
dol_now($mode='gmt')
Return date for now.
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).
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.