Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
palexandri opened this issue Nov 24, 2022 · 12 comments
Closed

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

palexandri opened this issue Nov 24, 2022 · 12 comments
Labels
Bug need more information This bug needs more information to be processed

Comments

@palexandri
Copy link

palexandri commented Nov 24, 2022

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

@palexandri palexandri added the Bug This is a bug (something does not work as expected) label Nov 24, 2022
@bafbes bafbes added DevCamp 2022 Nantes Discussion Some questions or discussions are opened and wait answers of author or other people to be processed labels Nov 25, 2022
@bafbes
Copy link
Contributor

bafbes commented Nov 25, 2022

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

@bafbes bafbes added the Works for me / Can't reproduce It seems not possible to reproduce the bug. label Nov 25, 2022
@palexandri
Copy link
Author

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
Copy link
Contributor

@ksar-ksar ksar-ksar removed Discussion Some questions or discussions are opened and wait answers of author or other people to be processed Works for me / Can't reproduce It seems not possible to reproduce the bug. DevCamp 2022 Nantes labels Nov 30, 2022
@bafbes
Copy link
Contributor

bafbes commented Dec 1, 2022

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

@palexandri
Copy link
Author

palexandri commented Dec 1, 2022

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
Copy link

edupulpillo commented Dec 21, 2022

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

@vrmaurice
Copy link

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
Copy link
Contributor

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

@vrmaurice
Copy link

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
Copy link

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
Copy link

vrmaurice commented Feb 16, 2023

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
Copy link
Contributor

Hello,

It is still the case with V18 ?

@ksar-ksar ksar-ksar added Bug need more information This bug needs more information to be processed and removed Bug This is a bug (something does not work as expected) labels Oct 18, 2023
PsyCrow-code added a commit to PsyCrow-code/dolibarr that referenced this issue Mar 3, 2024
@eldy eldy closed this as completed in a26d81a Mar 3, 2024
eldy pushed a commit that referenced this issue Mar 3, 2024
* Update facture.class.php

FIX  #22948

* Update facture.class.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug need more information This bug needs more information to be processed
Projects
None yet
Development

No branches or pull requests

5 participants