PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stats/commande_fournisseur.php

https://bitbucket.org/speedealing/speedealing
PHP | 181 lines | 121 code | 30 blank | 30 comment | 19 complexity | c32701321843dfdd65f6f65a07445d38 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_fournisseur.php
  21. * \ingroup product service commande
  22. * \brief Page des stats des commandes fournisseurs 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. $head=product_prepare_head($product, $user);
  60. $titre=$langs->trans("CardProduct".$product->type);
  61. $picto=($product->type==1?'service':'product');
  62. dol_fiche_head($head, 'referers', $titre, 0, $picto);
  63. print '<table class="border" width="100%">';
  64. // Reference
  65. print '<tr>';
  66. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  67. print $form->showrefnav($product,'ref','',1,'ref');
  68. print '</td></tr>';
  69. // Libelle
  70. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td></tr>';
  71. // Status (to sell)
  72. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  73. print $product->getLibStatut(2,0);
  74. print '</td></tr>';
  75. // Status (to buy)
  76. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  77. print $product->getLibStatut(2,1);
  78. print '</td></tr>';
  79. show_stats_for_company($product,$socid);
  80. print "</table>";
  81. print '</div>';
  82. $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,";
  83. $sql.= " c.rowid, c.total_ht as total_ht, c.ref,";
  84. $sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid";
  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."commande_fournisseur as c";
  88. $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as d";
  89. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  90. $sql.= " WHERE c.fk_soc = s.rowid";
  91. $sql.= " AND c.entity = ".$conf->entity;
  92. $sql.= " AND d.fk_commande = c.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 c.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("SuppliersOrders"),$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"],"c.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("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  109. print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  110. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  111. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  112. print "</tr>\n";
  113. $commandestatic=new Commande($db);
  114. if ($num > 0)
  115. {
  116. $var=True;
  117. while ($i < $num && $i < $conf->liste_limit)
  118. {
  119. $objp = $db->fetch_object($result);
  120. $var=!$var;
  121. print "<tr $bc[$var]>";
  122. print '<td><a href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$objp->commandeid.'">'.img_object($langs->trans("ShowOrder"),"order").' ';
  123. print $objp->ref;
  124. print "</a></td>\n";
  125. print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->nom,44).'</a></td>';
  126. print "<td>".$objp->code_client."</td>\n";
  127. print "<td align=\"center\">";
  128. print dol_print_date($db->jdate($objp->date_commande))."</td>";
  129. print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
  130. print '<td align="right">'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'</td>';
  131. print "</tr>\n";
  132. $i++;
  133. }
  134. }
  135. }
  136. else
  137. {
  138. dol_print_error($db);
  139. }
  140. print "</table>";
  141. print '<br>';
  142. $db->free($result);
  143. }
  144. }
  145. else
  146. {
  147. dol_print_error();
  148. }
  149. llxFooter();
  150. $db->close();
  151. ?>