*
* 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/card.php
* \ingroup Expense Report
* \brief Tab payment of an expense report
*/
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.'/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');
$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,'');
$object = new PaymentExpenseReport($db);
/*
* Actions
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer)
{
$db->begin();
$result = $object->delete($user);
if ($result > 0)
{
$db->commit();
header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
}
// Create payment
if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensereport->creer)
{
$db->begin();
$result=$object->valide();
if ($result > 0)
{
$db->commit();
$factures=array(); // TODO Get all id of invoices linked to this payment
foreach($factures as $id)
{
$fac = new Facture($db);
$fac->fetch($id);
$outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$fac->generateDocument($fac->modelpdf, $outputlangs);
}
}
header('Location: card.php?id='.$object->id);
exit;
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
}
}
/*
* View
*/
llxHeader('', $langs->trans("ExpenseReportPayment"));
if ($id > 0)
{
$result=$object->fetch($id);
if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
}
$form = new Form($db);
$head = payment_expensereport_prepare_head($object);
dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
/*
* Confirm deleting of the payment
*/
if ($action == 'delete')
{
print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
}
/*
* Confirm validation of the payment
*/
if ($action == 'valide')
{
$facid = $_GET['facid'];
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
}
$linkback = '';
// $linkback = '' . $langs->trans("BackToList") . '';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
print '
';
print '
';
print '
'."\n";
// Date payment
print ''.$langs->trans('Date').' | '.dol_print_date($object->datep,'day').' |
';
// Mode
print ''.$langs->trans('PaymentMode').' | '.$langs->trans("PaymentType".$object->type_code).' |
';
// Number
print ''.$langs->trans('Numero').' | '.$object->num_payment.' |
';
// Amount
print ''.$langs->trans('Amount').' | '.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
// Note
print ''.$langs->trans('Note').' | '.nl2br($object->note).' |
';
$disable_delete = 0;
// Bank account
if (! empty($conf->banque->enabled))
{
if ($object->bank_account)
{
$bankline=new AccountLine($db);
$bankline->fetch($object->bank_line);
if ($bankline->rappro)
{
$disable_delete = 1;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
}
print '';
print ''.$langs->trans('BankTransactionLine').' | ';
print '';
print $bankline->getNomUrl(1,0,'showconciliated');
print ' | ';
print '
';
print '';
print ''.$langs->trans('BankAccount').' | ';
print '';
$accountstatic=new Account($db);
$accountstatic->fetch($bankline->fk_account);
print $accountstatic->getNomUrl(1);
print ' | ';
print '
';
}
}
print '
';
print '
';
dol_fiche_end();
/*
* List of expense report paid
*/
$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).')';
$sql.= ' AND per.rowid = '.$id;
dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
print '
';
print '';
print '
';
print '';
print ''.$langs->trans('ExpenseReport').' | ';
print ''.$langs->trans('ExpectedToPay').' | ';
print ''.$langs->trans('PayedByThisPayment').' | ';
print ''.$langs->trans('RemainderToPay').' | ';
print ''.$langs->trans('Status').' | ';
print "
\n";
if ($num > 0)
{
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
print '';
$expensereport=new ExpenseReport($db);
$expensereport->fetch($objp->eid);
// Expense report
print '';
print $expensereport->getNomUrl(1);
print " | \n";
// Expected to pay
print ''.price($objp->total_ttc).' | ';
// Amount paid
print ''.price($objp->amount).' | ';
// Remain to pay
print ''.price($remaintopay).' | ';
// Status
print ''.$expensereport->getLibStatut(4,$objp->amount).' | ';
print "
\n";
if ($objp->paid == 1) // If at least one invoice is paid, disable delete
{
$disable_delete = 1;
}
$total = $total + $objp->amount;
$i++;
}
}
print "
\n";
print '
';
$db->free($resql);
}
else
{
dol_print_error($db);
}
print '';
/*
* Actions buttons
*/
print '';
llxFooter();
$db->close();