diff --git a/htdocs/core/lib/expensereport.lib.php b/htdocs/core/lib/expensereport.lib.php index f253f077243..a5f19174a84 100644 --- a/htdocs/core/lib/expensereport.lib.php +++ b/htdocs/core/lib/expensereport.lib.php @@ -78,7 +78,40 @@ function expensereport_prepare_head($object) return $head; } +/** + * Returns an array with the tabs for the "Expense report payment" section + * It loads tabs from modules looking for the entity payment + * + * @param Paiement $object Current payment object + * @return array Tabs for the payment section + */ +function payment_expensereport_prepare_head(PaymentExpenseReport $object) { + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'payment'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport'); + + $head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/info.php?id='.$object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'payment_expensereport', 'remove'); + + return $head; +} /** * Return array head with list of tabs to view object informations. diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index 9fc8c7627dd..edd80a0bff5 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2015-2017 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 @@ -31,6 +31,7 @@ class PaymentExpenseReport extends CommonObject { public $element='payment_expensereport'; //!< Id that identify managed objects public $table_element='payment_expensereport'; //!< Name of table without prefix where object is stored + public $picto = 'payment'; var $rowid; @@ -425,6 +426,32 @@ class PaymentExpenseReport extends CommonObject } + /** + * Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long + * @return string Libelle + */ + function getLibStatut($mode=0) + { + return ''; + } + + /** + * Renvoi le libelle d'un statut donne + * + * @param int $statut Id statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut + */ + function LibStatut($statut,$mode=0) + { + global $langs; + + return ''; + } + + /** * Initialise an instance with random values. * Used to build previews or test instances. @@ -613,4 +640,48 @@ class PaymentExpenseReport extends CommonObject return $result; } + + /** + * Tab information on object + * + * @param int $id Payment id + * @return void + */ + function info($id) + { + $sql = 'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as e'; + $sql.= ' WHERE e.rowid = '.$id; + + dol_syslog(get_class($this).'::info', LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_creat) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_creat); + $this->user_creation = $cuser; + } + if ($obj->fk_user_modif) + { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->tms); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } } diff --git a/htdocs/expensereport/payment/card.php b/htdocs/expensereport/payment/card.php index bc956955258..de01f01a5df 100644 --- a/htdocs/expensereport/payment/card.php +++ b/htdocs/expensereport/payment/card.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2015-2017 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 @@ -24,29 +24,25 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php'; if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load('bills'); $langs->load('banks'); $langs->load('companies'); +$langs->load('trips'); -// Security check $id=GETPOST('rowid')?GETPOST('rowid','int'):GETPOST('id','int'); $action=GETPOST('action','aZ09'); $confirm=GETPOST('confirm'); + +// Security check if ($user->societe_id) $socid=$user->societe_id; // TODO Add rule to restrict access payment //$result = restrictedArea($user, 'facture', $id,''); -$payment = new PaymentExpenseReport($db); -if ($id > 0) -{ - $result=$payment->fetch($id); - if (! $result) dol_print_error($db,'Failed to get payment id '.$id); -} - +$object = new PaymentExpenseReport($db); /* * Actions @@ -57,7 +53,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensere { $db->begin(); - $result = $payment->delete($user); + $result = $object->delete($user); if ($result > 0) { $db->commit(); @@ -66,7 +62,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensere } else { - setEventMessages($payment->error, $payment->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); } } @@ -76,7 +72,7 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensere { $db->begin(); - $result=$payment->valide(); + $result=$object->valide(); if ($result > 0) { @@ -99,12 +95,12 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensere } } - header('Location: card.php?id='.$payment->id); + header('Location: card.php?id='.$object->id); exit; } else { - setEventMessages($payment->error, $payment->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); } } @@ -114,27 +110,27 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensere * View */ -llxHeader(); +llxHeader('', $langs->trans("ExpenseReportPayment")); + +if ($id > 0) +{ + $result=$object->fetch($id); + if (! $result) dol_print_error($db,'Failed to get payment id '.$id); +} -$expensereport = new ExpenseReport($db); $form = new Form($db); -$h=0; +$head = payment_expensereport_prepare_head($object); -$head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$id; -$head[$h][1] = $langs->trans("Card"); -$hselected = $h; -$h++; - -dol_fiche_head($head, $hselected, $langs->trans("ExpenseReportPayment"), 0, 'payment'); +dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment'); /* * Confirm deleting of the payment */ if ($action == 'delete') { - print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); - + print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); + } /* @@ -143,46 +139,61 @@ if ($action == 'delete') if ($action == 'valide') { $facid = $_GET['facid']; - print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); - + print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + } +// $linkback = '' . $langs->trans("BackToList") . ''; -print ''; +dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', ''); -// Ref -print ''; -print ''; +print '
'; +print '
'; -// Date -print '
'; +print '
'.$langs->trans('Ref').''; -print $form->showrefnav($payment,'id','',1,'rowid','id'); -print '
'.$langs->trans('Date').''.dol_print_date($payment->datep,'day').'
'."\n"; + +// Date payment +print ''; // Mode -print ''; +print ''; // Number -print ''; +print ''; // Amount -print ''; +print ''; // Note -print ''; +print ''; +$disable_delete = 0; // Bank account if (! empty($conf->banque->enabled)) { - if ($payment->bank_account) + if ($object->bank_account) { $bankline=new AccountLine($db); - $bankline->fetch($payment->bank_line); + $bankline->fetch($object->bank_line); + if ($bankline->rappro) + { + $disable_delete = 1; + $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment")); + } print ''; print ''; print ''; + print ''; + + print ''; + print ''; + print ''; print ''; } @@ -190,13 +201,16 @@ if (! empty($conf->banque->enabled)) print '
'.$langs->trans('Date').''.dol_print_date($object->datep,'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$payment->type_code).'
'.$langs->trans('PaymentMode').''.$langs->trans("PaymentType".$object->type_code).'
'.$langs->trans('Numero').''.$payment->num_payment.'
'.$langs->trans('Numero').''.$object->num_payment.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Amount').''.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'.$langs->trans('Note').''.nl2br($object->note).'
'.$langs->trans('BankTransactionLine').''; - print $bankline->getNomUrl(1,0,'showall'); + print $bankline->getNomUrl(1,0,'showconciliated'); + print '
'.$langs->trans('BankAccount').''; + $accountstatic=new Account($db); + $accountstatic->fetch($bankline->fk_account); + print $accountstatic->getNomUrl(1); print '
'; +print ''; + +dol_fiche_end(); + /* - * List of donations paid + * List of expense report paid */ -$disable_delete = 0; -$sql = 'SELECT er.rowid as did, er.paid, er.total_ttc, per.amount'; +$sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount'; $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er'; $sql.= ' WHERE per.fk_expensereport = er.rowid'; $sql.= ' AND er.entity IN ('.getEntity('expensereport', 1).')'; @@ -210,12 +224,17 @@ if ($resql) $i = 0; $total = 0; - print '
'; + print '
'; + + print '
'; + print '
'; + print ''; print ''; - print ''; - print ''; + print ''; print ''; + print ''; + print ''; print "\n"; if ($num > 0) @@ -226,19 +245,28 @@ if ($resql) { $objp = $db->fetch_object($resql); - print ''; - // Ref + + $expensereport=new ExpenseReport($db); + $expensereport->fetch($objp->eid); + + // Expense report print '\n"; + // Expected to pay print ''; - // Status - print ''; + // Amount paid print ''; + + // Remain to pay + print ''; + + // Status + print ''; + print "\n"; if ($objp->paid == 1) // If at least one invoice is paid, disable delete { @@ -251,6 +279,8 @@ if ($resql) print "
'.$langs->trans('ExpenseReport').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('ExpectedToPay').''.$langs->trans('PayedByThisPayment').''.$langs->trans('RemainderToPay').''.$langs->trans('Status').'
'; - $expensereport->fetch($objp->did); print $expensereport->getNomUrl(1); print "'.price($objp->total_ttc).''.$expensereport->getLibStatut(4,$objp->amount).''.price($objp->amount).''.price($remaintopay).''.$expensereport->getLibStatut(4,$objp->amount).'
\n"; + print ''; + $db->free($resql); } else @@ -266,26 +296,13 @@ print ''; */ print '
'; -/* -if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) -{ - if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '') - { - if ($user->rights->facture->paiement) - { - print ''.$langs->trans('Valid').''; - } - } -} -*/ - -if ($_GET['action'] == '') +if ($action == '') { if ($user->rights->expensereport->supprimer) { if (! $disable_delete) { - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } else { @@ -296,8 +313,6 @@ if ($_GET['action'] == '') print '
'; - - llxFooter(); $db->close(); diff --git a/htdocs/expensereport/payment/info.php b/htdocs/expensereport/payment/info.php new file mode 100644 index 00000000000..bcecc54276b --- /dev/null +++ b/htdocs/expensereport/payment/info.php @@ -0,0 +1,81 @@ + + * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2013 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/expensereport/payment/info.php + * \ingroup Expense report + * \brief Tab payment info + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php'; + +$langs->load("bills"); +$langs->load("trips"); + +$id=GETPOST('id'); +$ref=GETPOST('ref', 'alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); + +/* + * Actions + */ + +// None + + +/* + * View + */ + +llxHeader('', $langs->trans("Payment")); + +$object = new PaymentExpenseReport($db); +$object->fetch($id, $ref); +$object->info($object->id); + +$head = payment_expensereport_prepare_head($object); + +dol_fiche_head($head, 'info', $langs->trans("ExpenseReportPayment"), -1, 'payment'); + + +//$linkback = '' . $langs->trans("BackToList") . ''; + +dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', ''); + + +print '
'; +print '
'; + +print '
'; + +print '
'; +dol_print_object_info($object); +print '
'; + +print '
'; + +dol_fiche_end(); + +llxFooter(); +$db->close();