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