PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stats/facture_fournisseur.php

https://bitbucket.org/speedealing/speedealing
PHP | 192 lines | 126 code | 33 blank | 33 comment | 19 complexity | bd85d984b4b9bfc01bec4696b88a2334 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/facture_fournisseur.php
  21. * \ingroup product service facture
  22. * \brief Page des stats des factures 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.'/fourn/class/fournisseur.facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. $langs->load("companies");
  29. $langs->load("bills");
  30. $langs->load("products");
  31. $langs->load("companies");
  32. $id = GETPOST('id', 'int');
  33. $ref = GETPOST('ref', 'alpha');
  34. // Security check
  35. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  36. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  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="f.datef";
  49. /*
  50. * View
  51. */
  52. $supplierinvoicestatic=new FactureFournisseur($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. /*
  62. * En mode visu
  63. */
  64. $head=product_prepare_head($product, $user);
  65. $titre=$langs->trans("CardProduct".$product->type);
  66. $picto=($product->type==1?'service':'product');
  67. dol_fiche_head($head, 'referers', $titre, 0, $picto);
  68. print '<table class="border" width="100%">';
  69. // Reference
  70. print '<tr>';
  71. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  72. print $form->showrefnav($product,'ref','',1,'ref');
  73. print '</td>';
  74. print '</tr>';
  75. // Libelle
  76. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  77. print '</tr>';
  78. // Status (to sell)
  79. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  80. print $product->getLibStatut(2,0);
  81. print '</td></tr>';
  82. // Status (to buy)
  83. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  84. print $product->getLibStatut(2,1);
  85. print '</td></tr>';
  86. show_stats_for_company($product,$socid);
  87. print "</table>";
  88. print '</div>';
  89. $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, f.facnumber, f.total_ht as total_ht,";
  90. $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
  91. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  92. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  93. $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
  94. $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d";
  95. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  96. $sql.= " WHERE f.fk_soc = s.rowid";
  97. $sql.= " AND f.entity = ".$conf->entity;
  98. $sql.= " AND d.fk_facture_fourn = f.rowid";
  99. $sql.= " AND d.fk_product =".$product->id;
  100. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  101. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  102. $sql.= " ORDER BY $sortfield $sortorder ";
  103. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  104. $result = $db->query($sql);
  105. if ($result)
  106. {
  107. $num = $db->num_rows($result);
  108. print_barre_liste($langs->trans("SuppliersInvoices"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  109. $i = 0;
  110. print "<table class=\"noborder\" width=\"100%\">";
  111. print '<tr class="liste_titre">';
  112. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  113. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  114. print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  115. print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  116. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  117. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  118. print "</tr>\n";
  119. if ($num > 0)
  120. {
  121. $var=True;
  122. while ($i < $num && $conf->liste_limit)
  123. {
  124. $objp = $db->fetch_object($result);
  125. $var=!$var;
  126. print "<tr $bc[$var]>";
  127. print '<td>';
  128. $supplierinvoicestatic->id=$objp->facid;
  129. $supplierinvoicestatic->ref=$objp->facnumber;
  130. print $supplierinvoicestatic->getNomUrl(1);
  131. print "</td>\n";
  132. 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>';
  133. print "<td>".$objp->code_client."</td>\n";
  134. print "<td align=\"center\">";
  135. print dol_print_date($db->jdate($objp->datef))."</td>";
  136. print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
  137. $fac=new Facture($db);
  138. print '<td align="right">'.$fac->LibStatut($objp->paye,$objp->statut,5).'</td>';
  139. print "</tr>\n";
  140. $i++;
  141. }
  142. }
  143. }
  144. else
  145. {
  146. dol_print_error($db);
  147. }
  148. print "</table>";
  149. print '<br>';
  150. $db->free($result);
  151. }
  152. }
  153. else
  154. {
  155. dol_print_error();
  156. }
  157. llxFooter();
  158. $db->close();
  159. ?>