index.php 27 KB

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