noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 67/119: Link between contact option and docum


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 67/119: Link between contact option and document
Date: Mon, 26 Oct 2020 18:27:23 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit c23d824fe7ee59eef2c6f982998c73611bb78030
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Sat Oct 10 17:37:13 2020 +0200

    Link between contact option and document
---
 include/ajax/ajax_card.php                         |  1 +
 include/ajax/ajax_card_attribute.php               |  1 +
 include/ajax/ajax_save_card_option.php             | 11 ++-----
 .../class/action_document_type_mtable.class.php    | 37 ++++++++++++++++++++++
 include/class/card_attribut_mtable.class.php       |  6 +---
 include/class/card_multiple.class.php              | 34 +++++++++++++-------
 include/class/contact_option_ref_mtable.class.php  |  5 +--
 .../template/action_document_type_mtable_input.php | 21 +++++++++++-
 include/template/card_multiple_display_option.php  |  7 ++++
 sql/upgrade.sql                                    | 11 +++++++
 10 files changed, 107 insertions(+), 27 deletions(-)

diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index fe8834f..b3103e4 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -63,6 +63,7 @@ require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/user.class.php';
 require_once NOALYSS_INCLUDE.'/class/fiche_attr.class.php';
+require_once NOALYSS_INCLUDE.'/lib/input_switch.class.php';
 
 mb_internal_encoding("UTF-8");
 
diff --git a/include/ajax/ajax_card_attribute.php 
b/include/ajax/ajax_card_attribute.php
index feedef0..418b103 100644
--- a/include/ajax/ajax_card_attribute.php
+++ b/include/ajax/ajax_card_attribute.php
@@ -79,6 +79,7 @@ else
     {
         case "input":
             $mtable->set_pk($ad_id);
+            if ( $ad_id < 0 ) 
$mtable->get_table()->set("ad_search_followup",0);
             $mtable->send_header();
             echo $mtable->ajax_input()->saveXML();
 
diff --git a/include/ajax/ajax_save_card_option.php 
b/include/ajax/ajax_save_card_option.php
index 6a6b36c..931f07e 100644
--- a/include/ajax/ajax_save_card_option.php
+++ b/include/ajax/ajax_save_card_option.php
@@ -49,12 +49,7 @@ $nb=count($ap_value);
 if ($nb == 0) return;
 
 for ($i=0;$i<$nb; $i++) {
-    if ( $ap_id[$i] == -1 ) {
-        $cn->exec_sql("INSERT INTO public.action_person_option (ap_value, 
contact_option_ref_id, action_person_id) 
-                        VALUES($1, $2, $3) ",
-                  [$ap_value[$i],$cor_id[$i],$action_person_id]);
-    } else {
-        $cn->exec_sql("UPDATE public.action_person_option SET ap_value=$1 
WHERE ap_id=$2)",
-                [$ap_value[$i],$action_person_id]);
-    }
+
+        $cn->exec_sql("UPDATE public.action_person_option SET ap_value=$1 
WHERE ap_id=$2",
+                [$ap_value[$i],$ap_id[$i]]);
 }
\ No newline at end of file
diff --git a/include/class/action_document_type_mtable.class.php 
b/include/class/action_document_type_mtable.class.php
index bd41af2..d3cc70b 100644
--- a/include/class/action_document_type_mtable.class.php
+++ b/include/class/action_document_type_mtable.class.php
@@ -81,6 +81,13 @@ class Action_Document_Type_MTable extends Manage_Table_SQL
         $this->other['make_invoice']=$http->request("make_invoice", "string", 
0);
         $this->other['seq']=$http->request("seq", "string", 0);
         
$this->other['select_option_operation']=$http->request("select_option_operation",
 "string", null);
+        $this->other["cor_id"]=$http->request("cor_id","array",[]);
+        $nb_corid=count($this->other["cor_id"]);
+        $http->set_empty(0);
+        for ($i=0;$i<$nb_corid;$i++) {
+            
$this->other["contact_option$i"]=$http->request("contact_option".$i,"number",0);
+        }
+                 
     }
 
     /**
@@ -155,6 +162,22 @@ class Action_Document_Type_MTable extends Manage_Table_SQL
     function input()
     {
         parent::input();
+        
+        
+        
+        // Detail option contact
+        $table=$this->get_table();
+        $cn=$table->cn;
+        $aOption=$cn->get_array("select 
cor_id,cor_label,cor_type,document_type_id ,coalesce(jdoc_enable,0) jdoc_enable
+                from 
+                contact_option_ref cor  
+                left join jnt_document_option_contact jdoc on 
(cor_id=contact_option_ref_id) 
+                where 
+                document_type_id is null
+                or document_type_id = $1
+                order by cor_label",[$this->table->dt_id]);
+        
+        // Detail option
         require NOALYSS_TEMPLATE."/action_document_type_mtable_input.php";
     }
 
@@ -191,6 +214,20 @@ class Action_Document_Type_MTable extends Manage_Table_SQL
             on conflict on constraint document_option_un
             do update set do_enable=$3 ", ["make_invoice", $object_sql->dt_id, 
$this->other['make_invoice']]);
         
+        // Option contact to save
+        $cn->exec_sql("delete from jnt_document_option_contact where 
document_type_id=$1",[$object_sql->dt_id]);
+        $nb_contact_option=count($this->other["cor_id"]);
+        $aOption=$this->other["cor_id"];
+        for ( $e=0;$e<$nb_contact_option;$e++) {
+            $option_id=$aOption[$e];
+            if ( isset($this->other["contact_option".$e])  ) {
+                $cn->exec_sql("insert into jnt_document_option_contact
+                    (jdoc_enable,document_type_id,contact_option_ref_id)
+                    values 
($1,$2,$3)",[$this->other["contact_option".$e],$object_sql->dt_id,$option_id]);
+                tracedebug("insert-into-contact.log", $cn->sql);
+                tracedebug("insert-into-contact.log", $cn->array);
+            }
+        }
         
     }
 
diff --git a/include/class/card_attribut_mtable.class.php 
b/include/class/card_attribut_mtable.class.php
index 3ba7d9b..2933dae 100644
--- a/include/class/card_attribut_mtable.class.php
+++ b/include/class/card_attribut_mtable.class.php
@@ -127,11 +127,7 @@ class Card_Attribut_MTable extends Manage_Table_SQL
         if ($p_key=="ad_search_followup")
         {
             $p_id=$this->get_table()->get("ad_id");
-            $ic=new ISelect("ad_search_followup", $p_value);
-            $ic->value=array(["value"=>0, "label"=>_("Non")],
-                ["value"=>0, "label"=>_("Oui")]
-            );
-            $ic->set_value($p_value);
+            $ic=new InputSwitch("ad_search_followup", $p_value);
             echo $ic->input();
         }
         /**
diff --git a/include/class/card_multiple.class.php 
b/include/class/card_multiple.class.php
index 270a700..e03a185 100644
--- a/include/class/card_multiple.class.php
+++ b/include/class/card_multiple.class.php
@@ -89,18 +89,30 @@ class Card_Multiple
         if ( ! $g_user->can_read_action($ag_id)) {
             throw new Exception (_("CMCDO01"."Security"));
         }
+        // insert new , synchronized
+        $cn->exec_sql("insert into action_person_option 
(ap_value,contact_option_ref_id ,action_person_id ) 
+            select null,cor_id,$1
+            from contact_option_ref 
+            where 
+            cor_id not in (
+                select contact_option_ref_id 
+                from action_person_option 
+                join action_person a on (a.ap_id=action_person_id) 
+                where f_id=$2)",[$p_action_person_id,$fiche_id]);
+
+        // delete disable
+        $cn->exec_sql("delete 
+                from action_person_option apo 
+                where contact_option_ref_id  in 
+               (select contact_option_ref_id from jnt_document_option_contact 
jdoc join action_gestion on                       (ag_type=document_type_id) 
+                    where ag_id=$1 and jdoc_enable=0)",[$ag_id]);
+        
         // First select the option
-        $sql="select
-       cor.cor_id,
-       cor.cor_label,
-       cor.cor_type,
-       coalesce (apo.ap_id,-1) as ap_id,
-        ap_value,
-        cor_value_select
-from
-contact_option_ref cor
-left join action_person_option apo on (cor.cor_id=apo.contact_option_ref_id)
-where action_person_id is null or action_person_id=$1";
+        $sql="select ap_id,cor_id,ap_value,cor_type ,cor_label,cor_value_select
+              from contact_option_ref cor 
+              join action_person_option apo on 
(cor.cor_id=apo.contact_option_ref_id) 
+              where action_person_id=$1 order by cor_label  ";
+        
         $a_option=$cn->get_array($sql,[$p_action_person_id]);
         require NOALYSS_TEMPLATE."/card_multiple_display_option.php";
         
diff --git a/include/class/contact_option_ref_mtable.class.php 
b/include/class/contact_option_ref_mtable.class.php
index bb8c21f..b6a62f9 100644
--- a/include/class/contact_option_ref_mtable.class.php
+++ b/include/class/contact_option_ref_mtable.class.php
@@ -36,13 +36,14 @@ class Contact_Option_Ref_MTable extends Manage_Table_SQL{
          $this->set_col_label("cor_label", _("Nom"));
          $this->set_col_label("cor_type", _("Type "));
          $this->set_col_label("document_option_id", _("Action"));
-         $this->set_col_label("core_value_select",_("Options"));
+         $this->set_col_label("cor_value_select",_("Options"));
          $this->set_property_visible("cor_id", false);
          $this->set_col_type("cor_type","select",[
              ["label"=>_("Texte"),"value"=>0],
              ["label"=>_("Nombre"),"value"=>1],
              ["label"=>_("Choix"),"value"=>3],
-             ["label"=>_("Date"),"value"=>2]
+             ["label"=>_("Date"),"value"=>2],
+             ["label"=>_("Coche"),"value"=>4]
          ]);
      }
 
diff --git a/include/template/action_document_type_mtable_input.php 
b/include/template/action_document_type_mtable_input.php
index eee56aa..9328c4c 100644
--- a/include/template/action_document_type_mtable_input.php
+++ b/include/template/action_document_type_mtable_input.php
@@ -95,4 +95,23 @@ echo _("Création de facture");
         </li> 
     </ul>
 
-</div>
\ No newline at end of file
+</div>
+<div>
+     <h3 class="info" sytle="margin-block: 4px"><?php echo _("Options 
contact") ?></h3>
+    <ul class="tab_row" style="padding-top: 0px">
+<?php        
+            
+$nb_option=count($aOption);
+for ($i=0;$i<$nb_option;$i++)
+{
+    echo '<li>';
+    
+    echo HtmlInput::hidden("cor_id[]", $aOption[$i]["cor_id"]);
+    $is=new InputSwitch("contact_option$i",$aOption[$i]["jdoc_enable"]);
+    echo $is->input();
+    echo "&nbsp;&nbsp;&nbsp;"._($aOption[$i]['cor_label']);
+    echo '</li>';
+}
+?>
+</ul>
+</div>
diff --git a/include/template/card_multiple_display_option.php 
b/include/template/card_multiple_display_option.php
index 2b07f9e..309aa37 100644
--- a/include/template/card_multiple_display_option.php
+++ b/include/template/card_multiple_display_option.php
@@ -79,6 +79,13 @@ if (!defined('ALLOWED'))
                     }
                 }
                 break;
+            case 4:
+                $input=new InputSwitch("ap_value[]");
+                if ( $a_option[$i]['ap_value'] =="") {
+                    $a_option[$i]['ap_value']=0;
+                }
+                break;
+                
         }
        $input->set_value ($a_option[$i]['ap_value']);
         echo '<span style="display:table-row">';
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 6ee0d7e..50e61a7 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -5,3 +5,14 @@ alter table attr_def add column ad_search_followup int;
 alter table attr_def alter column ad_search_followup set default 1;
 update attr_def set ad_search_followup=1;
 comment on column attr_def.ad_search_followup is '1 : search  available  from 
followup , 0  : search not available in followup'
+
+
+create table jnt_document_option_contact
+(
+jdoc_id bigserial primary key,
+jdoc_enable int not null, 
+document_type_id bigint references document_type (dt_id) on delete cascade on 
update cascade,
+contact_option_ref_id bigint references contact_option_ref(cor_id) on delete 
cascade  on update  cascade
+);
+ALTER TABLE public.jnt_document_option_contact ADD CONSTRAINT 
jnt_document_option_contact_un UNIQUE (document_type_id,contact_option_ref_id);
+ALTER TABLE public.jnt_document_option_contact ADD CONSTRAINT 
jnt_document_option_contact_check CHECK (jdoc_enable in (0,1));



reply via email to

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