From af3256f84a7022e83d4bd8c90cb46e4590c37f99 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 19 Mar 2016 21:35:03 +0100 Subject: [PATCH] Fix first change to fix serious pb with vat definition when using the POS. --- htdocs/cashdesk/affContenu.php | 2 +- htdocs/cashdesk/affIndex.php | 2 +- htdocs/cashdesk/class/Facturation.class.php | 35 ++++------ htdocs/cashdesk/facturation_verif.php | 77 ++++++++++++++------- htdocs/cashdesk/index_verif.php | 2 +- htdocs/cashdesk/tpl/facturation1.tpl.php | 15 ++-- htdocs/cashdesk/tpl/menu.tpl.php | 2 +- htdocs/cashdesk/tpl/validation1.tpl.php | 2 +- htdocs/cashdesk/validation_verif.php | 8 +-- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/functions.lib.php | 55 ++++++++++++--- 11 files changed, 127 insertions(+), 75 deletions(-) diff --git a/htdocs/cashdesk/affContenu.php b/htdocs/cashdesk/affContenu.php index 3f27d19c7f3..280f2b81908 100644 --- a/htdocs/cashdesk/affContenu.php +++ b/htdocs/cashdesk/affContenu.php @@ -59,7 +59,7 @@ exit;*/ print '
'; print '
'; -$page=GETPOST('menu','alpha'); +$page=GETPOST('menutpl','alpha'); if (empty($page)) $page='facturation'; if (in_array( diff --git a/htdocs/cashdesk/affIndex.php b/htdocs/cashdesk/affIndex.php index 6ac2915a9d1..e30a0ea3303 100644 --- a/htdocs/cashdesk/affIndex.php +++ b/htdocs/cashdesk/affIndex.php @@ -42,7 +42,7 @@ $langs->load("cashdesk"); */ //header("Content-type: text/html; charset=UTF-8"); -header("Content-type: text/html; charset=".$conf->file->character_set_client); +//header("Content-type: text/html; charset=".$conf->file->character_set_client); $arrayofjs=array(); $arrayofcss=array('/cashdesk/css/style.css'); diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index fd67bf9e2ae..3143805b860 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -99,26 +99,17 @@ class Facturation $product = new Product($db); $product->fetch($this->id); - $sql = "SELECT taux"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_tva"; - $sql.= " WHERE rowid = ".$this->tva(); - - dol_syslog("ajoutArticle", LOG_DEBUG); - $resql = $db->query($sql); - - if ($resql) - { - $obj = $db->fetch_object($resql); - $vat_rate=$obj->taux; - //var_dump($vat_rate);exit; - } - else - { - dol_print_error($db); - } - + + $vatrowid = $this->tva(); + + $tmp = getTaxesFromId($vatrowid); + $vat_rate = $tmp['rate']; + $vat_npr = $tmp['npr']; + + $localtaxarray = getLocalTaxesFromRate($vatrowid, 0, $societe, $mysoc, 1); + // Define part of HT, VAT, TTC - $resultarray=calcul_price_total($this->qte,$this->prix(),$this->remisePercent(),$vat_rate,0,0,0,'HT',0,$product->type,$mysoc); + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $vat_rate, 0, 0, 0, 'HT', $use_npr, $product->type, $mysoc, $locataxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; @@ -442,9 +433,8 @@ class Facturation * @param int $aTva Vat * @return int Vat */ - public function tva ( $aTva=null ) + public function tva($aTva=null) { - if ( !$aTva ) { return $this->tva; @@ -467,9 +457,8 @@ class Facturation * @param string $aNumFacture Invoice ref * @return string Invoice ref */ - public function numInvoice( $aNumFacture=null ) + public function numInvoice($aNumFacture=null) { - if ( !$aNumFacture ) { return $this->num_facture; diff --git a/htdocs/cashdesk/facturation_verif.php b/htdocs/cashdesk/facturation_verif.php index 8953f7b0ccc..95a129e88a5 100644 --- a/htdocs/cashdesk/facturation_verif.php +++ b/htdocs/cashdesk/facturation_verif.php @@ -37,7 +37,7 @@ switch ( $_GET['action'] ) default: if ( $_POST['hdnSource'] != 'NULL' ) { - $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx"; + $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx, p.recuperableonly"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = ".$conf_fkentrepot; @@ -66,19 +66,23 @@ switch ( $_GET['action'] ) { $ret[$key] = $value; } + // Here $ret['tva_tx'] is vat rate of product but we want to not use the one into table but found by function + + $productid = $ret['rowid']; + $product = new Product($db); + $product->fetch($productid); - /** add Ditto for MultiPrix*/ - if (! empty($conf->global->PRODUIT_MULTIPRICES)) + $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; + $societe = new Societe($db); + $societe->fetch($thirdpartyid); + + $tva_tx = get_default_tva($mysoc,$societe,$productid); + $tva_npr = get_default_npr($mysoc,$societe,$productid); + if (empty($tva_tx)) $tva_npr=0; + dol_syslog('tva_tx='.$tva_tx.'-tva_npr='.$tva_npr); + + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($societe->price_level)) { - $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; - $productid = $ret['rowid']; - - $societe = new Societe($db); - $societe->fetch($thirdpartyid); - - $product = new Product($db); - $product->fetch($productid); - if(isset($product->multiprices[$societe->price_level])) { $ret['price'] = $product->multiprices[$societe->price_level]; @@ -86,16 +90,39 @@ switch ( $_GET['action'] ) // $product->multiprices_min[$societe->price_level]; // $product->multiprices_min_ttc[$societe->price_level]; // $product->multiprices_base_type[$societe->price_level]; - $ret['tva_tx'] = $product->multiprices_tva_tx[$societe->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility + { + if (isset($prod->multiprices_tva_tx[$societe->price_level])) $tva_tx=$prod->multiprices_tva_tx[$societe->price_level]; + if (isset($prod->multiprices_recuperableonly[$societe->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$societe->price_level]; + if (empty($tva_tx)) $tva_npr=0; + } } } - /** end add Ditto */ + $ret['tva_tx'] = $tva_tx; + $ret['tva_npr'] = $tva_npr; + //var_dump('tva_tx='.$ret['tva_tx'].'-tva_npr='.$ret['tva_npr'].'-'.$conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL);exit; + $obj_facturation->id($ret['rowid']); $obj_facturation->ref($ret['ref']); $obj_facturation->stock($ret['reel']); $obj_facturation->prix($ret['price']); - $obj_facturation->tva($ret['tva_tx']); + + // Use $ret['tva_tx'] / ret['tva_npr'] to find vat id + $vatrowid = null; + $sqlfindvatid = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'c_tva'; + $sqlfindvatid.= ' WHERE taux = '.$ret['tva_tx'].' AND recuperableonly = '.(int) $ret['tva_npr']; + $sqlfindvatid.= ' AND fk_pays = '.$mysoc->country_id; + $resqlfindvatid=$db->query($sqlfindvatid); + if ($resqlfindvatid) + { + $obj = $db->fetch_object($resqlfindvatid); + if ($obj) $vatrowid = $obj->rowid; + } + else dol_print_error($db); + + dol_syslog("save vatrowid=".$vatrowid); + $obj_facturation->tva($vatrowid); // Save vat it for next use // Definition du filtre pour n'afficher que le produit concerne if ( $_POST['hdnSource'] == 'LISTE' ) @@ -107,7 +134,7 @@ switch ( $_GET['action'] ) $filtre = $_POST['txtRef']; } - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$filtre; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&filtre='.$filtre; } else { @@ -115,11 +142,11 @@ switch ( $_GET['action'] ) if ( $_POST['hdnSource'] == 'REF' ) { - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&filtre='.$_POST['txtRef']; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&filtre='.$_POST['txtRef']; } else { - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; } } } @@ -130,40 +157,38 @@ switch ( $_GET['action'] ) } else { - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; } break; case 'ajout_article': // We have clicked on button "Add product" - //var_dump('ajout_article'); - //exit; - if (! empty($obj_facturation->id)) // A product was previously selected and stored in session, so we can add it { + dol_syslog("facturation_verif save vat ".$_POST['selTva']); $obj_facturation->qte($_POST['txtQte']); - $obj_facturation->tva($_POST['selTva']); + $obj_facturation->tva($_POST['selTva']); // Save VAT selected so we can use it for next product $obj_facturation->remisePercent($_POST['txtRemise']); $obj_facturation->ajoutArticle(); // This add an entry into $_SESSION['poscart'] // We update prixTotalTtc } - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; break; case 'suppr_article': $obj_facturation->supprArticle($_GET['suppr_id']); - $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation'; + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; break; } // We saved object obj_facturation $_SESSION['serObjFacturation'] = serialize($obj_facturation); - +//var_dump($_SESSION['serObjFacturation']); header('Location: '.$redirection); exit; diff --git a/htdocs/cashdesk/index_verif.php b/htdocs/cashdesk/index_verif.php index db80866a77f..238a73f6ef7 100644 --- a/htdocs/cashdesk/index_verif.php +++ b/htdocs/cashdesk/index_verif.php @@ -125,7 +125,7 @@ if ( $retour >= 0 ) $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : ''); //var_dump($_SESSION);exit; - header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&id=NOUV'); + header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV'); exit; } else diff --git a/htdocs/cashdesk/tpl/facturation1.tpl.php b/htdocs/cashdesk/tpl/facturation1.tpl.php index f9ef89e909c..ecb11c3e6ee 100644 --- a/htdocs/cashdesk/tpl/facturation1.tpl.php +++ b/htdocs/cashdesk/tpl/facturation1.tpl.php @@ -119,7 +119,7 @@ $langs->load("cashdesk"); - + @@ -128,16 +128,17 @@ $langs->load("cashdesk"); diff --git a/htdocs/cashdesk/tpl/menu.tpl.php b/htdocs/cashdesk/tpl/menu.tpl.php index ce38bb7d7e8..745ea723b49 100644 --- a/htdocs/cashdesk/tpl/menu.tpl.php +++ b/htdocs/cashdesk/tpl/menu.tpl.php @@ -62,7 +62,7 @@ $langs->load("main"); print '