Tul xxx Tul
User / IP
:
216.73.216.227
Host / Server
:
45.84.207.204 / aircan.me
System
:
Linux lt-bnk-web1726.main-hosting.eu 5.14.0-611.36.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 3 11:23:52 EST 2026 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
u931257429
/
domains
/
aircan.me
/
public_html
/
vendefacil2
/
controllers
/
Viewing: Ventaspedientes.php
<?php require 'vendor/autoload.php'; use Dompdf\Dompdf; class Ventaspedientes extends Controller { private $id_usuario, $id_sucursal; public function __construct() { parent::__construct(); session_start(); if (empty($_SESSION['id_usuario'])) { header('Location: ' . BASE_URL); exit; } $this->id_usuario = $_SESSION['id_usuario']; $this->id_sucursal = $_SESSION['id_sucursal']; } public function index() { if (!verificar('ver_ventas')) { header('Location: ' . BASE_URL . 'admin/permisos'); exit; } $data['title'] = 'Ventas Pendientes'; $data['script'] = 'ventas-pendientes.js'; $data['modal'] = 'ventas-pendientes.php'; $this->views->getView('ventaspedientes', 'index', $data); } public function listar() { $data = []; if (verificar('ver_ventas')) { $data = $this->model->getPendientes($this->id_sucursal); for ($i = 0; $i < count($data); $i++) { $data[$i]['moneda'] = MONEDA; $estadoTxt = 'Pendiente'; $badge = '<span class="badge bg-warning">Pendiente</span>'; if ((int)$data[$i]['estado'] === 1) { $estadoTxt = 'Aprobado'; $badge = '<span class="badge bg-success">Aprobado</span>'; } elseif ((int)$data[$i]['estado'] === 2) { $estadoTxt = 'Rechazado'; $badge = '<span class="badge bg-danger">Rechazado</span>'; } $acciones = ''; $acciones .= '<a class="btn btn-info btn-sm" href="#" onclick="verPendiente(' . $data[$i]['id'] . ')"><i class="fas fa-eye"></i></a> '; $acciones .= '<a class="btn btn-danger btn-sm" href="#" onclick="verReportePendiente(' . $data[$i]['id'] . ')"><i class="fas fa-file-pdf"></i></a> '; if (verificar('anular_ventas')) { $acciones .= '<a class="btn btn-secondary btn-sm" href="#" onclick="eliminarPendiente(' . $data[$i]['id'] . ')"><i class="fas fa-trash"></i></a> '; } if ((int)$data[$i]['estado'] === 0) { $acciones .= '<a class="btn btn-success btn-sm" href="#" onclick="aprobarPendiente(' . $data[$i]['id'] . ')"><i class="fas fa-check"></i></a> '; $acciones .= '<a class="btn btn-warning btn-sm" href="#" onclick="rechazarPendiente(' . $data[$i]['id'] . ')"><i class="fas fa-times"></i></a>'; } else { if (!empty($data[$i]['venta_id'])) { $acciones .= ' <a class="btn btn-secondary btn-sm" href="#" onclick="verReporteVenta(' . $data[$i]['venta_id'] . ')"><i class="fas fa-receipt"></i></a>'; } } $data[$i]['estado_html'] = $badge; $data[$i]['estado_txt'] = $estadoTxt; $data[$i]['acciones'] = $acciones; } } echo json_encode($data, JSON_UNESCAPED_UNICODE); die(); } public function ver($id) { if (!verificar('ver_ventas')) { echo json_encode(['msg' => 'NO TIENES PERMISOS', 'type' => 'warning']); die(); } if (!is_numeric($id)) { echo json_encode(['msg' => 'ID inválido', 'type' => 'warning']); die(); } $pendiente = $this->model->getPendienteBySucursal((int)$id, $this->id_sucursal); if (empty($pendiente)) { echo json_encode(['msg' => 'Pedido no encontrado', 'type' => 'warning']); die(); } $pendiente['moneda'] = MONEDA; $pendiente['productos_json'] = json_decode($pendiente['productos'], true); echo json_encode($pendiente, JSON_UNESCAPED_UNICODE); die(); } private function generarSerie(int $sucursalId): string { $resultSerie = $this->model->getSerieVenta($sucursalId); $numSerie = ($resultSerie['total'] == null) ? 1 : $resultSerie['total'] + 1; return generate_numbers($numSerie, 1, 8)[0]; } public function aprobar($id) { if (!verificar('crear_ventas')) { echo json_encode(['msg' => 'NO TIENES PERMISOS', 'type' => 'warning']); die(); } if (!is_numeric($id)) { echo json_encode(['msg' => 'ID inválido', 'type' => 'warning']); die(); } $pendiente = $this->model->getPendienteBySucursal((int)$id, $this->id_sucursal); if (empty($pendiente)) { echo json_encode(['msg' => 'Pedido no encontrado', 'type' => 'warning']); die(); } if ((int)$pendiente['estado'] !== 0) { echo json_encode(['msg' => 'El pedido ya fue procesado', 'type' => 'warning']); die(); } $verificarCaja = $this->model->getCaja($this->id_sucursal); if (empty($verificarCaja)) { echo json_encode(['msg' => 'LA CAJA ESTÁ CERRADA', 'type' => 'warning']); die(); } $productos = json_decode($pendiente['productos'], true); if (empty($productos) || !is_array($productos)) { echo json_encode(['msg' => 'Pedido sin productos', 'type' => 'warning']); die(); } $totalCalculado = 0; foreach ($productos as $p) { $cantidad = isset($p['cantidad']) ? (int)$p['cantidad'] : 0; $precio = isset($p['precio']) ? (float)$p['precio'] : 0; $totalCalculado += $cantidad * $precio; } if ($totalCalculado <= 0) { echo json_encode(['msg' => 'Total inválido', 'type' => 'warning']); die(); } foreach ($productos as $p) { if (empty($p['id']) || empty($p['cantidad'])) { echo json_encode(['msg' => 'Productos inválidos', 'type' => 'warning']); die(); } $productoDb = $this->model->getProducto((int)$p['id']); if (empty($productoDb)) { echo json_encode(['msg' => 'Producto no encontrado (ID: ' . $p['id'] . ')', 'type' => 'warning']); die(); } if ((int)$productoDb['servicio'] === 0) { if ((int)$productoDb['cantidad'] < (int)$p['cantidad']) { echo json_encode(['msg' => 'Stock insuficiente para: ' . $productoDb['descripcion'], 'type' => 'warning']); die(); } } } $idCliente = $this->model->getOrCreateCliente( $pendiente['cliente_identidad'], $pendiente['cliente_num_identidad'], $pendiente['cliente_nombre'], $pendiente['cliente_telefono'], $pendiente['cliente_correo'], $pendiente['cliente_direccion'], $this->id_sucursal ); $fecha = date('Y-m-d'); $hora = date('H:i:s'); $moneda = MONEDA; $serie = $this->generarSerie($this->id_sucursal); $id_caja = $verificarCaja['id']; $descuento = (float)$pendiente['descuento']; $impuesto = (int)$pendiente['impuesto']; $empresa = $this->model->getEmpresa($this->id_sucursal); $totalNeto = $totalCalculado - $descuento; if ($totalNeto < 0) { $totalNeto = 0; } if ($impuesto === 1) { $igv = $totalNeto * ($empresa['impuesto'] / 100); $totalConImpuesto = $totalNeto + $igv; } else { $totalConImpuesto = $totalNeto; } $ivaMonto = ($impuesto === 1) ? ($totalConImpuesto - $totalNeto) : 0; $retencionMonto = 0; $totalFinal = $totalConImpuesto; $metodo = 'CONTADO'; $pago = $totalConImpuesto; $nota = 'Venta generada desde Ventas Pendientes'; $ventaId = $this->model->registrarVenta( json_encode($productos), $totalNeto, $totalConImpuesto, $fecha, $hora, $metodo, $descuento, $ivaMonto, $retencionMonto, $totalFinal, $impuesto, $moneda, $serie, $pago, $id_caja, $idCliente, $this->id_usuario, $this->id_sucursal, $nota ); if ($ventaId <= 0) { echo json_encode(['msg' => 'ERROR AL GENERAR VENTA', 'type' => 'error']); die(); } foreach ($productos as $p) { $productoDb = $this->model->getProducto((int)$p['id']); if (empty($productoDb)) { continue; } if ((int)$productoDb['servicio'] === 0) { $nuevaCantidad = (int)$productoDb['cantidad'] - (int)$p['cantidad']; $totalVentas = (int)$productoDb['ventas'] + (int)$p['cantidad']; $this->model->actualizarStock($nuevaCantidad, $totalVentas, (int)$productoDb['id']); $movimiento = 'Venta N°: ' . $ventaId; $this->model->registrarMovimiento($movimiento, 'salida', (int)$p['cantidad'], $nuevaCantidad, (int)$productoDb['id'], $this->id_usuario, $this->id_sucursal); } } $fechaProcesado = date('Y-m-d H:i:s'); $this->model->aprobarPendiente((int)$id, $fechaProcesado, $this->id_usuario, $ventaId); echo json_encode(['msg' => 'VENTA APROBADA', 'type' => 'success', 'idVenta' => $ventaId], JSON_UNESCAPED_UNICODE); die(); } public function rechazar($id) { if (!verificar('ver_ventas')) { echo json_encode(['msg' => 'NO TIENES PERMISOS', 'type' => 'warning']); die(); } if (!is_numeric($id)) { echo json_encode(['msg' => 'ID inválido', 'type' => 'warning']); die(); } $pendiente = $this->model->getPendienteBySucursal((int)$id, $this->id_sucursal); if (empty($pendiente)) { echo json_encode(['msg' => 'Pedido no encontrado', 'type' => 'warning']); die(); } if ((int)$pendiente['estado'] !== 0) { echo json_encode(['msg' => 'El pedido ya fue procesado', 'type' => 'warning']); die(); } $json = file_get_contents('php://input'); $datos = json_decode($json, true); $motivo = !empty($datos['motivo']) ? $datos['motivo'] : null; $fechaProcesado = date('Y-m-d H:i:s'); $res = $this->model->rechazarPendiente((int)$id, $motivo, $fechaProcesado, $this->id_usuario); if ($res == 1) { echo json_encode(['msg' => 'VENTA RECHAZADA', 'type' => 'success'], JSON_UNESCAPED_UNICODE); } else { echo json_encode(['msg' => 'ERROR AL RECHAZAR', 'type' => 'error'], JSON_UNESCAPED_UNICODE); } die(); } public function eliminar($id) { if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') { echo json_encode(['msg' => 'Solicitud inválida', 'type' => 'warning']); die(); } if (empty($_SERVER['REQUEST_METHOD']) || strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') { echo json_encode(['msg' => 'Solicitud inválida', 'type' => 'warning']); die(); } if (!verificar('anular_ventas')) { echo json_encode(['msg' => 'NO TIENES PERMISOS', 'type' => 'warning']); die(); } if (!is_numeric($id)) { echo json_encode(['msg' => 'ID inválido', 'type' => 'warning']); die(); } $pendiente = $this->model->getPendienteBySucursal((int)$id, $this->id_sucursal); if (empty($pendiente)) { echo json_encode(['msg' => 'Pedido no encontrado', 'type' => 'warning']); die(); } $res = $this->model->eliminarPendiente((int)$id, $this->id_sucursal); if ($res == 1) { echo json_encode(['msg' => 'PEDIDO ELIMINADO', 'type' => 'success'], JSON_UNESCAPED_UNICODE); } else { echo json_encode(['msg' => 'ERROR AL ELIMINAR', 'type' => 'error'], JSON_UNESCAPED_UNICODE); } die(); } public function reporte($datos) { if (!verificar('ver_ventas')) { header('Location: ' . BASE_URL . 'admin/permisos'); exit; } ob_start(); $array = explode(',', $datos); $tipo = $array[0] ?? 'ticked'; $idPendiente = $array[1] ?? null; if (!is_numeric($idPendiente)) { echo 'Pagina no Encontrada'; exit; } $data['title'] = 'Reporte'; $data['empresa'] = $this->model->getEmpresa($this->id_sucursal); $data['pendiente'] = $this->model->getPendienteBySucursal((int)$idPendiente, $this->id_sucursal); if (!empty($data['pendiente'])) { $data['pendiente']['moneda'] = MONEDA; } if (empty($data['pendiente'])) { echo 'Pagina no Encontrada'; exit; } $logoPath = 'assets/images/logo.png'; if (file_exists($logoPath)) { $data['logo'] = 'data:image/png;base64,' . base64_encode(file_get_contents($logoPath)); } else { $data['logo'] = null; } $this->views->getView('ventaspedientes', $tipo, $data); $html = ob_get_clean(); $dompdf = new Dompdf(); $options = $dompdf->getOptions(); $options->set('isJavascriptEnabled', true); $options->set('isRemoteEnabled', true); $dompdf->setOptions($options); $dompdf->loadHtml($html); if ($tipo == 'ticked') { $dompdf->setPaper(array(0, 0, 200, 841), 'portrait'); } else { $dompdf->setPaper('A4', 'vertical'); } $dompdf->render(); $dompdf->stream('reporte.pdf', array('Attachment' => false)); } }
Coded With 💗 by
0x6ick