From 17ebdd73fea435ec8a6286b06be439fc28d3232f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Jul 2020 05:13:24 +0200 Subject: [PATCH] FIX Fails to retraive accounting code of social contribution sometimes --- htdocs/accountancy/journal/bankjournal.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 07614dcc618..d1b986d4ea6 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -254,6 +254,8 @@ if ($result) { } else { $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60); } + + // Load of url links to the line into llx_bank $links = $object->get_url($obj->rowid); // Get an array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) //var_dump($i); @@ -319,6 +321,7 @@ if ($result) { $chargestatic->ref = $links[$key]['url_id']; $tabpay[$obj->rowid]["lib"] .= ' '.$chargestatic->getNomUrl(2); + $reg = array(); if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) { if ($reg[1] == 'socialcontribution') $reg[1] = 'SocialContribution'; @@ -330,11 +333,13 @@ if ($result) { $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30); $tabpay[$obj->rowid]["paymentscid"] = $chargestatic->id; + // Retreive the accounting code of the social contribution of the payment from link of payment. + // Note: We have the social contribution id, it can be faster to get accounting code from social contribution id. $sqlmid = 'SELECT cchgsoc.accountancy_code'; $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc "; $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; - $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; + $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'"; $sqlmid .= " WHERE bkurl.fk_bank=".$obj->rowid; dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=".$sqlmid, LOG_DEBUG);