diff --git a/app/Providers/LpjServiceProvider.php b/app/Providers/LpjServiceProvider.php index 474ae18..a7f8df1 100644 --- a/app/Providers/LpjServiceProvider.php +++ b/app/Providers/LpjServiceProvider.php @@ -4,6 +4,8 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; + use Modules\Lpj\Models\BankData; + use Modules\Lpj\Services\BankDataService; class LpjServiceProvider extends ServiceProvider { @@ -118,6 +120,9 @@ { $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); + $this->app->bind(BankDataService::class, function ($app){ + return new BankDataService($app->make(BankData::class)); + }); } /** diff --git a/app/Services/BankDataService.php b/app/Services/BankDataService.php new file mode 100644 index 0000000..98ab6e0 --- /dev/null +++ b/app/Services/BankDataService.php @@ -0,0 +1,116 @@ +bankData = $bankData; + } + + /** + * Get all bank data with optional filtering and pagination + * + * @param array $filters + * @param int|null $perPage + * + * @return Collection|LengthAwarePaginator + */ + public function getAllBankData(array $filters = [], ?int $perPage = null) + { + $query = $this->bankData->newQuery(); + + // Apply filters + if (isset($filters['village_code'])) { + $query->ofVillage($filters['village_code']); + } + if (isset($filters['district_code'])) { + $query->ofDistrict($filters['district_code']); + } + if (isset($filters['city_code'])) { + $query->ofCity($filters['city_code']); + } + if (isset($filters['province_code'])) { + $query->ofProvince($filters['province_code']); + } + if (isset($filters['date'])) { + $query->ofDate($filters['date']); + } + if (isset($filters['start_date']) && isset($filters['end_date'])) { + $query->betweenDates($filters['start_date'], $filters['end_date']); + } + if (isset($filters['year'])) { + $query->ofYear($filters['year']); + } + if (isset($filters['asset_type'])) { + $query->ofAssetType($filters['asset_type']); + } + + // Add more filters as needed + + return $perPage ? $query->paginate($perPage) : $query->get(); + } + + /** + * Create a new bank data entry + * + * @param array $data + * + * @return BankData + */ + public function createBankData(array $data) + : BankData + { + return $this->bankData->create($data); + } + + /** + * Update an existing bank data entry + * + * @param int $id + * @param array $data + * + * @return BankData + */ + public function updateBankData(int $id, array $data) + : BankData + { + $bankData = $this->bankData->findOrFail($id); + $bankData->update($data); + return $bankData; + } + + /** + * Delete a bank data entry + * + * @param int $id + * + * @return bool + */ + public function deleteBankData(int $id) + : bool + { + $bankData = $this->bankData->findOrFail($id); + return $bankData->delete(); + } + + /** + * Find a bank data entry by ID + * + * @param int $id + * + * @return BankData|null + */ + public function findBankData(int $id) + : ?BankData + { + return $this->bankData->find($id); + } + }