dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
4  * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
34 
35 $langs->loadLangs(array('bills', 'banks', 'companies', 'suppliers'));
36 
37 $id = GETPOST('id', 'int');
38 $action = GETPOST('action', 'alpha');
39 $confirm = GETPOST('confirm', 'alpha');
40 
41 $object = new PaiementFourn($db);
42 
43 // Load object
44 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
45 
46 $result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
47 
48 // Security check
49 if ($user->socid) $socid = $user->socid;
50 // Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
51 // It should be enough because all payments are done on invoices of the same thirdparty.
52 if ($socid && $socid != $object->thirdparty->id) {
54 }
55 
56 
57 /*
58  * Actions
59  */
60 
61 if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
62 {
63  $db->begin();
64 
65  $object->fetch($id);
66  $result = $object->update_note(GETPOST('note', 'restricthtml'));
67  if ($result > 0)
68  {
69  $db->commit();
70  $action = '';
71  } else {
72  setEventMessages($object->error, $object->errors, 'errors');
73  $db->rollback();
74  }
75 }
76 
77 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
78 {
79  $db->begin();
80 
81  $object->fetch($id);
82  $result = $object->delete();
83  if ($result > 0)
84  {
85  $db->commit();
86  header('Location: '.DOL_URL_ROOT.'/fourn/paiement/list.php');
87  exit;
88  } else {
89  setEventMessages($object->error, $object->errors, 'errors');
90  $db->rollback();
91  }
92 }
93 
94 if ($action == 'confirm_validate' && $confirm == 'yes' &&
95  ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer))
96  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
97 )
98 {
99  $db->begin();
100 
101  $object->fetch($id);
102  if ($object->validate() >= 0)
103  {
104  $db->commit();
105  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
106  exit;
107  } else {
108  setEventMessages($object->error, $object->errors, 'errors');
109  $db->rollback();
110  }
111 }
112 
113 if ($action == 'setnum_paiement' && !empty($_POST['num_paiement']))
114 {
115  $object->fetch($id);
116  $res = $object->update_num($_POST['num_paiement']);
117  if ($res === 0)
118  {
119  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
120  } else {
121  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
122  }
123 }
124 
125 if ($action == 'setdatep' && !empty($_POST['datepday']))
126 {
127  $object->fetch($id);
128  $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
129  $res = $object->update_date($datepaye);
130  if ($res === 0)
131  {
132  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
133  } else {
134  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
135  }
136 }
137 
138 // Build document
139 $upload_dir = $conf->fournisseur->payment->dir_output;
140 // TODO: get the appropriate permission
141 $permissiontoadd = true;
142 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
143 
144 
145 /*
146  * View
147  */
148 
149 llxHeader();
150 
151 $result = $object->fetch($id);
152 
153 $form = new Form($db);
154 $formfile = new FormFile($db);
155 
156 $head = payment_supplier_prepare_head($object);
157 
158 print dol_get_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
159 
160 if ($result > 0)
161 {
162  /*
163  * Confirmation of payment's delete
164  */
165  if ($action == 'delete')
166  {
167  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
168  }
169 
170  /*
171  * Confirmation of payment's validation
172  */
173  if ($action == 'validate')
174  {
175  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate');
176  }
177 
178  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
179 
180 
181  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref');
182 
183  print '<div class="fichecenter">';
184  print '<div class="underbanner clearboth"></div>';
185 
186  print '<table class="border centpercent">';
187 
188  /*print '<tr>';
189  print '<td width="20%">'.$langs->trans('Ref').'</td><td>';
190  print $form->showrefnav($object,'id','',1,'rowid','ref');
191  print '</td></tr>';*/
192 
193  // Date of payment
194  print '<tr><td class="titlefield">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td>';
195  print '<td>';
196  print $form->editfieldval("Date", 'datep', $object->date, $object, $object->statut == 0 && $user->rights->fournisseur->facture->creer, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
197  print '</td></tr>';
198 
199  // Payment mode
200  $labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
201  print '<tr><td>'.$langs->trans('PaymentMode').'</td>';
202  print '<td>'.$labeltype;
203  print $object->num_payment ? ' - '.$object->num_payment : '';
204  print '</td></tr>';
205 
206  // Payment numero
207  /* TODO Add field num_payment into payment table and save it
208  print '<tr><td>'.$form->editfieldkey("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td>';
209  print '<td>';
210  print $form->editfieldval("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
211  print '</td></tr>';
212  */
213 
214  // Amount
215  print '<tr><td>'.$langs->trans('Amount').'</td>';
216  print '<td>'.price($object->amount, '', $langs, 0, 0, -1, $conf->currency).'</td></tr>';
217 
218  if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
219  {
220  print '<tr><td>'.$langs->trans('Status').'</td>';
221  print '<td>'.$object->getLibStatut(4).'</td></tr>';
222  }
223 
224  $allow_delete = 1;
225  // Bank account
226  if (!empty($conf->banque->enabled))
227  {
228  if ($object->fk_account)
229  {
230  $bankline = new AccountLine($db);
231  $bankline->fetch($object->bank_line);
232  if ($bankline->rappro)
233  {
234  $allow_delete = 0;
235  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
236  }
237 
238  print '<tr>';
239  print '<td>'.$langs->trans('BankAccount').'</td>';
240  print '<td>';
241  $accountstatic = new Account($db);
242  $accountstatic->fetch($bankline->fk_account);
243  print $accountstatic->getNomUrl(1);
244  print '</td>';
245  print '</tr>';
246 
247  print '<tr>';
248  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
249  print '<td>';
250  print $bankline->getNomUrl(1, 0, 'showconciliated');
251  print '</td>';
252  print '</tr>';
253  }
254  }
255 
256  // Note
257  print '<tr><td>'.$form->editfieldkey("Comments", 'note', $object->note, $object, $user->rights->fournisseur->facture->creer).'</td>';
258  print '<td>';
259  print $form->editfieldval("Note", 'note', $object->note, $object, $user->rights->fournisseur->facture->creer, 'textarea');
260  print '</td></tr>';
261 
262  print '</table>';
263 
264  print '</div>';
265 
266  print '<br>';
267 
271  $sql = 'SELECT f.rowid, f.rowid as facid, f.ref, f.ref_supplier, f.type, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.datef as date, f.fk_statut as status,';
272  $sql .= ' pf.amount, s.nom as name, s.rowid as socid';
273  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
274  $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
275  $sql .= ' AND pf.fk_paiementfourn = '.$object->id;
276  $resql = $db->query($sql);
277  if ($resql)
278  {
279  $num = $db->num_rows($resql);
280 
281  $i = 0;
282  $total = 0;
283 
284  print '<table class="noborder centpercent">';
285  print '<tr class="liste_titre">';
286  print '<td>'.$langs->trans('Invoice').'</td>';
287  print '<td>'.$langs->trans('RefSupplier').'</td>';
288  print '<td>'.$langs->trans('Company').'</td>';
289  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
290  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
291  print '<td class="right">'.$langs->trans('Status').'</td>';
292  print "</tr>\n";
293 
294  if ($num > 0)
295  {
296  $facturestatic = new FactureFournisseur($db);
297 
298  while ($i < $num)
299  {
300  $objp = $db->fetch_object($resql);
301 
302  $facturestatic->id = $objp->facid;
303  $facturestatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
304  $facturestatic->date = $db->jdate($objp->date);
305  $facturestatic->type = $objp->type;
306  $facturestatic->total_ht = $objp->total_ht;
307  $facturestatic->total_tva = $objp->total_tva;
308  $facturestatic->total_ttc = $objp->total_ttc;
309  $facturestatic->statut = $objp->status;
310  $facturestatic->alreadypaid = -1; // unknown
311 
312  print '<tr class="oddeven">';
313  // Ref
314  print '<td>';
315  print $facturestatic->getNomUrl(1);
316  print "</td>\n";
317  // Ref supplier
318  print '<td>'.$objp->ref_supplier."</td>\n";
319  // Third party
320  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$objp->name.'</a></td>';
321  // Expected to pay
322  print '<td class="right">'.price($objp->total_ttc).'</td>';
323  // Paid
324  print '<td class="right">'.price($objp->amount).'</td>';
325  // Status
326  print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).'</td>';
327  print "</tr>\n";
328 
329  if ($objp->paye == 1)
330  {
331  $allow_delete = 0;
332  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
333  }
334  $total = $total + $objp->amount;
335  $i++;
336  }
337  }
338 
339 
340  print "</table>\n";
341  $db->free($resql);
342  } else {
343  dol_print_error($db);
344  }
345 
346  print '</div>';
347 
348 
349  /*
350  * Actions Buttons
351  */
352 
353  print '<div class="tabsAction">';
354  if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
355  {
356  if ($user->socid == 0 && $object->statut == 0 && $action == '')
357  {
358  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer))
359  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
360  {
361  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Valid').'</a>';
362  }
363  }
364  }
365  if ($user->socid == 0 && $action == '')
366  {
367  if ($user->rights->fournisseur->facture->supprimer)
368  {
369  if ($allow_delete)
370  {
371  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
372  } else {
373  print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
374  }
375  }
376  }
377  print '</div>';
378 
379 
380  print '<div class="fichecenter"><div class="fichehalfleft">';
381 
382  // Documents generes
383 
384  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
386  if (is_array($modellist))
387  {
388  $ref = dol_sanitizeFileName($object->ref);
389  $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
390  $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
391  $genallowed = $user->rights->fournisseur->facture->lire;
392  $delallowed = $user->rights->fournisseur->facture->creer;
393  $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF) ? '' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
394 
395  print $formfile->showdocuments('supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $societe->default_lang);
396  $somethingshown = $formfile->numoffiles;
397  }
398 
399  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
400  //print '<br>';
401 
402  // List of actions on element
403  /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
404  $formactions=new FormActions($db);
405  $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
406  */
407 
408  print '</div></div></div>';
409 } else {
410  $langs->load("errors");
411  print $langs->trans("ErrorRecordNotFound");
412 }
413 
415 
416 // End of page
417 llxFooter();
418 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage bank transaction lines.
Class to manage suppliers invoices.
Class to manage bank accounts.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer 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 payments for supplier invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...