orderstoinvoice.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  10. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  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. /**
  26. * \file htdocs/fourn/commande/orderstoinvoice.php
  27. * \ingroup commande
  28. * \brief Page to invoice multiple supplier orders
  29. */
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php';
  37. require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
  38. if (! empty($conf->projet->enabled)) {
  39. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  40. }
  41. $langs->load('orders');
  42. $langs->load('deliveries');
  43. $langs->load('companies');
  44. if (! $user->rights->fournisseur->facture->creer)
  45. accessforbidden();
  46. $id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST("facid")); // For backward compatibility
  47. $ref = GETPOST('ref', 'alpha');
  48. $action = GETPOST('action', 'alpha');
  49. $confirm = GETPOST('confirm', 'alpha');
  50. $sref = GETPOST('sref');
  51. $sref_client = GETPOST('sref_client');
  52. $sall = GETPOST('sall');
  53. $socid = GETPOST('socid', 'int');
  54. $selected = GETPOST('orders_to_invoice');
  55. $sortfield = GETPOST("sortfield", 'alpha');
  56. $sortorder = GETPOST("sortorder", 'alpha');
  57. $viewstatut = GETPOST('viewstatut');
  58. if (! $sortfield)
  59. $sortfield = 'c.rowid';
  60. if (! $sortorder)
  61. $sortorder = 'DESC';
  62. $now = dol_now();
  63. $date_start = dol_mktime(0, 0, 0, $_REQUEST["date_startmonth"], $_REQUEST["date_startday"], $_REQUEST["date_startyear"]); // Date for local PHP server
  64. $date_end = dol_mktime(23, 59, 59, $_REQUEST["date_endmonth"], $_REQUEST["date_endday"], $_REQUEST["date_endyear"]);
  65. $date_starty = dol_mktime(0, 0, 0, $_REQUEST["date_start_delymonth"], $_REQUEST["date_start_delyday"], $_REQUEST["date_start_delyyear"]); // Date for local PHP server
  66. $date_endy = dol_mktime(23, 59, 59, $_REQUEST["date_end_delymonth"], $_REQUEST["date_end_delyday"], $_REQUEST["date_end_delyyear"]);
  67. if ($action == 'create')
  68. {
  69. if (! is_array($selected))
  70. {
  71. $error++;
  72. setEventMessages($langs->trans('Error_OrderNotChecked'), null, 'errors');
  73. } else {
  74. $origin = GETPOST('origin');
  75. $originid = GETPOST('originid');
  76. }
  77. }
  78. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  79. include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
  80. $hookmanager = new HookManager($db);
  81. $hookmanager->initHooks(array('orderstoinvoicesupplier'));
  82. /*
  83. * Actions
  84. */
  85. if (($action == 'create' || $action == 'add') && ! $error) {
  86. require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
  87. if (! empty($conf->projet->enabled))
  88. require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  89. $langs->load('bills');
  90. $langs->load('products');
  91. $langs->load('main');
  92. if (isset($_GET['orders_to_invoice'])) {
  93. $orders_id = $_GET['orders_to_invoice'];
  94. $n = count($orders_id);
  95. $i = 0;
  96. $originid = $orders_id[0];
  97. $_GET['originid'] = $orders_id[0];
  98. }
  99. if (isset($_POST['orders_to_invoice'])) {
  100. $orders_id = $_POST['orders_to_invoice'];
  101. $nn = count($orders_id);
  102. $ii = 0;
  103. $originid = $orders_id[0];
  104. $_POST['originid'] = $orders_id[0];
  105. }
  106. $projectid = GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0;
  107. $lineid = GETPOST('lineid', 'int');
  108. $userid = GETPOST('userid', 'int');
  109. $search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref') : GETPOST('search_ref');
  110. // Security check
  111. if ($user->societe_id)
  112. $socid = $user->societe_id;
  113. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  114. $usehm = $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
  115. $object = new FactureFournisseur($db);
  116. // Insert new invoice in database
  117. if ($action == 'add' && $user->rights->fournisseur->facture->creer) {
  118. $object->socid = GETPOST('socid');
  119. $db->begin();
  120. $error = 0;
  121. // Standard or deposit or proforma invoice
  122. $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  123. if (empty($datefacture)) {
  124. $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
  125. }
  126. if (! $error) {
  127. $object->ref = $_POST['ref'];
  128. $object->ref_supplier = $_POST['ref_supplier'];
  129. $object->socid = $_POST['socid'];
  130. $object->libelle = $_POST['libelle'];
  131. $object->date = $datefacture;
  132. $object->date_echeance = $datedue;
  133. $object->note_public = GETPOST('note_public');
  134. $object->note_private = GETPOST('note_private');
  135. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  136. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  137. $projectid = GETPOST('projectid');
  138. if ($projectid > 0)
  139. $object->fk_project = $projectid;
  140. // Auto calculation of date due if not filled by user
  141. if (empty($object->date_echeance))
  142. $object->date_echeance = $object->calculate_date_lim_reglement();
  143. if ($_POST['origin'] && $_POST['originid']) {
  144. $object->linked_objects = $orders_id;
  145. $id = $object->create($user);
  146. if ($id > 0) {
  147. foreach ( $orders_id as $origin => $origin_id ) {
  148. $origin_id = (! empty($origin_id) ? $origin_id : $orders_id[$ii]);
  149. $object->add_object_linked($_POST['origin'], $origin_id);
  150. }
  151. while ( $ii < $nn ) {
  152. $objectsrc = new CommandeFournisseur($db);
  153. dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
  154. $result = $objectsrc->fetch($orders_id[$ii]);
  155. if ($result > 0) {
  156. $lines = $objectsrc->lines;
  157. if (empty($lines) && method_exists($objectsrc, 'fetch_lines')) {
  158. $objectsrc->fetch_lines();
  159. $lines = $objectsrc->lines;
  160. }
  161. $fk_parent_line = 0;
  162. $num = count($lines);
  163. for($i = 0; $i < $num; $i ++) {
  164. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  165. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  166. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  167. // Dates
  168. // TODO mutualiser
  169. $date_start = $lines[$i]->date_debut_prevue;
  170. if ($lines[$i]->date_debut_reel)
  171. $date_start = $lines[$i]->date_debut_reel;
  172. if ($lines[$i]->date_start)
  173. $date_start = $lines[$i]->date_start;
  174. $date_end = $lines[$i]->date_fin_prevue;
  175. if ($lines[$i]->date_fin_reel)
  176. $date_end = $lines[$i]->date_fin_reel;
  177. if ($lines[$i]->date_end)
  178. $date_end = $lines[$i]->date_end;
  179. // Reset fk_parent_line for no child products and special product
  180. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  181. $fk_parent_line = 0;
  182. }
  183. // FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example.
  184. $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type, -1, false, 0, $lines[$i]->fk_unit);
  185. if ($result > 0) {
  186. $lineid = $result;
  187. } else {
  188. $lineid = 0;
  189. $error ++;
  190. break;
  191. }
  192. // Defined the new fk_parent_line
  193. if ($result > 0 && $lines[$i]->product_type == 9) {
  194. $fk_parent_line = $result;
  195. }
  196. }
  197. } else {
  198. $mesgs[] = $objectsrc->error;
  199. $error ++;
  200. }
  201. $ii ++;
  202. }
  203. } else {
  204. $mesgs[] = $object->error;
  205. $error ++;
  206. }
  207. }
  208. }
  209. // End of object creation, we show it
  210. if ($id > 0 && ! $error) {
  211. foreach($orders_id as $fk_supplier_order) {
  212. $supplier_order = new CommandeFournisseur($db);
  213. if ($supplier_order->fetch($fk_supplier_order)>0 && $supplier_order->statut == 5)
  214. {
  215. if ($supplier_order->classifyBilled($user) < 0)
  216. {
  217. $db->rollback();
  218. $action = 'create';
  219. $_GET["origin"] = $_POST["origin"];
  220. $_GET["originid"] = $_POST["originid"];
  221. $mesgs[] = '<div class="error">' . $object->error . '</div>';
  222. $error++;
  223. break;
  224. }
  225. }
  226. }
  227. if(!$error) {
  228. $db->commit();
  229. header('Location: ' . DOL_URL_ROOT . '/fourn/facture/card.php?facid=' . $id);
  230. exit();
  231. }
  232. } else {
  233. $db->rollback();
  234. $action = 'create';
  235. $_GET["origin"] = $_POST["origin"];
  236. $_GET["originid"] = $_POST["originid"];
  237. $mesgs[] = '<div class="error">' . $object->error . '</div>';
  238. }
  239. }
  240. }
  241. /*
  242. * View
  243. */
  244. $html = new Form($db);
  245. $htmlother = new FormOther($db);
  246. $formfile = new FormFile($db);
  247. $companystatic = new Societe($db);
  248. // Mode creation
  249. if ($action == 'create' && !$error) {
  250. llxHeader();
  251. print load_fiche_titre($langs->trans('NewBill'));
  252. $soc = new Societe($db);
  253. if ($socid)
  254. $res = $soc->fetch($socid);
  255. if ($res) {
  256. $cond_reglement_id = $soc->cond_reglement_id;
  257. $mode_reglement_id = $soc->mode_reglement_id;
  258. }
  259. $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE) ? - 1 : '';
  260. print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  261. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  262. print '<input type="hidden" name="action" value="add">';
  263. print '<input type="hidden" name="socid" value="' . $soc->id . '">' . "\n";
  264. print '<input name="facnumber" type="hidden" value="provisoire">';
  265. print '<input name="ref_client" type="hidden" value="' . $ref_client . '">';
  266. print '<input name="ref_int" type="hidden" value="' . $ref_int . '">';
  267. print '<input type="hidden" name="origin" value="' . GETPOST('origin') . '">';
  268. print '<input type="hidden" name="originid" value="' . GETPOST('originid') . '">';
  269. print '<table class="border" width="100%">';
  270. // Ref
  271. print '<tr><td class="fieldrequired">' . $langs->trans('Ref') . '</td><td colspan="2">' . $langs->trans('Draft') . '</td></tr>';
  272. // Ref supplier
  273. print '<tr><td class="fieldrequired">' . $langs->trans('RefSupplier') . '</td><td><input name="ref_supplier" value="' . (isset($_POST['ref_supplier']) ? $_POST['ref_supplier'] : '') . '" type="text"></td>';
  274. print '</tr>';
  275. // Third party
  276. print '<tr><td class="fieldrequired">' . $langs->trans('Customer') . '</td><td colspan="2">';
  277. print $soc->getNomUrl(1);
  278. print '<input type="hidden" name="socid" value="' . $soc->id . '">';
  279. print '</td>';
  280. print '</tr>' . "\n";
  281. // Date invoice
  282. print '<tr><td class="fieldrequired">' . $langs->trans('Date') . '</td><td colspan="2">';
  283. $html->select_date('', '', '', '', '', "add", 1, 1);
  284. print '</td></tr>';
  285. // Payment term
  286. print '<tr><td class="nowrap">' . $langs->trans('PaymentConditionsShort') . '</td><td colspan="2">';
  287. $html->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id');
  288. print '</td></tr>';
  289. // Payment mode
  290. print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td colspan="2">';
  291. $html->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id');
  292. print '</td></tr>';
  293. // Project
  294. if (! empty($conf->projet->enabled)) {
  295. $formproject = new FormProjets($db);
  296. $langs->load('projects');
  297. print '<tr><td>' . $langs->trans('Project') . '</td><td colspan="2">';
  298. $formproject->select_projects($soc->id, $projectid, 'projectid');
  299. print '</td></tr>';
  300. }
  301. $objectsrc = new CommandeFournisseur($db);
  302. $listoforders = array ();
  303. foreach ( $selected as $sel ) {
  304. $result = $objectsrc->fetch($sel);
  305. if ($result > 0) {
  306. $listoforders[] = $objectsrc->ref;
  307. }
  308. }
  309. // Other attributes
  310. $parameters = array (
  311. 'objectsrc' => $objectsrc,
  312. 'idsrc' => $listoforders,
  313. 'colspan' => ' colspan="3"'
  314. );
  315. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  316. // Modele PDF
  317. print '<tr><td>' . $langs->trans('Model') . '</td>';
  318. print '<td>';
  319. $liste = ModelePDFSuppliersInvoices::liste_modeles($db);
  320. print $html->selectarray('model', $liste, $conf->global->INVOICE_SUPPLIER_ADDON_PDF);
  321. print "</td></tr>";
  322. // Public note
  323. print '<tr>';
  324. print '<td class="border" valign="top">' . $langs->trans('NotePublic') . '</td>';
  325. print '<td valign="top" colspan="2">';
  326. print '<textarea name="note_public" wrap="soft" cols="70" rows="' . ROWS_3 . '">';
  327. print $langs->trans("Orders") . ": " . implode(', ', $listoforders);
  328. print '</textarea></td></tr>';
  329. // Private note
  330. if (empty($user->societe_id)) {
  331. print '<tr>';
  332. print '<td class="border" valign="top">' . $langs->trans('NotePrivate') . '</td>';
  333. print '<td valign="top" colspan="2">';
  334. print '<textarea name="note" wrap="soft" cols="70" rows="' . ROWS_3 . '">';
  335. print '</textarea></td></tr>';
  336. }
  337. print '</table>';
  338. while ( $i < $n ) {
  339. print '<input type="hidden" name="orders_to_invoice[]" value="' . $orders_id[$i] . '">';
  340. $i ++;
  341. }
  342. // Button "Create Draft"
  343. print '<br><div class="center"><input type="submit" class="button" name="bouton" value="' . $langs->trans('CreateDraft') . '" /></div>';
  344. print "</form>\n";
  345. print '</td></tr>';
  346. print "</table>\n";
  347. }
  348. // Mode liste
  349. if (($action != 'create' && $action != 'add') && !$error) {
  350. llxHeader();
  351. ?>
  352. <script type="text/javascript">
  353. jQuery(document).ready(function() {
  354. jQuery("#checkall").click(function() {
  355. jQuery(".checkformerge").prop('checked', true);
  356. });
  357. jQuery("#checknone").click(function() {
  358. jQuery(".checkformerge").prop('checked', false);
  359. });
  360. });
  361. </script>
  362. <?php
  363. $sql = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
  364. $sql .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
  365. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s';
  366. $sql .= ', ' . MAIN_DB_PREFIX . 'commande_fournisseur as c';
  367. if (! $user->rights->societe->client->voir && ! $socid)
  368. $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
  369. $sql .= ' WHERE c.entity = ' . $conf->entity;
  370. $sql .= ' AND c.fk_soc = s.rowid';
  371. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  372. $sql .= " AND c.fk_statut IN (5)";
  373. $sql .= " AND c.billed = 0";
  374. // Find order that are not already invoiced
  375. //No need due to the billed status
  376. //$sql .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
  377. if ($socid)
  378. $sql .= ' AND s.rowid = ' . $socid;
  379. if (! $user->rights->societe->client->voir && ! $socid)
  380. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
  381. if ($sref) {
  382. $sql .= " AND c.ref LIKE '%" . $db->escape($sref) . "%'";
  383. }
  384. if ($sall) {
  385. $sql .= " AND (c.ref LIKE '%" . $db->escape($sall) . "%' OR c.note LIKE '%" . $db->escape($sall) . "%')";
  386. }
  387. // Date filter
  388. if ($date_start && $date_end)
  389. $sql .= " AND c.date_commande >= '" . $db->idate($date_start) . "' AND c.date_commande <= '" . $db->idate($date_end) . "'";
  390. if ($date_starty && $date_endy)
  391. $sql .= " AND c.date_livraison >= '" . $db->idate($date_starty) . "' AND c.date_livraison <= '" . $db->idate($date_endy) . "'";
  392. if (! empty($sref_client)) {
  393. $sql .= ' AND c.ref_supplier LIKE \'%' . $db->escape($sref_client) . '%\'';
  394. }
  395. $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder;
  396. dol_syslog('fourn/commande/ordertoinvoice.php sql=' . $sql);
  397. $resql = $db->query($sql);
  398. if ($resql) {
  399. if ($socid) {
  400. $soc = new Societe($db);
  401. $soc->fetch($socid);
  402. }
  403. $title = $langs->trans('ListOfSupplierOrders');
  404. $title .= ' - ' . $langs->trans('StatusOrderReceivedAllShort');
  405. $num = $db->num_rows($resql);
  406. print load_fiche_titre($title);
  407. $i = 0;
  408. $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);
  409. $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);
  410. if (! empty($socid)) {
  411. // Company
  412. $companystatic->id = $socid;
  413. $companystatic->nom = $soc->nom;
  414. print '<h3>' . $companystatic->getNomUrl(1, 'customer') . '</h3>';
  415. }
  416. print '<form method="get" action="orderstoinvoice.php">';
  417. print '<input type="hidden" name="socid" value="' . $socid . '">';
  418. print '<table class="noborder" width="100%">';
  419. print '<tr class="liste_titre">';
  420. print_liste_field_titre($langs->trans('Ref'), 'orderstoinvoice.php', 'c.ref', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder);
  421. print_liste_field_titre($langs->trans('RefSupplier'), 'orderstoinvoice.php', 'c.ref_supplier', '', '&amp;socid=' . $socid, '', $sortfield, $sortorder);
  422. print_liste_field_titre($langs->trans('OrderDate'), 'orderstoinvoice.php', 'c.date_commande', '', '&amp;socid=' . $socid, 'align="center"', $sortfield, $sortorder);
  423. print_liste_field_titre($langs->trans('DeliveryDate'), 'orderstoinvoice.php', 'c.date_livraison', '', '&amp;socid=' . $socid, 'align="center"', $sortfield, $sortorder);
  424. print_liste_field_titre($langs->trans('Status'), '', '', '', '', 'align="right"');
  425. print_liste_field_titre($langs->trans('GenerateBill'), '', '', '', '', 'align="center"');
  426. print "</tr>\n";
  427. // Lignes des champs de filtre
  428. print '<tr class="liste_titre">';
  429. print '<td class="liste_titre">';
  430. // REF
  431. print '<input class="flat" size="10" type="text" name="sref" value="' . $sref . '">';
  432. print '</td>';
  433. // print '<td class="liste_titre">';
  434. print '<td class="liste_titre" align="left">';
  435. print '<input class="flat" type="text" size="10" name="sref_client" value="' . $sref_client . '">';
  436. print '</td>';
  437. // DATE ORDER
  438. print '<td class="liste_titre" align="center">';
  439. print $period;
  440. print '</td>';
  441. // DATE DELIVERY
  442. print '<td class="liste_titre" align="center">';
  443. print $periodely;
  444. print '</td>';
  445. // SEARCH BUTTON
  446. print '<td align="right" class="liste_titre">';
  447. 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")) . '">';
  448. print '</td>';
  449. // ALL/NONE
  450. print '<td class="liste_titre" align="center">';
  451. if ($conf->use_javascript_ajax)
  452. print '<a href="#" id="checkall">' . $langs->trans("All") . '</a> / <a href="#" id="checknone">' . $langs->trans("None") . '</a>';
  453. print '</td>';
  454. print '</td></tr>';
  455. print '<form name="orders2invoice" action="orderstoinvoice.php" method="GET">';
  456. $var = True;
  457. $generic_commande = new CommandeFournisseur($db);
  458. while ( $i < $num ) {
  459. $objp = $db->fetch_object($resql);
  460. $var = ! $var;
  461. print '<tr ' . $bc[$var] . '>';
  462. print '<td class="nowrap">';
  463. $generic_commande->id = $objp->rowid;
  464. $generic_commande->ref = $objp->ref;
  465. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  466. print '<td class="nobordernopadding nowrap">';
  467. print $generic_commande->getNomUrl(1, $objp->fk_statut);
  468. print '</td>';
  469. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  470. $filename = dol_sanitizeFileName($objp->ref);
  471. $filedir = $conf->fournisseur->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref);
  472. $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $objp->rowid;
  473. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  474. print '</td></tr></table>';
  475. print '</td>';
  476. print '<td>' . $objp->ref_supplier . '</td>';
  477. // Order date
  478. print '<td align="center" nowrap>';
  479. print dol_print_date($db->jdate($objp->date_commande), 'day');
  480. print '</td>';
  481. // Delivery date
  482. print '<td align="center" nowrap>';
  483. print dol_print_date($db->jdate($objp->date_livraison), 'day');
  484. print '</td>';
  485. // Statut
  486. print '<td align="right" class="nowrap">' . $generic_commande->LibStatut($objp->fk_statut, 5) . '</td>';
  487. // Checkbox
  488. print '<td class="center">';
  489. print '<input class="flat checkformerge" type="checkbox" name="orders_to_invoice[]" value="' . $objp->rowid . '">';
  490. print '</td>';
  491. print '</tr>';
  492. $total = $total + $objp->price;
  493. $subtotal = $subtotal + $objp->price;
  494. $i ++;
  495. }
  496. print '</table>';
  497. /*
  498. * Boutons actions
  499. */
  500. print '<div class="center">';
  501. print '<div class="right">';
  502. print '<input type="hidden" name="socid" value="' . $socid . '">';
  503. print '<input type="hidden" name="action" value="create">';
  504. print '<input type="hidden" name="origin" value="order_supplier"><br>';
  505. // print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
  506. print '<input type="submit" class="butAction" value="' . $langs->trans("GenerateBill") . '">';
  507. print '</div>';
  508. print '</div>';
  509. print '</form>';
  510. $db->free($resql);
  511. } else {
  512. print dol_print_error($db);
  513. }
  514. }
  515. dol_htmloutput_mesg($mesg, $mesgs);
  516. llxFooter();
  517. $db->close();