Passed
Push — GENERAL_BUG_REVIEW_240911 ( 6dbc7d...fb375d )
by Rafael
53:50
created
Dolibarr/Code/Variants/Classes/ProductAttribute.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         }
514 514
     }
515 515
 
516
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
516
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
517 517
     /**
518 518
      * Load array lines
519 519
      *
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
      */
523 523
     public function fetch_lines($filters = '')
524 524
     {
525
-		// phpcs:enable
525
+        // phpcs:enable
526 526
         global $langs;
527 527
 
528 528
         $this->lines = array();
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
         return $this->LibStatut(0, $mode);
1243 1243
     }
1244 1244
 
1245
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1245
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1246 1246
     /**
1247 1247
      * Return label of a status
1248 1248
      *
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
      */
1253 1253
     public function LibStatut($status, $mode = 1)
1254 1254
     {
1255
-		// phpcs:enable
1255
+        // phpcs:enable
1256 1256
         return '';
1257 1257
     }
1258 1258
 
Please login to merge, or discard this patch.
Dolibarr/Code/Accountancy/Classes/AccountingJournal.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
         return $this->LibType($this->nature, $mode);
338 338
     }
339 339
 
340
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
340
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
341 341
     /**
342 342
      *  Return type of an accounting journal
343 343
      *
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function LibType($nature, $mode = 0)
349 349
     {
350
-		// phpcs:enable
350
+        // phpcs:enable
351 351
         global $langs;
352 352
 
353 353
         $langs->loadLangs(array("accountancy"));
Please login to merge, or discard this patch.
Dolibarr/Code/Accountancy/Classes/AccountancyExport.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -2545,14 +2545,14 @@
 block discarded – undo
2545 2545
     }
2546 2546
 
2547 2547
     /**
2548
-    * Export format : iSuite Expert
2549
-    *
2550
-    * by OpenSolus [https://opensolus.fr]
2551
-    *
2548
+     * Export format : iSuite Expert
2549
+     *
2550
+     * by OpenSolus [https://opensolus.fr]
2551
+     *
2552 2552
      * @param   array       $objectLines            data
2553 2553
      * @param   resource    $exportFile             [=null] File resource to export or print if null
2554 2554
      * @return  void
2555
-    */
2555
+     */
2556 2556
     public function exportiSuiteExpert($objectLines, $exportFile = null)
2557 2557
     {
2558 2558
         $separator = ';';
Please login to merge, or discard this patch.
Dolibarr/Code/Accountancy/Classes/BookKeeping.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1987,7 +1987,7 @@  discard block
 block discarded – undo
1987 1987
         return 1;
1988 1988
     }
1989 1989
 
1990
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1990
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1991 1991
     /**
1992 1992
      * Export bookkeeping
1993 1993
      *
@@ -1996,7 +1996,7 @@  discard block
 block discarded – undo
1996 1996
      */
1997 1997
     public function export_bookkeeping($model = 'ebp')
1998 1998
     {
1999
-		// phpcs:enable
1999
+        // phpcs:enable
2000 2000
         global $conf;
2001 2001
 
2002 2002
         $sql = "SELECT rowid, doc_date, doc_type,";
@@ -2180,7 +2180,7 @@  discard block
 block discarded – undo
2180 2180
         */
2181 2181
     }
2182 2182
 
2183
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2183
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2184 2184
     /**
2185 2185
      * Return list of accounts with label by chart of accounts
2186 2186
      *
@@ -2195,7 +2195,7 @@  discard block
 block discarded – undo
2195 2195
      */
2196 2196
     public function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '')
2197 2197
     {
2198
-		// phpcs:enable
2198
+        // phpcs:enable
2199 2199
         global $conf;
2200 2200
 
2201 2201
         require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/accounting.lib.php';
@@ -2292,7 +2292,7 @@  discard block
 block discarded – undo
2292 2292
         }
2293 2293
     }
2294 2294
 
2295
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2295
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2296 2296
     /**
2297 2297
      * Description of accounting account
2298 2298
      *
@@ -2301,7 +2301,7 @@  discard block
 block discarded – undo
2301 2301
      */
2302 2302
     public function get_compte_desc($account = null)
2303 2303
     {
2304
-		// phpcs:enable
2304
+        // phpcs:enable
2305 2305
         global $conf;
2306 2306
 
2307 2307
         $pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
Please login to merge, or discard this patch.
Dolibarr/Code/Accountancy/Classes/AccountingAccount.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
         return $this->LibStatut($this->status, $mode);
699 699
     }
700 700
 
701
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
701
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
702 702
     /**
703 703
      *  Return the label of a given status
704 704
      *
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
      */
709 709
     public function LibStatut($status, $mode = 0)
710 710
     {
711
-		// phpcs:enable
711
+        // phpcs:enable
712 712
         if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
713 713
             global $langs;
714 714
             $langs->load("users");
Please login to merge, or discard this patch.
Dolibarr/Code/Api/Classes/DolibarrApiAccess.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         $this->db = $db;
82 82
     }
83 83
 
84
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName
84
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName
85 85
     /**
86 86
      * Check access
87 87
      *
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public function __isAllowed()
94 94
     {
95
-		// phpcs:enable
95
+        // phpcs:enable
96 96
         global $conf, $db, $user;
97 97
 
98 98
         $login = '';
@@ -229,13 +229,13 @@  discard block
 block discarded – undo
229 229
         return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin';
230 230
     }
231 231
 
232
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName
232
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName
233 233
     /**
234 234
      * @return string string to be used with WWW-Authenticate header
235 235
      */
236 236
     public function __getWWWAuthenticateString()
237 237
     {
238
-		// phpcs:enable
238
+        // phpcs:enable
239 239
         return '';
240 240
     }
241 241
 
Please login to merge, or discard this patch.
Dolibarr/Code/Api/Api/Setup.php 1 patch
Indentation   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         return $list;
725 725
     }
726 726
 
727
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
727
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
728 728
     /**
729 729
      * Clean sensible object datas
730 730
      *
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
      */
734 734
     protected function _cleanObjectDatas($object)
735 735
     {
736
-		// phpcs:enable
736
+        // phpcs:enable
737 737
         $object = parent::_cleanObjectDatas($object);
738 738
 
739 739
         unset($object->error);
@@ -1401,7 +1401,6 @@  discard block
 block discarded – undo
1401 1401
     }
1402 1402
 
1403 1403
     /**
1404
-
1405 1404
      * Update Extrafield object
1406 1405
      *
1407 1406
      * @param   string  $attrname       extrafield attrname
Please login to merge, or discard this patch.
public/htdocs/accountancy/journal/bankjournal.php 1 patch
Indentation   +1093 added lines, -1093 removed lines patch added patch discarded remove patch
@@ -369,235 +369,235 @@  discard block
 block discarded – undo
369 369
                     // We save tabtype for a future use, to remember what kind of payment it is
370 370
                     $tabpay[$obj->rowid]['type'] = $links[$key]['type'];
371 371
                     $tabtype[$obj->rowid] = $links[$key]['type'];
372
-					/* phpcs:disable -- Code does nothing at this moment -> commented
372
+                    /* phpcs:disable -- Code does nothing at this moment -> commented
373 373
 					} elseif (in_array($links[$key]['type'], array('company', 'user'))) {
374 374
 						if ($tabpay[$obj->rowid]['type'] == 'unknown') {
375 375
 							// We can guess here it is a bank record for a thirdparty company or a user.
376 376
 							// But we won't be able to record somewhere else than into a waiting account, because there is no other journal to record the contreparty.
377 377
 						}
378 378
 					*/ // phpcs::enable
379
-				}
380
-
381
-				// Special case to ask later to add more request to get information for old links without company link.
382
-				if ($links[$key]['type'] == 'withdraw') {
383
-					$tabmoreinfo[$obj->rowid]['withdraw'] = 1;
384
-				}
379
+                }
385 380
 
386
-				if ($links[$key]['type'] == 'payment') {
387
-					$paymentstatic->id = $links[$key]['url_id'];
388
-					$paymentstatic->ref = $links[$key]['url_id'];
389
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentstatic->getNomUrl(2, '', ''); // TODO Do not include list of invoice in tooltip, the dol_string_nohtmltag is ko with this
390
-					$tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
391
-				} elseif ($links[$key]['type'] == 'payment_supplier') {
392
-					$paymentsupplierstatic->id = $links[$key]['url_id'];
393
-					$paymentsupplierstatic->ref = $links[$key]['url_id'];
394
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentsupplierstatic->getNomUrl(2);
395
-					$tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
396
-				} elseif ($links[$key]['type'] == 'company') {
397
-					$societestatic->id = $links[$key]['url_id'];
398
-					$societestatic->name = $links[$key]['label'];
399
-					$societestatic->email = $tabcompany[$obj->rowid]['email'];
400
-					$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
401
-					if ($compta_soc) {
402
-						if (empty($tabtp[$obj->rowid][$compta_soc])) {
403
-							$tabtp[$obj->rowid][$compta_soc] = $amounttouse;
404
-						} else {
405
-							$tabtp[$obj->rowid][$compta_soc] += $amounttouse;
406
-						}
407
-					}
408
-				} elseif ($links[$key]['type'] == 'user') {
409
-					$userstatic->id = $links[$key]['url_id'];
410
-					$userstatic->name = $links[$key]['label'];
411
-					$userstatic->email = $tabuser[$obj->rowid]['email'];
412
-					$userstatic->firstname = $tabuser[$obj->rowid]['firstname'];
413
-					$userstatic->lastname = $tabuser[$obj->rowid]['lastname'];
414
-					$userstatic->status = $tabuser[$obj->rowid]['status'];
415
-					$userstatic->accountancy_code = $tabuser[$obj->rowid]['accountancy_code'];
416
-					if ($userstatic->id > 0) {
417
-						$tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0);
418
-					} else {
419
-						$tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment.
420
-					}
421
-					if ($compta_user) {
422
-						$tabtp[$obj->rowid][$compta_user] += $amounttouse;
423
-					}
424
-				} elseif ($links[$key]['type'] == 'sc') {
425
-					$chargestatic->id = $links[$key]['url_id'];
426
-					$chargestatic->ref = $links[$key]['url_id'];
427
-
428
-					$tabpay[$obj->rowid]["lib"] .= ' '.$chargestatic->getNomUrl(2);
429
-					$reg = array();
430
-					if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
431
-						if ($reg[1] == 'socialcontribution') {
432
-							$reg[1] = 'SocialContribution';
433
-						}
434
-						$chargestatic->label = $langs->trans($reg[1]);
435
-					} else {
436
-						$chargestatic->label = $links[$key]['label'];
437
-					}
438
-					$chargestatic->ref = $chargestatic->label;
439
-					$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
440
-					$tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id;
441
-
442
-					// Retrieve the accounting code of the social contribution of the payment from link of payment.
443
-					// Note: We have the social contribution id, it can be faster to get accounting code from social contribution id.
444
-					$sqlmid = "SELECT cchgsoc.accountancy_code";
445
-					$sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc";
446
-					$sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
447
-					$sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
448
-					$sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
449
-					$sqlmid .= " WHERE bkurl.fk_bank = ".((int) $obj->rowid);
450
-
451
-					dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
452
-					$resultmid = $db->query($sqlmid);
453
-					if ($resultmid) {
454
-						$objmid = $db->fetch_object($resultmid);
455
-						$tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
456
-					}
457
-				} elseif ($links[$key]['type'] == 'payment_donation') {
458
-					$paymentdonstatic->id = $links[$key]['url_id'];
459
-					$paymentdonstatic->ref = $links[$key]['url_id'];
460
-					$paymentdonstatic->fk_donation = $links[$key]['url_id'];
461
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentdonstatic->getNomUrl(2);
462
-					$tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id;
463
-					$tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
464
-				} elseif ($links[$key]['type'] == 'member') {
465
-					$paymentsubscriptionstatic->id = $links[$key]['url_id'];
466
-					$paymentsubscriptionstatic->ref = $links[$key]['url_id'];
467
-					$paymentsubscriptionstatic->label = $links[$key]['label'];
468
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentsubscriptionstatic->getNomUrl(2);
469
-					$tabpay[$obj->rowid]["paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
470
-					$paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
471
-					$tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
472
-				} elseif ($links[$key]['type'] == 'payment_vat') {				// Payment VAT
473
-					$paymentvatstatic->id = $links[$key]['url_id'];
474
-					$paymentvatstatic->ref = $links[$key]['url_id'];
475
-					$paymentvatstatic->label = $links[$key]['label'];
476
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentvatstatic->getNomUrl(2);
477
-					$tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id;
478
-					$tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
479
-				} elseif ($links[$key]['type'] == 'payment_salary') {
480
-					$paymentsalstatic->id = $links[$key]['url_id'];
481
-					$paymentsalstatic->ref = $links[$key]['url_id'];
482
-					$paymentsalstatic->label = $links[$key]['label'];
483
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentsalstatic->getNomUrl(2);
484
-					$tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id;
485
-
486
-					// This part of code is no more required. it is here to solve case where a link were missing (with v14.0.0) and keep writing in accountancy complete.
487
-					// Note: A better way to fix this is to delete payment of salary and recreate it, or to fix the bookkeeping table manually after.
488
-					if (getDolGlobalString('ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
489
-						$tmpsalary = new Salary($db);
490
-						$tmpsalary->fetch($paymentsalstatic->id);
491
-						$tmpsalary->fetch_user($tmpsalary->fk_user);
492
-
493
-						$userstatic->id = $tmpsalary->user->id;
494
-						$userstatic->name = $tmpsalary->user->name;
495
-						$userstatic->email = $tmpsalary->user->email;
496
-						$userstatic->firstname = $tmpsalary->user->firstname;
497
-						$userstatic->lastname = $tmpsalary->user->lastname;
498
-						$userstatic->status = $tmpsalary->user->status;
499
-						$userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
500
-
501
-						if ($userstatic->id > 0) {
502
-							$tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0);
503
-						} else {
504
-							$tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen
505
-						}
381
+                // Special case to ask later to add more request to get information for old links without company link.
382
+                if ($links[$key]['type'] == 'withdraw') {
383
+                    $tabmoreinfo[$obj->rowid]['withdraw'] = 1;
384
+                }
506 385
 
507
-						if (empty($obj->typeop_user)) {	// Add test to avoid to add amount twice if a link already exists also on user.
508
-							$compta_user = $userstatic->accountancy_code;
509
-							if ($compta_user) {
510
-								$tabtp[$obj->rowid][$compta_user] += $amounttouse;
511
-								$tabuser[$obj->rowid] = array(
512
-								'id' => $userstatic->id,
513
-								'name' => dolGetFirstLastname($userstatic->firstname, $userstatic->lastname),
514
-								'lastname' => $userstatic->lastname,
515
-								'firstname' => $userstatic->firstname,
516
-								'email' => $userstatic->email,
517
-								'accountancy_code' => $compta_user,
518
-								'status' => $userstatic->status
519
-								);
520
-							}
521
-						}
522
-					}
523
-				} elseif ($links[$key]['type'] == 'payment_expensereport') {
524
-					$paymentexpensereportstatic->id = $links[$key]['url_id'];
525
-					$tabpay[$obj->rowid]["lib"] .= $paymentexpensereportstatic->getNomUrl(2);
526
-					$tabpay[$obj->rowid]["paymentexpensereport"] = $paymentexpensereportstatic->id;
527
-				} elseif ($links[$key]['type'] == 'payment_various') {
528
-					$paymentvariousstatic->id = $links[$key]['url_id'];
529
-					$paymentvariousstatic->ref = $links[$key]['url_id'];
530
-					$paymentvariousstatic->label = $links[$key]['label'];
531
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentvariousstatic->getNomUrl(2);
532
-					$tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id;
533
-					$paymentvariousstatic->fetch($paymentvariousstatic->id);
534
-					$account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 'NotDefined'); // NotDefined is a reserved word
535
-					$account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word
536
-					$tabpay[$obj->rowid]["account_various"] = $account_various;
537
-					$tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
538
-				} elseif ($links[$key]['type'] == 'payment_loan') {
539
-					$paymentloanstatic->id = $links[$key]['url_id'];
540
-					$paymentloanstatic->ref = $links[$key]['url_id'];
541
-					$paymentloanstatic->fk_loan = $links[$key]['url_id'];
542
-					$tabpay[$obj->rowid]["lib"] .= ' '.$paymentloanstatic->getNomUrl(2);
543
-					$tabpay[$obj->rowid]["paymentloanid"] = $paymentloanstatic->id;
544
-					//$tabtp[$obj->rowid][$account_pay_loan] += $amounttouse;
545
-					$sqlmid = 'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
546
-					$sqlmid .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl, '.MAIN_DB_PREFIX.'loan as l';
547
-					$sqlmid .= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
548
-
549
-					dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
550
-					$resultmid = $db->query($sqlmid);
551
-					if ($resultmid) {
552
-						$objmid = $db->fetch_object($resultmid);
553
-						$tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_capital]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : $amounttouse;
554
-						$tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_insurance]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : $amounttouse;
555
-						$tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_interest]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interes : $amounttouse;
556
-					}
557
-				} elseif ($links[$key]['type'] == 'banktransfert') {
558
-					$accountLinestatic->fetch($links[$key]['url_id']);
559
-					$tabpay[$obj->rowid]["lib"] .= ' '.$langs->trans("BankTransfer").'- '.$accountLinestatic ->getNomUrl(1);
560
-					$tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
561
-					$bankaccountstatic->fetch($tabpay[$obj->rowid]['fk_bank_account']);
562
-					$tabpay[$obj->rowid]["soclib"] = $bankaccountstatic->getNomUrl(2);
563
-				}
564
-			}
565
-		}
386
+                if ($links[$key]['type'] == 'payment') {
387
+                    $paymentstatic->id = $links[$key]['url_id'];
388
+                    $paymentstatic->ref = $links[$key]['url_id'];
389
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentstatic->getNomUrl(2, '', ''); // TODO Do not include list of invoice in tooltip, the dol_string_nohtmltag is ko with this
390
+                    $tabpay[$obj->rowid]["paymentid"] = $paymentstatic->id;
391
+                } elseif ($links[$key]['type'] == 'payment_supplier') {
392
+                    $paymentsupplierstatic->id = $links[$key]['url_id'];
393
+                    $paymentsupplierstatic->ref = $links[$key]['url_id'];
394
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsupplierstatic->getNomUrl(2);
395
+                    $tabpay[$obj->rowid]["paymentsupplierid"] = $paymentsupplierstatic->id;
396
+                } elseif ($links[$key]['type'] == 'company') {
397
+                    $societestatic->id = $links[$key]['url_id'];
398
+                    $societestatic->name = $links[$key]['label'];
399
+                    $societestatic->email = $tabcompany[$obj->rowid]['email'];
400
+                    $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
401
+                    if ($compta_soc) {
402
+                        if (empty($tabtp[$obj->rowid][$compta_soc])) {
403
+                            $tabtp[$obj->rowid][$compta_soc] = $amounttouse;
404
+                        } else {
405
+                            $tabtp[$obj->rowid][$compta_soc] += $amounttouse;
406
+                        }
407
+                    }
408
+                } elseif ($links[$key]['type'] == 'user') {
409
+                    $userstatic->id = $links[$key]['url_id'];
410
+                    $userstatic->name = $links[$key]['label'];
411
+                    $userstatic->email = $tabuser[$obj->rowid]['email'];
412
+                    $userstatic->firstname = $tabuser[$obj->rowid]['firstname'];
413
+                    $userstatic->lastname = $tabuser[$obj->rowid]['lastname'];
414
+                    $userstatic->status = $tabuser[$obj->rowid]['status'];
415
+                    $userstatic->accountancy_code = $tabuser[$obj->rowid]['accountancy_code'];
416
+                    if ($userstatic->id > 0) {
417
+                        $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0);
418
+                    } else {
419
+                        $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment.
420
+                    }
421
+                    if ($compta_user) {
422
+                        $tabtp[$obj->rowid][$compta_user] += $amounttouse;
423
+                    }
424
+                } elseif ($links[$key]['type'] == 'sc') {
425
+                    $chargestatic->id = $links[$key]['url_id'];
426
+                    $chargestatic->ref = $links[$key]['url_id'];
427
+
428
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$chargestatic->getNomUrl(2);
429
+                    $reg = array();
430
+                    if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
431
+                        if ($reg[1] == 'socialcontribution') {
432
+                            $reg[1] = 'SocialContribution';
433
+                        }
434
+                        $chargestatic->label = $langs->trans($reg[1]);
435
+                    } else {
436
+                        $chargestatic->label = $links[$key]['label'];
437
+                    }
438
+                    $chargestatic->ref = $chargestatic->label;
439
+                    $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
440
+                    $tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id;
441
+
442
+                    // Retrieve the accounting code of the social contribution of the payment from link of payment.
443
+                    // Note: We have the social contribution id, it can be faster to get accounting code from social contribution id.
444
+                    $sqlmid = "SELECT cchgsoc.accountancy_code";
445
+                    $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc";
446
+                    $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id";
447
+                    $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid";
448
+                    $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'";
449
+                    $sqlmid .= " WHERE bkurl.fk_bank = ".((int) $obj->rowid);
450
+
451
+                    dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
452
+                    $resultmid = $db->query($sqlmid);
453
+                    if ($resultmid) {
454
+                        $objmid = $db->fetch_object($resultmid);
455
+                        $tabtp[$obj->rowid][$objmid->accountancy_code] = isset($tabtp[$obj->rowid][$objmid->accountancy_code]) ? $tabtp[$obj->rowid][$objmid->accountancy_code] + $amounttouse : $amounttouse;
456
+                    }
457
+                } elseif ($links[$key]['type'] == 'payment_donation') {
458
+                    $paymentdonstatic->id = $links[$key]['url_id'];
459
+                    $paymentdonstatic->ref = $links[$key]['url_id'];
460
+                    $paymentdonstatic->fk_donation = $links[$key]['url_id'];
461
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentdonstatic->getNomUrl(2);
462
+                    $tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id;
463
+                    $tabtp[$obj->rowid][$account_pay_donation] = isset($tabtp[$obj->rowid][$account_pay_donation]) ? $tabtp[$obj->rowid][$account_pay_donation] + $amounttouse : $amounttouse;
464
+                } elseif ($links[$key]['type'] == 'member') {
465
+                    $paymentsubscriptionstatic->id = $links[$key]['url_id'];
466
+                    $paymentsubscriptionstatic->ref = $links[$key]['url_id'];
467
+                    $paymentsubscriptionstatic->label = $links[$key]['label'];
468
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsubscriptionstatic->getNomUrl(2);
469
+                    $tabpay[$obj->rowid]["paymentsubscriptionid"] = $paymentsubscriptionstatic->id;
470
+                    $paymentsubscriptionstatic->fetch($paymentsubscriptionstatic->id);
471
+                    $tabtp[$obj->rowid][$account_pay_subscription] = isset($tabtp[$obj->rowid][$account_pay_subscription]) ? $tabtp[$obj->rowid][$account_pay_subscription] + $amounttouse : $amounttouse;
472
+                } elseif ($links[$key]['type'] == 'payment_vat') {				// Payment VAT
473
+                    $paymentvatstatic->id = $links[$key]['url_id'];
474
+                    $paymentvatstatic->ref = $links[$key]['url_id'];
475
+                    $paymentvatstatic->label = $links[$key]['label'];
476
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentvatstatic->getNomUrl(2);
477
+                    $tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id;
478
+                    $tabtp[$obj->rowid][$account_pay_vat] = isset($tabtp[$obj->rowid][$account_pay_vat]) ? $tabtp[$obj->rowid][$account_pay_vat] + $amounttouse : $amounttouse;
479
+                } elseif ($links[$key]['type'] == 'payment_salary') {
480
+                    $paymentsalstatic->id = $links[$key]['url_id'];
481
+                    $paymentsalstatic->ref = $links[$key]['url_id'];
482
+                    $paymentsalstatic->label = $links[$key]['label'];
483
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentsalstatic->getNomUrl(2);
484
+                    $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id;
485
+
486
+                    // This part of code is no more required. it is here to solve case where a link were missing (with v14.0.0) and keep writing in accountancy complete.
487
+                    // Note: A better way to fix this is to delete payment of salary and recreate it, or to fix the bookkeeping table manually after.
488
+                    if (getDolGlobalString('ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) {
489
+                        $tmpsalary = new Salary($db);
490
+                        $tmpsalary->fetch($paymentsalstatic->id);
491
+                        $tmpsalary->fetch_user($tmpsalary->fk_user);
492
+
493
+                        $userstatic->id = $tmpsalary->user->id;
494
+                        $userstatic->name = $tmpsalary->user->name;
495
+                        $userstatic->email = $tmpsalary->user->email;
496
+                        $userstatic->firstname = $tmpsalary->user->firstname;
497
+                        $userstatic->lastname = $tmpsalary->user->lastname;
498
+                        $userstatic->status = $tmpsalary->user->status;
499
+                        $userstatic->accountancy_code = $tmpsalary->user->accountancy_code;
500
+
501
+                        if ($userstatic->id > 0) {
502
+                            $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0);
503
+                        } else {
504
+                            $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen
505
+                        }
506
+
507
+                        if (empty($obj->typeop_user)) {	// Add test to avoid to add amount twice if a link already exists also on user.
508
+                            $compta_user = $userstatic->accountancy_code;
509
+                            if ($compta_user) {
510
+                                $tabtp[$obj->rowid][$compta_user] += $amounttouse;
511
+                                $tabuser[$obj->rowid] = array(
512
+                                'id' => $userstatic->id,
513
+                                'name' => dolGetFirstLastname($userstatic->firstname, $userstatic->lastname),
514
+                                'lastname' => $userstatic->lastname,
515
+                                'firstname' => $userstatic->firstname,
516
+                                'email' => $userstatic->email,
517
+                                'accountancy_code' => $compta_user,
518
+                                'status' => $userstatic->status
519
+                                );
520
+                            }
521
+                        }
522
+                    }
523
+                } elseif ($links[$key]['type'] == 'payment_expensereport') {
524
+                    $paymentexpensereportstatic->id = $links[$key]['url_id'];
525
+                    $tabpay[$obj->rowid]["lib"] .= $paymentexpensereportstatic->getNomUrl(2);
526
+                    $tabpay[$obj->rowid]["paymentexpensereport"] = $paymentexpensereportstatic->id;
527
+                } elseif ($links[$key]['type'] == 'payment_various') {
528
+                    $paymentvariousstatic->id = $links[$key]['url_id'];
529
+                    $paymentvariousstatic->ref = $links[$key]['url_id'];
530
+                    $paymentvariousstatic->label = $links[$key]['label'];
531
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentvariousstatic->getNomUrl(2);
532
+                    $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id;
533
+                    $paymentvariousstatic->fetch($paymentvariousstatic->id);
534
+                    $account_various = (!empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : 'NotDefined'); // NotDefined is a reserved word
535
+                    $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word
536
+                    $tabpay[$obj->rowid]["account_various"] = $account_various;
537
+                    $tabtp[$obj->rowid][$account_subledger] = isset($tabtp[$obj->rowid][$account_subledger]) ? $tabtp[$obj->rowid][$account_subledger] + $amounttouse : $amounttouse;
538
+                } elseif ($links[$key]['type'] == 'payment_loan') {
539
+                    $paymentloanstatic->id = $links[$key]['url_id'];
540
+                    $paymentloanstatic->ref = $links[$key]['url_id'];
541
+                    $paymentloanstatic->fk_loan = $links[$key]['url_id'];
542
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$paymentloanstatic->getNomUrl(2);
543
+                    $tabpay[$obj->rowid]["paymentloanid"] = $paymentloanstatic->id;
544
+                    //$tabtp[$obj->rowid][$account_pay_loan] += $amounttouse;
545
+                    $sqlmid = 'SELECT pl.amount_capital, pl.amount_insurance, pl.amount_interest, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest';
546
+                    $sqlmid .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl, '.MAIN_DB_PREFIX.'loan as l';
547
+                    $sqlmid .= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid);
548
+
549
+                    dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);
550
+                    $resultmid = $db->query($sqlmid);
551
+                    if ($resultmid) {
552
+                        $objmid = $db->fetch_object($resultmid);
553
+                        $tabtp[$obj->rowid][$objmid->accountancy_account_capital] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_capital]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_capital] - $objmid->amount_capital : $amounttouse;
554
+                        $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_insurance]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_insurance] - $objmid->amount_insurance : $amounttouse;
555
+                        $tabtp[$obj->rowid][$objmid->accountancy_account_interest] = isset($tabtp[$obj->rowid][$objmid->accountancy_account_interest]) ? $tabtp[$obj->rowid][$objmid->accountancy_account_interest] - $objmid->amount_interes : $amounttouse;
556
+                    }
557
+                } elseif ($links[$key]['type'] == 'banktransfert') {
558
+                    $accountLinestatic->fetch($links[$key]['url_id']);
559
+                    $tabpay[$obj->rowid]["lib"] .= ' '.$langs->trans("BankTransfer").'- '.$accountLinestatic ->getNomUrl(1);
560
+                    $tabtp[$obj->rowid][$account_transfer] = isset($tabtp[$obj->rowid][$account_transfer]) ? $tabtp[$obj->rowid][$account_transfer] + $amounttouse : $amounttouse;
561
+                    $bankaccountstatic->fetch($tabpay[$obj->rowid]['fk_bank_account']);
562
+                    $tabpay[$obj->rowid]["soclib"] = $bankaccountstatic->getNomUrl(2);
563
+                }
564
+            }
565
+        }
566 566
 
567
-		if (empty($tabbq[$obj->rowid][$compta_bank])) {
568
-			$tabbq[$obj->rowid][$compta_bank] = $amounttouse;
569
-		} else {
570
-			$tabbq[$obj->rowid][$compta_bank] += $amounttouse;
571
-		}
567
+        if (empty($tabbq[$obj->rowid][$compta_bank])) {
568
+            $tabbq[$obj->rowid][$compta_bank] = $amounttouse;
569
+        } else {
570
+            $tabbq[$obj->rowid][$compta_bank] += $amounttouse;
571
+        }
572 572
 
573
-		// If no links were found to know the amount on thirdparty, we try to guess it.
574
-		// This may happens on bank entries without the links lines to 'company'.
575
-		if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) {	// If we don't find 'company' link because it is an old 'withdraw' record
576
-			foreach ($links as $key => $val) {
577
-				if ($links[$key]['type'] == 'payment') {
578
-					// Get thirdparty
579
-					$tmppayment->fetch($links[$key]['url_id']);
580
-					$arrayofamounts = $tmppayment->getAmountsArray();
581
-					if (is_array($arrayofamounts)) {
582
-						foreach ($arrayofamounts as $invoiceid => $amount) {
583
-							$tmpinvoice->fetch($invoiceid);
584
-							$tmpinvoice->fetch_thirdparty();
585
-							if ($tmpinvoice->thirdparty->code_compta_client) {
586
-								$tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
587
-							}
588
-						}
589
-					}
590
-				}
591
-			}
592
-		}
573
+        // If no links were found to know the amount on thirdparty, we try to guess it.
574
+        // This may happens on bank entries without the links lines to 'company'.
575
+        if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) {	// If we don't find 'company' link because it is an old 'withdraw' record
576
+            foreach ($links as $key => $val) {
577
+                if ($links[$key]['type'] == 'payment') {
578
+                    // Get thirdparty
579
+                    $tmppayment->fetch($links[$key]['url_id']);
580
+                    $arrayofamounts = $tmppayment->getAmountsArray();
581
+                    if (is_array($arrayofamounts)) {
582
+                        foreach ($arrayofamounts as $invoiceid => $amount) {
583
+                            $tmpinvoice->fetch($invoiceid);
584
+                            $tmpinvoice->fetch_thirdparty();
585
+                            if ($tmpinvoice->thirdparty->code_compta_client) {
586
+                                $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta_client] += $amount;
587
+                            }
588
+                        }
589
+                    }
590
+                }
591
+            }
592
+        }
593 593
 
594
-		// If no links were found to know the amount on thirdparty/user, we init it to account 'NotDefined'.
595
-		if (empty($tabtp[$obj->rowid])) {
596
-			$tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
597
-		}
594
+        // If no links were found to know the amount on thirdparty/user, we init it to account 'NotDefined'.
595
+        if (empty($tabtp[$obj->rowid])) {
596
+            $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank];
597
+        }
598 598
 
599
-		// Check account number is ok
600
-		/*if ($action == 'writebookkeeping')		// Make test now in such a case
599
+        // Check account number is ok
600
+        /*if ($action == 'writebookkeeping')		// Make test now in such a case
601 601
 		{
602 602
 			reset($tabbq[$obj->rowid]);
603 603
 			$first_key_tabbq = key($tabbq[$obj->rowid]);
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
 			}
616 616
 		}*/
617 617
 
618
-		// if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $amounttouse;
618
+        // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $amounttouse;
619 619
 
620
-		$i++;
621
-	}
620
+        $i++;
621
+    }
622 622
 } else {
623
-	dol_print_error($db);
623
+    dol_print_error($db);
624 624
 }
625 625
 
626 626
 
@@ -632,454 +632,454 @@  discard block
 block discarded – undo
632 632
 
633 633
 // Write bookkeeping
634 634
 if (!$error && $action == 'writebookkeeping') {
635
-	$now = dol_now();
636
-
637
-	$accountingaccountcustomer = new AccountingAccount($db);
638
-	$accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
639
-
640
-	$accountingaccountsupplier = new AccountingAccount($db);
641
-	$accountingaccountsupplier->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
642
-
643
-	$accountingaccountpayment = new AccountingAccount($db);
644
-	$accountingaccountpayment->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true);
645
-
646
-	$accountingaccountexpensereport = new AccountingAccount($db);
647
-	$accountingaccountexpensereport->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT, true);
648
-
649
-	$accountingaccountsuspense = new AccountingAccount($db);
650
-	$accountingaccountsuspense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true);
651
-
652
-	$error = 0;
653
-	foreach ($tabpay as $key => $val) {		// $key is rowid into llx_bank
654
-		$date = dol_print_date($val["date"], 'day');
655
-
656
-		$ref = getSourceDocRef($val, $tabtype[$key]);
657
-
658
-		$errorforline = 0;
659
-
660
-		$totalcredit = 0;
661
-		$totaldebit = 0;
662
-
663
-		$db->begin();
664
-
665
-		// Introduce a protection. Total of tabtp must be total of tabbq
666
-		//var_dump($tabpay);
667
-		//var_dump($tabtp);
668
-		//var_dump($tabbq);exit;
669
-
670
-		// Bank
671
-		if (!$errorforline && is_array($tabbq[$key])) {
672
-			// Line into bank account
673
-			foreach ($tabbq[$key] as $k => $mt) {
674
-				if ($mt) {
675
-					if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
676
-						$accountingaccount = new AccountingAccount($db);
677
-						$accountingaccount->fetch(0, $k, true);	// $k is accounting account of the bank.
678
-						$conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
679
-					} else {
680
-						$accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
681
-					}
682
-
683
-					$account_label = $accountingaccount->label;
684
-
685
-					$reflabel = '';
686
-					if (!empty($val['lib'])) {
687
-						$reflabel .= dol_string_nohtmltag($val['lib'])." - ";
688
-					}
689
-					$reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
690
-					if (!empty($val['soclib'])) {
691
-						$reflabel .= " - ".dol_string_nohtmltag($val['soclib']);
692
-					}
693
-
694
-					$bookkeeping = new BookKeeping($db);
695
-					$bookkeeping->doc_date = $val["date"];
696
-					$bookkeeping->doc_ref = $ref;
697
-					$bookkeeping->doc_type = 'bank';
698
-					$bookkeeping->fk_doc = $key;
699
-					$bookkeeping->fk_docdet = $val["fk_bank"];
700
-
701
-					$bookkeeping->numero_compte = $k;
702
-					$bookkeeping->label_compte = $account_label;
703
-
704
-					$bookkeeping->label_operation = $reflabel;
705
-					$bookkeeping->montant = $mt;
706
-					$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
707
-					$bookkeeping->debit = ($mt >= 0 ? $mt : 0);
708
-					$bookkeeping->credit = ($mt < 0 ? -$mt : 0);
709
-					$bookkeeping->code_journal = $journal;
710
-					$bookkeeping->journal_label = $langs->transnoentities($journal_label);
711
-					$bookkeeping->fk_user_author = $user->id;
712
-					$bookkeeping->date_creation = $now;
713
-
714
-					// No subledger_account value for the bank line but add a specific label_operation
715
-					$bookkeeping->subledger_account = '';
716
-					$bookkeeping->label_operation = $reflabel;
717
-					$bookkeeping->entity = $conf->entity;
718
-
719
-					$totaldebit += $bookkeeping->debit;
720
-					$totalcredit += $bookkeeping->credit;
721
-
722
-					$result = $bookkeeping->create($user);
723
-					if ($result < 0) {
724
-						if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
725
-							$error++;
726
-							$errorforline++;
727
-							setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
728
-						} else {
729
-							$error++;
730
-							$errorforline++;
731
-							setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
732
-						}
733
-					}
734
-				}
735
-			}
736
-		}
737
-
738
-		// Third party
739
-		if (!$errorforline) {
740
-			if (is_array($tabtp[$key])) {
741
-				// Line into thirdparty account
742
-				foreach ($tabtp[$key] as $k => $mt) {
743
-					if ($mt) {
744
-						$lettering = false;
745
-
746
-						$reflabel = '';
747
-						if (!empty($val['lib'])) {
748
-							$reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : "");
749
-						}
750
-						if ($tabtype[$key] == 'banktransfert') {
751
-							$reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
752
-						} else {
753
-							$reflabel .= dol_string_nohtmltag($val['soclib']);
754
-						}
635
+    $now = dol_now();
636
+
637
+    $accountingaccountcustomer = new AccountingAccount($db);
638
+    $accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
639
+
640
+    $accountingaccountsupplier = new AccountingAccount($db);
641
+    $accountingaccountsupplier->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true);
642
+
643
+    $accountingaccountpayment = new AccountingAccount($db);
644
+    $accountingaccountpayment->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true);
645
+
646
+    $accountingaccountexpensereport = new AccountingAccount($db);
647
+    $accountingaccountexpensereport->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_EXPENSEREPORT, true);
648
+
649
+    $accountingaccountsuspense = new AccountingAccount($db);
650
+    $accountingaccountsuspense->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'), true);
651
+
652
+    $error = 0;
653
+    foreach ($tabpay as $key => $val) {		// $key is rowid into llx_bank
654
+        $date = dol_print_date($val["date"], 'day');
655
+
656
+        $ref = getSourceDocRef($val, $tabtype[$key]);
657
+
658
+        $errorforline = 0;
659
+
660
+        $totalcredit = 0;
661
+        $totaldebit = 0;
662
+
663
+        $db->begin();
664
+
665
+        // Introduce a protection. Total of tabtp must be total of tabbq
666
+        //var_dump($tabpay);
667
+        //var_dump($tabtp);
668
+        //var_dump($tabbq);exit;
669
+
670
+        // Bank
671
+        if (!$errorforline && is_array($tabbq[$key])) {
672
+            // Line into bank account
673
+            foreach ($tabbq[$key] as $k => $mt) {
674
+                if ($mt) {
675
+                    if (empty($conf->cache['accountingaccountincurrententity'][$k])) {
676
+                        $accountingaccount = new AccountingAccount($db);
677
+                        $accountingaccount->fetch(0, $k, true);	// $k is accounting account of the bank.
678
+                        $conf->cache['accountingaccountincurrententity'][$k] = $accountingaccount;
679
+                    } else {
680
+                        $accountingaccount = $conf->cache['accountingaccountincurrententity'][$k];
681
+                    }
682
+
683
+                    $account_label = $accountingaccount->label;
684
+
685
+                    $reflabel = '';
686
+                    if (!empty($val['lib'])) {
687
+                        $reflabel .= dol_string_nohtmltag($val['lib'])." - ";
688
+                    }
689
+                    $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
690
+                    if (!empty($val['soclib'])) {
691
+                        $reflabel .= " - ".dol_string_nohtmltag($val['soclib']);
692
+                    }
693
+
694
+                    $bookkeeping = new BookKeeping($db);
695
+                    $bookkeeping->doc_date = $val["date"];
696
+                    $bookkeeping->doc_ref = $ref;
697
+                    $bookkeeping->doc_type = 'bank';
698
+                    $bookkeeping->fk_doc = $key;
699
+                    $bookkeeping->fk_docdet = $val["fk_bank"];
700
+
701
+                    $bookkeeping->numero_compte = $k;
702
+                    $bookkeeping->label_compte = $account_label;
703
+
704
+                    $bookkeeping->label_operation = $reflabel;
705
+                    $bookkeeping->montant = $mt;
706
+                    $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
707
+                    $bookkeeping->debit = ($mt >= 0 ? $mt : 0);
708
+                    $bookkeeping->credit = ($mt < 0 ? -$mt : 0);
709
+                    $bookkeeping->code_journal = $journal;
710
+                    $bookkeeping->journal_label = $langs->transnoentities($journal_label);
711
+                    $bookkeeping->fk_user_author = $user->id;
712
+                    $bookkeeping->date_creation = $now;
713
+
714
+                    // No subledger_account value for the bank line but add a specific label_operation
715
+                    $bookkeeping->subledger_account = '';
716
+                    $bookkeeping->label_operation = $reflabel;
717
+                    $bookkeeping->entity = $conf->entity;
718
+
719
+                    $totaldebit += $bookkeeping->debit;
720
+                    $totalcredit += $bookkeeping->credit;
721
+
722
+                    $result = $bookkeeping->create($user);
723
+                    if ($result < 0) {
724
+                        if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
725
+                            $error++;
726
+                            $errorforline++;
727
+                            setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
728
+                        } else {
729
+                            $error++;
730
+                            $errorforline++;
731
+                            setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
732
+                        }
733
+                    }
734
+                }
735
+            }
736
+        }
755 737
 
756
-						$bookkeeping = new BookKeeping($db);
757
-						$bookkeeping->doc_date = $val["date"];
758
-						$bookkeeping->doc_ref = $ref;
759
-						$bookkeeping->doc_type = 'bank';
760
-						$bookkeeping->fk_doc = $key;
761
-						$bookkeeping->fk_docdet = $val["fk_bank"];
762
-
763
-						$bookkeeping->label_operation = $reflabel;
764
-						$bookkeeping->montant = $mt;
765
-						$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
766
-						$bookkeeping->debit = ($mt < 0 ? -$mt : 0);
767
-						$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
768
-						$bookkeeping->code_journal = $journal;
769
-						$bookkeeping->journal_label = $langs->transnoentities($journal_label);
770
-						$bookkeeping->fk_user_author = $user->id;
771
-						$bookkeeping->date_creation = $now;
772
-
773
-						if ($tabtype[$key] == 'payment') {	// If payment is payment of customer invoice, we get ref of invoice
774
-							$lettering = true;
775
-							$bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
776
-							$bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
777
-							$bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER');
778
-							$bookkeeping->label_compte = $accountingaccountcustomer->label;
779
-						} elseif ($tabtype[$key] == 'payment_supplier') {	// If payment is payment of supplier invoice, we get ref of invoice
780
-							$lettering = true;
781
-							$bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
782
-							$bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
783
-							$bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER');
784
-							$bookkeeping->label_compte = $accountingaccountsupplier->label;
785
-						} elseif ($tabtype[$key] == 'payment_expensereport') {
786
-							$bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
787
-							$bookkeeping->subledger_label = $tabuser[$key]['name'];
788
-							$bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
789
-							$bookkeeping->label_compte = $accountingaccountexpensereport->label;
790
-						} elseif ($tabtype[$key] == 'payment_salary') {
791
-							$bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
792
-							$bookkeeping->subledger_label = $tabuser[$key]['name'];
793
-							$bookkeeping->numero_compte = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
794
-							$bookkeeping->label_compte = $accountingaccountpayment->label;
795
-						} elseif (in_array($tabtype[$key], array('sc', 'payment_sc'))) {   // If payment is payment of social contribution
796
-							$bookkeeping->subledger_account = '';
797
-							$bookkeeping->subledger_label = '';
798
-							$accountingaccount->fetch(null, $k, true);	// TODO Use a cache
799
-							$bookkeeping->numero_compte = $k;
800
-							$bookkeeping->label_compte = $accountingaccount->label;
801
-						} elseif ($tabtype[$key] == 'payment_vat') {
802
-							$bookkeeping->subledger_account = '';
803
-							$bookkeeping->subledger_label = '';
804
-							$accountingaccount->fetch(null, $k, true);		// TODO Use a cache
805
-							$bookkeeping->numero_compte = $k;
806
-							$bookkeeping->label_compte = $accountingaccount->label;
807
-						} elseif ($tabtype[$key] == 'payment_donation') {
808
-							$bookkeeping->subledger_account = '';
809
-							$bookkeeping->subledger_label = '';
810
-							$accountingaccount->fetch(null, $k, true);		// TODO Use a cache
811
-							$bookkeeping->numero_compte = $k;
812
-							$bookkeeping->label_compte = $accountingaccount->label;
813
-						} elseif ($tabtype[$key] == 'member') {
814
-							$bookkeeping->subledger_account = '';
815
-							$bookkeeping->subledger_label = '';
816
-							$accountingaccount->fetch(null, $k, true);		// TODO Use a cache
817
-							$bookkeeping->numero_compte = $k;
818
-							$bookkeeping->label_compte = $accountingaccount->label;
819
-						} elseif ($tabtype[$key] == 'payment_loan') {
820
-							$bookkeeping->subledger_account = '';
821
-							$bookkeeping->subledger_label = '';
822
-							$accountingaccount->fetch(null, $k, true);		// TODO Use a cache
823
-							$bookkeeping->numero_compte = $k;
824
-							$bookkeeping->label_compte = $accountingaccount->label;
825
-						} elseif ($tabtype[$key] == 'payment_various') {
826
-							$bookkeeping->subledger_account = $k;
827
-							$bookkeeping->subledger_label = $tabcompany[$key]['name'];
828
-							$accountingaccount->fetch(null, $tabpay[$key]["account_various"], true);	// TODO Use a cache
829
-							$bookkeeping->numero_compte = $tabpay[$key]["account_various"];
830
-							$bookkeeping->label_compte = $accountingaccount->label;
831
-						} elseif ($tabtype[$key] == 'banktransfert') {
832
-							$bookkeeping->subledger_account = '';
833
-							$bookkeeping->subledger_label = '';
834
-							$accountingaccount->fetch(null, $k, true);		// TODO Use a cache
835
-							$bookkeeping->numero_compte = $k;
836
-							$bookkeeping->label_compte = $accountingaccount->label;
837
-						} else {
838
-							if ($tabtype[$key] == 'unknown') {	// Unknown transaction, we will use a waiting account for thirdparty.
839
-								// Temporary account
840
-								$bookkeeping->subledger_account = '';
841
-								$bookkeeping->subledger_label = '';
842
-								$bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE');
843
-								$bookkeeping->label_compte = $accountingaccountsuspense->label;
844
-							}
845
-						}
846
-						$bookkeeping->label_operation = $reflabel;
847
-						$bookkeeping->entity = $conf->entity;
848
-
849
-						$totaldebit += $bookkeeping->debit;
850
-						$totalcredit += $bookkeeping->credit;
851
-
852
-						$result = $bookkeeping->create($user);
853
-						if ($result < 0) {
854
-							if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
855
-								$error++;
856
-								$errorforline++;
857
-								setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
858
-							} else {
859
-								$error++;
860
-								$errorforline++;
861
-								setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
862
-							}
863
-						} else {
864
-							if ($lettering && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
865
-								$lettering_static = new Lettering($db);
866
-								$nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
867
-							}
868
-						}
869
-					}
870
-				}
871
-			} else {	// If thirdparty unknown, output the waiting account
872
-				foreach ($tabbq[$key] as $k => $mt) {
873
-					if ($mt) {
874
-						$reflabel = '';
875
-						if (!empty($val['lib'])) {
876
-							$reflabel .= dol_string_nohtmltag($val['lib'])." - ";
877
-						}
878
-						$reflabel .= dol_string_nohtmltag('WaitingAccount');
879
-
880
-						$bookkeeping = new BookKeeping($db);
881
-						$bookkeeping->doc_date = $val["date"];
882
-						$bookkeeping->doc_ref = $ref;
883
-						$bookkeeping->doc_type = 'bank';
884
-						$bookkeeping->fk_doc = $key;
885
-						$bookkeeping->fk_docdet = $val["fk_bank"];
886
-						$bookkeeping->montant = $mt;
887
-						$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
888
-						$bookkeeping->debit = ($mt < 0 ? -$mt : 0);
889
-						$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
890
-						$bookkeeping->code_journal = $journal;
891
-						$bookkeeping->journal_label = $langs->transnoentities($journal_label);
892
-						$bookkeeping->fk_user_author = $user->id;
893
-						$bookkeeping->date_creation = $now;
894
-						$bookkeeping->label_compte = '';
895
-						$bookkeeping->label_operation = $reflabel;
896
-						$bookkeeping->entity = $conf->entity;
897
-
898
-						$totaldebit += $bookkeeping->debit;
899
-						$totalcredit += $bookkeeping->credit;
900
-
901
-						$result = $bookkeeping->create($user);
902
-
903
-						if ($result < 0) {
904
-							if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
905
-								$error++;
906
-								$errorforline++;
907
-								setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
908
-							} else {
909
-								$error++;
910
-								$errorforline++;
911
-								setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
912
-							}
913
-						}
914
-					}
915
-				}
916
-			}
917
-		}
738
+        // Third party
739
+        if (!$errorforline) {
740
+            if (is_array($tabtp[$key])) {
741
+                // Line into thirdparty account
742
+                foreach ($tabtp[$key] as $k => $mt) {
743
+                    if ($mt) {
744
+                        $lettering = false;
745
+
746
+                        $reflabel = '';
747
+                        if (!empty($val['lib'])) {
748
+                            $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : "");
749
+                        }
750
+                        if ($tabtype[$key] == 'banktransfert') {
751
+                            $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
752
+                        } else {
753
+                            $reflabel .= dol_string_nohtmltag($val['soclib']);
754
+                        }
755
+
756
+                        $bookkeeping = new BookKeeping($db);
757
+                        $bookkeeping->doc_date = $val["date"];
758
+                        $bookkeeping->doc_ref = $ref;
759
+                        $bookkeeping->doc_type = 'bank';
760
+                        $bookkeeping->fk_doc = $key;
761
+                        $bookkeeping->fk_docdet = $val["fk_bank"];
762
+
763
+                        $bookkeeping->label_operation = $reflabel;
764
+                        $bookkeeping->montant = $mt;
765
+                        $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
766
+                        $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
767
+                        $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
768
+                        $bookkeeping->code_journal = $journal;
769
+                        $bookkeeping->journal_label = $langs->transnoentities($journal_label);
770
+                        $bookkeeping->fk_user_author = $user->id;
771
+                        $bookkeeping->date_creation = $now;
772
+
773
+                        if ($tabtype[$key] == 'payment') {	// If payment is payment of customer invoice, we get ref of invoice
774
+                            $lettering = true;
775
+                            $bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
776
+                            $bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
777
+                            $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER');
778
+                            $bookkeeping->label_compte = $accountingaccountcustomer->label;
779
+                        } elseif ($tabtype[$key] == 'payment_supplier') {	// If payment is payment of supplier invoice, we get ref of invoice
780
+                            $lettering = true;
781
+                            $bookkeeping->subledger_account = $k; // For payment, the subledger account is stored as $key of $tabtp
782
+                            $bookkeeping->subledger_label = $tabcompany[$key]['name']; // $tabcompany is defined only if we are sure there is 1 thirdparty for the bank transaction
783
+                            $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER');
784
+                            $bookkeeping->label_compte = $accountingaccountsupplier->label;
785
+                        } elseif ($tabtype[$key] == 'payment_expensereport') {
786
+                            $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
787
+                            $bookkeeping->subledger_label = $tabuser[$key]['name'];
788
+                            $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
789
+                            $bookkeeping->label_compte = $accountingaccountexpensereport->label;
790
+                        } elseif ($tabtype[$key] == 'payment_salary') {
791
+                            $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code'];
792
+                            $bookkeeping->subledger_label = $tabuser[$key]['name'];
793
+                            $bookkeeping->numero_compte = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
794
+                            $bookkeeping->label_compte = $accountingaccountpayment->label;
795
+                        } elseif (in_array($tabtype[$key], array('sc', 'payment_sc'))) {   // If payment is payment of social contribution
796
+                            $bookkeeping->subledger_account = '';
797
+                            $bookkeeping->subledger_label = '';
798
+                            $accountingaccount->fetch(null, $k, true);	// TODO Use a cache
799
+                            $bookkeeping->numero_compte = $k;
800
+                            $bookkeeping->label_compte = $accountingaccount->label;
801
+                        } elseif ($tabtype[$key] == 'payment_vat') {
802
+                            $bookkeeping->subledger_account = '';
803
+                            $bookkeeping->subledger_label = '';
804
+                            $accountingaccount->fetch(null, $k, true);		// TODO Use a cache
805
+                            $bookkeeping->numero_compte = $k;
806
+                            $bookkeeping->label_compte = $accountingaccount->label;
807
+                        } elseif ($tabtype[$key] == 'payment_donation') {
808
+                            $bookkeeping->subledger_account = '';
809
+                            $bookkeeping->subledger_label = '';
810
+                            $accountingaccount->fetch(null, $k, true);		// TODO Use a cache
811
+                            $bookkeeping->numero_compte = $k;
812
+                            $bookkeeping->label_compte = $accountingaccount->label;
813
+                        } elseif ($tabtype[$key] == 'member') {
814
+                            $bookkeeping->subledger_account = '';
815
+                            $bookkeeping->subledger_label = '';
816
+                            $accountingaccount->fetch(null, $k, true);		// TODO Use a cache
817
+                            $bookkeeping->numero_compte = $k;
818
+                            $bookkeeping->label_compte = $accountingaccount->label;
819
+                        } elseif ($tabtype[$key] == 'payment_loan') {
820
+                            $bookkeeping->subledger_account = '';
821
+                            $bookkeeping->subledger_label = '';
822
+                            $accountingaccount->fetch(null, $k, true);		// TODO Use a cache
823
+                            $bookkeeping->numero_compte = $k;
824
+                            $bookkeeping->label_compte = $accountingaccount->label;
825
+                        } elseif ($tabtype[$key] == 'payment_various') {
826
+                            $bookkeeping->subledger_account = $k;
827
+                            $bookkeeping->subledger_label = $tabcompany[$key]['name'];
828
+                            $accountingaccount->fetch(null, $tabpay[$key]["account_various"], true);	// TODO Use a cache
829
+                            $bookkeeping->numero_compte = $tabpay[$key]["account_various"];
830
+                            $bookkeeping->label_compte = $accountingaccount->label;
831
+                        } elseif ($tabtype[$key] == 'banktransfert') {
832
+                            $bookkeeping->subledger_account = '';
833
+                            $bookkeeping->subledger_label = '';
834
+                            $accountingaccount->fetch(null, $k, true);		// TODO Use a cache
835
+                            $bookkeeping->numero_compte = $k;
836
+                            $bookkeeping->label_compte = $accountingaccount->label;
837
+                        } else {
838
+                            if ($tabtype[$key] == 'unknown') {	// Unknown transaction, we will use a waiting account for thirdparty.
839
+                                // Temporary account
840
+                                $bookkeeping->subledger_account = '';
841
+                                $bookkeeping->subledger_label = '';
842
+                                $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE');
843
+                                $bookkeeping->label_compte = $accountingaccountsuspense->label;
844
+                            }
845
+                        }
846
+                        $bookkeeping->label_operation = $reflabel;
847
+                        $bookkeeping->entity = $conf->entity;
848
+
849
+                        $totaldebit += $bookkeeping->debit;
850
+                        $totalcredit += $bookkeeping->credit;
851
+
852
+                        $result = $bookkeeping->create($user);
853
+                        if ($result < 0) {
854
+                            if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
855
+                                $error++;
856
+                                $errorforline++;
857
+                                setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
858
+                            } else {
859
+                                $error++;
860
+                                $errorforline++;
861
+                                setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
862
+                            }
863
+                        } else {
864
+                            if ($lettering && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) {
865
+                                $lettering_static = new Lettering($db);
866
+                                $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id));
867
+                            }
868
+                        }
869
+                    }
870
+                }
871
+            } else {	// If thirdparty unknown, output the waiting account
872
+                foreach ($tabbq[$key] as $k => $mt) {
873
+                    if ($mt) {
874
+                        $reflabel = '';
875
+                        if (!empty($val['lib'])) {
876
+                            $reflabel .= dol_string_nohtmltag($val['lib'])." - ";
877
+                        }
878
+                        $reflabel .= dol_string_nohtmltag('WaitingAccount');
879
+
880
+                        $bookkeeping = new BookKeeping($db);
881
+                        $bookkeeping->doc_date = $val["date"];
882
+                        $bookkeeping->doc_ref = $ref;
883
+                        $bookkeeping->doc_type = 'bank';
884
+                        $bookkeeping->fk_doc = $key;
885
+                        $bookkeeping->fk_docdet = $val["fk_bank"];
886
+                        $bookkeeping->montant = $mt;
887
+                        $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
888
+                        $bookkeeping->debit = ($mt < 0 ? -$mt : 0);
889
+                        $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
890
+                        $bookkeeping->code_journal = $journal;
891
+                        $bookkeeping->journal_label = $langs->transnoentities($journal_label);
892
+                        $bookkeeping->fk_user_author = $user->id;
893
+                        $bookkeeping->date_creation = $now;
894
+                        $bookkeeping->label_compte = '';
895
+                        $bookkeeping->label_operation = $reflabel;
896
+                        $bookkeeping->entity = $conf->entity;
897
+
898
+                        $totaldebit += $bookkeeping->debit;
899
+                        $totalcredit += $bookkeeping->credit;
900
+
901
+                        $result = $bookkeeping->create($user);
902
+
903
+                        if ($result < 0) {
904
+                            if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') {	// Already exists
905
+                                $error++;
906
+                                $errorforline++;
907
+                                setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings');
908
+                            } else {
909
+                                $error++;
910
+                                $errorforline++;
911
+                                setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
912
+                            }
913
+                        }
914
+                    }
915
+                }
916
+            }
917
+        }
918 918
 
919
-		if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) {
920
-			$error++;
921
-			$errorforline++;
922
-			setEventMessages('We tried to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors');
923
-		}
919
+        if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) {
920
+            $error++;
921
+            $errorforline++;
922
+            setEventMessages('We tried to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors');
923
+        }
924 924
 
925
-		if (!$errorforline) {
926
-			$db->commit();
927
-		} else {
928
-			//print 'KO for line '.$key.' '.$error.'<br>';
929
-			$db->rollback();
925
+        if (!$errorforline) {
926
+            $db->commit();
927
+        } else {
928
+            //print 'KO for line '.$key.' '.$error.'<br>';
929
+            $db->rollback();
930 930
 
931
-			$MAXNBERRORS = 5;
932
-			if ($error >= $MAXNBERRORS) {
933
-				setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
934
-				break; // Break in the foreach
935
-			}
936
-		}
937
-	}
938
-
939
-	if (empty($error) && count($tabpay) > 0) {
940
-		setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
941
-	} elseif (count($tabpay) == $error) {
942
-		setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
943
-	} else {
944
-		setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
945
-	}
946
-
947
-	$action = '';
948
-
949
-	// Must reload data, so we make a redirect
950
-	if (count($tabpay) != $error) {
951
-		$param = 'id_journal='.$id_journal;
952
-		$param .= '&date_startday='.$date_startday;
953
-		$param .= '&date_startmonth='.$date_startmonth;
954
-		$param .= '&date_startyear='.$date_startyear;
955
-		$param .= '&date_endday='.$date_endday;
956
-		$param .= '&date_endmonth='.$date_endmonth;
957
-		$param .= '&date_endyear='.$date_endyear;
958
-		$param .= '&in_bookkeeping='.$in_bookkeeping;
959
-		header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
960
-		exit;
961
-	}
931
+            $MAXNBERRORS = 5;
932
+            if ($error >= $MAXNBERRORS) {
933
+                setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped").' (>'.$MAXNBERRORS.')', null, 'errors');
934
+                break; // Break in the foreach
935
+            }
936
+        }
937
+    }
938
+
939
+    if (empty($error) && count($tabpay) > 0) {
940
+        setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
941
+    } elseif (count($tabpay) == $error) {
942
+        setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings');
943
+    } else {
944
+        setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
945
+    }
946
+
947
+    $action = '';
948
+
949
+    // Must reload data, so we make a redirect
950
+    if (count($tabpay) != $error) {
951
+        $param = 'id_journal='.$id_journal;
952
+        $param .= '&date_startday='.$date_startday;
953
+        $param .= '&date_startmonth='.$date_startmonth;
954
+        $param .= '&date_startyear='.$date_startyear;
955
+        $param .= '&date_endday='.$date_endday;
956
+        $param .= '&date_endmonth='.$date_endmonth;
957
+        $param .= '&date_endyear='.$date_endyear;
958
+        $param .= '&in_bookkeeping='.$in_bookkeeping;
959
+        header("Location: ".$_SERVER['PHP_SELF'].($param ? '?'.$param : ''));
960
+        exit;
961
+    }
962 962
 }
963 963
 
964 964
 
965 965
 
966 966
 // Export
967 967
 if ($action == 'exportcsv') {		// ISO and not UTF8 !
968
-	$sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
969
-
970
-	$filename = 'journal';
971
-	$type_export = 'journal';
972
-	include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
973
-
974
-	// CSV header line
975
-	print '"'.$langs->transnoentitiesnoconv("BankId").'"'.$sep;
976
-	print '"'.$langs->transnoentitiesnoconv("Date").'"'.$sep;
977
-	print '"'.$langs->transnoentitiesnoconv("PaymentMode").'"'.$sep;
978
-	print '"'.$langs->transnoentitiesnoconv("AccountAccounting").'"'.$sep;
979
-	print '"'.$langs->transnoentitiesnoconv("LedgerAccount").'"'.$sep;
980
-	print '"'.$langs->transnoentitiesnoconv("SubledgerAccount").'"'.$sep;
981
-	print '"'.$langs->transnoentitiesnoconv("Label").'"'.$sep;
982
-	print '"'.$langs->transnoentitiesnoconv("AccountingDebit").'"'.$sep;
983
-	print '"'.$langs->transnoentitiesnoconv("AccountingCredit").'"'.$sep;
984
-	print '"'.$langs->transnoentitiesnoconv("Journal").'"'.$sep;
985
-	print '"'.$langs->transnoentitiesnoconv("Note").'"'.$sep;
986
-	print "\n";
987
-
988
-	foreach ($tabpay as $key => $val) {
989
-		$date = dol_print_date($val["date"], 'day');
990
-
991
-		$ref = getSourceDocRef($val, $tabtype[$key]);
992
-
993
-		// Bank
994
-		foreach ($tabbq[$key] as $k => $mt) {
995
-			if ($mt) {
996
-				$reflabel = '';
997
-				if (!empty($val['lib'])) {
998
-					$reflabel .= dol_string_nohtmltag($val['lib'])." - ";
999
-				}
1000
-				$reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
1001
-				if (!empty($val['soclib'])) {
1002
-					$reflabel .= " - ".dol_string_nohtmltag($val['soclib']);
1003
-				}
1004
-
1005
-				print '"'.$key.'"'.$sep;
1006
-				print '"'.$date.'"'.$sep;
1007
-				print '"'.$val["type_payment"].'"'.$sep;
1008
-				print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1009
-				print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
1010
-				print "  ".$sep;
1011
-				print '"'.$reflabel.'"'.$sep;
1012
-				print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1013
-				print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1014
-				print '"'.$journal.'"'.$sep;
1015
-				print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1016
-				print "\n";
1017
-			}
1018
-		}
968
+    $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
969
+
970
+    $filename = 'journal';
971
+    $type_export = 'journal';
972
+    include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
973
+
974
+    // CSV header line
975
+    print '"'.$langs->transnoentitiesnoconv("BankId").'"'.$sep;
976
+    print '"'.$langs->transnoentitiesnoconv("Date").'"'.$sep;
977
+    print '"'.$langs->transnoentitiesnoconv("PaymentMode").'"'.$sep;
978
+    print '"'.$langs->transnoentitiesnoconv("AccountAccounting").'"'.$sep;
979
+    print '"'.$langs->transnoentitiesnoconv("LedgerAccount").'"'.$sep;
980
+    print '"'.$langs->transnoentitiesnoconv("SubledgerAccount").'"'.$sep;
981
+    print '"'.$langs->transnoentitiesnoconv("Label").'"'.$sep;
982
+    print '"'.$langs->transnoentitiesnoconv("AccountingDebit").'"'.$sep;
983
+    print '"'.$langs->transnoentitiesnoconv("AccountingCredit").'"'.$sep;
984
+    print '"'.$langs->transnoentitiesnoconv("Journal").'"'.$sep;
985
+    print '"'.$langs->transnoentitiesnoconv("Note").'"'.$sep;
986
+    print "\n";
987
+
988
+    foreach ($tabpay as $key => $val) {
989
+        $date = dol_print_date($val["date"], 'day');
990
+
991
+        $ref = getSourceDocRef($val, $tabtype[$key]);
992
+
993
+        // Bank
994
+        foreach ($tabbq[$key] as $k => $mt) {
995
+            if ($mt) {
996
+                $reflabel = '';
997
+                if (!empty($val['lib'])) {
998
+                    $reflabel .= dol_string_nohtmltag($val['lib'])." - ";
999
+                }
1000
+                $reflabel .= $langs->trans("Bank").' '.dol_string_nohtmltag($val['bank_account_ref']);
1001
+                if (!empty($val['soclib'])) {
1002
+                    $reflabel .= " - ".dol_string_nohtmltag($val['soclib']);
1003
+                }
1019 1004
 
1020
-		// Third party
1021
-		if (is_array($tabtp[$key])) {
1022
-			foreach ($tabtp[$key] as $k => $mt) {
1023
-				if ($mt) {
1024
-					$reflabel = '';
1025
-					if (!empty($val['lib'])) {
1026
-						$reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : "");
1027
-					}
1028
-					if ($tabtype[$key] == 'banktransfert') {
1029
-						$reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
1030
-					} else {
1031
-						$reflabel .= dol_string_nohtmltag($val['soclib']);
1032
-					}
1005
+                print '"'.$key.'"'.$sep;
1006
+                print '"'.$date.'"'.$sep;
1007
+                print '"'.$val["type_payment"].'"'.$sep;
1008
+                print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1009
+                print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
1010
+                print "  ".$sep;
1011
+                print '"'.$reflabel.'"'.$sep;
1012
+                print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1013
+                print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1014
+                print '"'.$journal.'"'.$sep;
1015
+                print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1016
+                print "\n";
1017
+            }
1018
+        }
1033 1019
 
1034
-					print '"'.$key.'"'.$sep;
1035
-					print '"'.$date.'"'.$sep;
1036
-					print '"'.$val["type_payment"].'"'.$sep;
1037
-					print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1038
-					if ($tabtype[$key] == 'payment_supplier') {
1039
-						print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER').'"'.$sep;
1040
-					} elseif ($tabtype[$key] == 'payment') {
1041
-						print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER').'"'.$sep;
1042
-					} elseif ($tabtype[$key] == 'payment_expensereport') {
1043
-						print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT').'"'.$sep;
1044
-					} elseif ($tabtype[$key] == 'payment_salary') {
1045
-						print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep;
1046
-					} else {
1047
-						print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1048
-					}
1049
-					print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
1050
-					print '"'.$reflabel.'"'.$sep;
1051
-					print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1052
-					print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1053
-					print '"'.$journal.'"'.$sep;
1054
-					print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1055
-					print "\n";
1056
-				}
1057
-			}
1058
-		} else {	// If thirdparty unknown, output the waiting account
1059
-			foreach ($tabbq[$key] as $k => $mt) {
1060
-				if ($mt) {
1061
-					$reflabel = '';
1062
-					if (!empty($val['lib'])) {
1063
-						$reflabel .= dol_string_nohtmltag($val['lib'])." - ";
1064
-					}
1065
-					$reflabel .= dol_string_nohtmltag('WaitingAccount');
1066
-
1067
-					print '"'.$key.'"'.$sep;
1068
-					print '"'.$date.'"'.$sep;
1069
-					print '"'.$val["type_payment"].'"'.$sep;
1070
-					print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep;
1071
-					print '"'.length_accounta(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep;
1072
-					print $sep;
1073
-					print '"'.$reflabel.'"'.$sep;
1074
-					print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1075
-					print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1076
-					print '"'.$journal.'"'.$sep;
1077
-					print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1078
-					print "\n";
1079
-				}
1080
-			}
1081
-		}
1082
-	}
1020
+        // Third party
1021
+        if (is_array($tabtp[$key])) {
1022
+            foreach ($tabtp[$key] as $k => $mt) {
1023
+                if ($mt) {
1024
+                    $reflabel = '';
1025
+                    if (!empty($val['lib'])) {
1026
+                        $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : "");
1027
+                    }
1028
+                    if ($tabtype[$key] == 'banktransfert') {
1029
+                        $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer);
1030
+                    } else {
1031
+                        $reflabel .= dol_string_nohtmltag($val['soclib']);
1032
+                    }
1033
+
1034
+                    print '"'.$key.'"'.$sep;
1035
+                    print '"'.$date.'"'.$sep;
1036
+                    print '"'.$val["type_payment"].'"'.$sep;
1037
+                    print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1038
+                    if ($tabtype[$key] == 'payment_supplier') {
1039
+                        print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER').'"'.$sep;
1040
+                    } elseif ($tabtype[$key] == 'payment') {
1041
+                        print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER').'"'.$sep;
1042
+                    } elseif ($tabtype[$key] == 'payment_expensereport') {
1043
+                        print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT').'"'.$sep;
1044
+                    } elseif ($tabtype[$key] == 'payment_salary') {
1045
+                        print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep;
1046
+                    } else {
1047
+                        print '"'.length_accountg(html_entity_decode($k)).'"'.$sep;
1048
+                    }
1049
+                    print '"'.length_accounta(html_entity_decode($k)).'"'.$sep;
1050
+                    print '"'.$reflabel.'"'.$sep;
1051
+                    print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1052
+                    print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1053
+                    print '"'.$journal.'"'.$sep;
1054
+                    print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1055
+                    print "\n";
1056
+                }
1057
+            }
1058
+        } else {	// If thirdparty unknown, output the waiting account
1059
+            foreach ($tabbq[$key] as $k => $mt) {
1060
+                if ($mt) {
1061
+                    $reflabel = '';
1062
+                    if (!empty($val['lib'])) {
1063
+                        $reflabel .= dol_string_nohtmltag($val['lib'])." - ";
1064
+                    }
1065
+                    $reflabel .= dol_string_nohtmltag('WaitingAccount');
1066
+
1067
+                    print '"'.$key.'"'.$sep;
1068
+                    print '"'.$date.'"'.$sep;
1069
+                    print '"'.$val["type_payment"].'"'.$sep;
1070
+                    print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep;
1071
+                    print '"'.length_accounta(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep;
1072
+                    print $sep;
1073
+                    print '"'.$reflabel.'"'.$sep;
1074
+                    print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep;
1075
+                    print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep;
1076
+                    print '"'.$journal.'"'.$sep;
1077
+                    print '"'.dol_string_nohtmltag($ref).'"'.$sep;
1078
+                    print "\n";
1079
+                }
1080
+            }
1081
+        }
1082
+    }
1083 1083
 }
1084 1084
 
1085 1085
 
@@ -1090,117 +1090,117 @@  discard block
 block discarded – undo
1090 1090
 $form = new Form($db);
1091 1091
 
1092 1092
 if (empty($action) || $action == 'view') {
1093
-	$invoicestatic = new Facture($db);
1094
-	$invoicesupplierstatic = new FactureFournisseur($db);
1095
-	$expensereportstatic = new ExpenseReport($db);
1096
-	$vatstatic = new Tva($db);
1097
-	$donationstatic = new Don($db);
1098
-	$loanstatic = new Loan($db);
1099
-	$salarystatic = new Salary($db);
1100
-	$variousstatic = new PaymentVarious($db);
1101
-
1102
-	$title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
1103
-	$help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#G&eacute;n&eacute;ration_des_&eacute;critures_en_comptabilit&eacute;';
1104
-	llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-bankjournal');
1105
-
1106
-	$nom = $title;
1107
-	$builddate = dol_now();
1108
-	//$description = $langs->trans("DescFinanceJournal") . '<br>';
1109
-	$description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1110
-
1111
-	$listofchoices = array(
1112
-		'notyet' => $langs->trans("NotYetInGeneralLedger"),
1113
-		'already' => $langs->trans("AlreadyInGeneralLedger")
1114
-	);
1115
-	$period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0);
1116
-	$period .= ' -  '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1117
-
1118
-	$varlink = 'id_journal='.$id_journal;
1119
-	$periodlink = '';
1120
-	$exportlink = '';
1121
-
1122
-	$listofchoices = array(
1123
-		1 => $langs->trans("TransfertAllBankLines"),
1124
-		2 => $langs->trans("TransfertOnlyConciliatedBankLine")
1125
-	);
1126
-	$moreoptions = [ "BankLineConciliated" => $form->selectarray('only_rappro', $listofchoices, $only_rappro)];
1127
-
1128
-	journalHead($nom, '', $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink, $moreoptions);
1129
-
1130
-	$desc = '';
1131
-
1132
-	if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1133
-		// Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1134
-		// Fiscal period test
1135
-		$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1136
-		$resql = $db->query($sql);
1137
-		if ($resql) {
1138
-			$obj = $db->fetch_object($resql);
1139
-			if ($obj->nb == 0) {
1140
-				print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1141
-				$desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1142
-				$desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1143
-				print $desc;
1144
-				print '</div>';
1145
-			}
1146
-		} else {
1147
-			dol_print_error($db);
1148
-		}
1149
-	}
1150
-
1151
-	// Bank test
1152
-	$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."bank_account WHERE entity = ".((int) $conf->entity)." AND fk_accountancy_journal IS NULL AND clos=0";
1153
-	$resql = $db->query($sql);
1154
-	if ($resql) {
1155
-		$obj = $db->fetch_object($resql);
1156
-		if ($obj->nb > 0) {
1157
-			print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount");
1158
-			$desc = ' : '.$langs->trans("AccountancyAreaDescBank", 6, '{link}');
1159
-			$desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'</strong>', $desc);
1160
-			print $desc;
1161
-			print '</div>';
1162
-		}
1163
-	} else {
1164
-		dol_print_error($db);
1165
-	}
1093
+    $invoicestatic = new Facture($db);
1094
+    $invoicesupplierstatic = new FactureFournisseur($db);
1095
+    $expensereportstatic = new ExpenseReport($db);
1096
+    $vatstatic = new Tva($db);
1097
+    $donationstatic = new Don($db);
1098
+    $loanstatic = new Loan($db);
1099
+    $salarystatic = new Salary($db);
1100
+    $variousstatic = new PaymentVarious($db);
1101
+
1102
+    $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1);
1103
+    $help_url ='EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#G&eacute;n&eacute;ration_des_&eacute;critures_en_comptabilit&eacute;';
1104
+    llxHeader('', dol_string_nohtmltag($title), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-generation page-bankjournal');
1105
+
1106
+    $nom = $title;
1107
+    $builddate = dol_now();
1108
+    //$description = $langs->trans("DescFinanceJournal") . '<br>';
1109
+    $description = $langs->trans("DescJournalOnlyBindedVisible").'<br>';
1110
+
1111
+    $listofchoices = array(
1112
+        'notyet' => $langs->trans("NotYetInGeneralLedger"),
1113
+        'already' => $langs->trans("AlreadyInGeneralLedger")
1114
+    );
1115
+    $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0);
1116
+    $period .= ' -  '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1);
1117
+
1118
+    $varlink = 'id_journal='.$id_journal;
1119
+    $periodlink = '';
1120
+    $exportlink = '';
1121
+
1122
+    $listofchoices = array(
1123
+        1 => $langs->trans("TransfertAllBankLines"),
1124
+        2 => $langs->trans("TransfertOnlyConciliatedBankLine")
1125
+    );
1126
+    $moreoptions = [ "BankLineConciliated" => $form->selectarray('only_rappro', $listofchoices, $only_rappro)];
1127
+
1128
+    journalHead($nom, '', $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink, $moreoptions);
1129
+
1130
+    $desc = '';
1131
+
1132
+    if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') {
1133
+        // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed)
1134
+        // Fiscal period test
1135
+        $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity);
1136
+        $resql = $db->query($sql);
1137
+        if ($resql) {
1138
+            $obj = $db->fetch_object($resql);
1139
+            if ($obj->nb == 0) {
1140
+                print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined");
1141
+                $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}');
1142
+                $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'</strong>', $desc);
1143
+                print $desc;
1144
+                print '</div>';
1145
+            }
1146
+        } else {
1147
+            dol_print_error($db);
1148
+        }
1149
+    }
1150
+
1151
+    // Bank test
1152
+    $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."bank_account WHERE entity = ".((int) $conf->entity)." AND fk_accountancy_journal IS NULL AND clos=0";
1153
+    $resql = $db->query($sql);
1154
+    if ($resql) {
1155
+        $obj = $db->fetch_object($resql);
1156
+        if ($obj->nb > 0) {
1157
+            print '<br><div class="warning">'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount");
1158
+            $desc = ' : '.$langs->trans("AccountancyAreaDescBank", 6, '{link}');
1159
+            $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'</strong>', $desc);
1160
+            print $desc;
1161
+            print '</div>';
1162
+        }
1163
+    } else {
1164
+        dol_print_error($db);
1165
+    }
1166 1166
 
1167 1167
 
1168
-	// Button to write into Ledger
1169
-	if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1170
-		|| getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1'
1171
-		|| (isModEnabled("salaries") && (getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1'))
1172
-		|| (isModEnabled("expensereport") && (getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == '-1'))) {
1168
+    // Button to write into Ledger
1169
+    if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1170
+        || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1'
1171
+        || (isModEnabled("salaries") && (getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1'))
1172
+        || (isModEnabled("expensereport") && (getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT') == '-1'))) {
1173 1173
 
1174 1174
 
1175
-		print($desc ? '' : '<br>').'<div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1176
-		$desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1177
-		$desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1178
-		print $desc;
1179
-		print '</div>';
1180
-	}
1175
+        print($desc ? '' : '<br>').'<div class="warning">'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
1176
+        $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}');
1177
+        $desc = str_replace('{link}', '<strong>'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'</strong>', $desc);
1178
+        print $desc;
1179
+        print '</div>';
1180
+    }
1181 1181
 
1182 1182
 
1183
-	print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1183
+    print '<br><div class="tabsAction tabsActionNoBottom centerimp">';
1184 1184
 
1185
-	if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1186
-		print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1187
-	}
1185
+    if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') {
1186
+        print '<input type="button" class="butAction" name="exportcsv" value="'.$langs->trans("ExportDraftJournal").'" onclick="launch_export();" />';
1187
+    }
1188 1188
 
1189
-	if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1190
-		|| getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1') {
1191
-		print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1192
-	} else {
1193
-		if ($in_bookkeeping == 'notyet') {
1194
-			print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1195
-		} else {
1196
-			print '<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1197
-		}
1198
-	}
1189
+    if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1'
1190
+        || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1') {
1191
+        print '<input type="button" class="butActionRefused classfortooltip" title="'.dol_escape_htmltag($langs->trans("SomeMandatoryStepsOfSetupWereNotDone")).'" value="'.$langs->trans("WriteBookKeeping").'" />';
1192
+    } else {
1193
+        if ($in_bookkeeping == 'notyet') {
1194
+            print '<input type="button" class="butAction" name="writebookkeeping" value="'.$langs->trans("WriteBookKeeping").'" onclick="writebookkeeping();" />';
1195
+        } else {
1196
+            print '<a class="butActionRefused classfortooltip" name="writebookkeeping">'.$langs->trans("WriteBookKeeping").'</a>';
1197
+        }
1198
+    }
1199 1199
 
1200
-	print '</div>';
1200
+    print '</div>';
1201 1201
 
1202
-	// TODO Avoid using js. We can use a direct link with $param
1203
-	print '
1202
+    // TODO Avoid using js. We can use a direct link with $param
1203
+    print '
1204 1204
 	<script type="text/javascript">
1205 1205
 		function launch_export() {
1206 1206
 			console.log("Set value into form and submit");
@@ -1216,259 +1216,259 @@  discard block
 block discarded – undo
1216 1216
 		}
1217 1217
 	</script>';
1218 1218
 
1219
-	/*
1219
+    /*
1220 1220
 	 * Show result array
1221 1221
 	 */
1222
-	print '<br>';
1223
-
1224
-	$i = 0;
1225
-	print '<div class="div-table-responsive">';
1226
-	print '<table class="noborder centpercent">';
1227
-	print '<tr class="liste_titre">';
1228
-	print "<td>".$langs->trans("Date")."</td>";
1229
-	print "<td>".$langs->trans("Piece").' ('.$langs->trans("ObjectsRef").")</td>";
1230
-	print "<td>".$langs->trans("AccountAccounting")."</td>";
1231
-	print "<td>".$langs->trans("SubledgerAccount")."</td>";
1232
-	print "<td>".$langs->trans("LabelOperation")."</td>";
1233
-	print '<td class="center">'.$langs->trans("PaymentMode")."</td>";
1234
-	print '<td class="right">'.$langs->trans("AccountingDebit")."</td>";
1235
-	print '<td class="right">'.$langs->trans("AccountingCredit")."</td>";
1236
-	print "</tr>\n";
1237
-
1238
-	$r = '';
1239
-
1240
-	foreach ($tabpay as $key => $val) {			  // $key is rowid in llx_bank
1241
-		$date = dol_print_date($val["date"], 'day');
1242
-
1243
-		$ref = getSourceDocRef($val, $tabtype[$key]);
1244
-
1245
-		// Bank
1246
-		foreach ($tabbq[$key] as $k => $mt) {
1247
-			if ($mt) {
1248
-				$reflabel = '';
1249
-				if (!empty($val['lib'])) {
1250
-					$reflabel .= $val['lib']." - ";
1251
-				}
1252
-				$reflabel .= $langs->trans("Bank").' '.$val['bank_account_ref'];
1253
-				if (!empty($val['soclib'])) {
1254
-					$reflabel .= " - ".$val['soclib'];
1255
-				}
1222
+    print '<br>';
1256 1223
 
1257
-				//var_dump($tabpay[$key]);
1258
-				print '<!-- Bank bank.rowid='.$key.' type='.$tabpay[$key]['type'].' ref='.$tabpay[$key]['ref'].'-->';
1259
-				print '<tr class="oddeven">';
1224
+    $i = 0;
1225
+    print '<div class="div-table-responsive">';
1226
+    print '<table class="noborder centpercent">';
1227
+    print '<tr class="liste_titre">';
1228
+    print "<td>".$langs->trans("Date")."</td>";
1229
+    print "<td>".$langs->trans("Piece").' ('.$langs->trans("ObjectsRef").")</td>";
1230
+    print "<td>".$langs->trans("AccountAccounting")."</td>";
1231
+    print "<td>".$langs->trans("SubledgerAccount")."</td>";
1232
+    print "<td>".$langs->trans("LabelOperation")."</td>";
1233
+    print '<td class="center">'.$langs->trans("PaymentMode")."</td>";
1234
+    print '<td class="right">'.$langs->trans("AccountingDebit")."</td>";
1235
+    print '<td class="right">'.$langs->trans("AccountingCredit")."</td>";
1236
+    print "</tr>\n";
1237
+
1238
+    $r = '';
1239
+
1240
+    foreach ($tabpay as $key => $val) {			  // $key is rowid in llx_bank
1241
+        $date = dol_print_date($val["date"], 'day');
1242
+
1243
+        $ref = getSourceDocRef($val, $tabtype[$key]);
1244
+
1245
+        // Bank
1246
+        foreach ($tabbq[$key] as $k => $mt) {
1247
+            if ($mt) {
1248
+                $reflabel = '';
1249
+                if (!empty($val['lib'])) {
1250
+                    $reflabel .= $val['lib']." - ";
1251
+                }
1252
+                $reflabel .= $langs->trans("Bank").' '.$val['bank_account_ref'];
1253
+                if (!empty($val['soclib'])) {
1254
+                    $reflabel .= " - ".$val['soclib'];
1255
+                }
1260 1256
 
1261
-				// Date
1262
-				print "<td>".$date."</td>";
1257
+                //var_dump($tabpay[$key]);
1258
+                print '<!-- Bank bank.rowid='.$key.' type='.$tabpay[$key]['type'].' ref='.$tabpay[$key]['ref'].'-->';
1259
+                print '<tr class="oddeven">';
1263 1260
 
1264
-				// Ref
1265
-				print "<td>".dol_escape_htmltag($ref)."</td>";
1261
+                // Date
1262
+                print "<td>".$date."</td>";
1266 1263
 
1267
-				// Ledger account
1268
-				$accounttoshow = length_accountg($k);
1269
-				if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1270
-					$accounttoshow = '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1271
-				}
1272
-				print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1273
-				print $accounttoshow;
1274
-				print "</td>";
1264
+                // Ref
1265
+                print "<td>".dol_escape_htmltag($ref)."</td>";
1275 1266
 
1276
-				// Subledger account
1277
-				print '<td class="maxwidth300">';
1278
-				/*$accounttoshow = length_accountg($k);
1267
+                // Ledger account
1268
+                $accounttoshow = length_accountg($k);
1269
+                if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1270
+                    $accounttoshow = '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1271
+                }
1272
+                print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1273
+                print $accounttoshow;
1274
+                print "</td>";
1275
+
1276
+                // Subledger account
1277
+                print '<td class="maxwidth300">';
1278
+                /*$accounttoshow = length_accountg($k);
1279 1279
 				if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1280 1280
 				{
1281 1281
 					print '<span class="error">'.$langs->trans("BankAccountNotDefined").'</span>';
1282 1282
 				}
1283 1283
 				else print $accounttoshow;*/
1284
-				print "</td>";
1285
-
1286
-				// Label operation
1287
-				print '<td>';
1288
-				print $reflabel;	// This is already html escaped content
1289
-				print "</td>";
1290
-
1291
-				print '<td class="center">'.$val["type_payment"]."</td>";
1292
-				print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1293
-				print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1294
-				print "</tr>";
1295
-
1296
-				$i++;
1297
-			}
1298
-		}
1299
-
1300
-		// Third party
1301
-		if (is_array($tabtp[$key])) {
1302
-			foreach ($tabtp[$key] as $k => $mt) {
1303
-				if ($mt) {
1304
-					$reflabel = '';
1305
-					if (!empty($val['lib'])) {
1306
-						$reflabel .= $val['lib'].(isset($val['soclib']) ? " - " : "");
1307
-					}
1308
-					if ($tabtype[$key] == 'banktransfert') {
1309
-						$reflabel .= $langs->trans('TransitionalAccount').' '.$account_transfer;
1310
-					} else {
1311
-						$reflabel .= isset($val['soclib']) ? $val['soclib'] : "";
1312
-					}
1313
-
1314
-					print '<!-- Thirdparty bank.rowid='.$key.' -->';
1315
-					print '<tr class="oddeven">';
1316
-
1317
-					// Date
1318
-					print "<td>".$date."</td>";
1319
-
1320
-					// Ref
1321
-					print "<td>".dol_escape_htmltag($ref)."</td>";
1322
-
1323
-					// Ledger account
1324
-					$account_ledger = $k;
1325
-					// Try to force general ledger account depending on type
1326
-					if ($tabtype[$key] == 'payment') {
1327
-						$account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER');
1328
-					}
1329
-					if ($tabtype[$key] == 'payment_supplier') {
1330
-						$account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER');
1331
-					}
1332
-					if ($tabtype[$key] == 'payment_expensereport') {
1333
-						$account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
1334
-					}
1335
-					if ($tabtype[$key] == 'payment_salary') {
1336
-						$account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
1337
-					}
1338
-					if ($tabtype[$key] == 'payment_vat') {
1339
-						$account_ledger = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT');
1340
-					}
1341
-					if ($tabtype[$key] == 'member') {
1342
-						$account_ledger = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT');
1343
-					}
1344
-					if ($tabtype[$key] == 'payment_various') {
1345
-						$account_ledger = $tabpay[$key]["account_various"];
1346
-					}
1347
-					$accounttoshow = length_accountg($account_ledger);
1348
-					if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1349
-						if ($tabtype[$key] == 'unknown') {
1350
-							// We will accept writing, but into a waiting account
1351
-							if (!getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') || getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') == '-1') {
1352
-								$accounttoshow = '<span class="error small">'.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').'</span>';
1353
-							} else {
1354
-								$accounttoshow = '<span class="warning small">'.$langs->trans('UnknownAccountForThirdparty', length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'))).'</span>'; // We will use a waiting account
1355
-							}
1356
-						} else {
1357
-							// We will refuse writing
1358
-							$errorstring = 'UnknownAccountForThirdpartyBlocking';
1359
-							if ($tabtype[$key] == 'payment') {
1360
-								$errorstring = 'MainAccountForCustomersNotDefined';
1361
-							}
1362
-							if ($tabtype[$key] == 'payment_supplier') {
1363
-								$errorstring = 'MainAccountForSuppliersNotDefined';
1364
-							}
1365
-							if ($tabtype[$key] == 'payment_expensereport') {
1366
-								$errorstring = 'MainAccountForUsersNotDefined';
1367
-							}
1368
-							if ($tabtype[$key] == 'payment_salary') {
1369
-								$errorstring = 'MainAccountForUsersNotDefined';
1370
-							}
1371
-							if ($tabtype[$key] == 'payment_vat') {
1372
-								$errorstring = 'MainAccountForVatPaymentNotDefined';
1373
-							}
1374
-							if ($tabtype[$key] == 'member') {
1375
-								$errorstring = 'MainAccountForSubscriptionPaymentNotDefined';
1376
-							}
1377
-							$accounttoshow = '<span class="error small">'.$langs->trans($errorstring).'</span>';
1378
-						}
1379
-					}
1380
-					print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1381
-					print $accounttoshow;	// This is a HTML string
1382
-					print "</td>";
1383
-
1384
-					// Subledger account
1385
-					$accounttoshowsubledger = '';
1386
-					if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) {	// Type of payments that uses a subledger
1387
-						$accounttoshowsubledger = length_accounta($k);
1388
-						if ($accounttoshow != $accounttoshowsubledger) {
1389
-							if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') {
1390
-								//var_dump($tabpay[$key]);
1391
-								//var_dump($tabtype[$key]);
1392
-								//var_dump($tabbq[$key]);
1393
-								//print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1394
-								if (!empty($tabcompany[$key]['code_compta'])) {
1395
-									if (in_array($tabtype[$key], array('payment_various', 'payment_salary'))) {
1396
-										// For such case, if subledger is not defined, we won't use subledger accounts.
1397
-										$accounttoshowsubledger = '<span class="warning small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").'</span>';
1398
-									} else {
1399
-										$accounttoshowsubledger = '<span class="warning small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).'</span>';
1400
-									}
1401
-								} else {
1402
-									$accounttoshowsubledger = '<span class="error small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").'</span>';
1403
-								}
1404
-							}
1405
-						} else {
1406
-							$accounttoshowsubledger = '';
1407
-						}
1408
-					}
1409
-					print '<td class="maxwidth300">';
1410
-					print $accounttoshowsubledger;	// This is a html string
1411
-					print "</td>";
1412
-
1413
-					print "<td>".$reflabel."</td>";
1414
-
1415
-					print '<td class="center">'.$val["type_payment"]."</td>";
1284
+                print "</td>";
1416 1285
 
1417
-					print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1286
+                // Label operation
1287
+                print '<td>';
1288
+                print $reflabel;	// This is already html escaped content
1289
+                print "</td>";
1418 1290
 
1419
-					print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1291
+                print '<td class="center">'.$val["type_payment"]."</td>";
1292
+                print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1293
+                print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1294
+                print "</tr>";
1420 1295
 
1421
-					print "</tr>";
1296
+                $i++;
1297
+            }
1298
+        }
1422 1299
 
1423
-					$i++;
1424
-				}
1425
-			}
1426
-		} else {	// Waiting account
1427
-			foreach ($tabbq[$key] as $k => $mt) {
1428
-				if ($mt) {
1429
-					$reflabel = '';
1430
-					if (!empty($val['lib'])) {
1431
-						$reflabel .= $val['lib']." - ";
1432
-					}
1433
-					$reflabel .= 'WaitingAccount';
1434
-
1435
-					print '<!-- Wait bank.rowid='.$key.' -->';
1436
-					print '<tr class="oddeven">';
1437
-					print "<td>".$date."</td>";
1438
-					print "<td>".$ref."</td>";
1439
-					// Ledger account
1440
-					print "<td>";
1441
-					/*if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1300
+        // Third party
1301
+        if (is_array($tabtp[$key])) {
1302
+            foreach ($tabtp[$key] as $k => $mt) {
1303
+                if ($mt) {
1304
+                    $reflabel = '';
1305
+                    if (!empty($val['lib'])) {
1306
+                        $reflabel .= $val['lib'].(isset($val['soclib']) ? " - " : "");
1307
+                    }
1308
+                    if ($tabtype[$key] == 'banktransfert') {
1309
+                        $reflabel .= $langs->trans('TransitionalAccount').' '.$account_transfer;
1310
+                    } else {
1311
+                        $reflabel .= isset($val['soclib']) ? $val['soclib'] : "";
1312
+                    }
1313
+
1314
+                    print '<!-- Thirdparty bank.rowid='.$key.' -->';
1315
+                    print '<tr class="oddeven">';
1316
+
1317
+                    // Date
1318
+                    print "<td>".$date."</td>";
1319
+
1320
+                    // Ref
1321
+                    print "<td>".dol_escape_htmltag($ref)."</td>";
1322
+
1323
+                    // Ledger account
1324
+                    $account_ledger = $k;
1325
+                    // Try to force general ledger account depending on type
1326
+                    if ($tabtype[$key] == 'payment') {
1327
+                        $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER');
1328
+                    }
1329
+                    if ($tabtype[$key] == 'payment_supplier') {
1330
+                        $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER');
1331
+                    }
1332
+                    if ($tabtype[$key] == 'payment_expensereport') {
1333
+                        $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_EXPENSEREPORT');
1334
+                    }
1335
+                    if ($tabtype[$key] == 'payment_salary') {
1336
+                        $account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT');
1337
+                    }
1338
+                    if ($tabtype[$key] == 'payment_vat') {
1339
+                        $account_ledger = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT');
1340
+                    }
1341
+                    if ($tabtype[$key] == 'member') {
1342
+                        $account_ledger = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT');
1343
+                    }
1344
+                    if ($tabtype[$key] == 'payment_various') {
1345
+                        $account_ledger = $tabpay[$key]["account_various"];
1346
+                    }
1347
+                    $accounttoshow = length_accountg($account_ledger);
1348
+                    if (empty($accounttoshow) || $accounttoshow == 'NotDefined') {
1349
+                        if ($tabtype[$key] == 'unknown') {
1350
+                            // We will accept writing, but into a waiting account
1351
+                            if (!getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') || getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') == '-1') {
1352
+                                $accounttoshow = '<span class="error small">'.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').'</span>';
1353
+                            } else {
1354
+                                $accounttoshow = '<span class="warning small">'.$langs->trans('UnknownAccountForThirdparty', length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'))).'</span>'; // We will use a waiting account
1355
+                            }
1356
+                        } else {
1357
+                            // We will refuse writing
1358
+                            $errorstring = 'UnknownAccountForThirdpartyBlocking';
1359
+                            if ($tabtype[$key] == 'payment') {
1360
+                                $errorstring = 'MainAccountForCustomersNotDefined';
1361
+                            }
1362
+                            if ($tabtype[$key] == 'payment_supplier') {
1363
+                                $errorstring = 'MainAccountForSuppliersNotDefined';
1364
+                            }
1365
+                            if ($tabtype[$key] == 'payment_expensereport') {
1366
+                                $errorstring = 'MainAccountForUsersNotDefined';
1367
+                            }
1368
+                            if ($tabtype[$key] == 'payment_salary') {
1369
+                                $errorstring = 'MainAccountForUsersNotDefined';
1370
+                            }
1371
+                            if ($tabtype[$key] == 'payment_vat') {
1372
+                                $errorstring = 'MainAccountForVatPaymentNotDefined';
1373
+                            }
1374
+                            if ($tabtype[$key] == 'member') {
1375
+                                $errorstring = 'MainAccountForSubscriptionPaymentNotDefined';
1376
+                            }
1377
+                            $accounttoshow = '<span class="error small">'.$langs->trans($errorstring).'</span>';
1378
+                        }
1379
+                    }
1380
+                    print '<td class="maxwidth300" title="'.dol_escape_htmltag(dol_string_nohtmltag($accounttoshow)).'">';
1381
+                    print $accounttoshow;	// This is a HTML string
1382
+                    print "</td>";
1383
+
1384
+                    // Subledger account
1385
+                    $accounttoshowsubledger = '';
1386
+                    if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) {	// Type of payments that uses a subledger
1387
+                        $accounttoshowsubledger = length_accounta($k);
1388
+                        if ($accounttoshow != $accounttoshowsubledger) {
1389
+                            if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') {
1390
+                                //var_dump($tabpay[$key]);
1391
+                                //var_dump($tabtype[$key]);
1392
+                                //var_dump($tabbq[$key]);
1393
+                                //print '<span class="error">'.$langs->trans("ThirdpartyAccountNotDefined").'</span>';
1394
+                                if (!empty($tabcompany[$key]['code_compta'])) {
1395
+                                    if (in_array($tabtype[$key], array('payment_various', 'payment_salary'))) {
1396
+                                        // For such case, if subledger is not defined, we won't use subledger accounts.
1397
+                                        $accounttoshowsubledger = '<span class="warning small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").'</span>';
1398
+                                    } else {
1399
+                                        $accounttoshowsubledger = '<span class="warning small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).'</span>';
1400
+                                    }
1401
+                                } else {
1402
+                                    $accounttoshowsubledger = '<span class="error small">'.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").'</span>';
1403
+                                }
1404
+                            }
1405
+                        } else {
1406
+                            $accounttoshowsubledger = '';
1407
+                        }
1408
+                    }
1409
+                    print '<td class="maxwidth300">';
1410
+                    print $accounttoshowsubledger;	// This is a html string
1411
+                    print "</td>";
1412
+
1413
+                    print "<td>".$reflabel."</td>";
1414
+
1415
+                    print '<td class="center">'.$val["type_payment"]."</td>";
1416
+
1417
+                    print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1418
+
1419
+                    print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1420
+
1421
+                    print "</tr>";
1422
+
1423
+                    $i++;
1424
+                }
1425
+            }
1426
+        } else {	// Waiting account
1427
+            foreach ($tabbq[$key] as $k => $mt) {
1428
+                if ($mt) {
1429
+                    $reflabel = '';
1430
+                    if (!empty($val['lib'])) {
1431
+                        $reflabel .= $val['lib']." - ";
1432
+                    }
1433
+                    $reflabel .= 'WaitingAccount';
1434
+
1435
+                    print '<!-- Wait bank.rowid='.$key.' -->';
1436
+                    print '<tr class="oddeven">';
1437
+                    print "<td>".$date."</td>";
1438
+                    print "<td>".$ref."</td>";
1439
+                    // Ledger account
1440
+                    print "<td>";
1441
+                    /*if (empty($accounttoshow) || $accounttoshow == 'NotDefined')
1442 1442
 					{
1443 1443
 						print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
1444 1444
 					}
1445 1445
 					else */
1446
-					print length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'));
1447
-					print "</td>";
1448
-					// Subledger account
1449
-					print "<td>";
1450
-					print "</td>";
1451
-					print "<td>".dol_escape_htmltag($reflabel)."</td>";
1452
-					print '<td class="center">'.$val["type_payment"]."</td>";
1453
-					print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1454
-					print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1455
-					print "</tr>";
1456
-
1457
-					$i++;
1458
-				}
1459
-			}
1460
-		}
1461
-	}
1446
+                    print length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'));
1447
+                    print "</td>";
1448
+                    // Subledger account
1449
+                    print "<td>";
1450
+                    print "</td>";
1451
+                    print "<td>".dol_escape_htmltag($reflabel)."</td>";
1452
+                    print '<td class="center">'.$val["type_payment"]."</td>";
1453
+                    print '<td class="right nowraponall amount">'.($mt < 0 ? price(-$mt) : '')."</td>";
1454
+                    print '<td class="right nowraponall amount">'.($mt >= 0 ? price($mt) : '')."</td>";
1455
+                    print "</tr>";
1456
+
1457
+                    $i++;
1458
+                }
1459
+            }
1460
+        }
1461
+    }
1462 1462
 
1463
-	if (!$i) {
1464
-		$colspan = 8;
1465
-		print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1466
-	}
1463
+    if (!$i) {
1464
+        $colspan = 8;
1465
+        print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1466
+    }
1467 1467
 
1468
-	print "</table>";
1469
-	print '</div>';
1468
+    print "</table>";
1469
+    print '</div>';
1470 1470
 
1471
-	llxFooter();
1471
+    llxFooter();
1472 1472
 }
1473 1473
 
1474 1474
 $db->close();
@@ -1484,110 +1484,110 @@  discard block
 block discarded – undo
1484 1484
  */
1485 1485
 function getSourceDocRef($val, $typerecord)
1486 1486
 {
1487
-	global $db, $langs;
1488
-
1489
-	// Defined the docref into $ref (We start with $val['ref'] by default and we complete according to other data)
1490
-	// WE MUST HAVE SAME REF FOR ALL LINES WE WILL RECORD INTO THE BOOKKEEPING
1491
-	$ref = $val['ref'];
1492
-	if ($ref == '(SupplierInvoicePayment)' || $ref == '(SupplierInvoicePaymentBack)') {
1493
-		$ref = $langs->transnoentitiesnoconv('Supplier');
1494
-	}
1495
-	if ($ref == '(CustomerInvoicePayment)' || $ref == '(CustomerInvoicePaymentBack)') {
1496
-		$ref = $langs->transnoentitiesnoconv('Customer');
1497
-	}
1498
-	if ($ref == '(SocialContributionPayment)') {
1499
-		$ref = $langs->transnoentitiesnoconv('SocialContribution');
1500
-	}
1501
-	if ($ref == '(DonationPayment)') {
1502
-		$ref = $langs->transnoentitiesnoconv('Donation');
1503
-	}
1504
-	if ($ref == '(SubscriptionPayment)') {
1505
-		$ref = $langs->transnoentitiesnoconv('Subscription');
1506
-	}
1507
-	if ($ref == '(ExpenseReportPayment)') {
1508
-		$ref = $langs->transnoentitiesnoconv('Employee');
1509
-	}
1510
-	if ($ref == '(LoanPayment)') {
1511
-		$ref = $langs->transnoentitiesnoconv('Loan');
1512
-	}
1513
-	if ($ref == '(payment_salary)') {
1514
-		$ref = $langs->transnoentitiesnoconv('Employee');
1515
-	}
1516
-
1517
-	$sqlmid = '';
1518
-	if ($typerecord == 'payment') {
1519
-		if (getDolGlobalInt('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1520
-			$sqlmid = "SELECT payfac.fk_facture as id, ".$db->ifsql('f1.rowid IS NULL', 'f.ref', 'f1.ref')." as ref";
1521
-			$sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1522
-			$sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1523
-			$sqlmid .= " LEFT JOIN ".$db->prefix()."societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1524
-			$sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f1 ON f1.rowid = sre.fk_facture";
1525
-			$sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1526
-		} else {
1527
-			$sqlmid = "SELECT payfac.fk_facture as id, f.ref as ref";
1528
-			$sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1529
-			$sqlmid .= " INNER JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1530
-			$sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1531
-		}
1532
-		$ref = $langs->transnoentitiesnoconv("Invoice");
1533
-	} elseif ($typerecord == 'payment_supplier') {
1534
-		$sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref';
1535
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f";
1536
-		$sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val["paymentsupplierid"]);
1537
-		$ref = $langs->transnoentitiesnoconv("SupplierInvoice");
1538
-	} elseif ($typerecord == 'payment_expensereport') {
1539
-		$sqlmid = 'SELECT e.rowid as id, e.ref';
1540
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as pe, ".MAIN_DB_PREFIX."expensereport as e";
1541
-		$sqlmid .= " WHERE pe.rowid=".((int) $val["paymentexpensereport"])." AND pe.fk_expensereport = e.rowid";
1542
-		$ref = $langs->transnoentitiesnoconv("ExpenseReport");
1543
-	} elseif ($typerecord == 'payment_salary') {
1544
-		$sqlmid = 'SELECT s.rowid as ref';
1545
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
1546
-		$sqlmid .= " WHERE s.rowid=".((int) $val["paymentsalid"]);
1547
-		$ref = $langs->transnoentitiesnoconv("SalaryPayment");
1548
-	} elseif ($typerecord == 'sc') {
1549
-		$sqlmid = 'SELECT sc.rowid as ref';
1550
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementcharge as sc";
1551
-		$sqlmid .= " WHERE sc.rowid=".((int) $val["paymentscid"]);
1552
-		$ref = $langs->transnoentitiesnoconv("SocialContribution");
1553
-	} elseif ($typerecord == 'payment_vat') {
1554
-		$sqlmid = 'SELECT v.rowid as ref';
1555
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."tva as v";
1556
-		$sqlmid .= " WHERE v.rowid=".((int) $val["paymentvatid"]);
1557
-		$ref = $langs->transnoentitiesnoconv("PaymentVat");
1558
-	} elseif ($typerecord == 'payment_donation') {
1559
-		$sqlmid = 'SELECT payd.fk_donation as ref';
1560
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_donation as payd";
1561
-		$sqlmid .= " WHERE payd.fk_donation=".((int) $val["paymentdonationid"]);
1562
-		$ref = $langs->transnoentitiesnoconv("Donation");
1563
-	} elseif ($typerecord == 'payment_loan') {
1564
-		$sqlmid = 'SELECT l.rowid as ref';
1565
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_loan as l";
1566
-		$sqlmid .= " WHERE l.rowid=".((int) $val["paymentloanid"]);
1567
-		$ref = $langs->transnoentitiesnoconv("LoanPayment");
1568
-	} elseif ($typerecord == 'payment_various') {
1569
-		$sqlmid = 'SELECT v.rowid as ref';
1570
-		$sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
1571
-		$sqlmid .= " WHERE v.rowid=".((int) $val["paymentvariousid"]);
1572
-		$ref = $langs->transnoentitiesnoconv("VariousPayment");
1573
-	}
1574
-	// Add warning
1575
-	if (empty($sqlmid)) {
1576
-		dol_syslog("Found a typerecord=".$typerecord." not supported", LOG_WARNING);
1577
-	}
1578
-
1579
-	if ($sqlmid) {
1580
-		dol_syslog("accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1581
-		$resultmid = $db->query($sqlmid);
1582
-		if ($resultmid) {
1583
-			while ($objmid = $db->fetch_object($resultmid)) {
1584
-				$ref .= ' '.$objmid->ref;
1585
-			}
1586
-		} else {
1587
-			dol_print_error($db);
1588
-		}
1589
-	}
1487
+    global $db, $langs;
1488
+
1489
+    // Defined the docref into $ref (We start with $val['ref'] by default and we complete according to other data)
1490
+    // WE MUST HAVE SAME REF FOR ALL LINES WE WILL RECORD INTO THE BOOKKEEPING
1491
+    $ref = $val['ref'];
1492
+    if ($ref == '(SupplierInvoicePayment)' || $ref == '(SupplierInvoicePaymentBack)') {
1493
+        $ref = $langs->transnoentitiesnoconv('Supplier');
1494
+    }
1495
+    if ($ref == '(CustomerInvoicePayment)' || $ref == '(CustomerInvoicePaymentBack)') {
1496
+        $ref = $langs->transnoentitiesnoconv('Customer');
1497
+    }
1498
+    if ($ref == '(SocialContributionPayment)') {
1499
+        $ref = $langs->transnoentitiesnoconv('SocialContribution');
1500
+    }
1501
+    if ($ref == '(DonationPayment)') {
1502
+        $ref = $langs->transnoentitiesnoconv('Donation');
1503
+    }
1504
+    if ($ref == '(SubscriptionPayment)') {
1505
+        $ref = $langs->transnoentitiesnoconv('Subscription');
1506
+    }
1507
+    if ($ref == '(ExpenseReportPayment)') {
1508
+        $ref = $langs->transnoentitiesnoconv('Employee');
1509
+    }
1510
+    if ($ref == '(LoanPayment)') {
1511
+        $ref = $langs->transnoentitiesnoconv('Loan');
1512
+    }
1513
+    if ($ref == '(payment_salary)') {
1514
+        $ref = $langs->transnoentitiesnoconv('Employee');
1515
+    }
1516
+
1517
+    $sqlmid = '';
1518
+    if ($typerecord == 'payment') {
1519
+        if (getDolGlobalInt('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1520
+            $sqlmid = "SELECT payfac.fk_facture as id, ".$db->ifsql('f1.rowid IS NULL', 'f.ref', 'f1.ref')." as ref";
1521
+            $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1522
+            $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1523
+            $sqlmid .= " LEFT JOIN ".$db->prefix()."societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture";
1524
+            $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f1 ON f1.rowid = sre.fk_facture";
1525
+            $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1526
+        } else {
1527
+            $sqlmid = "SELECT payfac.fk_facture as id, f.ref as ref";
1528
+            $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac";
1529
+            $sqlmid .= " INNER JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture";
1530
+            $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']);
1531
+        }
1532
+        $ref = $langs->transnoentitiesnoconv("Invoice");
1533
+    } elseif ($typerecord == 'payment_supplier') {
1534
+        $sqlmid = 'SELECT payfac.fk_facturefourn as id, f.ref';
1535
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as payfac, ".MAIN_DB_PREFIX."facture_fourn as f";
1536
+        $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val["paymentsupplierid"]);
1537
+        $ref = $langs->transnoentitiesnoconv("SupplierInvoice");
1538
+    } elseif ($typerecord == 'payment_expensereport') {
1539
+        $sqlmid = 'SELECT e.rowid as id, e.ref';
1540
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as pe, ".MAIN_DB_PREFIX."expensereport as e";
1541
+        $sqlmid .= " WHERE pe.rowid=".((int) $val["paymentexpensereport"])." AND pe.fk_expensereport = e.rowid";
1542
+        $ref = $langs->transnoentitiesnoconv("ExpenseReport");
1543
+    } elseif ($typerecord == 'payment_salary') {
1544
+        $sqlmid = 'SELECT s.rowid as ref';
1545
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
1546
+        $sqlmid .= " WHERE s.rowid=".((int) $val["paymentsalid"]);
1547
+        $ref = $langs->transnoentitiesnoconv("SalaryPayment");
1548
+    } elseif ($typerecord == 'sc') {
1549
+        $sqlmid = 'SELECT sc.rowid as ref';
1550
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiementcharge as sc";
1551
+        $sqlmid .= " WHERE sc.rowid=".((int) $val["paymentscid"]);
1552
+        $ref = $langs->transnoentitiesnoconv("SocialContribution");
1553
+    } elseif ($typerecord == 'payment_vat') {
1554
+        $sqlmid = 'SELECT v.rowid as ref';
1555
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."tva as v";
1556
+        $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvatid"]);
1557
+        $ref = $langs->transnoentitiesnoconv("PaymentVat");
1558
+    } elseif ($typerecord == 'payment_donation') {
1559
+        $sqlmid = 'SELECT payd.fk_donation as ref';
1560
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_donation as payd";
1561
+        $sqlmid .= " WHERE payd.fk_donation=".((int) $val["paymentdonationid"]);
1562
+        $ref = $langs->transnoentitiesnoconv("Donation");
1563
+    } elseif ($typerecord == 'payment_loan') {
1564
+        $sqlmid = 'SELECT l.rowid as ref';
1565
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_loan as l";
1566
+        $sqlmid .= " WHERE l.rowid=".((int) $val["paymentloanid"]);
1567
+        $ref = $langs->transnoentitiesnoconv("LoanPayment");
1568
+    } elseif ($typerecord == 'payment_various') {
1569
+        $sqlmid = 'SELECT v.rowid as ref';
1570
+        $sqlmid .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
1571
+        $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvariousid"]);
1572
+        $ref = $langs->transnoentitiesnoconv("VariousPayment");
1573
+    }
1574
+    // Add warning
1575
+    if (empty($sqlmid)) {
1576
+        dol_syslog("Found a typerecord=".$typerecord." not supported", LOG_WARNING);
1577
+    }
1578
+
1579
+    if ($sqlmid) {
1580
+        dol_syslog("accountancy/journal/bankjournal.php::sqlmid=".$sqlmid, LOG_DEBUG);
1581
+        $resultmid = $db->query($sqlmid);
1582
+        if ($resultmid) {
1583
+            while ($objmid = $db->fetch_object($resultmid)) {
1584
+                $ref .= ' '.$objmid->ref;
1585
+            }
1586
+        } else {
1587
+            dol_print_error($db);
1588
+        }
1589
+    }
1590 1590
 
1591
-	$ref = dol_trunc($langs->transnoentitiesnoconv("BankId").' '.$val['fk_bank'].' - '.$ref, 295); // 295 + 3 dots (...) is < than max size of 300
1592
-	return $ref;
1591
+    $ref = dol_trunc($langs->transnoentitiesnoconv("BankId").' '.$val['fk_bank'].' - '.$ref, 295); // 295 + 3 dots (...) is < than max size of 300
1592
+    return $ref;
1593 1593
 }
Please login to merge, or discard this patch.
Dolibarr/Code/Adherents/Classes/AdherentType.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
     }
277 277
 
278 278
     /**
279
-        * Delete a language for this member type
280
-        *
281
-        * @param string $langtodelete   Language code to delete
282
-        * @param User   $user           Object user making delete
283
-        * @return int                   Return integer <0 if KO, >0 if OK
284
-        */
279
+     * Delete a language for this member type
280
+     *
281
+     * @param string $langtodelete   Language code to delete
282
+     * @param User   $user           Object user making delete
283
+     * @return int                   Return integer <0 if KO, >0 if OK
284
+     */
285 285
     public function delMultiLangs($langtodelete, $user)
286 286
     {
287 287
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "adherent_type_lang";
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
         }
533 533
     }
534 534
 
535
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
535
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
536 536
     /**
537 537
      *  Return list of members' type
538 538
      *
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
      */
542 542
     public function liste_array($status = -1)
543 543
     {
544
-		// phpcs:enable
544
+        // phpcs:enable
545 545
         global $langs;
546 546
 
547 547
         $adherenttypes = array();
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
         return $this->LibStatut($this->status, $mode);
785 785
     }
786 786
 
787
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
787
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
788 788
     /**
789 789
      *  Return the label of a given status
790 790
      *
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
      */
795 795
     public function LibStatut($status, $mode = 0)
796 796
     {
797
-		// phpcs:enable
797
+        // phpcs:enable
798 798
         global $langs;
799 799
         $langs->load('companies');
800 800
 
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
         return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
814 814
     }
815 815
 
816
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
817
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
816
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
817
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
818 818
     /**
819 819
      *  Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
820 820
      *
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
      */
827 827
     public function _load_ldap_dn($info, $mode = 0)
828 828
     {
829
-		// phpcs:enable
829
+        // phpcs:enable
830 830
         $dn = '';
831 831
         if ($mode == 0) {
832 832
             $dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=" . $info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')] . "," . getDolGlobalString('LDAP_MEMBER_TYPE_DN');
@@ -841,8 +841,8 @@  discard block
 block discarded – undo
841 841
     }
842 842
 
843 843
 
844
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
845
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
844
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
845
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
846 846
     /**
847 847
      *  Initialize the info array (array of LDAP values) that will be used to call LDAP functions
848 848
      *
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
      */
851 851
     public function _load_ldap_info()
852 852
     {
853
-		// phpcs:enable
853
+        // phpcs:enable
854 854
         $info = array();
855 855
 
856 856
         // Object classes
Please login to merge, or discard this patch.