forked from Wavyzz/dolibarr
Fix first change to fix serious pb with vat definition when using the
POS.
This commit is contained in:
@@ -59,7 +59,7 @@ exit;*/
|
|||||||
print '<div class="inline-block" style="vertical-align: top">';
|
print '<div class="inline-block" style="vertical-align: top">';
|
||||||
print '<div class="principal">';
|
print '<div class="principal">';
|
||||||
|
|
||||||
$page=GETPOST('menu','alpha');
|
$page=GETPOST('menutpl','alpha');
|
||||||
if (empty($page)) $page='facturation';
|
if (empty($page)) $page='facturation';
|
||||||
|
|
||||||
if (in_array(
|
if (in_array(
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ $langs->load("cashdesk");
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//header("Content-type: text/html; charset=UTF-8");
|
//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();
|
$arrayofjs=array();
|
||||||
$arrayofcss=array('/cashdesk/css/style.css');
|
$arrayofcss=array('/cashdesk/css/style.css');
|
||||||
|
|||||||
@@ -99,26 +99,17 @@ class Facturation
|
|||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
$product->fetch($this->id);
|
$product->fetch($this->id);
|
||||||
|
|
||||||
$sql = "SELECT taux";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva";
|
|
||||||
$sql.= " WHERE rowid = ".$this->tva();
|
|
||||||
|
|
||||||
dol_syslog("ajoutArticle", LOG_DEBUG);
|
$vatrowid = $this->tva();
|
||||||
$resql = $db->query($sql);
|
|
||||||
|
|
||||||
if ($resql)
|
$tmp = getTaxesFromId($vatrowid);
|
||||||
{
|
$vat_rate = $tmp['rate'];
|
||||||
$obj = $db->fetch_object($resql);
|
$vat_npr = $tmp['npr'];
|
||||||
$vat_rate=$obj->taux;
|
|
||||||
//var_dump($vat_rate);exit;
|
$localtaxarray = getLocalTaxesFromRate($vatrowid, 0, $societe, $mysoc, 1);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define part of HT, VAT, TTC
|
// 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
|
// Calcul du total ht sans remise
|
||||||
$total_ht = $resultarray[0];
|
$total_ht = $resultarray[0];
|
||||||
@@ -444,7 +435,6 @@ class Facturation
|
|||||||
*/
|
*/
|
||||||
public function tva($aTva=null)
|
public function tva($aTva=null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( !$aTva ) {
|
if ( !$aTva ) {
|
||||||
|
|
||||||
return $this->tva;
|
return $this->tva;
|
||||||
@@ -469,7 +459,6 @@ class Facturation
|
|||||||
*/
|
*/
|
||||||
public function numInvoice($aNumFacture=null)
|
public function numInvoice($aNumFacture=null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( !$aNumFacture ) {
|
if ( !$aNumFacture ) {
|
||||||
|
|
||||||
return $this->num_facture;
|
return $this->num_facture;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ switch ( $_GET['action'] )
|
|||||||
default:
|
default:
|
||||||
if ( $_POST['hdnSource'] != 'NULL' )
|
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";
|
if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
$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;
|
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;
|
$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
|
||||||
|
|
||||||
/** add Ditto for MultiPrix*/
|
|
||||||
if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
|
||||||
{
|
|
||||||
$thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
|
|
||||||
$productid = $ret['rowid'];
|
$productid = $ret['rowid'];
|
||||||
|
|
||||||
$societe = new Societe($db);
|
|
||||||
$societe->fetch($thirdpartyid);
|
|
||||||
|
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
$product->fetch($productid);
|
$product->fetch($productid);
|
||||||
|
|
||||||
|
$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))
|
||||||
|
{
|
||||||
if(isset($product->multiprices[$societe->price_level]))
|
if(isset($product->multiprices[$societe->price_level]))
|
||||||
{
|
{
|
||||||
$ret['price'] = $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[$societe->price_level];
|
||||||
// $product->multiprices_min_ttc[$societe->price_level];
|
// $product->multiprices_min_ttc[$societe->price_level];
|
||||||
// $product->multiprices_base_type[$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->id($ret['rowid']);
|
||||||
$obj_facturation->ref($ret['ref']);
|
$obj_facturation->ref($ret['ref']);
|
||||||
$obj_facturation->stock($ret['reel']);
|
$obj_facturation->stock($ret['reel']);
|
||||||
$obj_facturation->prix($ret['price']);
|
$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
|
// Definition du filtre pour n'afficher que le produit concerne
|
||||||
if ( $_POST['hdnSource'] == 'LISTE' )
|
if ( $_POST['hdnSource'] == 'LISTE' )
|
||||||
@@ -107,7 +134,7 @@ switch ( $_GET['action'] )
|
|||||||
$filtre = $_POST['txtRef'];
|
$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
|
else
|
||||||
{
|
{
|
||||||
@@ -115,11 +142,11 @@ switch ( $_GET['action'] )
|
|||||||
|
|
||||||
if ( $_POST['hdnSource'] == 'REF' )
|
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
|
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
|
else
|
||||||
{
|
{
|
||||||
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
|
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ajout_article': // We have clicked on button "Add product"
|
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
|
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->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->remisePercent($_POST['txtRemise']);
|
||||||
$obj_facturation->ajoutArticle(); // This add an entry into $_SESSION['poscart']
|
$obj_facturation->ajoutArticle(); // This add an entry into $_SESSION['poscart']
|
||||||
// We update prixTotalTtc
|
// We update prixTotalTtc
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation';
|
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'suppr_article':
|
case 'suppr_article':
|
||||||
$obj_facturation->supprArticle($_GET['suppr_id']);
|
$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;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We saved object obj_facturation
|
// We saved object obj_facturation
|
||||||
$_SESSION['serObjFacturation'] = serialize($obj_facturation);
|
$_SESSION['serObjFacturation'] = serialize($obj_facturation);
|
||||||
|
//var_dump($_SESSION['serObjFacturation']);
|
||||||
header('Location: '.$redirection);
|
header('Location: '.$redirection);
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ if ( $retour >= 0 )
|
|||||||
$_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
|
$_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
|
||||||
//var_dump($_SESSION);exit;
|
//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;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -128,16 +128,17 @@ $langs->load("cashdesk");
|
|||||||
<?php //var_dump($tab_tva); ?>
|
<?php //var_dump($tab_tva); ?>
|
||||||
<select name="selTva" onchange="javascript: modif();" >
|
<select name="selTva" onchange="javascript: modif();" >
|
||||||
<?php
|
<?php
|
||||||
$tva_tx = $obj_facturation->tva();
|
$tva_tx = $obj_facturation->tva(); // Try to get a previously entered VAT rowid. First time, this will return empty.
|
||||||
$tab_tva_size=count($tab_tva);
|
|
||||||
for($i=0;$i < $tab_tva_size;$i++) {
|
|
||||||
|
|
||||||
if ( $tva_tx == $tab_tva[$i]['taux'] )
|
$tab_tva_size=count($tab_tva); // $tab_tva contains list of possible vat array('rowid'=> , 'taux'=> )
|
||||||
|
for ($i=0;$i < $tab_tva_size;$i++)
|
||||||
|
{
|
||||||
|
if ($tva_tx == $tab_tva[$i]['rowid'])
|
||||||
$selected = 'selected';
|
$selected = 'selected';
|
||||||
else
|
else
|
||||||
$selected = '';
|
$selected = '';
|
||||||
|
|
||||||
echo ('<option '.$selected.' value="'.$tab_tva[$i]['rowid'].'">'.$tab_tva[$i]['taux'].'</option>'."\n ");
|
echo '<option '.$selected.' value="'.$tab_tva[$i]['rowid'].'">'.$tab_tva[$i]['taux'].'</option>'."\n ";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ $langs->load("main");
|
|||||||
print '<div class="menu_bloc">';
|
print '<div class="menu_bloc">';
|
||||||
print '<ul class="menu">';
|
print '<ul class="menu">';
|
||||||
// Link to new sell
|
// Link to new sell
|
||||||
print '<li class="menu_choix1"><a href="affIndex.php?menu=facturation&id=NOUV"><span>'.$langs->trans("NewSell").'</span></a></li>';
|
print '<li class="menu_choix1"><a href="affIndex.php?menutpl=facturation&id=NOUV"><span>'.$langs->trans("NewSell").'</span></a></li>';
|
||||||
// Open new tab on backoffice (this is not a disconnect from POS)
|
// Open new tab on backoffice (this is not a disconnect from POS)
|
||||||
print '<li class="menu_choix2"><a href=".." target="backoffice"><span>'.$langs->trans("BackOffice").'</span></a></li>';
|
print '<li class="menu_choix2"><a href=".." target="backoffice"><span>'.$langs->trans("BackOffice").'</span></a></li>';
|
||||||
// Disconnect
|
// Disconnect
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ $langs->load("bills");
|
|||||||
<p class="note_label"><?php echo $langs->trans("Notes"); ?><br><textarea class="textarea_note" name="txtaNotes"></textarea></p>
|
<p class="note_label"><?php echo $langs->trans("Notes"); ?><br><textarea class="textarea_note" name="txtaNotes"></textarea></p>
|
||||||
|
|
||||||
<div class="center"><input class="button" type="submit" name="btnValider" value="<?php echo $langs->trans("ValidateInvoice"); ?>" /><br>
|
<div class="center"><input class="button" type="submit" name="btnValider" value="<?php echo $langs->trans("ValidateInvoice"); ?>" /><br>
|
||||||
<br><a class="lien1" href="affIndex.php?menu=facturation"><?php echo $langs->trans("RestartSelling"); ?></a>
|
<br><a class="lien1" href="affIndex.php?menutpl=facturation"><?php echo $langs->trans("RestartSelling"); ?></a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ switch ($action)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=validation';
|
$redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=validation';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -85,13 +85,13 @@ switch ($action)
|
|||||||
$obj_facturation->paiementLe($txtDatePaiement);
|
$obj_facturation->paiementLe($txtDatePaiement);
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirection = 'affIndex.php?menu=validation';
|
$redirection = 'affIndex.php?menutpl=validation';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 'retour':
|
case 'retour':
|
||||||
|
|
||||||
$redirection = 'affIndex.php?menu=facturation';
|
$redirection = 'affIndex.php?menutpl=facturation';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -336,7 +336,7 @@ switch ($action)
|
|||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
$redirection = 'affIndex.php?menu=validation_ok&facid='.$id; // Ajout de l'id de la facture, pour l'inclure dans un lien pointant directement vers celle-ci dans Dolibarr
|
$redirection = 'affIndex.php?menutpl=validation_ok&facid='.$id; // Ajout de l'id de la facture, pour l'inclure dans un lien pointant directement vers celle-ci dans Dolibarr
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3937,7 +3937,7 @@ class Form
|
|||||||
/**
|
/**
|
||||||
* Load into the cache vat rates of a country
|
* Load into the cache vat rates of a country
|
||||||
*
|
*
|
||||||
* @param string $country_code Country code
|
* @param string $country_code Country code with quotes ("'CA'", or "'CA,IN,...'")
|
||||||
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
|
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
|
||||||
*/
|
*/
|
||||||
function load_cache_vatrates($country_code)
|
function load_cache_vatrates($country_code)
|
||||||
|
|||||||
@@ -3503,20 +3503,52 @@ function get_localtax_by_third($local)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get vat rate and npr from id.
|
||||||
|
* You can call getLocalTaxesFromRate after to get other fields
|
||||||
|
*
|
||||||
|
* @param string $vatrate VAT Rate. Value can be value or the string with code into parenthesis or rowid if $firstparamisid is 1. Example: '8.5' or '8.5 (8.5NPR)' or 123.
|
||||||
|
* @param int $usenpr Use npr
|
||||||
|
* @return array array(localtax_type1(1-6 / 0 if not found), rate of localtax1, ...)
|
||||||
|
*/
|
||||||
|
function getTaxesFromId($vatrowid)
|
||||||
|
{
|
||||||
|
global $db, $mysoc;
|
||||||
|
|
||||||
|
dol_syslog("getTaxesFromId vatrowid=".$vatrowid);
|
||||||
|
|
||||||
|
// Search local taxes
|
||||||
|
$sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t";
|
||||||
|
$sql.= " WHERE t.rowid ='".$vatrowid."'";
|
||||||
|
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
|
return array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'rate'=>$obj->rate, 'npr'=>$obj->npr);
|
||||||
|
}
|
||||||
|
else dol_print_error($db);
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
|
* Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
|
||||||
* TODO
|
* TODO
|
||||||
* This function is also called to retrieve type for building PDF. Such call of function must be removed.
|
* This function is ALSO called to retrieve type for building PDF. Such call of function must be removed.
|
||||||
* Instead this function must be called when adding a line to get the array of localtax and type, and then
|
* Instead this function must be called when adding a line to get the array of localtax and type, and then
|
||||||
* provide it to the function calcul_price_total.
|
* provide it to the function calcul_price_total.
|
||||||
*
|
*
|
||||||
* @param float $vatrate VAT Rate. Value can be '8.5' or '8.5 (8.5NPR)'.
|
* @param string $vatrate VAT Rate. Value can be value or the string with code into parenthesis or rowid if $firstparamisid is 1. Example: '8.5' or '8.5 (8.5NPR)' or 123.
|
||||||
* @param int $local Number of localtax (1 or 2, or 0 to return 1 & 2)
|
* @param int $local Number of localtax (1 or 2, or 0 to return 1 & 2)
|
||||||
* @param Societe $buyer Company object
|
* @param Societe $buyer Company object
|
||||||
* @param Societe $seller Company object
|
* @param Societe $seller Company object
|
||||||
|
* @param int $firstparamisid 1 if first param is id into table (use this if you can)
|
||||||
* @return array array(localtax_type1(1-6 / 0 if not found), rate of localtax1, ...)
|
* @return array array(localtax_type1(1-6 / 0 if not found), rate of localtax1, ...)
|
||||||
*/
|
*/
|
||||||
function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller)
|
function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
|
||||||
{
|
{
|
||||||
global $db, $mysoc;
|
global $db, $mysoc;
|
||||||
|
|
||||||
@@ -3531,11 +3563,16 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller)
|
|||||||
|
|
||||||
// Search local taxes
|
// Search local taxes
|
||||||
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
|
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
|
||||||
if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
|
if ($firstparamisid) $sql.= " WHERE t.rowid ='".$vatrate."'";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql.=", ".MAIN_DB_PREFIX."c_country as c";
|
||||||
|
if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'"; // local tax in spain use the buyer country ??
|
||||||
else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
|
else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
|
||||||
$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
|
$sql.= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
|
||||||
if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
|
if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
|
||||||
|
}
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
|
|||||||
Reference in New Issue
Block a user