1

My civicrm instance has been running for a few years now. Since a couple of weeks ago I cannot add contributions anymore if their total amount contains decimal points. Due to my German locales I use the comma characters as a decimal delimiter.

Adding a contribution of 20,00 Euros works fine.
Adding a contribution of 20,99 Euros does not work.

When adding contributions over the standard civi frontend
If a add a contribution of 20,99 over the standard gui and click "save", then the hourglass appears and will never disappear. Nothing else happens. Nothing gets written to the db and no php or javascript errors get reported.

When adding contributions over API v3
My API Call (PHP Style):

$result = civicrm_api3('Contribution', 'create', [
      'financial_type_id' => "Spende",
      'receive_date' => "2022-03-20",
      'total_amount' => "20,99",
      'contact_id' => 399,
    ]);

After exection an error message appears: "DB Error: value count on row". Nothing is written to the database. The underlying sql:

INSERT INTO `civicrm_contribution` (`contact_id` , `financial_type_id` , `payment_instrument_id` , 
`receive_date` , `total_amount` , `fee_amount` , `net_amount` , 
`currency` , `contribution_status_id` , `check_number` , `tax_amount` ) 
VALUES ( 399 ,  1 ,  5 ,  20220320000000 ,  20.99 ,  0 ,  20,99 , 'EUR' ,  1 ,  
NULL ,  0 );

The SQL error is fairly obvious: the value of net_amount is basically a copy of total_amount. But while total_amount has been correctly formatted to "20.99" in the sql, the value of net_amount has been formatted as "20,99", so the comma is interpreted as an sql value delimiter. But why is a wrong formatting used?

When adding contributions over API v4
The call

$results = civicrm_api4('Contribution', 'create', [
  'values' => [
    'contact_id' => 399, 
    'financial_type_id' => 1, 
    'receive_date' => '2022-03-01', 
    'total_amount' => '20,99',
  ],
]);

results in a warning: "Formatting non-numeric values is no longer supported: 20,99 Caller: CRM_Utils_Money::format". The contribution is written to the db - but as "20.00", so the 99 Cents are missing.

Localization and system setup

  • CiviCrm 5.47.2
    as a wordpress plugin
    Formatting locale: Deutsch (German)
    Thousands Separator: .
    Decimal Delimiter: ,
  • Plugin for Wordpress 5.8.3
    language: German
  • Php 7.4
  • Nginx 1.14
  • ubuntu 18.04
    set to de_DE.UTF-8

Any advice on how to fix this would be greatly appreciated!

3
  • Welcome to SE! You have provided a lot of detail, but you say the problem started a couple of weeks ago, so something must have changed at that time (perhap something upgraded) if it was working correctly before then. I'd explore that as the next step in diagnosis.
    – Mick Kahn
    Commented Mar 20, 2022 at 17:58
  • The problem is with net_amount which is not formatted correctly. Could you check your localization setting? Commented Mar 20, 2022 at 19:31
  • Thank you both! Mick Kahn: I ran several updates on wordpress and civicrm, but I made no changes to the ubuntu/nginx/php settings. @Pradeep Nayak: I am not sure I get your question right. I set both Wordpress and CiviCRM to German. In a standalone-php-script (run outside Wordpress), locale_get_default() leads to "de_DE.utf-8". However localeconv() leads to decimal_point: "." and mon_decimal_point: "".
    – Steve
    Commented Mar 22, 2022 at 20:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.