PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/commande/orderstoinvoice.php

https://bitbucket.org/speedealing/speedealing
PHP | 693 lines | 537 code | 80 blank | 76 comment | 87 complexity | 3b69437fb18a2ab4ff0eb7948aed222f MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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 Juanjo Menent <jmenent@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/commande/orderstoinvoice.php
  25. * \ingroup commande
  26. * \brief Page to invoice multiple orders
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
  35. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  36. $langs->load('orders');
  37. $langs->load('deliveries');
  38. $langs->load('companies');
  39. if (! $user->rights->facture->creer)
  40. accessforbidden();
  41. $id = (GETPOST('id')?GETPOST("id"):GETPOST("facid")); // For backward compatibility
  42. $ref = GETPOST('ref','alpha');
  43. $action = GETPOST('action','alpha');
  44. $confirm = GETPOST('confirm','alpha');
  45. $sref = GETPOST('sref');
  46. $sref_client = GETPOST('sref_client');
  47. $sall = GETPOST('sall');
  48. $socid = GETPOST('socid','int');
  49. $sortfield = GETPOST("sortfield",'alpha');
  50. $sortorder = GETPOST("sortorder",'alpha');
  51. if (! $sortfield) $sortfield='c.rowid';
  52. if (! $sortorder) $sortorder='DESC';
  53. $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); // Date for local PHP server
  54. $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);
  55. $date_starty=dol_mktime(0,0,0,$_REQUEST["date_start_delymonth"],$_REQUEST["date_start_delyday"],$_REQUEST["date_start_delyyear"]); // Date for local PHP server
  56. $date_endy=dol_mktime(23,59,59,$_REQUEST["date_end_delymonth"],$_REQUEST["date_end_delyday"],$_REQUEST["date_end_delyyear"]);
  57. $selected=GETPOST('orders_to_invoice');
  58. $action=GETPOST('action','alpha');
  59. if ($action == 'create')
  60. {
  61. if (! is_array($selected))
  62. {
  63. $mesgs[]='<div class="error">'.$langs->trans('Error_OrderNotChecked').'</div>';
  64. }
  65. else
  66. {
  67. $socid=GETPOST('socid');
  68. $action=GETPOST('action');
  69. $origin=GETPOST('origin');
  70. $originid=GETPOST('originid');
  71. }
  72. }
  73. $now=dol_now();
  74. $viewstatut=GETPOST('viewstatut');
  75. /*
  76. * Actions
  77. */
  78. if (($action == 'create' || $action == 'add') && empty($mesgs))
  79. {
  80. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  81. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  82. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  83. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  84. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  85. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  86. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  87. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  88. if (! empty($conf->projet->enabled)) {
  89. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  90. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  91. }
  92. $langs->load('bills');
  93. $langs->load('products');
  94. $langs->load('main');
  95. if (isset($_GET['orders_to_invoice']))
  96. {
  97. $orders_id = $_GET['orders_to_invoice'];
  98. $n = count($orders_id);
  99. $i = 0;
  100. $originid=$orders_id[0];
  101. $_GET['originid']=$orders_id[0];
  102. }
  103. if (isset($_POST['orders_to_invoice']))
  104. {
  105. $orders_id = $_POST['orders_to_invoice'];
  106. $nn = count($orders_id);
  107. $ii = 0;
  108. $originid=$orders_id[0];
  109. $_POST['originid']=$orders_id[0];
  110. }
  111. $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
  112. $lineid = GETPOST('lineid','int');
  113. $userid = GETPOST('userid','int');
  114. $search_ref = GETPOST('sf_ref')?GETPOST('sf_ref'):GETPOST('search_ref');
  115. $closeOrders = GETPOST('autocloseorders') != '' ? true : false;
  116. // Security check
  117. $fieldid = GETPOST('ref','alpha')?'facnumber':'rowid';
  118. if ($user->societe_id) $socid=$user->societe_id;
  119. $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
  120. $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
  121. $object=new Facture($db);
  122. // Insert new invoice in database
  123. if ($action == 'add' && $user->rights->facture->creer)
  124. {
  125. $object->socid=GETPOST('socid');
  126. $db->begin();
  127. $error=0;
  128. // Standard or deposit or proforma invoice
  129. if ($_POST['type'] == 0 )
  130. {
  131. $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  132. if (empty($datefacture))
  133. {
  134. $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
  135. }
  136. if (! $error)
  137. {
  138. // Si facture standard
  139. $object->socid = $_POST['socid'];
  140. $object->type = $_POST['type'];
  141. $object->number = $_POST['facnumber'];
  142. $object->date = $datefacture;
  143. $object->note_public = trim($_POST['note_public']);
  144. $object->note = trim($_POST['note']);
  145. $object->ref_client = $_POST['ref_client'];
  146. $object->ref_int = $_POST['ref_int'];
  147. $object->modelpdf = $_POST['model'];
  148. $object->fk_project = $_POST['projectid'];
  149. $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
  150. $object->mode_reglement_id = $_POST['mode_reglement_id'];
  151. $object->amount = $_POST['amount'];
  152. $object->remise_absolue = $_POST['remise_absolue'];
  153. $object->remise_percent = $_POST['remise_percent'];
  154. if ($_POST['origin'] && $_POST['originid'])
  155. {
  156. $object->origin = $_POST['origin'];
  157. $object->origin_id = $orders_id[$ii];
  158. $object->linked_objects = $orders_id;
  159. $id = $object->create($user);
  160. if ($id>0)
  161. {
  162. foreach($orders_id as $origin => $origin_id)
  163. {
  164. $origin_id = (! empty($origin_id) ? $origin_id : $object->origin_id);
  165. $db->begin();
  166. $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
  167. $sql.= "fk_source";
  168. $sql.= ", sourcetype";
  169. $sql.= ", fk_target";
  170. $sql.= ", targettype";
  171. $sql.= ") VALUES (";
  172. $sql.= $origin_id;
  173. $sql.= ", '".$object->origin."'";
  174. $sql.= ", ".$id;
  175. $sql.= ", '".$object->element."'";
  176. $sql.= ")";
  177. if ($db->query($sql))
  178. {
  179. $db->commit();
  180. }
  181. else
  182. {
  183. $db->rollback();
  184. }
  185. }
  186. while ($ii < $nn)
  187. {
  188. dol_include_once('/commande/class/commande.class.php');
  189. $srcobject = new Commande($db);
  190. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  191. $result=$srcobject->fetch($orders_id[$ii]);
  192. if ($result > 0)
  193. {
  194. if($closeOrders) {
  195. $srcobject->classer_facturee();
  196. $srcobject->setStatut(3);
  197. }
  198. $lines = $srcobject->lines;
  199. if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
  200. $fk_parent_line=0;
  201. $num=count($lines);
  202. for ($i=0;$i<$num;$i++)
  203. {
  204. $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
  205. if ($lines[$i]->subprice < 0)
  206. {
  207. // Negative line, we create a discount line
  208. $discount = new DiscountAbsolute($db);
  209. $discount->fk_soc=$object->socid;
  210. $discount->amount_ht=abs($lines[$i]->total_ht);
  211. $discount->amount_tva=abs($lines[$i]->total_tva);
  212. $discount->amount_ttc=abs($lines[$i]->total_ttc);
  213. $discount->tva_tx=$lines[$i]->tva_tx;
  214. $discount->fk_user=$user->id;
  215. $discount->description=$desc;
  216. $discountid=$discount->create($user);
  217. if ($discountid > 0)
  218. {
  219. $result=$object->insert_discount($discountid);
  220. //$result=$discount->link_to_invoice($lineid,$id);
  221. }
  222. else
  223. {
  224. $mesgs[]=$discount->error;
  225. $error++;
  226. break;
  227. }
  228. }
  229. else
  230. {
  231. // Positive line
  232. $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
  233. // Date start
  234. $date_start=false;
  235. if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
  236. if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
  237. if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
  238. //Date end
  239. $date_end=false;
  240. if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
  241. if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
  242. if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
  243. // Reset fk_parent_line for no child products and special product
  244. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
  245. {
  246. $fk_parent_line = 0;
  247. }
  248. $result = $object->addline(
  249. $id,
  250. $desc,
  251. $lines[$i]->subprice,
  252. $lines[$i]->qty,
  253. $lines[$i]->tva_tx,
  254. $lines[$i]->localtax1_tx,
  255. $lines[$i]->localtax2_tx,
  256. $lines[$i]->fk_product,
  257. $lines[$i]->remise_percent,
  258. $date_start,
  259. $date_end,
  260. 0,
  261. $lines[$i]->info_bits,
  262. $lines[$i]->fk_remise_except,
  263. 'HT',
  264. 0,
  265. $product_type,
  266. $lines[$i]->rang,
  267. $lines[$i]->special_code,
  268. $object->origin,
  269. $lines[$i]->rowid,
  270. $fk_parent_line
  271. );
  272. if ($result > 0)
  273. {
  274. $lineid=$result;
  275. }
  276. else
  277. {
  278. $lineid=0;
  279. $error++;
  280. break;
  281. }
  282. // Defined the new fk_parent_line
  283. if ($result > 0 && $lines[$i]->product_type == 9)
  284. {
  285. $fk_parent_line = $result;
  286. }
  287. }
  288. }
  289. }
  290. else
  291. {
  292. $mesgs[]=$srcobject->error;
  293. $error++;
  294. }
  295. $ii++;
  296. }
  297. }
  298. else
  299. {
  300. $mesgs[]=$object->error;
  301. $error++;
  302. }
  303. }
  304. }
  305. }
  306. // End of object creation, we show it
  307. if ($id > 0 && ! $error)
  308. {
  309. $db->commit();
  310. header('Location: '.DOL_URL_ROOT.'/compta/facture.php?facid='.$id);
  311. exit;
  312. }
  313. else
  314. {
  315. $db->rollback();
  316. $action='create';
  317. $_GET["origin"]=$_POST["origin"];
  318. $_GET["originid"]=$_POST["originid"];
  319. $mesgs[]='<div class="error">'.$object->error.'</div>';
  320. }
  321. }
  322. }
  323. /*
  324. * View
  325. */
  326. $html = new Form($db);
  327. $htmlother = new FormOther($db);
  328. $formfile = new FormFile($db);
  329. $companystatic = new Societe($db);
  330. // Mode creation
  331. if ($action == 'create')
  332. {
  333. $facturestatic=new Facture($db);
  334. llxHeader();
  335. print_fiche_titre($langs->trans('NewBill'));
  336. $soc = new Societe($db);
  337. if ($socid) $res=$soc->fetch($socid);
  338. if ($res)
  339. {
  340. $cond_reglement_id = $soc->cond_reglement_id;
  341. $mode_reglement_id = $soc->mode_reglement_id;
  342. $remise_percent = $soc->remise_percent;
  343. }
  344. $remise_absolue = 0;
  345. $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
  346. $absolute_discount=$soc->getAvailableDiscounts();
  347. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  348. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  349. print '<input type="hidden" name="action" value="add">';
  350. print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
  351. print '<input name="facnumber" type="hidden" value="provisoire">';
  352. print '<input name="ref_client" type="hidden" value="'.$ref_client.'">';
  353. print '<input name="ref_int" type="hidden" value="'.$ref_int.'">';
  354. print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
  355. print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
  356. print '<input type="hidden" name="autocloseorders" value="'.GETPOST('autocloseorders').'">';
  357. print '<table class="border" width="100%">';
  358. // Ref
  359. print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
  360. // Third party
  361. print '<tr><td class="fieldrequired">'.$langs->trans('Customer').'</td><td colspan="2">';
  362. print $soc->getNomUrl(1);
  363. print '<input type="hidden" name="socid" value="'.$soc->id.'">';
  364. print '</td>';
  365. print '</tr>'."\n";
  366. // Type
  367. print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('Type').'</td><td colspan="2">';
  368. print '<table class="nobordernopadding">'."\n";
  369. // Standard invoice
  370. print '<tr height="18"><td width="16px" valign="middle">';
  371. print '<input type="radio" name="type" value="0"'.(GETPOST('type')==0?' checked="true"':'').'>';
  372. print '</td><td valign="middle">';
  373. $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
  374. print $desc;
  375. print '</td></tr>'."\n";
  376. print '</table>';
  377. // Date invoice
  378. print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
  379. $html->select_date(0,'','','','',"add",1,1);
  380. print '</td></tr>';
  381. // Payment term
  382. print '<tr><td nowrap>'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
  383. $html->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id');
  384. print '</td></tr>';
  385. // Payment mode
  386. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
  387. $html->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id');
  388. print '</td></tr>';
  389. // Project
  390. if (! empty($conf->projet->enabled))
  391. {
  392. $langs->load('projects');
  393. print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
  394. select_projects($soc->id, $projectid, 'projectid');
  395. print '</td></tr>';
  396. }
  397. // Modele PDF
  398. print '<tr><td>'.$langs->trans('Model').'</td>';
  399. print '<td>';
  400. include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  401. $liste=ModelePDFFactures::liste_modeles($db);
  402. print $html->selectarray('model',$liste,$conf->global->FACTURE_ADDON_PDF);
  403. print "</td></tr>";
  404. // Public note
  405. print '<tr>';
  406. print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
  407. print '<td valign="top" colspan="2">';
  408. print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
  409. dol_include_once('/commande/class/commande.class.php');
  410. $srcobject = new Commande($db);
  411. $listoforders = '';
  412. foreach ($selected as $sel)
  413. {
  414. $result=$srcobject->fetch($sel);
  415. if ($result > 0)
  416. {
  417. $listoforders .= ($listoforders?', ':'').$srcobject->ref;
  418. }
  419. }
  420. print $langs->trans("Orders").": ".$listoforders;
  421. print '</textarea></td></tr>';
  422. // Private note
  423. if (! $user->societe_id)
  424. {
  425. print '<tr>';
  426. print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
  427. print '<td valign="top" colspan="2">';
  428. print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
  429. print '</textarea></td></tr>';
  430. }
  431. print '</table>';
  432. while ($i < $n)
  433. {
  434. print '<input type="hidden" name="orders_to_invoice[]" value="'.$orders_id[$i].'">';
  435. $i++;
  436. }
  437. // Button "Create Draft"
  438. print '<br><center><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'" /></center>';
  439. print "</form>\n";
  440. print '</td></tr>';
  441. print "</table>\n";
  442. }
  443. //Mode liste
  444. if (($action != 'create' && $action != 'add') || ! empty($mesgs))
  445. {
  446. llxHeader();
  447. ?>
  448. <script type="text/javascript">
  449. jQuery(document).ready(function() {
  450. jQuery("#checkall").click(function() {
  451. jQuery(".checkformerge").attr('checked', true);
  452. });
  453. jQuery("#checknone").click(function() {
  454. jQuery(".checkformerge").attr('checked', false);
  455. });
  456. });
  457. </script>
  458. <?php
  459. $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  460. $sql.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
  461. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  462. $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
  463. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  464. $sql.= ' WHERE c.entity = '.$conf->entity;
  465. $sql.= ' AND c.fk_soc = s.rowid';
  466. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  467. $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  468. if ($socid) $sql.= ' AND s.rowid = '.$socid;
  469. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  470. if ($sref)
  471. {
  472. $sql.= " AND c.ref LIKE '%".$db->escape($sref)."%'";
  473. }
  474. if ($sall)
  475. {
  476. $sql.= " AND (c.ref LIKE '%".$db->escape($sall)."%' OR c.note LIKE '%".$db->escape($sall)."%')";
  477. }
  478. //Date filter
  479. if ($date_start && $date_end) $sql.= " AND c.date_commande >= '".$db->idate($date_start)."' AND c.date_commande <= '".$db->idate($date_end)."'";
  480. if ($date_starty && $date_endy) $sql.= " AND c.date_livraison >= '".$db->idate($date_starty)."' AND c.date_livraison <= '".$db->idate($date_endy)."'";
  481. if (!empty($sref_client))
  482. {
  483. $sql.= ' AND c.ref_client LIKE \'%'.$db->escape($sref_client).'%\'';
  484. }
  485. $sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
  486. $resql = $db->query($sql);
  487. if ($resql)
  488. {
  489. if ($socid)
  490. {
  491. $soc = new Societe($db);
  492. $soc->fetch($socid);
  493. }
  494. $title = $langs->trans('ListOfOrders');
  495. $title.=' - '.$langs->trans('StatusOrderValidated').', '.$langs->trans("StatusOrderSent").', '.$langs->trans('StatusOrderToBill');
  496. $num = $db->num_rows($resql);
  497. print_fiche_titre($title);
  498. $i = 0;
  499. $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);
  500. $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);
  501. if (! empty($socid))
  502. {
  503. // Company
  504. $companystatic->id=$socid;
  505. $companystatic->nom=$soc->nom;
  506. print '<h3>'.$companystatic->getNomUrl(1,'customer').'</h3>';
  507. }
  508. print '<table class="noborder" width="100%">';
  509. print '<tr class="liste_titre">';
  510. print_liste_field_titre($langs->trans('Ref'),'orderstoinvoice.php','c.ref','','&amp;socid='.$socid,'',$sortfield,$sortorder);
  511. print_liste_field_titre($langs->trans('RefCustomerOrder'),'orderstoinvoice.php','c.ref_client','','&amp;socid='.$socid,'',$sortfield,$sortorder);
  512. print_liste_field_titre($langs->trans('OrderDate'),'orderstoinvoice.php','c.date_commande','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
  513. print_liste_field_titre($langs->trans('DeliveryDate'),'orderstoinvoice.php','c.date_livraison','','&amp;socid='.$socid, 'align="center"',$sortfield,$sortorder);
  514. print_liste_field_titre($langs->trans('Status'),'','','','','align="right"');
  515. print_liste_field_titre($langs->trans('GenerateBill'),'','','','','align="center"');
  516. print '</tr>';
  517. // Lignes des champs de filtre
  518. print '<form method="get" action="orderstoinvoice.php">';
  519. print '<input type="hidden" name="socid" value="'.$socid.'">';
  520. print '<tr class="liste_titre">';
  521. print '<td class="liste_titre">';
  522. //REF
  523. print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
  524. print '</td>';
  525. //print '<td class="liste_titre">';
  526. print '<td class="liste_titre" align="left">';
  527. print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
  528. //DATE ORDER
  529. print '<td class="liste_titre" align="center">';
  530. print $period;
  531. print '</td>';
  532. //DATE DELIVERY
  533. print '<td class="liste_titre" align="center">';
  534. print $periodely;
  535. print '</td>';
  536. //SEARCH BUTTON
  537. print '</td><td align="right" class="liste_titre">';
  538. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  539. //ALL/NONE
  540. print '<td class="liste_titre" align="center">';
  541. if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a>';
  542. print '</td>';
  543. print '</td></tr>';
  544. print '</form>';
  545. print '<form name="orders2invoice" action="orderstoinvoice.php" method="GET">';
  546. $var=True;
  547. $generic_commande = new Commande($db);
  548. while ($i < $num)
  549. {
  550. $objp = $db->fetch_object($resql);
  551. $var=!$var;
  552. print '<tr '.$bc[$var].'>';
  553. print '<td nowrap="nowrap">';
  554. $generic_commande->id=$objp->rowid;
  555. $generic_commande->ref=$objp->ref;
  556. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  557. print '<td class="nobordernopadding" nowrap="nowrap">';
  558. print $generic_commande->getNomUrl(1,$objp->fk_statut);
  559. print '</td>';
  560. print '<td width="20" class="nobordernopadding" nowrap="nowrap">';
  561. if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && $db->jdate($objp->date_valid) < ($now - $conf->commande->client->warning_delay)) print img_picto($langs->trans("Late"),"warning");
  562. print '</td>';
  563. print '<td width="16" align="right" class="nobordernopadding">';
  564. $filename=dol_sanitizeFileName($objp->ref);
  565. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
  566. $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->rowid;
  567. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  568. print '</td></tr></table>';
  569. print '</td>';
  570. print '<td>'.$objp->ref_client.'</td>';
  571. // Order date
  572. print '<td align="center" nowrap>';
  573. print dol_print_date($db->jdate($objp->date_commande),'day');
  574. print '</td>';
  575. //Delivery date
  576. print '<td align="center" nowrap>';
  577. print dol_print_date($db->jdate($objp->date_livraison),'day');
  578. print '</td>';
  579. // Statut
  580. print '<td align="right" nowrap="nowrap">'.$generic_commande->LibStatut($objp->fk_statut,$objp->facturee,5).'</td>';
  581. // Checkbox
  582. print '<td align="center">';
  583. print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="'.$objp->rowid.'">';
  584. print '</td>' ;
  585. print '</tr>';
  586. $total = $total + $objp->price;
  587. $subtotal = $subtotal + $objp->price;
  588. $i++;
  589. }
  590. print '</table>';
  591. /*
  592. * Boutons actions
  593. */
  594. print '<center><br><input type="checkbox" checked="checked" name="autocloseorders"> '.$langs->trans("CloseProcessedOrdersAutomatically");
  595. print '<div align="right">';
  596. print '<input type="hidden" name="socid" value="'.$socid.'">';
  597. print '<input type="hidden" name="action" value="create">';
  598. print '<input type="hidden" name="origin" value="commande"><br>';
  599. //print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
  600. print '<input type="submit" class="butAction" value="'.$langs->trans("GenerateBill").'">';
  601. print '</div>';
  602. print '</form>';
  603. $db->free($resql);
  604. }
  605. else
  606. {
  607. print dol_print_error($db);
  608. }
  609. }
  610. dol_htmloutput_mesg($mesg,$mesgs);
  611. llxFooter();
  612. $db->close();
  613. ?>