PageRenderTime 76ms CodeModel.GetById 21ms RepoModel.GetById 6ms app.codeStats 0ms

/htdocs/contrat/services.php

https://bitbucket.org/speedealing/speedealing
PHP | 277 lines | 209 code | 32 blank | 36 comment | 98 complexity | f311abb468ecf4373eb1cb473e379469 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contrat/services.php
  21. * \ingroup contrat
  22. * \brief Page to list services in contracts
  23. */
  24. require ("../main.inc.php");
  25. require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  26. require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  27. require_once (DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  28. $langs->load("products");
  29. $langs->load("contracts");
  30. $langs->load("companies");
  31. $mode = GETPOST("mode");
  32. $sortfield = GETPOST("sortfield",'alpha');
  33. $sortorder = GETPOST("sortorder",'alpha');
  34. $page = GETPOST("page",'int');
  35. if ($page == -1) { $page = 0 ; }
  36. $limit = $conf->liste_limit;
  37. $offset = $limit * $page ;
  38. if (! $sortfield) $sortfield="c.rowid";
  39. if (! $sortorder) $sortorder="ASC";
  40. $filter=GETPOST("filter");
  41. $search_nom=GETPOST("search_nom");
  42. $search_contract=GETPOST("search_contract");
  43. $search_service=GETPOST("search_service");
  44. $statut=GETPOST('statut')?GETPOST('statut'):1;
  45. $socid=GETPOST('socid','int');
  46. $op1month=GETPOST('op1month');
  47. $op1day=GETPOST('op1day');
  48. $op1year=GETPOST('op1year');
  49. $filter_op1=GETPOST('filter_op1');
  50. $op2month=GETPOST('op2month');
  51. $op2day=GETPOST('op2day');
  52. $op2year=GETPOST('op2year');
  53. $filter_op2=GETPOST('filter_op2');
  54. // Security check
  55. $contratid = GETPOST('id','int');
  56. if (! empty($user->societe_id)) $socid=$user->societe_id;
  57. $result = restrictedArea($user, 'contrat',$contratid);
  58. $staticcontrat=new Contrat($db);
  59. $staticcontratligne=new ContratLigne($db);
  60. $companystatic=new Societe($db);
  61. /*
  62. * View
  63. */
  64. $now=dol_now();
  65. $form=new Form($db);
  66. llxHeader();
  67. $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut,";
  68. $sql.= " s.rowid as socid, s.nom,";
  69. $sql.= " cd.rowid, cd.description, cd.statut,";
  70. $sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype,";
  71. if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
  72. $sql.= " cd.date_ouverture_prevue,";
  73. $sql.= " cd.date_ouverture,";
  74. $sql.= " cd.date_fin_validite,";
  75. $sql.= " cd.date_cloture";
  76. $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c,";
  77. $sql.= " ".MAIN_DB_PREFIX."societe as s,";
  78. if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  79. $sql.= " ".MAIN_DB_PREFIX."contratdet as cd";
  80. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  81. $sql.= " WHERE c.entity = ".$conf->entity;
  82. $sql.= " AND c.rowid = cd.fk_contrat";
  83. $sql.= " AND c.fk_soc = s.rowid";
  84. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  85. if ($mode == "0") $sql.= " AND cd.statut = 0";
  86. if ($mode == "4") $sql.= " AND cd.statut = 4";
  87. if ($mode == "5") $sql.= " AND cd.statut = 5";
  88. if ($filter == "expired") $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  89. if ($search_nom) $sql.= " AND s.nom LIKE '%".$db->escape($search_nom)."%'";
  90. if ($search_contract) $sql.= " AND c.rowid = '".$db->escape($search_contract)."'";
  91. if ($search_service) $sql.= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')";
  92. if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
  93. $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year);
  94. $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year);
  95. if (! empty($filter_op1) && $filter_op1 != -1 && $filter_date1 != '') $sql.= " AND date_ouverture_prevue ".$filter_op1." ".$db->idate($filter_date1);
  96. if (! empty($filter_op2) && $filter_op2 != -1 && $filter_date2 != '') $sql.= " AND date_fin_validite ".$filter_op2." ".$db->idate($filter_date2);
  97. $sql .= $db->order($sortfield,$sortorder);
  98. $sql .= $db->plimit($limit + 1, $offset);
  99. //print $sql;
  100. dol_syslog("contrat/services.php sql=".$sql);
  101. $resql=$db->query($sql);
  102. if ($resql)
  103. {
  104. $num = $db->num_rows($resql);
  105. $i = 0;
  106. $param='';
  107. if ($search_contract) $param.='&amp;search_contract='.urlencode($search_contract);
  108. if ($search_nom) $param.='&amp;search_nom='.urlencode($search_nom);
  109. if ($search_service) $param.='&amp;search_service='.urlencode($search_service);
  110. if ($mode) $param.='&amp;mode='.$mode;
  111. if ($filter) $param.='&amp;filter='.$filter;
  112. if (! empty($filter_op1) && $filter_op1 != -1) $param.='&amp;filter_op1='.urlencode($filter_op1);
  113. if (! empty($filter_op2) && $filter_op2 != -1) $param.='&amp;filter_op2='.urlencode($filter_op2);
  114. if ($filter_date1 != '') $param.='&amp;op1day='.$op1day.'&amp;op1month='.$op1month.'&amp;op1year='.$op1year;
  115. if ($filter_date2 != '') $param.='&amp;op2day='.$op2day.'&amp;op2month='.$op2month.'&amp;op2year='.$op2year;
  116. $title=$langs->trans("ListOfServices");
  117. if ($mode == "0") $title=$langs->trans("ListOfInactiveServices"); // Must use == "0"
  118. if ($mode == "4" && $filter != "expired") $title=$langs->trans("ListOfRunningServices");
  119. if ($mode == "4" && $filter == "expired") $title=$langs->trans("ListOfExpiredServices");
  120. if ($mode == "5") $title=$langs->trans("ListOfClosedServices");
  121. print_barre_liste($title, $page, "services.php", $param, $sortfield, $sortorder,'',$num);
  122. print '<table class="liste" width="100%">';
  123. print '<tr class="liste_titre">';
  124. print_liste_field_titre($langs->trans("Contract"),"services.php", "c.rowid",$param,"","",$sortfield,$sortorder);
  125. print_liste_field_titre($langs->trans("Service"),"services.php", "p.description",$param,"","",$sortfield,$sortorder);
  126. print_liste_field_titre($langs->trans("Company"),"services.php", "s.nom",$param,"","",$sortfield,$sortorder);
  127. // Date debut
  128. if ($mode == "0") print_liste_field_titre($langs->trans("DateStartPlannedShort"),"services.php", "cd.date_ouverture_prevue",$param,'',' align="center"',$sortfield,$sortorder);
  129. if ($mode == "" || $mode > 0) print_liste_field_titre($langs->trans("DateStartRealShort"),"services.php", "cd.date_ouverture",$param,'',' align="center"',$sortfield,$sortorder);
  130. // Date fin
  131. if ($mode == "" || $mode < 5) print_liste_field_titre($langs->trans("DateEndPlannedShort"),"services.php", "cd.date_fin_validite",$param,'',' align="center"',$sortfield,$sortorder);
  132. else print_liste_field_titre($langs->trans("DateEndRealShort"),"services.php", "cd.date_cloture",$param,'',' align="center"',$sortfield,$sortorder);
  133. print_liste_field_titre($langs->trans("Status"),"services.php", "cd.statut,c.statut",$param,"","align=\"right\"",$sortfield,$sortorder);
  134. print "</tr>\n";
  135. print '<form method="POST" action="services.php">';
  136. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  137. print '<tr class="liste_titre">';
  138. print '<td class="liste_titre">';
  139. print '<input type="hidden" name="filter" value="'.$filter.'">';
  140. print '<input type="hidden" name="mode" value="'.$mode.'">';
  141. print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  142. print '</td>';
  143. // Service label
  144. print '<td class="liste_titre">';
  145. print '<input type="text" class="flat" size="18" name="search_service" value="'.dol_escape_htmltag($search_service).'">';
  146. print '</td>';
  147. // Third party
  148. print '<td class="liste_titre">';
  149. print '<input type="text" class="flat" size="24" name="search_nom" value="'.dol_escape_htmltag($search_nom).'">';
  150. print '</td>';
  151. print '<td class="liste_titre" align="center">';
  152. $arrayofoperators=array('<'=>'<','>'=>'>');
  153. print $form->selectarray('filter_op1',$arrayofoperators,$filter_op1,1);
  154. print ' ';
  155. $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year);
  156. print $form->select_date($filter_date1,'op1',0,0,1);
  157. print '</td>';
  158. print '<td class="liste_titre" align="center">';
  159. $arrayofoperators=array('<'=>'<','>'=>'>');
  160. print $form->selectarray('filter_op2',$arrayofoperators,$filter_op2,1);
  161. print ' ';
  162. $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year);
  163. print $form->select_date($filter_date2,'op2',0,0,1);
  164. print '</td>';
  165. print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  166. print "</td>";
  167. print "</tr>\n";
  168. print '</form>';
  169. $contractstatic=new Contrat($db);
  170. $productstatic=new Product($db);
  171. $var=True;
  172. while ($i < min($num,$limit))
  173. {
  174. $obj = $db->fetch_object($resql);
  175. $var=!$var;
  176. print "<tr ".$bc[$var].">";
  177. print '<td>';
  178. $contractstatic->id=$obj->cid;
  179. $contractstatic->ref=$obj->ref?$obj->ref:$obj->cid;
  180. print $contractstatic->getNomUrl(1,16);
  181. print '</td>';
  182. // Service
  183. print '<td>';
  184. if ($obj->pid)
  185. {
  186. $productstatic->id=$obj->pid;
  187. $productstatic->type=$obj->ptype;
  188. $productstatic->ref=$obj->pref;
  189. print $productstatic->getNomUrl(1,'',20);
  190. print $obj->label?' - '.dol_trunc($obj->label,16):'';
  191. if (! empty($obj->description) && ! empty($conf->global->PRODUIT_DESC_IN_LIST)) print '<br>'.dol_nl2br($obj->description);
  192. }
  193. else
  194. {
  195. if ($obj->type == 0) print img_object($obj->description,'product').dol_trunc($obj->description,20);
  196. if ($obj->type == 1) print img_object($obj->description,'service').dol_trunc($obj->description,20);
  197. }
  198. print '</td>';
  199. // Third party
  200. print '<td>';
  201. $companystatic->id=$obj->socid;
  202. $companystatic->nom=$obj->nom;
  203. $companystatic->client=1;
  204. print $companystatic->getNomUrl(1,'customer',28);
  205. print '</td>';
  206. // Start date
  207. if ($mode == "0") {
  208. print '<td align="center">';
  209. print ($obj->date_ouverture_prevue?dol_print_date($db->jdate($obj->date_ouverture_prevue)):'&nbsp;');
  210. if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)))
  211. print img_picto($langs->trans("Late"),"warning");
  212. else print '&nbsp;&nbsp;&nbsp;&nbsp;';
  213. print '</td>';
  214. }
  215. if ($mode == "" || $mode > 0) print '<td align="center">'.($obj->date_ouverture?dol_print_date($db->jdate($obj->date_ouverture)):'&nbsp;').'</td>';
  216. // Date fin
  217. if ($mode == "" || $mode < 5) print '<td align="center">'.($obj->date_fin_validite?dol_print_date($db->jdate($obj->date_fin_validite)):'&nbsp;');
  218. else print '<td align="center">'.dol_print_date($db->jdate($obj->date_cloture));
  219. // Icone warning
  220. if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) print img_warning($langs->trans("Late"));
  221. else print '&nbsp;&nbsp;&nbsp;&nbsp;';
  222. print '</td>';
  223. print '<td align="right" nowrap="nowrap">';
  224. if ($obj->cstatut == 0) // If contract is draft, we say line is also draft
  225. {
  226. print $contractstatic->LibStatut(0,5,($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now));
  227. }
  228. else
  229. {
  230. print $staticcontratligne->LibStatut($obj->statut,5,($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now)?1:0);
  231. }
  232. print '</td>';
  233. print "</tr>\n";
  234. $i++;
  235. }
  236. $db->free($resql);
  237. print "</table>";
  238. }
  239. else
  240. {
  241. dol_print_error($db);
  242. }
  243. $db->close();
  244. llxFooter();
  245. ?>