This commit is contained in:
Ravi Gulhane 2026-12-03 15:39:42 +05:30
parent f3f2fe0b8d
commit bd4d7ce0c0
7 changed files with 904 additions and 3 deletions

View File

@ -0,0 +1,272 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Font;
class HorizonFieldWorkExport implements FromArray, WithEvents, WithTitle
{
private const IDENTITY = [
'RBM/ZBM Name',
'Emp Code',
'Role Name',
'Position Name',
'Manager 1 Code',
'Manager 1 Name',
'Manager 2 Code',
'Manager 2 Name',
];
protected $days;
protected $rows;
public function __construct(array $days, array $rows)
{
$this->days = array_values($days);
$this->rows = array_values($rows);
}
public function title(): string
{
return 'Field Work';
}
public function array(): array
{
$identityCount = count(self::IDENTITY);
$lastColumn = $identityCount + count($this->days) * 2 + 1;
$title = array_fill(0, $lastColumn, '');
$title[0] = 'Monthly Field Work Report';
$header = array_fill(0, $lastColumn, '');
foreach (self::IDENTITY as $index => $label) {
$header[$index] = $label;
}
foreach ($this->days as $index => $day) {
$header[$identityCount + $index * 2] = $this->dayLabel((string) $day);
}
$header[$lastColumn - 1] = 'RBM/ZBM wise Total';
$sub = array_fill(0, $lastColumn, '');
foreach ($this->days as $index => $day) {
$column = $identityCount + $index * 2;
$sub[$column] = 'Link';
$sub[$column + 1] = 'Time';
}
$grid = [$title, $header, $sub];
foreach ($this->rows as $row) {
$line = array_fill(0, $lastColumn, '');
$line[0] = (string) ($row['name'] ?? '');
$line[1] = $this->codeValue($row['employee_code'] ?? '');
$line[2] = (string) ($row['role_name'] ?? '');
$line[3] = (string) ($row['position_name'] ?? '');
$line[4] = $this->codeValue($row['manager_1_code'] ?? '');
$line[5] = (string) ($row['manager_1_name'] ?? '');
$line[6] = $this->codeValue($row['manager_2_code'] ?? '');
$line[7] = (string) ($row['manager_2_name'] ?? '');
$cells = is_array($row['days'] ?? null) ? $row['days'] : [];
foreach ($this->days as $index => $day) {
$column = $identityCount + $index * 2;
$cell = is_array($cells[$day] ?? null) ? $cells[$day] : ['status' => 'blank'];
$status = $cell['status'] ?? 'blank';
if ($status === 'link' && !empty($cell['link'])) {
$line[$column] = 'Link';
$line[$column + 1] = (string) ($cell['time'] ?? '');
} elseif ($status === 'no') {
$line[$column] = 'No';
}
}
$line[$lastColumn - 1] = (int) ($row['total'] ?? 0);
$grid[] = $line;
}
if (!empty($this->rows)) {
$totalLine = array_fill(0, $lastColumn, '');
$totalLine[0] = 'Total';
$sum = 0;
foreach ($this->rows as $row) {
$sum += (int) ($row['total'] ?? 0);
}
$totalLine[$lastColumn - 1] = $sum;
$grid[] = $totalLine;
}
return $grid;
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
$sheet = $event->sheet->getDelegate();
$identityCount = count(self::IDENTITY);
$dayCount = count($this->days);
$lastColumn = $identityCount + $dayCount * 2 + 1;
$lastLetter = Coordinate::stringFromColumnIndex($lastColumn);
$rowCount = count($this->rows);
$lastRow = $rowCount ? $rowCount + 4 : 3;
$sheet->getStyle('A1')->applyFromArray([
'font' => ['bold' => true],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_LEFT,
'vertical' => Alignment::VERTICAL_CENTER,
],
]);
for ($column = 1; $column <= $identityCount; $column++) {
$letter = Coordinate::stringFromColumnIndex($column);
$sheet->mergeCells($letter . '2:' . $letter . '3');
}
foreach ($this->days as $index => $day) {
$start = Coordinate::stringFromColumnIndex($identityCount + $index * 2 + 1);
$end = Coordinate::stringFromColumnIndex($identityCount + $index * 2 + 2);
$sheet->mergeCells($start . '2:' . $end . '2');
}
$sheet->mergeCells($lastLetter . '2:' . $lastLetter . '3');
$sheet->getStyle('A2:' . $lastLetter . '3')->applyFromArray([
'font' => [
'bold' => true,
'color' => ['rgb' => '000000'],
],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['rgb' => '95B3D7'],
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
'wrapText' => true,
],
]);
if ($rowCount > 0) {
$dataEnd = $rowCount + 3;
$sheet->getStyle('A4:' . $lastLetter . $dataEnd)->applyFromArray([
'font' => [
'color' => ['rgb' => '000000'],
],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['rgb' => 'FFFFFF'],
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
'wrapText' => true,
],
]);
foreach ([1, 3, 4, 6, 8] as $column) {
$letter = Coordinate::stringFromColumnIndex($column);
$sheet->getStyle($letter . '4:' . $letter . $dataEnd)
->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_LEFT);
}
foreach ([2, 5, 7] as $column) {
$letter = Coordinate::stringFromColumnIndex($column);
for ($excelRow = 4; $excelRow <= $dataEnd; $excelRow++) {
$value = $sheet->getCell($letter . $excelRow)->getValue();
if (is_int($value) || (is_string($value) && preg_match('/^-?\d+$/', $value))) {
$sheet->getStyle($letter . $excelRow)->getNumberFormat()->setFormatCode('0');
}
}
}
foreach ($this->rows as $rowIndex => $row) {
$excelRow = $rowIndex + 4;
$cells = is_array($row['days'] ?? null) ? $row['days'] : [];
foreach ($this->days as $index => $day) {
$column = $identityCount + $index * 2 + 1;
$cell = is_array($cells[$day] ?? null) ? $cells[$day] : ['status' => 'blank'];
$status = $cell['status'] ?? 'blank';
$start = Coordinate::stringFromColumnIndex($column);
$end = Coordinate::stringFromColumnIndex($column + 1);
if ($status === 'link' && !empty($cell['link'])) {
$linkCell = $sheet->getCell($start . $excelRow);
$linkCell->getHyperlink()->setUrl((string) $cell['link']);
$sheet->getStyle($start . $excelRow)->applyFromArray([
'font' => [
'color' => ['rgb' => '0563C1'],
'underline' => Font::UNDERLINE_SINGLE,
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
]);
} else {
$sheet->mergeCells($start . $excelRow . ':' . $end . $excelRow);
}
}
}
$totalRow = $rowCount + 4;
$sheet->getStyle('A' . $totalRow . ':' . $lastLetter . $totalRow)->applyFromArray([
'font' => [
'bold' => true,
'color' => ['rgb' => '000000'],
],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['rgb' => '95B3D7'],
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
]);
$sheet->getStyle('A' . $totalRow)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
$sheet->getStyle($lastLetter . $totalRow)->getNumberFormat()->setFormatCode('0');
}
$sheet->getStyle('A2:' . $lastLetter . $lastRow)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
'color' => ['rgb' => '000000'],
],
],
]);
for ($column = 1; $column <= $lastColumn; $column++) {
$letter = Coordinate::stringFromColumnIndex($column);
$sheet->getColumnDimension($letter)->setWidth($column <= $identityCount ? 22 : 14);
}
},
];
}
private function dayLabel(string $iso): string
{
$bits = explode('-', $iso);
if (count($bits) !== 3) {
return $iso;
}
return $bits[2] . '-' . $bits[1] . '-' . $bits[0];
}
private function codeValue($value)
{
$text = trim((string) $value);
if ($text !== '' && preg_match('/^-?\d+$/', $text)) {
return (int) $text;
}
return $text;
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Auth;
class HorizonReportAccess
{
public static function canView(): bool
{
$user = Auth::user();
if (!$user || ($user->domain ?? '') !== 'horizon') {
return false;
}
$designation = strtoupper(trim(self::tokenDesignation($user->access_token ?? '')));
if ($designation === 'RBM') {
return false;
}
if (self::canViewPob()) {
return true;
}
// Match web: show Custom Reports for designations above RBM/ABM/TM.
return $designation !== '' && $designation !== 'ABM' && $designation !== 'TM';
}
public static function canViewPob(): bool
{
$user = Auth::user();
if (!$user || ($user->domain ?? '') !== 'horizon') {
return false;
}
$permissions = self::permissions($user->permissions ?? []);
if (in_array('all_data_access', $permissions, true)) {
return true;
}
$designation = strtoupper(trim(self::tokenDesignation($user->access_token ?? '')));
return $designation === 'HO';
}
private static function permissions($permissions): array
{
if (is_string($permissions)) {
$decoded = json_decode($permissions, true);
$permissions = is_array($decoded) ? $decoded : [];
}
if (!is_array($permissions)) {
return [];
}
$names = [];
foreach ($permissions as $permission) {
if (is_scalar($permission) && (string) $permission !== '') {
$names[] = (string) $permission;
}
}
return $names;
}
private static function tokenDesignation(string $token): string
{
$token = trim($token);
if (stripos($token, 'Bearer ') === 0) {
$token = trim(substr($token, 7));
}
$parts = explode('.', $token);
if (count($parts) < 2) {
return '';
}
$segment = strtr($parts[1], '-_', '+/');
$pad = strlen($segment) % 4;
if ($pad > 0) {
$segment .= str_repeat('=', 4 - $pad);
}
$payload = json_decode(base64_decode($segment));
$user = is_object($payload) ? ($payload->user ?? null) : null;
if (!is_object($user)) {
return '';
}
return (string) ($user->designation ?? '');
}
}

View File

@ -124,7 +124,7 @@ class FormController extends Controller
$supplyYes = ($post['supply_status'] ?? '') === 'Yes'; $supplyYes = ($post['supply_status'] ?? '') === 'Yes';
if (!$supplyYes) { if (!$supplyYes) {
$post['submission_status'] = 'Order Taken'; $post['submission_status'] = 'Order Taken';
return $post; return $this->splitPobByContactType($post);
} }
$actualUnits = 0; $actualUnits = 0;
$actualValue = 0; $actualValue = 0;
@ -142,6 +142,14 @@ class FormController extends Controller
$post['total_actual_pob_value'] = (string) $actualValue; $post['total_actual_pob_value'] = (string) $actualValue;
$post['supply_status'] = 'Yes'; $post['supply_status'] = 'Yes';
$post['submission_status'] = $hasInvoice ? 'Invoice Uploaded' : 'Submitted'; $post['submission_status'] = $hasInvoice ? 'Invoice Uploaded' : 'Submitted';
return $this->splitPobByContactType($post);
}
protected function splitPobByContactType(array $post) {
$type = $post['contact_type'] ?? '';
$actual = $post['total_actual_pob_value'] ?? '';
$post['chemist_actual_pob_value'] = $type === 'ebt_chemist' ? $actual : '';
$post['doctor_actual_pob_value'] = $type === 'ebt_doctor' ? $actual : '';
return $post; return $post;
} }
@ -9183,7 +9191,7 @@ class FormController extends Controller
} }
$exceldata[] = $row; $exceldata[] = $row;
} }
return Excel::download(new InvoicesExport($exceldata), $formdata->title.'.xlsx'); return Excel::download(new InvoicesExport($exceldata), $this->excelExportFilename($formdata->title ?? ''));
} }
if ($form_id === InceptNebAllocation::FORM_ID) { if ($form_id === InceptNebAllocation::FORM_ID) {
@ -11488,7 +11496,7 @@ class FormController extends Controller
response()->json(['status' => 'success']); response()->json(['status' => 'success']);
} else { } else {
return Excel::download(new InvoicesExport($exceldata), $formdata->title.'.xlsx'); return Excel::download(new InvoicesExport($exceldata), $this->excelExportFilename($formdata->title ?? ''));
} }
@ -13835,6 +13843,20 @@ class FormController extends Controller
Log::debug($cmd); Log::debug($cmd);
} }
/**
* Download names cannot contain "/" or "\". Form titles such as
* "View Galvus D/DM NPI Tracker" otherwise throw while building Content-Disposition.
*/
protected function excelExportFilename($title): string
{
$name = trim(preg_replace('/[\\\\\\/:*?"<>|]+/', '-', (string) $title));
$name = trim(preg_replace('/\s+/', ' ', $name), " .-");
if ($name === '') {
$name = 'report';
}
return $name.'.xlsx';
}
/** /**
* True when the form Data Designer has at least one show_in_view field. * True when the form Data Designer has at least one show_in_view field.
* Opt-in only: empty designer or export-only fields keep the legacy list. * Opt-in only: empty designer or export-only fields keep the legacy list.

View File

@ -0,0 +1,275 @@
<?php
namespace App\Http\Controllers;
use App\Exports\HorizonFieldWorkExport;
use App\Helpers\HorizonReportAccess;
use App\Http\Requests\LambdaRequest;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
class HorizonreportController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if (!HorizonReportAccess::canView()) {
abort(403);
}
return $next($request);
});
$this->_service = 'reports';
$this->_module = 'horizon_reports';
$this->_viewname = 'horizonreport';
$this->_title = 'Monthly Field Work Report';
$this->_base_url = '/horizonreport';
}
public function list(Request $request)
{
return redirect('/horizonreport/fieldwork');
}
public function fieldwork(Request $request)
{
$month = $this->month($request);
$built = $this->build($month);
$error = $built['error'];
if (!$error && session('error')) {
$error = session('error');
}
return view('horizonreport.fieldwork', [
'title' => $this->_title,
'month' => $month,
'months' => $this->months(),
'days' => $built['days'],
'dayLabels' => $built['day_labels'],
'rows' => $built['rows'],
'total' => $built['total'],
'access' => $built['access'],
'error' => $error,
]);
}
public function export(Request $request)
{
$month = $this->month($request);
$built = $this->build($month);
if ($built['error'] || $built['access'] === false) {
$message = $built['error'] ?: 'You do not have access to this report.';
return redirect('/horizonreport/fieldwork?month=' . urlencode($month))->with('error', $message);
}
$slug = strtolower(preg_replace('/\s+/', '-', $month));
return Excel::download(
new HorizonFieldWorkExport($built['days'], $built['rows']),
'horizon-field-work-' . $slug . '.xlsx'
);
}
public function pob(Request $request)
{
$from = trim((string) $request->input('from', ''));
$to = trim((string) $request->input('to', ''));
$filePath = '';
$error = null;
$message = null;
$access = HorizonReportAccess::canViewPob();
if ($access && ($from !== '' || $to !== '')) {
if ($from === '' || $to === '') {
$error = 'Please select a from date and a to date';
} elseif ($from > $to) {
$error = 'From date must be on or before the to date';
} else {
$built = $this->buildPob($from, $to);
$error = $built['error'];
$filePath = $built['file_path'];
if ($built['access'] === false) {
$access = false;
}
}
}
return view('horizonreport.pob', [
'title' => 'POB Report',
'from' => $from,
'to' => $to,
'filePath' => $filePath,
'access' => $access,
'error' => $error,
'message' => $message,
]);
}
private function months(): array
{
$now = now()->startOfMonth();
$cursor = now()->setDate(2026, 11, 1)->startOfMonth();
if ($cursor->gt($now)) {
return [$now->format('F Y')];
}
$months = [];
while ($cursor->lte($now)) {
$months[] = $cursor->format('F Y');
$cursor->addMonth();
}
return array_reverse($months);
}
private function month(Request $request): string
{
$months = $this->months();
$selected = (string) $request->input('month', '');
if (in_array($selected, $months, true)) {
return $selected;
}
return $months[0] ?? now()->format('F Y');
}
private function build(string $month): array
{
$empty = [
'access' => true,
'days' => [],
'day_labels' => [],
'rows' => [],
'total' => 0,
'error' => null,
];
$response = LambdaRequest::signedrequest(
'get',
'reports',
'horizon_reports/field_work_report',
['month' => $month],
120
);
$response = $this->unwrap($response);
if (!is_object($response) || ($response->status ?? '') !== 'success' || !is_object($response->data ?? null)) {
$empty['error'] = is_object($response)
? ($response->message ?? 'Unable to load the field work report.')
: 'Unable to load the field work report.';
return $empty;
}
$data = json_decode(json_encode($response->data), true);
if (!is_array($data)) {
$empty['error'] = 'Unable to load the field work report.';
return $empty;
}
$days = is_array($data['days'] ?? null) ? array_values($data['days']) : [];
$rows = is_array($data['rows'] ?? null) ? array_values($data['rows']) : [];
$total = 0;
foreach ($rows as $row) {
$total += (int) (is_array($row) ? ($row['total'] ?? 0) : 0);
}
$dayLabels = [];
foreach ($days as $day) {
$dayLabels[$day] = $this->dayLabel((string) $day);
}
return [
'access' => ($data['access'] ?? true) !== false,
'days' => $days,
'day_labels' => $dayLabels,
'rows' => $rows,
'total' => $total,
'error' => null,
];
}
private function buildPob(string $from, string $to): array
{
$empty = [
'access' => true,
'file_path' => '',
'error' => null,
];
$response = LambdaRequest::signedrequest(
'get',
'reports',
'horizon_reports/pob_report',
['from' => $from, 'to' => $to],
120
);
$response = $this->unwrap($response);
if (!is_object($response) || ($response->status ?? '') !== 'success' || !is_object($response->data ?? null)) {
$empty['error'] = is_object($response)
? ($response->message ?? 'Unable to fetch the POB report')
: 'Unable to fetch the POB report';
return $empty;
}
$data = json_decode(json_encode($response->data), true);
if (!is_array($data)) {
$empty['error'] = 'Unable to fetch the POB report';
return $empty;
}
if (($data['access'] ?? true) === false) {
return [
'access' => false,
'file_path' => '',
'error' => $response->message ?? 'You do not have access to this report.',
];
}
$filePath = trim((string) ($data['file_path'] ?? ''));
if ($filePath === '') {
$empty['error'] = $response->message ?? 'No file returned for the selected dates';
return $empty;
}
return [
'access' => true,
'file_path' => $filePath,
'error' => null,
];
}
private function dayLabel(string $iso): string
{
$bits = explode('-', $iso);
if (count($bits) !== 3) {
return $iso;
}
return $bits[2] . '-' . $bits[1] . '-' . $bits[0];
}
private function unwrap($response)
{
if (!is_object($response)) {
return $response;
}
if (isset($response->body) && is_string($response->body) && !isset($response->data)) {
$decoded = json_decode($response->body);
if (is_object($decoded)) {
return $decoded;
}
}
return $response;
}
}

View File

@ -0,0 +1,152 @@
@extends('layouts.vertical', ['page_title' => $title])
@section('css')
<style>
.horizon-field-wrap {
overflow: auto;
max-height: 70vh;
}
.horizon-field-grid.table {
color: #000;
border-color: #000;
}
.horizon-field-grid.table > :not(caption) > * > * {
background-color: #fff;
color: #000;
border: 1px solid #000;
box-shadow: none;
}
.horizon-field-grid.table > thead > tr > th,
.horizon-field-grid.table > tbody > tr.horizon-field-total > td {
background-color: #95B3D7;
color: #000;
font-weight: 700;
text-align: center;
vertical-align: middle;
}
.horizon-field-grid.table > tbody > tr.horizon-field-total > td:first-child {
text-align: left;
}
.horizon-field-grid.table a {
color: #0563C1;
text-decoration: underline;
}
</style>
@endsection
@section('content')
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card mt-3">
<div class="card-body">
<h4 class="page-title mb-0">{{ $title }}</h4>
@if ($access === false)
<div class="alert alert-danger mb-0 mt-3" role="alert">You do not have access to this report.</div>
@else
@if (!empty($error))
<div class="alert alert-danger mt-3" role="alert">{{ $error }}</div>
@endif
<form method="get" action="/horizonreport/fieldwork" class="row g-2 align-items-end mt-2">
<div class="col-md-4">
<label for="horizon-field-month" class="form-label">Month</label>
<select class="form-select" name="month" id="horizon-field-month">
@foreach ($months as $option)
<option value="{{ $option }}" {{ $month === $option ? 'selected' : '' }}>{{ $option }}</option>
@endforeach
</select>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary">Show report</button>
</div>
@if (empty($error) && count($rows))
<div class="col-auto">
<a href="/horizonreport/export?month={{ urlencode($month) }}" class="btn btn-outline-primary">Download Excel</a>
</div>
@endif
</form>
@endif
</div>
</div>
</div>
</div>
@if ($access !== false && empty($error))
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="table-responsive horizon-field-wrap">
<table class="table table-bordered table-sm mb-0 text-nowrap horizon-field-grid">
<thead>
<tr>
<th rowspan="2">RBM/ZBM Name</th>
<th rowspan="2">Emp Code</th>
<th rowspan="2">Role Name</th>
<th rowspan="2">Position Name</th>
<th rowspan="2">Manager 1 Code</th>
<th rowspan="2">Manager 1 Name</th>
<th rowspan="2">Manager 2 Code</th>
<th rowspan="2">Manager 2 Name</th>
@foreach ($days as $day)
<th colspan="2">{{ $dayLabels[$day] ?? $day }}</th>
@endforeach
<th rowspan="2">RBM/ZBM wise Total</th>
</tr>
<tr>
@foreach ($days as $day)
<th>Link</th>
<th>Time</th>
@endforeach
</tr>
</thead>
<tbody>
@forelse ($rows as $row)
<tr>
<td>{{ $row['name'] ?? '' }}</td>
<td>{{ $row['employee_code'] ?? '' }}</td>
<td>{{ $row['role_name'] ?? '' }}</td>
<td>{{ $row['position_name'] ?? '' }}</td>
<td>{{ $row['manager_1_code'] ?? '' }}</td>
<td>{{ $row['manager_1_name'] ?? '' }}</td>
<td>{{ $row['manager_2_code'] ?? '' }}</td>
<td>{{ $row['manager_2_name'] ?? '' }}</td>
@foreach ($days as $day)
@php
$cell = $row['days'][$day] ?? ['status' => 'blank'];
$status = $cell['status'] ?? 'blank';
@endphp
@if ($status === 'link' && !empty($cell['link']))
<td class="text-center">
<a href="{{ $cell['link'] }}" target="_blank" rel="noreferrer">Link</a>
</td>
<td class="text-center">{{ $cell['time'] ?? '' }}</td>
@elseif ($status === 'no')
<td colspan="2" class="text-center">No</td>
@else
<td colspan="2"></td>
@endif
@endforeach
<td class="text-center">{{ $row['total'] ?? 0 }}</td>
</tr>
@empty
<tr>
<td colspan="{{ 8 + count($days) * 2 + 1 }}">No rows for this month.</td>
</tr>
@endforelse
@if (count($rows))
<tr class="fw-semibold horizon-field-total">
<td colspan="{{ 8 + count($days) * 2 }}">Total</td>
<td class="text-center">{{ $total }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endif
</div>
@endsection

View File

@ -0,0 +1,86 @@
@extends('layouts.vertical', ['page_title' => $title])
@section('content')
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card mt-3">
<div class="card-body">
<h4 class="page-title mb-0">{{ $title }}</h4>
@if ($access === false)
<div class="alert alert-danger mb-0 mt-3" role="alert">You do not have access to this report.</div>
@else
@if (!empty($error))
<div class="alert alert-danger mt-3" role="alert">{{ $error }}</div>
@endif
@if (!empty($message))
<div class="alert alert-success mt-3" role="alert">{{ $message }}</div>
@endif
<form method="get" action="/horizonreport/pob" class="row g-2 align-items-end mt-2" id="horizon-pob-form">
<div class="col-md-3">
<label for="horizon-pob-from" class="form-label">From</label>
<input
type="date"
class="form-control"
name="from"
id="horizon-pob-from"
value="{{ $from }}"
>
</div>
<div class="col-md-3">
<label for="horizon-pob-to" class="form-label">To</label>
<input
type="date"
class="form-control"
name="to"
id="horizon-pob-to"
value="{{ $to }}"
>
</div>
<div class="col-auto" id="horizon-pob-action">
@if (!empty($filePath))
<a href="{{ $filePath }}" class="btn btn-primary" download="pob-report.xlsx" target="_blank" rel="noopener">Download</a>
@else
<button type="submit" class="btn btn-primary" id="horizon-pob-fetch">Fetch</button>
@endif
</div>
</form>
@endif
</div>
</div>
</div>
</div>
</div>
@endsection
@section('script')
<script>
(function () {
var form = document.getElementById('horizon-pob-form');
if (!form) return;
var fromInput = document.getElementById('horizon-pob-from');
var toInput = document.getElementById('horizon-pob-to');
var action = document.getElementById('horizon-pob-action');
function showFetchButton() {
if (!action || action.querySelector('#horizon-pob-fetch')) return;
action.innerHTML = '<button type="submit" class="btn btn-primary" id="horizon-pob-fetch">Fetch</button>';
bindFetchButton();
}
function bindFetchButton() {
var fetchBtn = document.getElementById('horizon-pob-fetch');
if (!fetchBtn) return;
form.addEventListener('submit', function () {
fetchBtn.disabled = true;
fetchBtn.textContent = 'Fetching...';
}, { once: true });
}
if (fromInput) fromInput.addEventListener('change', showFetchButton);
if (toInput) toInput.addEventListener('change', showFetchButton);
bindFetchButton();
})();
</script>
@endsection

View File

@ -219,6 +219,11 @@
<li> <li>
<a href="/horizonreport/fieldwork">Monthly Field Work Report</a> <a href="/horizonreport/fieldwork">Monthly Field Work Report</a>
</li> </li>
@if(\App\Helpers\HorizonReportAccess::canViewPob())
<li>
<a href="/horizonreport/pob">POB Report</a>
</li>
@endif
</ul> </ul>
</div> </div>
</li> </li>