Passed
Branch develop (a7390e)
by
unknown
25:38
created

PaymentDonation::update_fk_bank()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 10
1
<?php
2
/* Copyright (C) 2015       Alexandre Spangaro	  	<[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 *  \file       htdocs/don/class/paymentdonation.class.php
20
 *  \ingroup    Donation
21
 *  \brief      File of class to manage payment of donations
22
 */
23
24
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
25
26
27
/**
28
 *	Class to manage payments of donations
29
 */
30
class PaymentDonation extends CommonObject
31
{
32
	/**
33
	 * @var string ID to identify managed object
34
	 */
35
	public $element='payment_donation';
36
37
	/**
38
	 * @var string Name of table without prefix where object is stored
39
	 */
40
	public $table_element='payment_donation';
41
42
    /**
43
	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
44
	 */
45
	public $picto = 'payment';
46
47
	/**
48
	 * @var int ID
49
	 */
50
	public $rowid;
51
52
	/**
53
     * @var int ID
54
     */
55
	public $fk_donation;
56
57
	public $datec='';
58
	public $tms='';
59
	public $datep='';
60
    public $amount;            // Total amount of payment
61
    public $amounts=array();   // Array of amounts
62
	public $typepayment;
63
	public $num_payment;
64
65
	/**
66
     * @var int ID
67
     */
68
	public $fk_bank;
69
70
	/**
71
     * @var int ID
72
     */
73
	public $fk_user_creat;
74
75
	/**
76
     * @var int ID
77
     */
78
	public $fk_user_modif;
79
80
	/**
81
	 * @deprecated
82
	 * @see $amount, $amounts
83
	 */
84
	public $total;
85
86
	/**
87
	 *	Constructor
88
	 *
89
	 *  @param		DoliDB		$db      Database handler
90
	 */
91
	public function __construct($db)
92
	{
93
		$this->db = $db;
94
	}
95
96
	/**
97
	 *  Create payment of donation into database.
98
     *  Use this->amounts to have list of lines for the payment
99
     *
100
	 *  @param      User		$user			User making payment
101
	 *  @param      bool 		$notrigger 		false=launch triggers after, true=disable triggers
102
	 *  @return     int     					<0 if KO, id of payment if OK
103
	 */
104
	public function create($user, $notrigger = false)
105
	{
106
		global $conf, $langs;
107
108
		$error=0;
109
110
        $now=dol_now();
111
112
        // Validate parameters
113
		if (! $this->datepaid)
0 ignored issues
show
Bug introduced by
The property datepaid does not exist on PaymentDonation. Did you mean datep?
Loading history...
114
		{
115
			$this->error='ErrorBadValueForParameterCreatePaymentDonation';
116
			return -1;
117
		}
118
119
		// Clean parameters
120
		if (isset($this->fk_donation)) 		$this->fk_donation=trim($this->fk_donation);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_donation was declared of type integer, but trim($this->fk_donation) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
121
		if (isset($this->amount))			$this->amount=trim($this->amount);
122
		if (isset($this->fk_typepayment))   $this->fk_typepayment=trim($this->fk_typepayment);
123
		if (isset($this->num_payment))      $this->num_payment=trim($this->num_payment);
124
		if (isset($this->note))				$this->note=trim($this->note);
125
		if (isset($this->fk_bank))			$this->fk_bank=trim($this->fk_bank);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_bank was declared of type integer, but trim($this->fk_bank) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
126
		if (isset($this->fk_user_creat))	$this->fk_user_creat=trim($this->fk_user_creat);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_creat was declared of type integer, but trim($this->fk_user_creat) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
127
		if (isset($this->fk_user_modif))	$this->fk_user_modif=trim($this->fk_user_modif);
128
129
        $totalamount = 0;
130
        foreach ($this->amounts as $key => $value)  // How payment is dispatch
131
        {
132
            $newvalue = price2num($value, 'MT');
133
            $this->amounts[$key] = $newvalue;
134
            $totalamount += $newvalue;
135
        }
136
        $totalamount = price2num($totalamount);
137
138
        // Check parameters
139
        if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
140
141
142
		$this->db->begin();
143
144
		if ($totalamount != 0)
145
		{
146
			$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_donation (fk_donation, datec, datep, amount,";
147
			$sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
148
			$sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',";
149
			$sql.= " '".$this->db->idate($this->datepaid)."',";
150
			$sql.= " ".$totalamount.",";
151
			$sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.",";
152
			$sql.= " 0)";
153
154
			dol_syslog(get_class($this)."::create", LOG_DEBUG);
155
			$resql=$this->db->query($sql);
156
			if ($resql)
157
			{
158
				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_donation");
159
				$this->ref = $this->id;
160
			}
161
			else
162
			{
163
				$error++;
164
			}
165
		}
166
167
		if (! $error && ! $notrigger)
168
		{
169
			// Call triggers
170
			$result=$this->call_trigger('DONATION_PAYMENT_CREATE', $user);
171
			if ($result < 0) { $error++; }
172
			// End call triggers
173
		}
174
175
		if ($totalamount != 0 && ! $error)
176
		{
177
		    $this->amount=$totalamount;
178
            $this->total=$totalamount;    // deprecated
179
		    $this->db->commit();
180
			return $this->id;
181
		}
182
		else
183
		{
184
			$this->error=$this->db->error();
185
			$this->db->rollback();
186
			return -1;
187
		}
188
	}
189
190
	/**
191
	 *  Load object in memory from database
192
	 *
193
	 *  @param	int		$id         Id object
194
	 *  @return int         		<0 if KO, >0 if OK
195
	 */
196
	public function fetch($id)
197
	{
198
		global $langs;
199
		$sql = "SELECT";
200
		$sql.= " t.rowid,";
201
		$sql.= " t.fk_donation,";
202
		$sql.= " t.datec,";
203
		$sql.= " t.tms,";
204
		$sql.= " t.datep,";
205
		$sql.= " t.amount,";
206
		$sql.= " t.fk_typepayment,";
207
		$sql.= " t.num_payment,";
208
		$sql.= " t.note,";
209
		$sql.= " t.fk_bank,";
210
		$sql.= " t.fk_user_creat,";
211
		$sql.= " t.fk_user_modif,";
212
		$sql.= " pt.code as type_code, pt.libelle as type_libelle,";
213
		$sql.= ' b.fk_account';
214
		$sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as t";
215
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
216
		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
217
		$sql.= " WHERE t.rowid = ".$id;
218
219
		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
220
		$resql=$this->db->query($sql);
221
		if ($resql)
222
		{
223
			if ($this->db->num_rows($resql))
224
			{
225
				$obj = $this->db->fetch_object($resql);
226
227
				$this->id    = $obj->rowid;
228
				$this->ref   = $obj->rowid;
229
230
				$this->fk_donation		= $obj->fk_donation;
231
				$this->datec			= $this->db->jdate($obj->datec);
232
				$this->tms				= $this->db->jdate($obj->tms);
233
				$this->datep			= $this->db->jdate($obj->datep);
234
				$this->amount			= $obj->amount;
235
				$this->fk_typepayment	= $obj->fk_typepayment;
236
				$this->num_payment		= $obj->num_payment;
237
				$this->note				= $obj->note;
238
				$this->fk_bank			= $obj->fk_bank;
239
				$this->fk_user_creat	= $obj->fk_user_creat;
240
				$this->fk_user_modif	= $obj->fk_user_modif;
241
242
				$this->type_code		= $obj->type_code;
243
				$this->type_libelle		= $obj->type_libelle;
244
245
				$this->bank_account		= $obj->fk_account;
246
				$this->bank_line		= $obj->fk_bank;
247
			}
248
			$this->db->free($resql);
249
250
			return 1;
251
		}
252
		else
253
		{
254
			$this->error="Error ".$this->db->lasterror();
255
			return -1;
256
		}
257
	}
258
259
260
	/**
261
	 *  Update database
262
	 *
263
	 *  @param	User	$user        	User that modify
264
	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
265
	 *  @return int         			<0 if KO, >0 if OK
266
	 */
267
	public function update($user, $notrigger = 0)
268
	{
269
		global $conf, $langs;
270
		$error=0;
271
272
		// Clean parameters
273
274
		if (isset($this->fk_donation))		$this->fk_donation=trim($this->fk_donation);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_donation was declared of type integer, but trim($this->fk_donation) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
275
		if (isset($this->amount))			$this->amount=trim($this->amount);
276
		if (isset($this->fk_typepayment))	$this->fk_typepayment=trim($this->fk_typepayment);
277
		if (isset($this->num_payment))		$this->num_payment=trim($this->num_payment);
278
		if (isset($this->note))				$this->note=trim($this->note);
279
		if (isset($this->fk_bank))			$this->fk_bank=trim($this->fk_bank);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_bank was declared of type integer, but trim($this->fk_bank) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
280
		if (isset($this->fk_user_creat))	$this->fk_user_creat=trim($this->fk_user_creat);
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_creat was declared of type integer, but trim($this->fk_user_creat) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
281
		if (isset($this->fk_user_modif))	$this->fk_user_modif=trim($this->fk_user_modif);
282
283
		// Check parameters
284
		// Put here code to add control on parameters values
285
286
		// Update request
287
		$sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET";
288
		$sql.= " fk_donation=".(isset($this->fk_donation)?$this->fk_donation:"null").",";
289
		$sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
290
		$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
291
		$sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
292
		$sql.= " amount=".(isset($this->amount)?$this->amount:"null").",";
293
		$sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").",";
294
		$sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").",";
295
		$sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
296
		$sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").",";
297
		$sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").",";
298
		$sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null")."";
299
		$sql.= " WHERE rowid=".$this->id;
300
301
		$this->db->begin();
302
303
		dol_syslog(get_class($this)."::update", LOG_DEBUG);
304
		$resql = $this->db->query($sql);
305
		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
306
307
		if (! $error)
308
		{
309
			if (! $notrigger)
310
			{
311
				if (! $error && ! $notrigger)
312
				{
313
					// Call triggers
314
					$result=$this->call_trigger('DONATION_PAYMENT_MODIFY', $user);
315
					if ($result < 0) { $error++; }
316
					// End call triggers
317
				}
318
			}
319
		}
320
321
		// Commit or rollback
322
		if ($error)
323
		{
324
			foreach($this->errors as $errmsg)
325
			{
326
				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
327
				$this->error.=($this->error?', '.$errmsg:$errmsg);
328
			}
329
			$this->db->rollback();
330
			return -1*$error;
331
		}
332
		else
333
		{
334
			$this->db->commit();
335
			return 1;
336
		}
337
	}
338
339
340
	/**
341
	 *  Delete object in database
342
	 *
343
	 *  @param	User	$user        	User that delete
344
	 *  @param  int		$notrigger		0=launch triggers after, 1=disable triggers
345
	 *  @return int						<0 if KO, >0 if OK
346
	 */
347
	public function delete($user, $notrigger = 0)
348
	{
349
		global $conf, $langs;
350
		$error=0;
351
352
		$this->db->begin();
353
354
	    if (! $error)
355
        {
356
            $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
357
            $sql.= " WHERE type='payment_donation' AND url_id=".$this->id;
358
359
            dol_syslog(get_class($this)."::delete", LOG_DEBUG);
360
            $resql = $this->db->query($sql);
361
            if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
362
        }
363
364
		if (! $error)
365
		{
366
			$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation";
367
			$sql.= " WHERE rowid=".$this->id;
368
369
			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
370
			$resql = $this->db->query($sql);
371
			if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
372
		}
373
374
		if (! $error)
375
		{
376
			if (! $notrigger)
377
			{
378
				if (! $error && ! $notrigger)
379
				{
380
					// Call triggers
381
					$result=$this->call_trigger('DONATION_PAYMENT_DELETE', $user);
382
					if ($result < 0) { $error++; }
383
					// End call triggers
384
				}
385
			}
386
		}
387
388
		// Commit or rollback
389
		if ($error)
390
		{
391
			foreach($this->errors as $errmsg)
392
			{
393
				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
394
				$this->error.=($this->error?', '.$errmsg:$errmsg);
395
			}
396
			$this->db->rollback();
397
			return -1*$error;
398
		}
399
		else
400
		{
401
			$this->db->commit();
402
			return 1;
403
		}
404
	}
405
406
407
408
	/**
409
	 *	Load an object from its id and create a new one in database
410
	 *
411
	 *  @param	User	$user		    User making the clone
412
	 *	@param	int		$fromid     	Id of object to clone
413
	 * 	@return	int						New id of clone
414
	 */
415
	public function createFromClone(User $user, $fromid)
416
	{
417
		$error=0;
418
419
		$object=new PaymentDonation($this->db);
420
421
		$this->db->begin();
422
423
		// Load source object
424
		$object->fetch($fromid);
425
		$object->id=0;
426
		$object->statut=0;
427
428
		// Clear fields
429
		// ...
430
431
		// Create clone
432
		$object->context['createfromclone'] = 'createfromclone';
433
		$result=$object->create($user);
434
435
		// Other options
436
		if ($result < 0)
437
		{
438
			$this->error=$object->error;
439
			$error++;
440
		}
441
442
		if (! $error)
443
		{
444
445
		}
446
447
		unset($object->context['createfromclone']);
448
449
		// End
450
		if (! $error)
451
		{
452
			$this->db->commit();
453
			return $object->id;
454
		}
455
		else
456
		{
457
			$this->db->rollback();
458
			return -1;
459
		}
460
	}
461
462
463
	/**
464
	 * 	Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
465
	 *
466
	 *  @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
467
	 *  @return string        		Libelle
468
	 */
469
	public function getLibStatut($mode = 0)
470
	{
471
	    return '';
472
	}
473
474
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
475
	/**
476
	 *  Renvoi le libelle d'un statut donne
477
	 *
478
	 *  @param	int		$statut        	Id statut
479
	 *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
480
	 *  @return string 			       	Libelle du statut
481
	 */
482
    public function LibStatut($statut, $mode = 0)
483
    {
484
        // phpcs:enable
485
        global $langs;
486
487
        return '';
488
    }
489
490
491
	/**
492
     *  Initialise an instance with random values.
493
     *  Used to build previews or test instances.
494
     *	id must be 0 if object instance is a specimen.
495
     *
496
     *  @return	void
497
	 */
498
	public function initAsSpecimen()
499
	{
500
		$this->id=0;
501
502
		$this->fk_donation='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_donation was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
503
		$this->datec='';
504
		$this->tms='';
505
		$this->datep='';
506
		$this->amount='';
507
		$this->fk_typepayment='';
508
		$this->num_payment='';
509
		$this->note='';
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

509
		/** @scrutinizer ignore-deprecated */ $this->note='';
Loading history...
510
		$this->fk_bank='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_bank was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
511
		$this->fk_user_creat='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_creat was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
512
		$this->fk_user_modif='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_modif was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
513
	}
514
515
516
    /**
517
     *      Add record into bank for payment with links between this bank record and invoices of payment.
518
     *      All payment properties must have been set first like after a call to create().
519
     *
520
     *      @param	User	$user               Object of user making payment
521
     *      @param  string	$mode               'payment_donation'
522
     *      @param  string	$label              Label to use in bank record
523
     *      @param  int		$accountid          Id of bank account to do link with
524
     *      @param  string	$emetteur_nom       Name of transmitter
525
     *      @param  string	$emetteur_banque    Name of bank
526
     *      @return int                 		<0 if KO, >0 if OK
527
     */
528
    public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
529
    {
530
        global $conf;
531
532
        $error=0;
533
534
        if (! empty($conf->banque->enabled))
535
        {
536
            require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
537
538
            $acc = new Account($this->db);
539
            $acc->fetch($accountid);
540
541
            $total=$this->total;
1 ignored issue
show
Deprecated Code introduced by
The property PaymentDonation::$total has been deprecated. ( Ignorable by Annotation )

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

541
            $total=/** @scrutinizer ignore-deprecated */ $this->total;
Loading history...
542
            if ($mode == 'payment_donation') $amount=$total;
543
544
            // Insert payment into llx_bank
545
            $bank_line_id = $acc->addline(
546
                $this->datepaid,
0 ignored issues
show
Bug introduced by
The property datepaid does not exist on PaymentDonation. Did you mean datep?
Loading history...
547
                $this->paymenttype,  // Payment mode id or code ("CHQ or VIR for example")
0 ignored issues
show
Bug Best Practice introduced by
The property paymenttype does not exist on PaymentDonation. Did you maybe forget to declare it?
Loading history...
548
                $label,
549
                $amount,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $amount does not seem to be defined for all execution paths leading up to this point.
Loading history...
550
                $this->num_payment,
551
                '',
552
                $user,
553
                $emetteur_nom,
554
                $emetteur_banque
555
            );
556
557
            // Update fk_bank in llx_paiement.
558
            // On connait ainsi le paiement qui a genere l'ecriture bancaire
559
            if ($bank_line_id > 0)
560
            {
561
                $result=$this->update_fk_bank($bank_line_id);
562
                if ($result <= 0)
563
                {
564
                    $error++;
565
                    dol_print_error($this->db);
566
                }
567
568
                // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction
569
                $url='';
570
                if ($mode == 'payment_donation') $url=DOL_URL_ROOT.'/don/payment/card.php?rowid=';
571
                if ($url)
572
                {
573
                    $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
574
                    if ($result <= 0)
575
                    {
576
                        $error++;
577
                        dol_print_error($this->db);
578
                    }
579
                }
580
            }
581
            else
582
            {
583
                $this->error=$acc->error;
584
                $error++;
585
            }
586
        }
587
588
        if (! $error)
589
        {
590
            return 1;
591
        }
592
        else
593
        {
594
            return -1;
595
        }
596
    }
597
598
599
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
600
    /**
601
	 *  Update link between the donation payment and the generated line in llx_bank
602
	 *
603
	 *  @param	int		$id_bank         Id if bank
604
	 *  @return	int			             >0 if OK, <=0 if KO
605
	 */
606
	public function update_fk_bank($id_bank)
607
	{
608
        // phpcs:enable
609
		$sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id;
610
611
		dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
612
		$result = $this->db->query($sql);
613
		if ($result)
614
		{
615
			return 1;
616
		}
617
		else
618
		{
619
			$this->error=$this->db->error();
620
			return 0;
621
		}
622
	}
623
624
	/**
625
	 *  Return clicable name (with picto eventually)
626
	 *
627
	 *	@param	int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
628
	 * 	@param	int		$maxlen			Longueur max libelle
629
	 *	@return	string					Chaine avec URL
630
	 */
631
	public function getNomUrl($withpicto = 0, $maxlen = 0)
632
	{
633
		global $langs;
634
635
		$result='';
636
637
		if (empty($this->ref)) $this->ref=$this->lib;
0 ignored issues
show
Bug Best Practice introduced by
The property lib does not exist on PaymentDonation. Did you maybe forget to declare it?
Loading history...
638
        $label = $langs->trans("ShowPayment").': '.$this->ref;
639
640
		if (!empty($this->id))
641
		{
642
			$link = '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
643
			$linkend='</a>';
644
645
            if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
646
			if ($withpicto && $withpicto != 2) $result.=' ';
647
			if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref, $maxlen):$this->ref).$linkend;
648
		}
649
650
		return $result;
651
	}
652
}
653