Passed
Branch develop (c36c8e)
by
unknown
39:14
created

Loan::set_started()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 12
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) 2014-2018  Alexandre Spangaro   <[email protected]>
3
 * Copyright (C) 2015-2018  Frédéric France      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 *  \file       htdocs/loan/class/loan.class.php
21
 *  \ingroup    loan
22
 *  \brief      Class for loan module
23
 */
24
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
25
26
27
/**
28
 *  Loan
29
 */
30
class Loan extends CommonObject
31
{
32
	/**
33
	 * @var string ID to identify managed object
34
	 */
35
	public $element = 'loan';
36
37
	public $table = 'loan';
38
39
	/**
40
	 * @var string Name of table without prefix where object is stored
41
	 */
42
	public $table_element = 'loan';
43
44
	/**
45
	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
46
	 */
47
	public $picto = 'money-bill-alt';
48
49
	/**
50
	 * @var int ID
51
	 */
52
	public $rowid;
53
54
	public $datestart;
55
	public $dateend;
56
57
    /**
58
     * @var string Loan label
59
     */
60
    public $label;
61
62
	public $capital;
63
	public $nbterm;
64
	public $rate;
65
	public $paid;
66
	public $account_capital;
67
	public $account_insurance;
68
	public $account_interest;
69
70
	/**
71
     * @var integer|string date_creation
72
     */
73
	public $date_creation;
74
75
	/**
76
	 * @var integer|string date_modification
77
	 */
78
	public $date_modification;
79
80
	/**
81
	 * @var integer|string date_validation
82
	 */
83
	public $date_validation;
84
85
	public $insurance_amount;
86
87
	/**
88
     * @var int Bank ID
89
     */
90
	public $fk_bank;
91
92
	/**
93
     * @var int ID
94
     */
95
	public $fk_user_creat;
96
97
	/**
98
     * @var int ID
99
     */
100
	public $fk_user_modif;
101
102
	/**
103
     * @var int ID
104
     */
105
	public $fk_project;
106
107
108
	const STATUS_UNPAID = 0;
109
	const STATUS_PAID = 1;
110
    const STATUS_STARTED = 2;
111
112
113
	/**
114
	 * Constructor
115
	 *
116
	 * @param	DoliDB		$db		Database handler
117
	 */
118
	public function __construct($db)
119
	{
120
		$this->db = $db;
121
	}
122
123
	/**
124
	 *  Load object in memory from database
125
	 *
126
	 *  @param	int		$id		 id object
127
	 *  @return int				 <0 error , >=0 no error
128
	 */
129
	public function fetch($id)
130
	{
131
		$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public, l.insurance_amount,";
132
		$sql .= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
133
		$sql .= " FROM ".MAIN_DB_PREFIX."loan as l";
134
		$sql .= " WHERE l.rowid = ".$id;
135
136
		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
137
		$resql = $this->db->query($sql);
138
		if ($resql)
139
		{
140
			if ($this->db->num_rows($resql))
141
			{
142
				$obj = $this->db->fetch_object($resql);
143
144
				$this->id = $obj->rowid;
145
				$this->ref = $obj->rowid;
146
				$this->datestart = $this->db->jdate($obj->datestart);
147
				$this->dateend				= $this->db->jdate($obj->dateend);
148
				$this->label				= $obj->label;
149
				$this->capital				= $obj->capital;
150
				$this->nbterm = $obj->nbterm;
151
				$this->rate					= $obj->rate;
152
				$this->note_private = $obj->note_private;
153
				$this->note_public = $obj->note_public;
154
				$this->insurance_amount = $obj->insurance_amount;
155
				$this->paid = $obj->paid;
156
157
				$this->account_capital = $obj->accountancy_account_capital;
158
				$this->account_insurance	= $obj->accountancy_account_insurance;
159
				$this->account_interest		= $obj->accountancy_account_interest;
160
				$this->fk_project = $obj->fk_project;
161
162
				$this->db->free($resql);
163
				return 1;
164
			} else {
165
				$this->db->free($resql);
166
				return 0;
167
			}
168
		} else {
169
			$this->error = $this->db->lasterror();
170
			return -1;
171
		}
172
	}
173
174
175
	/**
176
	 *  Create a loan into database
177
	 *
178
	 *  @param	User	$user	User making creation
179
	 *  @return int				<0 if KO, id if OK
180
	 */
181
	public function create($user)
182
	{
183
		global $conf, $langs;
184
185
		$error = 0;
186
187
		$now = dol_now();
188
189
		// clean parameters
190
		$newcapital = price2num($this->capital, 'MT');
191
		if (empty($this->insurance_amount)) $this->insurance_amount = 0;
192
		$newinsuranceamount = price2num($this->insurance_amount, 'MT');
193
		if (isset($this->note_private)) $this->note_private = trim($this->note_private);
194
		if (isset($this->note_public)) $this->note_public = trim($this->note_public);
195
		if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital);
196
		if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance);
197
		if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest);
198
		if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
199
		if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat;
200
		if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
201
		if (isset($this->fk_project)) $this->fk_project = (int) $this->fk_project;
202
203
		// Check parameters
204
		if (!$newcapital > 0 || empty($this->datestart) || empty($this->dateend))
205
		{
206
			$this->error = "ErrorBadParameter";
207
			return -2;
208
		}
209
		if (($conf->accounting->enabled) && empty($this->account_capital))
210
		{
211
			$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyCapitalCode"));
212
			return -2;
213
		}
214
		if (($conf->accounting->enabled) && empty($this->account_insurance))
215
		{
216
			$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInsuranceCode"));
217
			return -2;
218
		}
219
		if (($conf->accounting->enabled) && empty($this->account_interest))
220
		{
221
			$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("LoanAccountancyInterestCode"));
222
			return -2;
223
		}
224
225
		$this->db->begin();
226
227
		$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
228
		$sql .= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
229
		$sql .= " datec, fk_projet, fk_user_author, insurance_amount)";
230
		$sql .= " VALUES ('".$this->db->escape($this->label)."',";
231
		$sql .= " '".$this->db->escape($this->fk_bank)."',";
232
		$sql .= " '".price2num($newcapital)."',";
233
		$sql .= " '".$this->db->idate($this->datestart)."',";
234
		$sql .= " '".$this->db->idate($this->dateend)."',";
235
		$sql .= " '".$this->db->escape($this->nbterm)."',";
236
		$sql .= " '".$this->db->escape($this->rate)."',";
237
		$sql .= " '".$this->db->escape($this->note_private)."',";
238
		$sql .= " '".$this->db->escape($this->note_public)."',";
239
		$sql .= " '".$this->db->escape($this->account_capital)."',";
240
		$sql .= " '".$this->db->escape($this->account_insurance)."',";
241
		$sql .= " '".$this->db->escape($this->account_interest)."',";
242
		$sql .= " ".$conf->entity.",";
243
		$sql .= " '".$this->db->idate($now)."',";
244
		$sql .= " ".(empty($this->fk_project) ? 'NULL' : $this->fk_project).",";
245
		$sql .= " ".$user->id.",";
246
		$sql .= " '".price2num($newinsuranceamount)."'";
247
		$sql .= ")";
248
249
		dol_syslog(get_class($this)."::create", LOG_DEBUG);
250
		$resql = $this->db->query($sql);
251
		if ($resql)
252
		{
253
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."loan");
254
255
			//dol_syslog("Loans::create this->id=".$this->id);
256
			$this->db->commit();
257
			return $this->id;
258
		} else {
259
			$this->error = $this->db->error();
260
			$this->db->rollback();
261
			return -1;
262
		}
263
	}
264
265
266
	/**
267
	 *  Delete a loan
268
	 *
269
	 *  @param	User	$user	Object user making delete
270
	 *  @return int 			<0 if KO, >0 if OK
271
	 */
272
	public function delete($user)
273
	{
274
		$error = 0;
275
276
		$this->db->begin();
277
278
		// Get bank transaction lines for this loan
279
		include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
280
		$account = new Account($this->db);
281
		$lines_url = $account->get_url('', $this->id, 'loan');
282
283
		// Delete bank urls
284
		foreach ($lines_url as $line_url)
285
		{
286
			if (!$error)
287
			{
288
				$accountline = new AccountLine($this->db);
289
				$accountline->fetch($line_url['fk_bank']);
290
				$result = $accountline->delete_urls($user);
291
				if ($result < 0)
292
				{
293
					$error++;
294
				}
295
			}
296
		}
297
298
		// Delete payments
299
		if (!$error)
300
		{
301
			$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id;
302
			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
303
			$resql = $this->db->query($sql);
304
			if (!$resql)
305
			{
306
				$error++;
307
				$this->error = $this->db->lasterror();
308
			}
309
		}
310
311
		if (!$error)
312
		{
313
			$sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id;
314
			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
315
			$resql = $this->db->query($sql);
316
			if (!$resql)
317
			{
318
				$error++;
319
				$this->error = $this->db->lasterror();
320
			}
321
		}
322
323
		if (!$error)
324
		{
325
			$this->db->commit();
326
			return 1;
327
		} else {
328
			$this->db->rollback();
329
			return -1;
330
		}
331
	}
332
333
334
	/**
335
	 *  Update loan
336
	 *
337
	 *  @param	User	$user	User who modified
338
	 *  @return int				<0 if error, >0 if ok
339
	 */
340
	public function update($user)
341
	{
342
		$this->db->begin();
343
344
		if (!is_numeric($this->nbterm))
345
		{
346
			$this->error = 'BadValueForParameterForNbTerm';
347
			return -1;
348
		}
349
350
		$sql = "UPDATE ".MAIN_DB_PREFIX."loan";
351
		$sql .= " SET label='".$this->db->escape($this->label)."',";
352
		$sql .= " capital='".price2num($this->db->escape($this->capital))."',";
353
		$sql .= " datestart='".$this->db->idate($this->datestart)."',";
354
		$sql .= " dateend='".$this->db->idate($this->dateend)."',";
355
		$sql .= " nbterm=".$this->nbterm.",";
356
		$sql .= " rate=".$this->db->escape($this->rate).",";
357
		$sql .= " accountancy_account_capital = '".$this->db->escape($this->account_capital)."',";
358
		$sql .= " accountancy_account_insurance = '".$this->db->escape($this->account_insurance)."',";
359
		$sql .= " accountancy_account_interest = '".$this->db->escape($this->account_interest)."',";
360
		$sql .= " fk_projet=".(empty($this->fk_project) ? 'NULL' : $this->fk_project).",";
361
		$sql .= " fk_user_modif = ".$user->id.",";
362
		$sql .= " insurance_amount = '".price2num($this->db->escape($this->insurance_amount))."'";
363
		$sql .= " WHERE rowid=".$this->id;
364
365
		dol_syslog(get_class($this)."::update", LOG_DEBUG);
366
		$resql = $this->db->query($sql);
367
		if ($resql)
368
		{
369
			$this->db->commit();
370
			return 1;
371
		} else {
372
			$this->error = $this->db->error();
373
			$this->db->rollback();
374
			return -1;
375
		}
376
	}
377
378
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
379
	/**
380
	 *  Tag loan as payed completely
381
	 *
382
	 *  @param	User	$user	Object user making change
383
	 *  @return	int				<0 if KO, >0 if OK
384
	 */
385
	public function set_paid($user)
386
	{
387
        // phpcs:enable
388
		$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
389
		$sql .= " paid = ".$this::STATUS_PAID;
390
		$sql .= " WHERE rowid = ".$this->id;
391
		$return = $this->db->query($sql);
392
		if ($return) {
393
			return 1;
394
		} else {
395
			$this->error = $this->db->lasterror();
396
			return -1;
397
		}
398
	}
399
400
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
401
	/**
402
	 *  Tag loan as payement started
403
	 *
404
	 *  @param	User	$user	Object user making change
405
	 *  @return	int				<0 if KO, >0 if OK
406
	 */
407
	public function set_started($user)
408
	{
409
        // phpcs:enable
410
		$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
411
		$sql .= " paid = ".$this::STATUS_STARTED;
412
		$sql .= " WHERE rowid = ".$this->id;
413
		$return = $this->db->query($sql);
414
		if ($return) {
415
			return 1;
416
		} else {
417
			$this->error = $this->db->lasterror();
418
			return -1;
419
		}
420
	}
421
422
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
423
	/**
424
	 *  Tag loan as payement as unpaid
425
	 *
426
	 *  @param	User	$user	Object user making change
427
	 *  @return	int				<0 if KO, >0 if OK
428
	 */
429
	public function set_unpaid($user)
430
	{
431
        // phpcs:enable
432
		$sql = "UPDATE ".MAIN_DB_PREFIX."loan SET";
433
		$sql .= " paid = ".$this::STATUS_UNPAID;
434
		$sql .= " WHERE rowid = ".$this->id;
435
		$return = $this->db->query($sql);
436
		if ($return) {
437
			return 1;
438
		} else {
439
			$this->error = $this->db->lasterror();
440
			return -1;
441
		}
442
	}
443
444
	/**
445
	 *  Return label of loan status (unpaid, paid)
446
	 *
447
	 *  @param  int		$mode			0=label, 1=short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label
448
	 *  @param  integer	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
449
	 *  @return string					Label
450
	 */
451
	public function getLibStatut($mode = 0, $alreadypaid = -1)
452
	{
453
		return $this->LibStatut($this->paid, $mode, $alreadypaid);
454
	}
455
456
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
457
	/**
458
	 *  Return label for given status
459
	 *
460
	 *  @param  int		$status			Id status
461
	 *  @param  int		$mode			0=Label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Label, 5=Short label + Picto
462
	 *  @param  integer	$alreadypaid	0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise)
463
	 *  @return string					Label
464
	 */
465
	public function LibStatut($status, $mode = 0, $alreadypaid = -1)
466
	{
467
		// phpcs:enable
468
		global $langs;
469
470
		// Load translation files required by the page
471
		$langs->loadLangs(array("customers", "bills"));
472
473
		unset($this->labelStatus); // Force to reset the array of status label, because label can change depending on parameters
474
		if (empty($this->labelStatus) || empty($this->labelStatusShort))
475
		{
476
			global $langs;
477
			$this->labelStatus[self::STATUS_UNPAID] = $langs->trans('Unpaid');
478
			$this->labelStatus[self::STATUS_PAID] = $langs->trans('Paid');
479
            $this->labelStatus[self::STATUS_STARTED] = $langs->trans("BillStatusStarted");
480
			if ($status == 0 && $alreadypaid > 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted");
481
			$this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('Unpaid');
482
			$this->labelStatusShort[self::STATUS_PAID] = $langs->trans('Enabled');
483
            $this->labelStatusShort[self::STATUS_STARTED] = $langs->trans("BillStatusStarted");
484
			if ($status == 0 && $alreadypaid > 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted");
485
		}
486
487
		$statusType = 'status1';
488
		if (($status == 0 && $alreadypaid > 0) || $status == self::STATUS_STARTED) $statusType = 'status3';
489
		if ($status == 1) $statusType = 'status6';
490
491
		return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
492
	}
493
494
495
	/**
496
	 *  Return clicable name (with eventually the picto)
497
	 *
498
	 *  @param	int		$withpicto					0=No picto, 1=Include picto into link, 2=Only picto
499
	 *  @param	int		$maxlen						Label max length
500
     *  @param  string  $option        				On what the link point to ('nolink', ...)
501
     *  @param  int     $notooltip                  1=Disable tooltip
502
     *  @param  string  $morecss                    Add more css on link
503
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
504
	 *  @return	string								Chaine with URL
505
	 */
506
	public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
507
	{
508
		global $conf, $langs;
509
510
		$result = '';
511
512
		$label = '<u>'.$langs->trans("ShowLoan").'</u>';
513
		if (!empty($this->ref)) {
514
			$label .= '<br><strong>'.$langs->trans('Ref').':</strong> '.$this->ref;
515
		}
516
		if (!empty($this->label)) {
517
			$label .= '<br><strong>'.$langs->trans('Label').':</strong> '.$this->label;
518
		}
519
520
		$url = DOL_URL_ROOT.'/loan/card.php?id='.$this->id;
521
522
		if ($option != 'nolink')
523
		{
524
			// Add param to save lastsearch_values or not
525
			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
526
			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
527
			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
528
		}
529
530
		$linkclose = '';
531
		if (empty($notooltip))
532
		{
533
			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
534
			{
535
				$label = $langs->trans("ShowMyObject");
536
				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
537
			}
538
			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
539
			$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
540
		} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
541
542
		$linkstart = '<a href="'.$url.'"';
543
		$linkstart .= $linkclose.'>';
544
		$linkend = '</a>';
545
546
		$result .= $linkstart;
547
		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
548
		if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref);
549
		$result .= $linkend;
550
551
		return $result;
552
	}
553
554
	/**
555
	 *  Initialise an instance with random values.
556
	 *  Used to build previews or test instances.
557
	 * 	id must be 0 if object instance is a specimen.
558
	 *
559
	 *  @return	void
560
	 */
561
	public function initAsSpecimen()
562
	{
563
	    global $user, $langs, $conf;
564
565
	    $now = dol_now();
566
567
	    // Initialise parameters
568
	    $this->id = 0;
569
	    $this->fk_bank = 1;
570
	    $this->label = 'SPECIMEN';
571
	    $this->specimen = 1;
572
	    $this->socid = 1;
573
	    $this->account_capital = 16;
574
	    $this->account_insurance = 616;
575
	    $this->account_interest = 518;
576
	    $this->datestart = $now;
577
	    $this->dateend = $now + (3600 * 24 * 365);
578
	    $this->note_public = 'SPECIMEN';
579
	    $this->capital = 20000;
580
	    $this->nbterm = 48;
581
	    $this->rate = 4.3;
582
	}
583
584
	/**
585
	 *  Return amount of payments already done
586
	 *
587
	 *  @return		int		Amount of payment already done, <0 if KO
588
	 */
589
	public function getSumPayment()
590
	{
591
		$table = 'payment_loan';
592
		$field = 'fk_loan';
593
594
		$sql = 'SELECT sum(amount_capital) as amount';
595
		$sql .= ' FROM '.MAIN_DB_PREFIX.$table;
596
		$sql .= ' WHERE '.$field.' = '.$this->id;
597
598
		dol_syslog(get_class($this)."::getSumPayment", LOG_DEBUG);
599
		$resql = $this->db->query($sql);
600
		if ($resql)
601
		{
602
			$amount = 0;
603
604
			$obj = $this->db->fetch_object($resql);
605
			if ($obj) $amount = $obj->amount ? $obj->amount : 0;
606
607
			$this->db->free($resql);
608
			return $amount;
609
		} else {
610
			$this->error = $this->db->lasterror();
611
			return -1;
612
		}
613
	}
614
615
	/**
616
	 *  Information on record
617
	 *
618
	 *  @param	int			$id		Id of record
619
	 *  @return	integer|null
620
	 */
621
	public function info($id)
622
	{
623
		$sql = 'SELECT l.rowid, l.datec, l.fk_user_author, l.fk_user_modif,';
624
		$sql .= ' l.tms';
625
		$sql .= ' WHERE l.rowid = '.$id;
626
627
		dol_syslog(get_class($this).'::info', LOG_DEBUG);
628
		$result = $this->db->query($sql);
629
630
		if ($result)
631
		{
632
			if ($this->db->num_rows($result))
633
			{
634
				$obj = $this->db->fetch_object($result);
635
				$this->id = $obj->rowid;
636
				if ($obj->fk_user_author)
637
				{
638
					$cuser = new User($this->db);
639
					$cuser->fetch($obj->fk_user_author);
640
					$this->user_creation = $cuser;
641
				}
642
				if ($obj->fk_user_modif)
643
				{
644
					$muser = new User($this->db);
645
					$muser->fetch($obj->fk_user_modif);
646
					$this->user_modification = $muser;
647
				}
648
				$this->date_creation = $this->db->jdate($obj->datec);
649
				if (empty($obj->fk_user_modif)) $obj->tms = "";
650
				$this->date_modification = $this->db->jdate($obj->tms);
651
652
				$this->db->free($result);
653
				return 1;
654
			} else {
655
				$this->db->free($result);
656
				return 0;
657
			}
658
		} else {
659
			$this->error = $this->db->lasterror();
660
			return -1;
661
		}
662
    }
663
}
664