noalyss Version-9
acc_report_mtable.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2021) Author Dany De Bontridder <danydb@noalyss.eu>
21
22require_once NOALYSS_INCLUDE.'/database/form_detail_sql.class.php';
23/**
24 * @file
25 * @brief manage simple report
26 */
27/**
28 * @class Acc_Report_MTable
29 * @brief manage simple report
30 */
32{
33
35
36 function __construct(\Data_SQL $p_table)
37 {
38 parent::__construct($p_table);
39 }
40
41 /**
42 *
43 * @brief build an object Acc_Report_MTable
44 * @param int $p_id Form_Detail_SQL.id
45 * @param int $p_form_def_id Parent Form
46 * @returns Acc_Report_MTable
47 * @throws Exception
48 */
49 static function build($p_id, $p_form_def_id)
50 {
52 $form_detail=new Form_Detail_SQL($cn, $p_id);
53 if ( $p_id == -1) {
54 $max=$cn->get_value("select coalesce(max(fo_pos),0) +10 from form_detail where fo_fr_id=$1",
55 [$p_form_def_id]);
56 $form_detail->setp("fo_pos",$max);
57 }
58 $acc_report_mtable=new Acc_Report_MTable($form_detail);
59 $acc_report_mtable->set_order(['fo_pos', 'fo_label', 'fo_formula']);
60
61 $acc_report_mtable->set_col_label("fo_pos", _("Position"));
62 $acc_report_mtable->set_col_label("fo_label", _("Libellé"));
63 $acc_report_mtable->set_col_label("fo_formula", _("Formula"));
64 $acc_report_mtable->set_form_definition_id($p_form_def_id);
65
66 $acc_report_mtable->set_sort_column("fo_pos");
67
68 $acc_report_mtable->set_col_type("fo_pos", "numeric");
69 $acc_report_mtable->set_col_type("fo_formula", "custom");
70 $acc_report_mtable->set_col_tips("fo_formula", 79);
71
72 $acc_report_mtable->add_json_param("form_def", $p_form_def_id);
73 $acc_report_mtable->add_json_param("op", "report_definition");
74 $acc_report_mtable->set_callback("ajax_misc.php");
75
76 return $acc_report_mtable;
77 }
78
79 public function get_form_definition_id()
80 {
82 }
83
85 {
86 $this->form_definition_id=$form_definition_id;
87 }
88
89 function input_custom($p_key, $p_value)
90 {
91 if ($p_key=='fo_formula')
92 {
93 $formula=new ITextarea('fo_formula');
94 $formula->id='fo_formula';
95 $formula->value=$p_value;
96 echo $formula->input();
97
98 echo HtmlInput::button_action(_("Cherche poste, fiche , analytique"),
99 sprintf('search_account_card({gDossier:%s,target:\'%s\'})',Dossier::id(),
100 "fo_formula")
101 );
102 echo HtmlInput::hidden("form_def",$this->form_definition_id);
103 }
104 }
105
106 function display_row_custom($p_key, $p_value, $p_id=0)
107 {
108 if ($p_key=='fo_formula')
109 {
110
111 return td($p_value);
112 }
113 }
114
115 function display_table($p_order="", $p_array=NULL)
116 {
117
118 return parent::display_table(" where fo_fr_id = $1 order by fo_pos", [$this->get_form_definition_id()]);
119 }
120 function check()
121 {
122 $obj=$this->get_table();
123 $obj->setp("fo_fr_id",$this->form_definition_id);
124 $n=0;
125 if ( ! Impress::check_formula($obj->getp("fo_formula"))) {
126 $this->set_error("fo_formula", _("Formule invalide"));
127 $n++;
128
129 }
130 if ( trim($obj->getp("fo_label")) == "") {
131 $n++;
132 $this->set_error("fo_label",_("Nom est vide"));
133 }
134
135 if ($n == 0 ) { return true; }
136 return false;
137 }
138
139}
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
manage simple report
display_table($p_order="", $p_array=NULL)
display the data of the table
input_custom($p_key, $p_value)
this function let you create your own input , for example for a ITEXT , a IRADIO ,...
static build($p_id, $p_form_def_id)
build an object Acc_Report_MTable
display_row_custom($p_key, $p_value, $p_id=0)
When displaying a row, if a column has the type "custom" , we can call this function to display prope...
__construct(\Data_SQL $p_table)
set_form_definition_id($form_definition_id)
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
static id()
return the 'gDossier' value after a check
static connect()
ORM abstract of the table public.form_detail.
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static hidden($p_name, $p_value, $p_id="")
Manage the TEXTAREA html element.
static check_formula($p_string)
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
set_error($p_col, $p_message)
set the error message for a wrong input