Passed
Push — GENERAL_BUG_REVIEW_240911 ( 776d89...c757bd )
by Rafael
50:33
created

Localtax::fetch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 50
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 44
nc 3
nop 1
dl 0
loc 50
rs 9.216
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2011-2014  Juanjo Menent   <[email protected]>
4
 * Copyright (C) 2024       Frédéric France             <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Rafael San José             <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Dolibarr\Code\Compta\Classes;
23
24
/**
25
 *      \file       htdocs/compta/localtax/class/localtax.class.php
26
 *      \ingroup    tax
27
 */
28
29
use Dolibarr\Core\Base\CommonObject;
30
31
32
/**
33
 *  Class to manage local tax
34
 */
35
class Localtax extends CommonObject
36
{
37
    /**
38
     * @var string ID to identify managed object
39
     */
40
    public $element = 'localtax';
41
42
    /**
43
     * @var string Name of table without prefix where object is stored
44
     */
45
    public $table_element = 'localtax';
46
47
    /**
48
     * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
49
     */
50
    public $picto = 'payment';
51
52
    public $ltt;
53
54
    public $datep;
55
    public $datev;
56
    public $amount;
57
58
    /**
59
     * @var int
60
     */
61
    public $accountid;
62
63
    /**
64
     * @var string
65
     */
66
    public $fk_type;
67
68
    public $paymenttype;
69
70
    /**
71
     * @var int
72
     */
73
    public $rappro;
74
75
76
    /**
77
     * @var string local tax
78
     */
79
    public $label;
80
81
    /**
82
     * @var int ID
83
     */
84
    public $fk_bank;
85
86
    /**
87
     * @var int ID
88
     */
89
    public $fk_user_creat;
90
91
    /**
92
     * @var int ID
93
     */
94
    public $fk_user_modif;
95
96
    /**
97
     *  Constructor
98
     *
99
     *  @param      DoliDB      $db      Database handler
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Compta\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
100
     */
101
    public function __construct($db)
102
    {
103
        $this->db = $db;
104
    }
105
106
107
    /**
108
     *  Create in database
109
     *
110
     *  @param      User    $user       User that create
111
     *  @return     int                 Return integer <0 if KO, >0 if OK
112
     */
113
    public function create($user)
114
    {
115
        global $conf, $langs;
116
117
        $error = 0;
118
119
        // Clean parameters
120
        $this->amount = trim($this->amount);
121
        $this->label = trim($this->label);
122
        $this->note = trim($this->note);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

122
        $this->note = trim(/** @scrutinizer ignore-deprecated */ $this->note);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
123
124
        // Insert request
125
        $sql = "INSERT INTO " . MAIN_DB_PREFIX . "localtax(";
126
        $sql .= "localtaxtype,";
127
        $sql .= "tms,";
128
        $sql .= "datep,";
129
        $sql .= "datev,";
130
        $sql .= "amount,";
131
        $sql .= "label,";
132
        $sql .= "note,";
133
        $sql .= "fk_bank,";
134
        $sql .= "fk_user_creat,";
135
        $sql .= "fk_user_modif";
136
        $sql .= ") VALUES (";
137
        $sql .= " " . ((int) $this->ltt) . ",";
138
        $sql .= " '" . $this->db->idate($this->tms) . "',";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

138
        $sql .= " '" . $this->db->idate(/** @scrutinizer ignore-deprecated */ $this->tms) . "',";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
139
        $sql .= " '" . $this->db->idate($this->datep) . "',";
140
        $sql .= " '" . $this->db->idate($this->datev) . "',";
141
        $sql .= " '" . $this->db->escape($this->amount) . "',";
142
        $sql .= " '" . $this->db->escape($this->label) . "',";
143
        $sql .= " '" . $this->db->escape($this->note) . "',";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

143
        $sql .= " '" . $this->db->escape(/** @scrutinizer ignore-deprecated */ $this->note) . "',";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
144
        $sql .= " " . ($this->fk_bank <= 0 ? "NULL" : (int) $this->fk_bank) . ",";
145
        $sql .= " " . ((int) $this->fk_user_creat) . ",";
146
        $sql .= " " . ((int) $this->fk_user_modif);
147
        $sql .= ")";
148
149
        dol_syslog(get_class($this) . "::create", LOG_DEBUG);
150
        $resql = $this->db->query($sql);
151
        if ($resql) {
152
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "localtax");
153
154
            // Call trigger
155
            $result = $this->call_trigger('LOCALTAX_CREATE', $user);
156
            if ($result < 0) {
157
                $error++;
158
            }
159
            // End call triggers
160
161
            if (!$error) {
162
                $this->db->commit();
163
                return $this->id;
164
            } else {
165
                $this->db->rollback();
166
                return -1;
167
            }
168
        } else {
169
            $this->error = "Error " . $this->db->lasterror();
170
            $this->db->rollback();
171
            return -1;
172
        }
173
    }
174
175
    /**
176
     *  Update database
177
     *
178
     *  @param      User    $user           User that modify
179
     *  @param      int     $notrigger      0=no, 1=yes (no update trigger)
180
     *  @return     int                     Return integer <0 if KO, >0 if OK
181
     */
182
    public function update(User $user, $notrigger = 0)
183
    {
184
        global $conf, $langs;
185
186
        $error = 0;
187
188
        // Clean parameters
189
        $this->amount = trim($this->amount);
190
        $this->label = trim($this->label);
191
        $this->note = trim($this->note);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

191
        /** @scrutinizer ignore-deprecated */ $this->note = trim($this->note);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
192
193
        $this->db->begin();
194
195
        // Update request
196
        $sql = "UPDATE " . MAIN_DB_PREFIX . "localtax SET";
197
        $sql .= " localtaxtype=" . ((int) $this->ltt) . ",";
198
        $sql .= " tms='" . $this->db->idate($this->tms) . "',";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

198
        $sql .= " tms='" . $this->db->idate(/** @scrutinizer ignore-deprecated */ $this->tms) . "',";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
199
        $sql .= " datep='" . $this->db->idate($this->datep) . "',";
200
        $sql .= " datev='" . $this->db->idate($this->datev) . "',";
201
        $sql .= " amount=" . price2num($this->amount) . ",";
202
        $sql .= " label='" . $this->db->escape($this->label) . "',";
203
        $sql .= " note='" . $this->db->escape($this->note) . "',";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

203
        $sql .= " note='" . $this->db->escape(/** @scrutinizer ignore-deprecated */ $this->note) . "',";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
204
        $sql .= " fk_bank=" . (int) $this->fk_bank . ",";
205
        $sql .= " fk_user_creat=" . (int) $this->fk_user_creat . ",";
206
        $sql .= " fk_user_modif=" . (int) $this->fk_user_modif;
207
        $sql .= " WHERE rowid=" . ((int) $this->id);
208
209
        dol_syslog(get_class($this) . "::update", LOG_DEBUG);
210
        $resql = $this->db->query($sql);
211
        if (!$resql) {
212
            $this->error = "Error " . $this->db->lasterror();
213
            $error++;
214
        }
215
216
        if (!$error && !$notrigger) {
217
            // Call trigger
218
            $result = $this->call_trigger('LOCALTAX_MODIFY', $user);
219
            if ($result < 0) {
220
                $error++;
221
            }
222
            // End call triggers
223
        }
224
225
        if (!$error) {
226
            $this->db->commit();
227
            return 1;
228
        } else {
229
            $this->db->rollback();
230
            return -1;
231
        }
232
    }
233
234
235
    /**
236
     *  Load object in memory from database
237
     *
238
     *  @param      int     $id     Object id
239
     *  @return     int             Return integer <0 if KO, >0 if OK
240
     */
241
    public function fetch($id)
242
    {
243
        $sql = "SELECT";
244
        $sql .= " t.rowid,";
245
        $sql .= " t.localtaxtype,";
246
        $sql .= " t.tms,";
247
        $sql .= " t.datep,";
248
        $sql .= " t.datev,";
249
        $sql .= " t.amount,";
250
        $sql .= " t.label,";
251
        $sql .= " t.note as note_private,";
252
        $sql .= " t.fk_bank,";
253
        $sql .= " t.fk_user_creat,";
254
        $sql .= " t.fk_user_modif,";
255
        $sql .= " b.fk_account,";
256
        $sql .= " b.fk_type,";
257
        $sql .= " b.rappro";
258
        $sql .= " FROM " . MAIN_DB_PREFIX . "localtax as t";
259
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank as b ON t.fk_bank = b.rowid";
260
        $sql .= " WHERE t.rowid = " . ((int) $id);
261
262
        dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
263
        $resql = $this->db->query($sql);
264
        if ($resql) {
265
            if ($this->db->num_rows($resql)) {
266
                $obj = $this->db->fetch_object($resql);
267
268
                $this->id    = $obj->rowid;
269
                $this->ref   = $obj->rowid;
270
                $this->ltt   = $obj->localtaxtype;
271
                $this->tms   = $this->db->jdate($obj->tms);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

271
                /** @scrutinizer ignore-deprecated */ $this->tms   = $this->db->jdate($obj->tms);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Documentation Bug introduced by
It seems like $this->db->jdate($obj->tms) can also be of type string. However, the property $tms is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
272
                $this->datep = $this->db->jdate($obj->datep);
273
                $this->datev = $this->db->jdate($obj->datev);
274
                $this->amount = $obj->amount;
275
                $this->label = $obj->label;
276
                $this->note  = $obj->note_private;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

276
                /** @scrutinizer ignore-deprecated */ $this->note  = $obj->note_private;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
277
                $this->note_private  = $obj->note_private;
278
                $this->fk_bank = $obj->fk_bank;
279
                $this->fk_user_creat = $obj->fk_user_creat;
280
                $this->fk_user_modif = $obj->fk_user_modif;
281
                $this->fk_account = $obj->fk_account;
282
                $this->fk_type = $obj->fk_type;
283
                $this->rappro  = $obj->rappro;
284
            }
285
            $this->db->free($resql);
286
287
            return 1;
288
        } else {
289
            $this->error = "Error " . $this->db->lasterror();
290
            return -1;
291
        }
292
    }
293
294
295
    /**
296
     *  Delete object in database
297
     *
298
     *  @param      User    $user       User that delete
299
     *  @return     int                 Return integer <0 if KO, >0 if OK
300
     */
301
    public function delete($user)
302
    {
303
        // Call trigger
304
        $result = $this->call_trigger('LOCALTAX_DELETE', $user);
305
        if ($result < 0) {
306
            return -1;
307
        }
308
        // End call triggers
309
310
        $sql = "DELETE FROM " . MAIN_DB_PREFIX . "localtax";
311
        $sql .= " WHERE rowid=" . ((int) $this->id);
312
313
        dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
314
        $resql = $this->db->query($sql);
315
        if (!$resql) {
316
            $this->error = "Error " . $this->db->lasterror();
317
            return -1;
318
        }
319
320
        return 1;
321
    }
322
323
324
    /**
325
     *  Initialise an instance with random values.
326
     *  Used to build previews or test instances.
327
     *  id must be 0 if object instance is a specimen.
328
     *
329
     *  @return int
330
     */
331
    public function initAsSpecimen()
332
    {
333
        global $user;
334
335
        $this->id = 0;
336
337
        $this->tms = dol_now();
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$tms has been deprecated: Use $date_modification ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

337
        /** @scrutinizer ignore-deprecated */ $this->tms = dol_now();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
338
        $this->ltt = 0;
339
        $this->datep = '';
340
        $this->datev = '';
341
        $this->amount = '';
342
        $this->label = '';
343
        $this->note = '';
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

343
        /** @scrutinizer ignore-deprecated */ $this->note = '';

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
344
        $this->fk_bank = 0;
345
        $this->fk_user_creat = $user->id;
346
        $this->fk_user_modif = $user->id;
347
348
        return 1;
349
    }
350
351
352
    /**
353
     *  Hum la function s'appelle 'Solde' elle doit a mon avis calcluer le solde de localtax, non ?
354
     *
355
     *  @param  int     $year       Year
356
     *  @return int                 ???
357
     */
358
    public function solde($year = 0)
359
    {
360
        $reglee = $this->localtax_sum_reglee($year);
361
362
        $payee = $this->localtax_sum_payee($year);
363
        $collectee = $this->localtax_sum_collectee($year);
364
365
        $solde = $reglee - ($collectee - $payee);
366
367
        return $solde;
368
    }
369
370
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
371
    /**
372
     *  Total de la localtax des factures emises par la societe.
373
     *
374
     *  @param  int     $year       Year
375
     *  @return int                 ???
376
     */
377
    public function localtax_sum_collectee($year = 0)
378
    {
379
		// phpcs:enable
380
        $sql = "SELECT sum(f.localtax) as amount";
381
        $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
382
        $sql .= " WHERE f.paye = 1";
383
        if ($year) {
384
            $sql .= " AND f.datef BETWEEN '" . $this->db->idate(dol_get_first_day($year, 1, 'gmt')) . "' AND '" . $this->db->idate(dol_get_last_day($year, 1, 'gmt')) . "'";
385
        }
386
387
        $result = $this->db->query($sql);
388
        if ($result) {
389
            if ($this->db->num_rows($result)) {
390
                $obj = $this->db->fetch_object($result);
391
                $ret = $obj->amount;
392
                $this->db->free($result);
393
                return $ret;
394
            } else {
395
                $this->db->free($result);
396
                return 0;
397
            }
398
        } else {
399
            print $this->db->lasterror();
400
            return -1;
401
        }
402
    }
403
404
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
405
    /**
406
     *  Total of localtax paid in invoice
407
     *
408
     *  @param  int     $year       Year
409
     *  @return int                 ???
410
     */
411
    public function localtax_sum_payee($year = 0)
412
    {
413
		// phpcs:enable
414
415
        $sql = "SELECT sum(f.total_localtax) as total_localtax";
416
        $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
417
        if ($year) {
418
            $sql .= " WHERE f.datef BETWEEN '" . $this->db->idate(dol_get_first_day($year, 1, 'gmt')) . "' AND '" . $this->db->idate(dol_get_last_day($year, 1, 'gmt')) . "'";
419
        }
420
421
        $result = $this->db->query($sql);
422
        if ($result) {
423
            if ($this->db->num_rows($result)) {
424
                $obj = $this->db->fetch_object($result);
425
                $ret = $obj->total_localtax;
426
                $this->db->free($result);
427
                return $ret;
428
            } else {
429
                $this->db->free($result);
430
                return 0;
431
            }
432
        } else {
433
            print $this->db->lasterror();
434
            return -1;
435
        }
436
    }
437
438
439
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
440
    /**
441
     *  Total of localtax paid
442
     *
443
     *  @param  int     $year       Year
444
     *  @return int                 ???
445
     */
446
    public function localtax_sum_reglee($year = 0)
447
    {
448
		// phpcs:enable
449
450
        $sql = "SELECT sum(f.amount) as amount";
451
        $sql .= " FROM " . MAIN_DB_PREFIX . "localtax as f";
452
        if ($year) {
453
            $sql .= " WHERE f.datev BETWEEN '" . $this->db->idate(dol_get_first_day($year, 1, 'gmt')) . "' AND '" . $this->db->idate(dol_get_last_day($year, 1, 'gmt')) . "'";
454
        }
455
456
        $result = $this->db->query($sql);
457
        if ($result) {
458
            if ($this->db->num_rows($result)) {
459
                $obj = $this->db->fetch_object($result);
460
                $ret = $obj->amount;
461
                $this->db->free($result);
462
                return $ret;
463
            } else {
464
                $this->db->free($result);
465
                return 0;
466
            }
467
        } else {
468
            print $this->db->lasterror();
469
            return -1;
470
        }
471
    }
472
473
474
    /**
475
     *  Add a payment of localtax
476
     *
477
     *  @param      User    $user       Object user that insert
478
     *  @return     int                 Return integer <0 if KO, rowid in localtax table if OK
479
     */
480
    public function addPayment($user)
481
    {
482
        global $conf, $langs;
483
484
        $this->db->begin();
485
486
        // Check parameters
487
        $this->amount = price2num($this->amount);
488
        if (!$this->label) {
489
            $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
490
            return -3;
491
        }
492
        if ($this->amount <= 0) {
493
            $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
494
            return -4;
495
        }
496
        if (isModEnabled("bank") && (empty($this->accountid) || $this->accountid <= 0)) {
497
            $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
498
            return -5;
499
        }
500
        if (isModEnabled("bank") && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
501
            $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
502
            return -5;
503
        }
504
505
        // Insertion dans table des paiement localtax
506
        $sql = "INSERT INTO " . MAIN_DB_PREFIX . "localtax (localtaxtype, datep, datev, amount";
507
        if ($this->note) {
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

507
        if (/** @scrutinizer ignore-deprecated */ $this->note) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
508
            $sql .= ", note";
509
        }
510
        if ($this->label) {
511
            $sql .= ", label";
512
        }
513
        $sql .= ", fk_user_creat, fk_bank";
514
        $sql .= ") ";
515
        $sql .= " VALUES (" . $this->ltt . ", '" . $this->db->idate($this->datep) . "',";
516
        $sql .= "'" . $this->db->idate($this->datev) . "'," . $this->amount;
517
        if ($this->note) {
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

517
        if (/** @scrutinizer ignore-deprecated */ $this->note) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
518
            $sql .= ", '" . $this->db->escape($this->note) . "'";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

518
            $sql .= ", '" . $this->db->escape(/** @scrutinizer ignore-deprecated */ $this->note) . "'";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
519
        }
520
        if ($this->label) {
521
            $sql .= ", '" . $this->db->escape($this->label) . "'";
522
        }
523
        $sql .= ", " . ((int) $user->id) . ", NULL";
524
        $sql .= ")";
525
526
        dol_syslog(get_class($this) . "::addPayment", LOG_DEBUG);
527
        $result = $this->db->query($sql);
528
        if ($result) {
529
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "localtax"); // TODO devrait s'appeler paiementlocaltax
530
            if ($this->id > 0) {
531
                $ok = 1;
532
                if (isModEnabled("bank")) {
533
                    // Insertion dans llx_bank
534
535
                    $acc = new Account($this->db);
536
                    $result = $acc->fetch($this->accountid);
537
                    if ($result <= 0) {
538
                        dol_print_error($this->db);
539
                    }
540
541
                    $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs((float) $this->amount), '', '', $user);
542
543
                    // Update fk_bank into llx_localtax so we know the line of localtax used to generate the bank entry.
544
                    if ($bank_line_id > 0) {
545
                        $this->update_fk_bank($bank_line_id);
546
                    } else {
547
                        $this->error = $acc->error;
548
                        $ok = 0;
549
                    }
550
551
                    // Mise a jour liens
552
                    $result = $acc->add_url_line($bank_line_id, $this->id, constant('BASE_URL') . '/compta/localtax/card.php?id=', "(VATPayment)", "payment_vat");
553
                    if ($result < 0) {
554
                        $this->error = $acc->error;
555
                        $ok = 0;
556
                    }
557
                }
558
559
                if ($ok) {
560
                    $this->db->commit();
561
                    return $this->id;
562
                } else {
563
                    $this->db->rollback();
564
                    return -3;
565
                }
566
            } else {
567
                $this->error = $this->db->lasterror();
568
                $this->db->rollback();
569
                return -2;
570
            }
571
        } else {
572
            $this->error = $this->db->lasterror();
573
            $this->db->rollback();
574
            return -1;
575
        }
576
    }
577
578
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
579
    /**
580
     *  Update the link between localtax payment and the line into llx_bank
581
     *
582
     *  @param      int     $id     Id bank account
583
     *  @return     int             Return integer <0 if KO, >0 if OK
584
     */
585
    public function update_fk_bank($id)
586
    {
587
		// phpcs:enable
588
        $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'localtax SET fk_bank = ' . ((int) $id);
589
        $sql .= ' WHERE rowid = ' . ((int) $this->id);
590
        $result = $this->db->query($sql);
591
        if ($result) {
592
            return 1;
593
        } else {
594
            dol_print_error($this->db);
595
            return -1;
596
        }
597
    }
598
599
600
    /**
601
     *  Returns clickable name
602
     *
603
     *  @param      int     $withpicto      0=Link, 1=Picto into link, 2=Picto
604
     *  @param      string  $option         Sur quoi pointe le lien
605
     *  @return     string                  Chaine avec URL
606
     */
607
    public function getNomUrl($withpicto = 0, $option = '')
608
    {
609
        global $langs;
610
611
        $result = '';
612
        $label = $langs->trans("ShowVatPayment") . ': ' . $this->ref;
613
614
        $link = '<a href="' . constant('BASE_URL') . '/compta/localtax/card.php?id=' . $this->id . '" title="' . dol_escape_htmltag($label, 1) . '" class="classfortooltip">';
615
        $linkend = '</a>';
616
617
        $picto = 'payment';
618
619
        if ($withpicto) {
620
            $result .= ($link . img_object($label, $picto, 'class="classfortooltip"') . $linkend);
621
        }
622
        if ($withpicto && $withpicto != 2) {
623
            $result .= ' ';
624
        }
625
        if ($withpicto != 2) {
626
            $result .= $link . $this->ref . $linkend;
627
        }
628
        return $result;
629
    }
630
631
    /**
632
     *  Return the label of the status
633
     *
634
     *  @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
635
     *  @return string                 Label of status
636
     */
637
    public function getLibStatut($mode = 0)
638
    {
639
        return $this->LibStatut($this->statut, $mode);
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$statut has been deprecated: Use $status instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

639
        return $this->LibStatut(/** @scrutinizer ignore-deprecated */ $this->statut, $mode);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
640
    }
641
642
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
643
    /**
644
     *  Return the label of a given status
645
     *
646
     *  @param  int     $status        Id status
647
     *  @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
648
     *  @return string                 Label of status
649
     */
650
    public function LibStatut($status, $mode = 0)
651
    {
652
		// phpcs:enable
653
        //global $langs;
654
655
        return '';
656
    }
657
658
    /**
659
     *  Return clicable link of object (with eventually picto)
660
     *
661
     *  @param      string      $option                 Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
662
     *  @param      array       $arraydata              Array of data
663
     *  @return     string                              HTML Code for Kanban thumb.
664
     */
665
    public function getKanbanView($option = '', $arraydata = null)
666
    {
667
        global $langs;
668
669
        $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
670
671
        $return = '<div class="box-flex-item box-flex-grow-zero">';
672
        $return .= '<div class="info-box info-box-sm">';
673
        $return .= '<span class="info-box-icon bg-infobox-action">';
674
        $return .= img_picto('', $this->picto);
675
        $return .= '</span>';
676
        $return .= '<div class="info-box-content">';
677
        $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref) . '</span>';
678
        if ($selected >= 0) {
679
            $return .= '<input id="cb' . $this->id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
680
        }
681
        if (property_exists($this, 'label')) {
682
            $return .= ' | <span class="info-box-label">' . $this->label . '</span>';
683
        }
684
        if (property_exists($this, 'datev')) {
685
            $return .= '<br><span class="opacitymedium">' . $langs->trans("DateEnd") . '</span> : <span class="info-box-label">' . dol_print_date($this->db->jdate($this->datev), 'day') . '</span>';
686
        }
687
        if (property_exists($this, 'datep')) {
688
            $return .= '<br><span class="opacitymedium">' . $langs->trans("DatePayment", '', '', '', '', 5) . '</span> : <span class="info-box-label">' . dol_print_date($this->db->jdate($this->datep), 'day') . '</span>';
689
        }
690
        if (property_exists($this, 'amount')) {
691
            $return .= '<br><span class="opacitymedium">' . $langs->trans("Amount") . '</span> : <span class="info-box-label amount">' . price($this->amount) . '</span>';
692
        }
693
        $return .= '</div>';
694
        $return .= '</div>';
695
        $return .= '</div>';
696
        return $return;
697
    }
698
}
699