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';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmargin.class.php';
44 $langs->loadLangs(array(
'bills',
'banks',
'companies'));
48 $action =
GETPOST(
'action',
'aZ09');
49 $confirm =
GETPOST(
'confirm',
'alpha');
50 $backtopage =
GETPOST(
'backtopage',
'alpha');
52 $socid =
GETPOST(
'socid',
'int');
59 $hookmanager->initHooks(array(
'paymentcard',
'globalcard'));
62 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
64 $result =
restrictedArea($user, $object->element, $object->id,
'paiement');
68 $socid = $user->socid;
72 if ($socid && $socid != $object->thirdparty->id) {
82 if ($action ==
'setnote' && $user->hasRight(
'facture',
'paiement')) {
85 $result = $object->update_note(
GETPOST(
'note',
'restricthtml'));
95 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
98 $result = $object->delete();
103 header(
"Location: ".$backtopage);
106 header(
"Location: list.php");
110 $langs->load(
"errors");
116 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->hasRight(
'facture',
'paiement')) {
119 if ($object->validate($user) > 0) {
123 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
124 $outputlangs = $langs;
125 if (
GETPOST(
'lang_id',
'aZ09')) {
127 $outputlangs->setDefaultLang(
GETPOST(
'lang_id',
'aZ09'));
130 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
131 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
132 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
134 $sql =
'SELECT f.rowid as facid';
135 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
136 $sql .=
' WHERE pf.fk_facture = f.rowid';
137 $sql .=
' AND f.fk_soc = s.rowid';
138 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
139 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
140 $resql = $db->query(
$sql);
143 $num = $db->num_rows($resql);
147 $objp = $db->fetch_object($resql);
151 if ($invoice->fetch($objp->facid) <= 0) {
157 if ($invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref) < 0) {
175 header(
'Location: '.$_SERVER[
'PHP_SELF'].
'?id='.$object->id);
181 $langs->load(
"errors");
186 if ($action ==
'setnum_paiement' &&
GETPOST(
'num_paiement') && $user->hasRight(
'facture',
'paiement')) {
187 $res = $object->update_num(
GETPOST(
'num_paiement'));
189 setEventMessages($langs->trans(
'PaymentNumberUpdateSucceeded'),
null,
'mesgs');
191 setEventMessages($langs->trans(
'PaymentNumberUpdateFailed'),
null,
'errors');
195 if ($action ==
'setdatep' &&
GETPOST(
'datepday') && $user->hasRight(
'facture',
'paiement')) {
196 $datepaye =
dol_mktime(
GETPOST(
'datephour',
'int'),
GETPOST(
'datepmin',
'int'),
GETPOST(
'datepsec',
'int'),
GETPOST(
'datepmonth',
'int'),
GETPOST(
'datepday',
'int'),
GETPOST(
'datepyear',
'int'));
197 $res = $object->update_date($datepaye);
199 setEventMessages($langs->trans(
'PaymentDateUpdateSucceeded'),
null,
'mesgs');
205 if ($action ==
'createbankpayment' && $user->hasRight(
'facture',
'paiement')) {
210 $label =
'(CustomerInvoicePayment)';
212 $label =
'(CustomerInvoicePaymentBack)';
215 $bankaccountid =
GETPOST(
'accountid',
'int');
216 if ($bankaccountid > 0) {
217 $object->paiementcode = $object->type_code;
218 $object->amounts = $object->getAmountsArray();
220 $result = $object->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
226 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")),
null,
'errors');
246 $thirdpartystatic =
new Societe($db);
248 $result = $object->fetch($id, $ref);
256 $head = payment_prepare_head($object);
258 print
dol_get_fiche_head($head,
'payment', $langs->trans(
"PaymentCustomerInvoice"), -1,
'payment');
261 if ($action ==
'delete') {
262 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"DeletePayment"), $langs->trans(
"ConfirmDeletePayment"),
'confirm_delete',
'', 0, 2);
266 if ($action ==
'valide') {
267 $facid = $_GET[
'facid'];
268 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&facid='.$facid, $langs->trans(
"ValidatePayment"), $langs->trans(
"ConfirmValidatePayment"),
'confirm_validate',
'', 0, 2);
271 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
276 print
'<div class="fichecenter">';
277 print
'<div class="underbanner clearboth"></div>';
279 print
'<table class="border centpercent">'.
"\n";
282 print
'<tr><td class="titlefield">'.$form->editfieldkey(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
283 print
$form->editfieldval(
"Date",
'datep', $object->date, $object, $user->hasRight(
'facture',
'paiement'),
'datehourpicker',
'',
null, $langs->trans(
'PaymentDateUpdateSucceeded'),
'', 0,
'',
'id',
'tzuser');
287 $labeltype = $langs->trans(
"PaymentType".$object->type_code) != (
"PaymentType".$object->type_code) ? $langs->trans(
"PaymentType".$object->type_code) : $object->type_label;
288 print
'<tr><td>'.$langs->trans(
'PaymentMode').
'</td><td>'.$labeltype;
289 print $object->num_payment ?
' - '.$object->num_payment :
'';
293 print
'<tr><td>'.$langs->trans(
'Amount').
'</td><td>'.
price($object->amount,
'', $langs, 0, -1, -1, $conf->currency).
'</td></tr>';
300 if ($object->fk_account > 0) {
301 $bankline->fetch($object->bank_line);
302 if ($bankline->rappro) {
304 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemoveConciliatedPayment"));
308 print
'<td>'.$langs->trans(
'BankAccount').
'</td>';
310 $accountstatic =
new Account($db);
311 $accountstatic->fetch($bankline->fk_account);
312 print $accountstatic->getNomUrl(1);
340 if ($object->fk_account > 0) {
341 if ($object->type_code ==
'CHQ' && $bankline->fk_bordereau > 0) {
342 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
344 $bordereau->fetch($bankline->fk_bordereau);
347 print
'<td>'.$langs->trans(
'CheckReceipt').
'</td>';
349 print $bordereau->getNomUrl(1);
356 print
'<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
358 if ($object->fk_account > 0) {
359 print $bankline->getNomUrl(1, 0,
'showconciliatedandaccounted');
361 $langs->load(
"admin");
362 print
'<span class="opacitymedium">';
363 print $langs->trans(
"NoRecordFoundIBankcAccount", $langs->transnoentitiesnoconv(
"Module85Name"));
365 if ($user->hasRight(
'facture',
'paiement')) {
368 $amountofpayments = $object->getAmountsArray();
369 $bankaccountidofinvoices =
null;
370 foreach ($amountofpayments as $idinvoice => $amountofpayment) {
371 $tmpinvoice =
new Facture($db);
372 $tmpinvoice->fetch($idinvoice);
373 if ($tmpinvoice->fk_account > 0 && $bankaccountidofinvoices !== 0) {
374 if (is_null($bankaccountidofinvoices)) {
375 $bankaccountidofinvoices = $tmpinvoice->fk_account;
376 } elseif ($bankaccountidofinvoices != $tmpinvoice->fk_account) {
377 $bankaccountidofinvoices = 0;
382 print
'<form method="POST" name="createbankpayment">';
383 print
'<input type="hidden" name="token" value="'.newToken().
'">';
384 print
'<input type="hidden" name="action" value="createbankpayment">';
385 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
386 print
' '.$langs->trans(
"ToCreateRelatedRecordIntoBank").
': ';
387 print
$form->select_comptes($bankaccountidofinvoices,
'accountid', 0,
'', 2,
'', 0,
'', 1);
389 print
'<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="'.$langs->trans(
"ClickHere").
'">';
399 print
'<tr><td class="tdtop">'.$form->editfieldkey(
"Comments",
'note', $object->note, $object, $user->hasRight(
'facture',
'paiement')).
'</td><td>';
400 print
$form->editfieldval(
"Note",
'note', $object->note, $object, $user->hasRight(
'facture',
'paiement'),
'textarea:'.ROWS_3.
':90%');
414 $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';
415 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiement_facture as pf,'.MAIN_DB_PREFIX.
'facture as f,'.MAIN_DB_PREFIX.
'societe as s';
416 $sql .=
' WHERE pf.fk_facture = f.rowid';
417 $sql .=
' AND f.fk_soc = s.rowid';
418 $sql .=
' AND f.entity IN ('.getEntity(
'invoice').
')';
419 $sql .=
' AND pf.fk_paiement = '.((int) $object->id);
420 $resql = $db->query(
$sql);
422 $num = $db->num_rows($resql);
429 print
'<div class="div-table-responsive">';
430 print
'<table class="noborder centpercent">';
432 print
'<tr class="liste_titre">';
433 print
'<td>'.$langs->trans(
'Bill').
'</td>';
434 print
'<td>'.$langs->trans(
'Company').
'</td>';
435 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
436 print
'<td>'.$langs->trans(
'Entity').
'</td>';
440 print
'<td class="right">'.$langs->trans(
'Margin').
'</td>';
442 print
'<td class="right">'.$langs->trans(
'ExpectedToPay').
'</td>';
443 print
'<td class="right">'.$langs->trans(
'PayedByThisPayment').
'</td>';
444 print
'<td class="right">'.$langs->trans(
'RemainderToPay').
'</td>';
445 print
'<td class="right">'.$langs->trans(
'Status').
'</td>';
450 $objp = $db->fetch_object($resql);
452 $thirdpartystatic->fetch($objp->socid);
455 $invoice->fetch($objp->facid);
460 $marginInfo = array();
461 $invoice->fetch_lines();
462 $marginInfo = $formmargin->getMarginInfosArray($invoice);
465 $paiement = $invoice->getSommePaiement();
466 $creditnotes = $invoice->getSumCreditNotesUsed();
467 $deposits = $invoice->getSumDepositsUsed();
468 $alreadypayed =
price2num($paiement + $creditnotes + $deposits,
'MT');
469 $remaintopay =
price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,
'MT');
471 print
'<tr class="oddeven">';
475 print $invoice->getNomUrl(1);
479 print
'<td class="tdoverflowmax150">';
480 print $thirdpartystatic->getNomUrl(1);
484 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
486 $mc->getInfo($objp->entity);
493 print
'<td class="right">'.price($marginInfo[
'total_margin']).
'</td>';
497 print
'<td class="right"><span class="amount">'.price($objp->total_ttc).
'</span></td>';
500 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
503 print
'<td class="right"><span class="amount">'.price($remaintopay).
'</span></td>';
506 print
'<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).
'</td>';
511 if ($objp->paye == 1 && empty($conf->global->INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED)) {
513 $title_button =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"CantRemovePaymentWithOneInvoicePaid"));
516 $total = $total + $objp->amount;
536 print
'<div class="tabsAction">';
538 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
539 if ($user->socid == 0 && $object->statut == 0 && $action ==
'') {
540 if ($user->hasRight(
'facture',
'paiement')) {
541 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'&action=valide&token='.
newToken().
'">'.$langs->trans(
'Valid').
'</a>';
546 if ($user->socid == 0 && $action ==
'') {
547 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $user->hasRight(
'facture',
'paiement') && !$disable_delete);