- Menambahkan kolom baru pada tabel `branches` melalui migrasi: - `address` - `mnemonic` - `customer_company` - `customer_mnemonic` - `company_group` - `curr_no` - `co_code` - `l_vendor_atm` - `l_vendor_cpc` - Memperbarui model `Branch` agar mendukung kolom baru di properti `fillable`. - Menambahkan dukungan pencarian berdasarkan kolom `address` pada: - `BranchExport.php` (untuk ekspor data) - `BranchController.php` (untuk API pencarian data cabang) - Memperbarui tampilan daftar cabang (`branch/index.blade.php`) untuk menampilkan kolom `address`. - Memperbarui format data ekspor cabang dengan menambahkan kolom `address`. - Memperbaiki pengaturan format kolom tanggal pada data ekspor. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Basicdata\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Modules\Basicdata\Models\Branch;
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|
|
|
class BranchExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
|
|
{
|
|
protected $search;
|
|
|
|
public function __construct($search = null, $parent_id = null)
|
|
{
|
|
$this->search = $search;
|
|
$this->parent_id = $parent_id;
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
$query = Branch::query();
|
|
|
|
if (!empty($this->search)) {
|
|
$search = strtolower($this->search);
|
|
$query->where(function ($q) use ($search) {
|
|
$q->whereRaw('LOWER(code) LIKE ?', ['%' . $search . '%'])
|
|
->orWhereRaw('LOWER(name) LIKE ?', ['%' . $search . '%'])
|
|
->orWhereRaw('LOWER(address) LIKE ?', ['%' . $search . '%'])
|
|
->orWhereHas('parent', function ($q) use ($search) {
|
|
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Apply parent filter if provided
|
|
if (isset($this->parent_id) && !empty($this->parent_id)) {
|
|
$parentId = $this->parent_id;
|
|
$query->where('parent_id', $parentId);
|
|
}
|
|
|
|
return $query->get();
|
|
}
|
|
|
|
public function map($row)
|
|
: array
|
|
{
|
|
return [
|
|
$row->id,
|
|
$row->code,
|
|
$row->name,
|
|
$row->parent ? $row->parent->name : '',
|
|
$row->address,
|
|
$row->created_at
|
|
];
|
|
}
|
|
|
|
public function headings()
|
|
: array
|
|
{
|
|
return [
|
|
'ID',
|
|
'Code',
|
|
'Name',
|
|
'Parent Branch',
|
|
'Address',
|
|
'Created At'
|
|
];
|
|
}
|
|
|
|
public function columnFormats()
|
|
: array
|
|
{
|
|
return [
|
|
'A' => NumberFormat::FORMAT_NUMBER,
|
|
'E' => NumberFormat::FORMAT_DATE_DATETIME
|
|
];
|
|
}
|
|
}
|