noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
anc_balance_double.class.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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/**
23 *@file
24 *@brief Print the crossed balance between 2 plan
25 */
26
27/**
28 * @class Anc_Balance_Double
29 * @brief Print the crossed balance between 2 plan
30 *
31 */
32
34{
35 /*!
36 * \brief compute the html display
37 *
38 *
39 * \return string
40 */
42 public $to_poste2;
43 public $pa_id2;
44 function display_html ()
45 {
46 if ($this->pa_id == $this->pa_id2) throw new Exception(_("Pas de croisement avec un seul plan"),1000);
47
48 bcscale(2);
49 $r="";
50
51 $array=$this->load();
52 $odd=0;
53 if ( is_array($array) == false )
54 {
55 return $array;
56
57 }
58 $old="";
59 $tot_deb=0;
60 $tot_cred=0;
61
62 foreach ( $array as $row)
63 {
64 $odd++;
65
66 $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
67
68 if ( $old == $row['a_po_name'] )
69 {
70 $r.='<td></td>';
71 }
72 else
73 {
74
75 if ( $tot_deb != 0 || $tot_cred !=0 )
76 {
77 $r.="<tr>".td('');
78 $r.="<td>"._("Total")." </td>".td(nbm($tot_deb),' class="num"').td(nbm($tot_cred),' class="num"');
79 $s=abs(bcsub($tot_deb,$tot_cred));
80
81 $d=($tot_deb>$tot_cred)?'debit':'credit';
82 $r.="<td class=\"num\">".nbm($s)."</td><td>$d</td>";
83 $r.="</tr>";
84 }
85 $tot_deb=0;
86 $tot_cred=0;
87
88 // new
89 $r.="</table>";
90 $r.="<table class=\"result\" style=\"margin-bottom:3px\">";
91 $r.="<tr>";
92 $r.="<th style=\"width:30%\" >"._("Poste Analytique")."</th>";
93 $r.="<th style=\"width:30%\">"._("Poste Analytique")."</th>";
94 $r.="<th style=\"text-align:right\">"._("Débit")."</th>";
95 $r.="<th style=\"text-align:right\">"._("Crédit")."</th>";
96 $r.="<th style=\"text-align:right\">"._("Solde")."</th>";
97 $r.="<th>D/C</th>";
98 $r.="</tr>";
99 $r.='<tr>';
100 $r.=td($row['a_po_name'].' '.$row['a_po_description']);
101 $old=$row['a_po_name'];
102 $r.= '</tr>';
103 $r.= '<tr>';
104 $r.=td('');
105 }
106 $tot_deb=bcadd($tot_deb,$row['a_d']);
107 $tot_cred=bcadd($tot_cred,$row['a_c']);
108
109 $r.=td($row['b_po_name']." ".$row['b_po_description']);
110
111 $r.=td(nbm($row['a_d']),' class="num"');
112 $r.=td(nbm($row['a_c']),' class="num"');
113 $r.=td(nbm($row['a_solde']),' class="num"');
114 $r.=sprintf("<td>%s</td>",$row['a_debit']);
115 $r.="</tr>";
116 } /* end loop */
117
118 if ( $tot_deb != 0 || $tot_cred !=0 )
119 {
120 $r.="<tr>".td('');
121 $r.="<td>Total </td> <td ' class=\"num\"> ".nbm($tot_deb)." </td> <td ' class=\"num\">".nbm($tot_cred)."</td>";
122 $s=abs($tot_deb-$tot_cred);
123 $d=($tot_deb>$tot_cred)?'debit':'credit';
124 $r.=td(nbm($s),' class="num"')."<td>$d</td>";
125 $r.="</tr>";
126 }
127
128 $r.="</table>";
129 $r.=h2info('Résumé');
130 $r.='<table class="result">';
131 $r.='<tr>';
132 $r.=th('Po').
133 th('Nom').
134 th('Débit',' style="text-align:right"').
135 th('Crédit','style="text-align:right" ').
136 th('Solde',' style="text-align:right"');
137
138 $sum=$this->show_sum($array);
140 foreach ($sum as $row)
141 {
142 $r.='<tr>';
143 $r.='<td>'.$row['poste'].'</td>';
144 $r.='<td>'.$row['desc'].'</td>';
145 $r.='<td class="num">'.nbm($row['debit']).'</td>';
146 $r.='<td class="num">'.nbm($row['credit']).'</td>';
147 $diff=bcsub($row['credit'],$row['debit']);
148 $tot_cred=bcadd($tot_cred,$row['credit']);
149 $tot_deb=bcadd($tot_deb,$row['debit']);
150
151 $r.=td(nbm($diff),' class="num" ');
152
153 $r.='<td>'.$row['dc'].'</td>';
154 $r.='</tr>';
155 }
156 $r.='<tr class="highlight">';
157 $r.=td('');
158 $r.=td('total');
159 $r.=td(nbm($tot_deb),'class="num"');
160 $r.=td(nbm($tot_cred),'class="num"');
162 $sign=($tot_cred<$tot_deb)?_("Débit"):_("Crédit");
163 $r.=td(nbm($solde),'class="num" style="border:solid 1px blue;font-weight:bold"');
164 $r.=td($sign);
165 $r.='</tr>';
166 $r.='</table>';
167
168 return $r;
169 }
170 /*!
171 * \brief Display the result in pdf
172 *
173 * \return none
174 */
175 function display_pdf()
176 {
177 $array=$this->load();
178 bcscale(2);
179 if (empty($array))return;
180 $pdf=new PDF($this->db);
181 $pdf->Setdossierinfo(dossier::name());
182 $pdf->setTitle("Balance analytique",true);
183 $pdf->SetAuthor('NOALYSS');
184 $pdf->AliasNbPages();
185 $pdf->AddPage();
186
187 $pa=new Anc_Plan($this->db,$this->pa_id);
188 $pa->get();
189 $pb=new Anc_Plan($this->db,$this->pa_id2);
190 $pb->get();
191 $pdf->SetFont('DejaVu','B',9);
192 $pdf->write_cell(0,7,sprintf("Balance croise plan %s %s ",
193 $pa->name,
194 $pb->name),1,0,'C');
195 $filtre_date="";
196 $filtre_pa="";
197 $filtre_pb="";
198
199 if ( $this->from !="" ||$this->to !="")
200 $filtre_date=sprintf("Filtre date %s %s",
201 $this->from,
202 $this->to);
203 if ( $this->from_poste !="" ||$this->to_poste !="")
204 $filtre_pa=sprintf("Filtre poste plan1 %s %s",
205 ($this->from_poste!="")?"de ".$this->from_poste:" ",
206 ($this->to_poste!="")?"jusque ".$this->to_poste:"");
207
208 if ( $this->from_poste2 !="" ||$this->to_poste2 !="")
209 $filtre_pb=sprintf("Filtre poste plan2 %s %s",
210 ($this->from_poste2!="")?"de ".$this->from_poste2:" ",
211 ($this->to_poste2!="")?"jusque ".$this->to_poste2:"");
212
213 $pdf->SetFont('DejaVu','',8);
214 $pdf->write_cell(50,7,$filtre_date);
215 $pdf->write_cell(50,7,$filtre_pa);
216 $pdf->write_cell(50,7,$filtre_pb);
217 $pdf->line_new();
218
219 $pdf->SetFont('DejaVu','',6);
220 $pdf->write_cell(20,7,'id','B');
221 $pdf->write_cell(100,7,'Poste Comptable','B');
222 $pdf->write_cell(20,7,'Débit','B',0,'L');
223 $pdf->write_cell(20,7,'Crédit','B',0,'L');
224 $pdf->write_cell(20,7,'Solde','B',0,'L');
225 $pdf->write_cell(20,7,'D/C','B',0,'L');
226 $pdf->line_new();
227
228 for ($i=0;$i<count($array);$i++)
229 {
230 $row=$array[$i];
231 $pdf->write_cell(20,6,$row['a_po_name'],0,0,'L');
232 $pdf->write_cell(40,6,mb_substr($row['a_po_description'],0,31),0,0,'L');
233 $pdf->write_cell(20,6,$row['b_po_name'],0,0,'L');
234 $pdf->write_cell(40,6,mb_substr($row['b_po_description'],0,31),0,0,'L');
235 $pdf->write_cell(20,6,$row['a_d'],0,0,'R');
236 $pdf->write_cell(20,6,$row['a_c'],0,0,'R');
237 $side=($row['a_c']>$row['a_d'])?"+":"-";
238 $side=($row['a_c'] == $row['a_d'])?"=":$side;
239 $pdf->write_cell(20,6,$side." ".$row['a_solde'],0,0,'R');
240 $pdf->write_cell(20,6,$row['a_debit'],0,0,'C');
241 $pdf->line_new();
242 }
243
244 $sum=$this->show_sum($array);
245 $pdf->SetFont('DejaVu','B',8);
246 $pdf->write_cell(70,6,'Somme',1,0,'C');
247 $pdf->line_new(5);
248 $pdf->SetFont('DejaVu','',6);
249
250 $pdf->write_cell(20,7,'Poste');
251 $pdf->write_cell(60,7,'Description','B');
252 $pdf->write_cell(20,7,'Débit','B',0,'L');
253 $pdf->write_cell(20,7,'Crédit','B',0,'L');
254 $pdf->write_cell(20,7,'Solde','B',0,'L');
255 $pdf->write_cell(20,7,'D/C','B',0,'L');
256 $pdf->line_new();
257 // Summary
259 for ($i=0;$i<count($sum);$i++)
260 {
261 $row=$sum[$i];
262 $pdf->write_cell(20,6,$row['poste'],0,0,'L');
263 $pdf->write_cell(60,6,$row['desc'],0,0,'L');
264 $pdf->write_cell(20,6,sprintf('%.2f',$row['debit']),0,0,'R');
265 $pdf->write_cell(20,6,sprintf('%.2f',$row['credit']),0,0,'R');
266 $side=($row['credit']>$row['debit'])?"+":"-";
267 $side=($row['debit'] == $row['credit'])?"=":$side;
268 $pdf->write_cell(20,6,sprintf($side." ".'%.2f',$row['solde']),0,0,'R');
269 $pdf->write_cell(20,6,$row['dc'],0,0,'R');
270 $pdf->line_new();
271 $tot_cred=bcadd($tot_cred,$row['credit']);
272 $tot_deb=bcadd($tot_deb,$row['debit']);
273 }
274 $pdf->write_cell(20,6,"",0,0,'L');
275 $pdf->write_cell(60,6,_('Total'),0,0,'L');
276 $pdf->write_cell(20,6,nb($tot_deb),0,0,'R');
277 $pdf->write_cell(20,6,nb($tot_cred),0,0,'R');
278 $side=($tot_cred > $tot_deb)?"+":"-";
279 $side=($tot_deb == $tot_cred)?"=":$side;
280 $solde=abs(bcsub($tot_cred,$tot_deb));
281 $pdf->write_cell(20,6,$side." ".$solde,0,0,'R');
282 $pdf->write_cell(20,6,$row['dc'],0,0,'R');
283 $pdf->line_new();
284 $fDate=date('dmy-Hi');
285 $pdf->output('crossbalance-'.$fDate.'.pdf','D');
286 }
287
288
289 /*!
290 * \brief Compute the csv export
291 * \return string with the csv
292 */
293 function display_csv()
294 {
295 $csv = new Noalyss_Csv("ca_bal_croise");
296 $csv->send_header();
297
298 $csv->add("Poste comptable Analytique");
299 $csv->add("Poste comptable Analytique");
300 $csv->add("Debit");
301 $csv->add("Credit");
302 $csv->add("Solde");
303 $csv->add("D/C");
304
305 $csv->write();
306
307 $array=$this->load();
308 if ( is_array($array) == false )
309 {
310 return $array;
311
312 }
313 foreach ( $array as $row)
314 {
315
316 $csv->add($row['a_po_name']);
317 $csv->add($row['b_po_name']);
318 $csv->add($row['a_d'],'number');
319 $csv->add($row['a_c'],'number');
320 $csv->add($row['a_solde'],'number');
321 $csv->add($row['a_debit'],'text');
322 $csv->write();
323 }
324
325
326 }
327 /*!
328 * \brief Compute the form to display
329 * \param $p_hidden hidden tag to be included (gDossier,...)
330 *
331 *
332 * \return string containing the data
333 */
334 function display_form($p_string='')
335 {
336 $r=parent::display_form($p_string);
337 // show the second plan
338 $r.='<span style="padding:5px;margin:5px;border:2px double blue;display:block;">';
339 $plan=new Anc_Plan($this->db);
340 $plan_id=new ISelect("pa_id2");
341 $plan_id->value=$this->db->make_array("select pa_id, pa_name from plan_analytique order by pa_name");
342 $plan_id->selected=$this->pa_id2;
343 $r.= "Plan Analytique :".$plan_id->input();
344 $r.=HtmlInput::request_to_hidden(array('ac'));
345
346
347
348
349 $poste=new IText();
350 $poste->size=10;
351 $r.=_('Entre le poste ');
352 $r.=$poste->input("from_poste2",$this->from_poste2);
353 $javascript="search_ca(".dossier::id().",'from_poste2','pa_id2')";
354 $r.=Icon_Action::icon_magnifier(uniqid(), $javascript);
355
356 $r.=_(" et le poste ");
357 $poste->id="to_poste2";
358 $r.=$poste->input("to_poste2",$this->to_poste2);
359 $javascript="search_ca(".dossier::id().",'to_poste2','pa_id2')";
360 $r.=Icon_Action::icon_magnifier(uniqid(), $javascript);
361
362 $r.='<span class="notice" style="display:block">'.
363 _('Selectionnez le plan qui vous int&eacute;resse avant de cliquer sur Recherche').
364 '</span>';
365
366 $r.='</span>';
367 $r.=HtmlInput::submit('Affiche', _('Rechercher'));
368 return $r;
369 }
370 /*!
371 * \brief Show the button to export in PDF or CSV
372 * \param $p_string hidden data to include in the form
373 *
374 *
375 * \return string with the button
376 */
377 function show_button($p_string="")
378 {
379 $r="";
380 $r.= '<form method="GET" action="export.php" style="display:inline">';
381 $r.= $p_string;
382 $r.= HtmlInput::hidden("to",$this->to);
383 $r.= HtmlInput::hidden("act","PDF:AncBalDouble");
384 $r.= HtmlInput::hidden("from",$this->from);
385 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
386 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
387 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
388 $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
389 $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
390 $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
391 $r.=dossier::hidden();
392 $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
393 $r.= '</form>';
394
395 $r.= '<form method="GET" action="export.php" style="display:inline">';
396 $r.= HtmlInput::hidden("to",$this->to);
397 $r.= HtmlInput::hidden("act","CSV:AncBalDouble");
398 $r.= HtmlInput::hidden("from",$this->from);
399 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
400 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
401 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
402 $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
403 $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
404 $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
405 $r.= $p_string;
406 $r.= dossier::hidden();
407 $r.=HtmlInput::submit('bt_csv',"Export en CSV");
408 $r.= '</form>';
409 return $r;
410
411 }
412 /*!
413 * \brief complete the object with the data in $_REQUEST
414 */
415 function get_request()
416 {
417 parent::get_request();
418 $this->from_poste2=(isset($_REQUEST['from_poste2']))?$_REQUEST['from_poste2']:"";
419 $this->to_poste2=(isset($_REQUEST['to_poste2']))?$_REQUEST['to_poste2']:"";
420 $this->pa_id2=(isset($_REQUEST['pa_id2']))?$_REQUEST['pa_id2']:"";
421
422 }
423 /*!
424 * \brief load the data from the database
425 *
426 * \return array
427 */
428 function load()
429 {
430 $filter_poste="";
431 $and="";
432 if ( $this->from_poste != "" )
433 {
434 $filter_poste.=" $and upper(pa.po_name)>= upper('".Database::escape_string($this->from_poste)."')";
435 $and=" and ";
436
437 }
438 if ( $this->to_poste != "" )
439 {
440 $filter_poste.=" $and upper(pa.po_name)<= upper('".Database::escape_string($this->to_poste)."')";
441 $and=" and ";
442 }
443
444 if ( $this->from_poste2 != "" )
445 {
446 $filter_poste.=" $and upper(pb.po_name)>= upper('".Database::escape_string($this->from_poste2)."')";
447 $and=" and ";
448 }
449 if ( $this->to_poste2 != "" )
450 {
451 $filter_poste.=" $and upper(pb.po_name)<= upper('".Database::escape_string($this->to_poste2)."')";
452 $and=" and ";
453 }
454 if ( $filter_poste != "")
455 $filter_poste=" where ".$filter_poste;
456
457 $sql="
458 select a_po_id ,
459 pa.po_name as a_po_name,
460 pa.po_description as a_po_description,
461 pb.po_description as b_po_description,
462
463 b_po_id,
464 pb.po_name as b_po_name,
465 sum(a_oa_amount_c) as a_c,
466 sum(a_oa_amount_d) as a_d
467 from (select
468 a.j_id,
469 a.po_id as a_po_id,
470 b.po_id as b_po_id,
471 case when a.oa_debit='t' then a.oa_amount else 0 end as a_oa_amount_d,
472 case when a.oa_debit='f' then a.oa_amount else 0 end as a_oa_amount_c
473 from
474 operation_analytique as a join operation_analytique as b on (a.oa_row=b.oa_row
475 and a.oa_group=b.oa_group
476 and a.j_id = b.j_id)
477 join poste_analytique as poa on (a.po_id=poa.po_id)
478 join poste_analytique as pob on (b.po_id=pob.po_id)
479 where poa.pa_id= $1
480 and pob.pa_id= $2 ".$this->set_sql_filter()."
481 ) as m join poste_analytique as pa on ( a_po_id=pa.po_id)
482 join poste_analytique as pb on (b_po_id=pb.po_id)
483
484 $filter_poste
485
486 group by a_po_id,b_po_id,pa.po_name,pa.po_description,pb.po_name,pb.po_description
487 order by 2;
488 ";
489
490
491 $array=$this->db->get_array($sql,[$this->pa_id,$this->pa_id2]);
492 $this->has_data=count($array);
493 if ( $this->has_data == 0 )
494 return null;
495 $a=array();
496 $count=0;
497 foreach ($array as $row)
498 {
499 $a[$count]['a_po_id']=$row['a_po_id'];
500 $a[$count]['a_d']=$row['a_d'];
501 $a[$count]['a_c']=$row['a_c'];
502 $a[$count]['b_po_id']=$row['b_po_id'];
503
504 $a[$count]['a_po_name']=$row['a_po_name'];
505 $a[$count]['a_po_description']=$row['a_po_description'];
506 $a[$count]['b_po_name']=$row['b_po_name'];
507 $a[$count]['b_po_description']=$row['b_po_description'];
508 $a[$count]['a_solde']=abs($row['a_c']-$row['a_d']);
509 $a[$count]['a_debit']=($row['a_d']>$row['a_c'])?"debit":"credit";
510
511 $count++;
512 }
513 return $a;
514
515
516 }
517
518
519 /*!
520 * \brief add extra lines with sum of each account
521 * \param $p_array array returned by load()
522 */
524 {
525 $tot_deb=0;
526 $tot_cred=0;
527 $old="";
528 $first=true;
529 $array=array();
530 foreach ( $p_array as $row)
531 {
532
533 if ( $old != $row['a_po_name'] && $first==false )
534
535 {
536 $s=abs($tot_deb-$tot_cred);
537 $d=($tot_deb>$tot_cred)?'debit':'credit';
538 $array[]=array('poste'=>$old,'desc'=>$old_desc
539 ,'debit'=>$tot_deb,'credit'=>$tot_cred,
540 'solde'=>$s,'dc'=>$d);
541
542 $tot_deb=0;
543 $tot_cred=0;
544
545 $old=$row['a_po_name'];
546 $old_desc=$row['a_po_description'];
547 }
548
549 if ( $first )
550 {
551 $first=false;
552 $old=$row['a_po_name'];
553 $old_desc=$row['a_po_description'];
554 }
555
556 $tot_deb+=$row['a_d'];
557 $tot_cred+=$row['a_c'];
558
559
560 }
561 $s=abs($tot_deb-$tot_cred);
562 $d=($tot_deb>$tot_cred)?'debit':'credit';
563 $array[]=array('poste'=>$old,'desc'=>$old_desc
564 ,'debit'=>$tot_deb,'credit'=>$tot_cred,
565
566 'solde'=>$s,'dc'=>$d);
567
568
569 return $array;
570
571 }
572 /*!
573 * \brief for testing and debuggind the class
574 * it must never be called from production system, it is
575 * intended only for developpers
576 * \param
577 * \param
578 * \param
579 *
580 *
581 * \return none
582 */
583 static function test_me()
584 {
585 $a=Dossier::connect();
586
588 $bal->get_request();
589
590 echo '<form method="GET">';
591
592 echo $bal->display_form();
593 echo '</form>';
594 if ( isset($_GET['result']))
595 {
596 echo $bal->show_button("","");
597 echo "<h1>HTML</h1>";
598 echo $bal->display_html();
599 echo "<h1>CSV</h1>";
600 echo $bal->display_csv();
601
602 }
603 }
604}
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
h2info($p_string)
Definition ac_common.php:63
nb($p_number)
format the number for the CSV export
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.
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc pa_id
$anc_grandlivre from_poste
$anc_grandlivre to
$anc_grandlivre to_poste
$anc_grandlivre from
$_REQUEST['ac']
$pa
_("actif, passif,charge,...")
$_GET['qcode']
Print the crossed balance between 2 plan.
show_sum($p_array)
add extra lines with sum of each account
static test_me()
for testing and debuggind the class it must never be called from production system,...
get_request()
complete the object with the data in $_REQUEST
show_button($p_string="")
Show the button to export in PDF or CSV.
$from_poste2
compute the html display
display_form($p_string='')
Compute the form to display.
display_csv()
Compute the csv export.
display_pdf()
Display the result in pdf.
load()
load the data from the database
Concerns the Analytic plan (table plan_analytique)
this class is the mother class for the CA printing
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input Text member :
static icon_magnifier($id, $p_javascript, $p_style="")
Display a icon with a magnify glass.
Manage the CSV : manage files and write CSV record.
API for creating PDF, unicode, based on tfpdf.
Definition pdf.class.php:34
$count
$SecUser db
$side