diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index f236bf34b..200a30651 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -1469,4 +1469,44 @@ function reset_filter(p_div) { // By default , unpaid is uncked $(p_div+"operation_filter").value="all"; +} + +/** + * propose to duplicate an operation + */ +function duplicate_operation(p_dossier,p_jr_id) { + waiting_box(); + var duplicate_div=create_div({id:"duplicate_operation_div",cssclass:"inner_box"}); + + new Ajax.Request("ajax_misc.php", { + parameters : { + "op":"ledger", + "gDossier":p_dossier, + "jr_id":p_jr_id, + "act":"duplicateop", + "div":"duplicate_operation_div" + }, + onSuccess:function(req) { + remove_waiting_box(); + console.debug("success"); + var xml=req.responseXML; + console.debug ("received"+xml); + if ( xml.getElementsByTagName("ctl").length==0) { + console.log("erreur"+req.responseText); + } + console.debug("ok we display"); + add_div(duplicate_div); + console.debug (getNodeText(xml.getElementsByTagName("code")[0])); + + console.debug("fill div"); + duplicate_div.setStyle({"position":"fixed","top":"15%","z-index":"999", + "min-width":"30rem", + "left":"30%", + "width":"40%"}); + duplicate_div.innerHTML=getNodeText(xml.getElementsByTagName("code")[0]); + duplicate_div.setStyle({display:"block"}); + } + } + + ); } \ No newline at end of file diff --git a/include/ajax/ajax_ledger.php b/include/ajax/ajax_ledger.php index 8b90b6e98..7f93ea81f 100644 --- a/include/ajax/ajax_ledger.php +++ b/include/ajax/ajax_ledger.php @@ -577,6 +577,22 @@ case 'reverseop': } $html=ob_get_contents(); ob_end_clean(); + break; + +case 'duplicateop': + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Duplicate operation + /////////////////////////////////////////////////////////////////////////////////////////////////////////// + $operation=new Acc_Operation($cn); + $operation->jr_id=$jr_id; + ob_start(); + echo HtmlInput::title_box(_("Dupliquer une opération"), $div); + echo $operation->form_clone_operation("cloneit"); + + $html=ob_get_contents(); + ob_end_clean(); + + break; } $html=escape_xml($html); diff --git a/include/class/acc_operation.class.php b/include/class/acc_operation.class.php index 3a71a3fe2..8586607fd 100644 --- a/include/class/acc_operation.class.php +++ b/include/class/acc_operation.class.php @@ -732,6 +732,60 @@ class Acc_Operation $type_operation->selected=$p_status; return $type_operation; } + /** + * create a form to recreate the operation and returns it, just like a correct + * + */ + function form_clone_operation($p_id) { + // retrieve all info about operation + $operation = $this->get_quant(); + $array=$operation->compute_array(); + global $g_user; + // Prepare the form + $r='
'; + + + // return the form as a string + return $r; + } } ///////////////////////////////////////////////////////////////////////////// @@ -764,6 +818,19 @@ class Acc_Detail extends Acc_Operation $this->det->note=$this->db->get_value($sql,array($this->jr_id)); $this->det->note=strip_tags($this->det->note); } + /** + * + */ + function compute_array() + { + $array=array(); + $array['desc']=$this->det->jr_comment; + $array['e_date']=""; + $array['e_ech']=""; + $array['p_jrn']=$this->det->jr_def_id; + return $array; + + } } ///////////////////////////////////////////////////////////////////////////// /** @@ -790,6 +857,30 @@ class Acc_Misc extends Acc_Detail FROM jrnx where j_grpt = $1 order by j_debit desc,j_poste"; $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id)); } + /*** + * Compute an array for using with Acc_Ledger::insert + * + */ + function compute_array() + { + $this->get(); + $array=parent::compute_array(); + $nb_array=count($this->det->array); + $array['nb_item']=$nb_array; + + for ($i=0;$i<$nb_array;$i++) { + $array["qc_".$i]=$this->det->array[$i]['j_qcode']; + $array["poste".$i]=$this->det->array[$i]['j_poste']; + $array["amount".$i]=$this->det->array[$i]['j_montant']; + if ( $this->det->array[$i]['j_debit'] == 't') { + $array["ck".$i]=1; + } + $array["ld".$i]=$this->det->array[$i]['j_text']; + } + + return $array; + + } } ///////////////////////////////////////////////////////////////////////////// /** @@ -813,6 +904,35 @@ class Acc_Sold extends Acc_Detail FROM quant_sold join jrnx using(j_id) where j_grpt=$1"; $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id)); } + /*** + * Compute an array for using with Acc_Ledger::insert + * + */ + function compute_array() + { + $this->get(); + $array=parent::compute_array(); + $nb_array=count($this->det->array); + $array['nb_item']=$nb_array; + + + $array["e_client"]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23", + array($this->det->array[0]['qs_client'])); + + for ($i=0;$i<$nb_array;$i++) { + $array["e_march".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23", + array($this->det->array[$i]['qs_fiche'])); + + $array["e_march".$i."_price"]=$this->det->array[$i]['qs_unit']; + $array["e_march".$i."_label"]=$this->det->array[$i]['j_text']; + $array["e_march".$i."_tva_id"]=$this->det->array[$i]['qs_vat_code']; + $array["e_march".$i."_tva_amount"]=$this->det->array[$i]['qs_vat']; + $array["e_quant".$i]=$this->det->array[$i]['qs_quantite']; + } + $array['correct']=1; + return $array; + + } } ///////////////////////////////////////////////////////////////////////////// @@ -839,6 +959,37 @@ class Acc_Purchase extends Acc_Detail FROM quant_purchase join jrnx using(j_id) where j_grpt=$1"; $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id)); } + /*** + * Compute an array for using with Acc_Ledger::insert + * + */ + function compute_array() + { + $this->get(); + $array=parent::compute_array(); + $nb_array=count($this->det->array); + $array['nb_item']=$nb_array; + + + $array["e_client"]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23", + array($this->det->array[0]['qp_supplier'])); + + for ($i=0;$i<$nb_array;$i++) { + $array["e_march".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23", + array($this->det->array[$i]['qp_fiche'])); + + $array["e_march".$i."_price"]=$this->det->array[$i]['qp_unit']; + $array["e_march".$i."_label"]=$this->det->array[$i]['j_text']; + $array["e_march".$i."_tva_id"]=$this->det->array[$i]['qp_vat_code']; + $array["e_march".$i."_tva_amount"]=$this->det->array[$i]['qp_vat']; + $array["e_quant".$i]=$this->det->array[$i]['qp_quantite']; + } + $array['correct']=1; + return $array; + + } + + } ///////////////////////////////////////////////////////////////////////////// /** @@ -861,4 +1012,27 @@ class Acc_Fin extends Acc_Detail FROM quant_fin where jr_id = $1"; $this->det->array=$this->db->get_array($sql,array($this->jr_id)); } + /*** + * Compute an array for using with Acc_Ledger::insert + * + */ + function compute_array() + { + $this->get(); + $array=parent::compute_array(); + $nb_array=count($this->det->array); + $array['nb_item']=$nb_array; + + + for ($i=0;$i<$nb_array;$i++) { + $array["e_other".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23", + array($this->det->array[$i]['qf_other'])); + + $array["e_other".$i."_amount"]=$this->det->array[$i]['qf_amount']; + $array["e_other".$i."_comment"]=$this->det->jr_comment; + } + $array['correct']=1; + return $array; + + } } diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index f79048b58..7dd1ccdf3 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -604,11 +604,24 @@ class HtmlInput } } } - } - + } + + return $r; + } + /** + * Transform a double array as a HTML string with hidden html value + * array has the formarray ["name"]="x",array['value']="y") the key name will be the hidden input name; + * @param double $array + */ + static function simple_array_to_hidden($array) + { + if (empty ($array)) return ""; + $r=""; + foreach ( $array as $key=>$value) { + $r.=HtmlInput::hidden($key, $value); + } return $r; } - /** * @brief transform a json to hidden * @param json $p_json diff --git a/include/template/ledger_detail_bottom.php b/include/template/ledger_detail_bottom.php index 6f89b1d91..c2d635420 100644 --- a/include/template/ledger_detail_bottom.php +++ b/include/template/ledger_detail_bottom.php @@ -1,5 +1,6 @@