diff --git a/.gitignore b/.gitignore index 33cde11b9c463870cd2f19ebbde5f29c8e35a2d6..42785132923b448837af6a1a18c082eea7d206d1 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ htdocs/conf/conf.php.old documents/ custom/ custom2/ +test/ nbproject default.properties .settings/ diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 27ffdf3323b13e336506426953631c95af35ed1d..b6a73ceaa604135242fe966bce35bd6d5c024a55 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2647,8 +2647,8 @@ else if ($id > 0 || ! empty($ref)) * List of payments */ - $sign=1; - if ($object->type == 2) $sign=-1; + $sign=1; + if ($object->type == 2) $sign=-1; $nbrows=8; $nbcols=2; if (! empty($conf->projet->enabled)) $nbrows++; @@ -2824,10 +2824,10 @@ else if ($id > 0 || ! empty($ref)) } else // Credit note { - // Total already paid back - print '<tr><td colspan="'.$nbcols.'" align="right">'; - print $langs->trans('AlreadyPaidBack'); - print ' :</td><td align="right">'.price($sign * $totalpaye).'</td><td> </td></tr>'; + // Total already paid back + print '<tr><td colspan="'.$nbcols.'" align="right">'; + print $langs->trans('AlreadyPaidBack'); + print ' :</td><td align="right">'.price($sign * $totalpaye).'</td><td> </td></tr>'; // Billed print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($sign * $object->total_ttc).'</td><td> </td></tr>'; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index e680368d380dfa4a75064ebcc0512b194909df23..9f844a4e806d5420327b3adf50d0f84229552d59 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -150,11 +150,11 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') // Clean parameters amount if payment is for a credit note if (GETPOST('type') == 2) { - foreach ($amounts as $key => $value) // How payment is dispatch - { - $newvalue = price2num($value,'MT'); - $amounts[$key] = -$newvalue; - } + foreach ($amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value,'MT'); + $amounts[$key] = -$newvalue; + } } // Creation of payment line @@ -469,13 +469,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $num = $db->num_rows($resql); if ($num > 0) { - $sign=1; - if ($facture->type == 2) $sign=-1; + $sign=1; + if ($facture->type == 2) $sign=-1; $arraytitle=$langs->trans('Invoice'); if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes"); $alreadypayedlabel=$langs->trans('Received'); - if ($facture->type == 2) $alreadypayedlabel=$langs->trans("PaidBack"); + if ($facture->type == 2) $alreadypayedlabel=$langs->trans("PaidBack"); $remaindertopay=$langs->trans('RemainderToTake'); if ($facture->type == 2) $remaindertopay=$langs->trans("RemainderToPayBack"); @@ -608,7 +608,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically"); if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically"); $buttontitle=$langs->trans('ToMakePayment'); - if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack'); + if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack'); print '<center><br>'; print '<input type="checkbox" checked="checked" name="closepaidinvoices"> '.$checkboxlabel; diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index f580acf7e8fbaf57ede1f34a5b67de6b4e399f04..0c87ba3bc802b6da68fbf9df61579a694ccd8f57 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -1,286 +1,286 @@ -<?php -/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> - * Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es> - * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * \file htdocs/core/lib/price.lib.php - * \brief Library with functions to calculate prices - */ - - -/** - * Calculate totals (net, vat, ...) of a line. - * Value for localtaxX_type are '0' : local tax not applied - * '1' : local tax apply on products and services without vat (vat is not applied for local tax calculation) - * '2' : local tax apply on products and services before vat (vat is calculated on amount + localtax) - * '3' : local tax apply on products without vat (vat is not applied for local tax calculation) - * '4' : local tax apply on products before vat (vat is calculated on amount + localtax) - * '5' : local tax apply on services without vat (vat is not applied for local tax calculation) - * '6' : local tax apply on services before vat (vat is calculated on amount + localtax) - * '7' : local tax is a fix amount applied on global invoice - * - * @param int $qty Quantity - * @param float $pu Unit price (HT or TTC selon price_base_type) - * @param float $remise_percent_ligne Discount for line - * @param float $txtva 0=do not apply standard tax, Vat rate=apply - * @param float $uselocaltax1_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller - * @param float $uselocaltax2_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller - * @param float $remise_percent_global 0 - * @param string $price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC - * @param int $info_bits Miscellanous informations on line - * @param int $type 0/1=Product/service - * @param string $seller Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier. - * @return result[ 0=total_ht, - * 1=total_vat, - * 2=total_ttc, - * 3=pu_ht, - * 4=pu_tva, - * 5=pu_ttc, - * 6=total_ht_without_discount, - * 7=total_vat_without_discount, - * 8=total_ttc_without_discount, - * 9=amount tax1 for total_ht, - * 10=amount tax2 for total_ht, - * 11=amount tax1 for pu_ht, - * 12=amount tax2 for pu_ht, - * 13=not used???, - * 14=amount tax1 for total_ht_without_discount, - * 15=amount tax1 for total_ht_without_discount] - */ -function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '') -{ - global $conf,$mysoc,$db; - - $result=array(); - - if (empty($seller) || ! is_object($seller)) - { - if (! is_object($mysoc)) // mysoc may be not defined (during migration process) - { +<?php +/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> + * Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es> + * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * \file htdocs/core/lib/price.lib.php + * \brief Library with functions to calculate prices + */ + + +/** + * Calculate totals (net, vat, ...) of a line. + * Value for localtaxX_type are '0' : local tax not applied + * '1' : local tax apply on products and services without vat (vat is not applied for local tax calculation) + * '2' : local tax apply on products and services before vat (vat is calculated on amount + localtax) + * '3' : local tax apply on products without vat (vat is not applied for local tax calculation) + * '4' : local tax apply on products before vat (vat is calculated on amount + localtax) + * '5' : local tax apply on services without vat (vat is not applied for local tax calculation) + * '6' : local tax apply on services before vat (vat is calculated on amount + localtax) + * '7' : local tax is a fix amount applied on global invoice + * + * @param int $qty Quantity + * @param float $pu Unit price (HT or TTC selon price_base_type) + * @param float $remise_percent_ligne Discount for line + * @param float $txtva 0=do not apply standard tax, Vat rate=apply + * @param float $uselocaltax1_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller + * @param float $uselocaltax2_rate 0=do not use this localtax, >0=apply, -1=autodetect according to seller + * @param float $remise_percent_global 0 + * @param string $price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC + * @param int $info_bits Miscellanous informations on line + * @param int $type 0/1=Product/service + * @param string $seller Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier. + * @return result[ 0=total_ht, + * 1=total_vat, + * 2=total_ttc, + * 3=pu_ht, + * 4=pu_tva, + * 5=pu_ttc, + * 6=total_ht_without_discount, + * 7=total_vat_without_discount, + * 8=total_ttc_without_discount, + * 9=amount tax1 for total_ht, + * 10=amount tax2 for total_ht, + * 11=amount tax1 for pu_ht, + * 12=amount tax2 for pu_ht, + * 13=not used???, + * 14=amount tax1 for total_ht_without_discount, + * 15=amount tax1 for total_ht_without_discount] + */ +function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '') +{ + global $conf,$mysoc,$db; + + $result=array(); + + if (empty($seller) || ! is_object($seller)) + { + if (! is_object($mysoc)) // mysoc may be not defined (during migration process) + { $mysoc=new Societe($db); $mysoc->getMysoc($conf); - } - $seller=$mysoc; // If seller is a customer, $seller is not provided, we use $mysoc - //var_dump($seller->country_id);exit; - } - - $countryid=$seller->country_id; - if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj; - if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj; - - // Now we search localtaxes information ourself (rates and types). - $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv"; - //$sql.= ", ".MAIN_DB_PREFIX."c_pays as cc"; - $sql.= " WHERE cv.taux = ".$txtva; - //$sql.= " AND cv.fk_pays = cc.rowid and cc.code = '".$mysoc->country_code."'"; - $sql.= " AND cv.fk_pays = ".$countryid; - dol_syslog("search vat information sql=".$sql); - $resql = $db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj) - { - $localtax1_rate=$obj->localtax1; - $localtax2_rate=$obj->localtax2; - $localtax1_type=$obj->localtax1_type; - $localtax2_type=$obj->localtax2_type; - //var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);exit; - } - } - else dol_print_error($db); - - // initialize total (may be HT or TTC depending on price_base_type) - $tot_sans_remise = $pu * $qty; - $tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100)); - $tot_avec_remise = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100)); - - // initialize result - for ($i=0; $i <= 15; $i++) $result[$i] = 0; - - // if there's some localtax including vat, we calculate localtaxes (we will add later) - $localtaxes = array(0,0,0); - $apply_tax = false; - switch($localtax1_type) { - case '2': // localtax on product or service - $apply_tax = true; - break; - case '4': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '6': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax1_rate && $apply_tax) { - $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); - $localtaxes[0] += $result[14]; - - $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); - $localtaxes[1] += $result[9]; - - $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); - $localtaxes[2] += $result[11]; - } - - $apply_tax = false; - switch($localtax2_type) { - case '2': // localtax on product or service - $apply_tax = true; - break; - case '4': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '6': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax2_rate && $apply_tax) { - $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); - $localtaxes[0] += $result[15]; - - $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); - $localtaxes[1] += $result[10]; - - $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); - $localtaxes[2] += $result[12]; - } - - //dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits"); - if ($price_base_type == 'HT') - { - // We work to define prices using the price without tax - $result[6] = price2num($tot_sans_remise, 'MT'); - $result[8] = price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result8bis= price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT'); - - $result[0] = price2num($tot_avec_remise, 'MT'); - $result[2] = price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result2bis= price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax) - - $result[3] = price2num($pu, 'MU'); - $result[5] = price2num(($pu + $localtaxes[2]) * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non - $result5bis= price2num(($pu + $localtaxes[2]) * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) - $result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU'); - } - else - { - // We work to define prices using the price with tax - $result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT'); - $result[6] = price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result6bis= price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT'); - - $result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT'); - $result[0] = price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non - $result0bis= price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) - $result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - HT - - $result[5] = price2num(($pu + $localtaxes[2]), 'MU'); - $result[3] = price2num(($pu + $localtaxes[2]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non - $result3bis= price2num(($pu + $localtaxes[2]) / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) - $result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU'); - } - - // if there's some localtax without vat, we calculate localtaxes (we will add them at end) - - //If price is 'TTC' we need to have the totals without VAT for a correct calculation - if ($price_base_type=='TTC') - { - $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU'); - $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU'); - $pu = price2num($pu / (1 + ($txtva / 100)),'MU'); - } - - $apply_tax = false; - switch($localtax1_type) { - case '1': // localtax on product or service - $apply_tax = true; - break; - case '3': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '5': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax1_rate && $apply_tax) { - - $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount - $result[8] += $result[14]; // total_ttc_without_discount + tax1 - - $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht - $result[2] += $result[9]; // total_ttc + tax1 - - $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht - $result[5] += $result[11]; // pu_ht + tax1 - } - - $apply_tax = false; - switch($localtax2_type) { - case '1': // localtax on product or service - $apply_tax = true; - break; - case '3': // localtax on product - if ($type == 0) $apply_tax = true; - break; - case '5': // localtax on service - if ($type == 1) $apply_tax = true; - break; - } - if ($uselocaltax2_rate && $apply_tax) { - $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount - $result[8] += $result[15]; // total_ttc_without_discount + tax2 - - $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht - $result[2] += $result[10]; // total_ttc + tax2 - - $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht - $result[5] += $result[12]; // pu_ht + tax2 - } - - // If rounding is not using base 10 (rare) - if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) - { - if ($price_base_type == 'HT') - { - $result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[2]=price2num($result[0]+$result[1], 'MT'); - $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - } - else - { - $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[0]=price2num($result[2]-$result[0], 'MT'); - $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; - } - } - - //print "Price.lib::calcul_price_total ".$result[0]."-".$result[1]."-".$result[2]; - - return $result; -} - + } + $seller=$mysoc; // If seller is a customer, $seller is not provided, we use $mysoc + //var_dump($seller->country_id);exit; + } + + $countryid=$seller->country_id; + if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj; + if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj; + + // Now we search localtaxes information ourself (rates and types). + $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv"; + //$sql.= ", ".MAIN_DB_PREFIX."c_pays as cc"; + $sql.= " WHERE cv.taux = ".$txtva; + //$sql.= " AND cv.fk_pays = cc.rowid and cc.code = '".$mysoc->country_code."'"; + $sql.= " AND cv.fk_pays = ".$countryid; + dol_syslog("search vat information sql=".$sql); + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + $localtax1_rate=$obj->localtax1; + $localtax2_rate=$obj->localtax2; + $localtax1_type=$obj->localtax1_type; + $localtax2_type=$obj->localtax2_type; + //var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);exit; + } + } + else dol_print_error($db); + + // initialize total (may be HT or TTC depending on price_base_type) + $tot_sans_remise = $pu * $qty; + $tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100)); + $tot_avec_remise = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100)); + + // initialize result + for ($i=0; $i <= 15; $i++) $result[$i] = 0; + + // if there's some localtax including vat, we calculate localtaxes (we will add later) + $localtaxes = array(0,0,0); + $apply_tax = false; + switch($localtax1_type) { + case '2': // localtax on product or service + $apply_tax = true; + break; + case '4': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '6': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax1_rate && $apply_tax) { + $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); + $localtaxes[0] += $result[14]; + + $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); + $localtaxes[1] += $result[9]; + + $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); + $localtaxes[2] += $result[11]; + } + + $apply_tax = false; + switch($localtax2_type) { + case '2': // localtax on product or service + $apply_tax = true; + break; + case '4': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '6': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax2_rate && $apply_tax) { + $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); + $localtaxes[0] += $result[15]; + + $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); + $localtaxes[1] += $result[10]; + + $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); + $localtaxes[2] += $result[12]; + } + + //dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits"); + if ($price_base_type == 'HT') + { + // We work to define prices using the price without tax + $result[6] = price2num($tot_sans_remise, 'MT'); + $result[8] = price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result8bis= price2num(($tot_sans_remise + $localtaxes[0]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT'); + + $result[0] = price2num($tot_avec_remise, 'MT'); + $result[2] = price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result2bis= price2num(($tot_avec_remise + $localtaxes[1]) * (1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax) + + $result[3] = price2num($pu, 'MU'); + $result[5] = price2num(($pu + $localtaxes[2]) * (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non + $result5bis= price2num(($pu + $localtaxes[2]) * (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) + $result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU'); + } + else + { + // We work to define prices using the price with tax + $result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT'); + $result[6] = price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result6bis= price2num(($tot_sans_remise + $localtaxes[0]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT'); + + $result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT'); + $result[0] = price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non + $result0bis= price2num(($tot_avec_remise + $localtaxes[1]) / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR) + $result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - HT + + $result[5] = price2num(($pu + $localtaxes[2]), 'MU'); + $result[3] = price2num(($pu + $localtaxes[2]) / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non + $result3bis= price2num(($pu + $localtaxes[2]) / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR) + $result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU'); + } + + // if there's some localtax without vat, we calculate localtaxes (we will add them at end) + + //If price is 'TTC' we need to have the totals without VAT for a correct calculation + if ($price_base_type=='TTC') + { + $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU'); + $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU'); + $pu = price2num($pu / (1 + ($txtva / 100)),'MU'); + } + + $apply_tax = false; + switch($localtax1_type) { + case '1': // localtax on product or service + $apply_tax = true; + break; + case '3': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '5': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax1_rate && $apply_tax) { + + $result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount + $result[8] += $result[14]; // total_ttc_without_discount + tax1 + + $result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht + $result[2] += $result[9]; // total_ttc + tax1 + + $result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht + $result[5] += $result[11]; // pu_ht + tax1 + } + + $apply_tax = false; + switch($localtax2_type) { + case '1': // localtax on product or service + $apply_tax = true; + break; + case '3': // localtax on product + if ($type == 0) $apply_tax = true; + break; + case '5': // localtax on service + if ($type == 1) $apply_tax = true; + break; + } + if ($uselocaltax2_rate && $apply_tax) { + $result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount + $result[8] += $result[15]; // total_ttc_without_discount + tax2 + + $result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht + $result[2] += $result[10]; // total_ttc + tax2 + + $result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht + $result[5] += $result[12]; // pu_ht + tax2 + } + + // If rounding is not using base 10 (rare) + if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) + { + if ($price_base_type == 'HT') + { + $result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[2]=price2num($result[0]+$result[1], 'MT'); + $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + } + else + { + $result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[0]=price2num($result[2]-$result[0], 'MT'); + $result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + $result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT; + } + } + + //print "Price.lib::calcul_price_total ".$result[0]."-".$result[1]."-".$result[2]; + + return $result; +} + diff --git a/htdocs/install/mysql/tables/llx_event_element.sql b/htdocs/install/mysql/tables/llx_event_element.sql new file mode 100644 index 0000000000000000000000000000000000000000..f151cfe40992e041f02139a95de6a45cf4c4210d --- /dev/null +++ b/htdocs/install/mysql/tables/llx_event_element.sql @@ -0,0 +1,30 @@ +-- ============================================================================ +-- Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net> +-- Copyright (C) 2011 Regis Houssin <eldy@users.sourceforge.net> +-- Copyright (C) 2012 Philippe Grand <philippe.grand@atoo-net.com> +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. +-- +-- ============================================================================ +-- Table used for multi-user event +-- ============================================================================ + +create table llx_event_element +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_source integer NOT NULL, + fk_target integer NOT NULL, + targettype varchar(32) NOT NULL +) ENGINE=innodb; + diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index 047cb51dd1a2b06a565a48064a864c5ae7ed4aef..112f2c680552dfbd7f2566d0cf5cd89fc93b9371 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -180,18 +180,18 @@ class BuildDocTest extends PHPUnit_Framework_TestCase // Crabe (japanese) $newlangs1=new Translate("",$conf); $newlangs1->setDefaultLang('ja_JP'); - $localobject->modelpdf='crabe'; - $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs1); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - - // Crabe (saudiarabia) - $newlangs2a=new Translate("",$conf); - $newlangs2a->setDefaultLang('sa_SA'); - $localobject->modelpdf='crabe'; - $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs2a); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $localobject->modelpdf='crabe'; + $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs1); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + + // Crabe (saudiarabia) + $newlangs2a=new Translate("",$conf); + $newlangs2a->setDefaultLang('sa_SA'); + $localobject->modelpdf='crabe'; + $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs2a); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; // Crabe (english_saudiarabia) $newlangs2b=new Translate("",$conf); @@ -424,4 +424,4 @@ class BuildDocTest extends PHPUnit_Framework_TestCase return 0; } } -?> \ No newline at end of file +?>