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_print.php');
00026 require_once 'class_impress.php';
00027
00028 class Anc_GrandLivre extends Anc_Print
00029 {
00030 function set_sql_filter()
00031 {
00032 $sql="";
00033 $and=" and ";
00034 if ( $this->from != "" )
00035 {
00036 $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
00037 }
00038 if ( $this->to != "" )
00039 {
00040 $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
00041 }
00042
00043 return $sql;
00044
00045 }
00046
00047
00048
00049
00050
00051 function load()
00052 {
00053 $filter_date=$this->set_sql_filter();
00054 $cond_poste='';
00055 if ($this->from_poste != "" )
00056 $cond_poste=" and upper(po_name) >= upper('".$this->from_poste."')";
00057 if ($this->to_poste != "" )
00058 $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
00059 $pa_id_cond="";
00060 if ( isset ( $this->pa_id) && $this->pa_id !='')
00061 $pa_id_cond= "pa_id=".$this->pa_id." and";
00062 $array=$this->db->get_array(" select oa_id,
00063 po_name,
00064 oa_description,
00065 po_description,
00066 oa_debit,
00067 to_char(oa_date,'DD.MM.YYYY') as oa_date,
00068 oa_amount,
00069 oa_group,
00070 j_id ,
00071 jr_internal,
00072 jr_id,
00073 jr_comment,
00074 j_poste,
00075 jrnx.f_id,
00076 ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) as qcode
00077 from operation_analytique as B join poste_analytique using(po_id)
00078 left join jrnx using (j_id)
00079 left join jrn on (j_grpt=jr_grpt_id)
00080 where $pa_id_cond oa_amount <> 0.0 $cond_poste $filter_date
00081 order by po_name,oa_date::date,qcode,j_poste");
00082
00083 return $array;
00084 }
00085
00086 function load_csv()
00087 {
00088 $filter_date=$this->set_sql_filter();
00089 $cond_poste='';
00090 if ($this->from_poste != "" )
00091 $cond_poste=" and upper(po_name) >= upper('".$this->from_poste."')";
00092 if ($this->to_poste != "" )
00093 $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
00094 $pa_id_cond="";
00095 if ( isset ( $this->pa_id) && $this->pa_id !='')
00096 $pa_id_cond= "pa_id=".$this->pa_id." and";
00097 $array=$this->db->get_array(" select
00098 po_name,
00099 to_char(oa_date,'DD.MM.YYYY') as oa_date,
00100 j_poste,
00101 ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) as qcode,
00102 jr_comment,
00103 jr_internal,
00104 case when oa_debit='t' then 'D' else 'C' end,
00105 oa_amount
00106 from operation_analytique as B join poste_analytique using(po_id)
00107 left join jrnx using (j_id)
00108 left join jrn on (j_grpt=jr_grpt_id)
00109 where $pa_id_cond oa_amount <> 0.0 $cond_poste $filter_date
00110 order by po_name,oa_date::date,qcode,j_poste");
00111
00112
00113 return $array;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123 function display_html()
00124 {
00125 $r="";
00126
00127 $array=$this->load();
00128 if ( is_array($array) == false )
00129 {
00130 return $array;
00131
00132 }
00133
00134 if ( empty($array) )
00135 {
00136 $r.= _("aucune donnée");
00137 return $r;
00138 }
00139 $r.= '<table class="result" style="width=100%">';
00140 $ix=0;$prev='xx';$idx=0;
00141 $tot_deb=$tot_cred=0;
00142
00143 foreach ( $array as $row )
00144 {
00145 if ($prev != $row['po_name'])
00146 {
00147 if ( $ix>0)
00148 {
00149 $r.='<tr>';
00150 $tot_solde=bcsub($tot_cred,$tot_deb);
00151 $sign=($tot_solde>0)?'C':'D';
00152 $r.=td('').td('').td('').td('').td('').td(nbm($tot_deb),' class="num"').td(nbm($tot_cred),' class="num"').td(nbm($tot_solde).$sign,' class="num"');
00153 }
00154 $r.='<tr>'.'<td colspan="7" style="width:auto">'.'<h2>'.h($row['po_name'].' '.$row['po_description']).'</td></tr>';
00155 $r.= '<tr>'.
00156 '<th>'._('Date').'</th>'.
00157 '<th>'._('Poste').'</th>'.
00158 '<th>'._('Quick_code').'</th>'.
00159 '<th>'._('libelle').'</th>'.
00160 '<th>'._('Num.interne').'</th>'.
00161 '<th style="text-align:right">'._('Debit').'</th>'.
00162 '<th style="text-align:right">'._('Credit').'</th>'.
00163 '</tr>';
00164
00165 $tot_deb=$tot_cred=0;
00166 $prev=$row['po_name'];
00167 $ix++;
00168 }
00169 $class=($idx%2==0)?'even':'odd'; $idx++;
00170 $r.='<tr class="'.$class.'">';
00171 $detail=($row['jr_id'] != null)?HtmlInput::detail_op($row['jr_id'],$row['jr_internal']):'';
00172 $post_detail=($row['j_poste'] != null)?HtmlInput::history_account($row['j_poste'],$row['j_poste']):'';
00173 $card_detail=($row['f_id'] != null)?HtmlInput::history_card($row['f_id'],$row['qcode']):'';
00174 $amount_deb=($row['oa_debit']=='t')?$row['oa_amount']:0;
00175 $amount_cred=($row['oa_debit']=='f')?$row['oa_amount']:0;
00176 $tot_deb=bcadd($tot_deb,$amount_deb);
00177 $tot_cred=bcadd($tot_cred,$amount_cred);
00178
00179 $r.=
00180 '<td>'.$row['oa_date'].'</td>'.
00181 td($post_detail).
00182 td($card_detail).
00183
00184 td($row['jr_comment']).
00185 '<td>'.$detail.'</td>'.
00186 '<td class="num">'.nbm($amount_deb).'</td>'.
00187 '<td class="num">'.nbm($amount_cred)
00188 .'</td>';
00189 $r.= '</tr>';
00190 }
00191 $r.='<tr>';
00192 $tot_solde=bcsub($tot_cred,$tot_deb);
00193 $sign=($tot_solde>0)?'C':'D';
00194 $r.=td('').td('').td('').td('').td('').td(nbm($tot_deb),' class="num"').td(nbm($tot_cred),' class="num"').td(nbm($tot_solde).$sign,' class="num"');
00195
00196 $r.= '</table>';
00197 return $r;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function show_button($p_string="")
00209 {
00210 $r="";
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 $r.= '<form method="GET" action="export.php" style="display:inline">';
00225 $r.= HtmlInput::hidden("act","CSV:AncGrandLivre");
00226 $r.= HtmlInput::hidden("to",$this->to);
00227 $r.= HtmlInput::hidden("from",$this->from);
00228 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
00229 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
00230 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
00231 $r.= $p_string;
00232 $r.= dossier::hidden();
00233 $r.=HtmlInput::submit('bt_csv',"Export en CSV");
00234 $r.= '</form>';
00235 return $r;
00236 }
00237 function display_csv()
00238 {
00239 $r="";
00240
00241 $array=$this->load_csv();
00242 if ( is_array($array) == false )
00243 {
00244 return $array;
00245
00246 }
00247
00248 if ( empty($array) )
00249 {
00250 $r.= _("aucune donnée");
00251 return $r;
00252 }
00253
00254 $ix=0;$prev='xx';
00255 $tot_deb=$tot_cred=0;
00256 $aheader=array();
00257 $aheader[]=array("title"=>'Imp. Analytique','type'=>'string');
00258 $aheader[]=array("title"=>'Date','type'=>'string');
00259 $aheader[]=array("title"=>'Poste','type'=>'string');
00260 $aheader[]=array("title"=>'Quick_Code','type'=>'string');
00261 $aheader[]=array("title"=>'libelle','type'=>'string');
00262 $aheader[]=array("title"=>'Num.interne','type'=>'string');
00263 $aheader[]=array("title"=>'Debit','type'=>'string');
00264 $aheader[]=array("title"=>'Credit','type'=>'num');
00265 Impress::array_to_csv($array, $aheader);
00266 }
00267 }