tambah laporan keseluruhan peti besi
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\LaporanKeseluruhan;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
|
||||
class PetibesiAllExportExcel implements FromCollection, WithHeadings, WithMapping, WithEvents
|
||||
{
|
||||
protected $petibesiData;
|
||||
protected $total = 0;
|
||||
protected $counter = 1;
|
||||
|
||||
public function __construct($petibesiData)
|
||||
{
|
||||
$this->petibesiData = $petibesiData;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return collect($this->petibesiData);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'No.',
|
||||
'Kod Cawangan',
|
||||
'Cawangan',
|
||||
'Nilai (RM)',
|
||||
];
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
$nilai = is_numeric($row['bakieod'] ?? null) ? (float) $row['bakieod'] : 0;
|
||||
$this->total += $nilai;
|
||||
|
||||
return [
|
||||
$this->counter++,
|
||||
$row['kodcaw'] ?? '',
|
||||
$row['details_caw'] ?? '',
|
||||
number_format($nilai, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
// 1. Tajuk laporan pada baris 1
|
||||
$event->sheet->mergeCells('A1:D1');
|
||||
$event->sheet->setCellValue('A1', 'LAPORAN PETI BESI');
|
||||
$event->sheet->getStyle('A1')->getFont()->setSize(14)->setBold(true);
|
||||
$event->sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
|
||||
|
||||
// 2. Jumlah keseluruhan di bawah data
|
||||
$lastRow = count($this->petibesiData) + 3; // +3 sebab ada tajuk + heading
|
||||
|
||||
$event->sheet->setCellValue("A{$lastRow}", 'Jumlah Keseluruhan');
|
||||
$event->sheet->mergeCells("A{$lastRow}:C{$lastRow}");
|
||||
$event->sheet->setCellValue("D{$lastRow}", number_format($this->total, 2));
|
||||
$event->sheet->getStyle("A{$lastRow}:D{$lastRow}")->getFont()->setBold(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Exports\LaporanKeseluruhan\PetibesiAllExportExcel;
|
||||
|
||||
class PetibesiController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$request->hostname = config('api.url');
|
||||
// dd($request->hostname );
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
$action = $request->input('action', 'search');
|
||||
// dd($action);
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$petibesi = Http::get($request->hostname . '/api/reports/petibesi', [
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanPetibesiCawangan.xlsx", $kod_cawangan, $request->endDate);
|
||||
return Excel::download(new PetibesiAllExportExcel($petibesi), $file_title);
|
||||
}
|
||||
|
||||
$petibesi = $petibesi ?? [];
|
||||
|
||||
return view('reports.petibesi.index', compact('petibesi', 'endDate'));
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ? $date_string : $current->toDateString();
|
||||
};
|
||||
|
||||
$hostname = config('api.url');
|
||||
|
||||
$response = Http::get("$hostname/api/reports/petibesi", [
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
]);
|
||||
|
||||
$petibesi = $response->json() ?? []; // Ensure it's an array
|
||||
|
||||
// Debugging: Check the response before using it
|
||||
if (empty($petibesi)) {
|
||||
return back()->with('error', 'Failed to fetch data from API.');
|
||||
}
|
||||
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
// Ensure $kod_cawangan is defined (Modify as per your data structure)
|
||||
$kod_cawangan = $request->input('kod_cawangan', 'DEFAULT');
|
||||
|
||||
$file_title = sprintf("LaporanPetibesi(%s).xlsx", $kod_cawangan, $endDate);
|
||||
return Excel::download(new PetibesiAllExportExcel($petibesi), $file_title);
|
||||
}
|
||||
return view('reports.petibesi.index', compact('petibesi', 'endDate'));
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,12 @@
|
||||
<h2 class="mx-auto text-center font-bold text-2xl uppercase">Outstanding</h2>
|
||||
</a>
|
||||
</div>
|
||||
<div
|
||||
class="bg-white ml-2 shadow border border-solid px-6 py-4 rounded-lg hover:bg-yellow-300 hover:transition-all mb-2 cursor-pointer">
|
||||
<a href="{{ route('reports.petibesi.index', ['startDate' => now()->toDateString(), 'endDate' => now()->toDateString()]) }}" class="">
|
||||
<h2 class="mx-auto text-center font-bold text-2xl uppercase">Peti Besi Cawangan</h2>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -317,6 +317,17 @@
|
||||
</li>
|
||||
</a>
|
||||
|
||||
<a href="{{ route('reports') }}" class="rounded mb-2 mr-2 {{ Route::is('reports') || Route::is('reports.*') ? 'bg-gray-200 rounded text-white-500' : 'hover:bg-yellow-300 ' }}">
|
||||
<li class="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center ">
|
||||
<div class="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
<span class="ml-2 text-lg">Laporan Keseluruhan</span>
|
||||
</div>
|
||||
</li>
|
||||
</a>
|
||||
|
||||
{{-- <a href="{{ route('permohonan.index') }}" class="rounded mb-2 mr-2
|
||||
{{ Route::is('permohonan') || Route::is('permohonan.*') ? 'bg-gray-200 rounded text-white-500' : 'hover:bg-yellow-300 ' }}">
|
||||
<li class="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center ">
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="bg-gray-900 opacity-50 hidden fixed inset-0 z-10" id="sidebarBackdrop"></div>
|
||||
<div id="main-content" class="h-full w-full bg-gray-50 relative overflow-y-auto">
|
||||
<main>
|
||||
<div class="pt-6 px-4">
|
||||
<breadcrumb
|
||||
:items="[{ 'title': 'Laporan Keseluruhan', 'icon': 'fas fa-users', 'url': '{{ route('reports') }}' }, { 'title': 'PetiBesi', 'icon': 'fas fa-users' }]">
|
||||
</breadcrumb>
|
||||
|
||||
<div class="container">
|
||||
<div class="flex w-full">
|
||||
<div class="xl:w-2/3 2xl:w-1/2 p-8 mx-auto">
|
||||
<div class="bg-yellow-600 text-gray-200 text-lg px-6 py-4 rounded-t-lg">
|
||||
<a href="{{ route('reports') }}" class="router-link-active">
|
||||
<i class="fas fa-backspace text-white"></i>
|
||||
</a>
|
||||
<span class="text-center mx-auto text-white font-bold">Peti Besi</span>
|
||||
</div>
|
||||
<form method="get" id="formpetibesi" action="{{ route('reports.petibesi.index') }}">
|
||||
<input type="hidden" id="formAction" name="action" value="search"> <!-- Hidden field to store action -->
|
||||
<div class="rounded bg-white shadow p-6">
|
||||
<div class="pb-6">
|
||||
<label class="font-semibold text-gray-700 block pb-1">Tarikh</label>
|
||||
<div class="flex space-x-2">
|
||||
<input name="endDate" type="date"
|
||||
value="{{ request()->endDate ?? $endDate }}"
|
||||
class="border border-2 rounded px-4 py-2 w-full" placeholder="Hingga">
|
||||
|
||||
<button type="submit" onclick="setAction('search')" class="border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300 ml-5">
|
||||
<i class="fas fa-magnifying-glass mr-2"></i> Search
|
||||
</button>
|
||||
|
||||
<button type="submit" onclick="setAction('excel')" class="border border-yellow-600 text-yellow-600 py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300 ml-2">
|
||||
<i class="fas fa-file-excel mr-2"></i> Excel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div kodcaw="operasi">
|
||||
<table class="min-w-full leading-normal">
|
||||
<thead class="text-center">
|
||||
<tr>
|
||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider">No</th>
|
||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider">Kod Cawangan</th>
|
||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider">Cawangan</th>
|
||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider">Nilai (RM)</th>
|
||||
<!-- <th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-xs font-semibold text-gray-600 uppercase tracking-wider">Action</th> -->
|
||||
</tr>
|
||||
</thead>
|
||||
@php
|
||||
$totalbakieod = 0; // LAMA
|
||||
|
||||
$totalAllbakieod = 0; // SEMUA
|
||||
@endphp
|
||||
<tbody>
|
||||
@forelse ($petibesi as $outs)
|
||||
@php
|
||||
$totalbakieod += $outs['bakieod'];
|
||||
|
||||
$totalAllbakieod += $outs['bakieod'];
|
||||
@endphp
|
||||
<tr>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $loop->iteration }}</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $outs['kodcaw'] }}</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ $outs['details_caw'] }}</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">{{ number_format($outs['bakieod'],2) }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="8" class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center text-gray-500">Data not available</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
<tr class="font-semibold bg-gray-50">
|
||||
<td colspan="3" class="px-5 py-5 border-b border-gray-200 text-sm">Jumlah Keseluruhan</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 text-sm">{{ number_format($totalAllbakieod ,2)}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
@include('layouts.footer')
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
<script>
|
||||
function setAction(action) {
|
||||
document.getElementById('formAction').value = action;
|
||||
document.getElementById('formpetibesi').submit();
|
||||
}
|
||||
</script>
|
||||
@@ -8,6 +8,7 @@ use App\Http\Controllers\Reports\StokAuditController;
|
||||
use App\Http\Controllers\Reports\LelonganController;
|
||||
use App\Http\Controllers\Reports\AgingController;
|
||||
use App\Http\Controllers\Reports\OutstandingController;
|
||||
use App\Http\Controllers\Reports\PetibesiController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['roleChecker:admin,akaun,operasi,kpo, null'])->group(function () {
|
||||
@@ -29,4 +30,5 @@ Route::middleware(['roleChecker:admin,akaun,operasi,kpo, null'])->group(function
|
||||
Route::get('aging/view', [AgingController::class, 'index'])->name('reports.aging.index');
|
||||
Route::get('laporan-aging/view', [AgingController::class, 'show'])->name('reports.aging.show');
|
||||
Route::get('outstanding/view', [OutstandingController::class, 'index'])->name('reports.outstanding.index');
|
||||
Route::get('petibesi/view', [PetibesiController::class, 'index'])->name('reports.petibesi.index');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user