mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-09 11:08:34 +01:00
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).
|
* 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;
|
||||||
|
|
||||||
@@ -1495,7 +1496,7 @@ abstract class CommonObject
|
|||||||
$fieldlocaltax1='total_localtax1';
|
$fieldlocaltax1='total_localtax1';
|
||||||
$fieldlocaltax2='total_localtax2';
|
$fieldlocaltax2='total_localtax2';
|
||||||
$fieldup='subprice';
|
$fieldup='subprice';
|
||||||
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
|
if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier')
|
||||||
{
|
{
|
||||||
$fieldtva='tva';
|
$fieldtva='tva';
|
||||||
$fieldup='pu_ht';
|
$fieldup='pu_ht';
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -1549,7 +1551,7 @@ abstract class CommonObject
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->total_ht += $obj->total_ht; // The only field visible at end of line detail
|
$this->total_ht += $obj->total_ht; // The only field visible at end of line detail
|
||||||
$this->total_tva += $obj->total_tva;
|
$this->total_tva += $obj->total_tva;
|
||||||
$this->total_localtax1 += $obj->total_localtax1;
|
$this->total_localtax1 += $obj->total_localtax1;
|
||||||
@@ -3249,7 +3251,7 @@ abstract class CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite magic function to solve problem of cloning object that are kept as references
|
* Overwrite magic function to solve problem of cloning object that are kept as references
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function __clone()
|
function __clone()
|
||||||
@@ -3264,6 +3266,6 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|||||||
@@ -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,9 +83,13 @@ 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);
|
||||||
|
|
||||||
$countryid=$seller->country_id;
|
$countryid=$seller->country_id;
|
||||||
if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj;
|
if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj;
|
||||||
if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj;
|
if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj;
|
||||||
@@ -93,7 +97,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
|
|||||||
// Now we search localtaxes information ourself (rates and types).
|
// Now we search localtaxes information ourself (rates and types).
|
||||||
$localtax1_type=0;
|
$localtax1_type=0;
|
||||||
$localtax2_type=0;
|
$localtax2_type=0;
|
||||||
|
|
||||||
if (is_array($localtaxes_array))
|
if (is_array($localtaxes_array))
|
||||||
{
|
{
|
||||||
$localtax1_type = $localtaxes_array[0];
|
$localtax1_type = $localtaxes_array[0];
|
||||||
|
|||||||
@@ -926,10 +926,10 @@ elseif ($action == 'builddoc')
|
|||||||
elseif ($action == 'calculate')
|
elseif ($action == 'calculate')
|
||||||
{
|
{
|
||||||
$calculationrule=GETPOST('calculationrule');
|
$calculationrule=GETPOST('calculationrule');
|
||||||
|
|
||||||
$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);
|
||||||
@@ -1441,21 +1441,21 @@ else
|
|||||||
}
|
}
|
||||||
|
|
||||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1, 240);
|
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1, 240);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirmation set paid
|
// Confirmation set paid
|
||||||
if ($action == 'paid')
|
if ($action == 'paid')
|
||||||
{
|
{
|
||||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1);
|
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirmation de la suppression de la facture fournisseur
|
// Confirmation de la suppression de la facture fournisseur
|
||||||
if ($action == 'delete')
|
if ($action == 'delete')
|
||||||
{
|
{
|
||||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
|
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1961,7 +1961,7 @@ else
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td align="center" width="16">';
|
print '<td align="center" width="16">';
|
||||||
if ($object->statut == 0)
|
if ($object->statut == 0)
|
||||||
{
|
{
|
||||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_delete_line&lineid='.$object->lines[$i]->rowid.'">'.img_delete().'</a>';
|
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_delete_line&lineid='.$object->lines[$i]->rowid.'">'.img_delete().'</a>';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user