dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
28require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
31if (isModEnabled("bank")) {
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
37
38$id = GETPOST('rowid') ? GETPOSTINT('rowid') : GETPOSTINT('id');
39$action = GETPOST('action', 'aZ09');
40$confirm = GETPOST('confirm');
41
42// Security check
43if ($user->socid) {
44 $socid = $user->socid;
45}
46// TODO Add rule to restrict access payment
47//$result = restrictedArea($user, 'facture', $id,'');
48
50
51if ($id > 0) {
52 $result = $object->fetch($id);
53 if (!$result) {
54 dol_print_error($db, 'Failed to get payment id '.$id);
55 }
56}
57
58
59/*
60 * Actions
61 */
62
63// Delete payment
64if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expensereport', 'supprimer')) {
65 $db->begin();
66
67 $result = $object->delete($user);
68 if ($result > 0) {
69 $db->commit();
70 header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
71 exit;
72 } else {
73 setEventMessages($object->error, $object->errors, 'errors');
74 $db->rollback();
75 }
76}
77
78
79/*
80 * View
81 */
82
83llxHeader('', $langs->trans("ExpenseReportPayment"));
84
85$form = new Form($db);
86
88
89print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
90
91/*
92 * Confirm deleting of the payment
93 */
94if ($action == 'delete') {
95 print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
96}
97
98$linkback = '';
99// $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
100
101dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
102
103print '<div class="fichecenter">';
104print '<div class="underbanner clearboth"></div>';
105
106print '<table class="border centpercent">'."\n";
107
108// Date payment
109print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td>'.dol_print_date($object->datep, 'day').'</td></tr>';
110
111// Mode
112print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
113
114// Number
115print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
116
117// Amount
118print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
119
120// Note public
121print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
122
123$disable_delete = 0;
124// Bank account
125if (isModEnabled("bank")) {
126 if ($object->bank_account) {
127 $bankline = new AccountLine($db);
128 $bankline->fetch($object->bank_line);
129 if ($bankline->rappro) {
130 $disable_delete = 1;
131 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
132 }
133
134 print '<tr>';
135 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
136 print '<td colspan="3">';
137 print $bankline->getNomUrl(1, 0, 'showconciliated');
138 print '</td>';
139 print '</tr>';
140
141 print '<tr>';
142 print '<td>'.$langs->trans('BankAccount').'</td>';
143 print '<td colspan="3">';
144 $accountstatic = new Account($db);
145 $accountstatic->fetch($bankline->fk_account);
146 print $accountstatic->getNomUrl(1);
147 print '</td>';
148 print '</tr>';
149 }
150}
151
152print '</table>';
153
154print '</div>';
155
156print dol_get_fiche_end();
157
158
159/*
160 * List of expense report paid
161 */
162
163$sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
164$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
165$sql .= ' WHERE per.fk_expensereport = er.rowid';
166$sql .= ' AND er.entity IN ('.getEntity('expensereport').')';
167$sql .= ' AND per.rowid = '.((int) $id);
168
169dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
170$resql = $db->query($sql);
171if ($resql) {
172 $num = $db->num_rows($resql);
173
174 $i = 0;
175 $total = 0;
176 print '<br>';
177
178 print '<div class="div-table-responsive">';
179 print '<table class="noborder centpercent">';
180
181 print '<tr class="liste_titre">';
182 print '<td>'.$langs->trans('ExpenseReport').'</td>';
183 print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
184 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
185 print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
186 print '<td class="center">'.$langs->trans('Status').'</td>';
187 print "</tr>\n";
188
189 if ($num > 0) {
190 while ($i < $num) {
191 $objp = $db->fetch_object($resql);
192
193 print '<tr class="oddeven">';
194
195 $expensereport = new ExpenseReport($db);
196 $expensereport->fetch($objp->eid);
197
198 // Expense report
199 print '<td>';
200 print $expensereport->getNomUrl(1);
201 print "</td>\n";
202
203 // Expected to pay
204 print '<td class="right">'.price($objp->total_ttc).'</td>';
205
206 // Amount paid
207 print '<td class="right">'.price($objp->amount).'</td>';
208
209 // Remain to pay
210 print '<td class="right">'.price($objp->total_ttc - $objp->amount).'</td>';
211
212 // Status
213 print '<td class="center">'.$expensereport->getLibStatut(4).'</td>';
214
215 print "</tr>\n";
216
217 if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
218 $disable_delete = 2;
219 $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
220 }
221 $total += $objp->amount;
222 $i++;
223 }
224 }
225
226
227 print "</table>\n";
228 print '</div>';
229
230 $db->free($resql);
231} else {
232 dol_print_error($db);
233}
234
235
236
237/*
238 * Actions buttons
239 */
240print '<div class="tabsAction">';
241
242// Delete
243if ($action == '') {
244 if ($user->hasRight('expensereport', 'supprimer')) {
245 if (!$disable_delete) {
246 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
247 } else {
248 print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
249 }
250 }
251}
252
253print '</div>';
254
255// End of page
256llxFooter();
257$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0)
Clean a string to keep only desirable HTML tags.
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_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_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...