PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stats/propal.php

https://bitbucket.org/speedealing/speedealing
PHP | 181 lines | 119 code | 32 blank | 30 comment | 19 complexity | e84b91a949032ea87c05dc0ebc1a5934 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. $mesg = '';
  38. $sortfield = GETPOST("sortfield",'alpha');
  39. $sortorder = GETPOST("sortorder",'alpha');
  40. $page = GETPOST("page",'int');
  41. if ($page == -1) { $page = 0; }
  42. $offset = $conf->liste_limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (! $sortorder) $sortorder="DESC";
  46. if (! $sortfield) $sortfield="p.datep";
  47. /*
  48. * View
  49. */
  50. $form = new Form($db);
  51. if ($id > 0 || ! empty($ref))
  52. {
  53. $product = new Product($db);
  54. $result = $product->fetch($id, $ref);
  55. llxHeader("","",$langs->trans("CardProduct".$product->type));
  56. if ($result > 0)
  57. {
  58. $head=product_prepare_head($product, $user);
  59. $titre=$langs->trans("CardProduct".$product->type);
  60. $picto=($product->type==1?'service':'product');
  61. dol_fiche_head($head, 'referers', $titre,0,$picto);
  62. print '<table class="border" width="100%">';
  63. // Reference
  64. print '<tr>';
  65. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  66. print $form->showrefnav($product,'ref','',1,'ref');
  67. print '</td>';
  68. print '</tr>';
  69. // Libelle
  70. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  71. print '</tr>';
  72. // Status (to sell)
  73. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  74. print $product->getLibStatut(2,0);
  75. print '</td></tr>';
  76. // Status (to buy)
  77. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  78. print $product->getLibStatut(2,1);
  79. print '</td></tr>';
  80. show_stats_for_company($product,$socid);
  81. print "</table>";
  82. print '</div>';
  83. $sql = "SELECT DISTINCT s.nom, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,";
  84. $sql.= "p.datep, p.fk_statut as statut";
  85. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  86. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  87. $sql.= ",".MAIN_DB_PREFIX."propal as p";
  88. $sql.= ", ".MAIN_DB_PREFIX."propaldet as d";
  89. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  90. $sql.= " WHERE p.fk_soc = s.rowid";
  91. $sql.= " AND p.entity = ".$conf->entity;
  92. $sql.= " AND d.fk_propal = p.rowid";
  93. $sql.= " AND d.fk_product =".$product->id;
  94. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  95. if ($socid) $sql.= " AND p.fk_soc = ".$socid;
  96. $sql.= " ORDER BY $sortfield $sortorder ";
  97. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  98. $result = $db->query($sql);
  99. if ($result)
  100. {
  101. $num = $db->num_rows($result);
  102. print_barre_liste($langs->trans("Proposals"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  103. $i = 0;
  104. print '<table class="noborder" width="100%">';
  105. print '<tr class="liste_titre">';
  106. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  107. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  108. print_liste_field_titre($langs->trans("DatePropal"),$_SERVER["PHP_SELF"],"p.datep","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  109. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"p.total","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  110. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  111. print "</tr>\n";
  112. $propalstatic=new Propal($db);
  113. if ($num > 0)
  114. {
  115. $var=True;
  116. while ($i < $num && $i < $conf->liste_limit)
  117. {
  118. $objp = $db->fetch_object($result);
  119. $var=!$var;
  120. print '<tr '.$bc[$var].'>';
  121. print '<td><a href="'.DOL_URL_ROOT.'/comm/propal.php?id='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' ';
  122. print $objp->ref;
  123. print '</a></td>'."\n";
  124. 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>';
  125. print '<td align="center">';
  126. print dol_print_date($db->jdate($objp->datep))."</td>";
  127. print '<td align="right">'.price($objp->amount).'</td>'."\n";
  128. print '<td align="right">'.$propalstatic->LibStatut($objp->statut,5).'</td>';
  129. print '</tr>'."\n";
  130. $i++;
  131. }
  132. }
  133. }
  134. else
  135. {
  136. dol_print_error($db);
  137. }
  138. print "</table>";
  139. print '<br>';
  140. $db->free($result);
  141. }
  142. }
  143. else
  144. {
  145. dol_print_error();
  146. }
  147. llxFooter();
  148. $db->close();
  149. ?>