dolibarr  16.0.1
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 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
27 if (!empty($conf->banque->enabled)) {
28  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 }
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("bills", "banks", "companies", "loan"));
33 
34 // Security check
35 $id = GETPOST("id", 'int');
36 $action = GETPOST('action', 'aZ09');
37 $confirm = GETPOST('confirm');
38 if ($user->socid) {
39  $socid = $user->socid;
40 }
41 // TODO ajouter regle pour restreindre acces paiement
42 //$result = restrictedArea($user, 'facture', $id,'');
43 
44 $payment = new PaymentLoan($db);
45 if ($id > 0) {
46  $result = $payment->fetch($id);
47  if (!$result) {
48  dol_print_error($db, 'Failed to get payment id '.$id);
49  }
50 }
51 
52 
53 /*
54  * Actions
55  */
56 
57 // Delete payment
58 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete) {
59  $db->begin();
60 
61  $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
62  $db->query($sql);
63 
64  $fk_loan = $payment->fk_loan;
65 
66  $result = $payment->delete($user);
67  if ($result > 0) {
68  $db->commit();
69  header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode($fk_loan));
70  exit;
71  } else {
72  setEventMessages($payment->error, $payment->errors, 'errors');
73  $db->rollback();
74  }
75 }
76 
77 
78 /*
79  * View
80  */
81 
82 llxHeader();
83 
84 $loan = new Loan($db);
85 $form = new Form($db);
86 
87 $h = 0;
88 
89 $head[$h][0] = DOL_URL_ROOT.'/loan/payment/card.php?id='.$id;
90 $head[$h][1] = $langs->trans("PaymentLoan");
91 $hselected = $h;
92 $h++;
93 
94 print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
95 
96 /*
97  * Confirm deletion of the payment
98  */
99 if ($action == 'delete') {
100  print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
101 }
102 
103 $linkback = '';
104 $morehtmlref = '';
105 $morehtmlright = '';
106 
107 dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
108 
109 print '<div class="fichecenter">';
110 print '<div class="underbanner clearboth"></div>';
111 
112 print '<table class="border centpercent">';
113 
114 // Date
115 print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
116 
117 // Mode
118 print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
119 
120 // Amount
121 print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
122 print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
123 print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
124 
125 // Note Private
126 print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
127 
128 // Note Public
129 print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
130 
131 // Bank account
132 if (!empty($conf->banque->enabled)) {
133  if ($payment->bank_account) {
134  $bankline = new AccountLine($db);
135  $bankline->fetch($payment->bank_line);
136 
137  print '<tr>';
138  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
139  print '<td>';
140  print $bankline->getNomUrl(1, 0, 'showall');
141  print '</td>';
142  print '</tr>';
143  }
144 }
145 
146 print '</table>';
147 
148 print '</div>';
149 
150 
151 /*
152  * List of loans paid
153  */
154 
155 $disable_delete = 0;
156 $sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest';
157 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l';
158 $sql .= ' WHERE pl.fk_loan = l.rowid';
159 $sql .= ' AND l.entity = '.((int) $conf->entity);
160 $sql .= ' AND pl.rowid = '.((int) $payment->id);
161 
162 dol_syslog("loan/payment/card.php", LOG_DEBUG);
163 $resql = $db->query($sql);
164 if ($resql) {
165  $num = $db->num_rows($resql);
166 
167  $i = 0;
168  $total = 0;
169  print '<br><table class="noborder centpercent">';
170  print '<tr class="liste_titre">';
171  print '<td>'.$langs->trans('Loan').'</td>';
172  print '<td>'.$langs->trans('Label').'</td>';
173  // print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
174  print '<td class="center">'.$langs->trans('Status').'</td>';
175  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
176  print "</tr>\n";
177 
178  if ($num > 0) {
179  while ($i < $num) {
180  $objp = $db->fetch_object($resql);
181 
182  print '<tr class="oddeven">';
183  // Ref
184  print '<td>';
185  $loan->fetch($objp->id);
186  print $loan->getNomUrl(1);
187  print "</td>\n";
188  // Label
189  print '<td>'.$objp->label.'</td>';
190  // Expected to pay
191  // print '<td class="right">'.price($objp->capital).'</td>';
192  // Status
193  print '<td class="center">'.$loan->getLibStatut(4, $objp->amount_capital).'</td>';
194  // Amount paid
195  $amount_payed = $objp->amount_capital + $objp->amount_insurance + $objp->amount_interest;
196 
197  print '<td class="right">'.price($amount_payed).'</td>';
198  print "</tr>\n";
199  if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
200  $disable_delete = 1;
201  }
202  $total = $total + $objp->amount_capital;
203  $i++;
204  }
205  }
206 
207 
208  print "</table>\n";
209  $db->free($resql);
210 } else {
211  dol_print_error($db);
212 }
213 
214 print '</div>';
215 
216 
217 /*
218  * Actions buttons
219  */
220 
221 print '<div class="tabsAction">';
222 
223 if (empty($action) && !empty($user->rights->loan->delete)) {
224  if (!$disable_delete) {
225  print '<a class="butActionDelete" href="card.php?id='.$id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
226  } else {
227  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
228  }
229 }
230 
231 print '</div>';
232 
233 // End of page
234 llxFooter();
235 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Loan.
Definition: loan.class.php:30
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Class to manage bank transaction lines.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of loans.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:73