noalyss Version-9
follow_up_detail.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20
21/*!\file
22 * \brief Follow_Up details are the details for a actions
23 */
24
25/*!
26 * \brief Follow_Up Details are the details for an actions, it means
27 * the details of an order, delivery order, submit a quote...
28 * this class is linked to the table action_detail
29 * - "id"=>"ad_id", primary key
30 * - "qcode"=>"f_id", quick_code
31 * - "text"=>"ad_text", description lines
32 * - "price_unit"=>"ad_pu", price by unit
33 * - "quantity"=>"ad_quant", quantity
34 * - "tva_id"=>"ad_tva_id", tva_od
35 * - "tva_amount"=>"ad_tva_amount", vat amount
36 * - "total"=>"ad_total_amount", total amount including vat
37 * - "ag_id"=>"ag_id" => foreign key to action_gestion
38 * - db is the database connection
39 */
41{
42 private static $variable=array(
43 "id"=>"ad_id",
44 "qcode"=>"f_id",
45 "text"=>"ad_text",
46 "price_unit"=>"ad_pu",
47 "quantity"=>"ad_quant",
48 "tva_id"=>"ad_tva_id",
49 "tva_amount"=>"ad_tva_amount",
50 "total"=>"ad_total_amount",
51 "ag_id"=>"ag_id"
52 );
54 function __construct ($p_cn,$p_id=0)
55 {
56 $this->db=$p_cn;
57 $this->ad_id=$p_id;
58 }
59 public function get_parameter($p_string)
60 {
61 if ( array_key_exists($p_string,self::$variable) )
62 {
63 $idx=self::$variable[$p_string];
64 return $this->$idx;
65 }
66 else
67 throw new Exception("Attribut inexistant $p_string");
68 }
69 public function set_parameter($p_string,$p_value)
70 {
71 if ( array_key_exists($p_string,self::$variable) )
72 {
73 $idx=self::$variable[$p_string];
74 $this->$idx=$p_value;
75 }
76 else
77 throw new Exception("Attribut inexistant $p_string");
78
79
80 }
81 public function get_info()
82 {
83 return var_export(self::$variable,true);
84 }
85 public function verify()
86 {
87 // Verify that the elt we want to add is correct
88 return 0;
89 }
90 public function save()
91 {
92 if ( $this->ad_id == 0 )
93 $this->insert();
94 else
95 $this->update();
96 }
97
98 public function insert()
99 {
100 if ( $this->verify() != 0 ) return;
101 $sql='INSERT INTO action_detail('.
102 ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
103 ' ad_total_amount, ag_id)'.
104 ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
105 $this->ad_id=$this->db->get_value($sql,array(
106 $this->f_id,
107 $this->ad_text,
108 $this->ad_pu,
109 $this->ad_quant,
110 $this->ad_tva_id,
111 $this->ad_tva_amount,
112 $this->ad_total_amount,
113 $this->ag_id
114 )
115 );
116
117 }
118
119 public function update()
120 {
121 if ( $this->verify() != 0 ) return;
122
123 $sql='UPDATE action_detail '.
124 ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
125 ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
126 ' WHERE ad_id=$9';
127 $this->id=$this->db->exec_sql($sql,array(
128 $this->f_id,
129 $this->ad_text,
130 $this->ad_pu,
131 $this->ad_quant,
132 $this->ad_tva_id,
133 $this->ad_tva_amount,
134 $this->ad_total_amount,
135 $this->ag_id,
136 $this->ad_id
137 )
138 );
139
140
141 }
142 /*!\brief retrieve all the details of an Follow_Up
143 *\return array of Action_Detail
144 *\see Follow_Up::get
145 */
146 public function load_all()
147 {
148 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
149 ad_total_amount, ag_id FROM action_detail ".
150 " where ag_id=$1 order by ad_id";
151 $res=$this->db->get_array(
152 $sql,
153 array($this->ag_id)
154 );
155 if ( $this->db->count() == 0 ) return array();
156 $aRet=array();
157 for($i=0;$i<count($res);$i++)
158 {
159 $a=new Follow_Up_Detail($this->db);
160 $row=$res[$i];
161 foreach ($row as $idx=>$value)
162 {
163 $a->$idx=$value;
164 }
165 $aRet[$i]=clone $a;
166 }
167 return $aRet;
168 }
169 /**
170 * @brief load the todo_list row thanks it's ID
171 * @return boolean true if found else false
172 */
173 public function load():bool
174 {
175 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
176 ad_total_amount, ag_id FROM action_detail".
177 " where ad_id=$1";
178
179 $res=$this->db->get_array(
180 $sql,
181 array($this->ad_id)
182 );
183 if ( $this->db->count() == 0 ) return false;
184 $row=$res[0];
185 foreach (self::$variable as $idx)
186 {
187 $this->$idx=$row[$idx];
188 }
189 return true;
190 }
191 public function delete()
192 {
193 $sql="delete from action_detail where ad_id=$1";
194 $this->db->exec_sql($sql,array($this->ad_id));
195 }
196 /*!\brief Fill an Action_Detail Object with the data contained in an array
197 *\param $array
198 - [ad_id7] => ad_id
199 - [e_march7] => f_id
200 - [e_march7_label] => ad_text
201 - [e_march7_price] => ad_pu
202 - [e_quant7] => ad_quant
203 - [e_march7_tva_id] => ad_tva_id
204 - [e_march7_tva_amount] => ad_tva_amount
205 - [tvac_march7] => ad_total_amount
206 - [ag_id] => ag_id
207 *\param $idx is the idx (example 7)
208 *\note */
209 public function from_array($array,$idx)
210 {
211 $row=$array;
212 $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
213
214 $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
215 if (trim($qcode)=='')
216 {
217 $this->f_id=0;
218 }
219 else
220 {
221 $tmp=new Fiche($this->db);
222 $tmp->get_by_qcode($qcode,false);
223 $this->f_id=$tmp->id;
224 }
225 $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
226 $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
227 $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
228 $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
229 $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
230 $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
231 $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
232 /* protect numeric */
233 if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
234 if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
235 if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
236 if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
237 if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
238 }
239
240 public static function display(Follow_Up $p_follow_up,$p_view)
241 {
242 $option=$p_follow_up->db->get_value("select do_option from document_option "
243 . " where document_type_id=$1 and do_code='detail_operation'",[$p_follow_up->dt_id]);
244
245 require NOALYSS_TEMPLATE."/follow_up_detail_display.php";
246 }
247
248}
249
250/* test::test_me(); */
251
isNumber($p_int)
Definition: ac_common.php:215
$idx
$fl ag_id
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
Follow_Up Details are the details for an actions, it means the details of an order,...
static display(Follow_Up $p_follow_up, $p_view)
set_parameter($p_string, $p_value)
__construct($p_cn, $p_id=0)
load()
load the todo_list row thanks it's ID
from_array($array, $idx)
Fill an Action_Detail Object with the data contained in an array.
load_all()
retrieve all the details of an Follow_Up
$SecUser db