llistes.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 llistes
viric@0
     6
{
viric@0
     7
viric@0
     8
function LlistaButxaques($connexio)
viric@0
     9
{
viric@0
    10
?>
viric@0
    11
<table border=1>
viric@0
    12
<tr>
viric@0
    13
	<th><?php echo _("ID") ?>
viric@0
    14
	<th><?php echo _("Nom") ?>
viric@0
    15
<?php
viric@0
    16
viric@0
    17
	$butxaques = obtenir_butxaques($connexio);
viric@0
    18
viric@0
    19
	foreach(array_keys($butxaques) as $i)
viric@0
    20
	{
viric@0
    21
		echo "<TR>\n";
viric@0
    22
		echo "\t<TD>" . $i . "\n";
viric@0
    23
		echo "\t<TD>" . strtohtml($butxaques[$i]) . "\n";
viric@0
    24
	}
viric@0
    25
viric@0
    26
	
viric@0
    27
?>
viric@0
    28
viric@0
    29
</table>
viric@0
    30
<?php
viric@0
    31
	return 0;
viric@0
    32
}
viric@0
    33
viric@0
    34
function LlistaMoviments($connexio, $ordre=1)
viric@0
    35
{
viric@0
    36
?>
viric@0
    37
<table border=1>
viric@0
    38
<tr>
viric@0
    39
	<th><a href="llista-moviments?ordre=1"><?php echo _("Data") ?></a>
viric@0
    40
	<th><a href="llista-moviments?ordre=2"><?php echo _("Modificat") ?></a>
viric@0
    41
	<th><?php echo _("Orígen") ?>
viric@0
    42
	<th><?php echo _("Destí") ?>
viric@0
    43
	<th><?php echo _("Diners") ?>
viric@0
    44
	<th><?php echo _("Raó") ?>
viric@0
    45
<?php
viric@0
    46
	$butxaques = obtenir_butxaques($connexio);
viric@0
    47
viric@0
    48
	if ($ordre == 1)
viric@0
    49
		$query ="SELECT UNIX_TIMESTAMP(data),
viric@0
    50
		UNIX_TIMESTAMP(data_modif), butxaca_origen,
viric@0
    51
		butxaca_desti, quantitat, rao FROM moviments
viric@0
    52
		ORDER BY data DESC;";
viric@0
    53
	else
viric@0
    54
		$query ="SELECT UNIX_TIMESTAMP(data),
viric@0
    55
		UNIX_TIMESTAMP(data_modif), butxaca_origen,
viric@0
    56
		butxaca_desti, quantitat, rao FROM moviments
viric@0
    57
		ORDER BY data_modif DESC;";
viric@0
    58
	$resultat = mysql_query($query, $connexio);
viric@0
    59
viric@0
    60
	if (!$resultat)
viric@0
    61
	{
viric@0
    62
		echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
    63
		return 1;
viric@0
    64
	}
viric@0
    65
viric@0
    66
	while ($fila = mysql_fetch_row($resultat))
viric@0
    67
	{
viric@0
    68
		echo "<TR>\n";
viric@0
    69
		echo "\t<TD><a href=\"update-moviment?id=". $fila[0].
viric@0
    70
			"\">" . date("d/m/Y H:i",$fila[0]) .
viric@0
    71
			"</a>\n";
viric@0
    72
		echo "\t<TD>". date("d/m/Y H:i",$fila[1]) ."\n";
viric@0
    73
		echo "\t<TD>" . strtohtml($butxaques[$fila[2]]) . "\n";
viric@0
    74
		echo "\t<TD>" . strtohtml($butxaques[$fila[3]]) . "\n";
viric@0
    75
		echo "\t<TD>" . sprintf("%.2f", $fila[4]) . "\n";
viric@0
    76
		echo "\t<TD>" . strtohtml($fila[5]) . "\n";
viric@0
    77
	}
viric@0
    78
viric@0
    79
	
viric@0
    80
?>
viric@0
    81
viric@0
    82
</table>
viric@0
    83
<?php
viric@0
    84
	return 0;
viric@0
    85
}
viric@0
    86
viric@0
    87
function LlistaIngressos($connexio, $ordre=1)
viric@0
    88
// 1 = per data. altres, per data_modif
viric@0
    89
{
viric@0
    90
?>
viric@0
    91
<table border=1>
viric@0
    92
<tr>
viric@0
    93
	<th><a href="llista-ingressos?ordre=1"><?php echo _("Data") ?></a>
viric@0
    94
	<th><a href="llista-ingressos?ordre=2"><?php echo _("Modificat") ?></a>
viric@0
    95
	<th><?php echo _("Butxaca") ?>
viric@0
    96
	<th><?php echo _("Diners") ?>
viric@0
    97
	<th><?php echo _("Raó") ?>
viric@0
    98
<?php
viric@0
    99
	$butxaques = obtenir_butxaques($connexio);
viric@0
   100
viric@0
   101
	if ($ordre == 1)
viric@0
   102
		$query ="SELECT UNIX_TIMESTAMP(data),
viric@0
   103
			UNIX_TIMESTAMP(data_modif), butxaca,
viric@0
   104
			quantitat, rao FROM ingressos ORDER BY data DESC;";
viric@0
   105
	else
viric@0
   106
		$query ="SELECT UNIX_TIMESTAMP(data),
viric@0
   107
			UNIX_TIMESTAMP(data_modif), butxaca,
viric@0
   108
			quantitat, rao FROM ingressos ORDER BY data_modif DESC;";
viric@0
   109
	$resultat = mysql_query($query, $connexio);
viric@0
   110
viric@0
   111
	if (!$resultat)
viric@0
   112
	{
viric@0
   113
		echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
   114
		return 1;
viric@0
   115
	}
viric@0
   116
viric@0
   117
	while ($fila = mysql_fetch_row($resultat))
viric@0
   118
	{
viric@0
   119
		echo "<TR>\n";
viric@0
   120
		echo "\t<TD><a href=\"update-ingres?id=". $fila[0].
viric@0
   121
			"\">" . date("d/m/Y H:i",$fila[0]) .
viric@0
   122
			"</a>\n";
viric@0
   123
		echo "\t<TD>". date("d/m/Y H:i",$fila[1]) ."\n";
viric@0
   124
		echo "\t<TD>" . strtohtml($butxaques[$fila[2]]) . "\n";
viric@0
   125
		echo "\t<TD>" . pricetohtml( $fila[3]) . "\n";
viric@0
   126
		echo "\t<TD>" . strtohtml($fila[4]) . "\n";
viric@0
   127
			"</a>\n";
viric@0
   128
	}
viric@0
   129
viric@0
   130
	
viric@0
   131
?>
viric@0
   132
viric@0
   133
</table>
viric@0
   134
<?php
viric@0
   135
	return 0;
viric@0
   136
}
viric@0
   137
viric@0
   138
function StatusButxaques($connexio)
viric@0
   139
{
viric@0
   140
?>
viric@0
   141
<table border=1>
viric@0
   142
<tr>
viric@0
   143
	<th><?php echo _("Butxaca") ?>
viric@0
   144
	<th><?php echo _("Ingressos") ?>
viric@0
   145
	<th><?php echo _("Despeses") ?>
viric@0
   146
	<th><?php echo _("Moviments negatius") ?>
viric@0
   147
	<th><?php echo _("Moviments positius") ?>
viric@0
   148
	<th><?php echo _("Total") ?>
viric@0
   149
<?php
viric@0
   150
	$butxaques = obtenir_butxaques($connexio);
viric@0
   151
viric@0
   152
	$total = 0;
viric@0
   153
	
viric@0
   154
	foreach(array_keys($butxaques) as $i)
viric@0
   155
	{
viric@0
   156
		echo "<tr>";
viric@0
   157
		echo "<td>" . $butxaques[$i]. "\n";
viric@0
   158
viric@0
   159
		// Ingressos
viric@0
   160
		$query ="SELECT SUM(quantitat) FROM ingressos WHERE
viric@0
   161
		butxaca =" . $i. " AND quantitat > 0;";
viric@0
   162
		$resultat = mysql_query($query, $connexio);
viric@0
   163
viric@0
   164
		if (!$resultat)
viric@0
   165
		{
viric@0
   166
			echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
   167
			return 1;
viric@0
   168
		}
viric@0
   169
viric@0
   170
		$fila = mysql_fetch_row($resultat);
viric@0
   171
		$ingressos = $fila[0];
viric@0
   172
		echo "<td>" . pricetohtml($fila[0]). "\n";
viric@0
   173
viric@0
   174
		// Despeses
viric@0
   175
		$query ="SELECT SUM(quantitat) FROM ingressos WHERE
viric@0
   176
		butxaca =" . $i. " AND quantitat < 0;";
viric@0
   177
		$resultat = mysql_query($query, $connexio);
viric@0
   178
viric@0
   179
		if (!$resultat)
viric@0
   180
		{
viric@0
   181
			echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
   182
			return 1;
viric@0
   183
		}
viric@0
   184
viric@0
   185
		$fila = mysql_fetch_row($resultat);
viric@0
   186
		echo "<td>" . pricetohtml($fila[0]). "\n";
viric@0
   187
		$ingressos = $ingressos + $fila[0];
viric@0
   188
viric@0
   189
		// Moviments negatius
viric@0
   190
		$query ="SELECT SUM(quantitat) FROM moviments WHERE
viric@0
   191
		butxaca_origen =" . $i. ";";
viric@0
   192
		$resultat = mysql_query($query, $connexio);
viric@0
   193
viric@0
   194
		if (!$resultat)
viric@0
   195
		{
viric@0
   196
			echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
   197
			return 1;
viric@0
   198
		}
viric@0
   199
viric@0
   200
		$fila = mysql_fetch_row($resultat);
viric@0
   201
		echo "<td>" . pricetohtml(-$fila[0]). "\n";
viric@0
   202
		$ingressos = $ingressos - $fila[0];
viric@0
   203
viric@0
   204
		// Moviments positius
viric@0
   205
		$query ="SELECT SUM(quantitat) FROM moviments WHERE
viric@0
   206
		butxaca_desti =" . $i. ";";
viric@0
   207
		$resultat = mysql_query($query, $connexio);
viric@0
   208
viric@0
   209
		if (!$resultat)
viric@0
   210
		{
viric@0
   211
			echo mysql_errno().": ".mysql_error()."<BR>";
viric@0
   212
			return 1;
viric@0
   213
		}
viric@0
   214
viric@0
   215
		$fila = mysql_fetch_row($resultat);
viric@0
   216
		echo "<td>" . pricetohtml($fila[0]). "\n";
viric@0
   217
		$ingressos = $ingressos + $fila[0];
viric@0
   218
viric@0
   219
		echo "<td>" . pricetohtml($ingressos) . "\n";
viric@0
   220
		$total = $total + $ingressos;
viric@0
   221
	}
viric@0
   222
viric@0
   223
	echo "<tr>\n";
viric@0
   224
	echo "<th>". _("Total"). "<td><td><td><td><td>" . pricetohtml($total).
viric@0
   225
		"\n";
viric@0
   226
viric@0
   227
	
viric@0
   228
?>
viric@0
   229
viric@0
   230
</table>
viric@0
   231
<?php
viric@0
   232
	return 0;
viric@0
   233
}
viric@0
   234
viric@0
   235
} // Fi de classe
viric@0
   236
?>