Link between contact option and document

This commit is contained in:
Dany De Bontridder 2020-10-10 17:37:13 +02:00
parent 7aadc12a6d
commit c23d824fe7
10 changed files with 107 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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();
}
/**

View file

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

View file

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

View file

@ -95,4 +95,23 @@ echo _("Création de facture");
</li>
</ul>
</div>
</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>

View file

@ -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">';

View file

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