31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
41 $langs->loadLangs(array(
'bills',
'banks',
'companies'));
45 $action =
GETPOST(
'action',
'aZ09');
46 $confirm =
GETPOST(
'confirm',
'alpha');
47 $backtopage =
GETPOST(
'backtopage',
'alpha');
49 $socid =
GETPOST(
'socid',
'int');
56 $hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
59 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
61 $result =
restrictedArea($user, $object->element, $object->id,
'paiement');
65 $socid = $user->socid;
69 if ($socid && $socid != $object->thirdparty->id) {
79 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
82 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
92 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
95 $result = $object->delete();
100 header(
"Location: ".$backtopage);
103 header(
"Location: list.php");
107 $langs->load(
"errors");
113 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
116 if ($object->validate($user) > 0) {
120 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
121 $outputlangs = $langs;
122 if (
GETPOST(
'lang_id',
'aZ09')) {
124 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
127 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
128 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
129 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
131 $sql =
'SELECT f.rowid as facid';
132 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
133 $sql .=
' WHERE pf.fk_facture = f.rowid';
134 $sql .=
' AND f.fk_soc = s.rowid';
135 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
136 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
137 $resql = $db->query(
$sql);
140 $num = $db->num_rows($resql);
144 $objp = $db->fetch_object($resql);
148 if ($invoice->fetch($objp->facid) <= 0) {
154 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
172 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
178 $langs->load(
"errors");
183 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
184 $res = $object->update_num(
GETPOST(
'num_paiement'));
186 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
188 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
192 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
193 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
194 $res = $object->update_date($datepaye);
196 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
202 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
207 $label =
'(CustomerInvoicePayment)';
209 $label =
'(CustomerInvoicePaymentBack)';
212 $bankaccountid =
GETPOST(
'accountid',
'int');
213 if ($bankaccountid > 0) {
214 $object->paiementcode = $object->type_code;
215 $object->amounts = $object->getAmountsArray();
217 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
223 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
243 $thirdpartystatic =
new Societe($db);
245 $result = $object->fetch($id, $ref);
253 $head = payment_prepare_head($object);
255 print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
258 if ($action ==
'delete') {
259 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
263 if ($action ==
'valide') {
264 $facid = $_GET[
'facid'];
265 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
268 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
273 print
'<div class="fichecenter">';
274 print
'<div class="underbanner clearboth"></div>';
276 print
'<table class="border centpercent">'.
"\n";
279 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement).
'</td><td>';
280 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $user->rights->facture->paiement,
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
284 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
285 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
286 print $object->num_payment ?
' - '.$object->num_payment :
'';
290 print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
297 if ($object->fk_account > 0) {
298 $bankline->fetch($object->bank_line);
299 if ($bankline->rappro) {
301 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
305 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
307 $accountstatic =
new Account($db);
308 $accountstatic->fetch($bankline->fk_account);
309 print $accountstatic->getNomUrl(1);
337 if ($object->fk_account > 0) {
338 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
339 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
341 $bordereau->fetch($bankline->fk_bordereau);
344 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
346 print $bordereau->getNomUrl(1);
353 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
355 if ($object->fk_account > 0) {
356 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
358 $langs->load(
"admin");
359 print
'<span class="opacitymedium">';
360 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
362 if (!empty($user->rights->facture->paiement)) {
365 $amountofpayments = $object->getAmountsArray();
366 $bankaccountidofinvoices =
null;
367 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
368 $tmpinvoice =
new Facture($db);
369 $tmpinvoice->fetch($idinvoice);
370 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
371 if (is_null($bankaccountidofinvoices)) {
372 $bankaccountidofinvoices = $tmpinvoice->fk_account;
373 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
374 $bankaccountidofinvoices = 0;
379 print
'<form method="POST" name="createbankpayment">';
380 print
'<input type="hidden" name="token" value="'.newToken().
'">';
381 print
'<input type="hidden" name="action" value="createbankpayment">';
382 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
383 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
384 print
$form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
386 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
396 print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->rights->facture->paiement).
'</td><td>';
397 print
$form->editfieldval(
"Note",
'note', $object->note, $object, $user->rights->facture->paiement,
'textarea:'.ROWS_3.
':90%');
411 $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';
412 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
413 $sql .=
' WHERE pf.fk_facture = f.rowid';
414 $sql .=
' AND f.fk_soc = s.rowid';
415 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
416 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
417 $resql = $db->query(
$sql);
419 $num = $db->num_rows($resql);
426 print
'<div class="div-table-responsive">';
427 print
'<table class="noborder centpercent">';
429 print
'<tr class="liste_titre">';
430 print
'<td>'.$langs->trans(
'Bill').
'</td>';
431 print
'<td>'.$langs->trans(
'Company').
'</td>';
432 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
433 print
'<td>'.$langs->trans(
'Entity').
'</td>';
435 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
436 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
437 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
438 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
443 $objp = $db->fetch_object($resql);
445 $thirdpartystatic->fetch($objp->socid);
448 $invoice->fetch($objp->facid);
450 $paiement = $invoice->getSommePaiement();
451 $creditnotes = $invoice->getSumCreditNotesUsed();
452 $deposits = $invoice->getSumDepositsUsed();
453 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
454 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
456 print
'<tr class="oddeven">';
460 print $invoice->getNomUrl(1);
464 print
'<td class="tdoverflowmax150">';
465 print $thirdpartystatic->getNomUrl(1);
469 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
471 $mc->getInfo($objp->entity);
476 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
479 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
482 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
485 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
490 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
492 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
495 $total = $total + $objp->amount;
515 print
'<div class="tabsAction">';
517 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
518 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
519 if ($user->rights->facture->paiement) {
520 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
525 if ($user->socid == 0 && $action ==
'') {
526 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $user->rights->facture->paiement && !$disable_delete);