noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 */
40#[AllowDynamicProperties]
42{
43 private static $variable=array(
44 "id"=>"ad_id",
45 "qcode"=>"f_id",
46 "text"=>"ad_text",
47 "price_unit"=>"ad_pu",
48 "quantity"=>"ad_quant",
49 "tva_id"=>"ad_tva_id",
50 "tva_amount"=>"ad_tva_amount",
51 "total"=>"ad_total_amount",
52 "ag_id"=>"ag_id"
53 );
55 function __construct ($p_cn,$p_id=0)
56 {
57 $this->db=$p_cn;
58 $this->ad_id=$p_id;
59 }
60 public function get_parameter($p_string)
61 {
62 if ( array_key_exists($p_string,self::$variable) )
63 {
64 $idx=self::$variable[$p_string];
65 return $this->$idx;
66 }
67 else
68 throw new Exception("Attribut inexistant $p_string");
69 }
70 public function set_parameter($p_string,$p_value)
71 {
72 if ( array_key_exists($p_string,self::$variable) )
73 {
74 $idx=self::$variable[$p_string];
75 $this->$idx=$p_value;
76 }
77 else
78 throw new Exception("Attribut inexistant $p_string");
79
80
81 }
82 public function get_info()
83 {
84 return var_export(self::$variable,true);
85 }
86 public function verify()
87 {
88 // Verify that the elt we want to add is correct
89 return 0;
90 }
91 public function save()
92 {
93 if ( $this->ad_id == 0 )
94 $this->insert();
95 else
96 $this->update();
97 }
98
99 public function insert()
100 {
101 if ( $this->verify() != 0 ) return;
102 $sql='INSERT INTO action_detail('.
103 ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
104 ' ad_total_amount, ag_id)'.
105 ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
106 $this->ad_id=$this->db->get_value($sql,array(
107 $this->f_id,
108 $this->ad_text,
109 $this->ad_pu,
110 $this->ad_quant,
111 $this->ad_tva_id,
112 $this->ad_tva_amount,
113 $this->ad_total_amount,
114 $this->ag_id
115 )
116 );
117
118 }
119
120 public function update()
121 {
122 if ( $this->verify() != 0 ) return;
123
124 $sql='UPDATE action_detail '.
125 ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
126 ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
127 ' WHERE ad_id=$9';
128 $this->id=$this->db->exec_sql($sql,array(
129 $this->f_id,
130 $this->ad_text,
131 $this->ad_pu,
132 $this->ad_quant,
133 $this->ad_tva_id,
134 $this->ad_tva_amount,
135 $this->ad_total_amount,
136 $this->ag_id,
137 $this->ad_id
138 )
139 );
140
141
142 }
143 /*!\brief retrieve all the details of an Follow_Up
144 *\return array of Action_Detail
145 *\see Follow_Up::get
146 */
147 public function load_all()
148 {
149 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
150 ad_total_amount, ag_id FROM action_detail ".
151 " where ag_id=$1 order by ad_id";
152 $res=$this->db->get_array(
153 $sql,
154 array($this->ag_id)
155 );
156 if ( $this->db->count() == 0 ) return array();
157 $aRet=array();
158 for($i=0;$i<count($res);$i++)
159 {
160 $a=new Follow_Up_Detail($this->db);
161 $row=$res[$i];
162 foreach ($row as $idx=>$value)
163 {
164 $a->$idx=$value;
165 }
166 $aRet[$i]=clone $a;
167 }
168 return $aRet;
169 }
170 /**
171 * @brief load the todo_list row thanks it's ID
172 * @return boolean true if found else false
173 */
174 public function load():bool
175 {
176 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
177 ad_total_amount, ag_id FROM action_detail".
178 " where ad_id=$1";
179
180 $res=$this->db->get_array(
181 $sql,
182 array($this->ad_id)
183 );
184 if ( $this->db->count() == 0 ) return false;
185 $row=$res[0];
186 foreach (self::$variable as $idx)
187 {
188 $this->$idx=$row[$idx];
189 }
190 return true;
191 }
192 public function delete()
193 {
194 $sql="delete from action_detail where ad_id=$1";
195 $this->db->exec_sql($sql,array($this->ad_id));
196 }
197 /*!\brief Fill an Action_Detail Object with the data contained in an array
198 *\param $array
199 - [ad_id7] => ad_id
200 - [e_march7] => f_id
201 - [e_march7_label] => ad_text
202 - [e_march7_price] => ad_pu
203 - [e_quant7] => ad_quant
204 - [e_march7_tva_id] => ad_tva_id
205 - [e_march7_tva_amount] => ad_tva_amount
206 - [tvac_march7] => ad_total_amount
207 - [ag_id] => ag_id
208 *\param $idx is the idx (example 7)
209 *\note */
210 public function from_array($array,$idx)
211 {
212 $row=$array;
213 $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
214
215 $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
216 if (trim($qcode)=='')
217 {
218 $this->f_id=0;
219 }
220 else
221 {
222 $tmp=new Fiche($this->db);
223 $tmp->get_by_qcode($qcode,false);
224 $this->f_id=$tmp->id;
225 }
226 $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
227 $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
228 $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
229 $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
230 $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
231 $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
232 $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
233 /* protect numeric */
234 if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
235 if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
236 if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
237 if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
238 if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
239 }
240
241 public static function display(Follow_Up $p_follow_up,$p_view)
242 {
243 $option=$p_follow_up->db->get_value("select do_option from document_option "
244 . " where document_type_id=$1 and do_code='detail_operation'",[$p_follow_up->dt_id]);
245
246 require NOALYSS_TEMPLATE."/follow_up_detail_display.php";
247 }
248
249}
250
251/* test::test_me(); */
252
isNumber($p_int)
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
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
class_action for manipulating actions action can be :
$SecUser db