* Copyright (C) 2024 MDW * Copyright (C) 2024 Frédéric France * * 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/loan/payment/card.php * \ingroup loan * \brief Payment's card of loan */ // Load Dolibarr environment 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 (isModEnabled("bank")) { require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; } /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langs->loadLangs(array("bills", "banks", "companies", "loan")); // Security check $id = GETPOSTINT("id"); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm'); if ($user->socid) { $socid = $user->socid; } // TODO ajouter regle pour restreindre access 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); } } /* * Actions */ // Delete payment if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) { $db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank); $db->query($sql); $fk_loan = $payment->fk_loan; $result = $payment->delete($user); if ($result > 0) { $db->commit(); header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode((string) ($fk_loan))); exit; } else { setEventMessages($payment->error, $payment->errors, 'errors'); $db->rollback(); } } /* * View */ $loan = new Loan($db); $form = new Form($db); $title = $langs->trans('Loans'); $help_url = "EN:Module_Loan|FR:Module_Emprunt"; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-loan page-payment-card'); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id; $head[$h][1] = $langs->trans("PaymentLoan"); $hselected = (string) $h; $h++; print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment'); /* * 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); } $linkback = ''; $morehtmlref = ''; $morehtmlstatus = ''; dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus); print '
'; print '
'; print ''; // Date print ''; // Mode print ''; // Amount print ''; print ''; print ''; // Note Private print ''; // Note Public print ''; // Bank account if (isModEnabled("bank")) { if ($payment->bank_account) { $bankline = new AccountLine($db); $bankline->fetch($payment->bank_line); print ''; print ''; print ''; print ''; } } print '
'.$langs->trans('Date').''.dol_print_date($payment->datep, 'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$payment->type_code).'
'.$langs->trans('LoanCapital').''.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Insurance').''.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Interest').''.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'
'.$langs->trans('NotePrivate').''.nl2br($payment->note_private).'
'.$langs->trans('NotePublic').''.nl2br($payment->note_public).'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1, 0, 'showall'); print '
'; print '
'; /* * List of loans paid */ $disable_delete = 0; $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'; $sql .= ' AND l.entity = '.((int) $conf->entity); $sql .= ' AND pl.rowid = '.((int) $payment->id); dol_syslog("loan/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 ''; print ''; print ''; print "\n"; if ($num > 0) { while ($i < $num) { $objp = $db->fetch_object($resql); print ''; // Ref print '\n"; // Label print ''; // Expected to pay // print ''; // Status print ''; // Amount paid $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest; print ''; print "\n"; if ($objp->paid == 1) { // If at least one invoice is paid, disable delete $disable_delete = 1; } $total += $objp->amount_capital; $i++; } } print "
'.$langs->trans('Loan').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; $loan->fetch($objp->id); print $loan->getNomUrl(1); print "'.$objp->label.''.price($objp->capital).''.$loan->getLibStatut(4, $objp->amount_capital).''.price($amount_payed).'
\n"; $db->free($resql); } else { dol_print_error($db); } print ''; /* * Actions buttons */ print '
'; if (empty($action) && $user->hasRight('loan', 'delete')) { if (!$disable_delete) { print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1); } else { print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0); } } print '
'; // End of page llxFooter(); $db->close();