exec_sql($sql); if ( ( $M = Database::num_row($Res)) == 0 ) return null; // store it in a HTLM table $result=''; $result.=""; $result.=''; $result.=''; $result.=''; $result.=''; $result.=''; $result.=""; // Sql result => table for ($i = 0; $i < $M ; $i++ ) { $r=Database::fetch_array($Res,$i); $result.=""; // sg_code and link to details $result.=""; // 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.=""; // Debit (in) $deb=GetQuantity($p_cn,$r['sg_code'],$p_year,'d'); $deb=($deb=='')?"0.0":$deb; $result.='"; // Credit (out) $cred=GetQuantity($p_cn,$r['sg_code'],$p_year,'c'); $cred=($cred=='')?"0.0":$cred; $result.='"; // diff $diff=$deb-$cred; $msg=($diff < 0)?_('Sortie /Vente '):_('Entrée/Achat '); $result.='"; $result.=""; } $result.="
CodeNomsEntréeSortieSolde
".''. $r['sg_code']." $name '.$deb."'.$cred."'. $msg.(abs($diff))."
"; return $result; } /*! ************************************************************ * \brief return an array of f_id and f_name * * * \param $p_cn database connection * \param _sg_code stock_goods.sg_code * \return * - array (f_id, f_label) or null if nothing is found */ function getFicheNameCode ($p_cn,$p_sg_code) { // Sql stmt $sql="select distinct f_id,ad_value from stock_goods join fiche_detail using(f_id) where ad_id=".ATTR_DEF_STOCK." and sg_code='$p_sg_code' "; // Execute $Res=$p_cn->exec_sql($sql); if ( ( $M=Database::num_row($Res)) == 0 ) return null; // Store in an array for ( $i=0; $i<$M;$i++) { $r=Database::fetch_array($Res,$i); $a['f_id']=$r['f_id']; $fiche=new Fiche($p_cn,$r['f_id']); $a['av_text']=$fiche->getName(); $result[$i]=$a; } return $result; } /*! ************************************************** * \brief View the details of a stock * * *\param $p_cn database connection * \param$p_sg_code * \param $p_year * \return HTML code */ function ViewDetailStock($p_cn,$p_sg_code,$p_year) { $sql="select sg_id, sg_code, j_montant, coalesce(j_date,sg_date) as j_date, sg_quantity, sg_type, jr_id, coalesce(jr_comment,sg_comment) as comment, coalesce(jr_internal,'Changement manuel') as 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 ( sg_exercice = '$p_year' or j_tech_per in (select p_id from parm_periode where p_exercice='$p_year') ) order by stock_date " ; // name $in_quantity=0; $out_quantity=0; $in_amount=0; $out_amount=0; $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.='

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

'; $Res=$p_cn->exec_sql($sql); if ( ($M=Database::num_row($Res)) == 0 ) return "no rows"; $r.=''; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $tot_quantity=0; for ( $i=0; $i < $M;$i++) { $l=Database::fetch_array($Res,$i); $r.=""; // date $r.=""; //type (deb = out cred=in) $r.=""; if ( $l['sg_type']=='c') { $quantity=(-1)*$l['sg_quantity']; $out_quantity+=$l['sg_quantity']; $out_amount+=$l['j_montant']; } else { $quantity=$l['sg_quantity']; $in_quantity+=$l['sg_quantity']; $in_amount+=$l['j_montant']; } $tot_quantity+=$quantity; // comment $r.=""; // jr_internal $r.=""; //amount $r.='"; //quantity $r.='"; // Unit Price $r.='"; $r.=td(HtmlInput::remove_stock($l['sg_id'],'Effacer'),'id="href'.$l['sg_id'].'"'); $r.=""; }// for ($i // write the total $msg=($tot_quantity<0)?'Sortie / Vente ':'Entrée / Achat '; $row=td('Total '.$msg,' colspan="4" style="width:auto;text-align:right"'); $row.=td(abs($tot_quantity), 'style="text-align:right"'); $row.=td(); $r.=td($row); $r.="
Date Entrée / Sortie DescriptionOpérationMontantQuantitéPrix/Cout Unitaire
"; $r.=format_date($l['j_date']); $r.=""; $r.=($l['sg_type']=='c')?'OUT':'IN'; $r.=""; $r.=h($l['comment']); $r.=""; if ( $l['jr_id'] != "") $r.= " ".$l['jr_internal'].""; else $r.=$l['jr_internal']; $r.="'; $r.=nbm($l['j_montant']); $r.="'; $r.=abs($quantity); $r.="'; $up=""; if ( $l['sg_quantity'] != 0 ) $up=round($l['j_montant']/$l['sg_quantity'],4); $r.=nbm($up); $r.="
"; $r.='
'; $r.=''; $row=td('Quantité IN/Achetée').td($in_quantity,'style="text-align:right"'); $r.=tr($row); $row=td('Quantité OUT/Vendue').td($out_quantity,'style="text-align:right"'); $r.=tr($row); $row=td('Quantité ').td(abs($tot_quantity),'style="text-align:right"'); $r.=tr($row); $r.='
'; $r.='
'; $r.='
'; $r.=''; $row=td('Montant IN/Acheté').td($in_amount,'style="text-align:right"'); $r.=tr($row); $row=td('Montant OUT/Vendu').td($out_amount,'style="text-align:right"'); $r.=tr($row); $row=td('Montant ').td($out_amount-$in_amount,'style="text-align:right"'); $r.=tr($row); $r.='
'; $r.='
'; return $r; } /*! ************************************************** * \brief * * parm : * - * gen : * - * return: */ function ChangeStock($p_sg_code,$p_year) { $sg_date=date("d.m.Y"); $r=''; $row=td('Description'); $row.=td(' '); $r.=tr($row); $row=td('Valeur(positive pour IN ou négative comme OUT)'); $row.=td(' '); $r.=tr($row); $row=td('Date'); $row.=td(' '); $r.=tr($row); $r.='
'; $r.=' '; return $r; } /*! * \brief return the quantity of a sg_code for the period * * \return number or NULL */ function GetQuantity($p_cn,$p_sg_code,$p_year,$p_type) { $sql="select sum(sg_quantity) as result from stock_goods left join jrnx on (stock_goods.j_id=jrnx.j_id) left join parm_periode on (parm_periode.p_id=jrnx.j_tech_per) where sg_code='$p_sg_code' and (p_exercice = '$p_year' or to_char(sg_date::timestamp,'YYYY')='$p_year') and sg_type='$p_type'"; $Res=$p_cn->exec_sql($sql); if ( Database::num_row($Res)== 0) return null; $value=Database::fetch_array($Res,0); return $value['result']; }