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