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 require_once('class_anc_acc_link.php');
00026
00027 class Anc_Table extends Anc_Acc_Link
00028 {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 function display_form($p_hidden='')
00039 {
00040 $r=parent::display_form($p_hidden);
00041 $icard=new ISelect('card_poste');
00042 $icard->value=array(
00043 array('value'=>1,'label'=>'Par fiche'),
00044 array('value'=>2,'label'=>'Par poste comptable')
00045 );
00046 $icard->selected=$this->card_poste;
00047 $r.=$icard->input();
00048 $r.=HtmlInput::request_to_hidden(array('ac'));
00049 return $r;
00050 }
00051
00052
00053
00054
00055
00056
00057 function load_poste()
00058 {
00059 $sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00060 $sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00061 $this->db->exec_sql('create temporary table table_analytic as select * from comptaproc.table_analytic_account(\''.$this->from.'\',\''.$this->to.'\')');
00062
00063 $header="select distinct po_id,po_name from table_analytic
00064 where
00065 pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
00066 $this->aheader=$this->db->get_array($header,array($this->pa_id));
00067
00068 $this->arow=$this->db->get_array("select distinct card_account,name
00069 from table_analytic
00070 where
00071 pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by card_account",array($this->pa_id));
00072
00073 $this->sql='select sum_amount from table_analytic where card_account=$1 and po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
00074 }
00075
00076
00077
00078
00079
00080 function load_card()
00081 {
00082 $sql_from_poste=($this->from_poste!='')?" and po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00083 $sql_to_poste=($this->to_poste!='')?" and po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00084 $this->db->exec_sql('create temporary table table_analytic as select * from comptaproc.table_analytic_card(\''.$this->from.'\',\''.$this->to.'\')');
00085
00086 $header="select distinct po_id,po_name from table_analytic
00087 where
00088 pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
00089 $this->aheader=$this->db->get_array($header,array($this->pa_id));
00090
00091 $this->arow=$this->db->get_array("select distinct f_id,card_account,name from table_analytic
00092 where
00093 pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by name",array($this->pa_id));
00094 $this->sql='select sum_amount from table_analytic where f_id=$1 and po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
00095 }
00096
00097
00098
00099
00100
00101 function show_button($p_hidden)
00102 {
00103 $r="";
00104 $r.= '<form method="GET" action="export.php" style="display:inline">';
00105 $r.= HtmlInput::hidden("act","CSV:AncTable");
00106 $r.= HtmlInput::hidden("to",$this->to);
00107 $r.= HtmlInput::hidden("from",$this->from);
00108 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
00109 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
00110 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
00111 $r.= HtmlInput::hidden("card_poste",$this->card_poste);
00112 $r.= $p_hidden;
00113 $r.= dossier::hidden();
00114 $r.=HtmlInput::submit('bt_csv',"Export en CSV");
00115 $r.= '</form>';
00116 return $r;
00117 }
00118 function display_html()
00119 {
00120 bcscale(2);
00121 if ( $this->check() != 0)
00122 {
00123 alert('Désolé mais une des dates données n\'est pas valide');
00124 return;
00125 }
00126
00127 if ( $this->card_poste=='1')
00128 {
00129 $this->load_card();
00130
00131 echo '<table class="result">';
00132 echo '<tr>';
00133 echo th('Fiche');
00134 foreach ($this->aheader as $h)
00135 {
00136 echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
00137 }
00138 echo th('Total',' style="text-align:right"');
00139 echo '</tr>';
00140
00141
00142
00143 $tot_global=0;
00144 for ($i=0;$i<count($this->arow);$i++)
00145 {
00146 $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
00147 echo $tr;
00148 echo td(HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['card_account'].' '.$this->arow[$i]['name']));
00149 $tot_row=0;
00150 for ($x=0;$x<count($this->aheader);$x++)
00151 {
00152 $amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
00153 if ($amount==null)$amount=0;
00154 if ( isset($tot_col[$x]))
00155 {
00156 $tot_col[$x]=bcadd($tot_col[$x],$amount);
00157 }
00158 else
00159 {
00160 $tot_col[$x]=$amount;
00161 }
00162 echo td(nbm($amount),' class="num" ');
00163 $tot_row=bcadd($tot_row,$amount);
00164 }
00165 echo td(nbm($tot_row),' class="num"');
00166 $tot_global=bcadd($tot_global,$tot_row);
00167 echo '</tr>';
00168
00169
00170 }
00171 echo '<tr>';
00172 echo td('Totaux');
00173 for ($i=0;$i<count($this->aheader);$i++)
00174 {
00175 echo td(nbm($tot_col[$i]),' class="num"');
00176 }
00177 echo td(nbm($tot_global),' class="num" style="font-size:1.3em;text-weight:bold;border:solid 1px blue"');
00178 echo '</tr>';
00179 echo '</table>';
00180 }
00181 if ( $this->card_poste=='2')
00182 {
00183 $this->load_poste();
00184
00185 echo '<table class="result">';
00186 echo '<tr>';
00187 echo th('poste comptable ');
00188 foreach ($this->aheader as $h)
00189 {
00190 echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
00191 }
00192 echo th('Total',' style="text-align:right"');
00193 echo '</tr>';
00194
00195
00196
00197 $tot_global=0;
00198 for ($i=0;$i<count($this->arow);$i++)
00199 {
00200 $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
00201 echo $tr;
00202 echo td(HtmlInput::history_account($this->arow[$i]['card_account'],$this->arow[$i]['card_account'].' '.$this->arow[$i]['name']));
00203 $tot_row=0;
00204 for ($x=0;$x<count($this->aheader);$x++)
00205 {
00206 $amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
00207 if ($amount==null)$amount=0;
00208 if ( isset($tot_col[$x]))
00209 {
00210 $tot_col[$x]=bcadd($tot_col[$x],$amount);
00211 }
00212 else
00213 {
00214 $tot_col[$x]=$amount;
00215 }
00216 echo td(nbm($amount),' class="num" ');
00217 $tot_row=bcadd($tot_row,$amount);
00218 }
00219 echo td(nbm($tot_row),' class="num"');
00220 $tot_global=bcadd($tot_global,$tot_row);
00221 echo '</tr>';
00222
00223
00224 }
00225 echo '<tr>';
00226
00227 echo td('Totaux');
00228 for ($i=0;$i<count($this->aheader);$i++)
00229 {
00230 echo td(nbm($tot_col[$i]),' class="num"');
00231 }
00232 echo td(nbm($tot_global),' class="num" style="font-size:1.3em;text-weight:bold;border:solid 1px blue"');
00233 echo '</tr>';
00234 echo '</table>';
00235
00236 }
00237
00238 }
00239 function export_csv()
00240 {
00241 bcscale(2);
00242 if ( $this->check () != 0 ) {echo "DATE INVALIDE";exit();}
00243
00244 if ( $this->card_poste=='1')
00245 {
00246 $this->load_card();
00247
00248 echo '"Fiche"';
00249 foreach ($this->aheader as $h)
00250 {
00251 echo ';"'.$h['po_name'].'"';
00252 }
00253 echo ';"Total"';
00254 printf("\r\n");
00255
00256
00257
00258
00259 for ($i=0;$i<count($this->arow);$i++)
00260 {
00261
00262 printf('"%s"',$this->arow[$i]['card_account'].' '.$this->arow[$i]['name']);
00263 $tot_row=0;
00264 for ($x=0;$x<count($this->aheader);$x++)
00265 {
00266 $amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
00267 if ($amount==null)$amount=0;
00268 if ( isset($tot_col[$x]))
00269 {
00270 $tot_col[$x]=bcadd($tot_col[$x],$amount);
00271 }
00272 else
00273 {
00274 $tot_col[$x]=$amount;
00275 }
00276 printf(";%s",nb($amount));
00277 $tot_row=bcadd($tot_row,$amount);
00278 }
00279 printf(";%s",nb($tot_row));
00280 printf("\r\n");
00281
00282
00283 }
00284 }
00285 if ( $this->card_poste=='2')
00286 {
00287 $this->load_poste();
00288
00289 echo '"Poste"';
00290 foreach ($this->aheader as $h)
00291 {
00292 echo ';"'.$h['po_name'].'"';
00293 }
00294 echo ';"Total"';
00295 printf("\r\n");
00296
00297
00298
00299
00300 for ($i=0;$i<count($this->arow);$i++)
00301 {
00302
00303 printf('"%s"',$this->arow[$i]['card_account'].' '.$this->arow[$i]['name']);
00304 $tot_row=0;
00305 for ($x=0;$x<count($this->aheader);$x++)
00306 {
00307 $amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
00308 if ($amount==null)$amount=0;
00309 if ( isset($tot_col[$x]))
00310 {
00311 $tot_col[$x]=bcadd($tot_col[$x],$amount);
00312 }
00313 else
00314 {
00315 $tot_col[$x]=$amount;
00316 }
00317 printf(";%s",nb($amount));
00318 $tot_row=bcadd($tot_row,$amount);
00319 }
00320 printf(";%s",nb($tot_row));
00321 printf("\r\n");
00322
00323
00324 }
00325 }
00326
00327 }
00328
00329 }