set_title('Choix de la tva'); * echo $a->input(); * $tva=new ITva_Popup("tva1"); * $tva->with_button(true); * // You must add the attributes gDossier, popup * $tva->set_attribute('popup','popup_tva'); * $tva->set_attribute('gDossier',dossier::id()); * * // We can add a label for the code * $tva->add_label('code'); * $tva->js='onchange="set_tva_label(this);"'; * echo $tva->input(); * @endcode */ class ITva_Popup extends HtmlInput { /** * @brief by default, the p_name is the name/id of the input type * the this->button is false (control if a button is visible) and * this->in_table=false (return the widget inside a table) * this->code is a span widget to display the code (in this case, you will * to set this->cn as database connexion) * to have its own javascript for the button you can use this->but_javascript) * by default it is 'popup_select_tva(this)'; */ private $filter; //!< filter the VAT by ledger PURCHASE or SALE or NO FILTER, default=NO static $vat_code=0; //name = $p_name; $this->button = true; $this->in_table = false; $this->value = $p_value; if ($p_id =="") $p_id= uniqid ("vat"); $this->id = $p_id; $this->filter = 'none'; } function with_button($p) { if ($p == true) $this->button = true; else $this->button = false; } protected function make_datalist() { $cn=Dossier::connect(); $r=""; switch ($this->filter) { case 'none': $sql="select tva_code,tva_label from v_tva_rate where tva_purchase <> '#' and tva_sale <> '#' order by tva_code "; break; case 'sale': $sql="select tva_code,tva_label from v_tva_rate where tva_sale <> '#' order by tva_code "; break; case 'purchase': $sql="select tva_code,tva_label from v_tva_rate where tva_purchase <> '#' order by tva_code "; break; } $a_tva_code=$cn->get_array($sql); if ( empty($a_tva_code)) return ""; $r.=sprintf(''; return $r; } /*! \brief show the html input of the widget */ public function input($p_name = null, $p_value = null) { $this->name = ($p_name == null) ? $this->name : $p_name; $this->value = ($p_value == null) ? $this->value : $p_value; $this->js = (isset($this->js)) ? $this->js : ''; $this->id = ($this->id == "") ? $this->name : $this->id; if ($this->readOnly == true) return $this->display(); $this->set_attribute('gDossier', dossier::id()); $this->set_attribute('ctl', $this->name); $code=""; // code is a span containing the label of the VAT (see add_label) if (isset($this->code)) { if ($this->cn != NULL) { $cnx=Dossier::connect(); /* check if tva_id == integer */ if (trim($this->value) != '' && isNumber($this->value) == 1 && strpos($this->value, ',') === false) $this->code->value = $cnx->get_value('select tva_label from tva_rate where tva_id=$1', array($this->value));; } $this->set_attribute('jcode', $this->code->name); $code = $this->code->input(); } $get_attribute = $this->get_node_attribute(); // show tva code if ( self::$vat_code == 1) { if ( isNumber($this->value ) == 1) { $cnx=Dossier::connect(); $this->value=$cnx->get_value('select tva_code from tva_rate where tva_id=$1',[$this->value]); } } $str = ''; $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $get_attribute,$this->id); $r.=$code; if ($this->in_table) $table = '