dolibarr 18.0.6
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24// Load Dolibarr environment
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
27require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
28if (isModEnabled("banque")) {
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30}
31
32// Load translation files required by the page
33$langs->loadLangs(array("bills", "banks", "companies", "loan"));
34
35// Security check
36$id = GETPOST("id", 'int');
37$action = GETPOST('action', 'aZ09');
38$confirm = GETPOST('confirm');
39if ($user->socid) {
40 $socid = $user->socid;
41}
42// TODO ajouter regle pour restreindre acces paiement
43//$result = restrictedArea($user, 'facture', $id,'');
44
45$payment = new PaymentLoan($db);
46if ($id > 0) {
47 $result = $payment->fetch($id);
48 if (!$result) {
49 dol_print_error($db, 'Failed to get payment id '.$id);
50 }
51}
52
53
54/*
55 * Actions
56 */
57
58// Delete payment
59if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) {
60 $db->begin();
61
62 $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
63 $db->query($sql);
64
65 $fk_loan = $payment->fk_loan;
66
67 $result = $payment->delete($user);
68 if ($result > 0) {
69 $db->commit();
70 header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode($fk_loan));
71 exit;
72 } else {
73 setEventMessages($payment->error, $payment->errors, 'errors');
74 $db->rollback();
75 }
76}
77
78
79/*
80 * View
81 */
82
83llxHeader();
84
85$loan = new Loan($db);
86$form = new Form($db);
87
88$h = 0;
89
90$head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
91$head[$h][1] = $langs->trans("PaymentLoan");
92$hselected = $h;
93$h++;
94
95print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
96
97/*
98 * Confirm deletion of the payment
99 */
100if ($action == 'delete') {
101 print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
102}
103
104$linkback = '';
105$morehtmlref = '';
106$morehtmlright = '';
107
108dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
109
110print '<div class="fichecenter">';
111print '<div class="underbanner clearboth"></div>';
112
113print '<table class="border centpercent">';
114
115// Date
116print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
117
118// Mode
119print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
120
121// Amount
122print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
123print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
124print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
125
126// Note Private
127print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
128
129// Note Public
130print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
131
132// Bank account
133if (isModEnabled("banque")) {
134 if ($payment->bank_account) {
135 $bankline = new AccountLine($db);
136 $bankline->fetch($payment->bank_line);
137
138 print '<tr>';
139 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
140 print '<td>';
141 print $bankline->getNomUrl(1, 0, 'showall');
142 print '</td>';
143 print '</tr>';
144 }
145}
146
147print '</table>';
148
149print '</div>';
150
151
152/*
153 * List of loans paid
154 */
155
156$disable_delete = 0;
157$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
158$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
159$sql .= ' WHERE pl.fk_loan = l.rowid';
160$sql .= ' AND l.entity = '.((int) $conf->entity);
161$sql .= ' AND pl.rowid = '.((int) $payment->id);
162
163dol_syslog("loan/payment/card.php", LOG_DEBUG);
164$resql = $db->query($sql);
165if ($resql) {
166 $num = $db->num_rows($resql);
167
168 $i = 0;
169 $total = 0;
170 print '<br><table class="noborder centpercent">';
171 print '<tr class="liste_titre">';
172 print '<td>'.$langs->trans('Loan').'</td>';
173 print '<td>'.$langs->trans('Label').'</td>';
174 // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
175 print '<td class="center">'.$langs->trans('Status').'</td>';
176 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
177 print "</tr>\n";
178
179 if ($num > 0) {
180 while ($i < $num) {
181 $objp = $db->fetch_object($resql);
182
183 print '<tr class="oddeven">';
184 // Ref
185 print '<td>';
186 $loan->fetch($objp->id);
187 print $loan->getNomUrl(1);
188 print "</td>\n";
189 // Label
190 print '<td>'.$objp->label.'</td>';
191 // Expected to pay
192 // print '<td class="right">'.price($objp->capital).'</td>';
193 // Status
194 print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
195 // Amount paid
196 $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
197
198 print '<td class="right">'.price($amount_payed).'</td>';
199 print "</tr>\n";
200 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
201 $disable_delete = 1;
202 }
203 $total = $total + $objp->amount_capital;
204 $i++;
205 }
206 }
207
208
209 print "</table>\n";
210 $db->free($resql);
211} else {
212 dol_print_error($db);
213}
214
215print '</div>';
216
217
218/*
219 * Actions buttons
220 */
221
222print '<div class="tabsAction">';
223
224if (empty($action) && !empty($user->rights->loan->delete)) {
225 if (!$disable_delete) {
226 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1);
227 } else {
228 print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
229 }
230}
231
232print '</div>';
233
234// End of page
235llxFooter();
236$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.