diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 6c17d1e4c..2fdcc3500 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -26,6 +26,11 @@
* - PHPSESSID
* - gDossier
* - $op operation the file has to execute
+ * Part 1
+ * dsp_tva fill a ipopup with a choice of possible VAT
+ * - if code is set then fill the field code
+ * - if compute is set then add event to call clean_tva and compute_ledger
+@Acc_Ledger_Sold::input
*
*/
require_once('class_database.php');
@@ -128,11 +133,20 @@ EOF;
for ($i=0;$i<$Max;$i++) {
$row=Database::fetch_array($Res,$i);
- 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."');\"";
- }
+ if ( ! isset($compute)) {
+ 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."');\"";
+ }
+ } else {
+ if ( ! isset($code) ) {
+ $script="onclick=\"$('$ctl').value='".$row['tva_id']."';hideIPopup('".$popup."');clean_tva('$compute');compute_ledger('$compute');\"";
+ } else {
+ $script="onclick=\"$('$ctl').value='".$row['tva_id']."';set_value('$code','".$row['tva_label']."');hideIPopup('".$popup."');clean_tva('$compute');compute_ledger('$compute');\"";
+ }
+
+ }
$set= '';
$r.='
';
$r.=td($set);
diff --git a/html/compta.php b/html/compta.php
index 1fcf2fb60..3daac5daa 100644
--- a/html/compta.php
+++ b/html/compta.php
@@ -87,6 +87,8 @@ if ( $action == 'ach' ||
if ( $action == 'fin') {
require_once ('compta_fin.inc.php');
}
-
+if ($action == 'let') {
+ require_once('letter.inc.php');
+}
html_page_stop();
?>
diff --git a/html/compute.php b/html/compute.php
index 4eab32ee0..fadc75f89 100644
--- a/html/compute.php
+++ b/html/compute.php
@@ -50,7 +50,7 @@ $cn=new Database(dossier::id());
$User=new User($cn);
$User->Check();
// Retrieve the rate of vat, it $t == -1 it means no VAT
-if ( $t != -1 ){
+if ( $t != -1 && isNumber($t) == 1 ){
$tva_rate=new Acc_Tva($cn);
$tva_rate->set_parameter('id',$t);
/**
@@ -65,7 +65,7 @@ $total=new Acc_Compute();
bcscale(4);
$amount=round(bcmul($p,$q),2);
$total->set_parameter('amount',$amount);
-if ( $t != -1 ) {
+if ( $t != -1 && isNumber($t) == 1 ) {
$total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate'));
$total->compute_vat();
$tvac=bcadd($total->get_parameter('amount_vat'),$amount);
diff --git a/html/js/scripts.js b/html/js/scripts.js
index ae4a51b4a..2fd888f3e 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -299,6 +299,8 @@ function popup_select_tva(obj) {
var queryString="PHPSESSID="+obj.phpsessid+"&gDossier="+obj.gDossier+"&op=dsp_tva"+"&ctl="+obj.ctl+'&popup='+obj.popup;
if ( obj.jcode )
queryString+='&code='+obj.jcode;
+ if (obj.compute)
+ queryString+='&compute='+obj.compute;
var action = new Ajax.Request(
"ajax_misc.php" ,
{ method:'get',
diff --git a/include/action.common.inc.php b/include/action.common.inc.php
index cfcdb6588..a86986147 100644
--- a/include/action.common.inc.php
+++ b/include/action.common.inc.php
@@ -30,6 +30,11 @@
*
*/
echo js_include('gestion.js');
+require_once('class_itva_popup.php');
+$pop_tva=new IPopup('popup_tva');
+$pop_tva->title=_('Choix TVA');
+$pop_tva->value='';
+echo $pop_tva->input();
$supl_hidden='';
if( isset($_REQUEST['sc']))
diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php
index 7e1da9de1..e1f7d5b28 100644
--- a/include/class_acc_ledger_purchase.php
+++ b/include/class_acc_ledger_purchase.php
@@ -38,6 +38,8 @@ require_once('user_common.php');
require_once('class_acc_parm_code.php');
require_once('class_acc_payment.php');
require_once('ac_common.php');
+require_once('class_itva_popup.php');
+
/*!\brief Handle the ledger of purchase,
*
*
@@ -156,6 +158,15 @@ class Acc_Ledger_Purchase extends Acc_Ledger {
if ( isNumber(${'e_quant'.$i}) == 0 )
throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
+ // Check if the given tva id is valid
+ if ( isNumber(${'e_march'.$i.'_tva_id'}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ $tva_rate=new Acc_Tva($this->db);
+ $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
+
+ if ( $tva_rate->load() != 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+
/* check if all card has a ATTR_DEF_ACCOUNT*/
$fiche=new fiche($this->db);
$fiche->get_by_qcode(${'e_march'.$i});
@@ -186,6 +197,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger {
}
if ( $nb == 0 )
throw new Exception(_('Il n\'y a aucune marchandise'),12);
+
}
public function save($p_array) {
@@ -928,9 +940,11 @@ class Acc_Ledger_Purchase extends Acc_Ledger {
// vat label
//--
- $Tva=new ITva_Select($this->db);
- $Tva->javascript="onChange=clean_tva($i);compute_ledger($i)";
- $Tva->selected=$march_tva_id;
+ $Tva=new ITva_Popup($this->db);
+ $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
+ $Tva->in_table=true;
+ $Tva->set_attribute('compute',$i);
+ $Tva->value=$march_tva_id;
$array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
// Tva_amount
diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php
index 498e5f22a..ee21b659b 100644
--- a/include/class_acc_ledger_sold.php
+++ b/include/class_acc_ledger_sold.php
@@ -38,6 +38,7 @@ require_once('user_common.php');
require_once('class_acc_payment.php');
require_once('ac_common.php');
require_once('class_own.php');
+require_once('class_itva_popup.php');
/*!\brief Handle the ledger of sold,
*
@@ -150,10 +151,20 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$fiche->get_by_qcode(${'e_march'.$i});
if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
+
+ // Check if the given tva id is valid
+ if ( isNumber(${'e_march'.$i.'_tva_id'}) == 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+ $tva_rate=new Acc_Tva($this->db);
+ $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
+
+ if ( $tva_rate->load() != 0 )
+ throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+
+ // if 2 accounts, take only the credit one
/* The account exists */
$sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
- // if 2 accounts, take only the credit one
if ( strpos($sposte,',') != 0 ) {
$array=explode(',',$sposte);
$poste_val=$array[1];
@@ -559,8 +570,9 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$r.="
"._('Code')."
";
$r.="
"._('Dénomination')."
";
$r.="
"._('prix')."
";
- $r.="
"._('tva')."
";
$r.="
"._('quantité')."
";
+ $r.="
"._('tva')."
";
+
if ( $own->MY_TVA_USE=='Y') {
$r.='
'._('Montant TVA').'
';
@@ -1068,9 +1080,12 @@ class Acc_Ledger_Sold extends Acc_Ledger {
if ( $flag_tva == 'Y' ) {
// vat label
//--
- $Tva=new ITva_Select($this->db);
- $Tva->javascript="onChange=clean_tva($i);compute_ledger($i)";
- $Tva->selected=$march_tva_id;
+ $Tva=new ITva_Popup($this->db);
+ $Tva->in_table=true;
+ $Tva->set_attribute('compute',$i);
+
+ $Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $Tva->value=$march_tva_id;
$array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
// vat amount
//--
diff --git a/include/class_action.php b/include/class_action.php
index d7efab9e6..d5223eceb 100644
--- a/include/class_action.php
+++ b/include/class_action.php
@@ -401,7 +401,8 @@ class Action
$num=new INum();
/* TVA */
- $itva=new ITva_Select($this->db);
+ $itva=new ITva_Popup($this->db);
+ $itva->in_table=true;
/* create aArticle for the detail section */
for ($i=0;$i< MAX_ARTICLE;$i++) {
@@ -453,7 +454,9 @@ class Action
$itva->name='e_march'.$i.'_tva_id';
$itva->value=($tmp_ad)?$tmp_ad->get_parameter('tva_id'):0;
- $itva->javascript=' onchange="clean_tva('.$i.');compute_ledger('.$i.')"';
+ $itva->javascript=' onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+ $itva->set_attribute('compute',$i);
+
$aArticle[$i]['tvaid']=$itva->input();
$num->name="e_march".$i."_tva_amount";
diff --git a/include/class_itva_popup.php b/include/class_itva_popup.php
index 601a6b59b..9dd565cfa 100644
--- a/include/class_itva_popup.php
+++ b/include/class_itva_popup.php
@@ -34,6 +34,11 @@ require_once('class_ispan.php');
echo $a->input();
$tva=new ITva_Popup("tva1");
$tva->with_button(true);
+ // You must add the attributes gDossier, popup and phpsessid
+ $tva->set_attribute('popup','popup_tva');
+ $tva->set_attribute('phpsessid',$_REQUEST['PHPSESSID']);
+ $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);"';
@@ -42,9 +47,19 @@ require_once('class_ispan.php');
*/
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)';
+ */
public function __construct($p_name=null) {
$this->name=$p_name;
$this->button=true;
+ $this->in_table=false;
}
function with_button($p) {
if ($p == true )
@@ -57,14 +72,21 @@ require_once('class_ispan.php');
{
$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->js=(isset($this->js))?$this->js:"format_number(this);";
if ( $this->readOnly==true) return $this->display();
$str='';
$r=sprintf($str,$this->name,$this->value,$this->name,$this->js);
- if ( $this->button==true)
+
+ if ($this->in_table)
+ $table='
'.'
'.td($r);
+
+ if ( $this->button==true && ! $this->in_table)
$r.=$this->dbutton();
+ if ( $this->button==true && $this->in_table)
+ $r=$table.td($this->dbutton()).'
';
+
if ( isset($this->code)){
if ( $this->cn != NULL){
/* check if tva_id == integer */
@@ -73,15 +95,17 @@ require_once('class_ispan.php');
array($this->value));;
}
$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;
-
+
+ $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;
+
+}
/**
*@brief show a button, if it is pushed show a popup to select the need vat
*@note
@@ -99,7 +123,9 @@ require_once('class_ispan.php');
$bt->set_attribute('popup','popup_tva');
if ( isset($this->code))
$bt->set_attribute('jcode',$this->code->name);
- $bt->javascript='popup_select_tva(this)';
+ if ( isset($this->compute))
+ $bt->set_attribute('compute',$this->compute);
+ $bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
$r=$bt->input();
return $r;
}
diff --git a/include/compta_ach.inc.php b/include/compta_ach.inc.php
index 1f85f876d..622c7b1b2 100644
--- a/include/compta_ach.inc.php
+++ b/include/compta_ach.inc.php
@@ -45,7 +45,10 @@ $search_card=new IPopup('ipop_card');
$search_card->title=_('Recherche de fiche');
$search_card->value='';
echo $search_card->input();
-
+$pop_tva=new IPopup('popup_tva');
+$pop_tva->title=_('Choix TVA');
+$pop_tva->value='';
+echo $pop_tva->input();
$p_action=(isset($_REQUEST['p_action']))?$_REQUEST['p_action']:'';
$cn=new Database(dossier::id());
diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php
index e2e25d358..c24675d45 100644
--- a/include/compta_ven.inc.php
+++ b/include/compta_ven.inc.php
@@ -46,6 +46,11 @@ $search_card->title=_('Recherche de fiche');
$search_card->value='';
echo $search_card->input();
+$pop_tva=new IPopup('popup_tva');
+$pop_tva->title=_('Choix TVA');
+$pop_tva->value='';
+echo $pop_tva->input();
+
$p_action=(isset($_REQUEST['p_action']))?$_REQUEST['p_action']:'';
$gDossier=dossier::id();
$cn=new Database(dossier::id());
diff --git a/include/letter.inc.php b/include/letter.inc.php
new file mode 100644
index 000000000..65c9c6a06
--- /dev/null
+++ b/include/letter.inc.php
@@ -0,0 +1,52 @@
+';
+echo ShowItem($array,'H','mtitle','mtitle',$subdef);
+echo '';
+if ($sa == 'poste') {
+ require_once('lettering.account.inc.php');
+ exit;
+}
+
+if ($sa=='qc') {
+ exit;
+}