Perubahan yang dilakukan: - Menambahkan command AutoSendStatementEmailCommand untuk otomatisasi pengiriman email statement. - Menambahkan job AutoSendStatementEmailJob untuk menangani proses pengiriman email secara asynchronous. - Menambahkan opsi --force dan --dry-run pada command untuk fleksibilitas eksekusi dan pengujian. - Mengintegrasikan command baru ke dalam WebstatementServiceProvider dan Console Kernel. - Mengimplementasikan scheduler untuk menjalankan job setiap menit secara otomatis. - Menambahkan kondisi auto send: is_available dan is_generated = true, email_sent_at = null. - Mendukung pengiriman statement multi-period dalam bentuk ZIP attachment. - Mengoptimalkan proses download dan integrasi file PDF dengan logging yang lebih detail. - Menambahkan logika prioritas local disk dibandingkan SFTP untuk pengambilan file secara efisien. - Menambahkan validasi tambahan untuk flow pengiriman email single dan multi period. - Mengimplementasikan error handling dan logging yang komprehensif. - Menggunakan database transaction untuk menjamin konsistensi data selama proses kirim email. - Menambahkan mekanisme prevent overlap dan timeout protection saat job berjalan. - Menghapus file sementara secara otomatis setelah email berhasil dikirim. - Membatasi proses pengiriman maksimal 50 statement per run untuk menjaga performa. Tujuan perubahan: - Mengotomatiskan pengiriman email statement pelanggan secara periodik dan aman. - Menyediakan fleksibilitas eksekusi manual dan simulasi pengujian sebelum produksi. - Menjamin efisiensi, stabilitas, dan monitoring penuh selama proses pengiriman.
198 lines
7.1 KiB
PHP
198 lines
7.1 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;
|
|
use Modules\Webstatement\Console\CombinePdf;
|
|
use Modules\Webstatement\Console\ConvertHtmlToPdf;
|
|
use Modules\Webstatement\Console\ExportDailyStatements;
|
|
use Modules\Webstatement\Console\ProcessDailyMigration;
|
|
use Modules\Webstatement\Console\ExportPeriodStatements;
|
|
use Modules\Webstatement\Console\UpdateAllAtmCardsCommand;
|
|
use Modules\Webstatement\Console\CheckEmailProgressCommand;
|
|
use Modules\Webstatement\Console\AutoSendStatementEmailCommand;
|
|
use Modules\Webstatement\Console\GenerateBiayakartuCommand;
|
|
use Modules\Webstatement\Console\SendStatementEmailCommand;
|
|
use Modules\Webstatement\Jobs\UpdateAtmCardBranchCurrencyJob;
|
|
use Modules\Webstatement\Console\GenerateAtmTransactionReport;
|
|
use Modules\Webstatement\Console\GenerateBiayaKartuCsvCommand;
|
|
|
|
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
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|