dolibarr 24.0.0-beta
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
66
67/*
68 * Actions
69 */
70
71// Delete payment
72if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) {
73 $db->begin();
74
75 $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
76 $db->query($sql);
77
78 $fk_loan = $payment->fk_loan;
79
80 $result = $payment->delete($user);
81 if ($result > 0) {
82 $db->commit();
83 header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode((string) ($fk_loan)));
84 exit;
85 } else {
86 setEventMessages($payment->error, $payment->errors, 'errors');
87 $db->rollback();
88 }
89}
90
91
92/*
93 * View
94 */
95$loan = new Loan($db);
96$form = new Form($db);
97
98$title = $langs->trans('Loans');
99$help_url = "EN:Module_Loan|FR:Module_Emprunt";
100
101llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-loan page-payment-card');
102
103$h = 0;
104$head = [];
105
106$head = array();
107$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
108$head[$h][1] = $langs->trans("PaymentLoan");
109$hselected = (string) $h;
110$h++;
111
112print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
113
114/*
115 * Confirm deletion of the payment
116 */
117if ($action == 'delete') {
118 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
119}
120
121$linkback = '';
122$morehtmlref = '';
123$morehtmlstatus = '';
124
125dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
126
127print '<div class="fichecenter">';
128print '<div class="underbanner clearboth"></div>';
129
130print '<table class="border centpercent">';
131
132// Date
133print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
134
135// Mode
136print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
137
138// Amount
139print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
140print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
141print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
142
143// Note Private
144print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
145
146// Note Public
147print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
148
149// Bank account
150if (isModEnabled("bank")) {
151 if ($payment->bank_account) {
152 $bankline = new AccountLine($db);
153 $bankline->fetch($payment->bank_line);
154
155 print '<tr>';
156 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
157 print '<td>';
158 print $bankline->getNomUrl(1, 0, 'showall');
159 print '</td>';
160 print '</tr>';
161 }
162}
163
164print '</table>';
165
166print '</div>';
167
168
169/*
170 * List of loans paid
171 */
172
173$disable_delete = 0;
174$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
175$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
176$sql .= ' WHERE pl.fk_loan = l.rowid';
177$sql .= ' AND l.entity = '.((int) $conf->entity);
178$sql .= ' AND pl.rowid = '.((int) $payment->id);
179
180dol_syslog("loan/payment/card.php", LOG_DEBUG);
181$resql = $db->query($sql);
182if ($resql) {
183 $num = $db->num_rows($resql);
184
185 $i = 0;
186 $total = 0;
187 print '<br><table class="noborder centpercent">';
188 print '<tr class="liste_titre">';
189 print '<td>'.$langs->trans('Loan').'</td>';
190 print '<td>'.$langs->trans('Label').'</td>';
191 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
192 print '<td class="center">'.$langs->trans('Status').'</td>';
193 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
194 print "</tr>\n";
195
196 if ($num > 0) {
197 while ($i < $num) {
198 $objp = $db->fetch_object($resql);
199
200 print '<tr class="oddeven">';
201 // Ref
202 print '<td>';
203 $loan->fetch($objp->id);
204 print $loan->getNomUrl(1);
205 print "</td>\n";
206 // Label
207 print '<td>'.$objp->label.'</td>';
208 // Expected to pay
209 // print '<td class="right">'.price($objp->capital).'</td>';
210 // Status
211 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
212 // Amount paid
213 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
214
215 print '<td class="right">'.price($amount_payed).'</td>';
216 print "</tr>\n";
217 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
218 $disable_delete = 1;
219 }
220 $total += $objp->amount_capital;
221 $i++;
222 }
223 }
224
225
226 print "</table>\n";
227 $db->free($resql);
228} else {
230}
231
232print '</div>';
233
234
235/*
236 * Actions buttons
237 */
238
239print '<div class="tabsAction">';
240
241if (empty($action) && $user->hasRight('loan', 'delete')) {
242 if (!$disable_delete) {
243 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1);
244 } else {
245 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
246 }
247}
248
249print '</div>';
250
251// End of page
252llxFooter();
253$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.