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