index.php 40 KB

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