- Menambahkan `AccountBalanceService` dengan transaksi PostgreSQL dan proper error handling. - Implementasi `BalanceServiceProvider` untuk mendukung dependency injection pattern. - Registrasi `BalanceServiceProvider` dalam `WebstatementServiceProvider`. - Penambahan `CAST` ke `DECIMAL(15,2)` untuk kompatibilitas PostgreSQL. - Perhitungan balance summary mencakup opening balance dan closing balance. - Agregasi transaksi dengan type casting yang aman. - Implementasi database transaction handling dengan mekanisme rollback dan commit. - Logging komprehensif untuk debugging dan audit trail. - Mendukung balance inquiry berdasarkan tanggal maupun periode tertentu. - Validasi akun dengan pengecekan `exists` untuk memastikan data valid.
205 lines
7.0 KiB
PHP
205 lines
7.0 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,
|
|
ProcessDailyStaging,
|
|
ExportPeriodStatements,
|
|
UpdateAllAtmCardsCommand,
|
|
CheckEmailProgressCommand,
|
|
GenerateBiayakartuCommand,
|
|
SendStatementEmailCommand,
|
|
GenerateAtmTransactionReport,
|
|
GenerateBiayaKartuCsvCommand,
|
|
AutoSendStatementEmailCommand,
|
|
GenerateClosingBalanceReportCommand,
|
|
GenerateClosingBalanceReportBulkCommand,
|
|
};
|
|
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->register(BalanceServiceProvider::class);
|
|
$this->app->bind(UpdateAtmCardBranchCurrencyJob::class);
|
|
}
|
|
|
|
/**
|
|
* Register commands in the format of Command::class
|
|
*/
|
|
protected function registerCommands(): void
|
|
{
|
|
$this->commands([
|
|
GenerateBiayakartuCommand::class,
|
|
GenerateBiayaKartuCsvCommand::class,
|
|
ProcessDailyStaging::class,
|
|
ExportDailyStatements::class,
|
|
CombinePdf::class,
|
|
ConvertHtmlToPdf::class,
|
|
UnlockPdf::class,
|
|
ExportPeriodStatements::class,
|
|
GenerateAtmTransactionReport::class,
|
|
SendStatementEmailCommand::class,
|
|
CheckEmailProgressCommand::class,
|
|
UpdateAllAtmCardsCommand::class,
|
|
AutoSendStatementEmailCommand::class,
|
|
GenerateClosingBalanceReportCommand::class,
|
|
GenerateClosingBalanceReportBulkCommand::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;
|
|
}
|
|
}
|