forked from Wavyzz/dolibarr
Fix: Calculation of second rounding method is available for supplier
invoices.
This commit is contained in:
@@ -1471,14 +1471,15 @@ abstract class CommonObject
|
||||
|
||||
/**
|
||||
* Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
|
||||
* Must be called at end of methods addline, updateline.
|
||||
* Must be called at end of methods addline or updateline.
|
||||
*
|
||||
* @param int $exclspec Exclude special product (product_type=9)
|
||||
* @param int $roundingadjust -1=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or 0), 0=Force use total of rounding, 1=Force use rounding of total
|
||||
* @param int $nodatabaseupdate 1=Do not update database. Update only properties of object.
|
||||
* @param Societe $seller If roundingadjust is 0, it means we recalculate total for lines before calculating total for object. For this, we need seller object.
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update_price($exclspec=0,$roundingadjust=-1,$nodatabaseupdate=0)
|
||||
function update_price($exclspec=0,$roundingadjust=-1,$nodatabaseupdate=0,$seller='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@@ -1535,7 +1536,8 @@ abstract class CommonObject
|
||||
// By default, no adjustement is required ($forcedroundingmode = -1)
|
||||
if ($forcedroundingmode == 0) // Check if we need adjustement onto line for vat
|
||||
{
|
||||
$tmpcal=calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type);
|
||||
$localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx);
|
||||
$tmpcal=calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array);
|
||||
$diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1);
|
||||
if ($diff)
|
||||
{
|
||||
|
||||
@@ -2871,13 +2871,13 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
|
||||
* Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
|
||||
* TODO
|
||||
* This function is 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 array of localtax and type and
|
||||
* provide it to function calcul_price_total.
|
||||
* Instead this function must be called when adding a line to get (array of localtax and type) and
|
||||
* provide it to the function calcul_price_total.
|
||||
*
|
||||
* @param real $vatrate VAT Rate
|
||||
* @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 int $thirdparty Company object
|
||||
* @return array array(Type of local tax (1 to 7 / 0 if not found), rate or amount of localtax)
|
||||
* @return array array(localtax_type1(1-6 / 0 if not found), rate of localtax1, ...)
|
||||
*/
|
||||
function getLocalTaxesFromRate($vatrate, $local, $thirdparty)
|
||||
{
|
||||
@@ -2886,7 +2886,7 @@ function getLocalTaxesFromRate($vatrate, $local, $thirdparty)
|
||||
dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local." thirdparty id=".(is_object($thirdparty)?$thirdparty->id:''));
|
||||
|
||||
// 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_pays as p";
|
||||
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$thirdparty->country_code."'";
|
||||
$sql .= " AND t.taux = ".$vatrate." AND t.active = 1";
|
||||
|
||||
@@ -72,9 +72,9 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
|
||||
|
||||
// Clean parameters
|
||||
if (empty($txtva)) $txtva=0;
|
||||
|
||||
if (empty($seller) || ! is_object($seller))
|
||||
{
|
||||
dol_syslog("calcul_price_total Warning: function is called with parameter seller that is missing", LOG_WARNING);
|
||||
if (! is_object($mysoc)) // mysoc may be not defined (during migration process)
|
||||
{
|
||||
$mysoc=new Societe($db);
|
||||
@@ -83,6 +83,10 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
|
||||
$seller=$mysoc; // If sell is done to a customer, $seller is not provided, we use $mysoc
|
||||
//var_dump($seller->country_id);exit;
|
||||
}
|
||||
if (empty($localtaxes_array) || ! is_array($localtaxes_array))
|
||||
{
|
||||
dol_syslog("calcul_price_total Warning: function is called with parameter localtaxes_array that is missing", LOG_WARNING);
|
||||
}
|
||||
// Too verbose. Enable for debug only
|
||||
//dol_syslog("calcul_price_total qty=".$qty." pu=".$pu." remiserpercent_ligne=".$remise_percent_ligne." txtva=".$txtva." uselocaltax1_rate=".$uselocaltax1_rate." uselocaltax2_rate=".$uselocaltax2_rate);
|
||||
|
||||
|
||||
@@ -929,7 +929,7 @@ elseif ($action == 'calculate')
|
||||
|
||||
$object->fetch($id);
|
||||
$object->fetch_thirdparty();
|
||||
$result=$object->update_price(0,($calculationrule=='totalofround'?0:1));
|
||||
$result=$object->update_price(0, ($calculationrule=='totalofround'?0:1), 0, $object->thirdparty);
|
||||
if ($result <= 0)
|
||||
{
|
||||
dol_print_error($db,$result);
|
||||
|
||||
@@ -388,7 +388,7 @@ OtherInformations=Other informations
|
||||
Quantity=Quantity
|
||||
Qty=Qty
|
||||
ChangedBy=Changed by
|
||||
ReCalculate=Rebuild
|
||||
ReCalculate=Recalculate
|
||||
ResultOk=Success
|
||||
ResultKo=Failure
|
||||
Reporting=Reporting
|
||||
|
||||
Reference in New Issue
Block a user