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