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

Bug with accountancy import #28306

Closed
lelex86 opened this issue Feb 20, 2024 · 0 comments
Closed

Bug with accountancy import #28306

lelex86 opened this issue Feb 20, 2024 · 0 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@lelex86
Copy link
Contributor

lelex86 commented Feb 20, 2024

Bug

Hello everyone!

Trying to import some accountancy data in FEC format on Dolibarr 18.0.4 I receive this error for each line of my file: "Data truncated for column 'montant' at row 1".

Have a nice day!

Environment Version

18.0.4

Environment OS

Darwin mbpdealexandra2.home 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:59 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6030 arm64

Environment Web server

Apache/2.4.54 (Unix) OpenSSL/1.0.2u PHP/7.4.33 mod_wsgi/3.5 Python/2.7.18 mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_perl/2.0.11 Perl/v5.30.1

Environment PHP

7.4.33

Environment Database

5.7.39 mysqli (mysqlnd 7.4.33)

Environment URL(s)

No response

Expected and actual behavior

When we import a document whith everything mathing the given import format we expect that it works.

Here, I receive this error for each line of my file: "Data truncated for column 'montant' at row 1".

Steps to reproduce the behavior

Importing an XLS FEC file.

Attached files

As I look for this error source, I find bugs in method "computeAmount" in accountancyimport.class.php:

We have this line : $field_index_list = array_flip($listfields); But the $listfields don't need to be flip as it is already on the good format: $listfields[$key]=$value; where $key is the field name like debit or credit and $value is an int matching the index for the $arrayrecord[index]['val'].

The second error is that in $listfields the indexes are all like b.something. Therefore, $listfield['debit'] must be change in $listfield['b.debit'];

With these things changed, the import work well.

Here is the corrected code :

/**
* Compute amount
*
* @param array $arrayrecord Array of read values: [fieldpos] => (['val']=>val, ['type']=>-1=null,0=blank,1=string), [fieldpos+1]...
* @param array $listfields Fields list to add
* @param int $record_key Record key
* @return mixed Value
*/
public function computeAmount(&$arrayrecord, $listfields, $record_key)
{
// get fields indexes
if (isset($listfields['b.debit']) && isset($listfields['b.credit'])) {
$debit_index = $listfields['b.debit'];
$credit_index = $listfields['b.credit'];

		$debit  = floatval($arrayrecord[$debit_index]['val']);
		$credit = floatval($arrayrecord[$credit_index]['val']);
		if (!empty($debit)) {
			$amount = $debit;
		} else {
			$amount = $credit;
		}

		return "'" . $this->db->escape(abs($amount)) . "'";
	}

	return "''";
}
@lelex86 lelex86 added the Bug This is a bug (something does not work as expected) label Feb 20, 2024
lvessiller-opendsi added a commit to Easya-Solutions/dolibarr that referenced this issue Apr 19, 2024
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