dolibarr  17.0.4
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 
29 // Load Dolibarr environment
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
36 
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('banks', 'bills', 'companies', 'suppliers'));
40 
41 
42 // Get Parameters
43 $id = GETPOST('id', 'int');
44 $action = GETPOST('action', 'alpha');
45 $confirm = GETPOST('confirm', 'alpha');
46 
47 // Initialize objects
48 $object = new PaiementFourn($db);
49 
50 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
51 $hookmanager->initHooks(array('supplierpaymentcard', 'globalcard'));
52 
53 // Load object
54 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
55 
56 $result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
57 
58 // Security check
59 if ($user->socid) {
60  $socid = $user->socid;
61 }
62 // Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
63 // It should be enough because all payments are done on invoices of the same thirdparty.
64 if ($socid && $socid != $object->thirdparty->id) {
66 }
67 
68 
69 /*
70  * Actions
71  */
72 
73 if ($action == 'setnote' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
74  $db->begin();
75 
76  $object->fetch($id);
77  $result = $object->update_note(GETPOST('note', 'restricthtml'));
78  if ($result > 0) {
79  $db->commit();
80  $action = '';
81  } else {
82  setEventMessages($object->error, $object->errors, 'errors');
83  $db->rollback();
84  }
85 }
86 
87 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) {
88  $db->begin();
89 
90  $object->fetch($id);
91  $result = $object->delete();
92  if ($result > 0) {
93  $db->commit();
94  header('Location: '.DOL_URL_ROOT.'/fourn/paiement/list.php');
95  exit;
96  } else {
97  setEventMessages($object->error, $object->errors, 'errors');
98  $db->rollback();
99  }
100 }
101 
102 if ($action == 'confirm_validate' && $confirm == 'yes' &&
103  ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
104  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
105 ) {
106  $db->begin();
107 
108  $object->fetch($id);
109  if ($object->validate() >= 0) {
110  $db->commit();
111  header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
112  exit;
113  } else {
114  setEventMessages($object->error, $object->errors, 'errors');
115  $db->rollback();
116  }
117 }
118 
119 if ($action == 'setnum_paiement' && GETPOST('num_paiement')) {
120  $object->fetch($id);
121  $res = $object->update_num(GETPOST('num_paiement'));
122  if ($res === 0) {
123  setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
124  } else {
125  setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
126  }
127 }
128 
129 if ($action == 'setdatep' && GETPOST('datepday')) {
130  $object->fetch($id);
131  $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
132  $res = $object->update_date($datepaye);
133  if ($res === 0) {
134  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
135  } else {
136  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
137  }
138 }
139 
140 // Build document
141 $upload_dir = $conf->fournisseur->payment->dir_output;
142 // TODO: get the appropriate permission
143 $permissiontoadd = true;
144 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
145 
146 // Actions to send emails
147 $triggersendname = 'PAYMENTRECEIPT_SENTBYMAIL';
148 $paramname = 'id';
149 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
150 $trackid = 'pre'.$object->id;
151 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
152 
153 
154 /*
155  * View
156  */
157 
158 llxHeader();
159 
160 $result = $object->fetch($id);
161 
162 $form = new Form($db);
163 $formfile = new FormFile($db);
164 
165 $head = payment_supplier_prepare_head($object);
166 
167 print dol_get_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
168 
169 if ($result > 0) {
170  /*
171  * Confirmation of payment's delete
172  */
173  if ($action == 'delete') {
174  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
175  }
176 
177  /*
178  * Confirmation of payment's validation
179  */
180  if ($action == 'validate') {
181  print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate');
182  }
183 
184  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
185 
186 
187  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref');
188 
189  print '<div class="fichecenter">';
190  print '<div class="underbanner clearboth"></div>';
191 
192  print '<table class="border centpercent">';
193 
194  /*print '<tr>';
195  print '<td width="20%">'.$langs->trans('Ref').'</td><td>';
196  print $form->showrefnav($object,'id','',1,'rowid','ref');
197  print '</td></tr>';*/
198 
199  // Date of payment
200  print '<tr><td class="titlefield">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).'</td>';
201  print '<td>';
202  print $form->editfieldval("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
203  print '</td></tr>';
204 
205  // Payment mode
206  $labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
207  print '<tr><td>'.$langs->trans('PaymentMode').'</td>';
208  print '<td>'.$labeltype;
209  print $object->num_payment ? ' - '.$object->num_payment : '';
210  print '</td></tr>';
211 
212  // Payment numero
213  /* TODO Add field num_payment into payment table and save it
214  print '<tr><td>'.$form->editfieldkey("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td>';
215  print '<td>';
216  print $form->editfieldval("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
217  print '</td></tr>';
218  */
219 
220  // Amount
221  print '<tr><td>'.$langs->trans('Amount').'</td>';
222  print '<td>'.price($object->amount, '', $langs, 0, 0, -1, $conf->currency).'</td></tr>';
223 
224  if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
225  print '<tr><td>'.$langs->trans('Status').'</td>';
226  print '<td>'.$object->getLibStatut(4).'</td></tr>';
227  }
228 
229  $allow_delete = 1;
230  // Bank account
231  if (isModEnabled("banque")) {
232  if ($object->fk_account) {
233  $bankline = new AccountLine($db);
234  $bankline->fetch($object->bank_line);
235  if ($bankline->rappro) {
236  $allow_delete = 0;
237  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
238  }
239 
240  print '<tr>';
241  print '<td>'.$langs->trans('BankAccount').'</td>';
242  print '<td>';
243  $accountstatic = new Account($db);
244  $accountstatic->fetch($bankline->fk_account);
245  print $accountstatic->getNomUrl(1);
246  print '</td>';
247  print '</tr>';
248 
249  print '<tr>';
250  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
251  print '<td>';
252  print $bankline->getNomUrl(1, 0, 'showconciliated');
253  print '</td>';
254  print '</tr>';
255  }
256  }
257 
258  // Note
259  print '<tr><td>'.$form->editfieldkey("Comments", 'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).'</td>';
260  print '<td>';
261  print $form->editfieldval("Note", 'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'textarea');
262  print '</td></tr>';
263 
264  print '</table>';
265 
266  print '</div>';
267 
268  print '<br>';
269 
273  $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,';
274  $sql .= ' pf.amount, s.nom as name, s.rowid as socid';
275  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
276  $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
277  $sql .= ' AND pf.fk_paiementfourn = '.((int) $object->id);
278  $resql = $db->query($sql);
279  if ($resql) {
280  $num = $db->num_rows($resql);
281 
282  $i = 0;
283  $total = 0;
284 
285  print '<table class="noborder centpercent">';
286  print '<tr class="liste_titre">';
287  print '<td>'.$langs->trans('Invoice').'</td>';
288  print '<td>'.$langs->trans('RefSupplier').'</td>';
289  print '<td>'.$langs->trans('Company').'</td>';
290  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
291  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
292  print '<td class="right">'.$langs->trans('Status').'</td>';
293  print "</tr>\n";
294 
295  if ($num > 0) {
296  $facturestatic = new FactureFournisseur($db);
297 
298  while ($i < $num) {
299  $objp = $db->fetch_object($resql);
300 
301  $facturestatic->id = $objp->facid;
302  $facturestatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
303  $facturestatic->date = $db->jdate($objp->date);
304  $facturestatic->type = $objp->type;
305  $facturestatic->total_ht = $objp->total_ht;
306  $facturestatic->total_tva = $objp->total_tva;
307  $facturestatic->total_ttc = $objp->total_ttc;
308  $facturestatic->statut = $objp->status;
309  $facturestatic->alreadypaid = -1; // unknown
310 
311  print '<tr class="oddeven">';
312  // Ref
313  print '<td>';
314  print $facturestatic->getNomUrl(1);
315  print "</td>\n";
316  // Ref supplier
317  print '<td>'.$objp->ref_supplier."</td>\n";
318  // Third party
319  print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$objp->name.'</a></td>';
320  // Expected to pay
321  print '<td class="right">'.price($objp->total_ttc).'</td>';
322  // Paid
323  print '<td class="right">'.price($objp->amount).'</td>';
324  // Status
325  print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).'</td>';
326  print "</tr>\n";
327 
328  if ($objp->paye == 1) {
329  $allow_delete = 0;
330  $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
331  }
332  $total = $total + $objp->amount;
333  $i++;
334  }
335  }
336 
337 
338  print "</table>\n";
339  $db->free($resql);
340  } else {
341  dol_print_error($db);
342  }
343 
344  print '</div>';
345 
346 
347  /*
348  * Actions Buttons
349  */
350 
351  print '<div class="tabsAction">';
352 
353  // Send by mail
354  if ($user->socid == 0 && $action == '') {
355  $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->send)));
356  if ($usercansend) {
357  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
358  } else {
359  print '<span class="butActionRefused classfortooltip">'.$langs->trans('SendMail').'</span>';
360  }
361  }
362 
363  // Payment validation
364  if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
365  if ($user->socid == 0 && $object->statut == 0 && $action == '') {
366  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
367  || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) {
368  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Valid').'</a>';
369  }
370  }
371  }
372 
373  // Delete payment
374  if ($user->socid == 0 && $action == '') {
375  if ($user->rights->fournisseur->facture->supprimer) {
376  if ($allow_delete) {
377  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
378  } else {
379  print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
380  }
381  }
382  }
383  print '</div>';
384 
385 
386  print '<div class="fichecenter"><div class="fichehalfleft">';
387 
388  // Generated documents
389  include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
391  if (is_array($modellist)) {
392  $ref = dol_sanitizeFileName($object->ref);
393  $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
394  $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
395  $genallowed = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
396  $delallowed = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
397  $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF) ? '' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
398 
399  print $formfile->showdocuments('supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $societe->default_lang);
400  $somethingshown = $formfile->numoffiles;
401  }
402 
403  print '</div><div class="fichehalfright">';
404  //print '<br>';
405 
406  // List of actions on element
407  /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
408  $formactions=new FormActions($db);
409  $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
410  */
411 
412  print '</div></div>';
413 
414  // Presend form
415  $modelmail = ''; //TODO: Add new 'payment receipt' model in email models
416  $defaulttopic = 'SendPaymentReceipt';
417  $diroutput = $conf->fournisseur->payment->dir_output;
418  $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
419  $trackid = 'pre'.$object->id;
420 
421  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
422 } else {
423  $langs->load("errors");
424  print $langs->trans("ErrorRecordNotFound");
425 }
426 
427 print dol_get_fiche_end();
428 
429 // End of page
430 llxFooter();
431 $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 suppliers invoices.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage payments for supplier invoices.
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
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_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...
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isModEnabled($module)
Is Dolibarr module enabled.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=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.