28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
35 $langs->loadLangs(array(
'bills',
'banks',
'companies',
'suppliers'));
38 $action =
GETPOST(
'action',
'alpha');
39 $confirm =
GETPOST(
'confirm',
'alpha');
43 $hookmanager->initHooks(array(
'supplierpaymentcard',
'globalcard'));
46 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
48 $result =
restrictedArea($user, $object->element, $object->id,
'paiementfourn',
'');
52 $socid = $user->socid;
56 if ($socid && $socid != $object->thirdparty->id) {
65 if ($action ==
'setnote' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
69 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
79 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->fournisseur->facture->supprimer) {
83 $result = $object->delete();
86 header(
'Location: '.DOL_URL_ROOT.
'/fourn/paiement/list.php');
94 if ($action ==
'confirm_validate' && $confirm ==
'yes' &&
95 ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
96 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
101 if ($object->validate() >= 0) {
103 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
111 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement')) {
113 $res = $object->update_num(
GETPOST(
'num_paiement'));
115 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
117 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
121 if ($action ==
'setdatep' &&
GETPOST(
'datepday')) {
123 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
124 $res = $object->update_date($datepaye);
126 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
133 $upload_dir = $conf->fournisseur->payment->dir_output;
135 $permissiontoadd =
true;
136 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
139 $triggersendname =
'PAYMENTRECEIPT_SENTBYMAIL';
141 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
142 $trackid =
'pre'.$object->id;
143 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
152 $result = $object->fetch($id);
157 $head = payment_supplier_prepare_head($object);
159 print
dol_get_fiche_head($head,
'payment', $langs->trans(
'SupplierPayment'), -1,
'payment');
165 if ($action ==
'delete') {
166 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete');
172 if ($action ==
'validate') {
173 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate');
176 $linkback =
'<a href="'.DOL_URL_ROOT.
'/fourn/paiement/list.php'.(!empty($socid) ?
'?socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
181 print
'<div class="fichecenter">';
182 print
'<div class="underbanner clearboth"></div>';
184 print
'<table class="border centpercent">';
192 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).
'</td>';
194 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer),
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'));
198 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
199 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td>';
200 print
'<td>'.$labeltype;
201 print $object->num_payment ?
' - '.$object->num_payment :
'';
213 print
'<tr><td>'.$langs->trans(
'Amount').
'</td>';
214 print
'<td>'.price($object->amount,
'', $langs, 0, 0, -1, $conf->currency).
'</td></tr>';
216 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
217 print
'<tr><td>'.$langs->trans(
'Status').
'</td>';
218 print
'<td>'.$object->getLibStatut(4).
'</td></tr>';
223 if (!empty($conf->banque->enabled)) {
224 if ($object->fk_account) {
226 $bankline->fetch($object->bank_line);
227 if ($bankline->rappro) {
229 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
233 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
235 $accountstatic =
new Account($db);
236 $accountstatic->fetch($bankline->fk_account);
237 print $accountstatic->getNomUrl(1);
242 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
244 print $bankline->getNomUrl(1, 0,
'showconciliated');
251 print
'<tr><td>'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).
'</td>';
253 print
$form->editfieldval(
"Note",
'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer),
'textarea');
265 $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,';
266 $sql .=
' pf.amount, s.nom as name, s.rowid as socid';
267 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
268 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
269 $sql .=
' AND pf.fk_paiementfourn = '.((int) $object->id);
270 $resql = $db->query($sql);
272 $num = $db->num_rows(
$resql);
277 print
'<table class="noborder centpercent">';
278 print
'<tr class="liste_titre">';
279 print
'<td>'.$langs->trans(
'Invoice').
'</td>';
280 print
'<td>'.$langs->trans(
'RefSupplier').
'</td>';
281 print
'<td>'.$langs->trans(
'Company').
'</td>';
282 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
283 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
284 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
291 $objp = $db->fetch_object(
$resql);
293 $facturestatic->id = $objp->facid;
294 $facturestatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
295 $facturestatic->date = $db->jdate($objp->date);
296 $facturestatic->type = $objp->type;
297 $facturestatic->total_ht = $objp->total_ht;
298 $facturestatic->total_tva = $objp->total_tva;
299 $facturestatic->total_ttc = $objp->total_ttc;
300 $facturestatic->statut = $objp->status;
301 $facturestatic->alreadypaid = -1;
303 print
'<tr class="oddeven">';
306 print $facturestatic->getNomUrl(1);
309 print
'<td>'.$objp->ref_supplier.
"</td>\n";
311 print
'<td><a href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$objp->socid.
'">'.
img_object($langs->trans(
'ShowCompany'),
'company').
' '.$objp->name.
'</a></td>';
313 print
'<td class="right">'.price($objp->total_ttc).
'</td>';
315 print
'<td class="right">'.price($objp->amount).
'</td>';
317 print
'<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).
'</td>';
320 if ($objp->paye == 1) {
322 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
324 $total = $total + $objp->amount;
343 print
'<div class="tabsAction">';
346 if ($user->socid == 0 && $action ==
'') {
347 $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->send)));
349 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a>';
351 print
'<span class="butActionRefused classfortooltip">'.$langs->trans(
'SendMail').
'</span>';
356 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
357 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
358 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
359 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) {
360 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=validate">'.$langs->trans(
'Valid').
'</a>';
366 if ($user->socid == 0 && $action ==
'') {
367 if ($user->rights->fournisseur->facture->supprimer) {
369 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>';
371 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.
'">'.$langs->trans(
'Delete').
'</a>';
378 print
'<div class="fichecenter"><div class="fichehalfleft">';
381 include_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_payment/modules_supplier_payment.php';
383 if (is_array($modellist)) {
386 $urlsource = $_SERVER[
'PHP_SELF'].
'?id='.$object->id;
387 $genallowed = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
388 $delallowed = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
389 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF) ?
'' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
391 print $formfile->showdocuments(
'supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0,
'',
'',
'', $societe->default_lang);
392 $somethingshown = $formfile->numoffiles;
395 print
'</div><div class="fichehalfright">';
404 print
'</div></div>';
408 $defaulttopic =
'SendPaymentReceipt';
409 $diroutput = $conf->fournisseur->payment->dir_output;
410 $autocopy =
'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
411 $trackid =
'pre'.$object->id;
413 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
415 $langs->load(
"errors");
416 print $langs->trans(
"ErrorRecordNotFound");