index.php 41 KB

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