propal.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 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/product/stats/propal.php
  21. * \ingroup product service propal
  22. * \brief Page des stats des propals 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.'/comm/propal/class/propal.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. $langs->load("products");
  29. $langs->load("companies");
  30. $id = GETPOST('id', 'int');
  31. $ref = GETPOST('ref', 'alpha');
  32. // Security check
  33. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  34. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  35. if ($user->societe_id) $socid=$user->societe_id;
  36. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  37. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  38. $hookmanager->initHooks(array('productstatspropal'));
  39. $mesg = '';
  40. $sortfield = GETPOST("sortfield",'alpha');
  41. $sortorder = GETPOST("sortorder",'alpha');
  42. $page = GETPOST("page",'int');
  43. if ($page == -1) { $page = 0; }
  44. $offset = $conf->liste_limit * $page;
  45. $pageprev = $page - 1;
  46. $pagenext = $page + 1;
  47. if (! $sortorder) $sortorder="DESC";
  48. if (! $sortfield) $sortfield="p.datep";
  49. /*
  50. * View
  51. */
  52. $form = new Form($db);
  53. if ($id > 0 || ! empty($ref))
  54. {
  55. $product = new Product($db);
  56. $result = $product->fetch($id, $ref);
  57. $parameters=array('id'=>$id);
  58. $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks
  59. llxHeader("","",$langs->trans("CardProduct".$product->type));
  60. if ($result > 0)
  61. {
  62. $head=product_prepare_head($product, $user);
  63. $titre=$langs->trans("CardProduct".$product->type);
  64. $picto=($product->type==1?'service':'product');
  65. dol_fiche_head($head, 'referers', $titre,0,$picto);
  66. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook
  67. print '<table class="border" width="100%">';
  68. // Reference
  69. print '<tr>';
  70. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  71. print $form->showrefnav($product,'ref','',1,'ref');
  72. print '</td>';
  73. print '</tr>';
  74. // Libelle
  75. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  76. print '</tr>';
  77. // Status (to sell)
  78. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  79. print $product->getLibStatut(2,0);
  80. print '</td></tr>';
  81. // Status (to buy)
  82. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  83. print $product->getLibStatut(2,1);
  84. print '</td></tr>';
  85. show_stats_for_company($product,$socid);
  86. print "</table>";
  87. print '</div>';
  88. $sql = "SELECT DISTINCT s.nom, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
  89. $sql.= "p.datep, p.fk_statut as statut";
  90. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  91. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  92. $sql.= ",".MAIN_DB_PREFIX."propal as p";
  93. $sql.= ", ".MAIN_DB_PREFIX."propaldet as d";
  94. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  95. $sql.= " WHERE p.fk_soc = s.rowid";
  96. $sql.= " AND p.entity = ".$conf->entity;
  97. $sql.= " AND d.fk_propal = p.rowid";
  98. $sql.= " AND d.fk_product =".$product->id;
  99. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  100. if ($socid) $sql.= " AND p.fk_soc = ".$socid;
  101. $sql.= " ORDER BY $sortfield $sortorder ";
  102. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  103. $result = $db->query($sql);
  104. if ($result)
  105. {
  106. $num = $db->num_rows($result);
  107. print_barre_liste($langs->trans("Proposals"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  108. $i = 0;
  109. print '<table class="noborder" width="100%">';
  110. print '<tr class="liste_titre">';
  111. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  112. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  113. print_liste_field_titre($langs->trans("DatePropal"),$_SERVER["PHP_SELF"],"p.datep","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  114. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"p.total","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  115. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  116. print "</tr>\n";
  117. $propalstatic=new Propal($db);
  118. if ($num > 0)
  119. {
  120. $var=True;
  121. while ($i < $num && $i < $conf->liste_limit)
  122. {
  123. $objp = $db->fetch_object($result);
  124. $var=!$var;
  125. print '<tr '.$bc[$var].'>';
  126. print '<td><a href="'.DOL_URL_ROOT.'/comm/propal.php?id='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' ';
  127. print $objp->ref;
  128. print '</a></td>'."\n";
  129. 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>';
  130. print '<td align="center">';
  131. print dol_print_date($db->jdate($objp->datep))."</td>";
  132. print '<td align="right">'.price($objp->amount).'</td>'."\n";
  133. print '<td align="right">'.$propalstatic->LibStatut($objp->statut,5).'</td>';
  134. print '</tr>'."\n";
  135. $i++;
  136. }
  137. }
  138. }
  139. else
  140. {
  141. dol_print_error($db);
  142. }
  143. print "</table>";
  144. print '<br>';
  145. $db->free($result);
  146. }
  147. }
  148. else
  149. {
  150. dol_print_error();
  151. }
  152. llxFooter();
  153. $db->close();