30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
40 $langs->loadLangs(array(
'bills',
'banks',
'companies'));
44 $action =
GETPOST(
'action',
'aZ09');
45 $confirm =
GETPOST(
'confirm',
'alpha');
46 $backtopage =
GETPOST(
'backtopage',
'alpha');
50 $hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
53 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
55 $result =
restrictedArea($user, $object->element, $object->id,
'paiement');
59 $socid = $user->socid;
63 if ($socid && $socid != $object->thirdparty->id) {
74 if ($action ==
'setnote' && $user->rights->facture->paiement) {
77 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
87 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->facture->paiement) {
90 $result = $object->delete();
95 header(
"Location: ".$backtopage);
98 header(
"Location: list.php");
102 $langs->load(
"errors");
108 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->rights->facture->paiement) {
111 if ($object->validate($user) > 0) {
115 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
116 $outputlangs = $langs;
117 if (
GETPOST(
'lang_id',
'aZ09')) {
119 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
122 $hidedetails = ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
123 $hidedesc = ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
124 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
126 $sql =
'SELECT f.rowid as facid';
127 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
128 $sql .=
' WHERE pf.fk_facture = f.rowid';
129 $sql .=
' AND f.fk_soc = s.rowid';
130 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
131 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
132 $resql = $db->query($sql);
135 $num = $db->num_rows(
$resql);
139 $objp = $db->fetch_object(
$resql);
143 if ($invoice->fetch($objp->facid) <= 0) {
149 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
167 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
173 $langs->load(
"errors");
178 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement')) {
179 $res = $object->update_num(
GETPOST(
'num_paiement'));
181 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
183 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
187 if ($action ==
'setdatep' &&
GETPOST(
'datepday')) {
188 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
189 $res = $object->update_date($datepaye);
191 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
196 if ($action ==
'createbankpayment' && !empty($user->rights->facture->paiement)) {
201 $label =
'(CustomerInvoicePayment)';
203 $label =
'(CustomerInvoicePaymentBack)';
206 $bankaccountid =
GETPOST(
'accountid',
'int');
207 if ($bankaccountid > 0) {
208 $object->paiementcode = $object->type_code;
209 $object->amounts = $object->getAmountsArray();
211 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
217 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
237 $thirdpartystatic =
new Societe($db);
239 $result = $object->fetch($id, $ref);
247 $head = payment_prepare_head($object);
249 print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
252 if ($action ==
'delete') {
253 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
257 if ($action ==
'valide') {
258 $facid = $_GET[
'facid'];
259 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
262 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
267 print
'<div class="fichecenter">';
268 print
'<div class="underbanner clearboth"></div>';
270 print
'<table class="border centpercent">'.
"\n";
273 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement).
'</td><td>';
274 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement,
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
278 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
279 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
280 print $object->num_payment ?
' - '.$object->num_payment :
'';
284 print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
291 if ($object->fk_account > 0) {
292 $bankline->fetch($object->bank_line);
293 if ($bankline->rappro) {
295 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
299 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
301 $accountstatic =
new Account($db);
302 $accountstatic->fetch($bankline->fk_account);
303 print $accountstatic->getNomUrl(1);
331 if ($object->fk_account > 0) {
332 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
333 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
335 $bordereau->fetch($bankline->fk_bordereau);
338 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
340 print $bordereau->getNomUrl(1);
347 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
349 if ($object->fk_account > 0) {
350 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
352 $langs->load(
"admin");
353 print
'<span class="opacitymedium">';
354 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
356 if (!empty($user->rights->facture->paiement)) {
359 $amountofpayments = $object->getAmountsArray();
360 $bankaccountidofinvoices =
null;
361 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
362 $tmpinvoice =
new Facture($db);
363 $tmpinvoice->fetch($idinvoice);
364 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
365 if (is_null($bankaccountidofinvoices)) {
366 $bankaccountidofinvoices = $tmpinvoice->fk_account;
367 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
368 $bankaccountidofinvoices = 0;
373 print
'<form method="POST" name="createbankpayment">';
374 print
'<input type="hidden" name="token" value="'.newToken().
'">';
375 print
'<input type="hidden" name="action" value="createbankpayment">';
376 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
377 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
378 print
$form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
380 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
390 print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->rights->facture->paiement).
'</td><td>';
391 print
$form->editfieldval(
"Note",
'note', $object->note, $object, $user->rights->facture->paiement,
'textarea:'.ROWS_3.
':90%');
405 $sql =
'SELECT f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.entity, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid';
406 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
407 $sql .=
' WHERE pf.fk_facture = f.rowid';
408 $sql .=
' AND f.fk_soc = s.rowid';
409 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
410 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
411 $resql = $db->query($sql);
413 $num = $db->num_rows(
$resql);
422 print
'<div class="div-table-responsive">';
423 print
'<table class="noborder centpercent">';
425 print
'<tr class="liste_titre">';
426 print
'<td>'.$langs->trans(
'Bill').
'</td>';
427 print
'<td>'.$langs->trans(
'Company').
'</td>';
428 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
429 print
'<td>'.$langs->trans(
'Entity').
'</td>';
431 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
432 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
433 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
434 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
439 $objp = $db->fetch_object(
$resql);
441 $thirdpartystatic->fetch($objp->socid);
444 $invoice->fetch($objp->facid);
446 $paiement = $invoice->getSommePaiement();
447 $creditnotes = $invoice->getSumCreditNotesUsed();
448 $deposits = $invoice->getSumDepositsUsed();
449 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
450 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
452 print
'<tr class="oddeven">';
456 print $invoice->getNomUrl(1);
460 print
'<td class="tdoverflowmax150">';
461 print $thirdpartystatic->getNomUrl(1);
465 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
467 $mc->getInfo($objp->entity);
472 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
475 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
478 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
481 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
486 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
488 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
491 $total = $total + $objp->amount;
511 print
'<div class="tabsAction">';
513 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
514 if ($user->socid == 0 && $object->statut == 0 && $_GET[
'action'] ==
'') {
515 if ($user->rights->facture->paiement) {
516 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&facid='.$objp->facid.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
521 if ($user->socid == 0 && $action ==
'') {
522 if ($user->rights->facture->paiement) {
523 if (!$disable_delete) {
524 print
'<a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
'Delete').
'</a>';
526 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.
'">'.$langs->trans(
'Delete').
'</a>';