list.php 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2019 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  6. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2016-2018 Josep Lluis Amador <joseplluis@lliuretic.cat>
  9. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
  11. * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
  12. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  13. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  14. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  15. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/societe/list.php
  32. * \ingroup societe
  33. * \brief Page to show list of third parties
  34. */
  35. // Load Dolibarr environment
  36. require_once '../main.inc.php';
  37. include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  43. // Load translation files required by the page
  44. $langs->loadLangs(array("companies", "commercial", "customers", "suppliers", "bills", "compta", "categories", "cashdesk"));
  45. // Get parameters
  46. $action = GETPOST('action', 'aZ09');
  47. $massaction = GETPOST('massaction', 'alpha');
  48. $show_files = GETPOST('show_files', 'int');
  49. $confirm = GETPOST('confirm', 'alpha');
  50. $toselect = GETPOST('toselect', 'array');
  51. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
  52. $optioncss = GETPOST('optioncss', 'alpha');
  53. if ($contextpage == 'poslist') {
  54. $optioncss = 'print';
  55. }
  56. $mode = GETPOST("mode", 'alpha');
  57. // search fields
  58. $search_all = trim(GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  59. $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
  60. $search_id = trim(GETPOST("search_id", "int"));
  61. $search_nom = trim(GETPOST("search_nom", 'restricthtml'));
  62. $search_alias = trim(GETPOST("search_alias", 'restricthtml'));
  63. $search_nom_only = trim(GETPOST("search_nom_only", 'restricthtml'));
  64. $search_barcode = trim(GETPOST("search_barcode", 'alpha'));
  65. $search_customer_code = trim(GETPOST('search_customer_code', 'alpha'));
  66. $search_supplier_code = trim(GETPOST('search_supplier_code', 'alpha'));
  67. $search_account_customer_code = trim(GETPOST('search_account_customer_code', 'alpha'));
  68. $search_account_supplier_code = trim(GETPOST('search_account_supplier_code', 'alpha'));
  69. $search_address = trim(GETPOST('search_address', 'alpha'));
  70. $search_zip = trim(GETPOST("search_zip", 'alpha'));
  71. $search_town = trim(GETPOST("search_town", 'alpha'));
  72. $search_state = trim(GETPOST("search_state", 'alpha'));
  73. $search_region = trim(GETPOST("search_region", 'alpha'));
  74. $search_email = trim(GETPOST('search_email', 'alpha'));
  75. $search_phone = trim(GETPOST('search_phone', 'alpha'));
  76. $search_fax = trim(GETPOST('search_fax', 'alpha'));
  77. $search_url = trim(GETPOST('search_url', 'alpha'));
  78. $search_idprof1 = trim(GETPOST('search_idprof1', 'alpha'));
  79. $search_idprof2 = trim(GETPOST('search_idprof2', 'alpha'));
  80. $search_idprof3 = trim(GETPOST('search_idprof3', 'alpha'));
  81. $search_idprof4 = trim(GETPOST('search_idprof4', 'alpha'));
  82. $search_idprof5 = trim(GETPOST('search_idprof5', 'alpha'));
  83. $search_idprof6 = trim(GETPOST('search_idprof6', 'alpha'));
  84. $search_vat = trim(GETPOST('search_vat', 'alpha'));
  85. $search_sale = GETPOST("search_sale", 'int');
  86. $search_categ_cus = GETPOST("search_categ_cus", 'int');
  87. $search_categ_sup = GETPOST("search_categ_sup", 'int');
  88. $search_country = GETPOST("search_country", 'intcomma');
  89. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  90. $search_price_level = GETPOST('search_price_level', 'int');
  91. $search_staff = GETPOST("search_staff", 'int');
  92. $search_status = GETPOST("search_status", 'int');
  93. $search_type = GETPOST('search_type', 'alpha');
  94. $search_level = GETPOST("search_level", "array:alpha");
  95. $search_stcomm = GETPOST('search_stcomm', "array:int");
  96. $search_import_key = trim(GETPOST("search_import_key", "alpha"));
  97. $search_parent_name = trim(GETPOST('search_parent_name', 'alpha'));
  98. $type = GETPOST('type', 'alpha');
  99. $place = GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'; // $place is string id of table for Bar or Restaurant
  100. $diroutputmassaction = $conf->societe->dir_output.'/temp/massgeneration/'.$user->id;
  101. // Load variable for pagination
  102. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  103. $sortfield = GETPOST('sortfield', 'aZ09comma');
  104. $sortorder = GETPOST('sortorder', 'aZ09comma');
  105. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  106. if (!$sortorder) {
  107. $sortorder = "ASC";
  108. }
  109. if (!$sortfield) {
  110. $sortfield = "s.nom";
  111. }
  112. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  113. // If $page is not defined, or '' or -1 or if we click on clear filters
  114. $page = 0;
  115. }
  116. $offset = $limit * $page;
  117. $pageprev = $page - 1;
  118. $pagenext = $page + 1;
  119. if ($type == 'c') {
  120. if (empty($contextpage) || $contextpage == 'thirdpartylist') {
  121. $contextpage = 'customerlist';
  122. } if ($search_type == '') {
  123. $search_type = '1,3';
  124. }
  125. }
  126. if ($type == 'p') {
  127. if (empty($contextpage) || $contextpage == 'thirdpartylist') {
  128. $contextpage = 'prospectlist';
  129. } if ($search_type == '') {
  130. $search_type = '2,3';
  131. }
  132. }
  133. if ($type == 't') {
  134. if (empty($contextpage) || $contextpage == 'poslist') {
  135. $contextpage = 'poslist';
  136. } if ($search_type == '') {
  137. $search_type = '1,2,3';
  138. }
  139. }
  140. if ($type == 'f') {
  141. if (empty($contextpage) || $contextpage == 'thirdpartylist') {
  142. $contextpage = 'supplierlist';
  143. } if ($search_type == '') {
  144. $search_type = '4';
  145. }
  146. }
  147. // Initialize technical objects to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  148. $object = new Societe($db);
  149. $extrafields = new ExtraFields($db);
  150. $hookmanager->initHooks(array($contextpage));
  151. // Fetch optionals attributes and labels
  152. $extrafields->fetch_name_optionals_label($object->table_element);
  153. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  154. // List of fields to search into when doing a "search in all"
  155. $fieldstosearchall = array(
  156. 's.nom'=>"ThirdPartyName",
  157. 's.name_alias'=>"AliasNameShort",
  158. 's.code_client'=>"CustomerCode",
  159. 's.code_fournisseur'=>"SupplierCode",
  160. 's.code_compta'=>"CustomerAccountancyCodeShort",
  161. 's.code_compta_fournisseur'=>"SupplierAccountancyCodeShort",
  162. 's.zip'=>"Zip",
  163. 's.town'=>"Town",
  164. 's.email'=>"EMail",
  165. 's.url'=>"URL",
  166. 's.tva_intra'=>"VATIntra",
  167. 's.siren'=>"ProfId1",
  168. 's.siret'=>"ProfId2",
  169. 's.ape'=>"ProfId3",
  170. 's.phone'=>"Phone",
  171. 's.fax'=>"Fax",
  172. );
  173. if (($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') {
  174. $fieldstosearchall['s.idprof4'] = 'ProfId4';
  175. }
  176. if (($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') {
  177. $fieldstosearchall['s.idprof5'] = 'ProfId5';
  178. }
  179. if (($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') {
  180. $fieldstosearchall['s.idprof6'] = 'ProfId6';
  181. }
  182. if (isModEnabled('barcode')) {
  183. $fieldstosearchall['s.barcode'] = 'Gencod';
  184. }
  185. // Personalized search criterias. Example: $conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS = 's.nom=ThirdPartyName;s.name_alias=AliasNameShort;s.code_client=CustomerCode'
  186. if (!empty($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS)) {
  187. $fieldstosearchall = dolExplodeIntoArray($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS);
  188. }
  189. // Define list of fields to show into list
  190. $checkedcustomercode = (in_array($contextpage, array('thirdpartylist', 'customerlist', 'prospectlist', 'poslist')) ? 1 : 0);
  191. $checkedsuppliercode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
  192. $checkedcustomeraccountcode = (in_array($contextpage, array('customerlist')) ? 1 : 0);
  193. $checkedsupplieraccountcode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
  194. $checkedtypetiers = 1;
  195. $checkedprofid1 = 0;
  196. $checkedprofid2 = 0;
  197. $checkedprofid3 = 0;
  198. $checkedprofid4 = 0;
  199. $checkedprofid5 = 0;
  200. $checkedprofid6 = 0;
  201. //$checkedprofid4=((($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  202. //$checkedprofid5=((($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  203. //$checkedprofid6=((($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') ? 1 : 0);
  204. $checkprospectlevel = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
  205. $checkstcomm = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
  206. $arrayfields = array(
  207. 's.rowid'=>array('label'=>"TechnicalID", 'position'=>1, 'checked'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)), 'enabled'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID))),
  208. 's.nom'=>array('label'=>"ThirdPartyName", 'position'=>2, 'checked'=>1),
  209. 's.name_alias'=>array('label'=>"AliasNameShort", 'position'=>3, 'checked'=>1),
  210. 's.barcode'=>array('label'=>"Gencod", 'position'=>5, 'checked'=>1, 'enabled'=>(isModEnabled('barcode'))),
  211. 's.code_client'=>array('label'=>"CustomerCodeShort", 'position'=>10, 'checked'=>$checkedcustomercode),
  212. 's.code_fournisseur'=>array('label'=>"SupplierCodeShort", 'position'=>11, 'checked'=>$checkedsuppliercode, 'enabled'=>(isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
  213. 's.code_compta'=>array('label'=>"CustomerAccountancyCodeShort", 'position'=>13, 'checked'=>$checkedcustomeraccountcode),
  214. 's.code_compta_fournisseur'=>array('label'=>"SupplierAccountancyCodeShort", 'position'=>14, 'checked'=>$checkedsupplieraccountcode, 'enabled'=>(isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
  215. 's.address'=>array('label'=>"Address", 'position'=>19, 'checked'=>0),
  216. 's.zip'=>array('label'=>"Zip", 'position'=>20, 'checked'=>1),
  217. 's.town'=>array('label'=>"Town", 'position'=>21, 'checked'=>0),
  218. 'state.nom'=>array('label'=>"State", 'position'=>22, 'checked'=>0),
  219. 'region.nom'=>array('label'=>"Region", 'position'=>23, 'checked'=>0),
  220. 'country.code_iso'=>array('label'=>"Country", 'position'=>24, 'checked'=>0),
  221. 's.email'=>array('label'=>"Email", 'position'=>25, 'checked'=>0),
  222. 's.url'=>array('label'=>"Url", 'position'=>26, 'checked'=>0),
  223. 's.phone'=>array('label'=>"Phone", 'position'=>27, 'checked'=>1),
  224. 's.fax'=>array('label'=>"Fax", 'position'=>28, 'checked'=>0),
  225. 'typent.code'=>array('label'=>"ThirdPartyType", 'position'=>29, 'checked'=>$checkedtypetiers),
  226. 'staff.code'=>array('label'=>"Workforce", 'position'=>31, 'checked'=>0),
  227. 's.siren'=>array('label'=>"ProfId1Short", 'position'=>40, 'checked'=>$checkedprofid1),
  228. 's.siret'=>array('label'=>"ProfId2Short", 'position'=>41, 'checked'=>$checkedprofid2),
  229. 's.ape'=>array('label'=>"ProfId3Short", 'position'=>42, 'checked'=>$checkedprofid3),
  230. 's.idprof4'=>array('label'=>"ProfId4Short", 'position'=>43, 'checked'=>$checkedprofid4),
  231. 's.idprof5'=>array('label'=>"ProfId5Short", 'position'=>44, 'checked'=>$checkedprofid5),
  232. 's.idprof6'=>array('label'=>"ProfId6Short", 'position'=>45, 'checked'=>$checkedprofid6),
  233. 's.tva_intra'=>array('label'=>"VATIntraShort", 'position'=>50, 'checked'=>0),
  234. 'customerorsupplier'=>array('label'=>'NatureOfThirdParty', 'position'=>61, 'checked'=>1),
  235. 's.fk_prospectlevel'=>array('label'=>"ProspectLevel", 'position'=>62, 'checked'=>$checkprospectlevel),
  236. 's.fk_stcomm'=>array('label'=>"StatusProsp", 'position'=>63, 'checked'=>$checkstcomm),
  237. 's2.nom'=>array('label'=>'ParentCompany', 'position'=>64, 'checked'=>0),
  238. 's.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  239. 's.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  240. 's.status'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  241. 's.import_key'=>array('label'=>"ImportId", 'checked'=>0, 'position'=>1100),
  242. );
  243. if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
  244. $arrayfields['s.price_level'] = array('label'=>"PriceLevel", 'position'=>30, 'checked'=>0);
  245. }
  246. // Extra fields
  247. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  248. $object->fields = dol_sort_array($object->fields, 'position');
  249. $arrayfields = dol_sort_array($arrayfields, 'position');
  250. // Security check
  251. $socid = GETPOST('socid', 'int');
  252. if ($user->socid) {
  253. $socid = $user->socid;
  254. }
  255. $result = restrictedArea($user, 'societe', $socid, '');
  256. /*
  257. * Actions
  258. */
  259. if ($action == "change") { // Change customer for TakePOS
  260. $idcustomer = GETPOST('idcustomer', 'int');
  261. // Check if draft invoice already exists, if not create it
  262. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' AND entity IN (".getEntity('invoice').")";
  263. $result = $db->query($sql);
  264. $num_lines = $db->num_rows($result);
  265. if ($num_lines == 0) {
  266. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  267. $invoice = new Facture($db);
  268. $constforthirdpartyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
  269. $invoice->socid = $conf->global->$constforthirdpartyid;
  270. $invoice->date = dol_now();
  271. $invoice->module_source = 'takepos';
  272. $invoice->pos_source = $_SESSION["takeposterminal"];
  273. $placeid = $invoice->create($user);
  274. $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
  275. $db->query($sql);
  276. }
  277. $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".((int) $idcustomer)." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
  278. $resql = $db->query($sql);
  279. ?>
  280. <script>
  281. console.log("Reload page invoice.php with place=<?php print $place; ?>");
  282. parent.$("#poslines").load("invoice.php?place=<?php print $place; ?>", function() {
  283. //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
  284. <?php if (!$resql) { ?>
  285. alert('Error failed to update customer on draft invoice.');
  286. <?php } ?>
  287. parent.$.colorbox.close(); /* Close the popup */
  288. });
  289. </script>
  290. <?php
  291. exit;
  292. }
  293. if (GETPOST('cancel', 'alpha')) {
  294. $action = 'list';
  295. $massaction = '';
  296. }
  297. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  298. $massaction = '';
  299. }
  300. $parameters = array();
  301. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  302. if ($reshook < 0) {
  303. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  304. }
  305. if (empty($reshook)) {
  306. // Selection of new fields
  307. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  308. // Purge search criteria
  309. 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
  310. $search_id = '';
  311. $search_nom = '';
  312. $search_alias = '';
  313. $search_categ_cus = 0;
  314. $search_categ_sup = 0;
  315. $search_sale = '';
  316. $search_barcode = "";
  317. $search_customer_code = '';
  318. $search_supplier_code = '';
  319. $search_account_customer_code = '';
  320. $search_account_supplier_code = '';
  321. $search_address = '';
  322. $search_zip = "";
  323. $search_town = "";
  324. $search_state = "";
  325. $search_region = "";
  326. $search_country = '';
  327. $search_email = '';
  328. $search_phone = '';
  329. $search_fax = '';
  330. $search_url = '';
  331. $search_idprof1 = '';
  332. $search_idprof2 = '';
  333. $search_idprof3 = '';
  334. $search_idprof4 = '';
  335. $search_idprof5 = '';
  336. $search_idprof6 = '';
  337. $search_vat = '';
  338. $search_type = '';
  339. $search_price_level = '';
  340. $search_type_thirdparty = '';
  341. $search_staff = '';
  342. $search_status = -1;
  343. $search_stcomm = '';
  344. $search_level = '';
  345. $search_parent_name = '';
  346. $search_import_key = '';
  347. $toselect = array();
  348. $search_array_options = array();
  349. }
  350. // Mass actions
  351. $objectclass = 'Societe';
  352. $objectlabel = 'ThirdParty';
  353. $permissiontoread = $user->hasRight('societe', 'lire');
  354. $permissiontodelete = $user->hasRight('societe', 'supprimer');
  355. $permissiontoadd = $user->hasRight("societe", "creer");
  356. $uploaddir = $conf->societe->dir_output;
  357. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  358. if ($action == 'setstcomm') {
  359. $object = new Client($db);
  360. $result = $object->fetch(GETPOST('stcommsocid'));
  361. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
  362. $result = $object->update($object->id, $user);
  363. if ($result < 0) {
  364. setEventMessages($object->error, $object->errors, 'errors');
  365. }
  366. $action = '';
  367. }
  368. }
  369. if ($search_status == '') {
  370. $search_status = 1; // always display active thirdparty first
  371. }
  372. /*
  373. * View
  374. */
  375. /*
  376. REM: Rules on permissions to see thirdparties
  377. Internal or External user + No permission to see customers => See nothing
  378. Internal user socid=0 + Permission to see ALL customers => See all thirdparties
  379. Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
  380. External user socid=x + Permission to see ALL customers => Can see only himself
  381. External user socid=x + No permission to see ALL customers => Can see only himself
  382. */
  383. $form = new Form($db);
  384. $formother = new FormOther($db);
  385. $companystatic = new Societe($db);
  386. $companyparent = new Societe($db);
  387. $formcompany = new FormCompany($db);
  388. $prospectstatic = new Client($db);
  389. $prospectstatic->client = 2;
  390. $prospectstatic->loadCacheOfProspStatus();
  391. $now = dol_now();
  392. $title = $langs->trans("ThirdParties");
  393. if ($type == 'c' && (empty($search_type) || ($search_type == '1,3'))) {
  394. $title = $langs->trans("Customers");
  395. }
  396. if ($type == 'p' && (empty($search_type) || ($search_type == '2,3'))) {
  397. $title = $langs->trans("Prospects");
  398. }
  399. if ($type == 'f' && (empty($search_type) || ($search_type == '4'))) {
  400. $title = $langs->trans("Suppliers");
  401. }
  402. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  403. // Select every potentiels, and note each potentiels which fit in search parameters
  404. $tab_level = array();
  405. $sql = "SELECT code, label, sortorder";
  406. $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  407. $sql .= " WHERE active > 0";
  408. $sql .= " ORDER BY sortorder";
  409. $resql = $db->query($sql);
  410. if ($resql) {
  411. while ($obj = $db->fetch_object($resql)) {
  412. // Compute level text
  413. $level = $langs->trans($obj->code);
  414. if ($level == $obj->code) {
  415. $level = $langs->trans($obj->label);
  416. }
  417. $tab_level[$obj->code] = $level;
  418. }
  419. } else {
  420. dol_print_error($db);
  421. }
  422. // Build and execute select
  423. // --------------------------------------------------------------------
  424. $sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.barcode, s.address, s.town, s.zip, s.datec, s.code_client, s.code_fournisseur, s.logo,";
  425. $sql .= " s.entity,";
  426. $sql .= " st.libelle as stcomm, st.picto as stcomm_picto, s.fk_stcomm as stcomm_id, s.fk_prospectlevel, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
  427. $sql .= " s.email, s.phone, s.fax, s.url, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4 as idprof4, s.idprof5 as idprof5, s.idprof6 as idprof6, s.tva_intra, s.fk_pays,";
  428. $sql .= " s.tms as date_update, s.datec as date_creation, s.import_key,";
  429. $sql .= " s.code_compta, s.code_compta_fournisseur, s.parent as fk_parent,s.price_level,";
  430. $sql .= " s2.nom as name2,";
  431. $sql .= " typent.code as typent_code,";
  432. $sql .= " staff.code as staff_code,";
  433. $sql .= " country.code as country_code, country.label as country_label,";
  434. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  435. $sql .= " region.code_region as region_code, region.nom as region_name";
  436. // We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
  437. if ($search_sale && $search_sale != '-1') {
  438. $sql .= ", sc.fk_soc, sc.fk_user";
  439. }
  440. // Add fields from extrafields
  441. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  442. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  443. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  444. }
  445. }
  446. // Add fields from hooks
  447. $parameters = array();
  448. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  449. $sql .= $hookmanager->resPrint;
  450. $sql = preg_replace('/,\s*$/', '', $sql);
  451. //$sql .= ", COUNT(rc.rowid) as anotherfield";
  452. $sqlfields = $sql; // $sql fields to remove for count totall
  453. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  454. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s.parent = s2.rowid";
  455. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  456. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (s.rowid = ef.fk_object)";
  457. }
  458. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  459. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  460. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_effectif as staff on (staff.id = s.fk_effectif)";
  461. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  462. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as region on (region.code_region = state.fk_region)";
  463. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id";
  464. // We'll need this table joined to the select in order to filter by sale
  465. if ($search_sale == -2) {
  466. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
  467. //elseif ($search_sale || (empty($user->rights->societe->client->voir) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->societe->client->readallthirdparties_advance)) && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  468. } elseif (!empty($search_sale) && $search_sale != '-1' || (empty($user->rights->societe->client->voir) && !$socid)) {
  469. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  470. }
  471. // Add table from hooks
  472. $parameters = array();
  473. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  474. $sql .= $hookmanager->resPrint;
  475. $sql .= " WHERE s.entity IN (".getEntity('societe').")";
  476. //if (empty($user->rights->societe->client->voir) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->societe->client->readallthirdparties_advance)) && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  477. if (empty($user->rights->societe->client->voir) && !$socid) {
  478. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  479. }
  480. if ($search_sale && $search_sale != '-1' && $search_sale != '-2') {
  481. $sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  482. }
  483. if (empty($user->rights->fournisseur->lire)) {
  484. $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  485. }
  486. if ($search_sale == -2) {
  487. $sql .= " AND sc.fk_user IS NULL";
  488. } elseif ($search_sale > 0) {
  489. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  490. }
  491. $searchCategoryCustomerList = $search_categ_cus ? array($search_categ_cus) : array();
  492. $searchCategoryCustomerOperator = 0;
  493. // Search for tag/category ($searchCategoryCustomerList is an array of ID)
  494. if (!empty($searchCategoryCustomerList)) {
  495. $searchCategoryCustomerSqlList = array();
  496. $listofcategoryid = '';
  497. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  498. if (intval($searchCategoryCustomer) == -2) {
  499. $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
  500. } elseif (intval($searchCategoryCustomer) > 0) {
  501. if ($searchCategoryCustomerOperator == 0) {
  502. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategoryCustomer).")";
  503. } else {
  504. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
  505. }
  506. }
  507. }
  508. if ($listofcategoryid) {
  509. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  510. }
  511. if ($searchCategoryCustomerOperator == 1) {
  512. if (!empty($searchCategoryCustomerSqlList)) {
  513. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  514. }
  515. } else {
  516. if (!empty($searchCategoryCustomerSqlList)) {
  517. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  518. }
  519. }
  520. }
  521. $searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array();
  522. $searchCategorySupplierOperator = 0;
  523. // Search for tag/category ($searchCategorySupplierList is an array of ID)
  524. if (!empty($searchCategorySupplierList)) {
  525. $searchCategorySupplierSqlList = array();
  526. $listofcategoryid = '';
  527. foreach ($searchCategorySupplierList as $searchCategorySupplier) {
  528. if (intval($searchCategorySupplier) == -2) {
  529. $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
  530. } elseif (intval($searchCategorySupplier) > 0) {
  531. if ($searchCategorySupplierOperator == 0) {
  532. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
  533. } else {
  534. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
  535. }
  536. }
  537. }
  538. if ($listofcategoryid) {
  539. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  540. }
  541. if ($searchCategorySupplierOperator == 1) {
  542. if (!empty($searchCategorySupplierSqlList)) {
  543. $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
  544. }
  545. } else {
  546. if (!empty($searchCategorySupplierSqlList)) {
  547. $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
  548. }
  549. }
  550. }
  551. if ($search_all) {
  552. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  553. }
  554. if (strlen($search_cti)) {
  555. $sql .= natural_search('s.phone', $search_cti);
  556. }
  557. if ($search_id > 0) {
  558. $sql .= natural_search("s.rowid", $search_id, 1);
  559. }
  560. if (empty($arrayfields['s.name_alias']['checked']) && $search_nom) {
  561. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_nom);
  562. } else {
  563. if ($search_nom) {
  564. $sql .= natural_search("s.nom", $search_nom);
  565. }
  566. if ($search_alias) {
  567. $sql .= natural_search("s.name_alias", $search_alias);
  568. }
  569. }
  570. if ($search_nom_only) {
  571. $sql .= natural_search("s.nom", $search_nom_only);
  572. }
  573. if ($search_customer_code) {
  574. $sql .= natural_search("s.code_client", $search_customer_code);
  575. }
  576. if ($search_supplier_code) {
  577. $sql .= natural_search("s.code_fournisseur", $search_supplier_code);
  578. }
  579. if ($search_account_customer_code) {
  580. $sql .= natural_search("s.code_compta", $search_account_customer_code);
  581. }
  582. if ($search_account_supplier_code) {
  583. $sql .= natural_search("s.code_compta_fournisseur", $search_account_supplier_code);
  584. }
  585. if ($search_address) {
  586. $sql .= natural_search('s.address', $search_address);
  587. }
  588. if (strlen($search_zip)) {
  589. $sql .= natural_search("s.zip", $search_zip);
  590. }
  591. if ($search_town) {
  592. $sql .= natural_search("s.town", $search_town);
  593. }
  594. if ($search_state) {
  595. $sql .= natural_search("state.nom", $search_state);
  596. }
  597. if ($search_region) {
  598. $sql .= natural_search("region.nom", $search_region);
  599. }
  600. if ($search_country && $search_country != '-1') {
  601. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  602. }
  603. if ($search_email) {
  604. $sql .= natural_search("s.email", $search_email);
  605. }
  606. if (strlen($search_phone)) {
  607. $sql .= natural_search("s.phone", $search_phone);
  608. }
  609. if (strlen($search_fax)) {
  610. $sql .= natural_search("s.fax", $search_fax);
  611. }
  612. if ($search_url) {
  613. $sql .= natural_search("s.url", $search_url);
  614. }
  615. if (strlen($search_idprof1)) {
  616. $sql .= natural_search("s.siren", $search_idprof1);
  617. }
  618. if (strlen($search_idprof2)) {
  619. $sql .= natural_search("s.siret", $search_idprof2);
  620. }
  621. if (strlen($search_idprof3)) {
  622. $sql .= natural_search("s.ape", $search_idprof3);
  623. }
  624. if (strlen($search_idprof4)) {
  625. $sql .= natural_search("s.idprof4", $search_idprof4);
  626. }
  627. if (strlen($search_idprof5)) {
  628. $sql .= natural_search("s.idprof5", $search_idprof5);
  629. }
  630. if (strlen($search_idprof6)) {
  631. $sql .= natural_search("s.idprof6", $search_idprof6);
  632. }
  633. if (strlen($search_vat)) {
  634. $sql .= natural_search("s.tva_intra", $search_vat);
  635. }
  636. // Filter on type of thirdparty
  637. if ($search_type > 0 && in_array($search_type, array('1,3', '1,2,3', '2,3'))) {
  638. $sql .= " AND s.client IN (".$db->sanitize($search_type).")";
  639. }
  640. if ($search_type > 0 && in_array($search_type, array('4'))) {
  641. $sql .= " AND s.fournisseur = 1";
  642. }
  643. if ($search_type == '0') {
  644. $sql .= " AND s.client = 0 AND s.fournisseur = 0";
  645. }
  646. if ($search_status != '' && $search_status >= 0) {
  647. $sql .= natural_search("s.status", $search_status, 2);
  648. }
  649. if (isModEnabled('barcode') && $search_barcode) {
  650. $sql .= natural_search("s.barcode", $search_barcode);
  651. }
  652. if ($search_price_level && $search_price_level != '-1') {
  653. $sql .= natural_search("s.price_level", $search_price_level, 2);
  654. }
  655. if ($search_type_thirdparty && $search_type_thirdparty > 0) {
  656. $sql .= natural_search("s.fk_typent", $search_type_thirdparty, 2);
  657. }
  658. if (!empty($search_staff) && $search_staff != '-1') {
  659. $sql .= natural_search("s.fk_effectif", $search_staff, 2);
  660. }
  661. if ($search_parent_name) {
  662. $sql .= natural_search("s2.nom", $search_parent_name);
  663. }
  664. if ($search_level) {
  665. $sql .= natural_search("s.fk_prospectlevel", join(',', $search_level), 3);
  666. }
  667. if ($search_stcomm) {
  668. $sql .= natural_search("s.fk_stcomm", join(',', $search_stcomm), 2);
  669. }
  670. if ($search_import_key) {
  671. $sql .= natural_search("s.import_key", $search_import_key);
  672. }
  673. // Add where from extra fields
  674. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  675. // Add where from hooks
  676. $parameters = array('socid' => $socid);
  677. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  678. if (empty($reshook)) {
  679. if ($socid) {
  680. $sql .= " AND s.rowid = ".((int) $socid);
  681. }
  682. }
  683. $sql .= $hookmanager->resPrint;
  684. // Add GroupBy from hooks
  685. $parameters = array('fieldstosearchall' => $fieldstosearchall);
  686. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  687. $sql .= $hookmanager->resPrint;
  688. // Count total nb of records
  689. $nbtotalofrecords = '';
  690. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  691. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  692. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  693. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  694. $resql = $db->query($sqlforcount);
  695. if ($resql) {
  696. $objforcount = $db->fetch_object($resql);
  697. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  698. } else {
  699. dol_print_error($db);
  700. }
  701. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  702. $page = 0;
  703. $offset = 0;
  704. }
  705. $db->free($resql);
  706. }
  707. // Complete request and execute it with limit
  708. $sql .= $db->order($sortfield, $sortorder);
  709. if ($limit) {
  710. $sql .= $db->plimit($limit + 1, $offset);
  711. }
  712. $resql = $db->query($sql);
  713. if (!$resql) {
  714. dol_print_error($db);
  715. exit;
  716. }
  717. $num = $db->num_rows($resql);
  718. // Direct jump if only one record found
  719. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($search_all != '' || $search_cti != '') && $action != 'list') {
  720. $obj = $db->fetch_object($resql);
  721. $id = $obj->rowid;
  722. if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
  723. if ($obj->client > 0) {
  724. header("Location: ".DOL_URL_ROOT.'/comm/card.php?socid='.$id);
  725. exit;
  726. }
  727. if ($obj->fournisseur > 0) {
  728. header("Location: ".DOL_URL_ROOT.'/fourn/card.php?socid='.$id);
  729. exit;
  730. }
  731. }
  732. header("Location: ".DOL_URL_ROOT.'/societe/card.php?socid='.$id);
  733. exit;
  734. }
  735. // Output page
  736. // --------------------------------------------------------------------
  737. llxHeader('', $title, $help_url);
  738. $arrayofselected = is_array($toselect) ? $toselect : array();
  739. $param = '';
  740. if (!empty($mode)) {
  741. $param .= '&mode='.urlencode($mode);
  742. }
  743. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  744. $param .= '&contextpage='.urlencode($contextpage);
  745. }
  746. if ($limit > 0 && $limit != $conf->liste_limit) {
  747. $param .= '&limit='.((int) $limit);
  748. }
  749. if ($optioncss != '') {
  750. $param .= '&optioncss='.urlencode($optioncss);
  751. }
  752. if ($search_all != '') {
  753. $param = "&search_all=".urlencode($search_all);
  754. }
  755. if ($search_categ_cus > 0) {
  756. $param .= '&search_categ_cus='.urlencode($search_categ_cus);
  757. }
  758. if ($search_categ_sup > 0) {
  759. $param .= '&search_categ_sup='.urlencode($search_categ_sup);
  760. }
  761. if ($search_sale > 0) {
  762. $param .= '&search_sale='.urlencode($search_sale);
  763. }
  764. if ($search_id > 0) {
  765. $param .= "&search_id=".urlencode($search_id);
  766. }
  767. if ($search_nom != '') {
  768. $param .= "&search_nom=".urlencode($search_nom);
  769. }
  770. if ($search_alias != '') {
  771. $param .= "&search_alias=".urlencode($search_alias);
  772. }
  773. if ($search_address != '') {
  774. $param .= '&search_address='.urlencode($search_address);
  775. }
  776. if ($search_zip != '') {
  777. $param .= "&search_zip=".urlencode($search_zip);
  778. }
  779. if ($search_town != '') {
  780. $param .= "&search_town=".urlencode($search_town);
  781. }
  782. if ($search_phone != '') {
  783. $param .= "&search_phone=".urlencode($search_phone);
  784. }
  785. if ($search_fax != '') {
  786. $param .= "&search_fax=".urlencode($search_fax);
  787. }
  788. if ($search_email != '') {
  789. $param .= "&search_email=".urlencode($search_email);
  790. }
  791. if ($search_url != '') {
  792. $param .= "&search_url=".urlencode($search_url);
  793. }
  794. if ($search_state != '') {
  795. $param .= "&search_state=".urlencode($search_state);
  796. }
  797. if ($search_region != '') {
  798. $param .= "&search_region=".urlencode($search_region);
  799. }
  800. if ($search_country != '') {
  801. $param .= "&search_country=".urlencode($search_country);
  802. }
  803. if ($search_customer_code != '') {
  804. $param .= "&search_customer_code=".urlencode($search_customer_code);
  805. }
  806. if ($search_supplier_code != '') {
  807. $param .= "&search_supplier_code=".urlencode($search_supplier_code);
  808. }
  809. if ($search_account_customer_code != '') {
  810. $param .= "&search_account_customer_code=".urlencode($search_account_customer_code);
  811. }
  812. if ($search_account_supplier_code != '') {
  813. $param .= "&search_account_supplier_code=".urlencode($search_account_supplier_code);
  814. }
  815. if ($search_barcode != '') {
  816. $param .= "&search_barcode=".urlencode($search_barcode);
  817. }
  818. if ($search_idprof1 != '') {
  819. $param .= '&search_idprof1='.urlencode($search_idprof1);
  820. }
  821. if ($search_idprof2 != '') {
  822. $param .= '&search_idprof2='.urlencode($search_idprof2);
  823. }
  824. if ($search_idprof3 != '') {
  825. $param .= '&search_idprof3='.urlencode($search_idprof3);
  826. }
  827. if ($search_idprof4 != '') {
  828. $param .= '&search_idprof4='.urlencode($search_idprof4);
  829. }
  830. if ($search_idprof5 != '') {
  831. $param .= '&search_idprof5='.urlencode($search_idprof5);
  832. }
  833. if ($search_idprof6 != '') {
  834. $param .= '&search_idprof6='.urlencode($search_idprof6);
  835. }
  836. if ($search_vat != '') {
  837. $param .= '&search_vat='.urlencode($search_vat);
  838. }
  839. if ($search_price_level != '') {
  840. $param .= '&search_price_level='.urlencode($search_price_level);
  841. }
  842. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  843. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  844. }
  845. if ($search_type != '') {
  846. $param .= '&search_type='.urlencode($search_type);
  847. }
  848. if ($search_status != '') {
  849. $param .= '&search_status='.urlencode($search_status);
  850. }
  851. if (is_array($search_level) && count($search_level)) {
  852. foreach ($search_level as $slevel) {
  853. $param .= '&search_level[]='.urlencode($slevel);
  854. }
  855. }
  856. if (is_array($search_stcomm) && count($search_stcomm)) {
  857. foreach ($search_stcomm as $slevel) {
  858. $param .= '&search_stcomm[]='.urlencode($slevel);
  859. }
  860. }
  861. if ($search_parent_name != '') {
  862. $param .= '&search_parent_name='.urlencode($search_parent_name);
  863. }
  864. if ($search_import_key != '') {
  865. $param .= '&search_import_key='.urlencode($search_import_key);
  866. }
  867. if ($type != '') {
  868. $param .= '&type='.urlencode($type);
  869. }
  870. // Add $param from extra fields
  871. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  872. // Add $param from hooks
  873. $parameters = array();
  874. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  875. $param .= $hookmanager->resPrint;
  876. // Show delete result message
  877. if (GETPOST('delsoc')) {
  878. setEventMessages($langs->trans("CompanyDeleted", GETPOST('delsoc')), null, 'mesgs');
  879. }
  880. // List of mass actions available
  881. $arrayofmassactions = array(
  882. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  883. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  884. );
  885. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  886. if (isModEnabled('category') && $user->hasRight("societe", "creer")) {
  887. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  888. }
  889. if ($user->hasRight("societe", "creer")) {
  890. $arrayofmassactions['preenable'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SetToStatus", $object->LibStatut($object::STATUS_INACTIVITY));
  891. }
  892. if ($user->hasRight("societe", "creer")) {
  893. $arrayofmassactions['predisable'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SetToStatus", $object->LibStatut($object::STATUS_CEASED));
  894. }
  895. if ($user->hasRight("societe", "creer")) {
  896. $arrayofmassactions['presetcommercial'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("AllocateCommercial");
  897. }
  898. if ($user->hasRight('societe', 'supprimer')) {
  899. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  900. }
  901. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete', 'preaffecttag', 'preenable', 'preclose'))) {
  902. $arrayofmassactions = array();
  903. }
  904. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  905. $typefilter = '';
  906. $label = 'MenuNewThirdParty';
  907. if (!empty($type)) {
  908. $typefilter = '&amp;type='.$type;
  909. if ($type == 'p') {
  910. $label = 'MenuNewProspect';
  911. }
  912. if ($type == 'c') {
  913. $label = 'MenuNewCustomer';
  914. }
  915. if ($type == 'f') {
  916. $label = 'NewSupplier';
  917. }
  918. }
  919. if ($contextpage == 'poslist' && $type == 't' && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
  920. print get_htmloutput_mesg(img_warning('default').' '.$langs->trans("BecarefullChangeThirdpartyBeforeAddProductToInvoice"), '', 'warning', 1);
  921. }
  922. // Show the new button only when this page is not opend from the Extended POS (pop-up window)
  923. // but allow it too, when a user has the rights to create a new customer
  924. if ($contextpage != 'poslist') {
  925. $url = DOL_URL_ROOT.'/societe/card.php?action=create'.$typefilter;
  926. if (!empty($socid)) {
  927. $url .= '&socid='.$socid;
  928. }
  929. $newcardbutton = '';
  930. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  931. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  932. $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url, '', $user->hasRight('societe', 'creer'));
  933. } elseif ($user->hasRight('societe', 'creer')) {
  934. $url = DOL_URL_ROOT.'/societe/card.php?action=create&type=t&contextpage=poslist&optioncss=print&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type=t&contextpage=poslist&nomassaction=1&optioncss=print&place='.$place);
  935. $label = 'MenuNewCustomer';
  936. $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url);
  937. }
  938. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter" autocomplete="off">'."\n";
  939. if ($optioncss != '') {
  940. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  941. }
  942. print '<input type="hidden" name="token" value="'.newToken().'">';
  943. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  944. print '<input type="hidden" name="action" value="list">';
  945. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  946. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  947. //print '<input type="hidden" name="page" value="'.$page.'">';
  948. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  949. print '<input type="hidden" name="page_y" value="">';
  950. print '<input type="hidden" name="mode" value="'.$mode.'">';
  951. if (empty($arrayfields['customerorsupplier']['checked'])) {
  952. print '<input type="hidden" name="type" value="'.$type.'">';
  953. }
  954. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'building', 0, $newcardbutton, '', $limit, 0, 0, 1);
  955. $langs->load("other");
  956. $textprofid = array();
  957. foreach (array(1, 2, 3, 4, 5, 6) as $key) {
  958. $label = $langs->transnoentities("ProfId".$key.$mysoc->country_code);
  959. $textprofid[$key] = '';
  960. if ($label != "ProfId".$key.$mysoc->country_code) { // Get only text between ()
  961. if (preg_match('/\((.*)\)/i', $label, $reg)) {
  962. $label = $reg[1];
  963. }
  964. $textprofid[$key] = $langs->trans("ProfIdShortDesc", $key, $mysoc->country_code, $label);
  965. }
  966. }
  967. // Add code for pre mass action (confirmation or email presend form)
  968. $topicmail = "Information";
  969. $modelmail = "thirdparty";
  970. $objecttmp = new Societe($db);
  971. $trackid = 'thi'.$object->id;
  972. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  973. if ($search_all) {
  974. $setupstring = '';
  975. foreach ($fieldstosearchall as $key => $val) {
  976. $fieldstosearchall[$key] = $langs->trans($val);
  977. $setupstring .= $key."=".$val.";";
  978. }
  979. print '<!-- Search done like if SOCIETE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  980. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  981. }
  982. $moreforfilter = '';
  983. if (empty($type) || $type == 'c' || $type == 'p') {
  984. if (isModEnabled('categorie') && $user->hasRight("categorie", "lire")) {
  985. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  986. $moreforfilter .= '<div class="divsearchfield">';
  987. $tmptitle = $langs->trans('Categories');
  988. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  989. $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $langs->trans('CustomersProspectsCategoriesShort'));
  990. $moreforfilter .= '</div>';
  991. }
  992. }
  993. if (empty($type) || $type == 'f') {
  994. if (isModEnabled("fournisseur") && isModEnabled('categorie') && $user->hasRight("categorie", "lire")) {
  995. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  996. $moreforfilter .= '<div class="divsearchfield">';
  997. $tmptitle = $langs->trans('Categories');
  998. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  999. $moreforfilter .= $formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $langs->trans('SuppliersCategoriesShort'));
  1000. $moreforfilter .= '</div>';
  1001. }
  1002. }
  1003. // If the user can view prospects other than his'
  1004. if ($user->hasRight("societe", "client", "voir") || $socid) {
  1005. $moreforfilter .= '<div class="divsearchfield">';
  1006. $tmptitle = $langs->trans('SalesRepresentatives');
  1007. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
  1008. $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $langs->trans('SalesRepresentatives'), ($conf->dol_optimize_smallscreen ? 'maxwidth200' : 'maxwidth300'), 1);
  1009. $moreforfilter .= '</div>';
  1010. }
  1011. if (!empty($moreforfilter)) {
  1012. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1013. print $moreforfilter;
  1014. $parameters = array('type'=>$type);
  1015. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1016. print $hookmanager->resPrint;
  1017. print '</div>';
  1018. }
  1019. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1020. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  1021. //$selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  1022. $selectedfields .= ((count($arrayofmassactions) && $contextpage != 'poslist') ? $form->showCheckAddButtons('checkforselect', 1) : '');
  1023. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  1024. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1025. // Fields title search
  1026. // --------------------------------------------------------------------
  1027. print '<tr class="liste_titre_filter">';
  1028. // Action column
  1029. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1030. print '<td class="liste_titre maxwidthsearch center actioncolumn">';
  1031. $searchpicto = $form->showFilterButtons('left');
  1032. print $searchpicto;
  1033. print '</td>';
  1034. }
  1035. if (!empty($arrayfields['s.rowid']['checked'])) {
  1036. print '<td class="liste_titre" data-key="id">';
  1037. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  1038. print '</td>';
  1039. }
  1040. if (!empty($arrayfields['s.nom']['checked'])) {
  1041. print '<td class="liste_titre" data-key="ref">';
  1042. if (!empty($search_nom_only) && empty($search_nom)) {
  1043. $search_nom = $search_nom_only;
  1044. }
  1045. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_nom" value="'.dol_escape_htmltag($search_nom).'">';
  1046. print '</td>';
  1047. }
  1048. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1049. print '<td class="liste_titre">';
  1050. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_alias" value="'.dol_escape_htmltag($search_alias).'">';
  1051. print '</td>';
  1052. }
  1053. // Barcode
  1054. if (!empty($arrayfields['s.barcode']['checked'])) {
  1055. print '<td class="liste_titre">';
  1056. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_barcode" value="'.dol_escape_htmltag($search_barcode).'">';
  1057. print '</td>';
  1058. }
  1059. // Customer code
  1060. if (!empty($arrayfields['s.code_client']['checked'])) {
  1061. print '<td class="liste_titre">';
  1062. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_customer_code" value="'.dol_escape_htmltag($search_customer_code).'">';
  1063. print '</td>';
  1064. }
  1065. // Supplier code
  1066. if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
  1067. print '<td class="liste_titre">';
  1068. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_supplier_code" value="'.dol_escape_htmltag($search_supplier_code).'">';
  1069. print '</td>';
  1070. }
  1071. // Account Customer code
  1072. if (!empty($arrayfields['s.code_compta']['checked'])) {
  1073. print '<td class="liste_titre">';
  1074. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_account_customer_code" value="'.dol_escape_htmltag($search_account_customer_code).'">';
  1075. print '</td>';
  1076. }
  1077. // Account Supplier code
  1078. if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
  1079. print '<td class="liste_titre">';
  1080. print '<input class="flat maxwidth75imp" type="text" name="search_account_supplier_code" value="'.dol_escape_htmltag($search_account_supplier_code).'">';
  1081. print '</td>';
  1082. }
  1083. // Address
  1084. if (!empty($arrayfields['s.address']['checked'])) {
  1085. print '<td class="liste_titre">';
  1086. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_address" value="'.dol_escape_htmltag($search_address).'">';
  1087. print '</td>';
  1088. }
  1089. // Zip
  1090. if (!empty($arrayfields['s.zip']['checked'])) {
  1091. print '<td class="liste_titre">';
  1092. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
  1093. print '</td>';
  1094. }
  1095. // Town
  1096. if (!empty($arrayfields['s.town']['checked'])) {
  1097. print '<td class="liste_titre">';
  1098. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
  1099. print '</td>';
  1100. }
  1101. // State
  1102. if (!empty($arrayfields['state.nom']['checked'])) {
  1103. print '<td class="liste_titre">';
  1104. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1105. print '</td>';
  1106. }
  1107. // Region
  1108. if (!empty($arrayfields['region.nom']['checked'])) {
  1109. print '<td class="liste_titre">';
  1110. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
  1111. print '</td>';
  1112. }
  1113. // Country
  1114. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1115. print '<td class="liste_titre center">';
  1116. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1117. print '</td>';
  1118. }
  1119. // Company type
  1120. if (!empty($arrayfields['typent.code']['checked'])) {
  1121. print '<td class="liste_titre maxwidthonsmartphone center">';
  1122. // We use showempty=0 here because there is already an unknown value into dictionary.
  1123. 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), 'minwidth50 maxwidth125', 1);
  1124. print '</td>';
  1125. }
  1126. // Multiprice level
  1127. if (!empty($arrayfields['s.price_level']['checked'])) {
  1128. print '<td class="liste_titre">';
  1129. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_price_level" value="'.dol_escape_htmltag($search_price_level).'">';
  1130. print '</td>';
  1131. }
  1132. // Staff
  1133. if (!empty($arrayfields['staff.code']['checked'])) {
  1134. print '<td class="liste_titre maxwidthonsmartphone center">';
  1135. print $form->selectarray("search_staff", $formcompany->effectif_array(0), $search_staff, 0, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100', 1);
  1136. print '</td>';
  1137. }
  1138. if (!empty($arrayfields['s.email']['checked'])) {
  1139. // Email
  1140. print '<td class="liste_titre">';
  1141. print '<input class="flat searchemail maxwidth50imp" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
  1142. print '</td>';
  1143. }
  1144. if (!empty($arrayfields['s.phone']['checked'])) {
  1145. // Phone
  1146. print '<td class="liste_titre">';
  1147. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
  1148. print '</td>';
  1149. }
  1150. if (!empty($arrayfields['s.fax']['checked'])) {
  1151. // Fax
  1152. print '<td class="liste_titre">';
  1153. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_fax" value="'.dol_escape_htmltag($search_fax).'">';
  1154. print '</td>';
  1155. }
  1156. if (!empty($arrayfields['s.url']['checked'])) {
  1157. // Url
  1158. print '<td class="liste_titre">';
  1159. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_url" value="'.dol_escape_htmltag($search_url).'">';
  1160. print '</td>';
  1161. }
  1162. if (!empty($arrayfields['s.siren']['checked'])) {
  1163. // IdProf1
  1164. print '<td class="liste_titre">';
  1165. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof1" value="'.dol_escape_htmltag($search_idprof1).'">';
  1166. print '</td>';
  1167. }
  1168. if (!empty($arrayfields['s.siret']['checked'])) {
  1169. // IdProf2
  1170. print '<td class="liste_titre">';
  1171. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof2" value="'.dol_escape_htmltag($search_idprof2).'">';
  1172. print '</td>';
  1173. }
  1174. if (!empty($arrayfields['s.ape']['checked'])) {
  1175. // IdProf3
  1176. print '<td class="liste_titre">';
  1177. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof3" value="'.dol_escape_htmltag($search_idprof3).'">';
  1178. print '</td>';
  1179. }
  1180. if (!empty($arrayfields['s.idprof4']['checked'])) {
  1181. // IdProf4
  1182. print '<td class="liste_titre">';
  1183. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof4" value="'.dol_escape_htmltag($search_idprof4).'">';
  1184. print '</td>';
  1185. }
  1186. if (!empty($arrayfields['s.idprof5']['checked'])) {
  1187. // IdProf5
  1188. print '<td class="liste_titre">';
  1189. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof5" value="'.dol_escape_htmltag($search_idprof5).'">';
  1190. print '</td>';
  1191. }
  1192. if (!empty($arrayfields['s.idprof6']['checked'])) {
  1193. // IdProf6
  1194. print '<td class="liste_titre">';
  1195. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof6" value="'.dol_escape_htmltag($search_idprof6).'">';
  1196. print '</td>';
  1197. }
  1198. if (!empty($arrayfields['s.tva_intra']['checked'])) {
  1199. // Vat number
  1200. print '<td class="liste_titre">';
  1201. print '<input class="flat searchstring maxwidth50imp" type="text" name="search_vat" value="'.dol_escape_htmltag($search_vat).'">';
  1202. print '</td>';
  1203. }
  1204. // Nature (customer/prospect/supplier)
  1205. if (!empty($arrayfields['customerorsupplier']['checked'])) {
  1206. print '<td class="liste_titre maxwidthonsmartphone center">';
  1207. if ($type != '') {
  1208. print '<input type="hidden" name="type" value="'.$type.'">';
  1209. }
  1210. print $formcompany->selectProspectCustomerType($search_type, 'search_type', 'search_type', 'list');
  1211. print '</td>';
  1212. }
  1213. // Prospect level
  1214. if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
  1215. print '<td class="liste_titre center">';
  1216. print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
  1217. print '</td>';
  1218. }
  1219. // Prospect status
  1220. if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
  1221. print '<td class="liste_titre maxwidthonsmartphone center">';
  1222. $arraystcomm = array();
  1223. foreach ($prospectstatic->cacheprospectstatus as $key => $val) {
  1224. $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  1225. }
  1226. //print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', '', 1);
  1227. print $form->multiselectarray('search_stcomm', $arraystcomm, $search_stcomm, 0, 0, 'width100', 0, 0, '', '', '', 2);
  1228. print '</td>';
  1229. }
  1230. if (!empty($arrayfields['s2.nom']['checked'])) {
  1231. print '<td class="liste_titre center">';
  1232. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
  1233. print '</td>';
  1234. }
  1235. // Extra fields
  1236. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1237. // Fields from hook
  1238. $parameters = array('arrayfields'=>$arrayfields);
  1239. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1240. print $hookmanager->resPrint;
  1241. // Date creation
  1242. if (!empty($arrayfields['s.datec']['checked'])) {
  1243. print '<td class="liste_titre">';
  1244. print '</td>';
  1245. }
  1246. // Date modification
  1247. if (!empty($arrayfields['s.tms']['checked'])) {
  1248. print '<td class="liste_titre">';
  1249. print '</td>';
  1250. }
  1251. // Status
  1252. if (!empty($arrayfields['s.status']['checked'])) {
  1253. print '<td class="liste_titre center minwidth75imp parentonrightofpage">';
  1254. print $form->selectarray('search_status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);
  1255. print '</td>';
  1256. }
  1257. if (!empty($arrayfields['s.import_key']['checked'])) {
  1258. print '<td class="liste_titre center">';
  1259. print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  1260. print '</td>';
  1261. }
  1262. // Action column
  1263. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1264. print '<td class="liste_titre center maxwidthsearch actioncolumn">';
  1265. $searchpicto = $form->showFilterButtons();
  1266. print $searchpicto;
  1267. print '</td>';
  1268. }
  1269. print '</tr>'."\n";
  1270. $totalarray = array();
  1271. $totalarray['nbfield'] = 0;
  1272. // Fields title label
  1273. // --------------------------------------------------------------------
  1274. print '<tr class="liste_titre">';
  1275. // Action column
  1276. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1277. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1278. $totalarray['nbfield']++;
  1279. }
  1280. if (!empty($arrayfields['s.rowid']['checked'])) {
  1281. print_liste_field_titre($arrayfields['s.rowid']['label'], $_SERVER["PHP_SELF"], "s.rowid", "", $param, ' data-key="id"', $sortfield, $sortorder, '');
  1282. $totalarray['nbfield']++;
  1283. }
  1284. if (!empty($arrayfields['s.nom']['checked'])) {
  1285. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, ' data-key="ref"', $sortfield, $sortorder, ' ');
  1286. $totalarray['nbfield']++;
  1287. }
  1288. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1289. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, "", $sortfield, $sortorder);
  1290. $totalarray['nbfield']++;
  1291. }
  1292. if (!empty($arrayfields['s.barcode']['checked'])) {
  1293. print_liste_field_titre($arrayfields['s.barcode']['label'], $_SERVER["PHP_SELF"], "s.barcode", $param, '', '', $sortfield, $sortorder);
  1294. $totalarray['nbfield']++;
  1295. }
  1296. if (!empty($arrayfields['s.code_client']['checked'])) {
  1297. print_liste_field_titre($arrayfields['s.code_client']['label'], $_SERVER["PHP_SELF"], "s.code_client", "", $param, '', $sortfield, $sortorder);
  1298. $totalarray['nbfield']++;
  1299. }
  1300. if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
  1301. print_liste_field_titre($arrayfields['s.code_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $param, '', $sortfield, $sortorder);
  1302. $totalarray['nbfield']++;
  1303. }
  1304. if (!empty($arrayfields['s.code_compta']['checked'])) {
  1305. print_liste_field_titre($arrayfields['s.code_compta']['label'], $_SERVER["PHP_SELF"], "s.code_compta", "", $param, '', $sortfield, $sortorder);
  1306. $totalarray['nbfield']++;
  1307. }
  1308. if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
  1309. print_liste_field_titre($arrayfields['s.code_compta_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_compta_fournisseur", "", $param, '', $sortfield, $sortorder);
  1310. $totalarray['nbfield']++;
  1311. }
  1312. if (!empty($arrayfields['s.address']['checked'])) {
  1313. print_liste_field_titre($arrayfields['s.address']['label'], $_SERVER['PHP_SELF'], 's.address', '', $param, '', $sortfield, $sortorder);
  1314. $totalarray['nbfield']++;
  1315. }
  1316. if (!empty($arrayfields['s.zip']['checked'])) {
  1317. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], "s.zip", "", $param, '', $sortfield, $sortorder);
  1318. $totalarray['nbfield']++;
  1319. }
  1320. if (!empty($arrayfields['s.town']['checked'])) {
  1321. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], "s.town", "", $param, '', $sortfield, $sortorder);
  1322. $totalarray['nbfield']++;
  1323. }
  1324. if (!empty($arrayfields['state.nom']['checked'])) {
  1325. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1326. $totalarray['nbfield']++;
  1327. }
  1328. if (!empty($arrayfields['region.nom']['checked'])) {
  1329. print_liste_field_titre($arrayfields['region.nom']['label'], $_SERVER["PHP_SELF"], "region.nom", "", $param, '', $sortfield, $sortorder);
  1330. $totalarray['nbfield']++;
  1331. }
  1332. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1333. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1334. $totalarray['nbfield']++;
  1335. }
  1336. if (!empty($arrayfields['typent.code']['checked'])) {
  1337. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, "", $sortfield, $sortorder, 'center ');
  1338. $totalarray['nbfield']++;
  1339. }
  1340. if (!empty($arrayfields['staff.code']['checked'])) {
  1341. print_liste_field_titre($arrayfields['staff.code']['label'], $_SERVER["PHP_SELF"], "staff.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1342. $totalarray['nbfield']++;
  1343. }
  1344. if (!empty($arrayfields['s.price_level']['checked'])) {
  1345. print_liste_field_titre($arrayfields['s.price_level']['label'], $_SERVER["PHP_SELF"], "s.price_level", "", $param, '', $sortfield, $sortorder);
  1346. $totalarray['nbfield']++;
  1347. }
  1348. if (!empty($arrayfields['s.email']['checked'])) {
  1349. print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
  1350. $totalarray['nbfield']++;
  1351. }
  1352. if (!empty($arrayfields['s.phone']['checked'])) {
  1353. print_liste_field_titre($arrayfields['s.phone']['label'], $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder);
  1354. $totalarray['nbfield']++;
  1355. }
  1356. if (!empty($arrayfields['s.fax']['checked'])) {
  1357. print_liste_field_titre($arrayfields['s.fax']['label'], $_SERVER["PHP_SELF"], "s.fax", "", $param, '', $sortfield, $sortorder);
  1358. $totalarray['nbfield']++;
  1359. }
  1360. if (!empty($arrayfields['s.url']['checked'])) {
  1361. print_liste_field_titre($arrayfields['s.url']['label'], $_SERVER["PHP_SELF"], "s.url", "", $param, '', $sortfield, $sortorder);
  1362. $totalarray['nbfield']++;
  1363. }
  1364. if (!empty($arrayfields['s.siren']['checked'])) {
  1365. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"), $textprofid[1], 1, 0), $_SERVER["PHP_SELF"], "s.siren", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1366. $totalarray['nbfield']++;
  1367. }
  1368. if (!empty($arrayfields['s.siret']['checked'])) {
  1369. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"), $textprofid[2], 1, 0), $_SERVER["PHP_SELF"], "s.siret", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1370. $totalarray['nbfield']++;
  1371. }
  1372. if (!empty($arrayfields['s.ape']['checked'])) {
  1373. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"), $textprofid[3], 1, 0), $_SERVER["PHP_SELF"], "s.ape", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1374. $totalarray['nbfield']++;
  1375. }
  1376. if (!empty($arrayfields['s.idprof4']['checked'])) {
  1377. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof4", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1378. $totalarray['nbfield']++;
  1379. }
  1380. if (!empty($arrayfields['s.idprof5']['checked'])) {
  1381. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId5Short"), $textprofid[5], 1, 0), $_SERVER["PHP_SELF"], "s.idprof5", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1382. $totalarray['nbfield']++;
  1383. }
  1384. if (!empty($arrayfields['s.idprof6']['checked'])) {
  1385. print_liste_field_titre($form->textwithpicto($langs->trans("ProfId6Short"), $textprofid[6], 1, 0), $_SERVER["PHP_SELF"], "s.idprof6", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1386. $totalarray['nbfield']++;
  1387. }
  1388. if (!empty($arrayfields['s.tva_intra']['checked'])) {
  1389. print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder, 'nowrap ');
  1390. $totalarray['nbfield']++;
  1391. }
  1392. if (!empty($arrayfields['customerorsupplier']['checked'])) {
  1393. print_liste_field_titre($arrayfields['customerorsupplier']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); // type of customer
  1394. $totalarray['nbfield']++;
  1395. }
  1396. if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
  1397. print_liste_field_titre($arrayfields['s.fk_prospectlevel']['label'], $_SERVER["PHP_SELF"], "s.fk_prospectlevel", "", $param, '', $sortfield, $sortorder, 'center ');
  1398. $totalarray['nbfield']++;
  1399. }
  1400. if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
  1401. print_liste_field_titre($arrayfields['s.fk_stcomm']['label'], $_SERVER["PHP_SELF"], "s.fk_stcomm", "", $param, '', $sortfield, $sortorder, 'center ');
  1402. $totalarray['nbfield']++;
  1403. }
  1404. if (!empty($arrayfields['s2.nom']['checked'])) {
  1405. print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER["PHP_SELF"], "s2.nom", "", $param, '', $sortfield, $sortorder, 'center ');
  1406. $totalarray['nbfield']++;
  1407. }
  1408. // Extra fields
  1409. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1410. // Hook fields
  1411. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1412. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1413. print $hookmanager->resPrint;
  1414. if (!empty($arrayfields['s.datec']['checked'])) {
  1415. print_liste_field_titre($arrayfields['s.datec']['label'], $_SERVER["PHP_SELF"], "s.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1416. $totalarray['nbfield']++; // For the column action
  1417. }
  1418. if (!empty($arrayfields['s.tms']['checked'])) {
  1419. print_liste_field_titre($arrayfields['s.tms']['label'], $_SERVER["PHP_SELF"], "s.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1420. $totalarray['nbfield']++; // For the column action
  1421. }
  1422. if (!empty($arrayfields['s.status']['checked'])) {
  1423. print_liste_field_titre($arrayfields['s.status']['label'], $_SERVER["PHP_SELF"], "s.status", "", $param, '', $sortfield, $sortorder, 'center ');
  1424. $totalarray['nbfield']++; // For the column action
  1425. }
  1426. if (!empty($arrayfields['s.import_key']['checked'])) {
  1427. print_liste_field_titre($arrayfields['s.import_key']['label'], $_SERVER["PHP_SELF"], "s.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  1428. $totalarray['nbfield']++; // For the column action
  1429. }
  1430. // Action column
  1431. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1432. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1433. $totalarray['nbfield']++;
  1434. }
  1435. print '</tr>'."\n";
  1436. // Loop on record
  1437. // --------------------------------------------------------------------
  1438. $i = 0;
  1439. $savnbfield = $totalarray['nbfield'];
  1440. $totalarray = array();
  1441. $totalarray['nbfield'] = 0;
  1442. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1443. while ($i < $imaxinloop) {
  1444. $obj = $db->fetch_object($resql);
  1445. if (empty($obj)) {
  1446. break; // Should not happen
  1447. }
  1448. $parameters = array('staticdata' => $obj);
  1449. // Note that $action and $object may have been modified by hook
  1450. // do companystatic fetch in hook if wanted or anything else
  1451. $reshook = $hookmanager->executeHooks('loadStaticObject', $parameters, $companystatic, $action);
  1452. if (empty($reshook)) {
  1453. $companystatic->id = $obj->rowid;
  1454. $companystatic->name = $obj->name;
  1455. $companystatic->name_alias = $obj->name_alias;
  1456. $companystatic->logo = $obj->logo;
  1457. $companystatic->barcode = $obj->barcode;
  1458. $companystatic->canvas = $obj->canvas;
  1459. $companystatic->client = $obj->client;
  1460. $companystatic->status = $obj->status;
  1461. $companystatic->email = $obj->email;
  1462. $companystatic->address = $obj->address;
  1463. $companystatic->zip = $obj->zip;
  1464. $companystatic->town = $obj->town;
  1465. $companystatic->fournisseur = $obj->fournisseur;
  1466. $companystatic->code_client = $obj->code_client;
  1467. $companystatic->code_fournisseur = $obj->code_fournisseur;
  1468. $companystatic->tva_intra = $obj->tva_intra;
  1469. $companystatic->country_code = $obj->country_code;
  1470. $companystatic->code_compta_client = $obj->code_compta;
  1471. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  1472. $companystatic->fk_prospectlevel = $obj->fk_prospectlevel;
  1473. $companystatic->fk_parent = $obj->fk_parent;
  1474. $companystatic->entity = $obj->entity;
  1475. }
  1476. if ($mode == 'kanban') {
  1477. if ($i == 0) {
  1478. print '<tr><td colspan="'.$savnbfield.'">';
  1479. print '<div class="box-flex-container kanban">';
  1480. }
  1481. // Output Kanban
  1482. print $companystatic->getKanbanView('', array('selected' => in_array($obj->rowid, $arrayofselected)));
  1483. if ($i == ($imaxinloop - 1)) {
  1484. print '</div>';
  1485. print '</td></tr>';
  1486. }
  1487. } else {
  1488. // Show line of result
  1489. $j = 0;
  1490. print '<tr data-rowid="'.$object->id.'" class="oddeven"';
  1491. if ($contextpage == 'poslist') {
  1492. print ' onclick="location.href=\'list.php?action=change&contextpage=poslist&idcustomer='.$obj->rowid.'&place='.urlencode($place).'\'"';
  1493. }
  1494. print '>';
  1495. // Action column (Show the massaction button only when this page is not opend from the Extended POS)
  1496. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1497. print '<td class="nowrap center actioncolumn">';
  1498. if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1499. $selected = 0;
  1500. if (in_array($obj->rowid, $arrayofselected)) {
  1501. $selected = 1;
  1502. }
  1503. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1504. }
  1505. print '</td>';
  1506. if (!$i) {
  1507. $totalarray['nbfield']++;
  1508. }
  1509. }
  1510. if (!empty($arrayfields['s.rowid']['checked'])) {
  1511. print '<td class="tdoverflowmax50" data-key="id">';
  1512. print $obj->rowid;
  1513. print "</td>\n";
  1514. if (!$i) {
  1515. $totalarray['nbfield']++;
  1516. }
  1517. }
  1518. if (!empty($arrayfields['s.nom']['checked'])) {
  1519. print '<td'.(empty($conf->global->MAIN_SOCIETE_SHOW_COMPLETE_NAME) ? ' class="tdoverflowmax200"' : '').' data-key="ref">';
  1520. if ($contextpage == 'poslist') {
  1521. print dol_escape_htmltag($companystatic->name);
  1522. } else {
  1523. print $companystatic->getNomUrl(1, '', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1524. }
  1525. print "</td>\n";
  1526. if (!$i) {
  1527. $totalarray['nbfield']++;
  1528. }
  1529. }
  1530. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1531. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->name_alias).'">';
  1532. print dol_escape_htmltag($companystatic->name_alias);
  1533. print "</td>\n";
  1534. if (!$i) {
  1535. $totalarray['nbfield']++;
  1536. }
  1537. }
  1538. // Barcode
  1539. if (!empty($arrayfields['s.barcode']['checked'])) {
  1540. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->barcode).'">'.dol_escape_htmltag($companystatic->barcode).'</td>';
  1541. if (!$i) {
  1542. $totalarray['nbfield']++;
  1543. }
  1544. }
  1545. // Customer code
  1546. if (!empty($arrayfields['s.code_client']['checked'])) {
  1547. print '<td class="nowraponall">'.dol_escape_htmltag($companystatic->code_client).'</td>';
  1548. if (!$i) {
  1549. $totalarray['nbfield']++;
  1550. }
  1551. }
  1552. // Supplier code
  1553. if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
  1554. print '<td class="nowraponall">'.dol_escape_htmltag($companystatic->code_fournisseur).'</td>';
  1555. if (!$i) {
  1556. $totalarray['nbfield']++;
  1557. }
  1558. }
  1559. // Account customer code
  1560. if (!empty($arrayfields['s.code_compta']['checked'])) {
  1561. print '<td>'.dol_escape_htmltag($companystatic->code_compta_client).'</td>';
  1562. if (!$i) {
  1563. $totalarray['nbfield']++;
  1564. }
  1565. }
  1566. // Account supplier code
  1567. if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
  1568. print '<td>'.dol_escape_htmltag($companystatic->code_compta_fournisseur).'</td>';
  1569. if (!$i) {
  1570. $totalarray['nbfield']++;
  1571. }
  1572. }
  1573. // Address
  1574. if (!empty($arrayfields['s.address']['checked'])) {
  1575. print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($companystatic->address).'">'.dol_escape_htmltag($companystatic->address).'</td>';
  1576. if (!$i) {
  1577. $totalarray['nbfield']++;
  1578. }
  1579. }
  1580. // Zip
  1581. if (!empty($arrayfields['s.zip']['checked'])) {
  1582. print "<td>".dol_escape_htmltag($companystatic->zip)."</td>\n";
  1583. if (!$i) {
  1584. $totalarray['nbfield']++;
  1585. }
  1586. }
  1587. // Town
  1588. if (!empty($arrayfields['s.town']['checked'])) {
  1589. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->town).'">'.dol_escape_htmltag($companystatic->town)."</td>\n";
  1590. if (!$i) {
  1591. $totalarray['nbfield']++;
  1592. }
  1593. }
  1594. // State
  1595. if (!empty($arrayfields['state.nom']['checked'])) {
  1596. print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
  1597. if (!$i) {
  1598. $totalarray['nbfield']++;
  1599. }
  1600. }
  1601. // Region
  1602. if (!empty($arrayfields['region.nom']['checked'])) {
  1603. print "<td>".dol_escape_htmltag($obj->region_name)."</td>\n";
  1604. if (!$i) {
  1605. $totalarray['nbfield']++;
  1606. }
  1607. }
  1608. // Country
  1609. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1610. print '<td class="center tdoverflowmax100">';
  1611. $labelcountry = ($companystatic->country_code && ($langs->trans("Country".$companystatic->country_code) != "Country".$companystatic->country_code)) ? $langs->trans("Country".$companystatic->country_code) : $obj->country_label;
  1612. print $labelcountry;
  1613. print '</td>';
  1614. if (!$i) {
  1615. $totalarray['nbfield']++;
  1616. }
  1617. }
  1618. // Type ent
  1619. if (!empty($arrayfields['typent.code']['checked'])) {
  1620. if (!isset($typenArray) || !is_array($typenArray) || count($typenArray) == 0) {
  1621. $typenArray = $formcompany->typent_array(1);
  1622. }
  1623. $labeltypeofcompany= empty($typenArray[$obj->typent_code]) ? '' : $typenArray[$obj->typent_code];
  1624. print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($labeltypeofcompany).'">';
  1625. print dol_escape_htmltag($labeltypeofcompany);
  1626. print '</td>';
  1627. if (!$i) {
  1628. $totalarray['nbfield']++;
  1629. }
  1630. }
  1631. // Multiprice level
  1632. if (!empty($arrayfields['s.price_level']['checked'])) {
  1633. print '<td class="center">'.$obj->price_level."</td>\n";
  1634. if (!$i) {
  1635. $totalarray['nbfield']++;
  1636. }
  1637. }
  1638. // Staff
  1639. if (!empty($arrayfields['staff.code']['checked'])) {
  1640. print '<td class="center">';
  1641. if (!is_array($staffArray) || count($staffArray) == 0) {
  1642. $staffArray = $formcompany->effectif_array(1);
  1643. }
  1644. print $staffArray[$obj->staff_code];
  1645. print '</td>';
  1646. if (!$i) {
  1647. $totalarray['nbfield']++;
  1648. }
  1649. }
  1650. if (!empty($arrayfields['s.email']['checked'])) {
  1651. print '<td class="tdoverflowmax150">'.dol_print_email($obj->email, $obj->rowid, $obj->rowid, 'AC_EMAIL', 0, 0, 1)."</td>\n";
  1652. if (!$i) {
  1653. $totalarray['nbfield']++;
  1654. }
  1655. }
  1656. if (!empty($arrayfields['s.phone']['checked'])) {
  1657. print '<td class="nowraponall">'.dol_print_phone($obj->phone, $companystatic->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."</td>\n";
  1658. if (!$i) {
  1659. $totalarray['nbfield']++;
  1660. }
  1661. }
  1662. if (!empty($arrayfields['s.fax']['checked'])) {
  1663. print '<td class="nowraponall">'.dol_print_phone($obj->fax, $companystatic->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'fax')."</td>\n";
  1664. if (!$i) {
  1665. $totalarray['nbfield']++;
  1666. }
  1667. }
  1668. if (!empty($arrayfields['s.url']['checked'])) {
  1669. print "<td>".dol_print_url($obj->url, '', '', 1)."</td>\n";
  1670. if (!$i) {
  1671. $totalarray['nbfield']++;
  1672. }
  1673. }
  1674. if (!empty($arrayfields['s.siren']['checked'])) {
  1675. print "<td>".$obj->idprof1."</td>\n";
  1676. if (!$i) {
  1677. $totalarray['nbfield']++;
  1678. }
  1679. }
  1680. if (!empty($arrayfields['s.siret']['checked'])) {
  1681. print "<td>".$obj->idprof2."</td>\n";
  1682. if (!$i) {
  1683. $totalarray['nbfield']++;
  1684. }
  1685. }
  1686. if (!empty($arrayfields['s.ape']['checked'])) {
  1687. print "<td>".$obj->idprof3."</td>\n";
  1688. if (!$i) {
  1689. $totalarray['nbfield']++;
  1690. }
  1691. }
  1692. if (!empty($arrayfields['s.idprof4']['checked'])) {
  1693. print "<td>".$obj->idprof4."</td>\n";
  1694. if (!$i) {
  1695. $totalarray['nbfield']++;
  1696. }
  1697. }
  1698. if (!empty($arrayfields['s.idprof5']['checked'])) {
  1699. print "<td>".$obj->idprof5."</td>\n";
  1700. if (!$i) {
  1701. $totalarray['nbfield']++;
  1702. }
  1703. }
  1704. if (!empty($arrayfields['s.idprof6']['checked'])) {
  1705. print "<td>".$obj->idprof6."</td>\n";
  1706. if (!$i) {
  1707. $totalarray['nbfield']++;
  1708. }
  1709. }
  1710. // VAT
  1711. if (!empty($arrayfields['s.tva_intra']['checked'])) {
  1712. print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($companystatic->tva_intra).'">';
  1713. if ($companystatic->tva_intra && !isValidVATID($companystatic)) {
  1714. print img_warning("BadVATNumber", '', 'pictofixedwidth');
  1715. }
  1716. print $companystatic->tva_intra;
  1717. print "</td>\n";
  1718. if (!$i) {
  1719. $totalarray['nbfield']++;
  1720. }
  1721. }
  1722. // Type
  1723. if (!empty($arrayfields['customerorsupplier']['checked'])) {
  1724. print '<td class="center">';
  1725. print $companystatic->getTypeUrl(1);
  1726. print '</td>';
  1727. if (!$i) {
  1728. $totalarray['nbfield']++;
  1729. }
  1730. }
  1731. if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
  1732. // Prospect level
  1733. print '<td class="center nowraponall">';
  1734. print $companystatic->getLibProspLevel();
  1735. print "</td>";
  1736. if (!$i) {
  1737. $totalarray['nbfield']++;
  1738. }
  1739. }
  1740. if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
  1741. // Prospect status
  1742. print '<td class="center nowraponall">';
  1743. $prospectid = $obj->rowid;
  1744. $statusprospect = $obj->stcomm_id;
  1745. $formcompany->selectProspectStatus('status_prospect', $prospectstatic, $statusprospect, $prospectid);
  1746. print '</td>';
  1747. if (!$i) {
  1748. $totalarray['nbfield']++;
  1749. }
  1750. }
  1751. // Parent company
  1752. if (!empty($arrayfields['s2.nom']['checked'])) {
  1753. print '<td class="center tdoverflowmax100">';
  1754. if ($companystatic->fk_parent > 0) {
  1755. $companyparent->fetch($companystatic->fk_parent);
  1756. print $companyparent->getNomUrl(1);
  1757. }
  1758. print "</td>";
  1759. if (!$i) {
  1760. $totalarray['nbfield']++;
  1761. }
  1762. }
  1763. // Extra fields
  1764. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1765. // Fields from hook
  1766. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1767. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1768. print $hookmanager->resPrint;
  1769. // Date creation
  1770. if (!empty($arrayfields['s.datec']['checked'])) {
  1771. print '<td class="center nowraponall">';
  1772. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1773. print '</td>';
  1774. if (!$i) {
  1775. $totalarray['nbfield']++;
  1776. }
  1777. }
  1778. // Date modification
  1779. if (!empty($arrayfields['s.tms']['checked'])) {
  1780. print '<td class="center nowraponall">';
  1781. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1782. print '</td>';
  1783. if (!$i) {
  1784. $totalarray['nbfield']++;
  1785. }
  1786. }
  1787. // Status
  1788. if (!empty($arrayfields['s.status']['checked'])) {
  1789. print '<td class="center nowraponall">'.$companystatic->getLibStatut(5).'</td>';
  1790. if (!$i) {
  1791. $totalarray['nbfield']++;
  1792. }
  1793. }
  1794. // Import key
  1795. if (!empty($arrayfields['s.import_key']['checked'])) {
  1796. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->import_key).'">';
  1797. print dol_escape_htmltag($obj->import_key);
  1798. print "</td>\n";
  1799. if (!$i) {
  1800. $totalarray['nbfield']++;
  1801. }
  1802. }
  1803. // Action column (Show the massaction button only when this page is not opend from the Extended POS)
  1804. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1805. print '<td class="nowrap center actioncolumn">';
  1806. if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1807. $selected = 0;
  1808. if (in_array($obj->rowid, $arrayofselected)) {
  1809. $selected = 1;
  1810. }
  1811. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1812. }
  1813. print '</td>';
  1814. if (!$i) {
  1815. $totalarray['nbfield']++;
  1816. }
  1817. }
  1818. print '</tr>'."\n";
  1819. }
  1820. $i++;
  1821. }
  1822. // Line that calls the select_status function by passing it js as the 5th parameter in order to activate the js script
  1823. $formcompany->selectProspectStatus('status_prospect', $prospectstatic, null, null, "js");
  1824. // If no record found
  1825. if ($num == 0) {
  1826. $colspan = 1;
  1827. foreach ($arrayfields as $key => $val) {
  1828. if (!empty($val['checked'])) {
  1829. $colspan++;
  1830. }
  1831. }
  1832. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1833. }
  1834. $db->free($resql);
  1835. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1836. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1837. print $hookmanager->resPrint;
  1838. print '</table>'."\n";
  1839. print '</div>'."\n";
  1840. print '</form>'."\n";
  1841. // End of page
  1842. llxFooter();
  1843. $db->close();