class_anc_acc_list.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 4431 $ */
00020 
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00022 
00023 /*!\file
00024  * \brief
00025  */
00026 
00027 require_once('class_anc_acc_link.php');
00028 
00029 class Anc_Acc_List extends Anc_Acc_Link
00030 {
00031   /**
00032    *@brief display form to get the parameter
00033    *  - card_poste 1 by card, 2 by account
00034    *  - from_poste
00035    *  - to_poste
00036    *  - from from date
00037    *  - to until date
00038    *  - pa_id Analytic plan to use
00039    */
00040   function display_form($p_hidden='')
00041   {
00042     $r=parent::display_form($p_hidden);
00043     $icard=new ISelect('card_poste');
00044     $icard->value=array(
00045                         array('value'=>1,'label'=>'Par fiche /Activité'),
00046                         array('value'=>2,'label'=>'Par poste comptable/Activité'),
00047                         array('value'=>3,'label'=>'Par activité/Fiche'),
00048                         array('value'=>4,'label'=>'Par activité/Poste Comptable')
00049 
00050                         );
00051 
00052     $icard->selected=$this->card_poste;
00053     $r.=$icard->input();
00054     $r.=HtmlInput::request_to_hidden(array('ac'));
00055     return $r;
00056   }
00057  /**
00058    * load the data
00059    * does not return anything but give a value to this->aheader and this->arow
00060    */
00061   function load_anc_account()
00062   {
00063     $date=$this->set_sql_filter();
00064     $date=($date != '')?"  $date":'';
00065     $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00066     $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00067     $this->arow=$this->db->get_array("
00068  SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
00069         CASE
00070             WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00071             ELSE operation_analytique.oa_amount
00072         END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
00073    FROM operation_analytique
00074    JOIN poste_analytique po USING (po_id)
00075    JOIN jrnx USING (j_id)
00076    JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
00077 "                                       where
00078                 pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
00079 
00080   GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
00081  HAVING sum(
00082 CASE
00083     WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00084     ELSE operation_analytique.oa_amount
00085 END) <> 0::numeric  order by po_id,j_poste",array($this->pa_id));
00086 
00087   }
00088   /**
00089    * load the data
00090    * does not return anything but give a value to this->aheader and this->arow
00091    */
00092   function load_anc_card()
00093   {
00094     $date=$this->set_sql_filter();
00095     $date=($date != '')?"  $date":'';
00096     $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00097     $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00098     $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
00099         CASE
00100             WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00101             ELSE operation_analytique.oa_amount
00102         END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
00103            FROM fiche_detail
00104           WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
00105    FROM operation_analytique
00106    JOIN poste_analytique po USING (po_id)
00107    JOIN jrnx USING (j_id) ".
00108                                      " where pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste
00109                                      ."
00110   GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
00111    FROM fiche_detail
00112   WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
00113  HAVING sum(
00114 CASE
00115     WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00116     ELSE operation_analytique.oa_amount
00117 END) <> 0::numeric order by po_name,name",array($this->pa_id));
00118 
00119   }
00120 
00121   /**
00122    * load the data
00123    * does not return anything but give a value to this->aheader and this->arow
00124    */
00125   function load_poste()
00126   {
00127     $date=$this->set_sql_filter();
00128     $date=($date != '')?"  $date":'';
00129     $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00130     $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00131   $this->arow=$this->db->get_array("SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
00132         CASE
00133             WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00134             ELSE operation_analytique.oa_amount
00135         END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
00136    FROM operation_analytique
00137    JOIN poste_analytique po USING (po_id)
00138    JOIN jrnx USING (j_id)
00139    JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
00140 "                                       where
00141                 pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
00142 
00143   GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, po.po_description
00144  HAVING sum(
00145 CASE
00146     WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00147     ELSE operation_analytique.oa_amount
00148 END) <> 0::numeric  order by j_poste,po_name",array($this->pa_id));
00149 
00150   }
00151 
00152   /**
00153    * load the data
00154    * does not return anything but give a value to this->aheader and this->arow
00155    */
00156   function load_card()
00157   {
00158     $date=$this->set_sql_filter();
00159     $date=($date != '')?"  $date":'';
00160     $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= upper('".Database::escape_string($this->from_poste)."')":'';
00161     $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= upper('".Database::escape_string($this->to_poste)."')":'';
00162 
00163    $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
00164         CASE
00165             WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00166             ELSE operation_analytique.oa_amount
00167         END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
00168            FROM fiche_detail
00169           WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS name
00170    FROM operation_analytique
00171    JOIN poste_analytique po USING (po_id)
00172    JOIN jrnx USING (j_id) ".
00173                                      " where pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste
00174                                      ."
00175   GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT fiche_detail.ad_value
00176    FROM fiche_detail
00177   WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), po.po_description
00178  HAVING sum(
00179 CASE
00180     WHEN operation_analytique.oa_debit = true THEN operation_analytique.oa_amount * (-1)::numeric
00181     ELSE operation_analytique.oa_amount
00182 END) <> 0::numeric order by name,po_name",array($this->pa_id));
00183   }
00184   /**
00185    *@brief display the button export CSV
00186    *@param $p_hidden is a string containing hidden items
00187    *@return html string
00188    */
00189   function show_button($p_hidden="")
00190   {
00191     $r="";
00192     $r.= '<form method="GET" action="export.php"  style="display:inline">';
00193     $r.= HtmlInput::hidden("act","CSV:AncAccList");
00194     $r.= HtmlInput::hidden("to",$this->to);
00195     $r.= HtmlInput::hidden("from",$this->from);
00196     $r.= HtmlInput::hidden("pa_id",$this->pa_id);
00197     $r.= HtmlInput::hidden("from_poste",$this->from_poste);
00198     $r.= HtmlInput::hidden("to_poste",$this->to_poste);
00199     $r.= HtmlInput::hidden("card_poste",$this->card_poste);
00200 
00201     $r.= $p_hidden;
00202     $r.= dossier::hidden();
00203     $r.=HtmlInput::submit('bt_csv',"Export en CSV");
00204     $r.= '</form>';
00205     return $r;
00206   }
00207   function display_html()
00208   {
00209     bcscale(2);
00210     if ( $this->check()  != 0)
00211       {
00212         alert('Désolé mais une des dates données n\'est pas valide');
00213         return;
00214       }
00215     //---------------------------------------------------------------------------
00216     // Card  - Acc
00217     //---------------------------------------------------------------------------
00218 
00219     if ( $this->card_poste=='1')
00220       {
00221         $this->load_card();
00222 
00223         /*
00224          * Show all the result
00225          */
00226         $tot_card=0;$prev='';
00227         echo '<table class="result" style="margin-left:5px;margin-top:5px">';
00228         $tot_glob=0;
00229         for ($i=0;$i<count($this->arow);$i++)
00230           {
00231             if ( $i == 0 )
00232               {
00233                 $prev=$this->arow[$i]['f_id'];
00234                 echo '<tr><td>'.HtmlInput::history_card ($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' '.$this->arow[$i]['name'],' display:inline').'</td></tr>';
00235               }
00236             $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
00237             if ( $i != 0 && $prev != $this->arow[$i]['f_id'])
00238               {
00239                 echo  td('Total');
00240                 echo td(nbm($tot_card),' class="num"');
00241                 echo '</tr>';
00242                 echo '<tr  style="padding-top:5px"><td>'.HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
00243                 $tot_card=0;
00244                 $prev = $this->arow[$i]['f_id'];
00245               }
00246 
00247             echo '<tr '.$style.'>';
00248             $amount=$this->arow[$i]['sum_amount'];
00249             if ($amount==null)$amount=0;
00250 
00251             $tot_card=bcadd($tot_card,$amount);
00252             $tot_glob=bcadd($tot_glob,$amount);
00253             echo td($this->arow[$i]['po_name']."   ".
00254                     $this->arow[$i]['po_description'],'style="padding-left:10"');
00255             echo td(nbm($amount),' class="num" ');
00256             echo '</tr>';
00257 
00258           }
00259         echo '<tr>';
00260         echo  td('Total');
00261         echo td(nbm($tot_card),' class="num"');
00262         echo '</tr>';
00263 
00264         echo '</table>';
00265         echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
00266       }
00267     //---------------------------------------------------------------------------
00268     // Accountancy - Analytic
00269     //---------------------------------------------------------------------------
00270 
00271     if ( $this->card_poste=='2')
00272       {
00273         $this->load_poste();
00274         /*
00275          * Show all the result
00276          */
00277         $tot_card=0;$prev='';
00278         echo '<table class="result" style="margin-left:20px;margin-top:5px">';
00279         $tot_glob=0;
00280         for ($i=0;$i<count($this->arow);$i++)
00281           {
00282             if ( $i == 0 )
00283               {
00284                 $prev=$this->arow[$i]['j_poste'];
00285                 echo '<tr><td>'.HtmlInput::history_account ($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' '.$this->arow[$i]['name'],' display:inline').'</td></tr>';
00286               }
00287             $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
00288             if ( $i != 0 && $prev != $this->arow[$i]['j_poste'])
00289               {
00290                 echo  td('Total');
00291                 echo td(nbm($tot_card),' class="num"');
00292                 echo '</tr>';
00293                 echo '<tr  style="padding-top:5px"><td>'.HtmlInput::history_account($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
00294                 $tot_card=0;
00295                 $prev = $this->arow[$i]['j_poste'];
00296               }
00297 
00298             echo '<tr '.$style.'>';
00299             $amount=$this->arow[$i]['sum_amount'];
00300             if ($amount==null)$amount=0;
00301 
00302             $tot_card=bcadd($tot_card,$amount);
00303             $tot_glob=bcadd($tot_glob,$amount);
00304 
00305 
00306             echo td($this->arow[$i]['po_name']."   ".
00307                     $this->arow[$i]['po_description'],'style="padding-left:10"');
00308             echo td(nbm($amount),' class="num" ');
00309             echo '</tr>';
00310 
00311           }
00312         echo '<tr>';
00313         echo  td('Total');
00314         echo td(nbm($tot_card),' class="num"');
00315         echo '</tr>';
00316 
00317         echo '</table>';
00318         echo td(nbm($tot_card),' class="num"');
00319       }
00320     //---------------------------------------------------------------------------
00321     // Acc after card
00322     //---------------------------------------------------------------------------
00323     if ( $this->card_poste=='3')
00324       {
00325         $this->load_anc_card();
00326         /*
00327          * Show all the result
00328          */
00329         $tot_card=0;$prev='';
00330         echo '<table class="result" style="margin-left:20px;margin-top:5px">';
00331         $tot_glob=0;
00332         for ($i=0;$i<count($this->arow);$i++)
00333           {
00334             if ( $i == 0 )
00335               {
00336                 $prev=$this->arow[$i]['po_id'];
00337                 echo '<tr><td>'.$this->arow[$i]['po_name']."  ".$this->arow[$i]['po_description'].'</td></tr>';
00338 
00339               }
00340             $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
00341             if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
00342               {
00343                 echo  td('Total');
00344                 echo td(nbm($tot_card),' class="num"');
00345                 echo '</tr>';
00346                 echo '<tr><td>'.$this->arow[$i]['po_name']."  ".$this->arow[$i]['po_description'].'</td></tr>';
00347 
00348                 $tot_card=0;
00349                 $prev = $this->arow[$i]['po_id'];
00350               }
00351 
00352             echo '<tr '.$style.'>';
00353             $amount=$this->arow[$i]['sum_amount'];
00354             if ($amount==null)$amount=0;
00355 
00356             $tot_card=bcadd($tot_card,$amount);
00357             $tot_glob=bcadd($tot_glob,$amount);
00358             echo '<td style="padding-left:10">'.HtmlInput::history_card ($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' '.$this->arow[$i]['name'],' display:inline').'</td>';
00359 
00360             echo td(nbm($amount),' class="num" ');
00361             echo '</tr>';
00362 
00363           }
00364         echo '<tr>';
00365         echo  td('Total');
00366         echo td(nbm($tot_card),' class="num"');
00367         echo '</tr>';
00368 
00369         echo '</table>';
00370         echo td(nbm($tot_card),' class="num"');
00371       }
00372     //---------------------------------------------------------------------------
00373     // Analytic - Accountancy
00374     //---------------------------------------------------------------------------
00375 
00376 
00377     if ( $this->card_poste=='4')
00378       {
00379         $this->load_anc_account();
00380 
00381         /*
00382          * Show all the result
00383          */
00384         $tot_card=0;$prev='';
00385         echo '<table class="result" style="margin-left:20px;margin-top:5px">';
00386         $tot_glob=0;
00387         for ($i=0;$i<count($this->arow);$i++)
00388           {
00389             if ( $i == 0 )
00390               {
00391                 $prev=$this->arow[$i]['po_id'];
00392                 echo '<tr><td>'.$this->arow[$i]['po_name']."  ".$this->arow[$i]['po_description'].'</td></tr>';
00393               }
00394             $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
00395             if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
00396               {
00397                 echo  td('Total');
00398                 echo td(nbm($tot_card),' class="num"');
00399                 echo '</tr>';
00400 
00401                 $tot_card=0;
00402                 $prev = $this->arow[$i]['po_id'];
00403                 echo '<tr><td>'.$this->arow[$i]['po_name']."  ".$this->arow[$i]['po_description'].'</td></tr>';
00404 
00405               }
00406 
00407             echo '<tr '.$style.'>';
00408             $amount=$this->arow[$i]['sum_amount'];
00409             if ($amount==null)$amount=0;
00410 
00411             $tot_card=bcadd($tot_card,$amount);
00412             $tot_glob=bcadd($tot_glob,$amount);
00413             echo '<td style="padding-left:10">'.HtmlInput::history_account ($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' '.$this->arow[$i]['name'],' display:inline').'</td>';
00414             echo td(nbm($amount),' class="num" ');
00415             echo '</tr>';
00416 
00417           }
00418         echo '<tr>';
00419         echo  td('Total');
00420         echo td(nbm($tot_card),' class="num"');
00421         echo '</tr>';
00422 
00423         echo '</table>';
00424         echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
00425       }
00426 
00427   }
00428   function export_csv()
00429   {
00430    bcscale(2);
00431    if ( $this->check () != 0 ) {echo "DATE INVALIDE";exit();}
00432       //---------------------------------------------------------------------------
00433     // Card  - Acc
00434     //---------------------------------------------------------------------------
00435 
00436     if ( $this->card_poste=='1')
00437       {
00438         $this->load_card();
00439 
00440         /*
00441          * Show all the result
00442          */
00443         $prev='';
00444 
00445 
00446         for ($i=0;$i<count($this->arow);$i++)
00447           {
00448             printf('"%s";" %s"', $this->arow[$i]['j_qcode'],$this->arow[$i]['name']);
00449 
00450             $amount=$this->arow[$i]['sum_amount'];
00451             if ($amount==null)$amount=0;
00452 
00453             printf(';"%s";" %s";',
00454                    $this->arow[$i]['po_name'],
00455                    $this->arow[$i]['po_description']);
00456             printf("%s",nb($amount));
00457             printf("\r\n");
00458           }
00459       }
00460     //---------------------------------------------------------------------------
00461     // Accountancy - Analytic
00462     //---------------------------------------------------------------------------
00463 
00464     if ( $this->card_poste=='2')
00465       {
00466         $this->load_poste();
00467         /*
00468          * Show all the result
00469          */
00470         for ($i=0;$i<count($this->arow);$i++)
00471           {
00472             printf('"%s";" %s"', $this->arow[$i]['j_poste'],$this->arow[$i]['name']);
00473 
00474             $amount=$this->arow[$i]['sum_amount'];
00475             if ($amount==null)$amount=0;
00476 
00477             printf(';"%s";" %s";',
00478                    $this->arow[$i]['po_name'],
00479                    $this->arow[$i]['po_description']);
00480             printf("%s",nb($amount));
00481             printf("\r\n");
00482 
00483 
00484           }
00485 
00486       }
00487     //---------------------------------------------------------------------------
00488     // Acc after card
00489     //---------------------------------------------------------------------------
00490     if ( $this->card_poste=='3')
00491       {
00492         $this->load_anc_card();
00493         /*
00494          * Show all the result
00495          */
00496         for ($i=0;$i<count($this->arow);$i++)
00497           {
00498             printf('"%s";" %s";', $this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
00499 
00500             $amount=$this->arow[$i]['sum_amount'];
00501             if ($amount==null)$amount=0;
00502 
00503             printf('"%s";"%s";',
00504                    $this->arow[$i]['j_qcode'],
00505                    $this->arow[$i]['name']);
00506             printf("%s",nb($amount));
00507             printf("\r\n");
00508 
00509 
00510           }
00511       }
00512     //---------------------------------------------------------------------------
00513     // Analytic - Accountancy
00514     //---------------------------------------------------------------------------
00515 
00516 
00517     if ( $this->card_poste=='4')
00518       {
00519         $this->load_anc_account();
00520 
00521         /*
00522          * Show all the result
00523          */
00524         for ($i=0;$i<count($this->arow);$i++)
00525           {
00526             printf('"%s";"%s";', $this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
00527 
00528             $amount=$this->arow[$i]['sum_amount'];
00529             if ($amount==null)$amount=0;
00530 
00531             printf('"%s";"%s";',
00532                    $this->arow[$i]['j_poste'],
00533                    $this->arow[$i]['name']);
00534             printf("%s",nb($amount));
00535             printf("\r\n");
00536 
00537 
00538           }
00539       }
00540 
00541 
00542 
00543 
00544   }
00545 
00546 }