prepare("INSERT INTO inversion_general (fecha, tipo_gasto, monto, descripcion) VALUES (?, ?, ?, ?)"); $stmt->execute([$fecha, $tipo_gasto, $monto, $descripcion]); // Redirect to the same month view after adding an expense $month = date('m', strtotime($fecha)); $year = date('Y', strtotime($fecha)); header("Location: inversion_general.php?month=$month&year=$year&status=success"); exit; } else { header("Location: inversion_general.php?status=error"); exit; } } // Handle deletion of an expense if (isset($_GET['delete_id'])) { $delete_id = $_GET['delete_id']; // Get the month and year from the query string for redirection $month = $_GET['month'] ?? date('m'); $year = $_GET['year'] ?? date('Y'); $stmt = $pdo->prepare("DELETE FROM inversion_general WHERE id = ?"); $stmt->execute([$delete_id]); header("Location: inversion_general.php?month=$month&year=$year&status=deleted"); exit; } // --- Monthly Navigation Logic --- $month = isset($_GET['month']) ? (int)$_GET['month'] : date('m'); $year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y'); $dateObj = DateTime::createFromFormat('!m', $month); $monthName = $dateObj->format('F'); // Full month name // Create a mapping for Spanish month names $meses_espanol = [ 'January' => 'Enero', 'February' => 'Febrero', 'March' => 'Marzo', 'April' => 'Abril', 'May' => 'Mayo', 'June' => 'Junio', 'July' => 'Julio', 'August' => 'Agosto', 'September' => 'Septiembre', 'October' => 'Octubre', 'November' => 'Noviembre', 'December' => 'Diciembre' ]; $monthNameSpanish = $meses_espanol[$monthName]; $prev_month = $month - 1; $prev_year = $year; if ($prev_month == 0) { $prev_month = 12; $prev_year--; } $next_month = $month + 1; $next_year = $year; if ($next_month == 13) { $next_month = 1; $next_year++; } // --- End of Navigation Logic --- // Fetch expenses for the selected month and year $stmt = $pdo->prepare("SELECT * FROM inversion_general WHERE YEAR(fecha) = ? AND MONTH(fecha) = ? ORDER BY fecha DESC"); $stmt->execute([$year, $month]); $gastos = $stmt->fetchAll(PDO::FETCH_ASSOC); // Group expenses by type $gastos_por_tipo = [ 'Publicidad' => [], 'Inversion de Mercaderia' => [], 'Gastos Personales' => [] ]; $totales_por_tipo = [ 'Publicidad' => 0, 'Inversion de Mercaderia' => 0, 'Gastos Personales' => 0 ]; foreach ($gastos as $gasto) { $tipo = $gasto['tipo_gasto']; if (array_key_exists($tipo, $gastos_por_tipo)) { $gastos_por_tipo[$tipo][] = $gasto; $totales_por_tipo[$tipo] += $gasto['monto']; } } $pageTitle = 'Inversión General'; include 'layout_header.php'; ?>

Registro de Inversión General

< Mes Anterior

Mes Siguiente >
Agregar Nuevo Gasto
'Gastos de Publicidad', 'Inversion de Mercaderia' => 'Inversión de Mercadería', 'Gastos Personales' => 'Gastos Personales' ]; ?> $titulo): ?>
Total: S/
Fecha Monto Descripción Acciones
No hay gastos registrados en esta categoría para .
S/ Editar Eliminar