noalyss Version-9
acc_bilan.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/*!\file
23 * \brief this class handle the different bilan, from the table bilan
24 *
25 */
26require_once NOALYSS_INCLUDE.'/header_print.php';
27
28/*!
29 * \brief this class handle the different bilan, from the table bilan, parse the form and replace
30 * in the template
31 */
32#[AllowDynamicProperties]
34{
35 var $db; /*!< database connection */
36 var $b_id; /*!< id of the bilan (bilan.b_id) */
37 var $from; /*!< from periode */
38 var $to; /*!< end periode */
39
40 function __construct($p_cn)
41 {
42 $this->db=$p_cn;
43 }
44 /*!
45 * \brief return a string with the form for selecting the periode and
46 * the type of bilan
47 * \param $p_filter_year filter on a year
48 *
49 * \return a string
50 */
51 function display_form($p_filter_year="")
52 {
53 global $g_parameter;
54 $r="";
55 $r.=dossier::hidden();
56 if ( $g_parameter->MY_REPORT == 'Y') {
57
58 $r.= '<TABLE>';
59
60 $r.='<TR>';
61 // filter on the current year
62 $w=new ISelect();
63 $w->table=1;
64
65 $periode_start=$this->db->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_start,p_end");
66
67 $periode_end=$this->db->make_array("select p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by p_end,p_start");
68
69 $w->label=_("Depuis");
70 $w->value=$this->from;
71 $w->selected=$this->from;
72 $r.= td($w->input('from_periode',$periode_start));
73 $w->label=_(" jusque ");
74 $w->value=$this->to;
75 $w->selected=$this->to;
76 $r.= td($w->input('to_periode',$periode_end));
77 $r.= "</TR>";
78 $r.="<tr>";
79 $mod=new ISelect();
80 $mod->table=1;
81 $mod->value=$this->db->make_array("select b_id, b_name from bilan order by b_name");
82 $mod->label=_("Choix du bilan");
83 $r.=td($mod->input('b_id'));
84 $r.="</tr>";
85 $r.= '</TABLE>';
86 return $r;
87 } elseif($g_parameter->MY_REPORT=="N") {
88
89 $periode=new Periode($this->db);
90 $from_periode=new IDate("from_periode");
91 $from_periode->value=$periode->get_first_date();
92 $to_periode=new IDate("to_periode");
93 $to_periode->value=$this->db->get_value("select to_char(max(p_end),'DD.MM.YYYY') from parm_periode $p_filter_year");
94 $r.='<p>';
95 $r.=_("Depuis")." ".$from_periode->input()." "._("jusque")." ".$to_periode->input();
96 $r.='</p>';
97 $mod=new ISelect();
98 $mod->value=$this->db->make_array("select b_id, b_name from bilan order by b_name");
99 $r.='<p>';
100 $r.=_("Choix du bilan");
101 $r.=$mod->input('b_id');
102 $r.='</p>';
103 return $r;
104 }else {
106 $msg=_("Configurer le report ");
107 echo_warning($msg . HtmlInput::anchor('COMPANY',"?gDossier=$dossier_id&ac=CFG/COMPANY"));
108 }
109 }
110 /**
111 * @brief check and warn if an accound has the wrong saldo
112 * @param $p_message legend of the fieldset
113 * @param $p_type type of the Acccount ACT actif, ACTINV...
114 * @param $p_type the saldo must debit or credit
115 */
116 private function warning($p_message,$p_type,$p_deb)
117 {
118 global $g_parameter;
119 $filter_sql="";
120 if ( $g_parameter->MY_REPORT=="Y") {
121 $filter_sql= sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per') ;
122 $periode=new Periode($this->db,$this->from);
123 $exercice=$periode->get_exercice();
124 } else {
125 $filter_sql=$this->filter_date();
126 $exercice=$this->db->get_value("select max( p_exercice) from parm_periode
127 where p_start >= to_date($1,'DD.MM.YYYY')
128 and p_end <= to_date($2,'DD.MM.YYYY') ",
129 [$this->from,$this->to]);
130 }
131 $sql="select
132 pcm_val,
133 pcm_lib,
134 sum(amount_deb) as amount_debit,
135 sum(amount_cred) as amount_credit
136 from
137 tmp_pcmn
138 join (select
139 j_poste,
140 case when j_debit='t' then j_montant else 0 end as amount_deb,
141 case when j_debit='f' then j_montant else 0 end as amount_cred
142 from jrnx
143 where ".$filter_sql."
144
145 ) as m on (j_poste=pcm_val)
146 where
147 pcm_type = '$p_type'
148 group by pcm_val,pcm_lib";
149 $res=$this->db->exec_sql($sql);
150 if ( Database::num_row($res) ==0 )
151 return;
152 $count=0;
153 $nRow=Database::num_row($res);
154
155 $ret="";
156 $obj=new Acc_Account_Ledger($this->db,0);
157 // $sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
158 // Find exercice
159
160 for ($i=0;$i<$nRow;$i++)
161 {
162
164 /* set the periode filter */
165 $obj->id=$line['pcm_val'];
166 $solde_signed=bcsub($line['amount_debit'],$line['amount_credit']);
167
168 if (
169 ($solde_signed < 0 && $p_deb == 'D' ) ||
170 ($solde_signed > 0 && $p_deb == 'C' )
171 )
172 {
173 $ret.= '<li> '.HtmlInput::history_account($line['pcm_val'],_('Anomalie pour le compte ').$line['pcm_val'].' '.h($line['pcm_lib']).
174 " D: ".$line['amount_debit'].
175 " C: ".$line['amount_credit']." diff ".(abs($solde_signed)),"",$exercice);
176 $count++;
177 }
178
179 }
180
181 echo '<fieldset>';
182 echo '<legend>'.$p_message.'</legend>';
183 if ( $count <> 0 )
184 {
185 echo '<ol>'.$ret.'</ol>';
186 echo '<span class="error">'._("Nbres anomalies").' : '.$count.'</span>';
187 }
188 else
189 echo _("Pas d'anomalie détectée");
190 echo '</fieldset>';
191
192
193 }
194 /*!\brief verify that the saldo is good for the type of account */
195 function verify()
196 {
197 global $g_parameter;
198 bcscale(2);
199 echo '<h3>'._("Comptes normaux").'</h3>';
200 $this->warning(_('Actif avec un solde crediteur'),'ACT','D');
201 $this->warning(_('Passif avec un solde debiteur'),'PAS','C');
202 $this->warning(_('Compte de resultat : Charge avec un solde crediteur'),'CHA','D');
203 $this->warning(_('Compte de resultat : produit avec un solde debiteur'),'PRO','C');
204 echo '<hr>';
205 echo '<h3>'._("Comptes inverses").' </h3>';
206 $this->warning(_('Compte inverse : actif avec un solde debiteur'),'ACTINV','C');
207 $this->warning(_('Compte inverse : passif avec un solde crediteur'),'PASINV','D');
208 $this->warning(_('Compte inverse : Charge avec un solde debiteur'),'CHAINV','C');
209 $this->warning(_('Compte inverse : produit avec un solde crediteur'),'PROINV','D');
210 echo '<h3'._("Solde").' </h3>';
211 if ( $g_parameter->MY_REPORT == 'Y') {
212
213 /* set the periode filter */
214 $sql_periode = sql_filter_per($this->db, $this->from, $this->to, 'p_id', 'j_tech_per');
215 } else {
216 $sql_periode=$this->filter_date();
217 }
218 $sqlAccount="select sum(amount_deb) as amount_debit ,
219 sum(amount_cred) as amount_credit
220 from (
221 select j_poste,
222 case when j_debit='t' then j_montant else 0 end as amount_deb,
223 case when j_debit='f' then j_montant else 0 end as amount_cred
224 from
225 jrnx
226 where
227 $sql_periode
228 ) as JP1 join tmp_pcmn on (JP1.j_poste=pcm_val)
229 where pcm_type=$1 or pcm_type=$2";
230
231
232 if ( ! $this->db->is_prepare("sqlAccount") ) $this->db->prepare("sqlAccount",$sqlAccount);
233
234
235
236 /* debit Actif */
237 $res=$this->db->execute("sqlAccount",array('ACT','ACTINV'));
239
240 /* Show detail */
241
242 $debit_actif=($result === false)?0:$result['amount_debit'];
243 /* Credit Actif */
244 $credit_actif=($result === false)?0:$result['amount_credit'];
245 $total_actif=abs(bcsub($debit_actif,$credit_actif));
246 echo '<table >';
247 echo tr(td(_('Total actif')).td($total_actif,'style="text-align:right"'));
248
249 /* debit passif */
250 $res=$this->db->execute("sqlAccount",array('PAS','PASINV'));
252 $debit_passif=($result === false)?0:$result['amount_debit'];
253
254 /* Credit passif */
255 $credit_passif=($result === false)?0:$result['amount_credit'];
256
257 $total_passif=abs(bcsub($debit_passif,$credit_passif));
258
259 /* diff actif / passif */
260 echo tr(td(_('Total passif')).td($total_passif,'style="text-align:right"'));
261 if ( $total_actif != $total_passif )
262 {
263 $diff=bcsub($total_actif,$total_passif);
264 echo tr(td(' Difference Actif - Passif ').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
265 }
266
267 /* debit charge */
268 $res=$this->db->execute("sqlAccount",array('CHA','CHAINV'));
270 $debit_charge=($result === false)?0:$result['amount_debit'];
271
272 /* Credit charge */
273 $credit_charge=($result === false)?0:$result['amount_credit'];
274
275 $total_charge=abs(bcsub($debit_charge,$credit_charge));
276 echo tr(td(_('Total charge ')).td($total_charge,'style="text-align:right"'));
277
278
279 /* debit prod */
280 $res=$this->db->execute("sqlAccount",array('PRO','PROINV'));
282 $debit_pro=($result === false)?0:$result['amount_debit'];
283
284 /* Credit prod */
285 $credit_pro=($result === false)?0:$result['amount_credit'];
286
287 $total_pro=abs(bcsub($debit_pro,$credit_pro));
288 echo tr(td(_('Total produit')).td($total_pro,'style="text-align:right"'));
289
290 $diff=bcsub($total_pro,$total_charge);
291
292 echo tr( td(_("Difference Produit - Charge"),'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
293 echo '</table>';
294 }
295 /*!
296 * \brief get data from the $_GET
297 *
298 */
300 {
301 // $g_parameter=new Noalyss_Parameter_Folder($this->db);
302 global $g_parameter;
303 $http=new \HttpInput();
304 $this->b_id=$http->get("b_id","number","");
305 if ( $g_parameter->MY_REPORT=="Y") {
306
307 $this->from=$http->get("from_periode","number",-1);
308 $this->to=$http->get("to_periode","number",-1);
309 }else {
310 $this->from=$http->get("from_periode","date","");
311 $this->to=$http->get("to_periode","date","");
312
313 }
314 }
315 /*!\brief load from the database the document data */
316 function load():void
317 {
318 try
319 {
320 if ( $this->b_id=="")
321 throw new Exception(_("le formulaire id n'est pas donnee"));
322
323 $sql="select b_name,b_file_template,b_file_form,lower(b_type) as b_type from bilan where".
324 " b_id = $1";
325 $res=$this->db->exec_sql($sql,[$this->b_id]);
326
327 if ( Database::num_row($res)==0)
328 throw new Exception (_('Aucun enregistrement trouve'));
330 $this->b_name=$array['b_name'];
331 $this->b_file_template=$array['b_file_template'];
332 $this->b_file_form=$array['b_file_form'];
333 $this->b_type=$array['b_type'];
334
335 }
336 catch(Exception $Ex)
337 {
338 record_log($Ex);
339 echo $Ex->getMessage();
340 throw $Ex;
341 }
342 }
343 /*!\brief open the file of the form */
344 /*\return an handle to this file */
345 function file_open_form()
346 {
347 $form=fopen($this->b_file_form,'r');
348 if ( $form == false)
349 {
350 echo 'Cannot Open';
351 throw new Exception(_('Echec ouverture fichier '.$this->b_file_form));
352 }
353 return $form;
354 }
355 /*!\brief open the file with the template */
356 /*\return an handle to this file */
358 {
359 $templ=fopen($this->b_file_template,'r');
360 if ( $templ == false)
361 {
362 echo 'Cannot Open';
363 throw new Exception(_('Echec ouverture fichier '.$this->b_file_template));
364 }
365 return $templ;
366
367 }
368 /*!
369 * \brief Compute all the formula
370 * \param $p_handle the handle to the file
371 * \param
372 * \param
373 *
374 *
375 * \return
376 */
377 function compute_formula($p_handle)
378 {
379 global $g_parameter;
380 while (! feof ($p_handle))
381 {
382 $buffer=trim(fgets($p_handle));
383 //echo "buffer [$buffer]\n";
384 // $a=(Impress::check_formula($buffer) == true)?"$buffer ok<br>":'<font color="red">'.'Pas ok '.$buffer."</font><br>";
385 // echo $a;
386 // blank line are skipped
387 if (noalyss_strlentrim($buffer)==0)
388 continue;
389 // skip comment
390 if ( strpos($buffer,'#') === true )
391 continue;
392 // buffer contains a formula A$=....
393 // We need to eval it
394 $type_date= ($g_parameter->MY_REPORT=="Y")?0:1;
395 $a=Impress::parse_formula($this->db,"$buffer",$buffer,$this->from,$this->to,false,$type_date);
396 $b=noalyss_str_replace("$","\$this->",$a);
397 // echo $b;
398 if ( eval("$b;") === false )
399 echo(__FILE__.__LINE__."Code failed with $b");
400
401
402 }// end read form line per line
403 }
404 /*!\brief generate the ods document
405 * \param the handle to the template file
406 * \return the xml
407 *@note
408 * Sur une seule ligne il y a plusieurs données, donc il y a plusieurs boucles, pour les autres documents
409 * cela devrait être fait aussi, actuellement ces documents, n'acceptent qu'une formule par ligne.
410 *@note
411 * Pas de header dans les entêtes car n'est pas compris dans le document qu'on utilise
412 */
413 function generate_odt()
414 {
415 // create a temp directory in /tmp to unpack file and to parse it
416 $dirname=tempnam($_ENV['TMP'],'bilan_');
417
418
419 unlink($dirname);
420 mkdir ($dirname);
421 chdir($dirname);
422
423 // Les documents sont dans noalyss/html/document/...
424 $file_base=NOALYSS_HOME.DIRECTORY_SEPARATOR.$this->b_file_template;
425 $work_file=basename($file_base);
426 if ( copy ($file_base,$work_file) == false )
427 {
428 echo _("erreur Ouverture fichier");
429 throw new Exception(_('Echec ouverture fichier '.$file_base));
430 }
431 ob_start();
432 /* unzip the document */
433 $zip = new Zip_Extended;
434 if ($zip->open($work_file) === TRUE)
435 {
436 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
437 $zip->close();
438 } else
439 {
440 echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
441 }
442
443 ob_end_clean();
444 unlink($work_file);
445 // remove the zip file
446 $p_file=fopen('content.xml','r');
447
448 if ( $p_file == false)
449 {
450 throw new Exception(_('Echec ouverture fichier '.$p_file));
451 }
452
453 $r="";
454 $regex="/&lt;&lt;\\$[A-Z]*[0-9]*&gt;&gt;/";
455 $lt="&lt;";
456 $gt="&gt;";
457 $header_txt=mb_convert_encoding(header_txt($this->db),'UTF-8','ISO8859-1');
458 $header_txt=iconv('ISO-8859-1','UTF-8//IGNORE',header_txt($this->db));
459
460
461
462 while ( !feof($p_file) )
463 {
464 $line_rtf=fgets($p_file);
465
466 /*
467 * replace the header tag, doesn't work if inside header
468 */
469 $line_rtf=preg_replace('/&lt;&lt;header&gt;&gt;/',$header_txt,$line_rtf);
470
471
472 // the line contains the magic <<
473 $tmp="";
474
475
476 while (preg_match_all($regex,$line_rtf,$f2) > 0 )
477 {
478 // the f2 array contains all the magic << in the line
479 foreach ($f2 as $f2_array)
480 {
481 foreach ($f2_array as $f2_str)
482 {
483 $to_remove=$f2_str;
484 $f2_value=noalyss_str_replace("&lt;","",$f2_str);
485 $f2_value=noalyss_str_replace("&gt;","",$f2_value);
486 $f2_value=noalyss_str_replace("$","",$f2_value);
487
488
489
490 // check for missing variables and labels (N vars)
491 if( ! isset($this->$f2_value))
492 {
493
494 $a = "!!".$f2_value."!!";
495 if( substr($f2_value, 0, 1) == "N" )
496 {
497 $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
498 " substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
499 if($ret[0]['acct_name'])
500 {
501 $a = $ret[0]['acct_name'];
502 $a=noalyss_str_replace('<','&lt;',$a);
503 $a=noalyss_str_replace('>','&gt;',$a);
504 }
505 }
506 }
507 else
508 {
509 $a=$this->$f2_value;
510 }
511 if ( $a=='-0' ) $a=0;
512
513 /* allow numeric cel in ODT for the formatting and formula */
514 if ( is_numeric($a) )
515 {
516 /* -- for libreOffice < 5 or openoffice -- */
517 $searched='office:value-type="string"><text:p>'.$f2_str;
518 $replaced='office:value-type="float" office:value="'.$a.'"><text:p>'.$f2_str;
519 $line_rtf=noalyss_str_replace($searched, $replaced, $line_rtf);
520 /* -- for libreOffice > 5 -- */
521 $searched='office:value-type="string" calcext:value-type="string"><text:p>'.$f2_str;
522 $replaced='office:value-type="float" office:value="'.$a.'" calcext:value-type="float"><text:p>'.$f2_str;
523 $line_rtf=noalyss_str_replace($searched, $replaced, $line_rtf);
524 }
525
526
527 $line_rtf=noalyss_str_replace($f2_str,$a,$line_rtf);
528
529 }// foreach end
530 } // foreach
531 } // preg_match_all
532 $r.=$line_rtf;
533
534 }// odt file is read
535
536 return $r;
537
538 }
539
540 /*!
541 * \brief generate the plain file (rtf,txt, or html)
542 * \param the handle to the template file
543 */
544 function generate_plain($p_file)
545 {
546 $r="";
547 if ( $this->b_type=='html')
548 {
549 $lt='&lt;';
550 $gt='&gt;';
551 $pattern='/&lt;&lt;header&gt;&gt;/';
552 }
553 else
554 {
555 $lt='<';
556 $gt='>';
557 $pattern='/<<header>>/';
558 }
559
560 $header_txt=header_txt($this->db);
561
562 if ($this->b_type == "rtf") {
563 $header_txt=convert_to_rtf($header_txt);
564 }
565 while ( !feof($p_file) )
566 {
567 $line_rtf=fgets($p_file);
568
569 $line_rtf=preg_replace($pattern,$header_txt,$line_rtf);
570
571
572 // the line contains the magic <<
573 if (preg_match_all("/".$lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt."/",$line_rtf,$f2) > 0)
574 {
575 // DEBUG
576 // echo $r.'<br>';
577 // the f2 array contains all the magic << in the line
578 foreach ($f2 as $f2_str)
579 {
580 // DEBUG
581 // echo "single_f2 = $f2_str <br>";
582 // replace single_f2 by its value
583 $f2_value=noalyss_str_replace($lt,"",$f2_str);
584 $f2_value=noalyss_str_replace($gt,"",$f2_value);
585 $f2_value=noalyss_str_replace("$","",$f2_value);
586 $f2_value=$f2_value[0];
587
588 // check for missing variables and labels (N vars)
589 if( ! isset($this->$f2_value))
590 {
591 $a = "!!".$f2_value."!!";
592 if( substr($f2_value, 0, 1) == "N" )
593 {
594 $ret = $this->db->get_array("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE ".
595 " pcm_val::text LIKE substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
596 array($f2_value));
597 if($ret[0]['acct_name'])
598 {
599 /* for rtf we have the string to put it in latin1 */
600 if ( $this->b_type != "rtf") { $a = mb_convert_encoding(($ret[0]['acct_name']),'ISO-8859-1','UTF-8');}
601 if ( $this->b_type == "rtf") { $a =convert_to_rtf($ret[0]['acct_name']);}
602 }
603 }
604 }
605 else
606 {
607 // DEBUG
608 //echo "f2_value=$f2_value";
609 // $a=${"$f2_value"};
610 $a=$this->$f2_value;
611 }
612 // DEBUG echo " a = $a";
613 if ( $a=='-0' ) $a=0;
614 $line_rtf=noalyss_str_replace($f2_str,$a,$line_rtf);
615
616 }// foreach end
617 }
618 $r.=$line_rtf;
619
620 }// rtf file is read
621 // DEBUG
622 // fwrite($out,$r);
623
624 return $r;
625
626
627
628
629 }
630 /*!\brief generate the document and send it to the browser
631 */
632 function generate()
633 {
634 // Load the data
635 $this->load();
636 // Open the files
637 $form=$this->file_open_form();
638
639 // Compute all the formula and add the value to this
640 $this->compute_formula($form);
641 fclose($form);
642 // open the form
643 $templ=$this->file_open_template();
644 switch ($this->b_type)
645 {
646 case 'rtf':
647 $result=$this->generate_plain($templ);
648 $this->send($result);
649 break;
650 case 'txt':
651 $result=$this->generate_plain($templ);
652 $this->send($result);
653 case 'html':
654 $result=$this->generate_plain($templ);
655 $this->send($result);
656
657 break;
658 case 'odt':
659 case 'ods':
660 $result=$this->generate_odt($templ);
661 $this->send($result);
662 break;
663
664 }
665 fclose($templ);
666 }
667 /*!\brief send the result of generate plain to the browser
668 * \param $p_result is the string returned by generate_...
669 */
670 function send($p_result)
671 {
672 switch ($this->b_type)
673 {
674 case 'rtf':
675 // A rtf file is generated
676 header('Content-type: application/rtf');
677 header('Content-Disposition: attachment; filename="'.$this->b_name.'.rtf"');
678 echo $p_result;
679 break;
680
681 case 'txt':
682 // A txt file is generated
683 header('Content-type: application/txt');
684 header('Content-Disposition: attachment; filename="'.$this->b_name.'.txt"');
685
686 echo $p_result;
687 break;
688 case 'html':
689 // A txt file is generated
690 header('Content-type: application/html');
691 header('Content-Disposition: attachment; filename="'.$this->b_name.'.html"');
692
693 echo $p_result;
694 break;
695 case 'odt':
696 case 'ods':
697 header("Pragma: public");
698 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
699 header("Cache-Control: must-revalidate");
700 if ( $this->b_type == 'odt' )
701 {
702 header('Content-type: application/vnd.oasis.opendocument.text');
703 header('Content-Disposition: attachment;filename="'.$this->b_name.'.odt"',FALSE);
704 }
705 if ( $this->b_type == 'ods' )
706 {
707 header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
708 header('Content-Disposition: attachment;filename="'.$this->b_name.'.ods"',FALSE);
709 }
710
711 header("Accept-Ranges: bytes");
712 ob_start();
713 // save the file in a temp folder
714 // create a temp directory in /tmp to unpack file and to parse it
715 // bug PHP 7 tempnam throw a notice
716 $dirname=@tempnam($_ENV['TMP'].DIRECTORY_SEPARATOR.'tmp','bilan_');
717
718
719 unlink($dirname);
720 mkdir ($dirname);
721 chdir($dirname);
722 // create a temp directory in /tmp to unpack file and to parse it
723 $file_base=NOALYSS_HOME.DIRECTORY_SEPARATOR.$this->b_file_template;
724 $work_file=basename($file_base);
725 if ( copy ($file_base,$work_file) == false )
726 {
727 throw new Exception ( _("Ouverture fichier impossible"));
728 }
729 /*
730 * unzip the document
731 */
732 ob_start();
733 $zip = new Zip_Extended;
734 if ($zip->open($work_file) === TRUE)
735 {
736 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
737 $zip->close();
738 }
739 else
740 {
741 echo __FILE__.":".__LINE__."cannot unzip model ".$file_base;
742 }
743
744 // Remove the file we do not need anymore
745 unlink ($work_file);
746
747
748 // replace the file
749 $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
750 if ( $p_file == false )
751 {
752 throw new Exception ( _("erreur Ouverture fichier").' content.xml');
753
754 }
755 $a=fwrite($p_file,$p_result);
756 if ( $a==false)
757 {
758 throw new Exception ( _("erreur écriture fichier").' content.xml');
759 }
760 // repack
761 $zip = new Zip_Extended;
762 $res = $zip->open($this->b_name.".".$this->b_type, ZipArchive::CREATE);
763 if($res !== TRUE)
764 {
765 throw new Exception (__FILE__.":".__LINE__."cannot recreate zip");
766 }
767 $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
768 $zip->close();
769
770 ob_end_clean();
771 fclose($p_file);
772 $fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
773 if ( $fdoc == false )
774 {
775 throw new Exception (_("erreur Ouverture fichier"));
776 }
777 $buffer=fread ($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
778 echo $buffer;
779
780 break;
781 // and send
782 }
783
784 }
785 static function test_me()
786 {
787
788 if ( isset($_GET['result']))
789 {
790 ob_start();
792 $a=new Acc_Bilan($cn);
793 $a->get_request_get();
794
795 $a->load();
796 $form=$a->file_open_form();
797 $a->compute_formula($form);
798 fclose($form);
799 // open the form
800 $templ=$a->file_open_template();
801 $r=$a->generate_odt($templ);
802 fclose($templ);
803 ob_end_clean();
804
805 $a->send($r);
806 }
807 else
808 {
810 $a=new Acc_Bilan($cn);
811 $a->get_request_get();
812
813 echo '<form method="get">';
814 echo $a->display_form();
815 echo HtmlInput::hidden('test_select',$_GET['test_select']).dossier::hidden();
816 echo HtmlInput::submit('result','Sauve');
817 echo '</form>';
818 }
819 }
820
821 /**
822 * @brief compute the where clause for filtering with the date
823 * @return string where clause : where jrnx.j_date < ...
824 * @throws Exception if one of the dates is not valid
825 */
826 private function filter_date():string
827 {
828 global $g_parameter;
829 if ( empty(isDate($this->from)) || empty(isDate($this->to)))
830 throw new Exception (_("Date invalide"));
831 $from=format_date($this->from,'DD.MM.YYYY','YYYYMMDD');
832 $to=format_date($this->to,'DD.MM.YYYY','YYYYMMDD');
833 $sql_periode=" to_char(jrnx.j_date,'YYYYMMDD')>= '$from'
834 and to_char(jrnx.j_date,'YYYYMMDD') <='$to' ";
835 return $sql_periode;
836 }
837}
838
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
Definition: ac_common.php:852
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
Definition: ac_common.php:682
isDate($p_date)
Definition: ac_common.php:236
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
echo_warning($p_string)
warns
Definition: ac_common.php:589
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
tr($p_string, $p_extra='')
Definition: ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
if(!function_exists( 'tracedebug')) convert_to_rtf($p_string)
encode the string for RTF, return a string
Definition: ac_common.php:1382
global $g_parameter
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
catch(Exception $e) $exercice
$anc_grandlivre to
$anc_grandlivre from
$dossier_id
Definition: ajax_poste.php:43
foreach($array as $idx=> $m) $w
$_GET['qcode']
Manage the account from the table jrn, jrnx or tmp_pcmn.
this class handle the different bilan, from the table bilan, parse the form and replace in the templa...
generate_plain($p_file)
generate the plain file (rtf,txt, or html)
load()
load from the database the document data
send($p_result)
send the result of generate plain to the browser
get_request_get()
get data from the $_GET
verify()
verify that the saldo is good for the type of account
generate_odt()
generate the ods document
warning($p_message, $p_type, $p_deb)
check and warn if an accound has the wrong saldo
generate()
generate the document and send it to the browser
file_open_template()
open the file with the template
display_form($p_filter_year="")
return a string with the form for selecting the periode and the type of bilan
__construct($p_cn)
compute_formula($p_handle)
Compute all the formula.
static test_me()
filter_date()
compute the where clause for filtering with the date
file_open_form()
open the file of the form
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static id()
return the 'gDossier' value after a check
static connect()
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple anchor with a url or a javascript if $p_js is not null then p_url will be javascript:...
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
static parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval=true, $p_type_date=0, $p_sql="")
For the periode tables parm_periode and jrn_periode.
extends the Zip object
$dirname
Definition: constant.php:42
$count
$SecUser db
$periode_start
Definition: fiche.inc.php:50
$periode_end
Definition: fiche.inc.php:51
header_txt($p_cn)
if( $delta< 0) elseif( $delta==0)