2
0
forked from Wavyzz/dolibarr

Fix: Calculation of second rounding method is available for supplier

invoices.
This commit is contained in:
Laurent Destailleur
2013-09-18 16:46:54 +02:00
parent 711146f5ea
commit 8526d34d3b
5 changed files with 28 additions and 22 deletions

View File

@@ -1471,14 +1471,15 @@ abstract class CommonObject
/** /**
* Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). * 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 $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 $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 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 * @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; global $conf;
@@ -1535,7 +1536,8 @@ abstract class CommonObject
// By default, no adjustement is required ($forcedroundingmode = -1) // By default, no adjustement is required ($forcedroundingmode = -1)
if ($forcedroundingmode == 0) // Check if we need adjustement onto line for vat 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); $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1);
if ($diff) if ($diff)
{ {

View File

@@ -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 * Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
* TODO * TODO
* This function is called to retrieve type for building PDF. Such call of function must be removed. * 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 * 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. * provide it to the function calcul_price_total.
* *
* @param real $vatrate VAT Rate * @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 * @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) 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:'')); dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local." thirdparty id=".(is_object($thirdparty)?$thirdparty->id:''));
// 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_pays as p"; $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 .= " WHERE t.fk_pays = p.rowid AND p.code = '".$thirdparty->country_code."'";
$sql .= " AND t.taux = ".$vatrate." AND t.active = 1"; $sql .= " AND t.taux = ".$vatrate." AND t.active = 1";

View File

@@ -72,9 +72,9 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
// Clean parameters // Clean parameters
if (empty($txtva)) $txtva=0; if (empty($txtva)) $txtva=0;
if (empty($seller) || ! is_object($seller)) 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) if (! is_object($mysoc)) // mysoc may be not defined (during migration process)
{ {
$mysoc=new Societe($db); $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 $seller=$mysoc; // If sell is done to a customer, $seller is not provided, we use $mysoc
//var_dump($seller->country_id);exit; //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 // 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); //dol_syslog("calcul_price_total qty=".$qty." pu=".$pu." remiserpercent_ligne=".$remise_percent_ligne." txtva=".$txtva." uselocaltax1_rate=".$uselocaltax1_rate." uselocaltax2_rate=".$uselocaltax2_rate);

View File

@@ -929,7 +929,7 @@ elseif ($action == 'calculate')
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $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) if ($result <= 0)
{ {
dol_print_error($db,$result); dol_print_error($db,$result);

View File

@@ -388,7 +388,7 @@ OtherInformations=Other informations
Quantity=Quantity Quantity=Quantity
Qty=Qty Qty=Qty
ChangedBy=Changed by ChangedBy=Changed by
ReCalculate=Rebuild ReCalculate=Recalculate
ResultOk=Success ResultOk=Success
ResultKo=Failure ResultKo=Failure
Reporting=Reporting Reporting=Reporting