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

stock.php

Go to the documentation of this file.
00001 
00002 <?
00003 /*
00004  *   This file is part of PHPCOMPTA.
00005  *
00006  *   PhpCompta is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   PhpCompta is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with PHPCOMPTA; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 // Auteur Dany De Bontridder ddebontridder@yahoo.fr
00021 /* $Revision: 1.14 $ */
00026 include_once("preference.php");
00027 include_once ("ac_common.php");
00028 include_once("postgres.php");
00029 include_once("stock_inc.php");
00030 include_once("check_priv.php");
00031 
00032 html_page_start($_SESSION['g_theme']);
00033 
00034 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00035   echo "You must choose a Dossier ";
00036   exit -2;
00037 }
00038 include_once ("postgres.php");
00039 /* Admin. Dossier */
00040 
00041 $cn=DbConnect($_SESSION['g_dossier']);
00042 include_once ("class_user.php");
00043 $User=new cl_user($cn);
00044 $User->Check();
00045 
00046 // Synchronize rights
00047 SyncRight($_SESSION['g_dossier'],$_SESSION['g_user']);
00048 
00049 // Get The priv on the selected folder
00050 if ( $User->admin == 0 ) {
00051   
00052   $r=GetPriv($_SESSION['g_dossier'],$_SESSION['g_user']);
00053   if ($r == 0 ){
00054     /* Cannot Access */
00055     NoAccess();
00056   }
00057 
00058 }
00059 
00060 
00061 //Show the top menu
00062 include_once ("user_menu.php");
00063 
00064 echo ShowMenuCompta($_SESSION['g_dossier'],"user_advanced.php");
00065 
00066 // Show Menu Left
00067 $left_menu=ShowMenuAdvanced("stock.php");
00068 //echo '<div class="lmenu">';
00069 echo $left_menu;
00070 //echo '</DIV>';
00071 $action= ( isset ($_GET['action']))? $_GET['action']:"";
00072 include_once("stock_inc.php");
00073 
00074 // Adjust the stock
00075 if ( isset ($_POST['sub_change'])) {
00076   $change=$_POST['stock_change'];
00077   $sg_code=$_POST['sg_code'];
00078   $sg_date=$_POST['sg_date'];
00079   if ( isDate($sg_date) == null 
00080        or isNumber($change) == 0 ) {
00081     $msg="Stock données non conformes";
00082     echo "<script> alert('$msg');</script>";
00083     echo_error($msg);
00084   } else {
00085     // Check if User Can change the stock 
00086     if ( CheckAction($g_dossier,$g_user,STOCK_WRITE) == 0 ) {
00087       NoAccess();
00088       exit (-1);
00089     }
00090 
00091     // if neg the stock decrease => credit
00092     $type=( $change < 0 )?'c':'d';
00093     if ( $change != 0)
00094       $Res=ExecSql($cn,"insert into stock_goods
00095                      (  j_id,
00096                         f_id, 
00097                         sg_code,
00098                         sg_quantity,
00099                         sg_type,
00100                         sg_date,
00101                          sg_tech_user)
00102                     values (
00103                         null,
00104                         0,
00105                         '$sg_code',
00106                         abs($change),
00107                         '$type',
00108                         to_date('$sg_date','DD.MM.YYYY'),
00109                         '$g_user');
00110                      ");
00111   // to update the view
00112   $action="detail";
00113   }
00114 }
00115 
00116 // View the summary
00117 
00118 // if year is not set then use the year of the user's periode
00119 if ( ! isset ($_GET['year']) ) {
00120   // get defaut periode
00121   $a=$User->GetPeriode();
00122   // get exercice of periode
00123   $year=GetExercice($cn,$a);
00124   } else
00125   { 
00126     $year=$_GET['year'];
00127   }
00128 
00129 // View details
00130 if ( $action == 'detail' ) {
00131   // Check if User Can see the stock 
00132   if ( CheckAction($_SESSION['g_dossier'],$_SESSION['g_user'],STOCK_READ) == 0 ) {
00133     NoAccess();
00134     exit (-1);
00135   }
00136   $sg_code=(isset ($_GET['sg_code'] ))?$_GET['sg_code']:$_POST['sg_code'];
00137   $year=(isset($_GET['year']))?$_GET['year']:$_POST['year'];
00138   $a=ViewDetailStock($cn,$sg_code,$year);
00139   $b=ChangeStock($sg_code,$year);
00140     echo '<div class="u_redcontent">' ;
00141     echo $a;
00142     echo 'Entrer la valeur qui doit augmenter ou diminuer le stock';
00143     echo '<form action="stock.php" method="POST">';
00144     echo $b;
00145     echo '<input type="submit" name="sub_change" value="Ok">';
00146     echo '</form>';
00147     echo '</div>';
00148     exit();
00149 }
00150 
00151 // Show the possible years
00152 $sql="select distinct (p_exercice) as exercice from parm_periode ";
00153 $Res=ExecSql($cn,$sql);
00154 $r="";
00155 for ( $i = 0; $i < pg_NumRows($Res);$i++) {
00156   $l=pg_fetch_array($Res,$i);
00157   $r.=sprintf('<A class="one" HREF="stock.php?year=%d">%d</a> - ',
00158               $l['exercice'],
00159               $l['exercice']);
00160  
00161 }
00162 // Check if User Can see the stock 
00163 if ( CheckAction($_SESSION['g_dossier'],$_SESSION['g_user'],STOCK_READ) == 0 ) {
00164   NoAccess();
00165   exit (-1);
00166 }
00167 
00168 // Show the current stock
00169 echo '<div class="u_redcontent">';
00170 echo $r;
00171 $a=ViewStock($cn,$year);
00172 if ( $a != null ) {
00173   echo $a;
00174 }
00175 echo '</div>';
00176 html_page_stop();
00177 ?>