tambah laporan keseluruhan ansuran excel
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\LaporanKeseluruhan;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
|
||||
class AnsuranAllExportExcel extends DefaultValueBinder implements
|
||||
FromArray,
|
||||
WithStrictNullComparison,
|
||||
WithHeadings,
|
||||
ShouldAutoSize,
|
||||
WithCustomValueBinder,
|
||||
WithColumnFormatting
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
['Laporan Ansuran Keseluruhan'], // Title row
|
||||
['Bil',
|
||||
'Cawangan',
|
||||
'Bilangan Ansuran',
|
||||
'Nilai Marhun',
|
||||
'Bayaran Pembiayaan (RM)',
|
||||
'Bayaran Kos Keuntungan (RM)',
|
||||
'Jumlah (RM)',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
if (empty($this->data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$formattedData = [];
|
||||
$bilangan_ansuran = 0;
|
||||
$total_nilai_marhun = 0;
|
||||
$bayaran_pembiayaan = 0;
|
||||
$bayaran_kos_keuntungan = 0;
|
||||
$jumlah_bayaran = 0;
|
||||
$counter = 1;
|
||||
|
||||
foreach ($this->data as $data) {
|
||||
$formattedData[] = [
|
||||
$counter++, // Numbering (Integer)
|
||||
$data['cawangan_detail'] ?? 'N/A', // Text
|
||||
(int) ($data['bilangan_ansuran'] ?? 0), // Integer
|
||||
(float) ($data['total_nilai_marhun'] ?? 0), // Decimal
|
||||
(float) ($data['bayaran_pembiayaan'] ?? 0), // Decimal
|
||||
(float) ($data['bayaran_kos_keuntungan'] ?? 0), // Decimal
|
||||
(float) ($data['jumlah_bayaran'] ?? 0), // Decimal
|
||||
];
|
||||
|
||||
// Update totals
|
||||
$bilangan_ansuran += (int) $data['bilangan_ansuran'];
|
||||
$total_nilai_marhun += (float) $data['total_nilai_marhun'];
|
||||
$bayaran_pembiayaan += (float) $data['bayaran_pembiayaan'];
|
||||
$bayaran_kos_keuntungan += (float) $data['bayaran_kos_keuntungan'];
|
||||
$jumlah_bayaran += (float) $data['jumlah_bayaran'];
|
||||
}
|
||||
|
||||
// Append total row (without numbering)
|
||||
$formattedData[] = [
|
||||
'', // No numbering for total row
|
||||
'Jumlah Keseluruhan',
|
||||
$bilangan_ansuran,
|
||||
$total_nilai_marhun,
|
||||
$bayaran_pembiayaan,
|
||||
$bayaran_kos_keuntungan,
|
||||
$jumlah_bayaran,
|
||||
];
|
||||
|
||||
return $formattedData;
|
||||
}
|
||||
|
||||
public function columnWidths(): array
|
||||
{
|
||||
return [
|
||||
'A' => 5, // Bil
|
||||
'B' => 25, // Cawangan
|
||||
'C' => 20, // Bilangan Ansuran
|
||||
'D' => 18, // Nilai Marhun
|
||||
'E' => 20, // Bayaran Pembiayaan
|
||||
'F' => 20, // Bayaran Kos Keuntungan
|
||||
'G' => 20, // Jumlah
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'C' => NumberFormat::FORMAT_NUMBER,
|
||||
'D' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'G' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
];
|
||||
}
|
||||
|
||||
public function bindValue(Cell $cell, $value)
|
||||
{
|
||||
if (is_numeric($value) && !is_string($value)) {
|
||||
$cell->setValueExplicit((float) $value, DataType::TYPE_NUMERIC);
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::bindValue($cell, $value);
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$sheet = $event->sheet;
|
||||
|
||||
// Merge the title row across all columns (A1 to G1)
|
||||
$sheet->mergeCells('A1:G1');
|
||||
|
||||
// Style the title (bold, center)
|
||||
$sheet->getStyle('A1')->applyFromArray([
|
||||
'font' => ['bold' => true, 'size' => 14],
|
||||
'alignment' => ['horizontal' => 'center', 'vertical' => 'center']
|
||||
]);
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,16 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\LaporanKeseluruhan\AnsuranAllExportExcel;
|
||||
|
||||
class AnsuranController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$request->hostname = config('api.url');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
@@ -37,6 +41,55 @@ class AnsuranController extends Controller
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanAnsuran %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new AnsuranAllExportExcel($data), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.ansuran.index', compact('summary_ansuran_by_cawangan', 'summary_ansuran', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$hostname = config('api.url');
|
||||
|
||||
$response = Http::get($hostname . '/api/reports/ansuran', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
]);
|
||||
|
||||
$ansuran = $response->json() ?? [];
|
||||
if (empty($ansuran)) {
|
||||
return back()->with('error', 'Failed to fetch data from API.');
|
||||
}
|
||||
|
||||
$summary_ansuran_by_cawangan = $response['summary_ansuran_by_cawangan'];
|
||||
$summary_ansuran = $response['summary_ansuran'];
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
// dd($ansuran);
|
||||
|
||||
if ($action === 'excel') {
|
||||
|
||||
$exportData = $ansuran['summary_ansuran_by_cawangan'];
|
||||
// Ensure $kod_cawangan is defined (Modify as per your data structure)
|
||||
$kod_cawangan = $request->input('kod_cawangan', 'DEFAULT');
|
||||
|
||||
$file_title = sprintf("LaporanAnsuran %s (%s - %s).xlsx", $kod_cawangan, $startDate, $endDate);
|
||||
return Excel::download(new AnsuranAllExportExcel($exportData), $file_title);
|
||||
}
|
||||
return view('reports.ansuran.index', compact('summary_ansuran_by_cawangan', 'summary_ansuran', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
|
||||
<div class="container">
|
||||
<div class="flex w-full">
|
||||
<div class="xl:w-2/3 2xl:w-1/2 p-8 mx-auto">
|
||||
<div class="xl:w-3/5 2xl:w-2/3 p-12 mx-auto">
|
||||
<div class="bg-yellow-600 text-gray-200 text-lg px-6 py-4 rounded-t-lg"><a href="/reports"
|
||||
class="router-link-active"><i class="fas fa-backspace text-white"></i></a> <span
|
||||
class="text-center mx-auto text-white font-bold">Laporan Ansuran Pembiayaan</span></div>
|
||||
<form method="get" id="formansuran" action="{{ route('reports.ansuran.index') }}">
|
||||
<form method="GET" id="formansuran" action="{{ route('reports.ansuran.show') }}">
|
||||
<div class="rounded bg-white shadow p-6">
|
||||
<div class="pb-6"><label for="username"
|
||||
class="font-semibold text-gray-700 block pb-1">Tarikh</label>
|
||||
@@ -34,9 +34,15 @@
|
||||
<input id="tarikhhingga" name="endDate" type="date"
|
||||
value="{{ request()->endDate ?? $endDate }}"
|
||||
class="border border-2 border-l-0 rounded-r px-4 py-2 w-80r mr-2">
|
||||
<button
|
||||
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
|
||||
<!-- Hidden Input to Determine Action -->
|
||||
<input type="hidden" name="action" id="formAction" value="search">
|
||||
|
||||
<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>
|
||||
|
||||
@@ -72,6 +78,10 @@
|
||||
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Bil Ansuran
|
||||
</th>
|
||||
<th
|
||||
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Nilai Marhun
|
||||
</th>
|
||||
<th
|
||||
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Bayaran Pembiayaan
|
||||
@@ -127,6 +137,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
||||
<div class="flex items-center">
|
||||
<div class="ml-3">
|
||||
<p class="text-gray-900 whitespace-no-wrap">
|
||||
{{ number_format($ansuran['total_nilai_marhun'], 2) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
||||
<div class="flex items-center">
|
||||
<div class="ml-3">
|
||||
@@ -189,6 +208,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
||||
<div class="flex items-center">
|
||||
<div class="ml-3">
|
||||
<p class="text-gray-900 whitespace-no-wrap">
|
||||
{{ number_format($summary_ansuran['total_nilai_marhun'], 2) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
||||
<div class="flex items-center">
|
||||
<div class="ml-3">
|
||||
@@ -229,3 +257,11 @@
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
<!-- JavaScript to Change Action -->
|
||||
<script>
|
||||
function setAction(action) {
|
||||
document.getElementById('formAction').value = action;
|
||||
document.getElementById('formansuran').submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -23,4 +23,5 @@ Route::middleware(['roleChecker:admin,akaun,operasi,kpo, null'])->group(function
|
||||
Route::get('laporan-lelong', [LelonganController::class, 'index'])->name('reports.lelongan.index');
|
||||
Route::get('lelongan/{kod_cawangan}', [LelonganController::class, 'downloadLelonganCawanganExcel'])->name('reports.lelongan.cawangan.excel');
|
||||
Route::get('laporan-lelong/view', [LelonganController::class, 'show'])->name('reports.lelongan.show');
|
||||
Route::get('laporan-ansuran/view', [AnsuranController::class, 'show'])->name('reports.ansuran.show');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user