dolibarr  19.0.0-dev
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
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
28 if (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');
39 if ($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);
46 if ($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
59 if ($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 
83 llxHeader();
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 
95 print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
96 
97 /*
98  * Confirm deletion of the payment
99  */
100 if ($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 
108 dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
109 
110 print '<div class="fichecenter">';
111 print '<div class="underbanner clearboth"></div>';
112 
113 print '<table class="border centpercent">';
114 
115 // Date
116 print '<tr><td>'.$langs->trans('Date').'</td><td>'.dol_print_date($payment->datep, 'day').'</td></tr>';
117 
118 // Mode
119 print '<tr><td>'.$langs->trans('Mode').'</td><td>'.$langs->trans("PaymentType".$payment->type_code).'</td></tr>';
120 
121 // Amount
122 print '<tr><td>'.$langs->trans('LoanCapital').'</td><td>'.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
123 print '<tr><td>'.$langs->trans('Insurance').'</td><td>'.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
124 print '<tr><td>'.$langs->trans('Interest').'</td><td>'.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
125 
126 // Note Private
127 print '<tr><td>'.$langs->trans('NotePrivate').'</td><td>'.nl2br($payment->note_private).'</td></tr>';
128 
129 // Note Public
130 print '<tr><td>'.$langs->trans('NotePublic').'</td><td>'.nl2br($payment->note_public).'</td></tr>';
131 
132 // Bank account
133 if (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 
147 print '</table>';
148 
149 print '</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 
163 dol_syslog("loan/payment/card.php", LOG_DEBUG);
164 $resql = $db->query($sql);
165 if ($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 
215 print '</div>';
216 
217 
218 /*
219  * Actions buttons
220  */
221 
222 print '<div class="tabsAction">';
223 
224 if (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 
232 print '</div>';
233 
234 // End of page
235 llxFooter();
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.
Definition: loan.class.php:31
Class to manage payments of loans.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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).
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.