Ejemplo n.º 1
0
/**
 * Regresa fecha en español.
 * Ej. Lunes 18 de septiembre
 * @param string $fecha
 * @return string $fecha_formateada
 */
function get_fecha_es($fecha)
{
    $dia_semana = get_nombre_dia(date('N', strtotime($fecha)));
    $fecha_arr = explode('-', $fecha);
    $mes = get_nombre_mes($fecha_arr[1]);
    return $dia_semana . ' ' . $fecha_arr[2] . ' de ' . $mes;
}
function armar_listado($result, $tipo_periodo)
{
    $item_anterior = -1;
    // Row: [0]:id_item, [1]:categoria, [2]:username, [3]:sum(cantidad), [4]:a�o de fecha, [5]: mes de fecha, [6]:unidad
    //
    $row = mysql_fetch_array($result);
    $categoria = $row[1];
    $listado = "<table border=0 width=100%>\n  \t\t\t\t<tr bgcolor='#777777'>\n    \t\t\t<th width=50% colspan=3><font color=#000000> Item </font></th>\n    \t\t\t<th width=50% colspan=3>{$categoria}</th>\n  \t\t\t\t</tr>\n  \t\t\t\t<tr class='provlisthead'>\n    \t\t\t<th width=25%>Mes</th>\n    \t\t\t<th width=25% colspan=2>A�o</th>\n    \t\t\t<th width=25% colspan=2>Cantidad</th>\n    \t\t\t<th width=25%>Unidad</th>\n  \t\t\t\t</tr>";
    if ($tipo_periodo == "MES") {
        $nombre_mes = get_nombre_mes($row[5]);
    } else {
        $nombre_mes = "-";
    }
    $cantidad = $row[3];
    $total_item = $cantidad;
    $unidad = $row[6];
    $ano = $row[4];
    $listado .= "<tr class=\"provlistrow\" align='center'>\n\t\t\t    <td width=25%>{$nombre_mes}</td>\n    \t\t\t<td width=25% colspan=2>{$ano}</td>\n    \t\t\t<td width=25% colspan=2 class='accion_{$row['8']}'>{$cantidad}</td>\n    \t\t\t<td width=25%>{$unidad}</td>\n  \t\t\t\t</tr>";
    $item_anterior = $row[0];
    while ($row = mysql_fetch_array($result)) {
        $item = $row[0];
        if ($item != $item_anterior) {
            //Imprimo total del item
            $listado .= "<tr class='provlisthead'>\n\t\t\t\t\t\t<th width=25% ></th>\n    \t\t\t\t\t<th width=25% colspan=2>Total</th>\n    \t\t\t\t\t<th width=25% colspan=2>{$total_item}</th>\n    \t\t\t\t\t<th width=25% ></th>\n  \t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table><p>";
            $item_anterior = $item;
            $total_item = 0;
            //Imprimo cabecera nuevo item
            $categoria = $row[1];
            $listado .= "<table border=0 width=100%>\n  \t\t\t\t\t\t<tr bgcolor='#777777'>\n    \t\t\t\t\t<th width=50% colspan=3><font color=#000000> Item </font></th>\n    \t\t\t\t\t<th width=50% colspan=3>{$categoria}</th>\n  \t\t\t\t\t\t</tr>\n  \t\t\t\t\t\t<tr class='provlisthead'>\n    \t\t\t\t\t<th width=25%>Mes</th>\n    \t\t\t\t\t<th width=25% colspan=2>A�o</th>\n    \t\t\t\t\t<th width=25% colspan=2>Cantidad</th>\n    \t\t\t\t\t<th width=25%>Unidad</th>\n  \t\t\t\t\t\t</tr>";
            if ($tipo_periodo == "MES") {
                $nombre_mes = get_nombre_mes($row[5]);
            } else {
                $nombre_mes = "-";
            }
            $cantidad = $row[3];
            $total_item += $cantidad;
            //Agrego info del item del mes
            $unidad = $row[6];
            $ano = $row[4];
            $listado .= "<tr class=\"provlistrow\" align='center'>\n\t\t\t\t\t    <td width=25%>{$nombre_mes}</td>\n    \t\t\t\t\t<td width=25% colspan=2>{$ano}</td>\n    \t\t\t\t\t<td width=25% colspan=2 class='accion_{$row['8']}'>{$cantidad}</td>\n    \t\t\t\t\t<td width=25%>{$unidad}</td>\n  \t\t\t\t\t\t</tr>";
        } else {
            if ($tipo_periodo == "MES") {
                $nombre_mes = get_nombre_mes($row[5]);
            } else {
                $nombre_mes = "-";
            }
            $cantidad = $row[3];
            $total_item += $cantidad;
            $unidad = $row[6];
            $ano = $row[4];
            $listado .= "<tr class=\"provlistrow\" align='center'>\n\t\t\t\t\t    <td width=25%>{$nombre_mes}</td>\n    \t\t\t\t\t<td width=25% colspan=2>{$ano}</td>\n    \t\t\t\t\t<td width=25% colspan=2 class='accion_{$row['8']}'>{$cantidad}</td>\n    \t\t\t\t\t<td width=25%>{$unidad}</td>\n  \t\t\t\t\t\t</tr>";
        }
    }
    //Imprimo total del ultimo item
    $listado .= "<tr class='provlisthead'>\n\t\t\t\t<th width=25% ></th>\n\t\t\t\t<th width=25% colspan=2>Total</th>\n\t\t\t\t<th width=25% colspan=2>{$total_item}</th>\n\t\t\t\t<th width=25% ></th>\n\t\t\t\t</tr>\n\t\t\t\t</table><p>";
    return $listado;
}