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