From 9d001a7ed02cb2811ae2337e438c71137ced0832 Mon Sep 17 00:00:00 2001
From: Dany De Bontridder
Date: Wed, 3 Jun 2020 16:09:31 +0200
Subject: [PATCH] =?UTF-8?q?task=20#0001413:=20Duplication=20d'op=C3=A9rati?=
=?UTF-8?q?on=202=20-=20le=20retour?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
html/js/acc_ledger.js | 40 +++++
include/ajax/ajax_ledger.php | 16 ++
include/class/acc_operation.class.php | 174 ++++++++++++++++++++++
include/lib/html_input.class.php | 19 ++-
include/template/ledger_detail_bottom.php | 32 ++--
5 files changed, 266 insertions(+), 15 deletions(-)
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='
";
+ if (count($a_code) == 1 ) {
+ $r.=HtmlInput::hidden("ac",$a_code[0]['code']);
+ $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$a_code[0]['code']);
+
+ } else {
+ $select=new ISelect("ac");
+ $select->value=array();
+ $nb_code=count($a_code);
+
+ for ($i=0;$i<$nb_code;$i++) {
+ $select->value[]=array("label"=>$a_code[$i]['code'],"value"=>$a_code[$i]['code']);
+ }
+ $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$select->input());
+
+ }
+
+ $r.="";
+ $r.=HtmlInput::simple_array_to_hidden($array);
+
+ //
+ $r.=HtmlInput::submit(uniqid(), _("Dupliquer"));
+ $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 @@
set_position("in-absolute");
$cn=Dossier::connect();
// Contains all the linked actions
$a_followup = Follow_Up::get_all_operation($jr_id);
@@ -199,7 +204,6 @@ if ($aRap != null ) {
$e
);
$remove=Icon_Action::trash(uniqid(), $js);
-// $remove=$rmReconciliation->input();
}
else
$remove='';
@@ -315,25 +319,29 @@ if ( $div != 'popup' ) {
echo HtmlInput::submit('save',_('Sauver'),'onClick="return verify_ca(\'popup\');"');
$owner=new Noalyss_Parameter_Folder($cn);
if ($owner->MY_ANALYTIC != 'nu' /*&& $div=='popup' */){
- echo '';
+
+ $select_box->add_javascript(_("Vérification CA"), sprintf("verify_ca('%s')",$div));
}
$per=new Periode($cn,$obj->det->jr_tech_per);
if ( $per->is_closed() == 0 && $owner->MY_STRICT=='N' && $g_user->check_action(RMOPER)==1)
{
- $remove=new IButton('Effacer');
- $remove->label=_('Effacer');
- $remove->javascript="return confirm_box(null,content[50],function () {removeOperation('".$obj->det->jr_id."',".dossier::id().",'".$div."')})";
- echo $remove->input();
+ $javascript="return confirm_box(null,content[50],function () {removeOperation('".$obj->det->jr_id."',".dossier::id().",'".$div."')})";
+ $select_box->add_javascript(_("Effacer"), $javascript);
}
//----------------------------------------------------
// Extourne
//----------------------------------------------------
- $reverse=new IButton('bext'.$div);
- $reverse->label=_('Extourner');
- $reverse->javascript="g('ext".$div."').style.display='block'";
- echo $reverse->input();
- echo '';
+ $select_box->add_javascript(_("Extourne"), sprintf("g('ext%s').style.display='block'",$div));
+
+ //-------------------------------------------------------------------
+ // Duplicate
+ //-------------------------------------------------------------------
+ $select_box->add_javascript(_("Duplicate"),sprintf("duplicate_operation('%s','%s')",Dossier::id(),$obj->jr_id));
+
+
+echo $select_box->input();
+echo '';
echo '';
echo '';
@@ -341,7 +349,7 @@ echo '';
$extourne_label=new IText("ext_label");
$extourne_label->size=40;
$r="