diff --git a/app/Exports/IjinUsahaExport.php b/app/Exports/IjinUsahaExport.php new file mode 100644 index 0000000..a7d02e4 --- /dev/null +++ b/app/Exports/IjinUsahaExport.php @@ -0,0 +1,47 @@ +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 + ]; + } +} diff --git a/app/Http/Controllers/IjinUsahaController.php b/app/Http/Controllers/IjinUsahaController.php index ea0cd95..360d223 100644 --- a/app/Http/Controllers/IjinUsahaController.php +++ b/app/Http/Controllers/IjinUsahaController.php @@ -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'); + } } diff --git a/app/Http/Controllers/KJPPController.php b/app/Http/Controllers/KJPPController.php index 801d6a8..d06a80e 100644 --- a/app/Http/Controllers/KJPPController.php +++ b/app/Http/Controllers/KJPPController.php @@ -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%"); }); } diff --git a/app/Http/Requests/KJPPRequest.php b/app/Http/Requests/KJPPRequest.php new file mode 100644 index 0000000..faa4b9c --- /dev/null +++ b/app/Http/Requests/KJPPRequest.php @@ -0,0 +1,48 @@ + '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!' + ]; + } +} diff --git a/app/Models/Branch.php b/app/Models/Branch.php index 834b5cc..4ca5bd9 100644 --- a/app/Models/Branch.php +++ b/app/Models/Branch.php @@ -13,4 +13,9 @@ class Branch extends Base { return $this->hasMany(Debiture::class, 'branch_id', 'id'); } + + public function kjpp() + { + return $this->belongsTo(KJPP::class); + } } diff --git a/app/Models/IjinUsaha.php b/app/Models/IjinUsaha.php index e2e464a..522a183 100644 --- a/app/Models/IjinUsaha.php +++ b/app/Models/IjinUsaha.php @@ -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); + } } diff --git a/app/Models/JenisJaminan.php b/app/Models/JenisJaminan.php index 43ab899..a630686 100644 --- a/app/Models/JenisJaminan.php +++ b/app/Models/JenisJaminan.php @@ -1,9 +1,15 @@ belongsTo(KJPP::class); } +} diff --git a/app/Models/KJPP.php b/app/Models/KJPP.php index 8d35c78..05cad4a 100644 --- a/app/Models/KJPP.php +++ b/app/Models/KJPP.php @@ -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'); + } } diff --git a/resources/views/Ijin_usaha/index.blade.php b/resources/views/Ijin_usaha/index.blade.php index 8364f63..2d225d5 100644 --- a/resources/views/Ijin_usaha/index.blade.php +++ b/resources/views/Ijin_usaha/index.blade.php @@ -20,6 +20,8 @@
+ Export to Excel + Tambah Ijin Usaha diff --git a/resources/views/kjpp/create.blade.php b/resources/views/kjpp/create.blade.php index 3082354..a7320c8 100644 --- a/resources/views/kjpp/create.blade.php +++ b/resources/views/kjpp/create.blade.php @@ -31,9 +31,9 @@ Nomor KJPP
- - @error('nomor') + + @error('code') {{ $message }} @enderror
@@ -43,37 +43,28 @@ Nama KJPP
- - @error('nama_kjpp') + + @error('name') {{ $message }} @enderror
- +
- + @if (isset($branch)) @foreach ($branch as $branches) - + @endforeach @endif -
-
-
- -
- - @error('nomor_ijin_usaha') + @error('jenis_kantor') {{ $message }} @enderror
diff --git a/resources/views/kjpp/index.blade.php b/resources/views/kjpp/index.blade.php index 421ece7..cd131b7 100644 --- a/resources/views/kjpp/index.blade.php +++ b/resources/views/kjpp/index.blade.php @@ -36,16 +36,16 @@ - - Nomor + + Nomor KJPP - + Nama KJPP - - Kota + + Jenis Kantor / Cabang Action @@ -124,16 +124,16 @@ }, }, nomor: { - title: 'Nomor', + title: 'Nomor KJPP', }, nama_kjpp: { title: 'Nama KJPP', }, - kota: { - title: 'Kota', + jenis_kantor: { + title: 'Jenis Kantor / Cabang', }, actions: { - title: 'Status', + title: 'Action', render: (item, data) => { return `