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