PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stats/commande.php

https://bitbucket.org/speedealing/speedealing
PHP | 188 lines | 122 code | 33 blank | 33 comment | 19 complexity | 426558f68c9a1ae0a53ab6d9ae81c1c3 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-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/commande.php
  21. * \ingroup product service commande
  22. * \brief Page des stats des commandes clients 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.'/commande/class/commande.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. $langs->load("orders");
  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_commande";
  48. /*
  49. * View
  50. */
  51. $form = new Form($db);
  52. if ($id > 0 || ! empty($ref))
  53. {
  54. $product = new Product($db);
  55. $result = $product->fetch($id, $ref);
  56. llxHeader("","",$langs->trans("CardProduct".$product->type));
  57. if ($result > 0)
  58. {
  59. /*
  60. * En mode visu
  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. print '<table class="border" width="100%">';
  67. // Reference
  68. print '<tr>';
  69. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  70. print $form->showrefnav($product,'ref','',1,'ref');
  71. print '</td>';
  72. print '</tr>';
  73. // Libelle
  74. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  75. print '</tr>';
  76. // Status (to sell)
  77. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  78. print $product->getLibStatut(2,0);
  79. print '</td></tr>';
  80. // Status (to buy)
  81. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  82. print $product->getLibStatut(2,1);
  83. print '</td></tr>';
  84. show_stats_for_company($product,$socid);
  85. print "</table>";
  86. print '</div>';
  87. $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,";
  88. $sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid";
  89. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  90. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  91. $sql.= ", ".MAIN_DB_PREFIX."commande as c";
  92. $sql.= ", ".MAIN_DB_PREFIX."commandedet as d";
  93. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  94. $sql.= " WHERE c.fk_soc = s.rowid";
  95. $sql.= " AND c.entity = ".$conf->entity;
  96. $sql.= " AND d.fk_commande = c.rowid";
  97. $sql.= " AND d.fk_product =".$product->id;
  98. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  99. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  100. $sql.= " ORDER BY $sortfield $sortorder ";
  101. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  102. $result = $db->query($sql);
  103. if ($result)
  104. {
  105. $num = $db->num_rows($result);
  106. print_barre_liste($langs->trans("CustomersOrders"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  107. $i = 0;
  108. print "<table class=\"noborder\" width=\"100%\">";
  109. print '<tr class="liste_titre">';
  110. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  111. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  112. print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  113. print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  114. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  115. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  116. print "</tr>\n";
  117. $commandestatic=new Commande($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.'/commande/fiche.php?id='.$objp->commandeid.'">'.img_object($langs->trans("ShowOrder"),"order").' ';
  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>".$objp->code_client."</td>\n";
  131. print "<td align=\"center\">";
  132. print dol_print_date($db->jdate($objp->date_commande))."</td>";
  133. print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
  134. print '<td align="right">'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'</td>';
  135. print "</tr>\n";
  136. $i++;
  137. }
  138. }
  139. }
  140. else
  141. {
  142. dol_print_error($db);
  143. }
  144. print "</table>";
  145. print '<br>';
  146. $db->free($result);
  147. }
  148. }
  149. else
  150. {
  151. dol_print_error();
  152. }
  153. llxFooter();
  154. $db->close();
  155. ?>