operation->od_direct='f'; } function get_post() { parent::get_post(); $this->operation->od_direct='f'; $this->e_client=$_POST['e_client']; for ($i=0;$i<$this->operation->nb_item;$i++) { $march="e_march".$i; $this->$march=$_POST['e_march'.$i]; $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"]; $this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0; $this->{"e_quant".$i}=$_POST['e_quant'.$i]; } } /*! * \brief save the detail and op in the database * */ function save() { try { $this->db->start(); if ($this->operation->save() == false ) return; // save the client $sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'. ' values '. "(%d,'%s','%s')", $this->operation->od_id, $this->e_client, "t"); $this->db->exec_sql($sql); // save the selling for ($i=0;$i<$this->operation->nb_item;$i++) { if ( strlen(trim($this->{"e_march".$i}))==0) continue; $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,opd_tva_id,opd_quantity,'. 'opd_debit,od_id)'. ' values '. "('%s',%.2f,%d,%f,'%s',%d)", $this->{"e_march".$i}, $this->{"e_march".$i."_price"}, $this->{"e_march".$i."_tva_id"}, $this->{"e_quant".$i}, 'f', $this->operation->od_id ); $this->db->exec_sql($sql); } } catch (Exception $e) { echo ($e->getMessage()); $this->db->rollback(); } $this->db->commit(); } /*!\brief compute an array accordingly with the FormVenView function */ function compute_array() { $count=0; $a_op=$this->operation->load(); $array=$this->operation->compute_array($a_op); $p_array=$this->load(); foreach ($p_array as $row) { if ( $row['opd_debit']=='t') { $array+=array('e_client'=>$row['opd_poste']); } else { $array+=array("e_march".$count=>$row['opd_poste'], "e_march".$count."_price"=>$row['opd_amount'], "e_march".$count."_tva_id"=>$row['opd_tva_id'], "e_quant".$count=>$row['opd_quantity'] ); $count++; } } return $array; } /*!\brief load the data from the database and return an array * \return an array */ function load() { $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,". " opd_quantity from op_predef_detail where od_id=".$this->operation->od_id. " order by opd_id"; $res=$this->db->exec_sql($sql); $array=Database::fetch_all($res); return $array; } function set_od_id($p_id) { $this->operation->od_id=$p_id; } }