index.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015-2020 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  10. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/compta/index.php
  27. * \ingroup compta
  28. * \brief Main page of accountancy area
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.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.'/compta/sociales/class/chargesociales.class.php';
  37. // L'espace compta/treso doit toujours etre actif car c'est un espace partage
  38. // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
  39. // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
  40. // est protegee par le droit qui va bien du module concerne.
  41. //if (!$user->rights->compta->general->lire)
  42. // accessforbidden();
  43. // Load translation files required by the page
  44. $langs->loadLangs(array('compta', 'bills'));
  45. if (!empty($conf->commande->enabled))
  46. $langs->load("orders");
  47. $action = GETPOST('action', 'alpha');
  48. $bid = GETPOST('bid', 'int');
  49. // Security check
  50. $socid = '';
  51. if ($user->socid > 0)
  52. {
  53. $action = '';
  54. $socid = $user->socid;
  55. }
  56. $max = 3;
  57. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  58. $hookmanager->initHooks(array('invoiceindex'));
  59. /*
  60. * Actions
  61. */
  62. /*
  63. * View
  64. */
  65. $now = dol_now();
  66. $facturestatic = new Facture($db);
  67. $facturesupplierstatic = new FactureFournisseur($db);
  68. $form = new Form($db);
  69. $formfile = new FormFile($db);
  70. $thirdpartystatic = new Societe($db);
  71. llxHeader("", $langs->trans("AccountancyTreasuryArea"));
  72. print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', 'bill');
  73. print '<div class="fichecenter"><div class="fichethirdleft">';
  74. if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  75. {
  76. // Search customer invoices
  77. if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
  78. {
  79. $listofsearchfields['search_invoice'] = array('text'=>'CustomerInvoice');
  80. }
  81. // Search supplier invoices
  82. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->lire)
  83. {
  84. $listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice');
  85. }
  86. if (!empty($conf->don->enabled) && $user->rights->don->lire)
  87. {
  88. $langs->load("donations");
  89. $listofsearchfields['search_donation'] = array('text'=>'Donation');
  90. }
  91. if (count($listofsearchfields))
  92. {
  93. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  94. print '<input type="hidden" name="token" value="'.newToken().'">';
  95. print '<div class="div-table-responsive-no-min">';
  96. print '<table class="noborder nohover centpercent">';
  97. $i = 0;
  98. foreach ($listofsearchfields as $key => $value)
  99. {
  100. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  101. print '<tr '.$bc[false].'>';
  102. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'"></td>';
  103. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  104. print '</tr>';
  105. $i++;
  106. }
  107. print '</table>';
  108. print '</div>';
  109. print '</form>';
  110. print '<br>';
  111. }
  112. }
  113. /**
  114. * Draft customers invoices
  115. */
  116. if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
  117. {
  118. $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.ref_client";
  119. $sql .= ", f.type";
  120. $sql .= ", s.nom as name";
  121. $sql .= ", s.rowid as socid, s.email";
  122. $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
  123. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
  124. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
  125. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  126. $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
  127. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  128. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  129. if ($socid)
  130. {
  131. $sql .= " AND f.fk_soc = $socid";
  132. }
  133. // Add where from hooks
  134. $parameters = array();
  135. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
  136. $sql .= $hookmanager->resPrint;
  137. $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total, f.tva, f.total_ttc, f.ref_client, f.type, ";
  138. $sql .= "s.email, s.nom, s.rowid, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
  139. // Add Group from hooks
  140. $parameters = array();
  141. $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
  142. $sql .= $hookmanager->resPrint;
  143. $resql = $db->query($sql);
  144. if ($resql)
  145. {
  146. $num = $db->num_rows($resql);
  147. print '<div class="div-table-responsive-no-min">';
  148. print '<table class="noborder centpercent">';
  149. print '<tr class="liste_titre">';
  150. print '<th colspan="3">';
  151. print $langs->trans("CustomersDraftInvoices").' ';
  152. print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
  153. print '<span class="badge marginleftonlyshort">'.$num.'</span>';
  154. print '</a>';
  155. print '</th>';
  156. print '</tr>';
  157. if ($num)
  158. {
  159. $companystatic = new Societe($db);
  160. $i = 0;
  161. $tot_ttc = 0;
  162. while ($i < $num)
  163. {
  164. $obj = $db->fetch_object($resql);
  165. $facturestatic->id = $obj->rowid;
  166. $facturestatic->ref = $obj->ref;
  167. $facturestatic->date = $db->jdate($obj->date);
  168. $facturestatic->type = $obj->type;
  169. $facturestatic->total_ht = $obj->total_ht;
  170. $facturestatic->total_tva = $obj->total_tva;
  171. $facturestatic->total_ttc = $obj->total_ttc;
  172. $facturestatic->ref_client = $obj->ref_client;
  173. $companystatic->id = $obj->socid;
  174. $companystatic->name = $obj->name;
  175. $companystatic->email = $obj->email;
  176. $companystatic->client = 1;
  177. $companystatic->code_client = $obj->code_client;
  178. $companystatic->code_fournisseur = $obj->code_fournisseur;
  179. $companystatic->code_compta = $obj->code_compta;
  180. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  181. print '<tr class="oddeven"><td class="nowrap">';
  182. print $facturestatic->getNomUrl(1, '');
  183. print '</td>';
  184. print '<td class="nowrap">';
  185. print $companystatic->getNomUrl(1, 'customer', 16);
  186. print '</td>';
  187. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  188. print '</tr>';
  189. $tot_ttc += $obj->total_ttc;
  190. $i++;
  191. }
  192. print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
  193. print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
  194. print '</tr>';
  195. } else {
  196. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  197. }
  198. print "</table></div><br>";
  199. $db->free($resql);
  200. } else {
  201. dol_print_error($db);
  202. }
  203. }
  204. /**
  205. * Draft suppliers invoices
  206. */
  207. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
  208. {
  209. $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier";
  210. $sql .= ", s.nom as name";
  211. $sql .= ", s.rowid as socid, s.email";
  212. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
  213. $sql .= ", cc.rowid as country_id, cc.code as country_code";
  214. $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
  215. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  216. $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
  217. $sql .= " AND f.entity IN (".getEntity('invoice').')';
  218. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  219. if ($socid) $sql .= " AND f.fk_soc = ".$socid;
  220. // Add where from hooks
  221. $parameters = array();
  222. $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
  223. $sql .= $hookmanager->resPrint;
  224. $resql = $db->query($sql);
  225. if ($resql)
  226. {
  227. $num = $db->num_rows($resql);
  228. print '<div class="div-table-responsive-no-min">';
  229. print '<table class="noborder centpercent">';
  230. print '<tr class="liste_titre">';
  231. print '<th colspan="3">';
  232. print $langs->trans("SuppliersDraftInvoices").' ';
  233. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
  234. print '<span class="badge marginleftonlyshort">'.$num.'</span>';
  235. print '</a>';
  236. print '</th>';
  237. print '</tr>';
  238. if ($num)
  239. {
  240. $companystatic = new Societe($db);
  241. $i = 0;
  242. $tot_ttc = 0;
  243. while ($i < $num)
  244. {
  245. $obj = $db->fetch_object($resql);
  246. $facturesupplierstatic->ref = $obj->ref;
  247. $facturesupplierstatic->id = $obj->rowid;
  248. $facturesupplierstatic->total_ht = $obj->total_ht;
  249. $facturesupplierstatic->total_tva = $obj->total_tva;
  250. $facturesupplierstatic->total_ttc = $obj->total_ttc;
  251. $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
  252. $facturesupplierstatic->type = $obj->type;
  253. $companystatic->id = $obj->socid;
  254. $companystatic->name = $obj->name;
  255. $companystatic->email = $obj->email;
  256. $companystatic->country_id = $obj->country_id;
  257. $companystatic->country_code = $obj->country_code;
  258. $companystatic->fournisseur = 1;
  259. $companystatic->code_client = $obj->code_client;
  260. $companystatic->code_fournisseur = $obj->code_fournisseur;
  261. $companystatic->code_compta = $obj->code_compta;
  262. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  263. print '<tr class="oddeven"><td class="nowrap">';
  264. print $facturesupplierstatic->getNomUrl(1, '', 16);
  265. print '</td>';
  266. print '<td>';
  267. print $companystatic->getNomUrl(1, 'supplier', 16);
  268. print '</td>';
  269. print '<td class="right">'.price($obj->total_ttc).'</td>';
  270. print '</tr>';
  271. $tot_ttc += $obj->total_ttc;
  272. $i++;
  273. }
  274. print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
  275. print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
  276. print '</tr>';
  277. } else {
  278. print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  279. }
  280. print "</table></div><br>";
  281. $db->free($resql);
  282. } else {
  283. dol_print_error($db);
  284. }
  285. }
  286. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  287. // Latest modified customer invoices
  288. if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
  289. {
  290. $langs->load("boxes");
  291. $facstatic = new Facture($db);
  292. $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms";
  293. $sql .= ", f.date_lim_reglement as datelimite";
  294. $sql .= ", s.nom as name";
  295. $sql .= ", s.rowid as socid";
  296. $sql .= ", s.code_client, s.code_compta, s.email";
  297. $sql .= ", cc.rowid as country_id, cc.code as country_code";
  298. $sql .= ", sum(pf.amount) as am";
  299. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays, ".MAIN_DB_PREFIX."facture as f";
  300. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
  301. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  302. $sql .= " WHERE s.rowid = f.fk_soc";
  303. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  304. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  305. if ($socid) $sql .= " AND f.fk_soc = ".$socid;
  306. // Add where from hooks
  307. $parameters = array();
  308. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
  309. $sql .= $hookmanager->resPrint;
  310. $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
  311. $sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
  312. $sql .= " cc.rowid, cc.code";
  313. $sql .= " ORDER BY f.tms DESC";
  314. $sql .= $db->plimit($max, 0);
  315. $resql = $db->query($sql);
  316. if ($resql)
  317. {
  318. $num = $db->num_rows($resql);
  319. $i = 0;
  320. print '<div class="div-table-responsive-no-min">';
  321. print '<table class="noborder centpercent">';
  322. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
  323. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  324. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  325. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  326. print '<th width="16">&nbsp;</th>';
  327. print '</tr>';
  328. if ($num)
  329. {
  330. $total_ttc = $totalam = $total = 0;
  331. while ($i < $num && $i < $conf->liste_limit)
  332. {
  333. $obj = $db->fetch_object($resql);
  334. $facturestatic->ref = $obj->ref;
  335. $facturestatic->id = $obj->rowid;
  336. $facturestatic->total_ht = $obj->total_ht;
  337. $facturestatic->total_tva = $obj->total_tva;
  338. $facturestatic->total_ttc = $obj->total_ttc;
  339. $facturestatic->statut = $obj->fk_statut;
  340. $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
  341. $facturestatic->type = $obj->type;
  342. $thirdpartystatic->id = $obj->socid;
  343. $thirdpartystatic->name = $obj->name;
  344. $thirdpartystatic->email = $obj->email;
  345. $thirdpartystatic->country_id = $obj->country_id;
  346. $thirdpartystatic->country_code = $obj->country_code;
  347. $thirdpartystatic->email = $obj->email;
  348. $thirdpartystatic->client = 1;
  349. $thirdpartystatic->code_client = $obj->code_client;
  350. //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
  351. $thirdpartystatic->code_compta = $obj->code_compta;
  352. //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  353. print '<tr class="oddeven">';
  354. print '<td class="nowrap">';
  355. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  356. print '<td class="nobordernopadding nowraponall">';
  357. print $facturestatic->getNomUrl(1, '');
  358. print '</td>';
  359. print '<td width="20" class="nobordernopadding nowrap">';
  360. if ($facturestatic->hasDelay()) {
  361. print img_warning($langs->trans("Late"));
  362. }
  363. print '</td>';
  364. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  365. $filename = dol_sanitizeFileName($obj->ref);
  366. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  367. $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
  368. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  369. print '</td></tr></table>';
  370. print '</td>';
  371. print '<td class="left">';
  372. print $thirdpartystatic->getNomUrl(1, 'customer', 44);
  373. print '</td>';
  374. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="nowrap right">'.price($obj->total_ht).'</td>';
  375. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  376. print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
  377. print '<td>'.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3, $obj->am).'</td>';
  378. print '</tr>';
  379. $total_ttc += $obj->total_ttc;
  380. $total += $obj->total_ht;
  381. $totalam += $obj->am;
  382. $i++;
  383. }
  384. } else {
  385. $colspan = 5;
  386. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
  387. print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  388. }
  389. print '</table></div><br>';
  390. $db->free($resql);
  391. } else {
  392. dol_print_error($db);
  393. }
  394. }
  395. // Last modified supplier invoices
  396. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
  397. {
  398. $langs->load("boxes");
  399. $facstatic = new FactureFournisseur($db);
  400. $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye";
  401. $sql .= ", s.nom as name";
  402. $sql .= ", s.rowid as socid";
  403. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
  404. $sql .= ", SUM(pf.amount) as am";
  405. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
  406. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
  407. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  408. $sql .= " WHERE s.rowid = ff.fk_soc";
  409. $sql .= " AND ff.entity = ".$conf->entity;
  410. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  411. if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
  412. // Add where from hooks
  413. $parameters = array();
  414. $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
  415. $sql .= $hookmanager->resPrint;
  416. $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye,";
  417. $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
  418. $sql .= " ORDER BY ff.tms DESC ";
  419. $sql .= $db->plimit($max, 0);
  420. $resql = $db->query($sql);
  421. if ($resql)
  422. {
  423. $num = $db->num_rows($resql);
  424. print '<div class="div-table-responsive-no-min">';
  425. print '<table class="noborder centpercent">';
  426. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
  427. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  428. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  429. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  430. print '<th width="16">&nbsp;</th>';
  431. print "</tr>\n";
  432. if ($num)
  433. {
  434. $i = 0;
  435. $total = $total_ttc = $totalam = 0;
  436. while ($i < $num)
  437. {
  438. $obj = $db->fetch_object($resql);
  439. $facstatic->ref = $obj->ref;
  440. $facstatic->id = $obj->rowid;
  441. $facstatic->total_ht = $obj->total_ht;
  442. $facstatic->total_tva = $obj->total_tva;
  443. $facstatic->total_ttc = $obj->total_ttc;
  444. $thirdpartystatic->id = $obj->socid;
  445. $thirdpartystatic->name = $obj->name;
  446. $thirdpartystatic->email = $obj->email;
  447. $thirdpartystatic->country_id = 0;
  448. $thirdpartystatic->country_code = '';
  449. $thirdpartystatic->client = 0;
  450. $thirdpartystatic->fournisseur = 1;
  451. $thirdpartystatic->code_client = '';
  452. $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
  453. $thirdpartystatic->code_compta = '';
  454. $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  455. print '<tr class="oddeven nowraponall"><td>';
  456. print $facstatic->getNomUrl(1, '');
  457. print '</td>';
  458. print '<td>';
  459. print $thirdpartystatic->getNomUrl(1, 'supplier', 44);
  460. print '</td>';
  461. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
  462. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  463. print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
  464. print '<td>'.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3).'</td>';
  465. print '</tr>';
  466. $total += $obj->total_ht;
  467. $total_ttc += $obj->total_ttc;
  468. $totalam += $obj->am;
  469. $i++;
  470. }
  471. } else {
  472. $colspan = 5;
  473. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
  474. print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  475. }
  476. print '</table></div><br>';
  477. } else {
  478. dol_print_error($db);
  479. }
  480. }
  481. // Latest donations
  482. if (!empty($conf->don->enabled) && $user->rights->don->lire)
  483. {
  484. include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  485. $langs->load("boxes");
  486. $donationstatic = new Don($db);
  487. $sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut";
  488. $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
  489. $sql .= " WHERE d.entity IN (".getEntity('donation').")";
  490. // Add where from hooks
  491. $parameters = array();
  492. $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
  493. $sql .= $hookmanager->resPrint;
  494. $sql .= $db->order("d.tms", "DESC");
  495. $sql .= $db->plimit($max, 0);
  496. $result = $db->query($sql);
  497. if ($result)
  498. {
  499. $var = false;
  500. $num = $db->num_rows($result);
  501. $i = 0;
  502. print '<div class="div-table-responsive-no-min">';
  503. print '<table class="noborder centpercent">';
  504. print '<tr class="liste_titre">';
  505. print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
  506. print '<th></th>';
  507. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  508. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  509. print '<th width="16">&nbsp;</th>';
  510. print '</tr>';
  511. if ($num)
  512. {
  513. $total_ttc = $totalam = $total = 0;
  514. while ($i < $num && $i < $max)
  515. {
  516. $objp = $db->fetch_object($result);
  517. $donationstatic->id = $objp->rowid;
  518. $donationstatic->ref = $objp->rowid;
  519. $donationstatic->lastname = $objp->lastname;
  520. $donationstatic->firstname = $objp->firstname;
  521. $label = $donationstatic->getFullName($langs);
  522. if ($objp->societe) $label .= ($label ? ' - ' : '').$objp->societe;
  523. print '<tr class="oddeven">';
  524. print '<td>'.$donationstatic->getNomUrl(1).'</td>';
  525. print '<td>'.$label.'</td>';
  526. print '<td class="nowrap right">'.price($objp->amount).'</td>';
  527. print '<td class="right">'.dol_print_date($db->jdate($objp->dm), 'day').'</td>';
  528. print '<td>'.$donationstatic->LibStatut($objp->fk_statut, 3).'</td>';
  529. print '</tr>';
  530. $i++;
  531. }
  532. } else {
  533. print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  534. }
  535. print '</table></div><br>';
  536. } else dol_print_error($db);
  537. }
  538. /**
  539. * Social contributions to pay
  540. */
  541. if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
  542. {
  543. if (!$socid)
  544. {
  545. $chargestatic = new ChargeSociales($db);
  546. $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
  547. $sql .= " cc.libelle as label,";
  548. $sql .= " SUM(pc.amount) as sumpaid";
  549. $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
  550. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
  551. $sql .= " WHERE c.fk_type = cc.id";
  552. $sql .= " AND c.entity IN (".getEntity('tax').')';
  553. $sql .= " AND c.paye = 0";
  554. // Add where from hooks
  555. $parameters = array();
  556. $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
  557. $sql .= $hookmanager->resPrint;
  558. $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
  559. $resql = $db->query($sql);
  560. if ($resql)
  561. {
  562. $num = $db->num_rows($resql);
  563. print '<div class="div-table-responsive-no-min">';
  564. print '<table class="noborder centpercent">';
  565. print '<tr class="liste_titre">';
  566. print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
  567. print '<th align="center">'.$langs->trans("DateDue").'</th>';
  568. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  569. print '<th class="right">'.$langs->trans("Paid").'</th>';
  570. print '<th align="center" width="16">&nbsp;</th>';
  571. print '</tr>';
  572. if ($num)
  573. {
  574. $i = 0;
  575. $tot_ttc = 0;
  576. while ($i < $num)
  577. {
  578. $obj = $db->fetch_object($resql);
  579. $chargestatic->id = $obj->rowid;
  580. $chargestatic->ref = $obj->rowid;
  581. $chargestatic->label = $obj->label;
  582. $chargestatic->paye = $obj->paye;
  583. print '<tr class="oddeven">';
  584. print '<td>'.$chargestatic->getNomUrl(1).'</td>';
  585. print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
  586. print '<td class="nowrap right">'.price($obj->amount).'</td>';
  587. print '<td class="nowrap right">'.price($obj->sumpaid).'</td>';
  588. print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
  589. print '</tr>';
  590. $tot_ttc += $obj->amount;
  591. $i++;
  592. }
  593. print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
  594. print '<td class="nowrap right">'.price($tot_ttc).'</td>';
  595. print '<td class="right"></td>';
  596. print '<td class="right">&nbsp;</td>';
  597. print '</tr>';
  598. } else {
  599. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  600. }
  601. print "</table></div><br>";
  602. $db->free($resql);
  603. } else {
  604. dol_print_error($db);
  605. }
  606. }
  607. }
  608. /*
  609. * Customers orders to be billed
  610. */
  611. if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user->rights->commande->lire && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
  612. {
  613. $commandestatic = new Commande($db);
  614. $langs->load("orders");
  615. $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc";
  616. $sql .= ", s.nom as name, s.email";
  617. $sql .= ", s.rowid as socid";
  618. $sql .= ", s.code_client, s.code_compta";
  619. $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.tva as total_tva, c.total_ttc,";
  620. $sql .= " cc.rowid as country_id, cc.code as country_code";
  621. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
  622. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  623. $sql .= ", ".MAIN_DB_PREFIX."commande as c";
  624. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
  625. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
  626. $sql .= " WHERE c.fk_soc = s.rowid";
  627. $sql .= " AND c.entity = ".$conf->entity;
  628. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  629. if ($socid) $sql .= " AND c.fk_soc = ".$socid;
  630. $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
  631. $sql .= " AND c.facture = 0";
  632. // Add where from hooks
  633. $parameters = array();
  634. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
  635. $sql .= $hookmanager->resPrint;
  636. $sql .= " GROUP BY s.nom, s.email, s.rowid, s.code_client, s.code_compta, c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.tva, c.total_ttc, cc.rowid, cc.code";
  637. $resql = $db->query($sql);
  638. if ($resql)
  639. {
  640. $num = $db->num_rows($resql);
  641. if ($num)
  642. {
  643. $i = 0;
  644. print '<div class="div-table-responsive-no-min">';
  645. print '<table class="noborder centpercent">';
  646. print "<tr class=\"liste_titre\">";
  647. print '<th colspan="2">';
  648. print $langs->trans("OrdersDeliveredToBill").' ';
  649. print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
  650. print '<span class="badge">'.$num.'</span>';
  651. print '</a>';
  652. print '</th>';
  653. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  654. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  655. print '<th class="right">'.$langs->trans("ToBill").'</th>';
  656. print '<th align="center" width="16">&nbsp;</th>';
  657. print '</tr>';
  658. $tot_ht = $tot_ttc = $tot_tobill = 0;
  659. $societestatic = new Societe($db);
  660. while ($i < $num)
  661. {
  662. $obj = $db->fetch_object($resql);
  663. $societestatic->id = $obj->socid;
  664. $societestatic->name = $obj->name;
  665. $societestatic->email = $obj->email;
  666. $societestatic->country_id = $obj->country_id;
  667. $societestatic->country_code = $obj->country_code;
  668. $societestatic->client = 1;
  669. $societestatic->code_client = $obj->code_client;
  670. //$societestatic->code_fournisseur = $obj->code_fournisseur;
  671. $societestatic->code_compta = $obj->code_compta;
  672. //$societestatic->code_fournisseur = $obj->code_fournisseur;
  673. $commandestatic->id = $obj->rowid;
  674. $commandestatic->ref = $obj->ref;
  675. print '<tr class="oddeven">';
  676. print '<td class="nowrap">';
  677. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  678. print '<td width="110" class="nobordernopadding nowrap">';
  679. print $commandestatic->getNomUrl(1);
  680. print '</td>';
  681. print '<td width="20" class="nobordernopadding nowrap">';
  682. print '&nbsp;';
  683. print '</td>';
  684. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  685. $filename = dol_sanitizeFileName($obj->ref);
  686. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  687. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  688. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  689. print '</td></tr></table>';
  690. print '</td>';
  691. print '<td class="left">';
  692. print $societestatic->getNomUrl(1, 'customer', 44);
  693. print '</td>';
  694. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
  695. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  696. print '<td class="nowrap right">'.price($obj->total_ttc - $obj->tot_fttc).'</td>';
  697. print '<td>'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
  698. print '</tr>';
  699. $tot_ht += $obj->total_ht;
  700. $tot_ttc += $obj->total_ttc;
  701. //print "x".$tot_ttc."z".$obj->tot_fttc;
  702. $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
  703. $i++;
  704. }
  705. print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</font> </td>';
  706. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($tot_ht).'</td>';
  707. print '<td class="nowrap right">'.price($tot_ttc).'</td>';
  708. print '<td class="nowrap right">'.price($tot_tobill).'</td>';
  709. print '<td>&nbsp;</td>';
  710. print '</tr>';
  711. print '</table></div><br>';
  712. }
  713. $db->free($resql);
  714. } else {
  715. dol_print_error($db);
  716. }
  717. }
  718. /*
  719. * Unpaid customers invoices
  720. */
  721. if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
  722. {
  723. $facstatic = new Facture($db);
  724. $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms";
  725. $sql .= ", f.date_lim_reglement as datelimite";
  726. $sql .= ", s.nom as name";
  727. $sql .= ", s.rowid as socid, s.email";
  728. $sql .= ", s.code_client, s.code_compta";
  729. $sql .= ", cc.rowid as country_id, cc.code as country_code";
  730. $sql .= ", sum(pf.amount) as am";
  731. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays,".MAIN_DB_PREFIX."facture as f";
  732. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
  733. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  734. $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
  735. $sql .= " AND f.entity IN (".getEntity('invoice').')';
  736. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  737. if ($socid) $sql .= " AND f.fk_soc = ".$socid;
  738. // Add where from hooks
  739. $parameters = array();
  740. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
  741. $sql .= $hookmanager->resPrint;
  742. $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
  743. $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
  744. $sql .= " ORDER BY f.datef ASC, f.ref ASC";
  745. $resql = $db->query($sql);
  746. if ($resql)
  747. {
  748. $num = $db->num_rows($resql);
  749. $i = 0;
  750. print '<div class="div-table-responsive-no-min">';
  751. print '<table class="noborder centpercent">';
  752. print '<tr class="liste_titre">';
  753. print '<th colspan="2">';
  754. print $langs->trans("BillsCustomersUnpaid", $num).' ';
  755. print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
  756. print '<span class="badge">'.$num.'</span>';
  757. print '</a>';
  758. print '</th>';
  759. print '<th class="right">'.$langs->trans("DateDue").'</th>';
  760. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  761. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  762. print '<th class="right">'.$langs->trans("Received").'</th>';
  763. print '<th width="16">&nbsp;</th>';
  764. print '</tr>';
  765. if ($num)
  766. {
  767. $societestatic = new Societe($db);
  768. $total_ttc = $totalam = $total = 0;
  769. while ($i < $num && $i < $conf->liste_limit)
  770. {
  771. $obj = $db->fetch_object($resql);
  772. $facturestatic->ref = $obj->ref;
  773. $facturestatic->id = $obj->rowid;
  774. $facturestatic->total_ht = $obj->total_ht;
  775. $facturestatic->total_tva = $obj->total_tva;
  776. $facturestatic->total_ttc = $obj->total_ttc;
  777. $facturestatic->type = $obj->type;
  778. $facturestatic->statut = $obj->fk_statut;
  779. $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
  780. $societestatic->id = $obj->socid;
  781. $societestatic->name = $obj->name;
  782. $societestatic->email = $obj->email;
  783. $societestatic->country_id = $obj->country_id;
  784. $societestatic->country_code = $obj->country_code;
  785. $societestatic->client = 1;
  786. $societestatic->code_client = $obj->code_client;
  787. $societestatic->code_fournisseur = $obj->code_fournisseur;
  788. $societestatic->code_compta = $obj->code_compta;
  789. $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  790. print '<tr class="oddeven">';
  791. print '<td class="nowrap">';
  792. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  793. print '<td width="110" class="nobordernopadding nowrap">';
  794. print $facturestatic->getNomUrl(1, '');
  795. print '</td>';
  796. print '<td width="20" class="nobordernopadding nowrap">';
  797. if ($facturestatic->hasDelay()) {
  798. print img_warning($langs->trans("Late"));
  799. }
  800. print '</td>';
  801. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  802. $filename = dol_sanitizeFileName($obj->ref);
  803. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  804. $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
  805. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  806. print '</td></tr></table>';
  807. print '</td>';
  808. print '<td class="left">';
  809. print $societestatic->getNomUrl(1, 'customer', 44);
  810. print '</td>';
  811. print '<td class="right">'.dol_print_date($db->jdate($obj->datelimite), 'day').'</td>';
  812. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
  813. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  814. print '<td class="nowrap right">'.price($obj->am).'</td>';
  815. print '<td>'.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3, $obj->am).'</td>';
  816. print '</tr>';
  817. $total_ttc += $obj->total_ttc;
  818. $total += $obj->total_ht;
  819. $totalam += $obj->am;
  820. $i++;
  821. }
  822. print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')</font> </td>';
  823. print '<td>&nbsp;</td>';
  824. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
  825. print '<td class="nowrap right">'.price($total_ttc).'</td>';
  826. print '<td class="nowrap right">'.price($totalam).'</td>';
  827. print '<td>&nbsp;</td>';
  828. print '</tr>';
  829. } else {
  830. $colspan = 6;
  831. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
  832. print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  833. }
  834. print '</table></div><br>';
  835. $db->free($resql);
  836. } else {
  837. dol_print_error($db);
  838. }
  839. }
  840. /*
  841. * Unpayed supplier invoices
  842. */
  843. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
  844. {
  845. $facstatic = new FactureFournisseur($db);
  846. $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
  847. $sql .= ", ff.date_lim_reglement";
  848. $sql .= ", s.nom as name";
  849. $sql .= ", s.rowid as socid, s.email";
  850. $sql .= ", s.code_client, s.code_compta";
  851. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
  852. $sql .= ", sum(pf.amount) as am";
  853. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
  854. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
  855. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  856. $sql .= " WHERE s.rowid = ff.fk_soc";
  857. $sql .= " AND ff.entity = ".$conf->entity;
  858. $sql .= " AND ff.paye = 0";
  859. $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
  860. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  861. if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
  862. // Add where from hooks
  863. $parameters = array();
  864. $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
  865. $sql .= $hookmanager->resPrint;
  866. $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,";
  867. $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
  868. $sql .= " ORDER BY ff.date_lim_reglement ASC";
  869. $resql = $db->query($sql);
  870. if ($resql)
  871. {
  872. $num = $db->num_rows($resql);
  873. print '<div class="div-table-responsive-no-min">';
  874. print '<table class="noborder centpercent">';
  875. print '<tr class="liste_titre">';
  876. print '<th colspan="2">';
  877. print $langs->trans("BillsSuppliersUnpaid", $num).' ';
  878. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
  879. // TODO: "impayees.php" looks very outdatetd and should be set to deprecated or directly remove in the next version
  880. // <a href="'.DOL_URL_ROOT.'/fourn/facture/impayees.php">
  881. print '<span class="badge">'.$num.'</span>';
  882. print '</a>';
  883. print '</th>';
  884. print '<th class="right">'.$langs->trans("DateDue").'</th>';
  885. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  886. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  887. print '<th class="right">'.$langs->trans("Paid").'</th>';
  888. print '<th width="16">&nbsp;</th>';
  889. print "</tr>\n";
  890. $societestatic = new Societe($db);
  891. if ($num)
  892. {
  893. $i = 0;
  894. $total = $total_ttc = $totalam = 0;
  895. while ($i < $num)
  896. {
  897. $obj = $db->fetch_object($resql);
  898. $facstatic->ref = $obj->ref;
  899. $facstatic->id = $obj->rowid;
  900. $facstatic->total_ht = $obj->total_ht;
  901. $facstatic->total_tva = $obj->total_tva;
  902. $facstatic->total_ttc = $obj->total_ttc;
  903. $societestatic->id = $obj->socid;
  904. $societestatic->name = $obj->name;
  905. $societestatic->email = $obj->email;
  906. $societestatic->client = 0;
  907. $societestatic->fournisseur = 1;
  908. $societestatic->code_client = $obj->code_client;
  909. $societestatic->code_fournisseur = $obj->code_fournisseur;
  910. $societestatic->code_compta = $obj->code_compta;
  911. $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  912. print '<tr class="oddeven"><td>';
  913. print $facstatic->getNomUrl(1, '');
  914. print '</td>';
  915. print '<td>'.$societestatic->getNomUrl(1, 'supplier', 44).'</td>';
  916. print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
  917. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
  918. print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
  919. print '<td class="nowrap right">'.price($obj->am).'</td>';
  920. print '<td>'.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3).'</td>';
  921. print '</tr>';
  922. $total += $obj->total_ht;
  923. $total_ttc += $obj->total_ttc;
  924. $totalam += $obj->am;
  925. $i++;
  926. }
  927. print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')</font> </td>';
  928. print '<td>&nbsp;</td>';
  929. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
  930. print '<td class="nowrap right">'.price($total_ttc).'</td>';
  931. print '<td class="nowrap right">'.price($totalam).'</td>';
  932. print '<td>&nbsp;</td>';
  933. print '</tr>';
  934. } else {
  935. $colspan = 6;
  936. if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
  937. print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
  938. }
  939. print '</table></div><br>';
  940. } else {
  941. dol_print_error($db);
  942. }
  943. }
  944. // TODO Mettre ici recup des actions en rapport avec la compta
  945. $resql = 0;
  946. if ($resql)
  947. {
  948. print '<div class="div-table-responsive-no-min">';
  949. print '<table class="noborder centpercent">';
  950. print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
  951. print "</tr>\n";
  952. $i = 0;
  953. while ($i < $db->num_rows($resql))
  954. {
  955. $obj = $db->fetch_object($resql);
  956. print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
  957. print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
  958. $i++;
  959. }
  960. $db->free($resql);
  961. print "</table></div><br>";
  962. }
  963. print '</div></div></div>';
  964. $parameters = array('user' => $user);
  965. $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
  966. // End of page
  967. llxFooter();
  968. $db->close();