dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
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 <http://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)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 $langs->load('bills');
32 $langs->load('banks');
33 $langs->load('companies');
34 $langs->load('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->societe_id) $socid=$user->societe_id;
42 // TODO Add rule to restrict access payment
43 //$result = restrictedArea($user, 'facture', $id,'');
44 
45 $object = new PaymentExpenseReport($db);
46 
47 /*
48  * Actions
49  */
50 
51 // Delete payment
52 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer)
53 {
54  $db->begin();
55 
56  $result = $object->delete($user);
57  if ($result > 0)
58  {
59  $db->commit();
60  header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
61  exit;
62  }
63  else
64  {
65  setEventMessages($object->error, $object->errors, 'errors');
66  $db->rollback();
67  }
68 }
69 
70 // Create payment
71 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensereport->creer)
72 {
73  $db->begin();
74 
75  $result=$object->valide();
76 
77  if ($result > 0)
78  {
79  $db->commit();
80 
81  $factures=array(); // TODO Get all id of invoices linked to this payment
82  foreach($factures as $id)
83  {
84  $fac = new Facture($db);
85  $fac->fetch($id);
86 
87  $outputlangs = $langs;
88  if (! empty($_REQUEST['lang_id']))
89  {
90  $outputlangs = new Translate("",$conf);
91  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
92  }
93  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
94  $fac->generateDocument($fac->modelpdf, $outputlangs);
95  }
96  }
97 
98  header('Location: card.php?id='.$object->id);
99  exit;
100  }
101  else
102  {
103  setEventMessages($object->error, $object->errors, 'errors');
104  $db->rollback();
105  }
106 }
107 
108 
109 /*
110  * View
111  */
112 
113 llxHeader('', $langs->trans("ExpenseReportPayment"));
114 
115 if ($id > 0)
116 {
117  $result=$object->fetch($id);
118  if (! $result) dol_print_error($db,'Failed to get payment id '.$id);
119 }
120 
121 $form = new Form($db);
122 
123 $head = payment_expensereport_prepare_head($object);
124 
125 dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
126 
127 /*
128  * Confirm deleting of the payment
129  */
130 if ($action == 'delete')
131 {
132  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
133 
134 }
135 
136 /*
137  * Confirm validation of the payment
138  */
139 if ($action == 'valide')
140 {
141  $facid = $_GET['facid'];
142  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
143 
144 }
145 
146 $linkback = '';
147 // $linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/payment/list.php">' . $langs->trans("BackToList") . '</a>';
148 
149 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '');
150 
151 print '<div class="fichecenter">';
152 print '<div class="underbanner clearboth"></div>';
153 
154 print '<table class="border centpercent">'."\n";
155 
156 // Date payment
157 print '<tr><td class="titlefield">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep,'day').'</td></tr>';
158 
159 // Mode
160 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
161 
162 // Number
163 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
164 
165 // Amount
166 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
167 
168 // Note
169 print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
170 
171 $disable_delete = 0;
172 // Bank account
173 if (! empty($conf->banque->enabled))
174 {
175  if ($object->bank_account)
176  {
177  $bankline=new AccountLine($db);
178  $bankline->fetch($object->bank_line);
179  if ($bankline->rappro)
180  {
181  $disable_delete = 1;
182  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
183  }
184 
185  print '<tr>';
186  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
187  print '<td colspan="3">';
188  print $bankline->getNomUrl(1,0,'showconciliated');
189  print '</td>';
190  print '</tr>';
191 
192  print '<tr>';
193  print '<td>'.$langs->trans('BankAccount').'</td>';
194  print '<td colspan="3">';
195  $accountstatic=new Account($db);
196  $accountstatic->fetch($bankline->fk_account);
197  print $accountstatic->getNomUrl(1);
198  print '</td>';
199  print '</tr>';
200  }
201 }
202 
203 print '</table>';
204 
205 print '</div>';
206 
207 dol_fiche_end();
208 
209 
210 /*
211  * List of expense report paid
212  */
213 
214 $sql = 'SELECT er.rowid as eid, er.paid, er.total_ttc, per.amount';
215 $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as per,'.MAIN_DB_PREFIX.'expensereport as er';
216 $sql.= ' WHERE per.fk_expensereport = er.rowid';
217 $sql.= ' AND er.entity IN ('.getEntity('expensereport').')';
218 $sql.= ' AND per.rowid = '.$id;
219 
220 dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
221 $resql=$db->query($sql);
222 if ($resql)
223 {
224  $num = $db->num_rows($resql);
225 
226  $i = 0;
227  $total = 0;
228  print '<br>';
229 
230  print '<div class="div-table-responsive">';
231  print '<table class="noborder" width="100%">';
232 
233  print '<tr class="liste_titre">';
234  print '<td>'.$langs->trans('ExpenseReport').'</td>';
235  print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
236  print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
237  print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
238  print '<td align="center">'.$langs->trans('Status').'</td>';
239  print "</tr>\n";
240 
241  if ($num > 0)
242  {
243  $var=True;
244 
245  while ($i < $num)
246  {
247  $objp = $db->fetch_object($resql);
248 
249  print '<tr class="oddeven">';
250 
251  $expensereport=new ExpenseReport($db);
252  $expensereport->fetch($objp->eid);
253 
254  // Expense report
255  print '<td>';
256  print $expensereport->getNomUrl(1);
257  print "</td>\n";
258 
259  // Expected to pay
260  print '<td align="right">'.price($objp->total_ttc).'</td>';
261 
262  // Amount paid
263  print '<td align="right">'.price($objp->amount).'</td>';
264 
265  // Remain to pay
266  print '<td align="right">'.price($remaintopay).'</td>';
267 
268  // Status
269  print '<td align="center">'.$expensereport->getLibStatut(4,$objp->amount).'</td>';
270 
271  print "</tr>\n";
272  if ($objp->paid == 1) // If at least one invoice is paid, disable delete
273  {
274  $disable_delete = 1;
275  }
276  $total = $total + $objp->amount;
277  $i++;
278  }
279  }
280 
281 
282  print "</table>\n";
283  print '</div>';
284 
285  $db->free($resql);
286 }
287 else
288 {
289  dol_print_error($db);
290 }
291 
292 print '</div>';
293 
294 
295 /*
296  * Actions buttons
297  */
298 print '<div class="tabsAction">';
299 
300 if ($action == '')
301 {
302  if ($user->rights->expensereport->supprimer)
303  {
304  if (! $disable_delete)
305  {
306  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
307  }
308  else
309  {
310  print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
311  }
312  }
313 }
314 
315 print '</div>';
316 
317 llxFooter();
318 
319 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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.
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage bank accounts.
payment_expensereport_prepare_head(PaymentExpenseReport $object)
Returns an array with the tabs for the "Expense report payment" section It loads tabs from modules lo...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage translations.
Class to manage Trips and Expenses.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
Class to manage invoices.