diff --git a/app/Enums/SigdStatus.php b/app/Enums/SigdStatus.php index 6004157..4fd8cfe 100644 --- a/app/Enums/SigdStatus.php +++ b/app/Enums/SigdStatus.php @@ -13,10 +13,10 @@ enum SigdStatus: int public function badge(): string { return match ($this) { - self::PENDING => 'PENDING', - self::PROSES => 'PROSES', - self::SELESAI => 'SELESAI', - self::GAGAL => 'GAGAL', + self::PENDING => 'PENDING', + self::PROSES => 'PROSES', + self::SELESAI => 'SELESAI', + self::GAGAL => 'GAGAL', }; } } diff --git a/app/Http/Controllers/Dashboard/DashboardInventoryController.php b/app/Http/Controllers/Dashboard/DashboardInventoryController.php index b0510a9..81f48da 100644 --- a/app/Http/Controllers/Dashboard/DashboardInventoryController.php +++ b/app/Http/Controllers/Dashboard/DashboardInventoryController.php @@ -24,9 +24,11 @@ class DashboardInventoryController extends Controller try { $inventoryYear = $request->input('year', date('Y')); - $dashboardData = $this->emissionService->getDashboardData($inventoryYear); + $data['dashboardData'] = $this->emissionService->getDashboardData($inventoryYear); + $data['title'] = $this->title; + $data['route'] = $this->route; - return view($this->template.'.index', $dashboardData); + return view($this->template.'.index', $data); } catch (\Exception $e) { Log::error('Error loading dashboard data', [ 'message' => $e->getMessage(), diff --git a/app/Http/Controllers/Tool/CalculationController.php b/app/Http/Controllers/Tool/CalculationController.php index 4f624bd..b275e13 100644 --- a/app/Http/Controllers/Tool/CalculationController.php +++ b/app/Http/Controllers/Tool/CalculationController.php @@ -14,6 +14,9 @@ use Illuminate\Routing\Controllers\Middleware; class CalculationController implements HasMiddleware { + protected $title = 'Kalkulasi Emisi'; + protected $template = 'modules.tool.calculation'; + protected $route = 'modules.kalkulasi.kalkulasi-emisi'; protected $service; public function __construct(CalculationService $service) @@ -30,77 +33,21 @@ class CalculationController implements HasMiddleware public function index(Request $request) { - if ($request->ajax()) { - $query = $this->service->getRawAll(); + + $data['route'] = $this->route; + $data['title'] = $this->title; + $data['sectors'] = $this->service->getSectors(); - // Apply category filter if a category is selected - if ($request->has('sectorFilter') && $request->sectorFilter != '' && $request->sectorFilter != 'SEMUA SEKTOR') { - $query = $query->where($request->sectorFilter, true); - } - - if ($request->has('inventoryYearFilter') && $request->inventoryYearFilter != '' && $request->inventoryYearFilter != 'SEMUA TAHUN') { - $query = $query->where('inventory_year', $request->inventoryYearFilter); - } - - $result = datatables()->of($query) - ->addColumn('sector', function ($row) { - return $row->sector; - }) - ->addColumn('duration', function ($row) { - if ($row->finished_time === null || $row->executed_time === null) { - return ''; - } - - // Parse the date-time strings into Carbon instances - $start = Carbon::parse($row->executed_time); - $end = Carbon::parse($row->finished_time); - - // Calculate the difference in seconds - $diffInSeconds = $start->diffInSeconds($end); - - // Format the duration as HH:MM:SS - $hours = floor($diffInSeconds / 3600); - $minutes = floor(($diffInSeconds % 3600) / 60); - $seconds = $diffInSeconds % 60; - - return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); - }) - ->editColumn('created_at', function ($row) { - return $row->created_at->format('d-m-Y H:i:s') - ?? ''; - }) - ->editColumn('executed_time', function ($row) { - if ($row->executed_time === null) { - return ''; - } - - return $row->executed_time->format('d-m-Y H:i:s'); - }) - ->editColumn('finished_time', function ($row) { - if ($row->finished_time === null) { - return ''; - } - - return $row->finished_time->format('d-m-Y H:i:s'); - }) - ->addColumn('status', function ($row) { - $status = SigdStatus::from($row->calculation_status); - return $status->badge() ?? ''; - }) - ->rawColumns(['status', 'sector', 'duration']) - ->make(true); - - return $result; - } - - $sectors = $this->service->getSectors(); - return view('tool.calculation.index', compact('sectors')); + return view($this->template.'.index', $data); } public function create() { - return view('tool.calculation.create'); + $data['route'] = $this->route; + $data['title'] = $this->title; + + return view($this->template.'.create',$data); } public function store(Request $request) @@ -132,7 +79,7 @@ class CalculationController implements HasMiddleware $this->service->create($data); logUserActivity(ActivityType::CALCULATION_EMISI); - return redirect()->route('calculation.index')->with('success', 'Kalkulasi Emisi berhasil ditambahkan.'); + return redirect()->route($this->route.'.index')->with('success', 'Kalkulasi Emisi berhasil ditambahkan.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Kalkulasi Emisi gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]); } @@ -147,4 +94,57 @@ class CalculationController implements HasMiddleware 'years' => $years ]); } + + public function grid(Request $request) + { + $_data = []; + + $data = $this->service->getRawAll(); + + // Apply category filter if a category is selected + if ($request->has('sectorFilter') && $request->sectorFilter != '' && $request->sectorFilter != 'SEMUA SEKTOR') { + $data = $query->where($request->sectorFilter, true); + } + + if ($request->has('inventoryYearFilter') && $request->inventoryYearFilter != '' && $request->inventoryYearFilter != 'SEMUA TAHUN') { + $data = $query->where('inventory_year', $request->inventoryYearFilter); + } + + foreach ($data->get() as $key => $row) { + + $status = SigdStatus::from($row->calculation_status); + if ($row->finished_time === null || $row->executed_time === null) { + $duration = ''; + } + + // Parse the date-time strings into Carbon instances + $start = Carbon::parse($row->executed_time); + $end = Carbon::parse($row->finished_time); + + // Calculate the difference in seconds + $diffInSeconds = $start->diffInSeconds($end); + + // Format the duration as HH:MM:SS + $hours = floor($diffInSeconds / 3600); + $minutes = floor(($diffInSeconds % 3600) / 60); + $seconds = $diffInSeconds % 60; + + $duration = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); + + + $_data[] = [ + 'no' => $key+1, + 'sector' => $row->sector, + 'inventory_year' => $row->inventory_year, + 'status' => $status->badge() ?? '', + 'finished_time' => @$row->finished_time ? date('d-m-Y H:i:s', strtotime(@$row->finished_time)) : '', + 'executed_time' => @$row->executed_time ? date('d-m-Y H:i:s', strtotime(@$row->executed_time)) : '', + 'created_at' => @$row->created_at ? date('d-m-Y H:i:s', strtotime(@$row->created_at)) : '', + 'duration' => $duration, + ]; + + } + + return response()->json($_data); + } } diff --git a/app/Http/Controllers/Tool/CalculationController.php.bak b/app/Http/Controllers/Tool/CalculationController.php.bak deleted file mode 100644 index 53d1433..0000000 --- a/app/Http/Controllers/Tool/CalculationController.php.bak +++ /dev/null @@ -1,148 +0,0 @@ -service = $service; - } - - public static function middleware(): array - { - return [ - //new Middleware('permission:/tool/calculation'), - ]; - } - - public function index(Request $request) - { - if ($request->ajax()) { - $query = $this->service->getRawAll(); - - // Apply category filter if a category is selected - if ($request->has('sectorFilter') && $request->sectorFilter != '' && $request->sectorFilter != 'SEMUA SEKTOR') { - $query = $query->where($request->sectorFilter, true); - } - - if ($request->has('inventoryYearFilter') && $request->inventoryYearFilter != '' && $request->inventoryYearFilter != 'SEMUA TAHUN') { - $query = $query->where('inventory_year', $request->inventoryYearFilter); - } - - $result = datatables()->of($query) - ->addColumn('sector', function ($row) { - return $row->sector; - }) - ->addColumn('duration', function ($row) { - if ($row->finished_time === null || $row->executed_time === null) { - return ''; - } - - // Parse the date-time strings into Carbon instances - $start = Carbon::parse($row->executed_time); - $end = Carbon::parse($row->finished_time); - - // Calculate the difference in seconds - $diffInSeconds = $start->diffInSeconds($end); - - // Format the duration as HH:MM:SS - $hours = floor($diffInSeconds / 3600); - $minutes = floor(($diffInSeconds % 3600) / 60); - $seconds = $diffInSeconds % 60; - - return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); - }) - ->editColumn('created_at', function ($row) { - return $row->created_at->format('d-m-Y H:i:s') - ?? ''; - }) - ->editColumn('executed_time', function ($row) { - if ($row->executed_time === null) { - return ''; - } - - return $row->executed_time->format('d-m-Y H:i:s'); - }) - ->editColumn('finished_time', function ($row) { - if ($row->finished_time === null) { - return ''; - } - - return $row->finished_time->format('d-m-Y H:i:s'); - }) - ->addColumn('status', function ($row) { - $status = SigdStatus::from($row->calculation_status); - return $status->badge() ?? ''; - }) - ->rawColumns(['status', 'sector', 'duration']) - ->make(true); - - return $result; - } - - $sectors = $this->service->getSectors(); - return view('tool.calculation.index', compact('sectors')); - } - - - public function create() - { - return view('tool.calculation.create'); - } - - public function store(Request $request) - { - // Validate the form data - $request->validate([ - 'inventory_year' => 'required|integer|min:2000|max:' . date('Y'), - 'energy' => 'boolean', - 'agriculture' => 'boolean', - 'folu' => 'boolean', - 'waste' => 'boolean', - ]); - - $isLocked = ActivityLock::isLocked($request->inventory_year); - - if ($isLocked) { - return back()->withErrors(['error' => 'Kalkulasi Emisi gagal disimpan. Tahun Inventory dikunci.']); - } - - try { - $data = $request->all(); - $data['energy'] = $request->has('energy') ? 1 : 0; - $data['agriculture'] = $request->has('agriculture') ? 1 : 0; - $data['folu'] = $request->has('folu') ? 1 : 0; - $data['waste'] = $request->has('waste') ? 1 : 0; - - $this->service->create($data); - logUserActivity(ActivityType::CALCULATION_EMISI); - - return redirect()->route('calculation.index')->with('success', 'Kalkulasi Emisi berhasil ditambahkan.'); - } catch (\Exception $e) { - return back()->withErrors(['error' => 'Kalkulasi Emisi gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]); - } - } - - public function getActivityYearRange(Request $request) - { - $inventoryYear = (int) $request->query('inventoryYear'); - $years = activityYearRange($inventoryYear); - - return response()->json([ - 'years' => $years - ]); - } -} diff --git a/app/Http/Controllers/Tool/CopyActivityController.php b/app/Http/Controllers/Tool/CopyActivityController.php index eb1d6f4..fc3db93 100644 --- a/app/Http/Controllers/Tool/CopyActivityController.php +++ b/app/Http/Controllers/Tool/CopyActivityController.php @@ -15,6 +15,9 @@ use Illuminate\Support\Facades\Auth; class CopyActivityController implements HasMiddleware { + protected $title = 'Salin Aktivitas'; + protected $template = 'modules.tool.copy'; + protected $route = 'modules.kalkulasi.salin-aktivitas'; protected $service; public function __construct(CopyActivityService $service) @@ -31,63 +34,14 @@ class CopyActivityController implements HasMiddleware public function index(Request $request) { - $availableYears = ActivityForm::select('inventory_year')->whereNull('agency_id') + $data['availableYears'] = ActivityForm::select('inventory_year')->whereNull('agency_id') ->distinct()->rowActive()->orderBy('inventory_year', 'desc') ->get()->pluck('inventory_year')->toArray(); + + $data['route'] = $this->route; + $data['title'] = $this->title; - if ($request->ajax()) { - $query = $this->service->getRawAll(); - - $result = datatables()->of($query) - ->addColumn('duration', function ($row) { - if ($row->finished_time === null || $row->executed_time === null) { - return ''; - } - - $start = Carbon::parse($row->executed_time); - $end = Carbon::parse($row->finished_time); - - // Calculate the difference in seconds - $diffInSeconds = $start->diffInSeconds($end); - - // Format the duration as HH:MM:SS - $hours = floor($diffInSeconds / 3600); - $minutes = floor(($diffInSeconds % 3600) / 60); - $seconds = $diffInSeconds % 60; - - return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); - }) - ->editColumn('created_at', function ($row) { - return $row->created_at->format('d-m-Y H:i:s') - ?? ''; - }) - ->editColumn('executed_time', function ($row) { - if ($row->executed_time === null) { - return ''; - } - - return $row->executed_time->format('d-m-Y H:i:s'); - }) - ->editColumn('finished_time', function ($row) { - if ($row->finished_time === null) { - return ''; - } - - return $row->finished_time->format('d-m-Y H:i:s'); - }) - ->addColumn('status', function ($row) { - $status = SigdStatus::from($row->status); - return $status->badge() ?? ''; - }) - ->rawColumns(['status', 'duration']) - ->make(true); - - return $result; - } - - return view('tool.copy.index', [ - 'availableYears' => $availableYears - ]); + return view($this->template.'.index', $data); } public function store(Request $request) @@ -109,9 +63,53 @@ class CopyActivityController implements HasMiddleware $this->service->create($data); - return redirect()->route('copy.index')->with('success', 'Salin Aktivitas berhasil ditambahkan.'); + return redirect()->route($this->route.'.index')->with('success', 'Salin Aktivitas berhasil ditambahkan.'); } catch (\Exception $e) { return back()->withErrors(['error' => 'Salin Aktivitas gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]); } } + + public function grid(Request $request) + { + $_data = []; + + $data = $this->service->getRawAll(); + + foreach ($data->get() as $key => $row) { + + $status = SigdStatus::from($row->status); + if ($row->finished_time === null || $row->executed_time === null) { + $duration = ''; + } + + // Parse the date-time strings into Carbon instances + $start = Carbon::parse($row->executed_time); + $end = Carbon::parse($row->finished_time); + + // Calculate the difference in seconds + $diffInSeconds = $start->diffInSeconds($end); + + // Format the duration as HH:MM:SS + $hours = floor($diffInSeconds / 3600); + $minutes = floor(($diffInSeconds % 3600) / 60); + $seconds = $diffInSeconds % 60; + + $duration = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); + + + $_data[] = [ + 'no' => $key+1, + 'to_year' => $row->to_year, + 'from_year' => $row->from_year, + 'status' => $status->badge() ?? '', + 'finished_time' => @$row->finished_time ? date('d-m-Y H:i:s', strtotime(@$row->finished_time)) : '', + 'executed_time' => @$row->executed_time ? date('d-m-Y H:i:s', strtotime(@$row->executed_time)) : '', + 'created_at' => @$row->created_at ? date('d-m-Y H:i:s', strtotime(@$row->created_at)) : '', + 'duration' => $duration, + ]; + + } + + return response()->json($_data); + } } diff --git a/app/Http/Controllers/Tool/LockActivityController.php b/app/Http/Controllers/Tool/LockActivityController.php index 0554931..33b1f24 100644 --- a/app/Http/Controllers/Tool/LockActivityController.php +++ b/app/Http/Controllers/Tool/LockActivityController.php @@ -10,6 +10,9 @@ use Illuminate\Routing\Controllers\Middleware; class LockActivityController implements HasMiddleware { + protected $title = 'Kunci Aktivitas'; + protected $template = 'modules.tool.lock'; + protected $route = 'modules.kalkulasi.kunci-aktivitas'; protected $lockService; public function __construct(LockActivityService $lockService) @@ -26,45 +29,10 @@ class LockActivityController implements HasMiddleware public function index(Request $request) { - if ($request->ajax()) { - $locks = $this->lockService->getAll(); + $data['route'] = $this->route; + $data['title'] = $this->title; - $result = datatables()->of($locks) - ->editColumn('updated_at', function ($row) { - return $row->created_at->format('d-m-Y H:i:s') - ?? ''; - }) - ->addColumn('status', function ($row) { - if ($row->lock_status == 'locked') { - return 'LOCKED'; - } else { - return 'OPEN'; - } - }) - ->addColumn('action', function ($row) { - $buttonStyle = 'style="min-width: 120px;"'; // Adjust min-width as needed - - $action = $row->lock_status == 'locked' - ? '
' - : ''; - - return $action; - }) - ->rawColumns(['status', 'action']) - ->make(true); - - return $result; - } - - return view('tool.lock.index'); + return view($this->template.'.index',$data); } public function lock(Request $request) @@ -102,4 +70,46 @@ class LockActivityController implements HasMiddleware return redirect()->back()->withErrors(['error' => 'Tahun Inventory ' . $request->year . 'gagal dibuka. Mohon dicoba kembali.']); } } + + public function grid(Request $request) + { + $_data = []; + + $data = $this->lockService->getAll(); + + foreach ($data as $key => $row) { + + if ($row->lock_status == 'locked') { + $status = 'LOCKED'; + } else { + $status = 'OPEN'; + } + + $buttonStyle = 'style="min-width: 120px;"'; // Adjust min-width as needed + + $action = $row->lock_status == 'locked' + ? '' + : ''; + + + $_data[] = [ + 'no' => $key+1, + 'inventory_year' => $row->inventory_year, + 'status' => $status, + 'executed_time' => @$row->created_at ? date('d-m-Y H:i:s', strtotime(@$row->created_at)) : '', + 'action' => $action, + ]; + + } + + return response()->json($_data); + } } diff --git a/app/Models/Calculation.php b/app/Models/Calculation.php index 7d840ad..dc03301 100644 --- a/app/Models/Calculation.php +++ b/app/Models/Calculation.php @@ -34,19 +34,19 @@ class Calculation extends SigdModel $badgeStyle = ''; if ($this->energy) { - $tags[] = 'ENERGI'; + $tags[] = 'ENERGI'; } if ($this->agriculture) { - $tags[] = 'PERTANIAN'; + $tags[] = 'PERTANIAN'; } if ($this->folu) { - $tags[] = 'LAHAN'; + $tags[] = 'LAHAN'; } if ($this->waste) { - $tags[] = 'LIMBAH'; + $tags[] = 'LIMBAH'; } if ($this->ippu) { - $tags[] = 'IPPU'; + $tags[] = 'IPPU'; } return implode(' ', $tags); diff --git a/resources/views/modules/form/livestock-manure/index.blade.php b/resources/views/modules/form/livestock-manure/index.blade.php index cff02d1..5609c7f 100644 --- a/resources/views/modules/form/livestock-manure/index.blade.php +++ b/resources/views/modules/form/livestock-manure/index.blade.php @@ -7,7 +7,7 @@| Waktu Input | -Tahun Inventory | -Sektor | -Status | -Waktu Eksekusi | -Waktu Selesai | -Durasi | +Waktu Input | +Tahun Inventory | +Sektor | +Status | +Waktu Eksekusi | +Waktu Selesai | +Durasi |
|---|
{{ $error }}
- @endforeach -| Waktu Input | -Tahun Tujuan | -Tahun Sumber | -Status | -Waktu Eksekusi | -Waktu Selesai | -Durasi | +Waktu Input | +Tahun Tujuan | +Tahun Sumber | +Status | +Waktu Eksekusi | +Waktu Selesai | +Durasi |
|---|