From c0354c5e93902e07893a10415d3bd84cfc01ab37 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 10 Feb 2021 12:07:09 +0100 Subject: [PATCH 1/5] NEW Bank Entries : display user linked to salary and social taxes --- htdocs/compta/bank/bankentries_list.php | 44 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 7d059734126..bf307fd0bb8 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -373,6 +373,7 @@ $formaccounting = new FormAccounting($db); $companystatic = new Societe($db); $bankaccountstatic = new Account($db); +$userstatic= new User($db); $banktransferstatic = new BonPrelevement($db); $societestatic = new Societe($db); @@ -477,8 +478,9 @@ else $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro as conciliated, b.num_releve, b.num_chq,"; $sql .= " b.fk_account, b.fk_type,"; $sql .= " ba.rowid as bankid, ba.ref as bankref,"; -$sql .= " bu.url_id,"; -$sql .= " s.nom, s.name_alias, s.client, s.fournisseur, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur"; +$sql .= " bu.url_id, bu.type as type_url,"; +$sql .= " s.nom, s.name_alias, s.client, s.fournisseur, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; +$sql .= " u.lastname as user_lastname, u.firstname as user_firstname, u.email as user_email, u.statut as user_statut"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); @@ -492,8 +494,9 @@ if ($search_bid > 0) $sql .= MAIN_DB_PREFIX."bank_class as l,"; $sql .= " ".MAIN_DB_PREFIX."bank_account as ba,"; $sql .= " ".MAIN_DB_PREFIX."bank as b"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'company'"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND (type = 'company' OR type = 'user')"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid AND bu.type = 'company'"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON bu.url_id = u.rowid AND bu.type = 'user'"; $sql .= " WHERE b.fk_account = ba.rowid"; $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; if ($search_account > 0) $sql .= " AND b.fk_account = ".$search_account; @@ -1381,20 +1384,29 @@ if ($resql) // Third party if (!empty($arrayfields['bu.label']['checked'])) { - print ''; + print ''; if ($objp->url_id) { - $companystatic->id = $objp->url_id; - $companystatic->name = $objp->nom; - $companystatic->name_alias = $objp->name_alias; - $companystatic->client = $objp->client; - $companystatic->email = $objp->email; - $companystatic->fournisseur = $objp->fournisseur; - $companystatic->code_client = $objp->code_client; - $companystatic->code_fournisseur = $objp->code_fournisseur; - $companystatic->code_compta = $objp->code_compta; - $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; - print $companystatic->getNomUrl(1); + if($objp->type_url == 'company') { + $companystatic->id = $objp->url_id; + $companystatic->name = $objp->nom; + $companystatic->name_alias = $objp->name_alias; + $companystatic->client = $objp->client; + $companystatic->email = $objp->email; + $companystatic->fournisseur = $objp->fournisseur; + $companystatic->code_client = $objp->code_client; + $companystatic->code_fournisseur = $objp->code_fournisseur; + $companystatic->code_compta = $objp->code_compta; + $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; + print $companystatic->getNomUrl(1); + } elseif ($objp->type_url == 'user') { + $userstatic->id = $objp->url_id; + $userstatic->firstname = $objp->user_firstname; + $userstatic->name = $objp->user_lastname; + $userstatic->email = $objp->user_email; + $userstatic->statut = $objp->user_statut; + print $userstatic->getNomUrl(1); + } } else { From 64ab2fa3b1878df9e9656b38f31326d4c3b48015 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 10 Feb 2021 12:19:50 +0100 Subject: [PATCH 2/5] Bank Entries : add user search --- htdocs/compta/bank/bankentries_list.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index bf307fd0bb8..c10d0d05238 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -88,7 +88,7 @@ $search_dt_start = dol_mktime(0, 0, 0, GETPOST('search_start_dtmonth', 'int'), G $search_dt_end = dol_mktime(0, 0, 0, GETPOST('search_end_dtmonth', 'int'), GETPOST('search_end_dtday', 'int'), GETPOST('search_end_dtyear', 'int')); $search_dv_start = dol_mktime(0, 0, 0, GETPOST('search_start_dvmonth', 'int'), GETPOST('search_start_dvday', 'int'), GETPOST('search_start_dvyear', 'int')); $search_dv_end = dol_mktime(0, 0, 0, GETPOST('search_end_dvmonth', 'int'), GETPOST('search_end_dvday', 'int'), GETPOST('search_end_dvyear', 'int')); -$search_thirdparty = GETPOST("search_thirdparty", 'alpha') ?GETPOST("search_thirdparty", 'alpha') : GETPOST("thirdparty", 'alpha'); +$search_thirdparty_user = GETPOST("search_thirdparty", 'alpha') ?GETPOST("search_thirdparty", 'alpha') : GETPOST("thirdparty", 'alpha'); $search_req_nb = GETPOST("req_nb", 'alpha'); $search_num_releve = GETPOST("search_num_releve", 'alpha'); $search_conciliated = GETPOST("search_conciliated", 'int'); @@ -145,7 +145,7 @@ $arrayfields = array( 'b.datev'=>array('label'=>$langs->trans("DateValueShort"), 'checked'=>1), 'type'=>array('label'=>$langs->trans("Type"), 'checked'=>1), 'b.num_chq'=>array('label'=>$langs->trans("Numero"), 'checked'=>1), - 'bu.label'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>500), + 'bu.label'=>array('label'=>$langs->trans("ThirdParty").'/'.$langs->trans("User"), 'checked'=>1, 'position'=>500), 'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>(($id > 0 || !empty($ref)) ? 0 : 1), 'position'=>1000), 'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600), 'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605), @@ -194,7 +194,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_ref = ""; $search_req_nb = ''; $search_description = ''; - $search_thirdparty = ''; + $search_thirdparty_user = ''; $search_num_releve = ''; $search_conciliated = ''; $thirdparty = ''; @@ -262,7 +262,7 @@ if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', ' $param .= '&search_conciliated='.urlencode($search_conciliated); if ($page) $param .= '&page='.urlencode($page); if ($offset) $param .= '&offset='.urlencode($offset); - if ($search_thirdparty) $param .= '&search_thirdparty='.urlencode($search_thirdparty); + if ($search_thirdparty_user) $param .= '&search_thirdparty='.urlencode($search_thirdparty_user); if ($search_num_releve) $param .= '&search_num_releve='.urlencode($search_num_releve); if ($search_description) $param .= '&search_description='.urlencode($search_description); if ($search_start_dt) $param .= '&search_start_dt='.urlencode($search_start_dt); @@ -403,7 +403,7 @@ if (!empty($ref)) $param .= '&ref='.urlencode($ref); if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref); if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description); if (!empty($search_type)) $param .= '&type='.urlencode($search_type); -if (!empty($search_thirdparty)) $param .= '&search_thirdparty='.urlencode($search_thirdparty); +if (!empty($search_thirdparty_user)) $param .= '&search_thirdparty='.urlencode($search_thirdparty_user); if (!empty($search_debit)) $param .= '&search_debit='.urlencode($search_debit); if (!empty($search_credit)) $param .= '&search_credit='.urlencode($search_credit); if (!empty($search_account)) $param .= '&search_account='.urlencode($search_account); @@ -510,7 +510,7 @@ if ($search_ref) $sql .= natural_search("b.rowid", $search_ref, 1); if ($search_req_nb) $sql .= natural_search("b.num_chq", $search_req_nb); if ($search_num_releve) $sql .= natural_search("b.num_releve", $search_num_releve); if ($search_conciliated != '' && $search_conciliated != '-1') $sql .= " AND b.rappro = ".$search_conciliated; -if ($search_thirdparty) $sql .= natural_search("s.nom", $search_thirdparty); +if ($search_thirdparty_user) $sql .= natural_search(array("s.nom", "u.firstname", "u.lastname"), $search_thirdparty_user); if ($search_description) { $search_description_to_use = $search_description; @@ -585,7 +585,7 @@ if (!empty($search_description)) $mode_balance_ok = false; if (!empty($search_type)) $mode_balance_ok = false; if (!empty($search_debit)) $mode_balance_ok = false; if (!empty($search_credit)) $mode_balance_ok = false; -if (!empty($search_thirdparty)) $mode_balance_ok = false; +if (!empty($search_thirdparty_user)) $mode_balance_ok = false; if ($search_conciliated != '' && $search_conciliated != '-1') $mode_balance_ok = false; if (!empty($search_num_releve)) $mode_balance_ok = false; @@ -917,7 +917,7 @@ if ($resql) } if (!empty($arrayfields['bu.label']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['ba.ref']['checked'])) { From 8f8f5058ded05ee8c7c87b82ce3a8f3fc91c8ff0 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 10 Feb 2021 16:04:29 +0100 Subject: [PATCH 3/5] Add link 'user' in bank_url for payment_sc --- .../class/paymentsocialcontribution.class.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index c771a664d5f..3814a016b0c 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -514,7 +514,7 @@ class PaymentSocialContribution extends CommonObject */ public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) { - global $conf; + global $conf, $langs; // Clean data $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement); @@ -578,6 +578,24 @@ class PaymentSocialContribution extends CommonObject $socialcontrib->fetch($key); $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc'); if ($result <= 0) dol_print_error($this->db); + + $fuser = new User($this->db); + $fuser->fetch($socialcontrib->fk_user); + + // Add link 'user' in bank_url between operation and bank transaction + $result = $acc->add_url_line( + $bank_line_id, + $socialcontrib->fk_user, + DOL_URL_ROOT.'/user/card.php?id=', + $fuser->getFullName($langs), + 'user' + ); + + if ($result <= 0) + { + $this->error = $acc->error; + $error++; + } } } } From 3aef987f3fd26b935738ed14e92e9397719c8663 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 10 Feb 2021 16:24:45 +0100 Subject: [PATCH 4/5] Display or not users in terms of user rights --- htdocs/compta/bank/bankentries_list.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index c10d0d05238..aadc0d01d80 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -1384,6 +1384,12 @@ if ($resql) // Third party if (!empty($arrayfields['bu.label']['checked'])) { + //payment line type to define user display + foreach($links as $key=>$value){ + if($links[$key]['type'] == 'payment_sc') $type_link = 'payment_sc'; + if($links[$key]['type'] == 'payment_salary') $type_link = 'payment_salary'; + } + print ''; if ($objp->url_id) { @@ -1399,7 +1405,10 @@ if ($resql) $companystatic->code_compta = $objp->code_compta; $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; print $companystatic->getNomUrl(1); - } elseif ($objp->type_url == 'user') { + } elseif ($objp->type_url == 'user' && + (($type_link == 'payment_salary' && !empty($user->rights->salaries->read)) + || ($type_link == 'payment_sc' && !empty($user->rights->tax->charges->lire))) + ) { $userstatic->id = $objp->url_id; $userstatic->firstname = $objp->user_firstname; $userstatic->name = $objp->user_lastname; From 2e14b9832d34fa98bbc43a85ca77af07eda341c3 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 10 Feb 2021 17:00:50 +0100 Subject: [PATCH 5/5] Clean code --- htdocs/compta/bank/bankentries_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index aadc0d01d80..7fa2032cd3d 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -1010,6 +1010,7 @@ if ($resql) while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); + $links = $bankaccountstatic->get_url($objp->rowid); // If we are in a situation where we need/can show balance, we calculate the start of balance if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && $mode_balance_ok) @@ -1200,7 +1201,6 @@ if ($resql) //print " "; // Add links after description - $links = $bankaccountstatic->get_url($objp->rowid); $cachebankaccount = array(); foreach ($links as $key=>$val) {