PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/bank/annuel.php

https://bitbucket.org/speedealing/speedealing
PHP | 282 lines | 210 code | 39 blank | 33 comment | 27 complexity | 874d99548079f669cdca07ea86dd27af MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/bank/annuel.php
  21. * \ingroup banque
  22. * \brief Page reporting mensuel Entrees/Sorties d'un compte bancaire
  23. */
  24. require 'pre.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  27. $id=GETPOST('account');
  28. $ref=GETPOST('ref');
  29. // Security check
  30. $fieldid = (! empty($ref)?$ref:$id);
  31. $fieldname = isset($ref)?'ref':'rowid';
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname);
  34. $year_start=GETPOST('year_start');
  35. $year_current = strftime("%Y",time());
  36. if (! $year_start)
  37. {
  38. $year_start = $year_current - 2;
  39. $year_end = $year_current;
  40. }
  41. else
  42. {
  43. $year_end=$year_start+2;
  44. }
  45. llxHeader();
  46. $form = new Form($db);
  47. // Get account informations
  48. $acct = new Account($db);
  49. if ($id > 0 && ! preg_match('/,/', $id)) // if for a particular account and not a list
  50. {
  51. $result=$acct->fetch($id);
  52. $id=$acct->id;
  53. }
  54. if (! empty($ref))
  55. {
  56. $result=$acct->fetch(0, $ref);
  57. $id=$acct->id;
  58. }
  59. // Ce rapport de tresorerie est base sur llx_bank (car doit inclure les transactions sans facture)
  60. // plutot que sur llx_paiement + llx_paiementfourn
  61. $sql = "SELECT SUM(b.amount)";
  62. $sql.= ", date_format(b.dateo,'%Y-%m') as dm";
  63. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  64. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  65. $sql.= " WHERE b.fk_account = ba.rowid";
  66. $sql.= " AND ba.entity = ".$conf->entity;
  67. $sql.= " AND b.amount >= 0";
  68. if (! empty($id))
  69. $sql .= " AND b.fk_account IN (".$db->escape($id).")";
  70. $sql.= " GROUP BY dm";
  71. $resql=$db->query($sql);
  72. if ($resql)
  73. {
  74. $num = $db->num_rows($resql);
  75. $i = 0;
  76. while ($i < $num)
  77. {
  78. $row = $db->fetch_row($resql);
  79. $encaiss[$row[1]] = $row[0];
  80. $i++;
  81. }
  82. }
  83. else
  84. {
  85. dol_print_error($db);
  86. }
  87. $sql = "SELECT SUM(b.amount)";
  88. $sql.= ", date_format(b.dateo,'%Y-%m') as dm";
  89. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  90. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  91. $sql.= " WHERE b.fk_account = ba.rowid";
  92. $sql.= " AND ba.entity = ".$conf->entity;
  93. $sql.= " AND b.amount <= 0";
  94. if (! empty($id))
  95. $sql .= " AND b.fk_account IN (".$db->escape($id).")";
  96. $sql.= " GROUP BY dm";
  97. $resql=$db->query($sql);
  98. if ($resql)
  99. {
  100. $num = $db->num_rows($resql);
  101. $i = 0;
  102. while ($i < $num)
  103. {
  104. $row = $db->fetch_row($resql);
  105. $decaiss[$row[1]] = -$row[0];
  106. $i++;
  107. }
  108. }
  109. else
  110. {
  111. dol_print_error($db);
  112. }
  113. // Onglets
  114. $head=bank_prepare_head($acct);
  115. dol_fiche_head($head,'annual',$langs->trans("FinancialAccount"),0,'account');
  116. $title=$langs->trans("FinancialAccount")." : ".$acct->label;
  117. $lien=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?account=".$acct->id."&year_start=".($year_start-1)."'>".img_previous()."</a> ".$langs->trans("Year")." <a href='".$_SERVER["PHP_SELF"]."?account=".$acct->id."&year_start=".($year_start+1)."'>".img_next()."</a>":"");
  118. print '<table class="border" width="100%">';
  119. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/index.php">'.$langs->trans("BackToList").'</a>';
  120. // Ref
  121. print '<tr><td valign="top" width="25%">'.$langs->trans("Ref").'</td>';
  122. print '<td colspan="3">';
  123. if ($_GET["account"])
  124. {
  125. if (! preg_match('/,/', $id))
  126. {
  127. print $form->showrefnav($acct, 'ref', $linkback, 1, 'ref');
  128. }
  129. else
  130. {
  131. $bankaccount=new Account($db);
  132. $listid=explode(',', $id);
  133. foreach($listid as $key => $aId)
  134. {
  135. $bankaccount->fetch($aId);
  136. $bankaccount->label=$bankaccount->ref;
  137. print $bankaccount->getNomUrl(1);
  138. if ($key < (count($listid)-1)) print ', ';
  139. }
  140. }
  141. }
  142. else
  143. {
  144. print $langs->trans("ALL");
  145. }
  146. print '</td></tr>';
  147. // Label
  148. print '<tr><td valign="top">'.$langs->trans("Label").'</td>';
  149. print '<td colspan="3">';
  150. if (! empty($id))
  151. {
  152. print $acct->label;
  153. }
  154. else
  155. {
  156. print $langs->trans("AllAccounts");
  157. }
  158. print '</td></tr>';
  159. print '</table>';
  160. print '<br>';
  161. // Affiche tableau
  162. print '<table class="notopnoleftnoright" width="100%">';
  163. print '<tr><td colspan="'.(1+($year_end-$year_start+1)*2).'" align="right">'.$lien.'</td></tr>';
  164. print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
  165. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  166. {
  167. print '<td align="center" width="20%" colspan="2">'.$annee.'</td>';
  168. }
  169. print '</tr>';
  170. print '<tr class="liste_titre">';
  171. print '<td class="liste_titre">&nbsp;</td>';
  172. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  173. {
  174. print '<td align="right">'.$langs->trans("Debit").'</td><td align="right">'.$langs->trans("Credit").'</td>';
  175. }
  176. print '</tr>';
  177. $var=true;
  178. for ($mois = 1 ; $mois < 13 ; $mois++)
  179. {
  180. $var=!$var;
  181. print '<tr '.$bc[$var].'>';
  182. print "<td>".dol_print_date(dol_mktime(1,1,1,$mois,1,2000),"%B")."</td>";
  183. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  184. {
  185. $case = sprintf("%04s-%02s",$annee,$mois);
  186. print '<td align="right" width="10%">&nbsp;';
  187. if ($decaiss[$case]>0)
  188. {
  189. print price($decaiss[$case]);
  190. $totsorties[$annee]+=$decaiss[$case];
  191. }
  192. print "</td>";
  193. print '<td align="right" width="10%">&nbsp;';
  194. if ($encaiss[$case]>0)
  195. {
  196. print price($encaiss[$case]);
  197. $totentrees[$annee]+=$encaiss[$case];
  198. }
  199. print "</td>";
  200. }
  201. print '</tr>';
  202. }
  203. // Total debit-credit
  204. print '<tr class="liste_total"><td><b>'.$langs->trans("Total")."</b></td>";
  205. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  206. {
  207. print '<td align="right"><b>'.price($totsorties[$annee]).'</b></td><td align="right"><b>'.price($totentrees[$annee]).'</b></td>';
  208. }
  209. print "</tr>\n";
  210. // Ligne vierge
  211. print '<tr><td>&nbsp;</td>';
  212. $nbcol=0;
  213. for ($annee = $year_start ; $annee <= $year_end ; $annee++)
  214. {
  215. $nbcol+=2;
  216. }
  217. print "</tr>\n";
  218. // Solde actuel
  219. $balance=0;
  220. $sql = "SELECT SUM(b.amount) as total";
  221. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  222. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  223. $sql.= " WHERE b.fk_account = ba.rowid";
  224. $sql.= " AND ba.entity = ".$conf->entity;
  225. if (! empty($id))
  226. $sql.= " AND b.fk_account IN (".$db->escape($id).")";
  227. $resql=$db->query($sql);
  228. if ($resql)
  229. {
  230. $obj = $db->fetch_object($resql);
  231. if ($obj) $balance=$obj->total;
  232. }
  233. else {
  234. dol_print_error($db);
  235. }
  236. print '<tr class="liste_total"><td><b>'.$langs->trans("CurrentBalance")."</b></td>";
  237. print '<td colspan="'.($nbcol).'" align="right">'.price($balance).'</td>';
  238. print "</tr>\n";
  239. print "</table>";
  240. print "\n</div>\n";
  241. llxFooter();
  242. $db->close();
  243. ?>