dolibarr 18.0.6
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 if (isset($listfields['b.debit']) && isset($listfields['b.credit'])) {
97 $debit_index = $listfields['b.debit'];
98 $credit_index = $listfields['b.credit'];
99
100 $debit = floatval($arrayrecord[$debit_index]['val']);
101 $credit = floatval($arrayrecord[$credit_index]['val']);
102 if (!empty($debit)) {
103 $amount = $debit;
104 } else {
105 $amount = $credit;
106 }
107
108 return "'" . $this->db->escape(abs($amount)) . "'";
109 }
110
111 return "''";
112 }
113
114
123 public function computeDirection(&$arrayrecord, $listfields, $record_key)
124 {
125 if (isset($listfields['b.debit'])) {
126 $debit_index = $listfields['b.debit'];
127
128 $debit = floatval($arrayrecord[$debit_index]['val']);
129 if (!empty($debit)) {
130 $sens = 'D';
131 } else {
132 $sens = 'C';
133 }
134
135 return "'" . $this->db->escape($sens) . "'";
136 }
137
138 return "''";
139 }
140}
Manage the different format accountancy import.
computeAmount(&$arrayrecord, $listfields, $record_key)
Compute amount.
cleanAmount(&$arrayrecord, $listfields, $record_key)
Clean amount.
cleanValue(&$arrayrecord, $listfields, $record_key)
Clean value with trim.
computeDirection(&$arrayrecord, $listfields, $record_key)
Compute direction.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.