list.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  8. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  9. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/contrat/list.php
  26. * \ingroup contrat
  27. * \brief Page liste des contrats
  28. */
  29. require ("../main.inc.php");
  30. require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. $langs->load("contracts");
  35. $langs->load("products");
  36. $langs->load("companies");
  37. $langs->load("compta");
  38. $action=GETPOST('action','alpha');
  39. $massaction=GETPOST('massaction','alpha');
  40. $show_files=GETPOST('show_files','int');
  41. $confirm=GETPOST('confirm','alpha');
  42. $toselect = GETPOST('toselect', 'array');
  43. $search_name=GETPOST('search_name');
  44. $search_town=GETPOST('search_town','alpha');
  45. $search_zip=GETPOST('search_zip','alpha');
  46. $search_state=trim(GETPOST("search_state"));
  47. $search_country=GETPOST("search_country",'int');
  48. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  49. $search_contract=GETPOST('search_contract');
  50. $search_ref_supplier=GETPOST('search_ref_supplier','alpha');
  51. $sall=GETPOST('sall', 'alphanohtml');
  52. $search_status=GETPOST('search_status');
  53. $socid=GETPOST('socid');
  54. $search_user=GETPOST('search_user','int');
  55. $search_sale=GETPOST('search_sale','int');
  56. $search_product_category=GETPOST('search_product_category','int');
  57. $day=GETPOST("day","int");
  58. $year=GETPOST("year","int");
  59. $month=GETPOST("month","int");
  60. $optioncss = GETPOST('optioncss','alpha');
  61. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  62. $sortfield = GETPOST("sortfield",'alpha');
  63. $sortorder = GETPOST("sortorder",'alpha');
  64. $page = GETPOST("page",'int');
  65. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  66. $offset = $limit * $page;
  67. $pageprev = $page - 1;
  68. $pagenext = $page + 1;
  69. if (! $sortfield) $sortfield='c.ref';
  70. if (! $sortorder) $sortorder='DESC';
  71. // Security check
  72. $id=GETPOST('id','int');
  73. if ($user->societe_id) $socid=$user->societe_id;
  74. $result = restrictedArea($user, 'contrat', $id);
  75. $staticcontrat=new Contrat($db);
  76. $staticcontratligne=new ContratLigne($db);
  77. if ($search_status == '') $search_status=1;
  78. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  79. $contextpage='contractlist';
  80. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  81. $hookmanager->initHooks(array($contextpage));
  82. $extrafields = new ExtraFields($db);
  83. // fetch optionals attributes and labels
  84. $extralabels = $extrafields->fetch_name_optionals_label('contrat');
  85. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  86. // List of fields to search into when doing a "search in all"
  87. $fieldstosearchall = array(
  88. 'c.ref'=>'Ref',
  89. 'c.ref_customer'=>'RefCustomer',
  90. 'c.ref_supplier'=>'RefSupplier',
  91. 's.nom'=>"ThirdParty",
  92. 'cd.description'=>'Description',
  93. 'c.note_public'=>'NotePublic',
  94. );
  95. if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
  96. $arrayfields=array(
  97. 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  98. 'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
  99. 'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
  100. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  101. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
  102. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
  103. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  104. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  105. 'sale_representative'=>array('label'=>$langs->trans("SalesRepresentative"), 'checked'=>1),
  106. 'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),
  107. 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  108. 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  109. 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  110. );
  111. // Extra fields
  112. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  113. {
  114. foreach($extrafields->attribute_label as $key => $val)
  115. {
  116. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  117. }
  118. }
  119. /*
  120. * Action
  121. */
  122. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  123. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  124. $parameters=array('socid'=>$socid);
  125. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  126. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  127. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  128. // Purge search criteria
  129. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  130. {
  131. $day='';
  132. $month='';
  133. $year='';
  134. $search_name="";
  135. $search_town='';
  136. $search_zip="";
  137. $search_state="";
  138. $search_type='';
  139. $search_country='';
  140. $search_contract="";
  141. $search_ref_supplier="";
  142. $search_user='';
  143. $search_sale='';
  144. $search_product_category='';
  145. $sall="";
  146. $search_status="";
  147. $toselect='';
  148. $search_array_options=array();
  149. }
  150. if (empty($reshook))
  151. {
  152. $objectclass='Contrat';
  153. $objectlabel='Contracts';
  154. $permtoread = $user->rights->contrat->lire;
  155. $permtodelete = $user->rights->contrat->supprimer;
  156. $uploaddir = $conf->contrat->dir_output;
  157. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  158. }
  159. /*
  160. * View
  161. */
  162. $now=dol_now();
  163. $form=new Form($db);
  164. $formother = new FormOther($db);
  165. $socstatic = new Societe($db);
  166. $contracttmp = new Contrat($db);
  167. llxHeader('', $langs->trans("Contracts"));
  168. $sql = 'SELECT';
  169. $sql.= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
  170. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  171. $sql.= " typent.code as typent_code,";
  172. $sql.= " state.code_departement as state_code, state.nom as state_name,";
  173. $sql.= ' SUM('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  174. $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')",1,0).') as nb_running,';
  175. $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')",1,0).') as nb_expired,';
  176. $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')",1,0).') as nb_late,';
  177. $sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed';
  178. // Add fields from extrafields
  179. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  180. // Add fields from hooks
  181. $parameters=array();
  182. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  183. $sql.=$hookmanager->resPrint;
  184. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  185. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  186. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  187. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  188. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  189. $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
  190. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
  191. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  192. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
  193. if ($search_user > 0)
  194. {
  195. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  196. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  197. }
  198. $sql.= " WHERE c.fk_soc = s.rowid ";
  199. $sql.= ' AND c.entity IN ('.getEntity('contract').')';
  200. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  201. if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid);
  202. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  203. if ($month > 0)
  204. {
  205. if ($year > 0 && empty($day))
  206. $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  207. else if ($year > 0 && ! empty($day))
  208. $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  209. else
  210. $sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
  211. }
  212. else if ($year > 0)
  213. {
  214. $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  215. }
  216. if ($search_name) $sql .= natural_search('s.nom', $search_name);
  217. if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
  218. if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
  219. if ($search_sale > 0)
  220. {
  221. $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  222. }
  223. if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  224. if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
  225. // Add where from extra fields
  226. foreach ($search_array_options as $key => $val)
  227. {
  228. $crit=$val;
  229. $tmpkey=preg_replace('/search_options_/','',$key);
  230. $typ=$extrafields->attribute_type[$tmpkey];
  231. $mode=0;
  232. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  233. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  234. {
  235. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  236. }
  237. }
  238. // Add where from hooks
  239. $parameters=array();
  240. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  241. $sql.=$hookmanager->resPrint;
  242. $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public,";
  243. $sql.= ' s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  244. $sql.= " typent.code,";
  245. $sql.= " state.code_departement, state.nom";
  246. // Add where from extra fields
  247. foreach ($extrafields->attribute_label as $key => $val)
  248. {
  249. $sql .= ', ef.'.$key;
  250. }
  251. // Add where from hooks
  252. $parameters=array();
  253. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  254. $sql.=$hookmanager->resPrint;
  255. $sql.= $db->order($sortfield,$sortorder);
  256. $totalnboflines=0;
  257. $result=$db->query($sql);
  258. if ($result)
  259. {
  260. $totalnboflines = $db->num_rows($result);
  261. }
  262. $nbtotalofrecords = '';
  263. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  264. {
  265. $result = $db->query($sql);
  266. $nbtotalofrecords = $db->num_rows($result);
  267. }
  268. $sql.= $db->plimit($limit + 1, $offset);
  269. $resql=$db->query($sql);
  270. if ($resql)
  271. {
  272. $num = $db->num_rows($resql);
  273. $i = 0;
  274. $arrayofselected=is_array($toselect)?$toselect:array();
  275. $param='';
  276. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  277. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  278. if ($sall != '') $param.='&sall='.$sall;
  279. if ($search_contract != '') $param.='&search_contract='.$search_contract;
  280. if ($search_name != '') $param.='&search_name='.$search_name;
  281. if ($search_ref_supplier != '') $param.='&search_ref_supplier='.$search_ref_supplier;
  282. if ($search_sale != '') $param.='&search_sale=' .$search_sale;
  283. if ($show_files) $param.='&show_files=' .$show_files;
  284. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  285. // Add $param from extra fields
  286. foreach ($search_array_options as $key => $val)
  287. {
  288. $crit=$val;
  289. $tmpkey=preg_replace('/search_options_/','',$key);
  290. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  291. }
  292. // List of mass actions available
  293. $arrayofmassactions = array(
  294. //'presend'=>$langs->trans("SendByMail"),
  295. //'builddoc'=>$langs->trans("PDFMerge"),
  296. );
  297. if ($user->rights->contrat->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  298. if ($massaction == 'presend') $arrayofmassactions=array();
  299. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  300. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  301. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  302. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  303. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  304. print '<input type="hidden" name="action" value="list">';
  305. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  306. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  307. print '<input type="hidden" name="page" value="'.$page.'">';
  308. print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'title_commercial.png', 0, '', '', $limit);
  309. if ($sall)
  310. {
  311. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  312. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  313. }
  314. $moreforfilter='';
  315. // If the user can view prospects other than his'
  316. if ($user->rights->societe->client->voir || $socid)
  317. {
  318. $langs->load("commercial");
  319. $moreforfilter.='<div class="divsearchfield">';
  320. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  321. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth300');
  322. $moreforfilter.='</div>';
  323. }
  324. // If the user can view other users
  325. if ($user->rights->user->user->lire)
  326. {
  327. $moreforfilter.='<div class="divsearchfield">';
  328. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  329. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  330. $moreforfilter.='</div>';
  331. }
  332. // If the user can view categories of products
  333. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  334. {
  335. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  336. $moreforfilter.='<div class="divsearchfield">';
  337. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  338. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  339. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  340. $moreforfilter.='</div>';
  341. }
  342. $parameters=array();
  343. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  344. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  345. else $moreforfilter = $hookmanager->resPrint;
  346. if (! empty($moreforfilter))
  347. {
  348. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  349. print $moreforfilter;
  350. print '</div>';
  351. }
  352. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  353. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  354. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  355. print '<div class="div-table-responsive">';
  356. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  357. print '<tr class="liste_titre_filter">';
  358. if (! empty($arrayfields['c.ref']['checked']))
  359. {
  360. print '<td class="liste_titre">';
  361. print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  362. print '</td>';
  363. }
  364. if (! empty($arrayfields['c.ref_customer']['checked']))
  365. {
  366. print '<td class="liste_titre">';
  367. print '<input type="text" class="flat" size="6" name="search_ref_customer value="'.dol_escape_htmltag($search_ref_customer).'">';
  368. print '</td>';
  369. }
  370. if (! empty($arrayfields['c.ref_supplier']['checked']))
  371. {
  372. print '<td class="liste_titre">';
  373. print '<input type="text" class="flat" size="6" name="search_ref_supplier value="'.dol_escape_htmltag($search_ref_supplier).'">';
  374. print '</td>';
  375. }
  376. if (! empty($arrayfields['s.nom']['checked']))
  377. {
  378. print '<td class="liste_titre">';
  379. print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
  380. print '</td>';
  381. }
  382. // Town
  383. if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  384. // Zip
  385. if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
  386. // State
  387. if (! empty($arrayfields['state.nom']['checked']))
  388. {
  389. print '<td class="liste_titre">';
  390. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  391. print '</td>';
  392. }
  393. // Country
  394. if (! empty($arrayfields['country.code_iso']['checked']))
  395. {
  396. print '<td class="liste_titre" align="center">';
  397. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  398. print '</td>';
  399. }
  400. // Company type
  401. if (! empty($arrayfields['typent.code']['checked']))
  402. {
  403. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  404. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
  405. print '</td>';
  406. }
  407. if (! empty($arrayfields['sale_representative']['checked']))
  408. {
  409. print '<td class="liste_titre"></td>';
  410. }
  411. if (! empty($arrayfields['c.date_contrat']['checked']))
  412. {
  413. // Date contract
  414. print '<td class="liste_titre center">';
  415. //print $langs->trans('Month').': ';
  416. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  417. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  418. //print '&nbsp;'.$langs->trans('Year').': ';
  419. $syear = $year;
  420. $formother->select_year($syear,'year',1, 20, 5);
  421. print '</td>';
  422. }
  423. // Extra fields
  424. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  425. {
  426. foreach($extrafields->attribute_label as $key => $val)
  427. {
  428. if (! empty($arrayfields["ef.".$key]['checked']))
  429. {
  430. $align=$extrafields->getAlignFlag($key);
  431. $typeofextrafield=$extrafields->attribute_type[$key];
  432. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  433. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  434. {
  435. $crit=$val;
  436. $tmpkey=preg_replace('/search_options_/','',$key);
  437. $searchclass='';
  438. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  439. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  440. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  441. }
  442. print '</td>';
  443. }
  444. }
  445. }
  446. // Fields from hook
  447. $parameters=array('arrayfields'=>$arrayfields);
  448. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  449. print $hookmanager->resPrint;
  450. // Date creation
  451. if (! empty($arrayfields['c.datec']['checked']))
  452. {
  453. print '<td class="liste_titre">';
  454. print '</td>';
  455. }
  456. // Date modification
  457. if (! empty($arrayfields['c.tms']['checked']))
  458. {
  459. print '<td class="liste_titre">';
  460. print '</td>';
  461. }
  462. // Status
  463. if (! empty($arrayfields['status']['checked']))
  464. {
  465. print '<td class="liste_titre" colspan="4" align="right"></td>';
  466. }
  467. print '<td class="liste_titre" align="middle">';
  468. $searchpicto=$form->showFilterButtons();
  469. print $searchpicto;
  470. print '</td>';
  471. print "</tr>\n";
  472. print '<tr class="liste_titre">';
  473. if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
  474. if (! empty($arrayfields['c.ref_customer']['checked'])) print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
  475. if (! empty($arrayfields['c.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
  476. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
  477. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  478. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  479. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  480. if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
  481. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  482. if (! empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
  483. if (! empty($arrayfields['c.date_contrat']['checked'])) print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
  484. // Extra fields
  485. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  486. {
  487. foreach($extrafields->attribute_label as $key => $val)
  488. {
  489. if (! empty($arrayfields["ef.".$key]['checked']))
  490. {
  491. $align=$extrafields->getAlignFlag($key);
  492. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  493. }
  494. }
  495. }
  496. // Hook fields
  497. $parameters=array('arrayfields'=>$arrayfields);
  498. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  499. print $hookmanager->resPrint;
  500. if (! empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  501. if (! empty($arrayfields['c.tms']['checked'])) print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  502. if (! empty($arrayfields['status']['checked']))
  503. {
  504. print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
  505. print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
  506. print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
  507. print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
  508. }
  509. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  510. print "</tr>\n";
  511. while ($i < min($num,$limit))
  512. {
  513. $obj = $db->fetch_object($resql);
  514. $contracttmp->ref=$obj->ref;
  515. $contracttmp->id=$obj->rowid;
  516. $contracttmp->ref_customer=$obj->ref_customer;
  517. $contracttmp->ref_supplier=$obj->ref_supplier;
  518. print '<tr class="oddeven">';
  519. if (! empty($arrayfields['c.ref']['checked']))
  520. {
  521. print '<td class="nowrap">';
  522. print $contracttmp->getNomUrl(1);
  523. if ($obj->nb_late) print img_warning($langs->trans("Late"));
  524. if (!empty($obj->note_private) || !empty($obj->note_public))
  525. {
  526. print ' <span class="note">';
  527. print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
  528. print '</span>';
  529. }
  530. print '</td>';
  531. }
  532. if (! empty($arrayfields['c.ref_customer']['checked']))
  533. {
  534. print '<td>'.$obj->ref_customer.'</td>';
  535. }
  536. if (! empty($arrayfields['c.ref_supplier']['checked']))
  537. {
  538. print '<td>'.$obj->ref_supplier.'</td>';
  539. }
  540. if (! empty($arrayfields['s.nom']['checked']))
  541. {
  542. print '<td><a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
  543. }
  544. // Town
  545. if (! empty($arrayfields['s.town']['checked']))
  546. {
  547. print '<td class="nocellnopadd">';
  548. print $obj->town;
  549. print '</td>';
  550. if (! $i) $totalarray['nbfield']++;
  551. }
  552. // Zip
  553. if (! empty($arrayfields['s.zip']['checked']))
  554. {
  555. print '<td class="nocellnopadd">';
  556. print $obj->zip;
  557. print '</td>';
  558. if (! $i) $totalarray['nbfield']++;
  559. }
  560. // State
  561. if (! empty($arrayfields['state.nom']['checked']))
  562. {
  563. print "<td>".$obj->state_name."</td>\n";
  564. if (! $i) $totalarray['nbfield']++;
  565. }
  566. // Country
  567. if (! empty($arrayfields['country.code_iso']['checked']))
  568. {
  569. print '<td align="center">';
  570. $tmparray=getCountry($obj->fk_pays,'all');
  571. print $tmparray['label'];
  572. print '</td>';
  573. if (! $i) $totalarray['nbfield']++;
  574. }
  575. // Type ent
  576. if (! empty($arrayfields['typent.code']['checked']))
  577. {
  578. print '<td align="center">';
  579. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  580. print $typenArray[$obj->typent_code];
  581. print '</td>';
  582. if (! $i) $totalarray['nbfield']++;
  583. }
  584. if (! empty($arrayfields['sale_representative']['checked']))
  585. {
  586. // Sales representatives
  587. print '<td>';
  588. if ($obj->socid > 0)
  589. {
  590. $result=$socstatic->fetch($obj->socid);
  591. $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
  592. if ($listsalesrepresentatives < 0) dol_print_error($db);
  593. $nbofsalesrepresentative=count($listsalesrepresentatives);
  594. if ($nbofsalesrepresentative > 3) // We print only number
  595. {
  596. print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
  597. print $nbofsalesrepresentative;
  598. print '</a>';
  599. }
  600. else if ($nbofsalesrepresentative > 0)
  601. {
  602. $userstatic=new User($db);
  603. $j=0;
  604. foreach($listsalesrepresentatives as $val)
  605. {
  606. $userstatic->id=$val['id'];
  607. $userstatic->lastname=$val['lastname'];
  608. $userstatic->firstname=$val['firstname'];
  609. print '<div class="float">'.$userstatic->getNomUrl(1);
  610. $j++;
  611. if ($j < $nbofsalesrepresentative) print ', ';
  612. print '</div>';
  613. }
  614. }
  615. //else print $langs->trans("NoSalesRepresentativeAffected");
  616. }
  617. else
  618. {
  619. print '&nbsp';
  620. }
  621. print '</td>';
  622. }
  623. // Date
  624. if (! empty($arrayfields['c.date_contrat']['checked']))
  625. {
  626. print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day').'</td>';
  627. }
  628. // Extra fields
  629. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  630. {
  631. foreach($extrafields->attribute_label as $key => $val)
  632. {
  633. if (! empty($arrayfields["ef.".$key]['checked']))
  634. {
  635. print '<td';
  636. $align=$extrafields->getAlignFlag($key);
  637. if ($align) print ' align="'.$align.'"';
  638. print '>';
  639. $tmpkey='options_'.$key;
  640. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  641. print '</td>';
  642. if (! $i) $totalarray['nbfield']++;
  643. }
  644. }
  645. }
  646. // Fields from hook
  647. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  648. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  649. print $hookmanager->resPrint;
  650. // Date creation
  651. if (! empty($arrayfields['c.datec']['checked']))
  652. {
  653. print '<td align="center" class="nowrap">';
  654. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  655. print '</td>';
  656. if (! $i) $totalarray['nbfield']++;
  657. }
  658. // Date modification
  659. if (! empty($arrayfields['c.tms']['checked']))
  660. {
  661. print '<td align="center" class="nowrap">';
  662. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  663. print '</td>';
  664. if (! $i) $totalarray['nbfield']++;
  665. }
  666. // Status
  667. if (! empty($arrayfields['status']['checked']))
  668. {
  669. print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
  670. print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
  671. print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
  672. print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
  673. }
  674. // Action column
  675. print '<td class="nowrap" align="center">';
  676. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  677. {
  678. $selected=0;
  679. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  680. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  681. }
  682. print '</td>';
  683. if (! $i) $totalarray['nbfield']++;
  684. print "</tr>\n";
  685. $i++;
  686. }
  687. $db->free($resql);
  688. print '</table>';
  689. print '</div>';
  690. print '</form>';
  691. }
  692. else
  693. {
  694. dol_print_error($db);
  695. }
  696. llxFooter();
  697. $db->close();