Skip to content

Commit

Permalink
Fix: wrong translation if multilang activated
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Dec 8, 2017
1 parent 2956828 commit 1bdffa9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 37 deletions.
45 changes: 32 additions & 13 deletions htdocs/comm/propal/card.php
Expand Up @@ -494,7 +494,7 @@

$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);

if ($result > 0) {
Expand Down Expand Up @@ -735,7 +735,7 @@
$db->begin();

// $tva_tx can be 'x.x (XXX)'

// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $tva_tx par celui du produit
Expand All @@ -750,7 +750,7 @@
$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
if (empty($tva_tx)) $tva_npr=0;

$pu_ht = $prod->price;
$pu_ttc = $prod->price_ttc;
$price_min = $prod->price_min;
Expand Down Expand Up @@ -791,7 +791,7 @@

$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
$tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));

// if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ?
if (! empty($price_ht)) {
$pu_ht = price2num($price_ht, 'MU');
Expand Down Expand Up @@ -844,13 +844,32 @@
// Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code)))
{
$tmptxt = '(';
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id','alpha'))
$newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt);
}
Expand Down Expand Up @@ -969,7 +988,7 @@
// Add buying price
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value

$pu_ht_devise = GETPOST('multicurrency_subprice');

$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
Expand Down Expand Up @@ -1305,7 +1324,7 @@
// Replicate extrafields
$objectsrc->fetch_optionals($originid);
$object->array_options = $objectsrc->array_options;

if (!empty($conf->multicurrency->enabled))
{
if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
Expand Down
56 changes: 38 additions & 18 deletions htdocs/commande/card.php
Expand Up @@ -49,7 +49,7 @@
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
}

require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';

$langs->load('orders');
Expand Down Expand Up @@ -112,7 +112,7 @@

if (empty($reshook))
{
if ($cancel)
if ($cancel)
{
if ($action != 'addlink' && $action != 'updateline')
{
Expand All @@ -126,7 +126,7 @@
}
$action='';
}

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once

include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
Expand Down Expand Up @@ -375,7 +375,7 @@

$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->fk_unit, $object->origin, $lines[$i]->rowid);

if ($result < 0) {
Expand Down Expand Up @@ -760,7 +760,7 @@

$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
$tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));

// if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ?
if (! empty($price_ht)) {
$pu_ht = price2num($price_ht, 'MU');
Expand All @@ -782,8 +782,8 @@
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id'))
$newlang = GETPOST('lang_id');
if (empty($newlang) && GETPOST('lang_id','alpha'))
$newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
Expand All @@ -801,12 +801,32 @@
// Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
$tmptxt = '(';
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id','alpha'))
$newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt);
}
Expand Down Expand Up @@ -2285,7 +2305,7 @@
}
print '</td></tr>';
*/

$tmparray=$object->getTotalWeightVolume();
$totalWeight=$tmparray['weight'];
$totalVolume=$tmparray['volume'];
Expand Down Expand Up @@ -2365,18 +2385,18 @@
print '<tr><td class="titlefieldmiddle">' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';

// Multicurrency Amount VAT
print '<tr><td>' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';

// Multicurrency Amount TTC
print '<tr><td>' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '</td>';
print '<td class="nowrap">' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '</td>';
print '</tr>';
}

// Total HT
print '<tr><td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
print '<td>' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td>';
Expand Down Expand Up @@ -2471,7 +2491,7 @@
}
print '</table>';
print '</div>';

print "</form>\n";

dol_fiche_end();
Expand Down
32 changes: 26 additions & 6 deletions htdocs/compta/facture.php
Expand Up @@ -1504,12 +1504,32 @@
// Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
$tmptxt = '(';
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
$outputlangs = $langs;
$newlang = '';
if (empty($newlang) && GETPOST('lang_id','alpha'))
$newlang = GETPOST('lang_id','alpha');
if (empty($newlang))
$newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
if (! empty($prod->customcode))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $outputlangs, 0);
} else {
if (! empty($prod->customcode))
$tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
if (! empty($prod->customcode) && ! empty($prod->country_code))
$tmptxt .= ' - ';
if (! empty($prod->country_code))
$tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
}
$tmptxt .= ')';
$desc = dol_concatdesc($desc, $tmptxt);
}
Expand Down

0 comments on commit 1bdffa9

Please sign in to comment.