index.php 36 KB

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