Skip to content

Commit

Permalink
Merge pull request #331 from OpenSID/rilis-v2311.0.0
Browse files Browse the repository at this point in the history
Rilis v2311.0.0
  • Loading branch information
vickyrolanda authored Nov 1, 2023
2 parents 409dbad + 95c733f commit 0aa1b66
Show file tree
Hide file tree
Showing 112 changed files with 2,118 additions and 456 deletions.
17 changes: 9 additions & 8 deletions app/Console/Commands/CrudAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CrudAll extends Command
* @var string
*/
protected $description = 'Generate scaffold infyom ';

private $files;

/**
Expand All @@ -44,10 +45,10 @@ public function handle()
$module = $this->option('module');
$connection = $this->option('connection');
$jsonData = [];
if (!empty($filepath)) {
if (! empty($filepath)) {
$this->info($filepath);
if (file_exists($filepath)) {
if (!is_readable($filepath)) {
if (! is_readable($filepath)) {
$this->error('File can\'t read');

return false;
Expand All @@ -63,26 +64,26 @@ public function handle()
}
} else {
$tmpJson = [];
if (!empty($table)) {
if (! empty($table)) {
$this->info('table ==>'.$table);
$tmpJson['tables'] = explode(',', $table);
$tmpJson['module'] = '';
}

if (!empty($module)) {
if (! empty($module)) {
$this->info('module ==>'.$module);
$tmpJson['module'] = $module;
}

if (!empty($connection)) {
if (! empty($connection)) {
$tmpJson['connection'] = $connection;
}
if (!empty($tmpJson)) {
if (! empty($tmpJson)) {
array_push($jsonData, $tmpJson);
}
}

if (!empty($jsonData)) {
if (! empty($jsonData)) {
$this->processJson($jsonData);
}

Expand Down Expand Up @@ -121,7 +122,7 @@ private function processJson($jsonData)

$this->call('crud-transformer', [
'model' => $model,
'--table' => $t
'--table' => $t,
]);

// $this->generatePermission(Str::snake($t));
Expand Down
178 changes: 178 additions & 0 deletions app/Console/Commands/GenerateDataDemo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

namespace App\Console\Commands;

use App\Models\Bantuan;
use App\Models\BantuanPeserta;
use App\Models\ClusterDesa;
use App\Models\Config;
use App\Models\Kategori;
use App\Models\Keluarga;
use App\Models\LogKeluarga;
use App\Models\LogPenduduk;
use App\Models\Penduduk;
use App\Models\Rtm;
use Database\Seeders\ArtikelDemoSeeder;
use Database\Seeders\BantuanDemoSeeder;
use Database\Seeders\ConfigDemoSeeder;
use Database\Seeders\KategoriDemoSeeder;
use Database\Seeders\KeluargaDemoSeeder;
use Database\Seeders\RTMDemoSeeder;
use Database\Seeders\WilayahDemoSeeder;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GenerateDataDemo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'openkab:demo-data {--kodekabupaten=} {--minpenduduk=} {--maxpenduduk=} {--append}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate data dummy untuk openkab contoh php artisan openkab:demo-data --kodekabupaten=35.25 --minpenduduk=1000 --maxpenduduk=5000';

private $listClass = [
Config::class,
ClusterDesa::class,
Penduduk::class,
Keluarga::class,
LogPenduduk::class,
LogKeluarga::class,
Rtm::class,
Bantuan::class,
BantuanPeserta::class,
Kategori::class,
];

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$minPenduduk = $this->option('minpenduduk') ?? 100;
$maxPenduduk = $this->option('maxpenduduk') ?? $minPenduduk * 2;
$kodekabupaten = $this->option('kodekabupaten');
$reset = 1;
$append = $this->option('append');
$this->info('set minimal jumlah penduduk '.$minPenduduk);
$this->info('set maksimal jumlah penduduk '.$maxPenduduk);
$this->info('set kode kabupaten '.$kodekabupaten);
$this->info('set nilai append '.$append);

if ($append) {
$reset = 0;
}
$this->info('set nilai reset '.$reset);

config()->set('seeder.config.kode_kabupaten', $kodekabupaten);
DB::connection('openkab')->statement('SET foreign_key_checks=0');

if ($reset) {
$this->reset();
$this->seedConfig();
$this->seedKategoriBerita();
$this->seedArtikel();
}

config()->set('seeder.keluarga.anggota_min', 2);
config()->set('seeder.keluarga.anggota_max', 5);
config()->set('seeder.bantuan.program_min', 1);
config()->set('seeder.bantuan.program_max', 3);
config()->set('seeder.bantuan.peserta_min', 5);
config()->set('seeder.bantuan.peserta_max', 20);
Config::select(['id', 'nama_desa'])->get()->each(function ($item) use ($minPenduduk, $maxPenduduk, $reset) {
config()->set('seeder.penduduk.max', fake()->numberBetween($minPenduduk, $maxPenduduk));
config()->set('seeder.wilayah.desa_aktif', $item->id);
config()->set('seeder.wilayah.desa_nama_aktif', $item->nama_desa);
$this->seedDataDesa($reset);
});

DB::connection('openkab')->statement('SET foreign_key_checks=1');
}

private function reset()
{
foreach ($this->listClass as $class) {
$tableObj = new $class;
$tableObj->truncate();
$this->info('hapus data pada tabel '.$tableObj->getTable().' dan reset auto_increment berhasil');
}
}

private function seedConfig()
{
$exitCode = Artisan::call('db:seed', ['--class' => ConfigDemoSeeder::class]);
$output = Artisan::output();
Log::error($output);
$this->info($output);
}

private function seedDataDesa($reset)
{
if ($reset) {
$this->seedWilayah();
}
$this->seedKeluarga();
$this->seedRumahTangga();
$this->seedBantuan();
}

private function seedWilayah()
{
$exitCode = Artisan::call('db:seed', ['--class' => WilayahDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}

private function seedKeluarga()
{
$exitCode = Artisan::call('db:seed', ['--class' => KeluargaDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}

private function seedRumahTangga()
{
$exitCode = Artisan::call('db:seed', ['--class' => RTMDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}

private function seedBantuan()
{
$exitCode = Artisan::call('db:seed', ['--class' => BantuanDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}

private function seedKategoriBerita()
{
$exitCode = Artisan::call('db:seed', ['--class' => KategoriDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}

private function seedArtikel()
{
$exitCode = Artisan::call('db:seed', ['--class' => ArtikelDemoSeeder::class]);
$output = Artisan::output();
Log::info($output);
$this->info($output);
}
}
8 changes: 4 additions & 4 deletions app/Console/Commands/TransformerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public function generate()
public function variables(): array
{
return [
'transforms' => implode(','.infy_nl_tab(1, 2), $this->generateTransforms()),
'transforms' => implode(','.infy_nl_tab(1, 2), $this->generateTransforms()),
];
}

protected function generateTransforms(): array
{
$transforms = [];
if (isset($this->config->fields) && !empty($this->config->fields)) {
$modelName = Str::lower($this->config->modelNames->name);
if (isset($this->config->fields) && ! empty($this->config->fields)) {
$modelName = Str::lower($this->config->modelNames->name);
foreach ($this->config->fields as $field) {
$transforms[] = "'".$field->name."' => \$". $modelName."->".$field->name;
$transforms[] = "'".$field->name."' => \$".$modelName.'->'.$field->name;
}
}

Expand Down
13 changes: 7 additions & 6 deletions app/Console/Commands/updateAdminMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\Modul;
use App\Models\Team;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

Expand All @@ -31,8 +32,9 @@ class updateAdminMenu extends Command
*/
public function handle()
{
Artisan::call('cache:clear');
$team = Team::whereName('administrator')->first();

setPermissionsTeamId($team->id);
if ($team) {
$team->menu = Modul::Menu;
$team->save();
Expand All @@ -49,22 +51,21 @@ public function handle()
$role->syncPermissions($permissions);
}


return Command::SUCCESS;
}

private function collectPermissions(){
private function collectPermissions()
{
$permissions = [];
foreach (Modul::Menu as $main_menu) {
foreach(Modul::permision as $permission){
foreach (Modul::permision as $permission) {
$permissionName = $main_menu['permission'].'-'.$permission;
Permission::findOrCreate($permissionName, 'web');
$permissions[] = $permissionName;

}
if (isset($main_menu['submenu'])) {
foreach ($main_menu['submenu'] as $sub_menu) {
foreach(Modul::permision as $permission){
foreach (Modul::permision as $permission) {
$permissionName = $sub_menu['permission'].'-'.$permission;
Permission::findOrCreate($permissionName, 'web');
$permissions[] = $permissionName;
Expand Down
2 changes: 1 addition & 1 deletion app/Enums/Modul.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class Modul extends Enum
'text' => 'Kategori Artikel',
'url' => 'master/kategori/0',
'permission' => 'master-data-artikel',
]
],
],
],

Expand Down
33 changes: 22 additions & 11 deletions app/Helpers/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
function openkab_versi()
{
return 'v2310.0.0';
return 'v2311.0.0';
}
}

Expand Down Expand Up @@ -214,6 +214,7 @@ function default_favicon($favicon)
function date_from_format($value, $format = null)
{
\Log::error($value);

return Carbon::createFromFormat($format ?? config('app.format.date'), $value);
}
}
Expand All @@ -238,13 +239,12 @@ function getDescription()
}
}


if (!function_exists('generateMenu')) {
if (! function_exists('generateMenu')) {
function generateMenu($tree, $parentId = null)
{
$result = '';
foreach($tree as $item){
if($item->children->count() > 0){
foreach ($tree as $item) {
if ($item->children->count() > 0) {
$classLink = empty($parentId) ? 'nav-link' : 'dropdown-item';
$result .= "
<li class='nav-item dropdown'>
Expand All @@ -253,19 +253,30 @@ function generateMenu($tree, $parentId = null)
</a>
<ul class='dropdown-menu'>";
$result .= generateMenu($item->children, $item->id);
$result .= "
$result .= '
</ul>
</li>";
}else {
if ($parentId){
</li>';
} else {
if ($parentId) {
$result .= "<li><a class='dropdown-item' href='{$item->href}'>{$item->text}</a></li>";
}else {
} else {
$result .= "<li class='nav-item'><a href='{$item->href}' class='nav-link'>{$item->text}</a></li>";
}

}
}

return $result;
}
}

if (! function_exists('angka_lokal')) {
/**
* Menampilkan nilai persentase.
*
* return decimal
*/
function angka_lokal($angka, $decimal = 0)
{
return number_format($angka, $decimal, ',', '.');
}
}
Loading

0 comments on commit 0aa1b66

Please sign in to comment.