Skip to content

Commit

Permalink
Merge branch 'meor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiextreme committed Sep 19, 2022
2 parents e5994aa + f3ca249 commit 9d26368
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 142 deletions.
35 changes: 33 additions & 2 deletions app/Http/Controllers/Segment/Admin/Bilik/BilikController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Http\Controllers\Controller;
use App\Models\Tetapan\Bangunan;
use App\Models\Tetapan\BangunanBilik;
use App\Models\Tetapan\BilikFasiliti;
use App\Models\Tetapan\Fasiliti;
use App\Models\Tetapan\Lokasi;
use Illuminate\Http\Request;
use Yajra\DataTables\DataTables;
Expand All @@ -17,8 +19,10 @@ public function __construct()

public function index(){
$lokasiList = Lokasi::where('flag', 1)->where('delete_id', 0)->get();
$kemudahanList = Fasiliti::where('flag', 1)->where('delete_id', 0)->get();
return view('segment.admin.bilik.index', [
'lokasiList' => $lokasiList
'lokasiList' => $lokasiList,
'kemudahanList' => $kemudahanList
]);
}

Expand Down Expand Up @@ -50,13 +54,29 @@ public function getBilik(Request $request){
$id = $request->input('id');
$model = BangunanBilik::find($id);

$data = [];
$data = [
'fasiliti' => []
];

$data['nama'] = $model->nama;
$data['lokasi_id'] = $model->bilikBangunan->lokasis_id;
$data['bangunan_id'] = $model->bangunans_id;
$data['aras'] = $model->aras;
$data['kapasiti'] = $model->kapasiti;

$fasiliti = $model->bilikFasiliti;

if($fasiliti){
foreach($fasiliti as $f){
$data['fasiliti'][] = [
'id' => $f->id,
'fasiliti_name' => $f->BFFasiliti->nama,
'fasilitisId' => $f->fasilitis_id,
'kuantiti' => $f->kuantiti
];
}
}

return response()->json([
'success' => 1,
'data' => $data
Expand All @@ -78,4 +98,15 @@ public function deleteBilik(Request $request){
'success' => 1,
]);
}

public function deleteItemBilik(Request $request){
$id = $request->input('id');
$model = BilikFasiliti::find($id);
$model->delete_id = 1;
$model->save();

return response()->json([
'success' => 1,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\Mykj\ListPegawai2;
use App\Models\Tempahan\TempahanBilik;
use App\Models\Tetapan\BangunanBilik;
use App\Models\Tetapan\Fasiliti;
use Illuminate\Http\Request;
use Yajra\DataTables\DataTables;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function getTempahanBilikList(){
->addColumn('tempoh', function($data){
return 'Dari: '.date('d-m-Y H:i', strtotime($data->masa_mula)).' <br> Hingga: '.date('d-m-Y H:i', strtotime($data->masa_tamat));
})
->addColumn('status', function($data){
->addColumn('status_tempahan', function($data){
$label = '';
if($data->status == 0){
$label = '<span style="color:blue">Belum Lulus</span>';
Expand All @@ -52,10 +53,27 @@ public function getTempahanBilikList(){
})
->addColumn('action', function($data){
})
->rawColumns(['action', 'nama', 'maklumat', 'tempoh', 'status'])
->rawColumns(['action', 'nama', 'maklumat', 'tempoh', 'status_tempahan'])
->make(true);
}

public function getFasilitiBilik(BangunanBilik $bilik){
$data = [];

$getFasiliti = $bilik->bilikFasiliti;

if(count($getFasiliti) > 0){
foreach($getFasiliti as $gF){
$data[] = [
'nama' => $gF->BFFasiliti->nama,
'kuantiti' => $gF->kuantiti
];
}
}
return $data;

}

public function getTempahanBilik(Request $request){
$id = $request->input('id');
$model = TempahanBilik::find($id);
Expand All @@ -65,7 +83,8 @@ public function getTempahanBilik(Request $request){
'tempahan' => date('d-m-Y H:i', strtotime($model->created_at)),
'masa_mula' => date('d-m-Y H:i', strtotime($model->masa_mula)),
'masa_tamat' => date('d-m-Y H:i', strtotime($model->masa_tamat)),
'bilik' => $model->tempahanBilik->nama
'bilik' => $model->tempahanBilik->nama,
'fasiliti' => self::getFasilitiBilik($model->tempahanBilik)
];

$getUrusetia = ListPegawai2::getMaklumatPegawai($model->nokp_urusetia);
Expand Down
26 changes: 26 additions & 0 deletions app/Models/Tetapan/BangunanBilik.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function bilikBangunan(){
return $this->hasOne(Bangunan::class, 'id', 'bangunans_id');
}

public function bilikFasiliti(){
return $this->hasMany(BilikFasiliti::class, 'biliks_id', 'id')->where('flag', 1)->where('delete_id', 0);
}

public static function storeUpdate(Request $request){
try {
$v = new ValidationController();
Expand Down Expand Up @@ -45,6 +49,11 @@ public static function storeUpdate(Request $request){
$model->kapasiti = $v->bilik_kapasiti;

if($model->save()){
$kemudahan_list = json_decode($request->input('kemudahan_list'));
if(!empty($kemudahan_list)){
BangunanBilik::addFasiliti($kemudahan_list, $model->id);
}

return response()->json([
'success' => 1
]);
Expand All @@ -63,4 +72,21 @@ public static function checkDuplicate($name, $id = false, $bangunan_id = false){

return !($model == null);
}

public static function addFasiliti($kemudahan, $bilik_id){
foreach($kemudahan as $k){
$model = BilikFasiliti::where('biliks_id', $bilik_id)->where('fasilitis_id', $k[0])->first();

if(!$model){
$model = new BilikFasiliti;
$model->biliks_id = $bilik_id;
$model->flag = 1;
$model->delete_id = 0;
}

$model->kuantiti = $k[1];
$model->fasilitis_id = $k[0];
$model->save();
}
}
}
2 changes: 1 addition & 1 deletion app/Models/Tetapan/BilikFasiliti.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function BFBilik(){
}

public function BFFasiliti(){
return $this->hasOne(Fasiliti::class, 'fasilitis_id', 'id');
return $this->hasOne(Fasiliti::class, 'id', 'fasilitis_id');
}
}
Loading

0 comments on commit 9d26368

Please sign in to comment.