Files
webstatement/app/Providers/WebstatementServiceProvider.php
Daeng Deni Mardaeni 3c01c1728c feat(webstatement): tambah console command dan perbaikan field required untuk laporan closing balance
Menambahkan fitur command line untuk generate laporan closing balance sekaligus memperbaiki pengisian field yang required di database.

Perubahan yang dilakukan:
- Membuat command `webstatement:generate-closing-balance-report` dengan parameter:
  - `account_number`: nomor rekening (required)
  - `period`: format tanggal YYYYMMDD (required)
  - `--user_id=`: ID user (optional, default 1)
- Menambahkan field `report_date` dengan konversi dari parameter `period` menggunakan Carbon
- Menambahkan field `created_by` dan `updated_by` untuk kebutuhan audit trail
- Menambahkan field `ip_address` dan `user_agent` dengan default 'console' untuk identifikasi proses non-web
- Memperbaiki validasi parameter dengan regex dan proper escaping
- Menghindari error SQLSTATE[23502] terkait field not null di database schema
- Menggunakan database transaction untuk menjaga konsistensi data
- Mengupdate fungsi `closing_balance_report_logs` untuk menyimpan semua field yang dibutuhkan
- Integrasi dengan `GenerateClosingBalanceReportJob` untuk pemrosesan laporan secara background
- Menambahkan logging komprehensif untuk monitoring `report_date` dan proses lainnya
- Mendukung eksekusi manual dan penjadwalan via Laravel scheduler
- Kompatibel dengan proses laporan closing balance via web dan CLI

Tujuan perubahan:
- Mempermudah proses generate laporan closing balance melalui CLI secara manual atau terjadwal
- Memastikan seluruh field wajib di `closing_balance_report_logs` terisi dengan benar
- Menyediakan audit trail lengkap dan logging yang detail untuk proses via console
- Meningkatkan keandalan sistem dengan validasi dan error handling yang lebih baik
2025-07-18 07:36:02 +07:00

202 lines
6.9 KiB
PHP

<?php
namespace Modules\Webstatement\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use Illuminate\Console\Scheduling\Schedule;
use Modules\Webstatement\Console\{
UnlockPdf,
CombinePdf,
ConvertHtmlToPdf,
ExportDailyStatements,
ProcessDailyMigration,
ExportPeriodStatements,
UpdateAllAtmCardsCommand,
CheckEmailProgressCommand,
GenerateBiayakartuCommand,
SendStatementEmailCommand,
GenerateAtmTransactionReport,
GenerateBiayaKartuCsvCommand,
AutoSendStatementEmailCommand,
GenerateClosingBalanceReportCommand
};
use Modules\Webstatement\Jobs\UpdateAtmCardBranchCurrencyJob;
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);
$this->app->bind(UpdateAtmCardBranchCurrencyJob::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
$this->commands([
GenerateBiayakartuCommand::class,
GenerateBiayaKartuCsvCommand::class,
ProcessDailyMigration::class,
ExportDailyStatements::class,
CombinePdf::class,
ConvertHtmlToPdf::class,
UnlockPdf::class,
ExportPeriodStatements::class,
GenerateAtmTransactionReport::class,
SendStatementEmailCommand::class,
CheckEmailProgressCommand::class,
UpdateAllAtmCardsCommand::class,
AutoSendStatementEmailCommand::class,
GenerateClosingBalanceReportCommand::class,
]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
$schedule = $this->app->make(Schedule::class);
// Mengambil tanggal dan waktu dari file .env untuk biaya kartu
$biayaKartuDay = env('BIAYA_KARTU_SCHEDULER_DAY', 14); // Default ke tanggal 14
$biayaKartuTime = env('BIAYA_KARTU_SCHEDULER_TIME', '22:00'); // Default ke jam 22:00
// Mengambil tanggal dan waktu dari file .env untuk biaya kartu CSV
$biayaKartuCsvDay = env('BIAYA_KARTU_CSV_SCHEDULER_DAY', 15); // Default ke tanggal 15
$biayaKartuCsvTime = env('BIAYA_KARTU_CSV_SCHEDULER_TIME', '00:00'); // Default ke jam 00:00
// Menjadwalkan job biaya kartu menggunakan nilai dari .env
$schedule->command('webstatement:generate-biaya-kartu')
->monthlyOn((int)$biayaKartuDay, $biayaKartuTime)
->appendOutputTo(storage_path('logs/biaya-kartu-scheduler.log'));
// Menjadwalkan job biaya kartu CSV menggunakan nilai dari .env
$schedule->command('webstatement:generate-biaya-kartu-csv')
->monthlyOn((int)$biayaKartuCsvDay, $biayaKartuCsvTime)
->appendOutputTo(storage_path('logs/biaya-kartu-csv-scheduler.log'));
// Schedule the daily migration process to run at 1:00 AM (from previous task)
$schedule->command('webstatement:process-daily-migration')
->dailyAt('09:00')
->withoutOverlapping()
->appendOutputTo(storage_path('logs/daily-migration.log'));
// Schedule the statement export to run at 2:00 AM (after migration is likely complete)
$schedule->command('webstatement:export-statements')
->dailyAt('09:30')
->withoutOverlapping()
->appendOutputTo(storage_path('logs/statement-export.log'));
// Combine PDf
$schedule->command('webstatement:combine-pdf')
->dailyAt('09:30')
->withoutOverlapping()
->appendOutputTo(storage_path('logs/combine-pdf.log'));
// Convert HTML to PDF
$schedule->command('webstatement:convert-html-to-pdf')
->dailyAt('09:30')
->withoutOverlapping()
->appendOutputTo(storage_path('logs/convert-html-to-pdf.log'));
// Unlock PDF
$schedule->command('webstatement:unlock-pdf')
->dailyAt('09:30')
->withoutOverlapping()
->appendOutputTo(storage_path('logs/unlock-pdf.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;
}
}