noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 {
51 $cn=Dossier::connect();
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 {
68 $cn=Dossier::connect();
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"));
148 $cn=Dossier::connect();
149 $dossier_id=Dossier::id();
150 $objname=$this->get_object_name();
151 $a_attribut=$cn->get_array("select ad_id,ad_text,ad_type,a1.ad_default_order from attr_min a1 join attr_def using (ad_id) where frd_id=$1 order by a1.ad_default_order",
152 [$this->table->frd_id]);
153 $nb_attribut=count($a_attribut);
154 printf('<ul class="list-unstyled" style="width: 60%%;margin-left: 21%%" 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_warning( _("Catégorie utilisée, les attributs de base ne peuvent pas être modifiés"));
160 }
161 echo _("Vous pouvez modifier l'ordre des attributs avec la souris");
162 for ($i=0; $i<$nb_attribut; $i++)
163 {
164 printf('<li id="%s_elt%d" style="cursor:move;border:1px solid navy;padding : 0.5rem 0.2rem 0.5rem 0.2rem;margin-top:2px">', $objname
165 , $a_attribut[$i]['ad_id']);
166 echo $a_attribut[$i]['ad_text'];
167 // cannot delete NAME and QUICKCODE + attribute used in a
168 if (!in_array($a_attribut[$i]['ad_id'], [ATTR_DEF_NAME, ATTR_DEF_QUICKCODE])&&$used==0)
169 {
170 // allow to remove attribute
171 $js=sprintf("category_card.remove_attribut('%s','%s','%s',%d)",
172 Dossier::id(), $this->table->frd_id, $objname, $a_attribut[$i]['ad_id']);
173 echo Icon_Action::trash(uniqid(), $js);
174 }
175 echo '</li>';
176 }
177 echo '</ul>';
178 // Add some attribute if not used
179 if ($used==0)
180 {
181 $sel_attribut=new ISelect("sel".$this->get_object_name());
182 $sel_attribut->value=$cn->make_array("select ad_id,ad_text
183 from attr_def
184 where
185 not exists (select 1
186 from
187 attr_min
188 where
189 frd_id=$1 and ad_id=attr_def.ad_id)", NULL,
190 [$this->table->frd_id]);
191 echo _("Attribut à ajouter");
192 echo $sel_attribut->input();
193 $js_script=sprintf("category_card.add_attribut('%s','%s','%s')",
194 $dossier_id, $this->table->frd_id, $objname);
195 echo Icon_Action::icon_add(uniqid(), $js_script);
196 }
197 echo \HtmlInput::hidden("attribut_order", "");
198 echo create_script("Sortable.create('{$objname}_list',{
199 onUpdate:function(){document.getElementById('attribut_order').value=Sortable.serialize('{$objname}_list')}})");
200 }
201
202 }
203
204 /**
205 * @brief When adding a template of category of card, the minimum is the name
206 * and the quickcode, which must be added into attr_min
207 */
209 {
210 $cn=Dossier::connect();
211 $frd_id=$this->get_table()->getp("frd_id");
212 $cn->exec_sql("insert into attr_min (frd_id,ad_id,ad_default_order) values ($1,$2,$3)",
214 $cn->exec_sql("insert into attr_min (frd_id,ad_id,ad_default_order) values ($1,$2,$3)",
215 [$frd_id, ATTR_DEF_QUICKCODE,10000]);
216 }
217
218 /**
219 * @brief save also the order
220 * @return void
221 */
222 function save()
223 {
224 parent::save();
225 $cn=$this->get_table()->get_cn();
226 $table_sql=$this->get_table();
227 $http=new HttpInput();
228 $ctl=$http->request("ctl")."_list";
229 $attribut_order=$http->post('attribut_order','string','');
230 if ($attribut_order=='') return;
231 parse_str($attribut_order,$aOrder);
232 if ( isset($aOrder[$ctl])) {
233 $order = 10;
234 foreach( $aOrder[$ctl] as $item) {
235 $ad_id = str_replace('elt','',$item);
236 $cn->exec_sql("update attr_min set ad_default_order = $1 where ad_id=$2 and frd_id=$3",
237 [$order,$ad_id,$table_sql->get('frd_id')]);
238 $order+=10;
239 }
240 }
241
242 }
243
244}
h2($p_string, $p_class="", $raw="")
Definition ac_common.php:68
hi($p_string)
Definition ac_common.php:48
echo_warning($p_string)
warns
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
_("actif, passif,charge,...")
ORM Manage the table public.fiche_def_ref , which concerns the template of category of card.
manage the http input (get , post, request) and extract from an array
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.
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
create_script($p_string)
create the HTML for adding the script tags around of the script