dolibarr 22.0.5
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 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';
28require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
29require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
30if (isModEnabled("bank")) {
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32}
33
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 ajouter regle pour restreindre access paiement
53//$result = 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
63// PaymentLoan::fetch() is a low-level by-id primitive (returns a record regardless of entity), so the
64// access restriction is enforced here in the caller, on the parent loan: restrictedArea() checks the
65// loan read right and that the loan belongs to an allowed entity.
66if ($payment->id > 0) {
67 restrictedArea($user, 'loan', $payment->fk_loan, '', '');
68}
69
70
71/*
72 * Actions
73 */
74
75// Delete payment
76if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) {
77 $db->begin();
78
79 $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
80 $db->query($sql);
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
109$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
110$head[$h][1] = $langs->trans("PaymentLoan");
111$hselected = (string) $h;
112$h++;
113
114print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
115
116/*
117 * Confirm deletion of the payment
118 */
119if ($action == 'delete') {
120 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
121}
122
123$linkback = '';
124$morehtmlref = '';
125$morehtmlstatus = '';
126
127dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
128
129print '<div class="fichecenter">';
130print '<div class="underbanner clearboth"></div>';
131
132print '<table class="border centpercent">';
133
134// Date
135print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
136
137// Mode
138print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
139
140// Amount
141print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
142print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
143print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
144
145// Note Private
146print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
147
148// Note Public
149print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
150
151// Bank account
152if (isModEnabled("bank")) {
153 if ($payment->bank_account) {
154 $bankline = new AccountLine($db);
155 $bankline->fetch($payment->bank_line);
156
157 print '<tr>';
158 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
159 print '<td>';
160 print $bankline->getNomUrl(1, 0, 'showall');
161 print '</td>';
162 print '</tr>';
163 }
164}
165
166print '</table>';
167
168print '</div>';
169
170
171/*
172 * List of loans paid
173 */
174
175$disable_delete = 0;
176$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
177$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
178$sql .= ' WHERE pl.fk_loan = l.rowid';
179$sql .= ' AND l.entity = '.((int) $conf->entity);
180$sql .= ' AND pl.rowid = '.((int) $payment->id);
181
182dol_syslog("loan/payment/card.php", LOG_DEBUG);
183$resql = $db->query($sql);
184if ($resql) {
185 $num = $db->num_rows($resql);
186
187 $i = 0;
188 $total = 0;
189 print '<br><table class="noborder centpercent">';
190 print '<tr class="liste_titre">';
191 print '<td>'.$langs->trans('Loan').'</td>';
192 print '<td>'.$langs->trans('Label').'</td>';
193 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
194 print '<td class="center">'.$langs->trans('Status').'</td>';
195 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
196 print "</tr>\n";
197
198 if ($num > 0) {
199 while ($i < $num) {
200 $objp = $db->fetch_object($resql);
201
202 print '<tr class="oddeven">';
203 // Ref
204 print '<td>';
205 $loan->fetch($objp->id);
206 print $loan->getNomUrl(1);
207 print "</td>\n";
208 // Label
209 print '<td>'.$objp->label.'</td>';
210 // Expected to pay
211 // print '<td class="right">'.price($objp->capital).'</td>';
212 // Status
213 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
214 // Amount paid
215 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
216
217 print '<td class="right">'.price($amount_payed).'</td>';
218 print "</tr>\n";
219 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
220 $disable_delete = 1;
221 }
222 $total += $objp->amount_capital;
223 $i++;
224 }
225 }
226
227
228 print "</table>\n";
229 $db->free($resql);
230} else {
231 dol_print_error($db);
232}
233
234print '</div>';
235
236
237/*
238 * Actions buttons
239 */
240
241print '<div class="tabsAction">';
242
243if (empty($action) && $user->hasRight('loan', 'delete')) {
244 if (!$disable_delete) {
245 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1);
246 } else {
247 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
248 }
249}
250
251print '</div>';
252
253// End of page
254llxFooter();
255$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.