noalyss Version-9
balance.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright(2004) Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Show the balance and let you print it or export to PDF
22 * file included by user_impress
23 *
24 * some variable are already defined ($cn, $g_user ...)
25 */
26if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
27include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
28include_once NOALYSS_INCLUDE.'/class/acc_balance.class.php';
31// Get the exercice
32$exercice=$http->request("exercice","number",0);
33if ($exercice == 0 ){
34 $exercice=$g_user->get_exercice();
35}
36
37bcscale(2);
38
39echo '<div class="content">';
40/*
41 * Let you change the exercice
42 */
43echo '<form method="GET" onsubmit="return waiting_box()">';
44echo _('Choisissez un autre exercice')." : ";
46$js=sprintf("updatePeriode(%d,'%s','%s','%s',1)",Dossier::id(),'exercice','from_periode','to_periode');
47$wex=$ex->select('exercice',$exercice,' onchange="'.$js.'"');
48echo $wex->input();
49echo dossier::hidden();
50echo HtmlInput::get_to_hidden(array('ac','type'));
51
52
53// Show the form for period
54echo HtmlInput::get_to_hidden(array('ac'));
55echo HtmlInput::hidden('type','bal');
56echo dossier::hidden();
57
58
60// filter on the current year
61$from=$http->get("from_periode", "number",0);
62$input_from=new IPeriod("from_periode",$from,$exercice);
63$input_from->id="from_periode";
64$input_from->show_end_date=false;
67$input_from->filter_year=true;
69if ( $g_parameter->MY_REPORT=='N') {
70 $input_from->filter_year=false;
71 if ($from == 0) { $input_from->value=$periode->get_first_periode();}
72}
73echo _('Depuis').' :'.$input_from->input();
74// filter on the current year
75$to=$http->get("to_periode", "number",0);
76
77
78if( $to == 0) {
80 list($per_max,$per_min)=$t_periode->get_limit($exercice);
81 $to=$per_min->p_id;
82}
83$input_to=new IPeriod("to_periode",$to,$exercice);
84$input_to->id="to_periode";
85$input_to->show_start_date=false;
86$input_to->filter_year=true;
87$input_to->type=ALL;
88$input_to->cn=$cn;
89$input_to->user=$g_user;
90
91echo " "._('jusque').' :'.$input_to->input();
92echo '<br>';
93echo HtmlInput::button_action(_('Avancé'), " if (\$('balance_advanced_div').style.display=='none') { \$('balance_advanced_div').show();} else { \$('balance_advanced_div').hide();}",uniqid(),"smallbutton");
94//-------------------------------------------------
95echo '<div id="balance_advanced_div" style="display:none">';
96
97/* add a all ledger choice */
98echo _('Filtre')." ";
99// temp var used to set the filter
101
102$array_ledger=$g_user->get_ledger('ALL',3);
104$selected=$http->get('r_jrn','array',array());
105$select_cat=$http->get('r_cat','array',array());
106
108// filter type : none(0), ledger(1), catgory of ledger (sale,purchase...)(=2)
109$filter=$http->get('p_filter',"string",0);
110$filter = ($filter=="")?0:$filter;
111
112echo '<ul style="list-style-type:none">';
113$rad->selected=false;
114if ( $filter==0) $rad->selected='t';
115
116echo '<li>'.$rad->input('p_filter',0)._('Aucun filtre, tous les journaux').'</li>';
117
118$rad->selected=false;
119if ( $filter==1) $rad->selected='t';
120echo '<li>'.$rad->input('p_filter',1)._('Filtré par journal');
121echo HtmlInput::button_choice_ledger(array('div'=>'','type'=>'ALL','all_type'=>1));
122echo '</li>';
123
124$rad->selected=false;
125if ( $filter==2) $rad->selected='t';
126
127echo '<li>'.$rad->input('p_filter',2)._('Filtré par catégorie').HtmlInput::select_cat($array_cat).'</li>';
128echo '</ul>';
129
130echo _('Totaux par sous-niveaux');
131$ck_lev1=new ICheckBox('lvl1');
132$ck_lev2=new ICheckBox('lvl2');
133$ck_lev3=new ICheckBox('lvl3');
134$ck_lev1->value=1;
135$ck_lev2->value=1;
136$ck_lev3->value=1;
137
138
139echo '<ul style="list-style-type:none">';
140
141if ($http->get('lvl1',"string",false) !== false)
142 $ck_lev1->selected=true;
143if ($http->get('lvl2',"string",false) !== false)
144 $ck_lev2->selected=true;
145if ($http->get('lvl3',"string",false) !== false)
146 $ck_lev3->selected=true;
147echo '<li>'.$ck_lev1->input()._('Niveau 1').'</li>';
148echo '<li>'.$ck_lev2->input()._('Niveau 2').'</li>';
149echo '<li>'.$ck_lev3->input()._('Niveau 3').'</li>';
150echo '</ul>';
151
152$unsold=new ICheckBox('unsold');
153if ($http->get('unsold',"string",false) !== false)
154 $unsold->selected=true;
155
156// previous exercice if checked
157$previous_exc=new ICheckBox('previous_exc');
158if ($http->get('previous_exc',"string",false) !== false)
159 $previous_exc->selected=true;
160
161
163$from_poste->name="from_poste";
164$from_poste->set_attribute('ipopup','ipop_account');
165$from_poste->set_attribute('label','from_poste_label');
166$from_poste->set_attribute('account','from_poste');
167
168$from_poste->value=$http->get('from_poste',"string",'');
169$from_span=new ISpan("from_poste_label","");
170
172$to_poste->name="to_poste";
173$to_poste->set_attribute('ipopup','ipop_account');
174$to_poste->set_attribute('label','to_poste_label');
175$to_poste->set_attribute('account','to_poste');
176
177$to_poste->value=$http->get('to_poste',"string",'');
178$to_span=new ISpan("to_poste_label","");
179
180echo "<div>";
181echo _("Plage de postes")." :".$from_poste->input();
182echo $from_span->input();
183echo " "._("jusque")." :".$to_poste->input();
184echo $to_span->input();
185echo "</div>";
186echo '<div>';
187echo '<p>';
188echo _("Uniquement comptes non soldés")." ".$unsold->input();
189echo '</p>';
190echo '<p>';
191echo _("Avec la balance de l'année précédente")." ".$previous_exc->input();
192echo '</p>';
193echo '</div>';
194?>
195<div>
196 <?php echo _("Récapitulatif par classe")?>
197 <?php
198 $summary=new ICheckBox("summary");
199 $summary->value=1;
200 $is_summary=$http->get("summary","string", 0);
201 $summary->set_check($is_summary);
202 echo $summary->input();
203 ?>
204</div>
205<?php
206echo '</div>';
207echo HtmlInput::submit("view",_("Visualisation"));
208echo '</form>';
209echo '<hr>';
210//-----------------------------------------------------
211// Form
212//-----------------------------------------------------
213// Show the export button
214if ( isset ($_GET['view'] ) )
215{
216
217 $hid=new IHidden();
218 $from_periode=$http->get("from_periode","number");
219 $to_periode=$http->get("to_periode","number");
220 $from_poste=$http->get("from_poste","string");
221 $to_poste=$http->get("to_poste","string");
222
223
224 echo "<table>";
225 echo '<TR>';
226
227 echo '<TD><form method="GET" ACTION="export.php" ';
228 $id=uniqid("export_");
229 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
230
231 echo dossier::hidden().
232 HtmlInput::submit('bt_pdf',"Export PDF").
233 HtmlInput::hidden("ac",$http->request('ac')).
234 HtmlInput::hidden("act","PDF:balance").
235 HtmlInput::hidden("summary", $is_summary).
236 HtmlInput::hidden("from_periode",$from_periode).
237 HtmlInput::hidden("to_periode",$to_periode);
238 echo HtmlInput::hidden('p_filter',$filter);
239 for ($e=0;$e<count($selected);$e++)
240 if (isset($selected[$e]) && in_array ($selected[$e],$array))
241 echo HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
242 for ($e=0;$e<count($array_cat);$e++)
243 if (isset($select_cat[$e]))
244 echo HtmlInput::hidden("r_cat[$e]",$e);
245
246 echo HtmlInput::hidden("from_poste",$from_poste).
247 HtmlInput::hidden("to_poste",$to_poste);
248 echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold','previous_exc'));
249
250 echo "</form></TD>";
251
252 echo '<TD><form method="GET" ACTION="export.php" ';
253 $id=uniqid("export_");
254 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
255
256
257 echo HtmlInput::submit('bt_csv',"Export CSV").
258 dossier::hidden().
259 HtmlInput::hidden("act","CSV:balance").
260 HtmlInput::hidden("from_periode",$from_periode).
261 HtmlInput::hidden("to_periode",$to_periode);
262 echo HtmlInput::get_to_hidden(array('ac'));
263 echo HtmlInput::hidden('p_filter',$filter);
264 for ($e=0;$e<count($selected);$e++){
265 if (isset($selected[$e]) && in_array ($selected[$e],$array)){
266 echo HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
267 }
268 }
269 for ($e=0;$e<count($array_cat);$e++)
270 if (isset($select_cat[$e]))
271 echo HtmlInput::hidden("r_cat[$e]",$e);
272
273 echo HtmlInput::hidden("from_poste",$from_poste).
274 HtmlInput::hidden("to_poste",$to_poste);
275 echo HtmlInput::get_to_hidden(array('unsold','previous_exc'));
276
277 echo "</form></TD>";
278 echo '<td style="vertical-align:top">';
280 echo '</td>';
281 echo "</TR>";
282
283 echo "</table>";
284}
285
286
287//-----------------------------------------------------
288// Display result
289//-----------------------------------------------------
290if ( isset($_GET['view'] ) )
291{
292
293 $bal=new Acc_Balance($cn);
294 if ( $filter==1)
295 {
296 for ($e=0;$e<count($selected);$e++)
297 if (isset($selected[$e]) && in_array ($selected[$e],$array))
298 $bal->jrn[]=$selected[$e];
299 }
300 if ( $filter == 0 )
301 {
302 $bal->jrn=[];
303 }
304 if ( $filter == 2 && ! empty($select_cat))
305 {
306 $bal->filter_cat($select_cat);
307 }
308 $bal->from_poste=$http->get('from_poste');
309 $bal->to_poste=$http->get('to_poste');
310 if ( isset($_GET['unsold'])) $bal->unsold=true;
311 $previous=(isset($_GET['previous_exc']))?1:0;
312 $from_periode=$http->get("from_periode","number");
313 $to_periode=$http->get("to_periode","number");
315 $previous= (isset ($row[0]['sum_cred_previous']))?1:0;
316
317 $periode=new Periode($cn);
318 $a=$periode->get_date_limit($from_periode);
319 $b=$periode->get_date_limit($to_periode);
320 echo '<h2>';
321 printf ( _("période du %s au %s"),$a['p_start'],$b['p_end']);
322 echo '</h2>';
323 echo '<span style="display:block">';
324 echo _('Cherche').Icon_Action::infobulle(24);
325 echo HtmlInput::filter_table("t_balance", "0,1","1");
326 echo '</span>';
327 echo '<table id="t_balance" width="100%">';
328 echo '<th>'._("Poste Comptable").'</th>';
329 echo '<th>'._("Libellé").'</th>';
330 if ( $previous == 1 ){
331 echo '<th style="text-align:right;">'._("Débit N-1").'</th>';
332 echo '<th style="text-align:right;">'._('Crédit N-1').'</th>';
333 echo '<th style="text-align:right;">'._('Solde N-1').'</th>';
334
335 }
336 echo '<th style="text-align:right;">'._('Ouverture').'</th>';
337 echo '<th style="text-align:right;">'._('Débit').'</th>';
338 echo '<th style="text-align:right;">'._('Crédit').'</th>';
339 echo '<th style="text-align:right;">'._('Solde').'</th>';
340
341 $i=0;
342 if ( $previous == 1) {
343 $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_deb_ope','sum_cred_ope','sum_cred_previous','sum_deb_previous','solde_previous');
344 }
345 else {
346 $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_deb_ope','sum_cred_ope') ;
347 }
348 foreach($a_sum as $a)
349 {
350 $lvl1[$a]=0;
351 $lvl2[$a]=0;
352 $lvl3[$a]=0;
353 }
354 $lvl1_old='';
355 $lvl2_old='';
356 $lvl3_old='';
357
358 bcscale(2);
359 $nb_row = count($row);
360
361 // Compute for the summary
362 $summary_tab=$bal->summary_init();
363 $summary_prev_tab=$bal->summary_init();
364 foreach ($row as $r)
365 {
366 $i++;
367 if ( $i%2 == 0 )
368 $tr="even";
369 else
370 $tr="odd";
371 $view_history=HtmlInput::history_account($r['poste'], $r['poste'], "",$exercice);
372 if ($previous == 1 ) {
373 $r['solde_previous']=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
374 }
375 /*
376 * level x
377 */
378 foreach (array(3,2,1) as $ind)
379 {
380 if ( ! isset($_GET['lvl'.$ind]))continue;
381 if (${'lvl'.$ind.'_old'} == '') ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
382 if ( ${'lvl'.$ind.'_old'} != mb_substr($r['poste'],0,$ind))
383 {
384
385 echo '<tr class="highlight">';
386 echo td(${'lvl'.$ind.'_old'},'style="font-weight:bold;"');
387 echo td(${'lvl'.$ind.'_old'}." "._("Total niveau")." ".$ind,'style="font-weight:bold;"');
388
389 // compare with previous exercice
390 if ($previous==1) {
391 echo td(nbm(${'lvl'.$ind}['sum_deb_previous']),'class="previous_year" style="font-weight:bold;"');
392 echo td(nbm(${'lvl'.$ind}['sum_cred_previous']),' class="previous_year" style="font-weight:bold;" ');
393 $delta_previous=${'lvl'.$ind}['solde_previous'];
394 $side_previous=($delta_previous > 0 ) ? "D":"C";
395 echo td(nbm(abs($delta_previous))." $side_previous",'class="previous_year" style="text-align:right;font-weight:bold;" ');
396
397 }
398
399 // Ouverture
400 $solde3=bcsub(${'lvl'.$ind}['sum_deb_ope'],${'lvl'.$ind}['sum_cred_ope']);
401 $side3=($solde3<0)?" C":" D";
402 $side3=($solde3==0)?" ":$side3;
403 echo td(nbm(abs($solde3)).$side3,'style="text-align:right;font-weight:bold;"');
404
405 // Saldo debit
406 $solde_deb=bcsub(${'lvl'.$ind}['sum_deb'],${'lvl'.$ind}['sum_deb_ope']);
407 echo td(nbm($solde_deb),'style="text-align:right;font-weight:bold;"');
408
409 // Saldo cred
410 $solde_cred=bcsub(${'lvl'.$ind}['sum_cred'],${'lvl'.$ind}['sum_cred_ope']);
411 echo td(nbm($solde_cred),'style="text-align:right;font-weight:bold;"');
412 $delta=bcsub(${'lvl'.$ind}['solde_cred'],${'lvl'.$ind}['solde_deb']);
413 $side=($delta > 0 ) ? "C":"D";
414 echo td(nbm(abs($delta))." $side",'style="text-align:right;font-weight:bold;" ');
415
416 echo '</tr>';
417 ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
418 foreach($a_sum as $a)
419 {
420 ${'lvl'.$ind}[$a]=0;
421 }
422 }
423 }
424
425 foreach($a_sum as $a)
426 {
427 $lvl1[$a]=bcadd($lvl1[$a],$r[$a]);
428 $lvl2[$a]=bcadd($lvl2[$a],$r[$a]);
429 $lvl3[$a]=bcadd($lvl3[$a],$r[$a]);
430 }
431 // For the Total row , there is no accounting
432 if ( $r['poste'] == "") {
433 $tr="highlight";
434 }
435
436 $summary_tab=$bal->summary_add($summary_tab,$r['poste'],$r['sum_deb'],$r['sum_cred']);
437
438 echo '<TR class="'.$tr.'">';
439 echo td($view_history);
440 // label + warning if the saldo is incorrect
441 $label=$r['label'];
442 if (in_array($r['type'],array('CHA','ACT','PASINV','PROINV')) && $r['sum_deb']<$r['sum_cred'])
443 {
444
445 $label.=" ".Icon_Action::warnbulle(85);
446 }
447 if (in_array($r['type'],array('PRO','PAS','ACTINV','CHAINV')) && $r['sum_deb']>$r['sum_cred'])
448 {
449
450 $label.=" ".Icon_Action::warnbulle(86);
451 }
452 print '<td>';
454 print '</td>';
455 if ($previous == 1 ) {
456 echo td(nbm($r['sum_deb_previous']),' class="previous_year"');
457 echo td(nbm($r['sum_cred_previous']),' class="previous_year" ');
458 $solde_previous=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
459 $side=($solde_previous<0)?"C":"D";
460 $side=($solde_previous==0)?"":$side;
461 $r['solde_previous']=$solde_previous;
462 echo td(nbm(abs($solde_previous))." ".$side,' class="previous_year"');
463
465 $r['poste'],
466 $r['sum_deb_previous'],
467 $r['sum_cred_previous']);
468
469 }
470 $solde=bcsub($r['sum_deb_ope'],$r['sum_cred_ope']);
471 $side=($solde < 0)?" C":" D";
472 $side=($solde==0)?"":$side;
473 echo td(nbm(abs($solde)).$side,'style="text-align:right;"');
474 echo td(nbm(bcsub($r['sum_deb'],$r['sum_deb_ope'])),'style="text-align:right;"');
475 echo td(nbm(bcsub($r['sum_cred'],$r['sum_cred_ope'])),'style="text-align:right;"');
476
477 $solde2=bcsub($r['sum_deb'],$r['sum_cred']);
478 $side=($solde2 < 0)?" C":" D";
479 $side=($solde2==0)?"":$side;
480
481 echo td(nbm(abs($solde2)).$side,'style="text-align:right;"');
482
483 if ( isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) echo '<td></td>';
484 echo '</TR>';
485
486 }
487 echo '</table>';
488 if ( DEBUGNOALYSS>1) echo \Noalyss\Dbg::hidden_info("\$row", $row);
489 // display the summary
490 if ($is_summary==1) {
491 if ( $previous == 1) {
492 echo '<div style="float:left;margin-right:50px">';
493 echo '<h2>';
494 echo _("Résumé Exercice précédent");
495 echo '</h2>';
496 $bal->summary_display($summary_prev_tab);
497 echo "</div>";
498 }
499 echo '<div style="float:left">';
500 echo '<h2>';
501 echo _("Résumé Exercice courant");
502 echo '</h2>';
503 $bal->summary_display($summary_tab);
504 echo "</div>";
505 }
506}// end submit
507echo "</div>";
508?>
get_array_column($p_array, $key)
Definition: ac_common.php:1278
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$from
Definition: balance.inc.php:61
$array_ledger
$gDossier
Definition: balance.inc.php:30
$from_span
$input_from
Definition: balance.inc.php:62
$to_span
$rad
$unsold
$wex
Definition: balance.inc.php:47
global $http
Definition: balance.inc.php:29
global $g_user
Definition: balance.inc.php:29
$selected
$js
Definition: balance.inc.php:46
$array_cat
if( $to==0) $input_to
Definition: balance.inc.php:83
$is_summary
$periode
Definition: balance.inc.php:59
$ck_lev2
$filter
$array
$to
Definition: balance.inc.php:75
global $g_parameter
Definition: balance.inc.php:29
$input_from id
Definition: balance.inc.php:63
$select_cat
$exercice
Definition: balance.inc.php:32
$from_poste
$ck_lev1
$ck_lev3
$ex
Definition: balance.inc.php:45
$to_poste
$previous_exc
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:34
$_GET['qcode']
Class for manipulating data to print the balance of account.
static array_cat()
create an array of the existing cat, to be used in a checkbox form
static id()
return the 'gDossier' value after a check
about the accountancy period (usually 1 year starting in January until december) = exercice
static history_account($p_account, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the account
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static print_window()
Javascript to print the current window.
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static hidden($p_name, $p_value, $p_id="")
static get_to_hidden($array)
transform $_GET data to hidden
static button_choice_ledger($p_array)
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
Html Input.
Generate the form for the periode Data Members.
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input.
Html Input.
Definition: ispan.class.php:32
For the periode tables parm_periode and jrn_periode.
const ALL
Definition: constant.php:204
catch(Exception $exc) $summary_tab
foreach($a_sum as $a) $lvl1_old
$summary_prev_tab
for($e=2;$e< $nb_col;$e++) $a_sum
$t_periode
print
Type of printing.
$side