Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once ('class_pre_operation.php');
00026
00027
00028
00029
00030 class Pre_op_ods extends Pre_operation_detail
00031 {
00032 var $op;
00033 function __construct($cn,$p_id=0)
00034 {
00035 parent::__construct($cn,$p_id);
00036 $this->operation->od_direct='f';
00037 }
00038
00039 function get_post()
00040 {
00041 parent::get_post();
00042 $this->operation->od_direct='f';
00043 for ($i=0;$i<$this->operation->nb_item;$i++)
00044 {
00045
00046 $this->{"e_account".$i}=$_POST['e_account'.$i];
00047 $this->{"e_account".$i."_amount"}=$_POST['e_account'.$i."_amount"];
00048 $this->{"e_account".$i."_type"}=$_POST['e_account'.$i."_type"];
00049
00050 }
00051 }
00052
00053
00054
00055
00056 function save()
00057 {
00058 try
00059 {
00060 $this->db->start();
00061 if ($this->operation->save() == false )
00062 return;
00063
00064
00065 for ($i=0;$i<$this->operation->nb_item;$i++)
00066 {
00067 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00068 'opd_debit,od_id)'.
00069 ' values '.
00070 "('%s',%.2f,'%s',%d)",
00071 $this->{"e_account".$i},
00072 $this->{"e_account".$i."_amount"},
00073 ($this->{"e_account".$i."_type"}=='d')?'t':'f',
00074 $this->operation->od_id
00075 );
00076 $this->db->exec_sql($sql);
00077 }
00078 }
00079 catch (Exception $e)
00080 {
00081 echo ($e->getMessage());
00082 $this->db->rollback();
00083 }
00084
00085 }
00086
00087
00088 function compute_array()
00089 {
00090 $count=0;
00091 $a_op=$this->operation->load();
00092 $array=$this->operation->compute_array($a_op);
00093 $p_array=$this->load();
00094 foreach ($p_array as $row)
00095 {
00096 $c=($row['opd_debit']=='t')?'d':'c';
00097 $array+=array("e_account".$count=>$row['opd_poste'],
00098 "e_account".$count."_amount"=>$row['opd_amount'],
00099 "e_account".$count."_type"=>$c
00100 );
00101 $count++;
00102
00103 }
00104 return $array;
00105 }
00106
00107
00108
00109 function load()
00110 {
00111 $sql="select opd_id,opd_poste,opd_amount,opd_debit".
00112 " from op_predef_detail where od_id=".$this->operation->od_id.
00113 " order by opd_debit, opd_id,opd_amount";
00114 $res=$this->db->exec_sql($sql);
00115 $array=Database::fetch_all($res);
00116 return $array;
00117 }
00118 function set_od_id($p_id)
00119 {
00120 $this->operation->od_id=$p_id;
00121 }
00122 }