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

user_action_ven.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 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00020 /* $Revision$ */
00024 echo_debug('user_action_ven.php',__LINE__,"include user_action_ven.php");
00025 require_once("user_form_ven.php");
00026 include_once("class_widget.php");
00027 require_once("class_jrn.php");
00028 $cn=DbConnect($_SESSION['g_dossier']);
00029 // default action is insert_vente
00030 if ( ! isset ($_GET['action']) && ! isset ($_POST["action"]) ) {
00031   exit;
00032    } else {
00033   $action=(isset($_GET['action']))?$_GET['action']:$_POST['action'];
00034   $blank=(isset($_GET["blank"]))?1:0;
00035 }
00036 
00037 if ( $action == 'insert_vente' ) {
00038    
00039     // Add item
00040         if (isset($_POST["add_item"]) ) {
00041           echo_debug('user_action_ven.php',__LINE__,"Add an item");
00042           $nb_number=$_POST["nb_item"];
00043           $nb_number++;
00044           
00045           $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,false,$nb_number);
00046           echo '<div class="u_redcontent">';
00047           echo   $form;
00048           echo '</div>';
00049 
00050         } // add an item
00051 
00052     // We want to see the encoded invoice 
00053     if ( isset ($_POST["view_invoice"])) {
00054       $nb_number=$_POST["nb_item"];
00055       if ( form_verify_input($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,$nb_number) == true)
00056         {
00057           $form=FormVenteView($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,$nb_number);
00058           // Check failed : invalid date or quantity
00059         } else {
00060             echo_error("Cannot validate ");
00061             $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,false,$nb_number);
00062           }
00063       echo '<div class="u_redcontent">';
00064       echo         $form;
00065       echo '</div>';
00066       
00067     } 
00068 
00069     // We want a blank form
00070     if ( $blank==1)
00071       {
00072        $jrn=new jrn($cn,  $_GET['p_jrn']);
00073       echo_debug('user_action_ven.php',__LINE__,"Blank form");
00074       // Show an empty form of invoice
00075       $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),null,false,$jrn->GetDefLine('cred'));
00076       echo '<div class="u_redcontent">';
00077       echo $form;
00078       echo '</div>';
00079     }
00080 
00081 }
00082 
00083 
00084     // Save the invoice 
00085 if ( isset($_POST["record_invoice"])) {
00086   // Check privilege
00087   if ( CheckJrn($_SESSION['g_dossier'],$User,$_GET['p_jrn']) != 2 )    {
00088     NoAccess();
00089     exit -1;
00090   }
00091 
00092   // echo "RECORD INVOICE";
00093    RecordInvoice($cn,$HTTP_POST_VARS,$User,$_GET['p_jrn']);
00094 }
00095 if (isset ($_POST['correct_new_invoice'])) {
00096   // Check privilege
00097   if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$_GET['p_jrn']) != 2 )    {
00098     NoAccess();
00099     exit -1;
00100   }
00101   
00102   $nb=$_POST['nb_item'];
00103   $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,false,$nb);
00104   echo '<div class="u_redcontent">';
00105   echo $form;
00106   echo '</div>';
00107 }
00108 // Save and print the invoice
00109 if ( isset($_POST["record_and_print_invoice"])) {
00110   // Check privilege
00111   if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$_GET['p_jrn']) != 2 )    {
00112     NoAccess();
00113     exit -1;
00114   }
00115   
00116   //  echo "RECORD AND PRINT INVOICE";
00117 
00118   $comment=RecordInvoice($cn,$HTTP_POST_VARS,$User,$_GET['p_jrn']);
00119 
00120   $nb_number=$_POST["nb_item"];
00121   if ( form_verify_input($cn,$p_jrn,$User->GetPeriode(),$HTTP_POST_VARS,$nb_number)== true) {
00122     $form=FormVenteView($cn,$p_jrn,$User->GetPeriode(),$HTTP_POST_VARS,$nb_number,'noform',$comment);
00123   } else {
00124             echo_error("Cannot validate ");
00125             $form=FormVenInput($cn,$_GET['p_jrn'],$User,$HTTP_POST_VARS,false,$nb_number);
00126   }
00127   
00128   echo '<div class="u_redcontent">';
00129   echo $form;
00130   echo "</div>  ";
00131 }
00132 
00133 
00134  if ( $action == 'voir_jrn' ) {
00135    // Check privilege
00136    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$_GET['p_jrn']) < 1 )    {
00137      NoAccess();
00138      exit -1;
00139    }
00140    // Extract the page number we want
00141    $debut=(isset($_REQUEST['p_page']))?$_REQUEST['p_page']:0;
00142 
00143 
00144 ?>
00145 <div class="u_redcontent">
00146 
00147 <form method= "get" action="user_jrn.php">
00148 
00149 <?
00150 $hid=new widget("hidden");
00151 
00152 $hid->name="p_jrn";
00153 $hid->value=$p_jrn;
00154 echo $hid->IOValue();
00155 
00156 $hid->name="action";
00157 $hid->value="voir_jrn";
00158 echo $hid->IOValue();
00159 
00160 
00161 $hid->name="jrn_type";
00162 $hid->value=$jrn_type;
00163 echo $hid->IOValue();
00164 
00165 
00166 
00167 $w=new widget("select");
00168 
00169 $periode_start=make_array($cn,"select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode order by p_id");
00170 // User is already set User=new cl_user($cn);
00171 $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->GetPeriode();
00172 $w->selected=$current;
00173 
00174 echo 'Période  '.$w->IOValue("p_periode",$periode_start).$w->Submit('gl_submit','Valider');
00175 ?>
00176 </form>
00177 <?
00178     // Ask to update payment
00179     if ( isset ( $_POST['paid'])) 
00180       {
00181         // reset all the paid flag because the checkbox is post only
00182         // when checked
00183         foreach ($_POST as $name=>$paid) 
00184           {
00185             list($ad) = sscanf($name,"set_jr_id%d");
00186             if ( $ad == null ) continue;
00187             $sql="update jrn set jr_rapt='' where jr_id=$ad";
00188             $Res=ExecSql($cn,$sql);
00189 
00190           }
00191         // set a paid flag for the checked box
00192         foreach ($_POST as $name=>$paid) 
00193           {
00194             list ($id) = sscanf ($name,"rd_paid%d");
00195 
00196             if ( $id == null ) continue;
00197             echo "Mise à jour $id";
00198             $paid=($paid=='on')?'paid':'';
00199             $sql="update jrn set jr_rapt='$paid' where jr_id=$id";
00200             $Res=ExecSql($cn,$sql);
00201           }
00202 
00203       }
00204  // Show list of sell
00205  // Date - date of payment - Customer - amount
00206    $sql=SQL_LIST_ALL_INVOICE." and jr_tech_per=".$current." and jr_def_id=".$_GET['p_jrn'] ;
00207    $step=$_SESSION['g_pagesize'];
00208    $page=(isset($_GET['offset']))?$_GET['page']:1;
00209    $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00210 
00211    list($max_line,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
00212    $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00213 
00214    echo "<hr>$bar";
00215    echo '<form method="POST">';
00216    $hid=new widget("hidden");
00217 
00218    $hid->name="p_jrn";
00219    $hid->value=$p_jrn;
00220    echo $hid->IOValue();
00221 
00222    $hid->name="action";
00223    $hid->value="voir_jrn";
00224    echo $hid->IOValue();
00225 
00226 
00227    $hid->name="jrn_type";
00228    $hid->value=$jrn_type;
00229    echo $hid->IOValue();
00230 
00231 
00232    echo $list;
00233    if ( $max_line !=0 )
00234      echo $hid->Submit('paid','Mise à jour paiement');
00235    echo '</FORM>';
00236    echo "$bar <hr>";
00237 
00238    echo '</div>';
00239 }
00240 if ( $action == 'voir_jrn_non_paye' ) {
00241    // Check privilege
00242    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$_GET['p_jrn']) < 1 )    {
00243      NoAccess();
00244      exit -1;
00245    }
00246     // Ask to update payment
00247     if ( isset ( $_POST['paid'])) 
00248       {
00249         // reset all the paid flag because the checkbox is post only
00250         // when checked
00251         foreach ($_POST as $name=>$paid) 
00252           {
00253             list($ad) = sscanf($name,"set_jr_id%d");
00254             if ( $ad == null ) continue;
00255             $sql="update jrn set jr_rapt='' where jr_id=$ad";
00256             $Res=ExecSql($cn,$sql);
00257 
00258           }
00259         // set a paid flag for the checked box
00260         foreach ($_POST as $name=>$paid) 
00261           {
00262             list ($id) = sscanf ($name,"rd_paid%d");
00263 
00264             if ( $id == null ) continue;
00265             echo "Mise à jour $id";
00266             $paid=($paid=='on')?'paid':'';
00267             $sql="update jrn set jr_rapt='$paid' where jr_id=$id";
00268             $Res=ExecSql($cn,$sql);
00269           }
00270 
00271       }
00272 
00273 // Show list of unpaid sell
00274 // Date - date of payment - Customer - amount
00275   // Nav. bar 
00276    $step=$_SESSION['g_pagesize'];
00277    $page=(isset($_GET['offset']))?$_GET['page']:1;
00278    $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00279 
00280   $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$_GET['p_jrn'] ;
00281   list($max_line,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
00282   $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$_GET['p_jrn'] ;
00283   list($max_line2,$list2)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
00284 
00285   // Get the max line
00286    $m=($max_line2>$max_line)?$max_line2:$max_line;
00287    $bar2=jrn_navigation_bar($offset,$m,$step,$page);
00288    
00289     echo '<div class="u_redcontent">';
00290     echo '<FORM METHOD="POST">';
00291     echo $bar2;
00292     echo '<h2 class="info"> Echeance dépassée </h2>';
00293     echo $list;
00294     echo  '<h2 class="info"> Non Payée </h2>';
00295     echo $list2;
00296     echo $bar2;
00297     // Add hidden parameter
00298     $hid=new widget("hidden");
00299 
00300     $hid->name="p_jrn";
00301     $hid->value=$p_jrn;
00302     echo $hid->IOValue();
00303 
00304     $hid->name="action";
00305     $hid->value="voir_jrn_non_paye";
00306     echo $hid->IOValue();
00307 
00308 
00309     $hid->name="jrn_type";
00310     $hid->value=$jrn_type;
00311     echo $hid->IOValue();
00312 
00313 
00314     echo $list;
00315     if ( $m != 0 )
00316       echo $hid->Submit('paid','Mise à jour paiement');
00317 
00318     echo '</FORM>';
00319     echo '</div>';
00320 }
00321 
00322 include("user_update.php");
00323 ?>

Generated on Fri Jun 23 00:12:46 2006 for phpcompta by  doxygen 1.4.4