34 const STR_PATTERN=
"([\[\{]{1,2}[[:alnum:]]*%*(-[c,d,s,S]){0,1}[\]\}]{1,2})";
58 return array(
'desc'=>$p_label.
' Erreur Formule!',
70 $cond_anc=
"and ".transform_sql_filter_per($cond);
72 elseif ($p_type_date == 1) {
73 $cond=
"( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= to_date('$p_end','DD.MM.YYYY'))";
74 $cond_anc=
"and ( oa_date >= to_date('$p_start','DD.MM.YYYY') and oa_date <= to_date('$p_end','DD.MM.YYYY'))";
76 throw new Exception(
"impress72 invalid type_date [ {$p_type_date} ] ");
80 if ( DEBUGNOALYSS > 1)
82 tracedebug(
"impress.debug.log",
"$p_formula ",
'parse_formula-71 $formula to parse' );
83 tracedebug(
"impress.debug.log",
"$p_label ",
'parse_formula-72 $p_label' );
84 tracedebug(
"impress.debug.log",
$p_start,
'parse_formula-73 $p_start' );
85 tracedebug(
"impress.debug.log",
$p_end,
'parse_formula-74 $p_end ' );
86 tracedebug(
"impress.debug.log", $p_type_date,
'parse_formula-75 $p_type_date' );
87 tracedebug(
"impress.debug.log", $p_sql,
'parse_formula-76 $p_sql' );
88 tracedebug(
"impress.debug.log", $cond ,
'parse_formula-77 $cond SQL accountancy' );
89 tracedebug(
"impress.debug.log", $cond_anc,
'parse_formula-78 $cond_anc SQL Analytic Acc' );
100 if ($p_type_date==0&&preg_match(
"/FROM=[0-9]+\.[0-9]+/", $p_formula, $afrom)==1)
104 $cond_anc=
" and ".transform_sql_filter_per($cond);
106 $p_formula=substr_replace($p_formula,
"", strpos($p_formula,
"FROM"));
108 if ($p_type_date==1&&preg_match(
"/FROM=[0-9]+\.[0-9]+/", $p_formula, $afrom)==1)
111 $p_formula=substr_replace($p_formula,
"", strpos($p_formula,
"FROM"));
127 $p_formula=
"\$result=".$p_formula.
";";
130 }
catch(Exception
$e) {
131 return array(
"desc"=>
"erreur",
"montant"=>
'0');
133 while (preg_match(
"/\[([0-9]+)(-[Tt]*)\]/", trim($p_label),
$e)==1)
135 $nom=
"!!".$e[1].
"!!";
138 $nom=$p_cn->get_value(
"SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE $1||'%' ORDER BY pcm_val ASC LIMIT 1",
143 $nom=strtoupper($nom);
145 $nom=strtolower($nom);
151 $aret=array(
'desc'=>$p_label,
201 $p_string=preg_replace(
"/\{\{[[:alnum:]]*\}\}/",
"", $p_string);
204 $p_string=preg_replace(
"/\{[[:alnum:]]*\}/",
"", $p_string);
207 $p_string=preg_replace(
"/FROM*=*[0-9]+/",
"", $p_string);
209 $p_string=preg_replace(
"/#.*/",
"", $p_string);
211 $p_string=preg_replace(
'/\$[a-z]*[A-Z]*[0-9]*[A-Z]*[a-z]*/',
"", $p_string);
212 $p_string=preg_replace(
'/=/',
"", $p_string);
215 $p_string=preg_replace(
"/\[[0-9]*[A-Z]*%*\]/",
"", $p_string);
217 $p_string=preg_replace(
"/\+|-|\/|\*/",
"", $p_string);
218 $p_string=preg_replace(
"/[0-9]*\.*[0-9]/",
"", $p_string);
244 for (
$i=0;
$i<count($aheader);
$i++)
246 $file_csv->add($aheader[
$i][
'title']);
258 if (
$e>count($aheader))
261 if (isset($aheader[
$e][
'type']))
263 switch ($aheader[
$e][
'type'])
266 $file_csv->add(
$value,
"number");
295 if (strpos($p_formula,
'-d')!=0)
299 elseif (strpos($p_formula,
'-c')!=0)
303 elseif (strpos($p_formula,
'-s')!=0)
307 elseif (strpos($p_formula,
'-S')!=0)
329 if ($p_from==
'00.0000')
331 $current_exercice=$p_cn->get_value(
'select p_exercice from parm_periode where p_id=$1',
334 throw new Execution(_(
'CP329'));
336 $first_day=$p_cn->get_value(
"select to_char(min(p_start),'DD.MM.YYYY') as p_start from parm_periode where p_exercice=$1",
338 $last_day=$p_cn->get_value(
"select to_char(p_end,'DD.MM.YYYY') from parm_periode where p_id=$1",[
$p_end]);
341 throw new Exception(
'Pas de limite à cette période', 1);
349 $pfrom=
$oPeriode->find_periode(
'01.'.$p_from);
352 catch (Exception $exp)
358 $first_day=$p_cn->get_value(
"select to_char(min(p_start),'DD.MM.YYYY') as p_start from parm_periode");
359 $last_day=$p_cn->get_value(
"select to_char(p_end,'DD.MM.YYYY') from parm_periode where p_id=$1",[
$p_end]);
362 throw new Exception(
'Pas de limite à cette période', 1);
377 static function compute_amount($p_cn, $p_expression, $p_cond_sql,$p_cond_anc_sql)
379 if ( DEBUGNOALYSS > 1)
381 tracedebug(
"impress.debug.log",
"$p_expression",
'$p_expression' );
382 tracedebug(
"impress.debug.log",
"$p_cond_sql",
'$p_cond_sql' );
391 if (preg_match(
"/\[.*\]/", $p_expression)) {
395 $detail=$P->get_solde_detail($p_cond_sql);
396 }
elseif (preg_match(
"/\{\{.*\}\}/", $p_expression))
401 $anc_account->load_by_code($p_expression);
403 if ( DEBUGNOALYSS > 1)
405 tracedebug(
"impress.debug.log", $p_expression,
'code analytic account');
406 tracedebug(
"impress.debug.log", $p_cond_anc_sql,
'condition SQL ');
411 $detail=$anc_account->get_balance($p_cond_anc_sql);
413 }
elseif (preg_match(
"/\{.*\}/", $p_expression))
419 if ( DEBUGNOALYSS > 1)
421 tracedebug(
"impress.debug.log",
"$p_expression",
'search_card qcode =');
423 $fiche->get_by_qcode(strtoupper(trim($p_expression)));
426 throw new \Exception (
"Impress::compute_amount383.".
427 " Unknown expression \$p_expression [$p_expression]".
428 " \$p_cond_sql $p_cond_sql");
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
noalyss_str_replace($search, $replace, $string)
remove_divide_zero($p_formula)
When it is needed to eval a formula , this function prevent the divide by zero.
global $g_user
if no group available , then stop
Manage the account from the table jrn, jrnx or tmp_pcmn.
Analytic account ; get the balance.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
contains function for the parsing and computing formulae .
static find_computing_mode($p_formula)
return what to consider
static compute_periode($p_cn, $p_from, $p_end)
make the condition SQL for filtering on the period
static array_to_csv($array, $aheader, $p_filename)
with the handle of a successull query, echo each row into CSV and send it directly
static compute_amount($p_cn, $p_expression, $p_cond_sql, $p_cond_anc_sql)
compute the amount of the accounting ,analytic accounting or a card, the SQL condition from sql_filte...
const STR_PATTERN
< string pattern to use
static check_formula($p_string)
static parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval=true, $p_type_date=0, $p_sql="")
Manage the CSV : manage files and write CSV record.
For the periode tables parm_periode and jrn_periode.
if( $delta< 0) elseif( $delta==0)