120 lines
3.8 KiB
PHP
120 lines
3.8 KiB
PHP
<?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 GadaianPerTellerExport extends DefaultValueBinder implements FromView, ShouldAutoSize, WithCustomValueBinder, WithColumnWidths, WithEvents, WithColumnFormatting, WithTitle
|
|
{
|
|
public $cawangan_detail;
|
|
public $query;
|
|
public $teller_with_gadaian_data;
|
|
|
|
public function __construct($cawangan_detail, $query, $teller_with_gadaian_data)
|
|
{
|
|
$this->cawangan_detail = $cawangan_detail;
|
|
$this->query = $query;
|
|
$this->teller_with_gadaian_data = $teller_with_gadaian_data;
|
|
}
|
|
|
|
public function title(): string
|
|
{
|
|
return sprintf("TELLER %s", $this->teller_with_gadaian_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' => 60,
|
|
'D' => 14.18,
|
|
'E' => 9.19,
|
|
'F' => 27.5,
|
|
];
|
|
}
|
|
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'D' => NumberFormat::FORMAT_NUMBER,
|
|
'G' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'J' => NumberFormat::FORMAT_NUMBER_00,
|
|
];
|
|
}
|
|
|
|
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_gadaian_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.gadaian.cawangan', [
|
|
'cawangan_detail' => $this->cawangan_detail,
|
|
'query' => $this->query,
|
|
'teller_with_gadaian_data' => $this->teller_with_gadaian_data,
|
|
]);
|
|
}
|
|
}
|