diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyNameAndDebtorLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyNameAndDebtorLogic.php new file mode 100644 index 00000000..05fb0746 --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyNameAndDebtorLogic.php @@ -0,0 +1,82 @@ + 'Update Company Account Status', + 'message' => 'You have successfully updated the Company Account Status' + ]; + } + /** @var CanUpdateCompany */ + private $canUpdateCompany; + + /** @var UpdatesCompany */ + private $updatesCompany; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var UpdatesCompanyDebtor */ + private $updatesCompanyDebtor; + + /** + * UpdateCompanyControllersLogic constructor. + * @param CanUpdateCompany $canUpdateCompany + * @param UpdatesCompany $updatesCompany + * @param FetchesCompany $fetchesCompany + * @param UpdatesCompanyDebtor $updatesCompanyDebtor + */ + public function __construct( + CanUpdateCompany $canUpdateCompany, + UpdatesCompany $updatesCompany, + FetchesCompany $fetchesCompany, + UpdatesCompanyDebtor $updatesCompanyDebtor + ) + { + $this->canUpdateCompany = $canUpdateCompany; + $this->updatesCompany = $updatesCompany; + $this->fetchesCompany = $fetchesCompany; + $this->updatesCompanyDebtor = $updatesCompanyDebtor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $object = new CompanyObject($request->input('name'), $request->input('reference'), $query->business_type, $request->input('type')); + + $this->canUpdateCompany->passes($object); + + $query = $this->updatesCompany->execute($query, $object); + + if ($request->input('debtor') || $query->first()->debtor !== null) { + $this->updatesCompanyDebtor->execute($query, $request->input('debtor')); + } + + return $this->resourceResponse(new CompanyResource($query)); + } + +} + diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php index 09b0e153..cbc5df53 100644 --- a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php @@ -83,4 +83,4 @@ class CompanyObject implements DataTransferObject -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompany.php b/app/Classes/Modules/Companies/Services/UpdatesCompany.php index f89bbca8..1b92c2d8 100644 --- a/app/Classes/Modules/Companies/Services/UpdatesCompany.php +++ b/app/Classes/Modules/Companies/Services/UpdatesCompany.php @@ -15,7 +15,7 @@ class UpdatesCompany extends AbstractUpdateRecord * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(Company $model, CompanyObject $object) + public function execute(Company $model, CompanyObject $object) { $model->name = $object->getName(); $model->reference = $object->getReference(); @@ -23,4 +23,4 @@ class UpdatesCompany extends AbstractUpdateRecord return $this->handler($model); } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php index 4cb43a9f..14e0d6e2 100644 --- a/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php @@ -11,6 +11,7 @@ class UpdatesCompanyDebtor extends AbstractUpdateRecord /** * @param Company $model + * @param CompanyObject $object * @param string $debtor * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException @@ -18,6 +19,7 @@ class UpdatesCompanyDebtor extends AbstractUpdateRecord public function execute(Company $model, string $debtor) { $model->debtor = $debtor; + return $this->handler($model); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Companies/UpdateCompanyNameAndDebtorController.php b/app/Http/Controllers/Companies/UpdateCompanyNameAndDebtorController.php new file mode 100644 index 00000000..18599e7f --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyNameAndDebtorController.php @@ -0,0 +1,19 @@ +execute($request); + } +} diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 015a86ee..f3a7881d 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -11,6 +11,7 @@ use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\DocumentType; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Facades\Log; class BookingResource extends JsonResource { diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index cb357684..6d7cb2e4 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -37,6 +37,7 @@ class CompanyResource extends JsonResource 'id' => $this->id, 'name' => $this->name, 'reference' => $this->reference, + 'debtor' => $this->debtor, 'type' => (int) $this->type, 'business_type' => (int) $this->business_type, 'status' => (int) $this->status, diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php index cfc8ab10..53f18364 100644 --- a/app/Http/Resources/WalletTransactionResource.php +++ b/app/Http/Resources/WalletTransactionResource.php @@ -7,6 +7,7 @@ use App\Classes\ValueObjects\Constants\TransactionType; use App\Models\Transaction; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Facades\Log; class WalletTransactionResource extends JsonResource { @@ -27,7 +28,14 @@ class WalletTransactionResource extends JsonResource $description = 'Credit Voucher for '.$this->payment_reference; break; case 1: - $marking = Transaction::where('payment_reference', $this->bill_no)->first()->owner->marking; + $booking = Transaction::where('payment_reference', $this->bill_no)->first()->owner; + + if(!$booking) { + $description = 'Payment for unknown booking, please contact tech support.'; + break; + } + + $marking = $booking->marking; $description = 'Payment For booking refs.'.''.$marking.''; break; case 11: diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index b87ac20e..702745c7 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -200,6 +200,14 @@