Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.46k stars 2.79k forks source link

Multicurrency U.P (net) (currency) update error #22948

Closed palexandri closed 8 months ago

palexandri commented 1 year ago

Bug

When updating the U.P (net) (currency) in a purchase order, there is an error in htdocs/fourn/commande/card.php:778 The reason is that price_ttc is not set and line 778 tries to divide the vat rate with an empty number. I would suggest to add elseif (GETPOST('price_ttc') != '') in line 769 in place of the else. This solves the issue.

Environment Version

16

Environment OS

ubuntu 22.04

Environment Web server

nginx

Environment PHP

8

Environment Database

MariaDB

Environment URL(s)

No response

Expected and actual behavior

No response

Steps to reproduce the behavior

No response

Attached files

No response

bafbes commented 1 year ago

I couldn't find any error in this page When updating the U.P. Can you send an example with errors ?

palexandri commented 1 year ago

The issue is present only when using multi currency and only when updating the U.P (net) (currency). Creation works fine. Method to reproduce.

  1. Create a new PO in a currency other than the default
  2. Create a new item line by inserting a value in the U.P (net) (currency) and selecting add εικόνα
  3. The line is inserted successfully. Try to modify this line by changing the U.P (net) (currency) value εικόνα
  4. A blank screen appears

The nginx logs state: PHP message: PHP Fatal error: Uncaught TypeError: Unsupported operand types: string / int in /var/www/dolibarr/htdocs/fourn/commande/card.php:778 The reason is that neither price_ht or price_ttc are set in the post since they are cleared when changing the U.P (net) (currency). Only the multicurrency_subprice is set. To avoid the error, one can replace the line 769 with this: } elseif (GETPOST('price_ttc') != '') {

ksar-ksar commented 1 year ago

Same error here : https://www.dolibarr.org/forum/t/http-error-500-when-modifying-product-price-in-multi-currency/23100

bafbes commented 1 year ago

I could not reproduce the error in php 8.1 nor in php 7.2

palexandri commented 1 year ago

I could not reproduce the error in php 8.1 nor in php 7.2

Are price_ht and price_ttc being posted when modifying U.P (net) (currency). Because in my case they are not and this is not relevant to the php version. I can dig deeper in the code and find the reason for this in the future.

edupulpillo commented 1 year ago

I also could not reproduce the problem using multicurrency and Dolibarr 16.0.3 and PHP 7.4.33 (Supplier Purchase orders)

vrmaurice commented 1 year ago

Line 1073 in /commande/card.php modified to

if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && ((float)price2num($pu_ht) * (1 - $remise_percent / 100) < (float)price2num($price_min)))) {

casting price2num to float solved the problem for me. Any comments?

ksar-ksar commented 1 year ago

The main issue, I think, is that, $pu_ht or $price_min are string and not numbers...

vrmaurice commented 1 year ago

I also could not reproduce the problem using multicurrency and Dolibarr 16.0.3 and PHP 7.4.33 (Supplier Purchase orders)

The problem occurs on PHP 8.0

vrmaurice commented 1 year ago

The main issue, I think, is that, $pu_ht or $price_min are string and not numbers...

There is indeed another problem with $pu_ht as well.

When in multi currency starting a new order and adding a product. then add a price in the second currency, it wont take the value entered and give following warning :

Warning: Undefined variable $pu_ht_devise in /customers/3/3/0/metron-technics.be/httpd.www/erp/htdocs/commande/card.php on line 953 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/3/0/

line 953 in Commane/card.php $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise);

vrmaurice commented 1 year ago

Line 1073 in /commande/card.php modified to

if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && ((float)price2num($pu_ht) * (1 - $remise_percent / 100) < (float)price2num($price_min)))) {

casting price2num to float solved the problem for me. Any comments?

After the above partial fix now the problem is as follows: Creating a new line in the sales order with second currency activated AND entering the price in that second currency will result in the Amount entered in the second currency not being saved (Multicurrency_price_HT not saved). values are all 00 (zero) Modifying the price in the second currency in that saved line will result in the value being saved (Multicurrency_subprice). Entering a new product line and fill in the price in original currency will be saved.

ksar-ksar commented 1 year ago

Hello,

It is still the case with V18 ?