1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2005 Rodolphe Quiedeville <[email protected]> |
4
|
|
|
* Copyright (C) 2005-2009 Regis Houssin <[email protected]> |
5
|
|
|
* Copyright (C) 2010-2011 Juanjo Menent <[email protected]> |
6
|
|
|
* Copyright (C) 2015 Marcos García <[email protected]> |
7
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Dolibarr\Code\Compta\Classes; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* \file htdocs/compta/prelevement/class/ligneprelevement.class.php |
28
|
|
|
* \ingroup prelevement |
29
|
|
|
* \brief File of class to manage lines of Direct Debit orders |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class to manage withdrawals |
35
|
|
|
*/ |
36
|
|
|
class LignePrelevement |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var int ID |
40
|
|
|
*/ |
41
|
|
|
public $id; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var float Amount |
45
|
|
|
*/ |
46
|
|
|
public $amount; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var int Socid |
50
|
|
|
*/ |
51
|
|
|
public $socid; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int Status of the line |
55
|
|
|
*/ |
56
|
|
|
public $statut; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string Ref of bon |
60
|
|
|
*/ |
61
|
|
|
public $bon_ref; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var int ID of bon |
65
|
|
|
*/ |
66
|
|
|
public $bon_rowid; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var DoliDB Database handler. |
|
|
|
|
70
|
|
|
*/ |
71
|
|
|
public $db; |
72
|
|
|
|
73
|
|
|
public $labelStatus = array(); |
74
|
|
|
|
75
|
|
|
const STATUS_DRAFT = 0; |
76
|
|
|
const STATUS_NOT_USED = 1; |
77
|
|
|
const STATUS_CREDITED = 2; // STATUS_CREDITED and STATUS_DEBITED is same. Difference is in ->type |
78
|
|
|
const STATUS_DEBITED = 2; // STATUS_CREDITED and STATUS_DEBITED is same. Difference is in ->type |
79
|
|
|
const STATUS_REJECTED = 3; |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Constructor |
84
|
|
|
* |
85
|
|
|
* @param DoliDB $db Database handler |
86
|
|
|
*/ |
87
|
|
|
public function __construct($db) |
88
|
|
|
{ |
89
|
|
|
global $conf, $langs; |
90
|
|
|
|
91
|
|
|
$this->db = $db; |
92
|
|
|
|
93
|
|
|
// List of language codes for status |
94
|
|
|
|
95
|
|
|
$langs->load("withdrawals"); |
96
|
|
|
$this->labelStatus[0] = $langs->trans("StatusWaiting"); |
97
|
|
|
$this->labelStatus[2] = $langs->trans("StatusPaid"); |
98
|
|
|
$this->labelStatus[3] = $langs->trans("StatusRefused"); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Recupere l'objet prelevement |
103
|
|
|
* |
104
|
|
|
* @param int $rowid Id de la facture a recuperer |
105
|
|
|
* @return integer Return integer <0 if KO, >=0 if OK |
106
|
|
|
*/ |
107
|
|
|
public function fetch($rowid) |
108
|
|
|
{ |
109
|
|
|
global $conf; |
110
|
|
|
|
111
|
|
|
$error = 0; |
112
|
|
|
|
113
|
|
|
$sql = "SELECT pl.rowid, pl.amount, p.ref, p.rowid as bon_rowid"; |
114
|
|
|
$sql .= ", pl.statut, pl.fk_soc"; |
115
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_lignes as pl"; |
116
|
|
|
$sql .= ", " . MAIN_DB_PREFIX . "prelevement_bons as p"; |
117
|
|
|
$sql .= " WHERE pl.rowid=" . ((int) $rowid); |
118
|
|
|
$sql .= " AND p.rowid = pl.fk_prelevement_bons"; |
119
|
|
|
$sql .= " AND p.entity = " . $conf->entity; |
120
|
|
|
|
121
|
|
|
$resql = $this->db->query($sql); |
122
|
|
|
if ($resql) { |
123
|
|
|
if ($this->db->num_rows($resql)) { |
124
|
|
|
$obj = $this->db->fetch_object($resql); |
125
|
|
|
|
126
|
|
|
$this->id = $obj->rowid; |
127
|
|
|
$this->amount = $obj->amount; |
128
|
|
|
$this->socid = $obj->fk_soc; |
129
|
|
|
$this->statut = $obj->statut; |
130
|
|
|
$this->bon_ref = $obj->ref; |
131
|
|
|
$this->bon_rowid = $obj->bon_rowid; |
132
|
|
|
} else { |
133
|
|
|
$error++; |
134
|
|
|
dol_syslog("LignePrelevement::Fetch rowid=$rowid numrows=0"); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$this->db->free($resql); |
138
|
|
|
} else { |
139
|
|
|
$error++; |
140
|
|
|
dol_syslog("LignePrelevement::Fetch rowid=$rowid"); |
141
|
|
|
dol_syslog($this->db->error()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $error; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Return status label of object |
149
|
|
|
* |
150
|
|
|
* @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto |
151
|
|
|
* @return string Label |
152
|
|
|
*/ |
153
|
|
|
public function getLibStatut($mode = 0) |
154
|
|
|
{ |
155
|
|
|
return $this->LibStatut($this->statut, $mode); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
159
|
|
|
/** |
160
|
|
|
* Return status label for a status |
161
|
|
|
* |
162
|
|
|
* @param int $status Id status |
163
|
|
|
* @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto |
164
|
|
|
* @return null|string Return status label (or null if $mode != 0, 1, 2, 3 or 4) |
165
|
|
|
*/ |
166
|
|
|
public function LibStatut($status, $mode = 0) |
167
|
|
|
{ |
168
|
|
|
// phpcs:enable |
169
|
|
|
global $langs; |
170
|
|
|
|
171
|
|
|
if ($mode == 0) { |
172
|
|
|
return $langs->trans($this->labelStatus[$status]); |
173
|
|
|
} elseif ($mode == 1) { |
174
|
|
|
if ($status == 0) { |
175
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut1', 'class="valignmiddle"') . ' ' . $langs->transnoentitiesnoconv($this->labelStatus[$status]); // Waiting |
176
|
|
|
} elseif ($status == 2) { |
177
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut6', 'class="valignmiddle"') . ' ' . $langs->transnoentitiesnoconv($this->labelStatus[$status]); // Credited |
178
|
|
|
} elseif ($status == 3) { |
179
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut8', 'class="valignmiddle"') . ' ' . $langs->transnoentitiesnoconv($this->labelStatus[$status]); // Refused |
180
|
|
|
} |
181
|
|
|
} elseif ($mode == 2) { |
182
|
|
|
if ($status == 0) { |
183
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut1', 'class="valignmiddle"'); |
184
|
|
|
} elseif ($status == 2) { |
185
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut6', 'class="valignmiddle"'); |
186
|
|
|
} elseif ($status == 3) { |
187
|
|
|
return img_picto($langs->trans($this->labelStatus[$status]), 'statut8', 'class="valignmiddle"'); |
188
|
|
|
} |
189
|
|
|
} elseif ($mode == 3) { |
190
|
|
|
if ($status == 0) { |
191
|
|
|
return $langs->trans($this->labelStatus[$status]) . ' ' . img_picto($langs->transnoentitiesnoconv($this->labelStatus[$status]), 'statut1', 'class="valignmiddle"'); |
192
|
|
|
} elseif ($status == 2) { |
193
|
|
|
return $langs->trans($this->labelStatus[$status]) . ' ' . img_picto($langs->transnoentitiesnoconv($this->labelStatus[$status]), 'statut6', 'class="valignmiddle"'); |
194
|
|
|
} elseif ($status == 3) { |
195
|
|
|
return $langs->trans($this->labelStatus[$status]) . ' ' . img_picto($langs->transnoentitiesnoconv($this->labelStatus[$status]), 'statut8', 'class="valignmiddle"'); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
// return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
199
|
|
|
return null; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Function used to replace a thirdparty id with another one. |
204
|
|
|
* |
205
|
|
|
* @param DoliDB $dbs Database handler, because function is static we name it $dbs not $db to avoid breaking coding test |
206
|
|
|
* @param int $origin_id Old thirdparty id |
207
|
|
|
* @param int $dest_id New thirdparty id |
208
|
|
|
* @return bool |
209
|
|
|
*/ |
210
|
|
|
public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id) |
211
|
|
|
{ |
212
|
|
|
$tables = array( |
213
|
|
|
'prelevement_lignes' |
214
|
|
|
); |
215
|
|
|
|
216
|
|
|
return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|