dolibarr 25.0.0-alpha
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-2026 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';
35require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
36require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
39if (isModEnabled("bank")) {
40 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41}
42
43// Load translation files required by the page
44$langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
45
46$id = GETPOST('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm');
49
51
52if ($id > 0) {
53 $result = $object->fetch($id);
54 if (!$result) {
55 dol_print_error($db, 'Failed to get payment id '.$id);
56 }
57}
58
59// Security check
60if ($user->isExternalUser()) {
61 $socid = $user->isExternalUser();
62}
63
64$result = restrictedArea($user, 'expensereport', $object->fk_expensereport, 'expensereport');
65
66
67/*
68 * Actions
69 */
70
71// Delete payment
72if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expensereport', 'supprimer')) {
73 $db->begin();
74
75 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
76 $result = $object->delete($user);
77 if ($result > 0) {
78 $db->commit();
79 header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
80 exit;
81 } else {
82 setEventMessages($object->error, $object->errors, 'errors');
83 $db->rollback();
84 }
85}
86
87
88/*
89 * View
90 */
91
92llxHeader('', $langs->trans("ExpenseReportPayment"));
93
94$form = new Form($db);
95
97
98print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
99
100/*
101 * Confirm deleting of the payment
102 */
103if ($action == 'delete') {
104 print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
105}
106
107$linkback = '';
108// $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
109
110dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
111
112print '<div class="fichecenter">';
113print '<div class="underbanner clearboth"></div>';
114
115print '<table class="border centpercent">'."\n";
116
117// Date payment
118print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
119
120// Mode
121print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
122
123// Number
124print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
125
126// Amount
127print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
128
129// Note public
130print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr((string) $object->note_public)).'</td></tr>';
131
132$disable_delete = 0;
133$title_button = '';
134// Bank account
135if (isModEnabled("bank")) {
136 if ($object->bank_account) {
137 $bankline = new AccountLine($db);
138 $bankline->fetch($object->bank_line);
139 if ($bankline->rappro) {
140 $disable_delete = 1;
141 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
142 }
143
144 print '<tr>';
145 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
146 print '<td colspan="3">';
147 print $bankline->getNomUrl(1, 0, 'showconciliated');
148 print '</td>';
149 print '</tr>';
150
151 print '<tr>';
152 print '<td>'.$langs->trans('BankAccount').'</td>';
153 print '<td colspan="3">';
154 $accountstatic = new Account($db);
155 $accountstatic->fetch($bankline->fk_account);
156 print $accountstatic->getNomUrl(1);
157 print '</td>';
158 print '</tr>';
159 }
160}
161
162print '</table>';
163
164print '</div>';
165
166print dol_get_fiche_end();
167
168
169/*
170 * List of expense report paid
171 */
172
173$sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
174$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
175$sql .= ' WHERE per.fk_expensereport = er.rowid';
176$sql .= ' AND er.entity IN ('.getEntity('expensereport').')';
177$sql .= ' AND per.rowid = '.((int) $id);
178
179dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
180$resql = $db->query($sql);
181if ($resql) {
182 $num = $db->num_rows($resql);
183
184 $i = 0;
185 $total = 0;
186 print '<br>';
187
188 print '<div class="div-table-responsive">';
189 print '<table class="noborder centpercent">';
190
191 print '<tr class="liste_titre">';
192 print '<td>'.$langs->trans('ExpenseReport').'</td>';
193 print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
194 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
195 print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
196 print '<td class="center">'.$langs->trans('Status').'</td>';
197 print "</tr>\n";
198
199 if ($num > 0) {
200 while ($i < $num) {
201 $objp = $db->fetch_object($resql);
202
203 print '<tr class="oddeven">';
204
205 $expensereport = new ExpenseReport($db);
206 $expensereport->fetch($objp->eid);
207
208 // Expense report
209 print '<td>';
210 print $expensereport->getNomUrl(1);
211 print "</td>\n";
212
213 // Expected to pay
214 print '<td class="right">'.price($objp->total_ttc).'</td>';
215
216 // Amount paid
217 print '<td class="right">'.price($objp->amount).'</td>';
218
219 // Remain to pay
220 print '<td class="right">'.price($objp->total_ttc - $objp->amount).'</td>';
221
222 // Status
223 print '<td class="center">'.$expensereport->getLibStatut(4).'</td>';
224
225 print "</tr>\n";
226
227 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
228 $disable_delete = 2;
229 $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
230 }
231 $total += $objp->amount;
232 $i++;
233 }
234 }
235
236
237 print "</table>\n";
238 print '</div>';
239
240 $db->free($resql);
241} else {
242 dol_print_error($db);
243}
244
245
246
247/*
248 * Actions buttons
249 */
250print '<div class="tabsAction">';
251
252// Delete
253if ($action == '') {
254 if ($user->hasRight('expensereport', 'supprimer')) {
255 if (!$disable_delete) {
256 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1, array('attr' => array('class' => 'reposition')))."\n";
257 } else {
258 print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
259 }
260 }
261}
262
263print '</div>';
264
265// End of page
266llxFooter();
267$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
payment_expensereport_prepare_head(PaymentExpenseReport $object)
Returns an array with the tabs for the "Expense report payment" section It loads tabs from modules lo...
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.