diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index d731d80df..312b69b83 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -41,6 +41,7 @@ require_once('ac_common.php'); require_once('class_itva_popup.php'); require_once('class_acc_ledger_info.php'); require_once('class_acc_ledger_fin.php'); +require_once 'class_stock_goods.php'; /*!\brief Handle the ledger of purchase, * @@ -472,7 +473,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger // always save quantity but in withStock we can find // what card need a stock management if ( $g_parameter->MY_STOCK='Y') - InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d',$repo) ; + Stock_Goods::insert_goods(array('db'=>$this->db,'j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>'d','repo'=>$repo)) ; if ( $g_parameter->MY_ANALYTIC != "nu" ) { diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index cac6e5707..4c62b6f8e 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -350,11 +350,12 @@ class Acc_Ledger_Sold extends Acc_Ledger {"e_quant".$i } <0)?-1:1; - + // always save quantity but in withStock we can find // what card need a stock management if ( $g_parameter->MY_STOCK='Y') - InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'c',$repo) ; + Stock_Goods::insert_goods(array('db'=>$this->db,'j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>'c','repo'=>$repo)) ; + if ( $g_parameter->MY_ANALYTIC != "nu" ) { diff --git a/include/class_stock_goods.php b/include/class_stock_goods.php index 70baa0374..dba3b834f 100644 --- a/include/class_stock_goods.php +++ b/include/class_stock_goods.php @@ -121,6 +121,47 @@ class Stock_Goods extends Stock_Goods_Sql throw $exc; } } + /** + * Insert into stock_goods from ACH and VEN + * @param type $p_array KEY : db => database conx, j_id => jrnx.j_id,goods=> f_id of the goods + * 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for purchase IN),'repo'=>r_id of the + * repository (stock_repository.r_id + */ + static function insert_goods(&$p_cn,$p_array) + { + global $g_user; + if ($g_user->can_write_repo($p_depot) == false) + return false; + + // Retrieve the good account for stock + $code = new Fiche($p_cn); + $code->get_by_qcode($p_good); + $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK); + if ($code_marchandise == NOTFOUND || $code_marchandise=='') + return false; + + $exercice = $g_user->get_exercice(); + + if ($exercice == 0) + throw new Exception('Annee invalide erreur'); + + $Res = $p_cn->exec_sql("insert into stock_goods ( + j_id, + f_id, + sg_code, + sg_quantity, + sg_type,sg_exercice,r_id ) values ($1,$2,$3,$4,$5,$6,$7)", array( + $p_array['j_id'], + $code->id, + $code_marchandise, + $p_array['quant'], + $p_array['dir'], + $exercice, + $p_array['repo'] + ) + ); + return $Res; + } }