diff --git a/html/ajax_misc.php b/html/ajax_misc.php index ec2a4a84a..bc8830d35 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -63,6 +63,19 @@ $user->check_dossier($gDossier,true); $html=var_export($_REQUEST,true); switch($op) { +case "rm_stock": + require_once('constant.security.php'); + if ( $user->check_action(GESTOCK) == 0 ) + { + exit(); + } + $cn->exec_sql('delete from stock_goods where sg_id=$1', + array($s_id)); + $html=escape_xml($s_id); + header('Content-type: text/xml; charset=UTF-8'); + printf('{"d_id":"%s"}',$s_id); + exit(); + break; //-------------------------------------------------- // get the last date of a ledger case 'lastdate': diff --git a/html/js/gestion.js b/html/js/gestion.js index 66d516fbe..88b357c93 100644 --- a/html/js/gestion.js +++ b/html/js/gestion.js @@ -86,3 +86,55 @@ function check_hour(p_ctl) } } +/** + *@brief remove an attached document of an action + *@param dossier + *@param dt_id id of the document (pk document:d_id) +*/ + +function removeStock(s_id,p_dossier) +{ + if ( ! confirm("Confirmez-vous l'effacement de cette entrée dans le stock?") ) + { + return; + } + queryString="?gDossier="+p_dossier+"&op=rm_stock&s_id="+s_id; + var action=new Ajax.Request ( + "ajax_misc.php", + { + method:'get', + parameters:queryString, + onFailure:errorRemoveStock, + onSuccess:successRemoveStock + } + + ); + +} +/** + *@brief error if a document if removed + */ +function errorRemoveStock() +{ + alert('Impossible d\'effacer '); +} +/** + *@brief success when removing a document + */ +function successRemoveStock(request,json) +{ + try + { + var answer=request.responseText.evalJSON(true); + var doc="stock"+answer.d_id; + var href="href"+answer.d_id; + $(href).innerHTML=''; + + $(doc).style.color="red"; + // $(doc).href="javascript:alert('Stock Effacé')"; + $(doc).style.textDecoration="line-through"; + } catch (e) + { + alert("success_box"+e.message); + } +} diff --git a/include/class_html_input.php b/include/class_html_input.php index d69dd86c7..7ade1266c 100755 --- a/include/class_html_input.php +++ b/include/class_html_input.php @@ -258,6 +258,15 @@ class HtmlInput $p_id,dossier::id(),$p_mesg); } + /** + * return a string containing the html code for calling the removeStock + */ + static function remove_stock($p_id,$p_mesg) + { + return sprintf('%s', + $p_id,dossier::id(),$p_mesg); + } + /** * display a div with the history of the card */ diff --git a/include/stock_inc.php b/include/stock_inc.php index adfe1b963..7b28676e9 100644 --- a/include/stock_inc.php +++ b/include/stock_inc.php @@ -128,7 +128,7 @@ function getFicheNameCode ($p_cn,$p_sg_code) // Sql stmt $sql="select distinct f_id,ad_value from stock_goods - join fiche_detail + join fiche_detail using(f_id) where ad_id=".ATTR_DEF_STOCK." and sg_code='$p_sg_code' @@ -163,7 +163,8 @@ function getFicheNameCode ($p_cn,$p_sg_code) */ function ViewDetailStock($p_cn,$p_sg_code,$p_year) { - $sql="select sg_code, + $sql="select sg_id, + sg_code, j_montant, coalesce(j_date,sg_date) as j_date, sg_quantity, @@ -207,7 +208,7 @@ function ViewDetailStock($p_cn,$p_sg_code,$p_year) $Res=$p_cn->exec_sql($sql); if ( ($M=Database::num_row($Res)) == 0 ) return "no rows"; $r.='
| Date | "; $r.="Entrée / Sortie | "; $r.="Description | "; @@ -220,11 +221,11 @@ function ViewDetailStock($p_cn,$p_sg_code,$p_year) for ( $i=0; $i < $M;$i++) { $l=Database::fetch_array($Res,$i); - $r.="||
|---|---|---|---|---|
| "; - $r.=$l['j_date']; + $r.=format_date($l['j_date']); $r.=" | "; //type (deb = out cred=in) @@ -247,13 +248,13 @@ function ViewDetailStock($p_cn,$p_sg_code,$p_year) $tot_quantity+=$quantity; // comment $r.=""; - $r.=$l['comment']; + $r.=h($l['comment']); $r.=" | "; // jr_internal $r.=""; if ( $l['jr_id'] != "") - $r.= " ".$l['jr_internal'].""; + $r.= " ".$l['jr_internal'].""; else $r.=$l['jr_internal']; @@ -263,7 +264,7 @@ function ViewDetailStock($p_cn,$p_sg_code,$p_year) //amount $r.=' | '; - $r.=$l['j_montant']; + $r.=nbm($l['j_montant']); $r.=" | "; //quantity $r.=''; @@ -275,9 +276,9 @@ function ViewDetailStock($p_cn,$p_sg_code,$p_year) $up=""; if ( $l['sg_quantity'] != 0 ) $up=round($l['j_montant']/$l['sg_quantity'],4); - $r.=sprintf("%.4f",$up); + $r.=nbm($up); $r.=" | "; - + $r.=td(HtmlInput::remove_stock($l['sg_id'],'Effacer'),'id="href'.$l['sg_id'].'"'); $r.="