Total Complexity | 92 |
Total Lines | 755 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like PaymentVAT often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PaymentVAT, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | */ |
||
37 | class PaymentVAT extends CommonObject |
||
38 | { |
||
39 | /** |
||
40 | * @var string ID to identify managed object |
||
41 | */ |
||
42 | public $element = 'payment_vat'; |
||
43 | |||
44 | /** |
||
45 | * @var string Name of table without prefix where object is stored |
||
46 | */ |
||
47 | public $table_element = 'payment_vat'; |
||
48 | |||
49 | /** |
||
50 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
51 | */ |
||
52 | public $picto = 'payment'; |
||
53 | |||
54 | /** |
||
55 | * @var int ID |
||
56 | */ |
||
57 | public $fk_tva; |
||
58 | |||
59 | public $datec = ''; |
||
60 | |||
61 | public $datep = ''; |
||
62 | |||
63 | /** |
||
64 | * @deprecated Use $amount instead |
||
65 | * @see $amount |
||
66 | * @var float|int |
||
67 | */ |
||
68 | public $total; |
||
69 | |||
70 | /** |
||
71 | * @var float|int |
||
72 | */ |
||
73 | public $amount; // Total amount of payment |
||
74 | |||
75 | /** |
||
76 | * @var array<float|int> |
||
77 | */ |
||
78 | public $amounts = array(); // Array of amounts |
||
79 | |||
80 | /** |
||
81 | * @var int ID |
||
82 | */ |
||
83 | public $fk_typepaiement; |
||
84 | |||
85 | /** |
||
86 | * @var string |
||
87 | * @deprecated Use $num_payment instead |
||
88 | * @see $num_payment |
||
89 | */ |
||
90 | public $num_paiement; |
||
91 | |||
92 | /** |
||
93 | * @var string Payment reference |
||
94 | * (Cheque or bank transfer reference. Can be "ABC123") |
||
95 | */ |
||
96 | public $num_payment; |
||
97 | |||
98 | /** |
||
99 | * @var int ID |
||
100 | */ |
||
101 | public $fk_bank; |
||
102 | |||
103 | /** |
||
104 | * @var int ID |
||
105 | */ |
||
106 | public $fk_user_creat; |
||
107 | |||
108 | /** |
||
109 | * @var int ID |
||
110 | */ |
||
111 | public $fk_user_modif; |
||
112 | |||
113 | /** |
||
114 | * @var int ID |
||
115 | */ |
||
116 | public $chid; |
||
117 | |||
118 | /** |
||
119 | * @var string lib |
||
120 | * @deprecated |
||
121 | * @see $label |
||
122 | */ |
||
123 | public $lib; |
||
124 | |||
125 | /** |
||
126 | * @var integer|string datepaye |
||
127 | */ |
||
128 | public $datepaye; |
||
129 | |||
130 | /** |
||
131 | * @var string |
||
132 | */ |
||
133 | public $type_code; |
||
134 | |||
135 | /** |
||
136 | * @var string |
||
137 | */ |
||
138 | public $type_label; |
||
139 | |||
140 | /** |
||
141 | * @var int |
||
142 | */ |
||
143 | public $bank_account; |
||
144 | |||
145 | /** |
||
146 | * @var int |
||
147 | */ |
||
148 | public $bank_line; |
||
149 | |||
150 | /** |
||
151 | * @var integer|string paiementtype |
||
152 | */ |
||
153 | public $paiementtype; |
||
154 | |||
155 | /** |
||
156 | * Constructor |
||
157 | * |
||
158 | * @param DoliDB $db Database handler |
||
|
|||
159 | */ |
||
160 | public function __construct($db) |
||
161 | { |
||
162 | $this->db = $db; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Create payment of vat into database. |
||
167 | * Use this->amounts to have list of lines for the payment |
||
168 | * |
||
169 | * @param User $user User making payment |
||
170 | * @param int $closepaidvat 1=Also close paid contributions to paid, 0=Do nothing more |
||
171 | * @return int Return integer <0 if KO, id of payment if OK |
||
172 | */ |
||
173 | public function create($user, $closepaidvat = 0) |
||
174 | { |
||
175 | $error = 0; |
||
176 | |||
177 | $now = dol_now(); |
||
178 | |||
179 | dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
||
180 | |||
181 | // Validate parameters |
||
182 | if (!$this->datepaye) { |
||
183 | $this->error = 'ErrorBadValueForParameterCreatePaymentVAT'; |
||
184 | return -1; |
||
185 | } |
||
186 | |||
187 | // Clean parameters |
||
188 | if (isset($this->fk_tva)) { |
||
189 | $this->fk_tva = (int) $this->fk_tva; |
||
190 | } |
||
191 | if (isset($this->amount)) { |
||
192 | $this->amount = (float) $this->amount; |
||
193 | } |
||
194 | if (isset($this->fk_typepaiement)) { |
||
195 | $this->fk_typepaiement = (int) $this->fk_typepaiement; |
||
196 | } |
||
197 | if (isset($this->num_paiement)) { |
||
198 | $this->num_paiement = trim($this->num_paiement); // deprecated |
||
199 | } |
||
200 | if (isset($this->num_payment)) { |
||
201 | $this->num_payment = trim($this->num_payment); |
||
202 | } |
||
203 | if (isset($this->note)) { |
||
204 | $this->note = trim($this->note); |
||
205 | } |
||
206 | if (isset($this->fk_bank)) { |
||
207 | $this->fk_bank = (int) $this->fk_bank; |
||
208 | } |
||
209 | if (isset($this->fk_user_creat)) { |
||
210 | $this->fk_user_creat = (int) $this->fk_user_creat; |
||
211 | } |
||
212 | if (isset($this->fk_user_modif)) { |
||
213 | $this->fk_user_modif = (int) $this->fk_user_modif; |
||
214 | } |
||
215 | |||
216 | $totalamount = 0; |
||
217 | foreach ($this->amounts as $key => $value) { // How payment is dispatch |
||
218 | $newvalue = (float) price2num($value, 'MT'); |
||
219 | $this->amounts[$key] = $newvalue; |
||
220 | $totalamount += $newvalue; |
||
221 | } |
||
222 | // $totalamount = price2num($totalamount); |
||
223 | |||
224 | // Check parameters |
||
225 | if ($totalamount == 0) { |
||
226 | return -1; // We accept negative amounts for chargebacks, but not null amounts. |
||
227 | } |
||
228 | |||
229 | |||
230 | $this->db->begin(); |
||
231 | |||
232 | if ($totalamount != 0) { |
||
233 | $sql = "INSERT INTO " . MAIN_DB_PREFIX . "payment_vat (fk_tva, datec, datep, amount,"; |
||
234 | $sql .= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; |
||
235 | $sql .= " VALUES ($this->chid, '" . $this->db->idate($now) . "',"; |
||
236 | $sql .= " '" . $this->db->idate($this->datepaye) . "',"; |
||
237 | $sql .= " " . ((float) $totalamount) . ","; |
||
238 | $sql .= " " . ((int) $this->paiementtype) . ", '" . $this->db->escape($this->num_payment) . "', '" . $this->db->escape($this->note) . "', " . $user->id . ","; |
||
239 | $sql .= " 0)"; |
||
240 | |||
241 | $resql = $this->db->query($sql); |
||
242 | if ($resql) { |
||
243 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "payment_vat"); |
||
244 | |||
245 | // Insert table of amounts / invoices |
||
246 | foreach ($this->amounts as $key => $amount) { |
||
247 | $contribid = $key; |
||
248 | if (is_numeric($amount) && $amount != 0) { |
||
249 | $amount = (float) price2num($amount); |
||
250 | |||
251 | // If we want to closed paid invoices |
||
252 | if ($closepaidvat) { |
||
253 | $contrib = new Tva($this->db); |
||
254 | $contrib->fetch($contribid); |
||
255 | $paiement = $contrib->getSommePaiement(); |
||
256 | //$creditnotes=$contrib->getSumCreditNotesUsed(); |
||
257 | $creditnotes = 0; |
||
258 | //$deposits=$contrib->getSumDepositsUsed(); |
||
259 | $deposits = 0; |
||
260 | $alreadypayed = (float) price2num($paiement + $creditnotes + $deposits, 'MT'); |
||
261 | $remaintopay = (float) price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); |
||
262 | if ($remaintopay == 0) { |
||
263 | $result = $contrib->setPaid($user); |
||
264 | } else { |
||
265 | dol_syslog("Remain to pay for conrib " . $contribid . " not null. We do nothing."); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | } else { |
||
271 | $error++; |
||
272 | } |
||
273 | } |
||
274 | |||
275 | $result = $this->call_trigger('PAYMENTVAT_CREATE', $user); |
||
276 | if ($result < 0) { |
||
277 | $error++; |
||
278 | } |
||
279 | |||
280 | if ($totalamount != 0 && !$error) { |
||
281 | $this->amount = $totalamount; |
||
282 | $this->total = $totalamount; // deprecated |
||
283 | $this->db->commit(); |
||
284 | return $this->id; |
||
285 | } else { |
||
286 | $this->error = $this->db->error(); |
||
287 | $this->db->rollback(); |
||
288 | return -1; |
||
289 | } |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * Load object in memory from database |
||
294 | * |
||
295 | * @param int $id Id object |
||
296 | * @return int Return integer <0 if KO, >0 if OK |
||
297 | */ |
||
298 | public function fetch($id) |
||
299 | { |
||
300 | $sql = "SELECT"; |
||
301 | $sql .= " t.rowid,"; |
||
302 | $sql .= " t.fk_tva,"; |
||
303 | $sql .= " t.datec,"; |
||
304 | $sql .= " t.tms,"; |
||
305 | $sql .= " t.datep,"; |
||
306 | $sql .= " t.amount,"; |
||
307 | $sql .= " t.fk_typepaiement,"; |
||
308 | $sql .= " t.num_paiement as num_payment,"; |
||
309 | $sql .= " t.note as note_private,"; |
||
310 | $sql .= " t.fk_bank,"; |
||
311 | $sql .= " t.fk_user_creat,"; |
||
312 | $sql .= " t.fk_user_modif,"; |
||
313 | $sql .= " pt.code as type_code, pt.libelle as type_label,"; |
||
314 | $sql .= ' b.fk_account'; |
||
315 | $sql .= " FROM " . MAIN_DB_PREFIX . "payment_vat as t LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as pt ON t.fk_typepaiement = pt.id"; |
||
316 | $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON t.fk_bank = b.rowid'; |
||
317 | $sql .= " WHERE t.rowid = " . ((int) $id); |
||
318 | // TODO link on entity of tax; |
||
319 | |||
320 | dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); |
||
321 | $resql = $this->db->query($sql); |
||
322 | if ($resql) { |
||
323 | if ($this->db->num_rows($resql)) { |
||
324 | $obj = $this->db->fetch_object($resql); |
||
325 | |||
326 | $this->id = $obj->rowid; |
||
327 | $this->ref = $obj->rowid; |
||
328 | |||
329 | $this->fk_tva = $obj->fk_tva; |
||
330 | $this->datec = $this->db->jdate($obj->datec); |
||
331 | $this->tms = $this->db->jdate($obj->tms); |
||
332 | $this->datep = $this->db->jdate($obj->datep); |
||
333 | $this->amount = $obj->amount; |
||
334 | $this->fk_typepaiement = $obj->fk_typepaiement; |
||
335 | $this->num_paiement = $obj->num_payment; |
||
336 | $this->num_payment = $obj->num_payment; |
||
337 | $this->note = $obj->note_private; |
||
338 | $this->note_private = $obj->note_private; |
||
339 | $this->fk_bank = $obj->fk_bank; |
||
340 | $this->fk_user_creat = $obj->fk_user_creat; |
||
341 | $this->fk_user_modif = $obj->fk_user_modif; |
||
342 | |||
343 | $this->type_code = $obj->type_code; |
||
344 | $this->type_label = $obj->type_label; |
||
345 | |||
346 | $this->bank_account = $obj->fk_account; |
||
347 | $this->bank_line = $obj->fk_bank; |
||
348 | } |
||
349 | $this->db->free($resql); |
||
350 | |||
351 | return 1; |
||
352 | } else { |
||
353 | $this->error = "Error " . $this->db->lasterror(); |
||
354 | return -1; |
||
355 | } |
||
356 | } |
||
357 | |||
358 | |||
359 | /** |
||
360 | * Update database |
||
361 | * |
||
362 | * @param User $user User that modify |
||
363 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
||
364 | * @return int Return integer <0 if KO, >0 if OK |
||
365 | */ |
||
366 | public function update($user = null, $notrigger = 0) |
||
367 | { |
||
368 | global $conf, $langs; |
||
369 | $error = 0; |
||
370 | |||
371 | // Clean parameters |
||
372 | |||
373 | if (isset($this->fk_tva)) { |
||
374 | $this->fk_tva = (int) $this->fk_tva; |
||
375 | } |
||
376 | if (isset($this->amount)) { |
||
377 | $this->amount = (float) $this->amount; |
||
378 | } |
||
379 | if (isset($this->fk_typepaiement)) { |
||
380 | $this->fk_typepaiement = (int) $this->fk_typepaiement; |
||
381 | } |
||
382 | if (isset($this->num_payment)) { |
||
383 | $this->num_payment = trim($this->num_payment); |
||
384 | } |
||
385 | if (isset($this->note)) { |
||
386 | $this->note = trim($this->note); |
||
387 | } |
||
388 | if (isset($this->fk_bank)) { |
||
389 | $this->fk_bank = (int) $this->fk_bank; |
||
390 | } |
||
391 | if (isset($this->fk_user_creat)) { |
||
392 | $this->fk_user_creat = (int) $this->fk_user_creat; |
||
393 | } |
||
394 | if (isset($this->fk_user_modif)) { |
||
395 | $this->fk_user_modif = (int) $this->fk_user_modif; |
||
396 | } |
||
397 | |||
398 | // Check parameters |
||
399 | // Put here code to add control on parameters values |
||
400 | |||
401 | // Update request |
||
402 | $sql = "UPDATE " . MAIN_DB_PREFIX . "payment_vat SET"; |
||
403 | $sql .= " fk_tva=" . (isset($this->fk_tva) ? ((int) $this->fk_tva) : "null") . ","; |
||
404 | $sql .= " datec=" . (dol_strlen($this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ","; |
||
405 | $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ","; |
||
406 | $sql .= " datep=" . (dol_strlen($this->datep) != 0 ? "'" . $this->db->idate($this->datep) . "'" : 'null') . ","; |
||
407 | $sql .= " amount=" . (isset($this->amount) ? (float) price2num($this->amount) : "null") . ","; |
||
408 | $sql .= " fk_typepaiement=" . (isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) : "null") . ","; |
||
409 | $sql .= " num_paiement=" . (isset($this->num_payment) ? "'" . $this->db->escape($this->num_payment) . "'" : "null") . ","; |
||
410 | $sql .= " note=" . (isset($this->note) ? "'" . $this->db->escape($this->note) . "'" : "null") . ","; |
||
411 | $sql .= " fk_bank=" . (isset($this->fk_bank) ? ((int) $this->fk_bank) : "null") . ","; |
||
412 | $sql .= " fk_user_creat=" . (isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) : "null") . ","; |
||
413 | $sql .= " fk_user_modif=" . (isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null"); |
||
414 | $sql .= " WHERE rowid=" . ((int) $this->id); |
||
415 | |||
416 | $this->db->begin(); |
||
417 | |||
418 | dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
||
419 | $resql = $this->db->query($sql); |
||
420 | if (!$resql) { |
||
421 | $error++; |
||
422 | $this->errors[] = "Error " . $this->db->lasterror(); |
||
423 | } |
||
424 | |||
425 | // Commit or rollback |
||
426 | if ($error) { |
||
427 | foreach ($this->errors as $errmsg) { |
||
428 | dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR); |
||
429 | $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
||
430 | } |
||
431 | $this->db->rollback(); |
||
432 | return -1 * $error; |
||
433 | } else { |
||
434 | $this->db->commit(); |
||
435 | return 1; |
||
436 | } |
||
437 | } |
||
438 | |||
439 | |||
440 | /** |
||
441 | * Delete object in database |
||
442 | * |
||
443 | * @param User $user User that delete |
||
444 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
||
445 | * @return int Return integer <0 if KO, >0 if OK |
||
446 | */ |
||
447 | public function delete($user, $notrigger = 0) |
||
448 | { |
||
449 | $error = 0; |
||
450 | |||
451 | dol_syslog(get_class($this) . "::delete"); |
||
452 | |||
453 | $this->db->begin(); |
||
454 | |||
455 | if ($this->bank_line > 0) { |
||
456 | $accline = new AccountLine($this->db); |
||
457 | $accline->fetch($this->bank_line); |
||
458 | $result = $accline->delete($user); |
||
459 | if ($result < 0) { |
||
460 | $this->errors[] = $accline->error; |
||
461 | $error++; |
||
462 | } |
||
463 | } |
||
464 | |||
465 | if (!$error) { |
||
466 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "payment_vat"; |
||
467 | $sql .= " WHERE rowid=" . ((int) $this->id); |
||
468 | |||
469 | dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
||
470 | $resql = $this->db->query($sql); |
||
471 | if (!$resql) { |
||
472 | $error++; |
||
473 | $this->errors[] = "Error " . $this->db->lasterror(); |
||
474 | } |
||
475 | } |
||
476 | |||
477 | // Commit or rollback |
||
478 | if ($error) { |
||
479 | foreach ($this->errors as $errmsg) { |
||
480 | dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); |
||
481 | $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
||
482 | } |
||
483 | $this->db->rollback(); |
||
484 | return -1 * $error; |
||
485 | } else { |
||
486 | $this->db->commit(); |
||
487 | return 1; |
||
488 | } |
||
489 | } |
||
490 | |||
491 | |||
492 | |||
493 | /** |
||
494 | * Load an object from its id and create a new one in database |
||
495 | * |
||
496 | * @param User $user User making the clone |
||
497 | * @param int $fromid Id of object to clone |
||
498 | * @return int New id of clone |
||
499 | */ |
||
500 | public function createFromClone(User $user, $fromid) |
||
534 | } |
||
535 | } |
||
536 | |||
537 | |||
538 | /** |
||
539 | * Initialise an instance with random values. |
||
540 | * Used to build previews or test instances. |
||
541 | * id must be 0 if object instance is a specimen. |
||
542 | * |
||
543 | * @return int |
||
544 | */ |
||
545 | public function initAsSpecimen() |
||
546 | { |
||
547 | $this->id = 0; |
||
548 | $this->fk_tva = 0; |
||
549 | $this->datec = dol_now(); |
||
550 | $this->tms = dol_now(); |
||
551 | $this->datep = dol_now(); |
||
552 | $this->amount = 100; |
||
553 | $this->fk_typepaiement = 0; |
||
554 | $this->num_payment = '123456'; |
||
555 | $this->note_private = 'Private note'; |
||
556 | $this->note_public = 'Public note'; |
||
557 | $this->fk_bank = 0; |
||
558 | $this->fk_user_creat = 0; |
||
559 | $this->fk_user_modif = 0; |
||
560 | |||
561 | return 1; |
||
562 | } |
||
563 | |||
564 | |||
565 | /** |
||
566 | * Add record into bank for payment with links between this bank record and invoices of payment. |
||
567 | * All payment properties must have been set first like after a call to create(). |
||
568 | * |
||
569 | * @param User $user Object of user making payment |
||
570 | * @param string $mode 'payment_sc' |
||
571 | * @param string $label Label to use in bank record |
||
572 | * @param int $accountid Id of bank account to do link with |
||
573 | * @param string $emetteur_nom Name of transmitter |
||
574 | * @param string $emetteur_banque Name of bank |
||
575 | * @return int Return integer <0 if KO, >0 if OK |
||
576 | */ |
||
577 | public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) |
||
578 | { |
||
579 | // Clean data |
||
580 | $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement); |
||
581 | |||
582 | $error = 0; |
||
583 | |||
584 | if (isModEnabled("bank")) { |
||
585 | |||
586 | $acc = new Account($this->db); |
||
587 | $acc->fetch($accountid); |
||
588 | |||
589 | $total = $this->amount; |
||
590 | if ($mode == 'payment_vat') { |
||
591 | $total = -$total; |
||
592 | } |
||
593 | |||
594 | // Insert payment into llx_bank |
||
595 | $bank_line_id = $acc->addline( |
||
596 | $this->datepaye, |
||
597 | $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") |
||
598 | $label, |
||
599 | $total, |
||
600 | $this->num_payment, |
||
601 | '', |
||
602 | $user, |
||
603 | $emetteur_nom, |
||
604 | $emetteur_banque |
||
605 | ); |
||
606 | |||
607 | // Update fk_bank in llx_paiement. |
||
608 | // We thus know the payment that generated the bank entry |
||
609 | if ($bank_line_id > 0) { |
||
610 | $result = $this->update_fk_bank($bank_line_id); |
||
611 | if ($result <= 0) { |
||
612 | $error++; |
||
613 | dol_print_error($this->db); |
||
614 | } |
||
615 | |||
616 | // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction |
||
617 | $url = ''; |
||
618 | if ($mode == 'payment_vat') { |
||
619 | $url = constant('BASE_URL') . '/compta/payment_vat/card.php?id='; |
||
620 | } |
||
621 | if ($url) { |
||
622 | $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); |
||
623 | if ($result <= 0) { |
||
624 | $error++; |
||
625 | dol_print_error($this->db); |
||
626 | } |
||
627 | } |
||
628 | |||
629 | // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) |
||
630 | $linkaddedforthirdparty = array(); |
||
631 | foreach ($this->amounts as $key => $value) { |
||
632 | if ($mode == 'payment_vat') { |
||
633 | $tva = new Tva($this->db); |
||
634 | $tva->fetch($key); |
||
635 | $result = $acc->add_url_line($bank_line_id, $tva->id, constant('BASE_URL') . '/compta/tva/card.php?id=', '(' . $tva->label . ')', 'vat'); |
||
636 | if ($result <= 0) { |
||
637 | dol_print_error($this->db); |
||
638 | } |
||
639 | } |
||
640 | } |
||
641 | } else { |
||
642 | $this->error = $acc->error; |
||
643 | $error++; |
||
644 | } |
||
645 | } |
||
646 | |||
647 | if (!$error) { |
||
648 | return 1; |
||
649 | } else { |
||
650 | return -1; |
||
651 | } |
||
652 | } |
||
653 | |||
654 | |||
655 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
656 | /** |
||
657 | * Update link between vat payment and line in llx_bank generated |
||
658 | * |
||
659 | * @param int $id_bank Id if bank |
||
660 | * @return int >0 if OK, <=0 if KO |
||
661 | */ |
||
662 | public function update_fk_bank($id_bank) |
||
663 | { |
||
664 | // phpcs:enable |
||
665 | $sql = "UPDATE " . MAIN_DB_PREFIX . "payment_vat SET fk_bank = " . ((int) $id_bank) . " WHERE rowid = " . ((int) $this->id); |
||
666 | |||
667 | dol_syslog(get_class($this) . "::update_fk_bank", LOG_DEBUG); |
||
668 | $result = $this->db->query($sql); |
||
669 | if ($result) { |
||
670 | return 1; |
||
671 | } else { |
||
672 | $this->error = $this->db->error(); |
||
673 | return 0; |
||
674 | } |
||
675 | } |
||
676 | |||
677 | |||
678 | /** |
||
679 | * Return the label of the status |
||
680 | * |
||
681 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
||
682 | * @return string Libelle |
||
683 | */ |
||
684 | public function getLibStatut($mode = 0) |
||
685 | { |
||
686 | return $this->LibStatut($this->statut, $mode); |
||
687 | } |
||
688 | |||
689 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
690 | /** |
||
691 | * Return the label of a given status |
||
692 | * |
||
693 | * @param int $status Id status |
||
694 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
||
695 | * @return string Label of status |
||
696 | */ |
||
697 | public function LibStatut($status, $mode = 0) |
||
739 | } |
||
740 | |||
741 | /** |
||
742 | * Return clickable name (with picto eventually) |
||
743 | * |
||
744 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
745 | * @param int $maxlen Longueur max libelle |
||
746 | * @return string Chaine avec URL |
||
747 | */ |
||
748 | public function getNomUrl($withpicto = 0, $maxlen = 0) |
||
749 | { |
||
750 | global $langs; |
||
751 | |||
752 | $result = ''; |
||
753 | |||
754 | if (empty($this->ref)) { |
||
755 | $this->ref = $this->lib; |
||
756 | } |
||
757 | |||
758 | $label = img_picto('', $this->picto) . ' <u>' . $langs->trans("VATPayment") . '</u>'; |
||
759 | $label .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; |
||
760 | if (!empty($this->label)) { |
||
761 | $labeltoshow = $this->label; |
||
762 | $reg = array(); |
||
763 | if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) { |
||
764 | // Label generique car entre parentheses. On l'affiche en le traduisant |
||
765 | if ($reg[1] == 'paiement') { |
||
766 | $reg[1] = 'Payment'; |
||
767 | } |
||
768 | $labeltoshow = $langs->trans($reg[1]); |
||
769 | } |
||
770 | $label .= '<br><b>' . $langs->trans('Label') . ':</b> ' . $labeltoshow; |
||
771 | } |
||
772 | if ($this->datep) { |
||
773 | $label .= '<br><b>' . $langs->trans('Date') . ':</b> ' . dol_print_date($this->datep, 'day'); |
||
774 | } |
||
775 | |||
776 | if (!empty($this->id)) { |
||
777 | $link = '<a href="' . constant('BASE_URL') . '/compta/payment_vat/card.php?id=' . $this->id . '" title="' . dol_escape_htmltag($label, 1) . '" class="classfortooltip">'; |
||
778 | $linkend = '</a>'; |
||
779 | |||
780 | if ($withpicto) { |
||
781 | $result .= ($link . img_object($label, 'payment', 'class="classfortooltip"') . $linkend . ' '); |
||
782 | } |
||
783 | if ($withpicto && $withpicto != 2) { |
||
784 | $result .= ' '; |
||
785 | } |
||
786 | if ($withpicto != 2) { |
||
787 | $result .= $link . ($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref) . $linkend; |
||
788 | } |
||
789 | } |
||
790 | |||
791 | return $result; |
||
794 |