diff --git a/assets/uploads/vouchers/69e7cefae9cfd-Screenshot_246.png b/assets/uploads/vouchers/69e7cefae9cfd-Screenshot_246.png new file mode 100644 index 0000000..0a0873d Binary files /dev/null and b/assets/uploads/vouchers/69e7cefae9cfd-Screenshot_246.png differ diff --git a/completados.php b/completados.php index ac01a30..af1d0ba 100644 --- a/completados.php +++ b/completados.php @@ -136,13 +136,13 @@ include 'layout_header.php'; ID - Clave Cliente Celular Producto Monto Total Monto Debe Nro. Operación + Clave Banco Recojo Cliente (Día y Hora) Estado @@ -163,6 +163,12 @@ include 'layout_header.php'; + + + + + + " data-id="" data-field="clave"> Oculto'; ?> - - - - - - > diff --git a/db/migrations/057_create_operaciones_provincia_table.sql b/db/migrations/057_create_operaciones_provincia_table.sql new file mode 100644 index 0000000..b268da1 --- /dev/null +++ b/db/migrations/057_create_operaciones_provincia_table.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS operaciones_provincia ( + id INT AUTO_INCREMENT PRIMARY KEY, + cliente VARCHAR(255), + celular VARCHAR(50), + producto VARCHAR(255), + monto_total DECIMAL(10, 2) DEFAULT 0.00, + monto_debe DECIMAL(10, 2) DEFAULT 0.00, + nro_operacion VARCHAR(100), + banco VARCHAR(100), + fecha_completado DATE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/migrations/058_add_pedido_id_to_operaciones_provincia.sql b/db/migrations/058_add_pedido_id_to_operaciones_provincia.sql new file mode 100644 index 0000000..579a54b --- /dev/null +++ b/db/migrations/058_add_pedido_id_to_operaciones_provincia.sql @@ -0,0 +1,2 @@ +ALTER TABLE operaciones_provincia ADD COLUMN pedido_id INT NULL; +ALTER TABLE operaciones_provincia ADD CONSTRAINT fk_operaciones_pedido FOREIGN KEY (pedido_id) REFERENCES pedidos(id) ON DELETE SET NULL; diff --git a/db/migrations/059_change_fecha_completado_to_datetime.sql b/db/migrations/059_change_fecha_completado_to_datetime.sql new file mode 100644 index 0000000..ee4f966 --- /dev/null +++ b/db/migrations/059_change_fecha_completado_to_datetime.sql @@ -0,0 +1,2 @@ +-- Migration: Change fecha_completado to DATETIME in operaciones_provincia +ALTER TABLE operaciones_provincia MODIFY COLUMN fecha_completado DATETIME; diff --git a/layout_header.php b/layout_header.php index d09db59..d36a1b2 100644 --- a/layout_header.php +++ b/layout_header.php @@ -50,6 +50,12 @@ $navItems = [ 'text' => 'Pedidos Completados', 'roles' => ['Administrador', 'admin', 'Asesor', 'Control Logistico', 'Soporte Logistico', 'Verificador de Pagos'] ], + 'operaciones_provincia' => [ + 'url' => 'operaciones_provincia.php', + 'icon' => 'fa-map-location-dot', + 'text' => 'Operaciones De provincia', + 'roles' => ['Administrador', 'admin'] + ], 'listos_para_recojo' => [ 'url' => 'listos_para_recojo.php', 'icon' => 'fa-box-open', diff --git a/operaciones_provincia.php b/operaciones_provincia.php new file mode 100644 index 0000000..be5b720 --- /dev/null +++ b/operaciones_provincia.php @@ -0,0 +1,293 @@ +prepare("SELECT * FROM operaciones_provincia WHERE DATE(fecha_completado) = ? ORDER BY fecha_completado DESC"); + $stmt->execute([$selected_date]); + $operaciones = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($operaciones as $op) { + $total_recaudacion += (float)($op['monto_debe'] ?? 0); + } +} catch (PDOException $e) { + // Handle error +} +?> + + + +
+
+

Operaciones De provincia

+
+
+ + +
+ +
+
+ +
+
+
+
+
Recaudación del Día
+

S/

+

+ + +

+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDClienteCelularProductoMonto TotalMonto que debeNro. OperaciónBancoFecha CompletadoAcciones
No hay operaciones registradas para esta fecha.
format('d/m/Y H:i:s')); + } catch (Exception $e) { + echo htmlspecialchars($op['fecha_completado']); + } + } + ?> + +
+
+
+
+
+ + + + diff --git a/save_operaciones_provincia.php b/save_operaciones_provincia.php new file mode 100644 index 0000000..307f6ce --- /dev/null +++ b/save_operaciones_provincia.php @@ -0,0 +1,78 @@ + false, 'message' => 'No autorizado']); + exit; +} + +$user_role = $_SESSION['user_role'] ?? ''; +if ($user_role !== 'Administrador' && $user_role !== 'admin') { + http_response_code(403); + echo json_encode(['success' => false, 'message' => 'No autorizado']); + exit; +} + +require_once 'db/config.php'; + +$data = json_decode(file_get_contents('php://input'), true); + +if (!$data) { + http_response_code(400); + echo json_encode(['success' => false, 'message' => 'No se recibieron datos']); + exit; +} + +$action = $data['action'] ?? ''; +$pdo = db(); + +try { + if ($action === 'create') { + $stmt = $pdo->prepare("INSERT INTO operaciones_provincia (cliente) VALUES ('')"); + $stmt->execute(); + echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]); + } elseif ($action === 'update') { + $id = $data['id']; + $column = $data['column']; + $value = $data['value']; + + $allowed_columns = [ + 'cliente', 'celular', 'producto', 'monto_total', + 'monto_debe', 'nro_operacion', 'banco', 'fecha_completado' + ]; + + if (!in_array($column, $allowed_columns)) { + throw new Exception("Columna no permitida"); + } + + // Convert date format if column is fecha_completado + if ($column === 'fecha_completado' && !empty($value)) { + // Try to parse d/m/Y H:i:s + $d = DateTime::createFromFormat('d/m/Y H:i:s', $value); + if ($d && $d->format('d/m/Y H:i:s') === $value) { + $value = $d->format('Y-m-d H:i:s'); + } else { + // Try d/m/Y + $d = DateTime::createFromFormat('d/m/Y', $value); + if ($d && $d->format('d/m/Y') === $value) { + $value = $d->format('Y-m-d 00:00:00'); + } + } + } + + $stmt = $pdo->prepare("UPDATE operaciones_provincia SET $column = :value WHERE id = :id"); + $stmt->execute(['value' => $value, 'id' => $id]); + echo json_encode(['success' => true]); + } elseif ($action === 'delete') { + $id = $data['id']; + $stmt = $pdo->prepare("DELETE FROM operaciones_provincia WHERE id = :id"); + $stmt->execute(['id' => $id]); + echo json_encode(['success' => true]); + } else { + throw new Exception("Acción no válida"); + } +} catch (Exception $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/save_pedido.php b/save_pedido.php index 21ac309..ca8da48 100644 --- a/save_pedido.php +++ b/save_pedido.php @@ -178,6 +178,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $current_fecha_completado = $stmt_check->fetchColumn(); if ($current_fecha_completado === null) { $sql_parts[] = "fecha_completado = NOW()"; + + // --- NEW: Insert into operaciones_provincia --- + $stmt_p = $pdo->prepare("SELECT * FROM pedidos WHERE id = ?"); + $stmt_p->execute([$id]); + $p_data = $stmt_p->fetch(PDO::FETCH_ASSOC); + + if ($p_data) { + $stmt_op = $pdo->prepare("INSERT INTO operaciones_provincia (pedido_id, cliente, celular, producto, monto_total, monto_debe, nro_operacion, banco, fecha_completado) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW())"); + $stmt_op->execute([ + $id, + $p_data['nombre_completo'], + $p_data['celular'], + $p_data['producto'], + $p_data['monto_total'], + $p_data['monto_debe'], + $numero_operacion, + $banco + ]); + } + // --- End of NEW --- } } @@ -209,6 +229,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $sql = "INSERT INTO pedidos ($columns_sql) VALUES ($values_sql)"; $stmt = $pdo->prepare($sql); $stmt->execute($params); + $new_id = $pdo->lastInsertId(); + + // --- NEW: Insert into operaciones_provincia if completed --- + if (in_array($estado, $completed_states)) { + $stmt_op = $pdo->prepare("INSERT INTO operaciones_provincia (pedido_id, cliente, celular, producto, monto_total, monto_debe, nro_operacion, banco, fecha_completado) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW())"); + $stmt_op->execute([ + $new_id, + $nombre_completo, + $celular, + $producto, + $monto_total, + $monto_debe, + $numero_operacion, + $banco + ]); + } + // --- End of NEW --- } if (isset($_POST['id']) && !empty($_POST['id'])) {