list.php 48 KB

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