|
1 <?php |
|
2 |
|
3 include("strings.inc"); |
|
4 |
|
5 class ingres |
|
6 { |
|
7 var $dia; |
|
8 var $mes; |
|
9 var $any; |
|
10 var $hora; |
|
11 var $minut; |
|
12 var $modificat; // Timestamp |
|
13 var $rao; |
|
14 var $butxaca; |
|
15 var $tipus; |
|
16 var $diners; |
|
17 var $comentari; |
|
18 |
|
19 function data() |
|
20 { |
|
21 return mktime($this->hora, $this->minut, 0, $this->mes, $this->dia, |
|
22 $this->any); |
|
23 } |
|
24 |
|
25 function setData($data) |
|
26 { |
|
27 $this->dia = date('d',$data); |
|
28 $this->mes = date('m',$data); |
|
29 $this->any = date('Y',$data); |
|
30 $this->hora = date('H',$data); |
|
31 $this->minut = date('i',$data); |
|
32 } |
|
33 |
|
34 function DBAfegir($connexio) |
|
35 { |
|
36 $query = "INSERT INTO ingressos |
|
37 (data,data_modif,rao,quantitat, |
|
38 butxaca,comentari) |
|
39 VALUES("; |
|
40 $query .= "FROM_UNIXTIME(" . mktime($this->hora, |
|
41 $this->minut, |
|
42 0, |
|
43 $this->mes, |
|
44 $this->dia, |
|
45 $this->any) . "), "; |
|
46 $query .= "FROM_UNIXTIME(". time() . "), "; |
|
47 $query .= "'" . strtosql( $this->rao) . "', "; |
|
48 if($this->tipus == "ingres") |
|
49 $query .= $this->diners . ", "; |
|
50 else |
|
51 $query .= "-". $this->diners . ", "; |
|
52 $query .= $this->butxaca . ", "; |
|
53 $query .= "'" . strtosql( $this->comentari) . "'); "; |
|
54 |
|
55 |
|
56 $resultat = mysql_query($query, $connexio); |
|
57 |
|
58 if (!$resultat) |
|
59 { |
|
60 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
61 return 1; |
|
62 } |
|
63 |
|
64 return 0; |
|
65 } |
|
66 |
|
67 function DBModificar($connexio, $data_vella) |
|
68 { |
|
69 $query = "UPDATE ingressos SET "; |
|
70 $query .= "data=FROM_UNIXTIME(" . $this->data() . "), "; |
|
71 $query .= "data_modif=FROM_UNIXTIME(". time() . "), "; |
|
72 $query .= "rao='" . strtosql( $this->rao) . "', "; |
|
73 $query .= "quantitat="; |
|
74 if($this->tipus == "ingres") |
|
75 $query .= $this->diners . ", "; |
|
76 else |
|
77 $query .= "-". $this->diners . ", "; |
|
78 $query .= "butxaca=" . $this->butxaca . ", "; |
|
79 $query .= "comentari='" . strtosql( $this->comentari) . "' "; |
|
80 $query .= "WHERE data=FROM_UNIXTIME(" . $data_vella . ");"; |
|
81 |
|
82 |
|
83 $resultat = mysql_query($query, $connexio); |
|
84 |
|
85 if (!$resultat) |
|
86 { |
|
87 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
88 return 1; |
|
89 } |
|
90 |
|
91 return 0; |
|
92 } |
|
93 |
|
94 function DBBorrar($connexio) |
|
95 { |
|
96 $query = "DELETE FROM ingressos WHERE UNIX_TIMESTAMP(data) = "; |
|
97 $query .= $this->data() . ";"; |
|
98 |
|
99 $resultat = mysql_query($query,$connexio); |
|
100 if (!$resultat) |
|
101 { |
|
102 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
103 return 1; |
|
104 } |
|
105 return 0; |
|
106 |
|
107 } |
|
108 |
|
109 function ingres($connexio=-1, $data=0) |
|
110 { |
|
111 // De nul |
|
112 if ($connexio==-1) |
|
113 { |
|
114 $this->dia = date('d'); |
|
115 $this->mes = date('m'); |
|
116 $this->any = date('Y'); |
|
117 $this->hora = date('H'); |
|
118 $this->minut = date('i'); |
|
119 $this->rao = ""; |
|
120 $this->butxaca = -1; |
|
121 $this->tipus = "despesa"; |
|
122 $this->diners = 0; |
|
123 $this->comentari = ""; |
|
124 } |
|
125 else |
|
126 { |
|
127 $query = "SELECT UNIX_TIMESTAMP(data), |
|
128 UNIX_TIMESTAMP(data_modif), rao, butxaca, quantitat, |
|
129 comentari FROM ingressos WHERE UNIX_TIMESTAMP(data) = "; |
|
130 $query .= $data . ";"; |
|
131 |
|
132 $resultat = mysql_query($query,$connexio); |
|
133 if (!$resultat) |
|
134 { |
|
135 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
136 return 1; // Què passa amb un return aquí? |
|
137 } |
|
138 |
|
139 // Només hi haurà un resultat |
|
140 $fila = mysql_fetch_row($resultat); |
|
141 |
|
142 settype($fila[4], float); |
|
143 |
|
144 $this->dia = date('d',$fila[0]); |
|
145 $this->mes = date('m',$fila[0]); |
|
146 $this->any = date('Y',$fila[0]); |
|
147 $this->hora = date('H',$fila[0]); |
|
148 $this->minut = date('i',$fila[0]); |
|
149 $this->modificat = $fila[1]; |
|
150 $this->rao = $fila[2]; |
|
151 $this->butxaca = $fila[3]; |
|
152 if ($fila[4] > 0) |
|
153 $this->tipus = "ingres"; |
|
154 else |
|
155 $this->tipus = "despesa"; |
|
156 $this->diners = abs($fila[4]); |
|
157 $this->comentari = $fila[5]; |
|
158 |
|
159 } |
|
160 } |
|
161 |
|
162 } |
|
163 |
|
164 class moviment |
|
165 { |
|
166 var $dia; |
|
167 var $mes; |
|
168 var $any; |
|
169 var $hora; |
|
170 var $minut; |
|
171 var $modificat; // Timestamp |
|
172 var $rao; |
|
173 var $butxaca_origen; |
|
174 var $butxaca_desti; |
|
175 var $diners; |
|
176 var $comentari; |
|
177 |
|
178 |
|
179 function data() |
|
180 { |
|
181 return mktime($this->hora, $this->minut, 0, $this->mes, $this->dia, |
|
182 $this->any); |
|
183 } |
|
184 function setData($data) |
|
185 { |
|
186 $this->dia = date('d',$data); |
|
187 $this->mes = date('m',$data); |
|
188 $this->any = date('Y',$data); |
|
189 $this->hora = date('H',$data); |
|
190 $this->minut = date('i',$data); |
|
191 } |
|
192 |
|
193 function DBAfegir($connexio) |
|
194 { |
|
195 $query = "INSERT INTO moviments |
|
196 (data,data_modif,rao,quantitat, |
|
197 butxaca_origen,butxaca_desti,comentari) |
|
198 VALUES("; |
|
199 $query .= "FROM_UNIXTIME(" . $this->data() . "), "; |
|
200 $query .= "FROM_UNIXTIME(". time() . "), "; |
|
201 $query .= "'" . strtosql( $this->rao) . "', "; |
|
202 $query .= $this->diners . ", "; |
|
203 $query .= $this->butxaca_origen . ", "; |
|
204 $query .= $this->butxaca_desti . ", "; |
|
205 $query .= "'" . strtosql( $this->comentari) . "'); "; |
|
206 |
|
207 |
|
208 $resultat = mysql_query($query, $connexio); |
|
209 |
|
210 if (!$resultat) |
|
211 { |
|
212 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
213 return 1; |
|
214 } |
|
215 |
|
216 return 0; |
|
217 } |
|
218 |
|
219 function DBBorrar($connexio) |
|
220 { |
|
221 $query = "DELETE FROM moviments WHERE UNIX_TIMESTAMP(data) = "; |
|
222 $query .= mktime($this->hora, |
|
223 $this->minut, |
|
224 0, |
|
225 $this->mes, |
|
226 $this->dia, |
|
227 $this->any) . ";"; |
|
228 |
|
229 $resultat = mysql_query($query,$connexio); |
|
230 if (!$resultat) |
|
231 { |
|
232 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
233 return 1; |
|
234 } |
|
235 return 0; |
|
236 |
|
237 } |
|
238 |
|
239 function moviment($connexio=-1, $data=0) |
|
240 { |
|
241 // De nul |
|
242 if ($connexio==-1) |
|
243 { |
|
244 $this->dia = date('d'); |
|
245 $this->mes = date('m'); |
|
246 $this->any = date('Y'); |
|
247 $this->hora = date('H'); |
|
248 $this->minut = date('i'); |
|
249 $this->rao = ""; |
|
250 $this->butxaca_origen = -1; |
|
251 $this->butxaca_desti = -1; |
|
252 $this->diners = 0; |
|
253 $this->comentari = ""; |
|
254 } |
|
255 else |
|
256 { |
|
257 $query = "SELECT UNIX_TIMESTAMP(data), |
|
258 UNIX_TIMESTAMP(data_modif), rao, butxaca_origen, butxaca_desti, |
|
259 quantitat, |
|
260 comentari FROM moviments WHERE UNIX_TIMESTAMP(data) = "; |
|
261 $query .= $data . ";"; |
|
262 |
|
263 $resultat = mysql_query($query,$connexio); |
|
264 if (!$resultat) |
|
265 { |
|
266 echo mysql_errno().": ".mysql_error()."<BR>"; |
|
267 return 1; // Què passa amb un return aquí? |
|
268 } |
|
269 |
|
270 // Només hi haurà un resultat |
|
271 $fila = mysql_fetch_row($resultat); |
|
272 |
|
273 settype($fila[4], float); |
|
274 |
|
275 $this->dia = date('d',$fila[0]); |
|
276 $this->mes = date('m',$fila[0]); |
|
277 $this->any = date('Y',$fila[0]); |
|
278 $this->hora = date('H',$fila[0]); |
|
279 $this->minut = date('i',$fila[0]); |
|
280 $this->modificat = $fila[1]; |
|
281 $this->rao = $fila[2]; |
|
282 $this->butxaca_origen = $fila[3]; |
|
283 $this->butxaca_desti = $fila[4]; |
|
284 $this->diners = abs($fila[5]); |
|
285 $this->comentari = $fila[6]; |
|
286 |
|
287 } |
|
288 } |
|
289 |
|
290 } |
|
291 |
|
292 ?> |