Task #0001992: Prévision, calcul avec comptabilité analytique

This commit is contained in:
sparkyx 2021-05-24 12:39:50 +02:00
parent 2838cc2f08
commit 1a632a2d1c
37 changed files with 1675 additions and 1189 deletions

View file

@ -23,8 +23,9 @@
require_once NOALYSS_INCLUDE.'/lib/itext.class.php';
require_once NOALYSS_INCLUDE.'/lib/ibutton.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_report_row.class.php';
require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
require_once NOALYSS_INCLUDE.'/database/form_detail_sql.class.php';
require_once NOALYSS_INCLUDE.'/database/form_definition_sql.class.php';
/*!
* \brief Class rapport Create, view, modify and parse report
@ -33,28 +34,29 @@ require_once NOALYSS_INCLUDE.'/lib/impress.class.php';
class Acc_Report
{
var $db; /*!< $db database connx */
var $id; /*!< $id formdef.fr_id */
var $name; /*!< $name report's name */
var $aAcc_Report_row; /*!< array of rapport_row */
private $form_definition; /*!< form_definition_sql
var $nb;
/*!\brief Constructor */
function __construct($p_cn,$p_id=0)
function __construct($p_cn,$p_id=-1)
{
$this->db=$p_cn;
$this->id=$p_id;
$this->name='Nouveau';
$this->aAcc_Report_row=null;
$this->form_definition=new Form_Definition_SQL($p_cn,$p_id);
}
/*!\brief Return the report's name
public function get_form_definition()
{
return $this->form_definition;
}
public function set_form_definition($form_definition): void
{
$this->form_definition=$form_definition;
}
/*!\brief Return the report's name
*/
function get_name()
{
$ret=$this->db->exec_sql("select fr_label from formdef where fr_id=".$this->id);
if (Database::num_row($ret) == 0) return $this->name;
$a=Database::fetch_array($ret,0);
$this->name=$a['fr_label'];
return $this->name;
return $this->form_definition->getp("fr_label");
}
/*!\brief return all the row and parse formula
* from a report
@ -65,15 +67,15 @@ class Acc_Report
function get_row($p_start,$p_end,$p_type_date)
{
$Res=$this->db->exec_sql("select fo_id ,
$Res=$this->form_definition->cn->exec_sql("select fo_id ,
fo_fr_id,
fo_pos,
fo_label,
fo_formula,
fr_label from form
inner join formdef on fr_id=fo_fr_id
where fr_id =".$this->id.
"order by fo_pos");
fr_label from form_detail
inner join form_definition on fr_id=fo_fr_id
where fr_id =$1
order by fo_pos",array($this->form_definition->getp("fr_id")));
$Max=Database::num_row($Res);
if ($Max==0)
{
@ -84,7 +86,7 @@ class Acc_Report
for ($i=0;$i<$Max;$i++)
{
$l_line=Database::fetch_array($Res,$i);
$col[]=Impress::parse_formula($this->db,
$col[]=Impress::parse_formula($this->form_definition->cn,
$l_line['fo_label'],
$l_line['fo_formula'],
$p_start,
@ -97,248 +99,40 @@ class Acc_Report
$this->row=$col;
return $col;
}
/*!
* \brief Display a form for encoding a new report or update one
*
* \param $p_line number of line
*
*/
function form($p_line=0)
{
$r="";
if ($p_line == 0 ) $p_line=count($this->aAcc_Report_row);
$r.= dossier::hidden();
$r.= HtmlInput::hidden('line',$p_line);
$r.= HtmlInput::hidden('fr_id',$this->id);
$wForm=new IText();
$r.=_("Nom du rapport")." : ";
$r.=$wForm->input('form_nom',$this->name);
$r.= '<TABLE id="rap1" width="100%">';
$r.= "<TR>";
$r.= "<TH> Position </TH>";
$r.= "<TH> Texte </TH>";
$r.= "<TH> Formule</TH>";
$r.= '</TR>';
$wName=new IText();
$wName->size=40;
$wPos=new IText();
$wPos->size=3;
$wForm=new IText();
$wForm->size=35;
for ( $i =0 ; $i < $p_line;$i++)
{
$r.= "<TR>";
$r.= "<TD>";
$wPos->value=( isset($this->aAcc_Report_row[$i]->fo_pos))?$this->aAcc_Report_row[$i]->fo_pos:$i+1;
$r.=$wPos->input("pos".$i);
$r.= '</TD>';
$r.= "<TD>";
$wName->value=( isset($this->aAcc_Report_row[$i]->fo_label))?$this->aAcc_Report_row[$i]->fo_label:"";
$r.=$wName->input("text".$i);
$r.= '</TD>';
$r.='<td>';
$search=new IPoste("form".$i);
$search->size=50;
$search->value=( isset($this->aAcc_Report_row[$i]->fo_formula))?$this->aAcc_Report_row[$i]->fo_formula:"";
$search->label=_("Recherche poste");
$search->set_attribute('gDossier',dossier::id());
$search->set_attribute('bracket',1);
$search->set_attribute('no_overwrite',1);
$search->set_attribute('noquery',1);
$search->set_attribute('account',$search->name);
$search->set_attribute('ipopup','ipop_card');
$r.=$search->input();
$r.='</td>';
$r.= "</TR>";
}
$r.= "</TABLE>";
$wButton=new IButton();
$wButton->javascript=" rapport_add_row('".dossier::id()."')";
$wButton->label="Ajout d'une ligne";
$r.=$wButton->input();
return $r;
}
/*!\brief save into form and form_def
*/
function save()
{
if ( strlen(trim($this->name)) == 0 )
return;
if ( $this->id == 0 )
$this->insert();
else
$this->update();
}
function insert()
{
try
{
$this->db->start();
$ret_sql=$this->db->exec_sql(
"insert into formdef (fr_label) values($1) returning fr_id",
array($this->name)
);
$this->id=Database::fetch_result($ret_sql,0,0);
$ix=1;
foreach ( $this->aAcc_Report_row as $row)
{
if ( strlen(trim($row->get_parameter("name"))) != 0 &&
strlen(trim($row->get_parameter("formula"))) != 0 )
{
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
$row->set_parameter("position",$ix);
$ret_sql=$this->db->exec_sql(
"insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
" values($1,$2,$3,$4)",
array($this->id,
$row->fo_pos,
$row->fo_label,
$row->fo_formula)
);
}
}
}
catch (Exception $e)
{
record_log($e);
$this->db->rollback();
echo $e->getMessage();
}
$this->db->commit();
}
function update()
{
try
{
$this->db->start();
$ret_sql=$this->db->exec_sql(
"update formdef set fr_label=$1 where fr_id=$2",
array($this->name,$this->id));
$ret_sql=$this->db->exec_sql(
"delete from form where fo_fr_id=$1",
array($this->id));
$ix=0;
foreach ( $this->aAcc_Report_row as $row)
{
if ( strlen(trim($row->get_parameter("name"))) != 0 &&
strlen(trim($row->get_parameter("formula"))) != 0 )
{
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
$row->set_parameter("position",$ix);
$ret_sql=$this->db->exec_sql(
"insert into form (fo_fr_id,fo_pos,fo_label,fo_formula)".
" values($1,$2,$3,$4)",
array($this->id,
$row->fo_pos,
$row->fo_label,
$row->fo_formula)
);
}
}
}
catch (Exception $e)
{
record_log($e);
$this->db->rollback();
echo $e->getMessage();
}
$this->db->commit();
}
/*!\brief fill a form thanks an array, usually it is $_POST
*\param $p_array keys = fr_id, form_nom,textXX, formXX, posXX where
XX is an number
*/
function from_array($p_array)
{
$this->id=(isset($p_array['fr_id']))?$p_array['fr_id']:0;
$this->name=(isset($p_array['form_nom']))?$p_array['form_nom']:"";
$ix=0;
$rr=new Acc_Report_Row();
$rr->set_parameter("form_id",$this->id);
$rr->set_parameter('database',$this->db);
$this->aAcc_Report_row=$rr->from_array($p_array);
$this->form_definition->save();
}
/*!\brief the fr_id MUST be set before calling
*/
function load()
{
$sql=$this->db->exec_sql(
"select fr_label from formdef where fr_id=$1",
array($this->id));
if ( Database::num_row($sql) == 0 ) return;
$this->name=Database::fetch_result($sql,0,0);
$sql=$this->db->exec_sql(
"select fo_id,fo_pos,fo_label,fo_formula ".
" from form ".
" where fo_fr_id=$1 order by fo_pos",
array($this->id));
$f=Database::fetch_all($sql);
$array=array();
if ( ! empty($f) )
{
foreach ($f as $r)
{
$obj=new Acc_Report_Row();
$obj->set_parameter("name",$r['fo_label']);
$obj->set_parameter("id",$r['fo_id']);
$obj->set_parameter("position",$r['fo_pos']);
$obj->set_parameter("formula",$r['fo_formula']);
$obj->set_parameter('database',$this->db);
$obj->set_parameter('form_id',$this->id);
$array[]=clone $obj;
}
}
$this->aAcc_Report_row=$array;
$this->form_definition->load();
}
function delete()
{
$ret=$this->db->exec_sql(
"delete from formdef where fr_id=$1",
array($this->id)
);
$this->form_definition->delete();
}
/*!\brief get a list from formdef of all defined form
/*!\brief get a list from form_definition of all defined form
*
*\return array of object rapport
*
*/
function get_list()
{
$sql="select fr_id,fr_label from formdef order by fr_label";
$ret=$this->db->exec_sql($sql);
$sql="select fr_id,fr_label from form_definition order by fr_label";
$ret=$this->form_definition->cn->exec_sql($sql);
if ( Database::num_row($ret) == 0 ) return array();
$array=Database::fetch_all($ret);
$obj=array();
foreach ($array as $row)
{
$tmp=new Acc_Report($this->db);
$tmp=new Acc_Report($this->form_definition->cn);
$tmp->id=$row['fr_id'];
$tmp->name=$row['fr_label'];
$obj[]=clone $tmp;
@ -351,7 +145,7 @@ class Acc_Report
*/
function make_array()
{
$sql=$this->db->make_array("select fr_id,fr_label from formdef order by fr_label");
$sql=$this->form_definition->cn->make_array("select fr_id,fr_label from form_definition order by fr_label");
return $sql;
}
@ -362,14 +156,20 @@ class Acc_Report
function export_csv($p_file)
{
$this->load();
fputcsv($p_file,array($this->name));
foreach ($this->aAcc_Report_row as $row)
fputcsv($p_file,array($this->form_definition->getp("fr_label")));
$array=$this->form_definition->get_cn()->get_array("select fo_label,fo_pos,fo_formula
from form_detail
where fo_fr_id=$1
order by fo_pos"
,array($this->form_definition->getp("fr_id"))
);
foreach ($array as $row)
{
fputcsv($p_file,array($row->get_parameter("name"),
$row->get_parameter('position'),
$row->get_parameter('formula'))
fputcsv($p_file,array($row["fo_label"],
$row["fo_pos"],
$row["fo_formula"])
);
}
@ -392,21 +192,18 @@ class Acc_Report
$file=fopen($file_report,'r');
$data=fgetcsv($file);
if ( empty($data) ) return;
$this->name=$data[0];
$array=array();
$cn=$this->form_definition->cn;
$id=$this->form_definition->getp("fr_id");
while($data=fgetcsv($file))
{
$obj=new Acc_Report_Row();
$obj->set_parameter("name",$data[0]);
$obj->set_parameter("id",0);
$obj->set_parameter("position",$data[1]);
$obj->set_parameter("formula",$data[2]);
$obj->set_parameter('database',$this->db);
$obj->set_parameter('form_id',0);
$array[]=clone $obj;
$obj=new Form_Detail_SQL($cn);
$obj->setp("fo_label",$data[0]);
$obj->setp("fo_pos",$data[1]);
$obj->set("fo_formula",$data[2]);
$obj->setp("fo_fr_id",$id);
$obj->insert();
}
$this->aAcc_Report_row=$array;
$this->insert();
}
}
/**
@ -416,42 +213,35 @@ class Acc_Report
*/
function exist($p_id=0)
{
$c=$this->id;
$c=$this->form_definition->getp("fr_id");
if ( $p_id != 0 ) $c=$p_id;
$ret=$this->db->exec_sql("select fr_label from formdef where fr_id=$1",array($c));
$ret=$this->form_definition->cn->exec_sql("select fr_label from form_definition where fr_id=$1",array($c));
if (Database::num_row($ret) == 0) return false;
return true;
}
static function test_me()
/**
* @brief display a form for creating a new report by importing it or set manually
*/
function create()
{
$cn=Dossier::connect();
$a=new Acc_Report($cn);
print_r($a->get_list());
$array=array("text0"=>"test1",
"form0"=>"7%",
"text1"=>"test2",
"form1"=>"6%",
"fr_id"=>110,
"form_nom"=>"Tableau"
);
$a->from_array($array);
print_r($a);
echo '<form method="post">';
echo $a->form(10);
echo HtmlInput::submit('update','Enregistre');
/* Add a line should be a javascript see comptanalytic */
// $r.= '<INPUT TYPE="submit" value="Ajoute une ligne" name="add_line">';
echo HtmlInput::submit('del_form','Efface ce rapport');
echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
echo "</FORM>";
if ( isset ($_POST['update']))
{
$b=new Acc_Report($cn);
$b->from_array($_POST);
echo '<hr>';
print_r($b);
}
require_once NOALYSS_INCLUDE."/template/acc_report-create.php";
}
/**
* @brief
* @param IText $name
*/
function input_name($name)
{
$name=new IText("fr_name",$name);
$name->id="fr_name_inplace";
$iName=new Inplace_Edit($name);
$iName->set_callback("ajax_misc.php");
$iName->add_json_param("op", "report_definition");
$iName->add_json_param("sa", "change_name");
$iName->add_json_param("gDossier", Dossier::id());
$iName->add_json_param("p_id", $this->form_definition->getp("fr_id"));
return $iName;
}
}

View file

@ -0,0 +1,129 @@
<?php
/*
* This file is part of NOALYSS.
*
* PhpCompta 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 2 of the License, or
* (at your option) any later version.
*
* PhpCompta 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 PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright (2002-2021) Author Dany De Bontridder <danydb@noalyss.eu>
require_once NOALYSS_INCLUDE."/lib/manage_table_sql.class.php";
require_once NOALYSS_INCLUDE.'/database/form_detail_sql.class.php';
require_once NOALYSS_INCLUDE."/lib/impress.class.php";
/**
* @file
* @brief manage simple report
*/
class Acc_Report_MTable extends Manage_Table_SQL
{
private $form_definition_id;
function __construct(\Data_SQL $p_table)
{
parent::__construct($p_table);
}
static function build($p_id, $p_form_def_id)
{
$cn=Dossier::connect();
$form_detail=new Form_Detail_SQL($cn, $p_id);
if ( $p_id == -1) {
$max=$cn->get_value("select coalesce(max(fo_pos),0) +10 from form_detail where fo_fr_id=$1",
[$p_form_def_id]);
$form_detail->setp("fo_pos",$max);
}
$acc_report_mtable=new Acc_Report_MTable($form_detail);
$acc_report_mtable->set_order(['fo_pos', 'fo_label', 'fo_formula']);
$acc_report_mtable->set_col_label("fo_pos", _("Position"));
$acc_report_mtable->set_col_label("fo_label", _("Libellé"));
$acc_report_mtable->set_col_label("fo_formula", _("Formula"));
$acc_report_mtable->set_form_definition_id($p_form_def_id);
$acc_report_mtable->set_sort_column("fo_pos");
$acc_report_mtable->set_col_type("fo_pos", "numeric");
$acc_report_mtable->set_col_type("fo_formula", "custom");
$acc_report_mtable->set_col_tips("fo_formula", 79);
$acc_report_mtable->add_json_param("form_def", $p_form_def_id);
$acc_report_mtable->add_json_param("op", "report_definition");
$acc_report_mtable->set_callback("ajax_misc.php");
return $acc_report_mtable;
}
public function get_form_definition_id()
{
return $this->form_definition_id;
}
public function set_form_definition_id($form_definition_id): void
{
$this->form_definition_id=$form_definition_id;
}
function input_custom($p_key, $p_value)
{
if ($p_key=='fo_formula')
{
$formula=new ITextarea('fo_formula');
$formula->id='fo_formula';
$formula->value=$p_value;
echo $formula->input();
echo HtmlInput::button_action(_("Cherche poste, fiche , analytique"),
sprintf('search_account_card({gDossier:%s,target:\'%s\'})',Dossier::id(),
"fo_formula")
);
echo HtmlInput::hidden("form_def",$this->form_definition_id);
}
}
function display_row_custom($p_key, $p_value, $p_id=0)
{
if ($p_key=='fo_formula')
{
return td($p_value);
}
}
function display_table($p_order="", $p_array=NULL)
{
return parent::display_table(" where fo_fr_id = $1 order by fo_pos", [$this->get_form_definition_id()]);
}
function check()
{
$obj=$this->get_table();
$obj->setp("fo_fr_id",$this->form_definition_id);
$n=0;
if ( ! Impress::check_formula($obj->getp("fo_formula"))) {
$this->set_error("fo_formula", _("Formule invalide"));
$n++;
}
if ( trim($obj->getp("fo_label")) == "") {
$n++;
$this->set_error("fo_label",_("Nom est vide"));
}
if ($n == 0 ) { return true; }
return false;
}
}

View file

@ -1,122 +0,0 @@
<?php
/*
* This file is part of NOALYSS.
*
* NOALYSS 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 2 of the License, or
* (at your option) any later version.
*
* NOALYSS 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 NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany De Bontridder danydb@aevalys.eu
/*!\file
* \brief this class maps the table form, which is a child table for formdef
*/
/*!\brief manipulate the form_def's child table (form) */
class Acc_Report_Row
{
private static $variable=array(
"name"=>"fo_label",
"formula"=>"fo_formula",
"id"=>"fo_id",
"position"=>"fo_pos",
"form_id"=>"fo_fr_id",
"database"=>"db"
);
function __construct ($p_name=null,$p_formula=null)
{
$this->set_parameter("id",0);
$this->set_parameter("name",$p_name);
$this->set_parameter("formula",$p_formula);
}
public function get_parameter($p_string)
{
if ( array_key_exists($p_string,self::$variable) )
{
$idx=self::$variable[$p_string];
return $this->$idx;
}
else
throw new Exception("Attribut inexistant $p_string");
}
public function set_parameter($p_string,$p_value)
{
if ( array_key_exists($p_string,self::$variable) )
{
$idx=self::$variable[$p_string];
$this->$idx=$p_value;
}
else
throw new Exception("Attribut inexistant $p_string");
}
public function get_info()
{
return var_export(self::$variable,true);
}
/*!\brief Convert an array into an array of row_rapport object
* the fo_id is 0, position = 0, the fo_frd_id (form_id) is
* the one of the current object, the db is also the current one
*\param $p_array contains the value
*\return an array of Acc_Report_Row object
*/
public function from_array($p_array)
{
extract ($p_array, EXTR_SKIP);
$ret=array();
$ix=0;
$found=0;
foreach ( $p_array as $r)
{
if ( isset(${'form'.$ix}) && isset ( ${'text'.$ix} ))
{
$obj=new Acc_Report_Row( ${'text'.$ix},${'form'.$ix});
if ( isset(${'pos'.$ix}) && isNumber(${'pos'.$ix})==1 )
$obj->set_parameter("position",${'pos'.$ix});
else
{
$obj->set_parameter("position",$found);
$found++;
}
$obj->fo_id=0;
$obj->fo_fr_id=$this->fo_fr_id;
$obj->db=$this->db;
$ret[]=clone $obj;
}
$ix++;
}
return $ret;
}
static function test_me()
{
$cn=Dossier::connect();
$a=new Acc_Report_Row();
$array=array("text0"=>"test1",
"form0"=>"7%",
"text1"=>"test2",
"form1"=>"6%"
);
$a->db=$cn;
$b=$a->from_array($array);
print_r($b);
echo $a->get_info();
}
}

View file

@ -0,0 +1,99 @@
<?php
/*
* This file is part of NOALYSS.
*
* PhpCompta 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 2 of the License, or
* (at your option) any later version.
*
* PhpCompta 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 PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright (2002-2021) Author Dany De Bontridder <danydb@noalyss.eu>
/**
* @file
* @brief Analytic account
*/
class Anc_Account
{
private $poste_analytique_sql;
public function __construct($p_cn, $p_id=-1)
{
$this->poste_analytique_sql=new Poste_analytique_SQL($p_cn, $p_id);
}
public function get_poste_analytique_sql()
{
return $this->poste_analytique_sql;
}
public function set_poste_analytique_sql($poste_analytique_sql): void
{
$this->poste_analytique_sql=$poste_analytique_sql;
}
/**
* @brief Get the balance of an Analytic account
* @param string $p_cond_sql SQL condition to filter , usually the period
* @see Impress::compute_amount
* @return array key = credit , debit , solde
*/
public function get_balance($p_cond_sql)
{
if ( DEBUGNOALYSS > 1)
{
tracedebug("impress.debug.log", "$p_cond_sql", 'Anc_Account->get_balance \$p_cond_sql');
}
$cn=$this->poste_analytique_sql->cn;
$detail=$cn->get_row("
select ( select coalesce (sum(oa1.oa_amount),0)
from operation_analytique oa1
where oa1.po_id=$1
and oa1.oa_debit='t'
$p_cond_sql
) as debit,
( select coalesce (sum(oa2.oa_amount),0)
from operation_analytique oa2
where oa2.po_id=$1
and oa2.oa_debit='f'
$p_cond_sql
) as credit
",[$this->poste_analytique_sql->getp("po_id")]);
if ( DEBUGNOALYSS > 1)
{
tracedebug("impress.debug.log", $cn->sql, 'Anc_Account->get_balance SQL executed');
}
$tdetail['credit']=$detail['credit'];
$tdetail['debit']=$detail['debit'];
$tdetail['solde']=abs(bcsub($detail['debit'],$detail['credit']));
return $tdetail;
}
/**
* @brief retrieve the Analytic account thanks its code
* @param type $p_code
* @return type
*/
public function load_by_code($p_code)
{
$cn=$this->poste_analytique_sql->cn;
$p_id= $cn->get_value("select po_id from poste_analytique where po_name=$1",
[ trim(strtoupper($p_code))]);
$p_id=(empty($p_id))?-1:$p_id;
$this->poste_analytique_sql->setp('po_id',$p_id);
$this->poste_analytique_sql->load();
return $this->poste_analytique_sql;
}
}

View file

@ -211,22 +211,22 @@ EOF;
$aItem = array();
$aReal = array();
$poste = new Acc_Account_Ledger($this->cn, 0);
$fiche = new Fiche($this->cn);
$aPeriode = $this->cn->get_array("select p_id,to_char(p_start,'MM.YYYY') as myear from parm_periode
where p_start >= (select p_start from parm_periode where p_id=$start)
and p_end <= (select p_end from parm_periode where p_id=$end)
order by p_start;");
where p_start >= (select p_start from parm_periode where p_id=$1)
and p_end <= (select p_end from parm_periode where p_id=$2)
order by p_start",[$start,$end]);
$error = array();
for ($j = 0; $j < count($aCat); $j++) {
// Item of the category, estimation for a specific month
$aItem[$j] = $this->cn->get_array('select fi_card,fi_account,fi_text,fi_amount,fi_debit ,
// Item of the category,montly estimation
$aItem[$j] = $this->cn->get_array('select fi_account,fi_text,fi_amount,
fi_amount_initial
from forecast_item where fc_id=$1 and fi_pid=0 order by fi_order ',
array($aCat[$j]['fc_id']));
// Item of the category, montly estimation
$aPerMonth[$j] = $this->cn->get_array('select fi_pid,fi_card,fi_account,fi_text,fi_amount,fi_debit
// Item of the category, estimation for a specific month
$aPerMonth[$j] = $this->cn->get_array('select fi_pid,fi_account,fi_text,fi_amount
from forecast_item where fc_id=$1 and fi_pid !=0 order by fi_order ',
array($aCat[$j]['fc_id']));
@ -234,20 +234,8 @@ EOF;
for ($k = 0; $k < count($aItem[$j]); $k++) {
/* for each periode */
for ($l = 0; $l < count($aPeriode); $l++) {
if ($aItem[$j][$k]['fi_account'] == '') {
$fiche->id = $aItem[$j][$k]['fi_card'];
$amount = $fiche->get_solde_detail("j_tech_per = " . $aPeriode[$l]['p_id']);
if ($aItem[$j][$k]['fi_debit'] == 'C' && $amount['debit'] > $amount['credit'])
{
$amount['solde'] = $amount["solde"] * (-1);
}
if ($aItem[$j][$k]['fi_debit'] == 'D' && $amount['debit'] < $amount['credit'])
{
$amount['solde'] = $amount["solde"] * (-1);
}
} else {
if ($aItem[$j][$k]['fi_account'] != '') {
$poste->id = $aItem[$j][$k]['fi_account'];
$aresult = Impress::parse_formula($this->cn, "OK", $poste->id, $aPeriode[$l]['p_id'], $aPeriode[$l]['p_id']);
$tmp_label = $aresult['desc'];
@ -299,9 +287,9 @@ EOF;
$old = $this->cn->get_array("select fc_id from forecast_category where f_id=$1", array($this->forecast_id));
/* save into forecast_item */
for ($i = 0; $i < count($array); $i++) {
$this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_card,fi_order,fc_id,
fi_amount,fi_debit,fi_pid) " .
" select fi_text,fi_account,fi_card,fi_order,$1,fi_amount,fi_debit,fi_pid " .
$this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_order,fc_id,
fi_amount,fi_pid) " .
" select fi_text,fi_account,fi_order,$1,fi_amount,fi_pid " .
" from forecast_item where fc_id=$2", array($array[$i]['fc_id'], $old[$i]['fc_id']));
}
$this->cn->commit();

View file

@ -25,25 +25,25 @@ require_once NOALYSS_INCLUDE.'/class/acc_tva.class.php';
require_once NOALYSS_INCLUDE.'/class/user.class.php';
require_once NOALYSS_INCLUDE.'/lib/zip_extended.class.php';
/* ! \file
/*! \file
* \brief Class Document corresponds to the table document
*/
/* ! \brief Class Document corresponds to the table document
/*! \brief Class Document corresponds to the table document
*/
class Document
{
var $db; /* !< $db Database connexion */
var $d_id; /* !< $d_id Document id */
var $ag_id; /* !< $ag_id action_gestion.ag_id (pk) */
var $d_mimetype; /* !< $d_mimetype */
var $d_filename; /* !< $d_filename */
var $d_lob; /* !< $d_lob the oid of the lob */
var $d_description; /* !< Description of the file */
var $d_number; /* !< $d_number number of the document */
var $md_id; /* !< $md_id document's template */
private $counter; /* !< counter for the items ( goods ) */
var $db; /*!< $db Database connexion */
var $d_id; /*!< $d_id Document id */
var $ag_id; /*!< $ag_id action_gestion.ag_id (pk) */
var $d_mimetype; /*!< $d_mimetype */
var $d_filename; /*!< $d_filename */
var $d_lob; /*!< $d_lob the oid of the lob */
var $d_description; /*!< Description of the file */
var $d_number; /*!< $d_number number of the document */
var $md_id; /*!< $md_id document's template */
private $counter; /*!< counter for the items ( goods ) */
/* Constructor
* \param $p_cn Database connection
@ -98,7 +98,7 @@ class Document
return $new_filename;
}
/* !
/*!
* \brief Generate the document, Call $this-\>replace to replace
* tag by value
* @param p_array contains the data normally it is the $_POST
@ -208,7 +208,7 @@ class Document
}
}
/* ! parseDocument
/*! parseDocument
* \brief This function parse a document and replace all
* the predefined tags by a value. This functions
* generate diffent documents (invoice, order, letter)
@ -223,7 +223,7 @@ class Document
function parseDocument($p_dir, $p_file, $p_type, $p_array)
{
/* !\note replace in the doc the tags by their values.
/*!\note replace in the doc the tags by their values.
* - MY_* table parameter
* - ART_VEN* table quant_sold for invoice
* - CUST_* table quant_sold and fiche for invoice
@ -323,7 +323,7 @@ class Document
}
}
/* ! saveGenerated
/*! saveGenerated
* \brief Save the generated Document
* \param $p_file is the generated file
*
@ -506,7 +506,7 @@ class Document
$cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
}
/* !
/*!
* \brief create and compute a string for reference the doc <A ...>
*
* \return a string
@ -565,7 +565,7 @@ class Document
$this->db->commit();
}
/* !\brief get all the document of a given action
/*!\brief get all the document of a given action
* \param $ag_id the ag_id from action::ag_id (primary key)
* \return an array of objects document or an empty array if nothing found
*/
@ -591,7 +591,7 @@ class Document
}
/* !\brief Get complete all the data member thx info from the database
/*!\brief Get complete all the data member thx info from the database
*/
function get()
@ -611,7 +611,7 @@ class Document
$this->d_description=$row['d_description'];
}
/* !
/*!
* \brief replace the TAG by the real value, this value can be into
* the database or in $_POST
* The possible tags are
@ -1686,7 +1686,7 @@ class Document
return $r;
}
/* !\brief remove a row from the table document, the lob object is not deleted
/*!\brief remove a row from the table document, the lob object is not deleted
* because can be linked elsewhere
*/
@ -1699,7 +1699,7 @@ class Document
$this->db->lo_unlink($d_lob);
}
/* !\brief Move a document from the table document into the concerned row
/*!\brief Move a document from the table document into the concerned row
* the document is not copied : it is only a link
*
* \param $p_internal internal code

View file

@ -153,8 +153,8 @@ class Forecast
/* save into forecast_item */
for ($i=0;$i<count($array);$i++)
{
$this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_card,fi_order,fc_id,fi_amount,fi_debit,fi_pid) ".
" select fi_text,fi_account,fi_card,fi_order,$1,fi_amount,fi_debit,fi_pid ".
$this->cn->exec_sql("insert into forecast_item (fi_text,fi_account,fi_order,fc_id,fi_amount,fi_pid) ".
" select fi_text,fi_account,fi_order,$1,fi_amount,fi_pid ".
" from forecast_item where fc_id=$2",array($array[$i]['fc_id'],$old[$i]['fc_id']));
}
}

View file

@ -33,6 +33,7 @@
require_once NOALYSS_INCLUDE . "/lib/manage_table_sql.class.php";
require_once NOALYSS_INCLUDE . "/database/forecast_item_sql.class.php";
require_once NOALYSS_INCLUDE . "/database/forecast_sql.class.php";
require_once NOALYSS_INCLUDE . "/lib/impress.class.php";
class Forecast_Item_MTable extends Manage_Table_SQL
{
@ -96,10 +97,8 @@ class Forecast_Item_MTable extends Manage_Table_SQL
{
$sql = "select fi_id,fi_text,fi_account,
case when fi_card is null then fi_account
else (select ad_value from fiche_detail where ad_id=23 and f_id=fi_card) end str_account_card,
fi_account str_account_card,
fc_desc,
fi_card,
fi.fi_amount ,
(select p_start from parm_periode pp where pp.p_id=fi.fi_pid) as str_periode
from forecast_item fi join forecast_category fc on (fi.fc_id=fc.fc_id)
@ -114,10 +113,8 @@ class Forecast_Item_MTable extends Manage_Table_SQL
if ( ! isset($p_row['fc_desc'])) {
$cn=$this->get_table()->cn;
$sql= "select fi_id,fi_text,fi_account,
case when fi_card is null then fi_account
else (select ad_value from fiche_detail where ad_id=23 and f_id=fi_card) end str_account_card,
fi_account str_account_card,
fc_desc,
fi_card,
fi.fi_amount ,
(select p_start from parm_periode pp where pp.p_id=fi.fi_pid) as str_periode
from forecast_item fi join forecast_category fc on (fi.fc_id=fc.fc_id)
@ -177,7 +174,6 @@ class Forecast_Item_MTable extends Manage_Table_SQL
ctl: tbl6058da883ded6
fc_id: 88
fi_text: Gérant
fi_card:
fi_account: [4160%]-[4890%]
fi_amount: 3000.0000
fi_pid: 0
@ -192,17 +188,27 @@ class Forecast_Item_MTable extends Manage_Table_SQL
$object_sql->setp("fi_account",$http->post('fi_account'));
$object_sql->setp("fi_amount",$http->post('fi_amount',"number"));
$object_sql->setp("fi_pid",$http->post('fi_pid',"number"));
$object_sql->setp("fi_debit",$http->post('fi_debit'));
$object_sql->setp("fi_amount_initial",$http->post("fi_amount_initial","number"));
$card=trim($http->post("fi_card"));
if ( $card !="") {
$f_id=$object_sql->cn->get_value("select f_id from fiche_detail where ad_value=upper($1) and ad_id=23",[$card]);
if ( $f_id !="") {
$object_sql->setp("fi_card",$f_id);
}
}
}
function check()
{
$object=$this->get_table();
if ( trim($object->getp("fi_text") ) == "") {
$this->set_error("fi_text", _("Intitulé est vide"));
}
if ( trim ($object->getp("fi_account"))=="") {
$this->set_error("fi_account", _("Formule est vide"));
}
if ( trim ($object->getp("fi_account"))=="") {
$this->set_error("fi_account", _("Formule est vide"));
}
if ( ! Impress::check_formula($object->getp("fi_account"))) {
$this->set_error("fi_account", _("Formule invalide"));
}
if ( $this->count_error()==0) return true;
return false;
}
}

View file

@ -668,7 +668,7 @@ class User
/**
*
* \brief return the mini rapport to display on the welcome page
* \return 0 if nothing if found or the report to display (formdef.fr_id)
* \return 0 if nothing if found or the report to display (form_definition.fr_id)
*/
function get_mini_report()