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