dolibarr/htdocs/loan/payment/card.php

236 lines
6.6 KiB
PHP
Raw Normal View History

2014-10-01 07:16:29 +02:00
<?php
2019-01-28 21:39:22 +01:00
/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
2014-10-01 07:16:29 +02:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2014-10-01 07:16:29 +02:00
*/
/**
2018-05-20 07:46:02 +02:00
* \file htdocs/loan/payment/card.php
* \ingroup loan
* \brief Payment's card of loan
2014-10-01 07:16:29 +02:00
*/
2015-03-22 20:19:22 +01:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
2014-10-01 07:16:29 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
$langs->loadLangs(array("bills", "banks", "companies", "loan"));
2014-10-01 07:16:29 +02:00
// Security check
$id = GETPOST("id", 'int');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm');
if ($user->socid) {
$socid = $user->socid;
}
2014-10-01 07:16:29 +02:00
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$payment = new PaymentLoan($db);
if ($id > 0) {
$result = $payment->fetch($id);
if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
2014-10-01 07:16:29 +02:00
}
/*
* Actions
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) {
2014-10-01 07:16:29 +02:00
$db->begin();
2021-03-30 03:37:54 +02:00
$sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
2018-10-19 15:36:13 +02:00
$db->query($sql);
2019-03-03 08:55:27 +01:00
$fk_loan = $payment->fk_loan;
2014-10-01 07:16:29 +02:00
$result = $payment->delete($user);
if ($result > 0) {
2018-05-20 07:46:02 +02:00
$db->commit();
2021-03-30 03:37:54 +02:00
header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode($fk_loan));
2018-05-20 07:46:02 +02:00
exit;
2020-05-21 15:05:19 +02:00
} else {
2015-12-11 09:54:30 +01:00
setEventMessages($payment->error, $payment->errors, 'errors');
2018-05-20 07:46:02 +02:00
$db->rollback();
2014-10-01 07:16:29 +02:00
}
}
/*
* View
*/
llxHeader();
$loan = new Loan($db);
$form = new Form($db);
$h = 0;
2014-10-01 07:16:29 +02:00
2016-12-18 13:21:09 +01:00
$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
2020-05-17 13:34:16 +02:00
$head[$h][1] = $langs->trans("PaymentLoan");
2014-10-01 07:16:29 +02:00
$hselected = $h;
$h++;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
2014-10-01 07:16:29 +02:00
/*
* Confirm deletion of the payment
*/
if ($action == 'delete') {
print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
2014-10-01 07:16:29 +02:00
}
$linkback = '';
$morehtmlref = '';
$morehtmlright = '';
2014-10-01 07:16:29 +02:00
dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
2014-10-01 07:16:29 +02:00
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2014-10-01 07:16:29 +02:00
print '<table class="border centpercent">';
2014-10-01 07:16:29 +02:00
// Date
print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
2014-10-01 07:16:29 +02:00
// Mode
2016-12-10 21:53:24 +01:00
print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
2014-10-01 07:16:29 +02:00
// Amount
2016-12-10 21:53:24 +01:00
print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
2014-10-01 07:16:29 +02:00
2015-03-27 17:13:52 +01:00
// Note Private
2016-12-10 21:53:24 +01:00
print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
2015-03-27 17:13:52 +01:00
// Note Public
2016-12-10 21:53:24 +01:00
print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
2014-10-01 07:16:29 +02:00
// Bank account
if (!empty($conf->banque->enabled)) {
if ($payment->bank_account) {
$bankline = new AccountLine($db);
2018-05-20 07:46:02 +02:00
$bankline->fetch($payment->bank_line);
2014-10-01 07:16:29 +02:00
2018-05-20 07:46:02 +02:00
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
2016-12-10 21:53:24 +01:00
print '<td>';
print $bankline->getNomUrl(1, 0, 'showall');
2018-05-20 07:46:02 +02:00
print '</td>';
print '</tr>';
}
2014-10-01 07:16:29 +02:00
}
print '</table>';
print '</div>';
2014-10-01 07:16:29 +02:00
/*
2021-02-03 19:36:02 +01:00
* List of loans paid
2014-10-01 07:16:29 +02:00
*/
$disable_delete = 0;
2014-11-10 06:08:50 +01:00
$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
$sql .= ' WHERE pl.fk_loan = l.rowid';
2021-08-28 03:09:18 +02:00
$sql .= ' AND l.entity = '.((int) $conf->entity);
$sql .= ' AND pl.rowid = '.((int) $payment->id);
2014-10-01 07:16:29 +02:00
2015-03-22 20:19:22 +01:00
dol_syslog("loan/payment/card.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql) {
2014-10-01 07:16:29 +02:00
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
2019-11-05 21:24:41 +01:00
print '<br><table class="noborder centpercent">';
2014-10-01 07:16:29 +02:00
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Loan').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
2019-03-03 08:55:27 +01:00
// print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td class="center">'.$langs->trans('Status').'</td>';
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
2014-10-01 07:16:29 +02:00
print "</tr>\n";
if ($num > 0) {
while ($i < $num) {
2014-10-01 07:16:29 +02:00
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
2014-10-01 07:16:29 +02:00
// Ref
print '<td>';
$loan->fetch($objp->id);
2017-01-07 17:54:47 +01:00
print $loan->getNomUrl(1);
2014-10-01 07:16:29 +02:00
print "</td>\n";
// Label
print '<td>'.$objp->label.'</td>';
// Expected to pay
2019-03-03 08:55:27 +01:00
// print '<td class="right">'.price($objp->capital).'</td>';
2014-10-01 07:16:29 +02:00
// Status
2019-03-03 08:55:27 +01:00
print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
2021-02-03 19:36:02 +01:00
// Amount paid
2018-05-20 07:46:02 +02:00
$amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
2019-03-03 08:55:27 +01:00
print '<td class="right">'.price($amount_payed).'</td>';
2014-10-01 07:16:29 +02:00
print "</tr>\n";
if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
2014-10-01 07:16:29 +02:00
$disable_delete = 1;
}
2014-11-10 06:08:50 +01:00
$total = $total + $objp->amount_capital;
2014-10-01 07:16:29 +02:00
$i++;
}
}
2018-04-22 19:27:37 +02:00
2014-10-01 07:16:29 +02:00
print "</table>\n";
$db->free($resql);
2020-05-21 15:05:19 +02:00
} else {
2014-10-01 07:16:29 +02:00
dol_print_error($db);
}
print '</div>';
/*
2014-11-10 06:08:50 +01:00
* Actions buttons
2014-10-01 07:16:29 +02:00
*/
print '<div class="tabsAction">';
2014-10-01 07:16:29 +02:00
if (empty($action) && !empty($user->rights->loan->delete)) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="card.php?id='.$id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
2014-10-01 07:16:29 +02:00
}
}
print '</div>';
2018-08-13 11:25:48 +02:00
// End of page
2014-10-01 07:16:29 +02:00
llxFooter();
$db->close();