PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/product/stats/contrat.php

https://bitbucket.org/speedealing/speedealing
PHP | 199 lines | 132 code | 33 blank | 34 comment | 17 complexity | 861231a609fef926cb2ab464fd6f86d1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 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/product/stats/contrat.php
  21. * \ingroup product service contrat
  22. * \brief Page des stats des contrats pour un produit
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. $langs->load("contracts");
  29. $langs->load("products");
  30. $langs->load("companies");
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. // Security check
  34. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  35. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  36. if ($user->societe_id) $socid=$user->societe_id;
  37. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  38. $mesg = '';
  39. $sortfield = GETPOST("sortfield",'alpha');
  40. $sortorder = GETPOST("sortorder",'alpha');
  41. $page = GETPOST("page",'int');
  42. if ($page == -1) { $page = 0; }
  43. $offset = $conf->liste_limit * $page;
  44. $pageprev = $page - 1;
  45. $pagenext = $page + 1;
  46. if (! $sortorder) $sortorder="DESC";
  47. if (! $sortfield) $sortfield="c.date_contrat";
  48. /*
  49. * View
  50. */
  51. $staticcontrat=new Contrat($db);
  52. $staticcontratligne=new ContratLigne($db);
  53. $form = new Form($db);
  54. if ($id > 0 || ! empty($ref))
  55. {
  56. $product = new Product($db);
  57. $result = $product->fetch($id, $ref);
  58. llxHeader("","",$langs->trans("CardProduct".$product->type));
  59. if ($result > 0)
  60. {
  61. $head=product_prepare_head($product,$user);
  62. $titre=$langs->trans("CardProduct".$product->type);
  63. $picto=($product->type==1?'service':'product');
  64. dol_fiche_head($head, 'referers', $titre, 0, $picto);
  65. print '<table class="border" width="100%">';
  66. // Reference
  67. print '<tr>';
  68. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  69. print $form->showrefnav($product,'ref','',1,'ref');
  70. print '</td>';
  71. print '</tr>';
  72. // Libelle
  73. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  74. print '</tr>';
  75. // Status (to sell)
  76. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  77. print $product->getLibStatut(2,0);
  78. print '</td></tr>';
  79. // Status (to buy)
  80. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  81. print $product->getLibStatut(2,1);
  82. print '</td></tr>';
  83. show_stats_for_company($product,$socid);
  84. print "</table>";
  85. print '</div>';
  86. $now=dol_now();
  87. $sql = "SELECT";
  88. $sql.= ' sum('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
  89. $sql.= ' sum('.$db->ifsql("cd.statut=4 AND cd.date_fin_validite > '".$db->idate($now)."'",1,0).") as nb_running,";
  90. $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_late,';
  91. $sql.= ' sum('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
  92. $sql.= " c.rowid as rowid, c.date_contrat, c.statut as statut,";
  93. $sql.= " s.nom, s.rowid as socid, s.code_client";
  94. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  95. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  96. $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
  97. $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd";
  98. $sql.= " WHERE c.rowid = cd.fk_contrat";
  99. $sql.= " AND c.fk_soc = s.rowid";
  100. $sql.= " AND c.entity = ".$conf->entity;
  101. $sql.= " AND cd.fk_product =".$product->id;
  102. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  103. if ($socid) $sql.= " AND s.rowid = ".$socid;
  104. $sql.= " GROUP BY c.rowid, c.date_contrat, c.statut, s.nom, s.rowid, s.code_client";
  105. $sql.= " ORDER BY $sortfield $sortorder";
  106. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  107. $result = $db->query($sql);
  108. if ($result)
  109. {
  110. $num = $db->num_rows($result);
  111. print_barre_liste($langs->trans("Contrats"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  112. $i = 0;
  113. print "<table class=\"noborder\" width=\"100%\">";
  114. print '<tr class="liste_titre">';
  115. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  116. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  117. print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  118. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"c.date_contrat","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  119. //print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  120. print '<td class="liste_titre" width="16">'.$staticcontratligne->LibStatut(0,3).'</td>';
  121. print '<td class="liste_titre" width="16">'.$staticcontratligne->LibStatut(4,3).'</td>';
  122. print '<td class="liste_titre" width="16">'.$staticcontratligne->LibStatut(5,3).'</td>';
  123. print "</tr>\n";
  124. $contratstatic=new Contrat($db);
  125. if ($num > 0)
  126. {
  127. $var=True;
  128. while ($i < $num && $i < $conf->liste_limit)
  129. {
  130. $objp = $db->fetch_object($result);
  131. $var=!$var;
  132. print "<tr $bc[$var]>";
  133. print '<td><a href="'.DOL_URL_ROOT.'/contrat/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowContract"),"contract").' ';
  134. print $objp->rowid;
  135. print "</a></td>\n";
  136. print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->nom,44).'</a></td>';
  137. print "<td>".$objp->code_client."</td>\n";
  138. print "<td align=\"center\">";
  139. print dol_print_date($db->jdate($objp->date_contrat))."</td>";
  140. //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
  141. //print '<td align="right">';
  142. print '<td align="center">'.($objp->nb_initial>0?$objp->nb_initial:'').'</td>';
  143. print '<td align="center">'.($objp->nb_running+$objp->nb_late>0?$objp->nb_running+$objp->nb_late:'').'</td>';
  144. print '<td align="center">'.($objp->nb_closed>0?$objp->nb_closed:'').'</td>';
  145. //$contratstatic->LibStatut($objp->statut,5).'</td>';
  146. print "</tr>\n";
  147. $i++;
  148. }
  149. }
  150. }
  151. else
  152. {
  153. dol_print_error($db);
  154. }
  155. print "</table>";
  156. print '<br>';
  157. $db->free($result);
  158. }
  159. }
  160. else
  161. {
  162. dol_print_error();
  163. }
  164. llxFooter();
  165. $db->close();
  166. ?>