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

stock_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.6 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00035 function ViewStock($p_cn,$p_year) {
00036  // build sql -- get the different merchandise sold or bought
00037   // during the p_year
00038 $sql=" select distinct sg_code
00039       from stock_goods 
00040       join jrnx on (stock_goods.j_id=jrnx.j_id)
00041       join parm_periode on (parm_periode.p_id=jrnx.j_tech_per)
00042     where
00043       p_exercice= '$p_year'
00044       and sg_code is not null and sg_code != '' and sg_code!='null'";
00045 
00046 
00047   // send the sql
00048   $Res=ExecSql($p_cn,$sql);
00049 
00050   
00051   if ( ( $M = pg_NumRows($Res)) == 0 ) return null;
00052   // store it in a HTLM table
00053   $result="<table>";
00054   $result.="<tr>";
00055   $result.='<th>Code</th>';
00056   $result.='<th>Noms</th>';
00057   $result.='<th>Entrée</th>';
00058   $result.='<th>Sortie</th>';
00059   $result.='<th>Solde</th>';
00060   $result.="</tr>";
00061 
00062   // Sql result => table
00063   for ($i = 0; $i < $M ; $i++ ) {
00064     $r=pg_fetch_array($Res,$i);
00065     $result.="<TR>";
00066 
00067     // sg_code  and link to details
00068     $result.="<td>".'<a class="one" 
00069               HREF="stock.php?action=detail&sg_code='.$r['sg_code'].'&year='.$p_year.'">'. 
00070               $r['sg_code']."</A></td>";
00071 
00072     // name
00073     $a_name=getFicheNameCode($p_cn,$r['sg_code']);
00074     $name="";
00075     if ( $a_name != null ) {
00076       foreach ($a_name as $key=>$element) {
00077         $name.=$element['av_text'].",";
00078       }
00079     }// if ( $a_name
00080     $result.="<td> $name </td>";
00081 
00082     // Debit (in)
00083     $deb=GetQuantity($p_cn,$r['sg_code'],$p_year,'d');
00084     $result.="<td>".$deb."</td>";
00085 
00086     // Credit (out)
00087     $cred=GetQuantity($p_cn,$r['sg_code'],$p_year,'c');
00088     $result.="<td>".$cred."</td>";
00089 
00090 
00091     // diff
00092     $diff=$deb-$cred;
00093     $result.="<td>".$diff."</td>";
00094     $result.="</tr>";
00095 
00096   }
00097       $result.="</table>";
00098 
00099   return $result;
00100 }
00111 function getFicheNameCode ($p_cn,$p_sg_code) {
00112   // Sql stmt
00113 $sql="select distinct f_id,av_text
00114          from stock_goods
00115          join jnt_fic_att_value using (f_id )
00116          join attr_value using (jft_id)
00117          where 
00118           ad_id=".ATTR_DEF_NAME." 
00119           and sg_code='$p_sg_code'
00120            ";
00121 // Execute
00122  $Res=ExecSql($p_cn,$sql);
00123  if ( ( $M=pg_NumRows($Res)) == 0 ) return null;
00124  
00125  // Store in an array
00126  for ( $i=0; $i<$M;$i++) {
00127    $r=pg_fetch_array($Res,$i);
00128    $a['f_id']=$r['f_id'];
00129    $a['av_text']=$r['av_text'];
00130    $result[$i]=$a;
00131 
00132  }
00133 
00134  return $result;
00135   
00136 }
00147 function ViewDetailStock($p_cn,$p_sg_code,$p_year) {
00148 $sql="select sg_code,
00149              j_montant,
00150              j_date,
00151              sg_quantity,
00152              sg_type,
00153              jr_comment,
00154              jr_internal,
00155              jr_id,
00156         case when sg_date is not null then sg_date else j_date end as stock_date
00157       from stock_goods
00158       left outer join jrnx using (j_id)
00159       left outer join jrn on jr_grpt_id=j_grpt
00160            where 
00161       sg_code='$p_sg_code' and (
00162           to_char(sg_date,'YYYY') = '$p_year'
00163        or to_char(j_date,'YYYY') = '$p_year'
00164        )
00165       order by stock_date
00166  " ;
00167 // $r.=sprintf('<input TYPE="button" onClick="modifyOperation(\'%s\',\'%s\')" value="%s">',
00168 //                  $row['jr_id'],$l_sessid,$row['jr_internal']);
00169     // name
00170 
00171 
00172   $r="";
00173   $a_name=getFicheNameCode($p_cn,$p_sg_code);
00174   $name="";
00175   if ( $a_name != null ) {
00176     foreach ($a_name as $key=>$element) {
00177       $name.=$element['av_text'].",";
00178     }
00179   }// if ( $a_name
00180   // Add java script for detail
00181   $r.=JS_VIEW_JRN_DETAIL;
00182 
00183  $r.='<H2 class="info">'.$p_sg_code."  Noms : ".$name.'</H2>';
00184   
00185   $Res=ExecSql($p_cn,$sql);
00186   if ( ($M=pg_NumRows($Res)) == 0 ) return "no rows";
00187   $r.="<table>";
00188   $r.="<TR>";
00189   $r.="<th>Date </th>";
00190   $r.="<th>Entrée / Sortie </th>";
00191   $r.="<th></th>";
00192   $r.="<th>Description</th>";
00193   $r.="<th>Montant</th>";
00194   $r.="<th>Quantité</th>";
00195   $r.="<th>Prix/Cout Unitaire</th>";
00196   $r.="</TR>";
00197   // compute sessid
00198   $l_sessid=$_REQUEST['PHPSESSID'];
00199 
00200   for ( $i=0; $i < $M;$i++) {
00201     $l=pg_fetch_array($Res,$i);
00202     $r.="<tR>";
00203 
00204     // date
00205     $r.="<TD>";
00206     $r.=$l['j_date'];
00207     $r.="</TD>";
00208 
00209     //type (deb = out cred=in)
00210     $r.="<TD>";
00211     $r.=($l['sg_type']=='c')?'OUT':'IN';
00212     $r.="</TD>";
00213 
00214     // jr_internal
00215     $r.="<TD>";
00216     $r.="</TD>";
00217 
00218 
00219     // comment
00220     $r.="<TD>";
00221     $r.=$l['jr_comment'];
00222     $r.="</TD>";
00223 
00224     //amount
00225     $r.="<TD>";
00226     $r.=$l['j_montant'];
00227     $r.="</TD>";
00228 
00229     //quantity
00230     $r.="<TD>";
00231     $r.=$l['sg_quantity'];
00232     $r.="</TD>";
00233 
00234     // Unit Price
00235     $r.="<TD>";
00236     $up=$l['j_montant']/$l['sg_quantity'];
00237     $r.=$up;
00238     $r.="</TD>";
00239 
00240     $r.="</TR>";
00241   }// for ($i
00242   $r.="</table>";
00243 
00244 
00245 
00246   return $r;
00247          
00248 }
00259 function ChangeStock($p_sg_code,$p_year){
00260 $sg_date=date("d.m.Y");
00261 $r='
00262 <input type="text" name="stock_change" value="0">
00263 <input type="hidden" name="sg_code" value="'.$p_sg_code.'">
00264 <input type="text" name="sg_date" value="'.$sg_date.'">
00265 <input type="hidden" name="year" value="'.$p_year.'">
00266 <br>
00267  ';
00268  return $r;
00269 
00270 }
00276 function GetQuantity($p_cn,$p_sg_code,$p_year,$p_type) {
00277   $sql="select sum(sg_quantity) as result
00278         from stock_goods
00279       join jrnx on (stock_goods.j_id=jrnx.j_id)
00280       join parm_periode on (parm_periode.p_id=jrnx.j_tech_per)
00281         where
00282         sg_code='$p_sg_code' and 
00283          p_exercice = '$p_year' and 
00284          sg_type='$p_type'";
00285   $Res=ExecSql($p_cn,$sql);
00286   if ( pg_NumRows($Res)== 0) return null;
00287   $value=pg_fetch_array($Res,0);
00288   return $value['result'];
00289     
00290 }