noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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';
30$gDossier=dossier::id();
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
59$periode=new Periode($cn);
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) {
79 $t_periode=new Periode($cn);
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 '<p>';
194echo _('Indiquer le type de poste');
195echo '<span class="text-muted">',_("actif, passif,charge,..."),'</span>';
196// var $type_account int value 0 => no shown, 1=> show it
197$type_account=new ICheckBox('type_account',1);
198if ($http->request('type_account','string',0)==1) $type_account->selected=true;
199echo $type_account->input();
200echo '</p>';
201echo '</div>';
202?>
203<div>
204 <?php echo _("Récapitulatif par classe")?>
205 <?php
206 $summary=new ICheckBox("summary");
207 $summary->value=1;
208 $is_summary=$http->get("summary","string", 0);
209 $summary->set_check($is_summary);
210 echo $summary->input();
211 ?>
212</div>
213<?php
214echo '</div>';
215echo HtmlInput::submit("view",_("Visualisation"));
216echo '</form>';
217echo '<hr>';
218//-----------------------------------------------------
219// Form
220//-----------------------------------------------------
221// Show the export button
222if ( isset ($_GET['view'] ) )
223{
224
225 $hid=new IHidden();
226 $from_periode=$http->get("from_periode","number");
227 $to_periode=$http->get("to_periode","number");
228 $from_poste=$http->get("from_poste","string");
229 $to_poste=$http->get("to_poste","string");
230
231
232 echo "<table>";
233 echo '<TR>';
234
235 echo '<TD><form method="GET" ACTION="export.php" ';
236 $id=uniqid("export_");
237 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
238
239 echo dossier::hidden().
240 HtmlInput::submit('bt_pdf',"Export PDF").
241 HtmlInput::hidden("ac",$http->request('ac')).
242 HtmlInput::hidden("act","PDF:balance").
243 HtmlInput::hidden("summary", $is_summary).
244 HtmlInput::hidden("from_periode",$from_periode).
245 HtmlInput::hidden("to_periode",$to_periode);
246 echo HtmlInput::hidden('p_filter',$filter);
247 for ($e=0;$e<count($selected);$e++)
248 if (isset($selected[$e]) && in_array ($selected[$e],$array))
249 echo HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
250 for ($e=0;$e<count($array_cat);$e++)
251 if (isset($select_cat[$e]))
252 echo HtmlInput::hidden("r_cat[$e]",$e);
253
254 echo HtmlInput::hidden("from_poste",$from_poste).
255 HtmlInput::hidden("to_poste",$to_poste);
256 echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold','previous_exc'));
257
258 echo "</form></TD>";
259
260 echo '<TD><form method="GET" ACTION="export.php" ';
261 $id=uniqid("export_");
262 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
263
264
265 echo HtmlInput::submit('bt_csv',"Export CSV").
266 dossier::hidden().
267 HtmlInput::hidden("act","CSV:balance").
268 HtmlInput::hidden("from_periode",$from_periode).
269 HtmlInput::hidden("to_periode",$to_periode);
270 echo HtmlInput::get_to_hidden(array('ac'));
271 echo HtmlInput::hidden('p_filter',$filter);
272 for ($e=0;$e<count($selected);$e++){
273 if (isset($selected[$e]) && in_array ($selected[$e],$array)){
274 echo HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
275 }
276 }
277 for ($e=0;$e<count($array_cat);$e++)
278 if (isset($select_cat[$e]))
279 echo HtmlInput::hidden("r_cat[$e]",$e);
280
281 echo HtmlInput::hidden("from_poste",$from_poste).
282 HtmlInput::hidden("to_poste",$to_poste);
283 echo HtmlInput::get_to_hidden(array('unsold','previous_exc'));
284
285 echo "</form></TD>";
286 echo '<td style="vertical-align:top">';
288 echo '</td>';
289 echo "</TR>";
290
291 echo "</table>";
292}
293
294
295//-----------------------------------------------------
296// Display result
297//-----------------------------------------------------
298if ( isset($_GET['view'] ) )
299{
300
301 $bal=new Acc_Balance($cn);
302 if ( $filter==1)
303 {
304 for ($e=0;$e<count($selected);$e++)
305 if (isset($selected[$e]) && in_array ($selected[$e],$array))
306 $bal->jrn[]=$selected[$e];
307 }
308 if ( $filter == 0 )
309 {
310 $bal->jrn=[];
311 }
312 if ( $filter == 2 && ! empty($select_cat))
313 {
314 $bal->filter_cat($select_cat);
315 }
316 $bal->from_poste=$http->get('from_poste');
317 $bal->to_poste=$http->get('to_poste');
318 if ( isset($_GET['unsold'])) $bal->unsold=true;
319 $previous=(isset($_GET['previous_exc']))?1:0;
320 $from_periode=$http->get("from_periode","number");
321 $to_periode=$http->get("to_periode","number");
322 // var $row array from Acc_Balance->get_row
324 $previous= (isset ($row[0]['sum_cred_previous']))?1:0;
325
326 $periode=new Periode($cn);
327 $a=$periode->get_date_limit($from_periode);
328 $b=$periode->get_date_limit($to_periode);
329 echo '<h2 class="h-section">';
330 printf ( _("période du %s au %s"),$a['p_start'],$b['p_end']);
331 echo '</h2>';
332 echo '<span style="display:block">';
333 echo _('Cherche').Icon_Action::infobulle(24);
334 echo HtmlInput::filter_table("t_balance", "0,1","1");
335 echo '</span>';
336 echo '<table id="t_balance" width="100%">';
337 echo '<th>'._("Poste Comptable").'</th>';
338 echo '<th>'._("Libellé").'</th>';
339 if ( $previous == 1 ){
340 echo '<th style="text-align:right;">'._("Débit N-1").'</th>';
341 echo '<th style="text-align:right;">'._('Crédit N-1').'</th>';
342 echo '<th style="text-align:right;">'._('Solde N-1').'</th>';
343
344 }
345 echo '<th style="text-align:right;">'._('Ouverture').'</th>';
346 echo '<th style="text-align:right;">'._('Débit').'</th>';
347 echo '<th style="text-align:right;">'._('Crédit').'</th>';
348 echo '<th style="text-align:right;">'._('Solde').'</th>';
349
350 $i=0;
351 if ( $previous == 1) {
352 $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');
353 }
354 else {
355 $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_deb_ope','sum_cred_ope') ;
356 }
357 foreach($a_sum as $a)
358 {
359 $lvl1[$a]=0;
360 $lvl2[$a]=0;
361 $lvl3[$a]=0;
362 }
363 $lvl1_old='';
364 $lvl2_old='';
365 $lvl3_old='';
366
367 bcscale(2);
368 $nb_row = count($row);
369
370 // Compute for the summary
371 $summary_tab=$bal->summary_init();
372 $summary_prev_tab=$bal->summary_init();
373 foreach ($row as $r)
374 {
375 $i++;
376 if ( $i%2 == 0 )
377 $tr="even";
378 else
379 $tr="odd";
380 $view_history=HtmlInput::history_account($r['poste'], $r['poste'], "",$exercice);
381 if ($previous == 1 ) {
382 $r['solde_previous']=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
383 }
384 /*
385 * level x
386 */
387 foreach (array(3,2,1) as $ind)
388 {
389 if ( ! isset($_GET['lvl'.$ind]))continue;
390 if (${'lvl'.$ind.'_old'} == '') ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
391 if ( ${'lvl'.$ind.'_old'} != mb_substr($r['poste'],0,$ind))
392 {
393
394 echo '<tr class="highlight">';
395 echo td(${'lvl'.$ind.'_old'},'style="font-weight:bold;"');
396 echo td(${'lvl'.$ind.'_old'}." "._("Total niveau")." ".$ind,'style="font-weight:bold;"');
397
398 // compare with previous exercice
399 if ($previous==1) {
400 echo td(nbm(${'lvl'.$ind}['sum_deb_previous']),'class="previous_year" style="font-weight:bold;"');
401 echo td(nbm(${'lvl'.$ind}['sum_cred_previous']),' class="previous_year" style="font-weight:bold;" ');
402 $delta_previous=${'lvl'.$ind}['solde_previous'];
403 $side_previous=($delta_previous > 0 ) ? "D":"C";
404 echo td(nbm(abs($delta_previous))." $side_previous",'class="previous_year" style="text-align:right;font-weight:bold;" ');
405
406 }
407
408 // Ouverture
409 $solde3=bcsub(${'lvl'.$ind}['sum_deb_ope'],${'lvl'.$ind}['sum_cred_ope']);
410 $side3=($solde3<0)?" C":" D";
411 $side3=($solde3==0)?" ":$side3;
412 echo td(nbm(abs($solde3)).$side3,'style="text-align:right;font-weight:bold;"');
413
414 // Saldo debit
415 $solde_deb=bcsub(${'lvl'.$ind}['sum_deb'],${'lvl'.$ind}['sum_deb_ope']);
416 echo td(nbm($solde_deb),'style="text-align:right;font-weight:bold;"');
417
418 // Saldo cred
419 $solde_cred=bcsub(${'lvl'.$ind}['sum_cred'],${'lvl'.$ind}['sum_cred_ope']);
420 echo td(nbm($solde_cred),'style="text-align:right;font-weight:bold;"');
421 $delta=bcsub(${'lvl'.$ind}['solde_cred'],${'lvl'.$ind}['solde_deb']);
422 $side=($delta > 0 ) ? "C":"D";
423 echo td(nbm(abs($delta))." $side",'style="text-align:right;font-weight:bold;" ');
424
425 echo '</tr>';
426 ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
427 foreach($a_sum as $a)
428 {
429 ${'lvl'.$ind}[$a]=0;
430 }
431 }
432 }
433
434 foreach($a_sum as $a)
435 {
436 $lvl1[$a]=bcadd($lvl1[$a],$r[$a]);
437 $lvl2[$a]=bcadd($lvl2[$a],$r[$a]);
438 $lvl3[$a]=bcadd($lvl3[$a],$r[$a]);
439 }
440 // For the Total row , there is no accounting
441 if ( $r['poste'] == "") {
442 $tr="highlight";
443 }
444
445 $summary_tab=$bal->summary_add($summary_tab,$r['poste'],$r['sum_deb'],$r['sum_cred']);
446
447 echo '<TR class="'.$tr.'">';
448 echo td($view_history);
449 // label + warning if the saldo is incorrect
450 $label=$r['label'];
451 if ( $type_account->selected && isset ($r['type'])) {
452 $label .= sprintf("<span class=\"text-70 text-muted\">(%s)</span>",$r['type']);
453 }
454 if (isset ($r['type']) && in_array($r['type'],array('CHA','ACT','PASINV','PROINV')) && $r['sum_deb']<$r['sum_cred'])
455 {
456
457 $label.=" ".Icon_Action::warnbulle(85);
458 }
459 if (isset ($r['type']) && in_array($r['type'],array('PRO','PAS','ACTINV','CHAINV')) && $r['sum_deb']>$r['sum_cred'])
460 {
461
462 $label.=" ".Icon_Action::warnbulle(86);
463 }
464 print '<td>';
466 print '</td>';
467 if ($previous == 1 ) {
468 echo td(nbm($r['sum_deb_previous']),' class="previous_year"');
469 echo td(nbm($r['sum_cred_previous']),' class="previous_year" ');
470 $solde_previous=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
471 $side=($solde_previous<0)?"C":"D";
472 $side=($solde_previous==0)?"":$side;
473 $r['solde_previous']=$solde_previous;
474 echo td(nbm(abs($solde_previous))." ".$side,' class="previous_year"');
475
477 $r['poste'],
478 $r['sum_deb_previous'],
479 $r['sum_cred_previous']);
480
481 }
482 $solde=bcsub($r['sum_deb_ope'],$r['sum_cred_ope']);
483 $side=($solde < 0)?" C":" D";
484 $side=($solde==0)?"":$side;
485 echo td(nbm(abs($solde)).$side,'style="text-align:right;"');
486 echo td(nbm(bcsub($r['sum_deb'],$r['sum_deb_ope'])),'style="text-align:right;"');
487 echo td(nbm(bcsub($r['sum_cred'],$r['sum_cred_ope'])),'style="text-align:right;"');
488
489 $solde2=bcsub($r['sum_deb'],$r['sum_cred']);
490 $side=($solde2 < 0)?" C":" D";
491 $side=($solde2==0)?"":$side;
492
493 echo td(nbm(abs($solde2)).$side,'style="text-align:right;"');
494
495 if ( isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) echo '<td></td>';
496 echo '</TR>';
497
498 }
499 echo '</table>';
500 if ( DEBUGNOALYSS>1) echo \Noalyss\Dbg::hidden_info("\$row", $row);
501 // display the summary
502 if ($is_summary==1) {
503 if ( $previous == 1) {
504 echo '<div style="float:left;margin-right:50px">';
505 echo '<h2>';
506 echo _("Résumé Exercice précédent");
507 echo '</h2>';
508 $bal->summary_display($summary_prev_tab);
509 echo "</div>";
510 }
511 echo '<div style="float:left">';
512 echo '<h2>';
513 echo _("Résumé Exercice courant");
514 echo '</h2>';
515 $bal->summary_display($summary_tab);
516 echo "</div>";
517 }
518}// end submit
519echo "</div>";
520?>
get_array_column($p_array, $key)
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.
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
catch(Exception $e) $exercice
$from
$array_ledger
$from_span
$input_from
$to_span
$unsold
$wex
$selected
$type_account
$array_cat
if( $to==0) $input_to
$is_summary
$ck_lev2
$filter
$to
$select_cat
$from_poste
$ck_lev1
$ck_lev3
_("actif, passif,charge,...")
$ex
$to_poste
$previous_exc
for($i=0;$i<=6;$i++) $ind
Definition calendar.php:55
$_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
about the accountancy period (usually 1 year starting in January until december) = exercice
static print_window()
Javascript to print the current window.
static hidden($p_name, $p_value, $p_id="")
static get_to_hidden($array)
transform $_GET data to hidden
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.
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