list.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/reception/list.php
  22. * \ingroup reception
  23. * \brief Page to list all receptions
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. $langs->loadLangs(array("sendings", "receptions", "deliveries", 'companies', 'bills', 'orders'));
  35. $socid = GETPOST('socid', 'int');
  36. $massaction = GETPOST('massaction', 'alpha');
  37. $toselect = GETPOST('toselect', 'array');
  38. $diroutputmassaction = $conf->reception->dir_output.'/temp/massgeneration/'.$user->id;
  39. $search_ref_rcp = GETPOST("search_ref_rcp");
  40. $search_ref_liv = GETPOST('search_ref_liv');
  41. $search_ref_supplier = GETPOST('search_ref_supplier');
  42. $search_company = GETPOST("search_company");
  43. $search_town = GETPOST('search_town', 'alpha');
  44. $search_zip = GETPOST('search_zip', 'alpha');
  45. $search_state = GETPOST("search_state");
  46. $search_country = GETPOST("search_country", 'int');
  47. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  48. $search_billed = GETPOST("search_billed", 'int');
  49. $sall = GETPOST('sall', 'alphanohtml');
  50. $optioncss = GETPOST('optioncss', 'alpha');
  51. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (!$sortfield) {
  56. $sortfield = "e.ref";
  57. }
  58. if (!$sortorder) {
  59. $sortorder = "DESC";
  60. }
  61. if (empty($page) || $page == -1) {
  62. $page = 0;
  63. } // If $page is not defined, or '' or -1
  64. $offset = $limit * $page;
  65. $pageprev = $page - 1;
  66. $pagenext = $page + 1;
  67. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  68. $contextpage = 'receptionlist';
  69. $search_status = GETPOST('search_status', 'intcomma');
  70. $object = new Reception($db);
  71. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  72. $hookmanager->initHooks(array('receptionlist'));
  73. $extrafields = new ExtraFields($db);
  74. // fetch optionals attributes and labels
  75. $extrafields->fetch_name_optionals_label($object->table_element);
  76. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  77. // List of fields to search into when doing a "search in all"
  78. $fieldstosearchall = array(
  79. 'e.ref'=>"Ref",
  80. 's.nom'=>"ThirdParty",
  81. 'e.note_public'=>'NotePublic',
  82. );
  83. if (empty($user->socid)) {
  84. $fieldstosearchall["e.note_private"] = "NotePrivate";
  85. }
  86. $checkedtypetiers = 0;
  87. $arrayfields = array(
  88. 'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  89. 'e.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
  90. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  91. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  92. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  93. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  94. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  95. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  96. 'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
  97. 'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  98. 'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  99. 'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  100. 'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)))
  101. );
  102. // Extra fields
  103. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  104. $object->fields = dol_sort_array($object->fields, 'position');
  105. $arrayfields = dol_sort_array($arrayfields, 'position');
  106. $error = 0;
  107. // Security check
  108. $receptionid = GETPOST('id', 'int');
  109. if ($user->socid) {
  110. $socid = $user->socid;
  111. }
  112. $result = restrictedArea($user, 'reception', $receptionid, '');
  113. /*
  114. * Actions
  115. */
  116. if (GETPOST('cancel')) {
  117. $action = 'list'; $massaction = '';
  118. }
  119. if (!GETPOST('confirmmassaction') && $massaction != 'confirm_createbills') {
  120. $massaction = '';
  121. }
  122. $parameters = array('socid'=>$socid);
  123. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  124. if ($reshook < 0) {
  125. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  126. }
  127. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  128. // Purge search criteria
  129. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  130. $search_ref_supplier = '';
  131. $search_ref_rcp = '';
  132. $search_ref_liv = '';
  133. $search_company = '';
  134. $search_town = '';
  135. $search_zip = "";
  136. $search_state = "";
  137. $search_country = '';
  138. $search_type_thirdparty = '';
  139. $search_billed = '';
  140. $search_status = '';
  141. $search_array_options = array();
  142. }
  143. if (empty($reshook)) {
  144. if ($massaction == 'confirm_createbills') {
  145. $receptions = GETPOST('toselect', 'array');
  146. $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
  147. $validate_invoices = GETPOST('validate_invoices', 'int');
  148. $errors = array();
  149. $TFact = array();
  150. $TFactThird = array();
  151. $nb_bills_created = 0;
  152. $lastid= 0;
  153. $lastref = '';
  154. $db->begin();
  155. foreach ($receptions as $id_reception) {
  156. $rcp = new Reception($db);
  157. // We only invoice reception that are validated
  158. if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != $rcp::STATUS_VALIDATED) {
  159. $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusSupplierOrderValidatedShort"));
  160. $error++;
  161. continue;
  162. }
  163. $objecttmp = new FactureFournisseur($db);
  164. if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
  165. // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
  166. $objecttmp = $TFactThird[$rcp->socid];
  167. // Add all links of this new reception to the existing invoice
  168. $objecttmp->fetchObjectLinked();
  169. $rcp->fetchObjectLinked();
  170. if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
  171. foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
  172. if (empty($objecttmp->linkedObjectsIds['order_supplier']) || !in_array($value, $objecttmp->linkedObjectsIds['order_supplier'])) { //Dont try to link if already linked
  173. $objecttmp->add_object_linked('order_supplier', $value); // add supplier order linked object
  174. }
  175. }
  176. }
  177. } else {
  178. // If we want one invoice per reception or if there is no first invoice yet for this thirdparty.
  179. $objecttmp->socid = $rcp->socid;
  180. $objecttmp->type = $objecttmp::TYPE_STANDARD;
  181. $objecttmp->cond_reglement_id = $rcp->cond_reglement_id || $rcp->thirdparty->cond_reglement_supplier_id;
  182. $objecttmp->mode_reglement_id = $rcp->mode_reglement_id || $rcp->thirdparty->mode_reglement_supplier_id;
  183. $objecttmp->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
  184. $objecttmp->remise_percent = !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
  185. $objecttmp->remise_absolue = !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
  186. $objecttmp->fk_project = $rcp->fk_project;
  187. //$objecttmp->multicurrency_code = $rcp->multicurrency_code;
  188. if (empty($createbills_onebythird)) {
  189. $objecttmp->ref_supplier = $rcp->ref;
  190. } else {
  191. // Set a unique value for the invoice for the n reception
  192. $objecttmp->ref_supplier = $langs->trans("Reception").' '.dol_print_date(dol_now(), 'dayhourlog').'-'.$rcp->socid;
  193. }
  194. $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  195. if (empty($datefacture)) {
  196. $datefacture = dol_now();
  197. }
  198. $objecttmp->date = $datefacture;
  199. $objecttmp->origin = 'reception';
  200. $objecttmp->origin_id = $id_reception;
  201. $objecttmp->array_options = $rcp->array_options; // Copy extrafields
  202. // Set $objecttmp->linked_objects with all links order_supplier existing on reception, so same links will be added to the generated supplier invoice
  203. $rcp->fetchObjectLinked();
  204. if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
  205. foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
  206. $objecttmp->linked_objects['order_supplier'] = $value;
  207. }
  208. }
  209. $res = $objecttmp->create($user); // This should create the supplier invoice + links into $objecttmp->linked_objects + add a link to ->origin_id
  210. //var_dump($objecttmp->error);exit;
  211. if ($res > 0) {
  212. $nb_bills_created++;
  213. $lastref = $objecttmp->ref;
  214. $lastid = $objecttmp->id;
  215. $TFactThird[$rcp->socid] = $objecttmp;
  216. } else {
  217. $langs->load("errors");
  218. $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
  219. $error++;
  220. }
  221. }
  222. if ($objecttmp->id > 0) {
  223. $res = $objecttmp->add_object_linked($objecttmp->origin, $id_reception);
  224. if ($res == 0) {
  225. $errors[] = $objecttmp->error;
  226. $error++;
  227. }
  228. if (!$error) {
  229. $lines = $rcp->lines;
  230. if (empty($lines) && method_exists($rcp, 'fetch_lines')) {
  231. $rcp->fetch_lines();
  232. $lines = $rcp->lines;
  233. }
  234. $fk_parent_line = 0;
  235. $num = count($lines);
  236. for ($i = 0; $i < $num; $i++) {
  237. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  238. // If we build one invoice for several reception, we must put the ref of reception on the invoice line
  239. if (!empty($createbills_onebythird)) {
  240. $desc = dol_concatdesc($desc, $langs->trans("Reception").' '.$rcp->ref.' - '.dol_print_date($rcp->date, 'day'));
  241. }
  242. if ($lines[$i]->subprice < 0) {
  243. // Negative line, we create a discount line
  244. $discount = new DiscountAbsolute($db);
  245. $discount->fk_soc = $objecttmp->socid;
  246. $discount->amount_ht = abs($lines[$i]->total_ht);
  247. $discount->amount_tva = abs($lines[$i]->total_tva);
  248. $discount->amount_ttc = abs($lines[$i]->total_ttc);
  249. $discount->tva_tx = $lines[$i]->tva_tx;
  250. $discount->fk_user = $user->id;
  251. $discount->description = $desc;
  252. $discountid = $discount->create($user);
  253. if ($discountid > 0) {
  254. $result = $objecttmp->insert_discount($discountid);
  255. //$result=$discount->link_to_invoice($lineid,$id);
  256. } else {
  257. setEventMessages($discount->error, $discount->errors, 'errors');
  258. $error++;
  259. break;
  260. }
  261. } else {
  262. // Positive line
  263. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  264. // Date start
  265. $date_start = false;
  266. if ($lines[$i]->date_debut_prevue) {
  267. $date_start = $lines[$i]->date_debut_prevue;
  268. }
  269. if ($lines[$i]->date_debut_reel) {
  270. $date_start = $lines[$i]->date_debut_reel;
  271. }
  272. if ($lines[$i]->date_start) {
  273. $date_start = $lines[$i]->date_start;
  274. }
  275. //Date end
  276. $date_end = false;
  277. if ($lines[$i]->date_fin_prevue) {
  278. $date_end = $lines[$i]->date_fin_prevue;
  279. }
  280. if ($lines[$i]->date_fin_reel) {
  281. $date_end = $lines[$i]->date_fin_reel;
  282. }
  283. if ($lines[$i]->date_end) {
  284. $date_end = $lines[$i]->date_end;
  285. }
  286. // Reset fk_parent_line for no child products and special product
  287. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  288. $fk_parent_line = 0;
  289. }
  290. // Extrafields
  291. if (method_exists($lines[$i], 'fetch_optionals')) {
  292. $lines[$i]->fetch_optionals();
  293. $array_options = $lines[$i]->array_options;
  294. }
  295. $objecttmp->context['createfromclone'];
  296. $result = $objecttmp->addline(
  297. $desc,
  298. $lines[$i]->subprice,
  299. $lines[$i]->tva_tx,
  300. $lines[$i]->localtax1_tx,
  301. $lines[$i]->localtax2_tx,
  302. $lines[$i]->qty,
  303. $lines[$i]->fk_product,
  304. $lines[$i]->remise_percent,
  305. $date_start,
  306. $date_end,
  307. 0,
  308. $lines[$i]->info_bits,
  309. 'HT',
  310. $product_type,
  311. $i,
  312. false,
  313. 0,
  314. null,
  315. $lines[$i]->rowid,
  316. 0,
  317. $lines[$i]->ref_supplier
  318. );
  319. $rcp->add_object_linked('facture_fourn_det', $result);
  320. if ($result > 0) {
  321. $lineid = $result;
  322. } else {
  323. $lineid = 0;
  324. $error++;
  325. break;
  326. }
  327. // Defined the new fk_parent_line
  328. if ($result > 0 && $lines[$i]->product_type == 9) {
  329. $fk_parent_line = $result;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
  336. if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
  337. $TFactThird[$rcp->socid] = $objecttmp;
  338. } else {
  339. $TFact[$objecttmp->id] = $objecttmp;
  340. }
  341. }
  342. // Build doc with all invoices
  343. $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
  344. $toselect = array();
  345. if (!$error && $validate_invoices) {
  346. $massaction = $action = 'builddoc';
  347. foreach ($TAllFact as &$objecttmp) {
  348. $result = $objecttmp->validate($user);
  349. if ($result <= 0) {
  350. $error++;
  351. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  352. break;
  353. }
  354. $id = $objecttmp->id; // For builddoc action
  355. $object =$objecttmp;
  356. // Fac builddoc
  357. $donotredirect = 1;
  358. $upload_dir = $conf->fournisseur->facture->dir_output;
  359. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  360. // Call action to build doc
  361. $savobject = $object;
  362. $object = $objecttmp;
  363. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  364. $object = $savobject;
  365. }
  366. $massaction = $action = 'confirm_createbills';
  367. }
  368. if (!$error) {
  369. $db->commit();
  370. if ($nb_bills_created == 1) {
  371. $texttoshow = $langs->trans('BillXCreated', '{s1}');
  372. $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
  373. setEventMessages($texttoshow, null, 'mesgs');
  374. } else {
  375. setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
  376. }
  377. } else {
  378. $db->rollback();
  379. $action = 'create';
  380. $_GET["origin"] = $_POST["origin"];
  381. $_GET["originid"] = $_POST["originid"];
  382. setEventMessages($object->error, $errors, 'errors');
  383. $error++;
  384. }
  385. }
  386. }
  387. /*
  388. * View
  389. */
  390. $form = new Form($db);
  391. $companystatic = new Societe($db);
  392. $reception = new Reception($db);
  393. $formcompany = new FormCompany($db);
  394. $formfile = new FormFile($db);
  395. $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
  396. llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
  397. $sql = "SELECT e.rowid, e.ref, e.ref_supplier, e.date_reception as date_reception, e.date_delivery as delivery_date, l.date_delivery as date_reception2, e.fk_statut, e.billed,";
  398. $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  399. $sql .= " typent.code as typent_code,";
  400. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  401. $sql .= ' e.date_creation as date_creation, e.tms as date_update';
  402. // Add fields from extrafields
  403. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  404. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  405. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
  406. }
  407. }
  408. // Add fields from hooks
  409. $parameters = array();
  410. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  411. $sql .= $hookmanager->resPrint;
  412. $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
  413. if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  414. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
  415. }
  416. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  417. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  418. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  419. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  420. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
  421. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
  422. if (!$user->rights->societe->client->voir && !$socid) { // Internal user with no permission to see all
  423. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  424. }
  425. $sql .= " WHERE e.entity IN (".getEntity('reception').")";
  426. if (!$user->rights->societe->client->voir && !$socid) { // Internal user with no permission to see all
  427. $sql .= " AND e.fk_soc = sc.fk_soc";
  428. $sql .= " AND sc.fk_user = ".((int) $user->id);
  429. }
  430. if ($socid) {
  431. $sql .= " AND e.fk_soc = ".((int) $socid);
  432. }
  433. if ($search_status <> '' && $search_status >= 0) {
  434. $sql .= " AND e.fk_statut = ".((int) $search_status);
  435. }
  436. if ($search_billed != '' && $search_billed >= 0) {
  437. $sql .= ' AND e.billed = '.((int) $search_billed);
  438. }
  439. if ($search_town) {
  440. $sql .= natural_search('s.town', $search_town);
  441. }
  442. if ($search_zip) {
  443. $sql .= natural_search("s.zip", $search_zip);
  444. }
  445. if ($search_state) {
  446. $sql .= natural_search("state.nom", $search_state);
  447. }
  448. if ($search_country) {
  449. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  450. }
  451. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  452. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  453. }
  454. if ($search_ref_rcp) {
  455. $sql .= natural_search('e.ref', $search_ref_rcp);
  456. }
  457. if ($search_ref_liv) {
  458. $sql .= natural_search('l.ref', $search_ref_liv);
  459. }
  460. if ($search_company) {
  461. $sql .= natural_search('s.nom', $search_company);
  462. }
  463. if ($search_ref_supplier) {
  464. $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
  465. }
  466. if ($sall) {
  467. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  468. }
  469. // Add where from extra fields
  470. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  471. // Add where from hooks
  472. $parameters = array();
  473. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  474. $sql .= $hookmanager->resPrint;
  475. $nbtotalofrecords = '';
  476. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  477. $result = $db->query($sql);
  478. $nbtotalofrecords = $db->num_rows($result);
  479. }
  480. $sql .= $db->order($sortfield, $sortorder);
  481. $sql .= $db->plimit($limit + 1, $offset);
  482. //print $sql;
  483. $resql = $db->query($sql);
  484. if (!$resql) {
  485. dol_print_error($db);
  486. exit;
  487. }
  488. $num = $db->num_rows($resql);
  489. $reception = new Reception($db);
  490. $arrayofselected = is_array($toselect) ? $toselect : array();
  491. $param = '';
  492. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  493. $param .= '&contextpage='.urlencode($contextpage);
  494. }
  495. if ($limit > 0 && $limit != $conf->liste_limit) {
  496. $param .= '&limit='.urlencode($limit);
  497. }
  498. if ($sall) {
  499. $param .= "&sall=".urlencode($sall);
  500. }
  501. if ($search_ref_rcp) {
  502. $param .= "&search_ref_rcp=".urlencode($search_ref_rcp);
  503. }
  504. if ($search_ref_liv) {
  505. $param .= "&search_ref_liv=".urlencode($search_ref_liv);
  506. }
  507. if ($search_company) {
  508. $param .= "&search_company=".urlencode($search_company);
  509. }
  510. if ($optioncss != '') {
  511. $param .= '&optioncss='.urlencode($optioncss);
  512. }
  513. if ($search_billed != '' && $search_billed >= 0) {
  514. $param .= "&search_billed=".urlencode($search_billed);
  515. }
  516. if ($search_town) {
  517. $param .= "&search_town=".urlencode($search_town);
  518. }
  519. if ($search_zip) {
  520. $param .= "&search_zip=".urlencode($search_zip);
  521. }
  522. if ($search_state) {
  523. $param .= "&search_state=".urlencode($search_state);
  524. }
  525. if ($search_status != '') {
  526. $param .= "&search_status=".urlencode($search_status);
  527. }
  528. if ($search_country) {
  529. $param .= "&search_country=".urlencode($search_country);
  530. }
  531. if ($search_type_thirdparty) {
  532. $param .= "&search_type_thirdparty=".urlencode($search_type_thirdparty);
  533. }
  534. if ($search_ref_supplier) {
  535. $param .= "&search_ref_supplier=".urlencode($search_ref_supplier);
  536. }
  537. // Add $param from extra fields
  538. if ($search_array_options) {
  539. foreach ($search_array_options as $key => $val) {
  540. $crit = $val;
  541. $tmpkey = preg_replace('/search_options_/', '', $key);
  542. if ($val != '') {
  543. $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
  544. }
  545. }
  546. }
  547. $arrayofmassactions = array(
  548. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  549. );
  550. if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
  551. $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisReceptions");
  552. }
  553. if ($massaction == 'createbills') {
  554. $arrayofmassactions = array();
  555. }
  556. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  557. //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  558. $i = 0;
  559. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  560. if ($optioncss != '') {
  561. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  562. }
  563. print '<input type="hidden" name="token" value="'.newToken().'">';
  564. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  565. print '<input type="hidden" name="action" value="list">';
  566. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  567. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  568. print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, '', '', $limit, 0, 0, 1);
  569. if ($massaction == 'createbills') {
  570. //var_dump($_REQUEST);
  571. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  572. print '<table class="noborder" width="100%" >';
  573. print '<tr>';
  574. print '<td class="titlefieldmiddle">';
  575. print $langs->trans('DateInvoice');
  576. print '</td>';
  577. print '<td>';
  578. print $form->selectDate('', '', '', '', '', '', 1, 1);
  579. print '</td>';
  580. print '</tr>';
  581. print '<tr>';
  582. print '<td>';
  583. print $langs->trans('CreateOneBillByThird');
  584. print '</td>';
  585. print '<td>';
  586. print $form->selectyesno('createbills_onebythird', '', 1);
  587. print '</td>';
  588. print '</tr>';
  589. print '<tr>';
  590. print '<td>';
  591. print $langs->trans('ValidateInvoices');
  592. print '</td>';
  593. print '<td>';
  594. if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
  595. print $form->selectyesno('validate_invoices', 0, 1, 1);
  596. print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
  597. } else {
  598. print $form->selectyesno('validate_invoices', 0, 1);
  599. }
  600. print '</td>';
  601. print '</tr>';
  602. print '</table>';
  603. print '<br>';
  604. print '<div class="center">';
  605. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisReceptions').'"> ';
  606. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  607. print '</div>';
  608. print '<br>';
  609. }
  610. if ($sall) {
  611. foreach ($fieldstosearchall as $key => $val) {
  612. $fieldstosearchall[$key] = $langs->trans($val);
  613. }
  614. print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
  615. }
  616. $moreforfilter = '';
  617. if (!empty($moreforfilter)) {
  618. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  619. print $moreforfilter;
  620. $parameters = array('type'=>$type);
  621. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  622. print $hookmanager->resPrint;
  623. print '</div>';
  624. }
  625. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  626. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  627. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  628. print '<div class="div-table-responsive">';
  629. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  630. // Fields title search
  631. // --------------------------------------------------------------------
  632. print '<tr class="liste_titre_filter">';
  633. // Ref
  634. if (!empty($arrayfields['e.ref']['checked'])) {
  635. print '<td class="liste_titre">';
  636. print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
  637. print '</td>';
  638. }
  639. // Ref customer
  640. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  641. print '<td class="liste_titre">';
  642. print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
  643. print '</td>';
  644. }
  645. // Thirdparty
  646. if (!empty($arrayfields['s.nom']['checked'])) {
  647. print '<td class="liste_titre left">';
  648. print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  649. print '</td>';
  650. }
  651. // Town
  652. if (!empty($arrayfields['s.town']['checked'])) {
  653. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  654. }
  655. // Zip
  656. if (!empty($arrayfields['s.zip']['checked'])) {
  657. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
  658. }
  659. // State
  660. if (!empty($arrayfields['state.nom']['checked'])) {
  661. print '<td class="liste_titre">';
  662. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  663. print '</td>';
  664. }
  665. // Country
  666. if (!empty($arrayfields['country.code_iso']['checked'])) {
  667. print '<td class="liste_titre center">';
  668. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  669. print '</td>';
  670. }
  671. // Company type
  672. if (!empty($arrayfields['typent.code']['checked'])) {
  673. print '<td class="liste_titre maxwidthonsmartphone center">';
  674. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  675. print '</td>';
  676. }
  677. // Date delivery planned
  678. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  679. print '<td class="liste_titre">&nbsp;</td>';
  680. }
  681. if (!empty($arrayfields['l.ref']['checked'])) {
  682. // Delivery ref
  683. print '<td class="liste_titre">';
  684. print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
  685. print '</td>';
  686. }
  687. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  688. // Date received
  689. print '<td class="liste_titre">&nbsp;</td>';
  690. }
  691. // Extra fields
  692. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  693. // Fields from hook
  694. $parameters = array('arrayfields'=>$arrayfields);
  695. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  696. print $hookmanager->resPrint;
  697. // Date creation
  698. if (!empty($arrayfields['e.datec']['checked'])) {
  699. print '<td class="liste_titre">';
  700. print '</td>';
  701. }
  702. // Date modification
  703. if (!empty($arrayfields['e.tms']['checked'])) {
  704. print '<td class="liste_titre">';
  705. print '</td>';
  706. }
  707. // Status
  708. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  709. print '<td class="liste_titre maxwidthonsmartphone right">';
  710. print $form->selectarray('search_status', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $search_status, 1);
  711. print '</td>';
  712. }
  713. // Status billed
  714. if (!empty($arrayfields['e.billed']['checked'])) {
  715. print '<td class="liste_titre maxwidthonsmartphone center">';
  716. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
  717. print '</td>';
  718. }
  719. // Action column
  720. print '<td class="liste_titre middle">';
  721. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  722. print $searchpicto;
  723. print '</td>';
  724. print "</tr>\n";
  725. print '<tr class="liste_titre">';
  726. if (!empty($arrayfields['e.ref']['checked'])) {
  727. print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
  728. }
  729. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  730. print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
  731. }
  732. if (!empty($arrayfields['s.nom']['checked'])) {
  733. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
  734. }
  735. if (!empty($arrayfields['s.town']['checked'])) {
  736. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  737. }
  738. if (!empty($arrayfields['s.zip']['checked'])) {
  739. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  740. }
  741. if (!empty($arrayfields['state.nom']['checked'])) {
  742. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  743. }
  744. if (!empty($arrayfields['country.code_iso']['checked'])) {
  745. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  746. }
  747. if (!empty($arrayfields['typent.code']['checked'])) {
  748. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  749. }
  750. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  751. print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
  752. }
  753. if (!empty($arrayfields['l.ref']['checked'])) {
  754. print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
  755. }
  756. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  757. print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
  758. }
  759. // Extra fields
  760. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  761. // Hook fields
  762. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  763. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  764. print $hookmanager->resPrint;
  765. if (!empty($arrayfields['e.datec']['checked'])) {
  766. print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  767. }
  768. if (!empty($arrayfields['e.tms']['checked'])) {
  769. print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  770. }
  771. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  772. print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  773. }
  774. if (!empty($arrayfields['e.billed']['checked'])) {
  775. print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
  776. }
  777. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  778. print "</tr>\n";
  779. $i = 0;
  780. $totalarray = array();
  781. while ($i < min($num, $limit)) {
  782. $obj = $db->fetch_object($resql);
  783. $reception->id = $obj->rowid;
  784. $reception->ref = $obj->ref;
  785. $companystatic->id = $obj->socid;
  786. $companystatic->ref = $obj->name;
  787. $companystatic->name = $obj->name;
  788. print '<tr class="oddeven">';
  789. // Ref
  790. if (!empty($arrayfields['e.ref']['checked'])) {
  791. print '<td class="nowraponall">';
  792. print $reception->getNomUrl(1);
  793. $filename = dol_sanitizeFileName($reception->ref);
  794. $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
  795. $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
  796. print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
  797. print "</td>\n";
  798. if (!$i) {
  799. $totalarray['nbfield']++;
  800. }
  801. }
  802. // Ref supplier
  803. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  804. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
  805. print dol_escape_htmltag($obj->ref_supplier);
  806. print "</td>\n";
  807. if (!$i) {
  808. $totalarray['nbfield']++;
  809. }
  810. }
  811. // Third party
  812. if (!empty($arrayfields['s.nom']['checked'])) {
  813. print '<td class="tdoverflowmax150">';
  814. print $companystatic->getNomUrl(1);
  815. print '</td>';
  816. if (!$i) {
  817. $totalarray['nbfield']++;
  818. }
  819. }
  820. // Town
  821. if (!empty($arrayfields['s.town']['checked'])) {
  822. print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">';
  823. print dol_escape_htmltag($obj->town);
  824. print '</td>';
  825. if (!$i) {
  826. $totalarray['nbfield']++;
  827. }
  828. }
  829. // Zip
  830. if (!empty($arrayfields['s.zip']['checked'])) {
  831. print '<td class="nocellnopadd center"">';
  832. print dol_escape_htmltag($obj->zip);
  833. print '</td>';
  834. if (!$i) {
  835. $totalarray['nbfield']++;
  836. }
  837. }
  838. // State
  839. if (!empty($arrayfields['state.nom']['checked'])) {
  840. print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
  841. if (!$i) {
  842. $totalarray['nbfield']++;
  843. }
  844. }
  845. // Country
  846. if (!empty($arrayfields['country.code_iso']['checked'])) {
  847. print '<td class="center">';
  848. $tmparray = getCountry($obj->fk_pays, 'all');
  849. print dol_escape_htmltag($tmparray['label']);
  850. print '</td>';
  851. if (!$i) {
  852. $totalarray['nbfield']++;
  853. }
  854. }
  855. // Type ent
  856. if (!empty($arrayfields['typent.code']['checked'])) {
  857. print '<td class="center">';
  858. if (count($typenArray) == 0) {
  859. $typenArray = $formcompany->typent_array(1);
  860. }
  861. print $typenArray[$obj->typent_code];
  862. print '</td>';
  863. if (!$i) {
  864. $totalarray['nbfield']++;
  865. }
  866. }
  867. // Date delivery planed
  868. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  869. print '<td class="center">';
  870. print dol_print_date($db->jdate($obj->delivery_date), "day");
  871. /*$now = time();
  872. if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
  873. {
  874. }*/
  875. print "</td>\n";
  876. }
  877. if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
  878. $reception->fetchObjectLinked($reception->id, $reception->element);
  879. $receiving = '';
  880. if (count($reception->linkedObjects['delivery']) > 0) {
  881. $receiving = reset($reception->linkedObjects['delivery']);
  882. }
  883. if (!empty($arrayfields['l.ref']['checked'])) {
  884. // Ref
  885. print '<td>';
  886. print !empty($receiving) ? $receiving->getNomUrl($db) : '';
  887. print '</td>';
  888. }
  889. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  890. // Date received
  891. print '<td class="center">';
  892. print dol_print_date($db->jdate($obj->date_reception), "day");
  893. print '</td>'."\n";
  894. }
  895. }
  896. // Extra fields
  897. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  898. // Fields from hook
  899. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  900. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  901. print $hookmanager->resPrint;
  902. // Date creation
  903. if (!empty($arrayfields['e.datec']['checked'])) {
  904. print '<td class="center nowrap">';
  905. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  906. print '</td>';
  907. if (!$i) {
  908. $totalarray['nbfield']++;
  909. }
  910. }
  911. // Date modification
  912. if (!empty($arrayfields['e.tms']['checked'])) {
  913. print '<td class="center nowrap">';
  914. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  915. print '</td>';
  916. if (!$i) {
  917. $totalarray['nbfield']++;
  918. }
  919. }
  920. // Status
  921. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  922. print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
  923. if (!$i) {
  924. $totalarray['nbfield']++;
  925. }
  926. }
  927. // Billed
  928. if (!empty($arrayfields['e.billed']['checked'])) {
  929. print '<td class="center">'.yn($obj->billed).'</td>';
  930. if (!$i) {
  931. $totalarray['nbfield']++;
  932. }
  933. }
  934. // Action column
  935. print '<td class="center">';
  936. if ($massactionbutton || $massaction) {
  937. // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  938. $selected = 0;
  939. if (in_array($obj->rowid, $arrayofselected)) {
  940. $selected = 1;
  941. }
  942. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  943. }
  944. print '</td>';
  945. if (!$i) {
  946. $totalarray['nbfield']++;
  947. }
  948. print "</tr>\n";
  949. $i++;
  950. }
  951. // If no record found
  952. if ($num == 0) {
  953. $colspan = 1;
  954. foreach ($arrayfields as $key => $val) {
  955. if (!empty($val['checked'])) {
  956. $colspan++;
  957. }
  958. }
  959. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  960. }
  961. print "</table>";
  962. print "</div>";
  963. print '</form>';
  964. $db->free($resql);
  965. llxFooter();
  966. $db->close();