list.php 51 KB

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