Tul xxx Tul
User / IP
:
216.73.217.33
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
/
siscaps
/
controllers
/
Viewing: ActivosFijosController.php
<?php use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; class ActivosFijosController { public function index(): void { $page = max(1, (int)($_GET['page'] ?? 1)); $perPage = 15; $res = FixedAsset::getAll($page, $perPage); $items = $res['items'] ?? []; $total = (int)($res['total'] ?? count($items)); $pages = (int)ceil(max(1, $total) / $perPage); require __DIR__ . '/../views/activos/index.php'; } public function create(): void { require __DIR__ . '/../views/activos/create.php'; } public function store(): void { $name = trim($_POST['name'] ?? ''); $description = trim($_POST['description'] ?? ''); $acquisitionValue = (float)($_POST['acquisition_value'] ?? 0); $usefulLifeYears = (int)($_POST['useful_life_years'] ?? 0); $acquisitionDate = trim($_POST['acquisition_date'] ?? ''); if ($name === '' || $acquisitionValue <= 0 || $usefulLifeYears <= 0 || $acquisitionDate === '') { setFlashMessage('error', 'Por favor complete los campos obligatorios y valores válidos.'); redirect('activos.create'); return; } // Normalizar fecha (Y-m-d) $dt = DateTime::createFromFormat('Y-m-d', $acquisitionDate); if ($dt === false) { setFlashMessage('error', 'La fecha de adquisición no es válida.'); redirect('activos.create'); return; } $acquisitionDate = $dt->format('Y-m-d'); // Calcular RAF anual (depreciación anual) $annualDepreciation = $acquisitionValue / max(1, $usefulLifeYears); try { $id = FixedAsset::create([ 'name' => $name, 'description' => $description, 'acquisition_value' => $acquisitionValue, 'useful_life_years' => $usefulLifeYears, 'acquisition_date' => $acquisitionDate, 'annual_depreciation' => $annualDepreciation, ]); setFlashMessage('success', 'Activo fijo creado correctamente.'); redirect('activos.index'); } catch (Throwable $e) { setFlashMessage('error', 'No se pudo crear el activo.'); redirect('activos.create'); } } public function edit(): void { // CSRF token if (empty($_SESSION['csrf'])) { $_SESSION['csrf'] = bin2hex(random_bytes(32)); } $csrf = $_SESSION['csrf']; $id = (int)($_GET['id'] ?? 0); $asset = $id > 0 ? FixedAsset::findById($id) : null; if (!$asset) { http_response_code(404); echo 'Activo no encontrado'; return; } require __DIR__ . '/../views/activos/edit.php'; } public function update(): void { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { redirect('activos.index'); return; } $csrf = $_POST['csrf'] ?? ''; if (!hash_equals($_SESSION['csrf'] ?? '', $csrf)) { setFlashMessage('error', 'Sesión inválida.'); redirect('activos.index'); return; } $id = (int)($_POST['id'] ?? 0); $name = trim($_POST['name'] ?? ''); $description = trim($_POST['description'] ?? ''); $acquisitionValue = (float)($_POST['acquisition_value'] ?? 0); $usefulLifeYears = (int)($_POST['useful_life_years'] ?? 0); $acquisitionDate = trim($_POST['acquisition_date'] ?? ''); if ($id <= 0 || $name === '' || $acquisitionValue <= 0 || $usefulLifeYears <= 0 || $acquisitionDate === '') { setFlashMessage('error', 'Datos inválidos.'); redirect('activos.edit&id=' . $id); return; } $dt = DateTime::createFromFormat('Y-m-d', $acquisitionDate); if ($dt === false) { setFlashMessage('error', 'Fecha inválida.'); redirect('activos.edit&id=' . $id); return; } $acquisitionDate = $dt->format('Y-m-d'); $annualDepreciation = $acquisitionValue / max(1, $usefulLifeYears); $ok = FixedAsset::update($id, [ 'name' => $name, 'description' => $description, 'acquisition_value' => $acquisitionValue, 'useful_life_years' => $usefulLifeYears, 'acquisition_date' => $acquisitionDate, 'annual_depreciation' => $annualDepreciation, ]); if ($ok) { setFlashMessage('success', 'Activo actualizado.'); redirect('activos.index'); return; } setFlashMessage('error', 'No se pudo actualizar.'); redirect('activos.edit&id=' . $id); } public function delete(): void { if ($_SERVER['REQUEST_METHOD'] !== 'POST') { redirect('activos.index'); return; } $csrf = $_POST['csrf'] ?? ''; if (!hash_equals($_SESSION['csrf'] ?? '', $csrf)) { setFlashMessage('error', 'Sesión inválida.'); redirect('activos.index'); return; } $id = (int)($_POST['id'] ?? 0); if ($id > 0) { FixedAsset::delete($id); setFlashMessage('success', 'Activo eliminado.'); } redirect('activos.index'); } public function exportExcel(): void { requireAuth(['ADMIN']); $rows = FixedAsset::listAll(); $totalValue = 0.0; $totalDepreciation = 0.0; foreach ($rows as $asset) { $totalValue += (float)($asset['acquisition_value'] ?? 0); $totalDepreciation += (float)($asset['annual_depreciation'] ?? 0); } $autoload = __DIR__ . '/../vendor/autoload.php'; if (is_file($autoload)) { @require_once $autoload; } if (!class_exists(Spreadsheet::class)) { http_response_code(500); echo 'PhpSpreadsheet no está disponible.'; return; } $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Activos Fijos'); $orgName = defined('ORG_NAME') ? constant('ORG_NAME') : 'Comité de Agua Potable y Saneamiento (CAPS)'; $orgSub = defined('ORG_SUBNAME') ? constant('ORG_SUBNAME') : 'Teodoro Mendoza- Laurel Galán'; $headerColor = '173e62'; $row = 1; $sheet->mergeCells("A{$row}:F{$row}"); $sheet->setCellValue("A{$row}", $orgName); $sheet->getStyle("A{$row}")->getFont()->setBold(true)->setSize(14); $sheet->getStyle("A{$row}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $row++; $sheet->mergeCells("A{$row}:F{$row}"); $sheet->setCellValue("A{$row}", $orgSub); $sheet->getStyle("A{$row}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $sheet->getStyle("A{$row}")->getFont()->setItalic(true)->setSize(11); $row++; $sheet->mergeCells("A{$row}:F{$row}"); $sheet->setCellValue("A{$row}", 'Reporte de Activos Fijos'); $sheet->getStyle("A{$row}")->getFont()->setBold(true)->setSize(15); $sheet->getStyle("A{$row}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $row++; $sheet->mergeCells("A{$row}:F{$row}"); $sheet->setCellValue("A{$row}", 'Generado: ' . date('d/m/Y H:i')); $sheet->getStyle("A{$row}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $row++; $sheet->mergeCells("A{$row}:F{$row}"); $sheet->setCellValue("A{$row}", 'Totales: ' . format_currency($totalValue) . ' | RAF anual: ' . format_currency($totalDepreciation)); $sheet->getStyle("A{$row}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); $row += 2; $headerRow = $row; $headers = [ 'Nombre de Activo', 'Descripción', 'Valor de adquisición', 'Vida útil (años)', 'Fecha de adquisición', 'Depreciación anual (RAF)', ]; $sheet->fromArray($headers, null, "A{$headerRow}"); $sheet->getStyle("A{$headerRow}:F{$headerRow}")->applyFromArray([ 'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']], 'fill' => [ 'fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => strtoupper($headerColor)], ], 'alignment' => [ 'horizontal' => Alignment::HORIZONTAL_CENTER, 'vertical' => Alignment::VERTICAL_CENTER, ], 'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]], ]); $row = $headerRow + 1; foreach ($rows as $asset) { $sheet->fromArray([ $asset['name'] ?? '', $asset['description'] ?? '', (float)($asset['acquisition_value'] ?? 0), (int)($asset['useful_life_years'] ?? 0), format_date($asset['acquisition_date'] ?? ''), (float)($asset['annual_depreciation'] ?? 0), ], null, "A{$row}"); $row++; } $dataEndRow = $row - 1; if ($dataEndRow >= $headerRow + 1) { $sheet->getStyle("A" . ($headerRow + 1) . ":F{$dataEndRow}")->applyFromArray([ 'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_HAIR]], 'alignment' => ['vertical' => Alignment::VERTICAL_CENTER], ]); $sheet->getStyle("C" . ($headerRow + 1) . ":C{$dataEndRow}") ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); $sheet->getStyle("F" . ($headerRow + 1) . ":F{$dataEndRow}") ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); $sheet->setAutoFilter("A{$headerRow}:F{$dataEndRow}"); } $sheet->mergeCells("A{$row}:B{$row}"); $sheet->setCellValue("A{$row}", 'Total valor'); $sheet->setCellValue("C{$row}", $totalValue); $sheet->mergeCells("D{$row}:E{$row}"); $sheet->setCellValue("D{$row}", 'Total RAF anual'); $sheet->setCellValue("F{$row}", $totalDepreciation); $sheet->getStyle("A{$row}:F{$row}")->applyFromArray([ 'font' => ['bold' => true], 'borders' => ['top' => ['borderStyle' => Border::BORDER_THIN]], ]); $sheet->getStyle("C{$row}:C{$row}") ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); $sheet->getStyle("F{$row}:F{$row}") ->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1); $row++; foreach (range('A', 'F') as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } $sheet->freezePane('A' . ($headerRow + 1)); $filename = 'Activos_Fijos_' . date('Ymd_His') . '.xlsx'; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Cache-Control: max-age=0'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); exit; } public function exportPdf(): void { // Intentar cargar Dompdf $autoload = __DIR__ . '/../vendor/autoload.php'; if (is_file($autoload)) { @require_once $autoload; } $rows = FixedAsset::listAll(); $html = $this->renderAssetsPdfHtml($rows); if (class_exists('Dompdf\\Dompdf')) { $dompdf = new Dompdf\Dompdf(); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $dompdf->stream('Activos_Fijos_' . date('Ymd_His') . '.pdf', ['Attachment' => true]); return; } header('Content-Type: text/html; charset=UTF-8'); echo $html; echo '<script>window.addEventListener("load",()=>setTimeout(()=>window.print(),200));</script>'; } private function renderAssetsPdfHtml(array $rows): string { $generatedAt = date('d/m/Y H:i'); $systemData = SystemData::get(); $committeeName = trim((string)($systemData['committee_name'] ?? '')); if ($committeeName === '') { $committeeName = 'Comité de Agua Potable y Saneamiento'; } $providerReg = trim((string)($systemData['provider_registration_number'] ?? '')); $ruc = trim((string)($systemData['ruc_number'] ?? '')); $municipality = trim((string)($systemData['municipality'] ?? '')); $department = trim((string)($systemData['department'] ?? '')); $physicalAddress = trim((string)($systemData['physical_address'] ?? '')); $phone = trim((string)($systemData['phone'] ?? '')); if ($physicalAddress !== '') { $maxAddr = 110; if (mb_strlen($physicalAddress) > $maxAddr) { $physicalAddress = rtrim(mb_substr($physicalAddress, 0, $maxAddr)) . '...'; } } $locationLine = trim(implode(' - ', array_filter([$municipality, $department]))); $regRucLine = trim(implode(' | ', array_filter([ $providerReg !== '' ? ('Reg. prestador: ' . $providerReg) : '', $ruc !== '' ? ('RUC: ' . $ruc) : '', ]))); $contactLine = trim(implode(' | ', array_filter([ $physicalAddress !== '' ? ('Dir.: ' . $physicalAddress) : '', $phone !== '' ? ('Tel.: ' . $phone) : '', ]))); $logoDataUri = null; $logoRel = trim((string)($systemData['logo_path'] ?? '')); if ($logoRel !== '') { $logoAbs = dirname(__DIR__) . '/public/' . ltrim($logoRel, '/'); if (is_file($logoAbs)) { $ext = strtolower(pathinfo($logoAbs, PATHINFO_EXTENSION)); $mimeMap = [ 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'webp' => 'image/webp', 'gif' => 'image/gif', ]; $mime = $mimeMap[$ext] ?? 'application/octet-stream'; $bin = @file_get_contents($logoAbs); if ($bin !== false) { $logoDataUri = 'data:' . $mime . ';base64,' . base64_encode($bin); } } } $totalValue = 0.0; $totalRaf = 0.0; foreach ($rows as $r) { $totalValue += (float)($r['acquisition_value'] ?? 0); $totalRaf += (float)($r['annual_depreciation'] ?? 0); } ob_start(); ?> <!doctype html> <html lang="es"> <head> <meta charset="utf-8"> <title>Activos Fijos</title> <style> @page { margin: 16mm 12mm; } * { box-sizing: border-box; } body { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color:#222; margin: 12px; } h1 { font-size: 16px; margin: 0 0 6px 0; } .membrete { border-bottom: 1px solid #ddd; padding-bottom: 6px; margin-bottom: 8px; } .membrete-table { width: 100%; border-collapse: collapse; table-layout: auto; } .membrete-logo { width: 64px; vertical-align: top; padding-right: 8px; } .membrete-logo img { width: 64px; height: 64px; object-fit: contain; } .membrete-info { vertical-align: top; } .membrete-right { width: 260px; vertical-align: top; text-align: right; } .membrete-title { font-size: 12px; font-weight: bold; margin: 0; line-height: 1.2; } .membrete-line { font-size: 9px; margin: 0; line-height: 1.2; color: #333; } .membrete-meta { font-size: 9px; color: #555; word-break: break-word; } .muted { color:#666; font-size: 11px; } table { width:100%; border-collapse: collapse; } th, td { padding:6px 8px; border-bottom:1px solid #f0f0f0; text-align:left; } thead th { background:#f8f9fa; border-bottom:1px solid #ddd; } .right { text-align:right; } </style> </head> <body> <div class="membrete"> <table class="membrete-table"> <tr> <td class="membrete-logo"> <?php if (!empty($logoDataUri)): ?> <img src="<?= htmlspecialchars($logoDataUri) ?>" alt="Logo"> <?php endif; ?> </td> <td class="membrete-info"> <p class="membrete-title"><?= htmlspecialchars($committeeName) ?></p> <?php if ($regRucLine !== ''): ?> <p class="membrete-line"><?= htmlspecialchars($regRucLine) ?></p> <?php endif; ?> <?php if ($locationLine !== ''): ?> <p class="membrete-line"><?= htmlspecialchars($locationLine) ?></p> <?php endif; ?> <?php if ($contactLine !== ''): ?> <p class="membrete-line"><?= htmlspecialchars($contactLine) ?></p> <?php endif; ?> </td> <td class="membrete-right"> <p class="membrete-title">Activos fijos</p> <div class="membrete-meta"><strong>Total activos:</strong> <?= count($rows) ?></div> <div class="membrete-meta"><strong>Total valor:</strong> <?= format_currency($totalValue) ?></div> <div class="membrete-meta"><strong>Total RAF:</strong> <?= format_currency($totalRaf) ?></div> <div class="membrete-meta"><strong>Generado:</strong> <?= htmlspecialchars($generatedAt) ?></div> </td> </tr> </table> </div> <h1>Activos fijos</h1> <table> <thead> <tr> <th style="width:24%">Nombre de Activo</th> <th style="width:28%">Descripción</th> <th class="right" style="width:14%">Valor</th> <th class="right" style="width:12%">Vida útil (años)</th> <th style="width:12%">Adquisición</th> <th class="right" style="width:10%">RAF anual</th> </tr> </thead> <tbody> <?php if ($rows): foreach ($rows as $r): ?> <tr> <td><?= htmlspecialchars($r['name'] ?? '') ?></td> <td class="muted"><?= htmlspecialchars($r['description'] ?? '') ?></td> <td class="right"><?= format_currency($r['acquisition_value'] ?? 0) ?></td> <td class="right"><?= (int)($r['useful_life_years'] ?? 0) ?></td> <td><?= htmlspecialchars(format_date($r['acquisition_date'] ?? '')) ?></td> <td class="right"><strong><?= format_currency($r['annual_depreciation'] ?? 0) ?></strong></td> </tr> <?php endforeach; else: ?> <tr><td colspan="6" class="muted">Sin activos registrados.</td></tr> <?php endif; ?> </tbody> <tfoot> <tr> <th colspan="2" class="right">Totales</th> <th class="right"><?= format_currency($totalValue) ?></th> <th></th> <th></th> <th class="right"><strong><?= format_currency($totalRaf) ?></strong></th> </tr> </tfoot> </table> </body> </html> <?php return (string)ob_get_clean(); } }
Coded With 💗 by
0x6ick