add laporan lelong keseluruhan

This commit is contained in:
BTMS2
2025-03-02 16:38:10 +08:00
parent e4ba147017
commit 61465e3dee
9 changed files with 943 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class LelonganExport implements WithMultipleSheets
{
public $cawangan_detail;
public $query;
public $lelongan;
public $summary_lelongan;
public function __construct($data)
{
$this->cawangan_detail = $data['cawangan_detail'];
$this->query = $data['query'];
$this->lelongan = $data['lelongan'];
$this->summary_lelongan = $data['summary_lelongan'];
}
public function sheets(): array
{
$sheets = [];
// Use array_reduce to calculate the sum of values
$data = $this->lelongan;
$teller_with_lelongan_summary_data = array_reduce(array_keys($data), function ($accumulator, $key) use ($data) {
$accumulator[] = [
'teller' => $key,
'summary_lelongan_teller' => $data[$key]['summary_lelongan_teller'],
];
return $accumulator;
}, []);
$sheets[] = new LelonganSummaryExport($this->cawangan_detail, $this->query, $teller_with_lelongan_summary_data, $this->summary_lelongan);
foreach ($this->lelongan as $teller => $data) {
$teller_with_lelongan_data = [
'teller' => $teller,
'data' => $data,
];
$sheets[] = new LelonganPerTellerExport($this->cawangan_detail, $this->query, $teller_with_lelongan_data);
}
return $sheets;
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithTitle;
class LelonganPerTellerExport extends DefaultValueBinder implements FromView, ShouldAutoSize, WithCustomValueBinder, WithColumnWidths, WithEvents, WithColumnFormatting, WithTitle
{
public $cawangan_detail;
public $query;
public $teller_with_lelongan_data;
public function __construct($cawangan_detail, $query, $teller_with_lelongan_data)
{
$this->cawangan_detail = $cawangan_detail;
$this->query = $query;
$this->teller_with_lelongan_data = $teller_with_lelongan_data;
}
public function title(): string
{
return sprintf("TELLER %s", $this->teller_with_lelongan_data['teller']);
}
public function bindValue(Cell $cell, $value)
{
if (is_numeric($value)) {
$cell->setValueExplicit($value, DataType::TYPE_NUMERIC);
return true;
}
// else return default behavior
return parent::bindValue($cell, $value);
}
public function columnWidths(): array
{
return [
'A' => 20.5,
'B' => 42,
'C' => 14.18,
'D' => 14.18,
'E' => 9.19,
'F' => 27.5,
];
}
public function columnFormats(): array
{
return [
'D' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'G' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'J' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'K' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'L' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
];
}
public function registerEvents(): array
{
$table_style = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => '#000000'],
],
],
];
$main_table_row_count = count($this->teller_with_lelongan_data) + 1;
$main_table_start_at_row = 9;
$main_table_range = 'A' . $main_table_start_at_row . ':J' . ($main_table_row_count + $main_table_start_at_row);
$summary_table_row_count = 1;
$summary_table_start_at_row = $main_table_row_count + $main_table_start_at_row + 5;
$summary_table_range = 'A' . $summary_table_start_at_row . ':I' . ($summary_table_row_count + $summary_table_start_at_row);
$summary_table_column_head = 'A' . $summary_table_start_at_row . ':F' . $summary_table_start_at_row;
// return [
// AfterSheet::class => function (AfterSheet $event) use ($main_table_range, $summary_table_range, $summary_table_column_head, $table_style) {
// $event->sheet->getStyle($main_table_range)->applyFromArray($table_style);
// $event->sheet->getStyle($summary_table_range)->applyFromArray($table_style);
// $event->sheet->mergeCells($summary_table_column_head);
// },
// ];
return [];
}
public function view(): View
{
return view('exports.lelongan.cawangan', [
'cawangan_detail' => $this->cawangan_detail,
'query' => $this->query,
'teller_with_lelongan_data' => $this->teller_with_lelongan_data,
]);
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use Maatwebsite\Excel\Concerns\WithEvents;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithTitle;
class LelonganSummaryExport extends DefaultValueBinder implements FromView, ShouldAutoSize, WithCustomValueBinder, WithColumnWidths, WithEvents, WithColumnFormatting, WithTitle
{
public $cawangan_detail;
public $query;
public $teller_with_lelongan_summary_data;
public $summary_lelongan;
public function __construct($cawangan_detail, $query, $teller_with_lelongan_data, $summary_lelongan)
{
$this->cawangan_detail = $cawangan_detail;
$this->query = $query;
$this->teller_with_lelongan_summary_data = $teller_with_lelongan_data;
$this->summary_lelongan = $summary_lelongan;
}
public function title(): string
{
return 'SUMMARY LELONGAN';
}
public function bindValue(Cell $cell, $value)
{
if (is_numeric($value)) {
$cell->setValueExplicit($value, DataType::TYPE_NUMERIC);
return true;
}
// else return default behavior
return parent::bindValue($cell, $value);
}
public function columnWidths(): array
{
return [
'A' => 28,
'B' => 14.67,
'C' => 16.00,
'D' => 14.18,
];
}
public function columnFormats(): array
{
return [
'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'G' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'J' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'C' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
'D' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
];
}
public function registerEvents(): array
{
$table_style = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => '#000000'],
],
],
];
$main_table_row_count = count($this->teller_with_lelongan_summary_data) + 1;
$main_table_start_at_row = 9;
$main_table_range = 'A' . $main_table_start_at_row . ':J' . ($main_table_row_count + $main_table_start_at_row);
$summary_table_row_count = 1;
$summary_table_start_at_row = $main_table_row_count + $main_table_start_at_row + 5;
$summary_table_range = 'A' . $summary_table_start_at_row . ':I' . ($summary_table_row_count + $summary_table_start_at_row);
$summary_table_column_head = 'A' . $summary_table_start_at_row . ':F' . $summary_table_start_at_row;
// return [
// AfterSheet::class => function (AfterSheet $event) use ($main_table_range, $summary_table_range, $summary_table_column_head, $table_style) {
// $event->sheet->getStyle($main_table_range)->applyFromArray($table_style);
// $event->sheet->getStyle($summary_table_range)->applyFromArray($table_style);
// $event->sheet->mergeCells($summary_table_column_head);
// },
// ];
return [];
}
public function view(): View
{
return view('exports.lelongan.summary', [
'cawangan_detail' => $this->cawangan_detail,
'query' => $this->query,
'teller_with_lelongan_data' => $this->teller_with_lelongan_summary_data,
'summary_lelongan' => $this->summary_lelongan,
]);
}
}
@@ -0,0 +1,111 @@
<?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 App\Exports\LelonganExport;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Auth;
class LelonganController extends Controller
{
public function index(Request $request)
{
$current = new Carbon();
$getReportDate = function ($date_string) use ($current) {
if ($date_string == null) {
return $current->toDateString();
}
return $date_string;
};
$request->hostname = config('api.url');
$lelongan = Http::get($request->hostname . '/api/reports/lelongan', [
'startDate' => $getReportDate($request->startDate),
'endDate' => $getReportDate($request->endDate),
])->json();
// dd($lelongan);
$startDate = $getReportDate($request->startDate);
$endDate = $getReportDate($request->endDate);
return view('reports.laporan-lelong.index', compact('lelongan', 'startDate', 'endDate'));
}
public function show(Request $request)
{
$validated = $request->validate(
['monthYear' => 'required'],
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
]);
$current = Carbon::now();
$tarikh_cetak = $current->toDateString();
$tokens = explode('-', $validated['monthYear']);
$month = ltrim($tokens[0], '0');
$year = $tokens[1];
// Set the locale to Malaysian
App::setLocale('ms');
// Create a Carbon instance representing the date
$date = Carbon::createFromDate($year, $month, 1); // Set the day to 1st of the month
// Get the name of the month in Malaysian local
$monthName = $date->translatedFormat('F');
$request->hostname = config('api.url');
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
'month' => $month,
'year' => $year,
])->json();
$tebus_date = $monthName . ' ' . $year;
$file_title = sprintf("Laporan-StokAudit %s (%s - %s).xlsx", 'Semua cawanangan', $monthName, $year);
if ($request->generateType === 'pdf') {
return view('reports.stok-audit.show', compact('tebus_date', 'tarikh_cetak', 'stokAudit', 'month', 'year'));
} else {
return Excel::download(new StokAuditExport($stokAudit), $file_title);
}
}
public function downloadLelonganCawanganExcel(Request $request)
{
$api_url = $request->hostname;
$auth_user = Auth::user();
$current = Carbon::now();
$current = new Carbon();
$tarikh_cetak = $current->toDateString();
$getReportDate = function ($date_string) use ($current) {
if ($date_string == null) {
return $current->toDateString();
}
return $date_string;
};
$request->hostname = config('api.url');
$kod_cawangan = $request->kod_cawangan;
// dd($kod_cawangan);
$data = Http::get($request->hostname . '/api/reports/lelongan/' . $kod_cawangan, [
'startDate' => $getReportDate($request->startDate),
'endDate' => $getReportDate($request->endDate),
])->json();
// dd($data);
$file_title = sprintf("LaporanLelongan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
return Excel::download(new LelonganExport($data), $file_title);
}
}