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

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