diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 539b0b8946a..2736ba149f3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -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; @@ -1495,7 +1496,7 @@ abstract class CommonObject $fieldlocaltax1='total_localtax1'; $fieldlocaltax2='total_localtax2'; $fieldup='subprice'; - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $fieldtva='tva'; $fieldup='pu_ht'; @@ -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) { @@ -1549,7 +1551,7 @@ abstract class CommonObject // } } - + $this->total_ht += $obj->total_ht; // The only field visible at end of line detail $this->total_tva += $obj->total_tva; $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 - * + * * @return void */ function __clone() @@ -3264,6 +3266,6 @@ abstract class CommonObject } } } - + } ?> diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 1a804dba1d6..b509c41666a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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"; diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index 23ec745b17d..1d51485185b 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -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,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 //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); - + $countryid=$seller->country_id; if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_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). $localtax1_type=0; $localtax2_type=0; - + if (is_array($localtaxes_array)) { $localtax1_type = $localtaxes_array[0]; diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 7de2b910237..a4a909e35c9 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -926,10 +926,10 @@ elseif ($action == 'builddoc') elseif ($action == 'calculate') { $calculationrule=GETPOST('calculationrule'); - + $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); @@ -1441,21 +1441,21 @@ else } print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1, 240); - + } // Confirmation set 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); - + } // Confirmation de la suppression de la facture fournisseur if ($action == 'delete') { 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 ''; print ''; - if ($object->statut == 0) + if ($object->statut == 0) { print 'lines[$i]->rowid.'">'.img_delete().''; } diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 9f8c6eebd51..35788d208fa 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -388,7 +388,7 @@ OtherInformations=Other informations Quantity=Quantity Qty=Qty ChangedBy=Changed by -ReCalculate=Rebuild +ReCalculate=Recalculate ResultOk=Success ResultKo=Failure Reporting=Reporting