list.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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. // Mass actions
  145. $objectclass = 'Reception';
  146. $objectlabel = 'Receptions';
  147. $permissiontoread = $user->rights->reception->lire;
  148. $permissiontoadd = $user->rights->reception->creer;
  149. $permissiontodelete = $user->rights->reception->supprimer;
  150. $uploaddir = $conf->reception->multidir_output[$conf->entity];
  151. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  152. if ($massaction == 'confirm_createbills') {
  153. $receptions = GETPOST('toselect', 'array');
  154. $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
  155. $validate_invoices = GETPOST('validate_invoices', 'int');
  156. $errors = array();
  157. $TFact = array();
  158. $TFactThird = array();
  159. $TFactThirdNbLines = array();
  160. $nb_bills_created = 0;
  161. $lastid= 0;
  162. $lastref = '';
  163. $db->begin();
  164. //sort ids to keep order if one bill per third
  165. sort($receptions);
  166. foreach ($receptions as $id_reception) {
  167. $rcp = new Reception($db);
  168. // We only invoice reception that are validated
  169. if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != $rcp::STATUS_VALIDATED) {
  170. $errors[] = $langs->trans('StatusOfRefMustBe', $rcp->ref, $langs->transnoentities("StatusSupplierOrderValidatedShort"));
  171. $error++;
  172. continue;
  173. }
  174. $objecttmp = new FactureFournisseur($db);
  175. if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) {
  176. // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
  177. $objecttmp = $TFactThird[$rcp->socid];
  178. // Add all links of this new reception to the existing invoice
  179. $objecttmp->fetchObjectLinked();
  180. $rcp->fetchObjectLinked();
  181. if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
  182. foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
  183. if (empty($objecttmp->linkedObjectsIds['order_supplier']) || !in_array($value, $objecttmp->linkedObjectsIds['order_supplier'])) { //Dont try to link if already linked
  184. $objecttmp->add_object_linked('order_supplier', $value); // add supplier order linked object
  185. }
  186. }
  187. }
  188. } else {
  189. // If we want one invoice per reception or if there is no first invoice yet for this thirdparty.
  190. $objecttmp->socid = $rcp->socid;
  191. $objecttmp->type = $objecttmp::TYPE_STANDARD;
  192. $objecttmp->cond_reglement_id = $rcp->cond_reglement_id || $rcp->thirdparty->cond_reglement_supplier_id;
  193. $objecttmp->mode_reglement_id = $rcp->mode_reglement_id || $rcp->thirdparty->mode_reglement_supplier_id;
  194. $objecttmp->fk_account = !empty($rcp->thirdparty->fk_account) ? $rcp->thirdparty->fk_account : 0;
  195. $objecttmp->remise_percent = !empty($rcp->thirdparty->remise_percent) ? $rcp->thirdparty->remise_percent : 0;
  196. $objecttmp->remise_absolue = !empty($rcp->thirdparty->remise_absolue) ? $rcp->thirdparty->remise_absolue : 0;
  197. $objecttmp->fk_project = $rcp->fk_project;
  198. //$objecttmp->multicurrency_code = $rcp->multicurrency_code;
  199. if (empty($createbills_onebythird)) {
  200. $objecttmp->ref_supplier = $rcp->ref;
  201. } else {
  202. // Set a unique value for the invoice for the n reception
  203. $objecttmp->ref_supplier = $langs->trans("Reception").' '.dol_print_date(dol_now(), 'dayhourlog').'-'.$rcp->socid;
  204. }
  205. $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  206. if (empty($datefacture)) {
  207. $datefacture = dol_now();
  208. }
  209. $objecttmp->date = $datefacture;
  210. $objecttmp->origin = 'reception';
  211. $objecttmp->origin_id = $id_reception;
  212. $objecttmp->array_options = $rcp->array_options; // Copy extrafields
  213. // Set $objecttmp->linked_objects with all links order_supplier existing on reception, so same links will be added to the generated supplier invoice
  214. $rcp->fetchObjectLinked();
  215. if (count($rcp->linkedObjectsIds['order_supplier']) > 0) {
  216. foreach ($rcp->linkedObjectsIds['order_supplier'] as $key => $value) {
  217. $objecttmp->linked_objects['order_supplier'] = $value;
  218. }
  219. }
  220. $res = $objecttmp->create($user); // This should create the supplier invoice + links into $objecttmp->linked_objects + add a link to ->origin_id
  221. //var_dump($objecttmp->error);exit;
  222. if ($res > 0) {
  223. $nb_bills_created++;
  224. $lastref = $objecttmp->ref;
  225. $lastid = $objecttmp->id;
  226. $TFactThird[$rcp->socid] = $objecttmp;
  227. $TFactThirdNbLines[$rcp->socid] = 0; //init nblines to have lines ordered by expedition and rang
  228. } else {
  229. $langs->load("errors");
  230. $errors[] = $rcp->ref.' : '.$langs->trans($objecttmp->error);
  231. $error++;
  232. }
  233. }
  234. if ($objecttmp->id > 0) {
  235. $res = $objecttmp->add_object_linked($objecttmp->origin, $id_reception);
  236. if ($res == 0) {
  237. $errors[] = $objecttmp->error;
  238. $error++;
  239. }
  240. if (!$error) {
  241. $lines = $rcp->lines;
  242. if (empty($lines) && method_exists($rcp, 'fetch_lines')) {
  243. $rcp->fetch_lines();
  244. $lines = $rcp->lines;
  245. }
  246. $fk_parent_line = 0;
  247. $num = count($lines);
  248. for ($i = 0; $i < $num; $i++) {
  249. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  250. // If we build one invoice for several reception, we must put the ref of reception on the invoice line
  251. if (!empty($createbills_onebythird)) {
  252. $desc = dol_concatdesc($desc, $langs->trans("Reception").' '.$rcp->ref.' - '.dol_print_date($rcp->date, 'day'));
  253. }
  254. if ($lines[$i]->subprice < 0) {
  255. // Negative line, we create a discount line
  256. $discount = new DiscountAbsolute($db);
  257. $discount->fk_soc = $objecttmp->socid;
  258. $discount->amount_ht = abs($lines[$i]->total_ht);
  259. $discount->amount_tva = abs($lines[$i]->total_tva);
  260. $discount->amount_ttc = abs($lines[$i]->total_ttc);
  261. $discount->tva_tx = $lines[$i]->tva_tx;
  262. $discount->fk_user = $user->id;
  263. $discount->description = $desc;
  264. $discountid = $discount->create($user);
  265. if ($discountid > 0) {
  266. $result = $objecttmp->insert_discount($discountid);
  267. //$result=$discount->link_to_invoice($lineid,$id);
  268. } else {
  269. setEventMessages($discount->error, $discount->errors, 'errors');
  270. $error++;
  271. break;
  272. }
  273. } else {
  274. // Positive line
  275. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  276. // Date start
  277. $date_start = false;
  278. if ($lines[$i]->date_debut_prevue) {
  279. $date_start = $lines[$i]->date_debut_prevue;
  280. }
  281. if ($lines[$i]->date_debut_reel) {
  282. $date_start = $lines[$i]->date_debut_reel;
  283. }
  284. if ($lines[$i]->date_start) {
  285. $date_start = $lines[$i]->date_start;
  286. }
  287. //Date end
  288. $date_end = false;
  289. if ($lines[$i]->date_fin_prevue) {
  290. $date_end = $lines[$i]->date_fin_prevue;
  291. }
  292. if ($lines[$i]->date_fin_reel) {
  293. $date_end = $lines[$i]->date_fin_reel;
  294. }
  295. if ($lines[$i]->date_end) {
  296. $date_end = $lines[$i]->date_end;
  297. }
  298. // Reset fk_parent_line for no child products and special product
  299. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  300. $fk_parent_line = 0;
  301. }
  302. // Extrafields
  303. if (method_exists($lines[$i], 'fetch_optionals')) {
  304. $lines[$i]->fetch_optionals();
  305. $array_options = $lines[$i]->array_options;
  306. }
  307. $objecttmp->context['createfromclone'];
  308. $rang = $i;
  309. //there may already be rows from previous receptions
  310. if (!empty($createbills_onebythird))
  311. $rang = $TFactThirdNbLines[$rcp->socid];
  312. $result = $objecttmp->addline(
  313. $desc,
  314. $lines[$i]->subprice,
  315. $lines[$i]->tva_tx,
  316. $lines[$i]->localtax1_tx,
  317. $lines[$i]->localtax2_tx,
  318. $lines[$i]->qty,
  319. $lines[$i]->fk_product,
  320. $lines[$i]->remise_percent,
  321. $date_start,
  322. $date_end,
  323. 0,
  324. $lines[$i]->info_bits,
  325. 'HT',
  326. $product_type,
  327. $rang,
  328. false,
  329. 0,
  330. null,
  331. $lines[$i]->rowid,
  332. 0,
  333. $lines[$i]->ref_supplier
  334. );
  335. $rcp->add_object_linked('facture_fourn_det', $result);
  336. if ($result > 0) {
  337. $lineid = $result;
  338. if (!empty($createbills_onebythird)) //increment rang to keep order
  339. $TFactThirdNbLines[$rcp->socid]++;
  340. } else {
  341. $lineid = 0;
  342. $error++;
  343. break;
  344. }
  345. // Defined the new fk_parent_line
  346. if ($result > 0 && $lines[$i]->product_type == 9) {
  347. $fk_parent_line = $result;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. //$rcp->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
  354. if (!empty($createbills_onebythird) && empty($TFactThird[$rcp->socid])) {
  355. $TFactThird[$rcp->socid] = $objecttmp;
  356. } else {
  357. $TFact[$objecttmp->id] = $objecttmp;
  358. }
  359. }
  360. // Build doc with all invoices
  361. $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
  362. $toselect = array();
  363. if (!$error && $validate_invoices) {
  364. $massaction = $action = 'builddoc';
  365. foreach ($TAllFact as &$objecttmp) {
  366. $result = $objecttmp->validate($user);
  367. if ($result <= 0) {
  368. $error++;
  369. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  370. break;
  371. }
  372. $id = $objecttmp->id; // For builddoc action
  373. $object =$objecttmp;
  374. // Fac builddoc
  375. $donotredirect = 1;
  376. $upload_dir = $conf->fournisseur->facture->dir_output;
  377. $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  378. // Call action to build doc
  379. $savobject = $object;
  380. $object = $objecttmp;
  381. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  382. $object = $savobject;
  383. }
  384. $massaction = $action = 'confirm_createbills';
  385. }
  386. if (!$error) {
  387. $db->commit();
  388. if ($nb_bills_created == 1) {
  389. $texttoshow = $langs->trans('BillXCreated', '{s1}');
  390. $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
  391. setEventMessages($texttoshow, null, 'mesgs');
  392. } else {
  393. setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
  394. }
  395. } else {
  396. $db->rollback();
  397. $action = 'create';
  398. $_GET["origin"] = $_POST["origin"];
  399. $_GET["originid"] = $_POST["originid"];
  400. setEventMessages($object->error, $errors, 'errors');
  401. $error++;
  402. }
  403. }
  404. }
  405. /*
  406. * View
  407. */
  408. $form = new Form($db);
  409. $companystatic = new Societe($db);
  410. $reception = new Reception($db);
  411. $formcompany = new FormCompany($db);
  412. $formfile = new FormFile($db);
  413. $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
  414. llxHeader('', $langs->trans('ListOfReceptions'), $helpurl);
  415. $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,";
  416. $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  417. $sql .= " typent.code as typent_code,";
  418. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  419. $sql .= ' e.date_creation as date_creation, e.tms as date_update';
  420. // Add fields from extrafields
  421. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  422. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  423. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  424. }
  425. }
  426. // Add fields from hooks
  427. $parameters = array();
  428. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  429. $sql .= $hookmanager->resPrint;
  430. $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
  431. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  432. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";
  433. }
  434. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  435. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  436. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  437. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  438. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'reception' AND ee.targettype = 'delivery'";
  439. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";
  440. if (empty($user->rights->societe->client->voir) && !$socid) { // Internal user with no permission to see all
  441. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  442. }
  443. // Add joins from hooks
  444. $parameters = array();
  445. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  446. $sql .= $hookmanager->resPrint;
  447. $sql .= " WHERE e.entity IN (".getEntity('reception').")";
  448. if (empty($user->rights->societe->client->voir) && !$socid) { // Internal user with no permission to see all
  449. $sql .= " AND e.fk_soc = sc.fk_soc";
  450. $sql .= " AND sc.fk_user = ".((int) $user->id);
  451. }
  452. if ($socid) {
  453. $sql .= " AND e.fk_soc = ".((int) $socid);
  454. }
  455. if ($search_status <> '' && $search_status >= 0) {
  456. $sql .= " AND e.fk_statut = ".((int) $search_status);
  457. }
  458. if ($search_billed != '' && $search_billed >= 0) {
  459. $sql .= ' AND e.billed = '.((int) $search_billed);
  460. }
  461. if ($search_town) {
  462. $sql .= natural_search('s.town', $search_town);
  463. }
  464. if ($search_zip) {
  465. $sql .= natural_search("s.zip", $search_zip);
  466. }
  467. if ($search_state) {
  468. $sql .= natural_search("state.nom", $search_state);
  469. }
  470. if ($search_country) {
  471. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  472. }
  473. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  474. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  475. }
  476. if ($search_ref_rcp) {
  477. $sql .= natural_search('e.ref', $search_ref_rcp);
  478. }
  479. if ($search_ref_liv) {
  480. $sql .= natural_search('l.ref', $search_ref_liv);
  481. }
  482. if ($search_company) {
  483. $sql .= natural_search('s.nom', $search_company);
  484. }
  485. if ($search_ref_supplier) {
  486. $sql .= natural_search('e.ref_supplier', $search_ref_supplier);
  487. }
  488. if ($sall) {
  489. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  490. }
  491. // Add where from extra fields
  492. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  493. // Add where from hooks
  494. $parameters = array();
  495. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  496. $sql .= $hookmanager->resPrint;
  497. $nbtotalofrecords = '';
  498. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  499. $result = $db->query($sql);
  500. $nbtotalofrecords = $db->num_rows($result);
  501. }
  502. $sql .= $db->order($sortfield, $sortorder);
  503. $sql .= $db->plimit($limit + 1, $offset);
  504. //print $sql;
  505. $resql = $db->query($sql);
  506. if (!$resql) {
  507. dol_print_error($db);
  508. exit;
  509. }
  510. $num = $db->num_rows($resql);
  511. $reception = new Reception($db);
  512. $arrayofselected = is_array($toselect) ? $toselect : array();
  513. $param = '';
  514. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  515. $param .= '&contextpage='.urlencode($contextpage);
  516. }
  517. if ($limit > 0 && $limit != $conf->liste_limit) {
  518. $param .= '&limit='.urlencode($limit);
  519. }
  520. if ($sall) {
  521. $param .= "&sall=".urlencode($sall);
  522. }
  523. if ($search_ref_rcp) {
  524. $param .= "&search_ref_rcp=".urlencode($search_ref_rcp);
  525. }
  526. if ($search_ref_liv) {
  527. $param .= "&search_ref_liv=".urlencode($search_ref_liv);
  528. }
  529. if ($search_company) {
  530. $param .= "&search_company=".urlencode($search_company);
  531. }
  532. if ($optioncss != '') {
  533. $param .= '&optioncss='.urlencode($optioncss);
  534. }
  535. if ($search_billed != '' && $search_billed >= 0) {
  536. $param .= "&search_billed=".urlencode($search_billed);
  537. }
  538. if ($search_town) {
  539. $param .= "&search_town=".urlencode($search_town);
  540. }
  541. if ($search_zip) {
  542. $param .= "&search_zip=".urlencode($search_zip);
  543. }
  544. if ($search_state) {
  545. $param .= "&search_state=".urlencode($search_state);
  546. }
  547. if ($search_status != '') {
  548. $param .= "&search_status=".urlencode($search_status);
  549. }
  550. if ($search_country) {
  551. $param .= "&search_country=".urlencode($search_country);
  552. }
  553. if ($search_type_thirdparty) {
  554. $param .= "&search_type_thirdparty=".urlencode($search_type_thirdparty);
  555. }
  556. if ($search_ref_supplier) {
  557. $param .= "&search_ref_supplier=".urlencode($search_ref_supplier);
  558. }
  559. // Add $param from extra fields
  560. if ($search_array_options) {
  561. foreach ($search_array_options as $key => $val) {
  562. $crit = $val;
  563. $tmpkey = preg_replace('/search_options_/', '', $key);
  564. if (is_array($val) && array_key_exists('start', $val) && array_key_exists('end', $val)) {
  565. // date range from list filters is stored as array('start' => <timestamp>, 'end' => <timestamp>)
  566. // start date
  567. $param .= '&search_options_'.$tmpkey.'_startyear='.dol_print_date($val['start'], '%Y');
  568. $param .= '&search_options_'.$tmpkey.'_startmonth='.dol_print_date($val['start'], '%m');
  569. $param .= '&search_options_'.$tmpkey.'_startday='.dol_print_date($val['start'], '%d');
  570. $param .= '&search_options_'.$tmpkey.'_starthour='.dol_print_date($val['start'], '%H');
  571. $param .= '&search_options_'.$tmpkey.'_startmin='.dol_print_date($val['start'], '%M');
  572. // end date
  573. $param .= '&search_options_'.$tmpkey.'_endyear='.dol_print_date($val['end'], '%Y');
  574. $param .= '&search_options_'.$tmpkey.'_endmonth='.dol_print_date($val['end'], '%m');
  575. $param .= '&search_options_'.$tmpkey.'_endday='.dol_print_date($val['end'], '%d');
  576. $param .= '&search_options_'.$tmpkey.'_endhour='.dol_print_date($val['end'], '%H');
  577. $param .= '&search_options_'.$tmpkey.'_endmin='.dol_print_date($val['end'], '%M');
  578. $val = '';
  579. }
  580. if ($val != '') {
  581. $param .= '&search_options_'.$tmpkey.'='.urlencode($val);
  582. }
  583. }
  584. }
  585. $arrayofmassactions = array(
  586. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  587. );
  588. if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
  589. $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisReceptions");
  590. }
  591. if ($massaction == 'createbills') {
  592. $arrayofmassactions = array();
  593. }
  594. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  595. //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  596. $i = 0;
  597. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  598. if ($optioncss != '') {
  599. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  600. }
  601. print '<input type="hidden" name="token" value="'.newToken().'">';
  602. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  603. print '<input type="hidden" name="action" value="list">';
  604. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  605. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  606. print_barre_liste($langs->trans('ListOfReceptions'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dollyrevert', 0, '', '', $limit, 0, 0, 1);
  607. if ($massaction == 'createbills') {
  608. //var_dump($_REQUEST);
  609. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  610. print '<table class="noborder" width="100%" >';
  611. print '<tr>';
  612. print '<td class="titlefieldmiddle">';
  613. print $langs->trans('DateInvoice');
  614. print '</td>';
  615. print '<td>';
  616. print $form->selectDate('', '', '', '', '', '', 1, 1);
  617. print '</td>';
  618. print '</tr>';
  619. print '<tr>';
  620. print '<td>';
  621. print $langs->trans('CreateOneBillByThird');
  622. print '</td>';
  623. print '<td>';
  624. print $form->selectyesno('createbills_onebythird', '', 1);
  625. print '</td>';
  626. print '</tr>';
  627. print '<tr>';
  628. print '<td>';
  629. print $langs->trans('ValidateInvoices');
  630. print '</td>';
  631. print '<td>';
  632. if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
  633. print $form->selectyesno('validate_invoices', 0, 1, 1);
  634. print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
  635. } else {
  636. print $form->selectyesno('validate_invoices', 0, 1);
  637. }
  638. print '</td>';
  639. print '</tr>';
  640. print '</table>';
  641. print '<br>';
  642. print '<div class="center">';
  643. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisReceptions').'"> ';
  644. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  645. print '</div>';
  646. print '<br>';
  647. }
  648. if ($sall) {
  649. foreach ($fieldstosearchall as $key => $val) {
  650. $fieldstosearchall[$key] = $langs->trans($val);
  651. }
  652. print $langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall);
  653. }
  654. $moreforfilter = '';
  655. if (!empty($moreforfilter)) {
  656. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  657. print $moreforfilter;
  658. $parameters = array('type'=>$type);
  659. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  660. print $hookmanager->resPrint;
  661. print '</div>';
  662. }
  663. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  664. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  665. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  666. print '<div class="div-table-responsive">';
  667. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  668. // Fields title search
  669. // --------------------------------------------------------------------
  670. print '<tr class="liste_titre_filter">';
  671. // Ref
  672. if (!empty($arrayfields['e.ref']['checked'])) {
  673. print '<td class="liste_titre">';
  674. print '<input class="flat" size="6" type="text" name="search_ref_rcp" value="'.$search_ref_rcp.'">';
  675. print '</td>';
  676. }
  677. // Ref customer
  678. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  679. print '<td class="liste_titre">';
  680. print '<input class="flat" size="6" type="text" name="search_ref_supplier" value="'.$search_ref_supplier.'">';
  681. print '</td>';
  682. }
  683. // Thirdparty
  684. if (!empty($arrayfields['s.nom']['checked'])) {
  685. print '<td class="liste_titre left">';
  686. print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
  687. print '</td>';
  688. }
  689. // Town
  690. if (!empty($arrayfields['s.town']['checked'])) {
  691. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  692. }
  693. // Zip
  694. if (!empty($arrayfields['s.zip']['checked'])) {
  695. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
  696. }
  697. // State
  698. if (!empty($arrayfields['state.nom']['checked'])) {
  699. print '<td class="liste_titre">';
  700. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  701. print '</td>';
  702. }
  703. // Country
  704. if (!empty($arrayfields['country.code_iso']['checked'])) {
  705. print '<td class="liste_titre center">';
  706. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  707. print '</td>';
  708. }
  709. // Company type
  710. if (!empty($arrayfields['typent.code']['checked'])) {
  711. print '<td class="liste_titre maxwidthonsmartphone center">';
  712. 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);
  713. print '</td>';
  714. }
  715. // Date delivery planned
  716. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  717. print '<td class="liste_titre">&nbsp;</td>';
  718. }
  719. if (!empty($arrayfields['l.ref']['checked'])) {
  720. // Delivery ref
  721. print '<td class="liste_titre">';
  722. print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
  723. print '</td>';
  724. }
  725. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  726. // Date received
  727. print '<td class="liste_titre">&nbsp;</td>';
  728. }
  729. // Extra fields
  730. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  731. // Fields from hook
  732. $parameters = array('arrayfields'=>$arrayfields);
  733. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  734. print $hookmanager->resPrint;
  735. // Date creation
  736. if (!empty($arrayfields['e.datec']['checked'])) {
  737. print '<td class="liste_titre">';
  738. print '</td>';
  739. }
  740. // Date modification
  741. if (!empty($arrayfields['e.tms']['checked'])) {
  742. print '<td class="liste_titre">';
  743. print '</td>';
  744. }
  745. // Status
  746. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  747. print '<td class="liste_titre maxwidthonsmartphone right">';
  748. print $form->selectarray('search_status', array('0'=>$langs->trans('StatusReceptionDraftShort'), '1'=>$langs->trans('StatusReceptionValidatedShort'), '2'=>$langs->trans('StatusReceptionProcessedShort')), $search_status, 1);
  749. print '</td>';
  750. }
  751. // Status billed
  752. if (!empty($arrayfields['e.billed']['checked'])) {
  753. print '<td class="liste_titre maxwidthonsmartphone center">';
  754. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
  755. print '</td>';
  756. }
  757. // Action column
  758. print '<td class="liste_titre middle">';
  759. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  760. print $searchpicto;
  761. print '</td>';
  762. print "</tr>\n";
  763. print '<tr class="liste_titre">';
  764. if (!empty($arrayfields['e.ref']['checked'])) {
  765. print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
  766. }
  767. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  768. print_liste_field_titre($arrayfields['e.ref_supplier']['label'], $_SERVER["PHP_SELF"], "e.ref_supplier", "", $param, '', $sortfield, $sortorder);
  769. }
  770. if (!empty($arrayfields['s.nom']['checked'])) {
  771. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');
  772. }
  773. if (!empty($arrayfields['s.town']['checked'])) {
  774. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  775. }
  776. if (!empty($arrayfields['s.zip']['checked'])) {
  777. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  778. }
  779. if (!empty($arrayfields['state.nom']['checked'])) {
  780. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  781. }
  782. if (!empty($arrayfields['country.code_iso']['checked'])) {
  783. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  784. }
  785. if (!empty($arrayfields['typent.code']['checked'])) {
  786. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  787. }
  788. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  789. print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
  790. }
  791. if (!empty($arrayfields['l.ref']['checked'])) {
  792. print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
  793. }
  794. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  795. print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');
  796. }
  797. // Extra fields
  798. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  799. // Hook fields
  800. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  801. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  802. print $hookmanager->resPrint;
  803. if (!empty($arrayfields['e.datec']['checked'])) {
  804. print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  805. }
  806. if (!empty($arrayfields['e.tms']['checked'])) {
  807. print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  808. }
  809. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  810. print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  811. }
  812. if (!empty($arrayfields['e.billed']['checked'])) {
  813. print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');
  814. }
  815. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  816. print "</tr>\n";
  817. $i = 0;
  818. $totalarray = array();
  819. $totalarray['nbfield'] = 0;
  820. while ($i < min($num, $limit)) {
  821. $obj = $db->fetch_object($resql);
  822. $reception->id = $obj->rowid;
  823. $reception->ref = $obj->ref;
  824. $companystatic->id = $obj->socid;
  825. $companystatic->ref = $obj->name;
  826. $companystatic->name = $obj->name;
  827. print '<tr class="oddeven">';
  828. // Ref
  829. if (!empty($arrayfields['e.ref']['checked'])) {
  830. print '<td class="nowraponall">';
  831. print $reception->getNomUrl(1);
  832. $filename = dol_sanitizeFileName($reception->ref);
  833. $filedir = $conf->reception->dir_output.'/'.dol_sanitizeFileName($reception->ref);
  834. $urlsource = $_SERVER['PHP_SELF'].'?id='.$reception->id;
  835. print $formfile->getDocumentsLink($reception->element, $filename, $filedir);
  836. print "</td>\n";
  837. if (!$i) {
  838. $totalarray['nbfield']++;
  839. }
  840. }
  841. // Ref supplier
  842. if (!empty($arrayfields['e.ref_supplier']['checked'])) {
  843. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
  844. print dol_escape_htmltag($obj->ref_supplier);
  845. print "</td>\n";
  846. if (!$i) {
  847. $totalarray['nbfield']++;
  848. }
  849. }
  850. // Third party
  851. if (!empty($arrayfields['s.nom']['checked'])) {
  852. print '<td class="tdoverflowmax150">';
  853. print $companystatic->getNomUrl(1);
  854. print '</td>';
  855. if (!$i) {
  856. $totalarray['nbfield']++;
  857. }
  858. }
  859. // Town
  860. if (!empty($arrayfields['s.town']['checked'])) {
  861. print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">';
  862. print dol_escape_htmltag($obj->town);
  863. print '</td>';
  864. if (!$i) {
  865. $totalarray['nbfield']++;
  866. }
  867. }
  868. // Zip
  869. if (!empty($arrayfields['s.zip']['checked'])) {
  870. print '<td class="nocellnopadd center"">';
  871. print dol_escape_htmltag($obj->zip);
  872. print '</td>';
  873. if (!$i) {
  874. $totalarray['nbfield']++;
  875. }
  876. }
  877. // State
  878. if (!empty($arrayfields['state.nom']['checked'])) {
  879. print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
  880. if (!$i) {
  881. $totalarray['nbfield']++;
  882. }
  883. }
  884. // Country
  885. if (!empty($arrayfields['country.code_iso']['checked'])) {
  886. print '<td class="center">';
  887. $tmparray = getCountry($obj->fk_pays, 'all');
  888. print dol_escape_htmltag($tmparray['label']);
  889. print '</td>';
  890. if (!$i) {
  891. $totalarray['nbfield']++;
  892. }
  893. }
  894. // Type ent
  895. if (!empty($arrayfields['typent.code']['checked'])) {
  896. print '<td class="center">';
  897. if (count($typenArray) == 0) {
  898. $typenArray = $formcompany->typent_array(1);
  899. }
  900. print $typenArray[$obj->typent_code];
  901. print '</td>';
  902. if (!$i) {
  903. $totalarray['nbfield']++;
  904. }
  905. }
  906. // Date delivery planed
  907. if (!empty($arrayfields['e.date_delivery']['checked'])) {
  908. print '<td class="center">';
  909. print dol_print_date($db->jdate($obj->delivery_date), "day");
  910. /*$now = time();
  911. if ( ($now - $db->jdate($obj->date_reception)) > $conf->warnings->lim && $obj->statutid == 1 )
  912. {
  913. }*/
  914. print "</td>\n";
  915. if (!$i) {
  916. $totalarray['nbfield']++;
  917. }
  918. }
  919. if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {
  920. $reception->fetchObjectLinked($reception->id, $reception->element);
  921. $receiving = '';
  922. if (count($reception->linkedObjects['delivery']) > 0) {
  923. $receiving = reset($reception->linkedObjects['delivery']);
  924. }
  925. if (!empty($arrayfields['l.ref']['checked'])) {
  926. // Ref
  927. print '<td>';
  928. print !empty($receiving) ? $receiving->getNomUrl($db) : '';
  929. print '</td>';
  930. }
  931. if (!empty($arrayfields['l.date_delivery']['checked'])) {
  932. // Date received
  933. print '<td class="center">';
  934. print dol_print_date($db->jdate($obj->date_reception), "day");
  935. print '</td>'."\n";
  936. }
  937. }
  938. // Extra fields
  939. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  940. // Fields from hook
  941. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  942. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  943. print $hookmanager->resPrint;
  944. // Date creation
  945. if (!empty($arrayfields['e.datec']['checked'])) {
  946. print '<td class="center nowrap">';
  947. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  948. print '</td>';
  949. if (!$i) {
  950. $totalarray['nbfield']++;
  951. }
  952. }
  953. // Date modification
  954. if (!empty($arrayfields['e.tms']['checked'])) {
  955. print '<td class="center nowrap">';
  956. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  957. print '</td>';
  958. if (!$i) {
  959. $totalarray['nbfield']++;
  960. }
  961. }
  962. // Status
  963. if (!empty($arrayfields['e.fk_statut']['checked'])) {
  964. print '<td class="right nowrap">'.$reception->LibStatut($obj->fk_statut, 5).'</td>';
  965. if (!$i) {
  966. $totalarray['nbfield']++;
  967. }
  968. }
  969. // Billed
  970. if (!empty($arrayfields['e.billed']['checked'])) {
  971. print '<td class="center">'.yn($obj->billed).'</td>';
  972. if (!$i) {
  973. $totalarray['nbfield']++;
  974. }
  975. }
  976. // Action column
  977. print '<td class="center">';
  978. if ($massactionbutton || $massaction) {
  979. // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  980. $selected = 0;
  981. if (in_array($obj->rowid, $arrayofselected)) {
  982. $selected = 1;
  983. }
  984. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  985. }
  986. print '</td>';
  987. if (!$i) {
  988. $totalarray['nbfield']++;
  989. }
  990. print "</tr>\n";
  991. $i++;
  992. }
  993. // If no record found
  994. if ($num == 0) {
  995. $colspan = 1;
  996. foreach ($arrayfields as $key => $val) {
  997. if (!empty($val['checked'])) {
  998. $colspan++;
  999. }
  1000. }
  1001. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  1002. }
  1003. // Show total line
  1004. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1005. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1006. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1007. print $hookmanager->resPrint;
  1008. print "</table>";
  1009. print "</div>";
  1010. print '</form>';
  1011. $db->free($resql);
  1012. llxFooter();
  1013. $db->close();