get_initial_name()], ENT_QUOTES, $charset);
}
protected function _get_query_base() {
if(!$this->filters['user_input']) {
$query = "
SELECT actes.id_acte as id, actes.*, date_ech_calc, raison_sociale, actes2.numero as num_acte_parent
FROM (actes ";
} else {
$members_actes = $this->get_analyse_query()->get_query_members("actes","actes.numero","actes.index_acte", "actes.id_acte");
$members_lignes = $this->get_analyse_query()->get_query_members("lignes_actes","lignes_actes.code","lignes_actes.index_ligne", "lignes_actes.id_ligne");
$query = "
select actes.id_acte as id, actes.*, date_ech_calc, actes2.numero as num_acte_parent, raison_sociale, max(".$members_actes["select"]."+".$members_lignes["select"].") as pert
from (actes left join lignes_actes on num_acte=id_acte ";
}
$query .= "
LEFT JOIN (SELECT MIN((DATE_FORMAT(date_ech, '%Y%m%d'))) AS date_ech_calc, num_acte FROM lignes_actes WHERE (('2' & statut) = '0') GROUP BY num_acte) dl ON dl.num_acte=actes.id_acte)
LEFT JOIN entites ON entites.id_entite=actes.num_fournisseur
LEFT JOIN liens_actes ON num_acte_lie=actes.id_acte
LEFT JOIN actes actes2 ON actes2.id_acte=liens_actes.num_acte ";
// $query .= "group by actes.id_acte ";
// if(trim($order)){
// $q.=$order;
// } else{
// $q.= "order by pert desc";
// }
return $query;
}
protected function fetch_data() {
$this->objects = array();
$query = $this->_get_query();
$result = pmb_mysql_query($query);
//Particularité ici : On s'assure qu'il n'existe pas qu'une ligne avec des valeurs NULLES
while($row = pmb_mysql_fetch_object($result)) {
if($row->id) {
$this->add_object($row);
}
}
if(!count($this->objects)) {
$this->pager['nb_results'] = 0;
} elseif($this->applied_sort_type != "SQL"){
$this->pager['nb_results'] = pmb_mysql_num_rows($result);
}
$this->messages = "";
}
/**
* Initialisation des filtres disponibles
*/
protected function init_available_filters() {
$this->available_filters =
array('main_fields' =>
array(
'global_search' => 'global_search',
'status' => 'acquisition_statut',
'entity' => 'acquisition_coord_lib',
'rubrique' => 'acquisition_rub',
'applicants' => 'acquisition_applicants',
'lgstats' => 'acquisition_lgstat',
'suppliers' => 'acquisition_ach_fou'
)
);
if(static::class != 'list_accounting_devis_ui') {
$this->available_filters['main_fields']['exercice'] = 'acquisition_budg_exer';
}
$this->available_filters['custom_fields'] = array();
}
protected function init_default_selected_filters() {
$this->add_selected_filter('global_search');
if(static::class != 'list_accounting_devis_ui') {
$this->add_selected_filter('exercice');
} else {
$this->add_empty_selected_filter();
}
$this->add_empty_selected_filter();
$this->add_selected_filter('status');
$this->add_selected_filter('entity');
$this->add_empty_selected_filter();
$this->add_selected_filter('rubrique');
//$this->add_selected_filter('applicants');
}
protected function get_filter_entite() {
if(!$this->filters['entite']) {
$query = entites::list_biblio(SESSuserid);
$result = pmb_mysql_query($query);
$this->filters['entite'] = pmb_mysql_result($result, 0, 'id_entite');
}
return $this->filters['entite'];
}
/**
* Initialisation des filtres de recherche
*/
public function init_filters($filters=array()) {
global $id_bibli;
//Paramètres utilisateur
global $deflt3bibli;
global $deflt3exercice;
$status = "deflt3".$this->get_initial_name()."_statut";
global ${$status};
$this->filters = array(
'type_acte' => $this->get_type_acte(),
'user_input' => '',
'entite' => ($id_bibli ? $id_bibli : ($deflt3bibli ? $deflt3bibli : $this->get_filter_entite())),
'status' => ${$status},
'rubrique' => '',
'applicants' => array(),
'lgstats' => array(),
'suppliers' => array()
);
if(static::class != 'list_accounting_devis_ui') {
$this->filters['exercice'] = ($deflt3exercice ? $deflt3exercice : '');
} else {
$this->filters['exercice'] = '';
}
parent::init_filters($filters);
}
/**
* Initialisation des settings par défaut
*/
protected function init_default_settings() {
parent::init_default_settings();
$this->set_setting_display('search_form', 'unfolded_filters', true);
$this->set_setting_display('search_form', 'export_icons', false);
$this->set_setting_column('default', 'align', 'left');
$this->set_setting_column('default', 'text', array('italic' => true));
$this->set_setting_column('print_mail', 'text', array('italic' => false));
}
/**
* Initialisation de la pagination par défaut
*/
protected function init_default_pager() {
global $nb_per_page_acq;
parent::init_default_pager();
$this->pager['nb_per_page'] = ($nb_per_page_acq ? $nb_per_page_acq : 10);
}
/**
* Initialisation du tri par défaut appliqué
*/
protected function init_default_applied_sort() {
if($this->filters['user_input']) {
$this->add_applied_sort('pert');
} else {
$this->add_applied_sort('id', 'desc');
}
}
/**
* Tri SQL
*/
protected function _get_query_order() {
if($this->applied_sort[0]['by']) {
$order = '';
$sort_by = $this->applied_sort[0]['by'];
switch($sort_by) {
default :
$order .= $sort_by;
break;
}
if($order) {
$this->applied_sort_type = 'SQL';
return " group by actes.id_acte order by ".$order." ".$this->applied_sort[0]['asc_desc'];
} else {
return " group by actes.id_acte";
}
}
}
/**
* Filtres provenant du formulaire
*/
public function set_filters_from_form() {
$this->set_filter_from_form('user_input');
$this->set_filter_from_form('entite', 'integer');
$this->set_filter_from_form('exercice', 'integer');
$this->set_filter_from_form('status', 'integer');
$this->set_filter_from_form('rubrique', 'integer');
$applicants = $this->objects_type.'_applicants';
global ${$applicants};
if(isset(${$applicants})) {
$this->filters['applicants'] = ${$applicants};
}
$this->set_filter_from_form('lgstats', 'integer');
$suppliers = $this->objects_type.'_suppliers';
global ${$suppliers};
if(isset(${$suppliers})) {
$this->filters['suppliers'] = ${$suppliers};
}
parent::set_filters_from_form();
}
protected function get_search_filter_global_search() {
global $charset;
return "";
}
protected function get_search_filter_entity() {
global $charset;
$selector = "";
return $selector;
}
protected function get_search_filter_exercice() {
$selector = exercices::getHtmlSelect($this->filters['entite'], $this->filters['exercice'], true, array('id'=>$this->objects_type.'_exercice','name'=>$this->objects_type.'_exercice','onchange'=>'submit();'), false);
return $selector;
}
protected function get_search_filter_status() {
global $charset;
$selector = "";
return $selector;
}
protected function get_search_filter_rubrique() {
global $charset;
$selector = "";
return $selector;
}
protected function get_search_filter_applicants() {
$elements = array();
if(!empty($this->filters['applicants'])) {
foreach ($this->filters['applicants'] as $applicant) {
if($applicant['id']) {
$name = emprunteur::get_name($applicant['id']);
$elements[] = array(
'id' => $applicant['id'],
'name' => $name
);
}
}
}
templates::init_selection_attributes(array(
array('name' => 'dyn', 'value' => '2'),
));
$selector .= templates::get_display_elements_completion_field($elements, $this->get_form_name(), $this->objects_type.'_applicants', $this->objects_type.'_applicants_id', 'emprunteur');
return $selector;
}
protected function get_search_filter_lgstats() {
$selector=lgstat::getHtmlSelect($this->filters['lgstats'], FALSE, array('id'=> $this->objects_type.'_lgstats', 'name'=> $this->objects_type.'_lgstats[]','multiple'=>'multiple','size'=>'5'));
return $selector;
}
protected function get_search_filter_suppliers() {
$elements = array();
if(!empty($this->filters['suppliers'])) {
foreach ($this->filters['suppliers'] as $supplier) {
if($supplier['id']) {
$entites = new entites($supplier['id']);
$elements[] = array(
'id' => $supplier['id'],
'name' => $entites->raison_sociale
);
}
}
}
templates::init_selection_attributes(array(
array('name' => 'dyn', 'value' => '2'),
));
$selector .= templates::get_display_elements_completion_field($elements, $this->get_form_name(), $this->objects_type.'_suppliers', $this->objects_type.'_suppliers_id', 'fournisseur');
return $selector;
}
/**
* Jointure externes SQL pour les besoins des filtres
*/
protected function _get_query_join_filters() {
$filter_join_query = '';
if($this->filters['rubrique'] || count($this->filters['applicants']) || count($this->filters['lgstats'])) {
$filter_join_query .= " LEFT JOIN lignes_actes ON lignes_actes.num_acte=actes.id_acte";
}
if(count($this->filters['applicants'])) {
$filter_join_query .= " LEFT JOIN lignes_actes_applicants ON lignes_actes_applicants.ligne_acte_num=lignes_actes.id_ligne";
}
if(count($this->filters['lgstats'])) {
$filter_join_query .= " LEFT JOIN lignes_actes_statuts ON lignes_actes_statuts.id_statut=lignes_actes.statut";
}
return $filter_join_query;
}
/**
* Filtre SQL
*/
protected function _get_query_filters() {
$filter_query = '';
$this->set_filters_from_form();
$filters = array();
$filters[] = "actes.type_acte = '".$this->filters['type_acte']."'";
if($this->filters['user_input']) {
$isbn = '';
$t_codes = array();
if (isEAN($this->filters['user_input'])) {
// la saisie est un EAN -> on tente de le formater en ISBN
$isbn = EANtoISBN($this->filters['user_input']);
// si échec, on prend l'EAN comme il vient
if($isbn) {
$t_codes[] = $isbn;
$t_codes[] = formatISBN($isbn,10);
}
} elseif (isISBN($this->filters['user_input'])) {
// si la saisie est un ISBN
$isbn = formatISBN($this->filters['user_input']);
if($isbn) {
$t_codes[] = $isbn ;
$t_codes[] = formatISBN($isbn,13);
}
} elseif (isISSN($this->filters['user_input'])) {
$t_codes[] = $this->filters['user_input'] ;
}
if (count($t_codes)) {
$codes_query = array();
foreach ($t_codes as $v) {
$codes_query [] = "lignes_actes.code like '%".addslashes($v)."%' ";
}
$filters[] = "(".implode(' or ', $codes_query).")";
} else {
$members_actes = $this->get_analyse_query()->get_query_members("actes","actes.numero","actes.index_acte", "actes.id_acte");
$members_lignes = $this->get_analyse_query()->get_query_members("lignes_actes","lignes_actes.code","lignes_actes.index_ligne", "lignes_actes.id_ligne");
$filters[] = "(".$members_actes["where"]." or ".$members_lignes["where"]." or actes.numero like '%".addslashes($this->filters['user_input'])."%')";
}
}
if($this->filters['entite']) {
$filters[] = "actes.num_entite = '".$this->filters['entite']."'";
}
if($this->filters['exercice']) {
$filters[] = "actes.num_exercice = '".$this->filters['exercice']."'";
}
if($this->filters['status']) {
if ($this->filters['status'] != '-1') {
if ($this->filters['status'] == 32) {
$filters[] = "((actes.statut & 32) = 32) ";
} else {
$filters[] = "((actes.statut & 32) = 0) and ((actes.statut & ".$this->filters['status'].") = '".$this->filters['status']."') ";
}
}
}
if($this->filters['rubrique']) {
$rubriques_ids = array_keys(rubriques::getChilds($this->filters['rubrique']));
$rubriques_ids[] = $this->filters['rubrique'];
$filters[] = "lignes_actes.num_rubrique IN (".implode(",",$rubriques_ids).")";
}
if(count($this->filters['applicants'])) {
$applicants = array();
$filtre_empr='';
$filtre_users='';
foreach ($this->filters['applicants'] as $applicant) {
if($applicant['id']) {
$applicants['empr'][] = $applicant['id'];
}
}
if (is_array($applicants['empr']) && count($applicants['empr'])) {
$filtre_empr = "lignes_actes_applicants.empr_num in ('".implode("','",$applicants['empr'])."') ";
}
if($filtre_empr) {
$filters[] = "(".$filtre_empr.")";
}
}
if(count($this->filters['lgstats'])) {
$filters[] = "lignes_actes.statut in (".implode(',',$this->filters['lgstats']).")";
}
if(count($this->filters['suppliers'])) {
$suppliers = array();
foreach ($this->filters['suppliers'] as $supplier) {
if($supplier['id']) {
$suppliers[] = $supplier['id'];
}
}
if(count($suppliers)) {
$filters[] = "actes.num_fournisseur in (".implode(',',$suppliers).")";
}
}
if(count($filters)) {
$filter_query .= $this->_get_query_join_filters();
$filter_query .= ' where '.implode(' and ', $filters);
}
return $filter_query;
}
protected function get_link_action($action, $act) {
global $msg;
return array(
'href' => static::get_controller_url_base()."&action=".$action."&id_bibli=".$this->filters['entite'],
'confirm' => $msg['acquisition_'.$this->get_initial_name().'list_'.$act]
);
}
protected function add_column_print($pdfdoc) {
global $base_path;
global $msg, $charset;
$this->columns[] = array(
'property' => '',
'label' => "",
'html' => "
get_initial_name()."=!!id!!' ,'print_PDF');\" >
",
'exportable' => false
);
}
protected function get_display_content_cell_print_mail($object) {
global $base_path;
global $sub;
global $msg, $charset;
global $acquisition_pdfcde_by_mail;
$bib_coord = pmb_mysql_fetch_object(entites::get_coordonnees($this->filters['entite'],1));
$display = "
filters['entite']."&id_".$this->get_initial_name()."=".$object->id_acte."&page=".$this->pager['page']."&by_mail=0'\" >
";
$parameter_name = 'acquisition_pdf'.$this->get_initial_name().'_by_mail';
global ${$parameter_name};
if (((($object->statut & ~STA_ACT_ARC) == STA_ACT_ENC) && ${$parameter_name} && !empty($bib_coord->email) && strpos($bib_coord->email,'@'))) {
$display .= "
filters['entite']."&id_".$this->get_initial_name()."=".$object->id_acte."&page=".$this->pager['page']."&by_mail=1';}\" >
";
}
return $display;
}
/**
* Construction dynamique de la fonction JS de tri
*/
protected function get_js_sort_script_sort() {
$display = parent::get_js_sort_script_sort();
$display = str_replace('!!categ!!', 'ach', $display);
$display = str_replace('!!sub!!', '', $display);
$display = str_replace('!!action!!', 'list', $display);
return $display;
}
protected function get_cell_content($object, $property) {
global $msg, $charset;
$content = '';
switch($property) {
case 'num_fournisseur':
$entites = new entites($object->num_fournisseur);
$content .= $entites->raison_sociale;
break;
case 'date_acte':
$content .= formatdate($object->date_acte);
break;
case 'statut':
$st = (($object->statut) & ~(STA_ACT_ARC));
switch ($st) {
case STA_ACT_ENC :
$statut = htmlentities($msg['acquisition_'.$this->get_initial_name().'_enc'], ENT_QUOTES, $charset);
break;
case STA_ACT_REC :
$statut = htmlentities($msg['acquisition_'.$this->get_initial_name().'_rec'], ENT_QUOTES, $charset);
break;
case STA_ACT_PAY :
$statut = htmlentities($msg['acquisition_'.$this->get_initial_name().'_pay'], ENT_QUOTES, $charset);
break;
default :
if(isset($msg['acquisition_'.$this->get_initial_name().'_enc'])) {
$statut = htmlentities($msg['acquisition_'.$this->get_initial_name().'_enc'], ENT_QUOTES, $charset);
} else {
$statut = '';
}
}
if(($object->statut & STA_ACT_ARC) == STA_ACT_ARC) {
$content .= ''.$statut.'';
} else {
$content .= $statut;
}
break;
case 'print_mail':
$content .= $this->get_display_content_cell_print_mail($object);
break;
default :
$content .= parent::get_cell_content($object, $property);
break;
}
return $content;
}
protected function _get_cell_header($name, $label = '') {
if($name == 'print_mail') {
return "