2017-03-19 07:26:37 +01:00
< ? php
2018-10-09 19:41:53 +02:00
/* Copyright ( C ) 2017 Alexandre Spangaro < aspangaro @ zendsi . com >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2017-03-19 07:26:37 +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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
2017-06-17 07:54:35 +02:00
* \file htdocs / compta / bank / class / paymentvarious . class . php
* \ingroup bank
* \brief Class for various payment
2017-03-19 07:26:37 +01:00
*/
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
/**
* Class to manage various payments
*/
class PaymentVarious extends CommonObject
{
2018-08-23 17:07:27 +02:00
/**
* @ var string ID to identify managed object
*/
public $element = 'variouspayment' ;
2018-09-02 13:38:11 +02:00
2018-08-22 18:34:50 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
public $table_element = 'payment_various' ;
2018-09-02 13:38:11 +02:00
2018-09-05 10:31:12 +02:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2017-09-01 07:21:27 +02:00
public $picto = 'bill' ;
2017-03-19 07:26:37 +01:00
2018-08-22 11:24:31 +02:00
/**
* @ var int ID
*/
public $id ;
2018-09-02 13:38:11 +02:00
2018-08-31 18:36:15 +02:00
/**
* @ var string Ref
*/
public $ref ;
2018-09-02 10:42:31 +02:00
public $tms ;
public $datep ;
public $datev ;
public $sens ;
public $amount ;
public $type_payment ;
public $num_payment ;
2018-09-02 13:38:11 +02:00
2018-08-22 11:39:37 +02:00
/**
2018-09-01 13:22:08 +02:00
* @ var string various payments label
2018-08-22 11:39:37 +02:00
*/
public $label ;
2018-09-02 13:38:11 +02:00
2018-09-02 10:42:31 +02:00
public $accountancy_code ;
2018-10-09 15:38:42 +02:00
/**
* @ var int ID
*/
2018-09-02 10:42:31 +02:00
public $fk_project ;
2018-10-09 15:38:42 +02:00
/**
* @ var int ID
*/
2018-09-02 10:42:31 +02:00
public $fk_bank ;
2018-10-09 15:38:42 +02:00
/**
* @ var int ID
*/
2018-09-02 10:42:31 +02:00
public $fk_user_author ;
2018-10-09 15:38:42 +02:00
/**
* @ var int ID
*/
2018-09-02 10:42:31 +02:00
public $fk_user_modif ;
2017-03-19 07:26:37 +01:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
function __construct ( $db )
{
$this -> db = $db ;
$this -> element = 'payment_various' ;
$this -> table_element = 'payment_various' ;
}
/**
* Update database
*
* @ param User $user User that modify
2018-09-04 20:48:35 +02:00
* @ param int $notrigger 0 = no , 1 = yes ( no update trigger )
2017-03-19 07:26:37 +01:00
* @ return int < 0 if KO , > 0 if OK
*/
function update ( $user = null , $notrigger = 0 )
{
global $conf , $langs ;
$error = 0 ;
// Clean parameters
$this -> amount = trim ( $this -> amount );
$this -> label = trim ( $this -> label );
$this -> note = trim ( $this -> note );
2018-10-09 20:31:14 +02:00
$this -> fk_bank = ( int ) $this -> fk_bank ;
$this -> fk_user_author = ( int ) $this -> fk_user_author ;
$this -> fk_user_modif = ( int ) $this -> fk_user_modif ;
2017-03-19 07:26:37 +01:00
$this -> db -> begin ();
// Update request
2017-06-17 07:54:35 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " payment_various SET " ;
2018-01-29 18:22:26 +01:00
if ( $this -> tms ) $sql .= " tms=' " . $this -> db -> idate ( $this -> tms ) . " ', " ;
2017-07-26 21:22:53 +02:00
$sql .= " datep=' " . $this -> db -> idate ( $this -> datep ) . " ', " ;
$sql .= " datev=' " . $this -> db -> idate ( $this -> datev ) . " ', " ;
2017-03-19 07:26:37 +01:00
$sql .= " sens= " . $this -> sens . " , " ;
2017-05-12 16:55:11 +02:00
$sql .= " amount= " . price2num ( $this -> amount ) . " , " ;
2017-03-19 07:26:37 +01:00
$sql .= " fk_typepayment= " . $this -> fk_typepayment . " ', " ;
2017-05-12 16:55:11 +02:00
$sql .= " num_payment=' " . $this -> db -> escape ( $this -> num_payment ) . " ', " ;
2017-03-19 07:26:37 +01:00
$sql .= " label=' " . $this -> db -> escape ( $this -> label ) . " ', " ;
$sql .= " note=' " . $this -> db -> escape ( $this -> note ) . " ', " ;
2017-03-19 15:23:35 +01:00
$sql .= " accountancy_code=' " . $this -> db -> escape ( $this -> accountancy_code ) . " ', " ;
2017-09-01 07:21:27 +02:00
$sql .= " fk_projet=' " . $this -> db -> escape ( $this -> fk_project ) . " ', " ;
2017-05-12 16:55:11 +02:00
$sql .= " fk_bank= " . ( $this -> fk_bank > 0 ? $this -> fk_bank : " null " ) . " , " ;
$sql .= " fk_user_author= " . $this -> fk_user_author . " , " ;
$sql .= " fk_user_modif= " . $this -> fk_user_modif ;
2017-03-19 07:26:37 +01:00
$sql .= " WHERE rowid= " . $this -> id ;
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$this -> error = " Error " . $this -> db -> lasterror ();
return - 1 ;
}
if ( ! $notrigger )
{
2017-06-17 07:54:35 +02:00
// Call trigger
$result = $this -> call_trigger ( 'PAYMENT_VARIOUS_MODIFY' , $user );
if ( $result < 0 ) $error ++ ;
// End call triggers
2017-03-19 07:26:37 +01:00
}
if ( ! $error )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return - 1 ;
}
}
/**
* Load object in memory from database
*
* @ param int $id id object
* @ param User $user User that load
* @ return int < 0 if KO , > 0 if OK
*/
function fetch ( $id , $user = null )
{
global $langs ;
$sql = " SELECT " ;
$sql .= " v.rowid, " ;
$sql .= " v.tms, " ;
$sql .= " v.datep, " ;
$sql .= " v.datev, " ;
$sql .= " v.sens, " ;
$sql .= " v.amount, " ;
$sql .= " v.fk_typepayment, " ;
$sql .= " v.num_payment, " ;
$sql .= " v.label, " ;
$sql .= " v.note, " ;
2017-03-19 15:23:35 +01:00
$sql .= " v.accountancy_code, " ;
2017-09-01 07:21:27 +02:00
$sql .= " v.fk_projet as fk_project, " ;
2017-03-19 07:26:37 +01:00
$sql .= " v.fk_bank, " ;
$sql .= " v.fk_user_author, " ;
$sql .= " v.fk_user_modif, " ;
$sql .= " b.fk_account, " ;
$sql .= " b.fk_type, " ;
$sql .= " b.rappro " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_various as v " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " bank as b ON v.fk_bank = b.rowid " ;
2017-03-19 08:17:32 +01:00
$sql .= " WHERE v.rowid = " . $id ;
2017-03-19 07:26:37 +01:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
if ( $this -> db -> num_rows ( $resql ))
{
$obj = $this -> db -> fetch_object ( $resql );
2017-03-19 15:23:35 +01:00
$this -> id = $obj -> rowid ;
$this -> ref = $obj -> rowid ;
$this -> tms = $this -> db -> jdate ( $obj -> tms );
$this -> datep = $this -> db -> jdate ( $obj -> datep );
$this -> datev = $this -> db -> jdate ( $obj -> datev );
$this -> sens = $obj -> sens ;
$this -> amount = $obj -> amount ;
2018-01-29 18:22:26 +01:00
$this -> type_payment = $obj -> fk_typepayment ;
2017-03-19 15:23:35 +01:00
$this -> num_payment = $obj -> num_payment ;
$this -> label = $obj -> label ;
$this -> note = $obj -> note ;
$this -> accountancy_code = $obj -> accountancy_code ;
2017-09-01 07:21:27 +02:00
$this -> fk_project = $obj -> fk_project ;
2017-03-19 15:23:35 +01:00
$this -> fk_bank = $obj -> fk_bank ;
$this -> fk_user_author = $obj -> fk_user_author ;
$this -> fk_user_modif = $obj -> fk_user_modif ;
$this -> fk_account = $obj -> fk_account ;
$this -> fk_type = $obj -> fk_type ;
$this -> rappro = $obj -> rappro ;
2017-03-19 07:26:37 +01:00
}
$this -> db -> free ( $resql );
return 1 ;
}
else
{
$this -> error = " Error " . $this -> db -> lasterror ();
return - 1 ;
}
}
/**
* Delete object in database
*
* @ param User $user User that delete
* @ return int < 0 if KO , > 0 if OK
*/
function delete ( $user )
{
global $conf , $langs ;
$error = 0 ;
// Call trigger
$result = $this -> call_trigger ( 'PAYMENT_VARIOUS_DELETE' , $user );
if ( $result < 0 ) return - 1 ;
// End call triggers
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " payment_various " ;
$sql .= " WHERE rowid= " . $this -> id ;
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$this -> error = " Error " . $this -> db -> lasterror ();
return - 1 ;
}
return 1 ;
}
/**
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ return void
*/
function initAsSpecimen ()
{
$this -> id = 0 ;
$this -> tms = '' ;
$this -> datep = '' ;
$this -> datev = '' ;
$this -> sens = '' ;
$this -> amount = '' ;
$this -> label = '' ;
2017-06-17 07:54:35 +02:00
$this -> accountancy_code = '' ;
2017-03-19 07:26:37 +01:00
$this -> note = '' ;
$this -> fk_bank = '' ;
$this -> fk_user_author = '' ;
$this -> fk_user_modif = '' ;
}
2017-12-10 14:05:36 +01:00
/**
* Create in database
*
* @ param User $user User that create
* @ return int < 0 if KO , > 0 if OK
*/
2017-03-19 07:26:37 +01:00
function create ( $user )
{
global $conf , $langs ;
$error = 0 ;
$now = dol_now ();
// Clean parameters
$this -> amount = price2num ( trim ( $this -> amount ));
$this -> label = trim ( $this -> label );
$this -> note = trim ( $this -> note );
2018-10-09 20:31:14 +02:00
$this -> fk_bank = ( int ) $this -> fk_bank ;
$this -> fk_user_author = ( int ) $this -> fk_user_author ;
$this -> fk_user_modif = ( int ) $this -> fk_user_modif ;
2017-03-19 07:26:37 +01:00
// Check parameters
if ( ! $this -> label )
{
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Label " ));
return - 3 ;
}
if ( $this -> amount < 0 || $this -> amount == '' )
{
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Amount " ));
return - 5 ;
}
if ( ! empty ( $conf -> banque -> enabled ) && ( empty ( $this -> accountid ) || $this -> accountid <= 0 ))
{
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Account " ));
return - 6 ;
}
if ( ! empty ( $conf -> banque -> enabled ) && ( empty ( $this -> type_payment ) || $this -> type_payment <= 0 ))
{
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " PaymentMode " ));
return - 7 ;
}
$this -> db -> begin ();
// Insert into llx_payment_various
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " payment_various ( " ;
$sql .= " datep " ;
$sql .= " , datev " ;
2017-03-19 08:17:32 +01:00
$sql .= " , sens " ;
2017-03-19 07:26:37 +01:00
$sql .= " , amount " ;
$sql .= " , fk_typepayment " ;
$sql .= " , num_payment " ;
if ( $this -> note ) $sql .= " , note " ;
$sql .= " , label " ;
2017-03-19 08:17:32 +01:00
$sql .= " , accountancy_code " ;
2017-09-01 07:21:27 +02:00
$sql .= " , fk_projet " ;
2017-03-19 07:26:37 +01:00
$sql .= " , fk_user_author " ;
$sql .= " , datec " ;
$sql .= " , fk_bank " ;
$sql .= " , entity " ;
$sql .= " ) " ;
$sql .= " VALUES ( " ;
$sql .= " ' " . $this -> db -> idate ( $this -> datep ) . " ' " ;
$sql .= " , ' " . $this -> db -> idate ( $this -> datev ) . " ' " ;
2017-07-15 03:41:07 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> sens ) . " ' " ;
2017-03-19 07:26:37 +01:00
$sql .= " , " . $this -> amount ;
2017-07-15 03:41:07 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> type_payment ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> num_payment ) . " ' " ;
2017-03-19 07:26:37 +01:00
if ( $this -> note ) $sql .= " , ' " . $this -> db -> escape ( $this -> note ) . " ' " ;
$sql .= " , ' " . $this -> db -> escape ( $this -> label ) . " ' " ;
2017-07-15 03:41:07 +02:00
$sql .= " , ' " . $this -> db -> escape ( $this -> accountancy_code ) . " ' " ;
2017-12-10 14:05:36 +01:00
$sql .= " , " . ( $this -> fk_project > 0 ? $this -> fk_project : 0 );
2017-07-15 03:41:07 +02:00
$sql .= " , " . $user -> id ;
2017-03-19 07:26:37 +01:00
$sql .= " , ' " . $this -> db -> idate ( $now ) . " ' " ;
$sql .= " , NULL " ;
$sql .= " , " . $conf -> entity ;
$sql .= " ) " ;
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result )
{
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " payment_various " );
2018-01-29 18:22:26 +01:00
$this -> ref = $this -> id ;
2017-03-19 07:26:37 +01:00
if ( $this -> id > 0 )
{
if ( ! empty ( $conf -> banque -> enabled ) && ! empty ( $this -> amount ))
{
// Insert into llx_bank
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
$acc = new Account ( $this -> db );
$result = $acc -> fetch ( $this -> accountid );
if ( $result <= 0 ) dol_print_error ( $this -> db );
// Insert payment into llx_bank
2017-03-19 15:23:35 +01:00
// Add link 'payment_various' in bank_url between payment and bank transaction
2018-09-08 18:38:24 +02:00
$sign = 1 ;
if ( $this -> sens == '0' ) $sign =- 1 ;
2017-03-19 15:23:35 +01:00
2017-03-19 07:26:37 +01:00
$bank_line_id = $acc -> addline (
$this -> datep ,
$this -> type_payment ,
$this -> label ,
2018-09-08 18:38:24 +02:00
$sign * abs ( $this -> amount ),
2017-03-19 07:26:37 +01:00
$this -> num_payment ,
'' ,
$user
);
// Update fk_bank into llx_paiement.
// So we know the payment which has generate the banking ecriture
if ( $bank_line_id > 0 )
{
$this -> update_fk_bank ( $bank_line_id );
}
else
{
$this -> error = $acc -> error ;
$error ++ ;
}
if ( ! $error )
{
// Add link 'payment_various' in bank_url between payment and bank transaction
$url = DOL_URL_ROOT . '/compta/bank/various_payment/card.php?id=' ;
$result = $acc -> add_url_line ( $bank_line_id , $this -> id , $url , " (VariousPayment) " , " payment_various " );
if ( $result <= 0 )
{
$this -> error = $acc -> error ;
$error ++ ;
}
}
if ( $result <= 0 )
{
$this -> error = $acc -> error ;
$error ++ ;
}
}
2017-12-10 14:05:36 +01:00
// Call trigger
$result = $this -> call_trigger ( 'PAYMENT_VARIOUS_CREATE' , $user );
if ( $result < 0 ) $error ++ ;
// End call triggers
2017-03-19 07:26:37 +01:00
}
else $error ++ ;
if ( ! $error )
{
$this -> db -> commit ();
return $this -> id ;
}
else
{
$this -> db -> rollback ();
return - 2 ;
}
}
else
{
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 1 ;
}
}
2018-09-02 13:38:11 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2017-03-19 07:26:37 +01:00
/**
* Update link between payment various and line generate into llx_bank
*
2017-12-10 14:05:36 +01:00
* @ param int $id_bank Id bank account
* @ return int < 0 if KO , > 0 if OK
2017-03-19 07:26:37 +01:00
*/
function update_fk_bank ( $id_bank )
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2017-03-19 07:26:37 +01:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'payment_various SET fk_bank = ' . $id_bank ;
$sql .= ' WHERE rowid = ' . $this -> id ;
$result = $this -> db -> query ( $sql );
if ( $result )
{
return 1 ;
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
2017-09-01 07:21:27 +02:00
/**
* Retourne le libelle du statut
*
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto
* @ return string Libelle
*/
function getLibStatut ( $mode = 0 )
{
return $this -> LibStatut ( $this -> statut , $mode );
}
2018-09-02 13:38:11 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2017-09-01 07:21:27 +02:00
/**
* Renvoi le libelle d ' un statut donne
*
* @ param int $statut Id status
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto
* @ return string Libelle
*/
function LibStatut ( $statut , $mode = 0 )
{
2018-09-02 13:38:11 +02:00
// phpcs:enable
2017-09-01 07:21:27 +02:00
global $langs ;
if ( $mode == 0 )
{
return $langs -> trans ( $this -> statuts [ $statut ]);
}
2018-09-02 13:38:11 +02:00
elseif ( $mode == 1 )
2017-09-01 07:21:27 +02:00
{
return $langs -> trans ( $this -> statuts_short [ $statut ]);
}
2018-09-02 13:38:11 +02:00
elseif ( $mode == 2 )
2017-09-01 07:21:27 +02:00
{
if ( $statut == 0 ) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut0' ) . ' ' . $langs -> trans ( $this -> statuts_short [ $statut ]);
2018-10-09 19:41:53 +02:00
elseif ( $statut == 1 ) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut4' ) . ' ' . $langs -> trans ( $this -> statuts_short [ $statut ]);
elseif ( $statut == 2 ) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut6' ) . ' ' . $langs -> trans ( $this -> statuts_short [ $statut ]);
2017-09-01 07:21:27 +02:00
}
2018-09-02 13:38:11 +02:00
elseif ( $mode == 3 )
2017-09-01 07:21:27 +02:00
{
if ( $statut == 0 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut0' );
2018-10-09 19:41:53 +02:00
elseif ( $statut == 1 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut4' );
elseif ( $statut == 2 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut6' );
2017-09-01 07:21:27 +02:00
}
2018-09-02 13:38:11 +02:00
elseif ( $mode == 4 )
2017-09-01 07:21:27 +02:00
{
if ( $statut == 0 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut0' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
2018-10-09 19:41:53 +02:00
elseif ( $statut == 1 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut4' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
elseif ( $statut == 2 && ! empty ( $this -> statuts_short [ $statut ])) return img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut6' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
2017-09-01 07:21:27 +02:00
}
2018-09-02 13:38:11 +02:00
elseif ( $mode == 5 )
2017-09-01 07:21:27 +02:00
{
if ( $statut == 0 && ! empty ( $this -> statuts_short [ $statut ])) return $langs -> trans ( $this -> statuts_short [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut0' );
2018-10-09 19:41:53 +02:00
elseif ( $statut == 1 && ! empty ( $this -> statuts_short [ $statut ])) return $langs -> trans ( $this -> statuts_short [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut4' );
elseif ( $statut == 2 && ! empty ( $this -> statuts_short [ $statut ])) return $langs -> trans ( $this -> statuts_short [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts_short [ $statut ]), 'statut6' );
2017-09-01 07:21:27 +02:00
}
}
2017-03-19 07:26:37 +01:00
/**
* Send name clicable ( with possibly the picto )
*
2018-09-08 18:38:24 +02:00
* @ param int $withpicto 0 = No picto , 1 = Include picto into link , 2 = Only picto
* @ param string $option link option
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
* @ param int $notooltip 1 = Disable tooltip
* @ return string String with URL
2017-03-19 07:26:37 +01:00
*/
2018-09-08 18:38:24 +02:00
function getNomUrl ( $withpicto = 0 , $option = '' , $save_lastsearch_value =- 1 , $notooltip = 0 )
2017-03-19 07:26:37 +01:00
{
2018-10-04 18:27:49 +02:00
global $db , $conf , $langs , $hookmanager ;
2017-03-19 07:26:37 +01:00
global $langs ;
2018-10-04 18:27:49 +02:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) $notooltip = 1 ; // Force disable tooltips
2017-03-19 07:26:37 +01:00
$result = '' ;
2018-10-04 18:27:49 +02:00
$label = '<u>' . $langs -> trans ( " ShowVariousPayment " ) . '</u>' ;
$label .= '<br>' ;
$label .= '<b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
$url = DOL_URL_ROOT . '/compta/bank/various_payment/card.php?id=' . $this -> id ;
if ( $option != 'nolink' )
{
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
if ( $save_lastsearch_value == - 1 && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) $add_save_lastsearch_values = 1 ;
if ( $add_save_lastsearch_values ) $url .= '&save_lastsearch_values=1' ;
}
$linkclose = '' ;
if ( empty ( $notooltip ))
{
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
$label = $langs -> trans ( " ShowMyObject " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
}
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
/*
$hookmanager -> initHooks ( array ( 'myobjectdao' ));
$parameters = array ( 'id' => $this -> id );
$reshook = $hookmanager -> executeHooks ( 'getnomurltooltip' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) $linkclose = $hookmanager -> resPrint ;
*/
}
else $linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
2017-03-19 07:26:37 +01:00
$linkend = '</a>' ;
2017-11-17 14:57:14 +01:00
$result .= $linkstart ;
2018-10-04 18:27:49 +02:00
if ( $withpicto ) $result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="paddingright"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'paddingright ' : '' ) . 'classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 );
if ( $withpicto != 2 ) $result .= $this -> ref ;
2017-11-17 14:57:14 +01:00
$result .= $linkend ;
2018-10-04 18:27:49 +02:00
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action ;
$hookmanager -> initHooks ( array ( 'variouspayment' ));
$parameters = array ( 'id' => $this -> id , 'getnomurl' => $result );
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) $result = $hookmanager -> resPrint ;
else $result .= $hookmanager -> resPrint ;
2017-03-19 07:26:37 +01:00
return $result ;
}
/**
* Information on record
*
2017-12-10 14:05:36 +01:00
* @ param int $id Id of record
* @ return void
2017-03-19 07:26:37 +01:00
*/
function info ( $id )
{
$sql = 'SELECT v.rowid, v.datec, v.fk_user_author' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'payment_various as v' ;
$sql .= ' WHERE v.rowid = ' . $id ;
dol_syslog ( get_class ( $this ) . '::info' , LOG_DEBUG );
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
if ( $obj -> fk_user_author )
{
$cuser = new User ( $this -> db );
$cuser -> fetch ( $obj -> fk_user_author );
$this -> user_creation = $cuser ;
}
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
if ( $obj -> fk_user_modif )
{
$muser = new User ( $this -> db );
$muser -> fetch ( $obj -> fk_user_modif );
$this -> user_modif = $muser ;
}
$this -> date_modif = $this -> db -> jdate ( $obj -> tms );
}
$this -> db -> free ( $result );
}
else
{
dol_print_error ( $this -> db );
}
}
}