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