|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-/* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
|
|
+/* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
|
|
|
*
|
|
|
* 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"));
|
|
|
|
|
|
-$expensereport = new ExpenseReport($db);
|
|
|
-$form = new Form($db);
|
|
|
+if ($id > 0)
|
|
|
+{
|
|
|
+ $result=$object->fetch($id);
|
|
|
+ if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
|
|
|
+}
|
|
|
|
|
|
-$h=0;
|
|
|
+$form = new Form($db);
|
|
|
|
|
|
-$head[$h][0] = DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$id;
|
|
|
-$head[$h][1] = $langs->trans("Card");
|
|
|
-$hselected = $h;
|
|
|
-$h++;
|
|
|
+$head = payment_expensereport_prepare_head($object);
|
|
|
|
|
|
-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 = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
|
|
|
|
|
|
-print '<table class="border" width="100%">';
|
|
|
+dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
|
|
|
|
|
|
-// Ref
|
|
|
-print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td>';
|
|
|
-print '<td colspan="3">';
|
|
|
-print $form->showrefnav($payment,'id','',1,'rowid','id');
|
|
|
-print '</td></tr>';
|
|
|
+print '<div class="fichecenter">';
|
|
|
+print '<div class="underbanner clearboth"></div>';
|
|
|
|
|
|
-// Date
|
|
|
-print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($payment->datep,'day').'</td></tr>';
|
|
|
+print '<table class="border centpercent">'."\n";
|
|
|
+
|
|
|
+// Date payment
|
|
|
+print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep,'day').'</td></tr>';
|
|
|
|
|
|
// Mode
|
|
|
-print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
|
|
|
+print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
|
|
|
|
|
|
// Number
|
|
|
-print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$payment->num_payment.'</td></tr>';
|
|
|
+print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
|
|
|
|
|
|
// Amount
|
|
|
-print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
|
|
|
+print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
|
|
|
|
|
|
// Note
|
|
|
-print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($payment->note).'</td></tr>';
|
|
|
+print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
|
|
|
|
|
|
+$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 '<tr>';
|
|
|
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
|
|
|
print '<td colspan="3">';
|
|
|
- print $bankline->getNomUrl(1,0,'showall');
|
|
|
+ print $bankline->getNomUrl(1,0,'showconciliated');
|
|
|
+ print '</td>';
|
|
|
+ print '</tr>';
|
|
|
+
|
|
|
+ print '<tr>';
|
|
|
+ print '<td>'.$langs->trans('BankAccount').'</td>';
|
|
|
+ print '<td colspan="3">';
|
|
|
+ $accountstatic=new Account($db);
|
|
|
+ $accountstatic->fetch($bankline->fk_account);
|
|
|
+ print $accountstatic->getNomUrl(1);
|
|
|
print '</td>';
|
|
|
print '</tr>';
|
|
|
}
|
|
@@ -190,13 +201,16 @@ if (! empty($conf->banque->enabled))
|
|
|
|
|
|
print '</table>';
|
|
|
|
|
|
+print '</div>';
|
|
|
+
|
|
|
+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 '<br><table class="noborder" width="100%">';
|
|
|
+ print '<br>';
|
|
|
+
|
|
|
+ print '<div class="div-table-responsive">';
|
|
|
+ print '<table class="noborder" width="100%">';
|
|
|
+
|
|
|
print '<tr class="liste_titre">';
|
|
|
print '<td>'.$langs->trans('ExpenseReport').'</td>';
|
|
|
- print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
|
|
|
- print '<td align="center">'.$langs->trans('Status').'</td>';
|
|
|
+ print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
|
|
|
print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
|
|
|
+ print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
|
|
|
+ print '<td align="center">'.$langs->trans('Status').'</td>';
|
|
|
print "</tr>\n";
|
|
|
|
|
|
if ($num > 0)
|
|
@@ -226,19 +245,28 @@ if ($resql)
|
|
|
{
|
|
|
$objp = $db->fetch_object($resql);
|
|
|
|
|
|
-
|
|
|
print '<tr class="oddeven">';
|
|
|
- // Ref
|
|
|
+
|
|
|
+ $expensereport=new ExpenseReport($db);
|
|
|
+ $expensereport->fetch($objp->eid);
|
|
|
+
|
|
|
+ // Expense report
|
|
|
print '<td>';
|
|
|
- $expensereport->fetch($objp->did);
|
|
|
print $expensereport->getNomUrl(1);
|
|
|
print "</td>\n";
|
|
|
+
|
|
|
// Expected to pay
|
|
|
print '<td align="right">'.price($objp->total_ttc).'</td>';
|
|
|
- // Status
|
|
|
- print '<td align="center">'.$expensereport->getLibStatut(4,$objp->amount).'</td>';
|
|
|
+
|
|
|
// Amount paid
|
|
|
print '<td align="right">'.price($objp->amount).'</td>';
|
|
|
+
|
|
|
+ // Remain to pay
|
|
|
+ print '<td align="right">'.price($remaintopay).'</td>';
|
|
|
+
|
|
|
+ // Status
|
|
|
+ print '<td align="center">'.$expensereport->getLibStatut(4,$objp->amount).'</td>';
|
|
|
+
|
|
|
print "</tr>\n";
|
|
|
if ($objp->paid == 1) // If at least one invoice is paid, disable delete
|
|
|
{
|
|
@@ -251,6 +279,8 @@ if ($resql)
|
|
|
|
|
|
|
|
|
print "</table>\n";
|
|
|
+ print '</div>';
|
|
|
+
|
|
|
$db->free($resql);
|
|
|
}
|
|
|
else
|
|
@@ -266,26 +296,13 @@ print '</div>';
|
|
|
*/
|
|
|
print '<div class="tabsAction">';
|
|
|
|
|
|
-/*
|
|
|
-if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
|
|
|
-{
|
|
|
- if ($user->societe_id == 0 && $payment->statut == 0 && $_GET['action'] == '')
|
|
|
- {
|
|
|
- if ($user->rights->facture->paiement)
|
|
|
- {
|
|
|
- print '<a class="butAction" href="card.php?id='.$_GET['id'].'&facid='.$objp->facid.'&action=valide">'.$langs->trans('Valid').'</a>';
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-*/
|
|
|
-
|
|
|
-if ($_GET['action'] == '')
|
|
|
+if ($action == '')
|
|
|
{
|
|
|
if ($user->rights->expensereport->supprimer)
|
|
|
{
|
|
|
if (! $disable_delete)
|
|
|
{
|
|
|
- print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&action=delete">'.$langs->trans('Delete').'</a>';
|
|
|
+ print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=delete">'.$langs->trans('Delete').'</a>';
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -296,8 +313,6 @@ if ($_GET['action'] == '')
|
|
|
|
|
|
print '</div>';
|
|
|
|
|
|
-
|
|
|
-
|
|
|
llxFooter();
|
|
|
|
|
|
$db->close();
|