Passed
Pull Request — dev (#6)
by Rafael
79:24 queued 24:08
created
Dolibarr/Modules/Contrat.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -248,8 +248,8 @@
 block discarded – undo
248 248
         }
249 249
 
250 250
         $sql = array(
251
-            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[1][2]) . "' AND type = 'contract' AND entity = " . ((int)$conf->entity),
252
-            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[1][2]) . "', 'contract', " . ((int)$conf->entity) . ")"
251
+            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[1][2]) . "' AND type = 'contract' AND entity = " . ((int) $conf->entity),
252
+            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[1][2]) . "', 'contract', " . ((int) $conf->entity) . ")"
253 253
         );
254 254
 
255 255
         return $this->_init($sql, $options);
Please login to merge, or discard this patch.
Dolibarr/Modules/MultiCurrency.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@
 block discarded – undo
163 163
                 'priority' => 61,
164 164
                 'label' => 'MutltiCurrencyAutoUpdateCurrencies',
165 165
                 'jobtype' => 'method',
166
-                'class' => 'multicurrency/class/multicurrency.class.php',   // TODO: Review. Is correct? The file no longer exists!
166
+                'class' => 'multicurrency/class/multicurrency.class.php', // TODO: Review. Is correct? The file no longer exists!
167 167
                 'objectname' => 'MultiCurrency',
168 168
                 'method' => 'syncRates',
169 169
                 'parameters' => '0,0,cron',
Please login to merge, or discard this patch.
Dolibarr/Modules/Facture.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
         $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object';
657 657
         $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on (fd.fk_product = p.rowid)';
658 658
         if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
659
-            $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)$conf->entity);
659
+            $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
660 660
         }
661 661
         $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_extrafields as extra3 on p.rowid = extra3.fk_object';
662 662
         $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'accounting_account as aa on fd.fk_code_ventilation = aa.rowid';
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
         }
794 794
 
795 795
         $sql = array(
796
-            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[1][2]) . "' AND type = 'invoice' AND entity = " . ((int)$conf->entity),
797
-            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[1][2]) . "','invoice'," . ((int)$conf->entity) . ")"
796
+            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[1][2]) . "' AND type = 'invoice' AND entity = " . ((int) $conf->entity),
797
+            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[1][2]) . "','invoice'," . ((int) $conf->entity) . ")"
798 798
         );
799 799
 
800 800
         return $this->_init($sql, $options);
Please login to merge, or discard this patch.
Dolibarr/Modules/ExpenseReport.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -266,8 +266,8 @@
 block discarded – undo
266 266
         $this->remove($options);
267 267
 
268 268
         $sql = array(
269
-            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'standard' AND type='expensereport' AND entity = " . ((int)$conf->entity),
270
-            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('standard','expensereport'," . ((int)$conf->entity) . ")"
269
+            "DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'standard' AND type='expensereport' AND entity = " . ((int) $conf->entity),
270
+            "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('standard','expensereport'," . ((int) $conf->entity) . ")"
271 271
         );
272 272
 
273 273
         return $this->_init($sql, $options);
Please login to merge, or discard this patch.
Dolibarr/Code/MultiCurrency/Classes/MultiCurrency.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     {
125 125
         global $conf;
126 126
 
127
-        $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "multicurrency WHERE code = '" . $dbs->escape($code) . "' AND entity = " . ((int)$conf->entity);
127
+        $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "multicurrency WHERE code = '" . $dbs->escape($code) . "' AND entity = " . ((int) $conf->entity);
128 128
 
129 129
         dol_syslog(__METHOD__, LOG_DEBUG);
130 130
         $resql = $dbs->query($sql);
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 
199 199
         if ($multicurrency_tx) {
200 200
             if ($way == 'dolibarr') {
201
-                return (float)price2num($amount * $multicurrency_tx, 'MU');
201
+                return (float) price2num($amount * $multicurrency_tx, 'MU');
202 202
             } else {
203
-                return (float)price2num($amount / $multicurrency_tx, 'MU');
203
+                return (float) price2num($amount / $multicurrency_tx, 'MU');
204 204
             }
205 205
         } else {
206 206
             return false;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     {
219 219
         global $db;
220 220
 
221
-        $sql = "SELECT multicurrency_tx FROM " . MAIN_DB_PREFIX . $table . " WHERE rowid = " . ((int)$fk_facture);
221
+        $sql = "SELECT multicurrency_tx FROM " . MAIN_DB_PREFIX . $table . " WHERE rowid = " . ((int) $fk_facture);
222 222
 
223 223
         dol_syslog(__METHOD__, LOG_DEBUG);
224 224
         $resql = $db->query($sql);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . " SET";
259 259
         $sql .= " name = '" . $this->db->escape($this->name) . "',";
260 260
         $sql .= " code = '" . $this->db->escape($this->code) . "'";
261
-        $sql .= " WHERE rowid = " . ((int)$this->id);
261
+        $sql .= " WHERE rowid = " . ((int) $this->id);
262 262
 
263 263
         $this->db->begin();
264 264
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             }
320 320
 
321 321
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element;
322
-            $sql .= " WHERE rowid = " . ((int)$this->id);
322
+            $sql .= " WHERE rowid = " . ((int) $this->id);
323 323
 
324 324
             dol_syslog(__METHOD__, LOG_DEBUG);
325 325
             $resql = $this->db->query($sql);
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         if (!empty($code)) {
480 480
             $sql .= ' WHERE c.code = \'' . $this->db->escape($code) . '\' AND c.entity = ' . $conf->entity;
481 481
         } else {
482
-            $sql .= ' WHERE c.rowid = ' . ((int)$id);
482
+            $sql .= ' WHERE c.rowid = ' . ((int) $id);
483 483
         }
484 484
 
485 485
         dol_syslog(__METHOD__, LOG_DEBUG);
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
     {
525 525
         $sql = "SELECT cr.rowid";
526 526
         $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line . ' as cr';
527
-        $sql .= ' WHERE cr.fk_multicurrency = ' . ((int)$this->id);
527
+        $sql .= ' WHERE cr.fk_multicurrency = ' . ((int) $this->id);
528 528
         $sql .= ' ORDER BY cr.date_sync DESC';
529 529
 
530 530
         $this->rates = array();
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
     {
561 561
         $sql = "SELECT cr.rowid";
562 562
         $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element_line . " as cr";
563
-        $sql .= " WHERE cr.fk_multicurrency = " . ((int)$this->id);
564
-        $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM " . MAIN_DB_PREFIX . $this->table_element_line . " AS cr2 WHERE cr2.fk_multicurrency = " . ((int)$this->id) . ")";
563
+        $sql .= " WHERE cr.fk_multicurrency = " . ((int) $this->id);
564
+        $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM " . MAIN_DB_PREFIX . $this->table_element_line . " AS cr2 WHERE cr2.fk_multicurrency = " . ((int) $this->id) . ")";
565 565
 
566 566
         dol_syslog(__METHOD__, LOG_DEBUG);
567 567
         $resql = $this->db->query($sql);
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         global $user;
596 596
 
597 597
         $currencyRate = new CurrencyRate($this->db);
598
-        $currencyRate->rate = (float)price2num($rate);
598
+        $currencyRate->rate = (float) price2num($rate);
599 599
 
600 600
         if ($currencyRate->create($user, $this->id) > 0) {
601 601
             $this->rate = $currencyRate;
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
         $sql .= ') VALUES (';
644 644
         $sql .= " '" . $this->db->escape($this->code) . "',";
645 645
         $sql .= " '" . $this->db->escape($this->name) . "',";
646
-        $sql .= " " . ((int)$this->entity) . ",";
646
+        $sql .= " " . ((int) $this->entity) . ",";
647 647
         $sql .= " '" . $this->db->idate($now) . "',";
648
-        $sql .= " " . ((int)$user->id);
648
+        $sql .= " " . ((int) $user->id);
649 649
         $sql .= ')';
650 650
 
651 651
         $this->db->begin();
Please login to merge, or discard this patch.
Dolibarr/Core/Base/DolibarrModules.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         $sql_del = "SELECT " . $this->db->decrypt('value') . " as value";
532 532
         $sql_del .= " FROM " . MAIN_DB_PREFIX . "const";
533 533
         $sql_del .= " WHERE " . $this->db->decrypt('name') . " = '" . $this->db->escape($this->const_name) . "'";
534
-        $sql_del .= " AND entity IN (0," . ((int)$entity) . ")";
534
+        $sql_del .= " AND entity IN (0," . ((int) $entity) . ")";
535 535
 
536 536
         $resql = $this->db->query($sql_del);
537 537
 
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
 
555 555
                 // If the module is active
556 556
                 foreach ($this->rights as $key => $value) {
557
-                    $r_id = $this->rights[$key][self::KEY_ID];  // permission id in llx_rights_def (not unique because primary key is couple id-entity)
557
+                    $r_id = $this->rights[$key][self::KEY_ID]; // permission id in llx_rights_def (not unique because primary key is couple id-entity)
558 558
                     $r_label = $this->rights[$key][self::KEY_LABEL];
559
-                    $r_type = $this->rights[$key][self::KEY_TYPE] ?? 'w';   // TODO deprecated
559
+                    $r_type = $this->rights[$key][self::KEY_TYPE] ?? 'w'; // TODO deprecated
560 560
                     $r_default = $this->rights[$key][self::KEY_DEFAULT] ?? 0;
561 561
                     $r_perms = $this->rights[$key][self::KEY_FIRST_LEVEL] ?? '';
562 562
                     $r_subperms = $this->rights[$key][self::KEY_SECOND_LEVEL] ?? '';
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
 
585 585
                     // Search if perm already present
586 586
                     $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "rights_def";
587
-                    $sql .= " WHERE entity = " . ((int)$entity);
588
-                    $sql .= " AND id = " . ((int)$r_id);
587
+                    $sql .= " WHERE entity = " . ((int) $entity);
588
+                    $sql .= " AND id = " . ((int) $r_id);
589 589
 
590 590
                     $resqlselect = $this->db->query($sql);
591 591
                     if ($resqlselect) {
@@ -597,19 +597,19 @@  discard block
 block discarded – undo
597 597
                             $sql .= ", libelle";
598 598
                             $sql .= ", module";
599 599
                             $sql .= ", module_origin";
600
-                            $sql .= ", type";   // TODO deprecated
600
+                            $sql .= ", type"; // TODO deprecated
601 601
                             $sql .= ", bydefault";
602 602
                             $sql .= ", perms";
603 603
                             $sql .= ", subperms";
604 604
                             $sql .= ", enabled";
605 605
                             $sql .= ") VALUES (";
606
-                            $sql .= ((int)$r_id);
607
-                            $sql .= ", " . ((int)$entity);
606
+                            $sql .= ((int) $r_id);
607
+                            $sql .= ", " . ((int) $entity);
608 608
                             $sql .= ", '" . $this->db->escape($r_label) . "'";
609 609
                             $sql .= ", '" . $this->db->escape($r_module) . "'";
610 610
                             $sql .= ", '" . $this->db->escape($r_module_origin) . "'";
611
-                            $sql .= ", '" . $this->db->escape($r_type) . "'";   // TODO deprecated
612
-                            $sql .= ", " . ((int)$r_default);
611
+                            $sql .= ", '" . $this->db->escape($r_type) . "'"; // TODO deprecated
612
+                            $sql .= ", " . ((int) $r_default);
613 613
                             $sql .= ", '" . $this->db->escape($r_perms) . "'";
614 614
                             $sql .= ", '" . $this->db->escape($r_subperms) . "'";
615 615
                             $sql .= ", '" . $this->db->escape($r_enabled) . "'";
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
         }
852 852
 
853 853
         // Run complementary sql requests
854
-        $num = count((array)$array_sql);
854
+        $num = count((array) $array_sql);
855 855
         for ($i = 0; $i < $num; $i++) {
856 856
             if (!$err) {
857 857
                 dol_syslog(get_class($this) . "::_remove", LOG_DEBUG);
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
                 $moduleNameInConf = 'supplier_proposal';
877 877
             }
878 878
 
879
-            unset($conf->modules[$moduleNameInConf]);   // Add this module in list of enabled modules so isModEnabled() will work (conf->module->enabled must no more be used)
879
+            unset($conf->modules[$moduleNameInConf]); // Add this module in list of enabled modules so isModEnabled() will work (conf->module->enabled must no more be used)
880 880
 
881 881
             return 1;
882 882
         } else {
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 
965 965
                 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "const";
966 966
                 $sql .= " WHERE " . $this->db->decrypt('name') . " LIKE '" . $this->db->escape($this->const_name) . "_" . strtoupper($key) . "'";
967
-                $sql .= " AND entity = " . ((int)$entity);
967
+                $sql .= " AND entity = " . ((int) $entity);
968 968
 
969 969
                 if (!$this->db->query($sql)) {
970 970
                     $this->error = $this->db->lasterror();
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
 
1070 1070
                 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "boxes_def";
1071 1071
                 $sql .= " WHERE file = '" . $this->db->escape($file) . "'";
1072
-                $sql .= " AND entity = " . $conf->entity;     // Do not use getEntity here, we want to delete only in current company
1072
+                $sql .= " AND entity = " . $conf->entity; // Do not use getEntity here, we want to delete only in current company
1073 1073
 
1074 1074
                 dol_syslog(get_class($this) . "::delete_boxes", LOG_DEBUG);
1075 1075
                 $resql = $this->db->query($sql);
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 
1133 1133
         // Delete all entities if core module
1134 1134
         if (empty($this->core_enabled)) {
1135
-            $sql .= " AND entity = " . ((int)$conf->entity);
1135
+            $sql .= " AND entity = " . ((int) $conf->entity);
1136 1136
         }
1137 1137
 
1138 1138
         dol_syslog(get_class($this) . "::delete_permissions", LOG_DEBUG);
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 
1162 1162
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "menu";
1163 1163
         $sql .= " WHERE module = '" . $this->db->escape($module) . "'";
1164
-        $sql .= " AND menu_handler = 'all'";    // We delete only lines that were added manually or by the module activation. We keep entry added by menuhandler like 'auguria'
1164
+        $sql .= " AND menu_handler = 'all'"; // We delete only lines that were added manually or by the module activation. We keep entry added by menuhandler like 'auguria'
1165 1165
         $sql .= " AND entity IN (0, " . $conf->entity . ")";
1166 1166
 
1167 1167
         dol_syslog(get_class($this) . "::delete_menus", LOG_DEBUG);
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
         if ($pathoffile) {     // Mostly for external modules
1220 1220
             $content = file_get_contents($pathoffile, false, null, 0, 1024 * 1024); // Max size loaded 1Mb
1221 1221
 
1222
-            if ((float)DOL_VERSION >= 6.0) {
1222
+            if ((float) DOL_VERSION >= 6.0) {
1223 1223
                 @include_once DOL_DOCUMENT_ROOT . '/core/lib/parsemd.lib.php';
1224 1224
 
1225 1225
                 $content = dolMd2Html(
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
         if ($filefound) {     // Mostly for external modules
1320 1320
             $content = file_get_contents($pathoffile);
1321 1321
 
1322
-            if ((float)DOL_VERSION >= 6.0) {
1322
+            if ((float) DOL_VERSION >= 6.0) {
1323 1323
                 @include_once DOL_DOCUMENT_ROOT . '/core/lib/parsemd.lib.php';
1324 1324
 
1325 1325
                 $content = dolMd2Html($content, 'parsedown', array('doc/' => dol_buildpath(strtolower($this->name) . '/doc/', 1)));
@@ -1458,7 +1458,7 @@  discard block
 block discarded – undo
1458 1458
 
1459 1459
         $sql = "SELECT tms FROM " . MAIN_DB_PREFIX . "const";
1460 1460
         $sql .= " WHERE " . $this->db->decrypt('name') . " = '" . $this->db->escape($this->const_name) . "'";
1461
-        $sql .= " AND entity IN (0, " . ((int)$conf->entity) . ")";
1461
+        $sql .= " AND entity IN (0, " . ((int) $conf->entity) . ")";
1462 1462
 
1463 1463
         dol_syslog(get_class($this) . "::getLastActiveDate", LOG_DEBUG);
1464 1464
         $resql = $this->db->query($sql);
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
                     $ignoreerror = $val['ignoreerror'];
1608 1608
                 }
1609 1609
                 // Add current entity id
1610
-                $sql = str_replace('__ENTITY__', (string)$conf->entity, $sql);
1610
+                $sql = str_replace('__ENTITY__', (string) $conf->entity, $sql);
1611 1611
 
1612 1612
                 dol_syslog(get_class($this) . "::_init ignoreerror=" . $ignoreerror, LOG_DEBUG);
1613 1613
                 $result = $this->db->query($sql, $ignoreerror);
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "const (name, value, visible, entity, note) VALUES";
1682 1682
         $sql .= " (" . $this->db->encrypt($this->const_name);
1683 1683
         $sql .= ", " . $this->db->encrypt('1');
1684
-        $sql .= ", 0, " . ((int)$entity);
1684
+        $sql .= ", 0, " . ((int) $entity);
1685 1685
         $sql .= ", '" . $this->db->escape($note) . "')";
1686 1686
 
1687 1687
         dol_syslog(get_class($this) . "::_active insert activation constant", LOG_DEBUG);
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
                     $sql .= ", " . $this->db->encrypt($newvalue);
1742 1742
                     $sql .= ", null";
1743 1743
                     $sql .= ", '0'";
1744
-                    $sql .= ", " . ((int)$entity);
1744
+                    $sql .= ", " . ((int) $entity);
1745 1745
                     $sql .= ")";
1746 1746
 
1747 1747
                     $resql = $this->db->query($sql);
@@ -1857,7 +1857,7 @@  discard block
 block discarded – undo
1857 1857
                     $sql .= ", " . $this->db->encrypt($newvalue, 1);
1858 1858
                     $sql .= ", null";
1859 1859
                     $sql .= ", '0'";
1860
-                    $sql .= ", " . ((int)$entity);
1860
+                    $sql .= ", " . ((int) $entity);
1861 1861
                     $sql .= ")";
1862 1862
 
1863 1863
                     dol_syslog(get_class($this) . "::insert_module_parts for key=" . $this->const_name . "_" . strtoupper($key), LOG_DEBUG);
@@ -1917,7 +1917,7 @@  discard block
 block discarded – undo
1917 1917
             $sql = "SELECT count(*) as nb";
1918 1918
             $sql .= " FROM " . MAIN_DB_PREFIX . "const";
1919 1919
             $sql .= " WHERE " . $this->db->decrypt('name') . " = '" . $this->db->escape($name) . "'";
1920
-            $sql .= " AND entity = " . ((int)$entity);
1920
+            $sql .= " AND entity = " . ((int) $entity);
1921 1921
 
1922 1922
             $result = $this->db->query($sql);
1923 1923
             if ($result) {
@@ -2021,7 +2021,7 @@  discard block
 block discarded – undo
2021 2021
                                 }
2022 2022
 
2023 2023
                                 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes (box_id, position, box_order, fk_user, entity)";
2024
-                                $sql .= " VALUES (" . ((int)$lastid) . ", " . ((int)$key2) . ", '0', 0, " . ((int)$conf->entity) . ")";
2024
+                                $sql .= " VALUES (" . ((int) $lastid) . ", " . ((int) $key2) . ", '0', 0, " . ((int) $conf->entity) . ")";
2025 2025
 
2026 2026
                                 dol_syslog(get_class($this) . "::insert_boxes onto page " . $key2 . "=" . $val2, LOG_DEBUG);
2027 2027
                                 $resql = $this->db->query($sql);
@@ -2105,7 +2105,7 @@  discard block
 block discarded – undo
2105 2105
                 if ($parameters) {
2106 2106
                     $sql .= " AND params = '".$this->db->escape($parameters)."'";
2107 2107
                 }*/
2108
-                $sql .= " AND entity = " . ((int)$entity); // Must be exact entity
2108
+                $sql .= " AND entity = " . ((int) $entity); // Must be exact entity
2109 2109
 
2110 2110
                 $now = dol_now();
2111 2111
 
@@ -2153,7 +2153,7 @@  discard block
 block discarded – undo
2153 2153
                                 $sql .= "'" . $this->db->escape($priority) . "', ";
2154 2154
                             }
2155 2155
                             if (is_int($status)) {
2156
-                                $sql .= ((int)$status) . ", ";
2156
+                                $sql .= ((int) $status) . ", ";
2157 2157
                             }
2158 2158
                             $sql .= $entity . ",";
2159 2159
                             $sql .= "'" . $this->db->escape($test) . "'";
@@ -2381,7 +2381,7 @@  discard block
 block discarded – undo
2381 2381
 
2382 2382
             if ($row[0] == 0) {
2383 2383
                 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "const (name, type, value, note, visible, entity)";
2384
-                $sql .= " VALUES (" . $this->db->encrypt($name) . ", 'chaine', " . $this->db->encrypt($dir) . ", '" . $this->db->escape("Directory for module " . $this->name) . "', '0', " . ((int)$conf->entity) . ")";
2384
+                $sql .= " VALUES (" . $this->db->encrypt($name) . ", 'chaine', " . $this->db->encrypt($dir) . ", '" . $this->db->escape("Directory for module " . $this->name) . "', '0', " . ((int) $conf->entity) . ")";
2385 2385
 
2386 2386
                 dol_syslog(get_class($this) . "::insert_dirs", LOG_DEBUG);
2387 2387
                 $this->db->query($sql);
@@ -2467,7 +2467,7 @@  discard block
 block discarded – undo
2467 2467
 
2468 2468
         $return .= '<div class="valignmiddle inline-block info-box-more">';
2469 2469
         //if ($versiontrans) print img_warning($langs->trans("Version").' '.$this->getVersion(1)).' ';
2470
-        $return .= '<a class="valignmiddle inline-block" href="javascript:document_preview(\'' . constant('BASE_URL') . '/admin/modulehelp.php?id=' . ((int)$this->numero) . '\',\'text/html\',\'' . dol_escape_js($langs->trans("Module")) . '\')">' . img_picto(($this->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule") . ' - ' : '') . $langs->trans("ClickToShowDescription"), $imginfo) . '</a>';
2470
+        $return .= '<a class="valignmiddle inline-block" href="javascript:document_preview(\'' . constant('BASE_URL') . '/admin/modulehelp.php?id=' . ((int) $this->numero) . '\',\'text/html\',\'' . dol_escape_js($langs->trans("Module")) . '\')">' . img_picto(($this->isCoreOrExternalModule() == 'external' ? $langs->trans("ExternalModule") . ' - ' : '') . $langs->trans("ClickToShowDescription"), $imginfo) . '</a>';
2471 2471
         $return .= '</div><br>';
2472 2472
 
2473 2473
         $return .= '<div class="valignmiddle inline-block info-box-actions">';
@@ -2623,7 +2623,7 @@  discard block
 block discarded – undo
2623 2623
     {
2624 2624
         require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/geturl.lib.php';
2625 2625
         if (!empty($this->url_last_version)) {
2626
-            $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0);    // Accept http or https links on external remote server only
2626
+            $lastVersion = getURLContent($this->url_last_version, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only
2627 2627
             if (isset($lastVersion['content']) && strlen($lastVersion['content']) < 30) {
2628 2628
                 // Security warning :  be careful with remote data content, the module editor could be hacked (or evil) so limit to a-z A-Z 0-9 _ . -
2629 2629
                 $this->lastVersion = preg_replace("/[^a-zA-Z0-9_\.\-]+/", "", $lastVersion['content']);
Please login to merge, or discard this patch.
Dolibarr/Core/Trait/DolDeprecationHandler.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
             return $this->$newProperty;
61 61
         }
62 62
         if ($this->isDynamicPropertiesEnabled()) {
63
-            return null;  // If the property is set, then __get is not called.
63
+            return null; // If the property is set, then __get is not called.
64 64
         }
65 65
         $msg = "DolDeprecationHandler: Undefined property '" . $name . "'" . self::getCallerInfoString();
66 66
         dol_syslog($msg);
67 67
         trigger_error($msg, E_USER_NOTICE);
68
-        return $this->$name;  // Returning value anyway (graceful degradation)
68
+        return $this->$name; // Returning value anyway (graceful degradation)
69 69
     }
70 70
 
71 71
     /**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         if (!$this->isDynamicPropertiesEnabled()) {
96 96
             $msg = "DolDeprecationHandler: Undefined property '" . $name . "'" . self::getCallerInfoString();
97 97
             trigger_error($msg, E_USER_NOTICE);
98
-            $this->$name = $value;  // Setting anyway for graceful degradation
98
+            $this->$name = $value; // Setting anyway for graceful degradation
99 99
         } else {
100 100
             $this->$name = $value;
101 101
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
         if (property_exists($this, 'enableDeprecatedReporting')) {
194 194
             // If the property exists, then we use it.
195
-            return (bool)$this->enableDeprecatedReporting;
195
+            return (bool) $this->enableDeprecatedReporting;
196 196
         }
197 197
 
198 198
         return (error_reporting() & E_DEPRECATED) === E_DEPRECATED;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
         if (property_exists($this, 'enableDynamicProperties')) {
211 211
             // If the property exists, then we use it.
212
-            return (bool)$this->enableDynamicProperties;
212
+            return (bool) $this->enableDynamicProperties;
213 213
         }
214 214
 
215 215
         // Otherwise it depends on a choice
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/Contrat/Classes/ContratLigne.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         return $this->LibStatut($this->statut, $mode, ((!empty($this->date_end)) ? ($this->date_end < dol_now() ? 1 : 0) : -1));
261 261
     }
262 262
 
263
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
263
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
264 264
     /**
265 265
      *  Return label of a contract line status
266 266
      *
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      */
274 274
     public static function LibStatut($status, $mode, $expired = -1, $moreatt = '', $morelabel = '')
275 275
     {
276
-		// phpcs:enable
276
+        // phpcs:enable
277 277
         global $langs;
278 278
         $langs->load("contracts");
279 279
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     }
710 710
 
711 711
 
712
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
712
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
713 713
     /**
714 714
      *  Update in database the fields total_xxx of lines
715 715
      *  Used by migration process
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
      */
719 719
     public function update_total()
720 720
     {
721
-		// phpcs:enable
721
+        // phpcs:enable
722 722
         $this->db->begin();
723 723
 
724 724
         // Mise a jour ligne en base
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
         }
837 837
     }
838 838
 
839
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840 840
     /**
841 841
      *  Activate a contract line
842 842
      *
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
      */
849 849
     public function active_line($user, $date, $date_end = '', $comment = '')
850 850
     {
851
-		// phpcs:enable
851
+        // phpcs:enable
852 852
         $error = 0;
853 853
 
854 854
         $this->db->begin();
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
         }
895 895
     }
896 896
 
897
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
898 898
     /**
899 899
      *  Close a contract line
900 900
      *
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
      */
907 907
     public function close_line($user, $date_end_real, $comment = '', $notrigger = 0)
908 908
     {
909
-		// phpcs:enable
909
+        // phpcs:enable
910 910
         $this->date_cloture = $date_end_real;
911 911
         $this->date_end_real = $date_end_real;
912 912
         $this->user_closing_id = $user->id;
Please login to merge, or discard this patch.