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

bank.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.7 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 require_once('class_jrn.php');
00022 require_once('user_form_fin.php');
00023 require_once('jrn.php');
00024 require_once("class_document.php");
00025 require_once("class_fiche.php");
00026 require_once("class_parm_code.php");
00027 require_once("check_priv.php");
00034 // First we show the menu
00035 // If nothing is asked the propose a blank form
00036 // to enter a new invoice
00037 if ( ! isset ($_REQUEST['p_jrn'])) {
00038   // no journal are selected so we select the first one
00039   $p_jrn=GetFirstJrnIdForJrnType($_SESSION['g_dossier'],'FIN'); 
00040 
00041 } else
00042 {
00043   $p_jrn=$_REQUEST['p_jrn'];
00044 }
00045 
00046 if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 )    {
00047         NoAccess();
00048         exit -1;
00049    }
00050 
00051 // for the back button
00052 $retour="";
00053 $h_url="";
00054 
00055 if ( isset ($_REQUEST['url'])) 
00056 {
00057   $retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00058   $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00059 }
00060 
00061 $sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
00062 //----------------------------------------------------------------------
00063 // ask the saldo of the bank
00064 if ( $sub_action == "solde" )
00065 {
00066    // Check privilege
00067    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 )    {
00068         NoAccess();
00069         exit -1;
00070    }
00071   echo '<div class="u_subtmenu">';
00072 
00073 echo ShowMenuJrnUser($_SESSION['g_dossier'],'FIN',0,'<td class="cell"><A class="mtitle" HREF="commercial.php?liste&p_action=bank&sa=list">Liste</A></td>'.
00074 '<td class="selectedcell">Solde</td>');
00075  echo '</div>';
00076     require_once("poste.php");
00077   // find the bank account
00078  // NOTE : those values are in a table because
00079  // they are _national_ parameters
00080   $banque=new parm_code($cn,'BANQUE');
00081   $caisse=new parm_code($cn,'CAISSE');
00082   $vir_interne=new parm_code($cn,'VIREMENT_INTERNE');
00083   $accountSql="select distinct pcm_val::text,pcm_lib from 
00084             tmp_pcmn 
00085             where pcm_val like '".$banque->p_value."%' or pcm_val like '".$vir_interne->p_value."%' 
00086             or pcm_val like '".$caisse->p_value."%'
00087             order by pcm_val::text";
00088   $ResAccount=ExecSql($cn,$accountSql);
00089   echo '<div class="u_redcontent">';
00090   echo "<table>";
00091   // for each account
00092   for ( $i = 0; $i < pg_NumRows($ResAccount);$i++) {
00093     // get the saldo
00094     $l=pg_fetch_array($ResAccount,$i);
00095     $m=GetSolde($cn,$l['pcm_val']);
00096     // print the result if the saldo is not equal to 0
00097     if ( $m != 0.0 ) {
00098       echo "<tr>";
00099       echo "<TD>".
00100         $l['pcm_val'].
00101         "</TD>".
00102         "<TD>".
00103         $l['pcm_lib'].
00104         "</TD>"."<TD>".
00105         $m.
00106         "</TD>"."</TR>";
00107     }
00108   }// for
00109   echo "</table>";
00110   echo "</div>";
00111   exit();
00112 }
00113 //-----------------------------------------------------
00114 // If a list of depense is asked
00115 // 
00116 if ( $sub_action == "list") 
00117 {
00118    // Check privilege
00119    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 )    {
00120         NoAccess();
00121         exit -1;
00122    }
00123   // show the menu with the list item selected
00124   echo '<div class="u_subtmenu">';
00125   echo ShowMenuJrnUser($_SESSION['g_dossier'],'FIN',0,'<td class="selectedcell">Liste</td>'.
00126                        '<td class="cell"><A class="mtitle" HREF="commercial.php?liste&p_action=bank&sa=solde">Solde</A></td>');
00127   echo '</div>';
00128 
00129   echo '<div class="u_redcontent">';
00130 
00131   
00132   echo '<form>';
00133   $hid=new widget("hidden");
00134   
00135   $hid->name="p_action";
00136   $hid->value="bank";
00137   echo $hid->IOValue();
00138 
00139 
00140   $hid->name="sa";
00141   $hid->value="list";
00142   echo $hid->IOValue();
00143 
00144 
00145 
00146   $w=new widget("select");
00147 
00148   $periode_start=make_array($cn,"select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode order by p_id");
00149   // User is already set User=new cl_user($cn);
00150   $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->GetPeriode();
00151   $w->selected=$current;
00152 
00153   echo 'Période  '.$w->IOValue("p_periode",$periode_start);
00154    $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
00155  echo JS_SEARCH_CARD;
00156  $w=new widget('js_search_only');
00157  $w->name='qcode';
00158  $w->value=$qcode;
00159  $w->label='';
00160  $w->extra='4';
00161  $sp= new widget("span");
00162  echo $sp->IOValue("qcode_label",$qcode)."</TD></TR>";
00163  echo $w->IOValue();
00164 echo $w->Submit('gl_submit','Rechercher');
00165   echo '</form>';
00166   echo $retour;
00167   // Show list of sell
00168   // Date - date of payment - Customer - amount
00169   $sql=SQL_LIST_ALL_INVOICE." and jr_tech_per=".$current." and jr_def_type='FIN'" ;
00170   $step=$_SESSION['g_pagesize'];
00171   $page=(isset($_GET['offset']))?$_GET['page']:1;
00172   $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00173 
00174   $l="";
00175   // check if qcode contains something
00176   if ( $qcode != "" )
00177     {
00178       // add a condition to filter on the quick code
00179       $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode='$qcode') ";
00180     }
00181 
00182   list($max_line,$list)=ListJrn($cn,0,"where jrn_def_type='FIN' and jr_tech_per=$current $l "
00183                                 ,null,$offset,0);
00184   $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00185 
00186   echo "<hr> $bar";
00187   echo $list;
00188   echo "$bar <hr>";
00189   echo $retour;
00190 
00191   echo '</div>';
00192 
00193  exit();
00194 } 
00195 //-----------------------------------------------------
00196 echo '<div class="u_subtmenu">';
00197 echo ShowMenuJrnUser($_SESSION['g_dossier'],'FIN',$p_jrn,'<td class="cell"><A class="mtitle" HREF="commercial.php?liste&p_action=bank&sa=list">Liste</A></td>'.
00198 '<td class="cell"><A class="mtitle" HREF="commercial.php?liste&p_action=bank&sa=solde">Solde</A></td>');
00199 echo '</div>';
00200 //-----------------------------------------------------
00201 // if we request to add an item 
00202 // the $_POST['add_item'] is set
00203 // or if we ask to correct the invoice
00204 if ( isset ($_POST['add_item']) || isset ($_POST['correct'])  ) 
00205 {
00206  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00207         NoAccess();
00208         exit -1;
00209    }
00210 
00211   $nb_item=$_POST['nb_item'];
00212   if ( isset  ($_POST['add_item']))
00213     $nb_item++; 
00214  // Submit button in the form
00215   $submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout article">
00216           <INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver" ID="SubmitButton">';
00217   $form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,$_POST,false,  $nb_item);
00218   //$form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,$_POST,false,  $nb_number);
00219 
00220   echo '<div class="u_redcontent">';
00221   echo $form;
00222   echo JS_CALC_LINE;
00223   echo '</div>';
00224   exit();
00225 }
00226 //-----------------------------------------------------
00227 // Save : record 
00228 //
00229 if ( isset($_POST['save'])) 
00230 {
00231  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00232         NoAccess();
00233         exit -1;
00234    }
00235 
00236   // we save the expense
00237   $r=RecordFin($cn,$_POST,$User,$p_jrn);
00238   $nb_number=$_POST['nb_item'];
00239   
00240   $submit='<h2 class="info"> Op&eacute;ration '.$r.' enregistr&eacute;</h2>';
00241 
00242   $form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,$_POST,true,$nb_number,true);
00243 
00244   echo '<div class="u_redcontent">';
00245   echo $form;
00246   echo '<hr>';
00247   echo '</form>';
00248   echo '<A href="commercial.php?p_action=bank&p_jrn='.$p_jrn.'">
00249     <input type="button" Value="Nouveau"></A>';
00250   exit();
00251 }
00252 //-----------------------------------------------------
00253 // we show the confirmation screen
00254 // 
00255 if ( isset ($_POST['view_invoice']) ) 
00256 {
00257  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00258         NoAccess();
00259         exit -1;
00260    }
00261 
00262   $nb_number=$_POST["nb_item"];
00263   $submit='<INPUT TYPE="SUBMIT" name="save" value="Confirmer">';
00264   $submit.='<INPUT TYPE="SUBMIT" name="correct" value="Corriger">';
00265   if ( form_verify_input ($cn,$p_jrn,$User->GetPeriode(),$_POST,$nb_number) != null ) {
00266     // Should use a read only view instead of FormFin
00267     // where we can check
00268     $form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,$_POST,true,  $nb_number,false);
00269   } else {
00270     // if something goes wrong, correct it
00271     $submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout article">
00272                     <INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver">';
00273     $form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,$_POST,false,  $nb_number);
00274 
00275   }
00276   
00277   echo '<div class="u_redcontent">';
00278   echo         $form;
00279   echo '</div>';
00280   exit();
00281 
00282 }
00283 
00284 
00285 
00286 //-----------------------------------------------------
00287 // By default we add a new invoice
00288 if ( $p_jrn != -1 ) 
00289 {
00290  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00291                 exit -1;
00292    }
00293 
00294   $jrn=new jrn($cn,  $p_jrn);
00295   echo_debug('depense.inc.php',__LINE__,"Blank form");
00296  // Submit button in the form
00297   $submit='<INPUT TYPE="SUBMIT" NAME="add_item" VALUE="Ajout article">
00298           <INPUT TYPE="SUBMIT" NAME="view_invoice" VALUE="Sauver" ID="SubmitButton">';
00299   // Show an empty form of invoice
00300   $form=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,null,false,$jrn->GetDefLine('deb'));
00301   echo '<div class="u_redcontent">';
00302   echo $form;
00303   echo JS_CALC_LINE;
00304   echo '</div>';
00305 }