Feature #1 : Jenis Fasilitas Kredit
This commit is contained in:
42
app/Exports/JenisFasilitasKreditExport.php
Normal file
42
app/Exports/JenisFasilitasKreditExport.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\Location\Models\Province;
|
||||
use Modules\Lpj\Models\JenisFasilitasKredit;
|
||||
use Modules\Usermanagement\Models\Role;
|
||||
|
||||
class JenisFasilitasKreditExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection(){
|
||||
return JenisFasilitasKredit::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' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
||||
'D' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
||||
];
|
||||
}
|
||||
}
|
||||
134
app/Http/Controllers/JenisFasilitasKreditController.php
Normal file
134
app/Http/Controllers/JenisFasilitasKreditController.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\JenisFasilitasKreditExport;
|
||||
use Modules\Lpj\Http\Requests\JenisFasilitasKreditRequest;
|
||||
use Modules\Lpj\Models\JenisFasilitasKredit;
|
||||
|
||||
class JenisFasilitasKreditController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function index(){
|
||||
return view('lpj::jenis_fasilitas_kredit.index');
|
||||
}
|
||||
|
||||
public function create(){
|
||||
return view('lpj::jenis_fasilitas_kredit.create');
|
||||
}
|
||||
|
||||
public function store(JenisFasilitasKreditRequest $request){
|
||||
$validate = $request->validated();
|
||||
|
||||
if($validate){
|
||||
try{
|
||||
// Save to database
|
||||
JenisFasilitasKredit::create($validate);
|
||||
return redirect()->route('basicdata.jenis-fasilitas-kredit.index')->with('success', 'Jenis Fasilitas Kredit created successfully');
|
||||
} catch (\Exception $e){
|
||||
return redirect()->route('basicdata.jenis-fasilitas-kredit.create')->with('error', 'Failed to create province');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
$jenisFasilitasKredit = JenisFasilitasKredit::find($id);
|
||||
return view('lpj::jenis_fasilitas_kredit.create', compact('jenisFasilitasKredit'));
|
||||
}
|
||||
|
||||
public function update(JenisFasilitasKreditRequest $request, $id){
|
||||
$validate = $request->validated();
|
||||
|
||||
if($validate){
|
||||
try{
|
||||
// Update in database
|
||||
$jenisFasilitasKredit = JenisFasilitasKredit::find($id);
|
||||
$jenisFasilitasKredit->update($validate);
|
||||
return redirect()->route('basicdata.jenis-fasilitas-kredit.index')->with('success', 'Jenis Fasilitas Kredit updated successfully');
|
||||
} catch (\Exception $e){
|
||||
return redirect()->route('basicdata.jenis-fasilitas-kredit.edit', $id)->with('error', 'Failed to update province');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id){
|
||||
try{
|
||||
// Delete from database
|
||||
$jenisFasilitasKredit = JenisFasilitasKredit::find($id);
|
||||
$jenisFasilitasKredit->delete();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Jenis Fasilitas Kredit deleted successfully']);
|
||||
} catch (\Exception $e){
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to delete province']);
|
||||
}
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request){
|
||||
if (is_null($this->user) || !$this->user->can('jenis_fasilitas_kredit.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = JenisFasilitasKredit::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'LIKE', "%$search%");
|
||||
$q->orWhere('name', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords/$request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = 0 + 1;
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
return Excel::download(new JenisFasilitasKreditExport, 'jenis_fasilitas_kredit.xlsx');
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class LpjController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('lpj::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('lpj::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('lpj::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/JenisFasilitasKreditRequest.php
Normal file
35
app/Http/Requests/JenisFasilitasKreditRequest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class JenisFasilitasKreditRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules()
|
||||
: array
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required|max:255',
|
||||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$rules['code'] = 'required|max:50|unique:jenis_fasilitas_kredit,code,' . $this->id;
|
||||
} else {
|
||||
$rules['code'] = 'required|max:50|unique:jenis_fasilitas_kredit,code';
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize()
|
||||
: bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
50
app/Models/Base.php
Normal file
50
app/Models/Base.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Base extends Model
|
||||
{
|
||||
use LogsActivity, SoftDeletes, Userstamps;
|
||||
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the class.
|
||||
*
|
||||
* @param array $attributes Optional attributes to initialize the object with.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
// Retrieve the module configuration from the module.json file
|
||||
$modulePath = dirname(__FILE__, 3) . '/module.json';
|
||||
$module = file_get_contents($modulePath);
|
||||
$module = json_decode($module);
|
||||
|
||||
// Set the connection property to the database connection specified in the module configuration
|
||||
$this->connection = $module->database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the activity log options for the User Management.
|
||||
*
|
||||
* @return LogOptions The activity log options.
|
||||
*/
|
||||
public function getActivitylogOptions()
|
||||
: LogOptions
|
||||
{
|
||||
return LogOptions::defaults()->logAll()->useLogName('LPJ : ');
|
||||
}
|
||||
}
|
||||
11
app/Models/JenisFasilitasKredit.php
Normal file
11
app/Models/JenisFasilitasKredit.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
class JenisFasilitasKredit extends Base
|
||||
{
|
||||
protected $table = 'jenis_fasilitas_kredit';
|
||||
|
||||
protected $fillable = ['code', 'name'];
|
||||
|
||||
}
|
||||
@@ -22,6 +22,10 @@ class LpjServiceProvider extends ServiceProvider
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
|
||||
if (class_exists('Breadcrumbs')) {
|
||||
require __DIR__ . '/../../routes/breadcrumbs.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user