dolibarr 19.0.3
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
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
36
37
38// Load translation files required by the page
39$langs->loadLangs(array('banks', 'bills', 'companies', 'suppliers'));
40
41
42// Get Parameters
43$id = GETPOST('id', 'int');
44$action = GETPOST('action', 'alpha');
45$confirm = GETPOST('confirm', 'alpha');
46
47$socid = 0;
48
49// Initialize objects
50$object = new PaiementFourn($db);
51
52// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
53$hookmanager->initHooks(array('supplierpaymentcard', 'globalcard'));
54
55// Load object
56include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
57
58$result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', ''); // This also test permission on read invoice
59
60// Security check
61if ($user->socid) {
62 $socid = $user->socid;
63}
64// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
65// It should be enough because all payments are done on invoices of the same thirdparty.
66if ($socid && $socid != $object->thirdparty->id) {
68}
69
70
71/*
72 * Actions
73 */
74
75if ($action == 'setnote' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
76 $db->begin();
77
78 $object->fetch($id);
79 $result = $object->update_note(GETPOST('note', 'restricthtml'));
80 if ($result > 0) {
81 $db->commit();
82 $action = '';
83 } else {
84 setEventMessages($object->error, $object->errors, 'errors');
85 $db->rollback();
86 }
87}
88
89if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight("fournisseur", "facture", "supprimer")) {
90 $db->begin();
91
92 $object->fetch($id);
93 $result = $object->delete();
94 if ($result > 0) {
95 $db->commit();
96 header('Location: '.DOL_URL_ROOT.'/fourn/paiement/list.php');
97 exit;
98 } else {
99 setEventMessages($object->error, $object->errors, 'errors');
100 $db->rollback();
101 }
102}
103
104if ($action == 'confirm_validate' && $confirm == 'yes' &&
105 ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")))
106 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate")))
107) {
108 $db->begin();
109
110 $object->fetch($id);
111 if ($object->validate() >= 0) {
112 $db->commit();
113 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
114 exit;
115 } else {
116 setEventMessages($object->error, $object->errors, 'errors');
117 $db->rollback();
118 }
119}
120
121if ($action == 'setnum_paiement' && GETPOST('num_paiement')) {
122 $object->fetch($id);
123 $res = $object->update_num(GETPOST('num_paiement'));
124 if ($res === 0) {
125 setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
126 } else {
127 setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
128 }
129}
130
131if ($action == 'setdatep' && GETPOST('datepday')) {
132 $object->fetch($id);
133 $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
134 $res = $object->update_date($datepaye);
135 if ($res === 0) {
136 setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
137 } else {
138 setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
139 }
140}
141
142// Build document
143$upload_dir = $conf->fournisseur->payment->dir_output;
144// TODO: get the appropriate permission
145$permissiontoadd = true;
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, '', $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("banque")) {
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->alreadypaid = -1; // unknown
313
314 print '<tr class="oddeven">';
315 // Ref
316 print '<td>';
317 print $facturestatic->getNomUrl(1);
318 print "</td>\n";
319 // Ref supplier
320 print '<td>'.$objp->ref_supplier."</td>\n";
321 // Third party
322 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$objp->name.'</a></td>';
323 // Expected to pay
324 print '<td class="right">'.price($objp->total_ttc).'</td>';
325 // Paid
326 print '<td class="right">'.price($objp->amount).'</td>';
327 // Status
328 print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).'</td>';
329 print "</tr>\n";
330
331 if ($objp->paye == 1) {
332 $allow_delete = 0;
333 $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
334 }
335 $total = $total + $objp->amount;
336 $i++;
337 }
338 }
339
340
341 print "</table>\n";
342 $db->free($resql);
343 } else {
344 dol_print_error($db);
345 }
346
347 print '</div>';
348
349
350 /*
351 * Actions Buttons
352 */
353
354 print '<div class="tabsAction">';
355
356 // Send by mail
357 if ($user->socid == 0 && $action != 'presend') {
358 $usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "send")));
359 if ($usercansend) {
360 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
361 } else {
362 print '<span class="butActionRefused classfortooltip">'.$langs->trans('SendMail').'</span>';
363 }
364 }
365
366 // Payment validation
367 if (getDolGlobalString('BILL_ADD_PAYMENT_VALIDATION')) {
368 if ($user->socid == 0 && $object->statut == 0 && $action == '') {
369 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")))
370 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate"))) {
371 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Valid').'</a>';
372 }
373 }
374 }
375
376 // Delete payment
377 if ($user->socid == 0 && $action != 'presend') {
378 if ($user->hasRight('fournisseur', 'facture', 'supprimer')) {
379 if ($allow_delete) {
380 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
381 } else {
382 print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
383 }
384 }
385 }
386 print '</div>';
387
388 if ($action != 'presend') {
389 print '<div class="fichecenter"><div class="fichehalfleft">';
390
391 // Generated documents
392 include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
394 if (is_array($modellist)) {
395 $ref = dol_sanitizeFileName($object->ref);
396 $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
397 $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
398 $genallowed = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
399 $delallowed = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
400 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (!getDolGlobalString('SUPPLIER_PAYMENT_ADDON_PDF') ? '' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
401
402 print $formfile->showdocuments('supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $object->thirdparty->default_lang);
403 $somethingshown = $formfile->numoffiles;
404 }
405
406 print '</div><div class="fichehalfright">';
407 //print '<br>';
408
409 // List of actions on element
410 /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
411 $formactions=new FormActions($db);
412 $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
413 */
414
415 print '</div></div>';
416 }
417
418 // Presend form
419 $modelmail = ''; //TODO: Add new 'payment receipt' model in email models
420 $defaulttopic = 'SendPaymentReceipt';
421 $diroutput = $conf->fournisseur->payment->dir_output;
422 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
423 $trackid = 'pre'.$object->id;
424
425 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
426} else {
427 $langs->load("errors");
428 print $langs->trans("ErrorRecordNotFound");
429}
430
431print dol_get_fiche_end();
432
433// End of page
434llxFooter();
435$db->close();
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_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.
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...
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
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.