index.php 10 KB

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