2004-10-19 22:35:36 +02:00
< ? php
2009-04-27 22:37:50 +02:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-01-15 15:01:59 +01:00
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2009-04-27 22:37:50 +02:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2015-11-12 11:59:15 +01:00
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 Juanjo Menent < jmenent @ 2 byte . es >
2004-01-31 18:29:54 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-01-31 18:29:54 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2004-01-31 18:29:54 +01:00
*/
2004-09-14 22:46:09 +02:00
2005-04-15 23:49:23 +02:00
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / compta / paiement / card . php
2009-07-15 21:53:31 +02:00
* \ingroup facture
2011-01-15 15:01:59 +01:00
* \brief Page of a customer payment
2014-09-18 21:18:25 +02:00
* \remarks Nearly same file than fournisseur / paiement / card . php
2009-07-15 21:53:31 +02:00
*/
2004-09-14 22:46:09 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2019-12-18 15:20:36 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php' ;
2013-12-25 02:40:42 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2022-08-29 11:25:14 +02:00
if ( isModEnabled ( 'banque' )) {
2021-02-23 21:09:01 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
}
2004-01-31 18:29:54 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
2019-12-18 15:20:36 +01:00
$langs -> loadLangs ( array ( 'bills' , 'banks' , 'companies' ));
2004-09-14 22:46:09 +02:00
2019-12-18 15:20:36 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2019-12-18 15:20:36 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2017-04-07 14:18:04 +02:00
2021-02-19 12:35:26 +01:00
$object = new Paiement ( $db );
2021-02-19 14:15:58 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'paymentcard' , 'globalcard' ));
2021-02-19 12:35:26 +01:00
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once.
2022-05-22 02:30:35 +02:00
$result = restrictedArea ( $user , $object -> element , $object -> id , 'paiement' );
2021-02-19 12:35:26 +01:00
2017-04-07 14:18:04 +02:00
// Security check
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-02-19 12:35:26 +01:00
// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
// It should be enough because all payments are done on invoices of the same thirdparty.
if ( $socid && $socid != $object -> thirdparty -> id ) {
accessforbidden ();
}
2012-02-20 20:31:35 +01:00
2022-02-28 19:45:53 +01:00
$error = 0 ;
2005-01-11 21:29:43 +01:00
2005-10-15 20:28:21 +02:00
/*
* Actions
*/
2021-02-23 21:09:01 +01:00
if ( $action == 'setnote' && $user -> rights -> facture -> paiement ) {
2020-10-31 14:32:18 +01:00
$db -> begin ();
$result = $object -> update_note ( GETPOST ( 'note' , 'restricthtml' ));
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
$action = '' ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$db -> rollback ();
}
2011-03-06 18:03:27 +01:00
}
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> facture -> paiement ) {
2005-10-15 20:28:21 +02:00
$db -> begin ();
2009-03-02 19:17:19 +01:00
2012-02-20 20:31:35 +01:00
$result = $object -> delete ();
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
2021-02-23 21:09:01 +01:00
if ( $backtopage ) {
2020-10-31 14:32:18 +01:00
header ( " Location: " . $backtopage );
exit ;
} else {
header ( " Location: list.php " );
exit ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$langs -> load ( " errors " );
2015-11-12 11:59:15 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2020-10-31 14:32:18 +01:00
$db -> rollback ();
2005-10-05 03:48:00 +02:00
}
2004-02-10 16:28:00 +01:00
}
2004-12-16 14:26:13 +01:00
2021-02-23 21:09:01 +01:00
if ( $action == 'confirm_validate' && $confirm == 'yes' && $user -> rights -> facture -> paiement ) {
2005-10-15 20:28:21 +02:00
$db -> begin ();
2021-02-23 21:09:01 +01:00
if ( $object -> validate ( $user ) > 0 ) {
2007-05-16 14:05:44 +02:00
$db -> commit ();
2009-03-02 19:17:19 +01:00
2010-08-14 03:42:59 +02:00
// Loop on each invoice linked to this payment to rebuild PDF
2021-04-27 17:43:12 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
$outputlangs = $langs ;
if ( GETPOST ( 'lang_id' , 'aZ09' )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( GETPOST ( 'lang_id' , 'aZ09' ));
}
$hidedetails = ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ;
$hidedesc = ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ;
$hideref = ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ;
$sql = 'SELECT f.rowid as facid' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf,' . MAIN_DB_PREFIX . 'facture as f,' . MAIN_DB_PREFIX . 'societe as s' ;
$sql .= ' WHERE pf.fk_facture = f.rowid' ;
$sql .= ' AND f.fk_soc = s.rowid' ;
$sql .= ' AND f.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2021-08-27 23:36:06 +02:00
$sql .= ' AND pf.fk_paiement = ' . (( int ) $object -> id );
2021-04-27 17:43:12 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$i = 0 ;
$num = $db -> num_rows ( $resql );
if ( $num > 0 ) {
while ( $i < $num ) {
$objp = $db -> fetch_object ( $resql );
$invoice = new Facture ( $db );
if ( $invoice -> fetch ( $objp -> facid ) <= 0 ) {
$errors ++ ;
setEventMessages ( $invoice -> error , $invoice -> errors , 'errors' );
break ;
}
if ( $invoice -> generateDocument ( $invoice -> model_pdf , $outputlangs , $hidedetails , $hidedesc , $hideref ) < 0 ) {
$errors ++ ;
setEventMessages ( $invoice -> error , $invoice -> errors , 'errors' );
break ;
}
$i ++ ;
}
}
$db -> free ( $resql );
} else {
$errors ++ ;
setEventMessages ( $db -> error , $db -> errors , 'errors' );
}
2007-05-16 14:05:44 +02:00
}
2021-04-27 17:43:12 +02:00
if ( ! $errors ) {
2021-04-27 01:58:19 +02:00
header ( 'Location: ' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id );
exit ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-04-27 01:58:19 +02:00
$db -> rollback ();
2021-04-22 15:57:06 +02:00
2020-10-31 14:32:18 +01:00
$langs -> load ( " errors " );
2015-11-12 11:59:15 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2005-10-05 03:48:00 +02:00
}
2004-12-16 14:26:13 +01:00
}
2022-02-22 23:44:56 +01:00
if ( $action == 'setnum_paiement' && GETPOST ( 'num_paiement' )) {
$res = $object -> update_num ( GETPOST ( 'num_paiement' ));
2021-02-23 21:09:01 +01:00
if ( $res === 0 ) {
2015-11-12 11:59:15 +01:00
setEventMessages ( $langs -> trans ( 'PaymentNumberUpdateSucceeded' ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2015-11-12 11:59:15 +01:00
setEventMessages ( $langs -> trans ( 'PaymentNumberUpdateFailed' ), null , 'errors' );
2011-10-01 23:24:39 +02:00
}
}
2022-02-22 23:44:56 +01:00
if ( $action == 'setdatep' && GETPOST ( 'datepday' )) {
2019-01-27 11:55:16 +01:00
$datepaye = dol_mktime ( GETPOST ( 'datephour' , 'int' ), GETPOST ( 'datepmin' , 'int' ), GETPOST ( 'datepsec' , 'int' ), GETPOST ( 'datepmonth' , 'int' ), GETPOST ( 'datepday' , 'int' ), GETPOST ( 'datepyear' , 'int' ));
2012-02-20 20:31:35 +01:00
$res = $object -> update_date ( $datepaye );
2021-02-23 21:09:01 +01:00
if ( $res === 0 ) {
2015-11-12 11:59:15 +01:00
setEventMessages ( $langs -> trans ( 'PaymentDateUpdateSucceeded' ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2015-11-12 11:59:15 +01:00
setEventMessages ( $langs -> trans ( 'PaymentDateUpdateFailed' ), null , 'errors' );
2011-10-01 23:24:39 +02:00
}
}
2022-02-28 19:45:53 +01:00
if ( $action == 'createbankpayment' && ! empty ( $user -> rights -> facture -> paiement )) {
$db -> begin ();
// Create the record into bank for the amount of payment $object
if ( ! $error ) {
$label = '(CustomerInvoicePayment)' ;
if ( GETPOST ( 'type' ) == Facture :: TYPE_CREDIT_NOTE ) {
$label = '(CustomerInvoicePaymentBack)' ; // Refund of a credit note
}
$bankaccountid = GETPOST ( 'accountid' , 'int' );
if ( $bankaccountid > 0 ) {
$object -> paiementcode = $object -> type_code ;
$object -> amounts = $object -> getAmountsArray ();
$result = $object -> addPaymentToBank ( $user , 'payment' , $label , $bankaccountid , '' , '' );
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BankAccount " )), null , 'errors' );
$error ++ ;
}
}
if ( ! $error ) {
$db -> commit ();
} else {
$db -> rollback ();
}
}
2011-10-01 23:24:39 +02:00
2005-01-11 21:29:43 +01:00
2004-01-31 18:29:54 +01:00
/*
2009-08-05 20:22:40 +02:00
* View
2004-01-31 18:29:54 +01:00
*/
2017-04-07 14:18:04 +02:00
llxHeader ( '' , $langs -> trans ( " Payment " ));
2004-01-31 18:29:54 +01:00
2019-12-18 15:20:36 +01:00
$thirdpartystatic = new Societe ( $db );
2011-01-15 15:01:59 +01:00
2019-12-18 15:20:36 +01:00
$result = $object -> fetch ( $id , $ref );
2021-02-23 21:09:01 +01:00
if ( $result <= 0 ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , 'Payement ' . $id . ' not found in database' );
2007-05-24 00:39:14 +02:00
exit ;
}
2005-08-16 21:19:29 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2004-01-31 18:29:54 +01:00
2013-12-25 02:40:42 +01:00
$head = payment_prepare_head ( $object );
2005-08-16 21:19:29 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'payment' , $langs -> trans ( " PaymentCustomerInvoice " ), - 1 , 'payment' );
2004-02-10 16:28:00 +01:00
2020-10-14 18:26:05 +02:00
// Confirmation of payment delete
2021-02-23 21:09:01 +01:00
if ( $action == 'delete' ) {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( " DeletePayment " ), $langs -> trans ( " ConfirmDeletePayment " ), 'confirm_delete' , '' , 0 , 2 );
2005-08-16 21:19:29 +02:00
}
2004-12-16 14:26:13 +01:00
2020-10-14 18:26:05 +02:00
// Confirmation of payment validation
2021-02-23 21:09:01 +01:00
if ( $action == 'valide' ) {
2006-09-13 09:48:41 +02:00
$facid = $_GET [ 'facid' ];
2020-10-15 10:15:37 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&facid=' . $facid , $langs -> trans ( " ValidatePayment " ), $langs -> trans ( " ConfirmValidatePayment " ), 'confirm_validate' , '' , 0 , 2 );
2005-08-16 21:19:29 +02:00
}
2004-02-10 16:28:00 +01:00
2019-12-18 15:20:36 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/paiement/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-02-03 02:29:19 +01:00
2017-04-07 14:18:04 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , '' );
2016-02-03 02:29:19 +01:00
2017-01-22 13:27:17 +01:00
2017-04-07 14:18:04 +02:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' . " \n " ;
2007-11-18 22:07:46 +01:00
2011-10-01 23:24:39 +02:00
// Date payment
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $form -> editfieldkey ( " Date " , 'datep' , $object -> date , $object , $user -> rights -> facture -> paiement ) . '</td><td>' ;
2022-04-08 12:38:49 +02:00
print $form -> editfieldval ( " Date " , 'datep' , $object -> date , $object , $user -> rights -> facture -> paiement , 'datehourpicker' , '' , null , $langs -> trans ( 'PaymentDateUpdateSucceeded' ), '' , 0 , '' , 'id' , 'tzuser' );
2011-10-01 23:24:39 +02:00
print '</td></tr>' ;
2006-11-10 01:28:39 +01:00
2010-08-14 03:42:59 +02:00
// Payment type (VIR, LIQ, ...)
2019-12-18 15:20:36 +01:00
$labeltype = $langs -> trans ( " PaymentType " . $object -> type_code ) != ( " PaymentType " . $object -> type_code ) ? $langs -> trans ( " PaymentType " . $object -> type_code ) : $object -> type_label ;
2019-01-09 13:28:12 +01:00
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td>' . $labeltype ;
2020-04-10 10:59:32 +02:00
print $object -> num_payment ? ' - ' . $object -> num_payment : '' ;
2019-01-09 13:28:12 +01:00
print '</td></tr>' ;
// Amount
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( 'Amount' ) . '</td><td>' . price ( $object -> amount , '' , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2018-03-31 22:44:32 +02:00
$disable_delete = 0 ;
// Bank account
2022-08-29 11:25:14 +02:00
if ( isModEnabled ( 'banque' )) {
2019-12-18 15:20:36 +01:00
$bankline = new AccountLine ( $db );
2018-11-14 18:10:41 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> fk_account > 0 ) {
2018-03-31 22:44:32 +02:00
$bankline -> fetch ( $object -> bank_line );
2021-02-23 21:09:01 +01:00
if ( $bankline -> rappro ) {
2018-03-31 22:44:32 +02:00
$disable_delete = 1 ;
$title_button = dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " CantRemoveConciliatedPayment " ));
}
print '<tr>' ;
print '<td>' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
print '<td>' ;
2019-12-18 15:20:36 +01:00
$accountstatic = new Account ( $db );
2018-03-31 22:44:32 +02:00
$accountstatic -> fetch ( $bankline -> fk_account );
print $accountstatic -> getNomUrl ( 1 );
print '</td>' ;
print '</tr>' ;
}
}
2006-11-10 01:28:39 +01:00
2011-10-01 23:24:39 +02:00
// Payment numero
2018-03-31 22:44:32 +02:00
/*
$titlefield = $langs -> trans ( 'Numero' ) . ' <em>(' . $langs -> trans ( " ChequeOrTransferNumber " ) . ')</em>' ;
print '<tr><td>' . $form -> editfieldkey ( $titlefield , 'num_paiement' , $object -> num_paiement , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer ) . '</td><td>' ;
print $form -> editfieldval ( $titlefield , 'num_paiement' , $object -> num_paiement , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer , 'string' , '' , null , $langs -> trans ( 'PaymentNumberUpdateSucceeded' ));
2011-10-01 23:24:39 +02:00
print '</td></tr>' ;
2006-11-10 01:28:39 +01:00
2018-03-31 22:44:32 +02:00
// Check transmitter
$titlefield = $langs -> trans ( 'CheckTransmitter' ) . ' <em>(' . $langs -> trans ( " ChequeMaker " ) . ')</em>' ;
print '<tr><td>' . $form -> editfieldkey ( $titlefield , 'chqemetteur' , $object -> , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer ) . '</td><td>' ;
print $form -> editfieldval ( $titlefield , 'chqemetteur' , $object -> aaa , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer , 'string' , '' , null , $langs -> trans ( 'ChequeMakeUpdateSucceeded' ));
print '</td></tr>' ;
2006-11-10 01:28:39 +01:00
2018-03-31 22:44:32 +02:00
// Bank name
$titlefield = $langs -> trans ( 'Bank' ) . ' <em>(' . $langs -> trans ( " ChequeBank " ) . ')</em>' ;
print '<tr><td>' . $form -> editfieldkey ( $titlefield , 'chqbank' , $object -> aaa , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer ) . '</td><td>' ;
print $form -> editfieldval ( $titlefield , 'chqbank' , $object -> aaa , $object , $object -> statut == 0 && $user -> rights -> fournisseur -> facture -> creer , 'string' , '' , null , $langs -> trans ( 'ChequeBankUpdateSucceeded' ));
2011-03-06 18:03:27 +01:00
print '</td></tr>' ;
2018-03-31 22:44:32 +02:00
*/
2006-11-10 01:28:39 +01:00
2008-11-15 01:10:42 +01:00
// Bank account
2022-08-29 11:25:14 +02:00
if ( isModEnabled ( 'banque' )) {
2021-01-23 12:16:25 +01:00
if ( $object -> fk_account > 0 ) {
if ( $object -> type_code == 'CHQ' && $bankline -> fk_bordereau > 0 ) {
2022-01-13 11:58:10 +01:00
include_once DOL_DOCUMENT_ROOT . '/compta/paiement/cheque/class/remisecheque.class.php' ;
2013-07-19 09:17:54 +02:00
$bordereau = new RemiseCheque ( $db );
$bordereau -> fetch ( $bankline -> fk_bordereau );
2013-10-16 19:00:00 +02:00
2013-07-19 09:17:54 +02:00
print '<tr>' ;
2018-03-31 22:44:32 +02:00
print '<td>' . $langs -> trans ( 'CheckReceipt' ) . '</td>' ;
print '<td>' ;
2013-07-19 13:39:01 +02:00
print $bordereau -> getNomUrl ( 1 );
2018-03-31 22:44:32 +02:00
print '</td>' ;
print '</tr>' ;
2013-07-19 09:17:54 +02:00
}
2018-03-31 22:44:32 +02:00
}
print '<tr>' ;
print '<td>' . $langs -> trans ( 'BankTransactionLine' ) . '</td>' ;
print '<td>' ;
2021-01-23 12:16:25 +01:00
if ( $object -> fk_account > 0 ) {
print $bankline -> getNomUrl ( 1 , 0 , 'showconciliatedandaccounted' );
} else {
2021-01-23 12:20:18 +01:00
$langs -> load ( " admin " );
2022-02-28 19:45:53 +01:00
print '<span class="opacitymedium">' ;
print $langs -> trans ( " NoRecordFoundIBankcAccount " , $langs -> transnoentitiesnoconv ( " Module85Name " ));
print '</span>' ;
if ( ! empty ( $user -> rights -> facture -> paiement )) {
// Try to guess $bankaccountidofinvoices that is ID of bank account defined on invoice.
// Return null if not found, return 0 if it has different value for at least 2 invoices, return the value if same on all invoices where a bank is defined.
$amountofpayments = $object -> getAmountsArray ();
$bankaccountidofinvoices = null ;
foreach ( $amountofpayments as $idinvoice => $amountofpayment ) {
$tmpinvoice = new Facture ( $db );
$tmpinvoice -> fetch ( $idinvoice );
if ( $tmpinvoice -> fk_account > 0 && $bankaccountidofinvoices !== 0 ) {
if ( is_null ( $bankaccountidofinvoices )) {
$bankaccountidofinvoices = $tmpinvoice -> fk_account ;
} elseif ( $bankaccountidofinvoices != $tmpinvoice -> fk_account ) {
$bankaccountidofinvoices = 0 ;
}
}
}
print '<form method="POST" name="createbankpayment">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="createbankpayment">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print ' ' . $langs -> trans ( " ToCreateRelatedRecordIntoBank " ) . ': ' ;
print $form -> select_comptes ( $bankaccountidofinvoices , 'accountid' , 0 , '' , 2 , '' , 0 , '' , 1 );
//print '<span class="opacitymedium">';
print '<input type="submit" class="button small smallpaddingimp" name="createbankpayment" value="' . $langs -> trans ( " ClickHere " ) . '">' ;
//print '</span>';
print '</form>' ;
}
2021-01-23 12:16:25 +01:00
}
2018-03-31 22:44:32 +02:00
print '</td>' ;
print '</tr>' ;
2008-11-15 01:10:42 +01:00
}
2018-03-31 22:44:32 +02:00
// Comments
2019-01-27 11:55:16 +01:00
print '<tr><td class="tdtop">' . $form -> editfieldkey ( " Comments " , 'note' , $object -> note , $object , $user -> rights -> facture -> paiement ) . '</td><td>' ;
print $form -> editfieldval ( " Note " , 'note' , $object -> note , $object , $user -> rights -> facture -> paiement , 'textarea:' . ROWS_3 . ':90%' );
2018-03-31 22:44:32 +02:00
print '</td></tr>' ;
2005-10-05 03:48:00 +02:00
print '</table>' ;
2004-01-31 18:29:54 +01:00
2017-04-07 14:18:04 +02:00
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-01-22 13:27:17 +01:00
2004-01-31 18:29:54 +01:00
2004-02-10 16:28:00 +01:00
/*
2010-01-15 00:21:22 +01:00
* List of invoices
2004-02-10 16:28:00 +01:00
*/
2010-01-15 00:21:22 +01:00
2020-09-22 16:34:38 +02:00
$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' ;
2019-12-18 15:20:36 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf,' . MAIN_DB_PREFIX . 'facture as f,' . MAIN_DB_PREFIX . 'societe as s' ;
$sql .= ' WHERE pf.fk_facture = f.rowid' ;
$sql .= ' AND f.fk_soc = s.rowid' ;
$sql .= ' AND f.entity IN (' . getEntity ( 'invoice' ) . ')' ;
2021-08-27 23:36:06 +02:00
$sql .= ' AND pf.fk_paiement = ' . (( int ) $object -> id );
2019-12-18 15:20:36 +01:00
$resql = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $resql ) {
2005-10-15 17:32:01 +02:00
$num = $db -> num_rows ( $resql );
2009-03-02 19:17:19 +01:00
2005-10-05 03:48:00 +02:00
$i = 0 ;
$total = 0 ;
2017-12-03 11:59:16 +01:00
2019-12-18 15:20:36 +01:00
$moreforfilter = '' ;
2017-12-03 11:59:16 +01:00
2017-01-22 13:27:17 +01:00
print '<br>' ;
2017-12-03 11:59:16 +01:00
2017-01-22 13:27:17 +01:00
print '<div class="div-table-responsive">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2017-12-03 11:59:16 +01:00
2005-10-05 03:48:00 +02:00
print '<tr class="liste_titre">' ;
2006-04-08 14:52:30 +02:00
print '<td>' . $langs -> trans ( 'Bill' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Company' ) . '</td>' ;
2022-08-29 12:03:25 +02:00
if ( isModEnabled ( 'multicompany' ) && ! empty ( $conf -> global -> MULTICOMPANY_INVOICE_SHARING_ENABLED )) {
2021-02-23 21:09:01 +01:00
print '<td>' . $langs -> trans ( 'Entity' ) . '</td>' ;
}
2019-02-10 11:01:23 +01:00
print '<td class="right">' . $langs -> trans ( 'ExpectedToPay' ) . '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td class="right">' . $langs -> trans ( 'PayedByThisPayment' ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( 'RemainderToPay' ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( 'Status' ) . '</td>' ;
2005-10-05 03:48:00 +02:00
print " </tr> \n " ;
2009-03-02 19:17:19 +01:00
2021-02-23 21:09:01 +01:00
if ( $num > 0 ) {
while ( $i < $num ) {
2005-10-15 17:32:01 +02:00
$objp = $db -> fetch_object ( $resql );
2017-12-03 11:59:16 +01:00
2018-03-07 18:32:25 +01:00
$thirdpartystatic -> fetch ( $objp -> socid );
2019-12-18 15:20:36 +01:00
$invoice = new Facture ( $db );
2018-03-07 18:32:25 +01:00
$invoice -> fetch ( $objp -> facid );
2010-02-10 18:07:25 +01:00
2018-03-07 18:32:25 +01:00
$paiement = $invoice -> getSommePaiement ();
2019-12-18 15:20:36 +01:00
$creditnotes = $invoice -> getSumCreditNotesUsed ();
$deposits = $invoice -> getSumDepositsUsed ();
$alreadypayed = price2num ( $paiement + $creditnotes + $deposits , 'MT' );
$remaintopay = price2num ( $invoice -> total_ttc - $paiement - $creditnotes - $deposits , 'MT' );
2018-03-07 18:32:25 +01:00
print '<tr class="oddeven">' ;
2011-03-19 14:59:04 +01:00
2020-10-31 14:32:18 +01:00
// Invoice
2009-03-02 19:17:19 +01:00
print '<td>' ;
2011-03-19 14:59:04 +01:00
print $invoice -> getNomUrl ( 1 );
2009-03-02 19:17:19 +01:00
print " </td> \n " ;
2010-02-10 18:07:25 +01:00
// Third party
2021-06-20 16:35:49 +02:00
print '<td class="tdoverflowmax150">' ;
2011-01-15 15:01:59 +01:00
print $thirdpartystatic -> getNomUrl ( 1 );
print '</td>' ;
2010-02-10 18:07:25 +01:00
2019-01-16 10:52:46 +01:00
// Expected to pay
2022-08-29 12:03:25 +02:00
if ( isModEnabled ( 'multicompany' ) && ! empty ( $conf -> global -> MULTICOMPANY_INVOICE_SHARING_ENABLED )) {
2018-11-07 16:45:04 +01:00
print '<td>' ;
$mc -> getInfo ( $objp -> entity );
print $mc -> label ;
print '</td>' ;
}
2010-02-10 18:07:25 +01:00
// Expected to pay
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $objp -> total_ttc ) . '</span></td>' ;
2010-02-10 18:07:25 +01:00
2020-10-31 14:32:18 +01:00
// Amount payed
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $objp -> amount ) . '</span></td>' ;
2011-03-19 14:59:04 +01:00
2020-10-31 14:32:18 +01:00
// Remain to pay
2021-03-29 13:00:17 +02:00
print '<td class="right"><span class="amount">' . price ( $remaintopay ) . '</span></td>' ;
2010-02-10 18:07:25 +01:00
2011-03-19 14:59:04 +01:00
// Status
2019-02-10 11:01:23 +01:00
print '<td class="right">' . $invoice -> getLibStatut ( 5 , $alreadypayed ) . '</td>' ;
2010-02-10 18:07:25 +01:00
2005-10-05 03:48:00 +02:00
print " </tr> \n " ;
2021-10-07 10:43:50 +02:00
// If at least one invoice is paid, disable delete. INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED Can be use for maintenance purpose. Never use this in production
if ( $objp -> paye == 1 && empty ( $conf -> global -> INVOICE_CAN_DELETE_PAYMENT_EVEN_IF_INVOICE_CLOSED )) {
2010-01-15 00:21:22 +01:00
$disable_delete = 1 ;
2016-01-09 10:37:53 +01:00
$title_button = dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " CantRemovePaymentWithOneInvoicePaid " ));
2005-10-05 03:48:00 +02:00
}
2021-10-07 10:43:50 +02:00
2005-10-05 03:48:00 +02:00
$total = $total + $objp -> amount ;
$i ++ ;
2009-03-02 19:17:19 +01:00
}
2005-10-05 03:48:00 +02:00
}
2017-12-03 11:59:16 +01:00
2005-10-05 03:48:00 +02:00
print " </table> \n " ;
2017-01-22 13:27:17 +01:00
print '</div>' ;
2017-12-03 11:59:16 +01:00
2009-03-02 19:17:19 +01:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2009-03-02 19:17:19 +01:00
dol_print_error ( $db );
2004-12-28 15:08:50 +01:00
}
2004-02-10 16:28:00 +01:00
2005-07-11 02:49:16 +02:00
2004-02-10 16:28:00 +01:00
/*
2020-10-14 18:26:05 +02:00
* Actions Buttons
2004-02-10 16:28:00 +01:00
*/
2005-07-11 02:49:16 +02:00
2004-12-16 14:26:13 +01:00
print '<div class="tabsAction">' ;
2004-01-31 18:29:54 +01:00
2021-02-23 21:09:01 +01:00
if ( ! empty ( $conf -> global -> BILL_ADD_PAYMENT_VALIDATION )) {
if ( $user -> socid == 0 && $object -> statut == 0 && $_GET [ 'action' ] == '' ) {
if ( $user -> rights -> facture -> paiement ) {
2021-09-18 22:09:55 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $id . '&facid=' . $objp -> facid . '&action=valide&token=' . newToken () . '">' . $langs -> trans ( 'Valid' ) . '</a>' ;
2008-10-29 11:37:36 +01:00
}
2007-02-04 22:23:58 +01:00
}
}
2010-01-15 00:21:22 +01:00
2021-02-23 21:09:01 +01:00
if ( $user -> socid == 0 && $action == '' ) {
if ( $user -> rights -> facture -> paiement ) {
if ( ! $disable_delete ) {
2021-09-18 22:09:55 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . $title_button . '">' . $langs -> trans ( 'Delete' ) . '</a>' ;
2010-01-15 00:21:22 +01:00
}
2007-02-04 22:23:58 +01:00
}
2004-12-16 14:26:13 +01:00
}
2008-10-29 11:37:36 +01:00
2009-03-02 19:17:19 +01:00
print '</div>' ;
2005-07-11 02:49:16 +02:00
2018-08-08 12:29:36 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-02-20 20:31:35 +01:00
$db -> close ();