llistes.inc
author viric@vicerveza
Thu, 18 May 2006 23:47:03 +0200
changeset 0 c270c8b5ddea
permissions -rw-r--r--
Initial release. Usable.

<?php

include("./strings.inc");

class llistes
{

function LlistaButxaques($connexio)
{
?>
<table border=1>
<tr>
	<th><?php echo _("ID") ?>
	<th><?php echo _("Nom") ?>
<?php

	$butxaques = obtenir_butxaques($connexio);

	foreach(array_keys($butxaques) as $i)
	{
		echo "<TR>\n";
		echo "\t<TD>" . $i . "\n";
		echo "\t<TD>" . strtohtml($butxaques[$i]) . "\n";
	}

	
?>

</table>
<?php
	return 0;
}

function LlistaMoviments($connexio, $ordre=1)
{
?>
<table border=1>
<tr>
	<th><a href="llista-moviments?ordre=1"><?php echo _("Data") ?></a>
	<th><a href="llista-moviments?ordre=2"><?php echo _("Modificat") ?></a>
	<th><?php echo _("Orígen") ?>
	<th><?php echo _("Destí") ?>
	<th><?php echo _("Diners") ?>
	<th><?php echo _("Raó") ?>
<?php
	$butxaques = obtenir_butxaques($connexio);

	if ($ordre == 1)
		$query ="SELECT UNIX_TIMESTAMP(data),
		UNIX_TIMESTAMP(data_modif), butxaca_origen,
		butxaca_desti, quantitat, rao FROM moviments
		ORDER BY data DESC;";
	else
		$query ="SELECT UNIX_TIMESTAMP(data),
		UNIX_TIMESTAMP(data_modif), butxaca_origen,
		butxaca_desti, quantitat, rao FROM moviments
		ORDER BY data_modif DESC;";
	$resultat = mysql_query($query, $connexio);

	if (!$resultat)
	{
		echo mysql_errno().": ".mysql_error()."<BR>";
		return 1;
	}

	while ($fila = mysql_fetch_row($resultat))
	{
		echo "<TR>\n";
		echo "\t<TD><a href=\"update-moviment?id=". $fila[0].
			"\">" . date("d/m/Y H:i",$fila[0]) .
			"</a>\n";
		echo "\t<TD>". date("d/m/Y H:i",$fila[1]) ."\n";
		echo "\t<TD>" . strtohtml($butxaques[$fila[2]]) . "\n";
		echo "\t<TD>" . strtohtml($butxaques[$fila[3]]) . "\n";
		echo "\t<TD>" . sprintf("%.2f", $fila[4]) . "\n";
		echo "\t<TD>" . strtohtml($fila[5]) . "\n";
	}

	
?>

</table>
<?php
	return 0;
}

function LlistaIngressos($connexio, $ordre=1)
// 1 = per data. altres, per data_modif
{
?>
<table border=1>
<tr>
	<th><a href="llista-ingressos?ordre=1"><?php echo _("Data") ?></a>
	<th><a href="llista-ingressos?ordre=2"><?php echo _("Modificat") ?></a>
	<th><?php echo _("Butxaca") ?>
	<th><?php echo _("Diners") ?>
	<th><?php echo _("Raó") ?>
<?php
	$butxaques = obtenir_butxaques($connexio);

	if ($ordre == 1)
		$query ="SELECT UNIX_TIMESTAMP(data),
			UNIX_TIMESTAMP(data_modif), butxaca,
			quantitat, rao FROM ingressos ORDER BY data DESC;";
	else
		$query ="SELECT UNIX_TIMESTAMP(data),
			UNIX_TIMESTAMP(data_modif), butxaca,
			quantitat, rao FROM ingressos ORDER BY data_modif DESC;";
	$resultat = mysql_query($query, $connexio);

	if (!$resultat)
	{
		echo mysql_errno().": ".mysql_error()."<BR>";
		return 1;
	}

	while ($fila = mysql_fetch_row($resultat))
	{
		echo "<TR>\n";
		echo "\t<TD><a href=\"update-ingres?id=". $fila[0].
			"\">" . date("d/m/Y H:i",$fila[0]) .
			"</a>\n";
		echo "\t<TD>". date("d/m/Y H:i",$fila[1]) ."\n";
		echo "\t<TD>" . strtohtml($butxaques[$fila[2]]) . "\n";
		echo "\t<TD>" . pricetohtml( $fila[3]) . "\n";
		echo "\t<TD>" . strtohtml($fila[4]) . "\n";
			"</a>\n";
	}

	
?>

</table>
<?php
	return 0;
}

function StatusButxaques($connexio)
{
?>
<table border=1>
<tr>
	<th><?php echo _("Butxaca") ?>
	<th><?php echo _("Ingressos") ?>
	<th><?php echo _("Despeses") ?>
	<th><?php echo _("Moviments negatius") ?>
	<th><?php echo _("Moviments positius") ?>
	<th><?php echo _("Total") ?>
<?php
	$butxaques = obtenir_butxaques($connexio);

	$total = 0;
	
	foreach(array_keys($butxaques) as $i)
	{
		echo "<tr>";
		echo "<td>" . $butxaques[$i]. "\n";

		// Ingressos
		$query ="SELECT SUM(quantitat) FROM ingressos WHERE
		butxaca =" . $i. " AND quantitat > 0;";
		$resultat = mysql_query($query, $connexio);

		if (!$resultat)
		{
			echo mysql_errno().": ".mysql_error()."<BR>";
			return 1;
		}

		$fila = mysql_fetch_row($resultat);
		$ingressos = $fila[0];
		echo "<td>" . pricetohtml($fila[0]). "\n";

		// Despeses
		$query ="SELECT SUM(quantitat) FROM ingressos WHERE
		butxaca =" . $i. " AND quantitat < 0;";
		$resultat = mysql_query($query, $connexio);

		if (!$resultat)
		{
			echo mysql_errno().": ".mysql_error()."<BR>";
			return 1;
		}

		$fila = mysql_fetch_row($resultat);
		echo "<td>" . pricetohtml($fila[0]). "\n";
		$ingressos = $ingressos + $fila[0];

		// Moviments negatius
		$query ="SELECT SUM(quantitat) FROM moviments WHERE
		butxaca_origen =" . $i. ";";
		$resultat = mysql_query($query, $connexio);

		if (!$resultat)
		{
			echo mysql_errno().": ".mysql_error()."<BR>";
			return 1;
		}

		$fila = mysql_fetch_row($resultat);
		echo "<td>" . pricetohtml(-$fila[0]). "\n";
		$ingressos = $ingressos - $fila[0];

		// Moviments positius
		$query ="SELECT SUM(quantitat) FROM moviments WHERE
		butxaca_desti =" . $i. ";";
		$resultat = mysql_query($query, $connexio);

		if (!$resultat)
		{
			echo mysql_errno().": ".mysql_error()."<BR>";
			return 1;
		}

		$fila = mysql_fetch_row($resultat);
		echo "<td>" . pricetohtml($fila[0]). "\n";
		$ingressos = $ingressos + $fila[0];

		echo "<td>" . pricetohtml($ingressos) . "\n";
		$total = $total + $ingressos;
	}

	echo "<tr>\n";
	echo "<th>". _("Total"). "<td><td><td><td><td>" . pricetohtml($total).
		"\n";

	
?>

</table>
<?php
	return 0;
}

} // Fi de classe
?>