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
00026 require_once ('class_pre_operation.php');
00027
00028
00029
00030
00031 class Pre_Op_Advanced extends Pre_operation_detail
00032 {
00033 var $op;
00034 function Pre_Op_Advanced($cn)
00035 {
00036 parent::__construct($cn);
00037 $this->operation->od_direct='t';
00038 }
00039 function get_post()
00040 {
00041 parent::get_post();
00042
00043 extract($_POST);
00044
00045 for ($i=0;$i<$this->operation->nb_item;$i++)
00046 {
00047 if ( ! isset ($_POST['poste'.$i]) && ! isset ($_POST['qc_'.$i]))
00048 continue;
00049 $this->{'poste'.$i}=(isset($_POST['qc_'.$i]))?$_POST['qc_'.$i]:$_POST['poste'.$i];
00050 $this->{'isqc'.$i}=(isset($_POST['qc_'.$i]))?'t':'f';
00051 $this->{"amount".$i}=$_POST['amount'.$i];
00052 $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
00053
00054 }
00055 }
00056
00057
00058
00059
00060 function save()
00061 {
00062 try
00063 {
00064 $this->db->start();
00065 if ($this->operation->save() == false )
00066 return;
00067
00068 for ($i=0;$i<$this->operation->nb_item;$i++)
00069 {
00070 if ( ! isset ($this->{"poste".$i}))
00071 continue;
00072
00073 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
00074 'opd_debit,od_id,opd_qc)'.
00075 ' values '.
00076 "('%s',%.2f,'%s',%d,'%s')",
00077 $this->{"poste".$i},
00078 $this->{"amount".$i},
00079 $this->{"ck".$i},
00080 $this->operation->od_id,
00081 $this->{'isqc'.$i}
00082 );
00083
00084 $this->db->exec_sql($sql);
00085
00086 }
00087 }
00088 catch (Exception $e)
00089 {
00090 echo ($e->getMessage());
00091 $this->db->rollback();
00092 }
00093
00094 }
00095
00096
00097 function compute_array()
00098 {
00099 $count=0;
00100 $a_op=$this->operation->load();
00101 $array=$this->operation->compute_array($a_op);
00102 $array['desc']=$array['e_comm'];
00103 $p_array=$this->load();
00104 if (empty($p_array)) return array();
00105 foreach ($p_array as $row)
00106 {
00107 $tmp_array=array("qc_".$count=>'',
00108 "poste".$count=>'',
00109 "amount".$count=>$row['opd_amount'],
00110 'ck'.$count=>$row['opd_debit']
00111 );
00112
00113 if ( $row['opd_qc'] == 't' )
00114 $tmp_array['qc_'.$count]=$row['opd_poste'];
00115 else
00116 $tmp_array['poste'.$count]=$row['opd_poste'];
00117
00118
00119 if ( $row['opd_debit'] == 'f' )
00120 unset ($tmp_array['ck'.$count]);
00121
00122 $array+=$tmp_array;
00123 $count++;
00124
00125 }
00126
00127 return $array;
00128 }
00129
00130
00131
00132 function load()
00133 {
00134 $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
00135 " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
00136 " order by opd_id";
00137 $res=$this->db->exec_sql($sql);
00138 $array=Database::fetch_all($res);
00139 return $array;
00140 }
00141 function set_od_id($p_id)
00142 {
00143 $this->operation->od_id=$p_id;
00144 }
00145 }