-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding coa, improving load time by adding lazy loading and updating l…
…aravel mix
- Loading branch information
Tony
committed
Nov 14, 2020
1 parent
43541ef
commit 43adaa5
Showing
198 changed files
with
493,309 additions
and
446,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace App; | ||
|
||
use illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
use App\Support\Dataviewer; | ||
use Spatie\Activitylog\Traits\LogsActivity; | ||
|
||
class Coa extends Model { | ||
|
||
use Dataviewer, LogsActivity, SoftDeletes; | ||
|
||
protected $table = 'coa'; | ||
protected $dates = ['deleted_at']; | ||
protected static $logFillable = true; | ||
protected static $logOnlyDirty = true; | ||
|
||
public static $rules = [ | ||
'kode' => 'sometimes|required|unique:coa', | ||
'name' => 'required', | ||
'id_induk' => 'required' | ||
]; | ||
|
||
protected $fillable = ['id_induk','kode','name','tipe','level','keterangan']; | ||
|
||
protected $allowedFilters = [ | ||
'id','id_induk','kode','name','tipe','level','keterangan' | ||
]; | ||
|
||
protected $orderable = [ | ||
'id','id_induk','kode','name','tipe','level','keterangan' | ||
]; | ||
|
||
public static function initialize(){ | ||
return [ | ||
'id_induk' => '','kode' => '', 'name' => '', 'tipe' => '','tipe' => '','level' => '','keterangan' => '', | ||
]; | ||
} | ||
|
||
public function induk() | ||
{ | ||
return $this->belongsTo('App\Coa','id_induk','id'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace App; | ||
|
||
use illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
use App\Support\Dataviewer; | ||
use Spatie\Activitylog\Traits\LogsActivity; | ||
|
||
class CoaSaldo extends Model { | ||
|
||
use Dataviewer, LogsActivity, SoftDeletes; | ||
|
||
protected $table = 'coa_saldo'; | ||
protected $dates = ['deleted_at']; | ||
protected static $logFillable = true; | ||
protected static $logOnlyDirty = true; | ||
|
||
public static $rules = [ | ||
'id_coa' => 'required', | ||
'id_cu' => 'required', | ||
'periode' => 'required' | ||
]; | ||
|
||
protected $fillable = ['id_coa','id_cu','id_tp','saldo','periode']; | ||
|
||
protected $allowedFilters = [ | ||
'id','id_coa','id_cu','id_tp','saldo','periode' | ||
]; | ||
|
||
protected $orderable = [ | ||
'id','id_coa','id_cu','id_tp','saldo','periode' | ||
]; | ||
|
||
public static function initialize(){ | ||
return [ | ||
'id_coa' => '','id_cu' => '', 'id_tp' => '', 'saldo' => '', 'periode' => '' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
namespace App\Http\Controllers; | ||
|
||
use DB; | ||
use Validator; | ||
use App\Coa; | ||
use Illuminate\Http\Request; | ||
|
||
class CoaController extends Controller{ | ||
|
||
|
||
public function index() | ||
{ | ||
$table_data = Coa::with('induk')->advancedFilter(); | ||
|
||
return response() | ||
->json([ | ||
'model' => $table_data | ||
]); | ||
} | ||
|
||
public function get() | ||
{ | ||
$table_data = Coa::orderby('kode','asc')->get(); | ||
|
||
return response() | ||
->json([ | ||
'model' => $table_data | ||
]); | ||
} | ||
|
||
public function create() | ||
{ | ||
return response() | ||
->json([ | ||
'form' => Coa::initialize(), | ||
'rules' => Coa::$rules, | ||
'option' => [] | ||
]); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$this->validate($request,Coa::$rules); | ||
|
||
\DB::beginTransaction(); | ||
try{ | ||
|
||
$name = $request->name; | ||
$tipe = ''; | ||
$level = ''; | ||
|
||
if($request->id_induk == 0){ | ||
$tipe = 'G'; | ||
$level = 1; | ||
}else{ | ||
$kelasInduk = Coa::findOrFail($request->id_induk); | ||
|
||
$tipe = 'P'; | ||
$level = $kelasInduk->level + 1; | ||
|
||
if($kelasInduk->tipe == 'P'){ | ||
$kelasInduk->tipe = 'G'; | ||
$kelasInduk->update(); | ||
} | ||
} | ||
|
||
$kelas = Coa::create($request->except('tipe','level') + [ | ||
'tipe' => $tipe, | ||
'level' => $level | ||
]); | ||
|
||
\DB::commit(); | ||
|
||
return response() | ||
->json([ | ||
'saved' => true, | ||
'message' => 'CoA ' .$name. ' berhasil ditambah', | ||
'id' => $kelas->id | ||
]); | ||
} catch (\Exception $e){ | ||
\DB::rollBack(); | ||
abort(500, $e->getMessage()); | ||
} | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
$kelas = Coa::findOrFail($id); | ||
|
||
return response() | ||
->json([ | ||
'form' => $kelas, | ||
'option' => [] | ||
]); | ||
} | ||
|
||
public function update(Request $request, $id) | ||
{ | ||
$rules = Coa::$rules; | ||
$rules['kode'] = $rules['kode'] . ',id,' . $id; | ||
$validationCertificate = Validator::make($request->all(), $rules); | ||
|
||
\DB::beginTransaction(); | ||
try{ | ||
$kelas = Coa::findOrFail($id); | ||
|
||
$name = $request->name; | ||
$tipe = ''; | ||
$level = ''; | ||
$id_induk_sebelumnya = $kelas->id_induk; | ||
|
||
if($request->id_induk == 0){ | ||
$tipe = 'G'; | ||
$level = 1; | ||
}else{ | ||
$kelasInduk = Coa::findOrFail($request->id_induk); | ||
|
||
$tipe = 'P'; | ||
$level = $kelasInduk->level + 1; | ||
|
||
if($kelasInduk->tipe == 'P'){ | ||
$kelasInduk->tipe = 'G'; | ||
$kelasInduk->update(); | ||
} | ||
} | ||
|
||
$kelas->update($request->except('tipe','level') + [ | ||
'tipe' => $tipe, | ||
'level' => $level | ||
]); | ||
|
||
if($id_induk_sebelumnya != 0){ | ||
$kelasAdaIndukSebelumnya = Coa::where('id_induk', $id_induk_sebelumnya)->first(); | ||
|
||
if(!$kelasAdaIndukSebelumnya){ | ||
$kelasIndukSebelumnya = Coa::findOrFail($id_induk_sebelumnya); | ||
if($kelasIndukSebelumnya->tipe == 'G'){ | ||
$kelasIndukSebelumnya->tipe = 'P'; | ||
$kelasIndukSebelumnya->update(); | ||
} | ||
} | ||
} | ||
|
||
\DB::commit(); | ||
|
||
return response() | ||
->json([ | ||
'saved' => true, | ||
'message' => 'CoA ' .$name. ' berhasil diubah', | ||
'id' => $kelas->id | ||
]); | ||
} catch (\Exception $e){ | ||
\DB::rollBack(); | ||
abort(500, $e->getMessage()); | ||
} | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
$kelas = Coa::findOrFail($id); | ||
$name = $kelas->name; | ||
|
||
$kelas->delete(); | ||
|
||
return response() | ||
->json([ | ||
'deleted' => true, | ||
'message' => 'CoA ' .$name. 'berhasil dihapus' | ||
]); | ||
} | ||
} |
Oops, something went wrong.