index.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || 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->rights->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";
  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="nowraponall tdoverflowmax100">';
  491. print $fichinterstatic->getNomUrl(1);
  492. print "</td>";
  493. print '<td class="nowrap tdoverflowmax100">';
  494. print $companystatic->getNomUrl(1, 'customer');
  495. print '</td></tr>';
  496. $i++;
  497. }
  498. }
  499. addSummaryTableLine(3, $num, $nbofloop, $total, "NoIntervention");
  500. finishSimpleTable(true);
  501. print "</table></div>";
  502. }
  503. }
  504. print '</div><div class="fichetwothirdright">';
  505. /*
  506. * Last modified customers or prospects
  507. */
  508. if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
  509. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  510. $sql .= ", s.code_client, s.code_compta, s.client";
  511. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  512. $sql .= ", s.logo, s.email, s.entity";
  513. $sql .= ", s.canvas";
  514. $sql .= ", s.datec, s.tms";
  515. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  516. if (empty($user->rights->societe->client->voir) && !$socid) {
  517. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  518. }
  519. $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
  520. $sql .= " AND s.client IN (".Societe::CUSTOMER.", ".Societe::PROSPECT.", ".Societe::CUSTOMER_AND_PROSPECT.")";
  521. if (empty($user->rights->societe->client->voir) && !$socid) {
  522. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  523. }
  524. // Add where from hooks
  525. $parameters = array('socid' => $socid);
  526. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
  527. if (empty($reshook)) {
  528. if ($socid > 0) {
  529. $sql .= " AND s.rowid = ".((int) $socid);
  530. }
  531. }
  532. $sql .= $hookmanager->resPrint;
  533. $sql .= " ORDER BY s.tms DESC";
  534. $sql .= $db->plimit($max, 0);
  535. $resql = $db->query($sql);
  536. if ($resql) {
  537. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  538. $header = "BoxTitleLastCustomersOrProspects";
  539. } elseif (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  540. $header = "BoxTitleLastModifiedProspects";
  541. } else {
  542. $header = "BoxTitleLastModifiedCustomers";
  543. }
  544. $num = $db->num_rows($resql);
  545. startSimpleTable($langs->trans($header, min($max, $num)), "societe/list.php", "type=p,c", 1);
  546. if ($num) {
  547. $i = 0;
  548. while ($i < $num && $i < $max) {
  549. $objp = $db->fetch_object($resql);
  550. $companystatic->id = $objp->socid;
  551. $companystatic->name = $objp->name;
  552. $companystatic->name_alias = $objp->name_alias;
  553. $companystatic->code_client = $objp->code_client;
  554. $companystatic->code_compta = $objp->code_compta;
  555. $companystatic->client = $objp->client;
  556. $companystatic->code_fournisseur = $objp->code_fournisseur;
  557. $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  558. $companystatic->fournisseur = $objp->fournisseur;
  559. $companystatic->logo = $objp->logo;
  560. $companystatic->email = $objp->email;
  561. $companystatic->entity = $objp->entity;
  562. $companystatic->canvas = $objp->canvas;
  563. print '<tr class="oddeven">';
  564. print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  565. print '<td class="nowrap">';
  566. //print $companystatic->getLibCustProspStatut();
  567. $obj = $companystatic;
  568. $s = '';
  569. if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  570. $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>';
  571. }
  572. if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  573. $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>';
  574. }
  575. /*
  576. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur)
  577. {
  578. $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>';
  579. }*/
  580. print $s;
  581. print '</td>';
  582. $datem = $db->jdate($objp->tms);
  583. print '<td class="right nowrap tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  584. print dol_print_date($datem, 'day', 'tzuserrel');
  585. print '</td>';
  586. print '</tr>';
  587. $i++;
  588. }
  589. }
  590. addSummaryTableLine(3, $num);
  591. finishSimpleTable(true);
  592. $db->free($resql);
  593. } else {
  594. dol_print_error($db);
  595. }
  596. }
  597. /*
  598. * Last suppliers
  599. */
  600. if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->hasRight('societe', 'lire')) {
  601. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  602. $sql .= ", s.code_client, s.code_compta, s.client";
  603. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  604. $sql .= ", s.logo, s.email, s.entity";
  605. $sql .= ", s.canvas";
  606. $sql .= ", s.datec as dc, s.tms as dm";
  607. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  608. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  609. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  610. }
  611. $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
  612. $sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
  613. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  614. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  615. }
  616. // Add where from hooks
  617. $parameters = array('socid' => $socid);
  618. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
  619. if (empty($reshook)) {
  620. if ($socid > 0) {
  621. $sql .= " AND s.rowid = ".((int) $socid);
  622. }
  623. }
  624. $sql .= $hookmanager->resPrint;
  625. $sql .= " ORDER BY s.datec DESC";
  626. $sql .= $db->plimit($max, 0);
  627. $resql = $db->query($sql);
  628. if ($resql) {
  629. $num = $db->num_rows($resql);
  630. startSimpleTable($langs->trans("BoxTitleLastModifiedSuppliers", min($max, $num)), "societe/list.php", "type=f", 1);
  631. if ($num) {
  632. $i = 0;
  633. while ($i < $num && $i < $max) {
  634. $objp = $db->fetch_object($resql);
  635. $companystatic->id = $objp->socid;
  636. $companystatic->name = $objp->name;
  637. $companystatic->name_alias = $objp->name_alias;
  638. $companystatic->code_client = $objp->code_client;
  639. $companystatic->code_compta = $objp->code_compta;
  640. $companystatic->client = $objp->client;
  641. $companystatic->code_fournisseur = $objp->code_fournisseur;
  642. $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  643. $companystatic->fournisseur = $objp->fournisseur;
  644. $companystatic->logo = $objp->logo;
  645. $companystatic->email = $objp->email;
  646. $companystatic->entity = $objp->entity;
  647. $companystatic->canvas = $objp->canvas;
  648. print '<tr class="oddeven">';
  649. print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
  650. print '<td>';
  651. $obj = $companystatic;
  652. $s = '';
  653. /*if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  654. $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>';
  655. }
  656. if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
  657. {
  658. $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>';
  659. }*/
  660. if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur) {
  661. $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>';
  662. }
  663. print $s;
  664. print '</td>';
  665. $datem = $db->jdate($objp->dm);
  666. print '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
  667. print dol_print_date($datem, 'day', 'tzuserrel');
  668. print '</td>';
  669. print '</tr>';
  670. $i++;
  671. }
  672. }
  673. addSummaryTableLine(3, $num);
  674. finishSimpleTable(true);
  675. $db->free($resql);
  676. } else {
  677. dol_print_error($db);
  678. }
  679. }
  680. /*
  681. * Last actions
  682. */
  683. /*if ($user->rights->agenda->myactions->read) {
  684. show_array_last_actions_done($max);
  685. }*/
  686. /*
  687. * Actions to do
  688. */
  689. /*if ($user->rights->agenda->myactions->read) {
  690. show_array_actions_to_do($max);
  691. }*/
  692. /*
  693. * Latest contracts
  694. */
  695. if (isModEnabled('contrat') && $user->hasRight("contrat", "lire") && 0) { // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
  696. $staticcontrat = new Contrat($db);
  697. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  698. $sql .= ", s.code_client, s.code_compta, s.client";
  699. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  700. $sql .= ", s.logo, s.email, s.entity";
  701. $sql .= ", s.canvas";
  702. $sql .= ", c.statut, c.rowid as contratid, p.ref, c.fin_validite as datefin, c.date_cloture as dateclo";
  703. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  704. $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
  705. $sql .= ", ".MAIN_DB_PREFIX."product as p";
  706. if (empty($user->rights->societe->client->voir) && !$socid) {
  707. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  708. }
  709. $sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
  710. $sql .= " AND c.fk_soc = s.rowid";
  711. $sql .= " AND c.fk_product = p.rowid";
  712. if (empty($user->rights->societe->client->voir) && !$socid) {
  713. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  714. }
  715. if ($socid) {
  716. $sql .= " AND s.rowid = ".((int) $socid);
  717. }
  718. $sql .= " ORDER BY c.tms DESC";
  719. $sql .= $db->plimit($max + 1, 0);
  720. $resql = $db->query($sql);
  721. if ($resql) {
  722. $num = $db->num_rows($resql);
  723. startSimpleTable($langs->trans("LastContracts", $max), "", "", 2);
  724. if ($num > 0) {
  725. $i = 0;
  726. while ($i < $num) {
  727. $obj = $db->fetch_object($resql);
  728. $companystatic->id = $obj->socid;
  729. $companystatic->name = $obj->name;
  730. $companystatic->name_alias = $obj->name_alias;
  731. $companystatic->code_client = $obj->code_client;
  732. $companystatic->code_compta = $obj->code_compta;
  733. $companystatic->client = $obj->client;
  734. $companystatic->code_fournisseur = $obj->code_fournisseur;
  735. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  736. $companystatic->fournisseur = $obj->fournisseur;
  737. $companystatic->logo = $obj->logo;
  738. $companystatic->email = $obj->email;
  739. $companystatic->entity = $obj->entity;
  740. $companystatic->canvas = $obj->canvas;
  741. $staticcontrat->id = $obj->contratid;
  742. $staticcontrat->ref = $obj->ref;
  743. print '<tr class="oddeven">';
  744. print '<td class="nowraponall">'.$staticcontrat->getNomUrl(1).'</td>';
  745. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  746. print '<td class="right">'.$staticcontrat->LibStatut($obj->statut, 3).'</td>';
  747. print '</tr>';
  748. $i++;
  749. }
  750. }
  751. addSummaryTableLine(2, $num);
  752. finishSimpleTable(true);
  753. $db->free($resql);
  754. } else {
  755. dol_print_error($db);
  756. }
  757. }
  758. /*
  759. * Opened (validated) proposals
  760. */
  761. if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
  762. $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";
  763. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  764. $sql .= ", s.code_client, s.code_compta, s.client";
  765. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  766. $sql .= ", s.logo, s.email, s.entity";
  767. $sql .= ", s.canvas";
  768. $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
  769. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  770. if (empty($user->rights->societe->client->voir) && !$socid) {
  771. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  772. }
  773. $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
  774. $sql .= " AND p.fk_soc = s.rowid";
  775. $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
  776. if (empty($user->rights->societe->client->voir) && !$socid) {
  777. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  778. }
  779. if ($socid) {
  780. $sql .= " AND s.rowid = ".((int) $socid);
  781. }
  782. $sql .= " ORDER BY p.rowid DESC";
  783. $resql = $db->query($sql);
  784. if ($resql) {
  785. $total = $total_ttc = 0;
  786. $num = $db->num_rows($resql);
  787. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  788. startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=1", 4, $num);
  789. if ($num > 0) {
  790. $i = 0;
  791. $othernb = 0;
  792. while ($i < $nbofloop) {
  793. $obj = $db->fetch_object($resql);
  794. if ($i >= $max) {
  795. $othernb += 1;
  796. $i++;
  797. $total += $obj->total_ht;
  798. $total_ttc += $obj->total_ttc;
  799. continue;
  800. }
  801. $propalstatic->id = $obj->propalid;
  802. $propalstatic->ref = $obj->ref;
  803. $propalstatic->ref_client = $obj->ref_client;
  804. $propalstatic->total_ht = $obj->total_ht;
  805. $propalstatic->total_tva = $obj->total_tva;
  806. $propalstatic->total_ttc = $obj->total_ttc;
  807. $companystatic->id = $obj->socid;
  808. $companystatic->name = $obj->name;
  809. $companystatic->name_alias = $obj->name_alias;
  810. $companystatic->code_client = $obj->code_client;
  811. $companystatic->code_compta = $obj->code_compta;
  812. $companystatic->client = $obj->client;
  813. $companystatic->code_fournisseur = $obj->code_fournisseur;
  814. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  815. $companystatic->fournisseur = $obj->fournisseur;
  816. $companystatic->logo = $obj->logo;
  817. $companystatic->email = $obj->email;
  818. $companystatic->entity = $obj->entity;
  819. $companystatic->canvas = $obj->canvas;
  820. $filename = dol_sanitizeFileName($obj->ref);
  821. $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  822. //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  823. $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
  824. print '<tr class="oddeven">';
  825. print '<td class="nowrap" width="140">';
  826. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  827. print '<td class="nobordernopadding nowraponall">'.$propalstatic->getNomUrl(1).'</td>';
  828. print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
  829. print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
  830. print '</tr>';
  831. print '</table>';
  832. print '</td>';
  833. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  834. $datem = $db->jdate($obj->dp);
  835. print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("Date").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
  836. print dol_print_date($datem, 'day', 'tzserver');
  837. print '</td>';
  838. print '<td class="right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  839. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
  840. print '</tr>';
  841. $i++;
  842. $total += $obj->total_ht;
  843. $total_ttc += $obj->total_ttc;
  844. }
  845. if ($othernb) {
  846. print '<tr class="oddeven">';
  847. print '<td class="nowrap" colspan="5">';
  848. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  849. print '</td>';
  850. print "</tr>\n";
  851. }
  852. }
  853. addSummaryTableLine(5, $num, $nbofloop, empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $total_ttc : $total, "NoProposal", true);
  854. finishSimpleTable(true);
  855. $db->free($resql);
  856. } else {
  857. dol_print_error($db);
  858. }
  859. }
  860. /*
  861. * Opened (validated) order
  862. */
  863. if (isModEnabled('commande') && $user->rights->commande->lire) {
  864. $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";
  865. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  866. $sql .= ", s.code_client, s.code_compta, s.client";
  867. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  868. $sql .= ", s.logo, s.email, s.entity";
  869. $sql .= ", s.canvas";
  870. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
  871. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  872. if (empty($user->rights->societe->client->voir) && !$socid) {
  873. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  874. }
  875. $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
  876. $sql .= " AND c.fk_soc = s.rowid";
  877. $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
  878. if (empty($user->rights->societe->client->voir) && !$socid) {
  879. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  880. }
  881. if ($socid) {
  882. $sql .= " AND s.rowid = ".((int) $socid);
  883. }
  884. $sql .= " ORDER BY c.rowid DESC";
  885. $resql = $db->query($sql);
  886. if ($resql) {
  887. $total = $total_ttc = 0;
  888. $num = $db->num_rows($resql);
  889. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  890. startSimpleTable("OrdersOpened", "commande/list.php", "search_status=".Commande::STATUS_VALIDATED, 4, $num);
  891. if ($num > 0) {
  892. $i = 0;
  893. $othernb = 0;
  894. while ($i < $nbofloop) {
  895. $obj = $db->fetch_object($resql);
  896. if ($i >= $max) {
  897. $othernb += 1;
  898. $i++;
  899. $total += $obj->total_ht;
  900. $total_ttc += $obj->total_ttc;
  901. continue;
  902. }
  903. $orderstatic->id = $obj->commandeid;
  904. $orderstatic->ref = $obj->ref;
  905. $orderstatic->ref_client = $obj->ref_client;
  906. $orderstatic->statut = $obj->fk_statut;
  907. $orderstatic->total_ht = $obj->total_ht;
  908. $orderstatic->total_tva = $obj->total_tva;
  909. $orderstatic->total_ttc = $obj->total_ttc;
  910. $companystatic->id = $obj->socid;
  911. $companystatic->name = $obj->name;
  912. $companystatic->name_alias = $obj->name_alias;
  913. $companystatic->code_client = $obj->code_client;
  914. $companystatic->code_compta = $obj->code_compta;
  915. $companystatic->client = $obj->client;
  916. $companystatic->code_fournisseur = $obj->code_fournisseur;
  917. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  918. $companystatic->fournisseur = $obj->fournisseur;
  919. $companystatic->logo = $obj->logo;
  920. $companystatic->email = $obj->email;
  921. $companystatic->entity = $obj->entity;
  922. $companystatic->canvas = $obj->canvas;
  923. $filename = dol_sanitizeFileName($obj->ref);
  924. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  925. //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  926. //$warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
  927. print '<tr class="oddeven">';
  928. print '<td class="nowrap" width="140">';
  929. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  930. print '<td class="nobordernopadding nowraponall">'.$orderstatic->getNomUrl(1).'</td>';
  931. print '<td width="18" class="nobordernopadding nowrap"></td>';
  932. print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($orderstatic->element, $filename, $filedir).'</td>';
  933. print '</tr>';
  934. print '</table>';
  935. print '</td>';
  936. print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
  937. $datem = $db->jdate($obj->dv);
  938. print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("DateValue").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
  939. print dol_print_date($datem, 'day', 'tzserver');
  940. print '</td>';
  941. print '<td class="right tdamount amount">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  942. print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut, $obj->billed, 3).'</td>';
  943. print '</tr>';
  944. $i++;
  945. $total += $obj->total_ht;
  946. $total_ttc += $obj->total_ttc;
  947. }
  948. if ($othernb) {
  949. print '<tr class="oddeven">';
  950. print '<td class="nowrap" colspan="5">';
  951. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  952. print '</td>';
  953. print "</tr>\n";
  954. }
  955. }
  956. addSummaryTableLine(5, $num, $nbofloop, empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $total_ttc : $total, "None", true);
  957. finishSimpleTable(true);
  958. $db->free($resql);
  959. } else {
  960. dol_print_error($db);
  961. }
  962. }
  963. print '</div>';
  964. print '</div>';
  965. $parameters = array('user' => $user);
  966. $reshook = $hookmanager->executeHooks('dashboardCommercials', $parameters, $object); // Note that $action and $object may have been modified by hook
  967. // End of page
  968. llxFooter();
  969. $db->close();