menambahkan fitur export to excel di menu master ijin usaha
This commit is contained in:
47
app/Exports/IjinUsahaExport.php
Normal file
47
app/Exports/IjinUsahaExport.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Modules\Lpj\Models\IjinUsaha;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class IjinUsahaExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return IjinUsaha::all();
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
return [
|
||||
$row->id,
|
||||
$row->code,
|
||||
$row->name,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Code',
|
||||
'Name',
|
||||
'Created At'
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'A' => NumberFormat::FORMAT_NUMBER,
|
||||
'B' => NumberFormat::FORMAT_NUMBER,
|
||||
'E' => NumberFormat::FORMAT_DATE_DATETIME
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\IjinUsahaExport;
|
||||
use Modules\Lpj\Http\Requests\IjinUsahaRequest;
|
||||
use Modules\Lpj\Models\IjinUsaha;
|
||||
|
||||
@@ -164,4 +166,9 @@ class IjinUsahaController extends Controller
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
return Excel::download(new IjinUsahaExport, 'ijin_usaha.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Lpj\Http\Requests\KJPPRequest;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Models\IjinUsaha;
|
||||
use Modules\Lpj\Models\JenisAset;
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\KJPP;
|
||||
|
||||
class KJPPController extends Controller
|
||||
@@ -28,7 +30,7 @@ class KJPPController extends Controller
|
||||
{
|
||||
$branch = Branch::all();
|
||||
$ijin_usaha = IjinUsaha::all();
|
||||
$jenis_aset = JenisAset::all();
|
||||
$jenis_aset = JenisJaminan::all();
|
||||
|
||||
return view('lpj::kjpp.create', compact('branch', 'ijin_usaha', 'jenis_aset'));
|
||||
}
|
||||
@@ -36,9 +38,22 @@ class KJPPController extends Controller
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(KJPPRequest $request)
|
||||
{
|
||||
//
|
||||
$validate = $request->validated();
|
||||
|
||||
if ($validate) {
|
||||
try {
|
||||
KJPP::create($validate);
|
||||
return redirect()
|
||||
->route('basicdata.kjpp.index')
|
||||
->with('success', 'Ijin Usaha created successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect()
|
||||
->route('basicdata.kjpp.create')
|
||||
->with('error', 'Failed to create ijin Usaha');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,8 +101,9 @@ class KJPPController extends Controller
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor', 'LIKE', "%$search%");
|
||||
$q->orWhere('nama_kjpp', 'LIKE', "%$search%");
|
||||
$q->where('code', 'LIKE', "%$search%");
|
||||
$q->orWhere('name', 'LIKE', "%$search%");
|
||||
$q->orWhere('jenis_kantor', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
48
app/Http/Requests/KJPPRequest.php
Normal file
48
app/Http/Requests/KJPPRequest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class KJPPRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required|string|not_regex:/^\d+$/|max:255',
|
||||
'jenis_kantor' => 'required'
|
||||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$rules['code'] = 'required|max:50|unique:kjpp,code,' . $this->id;
|
||||
} else {
|
||||
$rules['code'] = 'required|max:50|unique:kjpp,code';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'code.required' => 'Kode KJPP harus diisi!',
|
||||
'code.max' => 'Kode KJPP maksimal 255 huruf!',
|
||||
'code.unique' => 'Kode KJPP tidak boleh sama!',
|
||||
'name.required' => 'Nama KJPP harus diisi!',
|
||||
'name.not_regex' => 'Nama KJPP harus berupa huruf!',
|
||||
'name.max' => 'Nama KJPP maksimal 255 huruf!',
|
||||
'jenis_kantor.required' => 'Jenis Kantor harus diisi!'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,9 @@ class Branch extends Base
|
||||
{
|
||||
return $this->hasMany(Debiture::class, 'branch_id', 'id');
|
||||
}
|
||||
|
||||
public function kjpp()
|
||||
{
|
||||
return $this->belongsTo(KJPP::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,10 @@ class IjinUsaha extends Model
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = ['code', 'name'];
|
||||
|
||||
// relasi ke kjpp
|
||||
public function kjpp()
|
||||
{
|
||||
return $this->belongsTo(KJPP::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
class JenisJaminan extends Base
|
||||
class JenisJaminan extends Base
|
||||
{
|
||||
protected $table = 'jenis_jaminan';
|
||||
protected $fillable = ['code', 'name', 'slug', 'jenis_legalitas_jaminan_id'];
|
||||
|
||||
// relasi ke kjpp
|
||||
public function kjpp()
|
||||
{
|
||||
protected $table = 'jenis_jaminan';
|
||||
protected $fillable = ['code', 'name','slug','jenis_legalitas_jaminan_id'];
|
||||
return $this->belongsTo(KJPP::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,22 @@ class KJPP extends Model
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
// relasi ke branch
|
||||
public function branch()
|
||||
{
|
||||
return $this->hasOne(Branch::class, 'jenis_kantor');
|
||||
}
|
||||
|
||||
// relasi ke jenis aset
|
||||
public function jenis_aset()
|
||||
{
|
||||
return $this->hasMany(JenisJaminan::class, 'jenis_aset_id');
|
||||
}
|
||||
|
||||
// relasi ke ijin usaha
|
||||
public function ijin_usaha()
|
||||
{
|
||||
return $this->hasMany(IjinUsaha::class, 'ijin_usaha_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user