index.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2022 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. * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
  12. * Copyright (C) 2021-2023 Frédéric France <frederic.france@netlogic.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/compta/index.php
  29. * \ingroup compta
  30. * \brief Main page of accountancy area
  31. */
  32. // Load Dolibarr environment
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  42. // L'espace compta/treso doit toujours etre actif car c'est un espace partage
  43. // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
  44. // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
  45. // est protegee par le droit qui va bien du module concerne.
  46. //if (!$user->rights->compta->general->lire)
  47. // accessforbidden();
  48. // Load translation files required by the page
  49. $langs->loadLangs(array('compta', 'bills'));
  50. if (isModEnabled('commande')) {
  51. $langs->load("orders");
  52. }
  53. // Get parameters
  54. $action = GETPOST('action', 'aZ09');
  55. $bid = GETPOST('bid', 'int');
  56. // Security check
  57. $socid = '';
  58. if ($user->socid > 0) {
  59. $action = '';
  60. $socid = $user->socid;
  61. }
  62. $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
  63. // Maximum elements of the tables
  64. $maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
  65. $maxLatestEditCount = 5;
  66. $maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
  67. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  68. $hookmanager->initHooks(array('invoiceindex'));
  69. $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
  70. /*
  71. * Actions
  72. */
  73. // None
  74. /*
  75. * View
  76. */
  77. $now = dol_now();
  78. $form = new Form($db);
  79. $formfile = new FormFile($db);
  80. $thirdpartystatic = new Societe($db);
  81. llxHeader("", $langs->trans("InvoicesArea"));
  82. print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
  83. print '<div class="fichecenter"><div class="fichethirdleft">';
  84. if (isModEnabled('facture')) {
  85. print getNumberInvoicesPieChart('customers');
  86. print '<br>';
  87. }
  88. if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
  89. print getNumberInvoicesPieChart('suppliers');
  90. print '<br>';
  91. }
  92. if (isModEnabled('facture')) {
  93. print getCustomerInvoiceDraftTable($max, $socid);
  94. print '<br>';
  95. }
  96. if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
  97. print getDraftSupplierTable($max, $socid);
  98. print '<br>';
  99. }
  100. print '</div><div class="fichetwothirdright">';
  101. // Latest modified customer invoices
  102. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  103. $langs->load("boxes");
  104. $tmpinvoice = new Facture($db);
  105. $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
  106. $sql .= ", f.date_lim_reglement as datelimite";
  107. $sql .= ", s.nom as name";
  108. $sql .= ", s.rowid as socid";
  109. $sql .= ", s.code_client, s.code_compta, s.email";
  110. $sql .= ", cc.rowid as country_id, cc.code as country_code";
  111. $sql .= ", sum(pf.amount) as am";
  112. $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";
  113. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
  114. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  115. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  116. }
  117. $sql .= " WHERE s.rowid = f.fk_soc";
  118. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  119. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  120. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  121. }
  122. if ($socid) {
  123. $sql .= " AND f.fk_soc = ".((int) $socid);
  124. }
  125. // Add where from hooks
  126. $parameters = array();
  127. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
  128. $sql .= $hookmanager->resPrint;
  129. $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
  130. $sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
  131. $sql .= " cc.rowid, cc.code";
  132. $sql .= " ORDER BY f.tms DESC";
  133. $sql .= $db->plimit($max, 0);
  134. $resql = $db->query($sql);
  135. if ($resql) {
  136. $num = $db->num_rows($resql);
  137. $i = 0;
  138. $othernb = 0;
  139. print '<div class="div-table-responsive-no-min">';
  140. print '<table class="noborder centpercent">';
  141. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
  142. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  143. print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  144. }
  145. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  146. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  147. print '<th width="16">&nbsp;</th>';
  148. print '</tr>';
  149. if ($num) {
  150. $total_ttc = $totalam = $total_ht = 0;
  151. while ($i < $num && $i < $conf->liste_limit) {
  152. $obj = $db->fetch_object($resql);
  153. if ($i >= $max) {
  154. $othernb += 1;
  155. $i++;
  156. $total_ht += $obj->total_ht;
  157. $total_ttc += $obj->total_ttc;
  158. continue;
  159. }
  160. $tmpinvoice->ref = $obj->ref;
  161. $tmpinvoice->id = $obj->rowid;
  162. $tmpinvoice->total_ht = $obj->total_ht;
  163. $tmpinvoice->total_tva = $obj->total_tva;
  164. $tmpinvoice->total_ttc = $obj->total_ttc;
  165. $tmpinvoice->statut = $obj->status;
  166. $tmpinvoice->paye = $obj->paye;
  167. $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
  168. $tmpinvoice->type = $obj->type;
  169. $thirdpartystatic->id = $obj->socid;
  170. $thirdpartystatic->name = $obj->name;
  171. $thirdpartystatic->email = $obj->email;
  172. $thirdpartystatic->country_id = $obj->country_id;
  173. $thirdpartystatic->country_code = $obj->country_code;
  174. $thirdpartystatic->email = $obj->email;
  175. $thirdpartystatic->client = 1;
  176. $thirdpartystatic->code_client = $obj->code_client;
  177. //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
  178. $thirdpartystatic->code_compta = $obj->code_compta;
  179. //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  180. print '<tr class="oddeven">';
  181. print '<td class="nowrap">';
  182. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  183. print '<td class="nobordernopadding nowraponall">';
  184. print $tmpinvoice->getNomUrl(1, '');
  185. print '</td>';
  186. if ($tmpinvoice->hasDelay()) {
  187. print '<td width="20" class="nobordernopadding nowrap">';
  188. print img_warning($langs->trans("Late"));
  189. print '</td>';
  190. }
  191. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  192. $filename = dol_sanitizeFileName($obj->ref);
  193. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  194. $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
  195. print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
  196. print '</td></tr></table>';
  197. print '</td>';
  198. print '<td class="tdoverflowmax150">';
  199. print $thirdpartystatic->getNomUrl(1, 'customer', 44);
  200. print '</td>';
  201. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  202. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
  203. }
  204. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
  205. print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
  206. print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
  207. print '</tr>';
  208. $total_ttc += $obj->total_ttc;
  209. $total_ht += $obj->total_ht;
  210. $totalam += $obj->am;
  211. $i++;
  212. }
  213. if ($othernb) {
  214. print '<tr class="oddeven">';
  215. print '<td class="nowrap" colspan="5">';
  216. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  217. print '</td>';
  218. print "</tr>\n";
  219. }
  220. } else {
  221. $colspan = 5;
  222. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  223. $colspan++;
  224. }
  225. print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
  226. }
  227. print '</table></div><br>';
  228. $db->free($resql);
  229. } else {
  230. dol_print_error($db);
  231. }
  232. }
  233. // Last modified supplier invoices
  234. if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
  235. $langs->load("boxes");
  236. $facstatic = new FactureFournisseur($db);
  237. $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier";
  238. $sql .= ", s.nom as name";
  239. $sql .= ", s.rowid as socid";
  240. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
  241. $sql .= ", SUM(pf.amount) as am";
  242. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
  243. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
  244. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  245. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  246. }
  247. $sql .= " WHERE s.rowid = ff.fk_soc";
  248. $sql .= " AND ff.entity = ".$conf->entity;
  249. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  250. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  251. }
  252. if ($socid) {
  253. $sql .= " AND ff.fk_soc = ".((int) $socid);
  254. }
  255. // Add where from hooks
  256. $parameters = array();
  257. $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
  258. $sql .= $hookmanager->resPrint;
  259. $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier,";
  260. $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
  261. $sql .= " ORDER BY ff.tms DESC ";
  262. $sql .= $db->plimit($max, 0);
  263. $resql = $db->query($sql);
  264. if ($resql) {
  265. $num = $db->num_rows($resql);
  266. print '<div class="div-table-responsive-no-min">';
  267. print '<table class="noborder centpercent">';
  268. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
  269. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  270. print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  271. }
  272. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  273. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  274. print '<th width="16">&nbsp;</th>';
  275. print "</tr>\n";
  276. if ($num) {
  277. $i = 0;
  278. $total_ht = $total_ttc = $totalam = 0;
  279. $othernb = 0;
  280. while ($i < $num) {
  281. $obj = $db->fetch_object($resql);
  282. if ($i >= $max) {
  283. $othernb += 1;
  284. $i++;
  285. $total_ht += $obj->total_ht;
  286. $total_ttc += $obj->total_ttc;
  287. continue;
  288. }
  289. $facstatic->ref = $obj->ref;
  290. $facstatic->id = $obj->rowid;
  291. $facstatic->total_ht = $obj->total_ht;
  292. $facstatic->total_tva = $obj->total_tva;
  293. $facstatic->total_ttc = $obj->total_ttc;
  294. $facstatic->statut = $obj->status;
  295. $facstatic->paye = $obj->paye;
  296. $facstatic->type = $obj->type;
  297. $facstatic->ref_supplier = $obj->ref_supplier;
  298. $thirdpartystatic->id = $obj->socid;
  299. $thirdpartystatic->name = $obj->name;
  300. $thirdpartystatic->email = $obj->email;
  301. $thirdpartystatic->country_id = 0;
  302. $thirdpartystatic->country_code = '';
  303. $thirdpartystatic->client = 0;
  304. $thirdpartystatic->fournisseur = 1;
  305. $thirdpartystatic->code_client = '';
  306. $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
  307. $thirdpartystatic->code_compta = '';
  308. $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  309. print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
  310. print $facstatic->getNomUrl(1, '');
  311. print '</td>';
  312. print '<td class="nowrap tdoverflowmax100">';
  313. print $thirdpartystatic->getNomUrl(1, 'supplier');
  314. print '</td>';
  315. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  316. print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
  317. }
  318. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
  319. print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
  320. $alreadypaid = $facstatic->getSommePaiement();
  321. print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
  322. print '</tr>';
  323. $total_ht += $obj->total_ht;
  324. $total_ttc += $obj->total_ttc;
  325. $totalam += $obj->am;
  326. $i++;
  327. }
  328. if ($othernb) {
  329. print '<tr class="oddeven">';
  330. print '<td class="nowrap" colspan="5">';
  331. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  332. print '</td>';
  333. print "</tr>\n";
  334. }
  335. } else {
  336. $colspan = 5;
  337. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  338. $colspan++;
  339. }
  340. print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
  341. }
  342. print '</table></div><br>';
  343. } else {
  344. dol_print_error($db);
  345. }
  346. }
  347. // Latest donations
  348. if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
  349. include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  350. $langs->load("boxes");
  351. $donationstatic = new Don($db);
  352. $sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut as status";
  353. $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
  354. $sql .= " WHERE d.entity IN (".getEntity('donation').")";
  355. // Add where from hooks
  356. $parameters = array();
  357. $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
  358. $sql .= $hookmanager->resPrint;
  359. $sql .= $db->order("d.tms", "DESC");
  360. $sql .= $db->plimit($max, 0);
  361. $result = $db->query($sql);
  362. if ($result) {
  363. $num = $db->num_rows($result);
  364. $i = 0;
  365. $othernb = 0;
  366. print '<div class="div-table-responsive-no-min">';
  367. print '<table class="noborder centpercent">';
  368. print '<tr class="liste_titre">';
  369. print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
  370. print '<th></th>';
  371. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  372. print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
  373. print '<th width="16">&nbsp;</th>';
  374. print '</tr>';
  375. if ($num) {
  376. $total_ttc = $totalam = $total_ht = 0;
  377. while ($i < $num && $i < $max) {
  378. $obj = $db->fetch_object($result);
  379. if ($i >= $max) {
  380. $othernb += 1;
  381. $i++;
  382. $total_ht += $obj->total_ht;
  383. $total_ttc += $obj->total_ttc;
  384. continue;
  385. }
  386. $donationstatic->id = $obj->rowid;
  387. $donationstatic->ref = $obj->rowid;
  388. $donationstatic->lastname = $obj->lastname;
  389. $donationstatic->firstname = $obj->firstname;
  390. $donationstatic->date = $db->jdate($obj->date);
  391. $donationstatic->statut = $obj->status;
  392. $donationstatic->status = $obj->status;
  393. $label = $donationstatic->getFullName($langs);
  394. if ($obj->societe) {
  395. $label .= ($label ? ' - ' : '').$obj->societe;
  396. }
  397. print '<tr class="oddeven tdoverflowmax100">';
  398. print '<td>'.$donationstatic->getNomUrl(1).'</td>';
  399. print '<td>'.$label.'</td>';
  400. print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
  401. print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->dm), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->dm), 'day', 'tzuserrel').'</td>';
  402. print '<td>'.$donationstatic->getLibStatut(3).'</td>';
  403. print '</tr>';
  404. $i++;
  405. }
  406. if ($othernb) {
  407. print '<tr class="oddeven">';
  408. print '<td class="nowrap" colspan="5">';
  409. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  410. print '</td>';
  411. print "</tr>\n";
  412. }
  413. } else {
  414. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  415. }
  416. print '</table></div><br>';
  417. } else {
  418. dol_print_error($db);
  419. }
  420. }
  421. /**
  422. * Social contributions to pay
  423. */
  424. if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
  425. if (!$socid) {
  426. $chargestatic = new ChargeSociales($db);
  427. $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
  428. $sql .= " cc.libelle as label,";
  429. $sql .= " SUM(pc.amount) as sumpaid";
  430. $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
  431. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
  432. $sql .= " WHERE c.fk_type = cc.id";
  433. $sql .= " AND c.entity IN (".getEntity('tax').')';
  434. $sql .= " AND c.paye = 0";
  435. // Add where from hooks
  436. $parameters = array();
  437. $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
  438. $sql .= $hookmanager->resPrint;
  439. $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
  440. $resql = $db->query($sql);
  441. if ($resql) {
  442. $num = $db->num_rows($resql);
  443. print '<div class="div-table-responsive-no-min">';
  444. print '<table class="noborder centpercent">';
  445. print '<tr class="liste_titre">';
  446. print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
  447. print '<th align="center">'.$langs->trans("DateDue").'</th>';
  448. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  449. print '<th class="right">'.$langs->trans("Paid").'</th>';
  450. print '<th align="center" width="16">&nbsp;</th>';
  451. print '</tr>';
  452. if ($num) {
  453. $i = 0;
  454. $tot_ttc = 0;
  455. $othernb = 0;
  456. while ($i < $num) {
  457. $obj = $db->fetch_object($resql);
  458. if ($i >= $max) {
  459. $othernb += 1;
  460. $tot_ttc += $obj->amount;
  461. $i++;
  462. continue;
  463. }
  464. $chargestatic->id = $obj->rowid;
  465. $chargestatic->ref = $obj->rowid;
  466. $chargestatic->label = $obj->label;
  467. $chargestatic->paye = $obj->paye;
  468. $chargestatic->status = $obj->paye;
  469. print '<tr class="oddeven">';
  470. print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
  471. print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
  472. print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
  473. print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
  474. print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
  475. print '</tr>';
  476. $tot_ttc += $obj->amount;
  477. $i++;
  478. }
  479. if ($othernb) {
  480. print '<tr class="oddeven">';
  481. print '<td class="nowrap" colspan="5">';
  482. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  483. print '</td>';
  484. print "</tr>\n";
  485. }
  486. print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
  487. print '<td class="nowrap right">'.price($tot_ttc).'</td>';
  488. print '<td class="right"></td>';
  489. print '<td class="right">&nbsp;</td>';
  490. print '</tr>';
  491. } else {
  492. print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  493. }
  494. print "</table></div><br>";
  495. $db->free($resql);
  496. } else {
  497. dol_print_error($db);
  498. }
  499. }
  500. }
  501. /*
  502. * Customers orders to be billed
  503. */
  504. if (isModEnabled('facture') && isModEnabled('commande') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
  505. $commandestatic = new Commande($db);
  506. $langs->load("orders");
  507. $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
  508. $sql .= ", s.nom as name, s.email";
  509. $sql .= ", s.rowid as socid";
  510. $sql .= ", s.code_client, s.code_compta";
  511. $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
  512. $sql .= " cc.rowid as country_id, cc.code as country_code";
  513. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
  514. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  515. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  516. }
  517. $sql .= ", ".MAIN_DB_PREFIX."commande as c";
  518. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
  519. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
  520. $sql .= " WHERE c.fk_soc = s.rowid";
  521. $sql .= " AND c.entity = ".$conf->entity;
  522. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  523. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  524. }
  525. if ($socid) {
  526. $sql .= " AND c.fk_soc = ".((int) $socid);
  527. }
  528. $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
  529. $sql .= " AND c.facture = 0";
  530. // Add where from hooks
  531. $parameters = array();
  532. $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
  533. $sql .= $hookmanager->resPrint;
  534. $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.total_tva, c.total_ttc, cc.rowid, cc.code";
  535. $resql = $db->query($sql);
  536. if ($resql) {
  537. $num = $db->num_rows($resql);
  538. if ($num) {
  539. $i = 0;
  540. $othernb = 0;
  541. print '<div class="div-table-responsive-no-min">';
  542. print '<table class="noborder centpercent">';
  543. print "<tr class=\"liste_titre\">";
  544. print '<th colspan="2">';
  545. print $langs->trans("OrdersDeliveredToBill").' ';
  546. print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
  547. print '<span class="badge">'.$num.'</span>';
  548. print '</a>';
  549. print '</th>';
  550. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  551. print '<th class="right">'.$langs->trans("AmountHT").'</th>';
  552. }
  553. print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
  554. print '<th class="right">'.$langs->trans("ToBill").'</th>';
  555. print '<th align="center" width="16">&nbsp;</th>';
  556. print '</tr>';
  557. $tot_ht = $tot_ttc = $tot_tobill = 0;
  558. $societestatic = new Societe($db);
  559. while ($i < $num) {
  560. $obj = $db->fetch_object($resql);
  561. if ($i >= $max) {
  562. $othernb += 1;
  563. $i++;
  564. $total_ht += $obj->total_ht;
  565. $total_ttc += $obj->total_ttc;
  566. continue;
  567. }
  568. $societestatic->id = $obj->socid;
  569. $societestatic->name = $obj->name;
  570. $societestatic->email = $obj->email;
  571. $societestatic->country_id = $obj->country_id;
  572. $societestatic->country_code = $obj->country_code;
  573. $societestatic->client = 1;
  574. $societestatic->code_client = $obj->code_client;
  575. //$societestatic->code_fournisseur = $obj->code_fournisseur;
  576. $societestatic->code_compta = $obj->code_compta;
  577. //$societestatic->code_fournisseur = $obj->code_fournisseur;
  578. $commandestatic->id = $obj->rowid;
  579. $commandestatic->ref = $obj->ref;
  580. $commandestatic->statut = $obj->status;
  581. $commandestatic->billed = $obj->facture;
  582. print '<tr class="oddeven">';
  583. print '<td class="nowrap">';
  584. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  585. print '<td class="nobordernopadding nowrap">';
  586. print $commandestatic->getNomUrl(1);
  587. print '</td>';
  588. print '<td width="20" class="nobordernopadding nowrap">';
  589. print '&nbsp;';
  590. print '</td>';
  591. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  592. $filename = dol_sanitizeFileName($obj->ref);
  593. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  594. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  595. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  596. print '</td></tr></table>';
  597. print '</td>';
  598. print '<td class="nowrap tdoverflowmax100">';
  599. print $societestatic->getNomUrl(1, 'customer');
  600. print '</td>';
  601. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  602. print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
  603. }
  604. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
  605. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
  606. print '<td>'.$commandestatic->getLibStatut(3).'</td>';
  607. print '</tr>';
  608. $tot_ht += $obj->total_ht;
  609. $tot_ttc += $obj->total_ttc;
  610. //print "x".$tot_ttc."z".$obj->tot_fttc;
  611. $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
  612. $i++;
  613. }
  614. if ($othernb) {
  615. print '<tr class="oddeven">';
  616. print '<td class="nowrap" colspan="5">';
  617. print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
  618. print '</td>';
  619. print "</tr>\n";
  620. }
  621. print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</span> </td>';
  622. if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
  623. print '<td class="right">'.price($tot_ht).'</td>';
  624. }
  625. print '<td class="nowrap right">'.price($tot_ttc).'</td>';
  626. print '<td class="nowrap right">'.price($tot_tobill).'</td>';
  627. print '<td>&nbsp;</td>';
  628. print '</tr>';
  629. print '</table></div><br>';
  630. }
  631. $db->free($resql);
  632. } else {
  633. dol_print_error($db);
  634. }
  635. }
  636. // TODO Mettre ici recup des actions en rapport avec la compta
  637. $sql = '';
  638. if ($sql) {
  639. print '<div class="div-table-responsive-no-min">';
  640. print '<table class="noborder centpercent">';
  641. print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
  642. print "</tr>\n";
  643. $i = 0;
  644. $resql = $db->query($sql);
  645. if ($resql) {
  646. $num_rows = $db->num_rows($resql);
  647. while ($i < $num_rows) {
  648. $obj = $db->fetch_object($resql);
  649. print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
  650. print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
  651. $i++;
  652. }
  653. $db->free($resql);
  654. }
  655. print "</table></div><br>";
  656. }
  657. print '</div></div>';
  658. $parameters = array('user' => $user);
  659. $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
  660. // End of page
  661. llxFooter();
  662. $db->close();