index.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  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/comm/index.php
  22. * \ingroup commercial
  23. * \brief Home page of commercial area
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  30. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  31. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  32. if (! empty($conf->supplier_proposal->enabled)) require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  33. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  34. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  35. if (! $user->rights->societe->lire) accessforbidden();
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("commercial", "propal"));
  38. $action=GETPOST('action', 'alpha');
  39. $bid=GETPOST('bid', 'int');
  40. // Securite acces client
  41. $socid=GETPOST('socid','int');
  42. if (isset($user->societe_id) && $user->societe_id > 0)
  43. {
  44. $action = '';
  45. $socid = $user->societe_id;
  46. }
  47. $max=5;
  48. $now=dol_now();
  49. /*
  50. * Actions
  51. */
  52. /*
  53. * View
  54. */
  55. $form = new Form($db);
  56. $formfile = new FormFile($db);
  57. $companystatic=new Societe($db);
  58. if (! empty($conf->propal->enabled)) $propalstatic=new Propal($db);
  59. if (! empty($conf->supplier_proposal->enabled)) $supplierproposalstatic=new SupplierProposal($db);
  60. if (! empty($conf->commande->enabled)) $orderstatic=new Commande($db);
  61. if (! empty($conf->fournisseur->enabled)) $supplierorderstatic=new CommandeFournisseur($db);
  62. llxHeader("",$langs->trans("CommercialArea"));
  63. print load_fiche_titre($langs->trans("CommercialArea"),'','title_commercial.png');
  64. print '<div class="fichecenter"><div class="fichethirdleft">';
  65. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  66. {
  67. // Search proposal
  68. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  69. {
  70. $listofsearchfields['search_proposal']=array('text'=>'Proposal');
  71. }
  72. // Search customer order
  73. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  74. {
  75. $listofsearchfields['search_customer_order']=array('text'=>'CustomerOrder');
  76. }
  77. // Search supplier proposal
  78. if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire)
  79. {
  80. $listofsearchfields['search_supplier_proposal']=array('text'=>'SupplierProposalShort');
  81. }
  82. // Search supplier order
  83. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire)
  84. {
  85. $listofsearchfields['search_supplier_order']=array('text'=>'SupplierOrder');
  86. }
  87. // Search intervention
  88. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
  89. {
  90. $listofsearchfields['search_intervention']=array('text'=>'Intervention');
  91. }
  92. // Search contract
  93. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  94. {
  95. $listofsearchfields['search_contract']=array('text'=>'Contract');
  96. }
  97. if (count($listofsearchfields))
  98. {
  99. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  100. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  101. print '<table class="noborder nohover centpercent">';
  102. $i=0;
  103. foreach($listofsearchfields as $key => $value)
  104. {
  105. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  106. print '<tr '.$bc[false].'>';
  107. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
  108. if ($i == 0) print '<td class="noborderbottom" rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button "></td>';
  109. print '</tr>';
  110. $i++;
  111. }
  112. print '</table>';
  113. print '</form>';
  114. print '<br>';
  115. }
  116. }
  117. /*
  118. * Draft proposals
  119. */
  120. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  121. {
  122. $langs->load("propal");
  123. $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.tva as total_tva, p.total as total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  124. $sql.= ", s.code_client";
  125. $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
  126. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  127. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  128. $sql.= " WHERE p.fk_statut = 0";
  129. $sql.= " AND p.fk_soc = s.rowid";
  130. $sql.= " AND p.entity IN (".getEntity('propal').")";
  131. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  132. if ($socid) $sql.= " AND s.rowid = ".$socid;
  133. $resql=$db->query($sql);
  134. if ($resql)
  135. {
  136. $total = 0;
  137. $num = $db->num_rows($resql);
  138. print '<div class="div-table-responsive-no-min">';
  139. print '<table class="noborder" width="100%">';
  140. print '<tr class="liste_titre">';
  141. print '<th colspan="3">'.$langs->trans("ProposalsDraft").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
  142. if ($num > 0)
  143. {
  144. $i = 0;
  145. while ($i < $num)
  146. {
  147. $obj = $db->fetch_object($resql);
  148. print '<tr class="oddeven"><td class="nowrap">';
  149. $propalstatic->id=$obj->rowid;
  150. $propalstatic->ref=$obj->ref;
  151. $propalstatic->ref_client=$obj->ref_client;
  152. $propalstatic->total_ht = $obj->total_ht;
  153. $propalstatic->total_tva = $obj->total_tva;
  154. $propalstatic->total_ttc = $obj->total_ttc;
  155. print $propalstatic->getNomUrl(1);
  156. print '</td>';
  157. print '<td class="nowrap">';
  158. $companystatic->id=$obj->socid;
  159. $companystatic->name=$obj->name;
  160. $companystatic->client=$obj->client;
  161. $companystatic->code_client = $obj->code_client;
  162. $companystatic->code_fournisseur = $obj->code_fournisseur;
  163. $companystatic->canvas=$obj->canvas;
  164. print $companystatic->getNomUrl(1,'customer',16);
  165. print '</td>';
  166. print '<td align="right" class="nowrap">'.price($obj->total_ht).'</td></tr>';
  167. $i++;
  168. $total += $obj->total_ht;
  169. }
  170. if ($total>0)
  171. {
  172. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  173. }
  174. }
  175. else
  176. {
  177. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoProposal").'</td></tr>';
  178. }
  179. print "</table></div><br>";
  180. $db->free($resql);
  181. }
  182. else
  183. {
  184. dol_print_error($db);
  185. }
  186. }
  187. /*
  188. * Draft supplier proposals
  189. */
  190. if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire)
  191. {
  192. $langs->load("supplier_proposal");
  193. $sql = "SELECT p.rowid, p.ref, p.total_ht, p.tva as total_tva, p.total as total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  194. $sql.= ", s.code_client";
  195. $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
  196. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  197. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  198. $sql.= " WHERE p.fk_statut = 0";
  199. $sql.= " AND p.fk_soc = s.rowid";
  200. $sql.= " AND p.entity IN (".getEntity('supplier_proposal').")";
  201. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  202. if ($socid) $sql.= " AND s.rowid = ".$socid;
  203. $resql=$db->query($sql);
  204. if ($resql)
  205. {
  206. $total = 0;
  207. $num = $db->num_rows($resql);
  208. print '<div class="div-table-responsive-no-min">';
  209. print '<table class="noborder" width="100%">';
  210. print '<tr class="liste_titre">';
  211. print '<th colspan="3">'.$langs->trans("SupplierProposalsDraft").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
  212. if ($num > 0)
  213. {
  214. $i = 0;
  215. while ($i < $num)
  216. {
  217. $obj = $db->fetch_object($resql);
  218. print '<tr class="oddeven"><td class="nowrap">';
  219. $supplierproposalstatic->id=$obj->rowid;
  220. $supplierproposalstatic->ref=$obj->ref;
  221. $supplierproposalstatic->total_ht = $obj->total_ht;
  222. $supplierproposalstatic->total_tva = $obj->total_tva;
  223. $supplierproposalstatic->total_ttc = $obj->total_ttc;
  224. print $supplierproposalstatic->getNomUrl(1);
  225. print '</td>';
  226. print '<td class="nowrap">';
  227. $companystatic->id=$obj->socid;
  228. $companystatic->name=$obj->name;
  229. $companystatic->client=$obj->client;
  230. $companystatic->code_client = $obj->code_client;
  231. $companystatic->code_fournisseur = $obj->code_fournisseur;
  232. $companystatic->canvas=$obj->canvas;
  233. print $companystatic->getNomUrl(1,'supplier',16);
  234. print '</td>';
  235. print '<td align="right" class="nowrap">'.price($obj->total_ht).'</td></tr>';
  236. $i++;
  237. $total += $obj->total_ht;
  238. }
  239. if ($total>0)
  240. {
  241. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  242. }
  243. }
  244. else
  245. {
  246. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoProposal").'</td></tr>';
  247. }
  248. print "</table></div><br>";
  249. $db->free($resql);
  250. }
  251. else
  252. {
  253. dol_print_error($db);
  254. }
  255. }
  256. /*
  257. * Draft orders
  258. */
  259. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  260. {
  261. $langs->load("orders");
  262. $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.tva as total_tva, c.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  263. $sql.= ", s.code_client";
  264. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  265. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  266. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  267. $sql.= " WHERE c.fk_soc = s.rowid";
  268. $sql.= " AND c.fk_statut = 0";
  269. $sql.= " AND c.entity IN (".getEntity('commande').")";
  270. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  271. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  272. $resql = $db->query($sql);
  273. if ($resql)
  274. {
  275. $total = 0;
  276. $num = $db->num_rows($resql);
  277. print '<div class="div-table-responsive-no-min">';
  278. print '<table class="noborder" width="100%">';
  279. print '<tr class="liste_titre">';
  280. print '<th colspan="3">'.$langs->trans("DraftOrders").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
  281. if ($num > 0)
  282. {
  283. $i = 0;
  284. while ($i < $num)
  285. {
  286. $obj = $db->fetch_object($resql);
  287. print '<tr class="oddeven"><td class="nowrap">';
  288. $orderstatic->id=$obj->rowid;
  289. $orderstatic->ref=$obj->ref;
  290. $orderstatic->ref_client=$obj->ref_client;
  291. $orderstatic->total_ht = $obj->total_ht;
  292. $orderstatic->total_tva = $obj->total_tva;
  293. $orderstatic->total_ttc = $obj->total_ttc;
  294. print $orderstatic->getNomUrl(1);
  295. print '</td>';
  296. print '<td class="nowrap">';
  297. $companystatic->id=$obj->socid;
  298. $companystatic->name=$obj->name;
  299. $companystatic->client=$obj->client;
  300. $companystatic->code_client = $obj->code_client;
  301. $companystatic->code_fournisseur = $obj->code_fournisseur;
  302. $companystatic->canvas=$obj->canvas;
  303. print $companystatic->getNomUrl(1,'customer',16);
  304. print '</td>';
  305. if(! empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT)) {
  306. print '<td align="right" class="nowrap">'.price($obj->total_ht).'</td></tr>';
  307. }
  308. else {
  309. print '<td align="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  310. }
  311. $i++;
  312. $total += $obj->total_ttc;
  313. }
  314. if ($total>0)
  315. {
  316. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  317. }
  318. }
  319. else
  320. {
  321. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoOrder").'</td></tr>';
  322. }
  323. print "</table>";
  324. print "</div><br>";
  325. $db->free($resql);
  326. }
  327. else
  328. {
  329. dol_print_error($db);
  330. }
  331. }
  332. /*
  333. * Draft suppliers orders
  334. */
  335. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire)
  336. {
  337. $langs->load("orders");
  338. $sql = "SELECT cf.rowid, cf.ref, cf.ref_supplier, cf.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  339. $sql.= ", s.code_client";
  340. $sql.= ", s.code_fournisseur";
  341. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  342. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  343. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  344. $sql.= " WHERE cf.fk_soc = s.rowid";
  345. $sql.= " AND cf.fk_statut = 0";
  346. $sql.= " AND cf.entity IN (".getEntity('supplier_order').")";
  347. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  348. if ($socid) $sql.= " AND cf.fk_soc = ".$socid;
  349. $resql = $db->query($sql);
  350. if ($resql)
  351. {
  352. $total = 0;
  353. $num = $db->num_rows($resql);
  354. print '<div class="div-table-responsive-no-min">';
  355. print '<table class="noborder" width="100%">';
  356. print '<tr class="liste_titre">';
  357. print '<th colspan="3">'.$langs->trans("DraftSuppliersOrders").($num?' <span class="badge">'.$num.'</span>':'').'</th></tr>';
  358. if ($num > 0)
  359. {
  360. $i = 0;
  361. while ($i < $num)
  362. {
  363. $obj = $db->fetch_object($resql);
  364. print '<tr class="oddeven"><td class="nowrap">';
  365. $supplierorderstatic->id=$obj->rowid;
  366. $supplierorderstatic->ref=$obj->ref;
  367. $supplierorderstatic->ref_supplier=$obj->ref_suppliert;
  368. $supplierorderstatic->total_ht = $obj->total_ht;
  369. $supplierorderstatic->total_tva = $obj->total_tva;
  370. $supplierorderstatic->total_ttc = $obj->total_ttc;
  371. print $supplierorderstatic->getNomUrl(1);
  372. print '</td>';
  373. print '<td class="nowrap">';
  374. $companystatic->id=$obj->socid;
  375. $companystatic->name=$obj->name;
  376. $companystatic->client=$obj->client;
  377. $companystatic->code_client = $obj->code_client;
  378. $companystatic->code_fournisseur = $obj->code_fournisseur;
  379. $companystatic->canvas=$obj->canvas;
  380. print $companystatic->getNomUrl(1,'supplier',16);
  381. print '</td>';
  382. if(! empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT)) {
  383. print '<td align="right" class="nowrap">'.price($obj->total_ht).'</td></tr>';
  384. }
  385. else {
  386. print '<td align="right" class="nowrap">'.price($obj->total_ttc).'</td></tr>';
  387. }
  388. $i++;
  389. $total += $obj->total_ttc;
  390. }
  391. if ($total>0)
  392. {
  393. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  394. }
  395. }
  396. else
  397. {
  398. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoSupplierOrder").'</td></tr>';
  399. }
  400. print "</table>";
  401. print "</div><br>";
  402. $db->free($resql);
  403. } else {
  404. dol_print_error($db);
  405. }
  406. }
  407. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  408. $NBMAX=3;
  409. $max=3;
  410. /*
  411. * Last modified customers or prospects
  412. */
  413. if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
  414. {
  415. $langs->load("boxes");
  416. $sql = "SELECT s.rowid, s.nom as name, s.client, s.datec, s.tms, s.canvas";
  417. $sql.= ", s.code_client";
  418. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  419. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  420. $sql.= " WHERE s.client IN (1, 2, 3)";
  421. $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
  422. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  423. if ($socid) $sql.= " AND s.rowid = $socid";
  424. $sql .= " ORDER BY s.tms DESC";
  425. $sql .= $db->plimit($max, 0);
  426. $resql = $db->query($sql);
  427. if ($resql)
  428. {
  429. $num = $db->num_rows($resql);
  430. $i = 0;
  431. print '<div class="div-table-responsive-no-min">';
  432. print '<table class="noborder" width="100%">';
  433. print '<tr class="liste_titre">';
  434. print '<th colspan="2">';
  435. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastCustomersOrProspects",$max);
  436. else if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastModifiedProspects",$max);
  437. else print $langs->trans("BoxTitleLastModifiedCustomers",$max);
  438. print '</th>';
  439. print '<th align="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/societe/list.php?type=p,c">'.$langs->trans("FullList").'</a></th>';
  440. print '</tr>';
  441. if ($num)
  442. {
  443. while ($i < $num)
  444. {
  445. $objp = $db->fetch_object($resql);
  446. $companystatic->id=$objp->rowid;
  447. $companystatic->name=$objp->name;
  448. $companystatic->client=$objp->client;
  449. $companystatic->code_client = $objp->code_client;
  450. $companystatic->code_fournisseur = $objp->code_fournisseur;
  451. $companystatic->canvas=$objp->canvas;
  452. print '<tr class="oddeven">';
  453. print '<td class="nowrap">'.$companystatic->getNomUrl(1,'customer',48).'</td>';
  454. print '<td align="right" nowrap>';
  455. print $companystatic->getLibCustProspStatut();
  456. print "</td>";
  457. print '<td align="right" nowrap>'.dol_print_date($db->jdate($objp->tms),'day')."</td>";
  458. print '</tr>';
  459. $i++;
  460. }
  461. $db->free($resql);
  462. }
  463. else
  464. {
  465. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  466. }
  467. print "</table>";
  468. print "</div><br>";
  469. }
  470. }
  471. // Last suppliers
  472. if (! empty($conf->fournisseur->enabled) && $user->rights->societe->lire)
  473. {
  474. $langs->load("boxes");
  475. $sql = "SELECT s.nom as name, s.rowid, s.datec as dc, s.canvas, s.tms as dm";
  476. $sql.= ", s.code_fournisseur";
  477. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  478. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  479. $sql.= " WHERE s.fournisseur = 1";
  480. $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
  481. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  482. if ($socid) $sql.= " AND s.rowid = ".$socid;
  483. $sql.= " ORDER BY s.datec DESC";
  484. $sql.= $db->plimit($max, 0);
  485. $result = $db->query($sql);
  486. if ($result)
  487. {
  488. $num = $db->num_rows($result);
  489. $i = 0;
  490. print '<div class="div-table-responsive-no-min">';
  491. print '<table class="noborder" width="100%">';
  492. print '<tr class="liste_titre">';
  493. print '<th>'.$langs->trans("BoxTitleLastModifiedSuppliers",min($max,$num)).'</th>';
  494. print '<th align="right"><a class="commonlink" href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("FullList").'</a></th>';
  495. print '</tr>';
  496. if ($num)
  497. {
  498. while ($i < $num && $i < $max)
  499. {
  500. $objp = $db->fetch_object($result);
  501. $companystatic->id=$objp->rowid;
  502. $companystatic->name=$objp->name;
  503. $companystatic->code_client = $objp->code_client;
  504. $companystatic->code_fournisseur = $objp->code_fournisseur;
  505. $companystatic->canvas=$objp->canvas;
  506. print '<tr class="oddeven">';
  507. print '<td class="nowrap">'.$companystatic->getNomUrl(1,'supplier',44).'</td>';
  508. print '<td align="right">'.dol_print_date($db->jdate($objp->dm),'day').'</td>';
  509. print '</tr>';
  510. $i++;
  511. }
  512. }
  513. else
  514. {
  515. print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  516. }
  517. print '</table>';
  518. print '</div><br>';
  519. }
  520. }
  521. /*
  522. * Last actions
  523. */
  524. if ($user->rights->agenda->myactions->read)
  525. {
  526. show_array_last_actions_done($max);
  527. }
  528. /*
  529. * Actions to do
  530. */
  531. if ($user->rights->agenda->myactions->read)
  532. {
  533. show_array_actions_to_do(10);
  534. }
  535. /*
  536. * Last contracts
  537. */
  538. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire && 0) // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
  539. {
  540. $langs->load("contracts");
  541. $sql = "SELECT s.nom as name, s.rowid, s.canvas, ";
  542. $sql.= ", s.code_client";
  543. $sql.= " c.statut, c.rowid as contratid, p.ref, c.mise_en_service as datemes, c.fin_validite as datefin, c.date_cloture as dateclo";
  544. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  545. $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
  546. $sql.= ", ".MAIN_DB_PREFIX."product as p";
  547. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  548. $sql.= " WHERE c.fk_soc = s.rowid";
  549. $sql.= " AND c.entity IN (".getEntity('contract').")";
  550. $sql.= " AND c.fk_product = p.rowid";
  551. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  552. if ($socid) $sql.= " AND s.rowid = ".$socid;
  553. $sql.= " ORDER BY c.tms DESC";
  554. $sql.= $db->plimit(5, 0);
  555. $resql=$db->query($sql);
  556. if ($resql)
  557. {
  558. $num = $db->num_rows($resql);
  559. if ($num > 0)
  560. {
  561. print '<div class="div-table-responsive-no-min">';
  562. print '<table class="noborder" width="100%">';
  563. print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("LastContracts",5).'</th></tr>';
  564. $i = 0;
  565. $staticcontrat=new Contrat($db);
  566. while ($i < $num)
  567. {
  568. $obj = $db->fetch_object($resql);
  569. print '<tr class="oddeven"><td><a href=\"../contrat/card.php?id=".$obj->contratid."\">".img_object($langs->trans("ShowContract","contract"), "contract")." ".$obj->ref."</a></td>';
  570. print '<td>';
  571. $companystatic->id=$objp->rowid;
  572. $companystatic->name=$objp->name;
  573. $companystatic->code_client = $objp->code_client;
  574. $companystatic->code_fournisseur = $objp->code_fournisseur;
  575. $companystatic->canvas=$objp->canvas;
  576. print $companystatic->getNomUrl(1,'customer',44);
  577. print '</td>'."\n";
  578. print "<td align=\"right\">".$staticcontrat->LibStatut($obj->statut,3)."</td></tr>\n";
  579. $i++;
  580. }
  581. print "</table>";
  582. print "</div><br>";
  583. }
  584. }
  585. else
  586. {
  587. dol_print_error($db);
  588. }
  589. }
  590. /*
  591. * Opened proposals
  592. */
  593. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  594. {
  595. $langs->load("propal");
  596. $sql = "SELECT s.nom as name, s.rowid, s.code_client";
  597. $sql.= ", p.rowid as propalid, p.entity, p.total as total_ttc, p.total_ht, p.tva as total_tva, p.ref, p.ref_client, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
  598. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  599. $sql.= ", ".MAIN_DB_PREFIX."propal as p";
  600. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  601. $sql.= " WHERE p.fk_soc = s.rowid";
  602. $sql.= " AND p.entity IN (".getEntity('propal').")";
  603. $sql.= " AND p.fk_statut = 1";
  604. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  605. if ($socid) $sql.= " AND s.rowid = ".$socid;
  606. $sql.= " ORDER BY p.rowid DESC";
  607. $result=$db->query($sql);
  608. if ($result)
  609. {
  610. $total = 0;
  611. $num = $db->num_rows($result);
  612. $i = 0;
  613. if ($num > 0)
  614. {
  615. print '<div class="div-table-responsive-no-min">';
  616. print '<table class="noborder" width="100%">';
  617. print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("ProposalsOpened").' <a href="'.DOL_URL_ROOT.'/comm/propal/list.php?viewstatut=1"><span class="badge">'.$num.'</span></th></tr>';
  618. $nbofloop=min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD)?500:$conf->global->MAIN_MAXLIST_OVERLOAD));
  619. while ($i < $nbofloop)
  620. {
  621. $obj = $db->fetch_object($result);
  622. print '<tr class="oddeven">';
  623. // Ref
  624. print '<td class="nowrap" width="140">';
  625. $propalstatic->id=$obj->propalid;
  626. $propalstatic->ref=$obj->ref;
  627. $propalstatic->ref_client=$obj->ref_client;
  628. $propalstatic->total_ht = $obj->total_ht;
  629. $propalstatic->total_tva = $obj->total_tva;
  630. $propalstatic->total_ttc = $obj->total_ttc;
  631. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  632. print '<td class="nobordernopadding nowrap">';
  633. print $propalstatic->getNomUrl(1);
  634. print '</td>';
  635. print '<td width="18" class="nobordernopadding nowrap">';
  636. if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  637. print '</td>';
  638. print '<td width="16" align="center" class="nobordernopadding">';
  639. $filename=dol_sanitizeFileName($obj->ref);
  640. $filedir=$conf->propal->multidir_output[$obj->entity] . '/' . dol_sanitizeFileName($obj->ref);
  641. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  642. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  643. print '</td></tr></table>';
  644. print "</td>";
  645. print '<td class="nowrap">';
  646. $companystatic->id=$obj->rowid;
  647. $companystatic->name=$obj->name;
  648. $companystatic->client=$obj->client;
  649. $companystatic->code_client = $obj->code_client;
  650. $companystatic->code_fournisseur = $obj->code_fournisseur;
  651. $companystatic->canvas=$obj->canvas;
  652. print $companystatic->getNomUrl(1, 'customer', 44);
  653. print '</td>';
  654. print '<td align="right">';
  655. print dol_print_date($db->jdate($obj->dp),'day').'</td>'."\n";
  656. if(! empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT)) {
  657. print '<td align="right">'.price($obj->total_ht).'</td>';
  658. }
  659. else {
  660. print '<td align="right">'.price($obj->total_ttc).'</td>';
  661. }
  662. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut,3).'</td>'."\n";
  663. print '</tr>'."\n";
  664. $i++;
  665. $total += $obj->total_ttc;
  666. }
  667. if ($num > $nbofloop)
  668. {
  669. print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
  670. }
  671. else if ($total>0)
  672. {
  673. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td><td>&nbsp;</td></tr>";
  674. }
  675. print "</table>";
  676. print "</div><br>";
  677. }
  678. }
  679. else
  680. {
  681. dol_print_error($db);
  682. }
  683. }
  684. /*
  685. * Opened Order
  686. */
  687. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  688. {
  689. $langs->load("orders");
  690. $sql = "SELECT s.nom as name, s.rowid, c.rowid as commandeid, c.total_ttc, c.total_ht, c.tva as total_tva, c.ref, c.ref_client, c.fk_statut, c.date_valid as dv, c.facture as billed";
  691. $sql.= ", s.code_client";
  692. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  693. $sql.= ", ".MAIN_DB_PREFIX."commande as c";
  694. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  695. $sql.= " WHERE c.fk_soc = s.rowid";
  696. $sql.= " AND c.entity IN (".getEntity('commande').")";
  697. $sql.= " AND (c.fk_statut = ".Commande::STATUS_VALIDATED." or c.fk_statut = ".Commande::STATUS_SHIPMENTONPROCESS.")";
  698. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  699. if ($socid) $sql.= " AND s.rowid = ".$socid;
  700. $sql.= " ORDER BY c.rowid DESC";
  701. $result=$db->query($sql);
  702. if ($result)
  703. {
  704. $total = 0;
  705. $num = $db->num_rows($result);
  706. $i = 0;
  707. if ($num > 0)
  708. {
  709. print '<div class="div-table-responsive-no-min">';
  710. print '<table class="noborder" width="100%">';
  711. print '<tr class="liste_titre"><th class="liste_titre" colspan="5">'.$langs->trans("OrdersOpened").' <a href="'.DOL_URL_ROOT.'/commande/list.php?viewstatut=1"><span class="badge">'.$num.'</span></th></tr>';
  712. $nbofloop=min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD)?500:$conf->global->MAIN_MAXLIST_OVERLOAD));
  713. while ($i < $nbofloop)
  714. {
  715. $obj = $db->fetch_object($result);
  716. print '<tr class="oddeven">';
  717. // Ref
  718. print '<td class="nowrap" width="140">';
  719. $orderstatic->id=$obj->commandeid;
  720. $orderstatic->ref=$obj->ref;
  721. $orderstatic->ref_client=$obj->ref_client;
  722. $orderstatic->total_ht = $obj->total_ht;
  723. $orderstatic->total_tva = $obj->total_tva;
  724. $orderstatic->total_ttc = $obj->total_ttc;
  725. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  726. print '<td class="nobordernopadding nowrap">';
  727. print $orderstatic->getNomUrl(1);
  728. print '</td>';
  729. print '<td width="18" class="nobordernopadding nowrap">';
  730. //if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  731. print '</td>';
  732. print '<td width="16" align="center" class="nobordernopadding">';
  733. $filename=dol_sanitizeFileName($obj->ref);
  734. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  735. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  736. print $formfile->getDocumentsLink($orderstatic->element, $filename, $filedir);
  737. print '</td></tr></table>';
  738. print "</td>";
  739. print '<td class="nowrap">';
  740. $companystatic->id=$obj->rowid;
  741. $companystatic->name=$obj->name;
  742. $companystatic->client=$obj->client;
  743. $companystatic->code_client = $obj->code_client;
  744. $companystatic->code_fournisseur = $obj->code_fournisseur;
  745. $companystatic->canvas=$obj->canvas;
  746. print $companystatic->getNomUrl(1, 'customer', 44);
  747. print '</td>';
  748. print '<td align="right">';
  749. print dol_print_date($db->jdate($obj->dp),'day').'</td>'."\n";
  750. if(! empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT)) {
  751. print '<td align="right">'.price($obj->total_ht).'</td>';
  752. }
  753. else {
  754. print '<td align="right">'.price($obj->total_ttc).'</td>';
  755. }
  756. print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut,$obj->billed,3).'</td>'."\n";
  757. print '</tr>'."\n";
  758. $i++;
  759. $total += $obj->total_ttc;
  760. }
  761. if ($num > $nbofloop)
  762. {
  763. print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
  764. }
  765. else if ($total>0)
  766. {
  767. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td><td>&nbsp;</td></tr>";
  768. }
  769. print "</table>";
  770. print "</div><br>";
  771. }
  772. }
  773. else
  774. {
  775. dol_print_error($db);
  776. }
  777. }
  778. print '</div></div></div>';
  779. // End of page
  780. llxFooter();
  781. $db->close();