dolibarr 24.0.2
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 ajouter regle pour restreindre access paiement
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 $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
82 $db->query($sql);
83
84 $fk_loan = $payment->fk_loan;
85
86 $result = $payment->delete($user);
87 if ($result > 0) {
88 $db->commit();
89 header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode((string) ($fk_loan)));
90 exit;
91 } else {
92 setEventMessages($payment->error, $payment->errors, 'errors');
93 $db->rollback();
94 }
95}
96
97
98/*
99 * View
100 */
101$loan = new Loan($db);
102$form = new Form($db);
103
104$title = $langs->trans('Loans');
105$help_url = "EN:Module_Loan|FR:Module_Emprunt";
106
107llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-loan page-payment-card');
108
109$h = 0;
110$head = [];
111
112$head = array();
113$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
114$head[$h][1] = $langs->trans("PaymentLoan");
115$hselected = (string) $h;
116$h++;
117
118print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
119
120/*
121 * Confirm deletion of the payment
122 */
123if ($action == 'delete') {
124 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
125}
126
127$linkback = '';
128$morehtmlref = '';
129$morehtmlstatus = '';
130
131dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
132
133print '<div class="fichecenter">';
134print '<div class="underbanner clearboth"></div>';
135
136print '<table class="border centpercent">';
137
138// Date
139print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
140
141// Mode
142print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
143
144// Amount
145print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
146print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
147print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
148
149// Note Private
150print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
151
152// Note Public
153print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
154
155// Bank account
156if (isModEnabled("bank")) {
157 if ($payment->bank_account) {
158 $bankline = new AccountLine($db);
159 $bankline->fetch($payment->bank_line);
160
161 print '<tr>';
162 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
163 print '<td>';
164 print $bankline->getNomUrl(1, 0, 'showall');
165 print '</td>';
166 print '</tr>';
167 }
168}
169
170print '</table>';
171
172print '</div>';
173
174
175/*
176 * List of loans paid
177 */
178
179$disable_delete = 0;
180$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
181$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
182$sql .= ' WHERE pl.fk_loan = l.rowid';
183$sql .= ' AND l.entity = '.((int) $conf->entity);
184$sql .= ' AND pl.rowid = '.((int) $payment->id);
185
186dol_syslog("loan/payment/card.php", LOG_DEBUG);
187$resql = $db->query($sql);
188if ($resql) {
189 $num = $db->num_rows($resql);
190
191 $i = 0;
192 $total = 0;
193 print '<br><table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print '<td>'.$langs->trans('Loan').'</td>';
196 print '<td>'.$langs->trans('Label').'</td>';
197 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
198 print '<td class="center">'.$langs->trans('Status').'</td>';
199 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
200 print "</tr>\n";
201
202 if ($num > 0) {
203 while ($i < $num) {
204 $objp = $db->fetch_object($resql);
205
206 print '<tr class="oddeven">';
207 // Ref
208 print '<td>';
209 $loan->fetch($objp->id);
210 print $loan->getNomUrl(1);
211 print "</td>\n";
212 // Label
213 print '<td>'.$objp->label.'</td>';
214 // Expected to pay
215 // print '<td class="right">'.price($objp->capital).'</td>';
216 // Status
217 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
218 // Amount paid
219 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
220
221 print '<td class="right">'.price($amount_payed).'</td>';
222 print "</tr>\n";
223 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
224 $disable_delete = 1;
225 }
226 $total += $objp->amount_capital;
227 $i++;
228 }
229 }
230
231
232 print "</table>\n";
233 $db->free($resql);
234} else {
236}
237
238print '</div>';
239
240
241/*
242 * Actions buttons
243 */
244
245print '<div class="tabsAction">';
246
247if (empty($action) && $user->hasRight('loan', 'delete')) {
248 if (!$disable_delete) {
249 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1);
250 } else {
251 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 0);
252 }
253}
254
255print '</div>';
256
257// End of page
258llxFooter();
259$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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.