main
Ilham Wara Nugroho 2026-01-06 11:53:06 +07:00
parent fd4af7eb17
commit 35dc949f9e
605 changed files with 67749 additions and 7051 deletions

View File

@ -0,0 +1,127 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Enums\SigdStatus;
use App\Models\ActivityCopy;
use App\Models\ActivityLock;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
class CopyActivityQueue extends Command
{
protected $signature = 'copy_activity:process';
protected $description = 'Process for copy the activities queue';
private $logFilePath;
public function __construct()
{
parent::__construct();
}
public function handle()
{
set_time_limit(0);
$processing = ActivityCopy::where('status', SigdStatus::PROSES)
->rowActive()
->first();
if ($processing) {
return;
}
$process = ActivityCopy::where('status', SigdStatus::PENDING)
->rowActive()
->orderBy('created_at', 'asc')
->first();
if (!$process) {
return;
}
$process->update([
'executed_time' => now(),
'status' => SigdStatus::PROSES,
]);
$this->createLogFile($process);
$this->logMessage('info', 'Salin data aktivitas untuk Tahun: ' . $process->to_year . ', dari sumber Tahun: ' . $process->from_year . ', id: ' . $process->id);
try {
$isLocked = ActivityLock::isLocked($process->to_year);
if ($isLocked) {
$this->logMessage('warning', 'Salin data aktivitas untuk Tahun: ' . $process->to_year . ', dari sumber Tahun: ' . $process->from_year . ', id: ' . $process->id . ' sedang dikunci dan tidak dapat melakukan salin data.');
$process->update([
'finished_time' => now(),
'status' => SigdStatus::GAGAL,
]);
return;
}
$this->executeService($process);
$process->update([
'finished_time' => now(),
'status' => SigdStatus::SELESAI,
]);
$this->logMessage('info', 'Salin data aktivitas untuk Tahun: ' . $process->to_year . ', dari sumber Tahun: ' . $process->from_year . ', id: ' . $process->id . ' berhasil diselesaikan.');
} catch (\Exception $e) {
$this->logMessage('error', 'Terjadi kesalahan saat proses salin data aktivitas, id: ' . $process->id . '. Error: ' . $e->getMessage());
throw $e;
}
}
private function createLogFile(ActivityCopy $process)
{
$logDirectory = storage_path('logs/copy/');
if (!File::exists($logDirectory)) {
File::makeDirectory($logDirectory, 0755, true);
}
$logFileName = $logDirectory . $process->to_year . '_' . $process->from_year . '_' . $process->id . '.log';
file_put_contents($logFileName, '');
$this->logFilePath = $logFileName;
}
private function executeService($process)
{
$service = "\\App\\Services\\Tool\\CopyActivityService";
try {
$serviceClass = app($service);
if (method_exists($serviceClass, 'copyAllData')) {
$serviceClass->copyAllData($process->from_year, $process->to_year);
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method copyAllData.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$process->update([
'executed_time' => null,
'finished_time' => null,
'status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function logMessage($level, $message)
{
$this->line($message); // Output to console
// Log to the file
$formattedMessage = '[' . now() . '] ' . strtoupper($level) . ': ' . $message . PHP_EOL;
if ($this->logFilePath) {
file_put_contents($this->logFilePath, $formattedMessage, FILE_APPEND);
}
}
}

View File

@ -0,0 +1,214 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Calculation;
use App\Enums\SigdStatus;
use App\Models\ActivityLock;
use App\Models\ReferenceWs;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class EmisiCalculationQueue extends Command
{
protected $signature = 'calculation:process';
protected $description = 'Process for the worksheet emission calculation queue';
private $logFilePath;
public function __construct()
{
parent::__construct();
}
public function handle()
{
set_time_limit(0);
try {
$processing = Calculation::where('calculation_status', SigdStatus::PROSES)->rowActive()->first();
if ($processing) {
return;
}
$calculation = Calculation::where('calculation_status', SigdStatus::PENDING)
->rowActive()->orderBy('created_at', 'asc')->first();
if (!$calculation) {
// $this->logMessage('info', 'Semua kalkulasi emisi telah berhasil diselesaikan.');
return;
}
$calculation->update([
'executed_time' => now(),
'calculation_status' => SigdStatus::PROSES,
]);
$this->createLogFile($calculation);
$this->logMessage('info', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id);
$isLocked = ActivityLock::isLocked($calculation->inventory_year);
if ($isLocked) {
$this->logMessage('warning', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id . ' sedang dikunci dan tidak dapat melakukan kalkulasi.');
$calculation->update([
'finished_time' => now(),
'calculation_status' => SigdStatus::GAGAL,
]);
return;
}
if ($calculation->energy) $this->executeService('energy', $calculation);
if ($calculation->agriculture) $this->executeService('agriculture', $calculation);
if ($calculation->folu) $this->executeService('folu', $calculation);
if ($calculation->waste) $this->executeService('waste', $calculation);
if ($calculation->ippu) $this->executeService('ippu', $calculation);
// Execute Energy GPC emission calculation
$this->energyGPCCalc($calculation);
// Execute mapping IPCC to GPC
$this->gpcMapping($calculation);
$calculation->update([
'finished_time' => now(),
'calculation_status' => SigdStatus::SELESAI,
]);
$this->logMessage('info', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id . ' berhasil diselesaikan.');
} catch (Exception $e) {
$this->logMessage('error', 'Terjadi kesalahan saat kalkulasi emisi, id: ' . $calculation->id . '. Error: ' . $e->getMessage());
throw $e;
}
}
private function createLogFile(Calculation $calculation)
{
$logDirectory = storage_path('logs/calculation/');
$this->logMessage('info', 'Checking if log directory exists: ' . $logDirectory);
if (!File::exists($logDirectory)) {
$this->logMessage('info', 'Directory not found. Creating directory: ' . $logDirectory);
File::makeDirectory($logDirectory, 0755, true);
}
$logFileName = $logDirectory . $calculation->inventory_year . '_' . $calculation->id . '.log';
file_put_contents($logFileName, '');
$this->logFilePath = $logFileName;
$this->logMessage('info', 'Log file created: ' . $logFileName);
}
private function executeService($sector, $calculation)
{
// if ($calculation->$sector) {
$wsList = ReferenceWs::where('sector', $sector)
->whereNotNull('code')->rowActive()->get();
foreach ($wsList as $ws) {
if ($ws->code == '4d1_ef') {
continue;
}
$service = "\\App\\Services\\Emisi\\" . class_basename($ws->model) . "Service";
$this->logMessage('service yang dijalankan', "{$service}");
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($ws->code, $calculation->inventory_year);
$this->logMessage('info', "Kalkulasi Emisi pada Worksheet {$ws->ws_code}. {$ws->ws_title} telah berhasil diselesaikan.");
} else {
$this->logMessage('error', "{$service} tidak memiliki method proses kalkulasi.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan {$service} pada sektor {$sector}: " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
// }
}
private function gpcMapping($calculation)
{
$service = "\\App\\Services\\Emisi\\GpcMappingService";
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($calculation->inventory_year);
$this->logMessage('info', "Mapping dari Emisi IPCC ke GPC telah berhasil diproses");
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method save.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function energyGPCCalc($calculation)
{
$service = "\\App\\Services\\Emisi\\EnergyGPCService";
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($calculation->inventory_year);
$this->logMessage('info', "Kalkulasi Emisi Energi GPC telah berhasil diproses");
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method save.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function logMessage($level, $message)
{
$this->line($message); // Output to console
// Log to the file
$formattedMessage = '[' . now() . '] ' . strtoupper($level) . ': ' . $message . PHP_EOL;
if ($this->logFilePath) {
file_put_contents($this->logFilePath, $formattedMessage, FILE_APPEND);
}
$this->info($message);
// Also log to Laravel's default log channel
if ($level === 'error') {
Log::error($message);
}
// } else {
// Log::info($message);
// }
}
}

View File

@ -0,0 +1,214 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Calculation;
use App\Enums\SigdStatus;
use App\Models\ActivityLock;
use App\Models\ReferenceWs;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class EmisiCalculationQueue extends Command
{
protected $signature = 'calculation:process';
protected $description = 'Process for the worksheet emission calculation queue';
private $logFilePath;
public function __construct()
{
parent::__construct();
}
public function handle()
{
set_time_limit(0);
try {
$processing = Calculation::where('calculation_status', SigdStatus::PROSES)->rowActive()->first();
if ($processing) {
return;
}
$calculation = Calculation::where('calculation_status', SigdStatus::PENDING)
->rowActive()->orderBy('created_at', 'asc')->first();
if (!$calculation) {
// $this->logMessage('info', 'Semua kalkulasi emisi telah berhasil diselesaikan.');
return;
}
$calculation->update([
'executed_time' => now(),
'calculation_status' => SigdStatus::PROSES,
]);
$this->createLogFile($calculation);
$this->logMessage('info', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id);
$isLocked = ActivityLock::isLocked($calculation->inventory_year);
if ($isLocked) {
$this->logMessage('warning', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id . ' sedang dikunci dan tidak dapat melakukan kalkulasi.');
$calculation->update([
'finished_time' => now(),
'calculation_status' => SigdStatus::GAGAL,
]);
return;
}
if ($calculation->energy) $this->executeService('energy', $calculation);
if ($calculation->agriculture) $this->executeService('agriculture', $calculation);
if ($calculation->folu) $this->executeService('folu', $calculation);
if ($calculation->waste) $this->executeService('waste', $calculation);
if ($calculation->ippu) $this->executeService('ippu', $calculation);
// Execute Energy GPC emission calculation
$this->energyGPCCalc($calculation);
// Execute mapping IPCC to GPC
$this->gpcMapping($calculation);
$calculation->update([
'finished_time' => now(),
'calculation_status' => SigdStatus::SELESAI,
]);
$this->logMessage('info', 'Kalkulasi Emisi untuk Tahun Inventory: ' . $calculation->inventory_year . ', id: ' . $calculation->id . ' berhasil diselesaikan.');
} catch (Exception $e) {
$this->logMessage('error', 'Terjadi kesalahan saat kalkulasi emisi, id: ' . $calculation->id . '. Error: ' . $e->getMessage());
throw $e;
}
}
private function createLogFile(Calculation $calculation)
{
$logDirectory = storage_path('logs/calculation/');
$this->logMessage('info', 'Checking if log directory exists: ' . $logDirectory);
if (!File::exists($logDirectory)) {
$this->logMessage('info', 'Directory not found. Creating directory: ' . $logDirectory);
File::makeDirectory($logDirectory, 0755, true);
}
$logFileName = $logDirectory . $calculation->inventory_year . '_' . $calculation->id . '.log';
file_put_contents($logFileName, '');
$this->logFilePath = $logFileName;
$this->logMessage('info', 'Log file created: ' . $logFileName);
}
private function executeService($sector, $calculation)
{
// if ($calculation->$sector) {
$wsList = ReferenceWs::where('sector', $sector)
->whereNotNull('code')->rowActive()->get();
foreach ($wsList as $ws) {
if ($ws->code == '4d1_ef') {
continue;
}
$service = "\\App\\Services\\Emisi\\" . class_basename($ws->model) . "Service";
$this->logMessage('service yang dijalankan', "{$service}");
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($ws->code, $calculation->inventory_year);
$this->logMessage('info', "Kalkulasi Emisi pada Worksheet {$ws->ws_code}. {$ws->ws_title} telah berhasil diselesaikan.");
} else {
$this->logMessage('error', "{$service} tidak memiliki method proses kalkulasi.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan {$service} pada sektor {$sector}: " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
// }
}
private function gpcMapping($calculation)
{
$service = "\\App\\Services\\Emisi\\GpcMappingService";
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($calculation->inventory_year);
$this->logMessage('info', "Mapping dari Emisi IPCC ke GPC telah berhasil diproses");
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method save.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function energyGPCCalc($calculation)
{
$service = "\\App\\Services\\Emisi\\EnergyGPCService";
try {
$serviceClass = app($service);
if (method_exists($service, 'save')) {
$serviceClass->save($calculation->inventory_year);
$this->logMessage('info', "Kalkulasi Emisi Energi GPC telah berhasil diproses");
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method save.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$calculation->update([
'executed_time' => null,
'finished_time' => null,
'calculation_status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function logMessage($level, $message)
{
$this->line($message); // Output to console
// Log to the file
$formattedMessage = '[' . now() . '] ' . strtoupper($level) . ': ' . $message . PHP_EOL;
if ($this->logFilePath) {
file_put_contents($this->logFilePath, $formattedMessage, FILE_APPEND);
}
$this->info($message);
// Also log to Laravel's default log channel
if ($level === 'error') {
Log::error($message);
}
// } else {
// Log::info($message);
// }
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Enums\SigdStatus;
use App\Models\ActivityLock;
use App\Models\ActivityProdusenCalculate;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
class ProdusenCalculateQueue extends Command
{
protected $signature = 'produsen_calculate:process';
protected $description = 'Process for calculate data activities from produsen then copy data to konsolidasi activities queue';
private $logFilePath;
public function __construct()
{
parent::__construct();
}
public function handle()
{
set_time_limit(0);
$processing = ActivityProdusenCalculate::where('status', SigdStatus::PROSES)
->rowActive()->first();
if ($processing) {
return;
}
$process = ActivityProdusenCalculate::where('status', SigdStatus::PENDING)
->rowActive()->orderBy('created_at', 'asc')->first();
if (!$process) {
return;
}
$process->update([
'executed_time' => now(),
'status' => SigdStatus::PROSES,
]);
$this->createLogFile($process);
$this->logMessage('info', 'Hitung Data dari Produsen untuk Tahun: ' . $process->inventory_year . ', id: ' . $process->id);
try {
$isLocked = ActivityLock::isLocked($process->inventory_year);
if ($isLocked) {
$this->logMessage('warning', 'Hitung Data dari Produsen untuk Tahun: ' . $process->inventory_year . ', id: ' . $process->id . ' sedang dikunci dan tidak dapat melakukan Hitung Data dari Produsen.');
$process->update([
'finished_time' => now(),
'status' => SigdStatus::GAGAL,
]);
return;
}
$this->executeService($process);
$process->update([
'finished_time' => now(),
'status' => SigdStatus::SELESAI,
]);
$this->logMessage('info', 'Hitung Data dari Produsen untuk Tahun: ' . $process->inventory_year . ', id: ' . $process->id . ' berhasil diselesaikan.');
} catch (\Exception $e) {
$this->logMessage('error', 'Terjadi kesalahan saat proses Hitung Data dari Produsen, id: ' . $process->id . '. Error: ' . $e->getMessage());
throw $e;
}
}
private function createLogFile(ActivityProdusenCalculate $process)
{
$logDirectory = storage_path('logs/produsen_calculate/');
if (!File::exists($logDirectory)) {
File::makeDirectory($logDirectory, 0755, true);
}
$logFileName = $logDirectory . $process->to_year . '_' . $process->from_year . '_' . $process->id . '.log';
file_put_contents($logFileName, '');
$this->logFilePath = $logFileName;
}
private function executeService($process)
{
$service = "\\App\\Services\\Tool\\ProdusenCalculateService";
try {
$serviceClass = app($service);
if (method_exists($serviceClass, 'calculateAndSave')) {
$serviceClass->calculateAndSave($process->inventory_year);
} else {
$this->logMessage('error', get_class($serviceClass) . " tidak memiliki method calculateAndSave.");
}
} catch (\Exception $e) {
$this->logMessage('error', "Error saat menjalankan " . get_class($serviceClass) . ": " . $e->getMessage());
$process->update([
'executed_time' => null,
'finished_time' => null,
'status' => SigdStatus::PENDING,
]);
throw $e;
}
}
private function logMessage($level, $message)
{
$this->line($message); // Output to console
// Log to the file
$formattedMessage = '[' . now() . '] ' . strtoupper($level) . ': ' . $message . PHP_EOL;
if ($this->logFilePath) {
file_put_contents($this->logFilePath, $formattedMessage, FILE_APPEND);
}
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Enums;
enum ActivityType: string
{
case LOGIN = 'login';
case INSERT_ACTIVITY_DATA = 'insert_activity_data';
case UPDATE_ACTIVITY_DATA = 'update_activity_data';
case INSERT_METADATA = 'insert_metadata';
case DELETE_METADATA = 'delete_metadata';
// new activity tipe
case LOCK_ACTIVITY_FORM = 'lock_activity_form';
case UNLOCK_ACTIVITY_FORM = 'unlock_activity_form';
case COPY_ACTIVITY_FORM = 'copy_activity_form';
case CALCULATION_EMISI = 'calculation_emisi';
case PRODUSEN_CALCULATE = 'produsen_calculate';
case APPROVAL_KONSOLIDASI = 'approval_konsolidasi';
case DISSAPPROVAL_KONSOLIDASI = 'dissapproval_konsolidasi';
public function label(): string
{
return match ($this) {
self::LOGIN => 'Login',
self::INSERT_ACTIVITY_DATA => 'Input Data Aktivitas',
self::UPDATE_ACTIVITY_DATA => 'Ubah Data Aktivitas',
self::INSERT_METADATA => 'Input Metadata',
self::DELETE_METADATA => 'Hapus Metadata',
//new case
self::LOCK_ACTIVITY_FORM => 'Kunci Data Aktivitas',
self::UNLOCK_ACTIVITY_FORM => 'Buka Kunci Data Aktivitas',
self::COPY_ACTIVITY_FORM => 'Salin Data Aktivitas',
self::CALCULATION_EMISI => 'Buat Form Kalkulasi Emisi',
self::PRODUSEN_CALCULATE => 'Hitung Data dari Produsen',
self::APPROVAL_KONSOLIDASI => 'Data Aktivitas Produsen telah disetujui',
self::DISSAPPROVAL_KONSOLIDASI => 'Data Aktivitas Produsen batal disetujui',
};
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace App\Enums;
class FruitVegetableCategory
{
const FRUITS = [
'alpukat',
'belimbing',
'duku',
'durian',
'jambu_air',
'jambu_biji',
'jeruk',
'jeruk_besar',
'jeruk_siam',
'mangga',
'manggis',
'markisa',
'nangka',
'pepaya',
'pisang',
'rambutan',
'salak',
'sawo',
'sirsak',
'sukun',
];
const VEGETABLES = [
'bawang_daun',
'bayam',
'cabe_besar',
'cabe_rawit',
'jamur',
'kacang_merah',
'kacang_panjang',
'kangkung',
'ketimun',
'labu_siam',
'lobak',
'melinjo',
'petai',
'sawi',
'terong',
'tomat',
];
public static function all()
{
return array_merge(self::FRUITS, self::VEGETABLES);
}
public static function isFruit($category)
{
return in_array($category, self::FRUITS);
}
public static function isVegetable($category)
{
return in_array($category, self::VEGETABLES);
}
public static function getType($category)
{
if (self::isFruit($category)) {
return 'fruit';
} elseif (self::isVegetable($category)) {
return 'vegetable';
}
return null; // If the category is not found
}
}

View File

@ -0,0 +1,159 @@
<?php
namespace App\Enums;
enum GcomCrfData: string
{
case STATIONARY_ENERGY = 'stationary_energy';
case TRANSPORTATION = 'transportation';
case WASTE = 'waste';
case IPPU = 'ippu';
case AFOLU = 'afolu';
case GRID_SUPPLIED_ENERGY = 'grid_supplied_energy';
public function getData(): array
{
return match ($this) {
self::STATIONARY_ENERGY => [
'Residential buildings' => [
1 => (object)['gpc_code' => 'i_1_1', 'notation_key' => 'NE'],
2 => (object)['gpc_code' => 'i_1_2', 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'i_1_3', 'notation_key' => 'NE'], // DEFAULT
],
'Commercial buildings & facilities' => [
1 => (object)['gpc_code' => ['i_2_1','i_6_1'], 'notation_key' => 'NE'],
2 => (object)['gpc_code' => ['i_2_2','i_6_2'], 'notation_key' => 'NE'],
3 => (object)['gpc_code' => ['i_2_3','i_6_3'], 'notation_key' => 'NE'], // DEFAULT
],
'Institutional buildings & facilities' => [
1 => (object)['gpc_code' => 'ie', 'notation_key' => 'IE'],
2 => (object)['gpc_code' => 'ie', 'notation_key' => 'IE'],
3 => (object)['gpc_code' => 'ie', 'notation_key' => 'IE'],
'info' => 'Included in Commercial Buildings and Facilities'
],
'Industrial buildings & facilities' => [
1 => (object)['gpc_code' => 'i_3_1', 'notation_key' => 'NE'],
2 => (object)['gpc_code' => 'i_3_2', 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'i_3_3', 'notation_key' => 'NE'],
],
'Agriculture' => [
1 => (object)['gpc_code' => 'i_5_1', 'notation_key' => 'NO'],
2 => (object)['gpc_code' => 'i_5_2', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'i_5_3', 'notation_key' => 'NE'], // DEFAULT
],
'Fugitive emissions' => [
1 => (object)['gpc_code' => 'i_8_1', 'notation_key' => 'C'],
3 => (object)['gpc_code' => 'i_7_1', 'notation_key' => 'NO'],
]
],
self::TRANSPORTATION => [
'On-road' => [
1 => (object)['gpc_code' => 'ii_1_1', 'notation_key' => 'NE'],
2 => (object)['gpc_code' => 'ii_1_2', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'ii_1_3', 'notation_key' => 'NE'], // DEFAULT
],
'Rail' => [
1 => (object)['gpc_code' => 'ii_2_1', 'notation_key' => 'IE'],
2 => (object)['gpc_code' => 'ii_2_2', 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'ii_2_3', 'notation_key' => 'NE'], // DEFAULT
],
'Waterborne navigation' => [
1 => (object)['gpc_code' => 'ii_3_1', 'notation_key' => 'IE'],
2 => (object)['gpc_code' => 'ii_3_2', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'ii_3_3', 'notation_key' => 'NE'], // DEFAULT
],
'Aviation' => [
1 => (object)['gpc_code' => 'ii_4_1', 'notation_key' => 'NO'],
2 => (object)['gpc_code' => 'ii_4_2', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'ii_4_3', 'notation_key' => 'NE'], // DEFAULT
],
'Off-road' => [
1 => (object)['gpc_code' => 'ii_5_1', 'notation_key' => 'NO'],
2 => (object)['gpc_code' => 'ii_5_2', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'ii_5_3', 'notation_key' => 'NE'], // DEFAULT
],
],
self::WASTE => [
'Solid waste disposal' => [
1 => (object)['gpc_code' => ['iii_1_1','iii_1_3'], 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'iii_1_3', 'notation_key' => 'NO'],
],
'Biological treatment' => [
1 => (object)['gpc_code' => ['iii_2_1','iii_2_3'], 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'iii_2_3', 'notation_key' => 'NO'],
],
'Incinerated and open burning' => [
1 => (object)['gpc_code' => ['iii_3_1','iii_3_3'], 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'iii_3_3', 'notation_key' => 'NE'],
],
'Wastewater' => [
1 => (object)['gpc_code' => ['iii_4_1','iii_4_3'], 'notation_key' => 'NE'],
3 => (object)['gpc_code' => 'iii_4_3', 'notation_key' => 'NE'],
],
],
self::IPPU => [
'Industrial processes' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'iv_1', 'notation_key' => 'NE'], // DEFAULT
],
'Produce Use' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'iv_2', 'notation_key' => 'NE'], // DEFAULT
],
],
self::AFOLU => [
'Livestock' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'v_1', 'notation_key' => 'NE'], // DEFAULT
],
'Land Use' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'v_2', 'notation_key' => 'NE'], // DEFAULT
],
'Other AFOLU' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'v_3', 'notation_key' => 'NE'], // DEFAULT
],
],
self::GRID_SUPPLIED_ENERGY => [
'Electricity-only generation' => [
1 => (object)['gpc_code' => 'i_4_4', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
],
'CHP generation' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
],
'Heat/cold generation' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
],
'Local renewable generation' => [
1 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
3 => (object)['gpc_code' => 'no', 'notation_key' => 'NO'],
]
],
};
}
public function getLabel(): string
{
return match ($this) {
self::STATIONARY_ENERGY => 'Stationary Energy',
self::TRANSPORTATION => 'Transportation',
self::WASTE => 'Waste',
self::IPPU => 'IPPU',
self::AFOLU => 'AFOLU',
self::GRID_SUPPLIED_ENERGY => 'Generation of grid-supplied energy',
};
}
public static function getAllData(): array
{
$data = [];
foreach (self::cases() as $case) {
$data[$case->getLabel()] = $case->getData();
}
return $data;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Enums;
enum LandCategory: string
{
case FOREST = 'f';
case CROPLAND = 'c';
case GRASSLAND = 'g';
case WETLAND = 'w';
case SETTLEMENT = 's';
case OTHERLAND = 'o';
public static function getName(LandCategory $category): string
{
return match ($category) {
self::FOREST => 'Forest',
self::CROPLAND => 'Cropland',
self::GRASSLAND => 'Grassland',
self::WETLAND => 'Wetland',
self::SETTLEMENT => 'Settlement',
self::OTHERLAND => 'Otherland',
};
}
public static function getSubcategories(LandCategory $category): array
{
return match ($category) {
self::FOREST => ['hp', 'hs', 'hmp', 'hrp', 'ht', 'hms', 'hrs'],
self::CROPLAND => ['pk', 'pt', 'pc', 'sw', 'tr'],
self::GRASSLAND => ['b', 's', 'br'],
self::WETLAND => ['a', 'rw'],
self::SETTLEMENT => ['pm'],
self::OTHERLAND => ['t', 'aw', 'tm', 'bdr', 'tb'],
};
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace App\Enums;
enum LandType: string
{
case HP = 'Hutan Primer';
case HS = 'Hutan Sekunder';
case HMP = 'Hutan Mangrove Primer';
case HRP = 'Hutan Rawa Primer';
case HT = 'Hutan Tanaman';
case HMS = 'Hutan Mangrove Sekunder';
case HRS = 'Hutan Rawa Sekunder';
case PK = 'Perkebunan';
case PT = 'Pertanian Lahan Kering';
case PC = 'Pertanian Lahan Kering Campur';
case SW = 'Sawah';
case TR = 'Transmigrasi';
case B = 'Belukar';
case S = 'Savana/Padang Rumput';
case BR = 'Belukar Rawa';
case A = 'Air';
case RW = 'Rawa';
case PM = 'Pemukiman';
case T = 'Tanah Terbuka';
case AW = 'Awan';
case TM = 'Tambak';
case BDR = 'Bandara/Pelabuhan';
case TB = 'Pertambangan';
public static function getDescription(string $code): string
{
// Loop through the cases and return the description for the matching code
foreach (self::cases() as $case) {
if ($case->name === $code) {
return $case->value; // Return the description
}
}
return '-'; // Return a default value if not found
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Enums;
enum LingkupAksesData: string
{
case ALL = 'all';
case INTERNAL = 'internal';
public function label(): string
{
return match ($this) {
self::ALL => 'Semua Data',
self::INTERNAL => 'Internal Instansi',
};
}
public static function getOptions(): array
{
$options = [];
foreach (self::cases() as $case) {
$options[$case->value] = $case->label();
}
return $options;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Enums;
enum Sector: string
{
case PEMBANGKIT = 'Pembangkit Listrik';
case MANUFAKTUR = 'Industri Manufaktur';
case TRANSPORTASI = 'Transportasi';
case KOMERSIAL = 'Komersial';
case RUMAH_TANGGA = 'Rumah Tangga';
case ENERGI_LAINNYA = 'Lain-lain';
case PLN = 'Penggunaan Listrik PLN';
case AGRICULTURE = 'Pertanian';
case FOLU = 'Lahan';
case WASTE = 'Limbah';
public static function toArray(): array
{
return array_map(function ($case) {
return (object)[
'code' => strtolower(str_replace('_', '', $case->name)),
'name' => $case->value
];
}, self::cases());
}
public static function getName(string $code): ?string
{
foreach (self::cases() as $case) {
if (strtolower(str_replace(' ', '_', $case->name)) === $code) {
return $case->value;
}
}
return null;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Enums;
enum SigdStatus: int
{
case PENDING = 0;
case PROSES = 2;
case SELESAI = 1;
case GAGAL = 4;
// Method to get the badge color
public function badge(): string
{
return match ($this) {
self::PENDING => '<span class="badge badge-warning">PENDING</span>',
self::PROSES => '<span class="badge badge-info">PROSES</span>',
self::SELESAI => '<span class="badge badge-success">SELESAI</span>',
self::GAGAL => '<span class="badge badge-danger">GAGAL</span>',
};
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace App\Enums;
enum TransportationCategory: string
{
case ON_ROAD = 'on_road';
case WATERBORNE = 'waterborne';
case AVIATION = 'aviation';
public function getCategories(): array
{
switch ($this) {
case self::ON_ROAD:
return [
'premium',
'pertalite',
'pertamax',
'pertamax_plus',
'solar',
'biodiesel_biosolar',
'vigas',
'bbg'
];
case self::WATERBORNE:
return [
'minyak_bakar',
'minyak_diesel'
];
case self::AVIATION:
return [
'avgas',
'avtur'
];
default:
return [];
}
}
public static function getTransportationCategories(string $subSector): array
{
return match ($subSector) {
self::ON_ROAD->value => self::ON_ROAD->getCategories(),
self::WATERBORNE->value => self::WATERBORNE->getCategories(),
self::AVIATION->value => self::AVIATION->getCategories(),
default => [],
};
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace App\Enums;
enum WsCategory: string
{
// ENERGY
case pembangkit = '1A1a';
case manufaktur = '1A2';
case transportasi = '1A3';
case komersial = '1A4a';
case rumah_tangga = '1A4b';
case energi_lainnya = '1A5';
// AGRICULTURE
case enteric_fermentation = '3A1';
case manure_mgmt = '3A2a';
case manure_mgmt_direct_n2o = '3A2b';
case manure_mgmt_indirect_n2o = '3C6';
public function label(): string
{
return match ($this) {
self::pembangkit => '1A1a - Main Activity Electricity and Heat Production',
self::manufaktur => '1A2 - Manufacturing Industry and Construction',
self::transportasi => '1A3 - Transport',
self::komersial => '1A4a - Commercial / Institutional',
self::rumah_tangga => '1A5 - Non-specified',
self::enteric_fermentation => '3A1 - Methane Emissions from Enteric Fermentation and Manure Management',
self::manure_mgmt => '3A2a - Manure Management:(CH4) from Manure Management Systems',
self::manure_mgmt_direct_n2o => '3A2b - Manure Management: Direct N2O Emissions from Manure Management Systems',
self::manure_mgmt_indirect_n2o => '3C6 - Indirect N2O Emissions from Manure Management',
};
}
public static function fromName(string $name){
return constant("self::$name");
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Illuminate\Contracts\View\View;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class CrfExport implements FromView, WithStyles
{
protected $sector;
protected $crfData;
protected $worksheets;
public function __construct($sector, $crfData, $worksheets)
{
$this->sector = $sector;
$this->crfData = $crfData;
$this->worksheets = $worksheets;
}
public function view(): View
{
return view('reports.crf.report', [
'sector' => $this->sector,
'crfData' => $this->crfData,
'worksheets' => $this->worksheets,
'isExport' => true
]);
}
public function styles(Worksheet $sheet)
{
// Apply styles to the header rows
$tableStartRow = 6;
$tableHeaderRow = $tableStartRow; // + ($this->wsData->ws_header - 1);
$tableEndRow = $sheet->getHighestRow();
$columnStart = 'A';
$columnEnd = $sheet->getHighestColumn();
$sheet->getStyle('A1:A3')->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_LEFT],
]);
// Apply table header styles
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableHeaderRow)->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
]);
// Apply borders to the entire table
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Set dynamic column styles based on data
foreach ($sheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex();
// Skip the header rows
if ($rowIndex >= $tableStartRow && $rowIndex <= $tableHeaderRow) {
continue;
}
foreach ($row->getCellIterator() as $cell) {
$value = $cell->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
// Check if value is numeric
if (is_numeric($value)) {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
// Apply number formatting
// $cell->setValue($value);
$formatCode = floor($value) != $value ? '#,##0.0#' : '#,##0';
$cell->getStyle()->getNumberFormat()->setFormatCode($formatCode);
} else {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
}
}
}
// Auto-fit columns
foreach (range('A', $sheet->getHighestColumn()) as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
// // Style footer row
// $sheet->getStyle($columnStart . $tableEndRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
// 'font' => ['bold' => true],
// 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
// ]);
return [];
}
}

View File

@ -0,0 +1,192 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class FormExport implements FromCollection, WithTitle, ShouldAutoSize, WithEvents
{
private $data;
private $isTemplate, $titleExcel, $inventoryYear;
private $instansi;
public function __construct($data)
{
$this->data = $data;
$this->isTemplate = $data['isTemplate'];
$this->titleExcel = $data['titleExcel'];
$this->inventoryYear = $data['inventoryYear'];
$this->instansi = $data['instansi'];
}
public function collection()
{
// Fetch necessary data
$data = $this->data;
$formDetails = $data['formDetails'];
$unitsMap = $data['unitsMap'];
$activityFormDetails = $data['activityFormDetails'];
$excelData = collect();
if (!$this->isTemplate) {
// Add title row
$titleRow = [$this->titleExcel];
$excelData->push($titleRow);
$excelData->push(['']);
// Add print date row
$tanggalCetakRow = ['Tanggal Cetak: ' . now()->format('Y-m-d')];
$excelData->push($tanggalCetakRow);
$excelData->push(['']);
}
// Add header row
$header = ['TAHUN'];
foreach ($formDetails as $detail) {
$activityName = $detail->activity ? $detail->activity->name : 'N/A';
$unitCode = $unitsMap[$detail->unit_code]->code ?? '';
$header[] = $activityName . "\n" . '(' . $unitCode . ')';
}
$excelData->push($header);
// Add data rows
$years = activityYearRange($this->inventoryYear);
foreach ($years as $year) {
$row = [$year];
foreach ($formDetails as $detail) {
$activityValue = isset($activityFormDetails[$year])
? $activityFormDetails[$year]
->where('activity_code', $detail->activity_code)
->where('activity_unit_code', $detail->unit_code)
->first()->activity_value ?? ''
: '';
$row[] = $activityValue;
}
$excelData->push($row);
}
return $excelData;
}
public function title(): string
{
return 'Template'; // Sheet name
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
// Set page properties
$event->sheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$event->sheet->getPageSetup()->setFitToWidth(1);
$event->sheet->getPageSetup()->setFitToHeight(0);
$event->sheet->getPageMargins()->setTop(0.5);
$event->sheet->getPageMargins()->setBottom(0.5);
$event->sheet->getPageMargins()->setLeft(0.5);
$event->sheet->getPageMargins()->setRight(0.5);
$event->sheet->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
$event->sheet->getPageSetup()->setHorizontalCentered(true);
$event->sheet->getPageSetup()->setVerticalCentered(true);
if (!$this->isTemplate) {
// Merge cells for title and print date
// $event->sheet->mergeCells('A1:' . $event->sheet->getHighestColumn() . '1');
// $event->sheet->mergeCells('A3:' . $event->sheet->getHighestColumn() . '3');
$event->sheet->mergeCells('A1:' . 'S1');
$event->sheet->mergeCells('A3:' . 'S3');
}
// Set alignment and make header row bold and centered
$headerRow = $this->isTemplate == 1 ? 'A1' : 'A5';
$valueRow = $this->isTemplate == 1 ? 1 : 5;
$event->sheet->getStyle($headerRow . ':' . $event->sheet->getHighestColumn() . $valueRow)
->applyFromArray([
'font' => [
'bold' => true,
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
'wrapText' => true, // Ensure wrap text is enabled for newlines
],
]);
// Apply borders to the table
$event->sheet->getDelegate()->getStyle($headerRow . ':' . $event->sheet->getDelegate()->getHighestColumn() . $event->sheet->getDelegate()->getHighestRow())
->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Auto size columns starting from A onwards
$highestColumn = $event->sheet->getDelegate()->getHighestColumn();
$columns = $this->generateColumnsRange('A', $highestColumn);
$valueRow = $this->isTemplate == 1 ? '2' : '6';
foreach ($columns as $column) {
$event->sheet->getDelegate()->getColumnDimension($column)->setAutoSize(true);
// Apply number format to data columns (B onwards)
if ($column != 'A') {
$highestRow = $event->sheet->getDelegate()->getHighestRow($column);
for ($row = $valueRow; $row <= $highestRow; $row++) {
$cellValue = $event->sheet->getCell($column . $row)->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
if (!$this->isTemplate) {
if (is_numeric($cellValue)) {
$formatCode = floor($cellValue) != $cellValue ? '#,##0.0###############' : '#,##0';
}
}
$event->sheet->getStyle($column . $row)->getNumberFormat()->setFormatCode($formatCode);
}
if ($this->isTemplate) {
$event->sheet->getStyle($column . '2:' . $column . $event->sheet->getDelegate()->getHighestRow())
->applyFromArray([
'fill' => [
'fillType' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFFFFF00'],
],
]);
}
}
}
},
];
}
function generateColumnsRange($start, $end)
{
$columns = [];
$current = $start;
while ($current !== $end) {
$columns[] = $current;
$current++;
}
$columns[] = $end;
return $columns;
}
}

View File

@ -0,0 +1,188 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class FormKehutananExport implements FromCollection, WithTitle, ShouldAutoSize, WithEvents
{
private $data;
private $isTemplate, $titleExcel, $inventoryYear;
public function __construct($data)
{
$this->data = $data;
$this->isTemplate = $data['isTemplate'];
$this->titleExcel = $data['titleExcel'];
$this->inventoryYear = $data['inventoryYear'];
}
public function collection()
{
// Fetch necessary data
$data = $this->data;
$lands = $data['lands'];
// $unitsMap = $data['unitsMap'];
$activityFormDetails = $data['activityFormDetails'];
$excelData = collect();
if (!$this->isTemplate) {
// Add title row
$titleRow = [$this->titleExcel];
$excelData->push($titleRow);
$excelData->push(['']);
// Add print date row
$tanggalCetakRow = ['Tanggal Cetak: ' . now()->format('Y-m-d')];
$excelData->push($tanggalCetakRow);
$excelData->push(['']);
$excelData->push([$data['inventoryYear'] - 1]);
}
// Add header row
$header = $this->isTemplate ? [''] : [$data['inventoryYear'] - 2];
foreach ($lands as $land) {
$header[] = $land;
}
$excelData->push($header);
// Add data rows
foreach ($lands as $land1) {
$row = [$land1];
foreach ($lands as $land2) {
$activityValue = isset($activityFormDetails)
? optional(
$activityFormDetails
->where('activity_code', strtolower($land1 . '_' . $land2))
->first(),
)->activity_value
: '';
$row[] = $activityValue;
}
$excelData->push($row);
}
return $excelData;
}
public function title(): string
{
return 'Template'; // Sheet name
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
// Set page properties
$event->sheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$event->sheet->getPageSetup()->setFitToWidth(1);
$event->sheet->getPageSetup()->setFitToHeight(0);
$event->sheet->getPageMargins()->setTop(0.5);
$event->sheet->getPageMargins()->setBottom(0.5);
$event->sheet->getPageMargins()->setLeft(0.5);
$event->sheet->getPageMargins()->setRight(0.5);
$event->sheet->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
$event->sheet->getPageSetup()->setHorizontalCentered(true);
$event->sheet->getPageSetup()->setVerticalCentered(true);
if (!$this->isTemplate) {
// Merge cells for title and print date
$event->sheet->mergeCells('A1:' . $event->sheet->getHighestColumn() . '1');
$event->sheet->mergeCells('A3:' . $event->sheet->getHighestColumn() . '3');
$event->sheet->mergeCells('A5:' . $event->sheet->getHighestColumn() . '5');
// Set A5 center and bold
$event->sheet->getStyle('A5')->applyFromArray([
'font' => [
'bold' => true,
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
],
]);
}
// Set alignment and make header row bold and centered
$headerRow = $this->isTemplate == 1 ? 'A1' : 'A5';
$valueRow = $this->isTemplate == 1 ? 1 : 6;
$event->sheet->getStyle($headerRow . ':' . $event->sheet->getHighestColumn() . $valueRow)
->applyFromArray([
'font' => [
'bold' => true,
],
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
'vertical' => Alignment::VERTICAL_CENTER,
'wrapText' => true, // Ensure wrap text is enabled for newlines
],
]);
// Apply borders to the table
$event->sheet->getDelegate()->getStyle($headerRow . ':' . $event->sheet->getDelegate()->getHighestColumn() . $event->sheet->getDelegate()->getHighestRow())
->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Auto size columns starting from A onwards
foreach (range('A', $event->sheet->getDelegate()->getHighestColumn()) as $column) {
$event->sheet->getDelegate()->getColumnDimension($column)->setAutoSize(true);
}
// Apply number format to data columns (B onwards)
$dataColumns = range('B', $event->sheet->getDelegate()->getHighestColumn());
$valueRow = $this->isTemplate == 1 ? '2' : '7';
foreach ($dataColumns as $column) {
$highestRow = $event->sheet->getDelegate()->getHighestRow($column);
for ($row = $valueRow; $row <= $highestRow; $row++) {
$cellValue = $event->sheet->getCell($column . $row)->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
if (!$this->isTemplate) {
if (is_numeric($cellValue)) {
$formatCode = floor($cellValue) != $cellValue ? '#,##0.0###############' : '#,##0';
}
}
$event->sheet->getStyle($column . $row)->getNumberFormat()->setFormatCode($formatCode);
}
}
$event->sheet->getStyle('A' . $valueRow . ':A' . $event->sheet->getDelegate()->getHighestRow())
->applyFromArray([
'font' => [
'bold' => true,
],
]);
if ($this->isTemplate) {
foreach ($dataColumns as $column) {
$event->sheet->getStyle($column . '2:' . $column . $event->sheet->getDelegate()->getHighestRow())
->applyFromArray([
'fill' => [
'fillType' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFFFFF00'],
],
]);
}
}
},
];
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Illuminate\Contracts\View\View;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class GcomCrfExport implements FromView, WithStyles
{
protected $inventoryYear, $activityYear, $gpcData, $gpc;
public function __construct($inventoryYear, $activityYear, $gpcData, $gpc)
{
$this->inventoryYear = $inventoryYear;
$this->activityYear = $activityYear;
$this->gpcData = $gpcData;
$this->gpc = $gpc;
}
public function view(): View
{
return view('reports.gcom-crf.report', [
'inventoryYear' => $this->inventoryYear,
'activityYear' => $this->activityYear,
'gpcData' => $this->gpcData,
'gpc' => $this->gpc,
'isExport' => true
]);
}
public function styles(Worksheet $sheet)
{
$tableStartRow = 6;
$tableHeaderRow = $tableStartRow + 2;
$tableEndRow = $sheet->getHighestRow();
$columnStart = 'A';
$columnEnd = $sheet->getHighestColumn();
$sheet->getStyle('A1:A3')->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_LEFT],
]);
$sheet->mergeCells('A1:' . $columnEnd . '1');
$sheet->mergeCells('A2:' . $columnEnd . '2');
$sheet->mergeCells('A3:' . $columnEnd . '3');
// Apply table header styles
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableHeaderRow)->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
]);
// Apply borders to the entire table
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Set dynamic column styles based on data
foreach ($sheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex();
// Skip the header rows
if ($rowIndex >= $tableStartRow && $rowIndex <= $tableHeaderRow) {
continue;
}
foreach ($row->getCellIterator() as $cell) {
$value = $cell->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
if (is_numeric($value)) {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
$formatCode = floor($value) != $value ? '#,##0.0#' : '#,##0';
$cell->getStyle()->getNumberFormat()->setFormatCode($formatCode);
} else {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
}
}
}
// Auto-fit columns
foreach (range('A', $sheet->getHighestColumn()) as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
// // Style footer row
// $sheet->getStyle($columnStart . $tableEndRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
// 'font' => ['bold' => true],
// 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
// ]);
return [];
}
}

View File

@ -0,0 +1,119 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Illuminate\Contracts\View\View;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class GpcOutputExport implements FromView, WithStyles
{
protected $inventoryYear, $gpcOutputs, $gpcOutputRList;
public function __construct($inventoryYear, $gpcOutputs, $gpcOutputRList)
{
$this->inventoryYear = $inventoryYear;
$this->gpcOutputs = $gpcOutputs;
$this->gpcOutputRList = $gpcOutputRList;
}
public function view(): View
{
return view('reports.gpc-output.report', [
'inventoryYear' => $this->inventoryYear,
'gpcOutputs' => $this->gpcOutputs,
'gpcOutputRList' => $this->gpcOutputRList,
'isExport' => true
]);
}
public function styles(Worksheet $sheet)
{
$tableStartRow = 6;
$tableHeaderRow = $tableStartRow;
$tableEndRow = $sheet->getHighestRow();
$columnStart = 'A';
$columnEnd = $sheet->getHighestColumn();
$sheet->getStyle('A1:A3')->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_LEFT],
]);
$sheet->mergeCells('A1:' . $columnEnd . '1');
$sheet->mergeCells('A2:' . $columnEnd . '2');
$sheet->mergeCells('A3:' . $columnEnd . '3');
// Apply table header styles
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableHeaderRow)->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
]);
// Apply borders to the entire table
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Set dynamic column styles based on data
foreach ($sheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex();
// Skip the header rows
if ($rowIndex >= $tableStartRow && $rowIndex <= $tableHeaderRow) {
continue;
}
foreach ($row->getCellIterator() as $cell) {
$value = $cell->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
if (is_numeric($value)) {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
$formatCode = floor($value) != $value ? '#,##0.0#' : '#,##0';
$cell->getStyle()->getNumberFormat()->setFormatCode($formatCode);
} else {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
}
}
}
// Auto-fit columns
$highestColumn = $sheet->getHighestColumn();
$columns = $this->generateColumnsRange('A', $highestColumn);
foreach ($columns as $column) {
$sheet->getColumnDimension($column)->setAutoSize(true);
}
// // Style footer row
// $sheet->getStyle($columnStart . $tableEndRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
// 'font' => ['bold' => true],
// 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT],
// ]);
return [];
}
function generateColumnsRange($start, $end)
{
$columns = [];
$current = $start;
while ($current !== $end) {
$columns[] = $current;
$current++;
}
$columns[] = $end;
return $columns;
}
}

View File

@ -0,0 +1,105 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Illuminate\Contracts\View\View;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class WorksheetExport implements FromView, WithStyles
{
protected $wsData, $emisiData;
public function __construct($wsData, $emisiData)
{
$this->wsData = $wsData;
$this->emisiData = $emisiData;
}
public function view(): View
{
return view('reports.worksheet.report', [
'wsData' => $this->wsData,
'emisiData' => $this->emisiData,
'isExport' => true
]);
}
public function styles(Worksheet $sheet)
{
// Apply styles to the header rows
$tableStartRow = 6;
$tableHeaderRow = $tableStartRow + ($this->wsData->ws_header - 1);
$tableEndRow = $sheet->getHighestRow();
$columnStart = 'A';
$columnEnd = $sheet->getHighestColumn();
$sheet->getStyle('A1:A3')->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_LEFT],
]);
$sheet->mergeCells('A1:' . $columnEnd . '1');
$sheet->mergeCells('A2:' . $columnEnd . '2');
$sheet->mergeCells('A3:' . $columnEnd . '3');
// Apply table header styles
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableHeaderRow)->applyFromArray([
'font' => ['bold' => true],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
]);
// Apply borders to the entire table
$sheet->getStyle($columnStart . $tableStartRow . ':' . $columnEnd . $tableEndRow)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['argb' => 'FF000000'],
],
],
]);
// Set dynamic column styles based on data
foreach ($sheet->getRowIterator() as $row) {
$rowIndex = $row->getRowIndex();
// Skip the header rows
if ($rowIndex >= $tableStartRow && $rowIndex <= $tableHeaderRow) {
continue;
}
foreach ($row->getCellIterator() as $cell) {
$value = $cell->getValue();
$formatCode = NumberFormat::FORMAT_GENERAL;
// Check if value is numeric
if (is_numeric($value)) {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
// Apply number formatting
// $cell->setValue($value);
$formatCode = floor($value) != $value ? '#,##0.0###' : '#,##0';
$cell->getStyle()->getNumberFormat()->setFormatCode($formatCode);
} else {
$cell->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
}
}
}
// Style footer row
// $footerRowStyle = $sheet->getStyle($columnStart . $tableEndRow . ':' . $columnEnd . $tableEndRow);
// $footerRowStyle->applyFromArray([
// 'font' => ['bold' => true],
// ]);
// $sheet->getStyle($columnStart . $tableEndRow)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
// Auto-fit columns
foreach (range('A', $sheet->getHighestColumn()) as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
return [];
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Helpers;
use Exception;
use Throwable;
class FormulaEvaluator
{
/**
* Evaluate a mathematical formula string and return the result as float.
* Only supports numbers, + - * / ( ) . and scientific notation.
*
* @param string $formula
* @param array $vars (unused, for interface compatibility)
* @return float
* @throws \Exception
*/
public function evaluate(string $formula, array $vars = []): float
{
// Bersihkan spasi
$formula = trim($formula);
// Validasi karakter yang diperbolehkan
if (!preg_match('/^[0-9\.\+\-\*\/eE\(\)\s]+$/', $formula)) {
throw new \Exception('Invalid characters in formula: ' . $formula);
}
// Cek kurung buka/tutup
if (substr_count($formula, '(') !== substr_count($formula, ')')) {
throw new \Exception('Kurung buka/tutup pada formula tidak seimbang: ' . $formula);
}
// Ganti double minus (contoh: 4--3 jadi 4+3)
$formula = preg_replace('/--/', '+', $formula);
// Ganti +- jadi -
$formula = preg_replace('/\+\-/', '-', $formula);
set_error_handler(function ($errno, $errstr) {
throw new \Exception("Error evaluating formula: $errstr");
});
try {
$result = eval("return ($formula);");
} finally {
restore_error_handler();
}
if (!is_numeric($result)) {
throw new \Exception('Formula could not be evaluated: ' . $formula);
}
return (float)$result;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Helpers;
class FormulaHelper
{
public static function calculateFormula($formula, $values)
{
if (! $formula) {
return null;
}
// 1) trim off any leading '=' and whitespace
$parsed = trim($formula);
$parsed = ltrim($parsed, '=');
// 2) normalize multiplication symbols to '*'
// covers lowercase x, uppercase X, and the unicode ×
$parsed = str_ireplace(['x', 'X', '×'], '*', $parsed);
// 3) replace variables like BD1, EF1 with their numeric values
$parsed = preg_replace_callback(
'/\b([A-Z]{2}\d+)\b/',
function ($matches) use ($values) {
$key = strtoupper($matches[1]);
return (isset($values[$key]) && is_numeric($values[$key]))
? $values[$key]
: 0;
},
$parsed
);
// 4) ensure only digits, operators, dots, parentheses and spaces remain
if (! preg_match('/^[0-9\+\-\*\/\.\(\) ]+$/', $parsed)) {
return null;
}
try {
// 5) evaluate the expression
return eval("return {$parsed};");
} catch (\Throwable $e) {
return null;
}
}
}

View File

@ -243,7 +243,7 @@ if (!function_exists('renderMenu')) {
$link2 = count($child3) > 0 ? '' : '';
if ($access2) {
$active2 = activeMenuClass($p2->module) ? 'mm-active' : '';
$html .= '<li class=" nav-item ' . $ch2 . '"><a '.$collapse2.' class=" '.$active2.'" href="' . url($p2->url) . '"><i class="' . $p2->menu_icons . ' icon nav-icon"></i> <span>' . @$p2->title.'<span>';
$html .= '<li class=" nav-item ' . $ch2 . ' '.$active2.'"><a '.$collapse2.' class=" '.$active2.'" href="' . url($p2->url) . '"><i class="' . $p2->menu_icons . ' icon nav-icon"></i> <span>' . @$p2->title.'<span>';
if (count($child3) > 0) {
$html .= '<span class="menu-arrow"></span>';
$html .= '</a>';

View File

@ -0,0 +1,388 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Http\Controllers\Controller;
use App\Models\Adaptation;
use Illuminate\Http\Request;
use App\Models\KegiatanAdaptasi;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use Barryvdh\DomPDF\Facade\Pdf;
class FormAdaptasiController extends Controller
{
public function thankYou(string $id)
{
$user = Auth::user();
$km = KegiatanAdaptasi::findOrFail($id);
$data = [
'oleh' => $user ? $user->name : 'Guest',
'waktu' => $km->created_at->translatedFormat('l, d F Y, H:i'),
'nama' => $km->nama_kegiatan,
'tahun' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'subsektor' => $km->sub_sektor,
'target' => $km->target,
'satuan' => $km->satuan,
'penurunan' => $km->emission_factor,
];
return view('form.index-adaptasi-thankyou', compact('data', 'km'));
}
public function downloadPDF(string $id)
{
$user = Auth::user();
$km = KegiatanAdaptasi::findOrFail($id);
$data = [
'oleh' => $user ? $user->name : 'Guest',
'waktu' => $km->created_at->translatedFormat('l, d F Y, H:i'),
'nama' => $km->nama_kegiatan,
'tahun' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'subsektor' => $km->sub_sektor,
'target' => $km->target,
'satuan' => $km->satuan,
'penurunan' => $km->emission_factor,
];
$pdf = PDF::loadView('form.index-adaptasi.pdf', compact('data'))
->setPaper('a4', 'portrait');
return $pdf->download('bukti-submission-'.$km->nama_kegiatan.'.pdf');
}
public function view(string $id)
{
$ka = KegiatanAdaptasi::findOrFail($id);
$sessionData = [
'adaptation_id' => $ka->adaptation_id,
'nama_kegiatan' => $ka->nama_kegiatan,
'tahun_kegiatan' => $ka->tahun_kegiatan,
'sektor' => $ka->sektor,
'sub_sektor' => $ka->sub_sektor,
'kategori_aksi' => $ka->kategori_aksi,
// 'jenis_aksi' => $ka->jenis_aksi,
// 'aksi' => $ka->aksi,
'pelaksana_kegiatan' => $ka->pelaksana_kegiatan,
'lokasi_kegiatan' => $ka->lokasi_kegiatan,
'waktu_kegiatan' => $ka->waktu_kegiatan,
'dokumen' => $ka->dokumen,
'alokasi_apbn' => $ka->alokasi_apbn,
'alokasi_apbd' => $ka->alokasi_apbd,
'alokasi_swasta' => $ka->alokasi_swasta,
'alokasi_sumber_dana_lain' => $ka->alokasi_sumber_dana_lain,
'realisasi_apbn' => $ka->realisasi_apbn,
'realisasi_apbd' => $ka->realisasi_apbd,
'realisasi_swasta' => $ka->realisasi_swasta,
'realisasi_sumber_dana_lain' => $ka->realisasi_sumber_dana_lain,
'detail_kegiatan' => $ka->detail_kegiatan,
];
return view('form.index-adaptasi-view', [
'sessionData' => $sessionData,
'id' => $id,
]);
}
public function edit(string $id, Request $request)
{
$ka = KegiatanAdaptasi::findOrFail($id);
$sessionData = [
'adaptation_id' => $ka->adaptation_id,
'nama_kegiatan' => $ka->nama_kegiatan,
'tahun_kegiatan' => $ka->tahun_kegiatan,
'sektor' => $ka->sektor,
'sub_sektor' => $ka->sub_sektor,
'kategori_aksi' => $ka->kategori_aksi,
// 'jenis_aksi' => $ka->jenis_aksi,
// 'aksi' => $ka->aksi,
'pelaksana_kegiatan' => $ka->pelaksana_kegiatan,
'lokasi_kegiatan' => $ka->lokasi_kegiatan,
'waktu_kegiatan' => $ka->waktu_kegiatan,
'dokumen' => $ka->dokumen,
'alokasi_apbn' => $ka->alokasi_apbn,
'alokasi_apbd' => $ka->alokasi_apbd,
'alokasi_swasta' => $ka->alokasi_swasta,
'alokasi_sumber_dana_lain' => $ka->alokasi_sumber_dana_lain,
'realisasi_apbn' => $ka->realisasi_apbn,
'realisasi_apbd' => $ka->realisasi_apbd,
'realisasi_swasta' => $ka->realisasi_swasta,
'realisasi_sumber_dana_lain' => $ka->realisasi_sumber_dana_lain,
'detail_kegiatan' => $ka->detail_kegiatan,
];
$request->session()->put('kegiatan_adaptasi', $sessionData);
$startYear = 200;
$currentYear = now()->year;
$years = range($startYear, $currentYear);
rsort($years);
$sectors = KegiatanAdaptasi::distinct()->pluck('sektor')->toArray();
return view('form.index-adaptasi-edit', [
'sessionData' => $sessionData,
'years' => $years,
'currentYear' => $currentYear,
'sectors' => $sectors,
'adaptation' => $ka,
'readonly' => false
]);
}
public function create(Request $request)
{
if ($request->has('reset')) {
$request->session()->forget('kegiatan_adaptasi');
}
$sessionData = $request->session()->get('kegiatan_adaptasi', []);
$startYear = 2000;
$currentYear = date('Y');
$years = range($startYear, $currentYear);
rsort($years);
return view('form.index-adaptasi', compact('sessionData', 'years', 'currentYear'));
}
public function update(Request $request, $id)
{
$kegiatanAdaptasi = KegiatanAdaptasi::findOrFail($id);
$sessionData = $request->session()->get('kegiatan_adaptasi');
if (empty($sessionData)) {
return response()->json([
'success' => false,
'message' => 'Data tidak lengkap, silakan lengkapi semua bagian.'
]);
}
try {
DB::transaction(function() use ($sessionData, $request, $kegiatanAdaptasi) {
$kegiatanAdaptasi->update([
'adaptation_id' => $sessionData['adaptation_id'] ?? null,
'nama_kegiatan' => $sessionData['nama_kegiatan'] ?? null,
'tahun_kegiatan' => $sessionData['tahun_kegiatan'] ?? null,
'sektor' => $sessionData['sektor'] ?? null,
'sub_sektor' => $sessionData['sub_sektor'] ?? null,
'kategori_aksi' => $sessionData['kategori_aksi'] ?? null,
// 'jenis_aksi' => $sessionData['jenis_aksi'] ?? null,
// 'aksi' => $sessionData['aksi'] ?? null,
'pelaksana_kegiatan' => $sessionData['pelaksana_kegiatan'] ?? null,
'lokasi_kegiatan' => $sessionData['lokasi_kegiatan'] ?? null,
'waktu_kegiatan' => $sessionData['waktu_kegiatan'] ?? null,
'dokumen' => $sessionData['dokumen'] ?? null,
'alokasi_apbn' => $sessionData['alokasi_apbn'] ?? null,
'alokasi_apbd' => $sessionData['alokasi_apbd'] ?? null,
'alokasi_swasta' => $sessionData['alokasi_swasta'] ?? null,
'alokasi_sumber_dana_lain' => $sessionData['alokasi_sumber_dana_lain'] ?? null,
'realisasi_apbn' => $sessionData['realisasi_apbn'] ?? null,
'realisasi_apbd' => $sessionData['realisasi_apbd'] ?? null,
'realisasi_swasta' => $sessionData['realisasi_swasta'] ?? null,
'realisasi_sumber_dana_lain' => $sessionData['realisasi_sumber_dana_lain'] ?? null,
'detail_kegiatan' => $request['detail_kegiatan'] ?? $sessionData['detail_kegiatan'],
'updated_by' => auth()->check() ? auth()->user()->name : null,
]);
$request->session()->forget('kegiatan_adaptasi');
});
return response()->json([
'success' => true,
'redirect' => route('formAdaptasi.thankYou', $id),
]);
} catch(\Exception $e) {
Log::error('Error updating data: ' . $e->getMessage());
return back()->with('error', 'Gagal mengupdate data. Silakan coba lagi.');
}
}
public function storePart1(Request $request)
{
$validated = $request->validate([
'nama_kegiatan' => 'required|string',
'tahun_kegiatan' => 'required|integer|min:2000|max:' . date('Y'),
'sektor' => 'required|string',
'sub_sektor' => 'required|string',
'kategori_aksi' => 'required|string',
// 'jenis_aksi' => 'required|string',
// 'aksi' => 'required|string',
'pelaksana_kegiatan' => 'nullable|string',
'lokasi_kegiatan' => 'nullable|string',
'waktu_kegiatan' => 'nullable|string',
'dokumen' => 'nullable|string',
'adaptation_id' => 'required|string'
]);
$sessionData = $request->session()->get('kegiatan_adaptasi');
$sessionArray = is_object($sessionData) ? $sessionData->toArray() : (array) $sessionData;
$mergedData = array_merge($sessionArray, $validated);
$request->session()->put('kegiatan_adaptasi', $mergedData);
return response()->json(['success' => true]);
}
public function storePart2(Request $request)
{
$validated = $request->validate([
'alokasi_apbn' => 'nullable|string',
'alokasi_apbd' => 'nullable|string',
'alokasi_swasta' => 'nullable|string',
'alokasi_sumber_dana_lain' => 'nullable|string',
'realisasi_apbn' => 'nullable|string',
'realisasi_apbd' => 'nullable|string',
'realisasi_swasta' => 'nullable|string',
'realisasi_sumber_dana_lain' => 'nullable|string'
]);
$sessionData = $request->session()->get('kegiatan_adaptasi');
if(!$sessionData) {
return response()->json(['success' => false, 'message' => 'Silakan lengkapi bagian Informasi Umum terlebih dahulu']);
}
$updatedData = array_merge($sessionData, $validated);
$request->session()->put('kegiatan_adaptasi', $updatedData);
return response()->json(['success' => true]);
}
public function storeFinal(Request $request)
{
$sessionData = $request->session()->get('kegiatan_adaptasi');
if (empty($sessionData)) {
return response()->json([
'success' => false,
'message' => 'Silakan lengkapi semua bagian terlebih dahulu'
]);
}
try {
$adaptasiId = Str::uuid()->toString();
DB::transaction(function() use ($sessionData, $request, $adaptasiId) {
// 1⃣ Create master record
KegiatanAdaptasi::create([
'id' => $adaptasiId,
'adaptation_id' => $sessionData['adaptation_id'] ?? null,
'nama_kegiatan' => $sessionData['nama_kegiatan'] ?? null,
'tahun_kegiatan' => $sessionData['tahun_kegiatan'] ?? null,
'sektor' => $sessionData['sektor'] ?? null,
'sub_sektor' => $sessionData['sub_sektor'] ?? null,
'kategori_aksi' => $sessionData['kategori_aksi'] ?? null,
// 'jenis_aksi' => $sessionData['jenis_aksi'] ?? null,
// 'aksi' => $sessionData['aksi'] ?? null,
'pelaksana_kegiatan' => $sessionData['pelaksana_kegiatan'] ?? null,
'lokasi_kegiatan' => $sessionData['lokasi_kegiatan'] ?? null,
'waktu_kegiatan' => $sessionData['waktu_kegiatan'] ?? null,
'dokumen' => $sessionData['dokumen'] ?? null,
'alokasi_apbn' => $sessionData['alokasi_apbn'] ?? null,
'alokasi_apbd' => $sessionData['alokasi_apbd'] ?? null,
'alokasi_swasta' => $sessionData['alokasi_swasta'] ?? null,
'alokasi_sumber_dana_lain' => $sessionData['alokasi_sumber_dana_lain'] ?? null,
'realisasi_apbn' => $sessionData['realisasi_apbn'] ?? null,
'realisasi_apbd' => $sessionData['realisasi_apbd'] ?? null,
'realisasi_swasta' => $sessionData['realisasi_swasta'] ?? null,
'realisasi_sumber_dana_lain' => $sessionData['realisasi_sumber_dana_lain'] ?? null,
'detail_kegiatan' => $sessionData['detail_kegiatan'] ?? $request->input('detail_kegiatan'),
'created_by' => auth()->check() ? auth()->user()->name : null,
]);
// bersihkan session setelah sukses
$request->session()->forget('kegiatan_adaptasi');
});
return response()->json([
'success' => true,
'redirect' => route('formAdaptasi.thankYou', $adaptasiId),
]);
} catch (\Exception $e) {
Log::error('Error storing final data: ' . $e->getMessage());
return back()->with('error', 'Gagal menyimpan data. Silakan coba lagi.');
}
}
public function getSectors()
{
$query = Adaptation::select('sector')
->where('is_active', true)
->distinct();
$result = $query->pluck('sector');
return response()->json($result);
}
public function getSubSectors(Request $request)
{
$param = $request->input('sector');
$query = Adaptation::select('sub_sector')
->where('sector', $param)
->where('is_active', true)
->distinct();
$result = $query->pluck('sub_sector');
return response()->json($result);
}
public function getKategoriAksi(Request $request)
{
$param = $request->input('sub_sector');
$param2 = $request->input('sector');
$query = Adaptation::select('id','kategori_aksi')
->where('sub_sector', $param)
->where('sector', $param2)
->where('is_active', true)
->distinct()
->get();
// kirim langsung object, jangan pluck
return response()->json($query);
}
public function getJenisAksi(Request $request)
{
$param = $request->input('sub_sector');
$param2 = $request->input('sector');
$param3 = $request->input('kategori');
$query = Adaptation::select('jenis_aksi')
->where('sub_sector', $param)
->where('sector', $param2)
->where('kategori_aksi', $param3)
->where('is_active', true)
->distinct()->get();
$result = $query->pluck('jenis_aksi');
return response()->json($result);
}
public function getAksi(Request $request)
{
$param = $request->input('sub_sector');
$param2 = $request->input('sector');
$param3 = $request->input('kategori');
$param4 = $request->input('jenis');
$query = Adaptation::select('id', 'aksi')
->where('sub_sector', $param)
->where('sector', $param2)
->where('kategori_aksi', $param3)
->where('jenis_aksi', $param4)
->where('is_active', true)
->distinct('aksi')->get();
return response()->json($query);
}
}

View File

@ -0,0 +1,311 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Enums\ActivityType;
use App\Enums\LingkupAksesData;
use App\Exports\FormExport;
use App\Http\Controllers\Controller;
use App\Imports\FormImport;
use App\Models\ActivityApprovalKonsolidasi;
use App\Models\ActivityForm;
use App\Models\ActivityLock;
use App\Models\Agency;
use App\Models\LogUserActivity;
use App\Models\ReferenceUnit;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use Illuminate\Http\Request;
use App\Services\Activity\FormService;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
class FormController implements HasMiddleware
{
protected $formService;
public function __construct(FormService $formService)
{
$this->formService = $formService;
}
public static function middleware(): array
{
$sector = request()->route('sector');
$code = request()->route('code');
return [
// //new Middleware('permission:/' . $sector . '/' . $code, except: ['getUserActivities']),
];
}
public function data($sector, $code, $inventoryYear, $instansi = null)
{
// Fetch the form from the database based on sector and code
$form = SettingForm::rowActive()->where('sector', $sector)->where('code', $code)->first();
if (!$form) {
abort(404, 'Page not found');
}
// Fetch form details
$formDetails = SettingFormDetail::rowActive()->where('form_code', $code)->orderByRowNum()->get();
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
}
// get Agencies for produsen data mapping
$user = Auth::user();
$scope = $user->getScope();
if ($scope === LingkupAksesData::INTERNAL->value) {
$instansi = $user->agency_id;
}
$agencies = Agency::whereHas('agencyActivity', function ($query) use ($sector, $code, $scope, $user) {
$query->where('form_sector', $sector)
->where('form_code', $code);
if ($scope === LingkupAksesData::INTERNAL->value) {
$query->where('agency_id', $user->agency_id);
}
})->get();
// Fetch activity form and activity form details using service
$activityForm = $this->formService->getActivityForm($sector, $code, $inventoryYear, $instansi);
if ($instansi == 'all') {
$activityFormId = $activityForm->pluck('id')->toArray();
} else {
$activityFormId = $activityForm->id ?? null;
}
$activityFormDetails = $this->formService->getActivityFormDetails($activityFormId, $instansi);
// Fetch all units & set the mappings
$allUnits = ReferenceUnit::rowActive()->get();
$unitsMap = $allUnits->keyBy('code');
$unitsByCategory = $allUnits->groupBy('category');
// For Copy data feature
// $availableYears = ActivityForm::select('inventory_year')->distinct()
// ->where('sector', $sector)->where('form_code', $code)->rowActive()
// ->orderBy('inventory_year', 'desc')->get()->pluck('inventory_year')->toArray();
$isLocked = ActivityLock::isLocked($inventoryYear);
$isApprove = false;
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$isApprove = ActivityApprovalKonsolidasi::isApprove($activityFormId, $sector, $code, $inventoryYear, $instansi);
}
$internal = $instansi;
return compact(
'form',
'formDetails',
'activityForm',
'activityFormDetails',
'unitsMap',
'unitsByCategory',
'inventoryYear',
'isLocked',
'agencies',
'internal',
'isApprove'
);
}
public function show($sector, $code)
{
// Filter by Year
$inventoryYear = request('inventoryYear') ?? date('Y');
$instansi = request('instansi') ?? null;
// Retrieve data
$data = $this->data($sector, $code, $inventoryYear, $instansi);
return view('form.index', $data);
}
public function save(Request $request, $sector, $code)
{
$request->validate([
'data' => 'required|array',
]);
// Filter by Year
$inventoryYear = $request->input('inventoryYear') ?? date('Y');
$instansi = request('instansi') ?? null;
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
} else {
$instansi = null;
}
$data = $request->input('data');
$unitCodes = $request->input('unit_code');
try {
$this->formService->save($sector, $code, $inventoryYear, $data, $unitCodes, $instansi);
return redirect()->back()->with('success', 'Data berhasil disimpan.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data gagal disimpan. Mohon dicoba kembali.' . $e->getMessage()]);
}
}
public function convertUnit(Request $request)
{
$fromUnit = $request->get('from');
$toUnit = $request->get('to');
$value = $request->get('value');
$convertedValue = $this->formService->convertUnit($fromUnit, $toUnit, $value);
if ($convertedValue !== null) {
$output = getFormattedValue($convertedValue);
return response()->json([
'success' => true,
'convertedValue' => $output,
]);
}
return response()->json([
'success' => false,
'message' => 'Konversi tidak ditemukan',
]);
}
public function import(Request $request, $sector, $code, $inventoryYear, $instansi = null)
{
$request->validate([
'import_file' => 'required|file|mimes:xlsx,xls|max:2048', // Adjust max file size as needed
]);
try {
$formDetails = SettingFormDetail::where('form_code', $code)->rowActive()->orderByRowNum()->get();
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
} else {
$instansi = null;
}
Excel::import(new FormImport($this->formService, $sector, $code, $inventoryYear, $formDetails, $instansi), $request->file('import_file'));
return redirect()->back()->with('success', 'Data berhasil diimpor.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data gagal diimpor. Mohon dicoba kembali.' . $e->getMessage()]);
}
}
public function export($sector, $code, $inventoryYear, $instansi = null)
{
$data = $this->data($sector, $code, $inventoryYear, $instansi);
$data['inventoryYear'] = $inventoryYear;
$data['instansi'] = $instansi;
$isTemplate = request('isTemplate') ?? false;
$data['isTemplate'] = $isTemplate;
$instansiTitle = ($instansi && $instansi != 'all' && $instansi != 'none') ? ' (' . $instansi . ')' : '';
$titleExcel = $data['form']->name . ' ' . $inventoryYear . $instansiTitle;
if ($isTemplate) {
$titleExcel = 'Template ' . $titleExcel;
} else {
$titleExcel = 'Data Aktivitas ' . $titleExcel;
}
$data['titleExcel'] = $titleExcel;
$fileName = $titleExcel . '.xlsx';
return Excel::download(new FormExport($data), $fileName);
}
public function getUserActivities(Request $request)
{
if ($request->ajax()) {
$data = [];
$formId = $request->query('form_id');
if ($formId !== null && $formId !== '0') {
// $data = LogUserActivity::with('user')->where('form_id', $formId)
// ->orderBy('created_at', 'desc');
$data = LogUserActivity::rowActive()->orderByRowNum()->where('form_id', $formId);
}
$result = datatables()->of($data)
->addIndexColumn()
->addColumn('user_name', function ($row) {
return $row->user->name;
})
->editColumn('activity_type', function ($row) {
return ActivityType::from($row->activity_type)->label();
})
->editColumn('created_at', function ($row) {
return $row->created_at->format('d-m-Y H:i:s');
})
->make(true);
return $result;
}
}
public function lock($sector, $code, $id)
{
try {
$this->formService->lockForm($id);
return redirect()->back()->with('success', 'Data Aktivitas berhasil dikunci.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data Aktivitas gagal dikunci. Mohon dicoba kembali.']);
}
}
public function unlock($sector, $code, $id)
{
try {
$this->formService->unlockForm($id);
return redirect()->back()->with('success', 'Data Aktivitas berhasil dibuka.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data Aktivitas gagal dibuka. Mohon dicoba kembali.']);
}
}
public function copyData(Request $request, $sector, $code)
{
try {
$fromYear = $request->input('from_year');
$toYear = $request->input('to_year');
$this->formService->copyData($sector, $code, $fromYear, $toYear);
return redirect()->back()->with('success', 'Data Aktivitas berhasil disalin.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data Aktivitas gagal disalin. Mohon dicoba kembali.']);
}
}
public function approvalKonsolidasi($sector, $code, $inventoryYear, $instansi = null)
{
try {
$data = $this->data($sector, $code, $inventoryYear, $instansi);
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
}
$form = $data['activityForm'];
$this->formService->approvalKonsolidasi($form, $sector, $code, $inventoryYear, $instansi);
return redirect()->back()->with('success', 'Persetujuan Data Produsen berhasil diproses.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Persetujuan Data Produsen gagal diproses. Mohon dicoba kembali.' . $e->getMessage()]);
}
}
}

View File

@ -0,0 +1,216 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Enums\LingkupAksesData;
use App\Exports\FormKehutananExport;
use App\Http\Controllers\Controller;
use App\Imports\FormKehutananImport;
use App\Models\ActivityApprovalKonsolidasi;
use App\Models\ActivityForm;
use App\Models\ActivityLock;
use App\Models\Agency;
use App\Models\SettingForm;
use App\Services\Activity\FormKehutananService;
use Illuminate\Http\Request;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
class FormKehutananController implements HasMiddleware
{
protected $formService;
private $sector = 'folu';
private $code = 'lahan_mineral';
private $lands = array(
'HP',
'HS',
'HMP',
'HRP',
'HT',
'B',
'PK',
'PM',
'T',
'AW',
'S',
'A',
'HMS',
'HRS',
'BR',
'PT',
'PC',
'SW',
'TM',
'BDR',
'TR',
'TB',
'RW'
);
public function __construct(FormKehutananService $formService)
{
$this->formService = $formService;
}
public static function middleware(): array
{
$sector = 'folu';
$code = 'lahan_mineral';
return [
//new Middleware('permission:/' . $sector . '/' . $code),
];
}
public function data($sector, $code, $inventoryYear, $instansi = null)
{
// Fetch the form from the database based on sector and code
$form = SettingForm::rowActive()->where('sector', $sector)->where('code', $code)->first();
if (!$form) {
abort(404, 'Page not found');
}
// Fetch form details
$lands = $this->lands;
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
}
// get Agencies for produsen data mapping
$user = Auth::user();
$scope = $user->getScope();
if ($scope === LingkupAksesData::INTERNAL->value) {
$instansi = $user->agency_id;
}
$agencies = Agency::whereHas('agencyActivity', function ($query) use ($sector, $code, $scope, $user) {
$query->where('form_sector', $sector)
->where('form_code', $code);
if ($scope === LingkupAksesData::INTERNAL->value) {
$query->where('agency_id', $user->agency_id);
}
})->get();
// Fetch activity form and activity form details using service
$activityForm = $this->formService->getActivityForm($sector, $code, $inventoryYear, $instansi);
if ($instansi == 'all') {
$activityFormId = $activityForm->pluck('id')->toArray();
} else {
$activityFormId = $activityForm->id ?? null;
}
$activityFormDetails = $this->formService->getActivityFormDetails($activityFormId, $instansi);
$isLocked = ActivityLock::isLocked($inventoryYear);
$isApprove = false;
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$isApprove = ActivityApprovalKonsolidasi::isApprove($activityFormId, $sector, $code, $inventoryYear, $instansi);
}
$internal = $instansi;
return compact(
'form',
'lands',
'activityForm',
'activityFormDetails',
'inventoryYear',
'isLocked',
'agencies',
'internal',
'isApprove'
);
}
public function show()
{
$sector = $this->sector;
$code = $this->code;
$inventoryYear = request('inventoryYear') ?? date('Y');
$instansi = request('instansi') ?? null;
// Retrieve data
$data = $this->data($sector, $code, $inventoryYear, $instansi);
return view('form.index-kehutanan', $data);
}
public function import(Request $request, $inventoryYear, $instansi = null)
{
$request->validate([
'import_file' => 'required|file|mimes:xlsx,xls|max:2048', // Adjust max file size as needed
]);
$sector = $this->sector;
$code = $this->code;
$importService = $this->formService;
try {
$lands = $this->lands;
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
} else {
$instansi = null;
}
Excel::import(new FormKehutananImport($importService, $sector, $code, $inventoryYear, $lands, $instansi), $request->file('import_file'));
return redirect()->back()->with('success', 'Data berhasil diimpor.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Data gagal diimpor. Mohon dicoba kembali.' . $e->getMessage()]);
}
}
public function export($inventoryYear, $instansi = null)
{
$sector = $this->sector;
$code = $this->code;
$data = $this->data($sector, $code, $inventoryYear, $instansi);
$data['inventoryYear'] = $inventoryYear;
$isTemplate = request('isTemplate') ?? false;
$data['isTemplate'] = $isTemplate;
$instansiTitle = ($instansi && $instansi != 'all' && $instansi != 'none') ? ' (' . $instansi . ')' : '';
$titleExcel = $data['form']->name . ' ' . $inventoryYear . $instansiTitle;
if ($isTemplate) {
$titleExcel = 'Template ' . $titleExcel;
} else {
$titleExcel = 'Data Aktivitas ' . $titleExcel;
}
$data['titleExcel'] = $titleExcel;
$fileName = $titleExcel . '.xlsx';
return Excel::download(new FormKehutananExport($data), $fileName);
}
public function approvalKonsolidasi($inventoryYear, $instansi = null)
{
$sector = $this->sector;
$code = $this->code;
try {
$data = $this->data($sector, $code, $inventoryYear, $instansi);
if ($instansi && $instansi != 'all' && $instansi != 'none') {
$agency = Agency::where('name', $instansi)->rowActive()->first();
$instansi = $agency ? $agency->id : null;
}
$form = $data['activityForm'];
$this->formService->approvalKonsolidasi($form, $sector, $code, $inventoryYear, $instansi);
return redirect()->back()->with('success', 'Persetujuan Data Produsen berhasil diproses.');
} catch (\Exception $e) {
return redirect()->back()->withErrors(['error' => 'Persetujuan Data Produsen gagal diproses. Mohon dicoba kembali.' . $e->getMessage()]);
}
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Http\Controllers\Controller;
use App\Models\ActivityForm;
use App\Models\ActivityFormMetadata;
use App\Services\Activity\FormMetadataService;
use Illuminate\Http\Request;
class FormMetadataController extends Controller
{
protected $metaService;
public function __construct(FormMetadataService $metaService)
{
$this->metaService = $metaService;
}
public function index(Request $request)
{
$formId = $request->query('form_id');
$metadataList = ActivityFormMetadata::rowActive()->where('form_id', $formId)->orderBy('updated_at', 'DESC')->get();
$form = ActivityForm::rowActive()->where('id', $formId)->first();
if ($form) {
$form['storagePath'] = 'forms/' . $form->sector . '/' . $form->form_code . '/' . $form->inventory_year . '/metadata';
}
return view('form.metadata.list', compact('metadataList', 'form'));
}
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'publisher' => 'required|string|max:255',
'published_year' => 'required|integer',
'contact_name' => 'required|string|max:255',
'contact_phone' => 'required|string|max:255',
'contact_email' => 'required|email|max:255',
'file_document' => 'required|file|max:2048|mimes:pdf,doc,docx,xlsx,xls',
], [
'file_document.max' => 'Ukuran file tidak boleh melebihi 2MB.',
]);
$metadata = $this->metaService->store($request->all());
return response()->json(['success' => 'Metadata berhasil disimpan.']);
}
public function destroy(Request $request, ActivityFormMetadata $metadata)
{
$storagePath = $request->input('storage_path');
$this->metaService->destroy($metadata, $storagePath);
return response()->json(['success' => 'Metadata berhasil dihapus.']);
}
}

View File

@ -0,0 +1,777 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Http\Controllers\Controller;
use App\Models\ActivityDataMitigation;
use App\Models\ActivityDataMitigationForm;
use App\Models\Kabupaten;
use App\Models\Kecamatan;
use App\Models\KegiatanMitigasi;
use App\Models\Kelurahan;
use App\Models\Mitigation;
use App\Models\MitigationRendahKarbonDaerah;
use App\Services\Activity\FormMitigasiService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Barryvdh\DomPDF\Facade\Pdf;
class FormMitigasiController extends Controller
{
protected $formMitigasiService;
// Helper to sanitize integer input (empty string or not numeric to null)
private function sanitizeInteger($value)
{
if ($value === null || $value === '' || !is_numeric($value)) return null;
return (int)$value;
}
private function parseListData($raw)
{
if (!$raw) return [];
// Hilangkan trailing koma sebelum ].
$raw = preg_replace('/,(\s*\])/', '$1', $raw);
$data = json_decode($raw, true);
return is_array($data) ? $data : [];
}
public function __construct(FormMitigasiService $formMitigasiService)
{
$this->formMitigasiService = $formMitigasiService;
}
public function thankYou(string $id)
{
$user = Auth::user();
$km = KegiatanMitigasi::findOrFail($id);
$data = [
'oleh' => $user ? $user->name : 'Guest',
'waktu' => $km->created_at->translatedFormat('l, d F Y, H:i'),
'nama' => $km->nama_kegiatan,
'tahun' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'subsektor' => $km->sub_sektor,
'target' => $km->target,
'satuan' => $km->satuan,
'penurunan' => $km->emission_factor,
];
return view('form.index-mitigasi-thankyou', compact('data', 'km'));
}
public function downloadPDF(string $id)
{
$user = Auth::user();
$km = KegiatanMitigasi::findOrFail($id);
$data = [
'oleh' => $user ? $user->name : 'Guest',
'waktu' => $km->created_at->translatedFormat('l, d F Y, H:i'),
'nama' => $km->nama_kegiatan,
'tahun' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'subsektor' => $km->sub_sektor,
'target' => $km->target,
'satuan' => $km->satuan,
'penurunan' => $km->emission_factor,
];
$pdf = PDF::loadView('form.index-mitigasi-pdf', compact('data'))
->setPaper('a4', 'portrait');
return $pdf->download('bukti-submission-'.$km->nama_kegiatan.'.pdf');
}
public function view(string $id)
{
$km = KegiatanMitigasi::with('sumberData')->findOrFail($id);
$forms = ActivityDataMitigationForm::where('kegiatan_mitigasi_id', $id)->get();
$sessionData = [
'tipe_kegiatan' => $km->tipe_kegiatan,
'tahun_kegiatan' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'sub_sektor' => $km->sub_sektor,
'kategori_perhitungan' => $km->kategori_perhitungan,
'kategori_sub_aktivitas' => $km->kategori_sub_aktivitas,
'mitigation_id' => $km->mitigation_id,
'tipe_laporan' => $km->tipe_laporan,
'nama_kegiatan' => $km->nama_kegiatan,
'informasi_lokasi_kegiatan' => $km->informasi_lokasi_kegiatan,
'jenis_kegiatan' => $km->jenis_kegiatan,
'pelaksana_kegiatan' => $km->pelaksana_kegiatan,
'pelaksana_kegiatan_rad' => $km->pelaksana_kegiatan_rad,
'nomenklatur_kemendagri' => $km->nomenklatur_kemendagri,
'target' => $km->target,
'satuan' => $km->satuan,
'realisasi' => $km->realisasi,
'sdg' => is_array($km->sdg) ? $km->sdg : (json_decode($km->sdg, true) ?? []),
'catatan' => $km->catatan,
'alokasi_apbn' => $km->alokasi_apbn,
'alokasi_apbd' => $km->alokasi_apbd,
'alokasi_swasta' => $km->alokasi_swasta,
'alokasi_sumber_dana_lain' => $km->alokasi_sumber_dana_lain,
'realisasi_apbn' => $km->realisasi_apbn,
'realisasi_apbd' => $km->realisasi_apbd,
'realisasi_swasta' => $km->realisasi_swasta,
'realisasi_sumber_dana_lain' => $km->realisasi_sumber_dana_lain,
'kabupaten_kota_location' => $km->kabupaten_kota_location,
'kecamatan_location' => $km->kecamatan_location,
'kelurahan_location' => $km->kelurahan_location,
'lat_location' => $km->lat_location,
'long_location' => $km->long_location,
'sumber_data' => $km->sumberData->map(fn($s) => [
'title' => $s->judul_sumber_reference,
'year' => $s->tahun_sumber_reference,
'link' => $s->link_sumber_reference,
])->toArray(),
'activity_forms' => $forms->mapWithKeys(function($f) {
$raw = $f->values_array;
if (is_string($raw)) {
$values = json_decode($raw, true) ?: [];
} elseif (is_array($raw)) {
$values = $raw;
} else {
$values = [$f->value];
}
$values = array_map('strval', $values);
return [
"activity_data_{$f->sequence}" => $values,
"unit_{$f->sequence}" => $f->unit,
];
})->toArray(),
];
return view('form.index-mitigasi-view', [
'sessionData' => $sessionData,
'id' => $id,
]);
}
public function edit(string $id, Request $request)
{
$km = KegiatanMitigasi::with('sumberData')->findOrFail($id);
$forms = ActivityDataMitigationForm::where('kegiatan_mitigasi_id', $id)->get();
$sessionData = [
'mitigation_id' => $km->mitigation_id,
'tipe_laporan' => $km->tipe_laporan,
'tipe_kegiatan' => $km->tipe_kegiatan,
'tahun_kegiatan' => $km->tahun_kegiatan,
'sektor' => $km->sektor,
'sub_sektor' => $km->sub_sektor,
'kategori_perhitungan' => $km->kategori_perhitungan,
'kategori_sub_aktivitas' => $km->kategori_sub_aktivitas,
'nama_kegiatan' => $km->nama_kegiatan,
'informasi_lokasi_kegiatan' => $km->informasi_lokasi_kegiatan,
'jenis_kegiatan' => $km->jenis_kegiatan,
'pelaksana_kegiatan' => $km->pelaksana_kegiatan,
'pelaksana_kegiatan_rad' => $km->pelaksana_kegiatan_rad,
'nomenklatur_kemendagri' => $km->nomenklatur_kemendagri,
'target' => $km->target,
'satuan' => $km->satuan,
'realisasi' => $km->realisasi,
'sdg' => json_decode($km->sdg, true) ?? [],
'catatan' => $km->catatan,
'alokasi_apbn' => $km->alokasi_apbn,
'alokasi_apbd' => $km->alokasi_apbd,
'alokasi_swasta' => $km->alokasi_swasta,
'alokasi_sumber_dana_lain' => $km->alokasi_sumber_dana_lain,
'realisasi_apbn' => $km->realisasi_apbn,
'realisasi_apbd' => $km->realisasi_apbd,
'realisasi_swasta' => $km->realisasi_swasta,
'realisasi_sumber_dana_lain' => $km->realisasi_sumber_dana_lain,
'kabupaten_kota_location' => $km->kabupaten_kota_location,
'kecamatan_location' => $km->kecamatan_location,
'kelurahan_location' => $km->kelurahan_location,
'lat_location' => $km->lat_location,
'long_location' => $km->long_location,
'sumber_data' => $km->sumberData->map(fn($s) => [
'title' => $s->judul_sumber_reference,
'year' => $s->tahun_sumber_reference,
'link' => $s->link_sumber_reference,
])->toArray(),
'activity_forms' => $forms->mapWithKeys(function($f) {
$raw = $f->values_array;
if (is_string($raw)) {
$values = json_decode($raw, true) ?: [];
} elseif (is_array($raw)) {
$values = $raw;
} else {
$values = [$f->value];
}
$values = array_map('strval', $values);
return [
"activity_data_{$f->sequence}" => $values,
"unit_{$f->sequence}" => $f->unit,
];
})->toArray(),
];
$request->session()->put('kegiatan_mitigasi', $sessionData);
$startYear = 2000;
$currentYear = now()->year;
$years = range($startYear, $currentYear);
rsort($years);
$sectors = KegiatanMitigasi::distinct()->pluck('sektor')->toArray();
return view('form.index-mitigasi-edit', [
'sessionData' => $sessionData,
'years' => $years,
'currentYear' => $currentYear,
'sectors' => $sectors,
'mitigation' => $km,
'readonly' => false
]);
}
protected function persistActivityForms(array $inputs, string $mitigationId, string $kegiatanMitigasiId)
{
$isMultipleMap = ActivityDataMitigation::where('mitigation_id', $mitigationId)
->pluck('is_multiple', 'sequence')
->toArray();
$typeMap = ActivityDataMitigation::where('mitigation_id', $mitigationId)
->pluck('type_emission_reduction', 'sequence')
->toArray();
foreach ($isMultipleMap as $sequence => $isMultiple) {
$unit = $inputs['unit_' . $sequence] ?? null;
$value = $inputs['activity_data_' . $sequence] ?? null;
$typeEmis = $typeMap[$sequence] ?? null;
if ($isMultiple) {
$clean = is_array($value) ? array_filter($value, fn($v) => $v !== null && $v !== '') : [];
if (!empty($clean)) {
ActivityDataMitigationForm::create([
'kegiatan_mitigasi_id' => $kegiatanMitigasiId,
'sequence' => $sequence,
'value' => null,
'values_array' => array_values($clean),
'unit' => $unit,
'mitigation_id' => $mitigationId,
'type_emission_reduction' => $typeEmis,
]);
}
} else {
$single = is_array($value) ? ($value[0] ?? null) : $value;
if ($single !== null && $single !== '') {
ActivityDataMitigationForm::create([
'kegiatan_mitigasi_id' => $kegiatanMitigasiId,
'sequence' => $sequence,
'value' => $single,
'values_array' => null,
'unit' => $unit,
'mitigation_id' => $mitigationId,
'type_emission_reduction' => $typeEmis,
]);
}
}
}
}
public function create(Request $request)
{
if ($request->has('reset')) {
$request->session()->forget('kegiatan_mitigasi');
}
$sessionData = $request->session()->get('kegiatan_mitigasi', []);
$startYear = 2000;
$currentYear = date('Y');
$years = range($startYear, $currentYear);
rsort($years);
return view('form.index-mitigasi', compact('sessionData', 'years', 'currentYear'));
}
public function update(Request $request, $id)
{
$kegiatanMitigasi = KegiatanMitigasi::with('sumberData')->findOrFail($id);
$sessionData = $request->session()->get('kegiatan_mitigasi');
if (empty($sessionData)) {
return response()->json([
'success' => false,
'message' => 'Data tidak lengkap, silakan lengkapi semua bagian.'
]);
}
try {
DB::transaction(function() use ($sessionData, $request, $kegiatanMitigasi) {
$kegiatanMitigasi->revisi = ($kegiatanMitigasi->revisi ?? 0) + 1;
$kegiatanMitigasi->update([
'tipe_kegiatan' => $sessionData['tipe_kegiatan'] ?? null,
'tahun_kegiatan' => $this->sanitizeInteger($sessionData['tahun_kegiatan'] ?? null),
'sektor' => $sessionData['sektor'] ?? null,
'sub_sektor' => $sessionData['sub_sektor'] ?? null,
'kategori_perhitungan' => $sessionData['kategori_perhitungan'] ?? null,
'kategori_sub_aktivitas' => $sessionData['kategori_sub_aktivitas'] ?? null,
'mitigation_id' => $sessionData['mitigation_id'] ?? null,
'tipe_laporan' => $sessionData['tipe_laporan'] ?? 'laporan',
'nama_kegiatan' => $sessionData['nama_kegiatan'] ?? null,
'informasi_lokasi_kegiatan' => $sessionData['informasi_lokasi_kegiatan'] ?? null,
'jenis_kegiatan' => $sessionData['jenis_kegiatan'] ?? null,
'pelaksana_kegiatan' => $sessionData['pelaksana_kegiatan'] ?? null,
'pelaksana_kegiatan_rad' => $sessionData['pelaksana_kegiatan_rad'] ?? null,
'nomenklatur_kemendagri' => $sessionData['nomenklatur_kemendagri'] ?? null,
'target' => $sessionData['target'] ?? null,
'satuan' => $sessionData['satuan'] ?? null,
'realisasi' => $sessionData['realisasi'] ?? null,
'sdg' => json_encode($sessionData['sdg'] ?? []),
'catatan' => $sessionData['catatan'] ?? null,
'alokasi_apbn' => $sessionData['alokasi_apbn'] ?? null,
'alokasi_apbd' => $sessionData['alokasi_apbd'] ?? null,
'alokasi_swasta' => $sessionData['alokasi_swasta'] ?? null,
'alokasi_sumber_dana_lain' => $sessionData['alokasi_sumber_dana_lain'] ?? null,
'realisasi_apbn' => $sessionData['realisasi_apbn'] ?? null,
'realisasi_apbd' => $sessionData['realisasi_apbd'] ?? null,
'realisasi_swasta' => $sessionData['realisasi_swasta'] ?? null,
'realisasi_sumber_dana_lain'=> $sessionData['realisasi_sumber_dana_lain'] ?? null,
'kabupaten_kota_location' => $sessionData['kabupaten_kota_location'] ?? null,
'kecamatan_location' => $sessionData['kecamatan_location'] ?? null,
'kelurahan_location' => $sessionData['kelurahan_location'] ?? null,
'lat_location' => $sessionData['lat_location'] ?? null,
'long_location' => $sessionData['long_location'] ?? null,
'updated_by' => auth()->check() ? auth()->user()->name : null,
]);
// Update sumber data (delete all, re-insert sanitized)
$kegiatanMitigasi->sumberData()->delete();
foreach($sessionData['sumber_data'] ?? [] as $s) {
$kegiatanMitigasi->sumberData()->create([
'id' => Str::uuid(),
'judul_sumber_reference' => trim($s['title'] ?? '') ?: null,
'tahun_sumber_reference' => $this->sanitizeInteger($s['year'] ?? null),
'link_sumber_reference' => trim($s['link'] ?? '') ?: null,
]);
}
ActivityDataMitigationForm::where('kegiatan_mitigasi_id', $kegiatanMitigasi->id)->delete();
$this->persistActivityForms($request->all(), $sessionData['mitigation_id'], $kegiatanMitigasi->id);
$this->formMitigasiService->calculateAndPersist($sessionData['mitigation_id'], $kegiatanMitigasi);
$request->session()->forget('kegiatan_mitigasi');
});
return response()->json([
'success' => true,
'redirect' => route('formMitigasi.thankYou', $id),
]);
} catch (\Exception $e) {
Log::error('Error updating data: ' . $e->getMessage());
return back()->with('error', 'Gagal mengupdate data. Silakan coba lagi.');
}
}
public function loadQuestion(Request $request)
{
$mitigation_id = $request->input('mitigation_id');
if (!Str::isUuid($mitigation_id)) {
return response()->json(['message' => 'Invalid mitigation ID'], 400);
}
$questions = ActivityDataMitigation::select(
'activity_data_mitigation.id',
'activity_data_mitigation.activity_data',
'activity_data_mitigation.unit',
'activity_data_mitigation.sequence',
'activity_data_mitigation.type',
'activity_data_mitigation.list_data',
'activity_data_mitigation.is_multiple',
'activity_data_mitigation.question_plus',
'activity_data_mitigation.ad_sequence',
'activity_data_mitigation.type_emission_reduction',
'activity_data_mitigation.is_required',
'activity_data_mitigation.title_group',
'activity_data_mitigation.keterangan',
'am.activity_desc as activity_desc',
'am.activity_type as title'
)
->join('activity.mitigation as am', 'activity_data_mitigation.mitigation_id', '=', 'am.id')
->where('activity_data_mitigation.mitigation_id', $mitigation_id)
->orderBy('activity_data_mitigation.sequence')
->get()
->map(function ($item) {
$dataMitigation = ActivityDataMitigation::with('units')
->find($item->id);
$units = $dataMitigation && $dataMitigation->units->isNotEmpty()
? $dataMitigation->units->pluck('unit')
: collect([$item->unit])->filter();
$category = $dataMitigation && $dataMitigation->units->isNotEmpty()
? $dataMitigation->units->pluck('category')
: collect([$item->unit])->filter();
return [
'id' => $item->id,
'sequence' => $item->sequence,
'activity_data' => $item->activity_data,
'units' => $units->values(),
'category' => $category->values(),
'type' => $item->type,
'choices' => $this->parseListData($item->list_data),
'is_multiple' => (bool)$item->is_multiple,
'is_required' => (bool)$item->is_required,
'question_plus' => $item->question_plus,
'ad_sequence' => $item->ad_sequence,
'type_emission_reduction' => $item->type_emission_reduction,
'activity_desc' => $item->activity_desc,
'title' => $item->title,
'title_group' => $item->title_group,
'keterangan' => $item->keterangan,
];
});
return response()->json($questions);
}
public function storePart1(Request $request)
{
$validated = $request->validate([
'tipe_kegiatan' => 'required|in:inti,pendukung,prasyarat',
'tahun_kegiatan' => 'required|integer|min:2000|max:' . date('Y'),
'sektor' => 'required|string',
'sub_sektor' => 'required|string',
'kategori_perhitungan' => 'required|string',
'kategori_sub_aktivitas' => 'sometimes|nullable|string',
'mitigation_id' => 'required|string'
]);
$sessionData = $request->session()->get('kegiatan_mitigasi');
$sessionArray = is_object($sessionData) ? $sessionData->toArray() : (array) $sessionData;
$mergedData = array_merge($sessionArray, $validated);
if ($request->filled('laporan')) {
$mergedData['tipe_laporan'] = $request->laporan;
} else {
$mergedData['tipe_laporan'] = $sessionArray['tipe_laporan'] ?? 'laporan';
}
$request->session()->put('kegiatan_mitigasi', $mergedData);
return response()->json(['success' => true]);
}
public function storePart2(Request $request)
{
$validated = $request->validate([
'nama_kegiatan' => 'required|string',
'informasi_lokasi_kegiatan' => 'required|string',
'jenis_kegiatan' => 'required|string|in:lokal,berkelanjutan',
'pelaksana_kegiatan' => 'nullable|string',
'pelaksana_kegiatan_rad' => 'nullable|string',
'nomenklatur_kemendagri' => 'nullable|string',
'target' => 'required|string',
'satuan' => 'required|string',
'realisasi' => 'nullable|string',
'sdg' => 'nullable|array',
'catatan' => 'nullable|string',
]);
$sessionData = $request->session()->get('kegiatan_mitigasi');
if (!$sessionData) {
return response()->json(['success' => false, 'message' => 'Silakan lengkapi bagian Informasi Umum terlebih dahulu']);
}
$updatedData = array_merge($sessionData, $validated);
$request->session()->put('kegiatan_mitigasi', $updatedData);
return response()->json(['success' => true]);
}
public function storePart3(Request $request)
{
$validated = $request->validate([
'alokasi_apbn' => 'nullable|string',
'alokasi_apbd' => 'nullable|string',
'alokasi_swasta' => 'nullable|string',
'alokasi_sumber_dana_lain' => 'nullable|string',
'realisasi_apbn' => 'nullable|string',
'realisasi_apbd' => 'nullable|string',
'realisasi_swasta' => 'nullable|string',
'realisasi_sumber_dana_lain' => 'nullable|string'
]);
$sessionData = $request->session()->get('kegiatan_mitigasi');
if (!$sessionData) {
return response()->json(['success' => false, 'message' => 'Silakan lengkapi bagian Informasi Umum terlebih dahulu']);
}
$updatedData = array_merge($sessionData, $validated);
$request->session()->put('kegiatan_mitigasi', $updatedData);
return response()->json(['success' => true]);
}
public function storePart4(Request $request)
{
try {
$validated = $request->validate([
'titleSourceReference' => 'nullable|array',
'titleSourceReference.*' => 'nullable|string|max:255',
'yearSourceReference' => 'nullable|array',
'yearSourceReference.*' => 'nullable|string|max:4',
'linkSourceReference' => 'nullable|array',
'linkSourceReference.*' => 'nullable|string|max:500',
]);
$sessionData = $request->session()->get('kegiatan_mitigasi', []);
if (empty($sessionData)) {
return response()->json([
'success' => false,
'message' => 'Silakan lengkapi bagian Informasi Umum terlebih dahulu.'
]);
}
$titles = $validated['titleSourceReference'] ?? [];
$years = $validated['yearSourceReference'] ?? [];
$links = $validated['linkSourceReference'] ?? [];
$max = max(count($titles), count($years), count($links));
$sumberDataList = [];
for ($i = 0; $i < $max; $i++) {
$sumberDataList[] = [
'title' => trim($titles[$i] ?? ''),
'year' => trim($years[$i] ?? ''),
'link' => trim($links[$i] ?? ''),
];
}
$updatedData = array_merge($sessionData, ['sumber_data' => $sumberDataList]);
$request->session()->put('kegiatan_mitigasi', $updatedData);
return response()->json(['success' => true]);
} catch (\Exception $e) {
Log::error('Error storePart4: '.$e->getMessage());
return response()->json([
'success' => false,
'message' => 'Terjadi error server: '.$e->getMessage()
]);
}
}
public function storePart5(Request $request)
{
$validated = $request->validate([
'kabupaten_kota_location' => 'nullable|string',
'kecamatan_location' => 'nullable|string',
'kelurahan_location' => 'nullable|string',
'lat_location' => 'nullable|string',
'long_location' => 'nullable|string'
]);
$sessionData = $request->session()->get('kegiatan_mitigasi');
if (!$sessionData) {
return response()->json(['success' => false, 'message' => 'Silakan lengkapi bagian Informasi Umum terlebih dahulu']);
}
$updatedData = array_merge($sessionData, $validated);
$request->session()->put('kegiatan_mitigasi', $updatedData);
return response()->json(['success' => true]);
}
public function storeFinal(Request $request)
{
$sessionData = $request->session()->get('kegiatan_mitigasi');
if (empty($sessionData)) {
return response()->json([
'success' => false,
'message' => 'Silakan lengkapi semua bagian terlebih dahulu'
]);
}
try {
$mitigasiId = Str::uuid()->toString();
DB::transaction(function() use ($sessionData, $request, $mitigasiId) {
$kegiatanMitigasi = KegiatanMitigasi::create([
'id' => $mitigasiId,
'tipe_kegiatan' => $sessionData['tipe_kegiatan'] ?? null,
'tahun_kegiatan' => $this->sanitizeInteger($sessionData['tahun_kegiatan'] ?? null),
'sektor' => $sessionData['sektor'] ?? null,
'sub_sektor' => $sessionData['sub_sektor'] ?? null,
'kategori_perhitungan' => $sessionData['kategori_perhitungan'] ?? null,
'kategori_sub_aktivitas' => $sessionData['kategori_sub_aktivitas'] ?? null,
'mitigation_id' => $sessionData['mitigation_id'] ?? null,
'tipe_laporan' => $sessionData['tipe_laporan'] ?? 'laporan',
'nama_kegiatan' => $sessionData['nama_kegiatan'] ?? null,
'informasi_lokasi_kegiatan' => $sessionData['informasi_lokasi_kegiatan'] ?? null,
'jenis_kegiatan' => $sessionData['jenis_kegiatan'] ?? null,
'pelaksana_kegiatan' => $sessionData['pelaksana_kegiatan'] ?? null,
'pelaksana_kegiatan_rad' => $sessionData['pelaksana_kegiatan_rad'] ?? null,
'nomenklatur_kemendagri' => $sessionData['nomenklatur_kemendagri'] ?? null,
'target' => $sessionData['target'] ?? null,
'satuan' => $sessionData['satuan'] ?? null,
'realisasi' => $sessionData['realisasi'] ?? null,
'sdg' => json_encode($sessionData['sdg'] ?? []),
'catatan' => $sessionData['catatan'] ?? null,
'alokasi_apbn' => $sessionData['alokasi_apbn'] ?? null,
'alokasi_apbd' => $sessionData['alokasi_apbd'] ?? null,
'alokasi_swasta' => $sessionData['alokasi_swasta'] ?? null,
'alokasi_sumber_dana_lain' => $sessionData['alokasi_sumber_dana_lain'] ?? null,
'realisasi_apbn' => $sessionData['realisasi_apbn'] ?? null,
'realisasi_apbd' => $sessionData['realisasi_apbd'] ?? null,
'realisasi_swasta' => $sessionData['realisasi_swasta'] ?? null,
'realisasi_sumber_dana_lain' => $sessionData['realisasi_sumber_dana_lain'] ?? null,
'kabupaten_kota_location'=> $sessionData['kabupaten_kota_location'] ?? null,
'kecamatan_location' => $sessionData['kecamatan_location'] ?? null,
'kelurahan_location' => $sessionData['kelurahan_location'] ?? null,
'lat_location' => $sessionData['lat_location'] ?? null,
'long_location' => $sessionData['long_location'] ?? null,
'created_by' => auth()->check() ? auth()->user()->name : null,
]);
collect($sessionData['sumber_data'] ?? [])
->filter(function($s) {
return
trim($s['title'] ?? '') !== '' ||
trim($s['year'] ?? '') !== '' ||
trim($s['link'] ?? '') !== '';
})
->each(function($s) use ($kegiatanMitigasi) {
$kegiatanMitigasi->sumberData()->create([
'id' => Str::uuid()->toString(),
'judul_sumber_reference' => trim($s['title'] ?? '') ?: null,
'tahun_sumber_reference' => $this->sanitizeInteger($s['year'] ?? null),
'link_sumber_reference' => trim($s['link'] ?? '') ?: null,
]);
});
$this->persistActivityForms($request->all(), $sessionData['mitigation_id'], $mitigasiId);
$this->formMitigasiService->calculateAndPersist($sessionData['mitigation_id'], $kegiatanMitigasi, $mitigasiId);
$request->session()->forget('kegiatan_mitigasi');
});
return response()->json([
'success' => true,
'redirect' => route('formMitigasi.thankYou', $mitigasiId),
]);
} catch (\Exception $e) {
Log::error('Error storing final data: ' . $e->getMessage());
return back()->with('error', 'Gagal menyimpan data. Silakan coba lagi.');
}
}
// ... fungsi getSectors, getSubSectors, getKategoriPerhitungan, getSubActivity, getAksiRAD, getKabkot, getKecamatan, getKelurahan tidak perlu diubah ...
public function getSectors()
{
$query = Mitigation::select('sector')
->where('is_active', true)
->distinct();
$result = $query->pluck('sector');
return response()->json($result);
}
public function getSubSectors(Request $request)
{
$param = $request->input('sector');
$query = Mitigation::select('sub_sector')
->where('sector', $param)
->where('is_active', true)
->distinct();
$result = $query->pluck('sub_sector');
return response()->json($result);
}
public function getKategoriPerhitungan(Request $request)
{
$param = $request->input('sub_sector');
$param2 = $request->input('sector');
$query = Mitigation::select('id', 'activity_type')
->where('sub_sector', $param)
->where('sector', $param2)
->where('is_active', true)
->distinct('activity_type')->get();
return response()->json($query);
}
public function getSubActivity(Request $request)
{
$param = $request->input('sub_sector');
$param2 = $request->input('sector');
$param3 = $request->input('activity');
$query = Mitigation::select('id', 'sub_activity', 'sub_activity_desc')
->where('sub_sector', $param)
->where('sector', $param2)
->where('activity_type', $param3)
->where('is_active', true)
->distinct('sub_activity')->get();
return response()->json($query);
}
public function getAksiRAD(Request $request)
{
$param = $request->input('sub_sector');
$data = MitigationRendahKarbonDaerah::select('sector', 'sub_sector', 'name')
->where('sub_sector', $param)
->distinct('name')->get();
$result = $data->map(function ($item) {
return "[" . $item->sector . " - " . $item->sub_sector . "] " . $item->name;
});
return response()->json($result);
}
public function getKabkot()
{
$query = Kabupaten::select('kabkot_id', 'kabkot_name')
->get();
return response()->json($query);
}
public function getKecamatan(Request $request)
{
$param = $request->input('kabkot_id');
$query = Kecamatan::select('kec_id', 'kec_name')
->where('kabkot_id', $param)
->get();
return response()->json($query);
}
public function getKelurahan(Request $request)
{
$kabkot_id = $request->input('kabkot_id');
$kec_id = $request->input('kec_id');
$query = Kelurahan::select('kel_id', 'kel_name')
->where('kabkot_id', $kabkot_id)
->where('kec_id', $kec_id)
->get();
return response()->json($query);
}
}

View File

@ -0,0 +1,184 @@
<?php
namespace App\Http\Controllers\Activity;
use App\Http\Controllers\Controller;
use App\Models\LivestockManure;
use App\Models\ReferenceAr;
use App\Rules\UniqueInSchema;
use App\Services\Activity\LivestockManureService;
use Illuminate\Http\Request;
use Illuminate\Routing\Controllers\HasMiddleware;
use Illuminate\Routing\Controllers\Middleware;
class LivestockManureController implements HasMiddleware
{
protected $service;
public function __construct(LivestockManureService $service)
{
$this->service = $service;
}
public static function middleware(): array
{
return [
//new Middleware('permission:/agriculture/kotoran_ternak'),
];
}
public function index(Request $request)
{
if ($request->ajax()) {
$data = $this->service->getAll();
$result = datatables()::of($data)
->addColumn('no_baris', function ($lm) {
return $lm->row_num;
})
->addColumn('status', function ($lm) {
if ($lm->active_status == 1) {
return '<span class="badge badge-success">Aktif</span>';
} else {
return '<span class="badge badge-danger">Tidak Aktif</span>';
}
})
->editColumn('ef_direct_n2o_n', function ($lm) {
if ($lm->ef_direct_n2o_n === 0) {
return 0; // Show 0 as is
}
$output = getFormattedValue($lm->ef_direct_n2o_n, 2);
return $output;
})
->editColumn('ef_evaporation_n', function ($lm) {
if ($lm->ef_evaporation_n === 0) {
return 0; // Show 0 as is
}
$output = getFormattedValue($lm->ef_evaporation_n);
return $output;
})
->addColumn('action', function ($lm) {
$btn = '<a href="' . route('livestockManure.edit', $lm->id) . '" class="btn btn-primary">Edit</a>';
$btn .= ' <form action="' . route('livestockManure.destroy', $lm->id) . '" method="POST" style="display: inline;" class="delete-form">';
$btn .= csrf_field();
$btn .= method_field('DELETE');
$btn .= '<button type="button" class="btn btn-danger delete-button">Hapus</button>';
$btn .= '</form>';
if ($lm->active_status == 0) {
$btn .= ' <form action="' . route('livestockManure.setAktif', $lm->id) . '" method="POST" style="display: inline;" class="set-aktif-form">';
$btn .= csrf_field();
$btn .= method_field('PUT');
$btn .= '<button type="button" class="btn btn-info text-white set-aktif-button">Aktifkan</button>';
$btn .= '</form>';
}
return $btn;
})
->rawColumns(['no_baris', 'status', 'action'])
->make(true);
return $result;
}
return view('form.livestock-manure.index');
}
public function create()
{
return view('form.livestock-manure.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'ef_direct_n2o_n' => 'nullable',
'ef_evaporation_n' => 'nullable'
]);
try {
$nextRowNum = LivestockManure::max('row_num') + 1;
$formattedEf1 = getOriginalValue($request->input('ef_direct_n2o_n'));
$formattedEf2 = getOriginalValue($request->input('ef_evaporation_n'));
$data = array_merge($request->all(), [
'row_num' => $nextRowNum,
'active_status' => 0,
'ef_direct_n2o_n' => $formattedEf1,
'ef_evaporation_n' => $formattedEf2,
]);
$this->service->create($data);
return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil ditambahkan.');
} catch (\Exception $e) {
return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]);
}
}
public function edit($id)
{
$lm = $this->service->find($id);
return view('form.livestock-manure.edit', compact('lm'));
}
public function update(Request $request, LivestockManure $kotoran_ternak)
{
$request->validate([
// 'code' => [
// 'required',
// 'string',
// 'max:255',
// new UniqueInSchema('activity', 'livestock_manure', 'code', $lm->id),
// ],
'name' => 'required|string|max:255',
'ef_direct_n2o_n' => 'nullable',
'ef_evaporation_n' => 'nullable',
'row_num' => 'required|numeric',
]);
try {
$formattedEf1 = getOriginalValue($request->input('ef_direct_n2o_n'));
$formattedEf2 = getOriginalValue($request->input('ef_evaporation_n'));
$data = array_merge($request->all(), [
'ef_direct_n2o_n' => $formattedEf1,
'ef_evaporation_n' => $formattedEf2,
]);
$this->service->update($kotoran_ternak, $data);
return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diperbarui.');
} catch (\Exception $e) {
return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal diperbarui. Silakan coba lagi. Error: ' . $e->getMessage()]);
}
}
public function destroy(LivestockManure $kotoran_ternak)
{
try {
$this->service->delete($kotoran_ternak);
$records = LivestockManure::orderBy('row_num')->get();
foreach ($records as $index => $record) {
$record->row_num = $index + 1;
$record->save();
}
return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil dihapus.');
} catch (\Exception $e) {
return back()->withErrors(['error' => 'Jenis Pengelolaan Kotoran Ternak gagal dihapus. Silakan coba lagi. Error: ' . $e->getMessage()]);
}
}
public function setAktif($id)
{
try {
$this->service->setAktif($id);
return redirect()->route('livestockManure.index')->with('success', 'Jenis Pengelolaan Kotoran Ternak berhasil diaktifkan.');
} catch (\Exception $e) {
return back()->withErrors(['error' => 'Gagal mengaktifkan Jenis Pengelolaan Kotoran Ternak. Silakan coba lagi. Error: ' . $e->getMessage()]);
}
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use App\Services\DashboardService;
use Illuminate\Http\Request;
class DashboardInventoryController extends Controller
@ -11,13 +12,27 @@ class DashboardInventoryController extends Controller
protected $template = 'modules.dashboard.inventory';
protected $route = 'modules.dashboard.inventory';
/**
* Display a listing of the resource.
*/
public function index()
protected $emissionService;
public function __construct(DashboardService $emissionService)
{
$data['title'] = $this->title;
return view($this->template.'.index',$data);
$this->emissionService = $emissionService;
}
public function index(Request $request)
{
try {
$inventoryYear = $request->input('year', date('Y'));
$dashboardData = $this->emissionService->getDashboardData($inventoryYear);
return view($this->template.'.index', $dashboardData);
} catch (\Exception $e) {
Log::error('Error loading dashboard data', [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
}
}
/**

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Agriculture3A2bService;
use Illuminate\Http\Request;
class Agriculture3A2bController extends Controller
{
protected $service;
public function __construct(Agriculture3A2bService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// manure_mgmt_direct_n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Agriculture3AService;
use Illuminate\Http\Request;
class Agriculture3AController extends Controller
{
protected $service;
public function __construct(Agriculture3AService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// enteric_fermentation
// manure_mgmt
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Agriculture3C1Service;
use Illuminate\Http\Request;
class Agriculture3C1Controller extends Controller
{
protected $service;
public function __construct(Agriculture3C1Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// padi_sawah
// padi_ladang
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Agriculture3C3Service;
use Illuminate\Http\Request;
class Agriculture3C3Controller extends Controller
{
protected $service;
public function __construct(Agriculture3C3Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// urea_fertilization
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Agriculture3C4Service;
use Illuminate\Http\Request;
class Agriculture3C4Controller extends Controller
{
protected $service;
public function __construct(Agriculture3C4Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// managed_soils_direct_n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Agriculture3C5Service;
use Illuminate\Http\Request;
class Agriculture3C5Controller extends Controller
{
protected $service;
public function __construct(Agriculture3C5Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// managed_soils_indirect_n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Agriculture3C6Service;
use Illuminate\Http\Request;
class Agriculture3C6Controller extends Controller
{
protected $service;
public function __construct(Agriculture3C6Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// manure_mgmt_indirect_n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Energy1AService;
use Illuminate\Http\Request;
class Energy1AController extends Controller
{
protected $service;
public function __construct(Energy1AService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\EnergyGPCService;
use Illuminate\Http\Request;
class EnergyGPCController extends Controller
{
protected $service;
public function __construct(EnergyGPCService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Folu3BService;
use Illuminate\Http\Request;
class Folu3BController extends Controller
{
protected $service;
public function __construct(Folu3BService $service)
{
$this->service = $service;
}
public function data($sector, $code, $inventoryYear)
{
// Fetch the form from the database based on sector and code
$form = SettingForm::rowActive()->where('sector', $sector)->where('code', $code)->first();
if (!$form) {
abort(404, 'Page not found');
}
// Fetch form details
$formDetails = SettingFormDetail::rowActive()->where('form_code', $code)->orderByRowNum()->get();
// Fetch activity form and activity form details using service
$activityForm = $this->service->getActivityForm($sector, $code, $inventoryYear);
$activityFormId = $activityForm->id ?? null;
$activityFormDetails = $this->service->getActivityFormDetails($activityFormId);
return compact('form', 'formDetails', 'activityForm', 'activityFormDetails');
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\GpcMappingService;
use Illuminate\Http\Request;
class GpcMappingController extends Controller
{
protected $service;
public function __construct(GpcMappingService $service)
{
$this->service = $service;
}
public function save(Request $request, $inventoryYear)
{
if ($code) {
$result = $this->service->save($inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4AService;
use Illuminate\Http\Request;
class Waste4AController extends Controller
{
protected $service;
public function __construct(Waste4AService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4AMethaneService;
use App\Services\Emisi\Waste4APreService;
use Illuminate\Http\Request;
class Waste4AMethaneController extends Controller
{
protected $service;
public function __construct(Waste4AMethaneService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Agriculture3C5Service;
use App\Services\Emisi\Waste4APreService;
use Illuminate\Http\Request;
class Waste4APreController extends Controller
{
protected $service;
public function __construct(Waste4APreService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Waste4B1Service;
use Illuminate\Http\Request;
class Waste4B1Controller extends Controller
{
protected $service;
public function __construct(Waste4B1Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// ch4
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Models\SettingForm;
use App\Models\SettingFormDetail;
use App\Services\Emisi\Waste4B2Service;
use Illuminate\Http\Request;
class Waste4B2Controller extends Controller
{
protected $service;
public function __construct(Waste4B2Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4C1Service;
use Illuminate\Http\Request;
class Waste4C1Controller extends Controller
{
protected $service;
public function __construct(Waste4C1Service $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4C2aService;
use Illuminate\Http\Request;
class Waste4C2aController extends Controller
{
protected $service;
public function __construct(Waste4C2aService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
//4c2_co2
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4C2bService;
use Illuminate\Http\Request;
class Waste4C2bController extends Controller
{
protected $service;
public function __construct(Waste4C2bService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
//4c2_ch4
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4C2cService;
use Illuminate\Http\Request;
class Waste4C2cController extends Controller
{
protected $service;
public function __construct(Waste4C2cService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
//4c2_n2o
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4D1aService;
use Illuminate\Http\Request;
class Waste4D1aController extends Controller
{
protected $service;
public function __construct(Waste4D1aService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// 4D1_TOW
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4D1cService;
use Illuminate\Http\Request;
class Waste4D1cController extends Controller
{
protected $service;
public function __construct(Waste4D1cService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// 4D1_CH4
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4D1dService;
use Illuminate\Http\Request;
class Waste4D1dController extends Controller
{
protected $service;
public function __construct(Waste4D1dService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// 4D1_N
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Emisi;
use App\Http\Controllers\Controller;
use App\Services\Emisi\Waste4D1eService;
use Illuminate\Http\Request;
class Waste4D1eController extends Controller
{
protected $service;
public function __construct(Waste4D1eService $service)
{
$this->service = $service;
}
public function save(Request $request, $code, $inventoryYear)
{
// 4D1_Indirect_N2O
if ($code) {
$result = $this->service->save($code, $inventoryYear);
return $result;
}
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class BahanBakarListrikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class EmisiBatuBaraController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class EmisiMigasController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class EnergiLainnyaController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class IndustriManufakturController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KomersialController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ListrikPlnController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PembangkitListrikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PenggunaanListrikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PenyulinganController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class RumahTanggaController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class TransmisiDistribusiController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Energi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class TransportasiController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KarbonatKacaController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KarbonatKeramikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KarbonatLainnyaController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KarbonatMakananController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KarbonatPulpController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PelumasParafinController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PenggunaAcController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\IPPU;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ProduksiController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class CRFController extends Controller
{
protected $title = 'CRF';
protected $template = 'modules.kalkulasi.crf';
protected $route = 'modules.kalkulasi.crf';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'CRF','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/crf/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/crf/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class GCOMController extends Controller
{
protected $title = 'GCOM';
protected $template = 'modules.kalkulasi.gcom';
protected $route = 'modules.kalkulasi.gcom';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'GCOM','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/gcom/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/gcom/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class GPCController extends Controller
{
protected $title = 'GPC';
protected $template = 'modules.kalkulasi.gpc';
protected $route = 'modules.kalkulasi.gpc';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'GPC','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/gpc/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/gpc/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class HitungProdusenController extends Controller
{
protected $title = 'Hitung Produsen';
protected $template = 'modules.kalkulasi.hitung-produsen';
protected $route = 'modules.kalkulasi.hitung-produsen';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Hitung Produsen','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/hitung-produsen/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/hitung-produsen/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class KalkulasiEmisiController extends Controller
{
protected $title = 'Kalkulasi Emisi';
protected $template = 'modules.kalkulasi.kalkulasi-emisi';
protected $route = 'modules.kalkulasi.kalkulasi-emisi';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Kalkulasi Emisi','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/kalkulasi-emisi/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/kalkulasi-emisi/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class KunciAktifitasController extends Controller
{
protected $title = 'Kunci Aktivitas';
protected $template = 'modules.kalkulasi.kunci-aktivitas';
protected $route = 'modules.kalkulasi.kunci-aktivitas';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Kunci Aktivitas','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/kunci-aktivitas/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/kunci-aktivitas/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class SalinAktifitasController extends Controller
{
protected $title = 'Salin Aktivitas';
protected $template = 'modules.kalkulasi.salin-aktivitas';
protected $route = 'modules.kalkulasi.salin-aktivitas';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Salin Aktivitas','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/salin-aktivitas/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/salin-aktivitas/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Kalkulasi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class WorksheetController extends Controller
{
protected $title = 'Worksheet';
protected $template = 'modules.kalkulasi.worksheet';
protected $route = 'modules.kalkulasi.worksheet';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Worksheet','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('kalkulasi/worksheet/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('kalkulasi/worksheet/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Kalkulasi'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class DistribusiSampahDomestikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KependudukanController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class KomposisiSampahDomestikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class LimbahCairIndustriController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class SaranaAirLimbahDomestikController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Limbah;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class TimbulanSampahController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace App\Http\Controllers\Master;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AgencyController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,187 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\AR;
class ARController extends Controller
{
protected $title = 'AR';
protected $template = 'modules.pengaturan.ar';
protected $route = 'modules.pengaturan.ar';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'AR','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = AR::orderBy('nomor_baris','ASC')->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->ArId).'" href="'.url('pengaturan/ar/update/'.encode_id($row->ArId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/ar/delete/'.encode_id($row->ArId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->ArId),
'kode' => @$row->kode,
'nama' => @$row->nama,
'deskripsi' => @$row->deskripsi,
'nomor_baris' => @$row->nomor_baris,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'kode' => 'required|string|max:255|unique:p_ar,kode',
'nama' => 'required|string|max:255',
'deskripsi' => 'required|string',
'nomor_baris' => 'required|numeric',
],[
'kode.unique' => 'Kode Tidak Boleh Sama',
'nomor_baris.numeric' => 'Nomor Baris Harus Berupa Angka',
'kode.required' => 'Tidak Boleh Kosong',
'nama.required' => 'Tidak Boleh Kosong',
'deskripsi.required' => 'Tidak Boleh Kosong',
'nomor_baris.required' => 'Tidak Boleh Kosong',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = AR::find($keyId);
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}else{
$data = new AR;
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'AR','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = AR::where('ArId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = AR::where('ArId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,202 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\EF;
use App\Models\SumberDataEF;
use App\Models\Master\Activity;
class EFController extends Controller
{
protected $title = 'Data EF';
protected $template = 'modules.pengaturan.ef';
protected $route = 'modules.pengaturan.ef';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'EF','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['activity'] = Activity::all();
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
if(request()->activity){
$data = EF::with(['activity','sumberdata'])->where('ms_activity_id',decode_id(request()->activity))->orderBy('nomor_baris','ASC')->get();
}else{
$data = EF::with(['activity','sumberdata'])->orderBy('nomor_baris','ASC')->get();
}
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->EFId).'" href="'.url('pengaturan/ef/update/'.encode_id($row->EFId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/ef/delete/'.encode_id($row->EFId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->EFId),
'activity' => @$row->activity->nama,
'sumberdata' => @$row->sumberdata->nama,
'kategori' => @$row->category,
'kode' => @$row->kode,
'nilai' => @$row->value,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'ms_activity_id' => 'required',
'sumberdata_ef_id' => 'required',
'value' => 'required',
'category' => 'required|string|max:255',
'tag_1' => 'nullable|string|max:255',
'tag_2' => 'nullable|string|max:255',
'tag_3' => 'nullable|string|max:255',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = EF::find($keyId);
$data->ms_activity_id = decode_id($request->ms_activity_id);
$data->tag_1 = $request->tag_1;
$data->tag_2 = $request->tag_2;
$data->tag_3 = $request->tag_3;
$data->category = $request->category;
$data->sumberdata_ef_id = decode_id($request->sumberdata_ef_id);
$data->value = $request->value;
$data->deskripsi = $request->deskripsi;
$data->status = $request->status;
$data->save();
}else{
$data = new EF;
$data->ms_activity_id = decode_id($request->ms_activity_id);
$data->tag_1 = $request->tag_1;
$data->tag_2 = $request->tag_2;
$data->tag_3 = $request->tag_3;
$data->category = $request->category;
$data->sumberdata_ef_id = decode_id($request->sumberdata_ef_id);
$data->value = $request->value;
$data->deskripsi = $request->deskripsi;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'AR','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = EF::where('EFId',$keyId)->first();
$data['activity'] = Activity::all();
$data['sumberdata'] = SumberDataEF::all();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = EF::where('EFId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,187 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\GHG;
class GHGController extends Controller
{
protected $title = 'GHG';
protected $template = 'modules.pengaturan.ghg';
protected $route = 'modules.pengaturan.ghg';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'GHG','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = GHG::orderBy('nomor_baris','ASC')->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->GhgId).'" href="'.url('pengaturan/ghg/update/'.encode_id($row->GhgId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/ghg/delete/'.encode_id($row->GhgId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->GhgId),
'kode' => @$row->kode,
'nama' => @$row->nama,
'deskripsi' => @$row->deskripsi,
'nomor_baris' => @$row->nomor_baris,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'kode' => 'required|string|max:255|unique:p_ar,kode',
'nama' => 'required|string|max:255',
'deskripsi' => 'required|string',
'nomor_baris' => 'required|numeric',
],[
'kode.unique' => 'Kode Tidak Boleh Sama',
'nomor_baris.numeric' => 'Nomor Baris Harus Berupa Angka',
'kode.required' => 'Tidak Boleh Kosong',
'nama.required' => 'Tidak Boleh Kosong',
'deskripsi.required' => 'Tidak Boleh Kosong',
'nomor_baris.required' => 'Tidak Boleh Kosong',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = GHG::find($keyId);
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}else{
$data = new GHG;
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'GHG','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = GHG::where('GhgId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = GHG::where('GhgId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,211 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\GHG;
use App\Models\AR;
use App\Models\GWP;
class GWPController extends Controller
{
protected $title = 'GWP';
protected $template = 'modules.pengaturan.gwp';
protected $route = 'modules.pengaturan.gwp';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'GWP','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['ar'] = AR::where('status',1)->orderBy('nomor_baris','ASC')->get();
return view($this->template.'.form',$data);
}
public function grid(Request $request)
{
$data = GHG::orderBy('nomor_baris','ASC')->get();
$ar = AR::where('status',1)->orderBy('nomor_baris','ASC')->get();
$_data = [];
foreach ($data as $key => $row) {
$_ardata = [];
foreach ($ar as $keyAr => $rowAr) {
$_ardata['ar_'.$rowAr->ArId.'_'.strtolower($rowAr->kode)] = '<input name="ar_'.$rowAr->ArId.'_'.strtolower($rowAr->kode).'[]" type="text" value="'.getFormattedValue( getMatriks($row->kode, $rowAr->kode)).'" class="form-control">';
}
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->GhgId).'" href="'.url('pengaturan/ghg/update/'.encode_id($row->GhgId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/ghg/delete/'.encode_id($row->GhgId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = array_merge([
'no' => $key+1,
'id' => encode_id($row->GhgId),
'kode' => '<input name="ghg[]" type="hidden" value="'.encode_id($row->GhgId).'" class="form-control">'.@$row->kode,
'nama' => @$row->deskripsi,
'status' => @$status,
'action' => @$action,
],$_ardata);
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$post = request()->all();
$ghg_list = $post['ghg'] ?? [];
$ghg_count = count($ghg_list);
$ar_inputs = [];
try {
foreach ($post as $k => $v) {
if (\Str::startsWith($k, 'ar_')) {
// ekstrak ArId dari nama, format di code sebelumnya: ar_{ArId}_{kode}
if (preg_match('/^ar_(\d+)_/', $k, $m)) {
$arId = (int) $m[1];
} else {
// fallback: jika tidak ada angka, gunakan seluruh key (atau handle sesuai kebutuhan)
// skip jika tidak bisa ambil ArId
continue;
}
$ar_inputs[$arId] = array_values((array) $v); // cast ke array & reindex
}
}
foreach ($ar_inputs as $arId => $vals) {
$len = count($vals);
if ($len < $ghg_count) {
$ar_inputs[$arId] = array_pad($vals, $ghg_count, null);
} elseif ($len > $ghg_count) {
$ar_inputs[$arId] = array_slice($vals, 0, $ghg_count);
}
}
$inserts = [];
$now = now();
for ($i = 0; $i < $ghg_count; $i++) {
// decode ghg id (sesuaikan fungsi decode_id)
$ghgEncoded = $ghg_list[$i];
$ghgId = decode_id($ghgEncoded);
foreach ($ar_inputs as $arId => $vals) {
$rawValue = $vals[$i];
$value = is_string($rawValue) ? trim($rawValue) : $rawValue;
if ($value === '') $value = null;
$inserts[] = [
'ghg_id' => $ghgId,
'ar_id' => $arId,
'value' => $value,
'created_at'=> $now,
'updated_at'=> $now,
];
}
}
\DB::transaction(function () use ($inserts) {
$chunkSize = 500;
foreach (array_chunk($inserts, $chunkSize) as $chunk) {
foreach ($chunk as $row) {
GWP::updateOrCreate(
[
'ghg_id' => $row['ghg_id'],
'ar_id' => $row['ar_id'],
],[
'value' => @$row['value'] ? @$row['value'] : 0
]
);
}
}
});
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,170 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Kategori;
class KategoriController extends Controller
{
protected $title = 'Kategori';
protected $template = 'modules.pengaturan.kategori';
protected $route = 'modules.pengaturan.kategori';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Kategori','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = Kategori::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->KategoriId).'" href="'.url('pengaturan/kategori/update/'.encode_id($row->KategoriId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/kategori/delete/'.encode_id($row->KategoriId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->KategoriId),
'alias' => @$row->alias,
'nama' => @$row->nama,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'nama' => 'required|string|max:255',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = Kategori::find($keyId);
$data->alias = str_replace(' ','_',strtolower($request->nama));
$data->nama = $request->nama;
$data->status = $request->status;
$data->save();
}else{
$data = new Kategori;
$data->alias = str_replace(' ','_',strtolower($request->nama));
$data->nama = $request->nama;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Kategori','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = Kategori::where('KategoriId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = Kategori::where('KategoriId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\FilePengumuman;
class PengumumanController extends Controller
{
protected $title = 'Pengumuman/Peraturan';
protected $template = 'modules.pengaturan.pengumuman';
protected $route = 'modules.pengaturan.pengumuman';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Pengumuman/Peraturan','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FilePengumuman::all();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FilePengumumanId).'" href="'.url('pengaturan/pengumuman/update/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/pengumuman/delete/'.encode_id($row->FilePengumumanId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FilePengumumanId),
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/pengumuman');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'pengumuman/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FilePengumuman::find($keyId);
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FilePengumuman;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FilePengumuman::where('FilePengumumanId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FilePengumuman::where('FilePengumumanId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,187 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\SumberDataEF;
class SumberDataEFController extends Controller
{
protected $title = 'Sumber Data EF';
protected $template = 'modules.pengaturan.sumberdata-ef';
protected $route = 'modules.pengaturan.sumberdata-ef';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Sumber Data EF','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = SumberDataEF::orderBy('nomor_baris','ASC')->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->SumberDataId).'" href="'.url('pengaturan/sumberdata-ef/update/'.encode_id($row->SumberDataId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/sumberdata-ef/delete/'.encode_id($row->SumberDataId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->SumberDataId),
'kode' => @$row->kode,
'nama' => @$row->nama,
'deskripsi' => @$row->deskripsi,
'nomor_baris' => @$row->nomor_baris,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'kode' => 'required|string|max:255|unique:p_sumberdata_ef,kode',
'nama' => 'required|string|max:255',
'deskripsi' => 'required|string',
'nomor_baris' => 'required|numeric',
],[
'kode.unique' => 'Kode Tidak Boleh Sama',
'nomor_baris.numeric' => 'Nomor Baris Harus Berupa Angka',
'kode.required' => 'Tidak Boleh Kosong',
'nama.required' => 'Tidak Boleh Kosong',
'deskripsi.required' => 'Tidak Boleh Kosong',
'nomor_baris.required' => 'Tidak Boleh Kosong',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = SumberDataEF::find($keyId);
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}else{
$data = new SumberDataEF;
$data->kode = $request->kode;
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'AR','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = SumberDataEF::where('SumberDataId',$keyId)->first();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = SumberDataEF::where('SumberDataId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,180 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Unit;
use App\Models\Kategori;
class UnitController extends Controller
{
protected $title = 'Unit';
protected $template = 'modules.pengaturan.unit';
protected $route = 'modules.pengaturan.unit';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Unit','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = Unit::orderBy('UnitId','ASC')->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->UnitId).'" href="'.url('pengaturan/unit/update/'.encode_id($row->UnitId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/unit/delete/'.encode_id($row->UnitId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->UnitId),
'kode' => @$row->kode,
'kategori' => @$row->kategori->nama,
'nama' => @$row->nama,
'nomor_baris' => @$row->nomor_baris,
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->validate([
'nama' => 'required|string|max:255',
]);
try {
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = Unit::find($keyId);
$data->kategori_id = decode_id($request->kategori_id);
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->kode = $request->kode;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}else{
$data = new Unit;
$data->kategori_id = decode_id($request->kategori_id);
$data->nama = $request->nama;
$data->deskripsi = $request->deskripsi;
$data->kode = $request->kode;
$data->nomor_baris = $request->nomor_baris;
$data->status = $request->status;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Unit','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = Unit::where('UnitId',$keyId)->first();
$data['kategori'] = Kategori::all();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = Unit::where('UnitId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,198 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use App\Models\Unit;
use App\Models\UnitKonversi;
use App\Models\Kategori;
class UnitKonversiController extends Controller
{
protected $title = 'Unit Konversi';
protected $template = 'modules.pengaturan.unit-conversion';
protected $route = 'modules.pengaturan.unit-conversion';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Unit Konversi','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['kategori'] = Kategori::all();
$data['unit'] = Unit::where('kategori_id',decode_id(@request()->kategori_id))->get();
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
if(@$request->kategori_id){
$data = Unit::where('kategori_id',decode_id($request->kategori_id))->orderBy('UnitId','ASC')->get();
}else{
$data = [];
}
$_data = [];
foreach ($data as $key => $row) {
//unit to
foreach ($data as $keyAr => $rowAr) {
$_ardata['input_'.$rowAr->UnitId.'_'.strtolower($rowAr->kode)] = '<input name="val_'.$row->UnitId.'_'.$rowAr->UnitId.'" type="text" value="'.@valueUnitKonversion($row->kategori->KategoriId,$row->UnitId,$rowAr->UnitId).'" class="form-control">';
}
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$unit = Unit::where('kode',$row->kode)->first();
// $input = '<div class="append"></div>';
// $input = '';
// $input .= '<input type="text" value="0" class="form-control" name="val_'.@$unit->UnitId.'[]">';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->UnitId).'" href="'.url('pengaturan/unit/update/'.encode_id($row->UnitId)).'" data-toggle="tooltip" title="Simpan Perubahan Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-content-save-outline text-white"></i></a>';
// $action .= '<a data-id="'.encode_id($row->UnitId).'" href="'.url('pengaturan/unit/update/'.encode_id($row->UnitId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
// $action .= '<a href="#" data-href="'.url('pengaturan/unit/delete/'.encode_id($row->UnitId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = array_merge([
'no' => $key+1,
'id' => encode_id($row->UnitId),
'kategori' => @$row->kategori->nama,
'nama' => @$row->nama,
'kategoriID' => @$row->kategori->KategoriId,
'UnitId' => $unit->UnitId,
'status' => @$status,
'input' => @$input,
'action' => @$action,
],$_ardata);
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$kategoriId = decode_id($request->kategori_id);
foreach ($request->all() as $key => $value) {
// pastikan key diawali "val_"
if (!str_starts_with($key, 'val_')) {
continue;
}
// pecah: "val_6_17" -> ["val", "6", "17"]
$parts = explode('_', $key);
// jaga-jaga kalau format gak sesuai
if (count($parts) !== 3) {
continue;
}
$fromId = (int) $parts[1];
$toId = (int) $parts[2];
// skip kalau value kosong (opsional)
if ($value === null || $value === '') {
continue;
}
UnitKonversi::updateOrCreate(
['kategori_id' => $kategoriId, 'from_id' => $fromId, 'to_id' => $toId],
['value' => $value, 'updated_at' => now()]
);
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Unit Konversi','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = UnitKonversi::where('UnitKonversiId',$keyId)->first();
$data['kategori'] = Kategori::all();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = UnitKonversi::where('UnitKonversiId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -1,219 +0,0 @@
<?php
namespace App\Http\Controllers\Pengaturan;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Models\SumberDataEF;
use App\Models\FileDataAktivitas;
use App\Models\Master\Sektor;
class UploadAktifitasController extends Controller
{
protected $title = 'Data Aktifitas';
protected $template = 'modules.pengaturan.upload-aktifitas';
protected $route = 'modules.pengaturan.upload-aktifitas';
/**
* Display a listing of the resource.
*/
public function index()
{
permission('is_read', $this->route, 'module',true);
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Data Aktifitas','active' => true],
];
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['sektor'] = Sektor::all();
return view($this->template.'.index',$data);
}
public function grid(Request $request)
{
$data = FileDataAktivitas::with(['sektor'])->get();
$_data = [];
foreach ($data as $key => $row) {
$action = '';
$status = '';
if($row->status == 0){
$status = '<span class="btn btn-sm btn-block btn-danger"> Tidak Aktif </span>';
}else{
$status = '<span class="btn btn-sm btn-block btn-success"> Aktif </span>';
}
$file = '<a download href="'.asset($row->file).'" class="btn btn-sm w-100 btn-success"><i class="mdi mdi-download text-white"></i></a>';
$action .= '<div class="d-flex gap-1">';
if((permission('is_create', $this->route.'.*','module',false)) || (permission('is_update', $this->route.'.*','module',false))){
$action .= '<a data-id="'.encode_id($row->FileDataAktivitasId).'" href="'.url('pengaturan/upload-aktifitas/update/'.encode_id($row->FileDataAktivitasId)).'" data-toggle="tooltip" title="Edit Data" class="btn btn-sm btn-block btn-primary"><i class="mdi mdi-pencil text-white"></i></a>';
if(session('group_id') == 1){
$action .= '<a href="#" data-href="'.url('pengaturan/upload-aktifitas/delete/'.encode_id($row->FileDataAktivitasId)).'" data-toggle="tooltip" title="Edit Data" class="remove_data btn btn-sm btn-block btn-danger"><i class="mdi mdi-delete text-white"></i></a>';
}
}
$action .= '</div>';
$_data[] = [
'no' => $key+1,
'id' => encode_id($row->FileDataAktivitasId),
'sektor' => @$row->sektor->nama,
'tahun' => @$row->tahun,
'nama' => @$row->nama,
'file' => @$file,
'created_at' => date('d-m-Y H:i:s',strtotime(@$row->created_at)),
'status' => @$status,
'action' => @$action,
];
}
// return response()->json($_data); // Return the data as a JSON response
return response()->json($_data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// dd(request()->all());
$request->validate([
'sektor' => 'required',
'tahun' => 'required',
'nama' => 'required',
'file' => 'required|file|mimes:xls,xlsx,pdf,png,jpg,jpeg,docx|max:2000',
]);
try {
if (@$request->file) {
$file = $request->file;
$destinationPath = public_path('uploads/data_aktifitas');
$current = Carbon::now()->format('Y/m/d');
$path = $destinationPath . '/' . $current;
$fileName = $file->getClientOriginalName();
$fileMime = $file->getClientMimeType();
$fileExtension = $file->getClientOriginalExtension();
$fileSize = $file->getSize();
if(($fileExtension != 'xls') && ($fileExtension != 'xlsx') && ($fileExtension != 'pdf') && ($fileExtension != 'docx') && ($fileExtension != 'png') && ($fileExtension != 'jpg') && ($fileExtension != 'jpeg') ){
return redirect()->back()->with([
'message' => 'Maaf File Harus Berupa xls,xlsx,pdf,png,jpg,jpeg,docx!',
'type' => "error"
]);
}
$newFilename = session('id').'_'.uniqid('file_') . '.' . $fileExtension;
if (!File::exists($path)) {
File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
}
$filePath = 'data_aktifitas/' . $current . '/' . $newFilename;
$uploaded = $file->move($path, $newFilename);
}
if(@request()->secure_id){
$keyId = decode_id(@request()->secure_id);
$data = FileDataAktivitas::find($keyId);
$data->ms_sektor_id = decode_id($request->sektor);
$data->ms_subsektor_id = @$request->subsektor ? decode_id($request->subsektor) : NULL;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}else{
$data = new FileDataAktivitas;
$data->ms_sektor_id = decode_id($request->sektor);
$data->ms_subsektor_id = @$request->subsektor ? decode_id($request->subsektor) : NULL;
$data->tahun = $request->tahun;
$data->nama = $request->nama;
$data->file = $filePath;
$data->deskripsi = $request->deskripsi;
$data->save();
}
return redirect()->back()->with([
'message' => 'Berhasil update data',
'type' => 'success',
]);
} catch (\Exception $e) {
return redirect()->back()->with([
'message' => 'Gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage(),
'type' => 'error',
]);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update($id = null)
{
$data['breadcrumbs'] = [
['name' => 'Dashboard'],
['name' => 'Pengaturan'],
['name' => 'Data Aktivitas','active' => true],
];
$keyId = decode_id($id);
$data['title'] = $this->title;
$data['route'] = $this->route;
$data['keyId'] = $id;
$data['item'] = FileDataAktivitas::where('FileDataAktivitasId',$keyId)->first();
$data['sektor'] = Sektor::all();
return view($this->template.'.form',$data);
}
public function delete($id)
{
$keyId = decode_id($id);
$data = FileDataAktivitas::where('FileDataAktivitasId',$keyId)->delete();
return response()->json(['success' => true,'message' => 'Berhasil update data','type' => 'success']);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

Some files were not shown because too many files have changed in this diff Show More