dolibarr  9.0.0
balancebymonth.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2014 Alexandre Spangaro <aspangaro@zendsi.com>
4  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 Jean-Fran├žois Ferry <jfefe@aternatik.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
27 require '../../main.inc.php';
28 
29 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("bills","compta","accountancy","other"));
34 
35 // Filter
36 $year = GETPOST("year",'int');
37 if ($year == 0) {
38  $year_current = strftime("%Y", time());
39  $year_start = $year_current;
40 } else {
41  $year_current = $year;
42  $year_start = $year;
43 }
44 
45 
46 /*
47  * View
48  */
49 
50 llxHeader('', $langs->trans("Bookkeeping"));
51 
52 $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
53 $textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
54 
55 print load_fiche_titre($langs->trans("AccountBalanceByMonth") . ' ' . $textprevyear . ' ' . $langs->trans("Year") . ' ' . $year_start . ' ' . $textnextyear);
56 
57 $sql = "SELECT count(*) FROM " . MAIN_DB_PREFIX . "facturedet as fd";
58 $sql .= " , " . MAIN_DB_PREFIX . "facture as f";
59 $sql .= " WHERE fd.fk_code_ventilation = 0";
60 $sql .= " AND f.rowid = fd.fk_facture AND f.fk_statut = 1;";
61 
62 dol_syslog('accountancy/bookkeeping/balancebymonth.php:: $sql=' . $sql);
63 $result = $db->query($sql);
64 if ($result) {
65  $row = $db->fetch_row($result);
66  $nbfac = $row[0];
67 
68  $db->free($result);
69 }
70 
71 $y = $year_current;
72 
73 print '<table class="noborder" width="100%">';
74 print '<tr class="liste_titre">';
75 print '<td width=150>' . $langs->trans("Label") . '</td>';
76 print '<td align="center">' . $langs->trans("JanuaryMin") . '</td>';
77 print '<td align="center">' . $langs->trans("FebruaryMin") . '</td>';
78 print '<td align="center">' . $langs->trans("MarchMin") . '</td>';
79 print '<td align="center">' . $langs->trans("AprilMin") . '</td>';
80 print '<td align="center">' . $langs->trans("MayMin") . '</td>';
81 print '<td align="center">' . $langs->trans("JuneMin") . '</td>';
82 print '<td align="center">' . $langs->trans("JulyMin") . '</td>';
83 print '<td align="center">' . $langs->trans("AugustMin") . '</td>';
84 print '<td align="center">' . $langs->trans("SeptemberMin") . '</td>';
85 print '<td align="center">' . $langs->trans("OctoberMin") . '</td>';
86 print '<td align="center">' . $langs->trans("NovemberMin") . '</td>';
87 print '<td align="center">' . $langs->trans("DecemberMin") . '</td>';
88 print '<td align="center"><strong>Total</strong></td>';
89 print '</tr>';
90 
91 $sql = "SELECT bk.numero_compte AS 'compte',";
92 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=1,bk.montant,0)),2) AS 'Janvier',";
93 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=2,bk.montant,0)),2) AS 'Fevrier',";
94 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=3,bk.montant,0)),2) AS 'Mars',";
95 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=4,bk.montant,0)),2) AS 'Avril',";
96 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=5,bk.montant,0)),2) AS 'Mai',";
97 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=6,bk.montant,0)),2) AS 'Juin',";
98 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=7,bk.montant,0)),2) AS 'Juillet',";
99 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=8,bk.montant,0)),2) AS 'Aout',";
100 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=9,bk.montant,0)),2) AS 'Septembre',";
101 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=10,bk.montant,0)),2) AS 'Octobre',";
102 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=11,bk.montant,0)),2) AS 'Novembre',";
103 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=12,bk.montant,0)),2) AS 'Decembre',";
104 $sql .= " ROUND(SUM(bk.montant),2) as 'Total'";
105 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
106 $sql .= " WHERE bk.doc_date >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
107 $sql .= " AND bk.doc_date <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
108 $sql .= " GROUP BY bk.numero_compte";
109 
110 $resql = $db->query($sql);
111 if ($resql) {
112  $i = 0;
113  $num = $db->num_rows($resql);
114 
115  while ( $i < $num ) {
116 
117  $row = $db->fetch_row($resql);
118 
119  print '<tr class="oddeven"><td width="14%">' . length_accountg($row[0]) . '</td>';
120  print '<td align="right" width="6.5%">' . price($row[1]) . '</td>';
121  print '<td align="right" width="6.5%">' . price($row[2]) . '</td>';
122  print '<td align="right" width="6.5%">' . price($row[3]) . '</td>';
123  print '<td align="right" width="6.5%">' . price($row[4]) . '</td>';
124  print '<td align="right" width="6.5%">' . price($row[5]) . '</td>';
125  print '<td align="right" width="6.5%">' . price($row[6]) . '</td>';
126  print '<td align="right" width="6.5%">' . price($row[7]) . '</td>';
127  print '<td align="right" width="6.5%">' . price($row[8]) . '</td>';
128  print '<td align="right" width="6.5%">' . price($row[9]) . '</td>';
129  print '<td align="right" width="6.5%">' . price($row[10]) . '</td>';
130  print '<td align="right" width="6.5%">' . price($row[11]) . '</td>';
131  print '<td align="right" width="6.5%">' . price($row[12]) . '</td>';
132  print '<td align="right" width="8%"><strong>' . price($row[13]) . '</strong></td>';
133  print '</tr>';
134 
135  $i ++;
136  }
137  $db->free($resql);
138 } else {
139  print $db->lasterror();
140 }
141 print "</table>\n";
142 
143 // End of page
144 llxFooter();
145 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
llxHeader()
Empty header.
Definition: wrapper.php:44
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
img_previous($titlealt='default', $moreatt='')
Show previous logo.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...