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