noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 16/39: task #0001413: Duplication d'opération


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 16/39: task #0001413: Duplication d'opération 2 - le retour
Date: Sat, 11 Jul 2020 13:20:39 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 9d001a7ed02cb2811ae2337e438c71137ced0832
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Wed Jun 3 16:09:31 2020 +0200

    task #0001413: Duplication d'opération 2 - le retour
---
 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          |  17 ++-
 include/template/ledger_detail_bottom.php |  32 +++---
 5 files changed, 265 insertions(+), 14 deletions(-)

diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index f236bf3..200a306 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 8b90b6e..7f93ea8 100644
--- a/include/ajax/ajax_ledger.php
+++ b/include/ajax/ajax_ledger.php
@@ -578,6 +578,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);
  if ( ! headers_sent()) {     header('Content-type: text/xml; 
charset=UTF-8');} else { echo "HTML".unescape_xml($html);}
diff --git a/include/class/acc_operation.class.php 
b/include/class/acc_operation.class.php
index 3a71a3f..8586607 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='<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;
+        
+    }
 }
diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php
index f79048b..7dd1ccd 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 6f89b1d..c2d6354 100644
--- a/include/template/ledger_detail_bottom.php
+++ b/include/template/ledger_detail_bottom.php
@@ -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>";



reply via email to

[Prev in Thread] Current Thread [Next in Thread]