list.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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-2018 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/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
  37. $action=GETPOST('action','alpha');
  38. $massaction=GETPOST('massaction','alpha');
  39. $show_files=GETPOST('show_files','int');
  40. $confirm=GETPOST('confirm','alpha');
  41. $toselect = GETPOST('toselect', 'array');
  42. $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'contractlist'; // To manage different context of search
  43. $search_name=GETPOST('search_name');
  44. $search_email=GETPOST('search_email');
  45. $search_town=GETPOST('search_town','alpha');
  46. $search_zip=GETPOST('search_zip','alpha');
  47. $search_state=trim(GETPOST("search_state"));
  48. $search_country=GETPOST("search_country",'int');
  49. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  50. $search_contract=GETPOST('search_contract');
  51. $search_ref_customer=GETPOST('search_ref_customer','alpha');
  52. $search_ref_supplier=GETPOST('search_ref_supplier','alpha');
  53. $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
  54. $search_status=GETPOST('search_status');
  55. $socid=GETPOST('socid');
  56. $search_user=GETPOST('search_user','int');
  57. $search_sale=GETPOST('search_sale','int');
  58. $search_product_category=GETPOST('search_product_category','int');
  59. $search_dfmonth=GETPOST('search_dfmonth','int');
  60. $search_dfyear=GETPOST('search_dfyear','int');
  61. $search_op2df=GETPOST('search_op2df','alpha');
  62. $day=GETPOST("day","int");
  63. $year=GETPOST("year","int");
  64. $month=GETPOST("month","int");
  65. $optioncss = GETPOST('optioncss','alpha');
  66. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  67. $sortfield = GETPOST("sortfield",'alpha');
  68. $sortorder = GETPOST("sortorder",'alpha');
  69. $page = GETPOST("page",'int');
  70. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  71. $offset = $limit * $page;
  72. $pageprev = $page - 1;
  73. $pagenext = $page + 1;
  74. if (! $sortfield) $sortfield='c.ref';
  75. if (! $sortorder) $sortorder='DESC';
  76. // Security check
  77. $id=GETPOST('id','int');
  78. if ($user->societe_id) $socid=$user->societe_id;
  79. $result = restrictedArea($user, 'contrat', $id);
  80. $diroutputmassaction=$conf->contrat->dir_output . '/temp/massgeneration/'.$user->id;
  81. $staticcontrat=new Contrat($db);
  82. $staticcontratligne=new ContratLigne($db);
  83. if ($search_status == '') $search_status=1;
  84. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  85. $object = new Contrat($db);
  86. $hookmanager->initHooks(array('contractlist'));
  87. $extrafields = new ExtraFields($db);
  88. // fetch optionals attributes and labels
  89. $extralabels = $extrafields->fetch_name_optionals_label('contrat');
  90. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  91. // List of fields to search into when doing a "search in all"
  92. $fieldstosearchall = array(
  93. 'c.ref'=>'Ref',
  94. 'c.ref_customer'=>'RefCustomer',
  95. 'c.ref_supplier'=>'RefSupplier',
  96. 's.nom'=>"ThirdParty",
  97. 'c.note_public'=>'NotePublic',
  98. );
  99. if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
  100. $arrayfields=array(
  101. 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  102. 'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
  103. 'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
  104. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  105. 's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0),
  106. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
  107. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
  108. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  109. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  110. 'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),
  111. 'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),
  112. 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  113. 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  114. 'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
  115. 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  116. );
  117. // Extra fields
  118. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  119. {
  120. foreach($extrafields->attribute_label as $key => $val)
  121. {
  122. if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
  123. }
  124. }
  125. /*
  126. * Action
  127. */
  128. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  129. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  130. $parameters=array('socid'=>$socid);
  131. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  132. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  133. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  134. // Purge search criteria
  135. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
  136. {
  137. $day='';
  138. $month='';
  139. $year='';
  140. $search_dfmonth='';
  141. $search_dfyear='';
  142. $search_op2df='';
  143. $search_name="";
  144. $search_email="";
  145. $search_town='';
  146. $search_zip="";
  147. $search_state="";
  148. $search_type='';
  149. $search_country='';
  150. $search_contract="";
  151. $search_ref_customer="";
  152. $search_ref_supplier="";
  153. $search_user='';
  154. $search_sale='';
  155. $search_product_category='';
  156. $sall="";
  157. $search_status="";
  158. $toselect='';
  159. $search_array_options=array();
  160. }
  161. if (empty($reshook))
  162. {
  163. $objectclass='Contrat';
  164. $objectlabel='Contracts';
  165. $permtoread = $user->rights->contrat->lire;
  166. $permtodelete = $user->rights->contrat->supprimer;
  167. $uploaddir = $conf->contrat->dir_output;
  168. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  169. }
  170. /*
  171. * View
  172. */
  173. $now=dol_now();
  174. $form = new Form($db);
  175. $formfile = new FormFile($db);
  176. $formother = new FormOther($db);
  177. $socstatic = new Societe($db);
  178. $contracttmp = new Contrat($db);
  179. $sql = 'SELECT';
  180. $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,";
  181. $sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  182. $sql.= " typent.code as typent_code,";
  183. $sql.= " state.code_departement as state_code, state.nom as state_name,";
  184. $sql.= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
  185. $sql.= ' SUM('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  186. $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,';
  187. $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,';
  188. $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,';
  189. $sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed';
  190. // Add fields from extrafields
  191. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  192. // Add fields from hooks
  193. $parameters=array();
  194. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  195. $sql.=$hookmanager->resPrint;
  196. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  197. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  198. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  199. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  200. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  201. $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
  202. 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)";
  203. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  204. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
  205. if ($search_user > 0)
  206. {
  207. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  208. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  209. }
  210. $sql.= " WHERE c.fk_soc = s.rowid ";
  211. $sql.= ' AND c.entity IN ('.getEntity('contract').')';
  212. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  213. if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid);
  214. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  215. if ($month > 0)
  216. {
  217. if ($year > 0 && empty($day))
  218. $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))."'";
  219. else if ($year > 0 && ! empty($day))
  220. $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))."'";
  221. else
  222. $sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
  223. }
  224. else if ($year > 0)
  225. {
  226. $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))."'";
  227. }
  228. if ($search_name) $sql .= natural_search('s.nom', $search_name);
  229. if ($search_email) $sql .= natural_search('s.email', $search_email);
  230. if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
  231. if (!empty($search_ref_customer)) $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
  232. if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
  233. if ($search_sale > 0)
  234. {
  235. $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  236. }
  237. if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  238. 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;
  239. // Add where from extra fields
  240. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  241. // Add where from hooks
  242. $parameters=array();
  243. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  244. $sql.=$hookmanager->resPrint;
  245. $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,";
  246. $sql.= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  247. $sql.= " typent.code,";
  248. $sql.= " state.code_departement, state.nom";
  249. // Add fields from extrafields
  250. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
  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. if ($search_dfyear > 0 && $search_op2df)
  256. {
  257. if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
  258. elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
  259. else $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
  260. }
  261. $sql.= $db->order($sortfield,$sortorder);
  262. //print $sql;
  263. $totalnboflines=0;
  264. $result=$db->query($sql);
  265. if ($result)
  266. {
  267. $totalnboflines = $db->num_rows($result);
  268. }
  269. $nbtotalofrecords = '';
  270. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  271. {
  272. $result = $db->query($sql);
  273. $nbtotalofrecords = $db->num_rows($result);
  274. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  275. {
  276. $page = 0;
  277. $offset = 0;
  278. }
  279. }
  280. $sql.= $db->plimit($limit + 1, $offset);
  281. $resql=$db->query($sql);
  282. if (! $resql)
  283. {
  284. dol_print_error($db);
  285. exit;
  286. }
  287. $num = $db->num_rows($resql);
  288. // Direct jump if only one record found
  289. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
  290. {
  291. $obj = $db->fetch_object($resql);
  292. $id = $obj->rowid;
  293. header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
  294. exit;
  295. }
  296. // Output page
  297. // --------------------------------------------------------------------
  298. llxHeader('', $langs->trans("Contracts"));
  299. $i = 0;
  300. $arrayofselected=is_array($toselect)?$toselect:array();
  301. if ($socid > 0)
  302. {
  303. $soc = new Societe($db);
  304. $soc->fetch($socid);
  305. if (empty($search_name)) $search_name = $soc->name;
  306. }
  307. $param='';
  308. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  309. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  310. if ($sall != '') $param.='&sall='.urlencode($sall);
  311. if ($search_contract != '') $param.='&search_contract='.urlencode($search_contract);
  312. if ($search_name != '') $param.='&search_name='.urlencode($search_name);
  313. if ($search_email != '') $param.='&search_email='.urlencode($search_email);
  314. if ($search_ref_customer != '') $param.='&search_ref_customer='.urlencode($search_ref_customer);
  315. if ($search_ref_supplier != '') $param.='&search_ref_supplier='.urlencode($search_ref_supplier);
  316. if ($search_op2df != '') $param.='&search_op2df='.urlencode($search_op2df);
  317. if ($search_dfyear != '') $param.='&search_dfyear='.urlencode($search_dfyear);
  318. if ($search_dfmonth != '') $param.='&search_dfmonth='.urlencode($search_dfmonth);
  319. if ($search_sale != '') $param.='&search_sale=' .urlencode($search_sale);
  320. if ($search_user != '') $param.='&search_user=' .urlencode($search_user);
  321. if ($search_product_category != '') $param.='&search_product_category=' .urlencode($search_product_category);
  322. if ($show_files) $param.='&show_files=' .urlencode($show_files);
  323. if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
  324. // Add $param from extra fields
  325. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  326. // List of mass actions available
  327. $arrayofmassactions = array(
  328. 'presend'=>$langs->trans("SendByMail"),
  329. 'builddoc'=>$langs->trans("PDFMerge"),
  330. );
  331. if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
  332. if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
  333. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  334. $newcardbutton='';
  335. if ($user->rights->contrat->creer)
  336. {
  337. $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewContractSubscription').'</span>';
  338. $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
  339. $newcardbutton.= '</a>';
  340. }
  341. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  342. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  343. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  344. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  345. print '<input type="hidden" name="action" value="list">';
  346. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  347. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  348. print '<input type="hidden" name="page" value="'.$page.'">';
  349. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  350. print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'title_commercial.png', 0, $newcardbutton, '', $limit);
  351. $topicmail="SendContractRef";
  352. $modelmail="contract";
  353. $objecttmp=new Contrat($db);
  354. $trackid='con'.$object->id;
  355. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  356. if ($sall)
  357. {
  358. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  359. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
  360. }
  361. $moreforfilter='';
  362. // If the user can view prospects other than his'
  363. if ($user->rights->societe->client->voir || $socid)
  364. {
  365. $langs->load("commercial");
  366. $moreforfilter.='<div class="divsearchfield">';
  367. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  368. $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200');
  369. $moreforfilter.='</div>';
  370. }
  371. // If the user can view other users
  372. if ($user->rights->user->user->lire)
  373. {
  374. $moreforfilter.='<div class="divsearchfield">';
  375. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  376. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  377. $moreforfilter.='</div>';
  378. }
  379. // If the user can view categories of products
  380. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  381. {
  382. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  383. $moreforfilter.='<div class="divsearchfield">';
  384. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  385. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  386. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
  387. $moreforfilter.='</div>';
  388. }
  389. $parameters=array();
  390. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  391. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  392. else $moreforfilter = $hookmanager->resPrint;
  393. if (! empty($moreforfilter))
  394. {
  395. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  396. print $moreforfilter;
  397. print '</div>';
  398. }
  399. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  400. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  401. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  402. print '<div class="div-table-responsive">';
  403. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  404. print '<tr class="liste_titre_filter">';
  405. if (! empty($arrayfields['c.ref']['checked']))
  406. {
  407. print '<td class="liste_titre">';
  408. print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  409. print '</td>';
  410. }
  411. if (! empty($arrayfields['c.ref_customer']['checked']))
  412. {
  413. print '<td class="liste_titre">';
  414. print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
  415. print '</td>';
  416. }
  417. if (! empty($arrayfields['c.ref_supplier']['checked']))
  418. {
  419. print '<td class="liste_titre">';
  420. print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
  421. print '</td>';
  422. }
  423. if (! empty($arrayfields['s.nom']['checked']))
  424. {
  425. print '<td class="liste_titre">';
  426. print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
  427. print '</td>';
  428. }
  429. if (! empty($arrayfields['s.email']['checked']))
  430. {
  431. print '<td class="liste_titre">';
  432. print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
  433. print '</td>';
  434. }
  435. // Town
  436. 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>';
  437. // Zip
  438. 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>';
  439. // State
  440. if (! empty($arrayfields['state.nom']['checked']))
  441. {
  442. print '<td class="liste_titre">';
  443. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  444. print '</td>';
  445. }
  446. // Country
  447. if (! empty($arrayfields['country.code_iso']['checked']))
  448. {
  449. print '<td class="liste_titre" align="center">';
  450. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  451. print '</td>';
  452. }
  453. // Company type
  454. if (! empty($arrayfields['typent.code']['checked']))
  455. {
  456. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  457. 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));
  458. print '</td>';
  459. }
  460. if (! empty($arrayfields['sale_representative']['checked']))
  461. {
  462. print '<td class="liste_titre"></td>';
  463. }
  464. if (! empty($arrayfields['c.date_contrat']['checked']))
  465. {
  466. // Date contract
  467. print '<td class="liste_titre center nowraponall">';
  468. //print $langs->trans('Month').': ';
  469. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.$day.'">';
  470. print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.$month.'">';
  471. //print '&nbsp;'.$langs->trans('Year').': ';
  472. $syear = $year;
  473. print $formother->selectyear($syear,'year',1, 20, 5);
  474. print '</td>';
  475. }
  476. // Extra fields
  477. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  478. // Fields from hook
  479. $parameters=array('arrayfields'=>$arrayfields);
  480. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  481. print $hookmanager->resPrint;
  482. // Date creation
  483. if (! empty($arrayfields['c.datec']['checked']))
  484. {
  485. print '<td class="liste_titre">';
  486. print '</td>';
  487. }
  488. // Date modification
  489. if (! empty($arrayfields['c.tms']['checked']))
  490. {
  491. print '<td class="liste_titre">';
  492. print '</td>';
  493. }
  494. // First end date
  495. if (! empty($arrayfields['lower_planned_end_date']['checked']))
  496. {
  497. print '<td class="liste_titre nowraponall" align="center">';
  498. $arrayofoperators=array('0'=>'','='=>'=','<='=>'<=','>='=>'>=');
  499. print $form->selectarray('search_op2df',$arrayofoperators,$search_op2df,0);
  500. print '</br>';
  501. print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0, 'valignmiddle');
  502. print ' ';
  503. $formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '', 'valignmiddle');
  504. print '</td>';
  505. }
  506. // Status
  507. if (! empty($arrayfields['status']['checked']))
  508. {
  509. print '<td class="liste_titre" colspan="4" align="right"></td>';
  510. }
  511. print '<td class="liste_titre" align="middle">';
  512. $searchpicto=$form->showFilterButtons();
  513. print $searchpicto;
  514. print '</td>';
  515. print "</tr>\n";
  516. print '<tr class="liste_titre">';
  517. if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
  518. 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);
  519. 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);
  520. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
  521. if (! empty($arrayfields['s.email']['checked'])) print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email","","$param",'',$sortfield,$sortorder);
  522. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  523. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  524. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  525. 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);
  526. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  527. if (! empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
  528. 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);
  529. // Extra fields
  530. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  531. // Hook fields
  532. $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
  533. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  534. print $hookmanager->resPrint;
  535. if (! empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  536. 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);
  537. if (! empty($arrayfields['lower_planned_end_date']['checked'])) print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  538. if (! empty($arrayfields['status']['checked']))
  539. {
  540. print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
  541. print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
  542. print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
  543. print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
  544. }
  545. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  546. print "</tr>\n";
  547. while ($i < min($num,$limit))
  548. {
  549. $obj = $db->fetch_object($resql);
  550. $contracttmp->ref=$obj->ref;
  551. $contracttmp->id=$obj->rowid;
  552. $contracttmp->ref_customer=$obj->ref_customer;
  553. $contracttmp->ref_supplier=$obj->ref_supplier;
  554. if ($obj->socid > 0)
  555. {
  556. $result=$socstatic->fetch($obj->socid);
  557. }
  558. print '<tr class="oddeven">';
  559. if (! empty($arrayfields['c.ref']['checked']))
  560. {
  561. print '<td class="nowrap">';
  562. print $contracttmp->getNomUrl(1);
  563. if ($obj->nb_late) print img_warning($langs->trans("Late"));
  564. if (!empty($obj->note_private) || !empty($obj->note_public))
  565. {
  566. print ' <span class="note">';
  567. print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"),'note').'</a>';
  568. print '</span>';
  569. }
  570. $filename=dol_sanitizeFileName($obj->ref);
  571. $filedir=$conf->contrat->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  572. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  573. print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
  574. print '</td>';
  575. print '</td>';
  576. }
  577. if (! empty($arrayfields['c.ref_customer']['checked']))
  578. {
  579. print '<td>'.$obj->ref_customer.'</td>';
  580. }
  581. if (! empty($arrayfields['c.ref_supplier']['checked']))
  582. {
  583. print '<td>'.$obj->ref_supplier.'</td>';
  584. }
  585. if (! empty($arrayfields['s.nom']['checked']))
  586. {
  587. print '<td>';
  588. //print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';
  589. if ($obj->socid > 0)
  590. {
  591. print $socstatic->getNomUrl(1, '');
  592. }
  593. print '</td>';
  594. }
  595. if (! empty($arrayfields['s.email']['checked']))
  596. {
  597. print '<td>'.$obj->email.'</td>';
  598. }
  599. // Town
  600. if (! empty($arrayfields['s.town']['checked']))
  601. {
  602. print '<td class="nocellnopadd">';
  603. print $obj->town;
  604. print '</td>';
  605. if (! $i) $totalarray['nbfield']++;
  606. }
  607. // Zip
  608. if (! empty($arrayfields['s.zip']['checked']))
  609. {
  610. print '<td class="nocellnopadd">';
  611. print $obj->zip;
  612. print '</td>';
  613. if (! $i) $totalarray['nbfield']++;
  614. }
  615. // State
  616. if (! empty($arrayfields['state.nom']['checked']))
  617. {
  618. print "<td>".$obj->state_name."</td>\n";
  619. if (! $i) $totalarray['nbfield']++;
  620. }
  621. // Country
  622. if (! empty($arrayfields['country.code_iso']['checked']))
  623. {
  624. print '<td align="center">';
  625. $tmparray=getCountry($obj->fk_pays,'all');
  626. print $tmparray['label'];
  627. print '</td>';
  628. if (! $i) $totalarray['nbfield']++;
  629. }
  630. // Type ent
  631. if (! empty($arrayfields['typent.code']['checked']))
  632. {
  633. print '<td align="center">';
  634. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  635. print $typenArray[$obj->typent_code];
  636. print '</td>';
  637. if (! $i) $totalarray['nbfield']++;
  638. }
  639. if (! empty($arrayfields['sale_representative']['checked']))
  640. {
  641. // Sales representatives
  642. print '<td>';
  643. if ($obj->socid > 0)
  644. {
  645. $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
  646. if ($listsalesrepresentatives < 0) dol_print_error($db);
  647. $nbofsalesrepresentative=count($listsalesrepresentatives);
  648. if ($nbofsalesrepresentative > 3) // We print only number
  649. {
  650. print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
  651. print $nbofsalesrepresentative;
  652. print '</a>';
  653. }
  654. else if ($nbofsalesrepresentative > 0)
  655. {
  656. $userstatic=new User($db);
  657. $j=0;
  658. foreach($listsalesrepresentatives as $val)
  659. {
  660. $userstatic->id=$val['id'];
  661. $userstatic->lastname=$val['lastname'];
  662. $userstatic->firstname=$val['firstname'];
  663. $userstatic->email=$val['email'];
  664. $userstatic->statut=$val['statut'];
  665. $userstatic->entity=$val['entity'];
  666. $userstatic->photo=$val['photo'];
  667. //print '<div class="float">':
  668. print $userstatic->getNomUrl(-2);
  669. $j++;
  670. if ($j < $nbofsalesrepresentative) print ' ';
  671. //print '</div>';
  672. }
  673. }
  674. //else print $langs->trans("NoSalesRepresentativeAffected");
  675. }
  676. else
  677. {
  678. print '&nbsp';
  679. }
  680. print '</td>';
  681. }
  682. // Date
  683. if (! empty($arrayfields['c.date_contrat']['checked']))
  684. {
  685. print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzuser').'</td>';
  686. }
  687. // Extra fields
  688. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  689. // Fields from hook
  690. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  691. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  692. print $hookmanager->resPrint;
  693. // Date creation
  694. if (! empty($arrayfields['c.datec']['checked']))
  695. {
  696. print '<td align="center" class="nowrap">';
  697. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  698. print '</td>';
  699. if (! $i) $totalarray['nbfield']++;
  700. }
  701. // Date modification
  702. if (! empty($arrayfields['c.tms']['checked']))
  703. {
  704. print '<td align="center" class="nowrap">';
  705. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  706. print '</td>';
  707. if (! $i) $totalarray['nbfield']++;
  708. }
  709. // Date lower end date
  710. if (! empty($arrayfields['lower_planned_end_date']['checked']))
  711. {
  712. print '<td align="center" class="nowrapforall">';
  713. print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
  714. print '</td>';
  715. if (! $i) $totalarray['nbfield']++;
  716. }
  717. // Status
  718. if (! empty($arrayfields['status']['checked']))
  719. {
  720. print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
  721. print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
  722. print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
  723. print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
  724. }
  725. // Action column
  726. print '<td class="nowrap" align="center">';
  727. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  728. {
  729. $selected=0;
  730. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  731. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  732. }
  733. print '</td>';
  734. if (! $i) $totalarray['nbfield']++;
  735. print "</tr>\n";
  736. $i++;
  737. }
  738. $db->free($resql);
  739. print '</table>';
  740. print '</div>';
  741. print '</form>';
  742. $hidegeneratedfilelistifempty=1;
  743. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
  744. // Show list of available documents
  745. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  746. $urlsource.=str_replace('&amp;','&',$param);
  747. $filedir=$diroutputmassaction;
  748. $genallowed=$user->rights->contrat->lire;
  749. $delallowed=$user->rights->contrat->lire;
  750. print $formfile->showdocuments('massfilesarea_contract','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
  751. llxFooter();
  752. $db->close();