diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php index fe8834f2e..b3103e471 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 feedef07b..418b103df 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 6a6b36c8e..931f07ed3 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 bd41af234..d3cc70b14 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 3ba7d9b68..2933dae01 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 270a700a7..e03a185a0 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 bb8c21f9a..b6a62f9da 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 eee56aac4..9328c4c80 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"); - \ No newline at end of file + +
+

+ +
diff --git a/include/template/card_multiple_display_option.php b/include/template/card_multiple_display_option.php index 2b07f9e3b..309aa3754 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 ''; diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 6ee0d7ed2..50e61a794 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));