Skip to content

Commit

Permalink
adding coa, improving load time by adding lazy loading and updating l…
Browse files Browse the repository at this point in the history
…aravel mix
  • Loading branch information
Tony committed Nov 14, 2020
1 parent 43541ef commit 43adaa5
Show file tree
Hide file tree
Showing 198 changed files with 493,309 additions and 446,550 deletions.
Binary file modified .DS_Store
Binary file not shown.
45 changes: 45 additions & 0 deletions app/Coa.php
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');
}

}
39 changes: 39 additions & 0 deletions app/CoaSaldo.php
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' => ''
];
}
}
32 changes: 23 additions & 9 deletions app/Http/Controllers/AnggotaCuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ public function destroyKlaim($id)

private function syncCu($request, $kelas)
{
// if by user bkcu
if($request->anggota_cu_cu){
$cus = $request->anggota_cu_cu;
foreach($kelas->anggota_cu_cu as $aV){ $aTmp1[] = $aV['id']; }
Expand Down Expand Up @@ -702,19 +703,32 @@ private function syncCu($request, $kelas)
}
}

// if by user cu
if($request->id_cu){
$kelasCu = AnggotaCuCu::where('anggota_cu_id',$kelas->id)->where('cu_id', $request->id_cu)->first();

if($kelasCu){
$kelasCu = AnggotaCuCu::where('anggota_cu_id',$kelas->id)->where('cu_id', $request->id_cu);
$kelasCu->update([
'anggota_cu_id' => $kelas->id,
'cu_id' => $request->id_cu,
'tp_id' => $request->tp_id,
'no_ba' => $request->no_ba,
'tanggal_masuk' => $request->tanggal_masuk,
'keterangan_masuk' => $request->keterangan_masuk,
]);
$kelasCuCu = AnggotaCuCu::where('anggota_cu_id',$kelas->id)->where('cu_id', $request->id_cu)->whereNull('tanggal_keluar')->first();

if($kelasCuCu){
$kelasCuCu->update([
'anggota_cu_id' => $kelas->id,
'cu_id' => $request->id_cu,
'tp_id' => $request->tp_id,
'no_ba' => $request->no_ba,
'tanggal_masuk' => $request->tanggal_masuk,
'keterangan_masuk' => $request->keterangan_masuk,
]);
}else{
AnggotaCuCu::create([
'anggota_cu_id' => $kelas->id,
'cu_id' => $request->id_cu,
'tp_id' => $request->tp_id,
'no_ba' => $request->no_ba,
'tanggal_masuk' => $request->tanggal_masuk,
'keterangan_masuk' => $request->keterangan_masuk
]);
}
}else{
AnggotaCuCu::create([
'anggota_cu_id' => $kelas->id,
Expand Down
172 changes: 172 additions & 0 deletions app/Http/Controllers/CoaController.php
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'
]);
}
}
Loading

0 comments on commit 43adaa5

Please sign in to comment.