index.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/comm/index.php
  25. * \ingroup commercial
  26. * \brief Home page of commercial area
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  41. if (isModEnabled('ficheinter')) {
  42. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  43. }
  44. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  45. $hookmanager = new HookManager($db);
  46. $hookmanager->initHooks(array('commercialindex'));
  47. // Load translation files required by the page
  48. $langs->loadLangs(array("boxes", "commercial", "contracts", "orders", "propal", "supplier_proposal"));
  49. $action = GETPOST('action', 'aZ09');
  50. $bid = GETPOST('bid', 'int');
  51. // Securite acces client
  52. $socid = GETPOST('socid', 'int');
  53. if (isset($user->socid) && $user->socid > 0) {
  54. $action = '';
  55. $socid = $user->socid;
  56. }
  57. $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  58. $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
  59. $now = dol_now();
  60. //restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
  61. if (!$user->hasRight('propal', 'read') && !$user->hasRight('supplier_proposal', 'read') && !$user->hasRight('commande', 'read') && !$user->hasRight('fournisseur', 'commande', 'read')
  62. && !$user->hasRight('supplier_order', 'read') && !$user->hasRight('fichinter', 'read')) {
  63. accessforbidden();
  64. }
  65. /*
  66. * Actions
  67. */
  68. // None
  69. /*
  70. * View
  71. */
  72. $form = new Form($db);
  73. $formfile = new FormFile($db);
  74. $companystatic = new Societe($db);
  75. if (isModEnabled("propal")) {
  76. $propalstatic = new Propal($db);
  77. }
  78. if (isModEnabled('supplier_proposal')) {
  79. $supplierproposalstatic = new SupplierProposal($db);
  80. }
  81. if (isModEnabled('commande')) {
  82. $orderstatic = new Commande($db);
  83. }
  84. if (isModEnabled("supplier_order")) {
  85. $supplierorderstatic = new CommandeFournisseur($db);
  86. }
  87. if (isModEnabled('ficheinter')) {
  88. $fichinterstatic = new Fichinter($db);
  89. }
  90. llxHeader("", $langs->trans("CommercialArea"));
  91. print load_fiche_titre($langs->trans("CommercialArea"), '', 'commercial');
  92. print '<div class="fichecenter"><div class="fichethirdleft">';
  93. $tmp = getCustomerProposalPieChart($socid);
  94. if ($tmp) {
  95. print $tmp;
  96. print '<br>';
  97. }
  98. $tmp = getCustomerOrderPieChart($socid);
  99. if ($tmp) {
  100. print $tmp;
  101. print '<br>';
  102. }
  103. /*
  104. * Draft customer proposals
  105. */
  106. if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
  107. $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status";
  108. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  109. $sql .= ", s.code_client, s.code_compta, s.client";
  110. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  111. $sql .= ", s.logo, s.email, s.entity";
  112. $sql .= ", s.canvas";
  113. $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
  114. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  115. if (empty($user->rights->societe->client->voir) && !$socid) {
  116. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  117. }
  118. $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
  119. $sql .= " AND p.fk_soc = s.rowid";
  120. $sql .= " AND p.fk_statut = ".Propal::STATUS_DRAFT;
  121. if (empty($user->rights->societe->client->voir) && !$socid) {
  122. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  123. }
  124. if ($socid) {
  125. $sql .= " AND s.rowid = ".((int) $socid);
  126. }
  127. $resql = $db->query($sql);
  128. if ($resql) {
  129. $total = 0;
  130. $num = $db->num_rows($resql);
  131. $nbofloop = min($num, $maxofloop);
  132. startSimpleTable("ProposalsDraft", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
  133. if ($num > 0) {
  134. $i = 0;
  135. $othernb = 0;
  136. while ($i < $nbofloop) {
  137. $obj = $db->fetch_object($resql);
  138. if ($i >= $max) {
  139. $othernb++;
  140. $i++;
  141. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  142. continue;
  143. }
  144. $propalstatic->id = $obj->rowid;
  145. $propalstatic->ref = $obj->ref;
  146. $propalstatic->ref_client = $obj->ref_client;
  147. $propalstatic->total_ht = $obj->total_ht;
  148. $propalstatic->total_tva = $obj->total_tva;
  149. $propalstatic->total_ttc = $obj->total_ttc;
  150. $propalstatic->statut = $obj->status;
  151. $companystatic->id = $obj->socid;
  152. $companystatic->name = $obj->name;
  153. $companystatic->name_alias = $obj->name_alias;
  154. $companystatic->code_client = $obj->code_client;
  155. $companystatic->code_compta = $obj->code_compta;
  156. $companystatic->client = $obj->client;
  157. $companystatic->code_fournisseur = $obj->code_fournisseur;
  158. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  159. $companystatic->fournisseur = $obj->fournisseur;
  160. $companystatic->logo = $obj->logo;
  161. $companystatic->email = $obj->email;
  162. $companystatic->entity = $obj->entity;
  163. $companystatic->canvas = $obj->canvas;
  164. print '<tr class="oddeven">';
  165. print '<td class="nowraponall tdoverflowmax100">'.$propalstatic->getNomUrl(1).'</td>';
  166. print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  167. print '<td class="nowrap right tdamount amount">'.price((!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc)).'</td>';
  168. print '</tr>';
  169. $i++;
  170. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  171. }
  172. if ($othernb) {
  173. print '<tr class="oddeven">';
  174. print '<td class="nowrap" colspan="5">';
  175. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  176. print '</td>';
  177. print "</tr>\n";
  178. }
  179. }
  180. addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
  181. finishSimpleTable(true);
  182. $db->free($resql);
  183. } else {
  184. dol_print_error($db);
  185. }
  186. }
  187. /*
  188. * Draft supplier proposals
  189. */
  190. if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "lire")) {
  191. $sql = "SELECT p.rowid, p.ref, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status";
  192. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  193. $sql .= ", s.code_client, s.code_compta, s.client";
  194. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  195. $sql .= ", s.logo, s.email, s.entity";
  196. $sql .= ", s.canvas";
  197. $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p,";
  198. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  199. if (empty($user->rights->societe->client->voir) && !$socid) {
  200. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  201. }
  202. $sql .= " WHERE p.entity IN (".getEntity($supplierproposalstatic->element).")";
  203. $sql .= " AND p.fk_statut = ".SupplierProposal::STATUS_DRAFT;
  204. $sql .= " AND p.fk_soc = s.rowid";
  205. if (empty($user->rights->societe->client->voir) && !$socid) {
  206. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  207. }
  208. if ($socid) {
  209. $sql .= " AND s.rowid = ".((int) $socid);
  210. }
  211. $resql = $db->query($sql);
  212. if ($resql) {
  213. $total = 0;
  214. $num = $db->num_rows($resql);
  215. $nbofloop = min($num, $maxofloop);
  216. startSimpleTable("SupplierProposalsDraft", "supplier_proposal/list.php", "search_status=".SupplierProposal::STATUS_DRAFT, 2, $num);
  217. if ($num > 0) {
  218. $i = 0;
  219. $othernb = 0;
  220. while ($i < $nbofloop) {
  221. $obj = $db->fetch_object($resql);
  222. if ($i >= $max) {
  223. $othernb += 1;
  224. $i++;
  225. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  226. continue;
  227. }
  228. $supplierproposalstatic->id = $obj->rowid;
  229. $supplierproposalstatic->ref = $obj->ref;
  230. $supplierproposalstatic->total_ht = $obj->total_ht;
  231. $supplierproposalstatic->total_tva = $obj->total_tva;
  232. $supplierproposalstatic->total_ttc = $obj->total_ttc;
  233. $supplierproposalstatic->statut = $obj->status;
  234. $companystatic->id = $obj->socid;
  235. $companystatic->name = $obj->name;
  236. $companystatic->name_alias = $obj->name_alias;
  237. $companystatic->code_client = $obj->code_client;
  238. $companystatic->code_compta = $obj->code_compta;
  239. $companystatic->client = $obj->client;
  240. $companystatic->code_fournisseur = $obj->code_fournisseur;
  241. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  242. $companystatic->fournisseur = $obj->fournisseur;
  243. $companystatic->logo = $obj->logo;
  244. $companystatic->email = $obj->email;
  245. $companystatic->entity = $obj->entity;
  246. $companystatic->canvas = $obj->canvas;
  247. print '<tr class="oddeven">';
  248. print '<td class="nowraponall tdoverflowmax100">'.$supplierproposalstatic->getNomUrl(1).'</td>';
  249. print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
  250. print '<td class="nowrap right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  251. print '</tr>';
  252. $i++;
  253. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  254. }
  255. if ($othernb) {
  256. print '<tr class="oddeven">';
  257. print '<td class="nowrap" colspan="5">';
  258. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  259. print '</td>';
  260. print "</tr>\n";
  261. }
  262. }
  263. addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
  264. finishSimpleTable(true);
  265. $db->free($resql);
  266. } else {
  267. dol_print_error($db);
  268. }
  269. }
  270. /*
  271. * Draft sales orders
  272. */
  273. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  274. $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.total_tva, c.total_ttc, c.fk_statut as status";
  275. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  276. $sql .= ", s.code_client, s.code_compta, s.client";
  277. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  278. $sql .= ", s.logo, s.email, s.entity";
  279. $sql .= ", s.canvas";
  280. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
  281. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  282. if (empty($user->rights->societe->client->voir) && !$socid) {
  283. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  284. }
  285. $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
  286. $sql .= " AND c.fk_statut = ".Commande::STATUS_DRAFT;
  287. $sql .= " AND c.fk_soc = s.rowid";
  288. if (empty($user->rights->societe->client->voir) && !$socid) {
  289. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  290. }
  291. if ($socid) {
  292. $sql .= " AND c.fk_soc = ".((int) $socid);
  293. }
  294. $resql = $db->query($sql);
  295. if ($resql) {
  296. $total = 0;
  297. $num = $db->num_rows($resql);
  298. $nbofloop = min($num, $maxofloop);
  299. startSimpleTable("DraftOrders", "commande/list.php", "search_status=".Commande::STATUS_DRAFT, 2, $num);
  300. if ($num > 0) {
  301. $i = 0;
  302. $othernb = 0;
  303. while ($i < $nbofloop) {
  304. $obj = $db->fetch_object($resql);
  305. if ($i >= $max) {
  306. $othernb += 1;
  307. $i++;
  308. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  309. continue;
  310. }
  311. $orderstatic->id = $obj->rowid;
  312. $orderstatic->ref = $obj->ref;
  313. $orderstatic->ref_client = $obj->ref_client;
  314. $orderstatic->total_ht = $obj->total_ht;
  315. $orderstatic->total_tva = $obj->total_tva;
  316. $orderstatic->total_ttc = $obj->total_ttc;
  317. $orderstatic->statut = $obj->status;
  318. $companystatic->id = $obj->socid;
  319. $companystatic->name = $obj->name;
  320. $companystatic->name_alias = $obj->name_alias;
  321. $companystatic->code_client = $obj->code_client;
  322. $companystatic->code_compta = $obj->code_compta;
  323. $companystatic->client = $obj->client;
  324. $companystatic->code_fournisseur = $obj->code_fournisseur;
  325. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  326. $companystatic->fournisseur = $obj->fournisseur;
  327. $companystatic->logo = $obj->logo;
  328. $companystatic->email = $obj->email;
  329. $companystatic->entity = $obj->entity;
  330. $companystatic->canvas = $obj->canvas;
  331. print '<tr class="oddeven">';
  332. print '<td class="nowraponall tdoverflowmax100">'.$orderstatic->getNomUrl(1).'</td>';
  333. print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  334. print '<td class="nowrap right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  335. print '</tr>';
  336. $i++;
  337. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  338. }
  339. if ($othernb) {
  340. print '<tr class="oddeven">';
  341. print '<td class="nowrap" colspan="5">';
  342. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  343. print '</td>';
  344. print "</tr>\n";
  345. }
  346. }
  347. addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
  348. finishSimpleTable(true);
  349. $db->free($resql);
  350. } else {
  351. dol_print_error($db);
  352. }
  353. }
  354. /*
  355. * Draft purchase orders
  356. */
  357. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "commande", "lire")) || (isModEnabled("supplier_order") && $user->hasRight("supplier_order", "lire"))) {
  358. $sql = "SELECT cf.rowid, cf.ref, cf.ref_supplier, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_statut as status";
  359. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  360. $sql .= ", s.code_client, s.code_compta, s.client";
  361. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  362. $sql .= ", s.logo, s.email, s.entity";
  363. $sql .= ", s.canvas";
  364. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
  365. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  366. if (empty($user->rights->societe->client->voir) && !$socid) {
  367. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  368. }
  369. $sql .= " WHERE cf.entity IN (".getEntity($supplierorderstatic->element).")";
  370. $sql .= " AND cf.fk_statut = ".CommandeFournisseur::STATUS_DRAFT;
  371. $sql .= " AND cf.fk_soc = s.rowid";
  372. if (empty($user->rights->societe->client->voir) && !$socid) {
  373. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  374. }
  375. if ($socid) {
  376. $sql .= " AND cf.fk_soc = ".((int) $socid);
  377. }
  378. $resql = $db->query($sql);
  379. if ($resql) {
  380. $total = 0;
  381. $num = $db->num_rows($resql);
  382. $nbofloop = min($num, $maxofloop);
  383. startSimpleTable("DraftSuppliersOrders", "fourn/commande/list.php", "search_status=".CommandeFournisseur::STATUS_DRAFT, 2, $num);
  384. if ($num > 0) {
  385. $i = 0;
  386. $othernb = 0;
  387. while ($i < $nbofloop) {
  388. $obj = $db->fetch_object($resql);
  389. if ($i >= $max) {
  390. $othernb += 1;
  391. $i++;
  392. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  393. continue;
  394. }
  395. $supplierorderstatic->id = $obj->rowid;
  396. $supplierorderstatic->ref = $obj->ref;
  397. $supplierorderstatic->ref_supplier = $obj->ref_supplier;
  398. $supplierorderstatic->total_ht = $obj->total_ht;
  399. $supplierorderstatic->total_tva = $obj->total_tva;
  400. $supplierorderstatic->total_ttc = $obj->total_ttc;
  401. $supplierorderstatic->statut = $obj->status;
  402. $companystatic->id = $obj->socid;
  403. $companystatic->name = $obj->name;
  404. $companystatic->name_alias = $obj->name_alias;
  405. $companystatic->code_client = $obj->code_client;
  406. $companystatic->code_compta = $obj->code_compta;
  407. $companystatic->client = $obj->client;
  408. $companystatic->code_fournisseur = $obj->code_fournisseur;
  409. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  410. $companystatic->fournisseur = $obj->fournisseur;
  411. $companystatic->logo = $obj->logo;
  412. $companystatic->email = $obj->email;
  413. $companystatic->entity = $obj->entity;
  414. $companystatic->canvas = $obj->canvas;
  415. print '<tr class="oddeven">';
  416. print '<td class="nowraponall tdoverflowmax100">'.$supplierorderstatic->getNomUrl(1).'</td>';
  417. print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
  418. print '<td class="nowrap right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  419. print '</tr>';
  420. $i++;
  421. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  422. }
  423. if ($othernb) {
  424. print '<tr class="oddeven">';
  425. print '<td class="nowrap" colspan="5">';
  426. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  427. print '</td>';
  428. print "</tr>\n";
  429. }
  430. }
  431. addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
  432. finishSimpleTable(true);
  433. $db->free($resql);
  434. } else {
  435. dol_print_error($db);
  436. }
  437. }
  438. /*
  439. * Draft interventions
  440. */
  441. if (isModEnabled('ficheinter')) {
  442. $sql = "SELECT f.rowid, f.ref, s.nom as name, f.fk_statut, f.duree as duration";
  443. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  444. $sql .= ", s.code_client, s.code_compta, s.client";
  445. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  446. $sql .= ", s.logo, s.email, s.entity";
  447. $sql .= ", s.canvas";
  448. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  449. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  450. if (empty($user->rights->societe->client->voir) && !$socid) {
  451. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  452. }
  453. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  454. $sql .= " AND f.fk_soc = s.rowid";
  455. $sql .= " AND f.fk_statut = 0";
  456. if ($socid) {
  457. $sql .= " AND f.fk_soc = ".((int) $socid);
  458. }
  459. if (empty($user->rights->societe->client->voir) && !$socid) {
  460. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  461. }
  462. $resql = $db->query($sql);
  463. if ($resql) {
  464. $num = $db->num_rows($resql);
  465. $nbofloop = min($num, $maxofloop);
  466. startSimpleTable("DraftFichinter", "fichinter/list.php", "search_status=".Fichinter::STATUS_DRAFT, 2, $num);
  467. //print '<tr class="liste_titre">';
  468. //print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
  469. if ($num > 0) {
  470. $i = 0;
  471. while ($i < $nbofloop) {
  472. $obj = $db->fetch_object($resql);
  473. $fichinterstatic->id=$obj->rowid;
  474. $fichinterstatic->ref=$obj->ref;
  475. $fichinterstatic->statut=$obj->fk_statut;
  476. $companystatic->id = $obj->socid;
  477. $companystatic->name = $obj->name;
  478. $companystatic->name_alias = $obj->name_alias;
  479. $companystatic->code_client = $obj->code_client;
  480. $companystatic->code_compta = $obj->code_compta;
  481. $companystatic->client = $obj->client;
  482. $companystatic->code_fournisseur = $obj->code_fournisseur;
  483. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  484. $companystatic->fournisseur = $obj->fournisseur;
  485. $companystatic->logo = $obj->logo;
  486. $companystatic->email = $obj->email;
  487. $companystatic->entity = $obj->entity;
  488. $companystatic->canvas = $obj->canvas;
  489. print '<tr class="oddeven">';
  490. print '<td class="tdoverflowmax100">';
  491. print $fichinterstatic->getNomUrl(1);
  492. print "</td>";
  493. print '<td class="tdoverflowmax100">';
  494. print $companystatic->getNomUrl(1, 'customer');
  495. print '</td>';
  496. print '<td class="nowraponall tdoverflowmax100 right">';
  497. print convertSecondToTime($obj->duration);
  498. print '</td>';
  499. print '</tr>';
  500. $i++;
  501. }
  502. }
  503. addSummaryTableLine(3, $num, $nbofloop, $total, "NoIntervention");
  504. finishSimpleTable(true);
  505. print "</table></div>";
  506. }
  507. }
  508. print '</div><div class="fichetwothirdright">';
  509. /*
  510. * Last modified customers or prospects
  511. */
  512. if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
  513. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  514. $sql .= ", s.code_client, s.code_compta, s.client";
  515. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  516. $sql .= ", s.logo, s.email, s.entity";
  517. $sql .= ", s.canvas";
  518. $sql .= ", s.datec, s.tms";
  519. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  520. if (empty($user->rights->societe->client->voir) && !$socid) {
  521. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  522. }
  523. $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
  524. $sql .= " AND s.client IN (".Societe::CUSTOMER.", ".Societe::PROSPECT.", ".Societe::CUSTOMER_AND_PROSPECT.")";
  525. if (empty($user->rights->societe->client->voir) && !$socid) {
  526. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  527. }
  528. // Add where from hooks
  529. $parameters = array('socid' => $socid);
  530. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
  531. if (empty($reshook)) {
  532. if ($socid > 0) {
  533. $sql .= " AND s.rowid = ".((int) $socid);
  534. }
  535. }
  536. $sql .= $hookmanager->resPrint;
  537. $sql .= " ORDER BY s.tms DESC";
  538. $sql .= $db->plimit($max, 0);
  539. $resql = $db->query($sql);
  540. if ($resql) {
  541. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  542. $header = "BoxTitleLastCustomersOrProspects";
  543. } elseif (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  544. $header = "BoxTitleLastModifiedProspects";
  545. } else {
  546. $header = "BoxTitleLastModifiedCustomers";
  547. }
  548. $num = $db->num_rows($resql);
  549. startSimpleTable($langs->trans($header, min($max, $num)), "societe/list.php", "type=p,c", 1);
  550. if ($num) {
  551. $i = 0;
  552. while ($i < $num && $i < $max) {
  553. $objp = $db->fetch_object($resql);
  554. $companystatic->id = $objp->socid;
  555. $companystatic->name = $objp->name;
  556. $companystatic->name_alias = $objp->name_alias;
  557. $companystatic->code_client = $objp->code_client;
  558. $companystatic->code_compta = $objp->code_compta;
  559. $companystatic->client = $objp->client;
  560. $companystatic->code_fournisseur = $objp->code_fournisseur;
  561. $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  562. $companystatic->fournisseur = $objp->fournisseur;
  563. $companystatic->logo = $objp->logo;
  564. $companystatic->email = $objp->email;
  565. $companystatic->entity = $objp->entity;
  566. $companystatic->canvas = $objp->canvas;
  567. print '<tr class="oddeven">';
  568. print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  569. print '<td class="nowrap">';
  570. //print $companystatic->getLibCustProspStatut();
  571. $obj = $companystatic;
  572. $s = '';
  573. if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  574. $s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>';
  575. }
  576. if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  577. $s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>';
  578. }
  579. /*
  580. if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur)
  581. {
  582. $s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>';
  583. }*/
  584. print $s;
  585. print '</td>';
  586. $datem = $db->jdate($objp->tms);
  587. print '<td class="right nowrap tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  588. print dol_print_date($datem, 'day', 'tzuserrel');
  589. print '</td>';
  590. print '</tr>';
  591. $i++;
  592. }
  593. }
  594. addSummaryTableLine(3, $num);
  595. finishSimpleTable(true);
  596. $db->free($resql);
  597. } else {
  598. dol_print_error($db);
  599. }
  600. }
  601. /*
  602. * Last suppliers
  603. */
  604. if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->hasRight('societe', 'lire')) {
  605. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  606. $sql .= ", s.code_client, s.code_compta, s.client";
  607. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  608. $sql .= ", s.logo, s.email, s.entity";
  609. $sql .= ", s.canvas";
  610. $sql .= ", s.datec as dc, s.tms as dm";
  611. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  612. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  613. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  614. }
  615. $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
  616. $sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
  617. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  618. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  619. }
  620. // Add where from hooks
  621. $parameters = array('socid' => $socid);
  622. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
  623. if (empty($reshook)) {
  624. if ($socid > 0) {
  625. $sql .= " AND s.rowid = ".((int) $socid);
  626. }
  627. }
  628. $sql .= $hookmanager->resPrint;
  629. $sql .= " ORDER BY s.datec DESC";
  630. $sql .= $db->plimit($max, 0);
  631. $resql = $db->query($sql);
  632. if ($resql) {
  633. $num = $db->num_rows($resql);
  634. startSimpleTable($langs->trans("BoxTitleLastModifiedSuppliers", min($max, $num)), "societe/list.php", "type=f", 1);
  635. if ($num) {
  636. $i = 0;
  637. while ($i < $num && $i < $max) {
  638. $objp = $db->fetch_object($resql);
  639. $companystatic->id = $objp->socid;
  640. $companystatic->name = $objp->name;
  641. $companystatic->name_alias = $objp->name_alias;
  642. $companystatic->code_client = $objp->code_client;
  643. $companystatic->code_compta = $objp->code_compta;
  644. $companystatic->client = $objp->client;
  645. $companystatic->code_fournisseur = $objp->code_fournisseur;
  646. $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  647. $companystatic->fournisseur = $objp->fournisseur;
  648. $companystatic->logo = $objp->logo;
  649. $companystatic->email = $objp->email;
  650. $companystatic->entity = $objp->entity;
  651. $companystatic->canvas = $objp->canvas;
  652. print '<tr class="oddeven">';
  653. print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
  654. print '<td>';
  655. $obj = $companystatic;
  656. $s = '';
  657. /*if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  658. $s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>';
  659. }
  660. if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
  661. {
  662. $s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>';
  663. }*/
  664. if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur) {
  665. $s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>';
  666. }
  667. print $s;
  668. print '</td>';
  669. $datem = $db->jdate($objp->dm);
  670. print '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  671. print dol_print_date($datem, 'day', 'tzuserrel');
  672. print '</td>';
  673. print '</tr>';
  674. $i++;
  675. }
  676. }
  677. addSummaryTableLine(3, $num);
  678. finishSimpleTable(true);
  679. $db->free($resql);
  680. } else {
  681. dol_print_error($db);
  682. }
  683. }
  684. /*
  685. * Last actions
  686. */
  687. /*if ($user->hasRight('agenda', 'myactions', 'read')) {
  688. show_array_last_actions_done($max);
  689. }*/
  690. /*
  691. * Actions to do
  692. */
  693. /*if ($user->hasRight('agenda', 'myactions', 'read')) {
  694. show_array_actions_to_do($max);
  695. }*/
  696. /*
  697. * Latest contracts
  698. */
  699. if (isModEnabled('contrat') && $user->hasRight("contrat", "lire") && 0) { // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
  700. $staticcontrat = new Contrat($db);
  701. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  702. $sql .= ", s.code_client, s.code_compta, s.client";
  703. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  704. $sql .= ", s.logo, s.email, s.entity";
  705. $sql .= ", s.canvas";
  706. $sql .= ", c.statut, c.rowid as contratid, p.ref, c.fin_validite as datefin, c.date_cloture as dateclo";
  707. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  708. $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
  709. $sql .= ", ".MAIN_DB_PREFIX."product as p";
  710. if (empty($user->rights->societe->client->voir) && !$socid) {
  711. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  712. }
  713. $sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
  714. $sql .= " AND c.fk_soc = s.rowid";
  715. $sql .= " AND c.fk_product = p.rowid";
  716. if (empty($user->rights->societe->client->voir) && !$socid) {
  717. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  718. }
  719. if ($socid) {
  720. $sql .= " AND s.rowid = ".((int) $socid);
  721. }
  722. $sql .= " ORDER BY c.tms DESC";
  723. $sql .= $db->plimit($max + 1, 0);
  724. $resql = $db->query($sql);
  725. if ($resql) {
  726. $num = $db->num_rows($resql);
  727. startSimpleTable($langs->trans("LastContracts", $max), "", "", 2);
  728. if ($num > 0) {
  729. $i = 0;
  730. while ($i < $num) {
  731. $obj = $db->fetch_object($resql);
  732. $companystatic->id = $obj->socid;
  733. $companystatic->name = $obj->name;
  734. $companystatic->name_alias = $obj->name_alias;
  735. $companystatic->code_client = $obj->code_client;
  736. $companystatic->code_compta = $obj->code_compta;
  737. $companystatic->client = $obj->client;
  738. $companystatic->code_fournisseur = $obj->code_fournisseur;
  739. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  740. $companystatic->fournisseur = $obj->fournisseur;
  741. $companystatic->logo = $obj->logo;
  742. $companystatic->email = $obj->email;
  743. $companystatic->entity = $obj->entity;
  744. $companystatic->canvas = $obj->canvas;
  745. $staticcontrat->id = $obj->contratid;
  746. $staticcontrat->ref = $obj->ref;
  747. print '<tr class="oddeven">';
  748. print '<td class="nowraponall">'.$staticcontrat->getNomUrl(1).'</td>';
  749. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  750. print '<td class="right">'.$staticcontrat->LibStatut($obj->statut, 3).'</td>';
  751. print '</tr>';
  752. $i++;
  753. }
  754. }
  755. addSummaryTableLine(2, $num);
  756. finishSimpleTable(true);
  757. $db->free($resql);
  758. } else {
  759. dol_print_error($db);
  760. }
  761. }
  762. /*
  763. * Opened (validated) proposals
  764. */
  765. if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
  766. $sql = "SELECT p.rowid as propalid, p.entity, p.total_ttc, p.total_ht, p.total_tva, p.ref, p.ref_client, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
  767. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  768. $sql .= ", s.code_client, s.code_compta, s.client";
  769. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  770. $sql .= ", s.logo, s.email, s.entity";
  771. $sql .= ", s.canvas";
  772. $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
  773. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  774. if (empty($user->rights->societe->client->voir) && !$socid) {
  775. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  776. }
  777. $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
  778. $sql .= " AND p.fk_soc = s.rowid";
  779. $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
  780. if (empty($user->rights->societe->client->voir) && !$socid) {
  781. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  782. }
  783. if ($socid) {
  784. $sql .= " AND s.rowid = ".((int) $socid);
  785. }
  786. $sql .= " ORDER BY p.rowid DESC";
  787. $resql = $db->query($sql);
  788. if ($resql) {
  789. $total = $total_ttc = 0;
  790. $num = $db->num_rows($resql);
  791. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  792. startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=1", 4, $num);
  793. if ($num > 0) {
  794. $i = 0;
  795. $othernb = 0;
  796. while ($i < $nbofloop) {
  797. $obj = $db->fetch_object($resql);
  798. if ($i >= $max) {
  799. $othernb += 1;
  800. $i++;
  801. $total += $obj->total_ht;
  802. $total_ttc += $obj->total_ttc;
  803. continue;
  804. }
  805. $propalstatic->id = $obj->propalid;
  806. $propalstatic->ref = $obj->ref;
  807. $propalstatic->ref_client = $obj->ref_client;
  808. $propalstatic->total_ht = $obj->total_ht;
  809. $propalstatic->total_tva = $obj->total_tva;
  810. $propalstatic->total_ttc = $obj->total_ttc;
  811. $companystatic->id = $obj->socid;
  812. $companystatic->name = $obj->name;
  813. $companystatic->name_alias = $obj->name_alias;
  814. $companystatic->code_client = $obj->code_client;
  815. $companystatic->code_compta = $obj->code_compta;
  816. $companystatic->client = $obj->client;
  817. $companystatic->code_fournisseur = $obj->code_fournisseur;
  818. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  819. $companystatic->fournisseur = $obj->fournisseur;
  820. $companystatic->logo = $obj->logo;
  821. $companystatic->email = $obj->email;
  822. $companystatic->entity = $obj->entity;
  823. $companystatic->canvas = $obj->canvas;
  824. $filename = dol_sanitizeFileName($obj->ref);
  825. $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  826. //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  827. $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
  828. print '<tr class="oddeven">';
  829. print '<td class="nowrap" width="140">';
  830. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  831. print '<td class="nobordernopadding nowraponall">'.$propalstatic->getNomUrl(1).'</td>';
  832. print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
  833. print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
  834. print '</tr>';
  835. print '</table>';
  836. print '</td>';
  837. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  838. $datem = $db->jdate($obj->dp);
  839. print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("Date").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
  840. print dol_print_date($datem, 'day', 'tzserver');
  841. print '</td>';
  842. print '<td class="right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  843. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
  844. print '</tr>';
  845. $i++;
  846. $total += $obj->total_ht;
  847. $total_ttc += $obj->total_ttc;
  848. }
  849. if ($othernb) {
  850. print '<tr class="oddeven">';
  851. print '<td class="nowrap" colspan="5">';
  852. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  853. print '</td>';
  854. print "</tr>\n";
  855. }
  856. }
  857. addSummaryTableLine(5, $num, $nbofloop, empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $total_ttc : $total, "NoProposal", true);
  858. finishSimpleTable(true);
  859. $db->free($resql);
  860. } else {
  861. dol_print_error($db);
  862. }
  863. }
  864. /*
  865. * Opened (validated) order
  866. */
  867. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  868. $sql = "SELECT c.rowid as commandeid, c.total_ttc, c.total_ht, c.total_tva, c.ref, c.ref_client, c.fk_statut, c.date_valid as dv, c.facture as billed";
  869. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  870. $sql .= ", s.code_client, s.code_compta, s.client";
  871. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  872. $sql .= ", s.logo, s.email, s.entity";
  873. $sql .= ", s.canvas";
  874. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
  875. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  876. if (empty($user->rights->societe->client->voir) && !$socid) {
  877. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  878. }
  879. $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
  880. $sql .= " AND c.fk_soc = s.rowid";
  881. $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
  882. if (empty($user->rights->societe->client->voir) && !$socid) {
  883. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  884. }
  885. if ($socid) {
  886. $sql .= " AND s.rowid = ".((int) $socid);
  887. }
  888. $sql .= " ORDER BY c.rowid DESC";
  889. $resql = $db->query($sql);
  890. if ($resql) {
  891. $total = $total_ttc = 0;
  892. $num = $db->num_rows($resql);
  893. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  894. startSimpleTable("OrdersOpened", "commande/list.php", "search_status=".Commande::STATUS_VALIDATED, 4, $num);
  895. if ($num > 0) {
  896. $i = 0;
  897. $othernb = 0;
  898. while ($i < $nbofloop) {
  899. $obj = $db->fetch_object($resql);
  900. if ($i >= $max) {
  901. $othernb += 1;
  902. $i++;
  903. $total += $obj->total_ht;
  904. $total_ttc += $obj->total_ttc;
  905. continue;
  906. }
  907. $orderstatic->id = $obj->commandeid;
  908. $orderstatic->ref = $obj->ref;
  909. $orderstatic->ref_client = $obj->ref_client;
  910. $orderstatic->statut = $obj->fk_statut;
  911. $orderstatic->total_ht = $obj->total_ht;
  912. $orderstatic->total_tva = $obj->total_tva;
  913. $orderstatic->total_ttc = $obj->total_ttc;
  914. $companystatic->id = $obj->socid;
  915. $companystatic->name = $obj->name;
  916. $companystatic->name_alias = $obj->name_alias;
  917. $companystatic->code_client = $obj->code_client;
  918. $companystatic->code_compta = $obj->code_compta;
  919. $companystatic->client = $obj->client;
  920. $companystatic->code_fournisseur = $obj->code_fournisseur;
  921. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  922. $companystatic->fournisseur = $obj->fournisseur;
  923. $companystatic->logo = $obj->logo;
  924. $companystatic->email = $obj->email;
  925. $companystatic->entity = $obj->entity;
  926. $companystatic->canvas = $obj->canvas;
  927. $filename = dol_sanitizeFileName($obj->ref);
  928. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  929. //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  930. //$warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
  931. print '<tr class="oddeven">';
  932. print '<td class="nowrap" width="140">';
  933. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  934. print '<td class="nobordernopadding nowraponall">'.$orderstatic->getNomUrl(1).'</td>';
  935. print '<td width="18" class="nobordernopadding nowrap"></td>';
  936. print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($orderstatic->element, $filename, $filedir).'</td>';
  937. print '</tr>';
  938. print '</table>';
  939. print '</td>';
  940. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  941. $datem = $db->jdate($obj->dv);
  942. print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("DateValue").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
  943. print dol_print_date($datem, 'day', 'tzserver');
  944. print '</td>';
  945. print '<td class="right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  946. print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut, $obj->billed, 3).'</td>';
  947. print '</tr>';
  948. $i++;
  949. $total += $obj->total_ht;
  950. $total_ttc += $obj->total_ttc;
  951. }
  952. if ($othernb) {
  953. print '<tr class="oddeven">';
  954. print '<td class="nowrap" colspan="5">';
  955. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  956. print '</td>';
  957. print "</tr>\n";
  958. }
  959. }
  960. addSummaryTableLine(5, $num, $nbofloop, empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $total_ttc : $total, "None", true);
  961. finishSimpleTable(true);
  962. $db->free($resql);
  963. } else {
  964. dol_print_error($db);
  965. }
  966. }
  967. print '</div>';
  968. print '</div>';
  969. $parameters = array('user' => $user);
  970. $reshook = $hookmanager->executeHooks('dashboardCommercials', $parameters, $object); // Note that $action and $object may have been modified by hook
  971. // End of page
  972. llxFooter();
  973. $db->close();