index.php 41 KB

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