list.php 50 KB

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