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