/
paymentsocialcontribution.class.php
843 lines (727 loc) · 22.9 KB
/
paymentsocialcontribution.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<?php
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/compta/sociales/class/paymentsocialcontribution.class.php
* \ingroup facture
* \brief File of class to manage payment of social contributions
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
/**
* Class to manage payments of social contributions
*/
class PaymentSocialContribution extends CommonObject
{
/**
* @var string ID to identify managed object
*/
public $element = 'paiementcharge';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'paiementcharge';
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'payment';
/**
* @var string Label
*/
public $label;
/**
* @var int ID
*/
public $fk_charge;
public $datec = '';
public $datep = '';
/**
* @var string
*/
public $type_code;
/**
* @var string
*/
public $type_label;
/**
* @var int
*/
public $bank_account;
/**
* @var int
*/
public $bank_line;
/**
* @deprecated Use $amount instead.
* @see $amount
* @var float|int
*/
public $total;
/**
* @var float|int
*/
public $amount; // Total amount of payment
/**
* @var array<float|int>
*/
public $amounts = array(); // Array of amounts
/**
* @var int ID
*/
public $fk_typepaiement;
/**
* @var string
* @deprecated Use $num_payment instead
* @see $num_payment
*/
public $num_paiement;
/**
* @var string Payment reference
* (Cheque or bank transfer reference. Can be "ABC123")
*/
public $num_payment;
/**
* @var int ID
*/
public $fk_bank;
/**
* @var int ID
*/
public $fk_user_creat;
/**
* @var int ID
*/
public $fk_user_modif;
/**
* @var int ID
*/
public $chid;
/**
* @var integer|string datepaye
*/
public $datepaye;
/**
* @var integer|string paiementtype
*/
public $paiementtype;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct(DoliDB $db)
{
$this->db = $db;
}
/**
* Create payment of social contribution into database.
* Use this->amounts to have list of lines for the payment
*
* @param User $user User making payment
* @param int $closepaidcontrib 1=Also close paid contributions to paid, 0=Do nothing more
* @return int Return integer <0 if KO, id of payment if OK
*/
public function create($user, $closepaidcontrib = 0)
{
global $conf, $langs;
$error = 0;
$now = dol_now();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
// Validate parameters
if (!$this->datepaye) {
$this->error = 'ErrorBadValueForParameterCreatePaymentSocialContrib';
return -1;
}
// Clean parameters
if (isset($this->fk_charge)) {
$this->fk_charge = (int) $this->fk_charge;
}
if (isset($this->amount)) {
$this->amount = (float) $this->amount;
}
if (isset($this->fk_typepaiement)) {
$this->fk_typepaiement = (int) $this->fk_typepaiement;
}
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
if (isset($this->note_private)) {
$this->note_private = trim($this->note_private);
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
$totalamount = 0;
foreach ($this->amounts as $key => $value) { // How payment is dispatch
$newvalue = (float) price2num($value, 'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = (float) price2num($totalamount);
// Check parameters
if ($totalamount == 0) {
return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
}
$this->db->begin();
if ($totalamount != 0) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
$sql .= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
$sql .= " VALUES ($this->chid, '".$this->db->idate($now)."',";
$sql .= " '".$this->db->idate($this->datepaye)."',";
$sql .= " ".((float) $totalamount).",";
$sql .= " ".((int) $this->paiementtype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.",";
$sql .= " 0)";
$resql = $this->db->query($sql);
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
// Insere tableau des montants / factures
foreach ($this->amounts as $key => $amount) {
$contribid = $key;
if (is_numeric($amount) && $amount != 0) {
$amount = (float) price2num($amount);
// If we want to closed paid invoices
if ($closepaidcontrib) {
$contrib = new ChargeSociales($this->db);
$contrib->fetch($contribid);
$paiement = $contrib->getSommePaiement();
//$creditnotes=$contrib->getSumCreditNotesUsed();
$creditnotes = 0;
//$deposits=$contrib->getSumDepositsUsed();
$deposits = 0;
$alreadypayed = (float) price2num($paiement + $creditnotes + $deposits, 'MT');
$remaintopay = (float) price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT');
if ($remaintopay == 0) {
$result = $contrib->setPaid($user);
} else {
dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
}
}
}
}
} else {
$error++;
}
}
$result = $this->call_trigger('PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
if ($result < 0) {
$error++;
}
if ($totalamount != 0 && !$error) {
$this->amount = $totalamount;
$this->total = $totalamount; // deprecated
$this->db->commit();
return $this->id;
} else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Load object in memory from database
*
* @param int $id Id object
* @return int Return integer <0 if KO, >0 if OK
*/
public function fetch($id)
{
global $langs;
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.fk_charge,";
$sql .= " t.datec,";
$sql .= " t.tms,";
$sql .= " t.datep,";
$sql .= " t.amount,";
$sql .= " t.fk_typepaiement,";
$sql .= " t.num_paiement as num_payment,";
$sql .= " t.note,";
$sql .= " t.fk_bank,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,";
$sql .= " pt.code as type_code, pt.libelle as type_label,";
$sql .= ' b.fk_account';
$sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepaiement = pt.id";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
$sql .= " WHERE t.rowid = ".((int) $id);
// TODO link on entity of tax;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->fk_charge = $obj->fk_charge;
$this->datec = $this->db->jdate($obj->datec);
$this->tms = $this->db->jdate($obj->tms);
$this->datep = $this->db->jdate($obj->datep);
$this->amount = $obj->amount;
$this->total = $obj->amount;
$this->fk_typepaiement = $obj->fk_typepaiement;
$this->num_payment = $obj->num_payment;
$this->num_paiement = $obj->num_payment;
$this->note_private = $obj->note;
$this->fk_bank = $obj->fk_bank;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
$this->type_code = $obj->type_code;
$this->type_label = $obj->type_label;
$this->bank_account = $obj->fk_account;
$this->bank_line = $obj->fk_bank;
}
$this->db->free($resql);
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int Return integer <0 if KO, >0 if OK
*/
public function update($user = null, $notrigger = 0)
{
global $conf, $langs;
$error = 0;
// Clean parameters
if (isset($this->fk_charge)) {
$this->fk_charge = (int) $this->fk_charge;
}
if (isset($this->amount)) {
$this->amount = (float) $this->amount;
}
if (isset($this->fk_typepaiement)) {
$this->fk_typepaiement = (int) $this->fk_typepaiement;
}
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
if (isset($this->note_private)) {
$this->note_private = trim($this->note_private);
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET";
$sql .= " fk_charge=".(isset($this->fk_charge) ? ((int) $this->fk_charge) : "null").",";
$sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
$sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
$sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
$sql .= " amount=".(isset($this->amount) ? price2num($this->amount) : "null").",";
$sql .= " fk_typepaiement=".(isset($this->fk_typepaiement) ? ((int) $this->fk_typepaiement) : "null").",";
$sql .= " num_paiement=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
$sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
$sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").",";
$sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) : "null").",";
$sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null");
$sql .= " WHERE rowid=".((int) $this->id);
$this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Delete object in database
*
* @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int Return integer <0 if KO, >0 if OK
*/
public function delete($user, $notrigger = 0)
{
$error = 0;
dol_syslog(get_class($this)."::delete");
$this->db->begin();
if ($this->bank_line > 0) {
$accline = new AccountLine($this->db);
$accline->fetch($this->bank_line);
$result = $accline->delete($user);
if ($result < 0) {
$this->errors[] = $accline->error;
$error++;
}
}
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge";
$sql .= " WHERE rowid=".((int) $this->id);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
// Commit or rollback
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return 1;
}
}
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone(User $user, $fromid)
{
$error = 0;
$object = new PaymentSocialContribution($this->db);
$this->db->begin();
// Load source object
$object->fetch($fromid);
$object->id = 0;
$object->statut = 0;
// Clear fields
// ...
// Create clone
$object->context['createfromclone'] = 'createfromclone';
$result = $object->create($user);
// Other options
if ($result < 0) {
$this->error = $object->error;
$error++;
}
unset($object->context['createfromclone']);
// End
if (!$error) {
$this->db->commit();
return $object->id;
} else {
$this->db->rollback();
return -1;
}
}
/**
* Initialise an instance with random values.
* Used to build previews or test instances.
* id must be 0 if object instance is a specimen.
*
* @return int
*/
public function initAsSpecimen()
{
$this->id = 0;
$this->fk_charge = 0;
$this->datec = dol_now();
$this->tms = dol_now();
$this->datep = dol_now();
$this->amount = 100;
$this->fk_typepaiement = 0;
$this->num_payment = 'ABC123';
$this->note_private = '';
$this->note_public = '';
$this->fk_bank = 0;
$this->fk_user_creat = 0;
$this->fk_user_modif = 0;
return 1;
}
/**
* Add record into bank for payment with links between this bank record and invoices of payment.
* All payment properties must have been set first like after a call to create().
*
* @param User $user Object of user making payment
* @param string $mode 'payment_sc'
* @param string $label Label to use in bank record
* @param int $accountid Id of bank account to do link with
* @param string $emetteur_nom Name of transmitter
* @param string $emetteur_banque Name of bank
* @return int Return integer <0 if KO, >0 if OK
*/
public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
{
global $conf, $langs;
// Clean data
$this->num_payment = trim($this->num_payment);
$error = 0;
if (isModEnabled("bank")) {
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
$acc->fetch($accountid);
$total = $this->amount;
if ($mode == 'payment_sc') {
$total = -$total;
}
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
$this->datepaye,
$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
$label,
$total,
$this->num_payment,
'',
$user,
$emetteur_nom,
$emetteur_banque
);
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0) {
$result = $this->update_fk_bank($bank_line_id);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
$url = '';
if ($mode == 'payment_sc') {
$url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
}
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
}
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
$linkaddedforthirdparty = array();
foreach ($this->amounts as $key => $value) {
if ($mode == 'payment_sc') {
$socialcontrib = new ChargeSociales($this->db);
$socialcontrib->fetch($key);
$result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc');
if ($result <= 0) {
dol_print_error($this->db);
}
if ($socialcontrib->fk_user) {
$fuser = new User($this->db);
$fuser->fetch($socialcontrib->fk_user);
// Add link 'user' in bank_url between operation and bank transaction
$result = $acc->add_url_line(
$bank_line_id,
$socialcontrib->fk_user,
DOL_URL_ROOT.'/user/card.php?id=',
$fuser->getFullName($langs),
'user'
);
if ($result <= 0) {
$this->error = $acc->error;
$error++;
}
}
}
}
} else {
$this->error = $acc->error;
$error++;
}
}
if (!$error) {
return 1;
} else {
return -1;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee
*
* @param int $id_bank Id if bank
* @return int >0 if OK, <=0 if KO
*/
public function update_fk_bank($id_bank)
{
// phpcs:enable
$sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
return 1;
} else {
$this->error = $this->db->error();
return 0;
}
}
/**
* Return the label of the status
*
* @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
* @return string Label of status
*/
public function getLibStatut($mode = 0)
{
return $this->LibStatut($this->statut, $mode);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return the label of a given status
*
* @param int $status Id status
* @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
* @return string Label of status
*/
public function LibStatut($status, $mode = 0)
{
// phpcs:enable
global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
$langs->load('compta');
/*if ($mode == 0)
{
if ($status == 0) return $langs->trans('ToValidate');
if ($status == 1) return $langs->trans('Validated');
}
if ($mode == 1)
{
if ($status == 0) return $langs->trans('ToValidate');
if ($status == 1) return $langs->trans('Validated');
}
if ($mode == 2)
{
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
}
if ($mode == 3)
{
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
}
if ($mode == 4)
{
if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
}
if ($mode == 5)
{
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
}
if ($mode == 6)
{
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
}*/
return '';
}
/**
* Return clicable name (with picto eventually)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param int $maxlen Longueur max libelle
* @return string Chaine avec URL
*/
public function getNomUrl($withpicto = 0, $maxlen = 0)
{
global $langs;
$result = '';
if (empty($this->ref)) {
$this->ref = $this->label;
}
$label = img_picto('', $this->picto).' <u>'.$langs->trans("SocialContributionPayment").'</u>';
$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
if (!empty($this->label)) {
$labeltoshow = $this->label;
$reg = array();
if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) {
// Label generique car entre parentheses. On l'affiche en le traduisant
if ($reg[1] == 'paiement') {
$reg[1] = 'Payment';
}
$labeltoshow = $langs->trans($reg[1]);
}
$label .= '<br><b>'.$langs->trans('Label').':</b> '.$labeltoshow;
}
if ($this->datep) {
$label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'day');
}
if (!empty($this->id)) {
$link = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>';
if ($withpicto) {
$result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
}
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
}
}
return $result;
}
/**
* Return if object was dispatched into bookkeeping
*
* @return int Return integer <0 if KO, 0=no, 1=yes
*/
public function getVentilExportCompta()
{
$alreadydispatched = 0;
$type = 'bank';
$sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->bank_line);
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) {
$alreadydispatched = $obj->nb;
}
} else {
$this->error = $this->db->lasterror();
return -1;
}
if ($alreadydispatched) {
return 1;
}
return 0;
}
}