dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
36require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
37if (isModEnabled("bank")) {
38 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
39}
40
41// Load translation files required by the page
42$langs->loadLangs(array("bills", "banks", "companies", "loan"));
43
44// Security check
45$id = GETPOSTINT("id");
46$action = GETPOST('action', 'aZ09');
47$confirm = GETPOST('confirm');
48if ($user->socid) {
49 $socid = $user->socid;
50}
51// TODO add rule to restrict payment access
52//restrictedArea($user, 'facture', $id,'');
53
54$payment = new PaymentLoan($db);
55if ($id > 0) {
56 $result = $payment->fetch($id);
57 if (!$result) {
58 dol_print_error($db, 'Failed to get payment id '.$id);
59 }
60}
61
62if (!$user->hasRight('loan', 'read')) {
64}
65// PaymentLoan::fetch() is a low-level by-id primitive (returns a record regardless of entity), so the
66// access restriction is enforced here in the caller, on the parent loan: restrictedArea() checks the
67// loan read right and that the loan belongs to an allowed entity.
68if ($payment->id > 0) {
69 restrictedArea($user, 'loan', $payment->fk_loan, '', '');
70}
71
72
73/*
74 * Actions
75 */
76
77// Delete payment
78if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) {
79 $db->begin();
80
81 $fk_loan = $payment->fk_loan;
82
83 $result = $payment->delete($user);
84 if ($result > 0) {
85 $db->commit();
86 header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode((string) ($fk_loan)));
87 exit;
88 } else {
89 setEventMessages($payment->error, $payment->errors, 'errors');
90 $db->rollback();
91 }
92}
93
94
95/*
96 * View
97 */
98$loan = new Loan($db);
99$form = new Form($db);
100
101$title = $langs->trans('Loans');
102$help_url = "EN:Module_Loan|FR:Module_Emprunt";
103
104llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-loan page-payment-card');
105
106$h = 0;
107$head = [];
108
109$head = array();
110$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
111$head[$h][1] = $langs->trans("PaymentLoan");
112$hselected = (string) $h;
113$h++;
114
115print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
116
117/*
118 * Confirm deletion of the payment
119 */
120if ($action == 'delete') {
121 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
122}
123
124$linkback = '';
125$morehtmlref = '';
126$morehtmlstatus = '';
127
128dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
129
130print '<div class="fichecenter">';
131print '<div class="underbanner clearboth"></div>';
132
133print '<table class="border centpercent">';
134
135// Date
136print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
137
138// Mode
139print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
140
141// Amount
142print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
143print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
144print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
145
146// Note Private
147print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
148
149// Note Public
150print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
151
152// Bank account
153if (isModEnabled("bank")) {
154 if ($payment->bank_account) {
155 $bankline = new AccountLine($db);
156 $bankline->fetch($payment->bank_line);
157
158 print '<tr>';
159 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
160 print '<td>';
161 print $bankline->getNomUrl(1, 0, 'showall');
162 print '</td>';
163 print '</tr>';
164 }
165}
166
167print '</table>';
168
169print '</div>';
170
171
172/*
173 * List of loans paid
174 */
175
176$disable_delete = 0;
177$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
178$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
179$sql .= ' WHERE pl.fk_loan = l.rowid';
180$sql .= ' AND l.entity = '.((int) $conf->entity);
181$sql .= ' AND pl.rowid = '.((int) $payment->id);
182
183dol_syslog("loan/payment/card.php", LOG_DEBUG);
184$resql = $db->query($sql);
185if ($resql) {
186 $num = $db->num_rows($resql);
187
188 $i = 0;
189 $total = 0;
190 print '<br><table class="noborder centpercent">';
191 print '<tr class="liste_titre">';
192 print '<td>'.$langs->trans('Loan').'</td>';
193 print '<td>'.$langs->trans('Label').'</td>';
194 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
195 print '<td class="center">'.$langs->trans('Status').'</td>';
196 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
197 print "</tr>\n";
198
199 if ($num > 0) {
200 while ($i < $num) {
201 $objp = $db->fetch_object($resql);
202
203 print '<tr class="oddeven">';
204 // Ref
205 print '<td>';
206 $loan->fetch($objp->id);
207 print $loan->getNomUrl(1);
208 print "</td>\n";
209 // Label
210 print '<td>'.$objp->label.'</td>';
211 // Expected to pay
212 // print '<td class="right">'.price($objp->capital).'</td>';
213 // Status
214 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
215 // Amount paid
216 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
217
218 print '<td class="right">'.price($amount_payed).'</td>';
219 print "</tr>\n";
220 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
221 $disable_delete = 1;
222 }
223 $total += $objp->amount_capital;
224 $i++;
225 }
226 }
227
228
229 print "</table>\n";
230 $db->free($resql);
231} else {
232 dol_print_error($db);
233}
234
235print '</div>';
236
237
238/*
239 * Actions buttons
240 */
241
242print '<div class="tabsAction">';
243
244if (empty($action) && $user->hasRight('loan', 'delete')) {
245 if (!$disable_delete) {
246 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1, array('attr' => array('class' => 'reposition')))."\n";
247 } else {
248 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 0);
249 }
250}
251
252print '</div>';
253
254// End of page
255llxFooter();
256$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank transaction lines.
Class to manage generation of HTML components Only common components must be here.
Loan.
Class to manage payments of loans.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.