Skip to content

Commit

Permalink
fixing bug for mitraorang and adding tgl buat, tgl ubah in riwayat ak…
Browse files Browse the repository at this point in the history
…tivis
  • Loading branch information
t0n1zz committed Apr 27, 2023
1 parent 39bc8ad commit 35fc2cb
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 79 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules
/public/js/components
public/js/components
/public/js/components/
/public/storage
/storage/*.key
/vendor
Expand Down
123 changes: 82 additions & 41 deletions app/Http/Controllers/MitraOrangController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace App\Http\Controllers;

use DB;
Expand All @@ -10,7 +11,8 @@
use Illuminate\Http\Request;
use Venturecraft\Revisionable\Revision;

class MitraOrangController extends Controller{
class MitraOrangController extends Controller
{

protected $imagepath = 'images/mitra_orang/';
protected $width = 200;
Expand All @@ -19,69 +21,108 @@ class MitraOrangController extends Controller{

public function index()
{
$table_data = MitraOrang::with('Villages','Districts','Regencies','Provinces')->advancedFilter();
$table_data = MitraOrang::with('Villages', 'Districts', 'Regencies', 'Provinces')->advancedFilter();

$table_data = $this->formatQuery($table_data);

return response()
->json([
'model' => $table_data
]);
->json([
'model' => $table_data
]);
}

public function indexPeserta($kegiatan_id)
{
$kegiatanPeserta = KegiatanPeserta::where('kegiatan_id',$kegiatan_id)->whereNotNull('mitra_orang_id')->pluck('mitra_orang_id')->toArray();
$kegiatanPeserta = KegiatanPeserta::where('kegiatan_id', $kegiatan_id)->whereNotNull('mitra_orang_id')->pluck('mitra_orang_id')->toArray();

$table_data = MitraOrang::with('Villages', 'Districts', 'Regencies', 'Provinces')->whereNotIn('id', $kegiatanPeserta)->advancedFilter();

$table_data = MitraOrang::with('Villages','Districts','Regencies','Provinces')->whereNotIn('id', $kegiatanPeserta)->advancedFilter();
$table_data = $this->formatQuery($table_data);

return response()
->json([
'model' => $table_data
]);
->json([
'model' => $table_data
]);
}

public function formatQuery($table_data)
{
foreach ($table_data as $t) {
if ($t->pekerjaan_tingkat == 1) {
$t->pekerjaan_tingkat = 'Pengurus';
} else if ($t->pekerjaan_tingkat == 2) {
$t->pekerjaan_tingkat = 'Pengawas';
} else if ($t->pekerjaan_tingkat == 3) {
$t->pekerjaan_tingkat = 'Komite';
} else if ($t->pekerjaan_tingkat == 4) {
$t->pekerjaan_tingkat = 'Penasihat';
} else if ($t->pekerjaan_tingkat == 5) {
$t->pekerjaan_tingkat = 'Senior Manajer';
} else if ($t->pekerjaan_tingkat == 6) {
$t->pekerjaan_tingkat = 'Manajer';
} else if ($t->pekerjaan_tingkat == 7) {
$t->pekerjaan_tingkat = 'Supervisor';
} else if ($t->pekerjaan_tingkat == 8) {
$t->pekerjaan_tingkat = 'Staf';
} else if ($t->pekerjaan_tingkat == 9) {
$t->pekerjaan_tingkat = 'Kontrak';
} else if ($t->pekerjaan_tingkat == 10) {
$t->pekerjaan_tingkat = 'Kolektor';
} else if ($t->pekerjaan_tingkat == 11) {
$t->pekerjaan_tingkat = 'Kelompok Inti';
} else if ($t->pekerjaan_tingkat == 12) {
$t->pekerjaan_tingkat = 'Supporting Unit';
} else if ($t->pekerjaan_tingkat == 13) {
$t->pekerjaan_tingkat = 'Vendor sMartCU';
}
}

return $table_data;
}

public function create()
{
return response()
->json([
'form' => MitraOrang::initialize(),
'rules' => MitraOrang::$rules,
'option' => []
'form' => MitraOrang::initialize(),
'rules' => MitraOrang::$rules,
'option' => []
]);
}

public function store(Request $request)
{
$this->validate($request,MitraOrang::$rules);
$this->validate($request, MitraOrang::$rules);

$name = $request->name;

// processing single image upload
if(!empty($request->gambar))
$fileName = Helper::image_processing($this->imagepath,$this->width,$this->height,$request->gambar,'', $name);
if (!empty($request->gambar))
$fileName = Helper::image_processing($this->imagepath, $this->width, $this->height, $request->gambar, '', $name);
else
$fileName = '';

$kelas = MitraOrang::create($request->except('gambar') + [
'gambar' => $fileName
]);

return response()
->json([
'saved' => true,
'message' => $this->message. ' ' .$name. ' berhasil ditambah',
'message' => $this->message . ' ' . $name . ' berhasil ditambah',
'id' => $kelas->id
]);
]);
}

public function edit($id)
{
$kelas = MitraOrang::with('Villages','Districts','Regencies','Provinces')->findOrFail($id);
$kelas = MitraOrang::with('Villages', 'Districts', 'Regencies', 'Provinces')->findOrFail($id);

return response()
->json([
'form' => $kelas,
'option' => []
]);
->json([
'form' => $kelas,
'option' => []
]);
}

public function update(Request $request, $id)
Expand All @@ -93,19 +134,19 @@ public function update(Request $request, $id)
$kelas = MitraOrang::findOrFail($id);

// processing single image upload
if(!empty($request->gambar))
$fileName = Helper::image_processing($this->imagepath,$this->width,$this->height,$request->gambar, $kelas->gambar, $name);
if (!empty($request->gambar))
$fileName = Helper::image_processing($this->imagepath, $this->width, $this->height, $request->gambar, $kelas->gambar, $name);
else
$fileName = '';

$kelas->update($request->except('gambar') + [
'gambar' => $fileName
]);
]);

return response()
->json([
'saved' => true,
'message' => $this->message. ' ' .$name. ' berhasil diubah'
'message' => $this->message . ' ' . $name . ' berhasil diubah'
]);
}

Expand All @@ -119,36 +160,36 @@ public function destroy($id)
return response()
->json([
'deleted' => true,
'message' => $this->message. ' ' .$name. 'berhasil dihapus'
'message' => $this->message . ' ' . $name . 'berhasil dihapus'
]);
}

public function count()
{
$table_data = MitraOrang::count();
$table_data = MitraOrang::count();

return response()
return response()
->json([
'model' => $table_data
'model' => $table_data
]);
}

public function history()
{
$time = \Carbon\Carbon::now()->subMonths(6);
$table_data = Revision::with('revisionable')->where('revisionable_type','App\MitraOrang')->where('created_at','>=',$time)->orderBy('created_at','desc')->take(5);
{
$time = \Carbon\Carbon::now()->subMonths(6);

$table_data = Revision::with('revisionable')->where('revisionable_type', 'App\MitraOrang')->where('created_at', '>=', $time)->orderBy('created_at', 'desc')->take(5);

$history = collect();
foreach($table_data as $hs){
$history = collect();
foreach ($table_data as $hs) {
$n = collect($hs);
$n->put('user',$hs->userResponsible());
$n->put('user', $hs->userResponsible());
$history->push($n);
}

return response()
->json([
'model' => $history
]);
}
}
}
}
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/components/10.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/components/23.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/components/82.js

Large diffs are not rendered by default.

Loading

0 comments on commit 35fc2cb

Please sign in to comment.