dolibarr  7.0.0-beta
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 // Class
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
32 
33 // Langs
34 $langs->load("main");
35 $langs->load("compta");
36 $langs->load("bills");
37 $langs->load("other");
38 $langs->load("accountancy");
39 
40 // Filter
41 $year = GETPOST("year",'int');
42 if ($year == 0) {
43  $year_current = strftime("%Y", time());
44  $year_start = $year_current;
45 } else {
46  $year_current = $year;
47  $year_start = $year;
48 }
49 
50 
51 /*
52  * View
53  */
54 
55 llxHeader('', $langs->trans("Bookkeeping"));
56 
57 $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
58 $textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
59 
60 print load_fiche_titre($langs->trans("AccountBalanceByMonth") . ' ' . $textprevyear . ' ' . $langs->trans("Year") . ' ' . $year_start . ' ' . $textnextyear);
61 
62 $sql = "SELECT count(*) FROM " . MAIN_DB_PREFIX . "facturedet as fd";
63 $sql .= " , " . MAIN_DB_PREFIX . "facture as f";
64 $sql .= " WHERE fd.fk_code_ventilation = 0";
65 $sql .= " AND f.rowid = fd.fk_facture AND f.fk_statut = 1;";
66 
67 dol_syslog('accountancy/bookkeeping/balancebymonth.php:: $sql=' . $sql);
68 $result = $db->query($sql);
69 if ($result) {
70  $row = $db->fetch_row($result);
71  $nbfac = $row[0];
72 
73  $db->free($result);
74 }
75 
76 $y = $year_current;
77 
78 $var = true;
79 
80 print '<table class="noborder" width="100%">';
81 print '<tr class="liste_titre"><td width=150>' . $langs->trans("Label") . '</td><td align="center">' . $langs->trans("JanuaryMin") . '</td><td align="center">' . $langs->trans("FebruaryMin") . '</td><td align="center">' . $langs->trans("MarchMin") . '</td><td align="center">' . $langs->trans("AprilMin") . '</td><td align="center">' . $langs->trans("MayMin") . '</td><td align="center">' . $langs->trans("JuneMin") . '</td><td align="center">' . $langs->trans("JulyMin") . '</td><td align="center">' . $langs->trans("AugustMin") . '</td><td align="center">' . $langs->trans("SeptemberMin") . '</td><td align="center">' . $langs->trans("OctoberMin") . '</td><td align="center">' . $langs->trans("NovemberMin") . '</td><td align="center">' . $langs->trans("DecemberMin") . '</td><td align="center"><b>Total</b></td></tr>';
82 
83 $sql = "SELECT bk.numero_compte AS 'compte',";
84 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=1,bk.montant,0)),2) AS 'Janvier',";
85 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=2,bk.montant,0)),2) AS 'Fevrier',";
86 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=3,bk.montant,0)),2) AS 'Mars',";
87 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=4,bk.montant,0)),2) AS 'Avril',";
88 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=5,bk.montant,0)),2) AS 'Mai',";
89 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=6,bk.montant,0)),2) AS 'Juin',";
90 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=7,bk.montant,0)),2) AS 'Juillet',";
91 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=8,bk.montant,0)),2) AS 'Aout',";
92 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=9,bk.montant,0)),2) AS 'Septembre',";
93 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=10,bk.montant,0)),2) AS 'Octobre',";
94 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=11,bk.montant,0)),2) AS 'Novembre',";
95 $sql .= " ROUND(SUM(IF(MONTH(bk.doc_date)=12,bk.montant,0)),2) AS 'Decembre',";
96 $sql .= " ROUND(SUM(bk.montant),2) as 'Total'";
97 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk";
98 $sql .= " WHERE bk.doc_date >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
99 $sql .= " AND bk.doc_date <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
100 $sql .= " GROUP BY bk.numero_compte";
101 
102 $resql = $db->query($sql);
103 if ($resql) {
104  $i = 0;
105  $num = $db->num_rows($resql);
106 
107  while ( $i < $num ) {
108 
109  $row = $db->fetch_row($resql);
110 
111  print '<tr><td width="14%">' . length_accountg($row[0]) . '</td>';
112  print '<td align="right" width="6.5%">' . price($row[1]) . '</td>';
113  print '<td align="right" width="6.5%">' . price($row[2]) . '</td>';
114  print '<td align="right" width="6.5%">' . price($row[3]) . '</td>';
115  print '<td align="right" width="6.5%">' . price($row[4]) . '</td>';
116  print '<td align="right" width="6.5%">' . price($row[5]) . '</td>';
117  print '<td align="right" width="6.5%">' . price($row[6]) . '</td>';
118  print '<td align="right" width="6.5%">' . price($row[7]) . '</td>';
119  print '<td align="right" width="6.5%">' . price($row[8]) . '</td>';
120  print '<td align="right" width="6.5%">' . price($row[9]) . '</td>';
121  print '<td align="right" width="6.5%">' . price($row[10]) . '</td>';
122  print '<td align="right" width="6.5%">' . price($row[11]) . '</td>';
123  print '<td align="right" width="6.5%">' . price($row[12]) . '</td>';
124  print '<td align="right" width="8%"><b>' . price($row[13]) . '</b></td>';
125  print '</tr>';
126 
127  $i ++;
128  }
129  $db->free($resql);
130 } else {
131  print $db->lasterror();
132 }
133 print "</table>\n";
134 
135 llxFooter();
136 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_previous($titlealt= 'default', $moreatt='')
Show previous logo.
img_next($titlealt= 'default', $moreatt='')
Show next logo.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
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:459
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:1013
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...