dolibarr 22.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 * Copyright (C) 2024-2025 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.'/expensereport/class/expensereport.class.php';
29require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
32if (isModEnabled("bank")) {
33 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34}
35
44// Load translation files required by the page
45$langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
46
47$id = GETPOST('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
48$action = GETPOST('action', 'aZ09');
49$confirm = GETPOST('confirm');
50
52
53if ($id > 0) {
54 $result = $object->fetch($id);
55 if (!$result) {
56 dol_print_error($db, 'Failed to get payment id '.$id);
57 }
58}
59
60// Security check
61if ($user->socid) {
62 $socid = $user->socid;
63}
64
65// Load the parent expense report so restrictedArea() can also check the user hierarchy
66$expensereport = new ExpenseReport($db);
67if ($object->fk_expensereport > 0) {
68 if ($expensereport->fetch($object->fk_expensereport) <= 0) {
70 }
71}
72
73$result = restrictedArea($user, 'expensereport', ($expensereport->id > 0 ? $expensereport : 0), 'expensereport');
74
75
76/*
77 * Actions
78 */
79
80// Delete payment
81if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expensereport', 'supprimer')) {
82 $db->begin();
83
84 $result = $object->delete($user);
85 if ($result > 0) {
86 $db->commit();
87 header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
88 exit;
89 } else {
90 setEventMessages($object->error, $object->errors, 'errors');
91 $db->rollback();
92 }
93}
94
95
96/*
97 * View
98 */
99
100llxHeader('', $langs->trans("ExpenseReportPayment"));
101
102$form = new Form($db);
103
105
106print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
107
108/*
109 * Confirm deleting of the payment
110 */
111if ($action == 'delete') {
112 print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
113}
114
115$linkback = '';
116// $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
117
118dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
119
120print '<div class="fichecenter">';
121print '<div class="underbanner clearboth"></div>';
122
123print '<table class="border centpercent">'."\n";
124
125// Date payment
126print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
127
128// Mode
129print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
130
131// Number
132print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
133
134// Amount
135print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
136
137// Note public
138print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
139
140$disable_delete = 0;
141$title_button = '';
142// Bank account
143if (isModEnabled("bank")) {
144 if ($object->bank_account) {
145 $bankline = new AccountLine($db);
146 $bankline->fetch($object->bank_line);
147 if ($bankline->rappro) {
148 $disable_delete = 1;
149 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
150 }
151
152 print '<tr>';
153 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
154 print '<td colspan="3">';
155 print $bankline->getNomUrl(1, 0, 'showconciliated');
156 print '</td>';
157 print '</tr>';
158
159 print '<tr>';
160 print '<td>'.$langs->trans('BankAccount').'</td>';
161 print '<td colspan="3">';
162 $accountstatic = new Account($db);
163 $accountstatic->fetch($bankline->fk_account);
164 print $accountstatic->getNomUrl(1);
165 print '</td>';
166 print '</tr>';
167 }
168}
169
170print '</table>';
171
172print '</div>';
173
174print dol_get_fiche_end();
175
176
177/*
178 * List of expense report paid
179 */
180
181$sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
182$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
183$sql .= ' WHERE per.fk_expensereport = er.rowid';
184$sql .= ' AND er.entity IN ('.getEntity('expensereport').')';
185$sql .= ' AND per.rowid = '.((int) $id);
186
187dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
188$resql = $db->query($sql);
189if ($resql) {
190 $num = $db->num_rows($resql);
191
192 $i = 0;
193 $total = 0;
194 print '<br>';
195
196 print '<div class="div-table-responsive">';
197 print '<table class="noborder centpercent">';
198
199 print '<tr class="liste_titre">';
200 print '<td>'.$langs->trans('ExpenseReport').'</td>';
201 print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
202 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
203 print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
204 print '<td class="center">'.$langs->trans('Status').'</td>';
205 print "</tr>\n";
206
207 if ($num > 0) {
208 while ($i < $num) {
209 $objp = $db->fetch_object($resql);
210
211 print '<tr class="oddeven">';
212
213 $expensereport = new ExpenseReport($db);
214 $expensereport->fetch($objp->eid);
215
216 // Expense report
217 print '<td>';
218 print $expensereport->getNomUrl(1);
219 print "</td>\n";
220
221 // Expected to pay
222 print '<td class="right">'.price($objp->total_ttc).'</td>';
223
224 // Amount paid
225 print '<td class="right">'.price($objp->amount).'</td>';
226
227 // Remain to pay
228 print '<td class="right">'.price($objp->total_ttc - $objp->amount).'</td>';
229
230 // Status
231 print '<td class="center">'.$expensereport->getLibStatut(4).'</td>';
232
233 print "</tr>\n";
234
235 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
236 $disable_delete = 2;
237 $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
238 }
239 $total += $objp->amount;
240 $i++;
241 }
242 }
243
244
245 print "</table>\n";
246 print '</div>';
247
248 $db->free($resql);
249} else {
250 dol_print_error($db);
251}
252
253
254
255/*
256 * Actions buttons
257 */
258print '<div class="tabsAction">';
259
260// Delete
261if ($action == '') {
262 if ($user->hasRight('expensereport', 'supprimer')) {
263 if (!$disable_delete) {
264 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
265 } else {
266 print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
267 }
268 }
269}
270
271print '</div>';
272
273// End of page
274llxFooter();
275$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 accounts.
Class to manage bank transaction lines.
Class to manage Trips and Expenses.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of expense report.
payment_expensereport_prepare_head(PaymentExpenseReport $object)
Returns an array with the tabs for the "Expense report payment" section It loads tabs from modules lo...
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.