|
noalyss
Version-6.7.2
|
Class rapport Create, view, modify and parse report. More...
Public Member Functions | |
| __construct ($p_cn, $p_id=0) | |
| Constructor. | |
| delete () | |
| exist ($p_id=0) | |
| check if a report exist | |
| export_csv ($p_file) | |
| write to a file the definition of a report | |
| form ($p_line=0) | |
| Display a form for encoding a new report or update one. | |
| from_array ($p_array) | |
| fill a form thanks an array, usually it is $_POST | |
| get_list () | |
| get a list from formdef of all defined form | |
| get_name () | |
| Return the report's name. | |
| get_row ($p_start, $p_end, $p_type_date) | |
| return all the row and parse formula from a report | |
| insert () | |
| load () | |
| the fr_id MUST be set before calling | |
| make_array () | |
| To make a SELECT button with the needed value, it is used by the SELECT widget. | |
| save () | |
| save into form and form_def | |
| update () | |
| upload () | |
| upload a definition of a report and insert it into the database | |
Static Public Member Functions | |
| static | test_me () |
Data Fields | |
| $aAcc_Report_row | |
| $db | |
| $id | |
| $name | |
| $nb | |
Class rapport Create, view, modify and parse report.
Definition at line 33 of file class_acc_report.php.
| Acc_Report::__construct | ( | $ | p_cn, |
| $ | p_id = 0 |
||
| ) |
| Acc_Report::exist | ( | $ | p_id = 0 | ) |
check if a report exist
| $p_id,optional,if | given check the report with this fr_id |
Definition at line 415 of file class_acc_report.php.
References $ret, db, id, and Database\num_row().
{
$c=$this->id;
if ( $p_id != 0 ) $c=$p_id;
$ret=$this->db->exec_sql("select fr_label from formdef where fr_id=$1",array($c));
if (Database::num_row($ret) == 0) return false;
return true;
}
| Acc_Report::export_csv | ( | $ | p_file | ) |
write to a file the definition of a report
| p_file | is the file name (default php://output) |
Definition at line 360 of file class_acc_report.php.
| Acc_Report::form | ( | $ | p_line = 0 | ) |
Display a form for encoding a new report or update one.
| $p_line | number of line |
Definition at line 106 of file class_acc_report.php.
References $r, HtmlInput\hidden(), id, and name.
{
$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;
}
| Acc_Report::from_array | ( | $ | p_array | ) |
fill a form thanks an array, usually it is $_POST
| $p_array | keys = fr_id, form_nom,textXX, formXX, posXX where XX is an number |
Definition at line 269 of file class_acc_report.php.
get a list from formdef of all defined form
Definition at line 330 of file class_acc_report.php.
References $array, $obj, $ret, $row, $sql, $tmp, db, Database\fetch_all(), and Database\num_row().
{
$sql="select fr_id,fr_label from formdef order by fr_label";
$ret=$this->db->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->id=$row['fr_id'];
$tmp->name=$row['fr_label'];
$obj[]=clone $tmp;
}
return $obj;
}
Return the report's name.
Definition at line 51 of file class_acc_report.php.
References $a, $ret, db, Database\fetch_array(), name, and Database\num_row().
| Acc_Report::get_row | ( | $ | p_start, |
| $ | p_end, | ||
| $ | p_type_date | ||
| ) |
return all the row and parse formula from a report
| $p_start | start periode |
| $p_end | end periode |
| $p_type_date | type of the date : periode or calendar |
Definition at line 65 of file class_acc_report.php.
References $Max, $Res, db, Database\fetch_array(), Database\num_row(), and Impress\parse_formula().
{
$Res=$this->db->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");
$Max=Database::num_row($Res);
if ($Max==0)
{
$this->row=0;
return null;
}
$col=array();
for ($i=0;$i<$Max;$i++)
{
$l_line=Database::fetch_array($Res,$i);
$col[]=Impress::parse_formula($this->db,
$l_line['fo_label'],
$l_line['fo_formula'],
$p_start,
$p_end,
true,
$p_type_date
);
} //for ($i
$this->row=$col;
return $col;
}
Definition at line 187 of file class_acc_report.php.
References $e, $ix, $row, db, echo, Database\fetch_result(), name, and trim().
Referenced by save(), and upload().
{
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)
{
$this->db->rollback();
echo $e->getMessage();
}
$this->db->commit();
}
| Acc_Report::load | ( | ) |
the fr_id MUST be set before calling
Definition at line 287 of file class_acc_report.php.
References $array, $f, $obj, $r, $sql, db, Database\fetch_all(), Database\fetch_result(), name, and Database\num_row().
Referenced by export_csv().
{
$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;
}
| Acc_Report::save | ( | ) |
| static Acc_Report::test_me | ( | ) | [static] |
Definition at line 423 of file class_acc_report.php.
References $_REQUEST, $a, $array, $b, $cn, echo, HtmlInput\hidden(), id, and HtmlInput\submit().
{
$cn=new Database(dossier::id());
$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);
}
}
Definition at line 225 of file class_acc_report.php.
References $e, $ix, $row, db, echo, name, and trim().
Referenced by save().
{
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)
{
$this->db->rollback();
echo $e->getMessage();
}
$this->db->commit();
}
upload a definition of a report and insert it into the database
Definition at line 378 of file class_acc_report.php.
References $array, $data, $file, $obj, alert(), db, insert(), name, and trim().
{
if ( empty ($_FILES) ) return;
if ( strlen(trim($_FILES['report']['tmp_name'])) == 0 )
{
alert("Nom de fichier est vide");
return;
}
$file_report=tempnam('tmp','file_report');
if ( move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
{
// File is uploaded now we can try to parse it
$file=fopen($file_report,'r');
$data=fgetcsv($file);
if ( empty($data) ) return;
$this->name=$data[0];
$array=array();
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;
}
$this->aAcc_Report_row=$array;
$this->insert();
}
}
| Acc_Report::$aAcc_Report_row |
array of rapport_row
Definition at line 39 of file class_acc_report.php.
| Acc_Report::$db |
$db database connx
Definition at line 36 of file class_acc_report.php.
| Acc_Report::$id |
$id formdef.fr_id
Definition at line 37 of file class_acc_report.php.
| Acc_Report::$name |
$name report's name
Definition at line 38 of file class_acc_report.php.
| Acc_Report::$nb |
Definition at line 40 of file class_acc_report.php.