diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 8fc311ea7..6c17d1e4c 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -128,7 +128,11 @@ EOF; for ($i=0;$i<$Max;$i++) { $row=Database::fetch_array($Res,$i); - $script="onclick=\"$('$ctl').value='".$row['tva_id']."';hideIPopup('".$popup."');\""; + if ( ! isset($code)) { + $script="onclick=\"$('$ctl').value='".$row['tva_id']."';hideIPopup('".$popup."');\""; + } else { + $script="onclick=\"$('$ctl').value='".$row['tva_id']."';set_value('$code','".$row['tva_label']."');hideIPopup('".$popup."');\""; + } $set= ''; $r.=''; $r.=td($set); @@ -141,7 +145,7 @@ EOF; $r.=''; $r.=''; $html=escape_xml($r); - + header('Content-type: text/xml; charset=UTF-8'); echo << @@ -149,6 +153,26 @@ echo <<$html $popup +EOF; +break; + case 'label_tva': + $cn=new Database($gDossier); + if ( isNumber($id) == 0 ) + $value = _('tva inconnue'); + else { + $Res=$cn->get_array("select * from tva_rate where tva_id = $1",array($id)); + if ( count($Res) == 0 ) + $value=_('tva inconnue'); + else + $value=$Res[0]['tva_label']; + } +header('Content-type: text/xml; charset=UTF-8'); +echo << + +$code +$value + EOF; break; diff --git a/html/compute.php b/html/compute.php index 2bb2b8afc..4eab32ee0 100644 --- a/html/compute.php +++ b/html/compute.php @@ -49,20 +49,16 @@ foreach (array('t','c','p','q','n','gDossier') as $a) { $cn=new Database(dossier::id()); $User=new User($cn); $User->Check(); - -/** - *@todo check with my_own if the vat must be computed instead of - *a special value - */ // Retrieve the rate of vat, it $t == -1 it means no VAT if ( $t != -1 ){ $tva_rate=new Acc_Tva($cn); $tva_rate->set_parameter('id',$t); /** - *@todo if the tva_rate->load failed we have to return an - *error message "invalid tva" + *if the tva_rate->load failed we don't compute tva */ - $tva_rate->load(); + if ( $tva_rate->load() != 0 ) { + $tva_rate->set_parameter('rate',0); + } } $total=new Acc_Compute(); diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index c152ea9f5..aeb0513ac 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -190,6 +190,7 @@ function compute_ledger(p_ctl_nb) { var tva_id=-1; if ( g('e_march'+p_ctl_nb+'_tva_id') ) { tva_id=g('e_march'+p_ctl_nb+'_tva_id').value; + if ( trim(tva_id) == '') {tva_id=-1;} } g('e_march'+p_ctl_nb+'_price').value=trim(g('e_march'+p_ctl_nb+'_price').value); diff --git a/html/js/scripts.js b/html/js/scripts.js index b976b9363..0e00d243d 100644 --- a/html/js/scripts.js +++ b/html/js/scripts.js @@ -285,6 +285,8 @@ function popup_select_tva(obj) { try { showIPopup(obj.popup); var queryString="PHPSESSID="+obj.phpsessid+"&gDossier="+obj.gDossier+"&op=dsp_tva"+"&ctl="+obj.ctl+'&popup='+obj.popup; + if ( obj.jcode ) + queryString+='&code='+obj.jcode; var action = new Ajax.Request( "ajax_misc.php" , { method:'get', @@ -312,4 +314,40 @@ function success_popup_select_tva(req) { $(name_ctl).innerHTML=code_html; } catch (e) {alert(e.message);} +} +/** + *@brief display the popup with vat and explanation + *@param obj with 4 attributes gdossier, ctl,popup and phpsessid + */ +function set_tva_label(obj) { + try { + var queryString="PHPSESSID="+obj.phpsessid+"&gDossier="+obj.gDossier+"&op=label_tva"+"&id="+obj.value; + if ( obj.jcode ) + queryString+='&code='+obj.jcode; + var action = new Ajax.Request( + "ajax_misc.php" , + { method:'get', + parameters:queryString, + onFailure:ajax_misc_failure, + onSuccess:success_set_tva_label + } + ); + } catch (e) {alert(e.message);} +} +/** + *@brief display the popup with vat and explanations + */ +function success_set_tva_label(req) { + try { + var answer=req.responseXML; + var code=answer.getElementsByTagName('code'); + var value=answer.getElementsByTagName('value'); + + if ( code.length == 0 ) { var rec=req.responseText;alert ('erreur :'+rec);} + + var label_code=code[0].firstChild.nodeValue; + var label_value=value[0].firstChild.nodeValue; + set_value(label_code,label_value); + } catch (e) {alert(e.message);} + } \ No newline at end of file diff --git a/html/show_tva.php b/html/show_tva.php index 9be7a10fc..b7dd0fd81 100644 --- a/html/show_tva.php +++ b/html/show_tva.php @@ -51,7 +51,7 @@ for ($i=0;$i<$Max;$i++) { $row=Database::fetch_array($Res,$i); $set=sprintf( '', $_GET['ctl'],$row['tva_id']); - printf("%s %d%s%s", + printf("%s %d%s%s", $set, $row['tva_id'], $row['tva_label'], diff --git a/include/class_fiche.php b/include/class_fiche.php index c0557108c..b02a3641f 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -586,6 +586,7 @@ Array // Verify if the rate exists, if not then do not update if ( strlen(trim($value)) != 0 ) { + if ( isNumber($value) == 0 ) continue; if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0) { echo_debug("class_fiche",__LINE__,"Tva invalide $value"); diff --git a/include/class_itva_popup.php b/include/class_itva_popup.php index e4d2d8ec8..f34404e16 100644 --- a/include/class_itva_popup.php +++ b/include/class_itva_popup.php @@ -25,24 +25,53 @@ */ require_once ('class_ipopup.php'); require_once('class_ibutton.php'); - +require_once('class_ispan.php'); +/** + *@brief let you choose a TVA in a popup + *@code + $a=new IPopup('popup_tva'); + $a->set_title('Choix de la tva'); + echo $a->input(); + $tva=new ITva_Popup("tva1"); + $tva->with_button(true); + // 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 { public function __construct($p_name=null) { $this->name=$p_name; + $this->button=true; + } + function with_button($p) { + if ($p == true ) + $this->button=true; + else + $this->button=false; } - /*!\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($p_js))?$this->js:""; + $this->js=(isset($this->js))?$this->js:""; if ( $this->readOnly==true) return $this->display(); $str=''; $r=sprintf($str,$this->name,$this->value,$this->name,$this->js); + if ( $this->button==true) + $r.=$this->dbutton(); + if ( isset($this->code)){ + $r.=$this->code->input(); + $this->set_attribute('jcode',$this->code->name); + $this->set_attribute('gDossier',dossier::id()); + $this->set_attribute('ctl',$this->name); + $r.=$this->get_js_attr(); + } return $r; } @@ -61,9 +90,13 @@ require_once('class_ibutton.php'); $bt->set_attribute('gDossier',dossier::id()); $bt->set_attribute('ctl',$this->name); $bt->set_attribute('popup','popup_tva'); + if ( isset($this->code)) + $bt->set_attribute('jcode',$this->code->name); $bt->javascript='popup_select_tva(this)'; - return $bt->input(); + $r=$bt->input(); + return $r; } + /*!\brief print in html the readonly value of the widget*/ public function display() { @@ -71,12 +104,19 @@ require_once('class_ibutton.php'); $res=sprinf($r,$this->name,$this->value,$this->name); return $res; } + public function add_label($p_code) { + $this->code=new ISpan($p_code); + } static public function test_me() { $a=new IPopup('popup_tva'); $a->set_title('Choix de la tva'); echo $a->input(); $tva=new ITva_Popup("tva1"); + $tva->with_button(true); + // We can add a label for the code + $tva->add_label('code'); + $tva->js='onchange="set_tva_label(this);"'; echo $tva->input(); echo $tva->dbutton(); } diff --git a/include/quick_writing.inc.php b/include/quick_writing.inc.php index 454013123..b6f80d787 100644 --- a/include/quick_writing.inc.php +++ b/include/quick_writing.inc.php @@ -132,6 +132,7 @@ $ledger=new Acc_Ledger($cn,$id); $ledger->with_concerned=true; // no ledger selected, propose one +// Only ODS if ($id == -1 ) { echo '
'; @@ -140,7 +141,7 @@ if ($id == -1 ) echo '
'; echo dossier::hidden(); echo HtmlInput::hidden('p_action',$_REQUEST['p_action']); - echo $ledger->select_ledger()->input(); + echo $ledger->select_ledger('ODS',3)->input(); echo HtmlInput::submit('show_form',_('Choix du journal')); echo '
'; echo '
';