- Menambahkan command baru `webstatement:combine-pdf` melalui `CombinePdf` untuk menjalankan proses penggabungan file PDF. - Proses ini mencakup penggabungan file PDF dari folder r14 dan r23 berdasarkan periode tertentu. - File PDF yang dihasilkan juga dilindungi dengan password berbasis nomor rekening. - Membuat controller `CombinePdfController` dengan fungsi utama `combinePdfs` untuk mengontrol alur penggabungan file PDF: - Mendapatkan daftar akun yang relevan. - Mengecek file dari folder r14 dan r23 untuk setiap akun. - Melakukan logging saat file tidak ditemukan atau jika terdapat error dalam proses. - Mendaftarkan job `CombinePdfJob` untuk memproses file secara async. - Menambahkan job baru `CombinePdfJob`: - Menggunakan library `PDFMerger` untuk menggabungkan file. - Terapkan proteksi password menggunakan library `PDFPasswordProtect`. - Memastikan direktori output dibuat jika belum ada. - Melakukan logging saat proses berhasil maupun saat terjadi error. - Memperbarui `WebstatementServiceProvider`: - Mendaftarkan command baru ke dalam provider. - Menambahkan penjadwalan otomatis untuk menjalankan perintah `webstatement:combine-pdf` setiap hari pada pukul 09:30. - Logging hasil eksekusi ke file log `logs/combine-pdf.log`. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
171 lines
5.8 KiB
PHP
171 lines
5.8 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\CombinePdf;
|
|
use Modules\Webstatement\Console\ExportDailyStatements;
|
|
use Modules\Webstatement\Console\ProcessDailyMigration;
|
|
use Modules\Webstatement\Console\GenerateBiayakartuCommand;
|
|
use Modules\Webstatement\Jobs\UpdateAtmCardBranchCurrencyJob;
|
|
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
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 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'));
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|