76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admins\RekeningCoa;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\RekeningCoa;
|
|
use Illuminate\Http\Request;
|
|
|
|
class RekeningCoaController extends Controller
|
|
{
|
|
public function index(){
|
|
return view('pages.admin.rekening_coa.index');
|
|
}
|
|
|
|
public function getData(){
|
|
$rekeningCoa = RekeningCoa::orderBy('coa', 'asc')->get();
|
|
$nomor = 1;
|
|
|
|
return datatables()
|
|
->of($rekeningCoa)
|
|
->addColumn('nomor', function($rekeningCoa) use (&$nomor){
|
|
return $nomor++;
|
|
})
|
|
->rawColumns(['nomor'])
|
|
->addColumn('ubah', function($rekeningCoa) {
|
|
if($rekeningCoa->status <> 0){
|
|
return '<a class="me-1" href="javascript:void(0)" onclick="ubah(\''.$rekeningCoa->id.'\', \''.$rekeningCoa->kode_coa.'\',
|
|
\''.$rekeningCoa->sub_kode_coa.'\', \''.$rekeningCoa->detail_coa.'\', \''.$rekeningCoa->keterangan_coa.'\')">
|
|
<span class="btn btn-xs btn-warning"><i class="fas fa-edit"></i></span>
|
|
</a>';
|
|
}
|
|
})
|
|
->rawColumns(['ubah'])
|
|
->make(true);
|
|
}
|
|
|
|
public function simpan(Request $request){
|
|
try {
|
|
if($request->detail_coa <> null){
|
|
$status = 1;
|
|
$coa = $request->kode_coa.".".$request->sub_kode_coa.".".$request->detail_coa;
|
|
}else{
|
|
$status = 0;
|
|
$coa = $request->kode_coa.".".$request->sub_kode_coa;
|
|
}
|
|
RekeningCoa::create([
|
|
'kode_coa' => $request->kode_coa,
|
|
'sub_kode_coa' => $request->sub_kode_coa,
|
|
'detail_coa' => $request->detail_coa,
|
|
'coa' => $coa,
|
|
'keterangan_coa' => $request->keterangan_coa,
|
|
'status' => $status
|
|
]);
|
|
|
|
return redirect()->route('coa.index')->with(['success' => 'Data berhasil ditambahkan']);
|
|
|
|
} catch (\Throwable $th) {
|
|
return back()->withError($th->getMessage())->withInput();
|
|
}
|
|
}
|
|
|
|
public function ubah(Request $request){
|
|
try {
|
|
$rekeningCoa = RekeningCoa::where('id', $request->id_rekening_coa);
|
|
$rekeningCoa->update([
|
|
'detail_coa' => $request->detail_coa,
|
|
'keterangan_coa' => $request->keterangan_coa,
|
|
]);
|
|
|
|
return redirect()->route('coa.index')->with(['success' => 'Data berhasil diubah']);
|
|
|
|
} catch (\Throwable $th) {
|
|
return back()->withError($th->getMessage())->withInput();
|
|
}
|
|
}
|
|
} |