diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 9d50d98e243..4b9284b06a2 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -11,6 +11,7 @@ * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2018 Frédéric France + * Copyright (C) 2020 Tobias Sekan * * 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 @@ -715,7 +716,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors'); } } - elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '') && empty($error)) // Free product. // $price_ht is already set + elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) // Free product. // $price_ht is already set { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); @@ -745,8 +746,31 @@ if (empty($reshook)) $price_base_type = 'HT'; $pu_ht_devise = price2num($price_ht_devise, 'MU'); - $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $ref_supplier, $fk_unit); - //$result = $object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options, $fk_unit); + $result = $object->addline( + $desc, + $pu_ht, + $qty, + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $idprod, + $remise_percent, + $price_base_type, + $pu_ttc, + $info_bits, + $type, + -1, // rang + 0, // special_code + GETPOST('fk_parent_line'), + $fournprice, + $buyingprice, + $label, + $array_options, + $ref_supplier, + $fk_unit, + '', // origin + 0, // origin_id + $pu_ht_devise); } @@ -839,10 +863,10 @@ if (empty($reshook)) if (GETPOST('price_ht') != '') { - $price_base_type = 'HT'; $ht = price2num(GETPOST('price_ht')); } - else + + if (GETPOST('price_ttc') != '') { $reg = array(); $vatratecleaned = $vat_rate; @@ -854,9 +878,9 @@ if (empty($reshook)) $ttc = price2num(GETPOST('price_ttc')); $ht = $ttc / (1 + ($vatratecleaned / 100)); - $price_base_type = 'HT'; } + $price_base_type = 'HT'; $pu_ht_devise = GETPOST('multicurrency_subprice'); // Add buying price diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index d1d3b08bc2d..ab451b02177 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -14,6 +14,7 @@ * Copyright (C) 2016 Ferran Marcet * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2019 Frédéric France + * Copyright (C) 2020 Tobias Sekan * * 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 @@ -595,12 +596,12 @@ class SupplierProposal extends CommonObject //var_dump($this->line->fk_fournprice);exit; // Multicurrency - $this->line->fk_multicurrency = $this->fk_multicurrency; - $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; $this->line->multicurrency_subprice = $pu_ht_devise; - $this->line->multicurrency_total_ht = $multicurrency_total_ht; - $this->line->multicurrency_total_tva = $multicurrency_total_tva; - $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; // Mise en option de la ligne if (empty($qty) && empty($special_code)) $this->line->special_code = 3; @@ -708,6 +709,10 @@ class SupplierProposal extends CommonObject $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } + if ($conf->multicurrency->enabled && $pu_ht_devise > 0) { + $pu = 0; + } + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -719,6 +724,7 @@ class SupplierProposal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; + $pu_ht_devise = $tabprice[19]; //Fetch current line from the database and then clone the object and set it in $oldline property $line = new SupplierProposalLine($this->db); @@ -784,11 +790,11 @@ class SupplierProposal extends CommonObject } } - // Multicurrency - $this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx); - $this->line->multicurrency_total_ht = $multicurrency_total_ht; - $this->line->multicurrency_total_tva = $multicurrency_total_tva; - $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + // Multicurrency + $this->line->multicurrency_subprice = $pu_ht_devise; + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; $result = $this->line->update(); if ($result > 0)