task #0001413: Duplication d'opération 2 - le retour

This commit is contained in:
Dany De Bontridder 2020-06-03 16:09:31 +02:00
parent 09398054ce
commit 9d001a7ed0
5 changed files with 266 additions and 15 deletions

View file

@ -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"});
}
}
);
}

View file

@ -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);

View file

@ -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='<form id="'.$p_id.'" method="POST">';
$r.=Dossier::hidden();
$a_code=$this->db->get_array("select code from v_menu_dependency vmd where me_code=$1 and p_id=$2",
array( $operation->signature,$g_user->get_profile()));
// select the menu where the operation will be duplicated
if ( empty ($a_code)) {
$r.=_("Menu invalide");
return $r;
}
$r.="<p>";
$r.="<ul style=\"margin-left:2rem;padding-left:0;list-style:none;\">";
$r.=sprintf("<li>%s</li>",$operation->det->jr_pj_number);
$r.=sprintf("<li>%s</li>",$operation->det->jr_comment);
$r.=sprintf("<li>%s</li>",$operation->det->jr_montant);
$r.="</ul>";
$r.="</p>";
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.="</p>";
$r.=HtmlInput::simple_array_to_hidden($array);
//
$r.=HtmlInput::submit(uniqid(), _("Dupliquer"));
$r.='</form>';
// 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;
}
}

View file

@ -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

View file

@ -1,5 +1,6 @@
<hr>
<?php
/**
//This file is part of NOALYSS and is under GPL
//see licence.txt
@ -10,6 +11,10 @@
* Variables : $div = popup or box (det[0-9]
*
*/
require_once NOALYSS_INCLUDE."/lib/select_box.class.php";
$select_box=new \Select_Box("sb_".$jr_id, _("Autre action"));
$select_box->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 '<input type="button" class="smallbutton" value="'._('verifie CA').'" onClick="verify_ca(\''.$div.'\');">';
$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 '</p>';
$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 '</p>';
echo '</form>';
echo '<div id="ext'.$div.'" class="inner_box" style="position:absolute;top:40px;display:none">';
@ -341,7 +349,7 @@ echo '</form>';
$extourne_label=new IText("ext_label");
$extourne_label->size=40;
$r="<form id=\"form_".$div."\" onsubmit=\"return false;\">";
$r.=HtmlInput::hidden('jr_id',$_REQUEST['jr_id'])
$r.=HtmlInput::hidden('jr_id',$obj->jr_id)
. HtmlInput::hidden('div',$div).dossier::hidden().HtmlInput::hidden('act','reverseop');
$r.=HtmlInput::title_box(_('Extourner'), 'ext'.$div, 'hide');
$r.="<p>";