Files
webstatement/app/Providers/WebstatementServiceProvider.php
Daeng Deni Mardaeni d4ef7280ce feat(webstatement): tambahkan command dan job untuk generate CSV biaya kartu ATM
- Tambahkan `GenerateBiayaKartuCsvCommand` untuk membuat file CSV biaya kartu ATM melalui console command.
- Implementasikan job `GenerateBiayaKartuCsvJob` sebagai pengganti proses manual pembuatan CSV di controller.
- Hapus logika pembuatan CSV manual di `BiayaKartuController`.
- Update scheduler untuk menjalankan command baru (`webstatement:generate-biaya-kartu-csv`) setiap tanggal 15 pukul 00:00.
- Perbarui waktu schedule command `webstatement:generate-biaya-kartu` menjadi pukul 22:00 setiap tanggal 14.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
2025-05-09 09:07:39 +07:00

135 lines
3.9 KiB
PHP

<?php
namespace Modules\Webstatement\Providers;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Webstatement\Console\GenerateBiayakartuCommand;
use Nwidart\Modules\Traits\PathNamespace;
class WebstatementServiceProvider extends ServiceProvider
{
use PathNamespace;
protected string $name = 'Webstatement';
protected string $nameLower = 'webstatement';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
if (class_exists('Breadcrumbs')) {
require __DIR__ . '/../../routes/breadcrumbs.php';
}
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
$this->commands([
GenerateBiayakartuCommand::class,
GenerateBiayakartuCommand::class
]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
$schedule = $this->app->make(Schedule::class);
$schedule->command('webstatement:generate-biaya-kartu')
->monthlyOn(14, '22:00')
->appendOutputTo(storage_path('logs/biaya-kartu-scheduler.log'));
$schedule->command('webstatement:generate-biaya-kartu-csv')
->monthlyOn(15, '00:00')
->appendOutputTo(storage_path('logs/biaya-kartu-csv-scheduler.log'));
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
Blade::componentNamespace($componentNamespace, $this->nameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}