Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
ef5e38b0
Commit
ef5e38b0
authored
7 years ago
by
Darkjeff
Browse files
Options
Downloads
Patches
Plain Diff
correct bug result
parent
97da70e5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/accountancy/class/accountancycategory.class.php
+154
-0
154 additions, 0 deletions
htdocs/accountancy/class/accountancycategory.class.php
with
154 additions
and
0 deletions
htdocs/accountancy/class/accountancycategory.class.php
+
154
−
0
View file @
ef5e38b0
...
...
@@ -429,4 +429,158 @@ class AccountancyCategory
return
-
1
;
}
}
public
function
getCats
()
{
global
$db
,
$langs
,
$user
,
$mysoc
;
if
(
empty
(
$mysoc
->
country_id
)
&&
empty
(
$mysoc
->
country_code
))
{
dol_print_error
(
''
,
'Call to select_accounting_account with mysoc country not yet defined'
);
exit
();
}
if
(
!
empty
(
$mysoc
->
country_id
))
{
$sql
=
"SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"c_accounting_category as c"
;
$sql
.
=
" WHERE c.active = 1 "
;
$sql
.
=
" AND c.fk_country = "
.
$mysoc
->
country_id
;
$sql
.
=
" ORDER BY c.position ASC"
;
}
else
{
$sql
=
"SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"c_accounting_category as c, "
.
MAIN_DB_PREFIX
.
"c_country as co"
;
$sql
.
=
" WHERE c.active = 1 AND c.fk_country = co.rowid"
;
$sql
.
=
" AND co.code = '"
.
$mysoc
->
country_code
.
"'"
;
$sql
.
=
" ORDER BY c.position ASC"
;
}
dol_syslog
(
__METHOD__
.
" sql="
.
$sql
,
LOG_DEBUG
);
$resql
=
$this
->
db
->
query
(
$sql
);
if
(
$resql
)
{
$i
=
0
;
$obj
=
''
;
$num
=
$this
->
db
->
num_rows
(
$resql
);
$data
=
array
();
if
(
$num
)
{
while
(
$i
<
$num
)
{
$obj
=
$this
->
db
->
fetch_object
(
$resql
);
$data
[]
=
array
(
'rowid'
=>
$obj
->
rowid
,
'code'
=>
$obj
->
code
,
'position'
=>
$obj
->
position
,
'label'
=>
$obj
->
label
,
'formula'
=>
$obj
->
formula
,
'category_type'
=>
$obj
->
category_type
);
$i
++
;
}
}
return
$data
;
}
else
{
$this
->
error
=
"Error "
.
$this
->
db
->
lasterror
();
$this
->
errors
[]
=
$this
->
error
;
dol_syslog
(
__METHOD__
.
" "
.
implode
(
','
,
$this
->
errors
),
LOG_ERR
);
return
-
1
;
}
}
// calcule
const
PATTERN
=
'/(?:\-?\d+(?:\.?\d+)?[\+\-\*\/])+\-?\d+(?:\.?\d+)?/'
;
const
PARENTHESIS_DEPTH
=
10
;
public
function
calculate
(
$input
){
if
(
strpos
(
$input
,
'+'
)
!=
null
||
strpos
(
$input
,
'-'
)
!=
null
||
strpos
(
$input
,
'/'
)
!=
null
||
strpos
(
$input
,
'*'
)
!=
null
){
// Remove white spaces and invalid math chars
$input
=
str_replace
(
','
,
'.'
,
$input
);
$input
=
preg_replace
(
'[^0-9\.\+\-\*\/\(\)]'
,
''
,
$input
);
// Calculate each of the parenthesis from the top
$i
=
0
;
while
(
strpos
(
$input
,
'('
)
||
strpos
(
$input
,
')'
)){
$input
=
preg_replace_callback
(
'/\(([^\(\)]+)\)/'
,
'self::callback'
,
$input
);
$i
++
;
if
(
$i
>
self
::
PARENTHESIS_DEPTH
){
break
;
}
}
// Calculate the result
if
(
preg_match
(
self
::
PATTERN
,
$input
,
$match
)){
return
$this
->
compute
(
$match
[
0
]);
}
return
0
;
}
return
$input
;
}
private
function
compute
(
$input
){
$compute
=
create_function
(
''
,
'return '
.
$input
.
';'
);
return
0
+
$compute
();
}
private
function
callback
(
$input
){
if
(
is_numeric
(
$input
[
1
])){
return
$input
[
1
];
}
elseif
(
preg_match
(
self
::
PATTERN
,
$input
[
1
],
$match
)){
return
$this
->
compute
(
$match
[
0
]);
}
return
0
;
}
/**
* get cpts of category
*
* @return array Result in table
*/
public
function
getCptsCat
(
$cat_id
)
{
global
$mysoc
;
$sql
=
""
;
if
(
empty
(
$mysoc
->
country_id
)
&&
empty
(
$mysoc
->
country_code
))
{
dol_print_error
(
''
,
'Call to select_accounting_account with mysoc country not yet defined'
);
exit
();
}
$sql
=
"SELECT t.rowid, t.account_number, t.label as name_cpt"
;
$sql
.
=
" FROM "
.
MAIN_DB_PREFIX
.
"accounting_account as t"
;
$sql
.
=
" WHERE t.fk_accounting_category = "
.
$cat_id
;
$sql
.
=
" ORDER BY t.account_number "
;
//echo $sql;
$resql
=
$this
->
db
->
query
(
$sql
);
if
(
$resql
)
{
$i
=
0
;
$obj
=
''
;
$num
=
$this
->
db
->
num_rows
(
$resql
);
$data
=
array
();
if
(
$num
)
{
while
(
$obj
=
$this
->
db
->
fetch_object
(
$resql
)
)
{
$name_cat
=
$obj
->
name_cat
;
$data
[]
=
array
(
'id'
=>
$obj
->
rowid
,
'account_number'
=>
$obj
->
account_number
,
'name_cpt'
=>
$obj
->
name_cpt
,
);
$i
++
;
}
}
return
$data
;
}
else
{
$this
->
error
=
"Error "
.
$this
->
db
->
lasterror
();
dol_syslog
(
__METHOD__
.
" "
.
$this
->
error
,
LOG_ERR
);
return
-
1
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment