00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 require_once("class_ihidden.php");
00027 require_once ('class_anc_print.php');
00028 require_once ('class_anc_plan.php');
00029 require_once ('ac_common.php');
00030 include_once("class_pdf.php");
00031 require_once ('header_print.php');
00032
00033
00034
00035
00036 class Anc_Balance_Simple extends Anc_Print
00037 {
00038
00039
00040
00041
00042
00043
00044 function load()
00045 {
00046 $filter=$this->set_sql_filter();
00047
00048
00049 $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
00050 $sql.=" po_name||' '||coalesce(po_description,'') as po_name";
00051 $sql.=" from ";
00052 $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end as deb,";
00053 $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
00054 $sql.=" from operation_analytique join poste_analytique using(po_id)";
00055 $sql.=(empty($filter) == false)?" where ".$filter:"";
00056 $sql.=" ) as m join poste_analytique using (po_id)";
00057 $sql.=" where pa_id=".$this->pa_id;
00058 $sql.=" group by po_id,po_name,po_description";
00059 $sql.=" order by po_id";
00060 $res=$this->db->exec_sql($sql);
00061
00062 if ( Database::num_row($res) == 0 )
00063 return null;
00064 $a=array();
00065 $count=0;
00066 $array=Database::fetch_all($res);
00067 foreach ($array as $row)
00068 {
00069 $a[$count]['po_id']=$row['po_id'];
00070 $a[$count]['sum_deb']=$row['sum_deb'];
00071 $a[$count]['sum_cred']=$row['sum_cred'];
00072 $a[$count]['po_name']=$row['po_name'];
00073 $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
00074 $a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
00075 $count++;
00076 }
00077 return $a;
00078
00079
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 function set_sql_filter()
00089 {
00090 $sql="";
00091 $and="";
00092 if ( $this->from != "" )
00093 {
00094 $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
00095 $and=" and ";
00096 }
00097 if ( $this->to != "" )
00098 {
00099 $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
00100 $and=" and ";
00101 }
00102 if ( $this->from_poste != "" )
00103 {
00104 $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
00105 $and=" and ";
00106 }
00107 if ( $this->to_poste != "" )
00108 {
00109 $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
00110 $and=" and ";
00111 }
00112 return $sql;
00113
00114 }
00115
00116
00117
00118
00119
00120
00121 function display_html()
00122 {
00123 $r="<table class=\"result\">";
00124 $r.="<tr>";
00125 $r.="<th>Poste comptable Analytique</th>";
00126 $r.="<th>Débit</th>";
00127 $r.="<th>Crédit</th>";
00128 $r.="<th>Solde</th>";
00129 $r.="<th>D/C</th>";
00130 $r.="</tr>";
00131
00132 $array=$this->load();
00133 $odd=0;
00134 if ( is_array($array) == false )
00135 {
00136 return $array;
00137
00138 }
00139 foreach ( $array as $row)
00140 {
00141 $odd++;
00142
00143 $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
00144
00145
00146 $r.=sprintf("<td align=\"left\">%s</td>",h($row['po_name']));
00147 $r.=td(nbm($row['sum_deb']),' class="num"');
00148 $r.=td(nbm($row['sum_cred']),' class="num"');
00149 $r.=td(nbm($row['solde']),' class="num"');
00150 $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
00151 $deb=($row['solde'] == 0 )?'':$deb;
00152 $r.=sprintf("<td>%s</td>",$deb);
00153 $r.="</tr>";
00154 }
00155 $r.="</table>";
00156 return $r;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165 function display_form($p_string="")
00166 {
00167 $r=parent::display_form($p_string);
00168
00169 $r.= HtmlInput::submit('Affiche','Affiche');
00170
00171 return $r;
00172 }
00173
00174
00175
00176
00177
00178
00179 function display_pdf()
00180 {
00181 $array=$this->load();
00182 $pdf=new PDFBalance_Simple($this->db);
00183 $pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
00184 $pdf->AliasNbPages();
00185 $pdf->AddPage();
00186 $pdf->setTitle("Balance analytique",true);
00187
00188 $pdf->SetFont('DejaVu','',6);
00189 for ($i=0;$i<count($array);$i++)
00190 {
00191 $row=$array[$i];
00192 $pdf->Cell(20,6,$row['po_id'],0,0,'L');
00193 $pdf->Cell(90,6,$row['po_name'],0,0,'L');
00194 $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_deb'])),0,0,'R');
00195 $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_cred'])),0,0,'R');
00196 $pdf->Cell(20,6,sprintf('%s',nbm($row['solde'])),0,0,'R');
00197 $pdf->Cell(20,6,$row['debit'],0,0,'R');
00198 $pdf->Ln();
00199 }
00200 $fDate=date('dmy-Hi');
00201 $pdf->output('simple-balance-'.$fDate.'.pdf','D');
00202
00203 }
00204
00205
00206
00207
00208 function display_csv()
00209 {
00210 $array=$this->load();
00211 if ( is_array($array) == false )
00212 {
00213 return $array;
00214
00215 }
00216 $r="";
00217 foreach ( $array as $row)
00218 {
00219
00220 $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
00221 $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
00222 $r.=sprintf("'%s';",$row['po_id']);
00223 $r.=sprintf("'%s';",$row['po_name']);
00224 $r.=sprintf("%s;",nb($row['sum_deb']));
00225 $r.=sprintf("%s;",nb($row['sum_cred']));
00226 $r.=sprintf("%s;",nb($row['solde']));
00227 $r.=sprintf("'%s'",$row['debit']);
00228 $r.="\r\n";
00229 }
00230 return $r;
00231
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 function show_button($p_string="")
00243 {
00244 $r="";
00245 $r.= '<form method="GET" action="export.php" style="display:inline">';
00246 $r.= $p_string;
00247 $r.= dossier::hidden();
00248 $r.= HtmlInput::hidden("to",$this->to);
00249 $r.= HtmlInput::hidden("act","PDF:AncBalSimple");
00250
00251 $r.= HtmlInput::hidden("from",$this->from);
00252 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
00253 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
00254 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
00255 $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
00256 $r.= '</form>';
00257
00258 $r.= '<form method="GET" action="export.php" style="display:inline">';
00259 $r.= HtmlInput::hidden("act","CSV:AncBalSimple");
00260 $r.= HtmlInput::hidden("to",$this->to);
00261 $r.= HtmlInput::hidden("from",$this->from);
00262 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
00263 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
00264 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
00265 $r.= $p_string;
00266 $r.= dossier::hidden();
00267 $r.=HtmlInput::submit('bt_csv',"Export en CSV");
00268 $r.= '</form>';
00269 return $r;
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 static function test_me ()
00284 {
00285
00286 $a=new Database(dossier::id());
00287
00288 $bal=new Anc_Balance_Simple($a);
00289 $bal->get_request();
00290
00291 echo '<form method="GET">';
00292
00293 echo $bal->display_form();
00294 echo '</form>';
00295 if ( isset($_GET['result']))
00296 {
00297 echo $bal->show_button("","");
00298 echo "<h1>HTML</h1>";
00299 echo $bal->display_html();
00300 echo "<h1>CSV</h1>";
00301 echo $bal->display_csv();
00302
00303
00304
00305 }
00306
00307 }
00308 }