rekod gadai tebus hari sama
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
<?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 GadaiTebusAllExportExcel extends DefaultValueBinder implements
|
||||
FromArray,
|
||||
WithStrictNullComparison,
|
||||
WithHeadings,
|
||||
ShouldAutoSize,
|
||||
WithCustomValueBinder,
|
||||
WithColumnFormatting
|
||||
{
|
||||
public $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
['Laporan Gadai Tebus Keseluruhan'], // Title row
|
||||
['Bil',
|
||||
'Cawangan',
|
||||
'Bilangan SAG',
|
||||
'Jumlah Pembiayaan (RM)',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
if (empty($this->data)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$formattedData = [];
|
||||
$total_gadai_tebus_samahari = 0;
|
||||
$jumlah_pinjaman = 0;
|
||||
$counter = 1;
|
||||
|
||||
foreach ($this->data as $data) {
|
||||
$formattedData[] = [
|
||||
$counter++, // Numbering (Integer)
|
||||
$data['details_caw'] ?? 'N/A',
|
||||
(int) ($data['total_gadai_tebus_samahari'] ?? 0), // Integer
|
||||
(float) ($data['jumlah_pinjaman'] ?? 0), // Decimal
|
||||
];
|
||||
|
||||
// Update totals
|
||||
$total_gadai_tebus_samahari += (int) $data['total_gadai_tebus_samahari'];
|
||||
$jumlah_pinjaman += (float) $data['jumlah_pinjaman'];
|
||||
}
|
||||
|
||||
// Append total row (without numbering)
|
||||
$formattedData[] = [
|
||||
'', // No numbering for total row
|
||||
'Jumlah Keseluruhan',
|
||||
$total_gadai_tebus_samahari,
|
||||
$jumlah_pinjaman,
|
||||
];
|
||||
|
||||
return $formattedData;
|
||||
}
|
||||
|
||||
public function columnWidths(): array
|
||||
{
|
||||
return [
|
||||
'A' => 5, // Bil
|
||||
'B' => 25, // Cawangan
|
||||
'C' => 20, // Bilangan SAG
|
||||
'D' => 20, // Jumlah
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'C' => NumberFormat::FORMAT_NUMBER,
|
||||
'D' => 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']
|
||||
]);
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\LaporanKeseluruhan\GadaiTebusAllExportExcel;
|
||||
|
||||
class GadaianController extends Controller
|
||||
{
|
||||
@@ -66,4 +67,36 @@ class GadaianController extends Controller
|
||||
$file_title = sprintf("LaporanGadaian %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new GadaianExport($data), $file_title);
|
||||
}
|
||||
|
||||
public function gadaitebus(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$action = $request->input('action', 'search');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$gadaian = Http::get($request->hostname . '/api/reports/gadaitebus', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanGadaiTebus %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new GadaiTebusAllExportExcel($gadaian), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.gadaitebus.index', compact('gadaian', 'startDate', 'endDate'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user