188 lines
5.8 KiB
PHP
188 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Pengaturan;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\AR;
|
|
|
|
class ARController extends Controller
|
|
{
|
|
protected $title = 'AR';
|
|
protected $template = 'modules.pengaturan.ar';
|
|
protected $route = 'modules.pengaturan.ar';
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
permission('is_read', $this->route, 'module',true);
|
|
|
|
$data['breadcrumbs'] = [
|
|
['name' => 'Dashboard'],
|
|
['name' => 'Pengaturan'],
|
|
['name' => 'AR','active' => true],
|
|
];
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
return view($this->template.'.index',$data);
|
|
}
|
|
|
|
public function grid(Request $request)
|
|
{
|
|
|
|
$data = AR::orderBy('nomor_baris','ASC')->get();
|
|
$_data = [];
|
|
|
|
|
|
foreach ($data as $key => $row) {
|
|
|
|
|
|
$action = '';
|
|
$status = '';
|
|
if($row->status == 0){
|
|
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
|
|
}else{
|
|
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
|
|
}
|
|
$action .= '<div class="d-flex gap-1">';
|
|
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
|
|
$action .= '<a data-id="'.encode_id($row->ArId).'" href="'.url('pengaturan/ar/update/'.encode_id($row->ArId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
|
|
if(session('group_id') == 1){
|
|
$action .= '<a href="#" data-href="'.url('pengaturan/ar/delete/'.encode_id($row->ArId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
|
|
}
|
|
}
|
|
$action .= '</div>';
|
|
|
|
$_data[] = [
|
|
'no' => $key+1,
|
|
'id' => encode_id($row->ArId),
|
|
'kode' => @$row->kode,
|
|
'nama' => @$row->nama,
|
|
'deskripsi' => @$row->deskripsi,
|
|
'nomor_baris' => @$row->nomor_baris,
|
|
'status' => @$status,
|
|
'action' => @$action,
|
|
];
|
|
|
|
}
|
|
|
|
// return response()->json($_data); // Return the data as a JSON response
|
|
return response()->json($_data);
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'kode' => 'required|string|max:255|unique:p_ar,kode',
|
|
'nama' => 'required|string|max:255',
|
|
'deskripsi' => 'required|string',
|
|
'nomor_baris' => 'required|numeric',
|
|
],[
|
|
'kode.unique' => 'Kode Tidak Boleh Sama',
|
|
'nomor_baris.numeric' => 'Nomor Baris Harus Berupa Angka',
|
|
|
|
'kode.required' => 'Tidak Boleh Kosong',
|
|
'nama.required' => 'Tidak Boleh Kosong',
|
|
'deskripsi.required' => 'Tidak Boleh Kosong',
|
|
'nomor_baris.required' => 'Tidak Boleh Kosong',
|
|
]);
|
|
|
|
try {
|
|
if(@request()->secure_id){
|
|
$keyId = decode_id(@request()->secure_id);
|
|
$data = AR::find($keyId);
|
|
$data->kode = $request->kode;
|
|
$data->nama = $request->nama;
|
|
$data->deskripsi = $request->deskripsi;
|
|
$data->nomor_baris = $request->nomor_baris;
|
|
$data->status = $request->status;
|
|
$data->save();
|
|
}else{
|
|
$data = new AR;
|
|
$data->kode = $request->kode;
|
|
$data->nama = $request->nama;
|
|
$data->deskripsi = $request->deskripsi;
|
|
$data->nomor_baris = $request->nomor_baris;
|
|
$data->status = $request->status;
|
|
$data->save();
|
|
}
|
|
|
|
|
|
return redirect()->back()->with([
|
|
'message' => 'Berhasil update data',
|
|
'type' => 'success',
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return redirect()->back()->with([
|
|
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
|
|
'type' => 'error',
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update($id = null)
|
|
{
|
|
$data['breadcrumbs'] = [
|
|
['name' => 'Dashboard'],
|
|
['name' => 'Pengaturan'],
|
|
['name' => 'AR','active' => true],
|
|
];
|
|
$keyId = decode_id($id);
|
|
$data['title'] = $this->title;
|
|
$data['route'] = $this->route;
|
|
$data['keyId'] = $id;
|
|
$data['item'] = AR::where('ArId',$keyId)->first();
|
|
return view($this->template.'.form',$data);
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$keyId = decode_id($id);
|
|
|
|
$data = AR::where('ArId',$keyId)->delete();
|
|
|
|
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
//
|
|
}
|
|
}
|