noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
itva_popup.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Html Input
24 */
25
26/**
27 * @brief let you choose a TVA in a popup
28 * @code
29 * $a=new IPopup('popup_tva');
30 * $a->set_title('Choix de la tva');
31 * echo $a->input();
32 * $tva=new ITva_Popup("tva1");
33 * $tva->with_button(true);
34 * // You must add the attributes gDossier, popup
35 * $tva->set_attribute('popup','popup_tva');
36 * $tva->set_attribute('gDossier',dossier::id());
37 *
38 * // We can add a label for the code
39 * $tva->add_label('code');
40 * $tva->js='onchange="set_tva_label(this);"';
41 * echo $tva->input();
42 * @endcode
43 */
44class ITva_Popup extends HtmlInput
45{
46 /**
47 * @brief by default, the p_name is the name/id of the input type
48 * the this->button is false (control if a button is visible) and
49 * this->in_table=false (return the widget inside a table)
50 * this->code is a span widget to display the code (in this case, you will
51 * to set this->cn as database connexion)
52 * to have its own javascript for the button you can use this->but_javascript)
53 * by default it is 'popup_select_tva(this)';
54 */
55 private $filter; //!< filter the VAT by ledger PURCHASE or SALE or NO FILTER, default=NO
56 static $vat_code=0; //<! 0 show the numeric ID or 1 for CODE
57
58 public function __construct($p_name = null, $p_value = "", $p_id = "")
59 {
60 $this->name = $p_name;
61 $this->button = true;
62 $this->in_table = false;
63 $this->value = $p_value;
64 $this->id = $p_id;
65 $this->filter = 'none';
66 }
67
68 function with_button($p)
69 {
70 if ($p == true)
71 $this->button = true;
72 else
73 $this->button = false;
74 }
75 protected function make_datalist()
76 {
77 $cn=Dossier::connect();
78 $r="";
79 switch ($this->filter) {
80 case 'none':
81 $sql="select tva_code,tva_label
82 from v_tva_rate
83 where
84 tva_purchase <> '#' and tva_sale <> '#'
85 order by tva_code ";
86 break;
87 case 'sale':
88 $sql="select tva_code,tva_label
89 from v_tva_rate
90 where
91 tva_sale <> '#'
92 order by tva_code ";
93 break;
94 case 'purchase':
95 $sql="select tva_code,tva_label
96 from v_tva_rate
97 where
98 tva_purchase <> '#'
99 order by tva_code ";
100 break;
101 }
102 $a_tva_code=$cn->get_array($sql);
103 if ( empty($a_tva_code)) return "";
104 $r.=sprintf('<datalist id="dl_tva_%s"">',$this->id);
105 foreach ($a_tva_code as $item) {
106 $r.=sprintf('<option value="%s">%s %s</option>'
107 ,$item['tva_code'],$item['tva_code']
108 ,htmlentities($item['tva_label']));
109 }
110 $r.='</datalist>';
111 return $r;
112
113 }
114 /*!
115 \brief show the html input of the widget
116 */
117 public function input($p_name = null, $p_value = null)
118 {
119 $this->name = ($p_name == null) ? $this->name : $p_name;
120 $this->value = ($p_value == null) ? $this->value : $p_value;
121 $this->js = (isset($this->js)) ? $this->js : '';
122 $this->id = ($this->id == "") ? $this->name : $this->id;
123 if ($this->readOnly == true) return $this->display();
124
125 $this->set_attribute('gDossier', dossier::id());
126 $this->set_attribute('ctl', $this->name);
127
128 $code="";
129
130 // code is a span containing the label of the VAT (see add_label)
131 if (isset($this->code)) {
132 if ($this->cn != NULL) {
133 $cnx=Dossier::connect();
134 /* check if tva_id == integer */
135 if (trim($this->value) != '' && isNumber($this->value) == 1 && strpos($this->value, ',') === false)
136 $this->code->value = $cnx->get_value('select tva_label from tva_rate where tva_id=$1',
137 array($this->value));;
138 }
139 $this->set_attribute('jcode', $this->code->name);
140 $code = $this->code->input();
141
142 }
143 $strAttribut = $this->get_node_attribute();
144 // show tva code
145 if ( self::$vat_code == 1) {
146 if ( isNumber($this->value ) == 1) {
147 $cnx=Dossier::connect();
148 $this->value=$cnx->get_value('select tva_code from tva_rate where tva_id=$1',[$this->value]);
149 }
150 }
151
152 $str = '<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" placeholder="%s" size="6" %s %s
153list="dl_tva_%s" autocomplete="off">';
154 $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut,$this->id);
155 $r.=$code;
156
157 if ($this->in_table)
158 $table = '<table>' . '<tr>' . td($r);
159
160 if ($this->button == true && !$this->in_table)
161 $r .= $this->dbutton();
162
163 if ($this->button == true && $this->in_table)
164 $r = $table . td($this->dbutton()) . '</tr></table>';
165
166 if ($this->table == 1) $r = td($r);
167 $r.=$this->make_datalist();
168 return $r;
169
170 }
171
172 /**
173 *@brief Set a filter to limit the choice of VAT ;
174 * possible values are :
175 * - sale if there is an accounting for sale
176 * - purchase if there is an accounting for purchase
177 * - none : show VAT
178 *
179 */
181 {
182 $this->filter = $p_filter;
183 }
184
185 /**
186 * @brief show a button, if it is pushed show a popup to select the need vat
187 * @note
188 * - a ipopup must be created before with the name popup_tva
189 * - the javascript noalyss_script.js must be loaded
190 * @return string with html code
191 */
192 function dbutton()
193 {
194 if (trim($this->name) == '') throw new Exception (_('Le nom ne peut ĂȘtre vide'));
195 $this->id = ($this->id == "") ? $this->name : $this->id;
196
197 // button
198 $bt = new ISmallButton('bt_' . $this->id);
199 $bt->tabindex = "-1";
200 $bt->label = ICON_SEARCH;
201
202 $bt->set_attribute('gDossier', dossier::id());
203 $bt->set_attribute('ctl', $this->id);
204 $bt->set_attribute('popup', 'popup_tva');
205 if (isset($this->code))
206 $bt->set_attribute('jcode', $this->code->name);
207 if (isset($this->compute))
208 $bt->set_attribute('compute', $this->compute);
209 $bt->set_attribute("filter", $this->filter);
210 $bt->javascript = (isset($this->but_javascript)) ? $this->but_javascript : 'popup_select_tva(this)';
211 $r = $bt->input();
212 return $r;
213 }
214
215 /*!\brief print in html the readonly value of the widget*/
216 public function display()
217 {
218 $cn = Dossier::connect();
219 $tva = Acc_Tva::build($cn, $this->value);
220
221 $comment = ($tva->load() != "-1") ? $tva->tva_label : "";
222 $res = sprintf('<input type="text" name="%s" size="6" class="input_text_ro" value="%s" id="%s" readonly="">%s', $this->name, $this->value, $this->name, $comment);
223 return $res;
224 }
225
226 /**
227 * @brief add a field to show the selected tva's label
228 * @param $p_code is the name of the label where you can see the label of VAT
229 * @param $p_cn is a database connection if NULL it doesn't seek in the database
230 */
231 public function add_label($p_code, $p_cn = null)
232 {
233 $this->cn = $p_cn;
234 $this->code = new ISpan($p_code);
235 }
236
237 /**
238 * @brief show the Numeric ID or the code
239 * @param int $vat_code 0 for numeric , 1 for Code
240 * @return void
241 * @throws Exception if $vat_code is
242 */
243 static function set_vat_code(int $vat_code)
244 {
245 if (isNumber($vat_code)==0){
246 throw new Exception("VAT_CODE [{$vat_code}]: invalide data",EXC_INVALID);
247 }
248 self::$vat_code= $vat_code;
249 }
250 static public function test_me()
251 {
252
253 $tva = new ITva_Popup("tva1");
254 $tva->with_button(true);
255 // We can add a label for the code
256 $tva->add_label('code');
257 $tva->js = 'onchange="set_tva_label(this);"';
258 echo $tva->input();
259
260 echo '<hr>';
261 echo $tva->dbutton();
262
263 }
264
265}
isNumber($p_int)
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$input_from cn
$from_poste name
_("actif, passif,charge,...")
$p
Definition calendar.php:9
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
set_attribute($p_name, $p_value)
add an HTML attribute for the INPUT field
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
get_node_attribute()
Insert attribute inside a INPUT TYPE, these attribute can be retrieved in javascript with element....
Html Input.
let you choose a TVA in a popup
add_label($p_code, $p_cn=null)
add a field to show the selected tva's label
static set_vat_code(int $vat_code)
show the Numeric ID or the code
display()
print in html the readonly value of the widget
dbutton()
show a button, if it is pushed show a popup to select the need vat
__construct($p_name=null, $p_value="", $p_id="")
input($p_name=null, $p_value=null)
show the html input of the widget
$filter
by default, the p_name is the name/id of the input type the this->button is false (control if a butto...
set_filter($p_filter)
Set a filter to limit the choice of VAT ; possible values are :
$all table
const EXC_INVALID
Definition constant.php:346
const ICON_SEARCH
Definition constant.php:103
$str
Definition fiche.inc.php:91
$icard readOnly