* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015-2016 Marcos GarcĂ­a * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/user/bank.php * \ingroup HRM * \brief Tab for HRM */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php'; if (! empty($conf->holiday->enabled)) require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; if (! empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; // Load translation files required by page $langs->loadLangs(array('companies', 'commercial', 'banks', 'bills', 'trips', 'holiday', 'salaries')); $id = GETPOST('id', 'int'); $bankid = GETPOST('bankid', 'int'); $action = GETPOST("action", 'alpha'); $cancel = GETPOST('cancel', 'alpha'); // Security check $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; $feature2 = (($socid && $user->rights->user->self->creer)?'':'user'); // Ok if user->rights->salaries->read or user->rights->hrm->read //$result = restrictedArea($user, 'salaries|hrm', $id, 'user&user', $feature2); $ok=false; if ($user->id == $id) $ok=true; // A user can always read its own card if (! empty($user->rights->salaries->read)) $ok=true; if (! empty($user->rights->hrm->read)) $ok=true; if (! $ok) { accessforbidden(); } $object = new User($db); if ($id > 0 || ! empty($ref)) { $result = $object->fetch($id, $ref, '', 1); $object->getrights(); } /* * Actions */ if ($action == 'add' && ! $cancel) { // Modification $account = new UserBankAccount($db); $account->userid = $object->id; $account->bank = GETPOST('bank', 'alpha'); $account->label = GETPOST('label', 'alpha'); $account->courant = GETPOST('courant', 'alpha'); $account->code_banque = GETPOST('code_banque', 'alpha'); $account->code_guichet = GETPOST('code_guichet', 'alpha'); $account->number = GETPOST('number', 'alpha'); $account->cle_rib = GETPOST('cle_rib', 'alpha'); $account->bic = GETPOST('bic', 'alpha'); $account->iban = GETPOST('iban', 'alpha'); $account->domiciliation = GETPOST('domiciliation', 'alpha'); $account->proprio = GETPOST('proprio', 'alpha'); $account->owner_address = GETPOST('owner_address', 'alpha'); $result = $account->create($user); if (! $result) { setEventMessages($account->error, $account->errors, 'errors'); $action='edit'; // Force chargement page edition } else { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); $action = ''; } } if ($action == 'update' && ! $cancel) { // Modification $account = new UserBankAccount($db); $account->fetch($bankid); $account->userid = $object->id; $account->bank = GETPOST('bank', 'alpha'); $account->label = GETPOST('label', 'alpha'); $account->courant = GETPOST('courant', 'alpha'); $account->code_banque = GETPOST('code_banque', 'alpha'); $account->code_guichet = GETPOST('code_guichet', 'alpha'); $account->number = GETPOST('number', 'alpha'); $account->cle_rib = GETPOST('cle_rib', 'alpha'); $account->bic = GETPOST('bic', 'alpha'); $account->iban = GETPOST('iban', 'alpha'); $account->domiciliation = GETPOST('domiciliation', 'alpha'); $account->proprio = GETPOST('proprio', 'alpha'); $account->owner_address = GETPOST('owner_address', 'alpha'); $result = $account->update($user); if (! $result) { setEventMessages($account->error, $account->errors, 'errors'); $action='edit'; // Force chargement page edition } else { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); $action = ''; } } /* * View */ $form = new Form($db); llxHeader(null, $langs->trans("BankAccounts")); $head = user_prepare_head($object); $account = new UserBankAccount($db); if (! $bankid) { $account->fetch(0, '', $id); } else { $account->fetch($bankid); } if (empty($account->userid)) $account->userid=$object->id; if ($id && $bankid && $action == 'edit' && $user->rights->user->user->creer) { print '
'; print ''; print ''; print ''; print ''; } if ($id && $action == 'create' && $user->rights->user->user->creer) { print ''; print ''; print ''; print ''; } // View if ($action != 'edit' && $action != 'create') // If not bank account yet, $account may be empty { $title = $langs->trans("User"); dol_fiche_head($head, 'bank', $title, -1, 'user'); $linkback = ''; if ($user->rights->user->user->lire || $user->admin) { $linkback = ''.$langs->trans("BackToList").''; } dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin); print '
'; print '
'; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Login").''.$object->login.'
'; print '
'; print load_fiche_titre($langs->trans("BAN")); print '
'; print ''; print ''; print ''; print ''; print ''; // Show fields of bank account foreach ($account->getFieldsToShow() as $val) { if ($val == 'BankCode') { $content = $account->code_banque; } elseif ($val == 'DeskCode') { $content = $account->code_guichet; } elseif ($val == 'BankAccountNumber') { $content = $account->number; } elseif ($val == 'BankAccountNumberKey') { $content = $account->cle_rib; } print ''; print ''; print ''; } print ''; print ''; print ''; print ''; print '\n"; print '\n"; print '\n"; print '
'.$langs->trans("LabelRIB").''.$account->label.'
'.$langs->trans("BankName").''.$account->bank.'
'.$langs->trans($val).''.$content.'
'.$langs->trans("IBAN").''.$account->iban . ' '; if (! empty($account->iban)) { if (! checkIbanForAccount($account)) { print img_picto($langs->trans("IbanNotValid"), 'warning'); } else { print img_picto($langs->trans("IbanValid"), 'info'); } } print '
'.$langs->trans("BIC").''.$account->bic.' '; if (! empty($account->bic)) { if (! checkSwiftForAccount($account)) { print img_picto($langs->trans("SwiftNotValid"), 'warning'); } else { print img_picto($langs->trans("SwiftValid"), 'info'); } } print '
'.$langs->trans("BankAccountDomiciliation").''; print $account->domiciliation; print "
'.$langs->trans("BankAccountOwner").''; print $account->proprio; print "
'.$langs->trans("BankAccountOwnerAddress").''; print $account->owner_address; print "
'; // Check BBAN if ($account->label && ! checkBanForAccount($account)) { print '
'.$langs->trans("RIBControlError").'
'; } print '
'; // Nbre max d'elements des petites listes $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT; /* * Last salaries */ if (! empty($conf->salaries->enabled) && ($user->rights->salaries->read && $object->id == $user->id) ) { $salary = new PaymentSalary($db); $sql = "SELECT ps.rowid, ps.datesp, ps.dateep, ps.amount"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as ps"; $sql.= " WHERE ps.fk_user = ".$object->id; $sql.= " AND ps.entity = ".$conf->entity; $sql.= " ORDER BY ps.datesp DESC"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); print ''; print ''; print ''; print ''; $i = 0; while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); print ''; print '\n"; print '\n"; print ''; $i++; } $db->free($resql); if ($num <= 0) print '
'; print '
'.$langs->trans("LastSalaries", ($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllSalaries").' '.$num.'
'; $salary->id = $objp->rowid; $salary->ref = $objp->rowid; print $salary->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->datesp), 'day')."'.dol_print_date($db->jdate($objp->dateep), 'day')."'.price($objp->amount).'
'.$langs->trans("None").''; print "
"; } else { dol_print_error($db); } } /* * Last holidays */ if (! empty($conf->holiday->enabled) && ($user->rights->holiday->read_all || ($user->rights->holiday->read && $object->id == $user->id)) ) { $holiday = new Holiday($db); $sql = "SELECT h.rowid, h.statut, h.fk_type, h.date_debut, h.date_fin, h.halfday"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday as h"; $sql.= " WHERE h.fk_user = ".$object->id; $sql.= " AND h.entity = ".$conf->entity; $sql.= " ORDER BY h.date_debut DESC"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); print ''; print ''; print ''; print ''; $i = 0; while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); print ''; print '\n"; print ''; print ''; $i++; } $db->free($resql); if ($num <= 0) print '
'; print '
'.$langs->trans("LastHolidays", ($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllHolidays").' '.$num.'
'; $holiday->id = $objp->rowid; $holiday->ref = $objp->rowid; $holiday->fk_type = $objp->fk_type; $nbopenedday=num_open_day($db->jdate($objp->date_debut), $db->jdate($objp->date_fin), 0, 1, $objp->halfday); print $holiday->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->date_debut), 'day')."'.$nbopenedday.' '.$langs->trans('DurationDays').''.$holiday->LibStatut($objp->statut, 5).'
'.$langs->trans("None").''; print "
"; } else { dol_print_error($db); } } /* * Last expense report */ if (! empty($conf->expensereport->enabled) && ($user->rights->expensereport->readall || ($user->rights->expensereport->lire && $object->id == $user->id)) ) { $exp = new ExpenseReport($db); $sql = "SELECT e.rowid, e.ref, e.fk_statut, e.date_debut, e.total_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e"; $sql.= " WHERE e.fk_user_author = ".$object->id; $sql.= " AND e.entity = ".$conf->entity; $sql.= " ORDER BY e.date_debut DESC"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); print ''; print ''; print ''; print ''; $i = 0; while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); print ''; print '\n"; print ''; print ''; $i++; } $db->free($resql); if ($num <= 0) print '
'; print '
'.$langs->trans("LastExpenseReports", ($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllExpenseReports").' '.$num.'
'; $exp->id = $objp->rowid; $exp->ref = $objp->ref; $exp->fk_type = $objp->fk_type; print $exp->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->date_debut), 'day')."'.price($objp->total_ttc).''.$exp->LibStatut($objp->fk_statut, 5).'
'.$langs->trans("None").''; print "
"; } else { dol_print_error($db); } } print '
'; print '
'; dol_fiche_end(); /* * Barre d'actions */ print '
'; if ($user->rights->user->user->creer) { if ($account->id > 0) print ''.$langs->trans("Edit").''; else print ''.$langs->trans("Create").''; } print '
'; } // Edit if ($id && ($action == 'edit' || $action == 'create' ) && $user->rights->user->user->creer) { $title = $langs->trans("User"); dol_fiche_head($head, 'bank', $title, 0, 'user'); $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin); //print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; // Show fields of bank account foreach ($account->getFieldsToShow() as $val) { if ($val == 'BankCode') { $name = 'code_banque'; $size = 8; $content = $account->code_banque; } elseif ($val == 'DeskCode') { $name = 'code_guichet'; $size = 8; $content = $account->code_guichet; } elseif ($val == 'BankAccountNumber') { $name = 'number'; $size = 18; $content = $account->number; } elseif ($val == 'BankAccountNumberKey') { $name = 'cle_rib'; $size = 3; $content = $account->cle_rib; } print ''; print ''; print ''; } // IBAN print ''; print ''; print ''; print ''; print '"; print ''; print ''; print "\n"; print '"; print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankName").'
'.$langs->trans($val).'
'.$langs->trans("IBAN").'
'.$langs->trans("BIC").'
'.$langs->trans("BankAccountDomiciliation").''; print '
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; print '
'; //print '
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; } if ($id && $action == 'edit' && $user->rights->user->user->creer) print '
'; if ($id && $action == 'create' && $user->rights->user->user->creer) print ''; // End of page llxFooter(); $db->close();