noalyss Version-9
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
57 public function __construct($p_name = null, $p_value = "", $p_id = "")
58 {
59 $this->name = $p_name;
60 $this->button = true;
61 $this->in_table = false;
62 $this->value = $p_value;
63 $this->id = $p_id;
64 $this->filter = 'none';
65 }
66
67 function with_button($p)
68 {
69 if ($p == true)
70 $this->button = true;
71 else
72 $this->button = false;
73 }
74
75 /*!\brief show the html input of the widget*/
76 public function input($p_name = null, $p_value = null)
77 {
78 $this->name = ($p_name == null) ? $this->name : $p_name;
79 $this->value = ($p_value == null) ? $this->value : $p_value;
80 $this->js = (isset($this->js)) ? $this->js : '';
81 $this->id = ($this->id == "") ? $this->name : $this->id;
82 if ($this->readOnly == true) return $this->display();
83
84 $this->set_attribute('gDossier', dossier::id());
85 $this->set_attribute('ctl', $this->name);
86
87 $code="";
88
89 // code is a span containing the label of the VAT (see add_label)
90 if (isset($this->code)) {
91 if ($this->cn != NULL) {
92 /* check if tva_id == integer */
93 if (trim($this->value) != '' && isNumber($this->value) == 1 && strpos($this->value, ',') === false)
94 $this->code->value = $this->cn->get_value('select tva_label from tva_rate where tva_id=$1',
95 array($this->value));;
96 }
97 $this->set_attribute('jcode', $this->code->name);
98 $code = $this->code->input();
99
100 }
101 $strAttribut = $this->get_node_attribute();
102
103
104 $str = '<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" placeholder="%s" size="3" %s %s>';
105 $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut);
106 $r.=$code;
107 if ($this->in_table)
108 $table = '<table>' . '<tr>' . td($r);
109
110 if ($this->button == true && !$this->in_table)
111 $r .= $this->dbutton();
112
113 if ($this->button == true && $this->in_table)
114 $r = $table . td($this->dbutton()) . '</tr></table>';
115
116 if ($this->table == 1) $r = td($r);
117 return $r;
118
119 }
120
121 /**
122 * Set a filter to limit the choice of VAT ;
123 * possible values are :
124 * - sale if there is an accounting for sale
125 * - purchase if there is an accounting for purchase
126 * - none : show VAT
127 *
128 */
130 {
131 $this->filter = $p_filter;
132 }
133
134 /**
135 * @brief show a button, if it is pushed show a popup to select the need vat
136 * @note
137 * - a ipopup must be created before with the name popup_tva
138 * - the javascript noalyss_script.js must be loaded
139 * @return string with html code
140 */
141 function dbutton()
142 {
143 if (trim($this->name) == '') throw new Exception (_('Le nom ne peut ĂȘtre vide'));
144 $this->id = ($this->id == "") ? $this->name : $this->id;
145
146 // button
147 $bt = new ISmallButton('bt_' . $this->id);
148 $bt->tabindex = "-1";
149 $bt->label = _(' TVA ');
150 $bt->set_attribute('gDossier', dossier::id());
151 $bt->set_attribute('ctl', $this->id);
152 $bt->set_attribute('popup', 'popup_tva');
153 if (isset($this->code))
154 $bt->set_attribute('jcode', $this->code->name);
155 if (isset($this->compute))
156 $bt->set_attribute('compute', $this->compute);
157 $bt->set_attribute("filter", $this->filter);
158 $bt->javascript = (isset($this->but_javascript)) ? $this->but_javascript : 'popup_select_tva(this)';
159 $r = $bt->input();
160 return $r;
161 }
162
163 /*!\brief print in html the readonly value of the widget*/
164 public function display()
165 {
167 $tva = new Acc_Tva($cn, $this->value);
168
169 $comment = ($tva->load() != "-1") ? $tva->tva_label : "";
170 $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);
171 return $res;
172 }
173
174 /**
175 * @brief add a field to show the selected tva's label
176 * @param $p_code is the name of the label where you can see the label of VAT
177 * @param $p_cn is a database connection if NULL it doesn't seek in the database
178 */
179 public function add_label($p_code, $p_cn = null)
180 {
181 $this->cn = $p_cn;
182 $this->code = new ISpan($p_code);
183 }
184
185 static public function test_me()
186 {
187 $a = new IPopup('popup_tva');
188 $a->set_title('Choix de la tva');
189 echo $a->input();
190 $tva = new ITva_Popup("tva1");
191 $tva->with_button(true);
192 // We can add a label for the code
193 $tva->add_label('code');
194 $tva->js = 'onchange="set_tva_label(this);"';
195 echo $tva->input();
196 echo $tva->dbutton();
197 }
198}
isNumber($p_int)
Definition: ac_common.php:215
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
$code
$p
Definition: array.php:34
$input_from cn
Definition: balance.inc.php:66
$from_poste name
$input_from id
Definition: balance.inc.php:63
Acc_Tva is used for to map the table tva_rate parameter are.
static connect()
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
set_attribute($p_name, $p_value)
set the extra javascript property 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....
create a popup in html above the current layer the html inside the popup cannot contain any floating ...
Html Input.
Definition: ispan.class.php:32
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 test_me()
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
$str
Definition: fiche.inc.php:91
$icard readOnly