noalyss Version-9
template_card_category.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 * NOALYSS 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 (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22require_once NOALYSS_INCLUDE.'/database/fiche_def_ref_sql.class.php';
23
24/**
25 * @file
26 * @brief Manage the template of card category
27 */
28
29/**
30 * @class Template_Card_Category
31 * @brief Manage the template of card category
32 */
34{
35
36 function __construct(Fiche_def_ref_SQL $p_table)
37 {
38 $this->table=$p_table;
39 parent::__construct($p_table);
40 // Label of the columns
41 $this->set_col_label("frd_text", _("Nom"));
42 $this->set_col_label("frd_class_base", _("Poste comptable de base"));
43 $this->set_col_label("frd_id", _("ID"));
44 // Cannot update frd_id
45 $this->set_property_updatable("frd_id", FALSE);
46 $this->a_order=["frd_id", "frd_text", "frd_class_base"];
47 }
48
49 function delete()
50 {
52
53 if ($cn->get_value("select count(*) from fiche_def where frd_id=$1",
54 [$this->table->frd_id])>0)
55 {
56 throw new Exception(_("Effacement impossible : catégorie utilisée"));
57 }
58 $cn->exec_sql("delete from attr_min where frd_id=$1",[$this->table->frd_id]);
59 $this->table->delete();
60 }
61
62 /**
63 * Check before inserting or updating, return TRUE if ok otherwise FALSE.
64 * @return boolean
65 */
66 function check()
67 {
69 $error=0;
70 if (trim($this->table->frd_text)=="")
71 {
72 $this->set_error("frd_text", _("Le nom ne peut pas être vide"));
73 $error++;
74 }
75 if (trim($this->table->frd_class_base)!="")
76 {
77 $cnt=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1"
78 , [$this->table->frd_class_base]);
79 if ($cnt==0)
80 {
81 $this->set_error("frd_class_base",
82 _("Poste comptable n'existe pas"));
83 $error++;
84 }
85 }
86
87 if ($error!=0)
88 {
89 return false;
90 }
91 return true;
92 }
93
94 /**
95 * @brief display into a dialog box the datarow in order
96 * to be appended or modified. Can be override if you need
97 * a more complex form
98 */
99 function input()
100 {
101 echo "<br><font color=\"red\"> ";
102 echo _("Attention, ne pas changer la signification de ce poste.");
103 echo hi(_("par exemple ne pas changer Client par fournisseur"))."<br>";
104 echo _("sinon le programme fonctionnera mal, ".
105 "utiliser uniquement des chiffres pour la classe de base ou rien")."</font>";
106 $error_name=$this->get_error("frd_text");
107 $error_account=$this->get_error("frd_class_base");
108 $error_name=($error_name=="")?"":HtmlInput::errorbulle($error_name);
109 $error_account=($error_account=="")?"":HtmlInput::errorbulle($error_account);
110
111 $frd_id=HtmlInput::hidden("frd_id",$this->get_table()->getp("frd_id"));
112 $name=new IText("frd_text",$this->get_table()->getp("frd_text"));
113 $account=new IPoste("frd_class_base",$this->get_table()->getp("frd_class_base"));
114 $account->set_attribute('gDossier',Dossier::id());
115 $account->set_attribute('jrn',0);
116 $account->set_attribute('account','frd_class_base');
117 $name_label=_("Nom");
118 $account_label=_("Poste comptable de base");
119 echo <<<EOF
120 <table>
121 <tbody>
122 <tr>
123 <td> ID </td>
124 <td>{$frd_id}{$this->get_table()->getp("frd_id")}</td>
125 </tr>
126 <tr>
127 <td> {$name_label} {$error_name}</td>
128 <td>
129 {$name->input()}
130 </td>
131 </tr>
132 <tr>
133 <td> {$account_label} {$error_account}</td>
134 <td>
135 {$account->input()}
136 </td>
137 </tr>
138 </tbody>
139 </table>
140EOF;
141 echo HtmlInput::get_to_hidden(["gDossier","op","p_id"]);
142 /**
143 * Add / Remove attribut Minimum
144 */
145 if ($this->table->frd_id!=-1)
146 {
147 echo h2(_("Attribut minimum pour les catégories de fiches"));
150 $objname=$this->get_object_name();
151 $a_attribut=$cn->get_array("select ad_id,ad_text,ad_type from attr_min join attr_def using (ad_id) where frd_id=$1 order by 2",
152 [$this->table->frd_id]);
153 $nb_attribut=count($a_attribut);
154 printf('<ul id="%s_list"> ', $objname);
155 $used=$cn->get_value("select count(*) from jnt_fic_attr join fiche_def using (fd_id) where frd_id=$1",
156 [$this->table->frd_id]);
157 if ($used!=0)
158 {
159 echo _("Catégorie utilisée, les attributs ne peuvent pas être modifiés");
160 }
161 for ($i=0; $i<$nb_attribut; $i++)
162 {
163 printf('<li id="%s_elt%d">', $objname
164 , $a_attribut[$i]['ad_id']);
165 echo $a_attribut[$i]['ad_text'];
166 // cannot delete NAME and QUICKCODE + attribute used in a
167 if (!in_array($a_attribut[$i]['ad_id'], [ATTR_DEF_NAME, ATTR_DEF_QUICKCODE])&&$used==0)
168 {
169 // allow to remove attribute
170 $js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
171 Dossier::id(), $this->table->frd_id, $objname, $a_attribut[$i]['ad_id']);
172 echo Icon_Action::trash(uniqid(), $js);
173 }
174 echo '</li>';
175 }
176 echo '</ul>';
177 // Add some attribute if not used
178 if ($used==0)
179 {
180 $sel_attribut=new ISelect("sel".$this->get_object_name());
181 $sel_attribut->value=$cn->make_array("select ad_id,ad_text
182 from attr_def
183 where
184 not exists (select 1
185 from
186 attr_min
187 where
188 frd_id=$1 and ad_id=attr_def.ad_id)", NULL,
189 [$this->table->frd_id]);
190 echo _("Attribut à ajouter");
191 echo $sel_attribut->input();
192 $js_script=sprintf("category_card.add_attribut('%s','%s','%s')",
193 $dossier_id, $this->table->frd_id, $objname);
194 echo Icon_Action::icon_add(uniqid(), $js_script);
195 }
196 }
197
198 }
199
200 /**
201 * When adding a template of category of card, the minimum is the name
202 * and the quickcode, which must be added into attr_min
203 */
205 {
207 $frd_id=$this->get_table()->getp("frd_id");
208 $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
210 $cn->exec_sql("insert into attr_min (frd_id,ad_id) values ($1,$2)",
212 }
213
214}
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
hi($p_string)
Definition: ac_common.php:48
tr($p_string, $p_extra='')
Definition: ac_common.php:88
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$dossier_id
Definition: ajax_poste.php:43
static id()
return the 'gDossier' value after a check
static connect()
ORM Manage the table public.fiche_def_ref , which concerns the template of category of card.
static hidden($p_name, $p_value, $p_id="")
static errorbulle($p_comment)
static get_to_hidden($array)
transform $_GET data to hidden
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30
static icon_add($id, $p_javascript, $p_style="")
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
Purpose is to propose a librairy to display a table content and allow to update and delete row ,...
set_property_updatable($p_key, $p_value)
set a column of the data row updatable or not
get_error($p_col)
retrieve the error message
set_error($p_col, $p_message)
set the error message for a wrong input
set_col_label($p_key, $p_display)
set the name to display for a column
Manage the template of card category.
input()
display into a dialog box the datarow in order to be appended or modified.
__construct(Fiche_def_ref_SQL $p_table)
check()
Check before inserting or updating, return TRUE if ok otherwise FALSE.
add_mandatory_attr()
When adding a template of category of card, the minimum is the name and the quickcode,...
$all table
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_QUICKCODE
Definition: constant.php:237