facture_fournisseur.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/product/stats/facture_fournisseur.php
  22. * \ingroup product service facture
  23. * \brief Page des stats des factures fournisseurs pour un produit
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. $langs->load("companies");
  30. $langs->load("bills");
  31. $langs->load("products");
  32. $langs->load("companies");
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. // Security check
  36. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  37. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  40. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  41. $hookmanager->initHooks(array('productstatssupplyinvoice'));
  42. $mesg = '';
  43. $sortfield = GETPOST("sortfield",'alpha');
  44. $sortorder = GETPOST("sortorder",'alpha');
  45. $page = GETPOST("page",'int');
  46. if ($page == -1) { $page = 0; }
  47. $offset = $conf->liste_limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (! $sortorder) $sortorder="DESC";
  51. if (! $sortfield) $sortfield="f.datef";
  52. /*
  53. * View
  54. */
  55. $supplierinvoicestatic=new FactureFournisseur($db);
  56. $form = new Form($db);
  57. if ($id > 0 || ! empty($ref))
  58. {
  59. $product = new Product($db);
  60. $result = $product->fetch($id, $ref);
  61. $parameters=array('id'=>$id);
  62. $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks
  63. $error=$hookmanager->error; $errors=$hookmanager->errors;
  64. llxHeader("","",$langs->trans("CardProduct".$product->type));
  65. if ($result > 0)
  66. {
  67. /*
  68. * En mode visu
  69. */
  70. $head=product_prepare_head($product, $user);
  71. $titre=$langs->trans("CardProduct".$product->type);
  72. $picto=($product->type==1?'service':'product');
  73. dol_fiche_head($head, 'referers', $titre, 0, $picto);
  74. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook
  75. print '<table class="border" width="100%">';
  76. // Reference
  77. print '<tr>';
  78. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  79. print $form->showrefnav($product,'ref','',1,'ref');
  80. print '</td>';
  81. print '</tr>';
  82. // Libelle
  83. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
  84. print '</tr>';
  85. // Status (to sell)
  86. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  87. print $product->getLibStatut(2,0);
  88. print '</td></tr>';
  89. // Status (to buy)
  90. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  91. print $product->getLibStatut(2,1);
  92. print '</td></tr>';
  93. show_stats_for_company($product,$socid);
  94. print "</table>";
  95. print '</div>';
  96. $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,";
  97. $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid";
  98. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  99. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  100. $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
  101. $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d";
  102. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  103. $sql.= " WHERE f.fk_soc = s.rowid";
  104. $sql.= " AND f.entity = ".$conf->entity;
  105. $sql.= " AND d.fk_facture_fourn = f.rowid";
  106. $sql.= " AND d.fk_product =".$product->id;
  107. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  108. if ($socid) $sql.= " AND f.fk_soc = ".$socid;
  109. $sql.= " ORDER BY $sortfield $sortorder ";
  110. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  111. $result = $db->query($sql);
  112. if ($result)
  113. {
  114. $num = $db->num_rows($result);
  115. print_barre_liste($langs->trans("SuppliersInvoices"),$page,$_SERVER["PHP_SELF"],"&amp;id=$product->id",$sortfield,$sortorder,'',$num,0,'');
  116. $i = 0;
  117. print "<table class=\"noborder\" width=\"100%\">";
  118. print '<tr class="liste_titre">';
  119. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  120. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  121. print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&amp;id=".$product->id,'',$sortfield,$sortorder);
  122. print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$product->id,'align="center"',$sortfield,$sortorder);
  123. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  124. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
  125. print "</tr>\n";
  126. if ($num > 0)
  127. {
  128. $var=True;
  129. while ($i < $num && $conf->liste_limit)
  130. {
  131. $objp = $db->fetch_object($result);
  132. $var=!$var;
  133. print "<tr ".$bc[$var].">";
  134. print '<td>';
  135. $supplierinvoicestatic->id=$objp->facid;
  136. $supplierinvoicestatic->ref=$objp->facnumber;
  137. print $supplierinvoicestatic->getNomUrl(1);
  138. print "</td>\n";
  139. 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>';
  140. print "<td>".$objp->code_client."</td>\n";
  141. print "<td align=\"center\">";
  142. print dol_print_date($db->jdate($objp->datef))."</td>";
  143. print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
  144. print '<td align="right">'.$supplierinvoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>';
  145. print "</tr>\n";
  146. $i++;
  147. }
  148. }
  149. }
  150. else
  151. {
  152. dol_print_error($db);
  153. }
  154. print "</table>";
  155. print '<br>';
  156. $db->free($result);
  157. }
  158. }
  159. else
  160. {
  161. dol_print_error();
  162. }
  163. llxFooter();
  164. $db->close();