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';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
38if (isModEnabled("bank")) {
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40}
41
42// Load translation files required by the page
43$langs->loadLangs(array("bills", "banks", "companies", "loan"));
44
45// Security check
46$id = GETPOSTINT("id");
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm');
49if ($user->socid) {
50 $socid = $user->socid;
51}
52// TODO add rule to restrict payment access
53//restrictedArea($user, 'facture', $id,'');
54
55$payment = new PaymentLoan($db);
56if ($id > 0) {
57 $result = $payment->fetch($id);
58 if (!$result) {
59 dol_print_error($db, 'Failed to get payment id '.$id);
60 }
61}
62
63if (!$user->hasRight('loan', 'read')) {
65}
66// PaymentLoan::fetch() is a low-level by-id primitive (returns a record regardless of entity), so the
67// access restriction is enforced here in the caller, on the parent loan: restrictedArea() checks the
68// loan read right and that the loan belongs to an allowed entity.
69if ($payment->id > 0) {
70 restrictedArea($user, 'loan', $payment->fk_loan, '', '');
71}
72
73
74/*
75 * Actions
76 */
77
78// Delete payment
79if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) {
80 $db->begin();
81
82 $fk_loan = $payment->fk_loan;
83
84 $result = $payment->delete($user);
85 if ($result > 0) {
86 $db->commit();
87 header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode((string) ($fk_loan)));
88 exit;
89 } else {
90 setEventMessages($payment->error, $payment->errors, 'errors');
91 $db->rollback();
92 }
93}
94
95
96/*
97 * View
98 */
99$loan = new Loan($db);
100$form = new Form($db);
101
102$title = $langs->trans('Loans');
103$help_url = "EN:Module_Loan|FR:Module_Emprunt";
104
105llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-loan page-payment-card');
106
107$h = 0;
108$head = [];
109
110$head = array();
111$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
112$head[$h][1] = $langs->trans("PaymentLoan");
113$hselected = (string) $h;
114$h++;
115
116print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
117
118/*
119 * Confirm deletion of the payment
120 */
121if ($action == 'delete') {
122 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
123}
124
125$linkback = '';
126$morehtmlref = '';
127$morehtmlstatus = '';
128
129dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
130
131print '<div class="fichecenter">';
132print '<div class="underbanner clearboth"></div>';
133
134print '<table class="border centpercent">';
135
136// Date
137print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
138
139// Mode
140print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
141
142// Amount
143print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
144$loan->fetch($payment->fk_loan);
145print '<tr><td>'.loanChargeLabel($loan->charge_type, $langs).'</td><td>'.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
146print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
147
148// Note Private
149print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
150
151// Note Public
152print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
153
154// Bank account
155if (isModEnabled("bank")) {
156 if ($payment->bank_account) {
157 $bankline = new AccountLine($db);
158 $bankline->fetch($payment->bank_line);
159
160 print '<tr>';
161 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
162 print '<td>';
163 print $bankline->getNomUrl(1, 0, 'showall');
164 print '</td>';
165 print '</tr>';
166 }
167}
168
169print '</table>';
170
171print '</div>';
172
173
174/*
175 * List of loans paid
176 */
177
178$disable_delete = 0;
179$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
180$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
181$sql .= ' WHERE pl.fk_loan = l.rowid';
182$sql .= ' AND l.entity = '.((int) $conf->entity);
183$sql .= ' AND pl.rowid = '.((int) $payment->id);
184
185dol_syslog("loan/payment/card.php", LOG_DEBUG);
186$resql = $db->query($sql);
187if ($resql) {
188 $num = $db->num_rows($resql);
189
190 $i = 0;
191 $total = 0;
192 print '<br><table class="noborder centpercent">';
193 print '<tr class="liste_titre">';
194 print '<td>'.$langs->trans('Loan').'</td>';
195 print '<td>'.$langs->trans('Label').'</td>';
196 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
197 print '<td class="center">'.$langs->trans('Status').'</td>';
198 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
199 print "</tr>\n";
200
201 if ($num > 0) {
202 while ($i < $num) {
203 $objp = $db->fetch_object($resql);
204
205 print '<tr class="oddeven">';
206 // Ref
207 print '<td>';
208 $loan->fetch($objp->id);
209 print $loan->getNomUrl(1);
210 print "</td>\n";
211 // Label
212 print '<td>'.$objp->label.'</td>';
213 // Expected to pay
214 // print '<td class="right">'.price($objp->capital).'</td>';
215 // Status
216 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
217 // Amount paid
218 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
219
220 print '<td class="right">'.price($amount_payed).'</td>';
221 print "</tr>\n";
222 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
223 $disable_delete = 1;
224 }
225 $total += $objp->amount_capital;
226 $i++;
227 }
228 }
229
230
231 print "</table>\n";
232 $db->free($resql);
233} else {
234 dol_print_error($db);
235}
236
237print '</div>';
238
239
240/*
241 * Actions buttons
242 */
243
244print '<div class="tabsAction">';
245
246if (empty($action) && $user->hasRight('loan', 'delete')) {
247 if (!$disable_delete) {
248 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";
249 } else {
250 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 0);
251 }
252}
253
254print '</div>';
255
256// End of page
257llxFooter();
258$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
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:542
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.