2014-08-27 07:03:42 +02:00
< ? php
2016-02-01 15:07:12 +01:00
/* Copyright ( C ) 2013 - 2016 Florian Henry < florian . henry @ open - concept . pro >
2014-08-27 07:03:42 +02:00
* Copyright ( C ) 2013 - 2014 Olivier Geffroy < jeff @ jeffinfo . com >
2016-02-01 15:07:12 +01:00
* Copyright ( C ) 2013 - 2016 Alexandre Spangaro < aspangaro . dolibarr @ gmail . com >
2015-07-09 07:48:09 +02:00
* Copyright ( C ) 2015 Ari Elbaz ( elarifr ) < github @ accedinfo . com >
2016-04-16 20:16:38 +02:00
* Copyright ( C ) 2016 Marcos García < marcosgdf @ gmail . com >
2014-08-27 07:03:42 +02: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 />.
*/
/**
2016-04-17 15:44:04 +02:00
* \file htdocs / accountancy / class / html . formventilation . class . php
* \ingroup Advanced accountancy
* \brief File of class with all html predefined components
2014-08-27 07:03:42 +02:00
*/
2014-09-02 20:00:10 +02:00
2014-08-30 07:11:28 +02:00
/**
2016-02-01 15:07:12 +01:00
* Class to manage generation of HTML components for bank module
2014-08-30 07:11:28 +02:00
*/
class FormVentilation extends Form
{
2014-08-27 07:03:42 +02:00
/**
2016-02-01 15:07:12 +01:00
* Return select filter with date of transaction
2014-08-27 07:03:42 +02:00
*
2016-02-01 15:07:12 +01:00
* @ param string $htmlname Name of select field
* @ param string $selectedkey Value
* @ return string HTML edit field
2014-08-27 07:03:42 +02:00
*/
2016-01-14 18:24:02 +01:00
function select_bookkeeping_importkey ( $htmlname = 'importkey' , $selectedkey = '' ) {
2016-04-16 20:16:38 +02:00
$options = array ();
2016-02-01 15:07:12 +01:00
$sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping' ;
2016-09-29 12:36:59 +02:00
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= " WHERE entity IN ( " . getEntity ( " accountancy " , 1 ) . " ) " ;
}
2014-08-27 07:03:42 +02:00
$sql .= ' ORDER BY import_key DESC' ;
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_bookkeeping_importkey " , LOG_DEBUG );
2014-08-27 07:03:42 +02:00
$resql = $this -> db -> query ( $sql );
2016-04-16 20:16:38 +02:00
if ( ! $resql ) {
2014-08-27 07:03:42 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_bookkeeping_importkey " . $this -> error , LOG_ERR );
return - 1 ;
}
2016-04-16 20:16:38 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$options [ $obj -> import_key ] = dol_print_date ( $obj -> import_key , 'dayhourtext' );
}
return Form :: selectarray ( $htmlname , $options , $selectedkey );
2014-08-27 07:03:42 +02:00
}
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
/**
2016-02-01 15:07:12 +01:00
* Return list of accounts with label by chart of accounts
2014-08-27 07:03:42 +02:00
*
2016-11-04 15:43:30 +01:00
* @ param string $selectid Preselected id or code of accounting accounts ( depends on $select_in )
2016-10-01 18:22:30 +02:00
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
* @ param array $event Event options
* @ param int $select_in selectid value is a aa . rowid ( 0 default ) or aa . account_number ( 1 )
* @ param int $select_out set value returned by select 0 = rowid ( default ), 1 = account_number
* @ param string $morecss More css non HTML object
2016-02-01 15:07:12 +01:00
* @ return string String with HTML select
2014-08-27 07:03:42 +02:00
*/
2016-10-01 18:22:30 +02:00
function select_account ( $selectid , $htmlname = 'account' , $showempty = 0 , $event = array (), $select_in = 0 , $select_out = 0 , $morecss = 'maxwidth300 maxwidthonsmartphone' ) {
2015-02-10 10:25:59 +01:00
global $conf ;
2016-06-29 11:06:02 +02:00
2016-02-01 15:07:12 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
2016-04-16 20:16:38 +02:00
$trunclength = defined ( 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT' ) ? $conf -> global -> ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50 ;
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
$sql = " SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version " ;
2015-09-05 08:03:06 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_account as aa " ;
2014-08-27 07:03:42 +02:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version " ;
$sql .= " AND asy.rowid = " . $conf -> global -> CHARTOFACCOUNTS ;
$sql .= " AND aa.active = 1 " ;
$sql .= " ORDER BY aa.account_number " ;
2016-06-29 11:06:02 +02:00
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_account " , LOG_DEBUG );
2014-08-27 07:03:42 +02:00
$resql = $this -> db -> query ( $sql );
2016-04-16 20:16:38 +02:00
if ( ! $resql ) {
2014-08-27 07:03:42 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_account " . $this -> error , LOG_ERR );
2016-04-16 20:16:38 +02:00
return - 1 ;
}
$out = ajax_combobox ( $htmlname , $event );
2016-11-04 15:43:30 +01:00
// TODO Add $options in cache so next call will not execute the request
$selected = 0 ;
2016-04-16 20:16:38 +02:00
$options = array ();
2016-11-04 15:43:30 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
2016-04-16 20:16:38 +02:00
$label = length_accountg ( $obj -> account_number ) . ' - ' . $obj -> label ;
$label = dol_trunc ( $label , $trunclength );
$select_value_in = $obj -> rowid ;
$select_value_out = $obj -> rowid ;
2016-11-04 15:43:30 +01:00
// Try to guess if we have found default value
2016-04-16 20:16:38 +02:00
if ( $select_in == 1 ) {
$select_value_in = $obj -> account_number ;
}
if ( $select_out == 1 ) {
$select_value_out = $obj -> account_number ;
}
// Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
// Because same account_number can be share between different accounting_system and do have the same meaning
2016-11-04 15:43:30 +01:00
if ( $selectid != '' && $selectid == $select_value_in ) {
//var_dump("Found ".$selectid." ".$select_value_in);
2016-04-16 20:16:38 +02:00
$selected = $select_value_out ;
}
$options [ $select_value_out ] = $label ;
2014-08-27 07:03:42 +02:00
}
2016-04-16 20:16:38 +02:00
2016-10-14 13:05:01 +02:00
$out .= Form :: selectarray ( $htmlname , $options , $selected , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , $morecss , 1 );
2014-08-27 07:03:42 +02:00
$this -> db -> free ( $resql );
2016-11-04 15:43:30 +01:00
2014-08-27 07:03:42 +02:00
return $out ;
}
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
/**
2016-02-01 15:07:12 +01:00
* Return list of accounts with label by class of accounts
2014-08-27 07:03:42 +02:00
*
2016-02-01 15:07:12 +01:00
* @ param string $selectid Preselected pcg_type
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
* @ param array $event Event options
2016-06-29 11:06:02 +02:00
*
2016-02-01 15:07:12 +01:00
* @ return string String with HTML select
2014-08-27 07:03:42 +02:00
*/
2016-01-14 18:24:02 +01:00
function select_pcgtype ( $selectid , $htmlname = 'pcg_type' , $showempty = 0 , $event = array ()) {
2015-02-10 10:25:59 +01:00
global $conf ;
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
$sql = " SELECT DISTINCT pcg_type " ;
2015-09-05 08:03:06 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_account as aa " ;
2014-09-06 14:45:35 +02:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version " ;
$sql .= " AND asy.rowid = " . $conf -> global -> CHARTOFACCOUNTS ;
2014-08-27 07:03:42 +02:00
$sql .= " ORDER BY pcg_type " ;
2016-06-29 11:06:02 +02:00
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_pcgtype " , LOG_DEBUG );
2014-08-27 07:03:42 +02:00
$resql = $this -> db -> query ( $sql );
2016-04-16 20:16:38 +02:00
if ( ! $resql ) {
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_pcgtype " . $this -> error , LOG_ERR );
return - 1 ;
}
$options = array ();
$out = ajax_combobox ( $htmlname , $event );
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$options [ $obj -> pcg_type ] = $obj -> pcg_type ;
2014-08-27 07:03:42 +02:00
}
2016-04-16 20:16:38 +02:00
$out .= Form :: selectarray ( $htmlname , $options , $selectid , $showempty );
2014-08-27 07:03:42 +02:00
$this -> db -> free ( $resql );
return $out ;
}
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
/**
2016-02-01 15:07:12 +01:00
* Return list of accounts with label by sub_class of accounts
2014-08-27 07:03:42 +02:00
*
2016-02-01 15:07:12 +01:00
* @ param string $selectid Preselected pcg_type
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
* @ param array $event Event options
2016-06-29 11:06:02 +02:00
*
2016-02-01 15:07:12 +01:00
* @ return string String with HTML select
2014-08-27 07:03:42 +02:00
*/
2016-01-14 18:24:02 +01:00
function select_pcgsubtype ( $selectid , $htmlname = 'pcg_subtype' , $showempty = 0 , $event = array ()) {
2015-02-10 10:25:59 +01:00
global $conf ;
2016-06-29 11:06:02 +02:00
2014-08-27 07:03:42 +02:00
$sql = " SELECT DISTINCT pcg_subtype " ;
2015-09-05 08:03:06 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_account as aa " ;
2014-09-06 14:45:35 +02:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version " ;
$sql .= " AND asy.rowid = " . $conf -> global -> CHARTOFACCOUNTS ;
2014-08-27 07:03:42 +02:00
$sql .= " ORDER BY pcg_subtype " ;
2016-06-29 11:06:02 +02:00
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_pcgsubtype " , LOG_DEBUG );
2014-08-27 07:03:42 +02:00
$resql = $this -> db -> query ( $sql );
2016-04-16 20:16:38 +02:00
if ( ! $resql ) {
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_pcgsubtype " . $this -> error , LOG_ERR );
return - 1 ;
}
$options = array ();
$out = ajax_combobox ( $htmlname , $event );
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$options [ $obj -> pcg_subtype ] = $obj -> pcg_subtype ;
2014-08-27 07:03:42 +02:00
}
2016-04-16 20:16:38 +02:00
$out .= Form :: selectarray ( $htmlname , $options , $selectid , $showempty );
2014-08-27 07:03:42 +02:00
$this -> db -> free ( $resql );
return $out ;
}
2016-06-29 11:06:02 +02:00
2015-12-21 13:09:22 +01:00
/**
* Return list of auxilary thirdparty accounts
*
* @ param string $selectid Preselected pcg_type
* @ param string $htmlname Name of field in html form
* @ param int $showempty Add an empty field
* @ param array $event Event options
2016-06-29 11:06:02 +02:00
*
2015-12-21 13:09:22 +01:00
* @ return string String with HTML select
*/
function select_auxaccount ( $selectid , $htmlname = 'account_num_aux' , $showempty = 0 , $event = array ()) {
2016-04-16 20:16:38 +02:00
$aux_account = array ();
2015-12-21 13:09:22 +01:00
// Auxiliary customer account
$sql = " SELECT DISTINCT code_compta, nom " ;
2016-04-16 20:16:38 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe " ;
2016-09-29 12:36:59 +02:00
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= " WHERE entity IN ( " . getEntity ( " societe " , 1 ) . " ) " ;
}
2015-12-21 13:09:22 +01:00
$sql .= " ORDER BY code_compta " ;
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_auxaccount " , LOG_DEBUG );
2015-12-21 13:09:22 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
2016-04-16 20:16:38 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( ! empty ( $obj -> code_compta )) {
$aux_account [ $obj -> code_compta ] = $obj -> code_compta . ' (' . $obj -> nom . ')' ;
2015-12-21 13:09:22 +01:00
}
}
} else {
2016-04-16 20:16:38 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_pcgsubtype " . $this -> error , LOG_ERR );
return - 1 ;
2015-12-21 13:09:22 +01:00
}
$this -> db -> free ( $resql );
2016-04-16 20:16:38 +02:00
2015-12-21 13:09:22 +01:00
// Auxiliary supplier account
$sql = " SELECT DISTINCT code_compta_fournisseur, nom " ;
2016-04-16 20:16:38 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe " ;
2016-09-29 12:36:59 +02:00
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= " WHERE entity IN ( " . getEntity ( " societe " , 1 ) . " ) " ;
}
2016-06-29 11:06:02 +02:00
$sql .= " ORDER BY code_compta_fournisseur " ;
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " ::select_auxaccount " , LOG_DEBUG );
2015-12-21 13:09:22 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
2016-04-16 20:16:38 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( ! empty ( $obj -> code_compta_fournisseur )) {
$aux_account [ $obj -> code_compta_fournisseur ] = $obj -> code_compta_fournisseur . ' (' . $obj -> nom . ')' ;
2015-12-21 13:09:22 +01:00
}
}
} else {
2016-04-16 20:16:38 +02:00
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " ::select_pcgsubtype " . $this -> error , LOG_ERR );
return - 1 ;
2015-12-21 13:09:22 +01:00
}
$this -> db -> free ( $resql );
2016-04-16 20:16:38 +02:00
2016-02-01 15:07:12 +01:00
// Build select
2016-04-16 20:16:38 +02:00
$out = ajax_combobox ( $htmlname , $event );
2016-05-12 21:32:24 +02:00
$out .= Form :: selectarray ( $htmlname , $aux_account , $selectid , $showempty , 0 , 0 , '' , 0 , 0 , 0 , '' , 'maxwidth300' );
2016-04-16 20:16:38 +02:00
2015-12-21 13:09:22 +01:00
return $out ;
}
2016-06-29 11:06:02 +02:00
2016-01-25 12:39:21 +01:00
/**
* Return HTML combo list of years existing into book keepping
*
* @ param string $selected Preselected value
* @ param string $htmlname Name of HTML select object
* @ param int $useempty Affiche valeur vide dans liste
* @ param string $output_format ( html / opton ( for option html only ) / array ( to return options arrays
* @ return string / array
*/
2016-04-16 20:16:38 +02:00
function selectyear_accountancy_bookkepping ( $selected = '' , $htmlname = 'yearid' , $useempty = 0 , $output_format = 'html' )
{
2016-09-29 12:36:59 +02:00
global $conf ;
2016-04-16 20:16:38 +02:00
$out_array = array ();
2016-01-25 12:39:21 +01:00
$sql = " SELECT DISTINCT date_format(doc_date,'%Y') as dtyear " ;
2016-04-16 20:16:38 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_bookkeeping " ;
2016-09-29 12:36:59 +02:00
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= " WHERE entity IN ( " . getEntity ( " accountancy " , 1 ) . " ) " ;
}
2016-06-29 11:06:02 +02:00
$sql .= " ORDER BY date_format(doc_date,'%Y') " ;
2016-04-16 20:16:38 +02:00
dol_syslog ( get_class ( $this ) . " :: " . __METHOD__ , LOG_DEBUG );
2016-01-25 12:39:21 +01:00
$resql = $this -> db -> query ( $sql );
2016-04-16 20:16:38 +02:00
if ( ! $resql ) {
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " :: " . __METHOD__ . $this -> error , LOG_ERR );
return - 1 ;
}
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$out_array [ $obj -> dtyear ] = $obj -> dtyear ;
2016-01-25 12:39:21 +01:00
}
$this -> db -> free ( $resql );
2016-04-16 20:16:38 +02:00
2016-01-25 12:39:21 +01:00
if ( $output_format == 'html' ) {
2016-04-16 20:16:38 +02:00
return Form :: selectarray ( $htmlname , $out_array , $selected , $useempty , 0 , 0 , 'placeholder="aa"' );
} else {
2016-01-25 12:39:21 +01:00
return $out_array ;
}
}
2016-06-29 11:06:02 +02:00
/**
* Return HTML combo list of years existing into book keepping
*
2016-09-30 18:38:48 +02:00
* @ param string $selected Preselected value
* @ param string $htmlname Name of HTML select object
* @ param int $useempty Affiche valeur vide dans liste
* @ param string $output_format Html / option ( for option html only ) / array ( to return options arrays
2016-06-29 11:06:02 +02:00
* @ return string / array
*/
function selectjournal_accountancy_bookkepping ( $selected = '' , $htmlname = 'journalid' , $useempty = 0 , $output_format = 'html' )
{
2016-10-01 18:42:50 +02:00
global $conf , $langs ;
2016-09-29 12:36:59 +02:00
2016-06-29 11:06:02 +02:00
$out_array = array ();
$sql = " SELECT DISTINCT code_journal " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " accounting_bookkeeping " ;
2016-09-29 12:36:59 +02:00
if ( ! empty ( $conf -> multicompany -> enabled )) {
$sql .= " WHERE entity IN ( " . getEntity ( " accountancy " , 1 ) . " ) " ;
}
2016-06-29 11:06:02 +02:00
$sql .= " ORDER BY code_journal " ;
dol_syslog ( get_class ( $this ) . " :: " . __METHOD__ , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
$this -> error = " Error " . $this -> db -> lasterror ();
dol_syslog ( get_class ( $this ) . " :: " . __METHOD__ . $this -> error , LOG_ERR );
return - 1 ;
}
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2016-09-30 18:38:48 +02:00
$out_array [ $obj -> code_journal ] = $obj -> code_journal ? $obj -> code_journal : $langs -> trans ( " NotDefined " ); // TODO Not defined is accepted ? We should avoid this, shouldn't we ?
2016-06-29 11:06:02 +02:00
}
$this -> db -> free ( $resql );
if ( $output_format == 'html' ) {
return Form :: selectarray ( $htmlname , $out_array , $selected , $useempty , 0 , 0 , 'placeholder="aa"' );
} else {
return $out_array ;
}
}
2014-08-27 07:03:42 +02:00
}