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

If VATIsNotUsed = true, Add value to CustomerAbsoluteDiscount gives error. #29306

Closed
mikko80 opened this issue Apr 10, 2024 · 13 comments
Closed
Labels
Bug This is a bug (something does not work as expected)

Comments

@mikko80
Copy link
Contributor

mikko80 commented Apr 10, 2024

Bug

If VATIsNotUsed = true, Adding value to CustomerAbsoluteDiscount not working. It gives error.
Fatal error: Uncaught TypeError: Unsupported operand types: string * string in /societe/class/societe.class.php:2435 Stack trace: #0 /comm/remx.php(182): Societe->set_remise_except('80', Object(User), 'Testi', '', '0', 'HT') #1 {main} thrown in /societe/class/societe.class.php on line 2435

Dolibarr Version

19.0.1

Environment PHP

8.2.16

Environment Database

10.3.39-MariaDB, mysqli (mysqlnd 8.2.16)

Steps to reproduce the behavior and expected behavior

In invoices or third party try to add absolute discount values.

Attached files

No response

@mikko80 mikko80 added the Bug This is a bug (something does not work as expected) label Apr 10, 2024
@mikko80
Copy link
Contributor Author

mikko80 commented Apr 10, 2024

ADD: societe.class.php:
// Check parameters
.....
line 2412->
if (empty($vatrate)) {
$vatrate = '0 (0%)';
}

@JonBendtsen
Copy link
Contributor

JonBendtsen commented Apr 10, 2024

ADD: societe.class.php: // Check parameters ..... line 2412-> if (empty($vatrate)) { $vatrate = '0 (0%)'; }

that is one method. I was thinking of, this change

-       public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0, $price_base_type = 'HT')
+       public function set_remise_except($remise, User $user, $desc, $vatrate = 0, $discount_type = 0, $price_base_type = 'HT')

but I don't know which is correct?

Which appears to be working?
image

@JonBendtsen
Copy link
Contributor

seems to work irregardless of choosing with or without tax (and when sales tax set to * not used in the configuration

image

image

@JonBendtsen
Copy link
Contributor

this works as well

-       public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0, $price_base_type = 'HT')
+       public function set_remise_except($remise, User $user, $desc, $vatrate = '0 (0%)', $discount_type = 0, $price_base_type = 'HT')

@JonBendtsen
Copy link
Contributor

@mikko80 I wonder if it should be a string or a float?

JonSweet16:htdocs jonbendtsen$ grep -ir -e '(string) $tva_tx'
./fourn/class/fournisseur.facture-rec.class.php:					if (!empty($facfourn_src->lines[$i]->vat_src_code) && !preg_match('/\(/', (string) $tva_tx)) {
./compta/facture/class/facture-rec.class.php:					if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\(/', (string) $tva_tx)) {
JonSweet16:htdocs jonbendtsen$ grep -ir -e '(float) $tva_tx'
./fourn/facture/card.php:					$discount->tva_tx = abs((float) $tva_tx);
./fourn/facture/card.php:				$pu_ht = price2num((float) $pu_ttc / (1 + ((float) $tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
./compta/facture/card.php:					$discount->tva_tx = abs((float) $tva_tx);
./societe/price.php:				$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/card.php:				$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:					$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:					$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:				$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:				$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
./product/price.php:			$sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; 

@JonBendtsen
Copy link
Contributor

yeah, being a float works too

-       public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0, $price_base_type = 'HT')
+       public function set_remise_except($remise, User $user, $desc, $vatrate = 0.0, $discount_type = 0, $price_base_type = 'HT')

@JonBendtsen
Copy link
Contributor

@mikko80 maybe the best thing would be to set the rate to 0 when one has selected not to use sales tax?

@mikko80
Copy link
Contributor Author

mikko80 commented Apr 11, 2024

@JonBendtsen Yes. I think also the best is 0 It works regardless of the user's language and the abbreviation used for VAT.
But I did some test and did not get working that what you suggested there, when VATIsNotUsed = true

Maybe this is better solution?
if ($this->id > 0) {
// Clean vat code
$reg = array();
$vat_src_code = '';
if (preg_match('/((.))/', $vatrate, $reg)) {
$vat_src_code = $reg[1];
$vatrate = preg_replace('/\s
(.*)/', '', $vatrate); // Remove code into vatrate.
}
else {
$vatrate = 0;
}

@JonBendtsen
Copy link
Contributor

@JonBendtsen Yes. I think also the best is 0 It works regardless of the user's language and the abbreviation used for VAT. But I did some test and did not get working that what you suggested there, when VATIsNotUsed = true

I am not sure I used that variable, what I did was, because I am using Dolibarr solely for a non profit dance organisation

image

@mikko80
Copy link
Contributor Author

mikko80 commented Apr 11, 2024

@JonBendtsen Hmm. What php/doli version you tested?

@JonBendtsen
Copy link
Contributor

Primarily 19, but some files are from develop

@JonBendtsen
Copy link
Contributor

@mikko80 Your fix seems to be merged, so I suppose this issue can be closed?

@mikko80
Copy link
Contributor Author

mikko80 commented Sep 12, 2024

FIX V20 Update societe.class.php FIX#29306 #30939

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

2 participants