index.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 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/expedition/index.php
  21. * \ingroup expedition
  22. * \brief Home page of shipping area.
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array('orders', 'sendings'));
  29. /*
  30. * View
  31. */
  32. $orderstatic=new Commande($db);
  33. $companystatic=new Societe($db);
  34. $shipment=new Expedition($db);
  35. $helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
  36. llxHeader('',$langs->trans("Shipment"),$helpurl);
  37. print load_fiche_titre($langs->trans("SendingsArea"));
  38. print '<div class="fichecenter"><div class="fichethirdleft">';
  39. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  40. {
  41. print '<form method="post" action="list.php">';
  42. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  43. print '<table class="noborder nohover" width="100%">';
  44. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  45. print '<tr class="oddeven"><td>';
  46. print $langs->trans("Shipment").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  47. print "</table></form><br>\n";
  48. }
  49. /*
  50. * Shipments to validate
  51. */
  52. $clause = " WHERE ";
  53. $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
  54. $sql.= " s.nom as name, s.rowid as socid,";
  55. $sql.= " c.ref as commande_ref, c.rowid as commande_id";
  56. $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
  57. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
  58. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
  59. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  60. if (!$user->rights->societe->client->voir && !$socid)
  61. {
  62. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  63. $sql.= $clause." sc.fk_user = " .$user->id;
  64. $clause = " AND ";
  65. }
  66. $sql.= $clause." e.fk_statut = 0";
  67. $sql.= " AND e.entity IN (".getEntity('expedition').")";
  68. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  69. $resql=$db->query($sql);
  70. if ($resql)
  71. {
  72. $num = $db->num_rows($resql);
  73. if ($num)
  74. {
  75. print '<table class="noborder" width="100%">';
  76. print '<tr class="liste_titre">';
  77. print '<th colspan="3">'.$langs->trans("SendingsToValidate").'</th></tr>';
  78. $i = 0;
  79. while ($i < $num)
  80. {
  81. $obj = $db->fetch_object($resql);
  82. $shipment->id=$obj->rowid;
  83. $shipment->ref=$obj->ref;
  84. $shipment->ref_customer=$obj->ref_customer;
  85. print '<tr class="oddeven"><td class="nowrap">';
  86. print $shipment->getNomUrl(1);
  87. print "</td>";
  88. print '<td>';
  89. print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
  90. print '</td>';
  91. print '<td>';
  92. if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
  93. print '</td></tr>';
  94. $i++;
  95. }
  96. print "</table><br>";
  97. }
  98. }
  99. /*
  100. * Commandes a traiter
  101. */
  102. $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut, s.nom as name, s.rowid as socid";
  103. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
  104. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  105. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  106. $sql.= " WHERE c.fk_soc = s.rowid";
  107. $sql.= " AND c.entity = ".$conf->entity;
  108. $sql.= " AND c.fk_statut = 1";
  109. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  110. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  111. $sql.= " ORDER BY c.rowid ASC";
  112. $resql=$db->query($sql);
  113. if ($resql)
  114. {
  115. $num = $db->num_rows($resql);
  116. if ($num)
  117. {
  118. $langs->load("orders");
  119. $i = 0;
  120. print '<table class="noborder" width="100%">';
  121. print '<tr class="liste_titre">';
  122. print '<th colspan="3">'.$langs->trans("OrdersToProcess").'</th></tr>';
  123. while ($i < $num)
  124. {
  125. $obj = $db->fetch_object($resql);
  126. $orderstatic->id=$obj->rowid;
  127. $orderstatic->ref=$obj->ref;
  128. $orderstatic->ref_customer=$obj->ref_customer;
  129. $orderstatic->statut=$obj->fk_statut;
  130. $orderstatic->billed=0;
  131. $companystatic->name=$obj->name;
  132. $companystatic->id=$obj->socid;
  133. print '<tr class="oddeven">';
  134. print '<td class="nowrap">';
  135. print $orderstatic->getNomUrl(1);
  136. print '</td>';
  137. print '<td>';
  138. print $companystatic->getNomUrl(1,'customer',32);
  139. print '</td>';
  140. print '<td align="right">';
  141. print $orderstatic->getLibStatut(3);
  142. print '</td>';
  143. print '</tr>';
  144. $i++;
  145. }
  146. print "</table><br>";
  147. }
  148. }
  149. //print '</td><td valign="top" width="70%">';
  150. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  151. /*
  152. * Commandes en traitement
  153. */
  154. $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
  155. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
  156. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  157. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  158. $sql.= " WHERE c.fk_soc = s.rowid";
  159. $sql.= " AND c.entity = ".$conf->entity;
  160. $sql.= " AND c.fk_statut = 2";
  161. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  162. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  163. $resql = $db->query($sql);
  164. if ( $resql )
  165. {
  166. $langs->load("orders");
  167. $num = $db->num_rows($resql);
  168. if ($num)
  169. {
  170. $i = 0;
  171. print '<table class="noborder" width="100%">';
  172. print '<tr class="liste_titre">';
  173. print '<th colspan="3">'.$langs->trans("OrdersInProcess").'</th></tr>';
  174. while ($i < $num)
  175. {
  176. $obj = $db->fetch_object($resql);
  177. $orderstatic->id=$obj->rowid;
  178. $orderstatic->ref=$obj->ref;
  179. $orderstatic->ref_customer=$obj->ref_customer;
  180. $orderstatic->statut=$obj->status;
  181. $orderstatic->billed=$obj->billed;
  182. $companystatic->name=$obj->name;
  183. $companystatic->id=$obj->socid;
  184. print '<tr class="oddeven"><td>';
  185. print $orderstatic->getNomUrl(1);
  186. print '</td>';
  187. print '<td>';
  188. print $companystatic->getNomUrl(1,'customer');
  189. print '</td>';
  190. print '<td align="right">';
  191. print $orderstatic->getLibStatut(3);
  192. print '</td>';
  193. print '</tr>';
  194. $i++;
  195. }
  196. print "</table><br>";
  197. }
  198. }
  199. else dol_print_error($db);
  200. /*
  201. * Last shipments
  202. */
  203. $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
  204. $sql.= " s.nom as name, s.rowid as socid,";
  205. $sql.= " c.ref as commande_ref, c.rowid as commande_id";
  206. $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
  207. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
  208. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
  209. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  210. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  211. $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
  212. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
  213. $sql.= " AND e.fk_statut = 1";
  214. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  215. $sql.= " ORDER BY e.date_delivery DESC";
  216. $sql.= $db->plimit(5, 0);
  217. $resql = $db->query($sql);
  218. if ($resql)
  219. {
  220. $num = $db->num_rows($resql);
  221. if ($num)
  222. {
  223. $i = 0;
  224. print '<table class="noborder" width="100%">';
  225. print '<tr class="liste_titre">';
  226. print '<th colspan="3">'.$langs->trans("LastSendings", $num).'</th></tr>';
  227. while ($i < $num)
  228. {
  229. $obj = $db->fetch_object($resql);
  230. $shipment->id=$obj->rowid;
  231. $shipment->ref=$obj->ref;
  232. $shipment->ref_customer=$obj->ref_customer;
  233. print '<tr class="oddeven"><td>';
  234. print $shipment->getNomUrl(1);
  235. print '</td>';
  236. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
  237. print '<td>';
  238. if ($obj->commande_id > 0)
  239. {
  240. $orderstatic->id=$obj->commande_id;
  241. $orderstatic->ref=$obj->commande_ref;
  242. print $orderstatic->getNomUrl(1);
  243. }
  244. else print '&nbsp;';
  245. print '</td></tr>';
  246. $i++;
  247. }
  248. print "</table><br>";
  249. }
  250. $db->free($resql);
  251. }
  252. else dol_print_error($db);
  253. print '</div></div></div>';
  254. // End of page
  255. llxFooter();
  256. $db->close();