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