dolibarr  7.0.0-beta
listbyaccount.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Neil Orley <neil.orley@oeris.fr>
3  * Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
4  * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 
27 require '../../main.inc.php';
28 
29 // Class
30 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
35 
36 // Langs
37 $langs->load("accountancy");
38 
39 $page = GETPOST("page");
40 $sortorder = GETPOST("sortorder");
41 $sortfield = GETPOST("sortfield");
42 $action = GETPOST('action', 'alpha');
43 $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
44 $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
45 $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
46 
47 
48 
49 $search_accountancy_code = GETPOST("search_accountancy_code");
50 $search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha');
51 if ($search_accountancy_code_start == - 1) {
52  $search_accountancy_code_start = '';
53 }
54 $search_label_account = GETPOST('search_label_account', 'alpha');
55 $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
56 $search_direction = GETPOST('search_direction', 'alpha');
57 $search_ledger_code = GETPOST('search_ledger_code', 'alpha');
58 
59 // Load variable for pagination
60 $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
61 $sortfield = GETPOST('sortfield', 'alpha');
62 $sortorder = GETPOST('sortorder', 'alpha');
63 $page = GETPOST('page','int');
64 if (empty($page) || $page < 0) { $page = 0; }
65 $offset = $limit * $page;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 if ($sortorder == "") $sortorder = "ASC";
69 if ($sortfield == "") $sortfield = "t.rowid";
70 
71 if (empty($search_date_start)) {
72  $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
73  $sql.= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
74  $sql.= $db->plimit(1);
75  $res = $db->query($sql);
76 
77  if ($res->num_rows > 0) {
78  $fiscalYear = $db->fetch_object($res);
79  $search_date_start = strtotime($fiscalYear->date_start);
80  $search_date_end = strtotime($fiscalYear->date_end);
81  } else {
82  $month_start= ($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
83  $year_start = dol_print_date(dol_now(), '%Y');
84  $year_end = $year_start + 1;
85  $month_end = $month_start - 1;
86  if ($month_end < 1)
87  {
88  $month_end = 12;
89  $year_end--;
90  }
91  $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
92  $search_date_end = dol_get_last_day($year_end, $month_end);
93  }
94 }
95 
96 $object = new BookKeeping($db);
97 
98 
99 $options = '';
100 $filter = array ();
101 
102 if (! empty($search_date_start)) {
103  $filter['t.doc_date>='] = $search_date_start;
104  $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int');
105 }
106 if (! empty($search_date_end)) {
107  $filter['t.doc_date<='] = $search_date_end;
108  $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int');
109 }
110 if (! empty($search_doc_date)) {
111  $filter['t.doc_date'] = $search_doc_date;
112  $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int');
113 }
114 
115 if (! GETPOST('button_removefilter_x','alpha') && ! GETPOST('button_removefilter.x','alpha') && ! GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
116 {
117  if (! empty($search_accountancy_code_start)) {
118  $filter['t.numero_compte'] = $search_accountancy_code_start;
119  $options .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start);
120  }
121  if (! empty($search_label_account)) {
122  $filter['t.label_operation'] = $search_label_account;
123  $options .= '&search_label_account=' . urlencode($search_label_account);
124  }
125  if (! empty($search_mvt_label)) {
126  $filter['t.label_operation'] = $search_mvt_label;
127  $options .= '&search_mvt_label=' . urlencode($search_mvt_label);
128  }
129  if (! empty($search_direction)) {
130  $filter['t.sens'] = $search_direction;
131  $options .= '&search_direction=' . urlencode($search_direction);
132  }
133  if (! empty($search_ledger_code)) {
134  $filter['t.code_journal'] = $search_ledger_code;
135  $options .= '&search_ledger_code=' . urlencode($search_ledger_code);
136  }
137 }
138 
139 
140 /*
141  * Action
142  */
143 
144 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
145 {
146  $search_doc_date = '';
147  $search_accountancy_code = '';
148  $search_accountancy_code_start = '';
149  $search_label_account = '';
150  $search_mvt_label = '';
151  $search_direction = '';
152  $search_ledger_code = '';
153 }
154 
155 if ($action == 'delmouvconfirm') {
156 
157  $mvt_num = GETPOST('mvt_num', 'int');
158 
159  if (! empty($mvt_num)) {
160  $result = $object->deleteMvtNum($mvt_num);
161  if ($result < 0) {
162  setEventMessages($object->error, $object->errors, 'errors');
163  }
164  Header("Location: listbyaccount.php");
165  exit();
166  }
167 }
168 
169 
170 /*
171  * View
172  */
173 
174 $formaccounting = new FormAccounting($db);
175 $formother = new FormOther($db);
176 $form = new Form($db);
177 
178 $title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting");
179 
180 llxHeader('', $title_page);
181 
182 
183 // List
184 $nbtotalofrecords = '';
185 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
186  $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter);
187  if ($nbtotalofrecords < 0) {
188  setEventMessages($object->error, $object->errors, 'errors');
189  }
190 }
191 
192 $result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter);
193 
194 if ($result < 0) {
195  setEventMessages($object->error, $object->errors, 'errors');
196 }
197 
198 $num=count($object->lines);
199 
200 
201 if ($action == 'delmouv') {
202  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1);
203  print $formconfirm;
204 }
205 if ($action == 'delbookkeepingyear') {
206 
207  $form_question = array ();
208  $delyear = GETPOST('delyear');
209 
210  if (empty($delyear)) {
211  $delyear = dol_print_date(dol_now(), '%Y');
212  }
213  $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array');
214 
215  $form_question['delyear'] = array (
216  'name' => 'delyear',
217  'type' => 'select',
218  'label' => $langs->trans('DelYear'),
219  'values' => $year_array,
220  'default' => $delyear
221  );
222 
223  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1, 250);
224  print $formconfirm;
225 }
226 
227 
228 
229 
230 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">';
231 
232 $viewflat = ' <a class="nohover" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">' . $langs->trans("ViewFlatList") . '</a>';
233 $addbutton = '<a class="butAction" href="./card.php?action=create">' . $langs->trans("NewAccountingMvt") . '</a>';
234 
235 $param=$options;
236 if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
237 if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
238 
239 print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $result, $nbtotalofrecords, 'title_accountancy', 0, $viewflat.$addbutton, '', $limit);
240 
241 // Reverse sort order
242 if ( preg_match('/^asc/i', $sortorder) )
243  $sortorder = "asc";
244 else
245  $sortorder = "desc";
246 
247 print '<table class="noborder" width="100%">';
248 
249 print '<tr class="liste_titre">';
250 print '<td class="liste_titre">' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . '</td>';
251 print '<td class="liste_titre"></td>';
252 print '<td class="liste_titre" align="center">';
253 print $langs->trans('From') . ': ';
254 print $form->select_date($search_date_start, 'date_start', 0, 0, 1);
255 print '<br>';
256 print $langs->trans('to') . ': ';
257 print $form->select_date($search_date_end, 'date_end', 0, 0, 1);
258 print '</td>';
259 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_mvt_label" value="' . $search_mvt_label . '"/></td>';
260 print '<td class="liste_titre"><input type="text" size="7" class="flat" name="search_label_account" value="' . $search_label_account . '"/></td>';
261 print '<td class="liste_titre">&nbsp;</td>';
262 print '<td class="liste_titre">&nbsp;</td>';
263 print '<td class="liste_titre" align="center"><input type="text" name="search_ledger_code" size="3" value="' . $search_ledger_code . '"></td>';
264 print '<td class="liste_titre" align="right" colspan="2">';
265 $searchpicto=$form->showFilterAndCheckAddButtons(0);
266 print $searchpicto;
267 print '</td>';
268 
269 print '<tr class="liste_titre">';
270 print_liste_field_titre("AccountAccountingShort", $_SERVER['PHP_SELF']);
271 print_liste_field_titre("TransactionNumShort", $_SERVER['PHP_SELF'], "t.piece_num", "", $options, 'align="right"', $sortfield, $sortorder);
272 print_liste_field_titre("Docdate", $_SERVER['PHP_SELF'], "t.doc_date", "", $options, 'align="center"', $sortfield, $sortorder);
273 print_liste_field_titre("Docref", $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder);
274 print_liste_field_titre("Label");
275 print_liste_field_titre("Debit", $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder);
276 print_liste_field_titre("Credit", $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder);
277 print_liste_field_titre("Codejournal", $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder);
278 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder);
279 print "</tr>\n";
280 
281 print '</tr>';
282 
283 
284 $total_debit = 0;
285 $total_credit = 0;
286 $sous_total_debit = 0;
287 $sous_total_credit = 0;
288 $displayed_account_number = null; // Start with undefined to be able to distinguish with empty
289 
290 $i=0;
291 while ($i < min($num, $limit))
292 {
293  $line = $object->lines[$i];
294 
295  $total_debit += $line->debit;
296  $total_credit += $line->credit;
297 
298  $accountg = length_accountg($line->numero_compte);
299  //if (empty($accountg)) $accountg = '-';
300 
301  // Is it a break ?
302  if ($accountg != $displayed_account_number || ! isset($displayed_account_number)) {
303 
304  // Affiche un Sous-Total par compte comptable
305  if (isset($displayed_account_number)) {
306  print '<tr class="liste_total"><td align="right" colspan="5">'.$langs->trans("SubTotal").':</td><td class="nowrap" align="right">'.price($sous_total_debit).'</td><td class="nowrap" align="right">'.price($sous_total_credit).'</td>';
307  print "<td>&nbsp;</td>\n";
308  print "<td>&nbsp;</td>\n";
309  print '</tr>';
310  }
311 
312  // Show the break account
313  $colspan = 9;
314  print "<tr>";
315  print '<td colspan="'.$colspan.'" style="font-weight:bold; border-bottom: 1pt solid black;">';
316  if (! empty($line->numero_compte) && $line->numero_compte != '-1') print length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte);
317  else print '<span class="error">'.$langs->trans("Unknown").'</span>';
318  print '</td>';
319  print '</tr>';
320 
321  $displayed_account_number = $accountg;
322  //if (empty($displayed_account_number)) $displayed_account_number='-';
323  $sous_total_debit = 0;
324  $sous_total_credit = 0;
325  }
326 
327  print '<tr class="oddeven">';
328  print '<td>&nbsp;</td>';
329  print '<td align="right"><a href="./card.php?piece_num=' . $line->piece_num . '">'.$line->piece_num.'</a></td>';
330  print '<td align="center">' . dol_print_date($line->doc_date, 'day') . '</td>';
331 
332  // TODO Add a link according to doc_type and fk_doc
333  print '<td class="nowrap">';
334  //if ($line->doc_type == 'supplier_invoice')
335  //if ($line->doc_type == 'customer_invoice')
336  print $line->doc_ref;
337  print '</td>';
338 
339  // Affiche un lien vers la facture client/fournisseur
340  $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref);
341  print strlen(length_accounta($line->subledger_account)) == 0 ? '<td>' . $line->label_operation . '</td>' : '<td>' . $line->label_operation . '<br><span style="font-size:0.8em">(' . length_accounta($line->subledger_account) . ')</span></td>';
342 
343 
344  print '<td align="right">' . ($line->debit ? price($line->debit) :''). '</td>';
345  print '<td align="right">' . ($line->credit ? price($line->credit) : '') . '</td>';
346  print '<td align="center">' . $line->code_journal . '</td>';
347  print '<td align="center">';
348  print '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num=' . $line->piece_num . '">' . img_edit() . '</a>&nbsp;';
349  print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delmouv&mvt_num=' . $line->piece_num . $options . '&page=' . $page . '">' . img_delete() . '</a>';
350  print '</td>';
351  print "</tr>\n";
352 
353  // Comptabilise le sous-total
354  $sous_total_debit += $line->debit;
355  $sous_total_credit += $line->credit;
356 
357  $i++;
358 }
359 
360 // Affiche un Sous-Total du dernier compte comptable affiché
361 print '<tr class="liste_total">';
362 print '<td align="right" colspan="5">'.$langs->trans("SubTotal").':</td><td class="nowrap" align="right">'.price($sous_total_debit).'</td><td class="nowrap" align="right">'.price($sous_total_credit).'</td>';
363 print "<td>&nbsp;</td>\n";
364 print "<td>&nbsp;</td>\n";
365 print '</tr>';
366 
367 
368 // Affiche le Total
369 print '<tr class="liste_total">';
370 print '<td align="right" colspan="5">'.$langs->trans("Total").':</td>';
371 print '<td align="right">';
372 print price($total_debit);
373 print '</td>';
374 print '<td align="right">';
375 print price($total_credit);
376 print '</td>';
377 print '<td colspan="2"></td>';
378 print '</tr>';
379 
380 print "</table>";
381 print '</form>';
382 
383 llxFooter();
384 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage Ledger (General Ledger and Subledger)
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
dol_now($mode='gmt')
Return date for now.
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
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_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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
Class to manage generation of HTML components for accounting management.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.