list.php 77 KB

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