dolibarr  7.0.0-beta
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@capnetworks.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-2017 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
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.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
38 if (! empty($conf->projet->enabled)) {
39  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
40 }
41 
42 $langs->load('orders');
43 $langs->load('deliveries');
44 $langs->load('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  }
123  if (isset($_POST['orders_to_invoice']))
124  {
125  $orders_id = GETPOST('orders_to_invoice','',2);
126  $nn = count($orders_id);
127  $ii = 0;
128 
129  $originid=$orders_id[0];
130  $_POST['originid']=$orders_id[0];
131 
132  }
133 
134  $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
135  $lineid = GETPOST('lineid','int');
136  $userid = GETPOST('userid','int');
137  $search_ref = GETPOST('sf_ref')?GETPOST('sf_ref'):GETPOST('search_ref');
138  $closeOrders = GETPOST('autocloseorders') ? true : false;
139 
140  // Security check
141  $fieldid = GETPOST('ref','alpha')?'facnumber':'rowid';
142  if ($user->societe_id) $socid=$user->societe_id;
143  $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
144 
145  $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
146  $object=new Facture($db);
147 
148  // Insert new invoice in database
149  if ($action == 'add' && $user->rights->facture->creer)
150  {
151  $object->socid=GETPOST('socid');
152  $db->begin();
153  $error=0;
154 
155  // Standard or deposit or proforma invoice
156  if ($_POST['type'] == 0 )
157  {
158  $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
159  if (empty($datefacture))
160  {
161  $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
162  }
163  if (! $error)
164  {
165  // Si facture standard
166  $object->socid = $_POST['socid'];
167  $object->type = $_POST['type'];
168  $object->number = $_POST['facnumber'];
169  $object->date = $datefacture;
170  $object->note_public = trim($_POST['note_public']);
171  $object->note = trim($_POST['note']);
172  $object->ref_client = $_POST['ref_client'];
173  $object->ref_int = $_POST['ref_int'];
174  $object->modelpdf = $_POST['model'];
175  $object->fk_project = $_POST['projectid'];
176  $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
177  $object->mode_reglement_id = $_POST['mode_reglement_id'];
178  $object->amount = $_POST['amount'];
179  $object->remise_absolue = $_POST['remise_absolue'];
180  $object->remise_percent = $_POST['remise_percent'];
181 
182  $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
183  if ($ret < 0) $error++;
184 
185  if ($_POST['origin'] && $_POST['originid'])
186  {
187  $object->origin = $_POST['origin'];
188  $object->origin_id = $orders_id[$ii];
189  $object->linked_objects = $orders_id;
190  $id = $object->create($user);
191  $object->fetch_thirdparty();
192 
193  if ($id>0)
194  {
195  foreach($orders_id as $origin => $origin_id)
196  {
197  $origin_id = (! empty($origin_id) ? $origin_id : $object->origin_id);
198  $db->begin();
199  $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
200  $sql.= "fk_source";
201  $sql.= ", sourcetype";
202  $sql.= ", fk_target";
203  $sql.= ", targettype";
204  $sql.= ") VALUES (";
205  $sql.= $origin_id;
206  $sql.= ", '".$object->origin."'";
207  $sql.= ", ".$id;
208  $sql.= ", '".$object->element."'";
209  $sql.= ")";
210 
211  if ($db->query($sql))
212  {
213  $db->commit();
214  }
215  else
216  {
217  $db->rollback();
218  }
219  }
220 
221  while ($ii < $nn)
222  {
223  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
224  $objectsrc = new Commande($db);
225  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
226  $result=$objectsrc->fetch($orders_id[$ii]);
227  if ($result > 0)
228  {
229  if ($closeOrders)
230  {
231  $objectsrc->classifyBilled($user);
232  $objectsrc->setStatut(3);
233  }
234  $lines = $objectsrc->lines;
235  if (empty($lines) && method_exists($objectsrc, 'fetch_lines'))
236  {
237  $objectsrc->fetch_lines();
238  $lines = $objectsrc->lines;
239  }
240  $fk_parent_line=0;
241  $num=count($lines);
242  for ($i=0;$i<$num;$i++)
243  {
244  $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
245  if ($lines[$i]->subprice < 0)
246  {
247  // Negative line, we create a discount line
248  $discount = new DiscountAbsolute($db);
249  $discount->fk_soc=$object->socid;
250  $discount->amount_ht=abs($lines[$i]->total_ht);
251  $discount->amount_tva=abs($lines[$i]->total_tva);
252  $discount->amount_ttc=abs($lines[$i]->total_ttc);
253  $discount->tva_tx=$lines[$i]->tva_tx;
254  $discount->fk_user=$user->id;
255  $discount->description=$desc;
256  $discountid=$discount->create($user);
257  if ($discountid > 0)
258  {
259  $result=$object->insert_discount($discountid);
260  //$result=$discount->link_to_invoice($lineid,$id);
261  }
262  else
263  {
264  setEventMessages($discount->error, $discount->errors, 'errors');
265  $error++;
266  break;
267  }
268  }
269  else
270  {
271  // Positive line
272  $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
273  // Date start
274  $date_start=false;
275  if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
276  if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
277  if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
278  //Date end
279  $date_end=false;
280  if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
281  if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
282  if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
283  // Reset fk_parent_line for no child products and special product
284  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
285  {
286  $fk_parent_line = 0;
287  }
288  $result = $object->addline(
289  $desc,
290  $lines[$i]->subprice,
291  $lines[$i]->qty,
292  $lines[$i]->tva_tx,
293  $lines[$i]->localtax1_tx,
294  $lines[$i]->localtax2_tx,
295  $lines[$i]->fk_product,
296  $lines[$i]->remise_percent,
297  $date_start,
298  $date_end,
299  0,
300  $lines[$i]->info_bits,
301  $lines[$i]->fk_remise_except,
302  'HT',
303  0,
304  $product_type,
305  $ii,
306  $lines[$i]->special_code,
307  $object->origin,
308  $lines[$i]->rowid,
309  $fk_parent_line,
310  $lines[$i]->fk_fournprice,
311  $lines[$i]->pa_ht,
312  $lines[$i]->label
313  );
314  if ($result > 0)
315  {
316  $lineid=$result;
317  }
318  else
319  {
320  $lineid=0;
321  $error++;
322  break;
323  }
324  // Defined the new fk_parent_line
325  if ($result > 0 && $lines[$i]->product_type == 9)
326  {
327  $fk_parent_line = $result;
328  }
329  }
330  }
331  }
332  else
333  {
334  setEventMessages($objectsrc->error, $objectsrc->errors, 'errors');
335  $error++;
336  }
337  $ii++;
338  }
339  }
340  else
341  {
342  setEventMessages($object->error, $object->errors, 'errors');
343  $error++;
344  }
345  }
346  }
347  }
348 
349  // End of object creation, we show it
350  if ($id > 0 && ! $error)
351  {
352  $db->commit();
353  header('Location: '.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$id);
354  exit;
355  }
356  else
357  {
358  $db->rollback();
359  $action='create';
360  $_GET["origin"]=$_POST["origin"];
361  $_GET["originid"]=$_POST["originid"];
362  setEventMessages($object->error, $object->errors, 'errors');
363  $error++;
364  }
365  }
366 }
367 
368 
369 /*
370  * View
371  */
372 
373 $html = new Form($db);
374 $htmlother = new FormOther($db);
375 $formfile = new FormFile($db);
376 $companystatic = new Societe($db);
377 
378 // Mode creation
379 if ($action == 'create' && !$error)
380 {
381  $facturestatic=new Facture($db);
382 
383  llxHeader();
384  print load_fiche_titre($langs->trans('NewBill'));
385 
386  $soc = new Societe($db);
387  if ($socid) $res=$soc->fetch($socid);
388  if ($res)
389  {
390  $cond_reglement_id = $soc->cond_reglement_id;
391  $mode_reglement_id = $soc->mode_reglement_id;
392  $remise_percent = $soc->remise_percent;
393  }
394  $remise_absolue = 0;
395  $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:'';
396 
397  $absolute_discount=$soc->getAvailableDiscounts();
398  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
399  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
400  print '<input type="hidden" name="action" value="add">';
401  print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
402  print '<input name="facnumber" type="hidden" value="provisoire">';
403  print '<input name="ref_client" type="hidden" value="'.$ref_client.'">';
404  print '<input name="ref_int" type="hidden" value="'.$ref_int.'">';
405  print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
406  print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
407  print '<input type="hidden" name="autocloseorders" value="'.GETPOST('autocloseorders').'">';
408 
409  dol_fiche_head();
410 
411  print '<table class="border" width="100%">';
412 
413  // Ref
414  print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
415 
416  // Third party
417  print '<tr><td class="fieldrequired">'.$langs->trans('Customer').'</td><td>';
418  print $soc->getNomUrl(1);
419  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
420  print '</td>';
421  print '</tr>'."\n";
422 
423  // Type
424  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Type').'</td><td>';
425  print '<table class="nobordernopadding">'."\n";
426 
427  // Standard invoice
428  print '<tr height="18"><td width="16px" valign="middle">';
429  print '<input type="radio" name="type" value="0"'.(GETPOST('type')==0?' checked':'').'>';
430  print '</td><td valign="middle">';
431  $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
432  print $desc;
433  print '</td></tr>'."\n";
434  print '</table>';
435 
436  // Date invoice
437  print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
438  $html->select_date('','','','','',"add",1,1);
439  print '</td></tr>';
440  // Payment term
441  print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
442  $html->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
443  print '</td></tr>';
444  // Payment mode
445  print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
446  $html->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
447  print '</td></tr>';
448  // Project
449  if (! empty($conf->projet->enabled))
450  {
451  $formproject=new FormProjets($db);
452 
453  $langs->load('projects');
454  print '<tr><td>'.$langs->trans('Project').'</td><td>';
455  $formproject->select_projects($soc->id, $projectid, 'projectid');
456  print '</td></tr>';
457  }
458 
459  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
460  $objectsrc = new Commande($db);
461  $listoforders = array();
462  foreach ($selected as $sel)
463  {
464  $result=$objectsrc->fetch($sel);
465  if ($result > 0)
466  {
467  $listoforders[] = $objectsrc->ref;
468  }
469  }
470 
471  // Other attributes
472  $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders);
473  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
474  print $hookmanager->resPrint;
475  if (empty($reshook) && ! empty($extrafields->attribute_label))
476  {
477  $object=new Facture($db);
478  print $object->showOptionals($extrafields,'edit');
479  }
480 
481  // Modele PDF
482  print '<tr><td>'.$langs->trans('Model').'</td>';
483  print '<td>';
484  include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
486  print $html->selectarray('model',$liste,$conf->global->FACTURE_ADDON_PDF);
487  print "</td></tr>";
488 
489  // Public note
490  print '<tr>';
491  print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
492  print '<td valign="top">';
493  print '<textarea name="note_public" class="quatrevingtpercent" rows="'.ROWS_3.'">';
494 
495  print $langs->trans("Orders").": ".implode(', ', $listoforders);
496 
497  print '</textarea></td></tr>';
498  // Private note
499  if (empty($user->societe_id))
500  {
501  print '<tr>';
502  print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
503  print '<td valign="top">';
504  print '<textarea name="note" class="quatrevingtpercent" rows="'.ROWS_3.'">';
505 
506  print '</textarea></td></tr>';
507  }
508 
509  print '</table>';
510 
511  while ($i < $n)
512  {
513  print '<input type="hidden" name="orders_to_invoice[]" value="'.$orders_id[$i].'">';
514 
515  $i++;
516  }
517 
518  dol_fiche_end();
519 
520  // Button "Create Draft"
521  print '<div class="center"><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'" /></div>';
522  print "</form>\n";
523 
524  print '</td></tr>';
525  print "</table>\n";
526 
527 
528 }
529 
530 // Mode liste
531 if (($action != 'create' && $action != 'add') || ($action == 'create' && $error))
532 {
533  llxHeader();
534  ?>
535  <script type="text/javascript">
536  jQuery(document).ready(function() {
537  jQuery("#checkall").click(function() {
538  jQuery(".checkformerge").prop('checked', true);
539  });
540  jQuery("#checknone").click(function() {
541  jQuery(".checkformerge").prop('checked', false);
542  });
543  });
544  </script>
545  <?php
546 
547  $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
548  $sql.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
549  $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
550  $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
551  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
552  $sql.= ' WHERE c.entity IN ('.getEntity('commande').')';
553  $sql.= ' AND c.fk_soc = s.rowid';
554 
555  // Show orders with status validated, shipping started and delivered (well any order we can bill)
556  $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
557 
558  if ($socid) $sql.= ' AND s.rowid = '.$socid;
559  if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
560  if ($sref)
561  {
562  $sql.= " AND c.ref LIKE '%".$db->escape($sref)."%'";
563  }
564  if ($sall)
565  {
566  $sql.= " AND (c.ref LIKE '%".$db->escape($sall)."%' OR c.note LIKE '%".$db->escape($sall)."%')";
567  }
568 
569  //Date filter
570  if ($date_start && $date_end) $sql.= " AND c.date_commande >= '".$db->idate($date_start)."' AND c.date_commande <= '".$db->idate($date_end)."'";
571  if ($date_starty && $date_endy) $sql.= " AND c.date_livraison >= '".$db->idate($date_starty)."' AND c.date_livraison <= '".$db->idate($date_endy)."'";
572 
573  if (!empty($sref_client))
574  {
575  $sql.= ' AND c.ref_client LIKE \'%'.$db->escape($sref_client).'%\'';
576  }
577  $sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
578  $resql = $db->query($sql);
579 
580  if ($resql)
581  {
582  if ($socid)
583  {
584  $soc = new Societe($db);
585  $soc->fetch($socid);
586  }
587  $title = $langs->trans('ListOfOrders');
588  $title.=' - '.$langs->trans('StatusOrderValidated').', '.$langs->trans("StatusOrderSent").', '.$langs->trans('StatusOrderToBill');
589  $num = $db->num_rows($resql);
590  print load_fiche_titre($title);
591  $i = 0;
592  $period=$html->select_date($date_start,'date_start',0,0,1,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,1,'',1,0,1);
593  $periodely=$html->select_date($date_starty,'date_start_dely',0,0,1,'',1,0,1).' - '.$html->select_date($date_endy,'date_end_dely',0,0,1,'',1,0,1);
594 
595  if (! empty($socid))
596  {
597  // Company
598  $companystatic->id=$socid;
599  $companystatic->name=$soc->name;
600  print '<h3>'.$companystatic->getNomUrl(1,'customer').'</h3>';
601  }
602 
603  print '<table class="noborder" width="100%">';
604  print '<tr class="liste_titre">';
605  print_liste_field_titre('Ref',$_SERVER["PHP_SELF"],'c.ref','','&amp;socid='.$socid,'',$sortfield,$sortorder);
606  print_liste_field_titre('RefCustomerOrder',$_SERVER["PHP_SELF"],'c.ref_client','','&amp;socid='.$socid,'',$sortfield,$sortorder);
607  print_liste_field_titre('OrderDate',$_SERVER["PHP_SELF"],'c.date_commande','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
608  print_liste_field_titre('DeliveryDate',$_SERVER["PHP_SELF"],'c.date_livraison','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
609  print_liste_field_titre('Status','','','','','align="right"');
610  print_liste_field_titre('GenerateBill','','','','','align="center"');
611  print '</tr>';
612 
613  // Lignes des champs de filtre
614  print '<form method="get" action="orderstoinvoice.php">';
615  print '<input type="hidden" name="socid" value="'.$socid.'">';
616  print '<tr class="liste_titre">';
617  print '<td class="liste_titre">';
618  //REF
619  print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
620  print '</td>';
621 
622  print '<td class="liste_titre" align="left">';
623  print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
624  print '</td>';
625 
626  //DATE ORDER
627  print '<td class="liste_titre" align="center">';
628  print $period;
629  print '</td>';
630 
631  //DATE DELIVERY
632  print '<td class="liste_titre" align="center">';
633  print $periodely;
634  print '</td>';
635 
636  //SEARCH BUTTON
637  print '<td align="right" class="liste_titre">';
638  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")).'">';
639  print '</td>';
640 
641  //ALL/NONE
642  print '<td align="center" class="liste_titre">';
643  if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a>';
644  print '</td>';
645 
646  print '</tr>';
647  print '</form>';
648 
649  print '<form name="orders2invoice" action="orderstoinvoice.php" method="GET">';
650  $var=true;
651  $generic_commande = new Commande($db);
652 
653  while ($i < $num)
654  {
655  $objp = $db->fetch_object($resql);
656 
657  print '<tr class="oddeven">';
658  print '<td class="nowrap">';
659 
660  $generic_commande->id=$objp->rowid;
661  $generic_commande->ref=$objp->ref;
662  $generic_commande->statut = $objp->fk_statut;
663  $generic_commande->date_commande = $db->jdate($objp->date_commande);
664  $generic_commande->date_livraison = $db->jdate($objp->date_livraison);
665 
666  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
667  print '<td class="nobordernopadding nowrap">';
668  print $generic_commande->getNomUrl(1,0);
669  print '</td>';
670 
671  print '<td width="20" class="nobordernopadding nowrap">';
672  if ($generic_commande->hasDelay()) {
673  print img_picto($langs->trans("Late"),"warning");
674  }
675  print '</td>';
676 
677  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
678  $filename=dol_sanitizeFileName($objp->ref);
679  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
680  $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->rowid;
681  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
682  print '</td></tr></table>';
683  print '</td>';
684 
685  print '<td>'.$objp->ref_client.'</td>';
686 
687  // Order date
688  print '<td align="center" class="nowrap">';
689  print dol_print_date($db->jdate($objp->date_commande),'day');
690  print '</td>';
691 
692  //Delivery date
693  print '<td align="center" class="nowrap">';
694  print dol_print_date($db->jdate($objp->date_livraison),'day');
695  print '</td>';
696 
697  // Statut
698  print '<td align="right" class="nowrap">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>';
699 
700  // Checkbox
701  print '<td align="center">';
702  print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="'.$objp->rowid.'">';
703  print '</td>' ;
704 
705  print '</tr>';
706 
707  $total = $total + $objp->price;
708  $subtotal = $subtotal + $objp->price;
709  $i++;
710  }
711  print '</table>';
712 
713  /*
714  * Boutons actions
715  */
716  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");
717  print '<div align="right">';
718  print '<input type="hidden" name="socid" value="'.$socid.'">';
719  print '<input type="hidden" name="action" value="create">';
720  print '<input type="hidden" name="origin" value="commande"><br>';
721  //print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
722  print '<input type="submit" class="butAction" value="'.$langs->trans("GenerateBill").'">';
723  print '</div>';
724  print '</div>';
725  print '</form>';
726  $db->free($resql);
727  }
728  else
729  {
730  dol_print_error($db);
731  }
732 
733 }
734 
735 llxFooter();
736 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
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_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage 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.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage building of HTML components.
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
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...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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).
print
Draft customers invoices.
Definition: index.php:91
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
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.
type
Definition: viewcat.php:283
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.