"; $result.=""; $result.='Code'; $result.='Noms'; $result.='Entrée'; $result.='Sortie'; $result.='Solde'; $result.=""; // Sql result => table for ($i = 0; $i < $M ; $i++ ) { $r=pg_fetch_array($Res,$i); $result.=""; // sg_code and link to details $result.="".''. $r['sg_code'].""; // name $a_name=getFicheNameCode($p_cn,$r['sg_code']); $name=""; if ( $a_name != null ) { foreach ($a_name as $key=>$element) { $name.=$element['av_text'].","; } }// if ( $a_name $result.=" $name "; // Debit (in) $result.="".$r['deb_sum'].""; // Credit (out) $result.="".$r['cred_sum'].""; // diff $diff=$r['deb_sum']-$r['cred_sum']; $result.="".$diff.""; $result.=""; } $result.=""; return $result; } /* function getFicheNameCode ($p_cn,$p_sg_code) ************************************************************ * Purpose : return an array of f_id and f_name * * parm : * - p_cn database connection * - stock_goods.sg_code * gen : * - none * return: * - array (f_id, f_label) or null if nothing is found */ function getFicheNameCode ($p_cn,$p_sg_code) { // Sql stmt $sql="select f_id,av_text from stock_goods join jnt_fic_att_value using (f_id ) join attr_value using (jft_id) where ad_id=".ATTR_DEF_NAME." and sg_code='$p_sg_code' "; // Execute $Res=ExecSql($p_cn,$sql); if ( ( $M=pg_NumRows($Res)) == 0 ) return null; // Store in an array for ( $i=0; $i<$M;$i++) { $r=pg_fetch_array($Res,$i); $a['f_id']=$r['f_id']; $a['av_text']=$r['av_text']; $result[$i]=$a; } return $result; } /* function ViewDetailStock($cn,$sg_code,$year) ************************************************** * Purpose : * * parm : * - cn database connection * - sg_code * - year * gen : * - * return: HTML code */ function ViewDetailStock($p_cn,$p_sg_code,$p_year) { $sql="select sg_code, j_montant, j_date, sg_quantity, sg_type, jr_comment, jr_internal, jr_id, case when sg_date is not null then sg_date else j_date end as stock_date from stock_goods left outer join jrnx using (j_id) left outer join jrn on jr_grpt_id=j_grpt where sg_code='$p_sg_code' and ( to_char(sg_date,'YYYY') = '$p_year' or to_char(j_date,'YYYY') = '$p_year' ) order by stock_date " ; // $r.=sprintf('', // $row['jr_id'],$l_sessid,$row['jr_internal']); // name $r=""; $a_name=getFicheNameCode($p_cn,$p_sg_code); $name=""; if ( $a_name != null ) { foreach ($a_name as $key=>$element) { $name.=$element['av_text'].","; } }// if ( $a_name // Add java script for detail $r.=JS_VIEW_JRN_DETAIL; $r.='

'.$p_sg_code." Noms : ".$name.'

'; $Res=ExecSql($p_cn,$sql); if ( ($M=pg_NumRows($Res)) == 0 ) return "no rows"; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; // compute sessid $l_sessid=(isset($_POST['PHPSESSID']))?$_POST['PHPSESSID']:$_GET['PHPSESSID']; for ( $i=0; $i < $M;$i++) { $l=pg_fetch_array($Res,$i); $r.=""; // date $r.=""; //type (deb = out cred=in) $r.=""; // jr_internal $r.=""; // comment $r.=""; //amount $r.=""; //quantity $r.=""; // Unit Price $r.=""; $r.=""; }// for ($i $r.="
Date Entrée / Sortie DescriptionMontantQuantitéPrix/Cout Unitaire
"; $r.=$l['j_date']; $r.=""; $r.=($l['sg_type']=='c')?'OUT':'IN'; $r.=""; $r.=""; $r.=$l['jr_comment']; $r.=""; $r.=$l['j_montant']; $r.=""; $r.=$l['sg_quantity']; $r.=""; $up=$l['j_montant']/$l['sg_quantity']; $r.=$up; $r.="
"; return $r; } /* function ChangeStock($cn,$sg_code,$sg_date) ************************************************** * Purpose : * * parm : * - * gen : * - * return: */ function ChangeStock($p_sg_code,$p_year){ $sg_date=date("d.m.Y"); $r='
'; return $r; }