2005-01-07 14:19:10 +01:00
< ? php
2012-08-16 19:18:24 +02:00
/* Copyright ( C ) 2002 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2018-01-18 18:22:10 +01:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2018-01-18 18:22:10 +01:00
* Copyright ( C ) 2010 - 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2017 Ferran Marcet < fmarcet @ 2 byte . es >
2018-10-27 17:45:29 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2005-01-07 14:19:10 +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
2005-01-07 14:19:10 +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 />.
2005-01-07 14:19:10 +01:00
*/
2005-01-07 22:18:52 +01:00
/**
2008-11-05 23:34:14 +01:00
* \file htdocs / compta / facture / prelevement . php
* \ingroup facture
2020-06-14 21:19:31 +02:00
* \brief Management of direct debit order or credit tranfer of invoices
2008-11-05 23:34:14 +01:00
*/
2005-01-07 14:19:10 +01: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 . '/core/lib/invoice.lib.php' ;
2020-06-22 22:54:33 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php' ;
2020-04-28 02:10:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2020-06-08 11:43:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php' ;
2020-06-22 22:54:33 +02:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2005-01-07 14:19:10 +01:00
2018-05-27 09:27:09 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'bills' , 'banks' , 'withdrawals' , 'companies' ));
2005-01-07 14:19:10 +01:00
2020-04-10 10:59:32 +02:00
$id = ( GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : GETPOST ( 'facid' , 'int' )); // For backward compatibility
$ref = GETPOST ( 'ref' , 'alpha' );
$socid = GETPOST ( 'socid' , 'int' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2020-06-08 11:43:20 +02:00
$type = GETPOST ( 'type' , 'aZ09' );
2020-04-10 10:59:32 +02:00
$fieldid = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2021-02-23 21:09:01 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2005-09-03 14:47:56 +02:00
2021-12-28 18:32:02 +01:00
$moreparam = '' ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$object = new FactureFournisseur ( $db );
2021-12-28 17:40:25 +01:00
$moreparam = '&type=' . $type ;
2020-06-22 22:54:33 +02:00
} else {
$object = new Facture ( $db );
}
2012-05-06 02:27:09 +02:00
2012-08-16 19:18:24 +02:00
// Load object
2021-02-23 21:09:01 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2020-04-10 10:59:32 +02:00
$ret = $object -> fetch ( $id , $ref );
2020-08-07 16:59:27 +02:00
$isdraft = (( $object -> statut == FactureFournisseur :: STATUS_DRAFT ) ? 1 : 0 );
2021-02-23 21:09:01 +01:00
if ( $ret > 0 ) {
2012-08-16 19:18:24 +02:00
$object -> fetch_thirdparty ();
}
}
2005-09-03 14:47:56 +02:00
2020-04-10 10:59:32 +02:00
$hookmanager -> initHooks ( array ( 'directdebitcard' , 'globalcard' ));
2019-07-18 15:40:50 +02:00
2020-08-07 16:59:27 +02:00
if ( $type == 'bank-transfer' ) {
$result = restrictedArea ( $user , 'fournisseur' , $id , 'facture_fourn' , 'facture' , 'fk_soc' , $fieldid , $isdraft );
2021-10-23 07:13:08 +02:00
if ( empty ( $user -> rights -> fournisseur -> facture -> lire )) {
2021-02-23 21:09:01 +01:00
accessforbidden ();
}
2020-08-07 16:59:27 +02:00
} else {
$result = restrictedArea ( $user , 'facture' , $id , '' , '' , 'fk_soc' , $fieldid , $isdraft );
2021-02-23 21:09:01 +01:00
if ( ! $user -> rights -> facture -> lire ) {
accessforbidden ();
}
2020-08-07 16:59:27 +02:00
}
2019-07-18 15:40:50 +02:00
2021-10-11 02:00:12 +02:00
if ( $type == 'bank-transfer' ) {
$usercancreate = ( $user -> rights -> fournisseur -> facture -> creer || $user -> rights -> supplier_invoice -> creer );
} else {
$usercancreate = $user -> rights -> facture -> creer ;
}
2014-12-09 11:19:16 +01:00
2005-09-03 14:47:56 +02:00
/*
* Actions
*/
2008-11-05 23:34:14 +01:00
2019-07-18 15:40:50 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 21:09:01 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2019-07-18 15:40:50 +02:00
2021-02-23 21:09:01 +01:00
if ( empty ( $reshook )) {
2021-10-11 02:00:12 +02:00
if ( $action == " new " && $usercancreate ) {
2021-02-23 21:09:01 +01:00
if ( $object -> id > 0 ) {
2020-10-31 14:32:18 +01:00
$db -> begin ();
$newtype = $type ;
$sourcetype = 'facture' ;
if ( $type == 'bank-transfer' ) {
$sourcetype = 'supplier_invoice' ;
$newtype = 'bank-transfer' ;
}
$result = $object -> demande_prelevement ( $user , price2num ( GETPOST ( 'withdraw_request_amount' , 'alpha' )), $newtype , $sourcetype );
2021-02-23 21:09:01 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
} else {
$db -> rollback ();
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
$action = '' ;
}
2021-10-11 02:00:12 +02:00
if ( $action == " delete " && $usercancreate ) {
2021-02-23 21:09:01 +01:00
if ( $object -> id > 0 ) {
2020-10-31 14:32:18 +01:00
$result = $object -> demande_prelevement_delete ( $user , GETPOST ( 'did' , 'int' ));
2021-02-23 21:09:01 +01:00
if ( $result == 0 ) {
2020-10-31 14:32:18 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id . '&type=' . $type );
exit ;
}
}
}
2021-10-11 02:00:12 +02:00
// payments conditions
if ( $action == 'setconditions' && $usercancreate ) {
$object -> fetch ( $id );
$object -> cond_reglement_code = 0 ; // To clean property
$object -> cond_reglement_id = 0 ; // To clean property
$error = 0 ;
$db -> begin ();
if ( ! $error ) {
$result = $object -> setPaymentTerms ( GETPOST ( 'cond_reglement_id' , 'int' ));
if ( $result < 0 ) {
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
if ( ! $error ) {
$old_date_echeance = $object -> date_echeance ;
$new_date_echeance = $object -> calculate_date_lim_reglement ();
if ( $new_date_echeance > $old_date_echeance ) {
$object -> date_echeance = $new_date_echeance ;
}
if ( $object -> date_echeance < $object -> date ) {
$object -> date_echeance = $object -> date ;
}
$result = $object -> update ( $user );
if ( $result < 0 ) {
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
if ( $error ) {
$db -> rollback ();
} else {
$db -> commit ();
}
} elseif ( $action == 'setmode' && $usercancreate ) {
// payment mode
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
} elseif ( $action == 'setdatef' && $usercancreate ) {
$newdate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'datefmonth' , 'int' ), GETPOST ( 'datefday' , 'int' ), GETPOST ( 'datefyear' , 'int' ), 'tzserver' );
if ( $newdate > ( dol_now ( 'tzuserrel' ) + ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY ) ? 0 : $conf -> global -> INVOICE_MAX_FUTURE_DELAY ))) {
if ( empty ( $conf -> global -> INVOICE_MAX_FUTURE_DELAY )) {
setEventMessages ( $langs -> trans ( " WarningInvoiceDateInFuture " ), null , 'warnings' );
} else {
setEventMessages ( $langs -> trans ( " WarningInvoiceDateTooFarInFuture " ), null , 'warnings' );
}
}
$object -> date = $newdate ;
$date_echence_calc = $object -> calculate_date_lim_reglement ();
if ( ! empty ( $object -> date_echeance ) && $object -> date_echeance < $date_echence_calc ) {
$object -> date_echeance = $date_echence_calc ;
}
if ( $object -> date_echeance && $object -> date_echeance < $object -> date ) {
$object -> date_echeance = $object -> date ;
}
$result = $object -> update ( $user );
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
} elseif ( $action == 'setdate_lim_reglement' && $usercancreate ) {
$object -> date_echeance = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'date_lim_reglementmonth' , 'int' ), GETPOST ( 'date_lim_reglementday' , 'int' ), GETPOST ( 'date_lim_reglementyear' , 'int' ));
if ( ! empty ( $object -> date_echeance ) && $object -> date_echeance < $object -> date ) {
$object -> date_echeance = $object -> date ;
setEventMessages ( $langs -> trans ( " DatePaymentTermCantBeLowerThanObjectDate " ), null , 'warnings' );
}
$result = $object -> update ( $user );
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
}
2005-01-07 16:56:06 +01:00
}
2005-01-07 14:19:10 +01:00
2005-09-03 14:47:56 +02:00
2008-11-05 23:34:14 +01:00
/*
* View
*/
2005-01-07 14:19:10 +01:00
2020-06-22 22:54:33 +02:00
$form = new Form ( $db );
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2009-01-07 16:21:16 +01:00
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2021-12-28 17:40:25 +01:00
$title = $langs -> trans ( 'SupplierInvoice' ) . " - " . $langs -> trans ( 'CreditTransfer' );
2020-06-22 22:54:33 +02:00
$helpurl = " " ;
} else {
$title = $langs -> trans ( 'InvoiceCustomer' ) . " - " . $langs -> trans ( 'StandingOrders' );
$helpurl = " EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes " ;
}
2016-08-31 06:27:35 +02:00
llxHeader ( '' , $title , $helpurl );
2005-01-07 14:19:10 +01:00
2021-02-23 21:09:01 +01:00
if ( $object -> id > 0 ) {
2017-12-18 12:43:03 +01:00
$selleruserevenustamp = $mysoc -> useRevenueStamp ();
2022-05-22 17:09:08 +02:00
$totalpaid = $object -> getSommePaiement ();
2012-08-16 19:18:24 +02:00
$totalcreditnotes = $object -> getSumCreditNotesUsed ();
$totaldeposits = $object -> getSumDepositsUsed ();
2022-05-22 17:09:08 +02:00
//print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
2012-08-16 19:18:24 +02:00
// We can also use bcadd to avoid pb with floating points
// For example print 239.2 - 229.3 - 9.9; does not return 0.
2022-05-22 17:09:08 +02:00
//$resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
2012-08-16 19:18:24 +02:00
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
2022-05-22 17:09:08 +02:00
$resteapayer = price2num ( $object -> total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits , 'MT' );
2012-08-16 19:18:24 +02:00
2021-02-23 21:09:01 +01:00
if ( $object -> paye ) {
$resteapayer = 0 ;
}
2019-11-13 19:35:39 +01:00
$resteapayeraffiche = $resteapayer ;
2012-08-16 19:18:24 +02:00
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2022-10-12 12:14:04 +02:00
if ( ! empty ( $conf -> global -> FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS )) { // Not recommended
2020-06-22 22:54:33 +02:00
$filterabsolutediscount = " fk_invoice_supplier_source IS NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = " fk_invoice_supplier_source IS NOT NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$filterabsolutediscount = " fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%') " ;
$filtercreditnote = " fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%') " ;
}
$absolute_discount = $object -> thirdparty -> getAvailableDiscounts ( '' , $filterabsolutediscount , 0 , 1 );
$absolute_creditnote = $object -> thirdparty -> getAvailableDiscounts ( '' , $filtercreditnote , 0 , 1 );
$absolute_discount = price2num ( $absolute_discount , 'MT' );
$absolute_creditnote = price2num ( $absolute_creditnote , 'MT' );
2018-02-20 12:26:29 +01:00
} else {
2022-10-12 12:14:04 +02:00
if ( ! empty ( $conf -> global -> FACTURE_DEPOSITS_ARE_JUST_PAYMENTS )) { // Not recommended
2020-06-22 22:54:33 +02:00
$filterabsolutediscount = " fk_facture_source IS NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
$filtercreditnote = " fk_facture_source IS NOT NULL " ; // If we want deposit to be substracted to payments only and not to total of final invoice
} else {
$filterabsolutediscount = " fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%') " ;
$filtercreditnote = " fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%') " ;
}
2018-02-20 12:26:29 +01:00
2020-06-22 22:54:33 +02:00
$absolute_discount = $object -> thirdparty -> getAvailableDiscounts ( '' , $filterabsolutediscount );
$absolute_creditnote = $object -> thirdparty -> getAvailableDiscounts ( '' , $filtercreditnote );
$absolute_discount = price2num ( $absolute_discount , 'MT' );
$absolute_creditnote = price2num ( $absolute_creditnote , 'MT' );
}
2012-08-16 19:18:24 +02:00
$author = new User ( $db );
2022-05-20 17:51:16 +02:00
if ( $object -> fk_user_author ) {
$author -> fetch ( $object -> fk_user_author );
2012-08-16 19:18:24 +02:00
}
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$head = facturefourn_prepare_head ( $object );
} else {
$head = facture_prepare_head ( $object );
}
2012-08-16 19:18:24 +02:00
2021-10-11 01:23:00 +02:00
$numopen = 0 ;
$pending = 0 ;
$numclosed = 0 ;
// How many Direct debit or Credit transfer open requests ?
$sql = " SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande " ;
$sql .= " , pfd.date_traite as date_traite " ;
$sql .= " , pfd.amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
if ( $type == 'bank-transfer' ) {
$sql .= " WHERE fk_facture_fourn = " . (( int ) $object -> id );
} else {
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
}
$sql .= " AND pfd.traite = 0 " ;
$sql .= " AND pfd.ext_payment_id IS NULL " ;
$sql .= " ORDER BY pfd.date_demande DESC " ;
2022-05-15 22:29:19 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$num = $db -> num_rows ( $resql );
2021-10-11 01:23:00 +02:00
$numopen = $num ;
} else {
dol_print_error ( $db );
}
2020-12-23 23:16:27 +01:00
print dol_get_fiche_head ( $head , 'standingorders' , $title , - 1 , ( $type == 'bank-transfer' ? 'supplier_invoice' : 'bill' ));
2012-08-16 19:18:24 +02:00
2016-12-11 13:16:21 +01:00
// Invoice content
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
} else {
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
}
2012-08-16 19:18:24 +02:00
2020-04-10 10:59:32 +02:00
$morehtmlref = '<div class="refidno">' ;
2016-12-11 13:16:21 +01:00
// Ref customer
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , null , null , '' , 1 );
} else {
$morehtmlref .= $form -> editfieldkey ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , 0 , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , 0 , 'string' , '' , null , null , '' , 1 );
}
2016-12-11 13:16:21 +01:00
// Thirdparty
2020-04-10 10:59:32 +02:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) {
$morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?socid=' . $object -> thirdparty -> id . '&search_company=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherBills " ) . '</a>)' ;
}
2020-06-22 22:54:33 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) {
$morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?socid=' . $object -> thirdparty -> id . '&search_company=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherBills " ) . '</a>)' ;
}
2020-06-22 22:54:33 +02:00
}
2016-12-11 13:16:21 +01:00
// Project
2022-08-29 11:24:40 +02:00
if ( isModEnabled ( 'project' )) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2022-06-02 11:11:28 +02:00
if ( $usercancreate ) {
2020-10-31 14:32:18 +01:00
if ( $action != 'classify' ) {
2022-06-02 11:11:28 +02:00
//$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
2020-04-10 10:59:32 +02:00
$morehtmlref .= ' : ' ;
2019-10-26 18:13:20 +02:00
}
2020-10-31 14:32:18 +01:00
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= '<input type="hidden" name="type" value="' . $type . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2020-10-31 14:32:18 +01:00
} else {
$morehtmlref .= '' ;
}
}
2012-08-16 19:18:24 +02:00
}
2020-04-10 10:59:32 +02:00
$morehtmlref .= '</div>' ;
2012-08-16 19:18:24 +02:00
2022-05-22 17:09:08 +02:00
$object -> totalpaid = $totalpaid ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2012-08-16 19:18:24 +02:00
2021-12-28 17:40:25 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , $moreparam , 0 , '' , '' );
2016-12-11 13:16:21 +01:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2020-01-20 12:39:25 +01:00
print '<table class="border centpercent tableforfield">' ;
2012-08-16 19:18:24 +02:00
// Type
2022-06-02 11:11:28 +02:00
print '<tr><td class="titlefield fieldname_type">' . $langs -> trans ( 'Type' ) . '</td><td colspan="3">' ;
2021-02-05 12:07:39 +01:00
print '<span class="badgeneutral">' ;
2012-08-16 19:18:24 +02:00
print $object -> getLibType ();
2021-02-05 12:07:39 +01:00
print '</span>' ;
2020-06-22 22:54:33 +02:00
if ( $object -> module_source ) {
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">(' . $langs -> trans ( " POS " ) . ' ' . $object -> module_source . ' - ' . $langs -> trans ( " Terminal " ) . ' ' . $object -> pos_source . ')</span>' ;
2020-06-22 22:54:33 +02:00
}
2021-02-23 21:09:01 +01:00
if ( $object -> type == $object :: TYPE_REPLACEMENT ) {
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$facreplaced = new FactureFournisseur ( $db );
} else {
$facreplaced = new Facture ( $db );
}
2012-08-16 19:18:24 +02:00
$facreplaced -> fetch ( $object -> fk_facture_source );
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " ReplaceInvoice " , $facreplaced -> getNomUrl ( 1 )) . '</span>' ;
2012-08-16 19:18:24 +02:00
}
2022-06-02 11:11:28 +02:00
if ( $object -> type == $object :: TYPE_CREDIT_NOTE && ! empty ( $object -> fk_facture_source )) {
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$facusing = new FactureFournisseur ( $db );
} else {
$facusing = new Facture ( $db );
}
2012-08-16 19:18:24 +02:00
$facusing -> fetch ( $object -> fk_facture_source );
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " CorrectInvoice " , $facusing -> getNomUrl ( 1 )) . '</span>' ;
2012-08-16 19:18:24 +02:00
}
2019-11-13 19:35:39 +01:00
$facidavoir = $object -> getListIdAvoirFromInvoice ();
2021-02-23 21:09:01 +01:00
if ( count ( $facidavoir ) > 0 ) {
2021-05-07 21:28:35 +02:00
$invoicecredits = array ();
foreach ( $facidavoir as $facid ) {
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$facavoir = new FactureFournisseur ( $db );
} else {
$facavoir = new Facture ( $db );
}
2021-05-07 21:28:35 +02:00
$facavoir -> fetch ( $facid );
$invoicecredits [] = $facavoir -> getNomUrl ( 1 );
2012-08-16 19:18:24 +02:00
}
2022-06-02 11:11:28 +02:00
print ' <span class="opacitymediumbycolor paddingleft">' . $langs -> transnoentities ( " InvoiceHasAvoir " );
print ' ' . ( count ( $invoicecredits ) ? ' ' : '' ) . implode ( ',' , $invoicecredits );
print '</span>' ;
2012-08-16 19:18:24 +02:00
}
/*
2022-06-02 11:11:28 +02:00
if ( $objectidnext > 0 ) {
2012-08-16 19:18:24 +02:00
$facthatreplace = new Facture ( $db );
2022-06-02 11:11:28 +02:00
$facthatreplace -> fetch ( $objectidnext );
print ' <span class="opacitymediumbycolor paddingleft">' . str_replace ( '{s1}' , $facthatreplace -> getNomUrl ( 1 ), $langs -> transnoentities ( " ReplacedByInvoice " , '{s1}' )) . '</span>' ;
2012-08-16 19:18:24 +02:00
}
*/
print '</td></tr>' ;
2022-06-02 11:11:28 +02:00
// Relative and absolute discounts
print '<!-- Discounts -->' . " \n " ;
print '<tr><td>' . $langs -> trans ( 'DiscountStillRemaining' ) . '</td><td colspan="3">' ;
2018-03-02 16:48:25 +01:00
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
//$societe = new Fournisseur($db);
//$result = $societe->fetch($object->socid);
$thirdparty = $object -> thirdparty ;
$discount_type = 1 ;
} else {
$thirdparty = $object -> thirdparty ;
$discount_type = 0 ;
}
2019-11-13 19:35:39 +01:00
$backtopage = urlencode ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id );
2018-03-02 16:48:25 +01:00
$cannotApplyDiscount = 1 ;
include DOL_DOCUMENT_ROOT . '/core/tpl/object_discounts.tpl.php' ;
2012-08-16 19:18:24 +02:00
print '</td></tr>' ;
2020-06-22 22:54:33 +02:00
// Label
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
print '<tr>' ;
print '<td>' . $form -> editfieldkey ( " Label " , 'label' , $object -> label , $object , 0 ) . '</td>' ;
print '<td>' . $form -> editfieldval ( " Label " , 'label' , $object -> label , $object , 0 ) . '</td>' ;
print '</tr>' ;
}
2012-08-16 19:18:24 +02:00
// Date invoice
print '<tr><td>' ;
2020-01-20 12:39:25 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2016-08-31 06:27:35 +02:00
print $langs -> trans ( 'DateInvoice' );
2012-08-16 19:18:24 +02:00
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty ( $object -> brouillon ) && $user -> rights -> facture -> creer ) {
2021-10-11 01:27:21 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editinvoicedate&token=' . newToken () . '&id=' . $object -> id . '&type=' . urlencode ( $type ) . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2012-08-16 19:18:24 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE ) {
if ( $action == 'editinvoicedate' ) {
2021-10-11 01:43:36 +02:00
print $form -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> date , 'invoicedate' , 0 , 0 , 1 , $type );
2020-05-21 15:05:19 +02:00
} else {
2020-06-22 22:54:33 +02:00
print dol_print_date ( $object -> date , 'day' );
2012-08-16 19:18:24 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-06-22 22:54:33 +02:00
print dol_print_date ( $object -> date , 'day' );
2012-08-16 19:18:24 +02:00
}
print '</td>' ;
print '</tr>' ;
2015-06-21 17:05:49 +02:00
// Payment condition
2012-08-16 19:18:24 +02:00
print '<tr><td>' ;
2020-01-20 12:39:25 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2014-12-09 11:19:16 +01:00
print $langs -> trans ( 'PaymentConditionsShort' );
2012-08-16 19:18:24 +02:00
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty ( $object -> brouillon ) && $user -> rights -> facture -> creer ) {
2021-10-11 01:27:21 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&token=' . newToken () . '&id=' . $object -> id . '&type=' . urlencode ( $type ) . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2012-08-16 19:18:24 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE ) {
if ( $action == 'editconditions' ) {
2021-10-11 01:43:36 +02:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> cond_reglement_id , 'cond_reglement_id' , 0 , $type );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
$form -> form_conditions_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> cond_reglement_id , 'none' );
2012-08-16 19:18:24 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2012-08-16 19:18:24 +02:00
print ' ' ;
}
print '</td></tr>' ;
2014-12-09 11:19:16 +01:00
// Date payment term
2012-08-16 19:18:24 +02:00
print '<tr><td>' ;
2020-01-20 12:39:25 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2014-12-09 11:19:16 +01:00
print $langs -> trans ( 'DateMaxPayment' );
2012-08-16 19:18:24 +02:00
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && ! empty ( $object -> brouillon ) && $user -> rights -> facture -> creer ) {
2021-10-11 01:27:21 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editpaymentterm&token=' . newToken () . '&id=' . $object -> id . '&type=' . urlencode ( $type ) . '">' . img_edit ( $langs -> trans ( 'SetDate' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2012-08-16 19:18:24 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2021-02-23 21:09:01 +01:00
if ( $object -> type != $object :: TYPE_CREDIT_NOTE ) {
2020-06-22 22:54:33 +02:00
$duedate = $object -> date_lim_reglement ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$duedate = $object -> date_echeance ;
}
2021-02-23 21:09:01 +01:00
if ( $action == 'editpaymentterm' ) {
2021-10-11 01:43:36 +02:00
print $form -> form_date ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $duedate , 'paymentterm' , 0 , 0 , 1 , $type );
2020-05-21 15:05:19 +02:00
} else {
2020-06-22 22:54:33 +02:00
print dol_print_date ( $duedate , 'day' );
2015-09-05 10:56:13 +02:00
if ( $object -> hasDelay ()) {
print img_warning ( $langs -> trans ( 'Late' ));
}
2012-08-16 19:18:24 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2012-08-16 19:18:24 +02:00
print ' ' ;
}
print '</td></tr>' ;
2014-12-09 11:19:16 +01:00
// Payment mode
2012-08-16 19:18:24 +02:00
print '<tr><td>' ;
2020-01-20 12:39:25 +01:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2012-08-16 19:18:24 +02:00
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $action != 'editmode' && ! empty ( $object -> brouillon ) && $user -> rights -> facture -> creer ) {
2021-10-11 01:27:21 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&token=' . newToken () . '&id=' . $object -> id . '&type=' . urlencode ( $type ) . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2012-08-16 19:18:24 +02:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2021-10-11 01:43:36 +02:00
$filtertype = 'CRDT' ;
if ( $type == 'bank-transfer' ) {
$filtertype = 'DBIT' ;
}
2021-02-23 21:09:01 +01:00
if ( $action == 'editmode' ) {
2021-10-11 01:43:36 +02:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'mode_reglement_id' , $filtertype , 1 , 0 , $type );
2020-05-21 15:05:19 +02:00
} else {
2015-06-21 17:05:49 +02:00
$form -> form_modes_reglement ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> mode_reglement_id , 'none' );
2012-08-16 19:18:24 +02:00
}
print '</td></tr>' ;
2014-12-09 11:19:16 +01:00
// Bank Account
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
print $langs -> trans ( 'BankAccount' );
print '<td>' ;
2021-02-23 21:09:01 +01:00
if (( $action != 'editbankaccount' ) && $user -> rights -> commande -> creer && ! empty ( $object -> brouillon )) {
2021-10-11 01:27:21 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editbankaccount&token=' . newToken () . '&id=' . $object -> id . '&type=' . urlencode ( $type ) . '">' . img_edit ( $langs -> trans ( 'SetBankAccount' ), 1 ) . '</a></td>' ;
2021-02-23 21:09:01 +01:00
}
2014-12-09 11:19:16 +01:00
print '</tr></table>' ;
print '</td><td colspan="3">' ;
2021-02-23 21:09:01 +01:00
if ( $action == 'editbankaccount' ) {
2020-10-31 14:32:18 +01:00
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'fk_account' , 1 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$form -> formSelectAccount ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> fk_account , 'none' );
2014-12-09 11:19:16 +01:00
}
print " </td> " ;
print '</tr>' ;
2015-06-05 14:46:30 +02:00
2021-08-02 17:56:58 +02:00
// IBAN of seller or supplier
2020-06-24 19:59:06 +02:00
$title = 'CustomerIBAN' ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-24 19:59:06 +02:00
$title = 'SupplierIBAN' ;
}
print '<tr><td>' . $langs -> trans ( $title ) . '</td><td colspan="3">' ;
2020-06-08 11:43:20 +02:00
$bac = new CompanyBankAccount ( $db );
$bac -> fetch ( 0 , $object -> thirdparty -> id );
print $bac -> iban . (( $bac -> iban && $bac -> bic ) ? ' / ' : '' ) . $bac -> bic ;
2020-06-24 19:59:06 +02:00
if ( ! empty ( $bac -> iban )) {
2021-02-23 21:09:01 +01:00
if ( $bac -> verif () <= 0 ) {
print img_warning ( 'Error on default bank number for IBAN : ' . $bac -> error_message );
}
2020-06-24 19:59:06 +02:00
} else {
2021-10-11 01:49:50 +02:00
if ( $numopen || ( $type != 'bank-transfer' && $object -> mode_reglement_code == 'PRE' ) || ( $type == 'bank-transfer' && $object -> mode_reglement_code == 'VIR' )) {
2021-10-11 01:23:00 +02:00
print img_warning ( $langs -> trans ( " NoDefaultIBANFound " ));
}
2020-06-24 19:59:06 +02:00
}
2020-06-08 11:43:20 +02:00
2016-12-11 13:16:21 +01:00
print '</td></tr>' ;
2017-10-03 14:50:52 +02:00
2016-12-11 13:16:21 +01:00
print '</table>' ;
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-10-03 14:50:52 +02:00
2020-01-20 12:39:25 +01:00
print '<table class="border centpercent tableforfield">' ;
2017-10-03 14:50:52 +02:00
2022-08-29 12:02:55 +02:00
if ( isModEnabled ( 'multicurrency' ) && ( $object -> multicurrency_code != $conf -> currency )) {
2020-10-31 14:32:18 +01:00
// Multicurrency Amount HT
print '<tr><td class="titlefieldmiddle">' . $form -> editfieldkey ( 'MulticurrencyAmountHT' , 'multicurrency_total_ht' , '' , $object , 0 ) . '</td>' ;
print '<td class="nowrap">' . price ( $object -> multicurrency_total_ht , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
print '</tr>' ;
2017-10-03 14:50:52 +02:00
2020-10-31 14:32:18 +01:00
// Multicurrency Amount VAT
print '<tr><td>' . $form -> editfieldkey ( 'MulticurrencyAmountVAT' , 'multicurrency_total_tva' , '' , $object , 0 ) . '</td>' ;
print '<td class="nowrap">' . price ( $object -> multicurrency_total_tva , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
print '</tr>' ;
2017-10-03 14:50:52 +02:00
2020-10-31 14:32:18 +01:00
// Multicurrency Amount TTC
print '<tr><td>' . $form -> editfieldkey ( 'MulticurrencyAmountTTC' , 'multicurrency_total_ttc' , '' , $object , 0 ) . '</td>' ;
print '<td class="nowrap">' . price ( $object -> multicurrency_total_ttc , '' , $langs , 0 , - 1 , - 1 , ( ! empty ( $object -> multicurrency_code ) ? $object -> multicurrency_code : $conf -> currency )) . '</td>' ;
print '</tr>' ;
2016-12-11 13:16:21 +01:00
}
// Amount
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '<td class="nowrap">' . price ( $object -> total_ht , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-12-11 13:16:21 +01:00
// Vat
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td colspan="3" class="nowrap">' . price ( $object -> total_tva , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2016-12-11 13:16:21 +01:00
print '</tr>' ;
2012-08-16 19:18:24 +02:00
// Amount Local Taxes
2021-02-23 21:09:01 +01:00
if (( $mysoc -> localtax1_assuj == " 1 " && $mysoc -> useLocalTax ( 1 )) || $object -> total_localtax1 != 0 ) { // Localtax1
2020-10-31 14:32:18 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td>' ;
print '<td class="nowrap">' . price ( $object -> total_localtax1 , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2014-07-04 13:44:26 +02:00
}
2021-02-23 21:09:01 +01:00
if (( $mysoc -> localtax2_assuj == " 1 " && $mysoc -> useLocalTax ( 2 )) || $object -> total_localtax2 != 0 ) { // Localtax2
2020-10-31 14:32:18 +01:00
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td>' ;
print '<td class=nowrap">' . price ( $object -> total_localtax2 , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2012-08-16 19:18:24 +02:00
}
2014-09-04 15:14:30 +02:00
2016-12-11 13:16:21 +01:00
// Revenue stamp
2021-02-23 21:09:01 +01:00
if ( $selleruserevenustamp ) { // Test company use revenue stamp
2020-10-31 14:32:18 +01:00
print '<tr><td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'RevenueStamp' );
print '</td>' ;
2021-02-23 21:09:01 +01:00
if ( $action != 'editrevenuestamp' && ! empty ( $object -> brouillon ) && $user -> rights -> facture -> creer ) {
2021-09-27 12:24:01 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=editrevenuestamp&token=' . newToken () . '&facid=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetRevenuStamp' ), 1 ) . '</a></td>' ;
2020-10-31 14:32:18 +01:00
}
print '</tr></table>' ;
print '</td><td>' ;
2021-02-23 21:09:01 +01:00
print price ( $object -> revenuestamp , 1 , '' , 1 , - 1 , - 1 , $conf -> currency );
2020-10-31 14:32:18 +01:00
print '</td></tr>' ;
2016-12-11 13:16:21 +01:00
}
2012-08-16 19:18:24 +02:00
2016-12-11 13:16:21 +01:00
// Total with tax
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td class="nowrap">' . price ( $object -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2012-08-16 19:18:24 +02:00
2022-05-22 17:09:08 +02:00
$resteapayer = price2num ( $object -> total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits , 'MT' );
2013-05-01 20:40:29 +02:00
2020-10-31 14:32:18 +01:00
// TODO Replace this by an include with same code to show already done payment visible in invoice card
print '<tr><td>' . $langs -> trans ( 'RemainderToPay' ) . '</td><td class="nowrap">' . price ( $resteapayer , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2017-10-03 14:50:52 +02:00
2012-08-16 19:18:24 +02:00
print '</table>' ;
2017-10-03 14:50:52 +02:00
2016-12-11 13:16:21 +01:00
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2017-10-03 14:50:52 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2012-08-16 19:18:24 +02:00
2020-06-08 11:43:20 +02:00
// For which amount ?
2018-01-18 18:22:10 +01:00
$sql = " SELECT SUM(pfd.amount) as amount " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture_fourn = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
} else {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
}
2018-01-18 18:22:10 +01:00
$sql .= " AND pfd.traite = 0 " ;
2020-06-14 21:46:32 +02:00
$sql .= " AND pfd.ext_payment_id IS NULL " ;
2018-01-18 18:22:10 +01:00
2022-05-15 22:29:19 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
2021-02-23 21:09:01 +01:00
if ( $obj ) {
$pending = $obj -> amount ;
}
2020-05-21 15:05:19 +02:00
} else {
2018-01-18 18:22:10 +01:00
dol_print_error ( $db );
}
2012-08-16 19:18:24 +02:00
/*
* Buttons
2014-09-04 15:14:30 +02:00
*/
2018-01-18 18:22:10 +01:00
2012-08-16 19:18:24 +02:00
print " \n <div class= \" tabsAction \" > \n " ;
2020-06-22 22:54:33 +02:00
$buttonlabel = $langs -> trans ( " MakeWithdrawRequest " );
2020-12-01 02:41:19 +01:00
$user_perms = $user -> rights -> prelevement -> bons -> creer ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
$buttonlabel = $langs -> trans ( " MakeBankTransferOrder " );
2020-12-01 02:41:19 +01:00
$user_perms = $user -> rights -> paymentbybanktransfer -> create ;
2020-06-22 22:54:33 +02:00
}
2017-12-10 15:24:47 +01:00
// Add a transfer request
2021-02-23 21:09:01 +01:00
if ( $object -> statut > $object :: STATUS_DRAFT && $object -> paye == 0 && $num == 0 ) {
if ( $resteapayer > 0 ) {
if ( $user_perms ) {
2020-10-31 14:32:18 +01:00
$remaintopaylesspendingdebit = $resteapayer - $pending ;
print '<form method="POST" action="">' ;
print '<input type="hidden" name="token" value="' . newToken () . '" />' ;
print '<input type="hidden" name="id" value="' . $object -> id . '" />' ;
print '<input type="hidden" name="type" value="' . $type . '" />' ;
print '<input type="hidden" name="action" value="new" />' ;
print '<label for="withdraw_request_amount">' . $langs -> trans ( 'BankTransferAmount' ) . ' </label>' ;
print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="' . $remaintopaylesspendingdebit . '" size="9" />' ;
print '<input type="submit" class="butAction" value="' . $buttonlabel . '" />' ;
print '</form>' ;
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $buttonlabel . '</a>' ;
}
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " AmountMustBePositive " )) . '">' . $buttonlabel . '</a>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 21:09:01 +01:00
if ( $num == 0 ) {
if ( $object -> statut > $object :: STATUS_DRAFT ) {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " AlreadyPaid " )) . '">' . $buttonlabel . '</a>' ;
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " Draft " )) . '">' . $buttonlabel . '</a>' ;
}
2020-06-23 11:38:20 +02:00
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " RequestAlreadyDone " )) . '">' . $buttonlabel . '</a>' ;
2014-09-04 15:14:30 +02:00
}
2012-09-16 22:45:58 +02:00
}
2012-08-16 19:18:24 +02:00
print " </div><br> \n " ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
print '<div class="opacitymedium">' . $langs -> trans ( " DoCreditTransferBeforePayments " ) . '</div><br>' ;
} else {
print '<div class="opacitymedium">' . $langs -> trans ( " DoStandingOrdersBeforePayments " ) . '</div><br>' ;
}
2012-08-16 19:18:24 +02:00
/*
* Withdrawals
2017-11-24 14:23:25 +01:00
*/
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2012-08-16 19:18:24 +02:00
print '<tr class="liste_titre">' ;
2019-01-18 10:10:39 +01:00
print '<td class="left">' . $langs -> trans ( " DateRequest " ) . '</td>' ;
2019-12-12 10:31:08 +01:00
print '<td class="center">' . $langs -> trans ( " User " ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( " Amount " ) . '</td>' ;
2020-07-01 14:19:47 +02:00
if ( $type == 'bank-transfer' ) {
2020-06-22 22:54:33 +02:00
print '<td class="center">' . $langs -> trans ( " BankTransferReceipt " ) . '</td>' ;
} else {
print '<td class="center">' . $langs -> trans ( " WithdrawalReceipt " ) . '</td>' ;
}
2015-06-21 17:05:49 +02:00
print '<td> </td>' ;
2019-12-12 10:31:08 +01:00
print '<td class="center">' . $langs -> trans ( " DateProcess " ) . '</td>' ;
2015-06-21 17:05:49 +02:00
print '<td> </td>' ;
2012-08-16 19:18:24 +02:00
print '</tr>' ;
2020-06-08 11:43:20 +02:00
$sql = " SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande, " ;
$sql .= " pfd.date_traite as date_traite, pfd.amount, " ;
2020-07-01 14:19:47 +02:00
$sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status " ;
2019-11-13 19:35:39 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on pfd.fk_user_demande = u.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons " ;
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture_fourn = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
} else {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
}
2019-11-13 19:35:39 +01:00
$sql .= " AND pfd.traite = 0 " ;
2020-06-14 21:46:32 +02:00
$sql .= " AND pfd.ext_payment_id IS NULL " ;
2019-11-13 19:35:39 +01:00
$sql .= " ORDER BY pfd.date_demande DESC " ;
2018-01-18 18:22:10 +01:00
2022-05-15 22:29:19 +02:00
$resql = $db -> query ( $sql );
2018-01-18 18:22:10 +01:00
$num = 0 ;
2022-05-15 22:29:19 +02:00
if ( $resql ) {
2012-08-16 19:18:24 +02:00
$i = 0 ;
2020-07-01 14:19:47 +02:00
$tmpuser = new User ( $db );
2018-01-18 18:22:10 +01:00
$num = $db -> num_rows ( $result );
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2022-05-15 22:29:19 +02:00
$obj = $db -> fetch_object ( $resql );
2017-10-03 14:50:52 +02:00
2020-07-01 14:19:47 +02:00
$tmpuser -> id = $obj -> user_id ;
$tmpuser -> login = $obj -> login ;
$tmpuser -> ref = $obj -> login ;
$tmpuser -> email = $obj -> email ;
$tmpuser -> lastname = $obj -> lastname ;
$tmpuser -> firstname = $obj -> firstname ;
$tmpuser -> statut = $obj -> user_status ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2020-07-01 14:19:47 +02:00
2020-06-24 19:59:06 +02:00
print '<td class="left">' . dol_print_date ( $db -> jdate ( $obj -> date_demande ), 'dayhour' ) . " </td> \n " ;
2020-07-01 14:19:47 +02:00
print '<td align="center">' ;
print $tmpuser -> getNomUrl ( 1 , '' , 0 , 0 , 0 , 0 , 'login' );
print '</td>' ;
2019-12-12 10:31:08 +01:00
print '<td class="center">' . price ( $obj -> amount ) . '</td>' ;
2012-08-16 19:18:24 +02:00
print '<td align="center">-</td>' ;
print '<td> </td>' ;
2015-06-21 17:05:49 +02:00
2019-12-12 10:31:08 +01:00
print '<td class="center">' . $langs -> trans ( " OrderWaiting " ) . '</td>' ;
2015-06-21 17:05:49 +02:00
2019-02-10 10:23:37 +01:00
print '<td class="right">' ;
2020-10-01 10:50:54 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '&did=' . $obj -> rowid . '&type=' . $type . '">' ;
2012-08-16 19:18:24 +02:00
print img_delete ();
print '</a></td>' ;
2015-06-21 17:05:49 +02:00
2012-08-16 19:18:24 +02:00
print " </tr> \n " ;
$i ++ ;
}
2022-05-15 22:29:19 +02:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2012-08-16 19:18:24 +02:00
dol_print_error ( $db );
}
2017-10-03 14:50:52 +02:00
2018-01-18 18:22:10 +01:00
// Past requests
$sql = " SELECT pfd.rowid, pfd.traite, pfd.date_demande, pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount, " ;
2019-11-13 19:35:39 +01:00
$sql .= " pb.ref, " ;
2020-07-01 14:19:47 +02:00
$sql .= " u.rowid as user_id, u.email, u.lastname, u.firstname, u.login, u.statut as user_status " ;
2019-11-13 19:35:39 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " prelevement_facture_demande as pfd " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on pfd.fk_user_demande = u.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " prelevement_bons as pb ON pb.rowid = pfd.fk_prelevement_bons " ;
2020-06-08 11:43:20 +02:00
if ( $type == 'bank-transfer' ) {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture_fourn = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
} else {
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_facture = " . (( int ) $object -> id );
2020-06-08 11:43:20 +02:00
}
2019-11-13 19:35:39 +01:00
$sql .= " AND pfd.traite = 1 " ;
2020-06-14 21:46:32 +02:00
$sql .= " AND pfd.ext_payment_id IS NULL " ;
2019-11-13 19:35:39 +01:00
$sql .= " ORDER BY pfd.date_demande DESC " ;
2012-08-16 19:18:24 +02:00
$result = $db -> query ( $sql );
2021-02-23 21:09:01 +01:00
if ( $result ) {
2012-08-16 19:18:24 +02:00
$num = $db -> num_rows ( $result );
2017-11-25 23:26:14 +01:00
$numclosed = $num ;
2012-08-16 19:18:24 +02:00
$i = 0 ;
2020-07-01 14:19:47 +02:00
$tmpuser = new User ( $db );
2021-02-23 21:09:01 +01:00
while ( $i < $num ) {
2012-08-16 19:18:24 +02:00
$obj = $db -> fetch_object ( $result );
2017-10-03 14:50:52 +02:00
2020-07-01 14:19:47 +02:00
$tmpuser -> id = $obj -> user_id ;
$tmpuser -> login = $obj -> login ;
$tmpuser -> ref = $obj -> login ;
$tmpuser -> email = $obj -> email ;
$tmpuser -> lastname = $obj -> lastname ;
$tmpuser -> firstname = $obj -> firstname ;
$tmpuser -> statut = $obj -> user_status ;
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2012-08-16 19:18:24 +02:00
2019-01-27 11:55:16 +01:00
print '<td class="left">' . dol_print_date ( $db -> jdate ( $obj -> date_demande ), 'day' ) . " </td> \n " ;
2012-08-16 19:18:24 +02:00
2020-07-01 14:19:47 +02:00
print '<td align="center">' ;
print $tmpuser -> getNomUrl ( 1 , '' , 0 , 0 , 0 , 0 , 'login' );
print '</td>' ;
2012-08-16 19:18:24 +02:00
2019-12-12 10:31:08 +01:00
print '<td class="center">' . price ( $obj -> amount ) . '</td>' ;
2012-08-16 19:18:24 +02:00
2019-12-12 10:31:08 +01:00
print '<td class="center">' ;
2021-02-23 21:09:01 +01:00
if ( $obj -> fk_prelevement_bons > 0 ) {
2019-11-13 19:35:39 +01:00
$withdrawreceipt = new BonPrelevement ( $db );
$withdrawreceipt -> id = $obj -> fk_prelevement_bons ;
$withdrawreceipt -> ref = $obj -> ref ;
2018-01-18 18:22:10 +01:00
print $withdrawreceipt -> getNomUrl ( 1 );
}
2012-08-16 19:18:24 +02:00
print " </td> \n " ;
print '<td> </td>' ;
2015-06-21 17:05:49 +02:00
2019-12-12 10:31:08 +01:00
print '<td class="center">' . dol_print_date ( $db -> jdate ( $obj -> date_traite ), 'day' ) . " </td> \n " ;
2015-06-21 17:05:49 +02:00
2012-08-16 19:18:24 +02:00
print '<td> </td>' ;
print " </tr> \n " ;
$i ++ ;
}
2017-11-25 23:26:14 +01:00
2021-02-23 21:09:01 +01:00
if ( ! $numopen && ! $numclosed ) {
2022-04-11 19:21:04 +02:00
print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span></td></tr>' ;
2021-02-23 21:09:01 +01:00
}
2017-11-25 23:26:14 +01:00
2012-08-16 19:18:24 +02:00
$db -> free ( $result );
2020-05-21 15:05:19 +02:00
} else {
2012-08-16 19:18:24 +02:00
dol_print_error ( $db );
}
print " </table> " ;
2017-11-24 14:23:25 +01:00
print '</div>' ;
2008-11-05 23:34:14 +01:00
}
2005-01-07 14:19:10 +01:00
2018-07-30 17:28:44 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-08-16 19:18:24 +02:00
$db -> close ();