diff --git a/app/Classes/Modules/CompanyBanks/ControllerLogic/DeleteCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllerLogic/DeleteCompanyBankLogic.php index c8066cec..91bbe068 100644 --- a/app/Classes/Modules/CompanyBanks/ControllerLogic/DeleteCompanyBankLogic.php +++ b/app/Classes/Modules/CompanyBanks/ControllerLogic/DeleteCompanyBankLogic.php @@ -66,13 +66,13 @@ class DeleteCompanyBankLogic extends AbstractControllerLogic try { DB::beginTransaction(); - $segment_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); + $company_bank_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); $this->canDeleteCompanyBank->passes(); - $this->deletesCompanyBank->execute($segment_query); + $this->deletesCompanyBank->execute($company_bank_query); DB::commit(); - return $this->resourceResponse(new CompanyBankResource($segment_query)); + return $this->resourceResponse(new CompanyBankResource($company_bank_query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); diff --git a/app/Classes/Modules/CompanyBanks/ControllerLogic/UpdateCompanyBankLogic.php b/app/Classes/Modules/CompanyBanks/ControllerLogic/UpdateCompanyBankLogic.php index dabedaa8..3de3bdaa 100644 --- a/app/Classes/Modules/CompanyBanks/ControllerLogic/UpdateCompanyBankLogic.php +++ b/app/Classes/Modules/CompanyBanks/ControllerLogic/UpdateCompanyBankLogic.php @@ -37,23 +37,23 @@ class UpdateCompanyBankLogic extends AbstractControllerLogic private $updatesCompanyBank; /** @var FetchesCompanyBank */ - private $fetchesSegment; + private $fetchesCompanyBank; /** * UpdateStandardSegmentConstantLogic constructor. * @param CanUpdateCompanyBank $canUpdateCompanyBank * @param UpdatesCompanyBank $updatesCompanyBank - * @param FetchesCompanyBank $fetchesSegment + * @param FetchesCompanyBank $fetchesCompanyBank */ public function __construct( CanUpdateCompanyBank $canUpdateCompanyBank, UpdatesCompanyBank $updatesCompanyBank, - FetchesCompanyBank $fetchesSegment + FetchesCompanyBank $fetchesCompanyBank ) { $this->canUpdateCompanyBank = $canUpdateCompanyBank; $this->updatesCompanyBank = $updatesCompanyBank; - $this->fetchesSegment = $fetchesSegment; + $this->fetchesCompanyBank = $fetchesCompanyBank; } /** @@ -66,7 +66,7 @@ class UpdateCompanyBankLogic extends AbstractControllerLogic try { DB::beginTransaction(); - $company_bank_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $company_bank_query = $this->fetchesCompanyBank->execute(['id' => $request->route('id')]); $company_bank_object = new CompanyBankObject( $company_bank_query->country_id, diff --git a/app/Classes/Modules/Currencies/ControllerLogic/CreateCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllerLogic/CreateCurrencyLogic.php new file mode 100644 index 00000000..a1150831 --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllerLogic/CreateCurrencyLogic.php @@ -0,0 +1,87 @@ + 'Created Currency', + 'message' => 'You have successfully created a new Currency' + ]; + } + + /** @var CanCreateCurrency */ + private $canCreateCurrency; + + /** @var CreatesCurrency */ + private $createsCurrency; + + /** @var CreatesCurrencyLog */ + private $createsCurrencyLog; + + /** + * CreateSegmentLogic constructor. + * @param CanCreateCurrency $canCreateCurrency + * @param CreatesCurrency $createsCurrency + * @param CreatesCurrencyLog $createsCurrencyLog + */ + public function __construct( + CanCreateCurrency $canCreateCurrency, + CreatesCurrency $createsCurrency, + CreatesCurrencyLog $createsCurrencyLog + ) + { + $this->canCreateCurrency = $canCreateCurrency; + $this->createsCurrency = $createsCurrency; + $this->createsCurrencyLog = $createsCurrencyLog; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_object = new CurrencyObject( + $request->input('country_id'), + $request->input('name'), + $request->input('short_code'), + $request->input('symbol'), + number_format( (float) $request->input('selling'), 5, '.', '') + ); + $this->canCreateCurrency->passes($currency_object); + $currency_query = $this->createsCurrency->execute($currency_object); + + $currency_log_query = $this->createsCurrencyLog->execute($currency_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyResource($currency_query)); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllerLogic/DeleteCurrencyLogic.php b/app/Classes/Modules/Currencies/ControllerLogic/DeleteCurrencyLogic.php new file mode 100644 index 00000000..85d347ac --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllerLogic/DeleteCurrencyLogic.php @@ -0,0 +1,82 @@ + 'Delete Currency', + 'message' => 'You have successfully deleted the Currency' + ]; + } + + /** @var CanDeleteCurrency */ + private $canDeleteCurrency; + + /** @var DeletesCurrency */ + private $deletesCurrency; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateSegment $canDeleteCurrency + * @param UpdatesSegment $deletesSegment + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct( + CanDeleteCurrency $canDeleteCurrency, + DeletesCurrency $deletesCurrency, + FetchesCurrency $fetchesCurrency + ) + { + $this->canDeleteCurrency = $canDeleteCurrency; + $this->deletesCurrency = $deletesCurrency; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]); + $this->canDeleteCurrency->passes(); + $this->deletesCurrency->execute($currency_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyResource($currency_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/ControllerLogic/UpdateCurrencyRateLogic.php b/app/Classes/Modules/Currencies/ControllerLogic/UpdateCurrencyRateLogic.php new file mode 100644 index 00000000..b63c007e --- /dev/null +++ b/app/Classes/Modules/Currencies/ControllerLogic/UpdateCurrencyRateLogic.php @@ -0,0 +1,98 @@ + 'Updated Currency Rate', + 'message' => 'You have successfully updated the Currency Rate' + ]; + } + + /** @var CanUpdateCurrency */ + private $canUpdateCurrency; + + /** @var UpdatesCurrencyRate */ + private $updatesCurrencyRate; + + /** @var FetchesCurrency */ + private $fetchesCurrency; + + /** @var CreatesCurrencyLog */ + private $createsCurrencyLog; + + /** + * UpdateStandardSegmentConstantLogic constructor. + * @param CanUpdateCurrency $canUpdateCurrency + * @param UpdatesCurrencyRate $updatesCurrencyRate + * @param FetchesCurrency $fetchesCurrency + */ + public function __construct( + CanUpdateCurrency $canUpdateCurrency, + UpdatesCurrencyRate $updatesCurrencyRate, + CreatesCurrencyLog $createsCurrencyLog, + FetchesCurrency $fetchesCurrency + ) + { + $this->canUpdateCurrency = $canUpdateCurrency; + $this->updatesCurrencyRate = $updatesCurrencyRate; + $this->createsCurrencyLog = $createsCurrencyLog; + $this->fetchesCurrency = $fetchesCurrency; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $currency_query = $this->fetchesCurrency->execute(['id' => $request->route('id')]); + + $currency_object = new CurrencyObject( + $currency_query->country_id, + $currency_query->name, + $currency_query->short_code, + $currency_query->symbol, + $request->input('selling', $currency_query->selling) + ); + $this->canUpdateCurrency->passes($currency_object); + $currency_query = $this->updatesCurrencyRate->execute($currency_query, $currency_object); + + $currency_log_query = $this->createsCurrencyLog->execute($currency_query); + + DB::commit(); + + return $this->resourceResponse(new CurrencyResource($currency_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php new file mode 100644 index 00000000..8996824b --- /dev/null +++ b/app/Classes/Modules/Currencies/DataTransferObjects/CurrencyObject.php @@ -0,0 +1,78 @@ +country_id = $country_id; + $this->name = $name; + $this->short_code = $short_code; + $this->symbol = $symbol; + $this->selling = $selling; + } + + /** + * @return int + */ + public function getCountryId(): ?int + { + return $this->country_id; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @return string + */ + public function getShortCode(): ?string + { + return $this->short_code; + } + + /** + * @return string + */ + public function getSymbol(): ?string + { + return $this->symbol; + } + + /** + * @return float + */ + public function getSelling(): ?float + { + return $this->selling; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/CreatesCurrency.php b/app/Classes/Modules/Currencies/Services/CreatesCurrency.php new file mode 100644 index 00000000..e2c8f5c1 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/CreatesCurrency.php @@ -0,0 +1,26 @@ +country_id = $object->getCountryId(); + $model->name = $object->getName(); + $model->short_code = $object->getShortCode(); + $model->symbol = $object->getSymbol(); + $model->selling = $object->getSelling(); + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php new file mode 100644 index 00000000..a5de84ab --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/CreatesCurrencyLog.php @@ -0,0 +1,24 @@ +currency_id = $object->id; + $model->selling = $object->selling; + $model->created_by = \Auth::user()->id; + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/DeletesCurrency.php b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php new file mode 100644 index 00000000..13606c86 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/DeletesCurrency.php @@ -0,0 +1,14 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/FetchesCurrency.php b/app/Classes/Modules/Currencies/Services/FetchesCurrency.php new file mode 100644 index 00000000..f9c475b3 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/FetchesCurrency.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Services/UpdatesCurrencyRate.php b/app/Classes/Modules/Currencies/Services/UpdatesCurrencyRate.php new file mode 100644 index 00000000..ac8704f3 --- /dev/null +++ b/app/Classes/Modules/Currencies/Services/UpdatesCurrencyRate.php @@ -0,0 +1,23 @@ +selling = $object->getSelling(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php new file mode 100644 index 00000000..42da8a25 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanCreateCurrency.php @@ -0,0 +1,55 @@ +currencyValidation = $currencyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + if (!\Auth::user()->can('add currency')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->currencyValidation->validate($object); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php new file mode 100644 index 00000000..bfeb6885 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanDeleteCurrency.php @@ -0,0 +1,45 @@ +can('delete currency')) { + return false; + } + + return true; + + } + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param CurrencyObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php b/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php new file mode 100644 index 00000000..bb055060 --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Rules/CanUpdateCurrency.php @@ -0,0 +1,58 @@ +currencyValidation = $currencyValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('edit currency')) { + return false; + } + + return true; + } + + /** + * @param CurrencyValidation $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->currencyValidation->validate($object); + } + + /** + * @param CurrencyValidation $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php new file mode 100644 index 00000000..e11d468f --- /dev/null +++ b/app/Classes/Modules/Currencies/Standards/Validators/CurrencyValidation.php @@ -0,0 +1,46 @@ + $object->getCountryId(), + 'name' => $object->getName(), + 'short_code' => $object->getShortCode(), + 'symbol' => $object->getSymbol(), + 'selling' => $object->getSelling() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'country_id' => 'required', + 'name' => 'required', + 'short_code' => 'required', + 'short_code' => 'required', + 'selling' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/CreateCurrencyController.php b/app/Http/Controllers/Currencies/CreateCurrencyController.php new file mode 100644 index 00000000..14d1d322 --- /dev/null +++ b/app/Http/Controllers/Currencies/CreateCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/DeleteCurrencyController.php b/app/Http/Controllers/Currencies/DeleteCurrencyController.php new file mode 100644 index 00000000..e4114c77 --- /dev/null +++ b/app/Http/Controllers/Currencies/DeleteCurrencyController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Currencies/UpdateCurrencyRateController.php b/app/Http/Controllers/Currencies/UpdateCurrencyRateController.php new file mode 100644 index 00000000..7f04c1c1 --- /dev/null +++ b/app/Http/Controllers/Currencies/UpdateCurrencyRateController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/CurrencyResource.php b/app/Http/Resources/CurrencyResource.php new file mode 100644 index 00000000..11ff5361 --- /dev/null +++ b/app/Http/Resources/CurrencyResource.php @@ -0,0 +1,26 @@ + $this->id, + 'country_id' => $this->country_id, + 'name' => $this->name, + 'short_code' => $this->short_code, + 'symbol' => $this->symbol, + 'selling' => $this->selling + ]; + } +} diff --git a/app/Models/Currency.php b/app/Models/Currency.php index a3bc2672..e29fc0d1 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -1,6 +1,6 @@ string('name')->nullable(); $table->string('short_code')->nullable(); $table->string('symbol')->nullable(); + $table->float('selling', 20, 5)->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2014_10_11_100011_create_currency_logs_table.php b/database/migrations/2014_10_11_100011_create_currency_logs_table.php new file mode 100644 index 00000000..1b2499d0 --- /dev/null +++ b/database/migrations/2014_10_11_100011_create_currency_logs_table.php @@ -0,0 +1,36 @@ +id(); + $table->bigInteger('currency_id')->unsigned()->nullable(); + $table->foreign('currency_id')->references('id')->on('currencies')->onDelete('cascade'); + $table->float('selling', 20, 5)->nullable(); + $table->bigInteger('created_by')->unsigned()->nullable(); + $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('currency_logs'); + } +} diff --git a/database/seeds/AdminUserPermissionsTableSeeder.php b/database/seeds/AdminUserPermissionsTableSeeder.php index 69634742..90ef26e1 100644 --- a/database/seeds/AdminUserPermissionsTableSeeder.php +++ b/database/seeds/AdminUserPermissionsTableSeeder.php @@ -24,7 +24,6 @@ class AdminUserPermissionsTableSeeder extends Seeder Permission::create(['name' => 'edit document', 'guard_name' => 'web']); Permission::create(['name' => 'delete document', 'guard_name' => 'web']); - Permission::create(['name' => 'view standard_segment', 'guard_name' => 'web']); Permission::create(['name' => 'add standard_segment', 'guard_name' => 'web']); Permission::create(['name' => 'edit standard_segment', 'guard_name' => 'web']); @@ -50,6 +49,11 @@ class AdminUserPermissionsTableSeeder extends Seeder Permission::create(['name' => 'edit company_bank', 'guard_name' => 'web']); Permission::create(['name' => 'delete company_bank', 'guard_name' => 'web']); + Permission::create(['name' => 'view currency', 'guard_name' => 'web']); + Permission::create(['name' => 'add currency', 'guard_name' => 'web']); + Permission::create(['name' => 'edit currency', 'guard_name' => 'web']); + Permission::create(['name' => 'delete currency', 'guard_name' => 'web']); + /////////////////////////////////////////////////////////////////////// $shadow_admin_role = Role::create([ diff --git a/database/seeds/CurrenciesTableSeeder.php b/database/seeds/CurrenciesTableSeeder.php index dde39abf..f969b577 100644 --- a/database/seeds/CurrenciesTableSeeder.php +++ b/database/seeds/CurrenciesTableSeeder.php @@ -19,6 +19,7 @@ class CurrenciesTableSeeder extends Seeder 'name' => 'Ringgit', 'short_code' => 'MYR', 'symbol' => 'RM', + 'selling' => 1, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ]