dolibarr  16.0.5
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2017 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.'/expensereport/class/expensereport.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
29 if (!empty($conf->banque->enabled)) {
30  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 }
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
35 
36 $id = GETPOST('rowid') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
37 $action = GETPOST('action', 'aZ09');
38 $confirm = GETPOST('confirm');
39 
40 // Security check
41 if ($user->socid) {
42  $socid = $user->socid;
43 }
44 // TODO Add rule to restrict access payment
45 //$result = restrictedArea($user, 'facture', $id,'');
46 
47 $object = new PaymentExpenseReport($db);
48 
49 if ($id > 0) {
50  $result = $object->fetch($id);
51  if (!$result) {
52  dol_print_error($db, 'Failed to get payment id '.$id);
53  }
54 }
55 
56 
57 /*
58  * Actions
59  */
60 
61 // Delete payment
62 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) {
63  $db->begin();
64 
65  $result = $object->delete($user);
66  if ($result > 0) {
67  $db->commit();
68  header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
69  exit;
70  } else {
71  setEventMessages($object->error, $object->errors, 'errors');
72  $db->rollback();
73  }
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 llxHeader('', $langs->trans("ExpenseReportPayment"));
82 
83 $form = new Form($db);
84 
85 $head = payment_expensereport_prepare_head($object);
86 
87 print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
88 
89 /*
90  * Confirm deleting of the payment
91  */
92 if ($action == 'delete') {
93  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
94 }
95 
96 $linkback = '';
97 // $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
98 
99 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
100 
101 print '<div class="fichecenter">';
102 print '<div class="underbanner clearboth"></div>';
103 
104 print '<table class="border centpercent">'."\n";
105 
106 // Date payment
107 print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
108 
109 // Mode
110 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
111 
112 // Number
113 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
114 
115 // Amount
116 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
117 
118 // Note public
119 print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note_public).'</td></tr>';
120 
121 $disable_delete = 0;
122 // Bank account
123 if (!empty($conf->banque->enabled)) {
124  if ($object->bank_account) {
125  $bankline = new AccountLine($db);
126  $bankline->fetch($object->bank_line);
127  if ($bankline->rappro) {
128  $disable_delete = 1;
129  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
130  }
131 
132  print '<tr>';
133  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
134  print '<td colspan="3">';
135  print $bankline->getNomUrl(1, 0, 'showconciliated');
136  print '</td>';
137  print '</tr>';
138 
139  print '<tr>';
140  print '<td>'.$langs->trans('BankAccount').'</td>';
141  print '<td colspan="3">';
142  $accountstatic = new Account($db);
143  $accountstatic->fetch($bankline->fk_account);
144  print $accountstatic->getNomUrl(1);
145  print '</td>';
146  print '</tr>';
147  }
148 }
149 
150 print '</table>';
151 
152 print '</div>';
153 
154 print dol_get_fiche_end();
155 
156 
157 /*
158  * List of expense report paid
159  */
160 
161 $sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
162 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
163 $sql .= ' WHERE per.fk_expensereport = er.rowid';
164 $sql .= ' AND er.entity IN ('.getEntity('expensereport').')';
165 $sql .= ' AND per.rowid = '.((int) $id);
166 
167 dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
168 $resql = $db->query($sql);
169 if ($resql) {
170  $num = $db->num_rows($resql);
171 
172  $i = 0;
173  $total = 0;
174  print '<br>';
175 
176  print '<div class="div-table-responsive">';
177  print '<table class="noborder centpercent">';
178 
179  print '<tr class="liste_titre">';
180  print '<td>'.$langs->trans('ExpenseReport').'</td>';
181  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
182  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
183  print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
184  print '<td class="center">'.$langs->trans('Status').'</td>';
185  print "</tr>\n";
186 
187  if ($num > 0) {
188  while ($i < $num) {
189  $objp = $db->fetch_object($resql);
190 
191  print '<tr class="oddeven">';
192 
193  $expensereport = new ExpenseReport($db);
194  $expensereport->fetch($objp->eid);
195 
196  // Expense report
197  print '<td>';
198  print $expensereport->getNomUrl(1);
199  print "</td>\n";
200 
201  // Expected to pay
202  print '<td class="right">'.price($objp->total_ttc).'</td>';
203 
204  // Amount paid
205  print '<td class="right">'.price($objp->amount).'</td>';
206 
207  // Remain to pay
208  print '<td class="right">'.price($objp->total_ttc - $objp->amount).'</td>';
209 
210  // Status
211  print '<td class="center">'.$expensereport->getLibStatut(4, $objp->amount).'</td>';
212 
213  print "</tr>\n";
214 
215  if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
216  $disable_delete = 2;
217  $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
218  }
219  $total = $total + $objp->amount;
220  $i++;
221  }
222  }
223 
224 
225  print "</table>\n";
226  print '</div>';
227 
228  $db->free($resql);
229 } else {
230  dol_print_error($db);
231 }
232 
233 
234 
235 /*
236  * Actions buttons
237  */
238 print '<div class="tabsAction">';
239 
240 if ($action == '') {
241  if ($user->rights->expensereport->supprimer) {
242  if (!$disable_delete) {
243  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
244  } else {
245  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($title_button).'">'.$langs->trans('Delete').'</a>';
246  }
247  }
248 }
249 
250 print '</div>';
251 
252 // End of page
253 llxFooter();
254 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
payment_expensereport_prepare_head
payment_expensereport_prepare_head(PaymentExpenseReport $object)
Returns an array with the tabs for the "Expense report payment" section It loads tabs from modules lo...
Definition: expensereport.lib.php:95
dol_banner_tab
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.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
PaymentExpenseReport
Class to manage payments of expense report.
Definition: paymentexpensereport.class.php:31
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36
$resql
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
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
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
Account
Class to manage bank accounts.
Definition: account.class.php:38