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