noalyss Version-10
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 if ($p_id =="") $p_id= uniqid ("vat");
65 $this->id = $p_id;
66 $this->filter = 'none';
67 }
68
69 function with_button($p)
70 {
71 if ($p == true)
72 $this->button = true;
73 else
74 $this->button = false;
75 }
76 protected function make_datalist()
77 {
78 $cn=Dossier::connect();
79 $r="";
80 switch ($this->filter) {
81 case 'none':
82 $sql="select tva_code,tva_label
83 from v_tva_rate
84 where
85 tva_purchase <> '#' and tva_sale <> '#'
86 order by tva_code ";
87 break;
88 case 'sale':
89 $sql="select tva_code,tva_label
90 from v_tva_rate
91 where
92 tva_sale <> '#'
93 order by tva_code ";
94 break;
95 case 'purchase':
96 $sql="select tva_code,tva_label
97 from v_tva_rate
98 where
99 tva_purchase <> '#'
100 order by tva_code ";
101 break;
102 }
103 $a_tva_code=$cn->get_array($sql);
104 if ( empty($a_tva_code)) return "";
105 $r.=sprintf('<datalist id="dl_tva_%s"">',$this->id);
106 foreach ($a_tva_code as $item) {
107 $r.=sprintf('<option value="%s">%s %s</option>'
108 ,$item['tva_code'],$item['tva_code']
109 ,htmlentities($item['tva_label']));
110 }
111 $r.='</datalist>';
112 return $r;
113
114 }
115 /*!
116 \brief show the html input of the widget
117 */
118 public function input($p_name = null, $p_value = null)
119 {
120 $this->name = ($p_name == null) ? $this->name : $p_name;
121 $this->value = ($p_value == null) ? $this->value : $p_value;
122 $this->js = (isset($this->js)) ? $this->js : '';
123 $this->id = ($this->id == "") ? $this->name : $this->id;
124 if ($this->readOnly == true) return $this->display();
125
126 $this->set_attribute('gDossier', dossier::id());
127 $this->set_attribute('ctl', $this->name);
128
129 $code="";
130
131 // code is a span containing the label of the VAT (see add_label)
132 if (isset($this->code)) {
133 if ($this->cn != NULL) {
134 $cnx=Dossier::connect();
135 /* check if tva_id == integer */
136 if (trim($this->value) != '' && isNumber($this->value) == 1 && strpos($this->value, ',') === false)
137 $this->code->value = $cnx->get_value('select tva_label from tva_rate where tva_id=$1',
138 array($this->value));;
139 }
140 $this->set_attribute('jcode', $this->code->name);
141 $code = $this->code->input();
142
143 }
144 $get_attribute = $this->get_node_attribute();
145 // show tva code
146 if ( self::$vat_code == 1) {
147 if ( isNumber($this->value ) == 1) {
148 $cnx=Dossier::connect();
149 $this->value=$cnx->get_value('select tva_code from tva_rate where tva_id=$1',[$this->value]);
150 }
151 }
152
153 $str = '<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" placeholder="%s" size="6" %s %s
154list="dl_tva_%s" autocomplete="off">';
155 $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $get_attribute,$this->id);
156 $r.=$code;
157
158 if ($this->in_table)
159 $table = '<table>' . '<tr>' . td($r);
160
161 if ($this->button == true && !$this->in_table)
162 $r .= $this->dbutton();
163
164 if ($this->button == true && $this->in_table)
165 $r = $table . td($this->dbutton()) . '</tr></table>';
166
167 if ($this->table == 1) $r = td($r);
168 $r.=$this->make_datalist();
169 return $r;
170
171 }
172
173 /**
174 *@brief Set a filter to limit the choice of VAT ;
175 * possible values are :
176 * - sale if there is an accounting for sale
177 * - purchase if there is an accounting for purchase
178 * - none : show VAT
179 *
180 */
182 {
183 $this->filter = $p_filter;
184 }
185
186 /**
187 * @brief show a button, if it is pushed show a popup to select the need vat
188 * @note
189 * - a ipopup must be created before with the name popup_tva
190 * - the javascript noalyss_script.js must be loaded
191 * @return string with html code
192 */
193 function dbutton()
194 {
195 if (trim($this->name) == '') throw new Exception (_('Le nom ne peut ĂȘtre vide'));
196 $this->id = ($this->id == "") ? $this->name : $this->id;
197
198 // button
199 $bt = new ISmallButton('bt_' . $this->id);
200 $bt->tabindex = "-1";
201 $bt->label = ICON_SEARCH;
202
203 $bt->set_attribute('gDossier', dossier::id());
204 $bt->set_attribute('ctl', $this->id);
205 $bt->set_attribute('popup', 'popup_tva');
206 if (isset($this->code))
207 $bt->set_attribute('jcode', $this->code->name);
208 if (isset($this->compute))
209 $bt->set_attribute('compute', $this->compute);
210 $bt->set_attribute("filter", $this->filter);
211 $bt->javascript = (isset($this->but_javascript)) ? $this->but_javascript : 'popup_select_tva(this)';
212 $r = $bt->input();
213 return $r;
214 }
215
216 /*!\brief print in html the readonly value of the widget*/
217 public function display()
218 {
219 $cn = Dossier::connect();
220 $tva = Acc_Tva::build($cn, $this->value);
221
222 $comment = ($tva->load() != "-1") ? $tva->tva_label : "";
223 $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);
224 return $res;
225 }
226
227 /**
228 * @brief add a field to show the selected tva's label
229 * @param $p_code is the name of the label where you can see the label of VAT
230 * @param $p_cn is a database connection if NULL it doesn't seek in the database
231 */
232 public function add_label($p_code, $p_cn = null)
233 {
234 $this->cn = $p_cn;
235 $this->code = new ISpan($p_code);
236 }
237
238 /**
239 * @brief show the Numeric ID or the code
240 * @param int $vat_code 0 for numeric , 1 for Code
241 * @return void
242 * @throws Exception if $vat_code is
243 */
244 static function set_vat_code(int $vat_code)
245 {
246 if (isNumber($vat_code)==0){
247 throw new Exception("VAT_CODE [{$vat_code}]: invalide data",EXC_INVALID);
248 }
249 self::$vat_code= $vat_code;
250 }
251 static public function test_me()
252 {
253
254 $tva = new ITva_Popup("tva1");
255 $tva->with_button(true);
256 // We can add a label for the code
257 $tva->add_label('code');
258 $tva->js = 'onchange="set_tva_label(this);"';
259 echo $tva->input();
260
261 echo '<hr>';
262 echo $tva->dbutton();
263
264 }
265
266}
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:358
const ICON_SEARCH
Definition constant.php:108
$icard readOnly