Follow-up export contact option with all the the card's attribute

This commit is contained in:
sparkyx 2020-10-22 14:49:56 +02:00
parent 9f878b1be3
commit bfe3db9037

View file

@ -37,32 +37,75 @@ if ( $g_user->can_read_action($ag_id) == false ) return;
$csv=new Noalyss_CSV("followup".$ag_id);
$csv->send_header();
$document=new Follow_Up($cn);
echo $document->export_csv(["tdoc"=>$ag_id]);
$document_type=$cn->get_value("select ag_type from action_gestion where ag_id=$1",[$ag_id]);
$ret=$cn->exec_sql("select f_id,(select ad_value from fiche_detail where f_id=a.f_id and ad_id=25) as company,
(select ad_value from fiche_detail where f_id=a.f_id and ad_id=1) as name,
(select ad_value from fiche_detail where f_id=a.f_id and ad_id=32) as first_name,
(select ad_value from fiche_detail where f_id=a.f_id and ad_id=23) as quick_code,
cor.cor_label,
apo.ap_value
$aRow=$cn->get_array("select a.f_id,ap_id,ag_id,f.ad_value,f.ad_id,fd.fd_id,jfa.jnt_order
from action_person a
left join action_person_option apo ON (a.ap_id=apo.action_person_id)
left join contact_option_ref cor on (apo.contact_option_ref_id=cor.cor_id)
where ag_id=$1",[$ag_id]);
$aTitle= array (
array("title"=>_("fiche_id"), "type"=>"string"),
array("title"=>_("société"), "type"=>"string"),
array("title"=>_("nom"), "type"=>"string"),
array("title"=>_("prénom"), "type"=>"string"),
array("title"=>_("qcode"), "type"=>"string"),
array("title"=>_("option"), "type"=>"string"),
array("title"=>_("valeur"), "type"=>"string"));
$cn->query_to_csv($ret,$aTitle);
join fiche f1 on (a.f_id=f1.f_id)
join fiche_detail f on (a.f_id=f.f_id)
join fiche_def fd on (fd.fd_id=f1.fd_id)
join jnt_fic_attr jfa on (fd.fd_id=jfa.fd_id and jfa.ad_id=f.ad_id)
where ag_id=$1
order by f1.fd_id, a.f_id,jnt_order;;",[$ag_id]);
$ret=$cn->exec_sql('select t_tag,t_description from action_tags join tags using (t_id) where ag_id=$1',[$ag_id]);
$aTitle=array(
array('title'=>_('Etiquette'),"type"=>"string"),
array('title'=>_("Description"),"type"=>"string")
);
$cn->query_to_csv($ret,$aTitle);
$nb=count($aRow);
$lastcat=0;$lastcard=0;
for ($i=0;$i< $nb;$i++)
{
// for each card we sent all info
if ($lastcard != $aRow[$i]['f_id']) {
// Write contact option
$aOption=$cn->get_array(" select ap_value
from
action_person a
join action_person_option apo on (a.ap_id=apo.action_person_id)
join contact_option_ref cor on (cor.cor_id=apo.contact_option_ref_id)
where ag_id=$1 and f_id=$2 order by cor_id",array($ag_id,$lastcard));
$nb_option=count($aOption);
for ($h=0;$h < $nb_option;$h++) {
$csv->add($h);
}
$csv->write();
$lastcard=$aRow[$i]['f_id'];
}
// For each category we send the column header
if ( $lastcat != $aRow[$i]['fd_id']) {
// Get attribut fd
$aColHeader = $cn->get_array("select jnt_order,
ad_text,
ad_type
from fiche_def f
join jnt_fic_attr jfa using (fd_id)
join attr_def ad using (ad_id)
where
f.fd_id=$1
order by jnt_order",[$aRow[$i]['fd_id']]);
$aCol=array();
$nb_col=count($aColHeader);
for ( $j = 0;$j < $nb_col;$j++) {
$aCol[]=$aColHeader[$j]['ad_text'];
}
// Add contact header option
$aOptionCat=$cn->get_array("select
cor.cor_label
from
public.jnt_document_option_contact jdoc
join contact_option_ref cor on
(jdoc.contact_option_ref_id = cor_id )
where
document_type_id = $1
and jdoc_enable = 1 order by cor_id",array($document_type));
$nb_col=count($aOptionCat);
for ( $j = 0;$j < $nb_col;$j++) {
$aCol[]=$aOptionCat[$j]['cor_label'];
}
$csv->write_header($aCol);
$lastcat=$aRow[$i]['fd_id'];
}
$csv->add($aRow[$i]['ad_value']);
}
$csv->write();