Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

tva.inc.php

Go to the documentation of this file.
00001 <?
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: 1.4 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00025   // Confirm remove
00026   if ( isset ($_POST['confirm_rm'])) 
00027   {
00028     ExecSql($cn,'select tva_delete('.$_POST['tva_id'].')');
00029   }
00030 //-----------------------------------------------------
00031 // Record Change
00032   if ( isset ($_POST['confirm_mod'])
00033        || isset ($_POST['confirm_add'])) 
00034     {
00035       extract($_POST);
00036       $tva_id=FormatString($tva_id);
00037       $tva_label=FormatString($tva_label);
00038       $tva_rate=FormatString($tva_rate);
00039       $tva_comment=FormatString($tva_comment);
00040       $tva_poste=FormatString($tva_poste);
00041       $err=0; // Error code
00042       if ( isNumber($tva_id) == 0 ) {
00043         $err=1;
00044         
00045      } 
00046       if ( isNumber($tva_rate) == 0 ) {
00047         $err=2;
00048      } 
00049 
00050       if ( $err == 0 ) 
00051         {
00052           if (  isset ($_POST['confirm_add']) ) 
00053             {
00054           $Res=ExecSql($cn,
00055                        "select tva_insert($tva_id,'$tva_label',
00056                         '$tva_rate','$tva_comment','$tva_poste')");
00057 
00058             }
00059           if (  isset ($_POST['confirm_mod']) ) 
00060             {
00061           $Res=ExecSql($cn,
00062                        "select tva_modify($tva_id,'$tva_label',
00063                        '$tva_rate','$tva_comment','$tva_poste')");
00064             }
00065           $ret_sql=pg_fetch_row($Res);
00066           $err=$ret_sql[0];
00067         }
00068       if ( $err != 0 ) 
00069         {
00070           $err_code=array(1=>"Tva id n\'est pas un nombre",
00071                           2=>"Taux tva invalide",
00072                           3=>"Label ne peut être vide",
00073                           4=>"Poste invalide",
00074                           5=>"Tva id doit être unique");
00075           $str_err=$err_code[$err];
00076           echo "<script>alert ('$str_err'); </script>";;
00077         }
00078   }
00079 
00080   //-----------------------------------------------------
00081   // Display
00082   $sql="select tva_id,tva_label,tva_rate,tva_comment,tva_poste from tva_rate order by tva_id";
00083   $Res=ExecSql($cn,$sql);
00084   ?>
00085 <TABLE>
00086 <TR>
00087 <th>Id</th>
00088 <th>Label</TH>
00089 <th>Taux</th>
00090 <th>Commentaire</th>
00091 <th>Poste</th>
00092 </tr>
00093 <?
00094   $val=pg_fetch_all($Res);
00095   echo_debug('parametre',__LINE__,$val);
00096   foreach ( $val as $row)
00097     {
00098       // load value into an array
00099       $index=$row['tva_id']     ;
00100       $a[$index]=array(
00101                        'tva_label'=> $row['tva_label'],
00102                        'tva_rate'=>$row['tva_rate'],
00103                        'tva_comment'=>$row['tva_comment'],
00104                        'tva_poste'=>$row['tva_poste']
00105                        );
00106       echo "<TR>";
00107       echo '<FORM METHOD="POST">';
00108 
00109       echo "<TD>";
00110       echo $row['tva_id'];
00111       echo "</TD>";
00112 
00113       echo "<TD>";
00114       echo $row['tva_label'];
00115       echo "</TD>";
00116 
00117       echo "<TD>";
00118       echo $row['tva_rate'];
00119       echo "</TD>";
00120 
00121       echo "<TD>";
00122       echo $row['tva_comment'];
00123       echo "</TD>";
00124 
00125       echo "<TD>";
00126       echo $row['tva_poste'];
00127       echo "</TD>";
00128 
00129       echo "<TD>";
00130       echo '<input type="submit" name="rm" value="Efface">';
00131       echo '<input type="submit" name="mod" value="Modifie">';
00132       $w=new widget("hidden");
00133       $w->name="tva_id";
00134       $w->value=$row['tva_id'];
00135       echo $w->IOValue();
00136       $w=new widget("hidden");
00137       $w->name="p_action";
00138       $w->value="tva";
00139       echo $w->IOValue();
00140 
00141       echo "</TD>";
00142 
00143       echo '</FORM>';
00144       echo "</TR>";
00145     }
00146 ?>
00147 </TABLE>
00148     <? // if we add / remove or modify a vat we don't show this button
00149 if (   ! isset ($_POST['add'])
00150   &&   ! isset ($_POST['mod'])
00151   &&   ! isset ($_POST['rm'])
00152 
00153 ) { ?>
00154     <form method="post">
00155     <input type="submit" name="add" value="Ajouter un taux de tva">
00156     <input type="hidden" name="p_action" value="tva">
00157      </form>
00158 <?
00159        } 
00160 
00161 
00162     //-----------------------------------------------------
00163     // remove
00164     if ( isset ( $_REQUEST['rm'])) 
00165       {
00166         echo_debug("parametre",__LINE__,"efface ".$_POST['tva_id']);
00167         echo "Voulez-vous vraiment effacer ce taux ? ";
00168         $index=$_POST['tva_id'];
00169         
00170 ?>
00171 <table>
00172    <TR>
00173    <th>Label</TH>
00174    <th>Taux</th>
00175    <th>Commentaire</th>
00176    <th>Poste</th>
00177    </tr>
00178 <tr>
00179    <td> <? echo $a[$index]['tva_label']; ?></td>
00180    <td> <? echo $a[$index]['tva_rate']; ?></td>
00181    <td> <? echo $a[$index]['tva_comment']; ?></td>
00182    <td> <? echo $a[$index]['tva_poste']; ?></td>
00183 </Tr>
00184 </table>
00185 <?
00186     echo '<FORM method="post">';
00187     echo '<input type="hidden" name="tva_id" value="'.$index.'">';
00188     echo '<input type="submit" name="confirm_rm" value="Confirme">';
00189     echo '<input type="submit" value="Cancel" name="no">';
00190     echo "</form>"; 
00191 
00192   }
00193   //-----------------------------------------------------
00194   // add
00195   if ( isset ( $_REQUEST['add'])) 
00196   {
00197     echo_debug("parametre",__LINE__,"add a line ");
00198     echo "Tva à ajouter, l'id doit être différent pour chaque taux";
00199     echo '<FORM method="post">';
00200 
00201 
00202 ?>
00203 <table >
00204    <TR>
00205    <th>id</TH>
00206    <th>Label</TH>
00207    <th>Taux</th>
00208    <th>Commentaire</th>
00209    <th>Poste</th>
00210    </tr>
00211 <tr valign="top">
00212    <td> <? $w=new widget("text");$w->size=5; echo $w->IOValue('tva_id','') ?></td>
00213    <td> <? $w=new widget("text");$w->size=20; echo $w->IOValue('tva_label','') ?></td>
00214    <td> <? $w=new widget("text");$w->size=5; echo $w->IOValue('tva_rate','') ?></td>
00215    <td> <? $w=new widget("textarea"); $w->heigh=2;$w->width=20;echo $w->IOValue('tva_comment','') ?></td>
00216    <td> <? $w=new widget("text"); $w->size=10;echo $w->IOValue('tva_poste','') ?></td>
00217 </Tr>
00218 </table>
00219 <input type="submit" value="Confirme" name="confirm_add">
00220 <input type="submit" value="Cancel" name="no">
00221 
00222  </FORM>
00223 <?  }
00224 
00225   //-----------------------------------------------------
00226   // mod
00227   if ( isset ( $_REQUEST['mod'])) 
00228     {
00229 
00230       echo_debug("parametre",__LINE__,"modifie ".$_POST['tva_id']);
00231       echo "Tva à modifier";
00232       $index=$_POST['tva_id'];
00233 
00234       echo '<FORM method="post">';
00235       echo '<input type="hidden" name="tva_id" value="'.$index.'">';
00236 ?>
00237 <table>
00238    <TR>
00239    <th>Label</TH>
00240    <th>Taux</th>
00241    <th>Commentaire</th>
00242    <th>Poste</th>
00243    </tr>
00244 <tr valign="top">
00245    <td> <? $w=new widget("text");$w->size=20; echo $w->IOValue('tva_label',$a[$index]['tva_label']) ?></td>
00246    <td> <? $w=new widget("text");$w->size=5; echo $w->IOValue('tva_rate',$a[$index]['tva_rate']) ?></td>
00247    <td> <? $w=new widget("textarea"); $w->heigh=2;$w->width=20;
00248    echo $w->IOValue('tva_comment',$a[$index]['tva_comment']) ?></td>
00249    <td> <? $w=new widget("text");$w->size=5; echo $w->IOValue('tva_poste',$a[$index]['tva_poste']) ?></td>
00250 </Tr>
00251 </table>
00252 <input type="submit" value="Confirme" name="confirm_mod">
00253 <input type="submit" value="Cancel" name="no">
00254  </FORM>
00255 <? 
00256     }
00257 
00258 ?>