dolibarr  18.0.0-alpha
accountancyimport.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8  * Copyright (C) 2016-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
10  * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
11  * Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
13  * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
41 {
45  public $db;
46 
47 
53  public function __construct(DoliDB $db)
54  {
55  $this->db = $db;
56  }
57 
66  public function cleanAmount(&$arrayrecord, $listfields, $record_key)
67  {
68  $value_trim = trim($arrayrecord[$record_key]['val']);
69  return floatval($value_trim);
70  }
71 
80  public function cleanValue(&$arrayrecord, $listfields, $record_key)
81  {
82  return trim($arrayrecord[$record_key]['val']);
83  }
84 
93  public function computeAmount(&$arrayrecord, $listfields, $record_key)
94  {
95  // get fields indexes
96  $field_index_list = array_flip($listfields);
97  if (isset($field_index_list['debit']) && isset($field_index_list['credit'])) {
98  $debit_index = $field_index_list['debit'];
99  $credit_index = $field_index_list['credit'];
100 
101  $debit = floatval($arrayrecord[$debit_index]['val']);
102  $credit = floatval($arrayrecord[$credit_index]['val']);
103  if (!empty($debit)) {
104  $amount = $debit;
105  } else {
106  $amount = $credit;
107  }
108 
109  return "'" . $this->db->escape(abs($amount)) . "'";
110  }
111 
112  return "''";
113  }
114 
115 
124  public function computeDirection(&$arrayrecord, $listfields, $record_key)
125  {
126  $field_index_list = array_flip($listfields);
127  if (isset($field_index_list['debit'])) {
128  $debit_index = $field_index_list['debit'];
129 
130  $debit = floatval($arrayrecord[$debit_index]['val']);
131  if (!empty($debit)) {
132  $sens = 'D';
133  } else {
134  $sens = 'C';
135  }
136 
137  return "'" . $this->db->escape($sens) . "'";
138  }
139 
140  return "''";
141  }
142 }
db
$conf db
API class for accounts.
Definition: inc.php:41
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
AccountancyImport\computeAmount
computeAmount(&$arrayrecord, $listfields, $record_key)
Compute amount.
Definition: accountancyimport.class.php:93
AccountancyImport\cleanAmount
cleanAmount(&$arrayrecord, $listfields, $record_key)
Clean amount.
Definition: accountancyimport.class.php:66
AccountancyImport
Manage the different format accountancy import.
Definition: accountancyimport.class.php:40
AccountancyImport\cleanValue
cleanValue(&$arrayrecord, $listfields, $record_key)
Clean value with trim.
Definition: accountancyimport.class.php:80
AccountancyImport\__construct
__construct(DoliDB $db)
Constructor.
Definition: accountancyimport.class.php:53
AccountancyImport\computeDirection
computeDirection(&$arrayrecord, $listfields, $record_key)
Compute direction.
Definition: accountancyimport.class.php:124