index.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.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/fourn/index.php
  21. * \ingroup fournisseur
  22. * \brief Home page of suppliers area
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  28. $langs->loadLangs(array("suppliers", "orders", "companies"));
  29. // Security check
  30. $socid = GETPOST("socid", 'int');
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. $result = restrictedArea($user, 'societe',$socid,'');
  33. /*
  34. * View
  35. */
  36. $commandestatic=new CommandeFournisseur($db);
  37. $facturestatic=new FactureFournisseur($db);
  38. $companystatic=new Societe($db);
  39. llxHeader("",$langs->trans("SuppliersArea"));
  40. print load_fiche_titre($langs->trans("SuppliersArea"));
  41. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  42. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  43. print '<div class="fichecenter"><div class="fichethirdleft">';
  44. // Orders
  45. $sql = "SELECT count(cf.rowid), cf.fk_statut";
  46. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
  47. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  48. if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  49. $sql.= " WHERE cf.fk_soc = s.rowid ";
  50. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " .$user->id;
  51. $sql.= " AND cf.entity = ".$conf->entity;
  52. $sql.= " GROUP BY cf.fk_statut";
  53. $resql = $db->query($sql);
  54. if ($resql)
  55. {
  56. $num = $db->num_rows($resql);
  57. $i = 0;
  58. print '<table class="noborder" width="100%">';
  59. print '<tr class="liste_titre"><td>'.$langs->trans("Orders").'</td><td align="center">'.$langs->trans("Nb").'</td><td>&nbsp;</td>';
  60. print "</tr>\n";
  61. while ($i < $num)
  62. {
  63. $row = $db->fetch_row($resql);
  64. print '<tr class="oddeven">';
  65. print '<td>'.$commandestatic->LibStatut($row[1]).'</td>';
  66. print '<td align="center">'.$row[0].'</td>';
  67. print '<td align="center"><a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?statut='.$row[1].'">'.$commandestatic->LibStatut($row[1],3).'</a></td>';
  68. print "</tr>\n";
  69. $i++;
  70. }
  71. print "</table>";
  72. print "<br>\n";
  73. $db->free($resql);
  74. }
  75. else
  76. {
  77. dol_print_error($db);
  78. }
  79. // Draft orders
  80. if (! empty($conf->fournisseur->enabled))
  81. {
  82. $langs->load("orders");
  83. $sql = "SELECT cf.rowid, cf.ref, cf.total_ttc,";
  84. $sql.= " s.nom as name, s.rowid as socid";
  85. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  86. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  87. if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  88. $sql.= " WHERE cf.fk_soc = s.rowid";
  89. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " .$user->id;
  90. $sql.= " AND cf.entity = ".$conf->entity;
  91. $sql.= " AND cf.fk_statut = 0";
  92. if ($socid) $sql .= " AND cf.fk_soc = ".$socid;
  93. $resql = $db->query($sql);
  94. if ($resql)
  95. {
  96. $total = 0;
  97. $num = $db->num_rows($resql);
  98. if ($num)
  99. {
  100. print '<table class="noborder" width="100%">';
  101. print '<tr class="liste_titre">';
  102. print '<td colspan="3">'.$langs->trans("DraftOrders").' <span class="badge">'.$num.'</span></td></tr>';
  103. $i = 0;
  104. while ($i < $num)
  105. {
  106. $obj = $db->fetch_object($resql);
  107. print '<tr class="oddeven"><td class="nowrap">';
  108. $commandestatic->id=$obj->rowid;
  109. $commandestatic->ref=$obj->ref;
  110. print $commandestatic->getNomUrl(1,'',16);
  111. print '</td>';
  112. print '<td class="nowrap">';
  113. $companystatic->id=$obj->socid;
  114. $companystatic->name=$obj->name;
  115. $companystatic->client=0;
  116. print $companystatic->getNomUrl(1,'',16);
  117. print '</td>';
  118. print '<td align="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  119. $i++;
  120. $total += $obj->total_ttc;
  121. }
  122. if ($total>0)
  123. {
  124. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  125. }
  126. print "</table>";
  127. print "<br>\n";
  128. }
  129. }
  130. }
  131. // Draft invoices
  132. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire)
  133. {
  134. $sql = "SELECT ff.ref_supplier, ff.rowid, ff.total_ttc, ff.type";
  135. $sql.= ", s.nom as name, s.rowid as socid";
  136. $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
  137. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  138. if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  139. $sql.= " WHERE s.rowid = ff.fk_soc";
  140. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " .$user->id;
  141. $sql.= " AND ff.entity = ".$conf->entity;
  142. $sql.= " AND ff.fk_statut = 0";
  143. if ($socid) $sql .= " AND f.fk_soc = ".$socid;
  144. $resql = $db->query($sql);
  145. if ( $resql )
  146. {
  147. $num = $db->num_rows($resql);
  148. if ($num)
  149. {
  150. print '<table class="noborder" width="100%">';
  151. print '<tr class="liste_titre">';
  152. print '<td colspan="3">'.$langs->trans("DraftBills").' <span class="badge">'.$num.'</span></td></tr>';
  153. $i = 0;
  154. $tot_ttc = 0;
  155. while ($i < $num && $i < 20)
  156. {
  157. $obj = $db->fetch_object($resql);
  158. print '<tr class="oddeven"><td class="nowrap">';
  159. $facturestatic->ref=$obj->ref;
  160. $facturestatic->id=$obj->rowid;
  161. $facturestatic->type=$obj->type;
  162. print $facturestatic->getNomUrl(1,'');
  163. print '</td>';
  164. print '<td class="nowrap">';
  165. $companystatic->id=$obj->socid;
  166. $companystatic->name=$obj->name;
  167. $companystatic->client=0;
  168. print $companystatic->getNomUrl(1,'',16);
  169. print '</td>';
  170. print '<td align="right">'.price($obj->total_ttc).'</td>';
  171. print '</tr>';
  172. $tot_ttc+=$obj->total_ttc;
  173. $i++;
  174. }
  175. print '<tr class="liste_total"><td align="left">'.$langs->trans("Total").'</td>';
  176. print '<td colspan="2" align="right">'.price($tot_ttc).'</td>';
  177. print '</tr>';
  178. print "</table>";
  179. print "<br>\n";
  180. }
  181. $db->free($resql);
  182. }
  183. else
  184. {
  185. dol_print_error($db);
  186. }
  187. }
  188. //print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  189. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  190. /*
  191. * List last modified supliers
  192. */
  193. $max=10;
  194. $sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur, s.code_compta_fournisseur";
  195. $sql.= ", st.libelle as stcomm";
  196. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  197. $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
  198. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  199. $sql.= " WHERE s.fk_stcomm = st.id";
  200. $sql.= " AND s.fournisseur = 1";
  201. $sql.= " AND s.entity IN (".getEntity('societe').")";
  202. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  203. if ($socid) $sql .= " AND s.rowid = ".$socid;
  204. $sql.= " ORDER BY s.tms DESC";
  205. $sql .= $db->plimit($max, 0);
  206. $resql = $db->query($sql);
  207. if ($resql)
  208. {
  209. $langs->load("boxes");
  210. $num = $db->num_rows($resql);
  211. $i = 0;
  212. print '<table class="noborder" width="100%">';
  213. print '<tr class="liste_titre">';
  214. print '<td colspan="2">'.$langs->trans("BoxTitleLastSuppliers",min($max,$num))."</td>\n";
  215. print '<td align="right">'.$langs->trans("DateModification")."</td>\n";
  216. print "</tr>\n";
  217. while ($obj = $db->fetch_object($resql) )
  218. {
  219. print '<tr class="oddeven">';
  220. print '<td><a href="card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"),"company").'</a>';
  221. print "&nbsp;<a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
  222. print '<td align="left">'.$obj->code_fournisseur.'&nbsp;</td>';
  223. print '<td align="right">'.dol_print_date($db->jdate($obj->tms),'day').'</td>';
  224. print "</tr>\n";
  225. }
  226. print "</table>\n";
  227. $db->free($resql);
  228. }
  229. else
  230. {
  231. dol_print_error($db);
  232. }
  233. /*
  234. * List of suppliers categories
  235. */
  236. $companystatic->LoadSupplierCateg();
  237. $categstatic=new Categorie($db);
  238. if (count($companystatic->SupplierCategories))
  239. {
  240. print '<br>';
  241. print '<table class="liste" width="100%">';
  242. print '<tr class="liste_titre"><td colspan="2">';
  243. print $langs->trans("Category");
  244. print "</td></tr>\n";
  245. foreach ($companystatic->SupplierCategories as $rowid => $label)
  246. {
  247. print '<tr class="oddeven">'."\n";
  248. print '<td>';
  249. $categstatic->id=$rowid;
  250. $categstatic->ref=$label;
  251. $categstatic->label=$label;
  252. print $categstatic->getNomUrl(1);
  253. print '</td>'."\n";
  254. // TODO this page not exist
  255. /*
  256. print '<td align="right">';
  257. print '<a href="stats.php?cat='.$rowid.'">('.$langs->trans("Stats").')</a>';
  258. print "</tr>\n";
  259. */
  260. }
  261. print "</table>\n";
  262. print "<br>\n";
  263. }
  264. //print "</td></tr></table>\n";
  265. print '</div></div></div>';
  266. // End of page
  267. llxFooter();
  268. $db->close();