diff --git a/app/Classes/General/Interfaces/Notifiable.php b/app/Classes/General/Interfaces/Notifiable.php new file mode 100644 index 00000000..e9d8f22d --- /dev/null +++ b/app/Classes/General/Interfaces/Notifiable.php @@ -0,0 +1,15 @@ +getTotal(); if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){ - $billPlzBill = $this->createsBillplzBill->execute($request->user()->name, $request->user()->email, 'This payment is made for transfer ref. '.$booking->marking, $configurations->getTotal(), $billNumber, $request->input('bank_code')); + $billPlzBill = $this->createsBillplzBill->execute($booking->company->name, $request->user()->email, 'This payment is made for transfer ref. '.$booking->marking, $configurations->getTotal(), $billNumber, $request->input('bank_code')); $paymentReference = $billPlzBill->id; } diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 74e92fa6..d31ee2ce 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -84,12 +84,14 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); - $refund = $transaction->transactions()->refunds()->sum('amount'); if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); - $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); + $amount = $transaction->booking->fix_currency_id == 1 ? $request->input('amount') : $request->input('amount') / $transaction->currency_rate; + + + $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $amount); $transactionRefundCalculationObject->init(); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, diff --git a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php index d5e052a9..cf894bfd 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php @@ -13,6 +13,9 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\Services\FetchesDocument; use App\Classes\Modules\Documents\Services\ApprovesDocument; +use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject; +Use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor; +use App\Classes\General\Interfaces\Notifiable; use App\Models\Document; use Illuminate\Http\JsonResponse; @@ -46,6 +49,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic /** @var UpdatesCompanyStatus */ private $updatesCompanyStatus; + /** @var CreateNotificationProcessor */ + private $createNotificationProcessor; + /** * ApproveIdentificationDocumentLogic constructor. * @param CanApproveDocument $canApproveDocument @@ -53,14 +59,16 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic * @param RejectsDocument $rejectsDocument * @param FetchesDocument $fetchesDocument * @param UpdatesCompanyStatus $updatesCompanyStatus + * @param CreateNotificationProcessor $createNotificationProcessor */ - public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus) + public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, CreateNotificationProcessor $createNotificationProcessor) { $this->canApproveDocument = $canApproveDocument; $this->approvesDocument = $approvesDocument; $this->rejectsDocument = $rejectsDocument; $this->fetchesDocument = $fetchesDocument; $this->updatesCompanyStatus = $updatesCompanyStatus; + $this->createNotificationProcessor = $createNotificationProcessor; } /** @@ -84,6 +92,16 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + $object = new NotificationObject( + 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ), + ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ), + $document->owner, + $document->owner->employees()->first(), + $document, + ); + + $this->createNotificationProcessor->execute($object); + return $this->resourceResponse(new DocumentResource($document)); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php new file mode 100644 index 00000000..92278bef --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php @@ -0,0 +1,62 @@ + 'Update Company Account Status', + 'message' => 'You have successfully updated the Company Account Status' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + /** + * UpdateCompanyStatusLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct( + FetchesCompany $fetchesCompany, + UpdatesCompanyStatus $updatesCompanyStatus + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $company_query = $this->updatesCompanyStatus->execute($company, $request->input('status')); + + return $this->resourceResponse(new CompanyResource($company_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php index be216473..53a71772 100644 --- a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php +++ b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php @@ -26,7 +26,6 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit 'Code', 'DebtorControlAcc', 'ControlAccount', - 'AccNo', 'CompanyName', 'Desc2', 'DebtorType', @@ -56,8 +55,12 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit { return Company::where(function($query){ $query->whereNull('debtor')->orWhere('debtor', ''); - })->whereNotIn('id', [2207, 2248, 2029])->where('business_type', BusinessType::IMPORTER)->where('status', ApprovalStatus::APPROVED)->whereHas('transactions', function($query){ - return $query->whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP])->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::PENDING_VERIFICATION]); + })->whereNotIn('id', [2207, 2248, 2029])->where('business_type', BusinessType::IMPORTER)->where('status', ApprovalStatus::APPROVED)->where(function($query){ + $query->whereHas('transactions', function($query){ + return $query->whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP])->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::PENDING_VERIFICATION]); + })->orWhereHas('wallets', function($query){ + return $query->whereHas('transactions'); + }); }); } @@ -72,7 +75,6 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit '<>', '300-0000', '300-0000', - '300-0000', $company->name.' (PURCHASE)', $company->reference, '', diff --git a/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php index 0ca1d730..57dba200 100644 --- a/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php @@ -39,7 +39,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading 'DetailDescription', 'Qty', 'UnitPrice', - 'AccNo' + 'AccNo', + 'DeptNo' ]; } @@ -100,7 +101,8 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading 'PLEASE REFER TO THE ATTACHED APPENDIX REF ' . $booking->marking, 1, $transaction->amount, - '500-0000' + '500-0000', + 'CIEF' ]; } } \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsTransactions.php b/app/Classes/Modules/Exports/Services/ExportsTransactions.php index f9bbecaf..9e328cca 100644 --- a/app/Classes/Modules/Exports/Services/ExportsTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsTransactions.php @@ -11,8 +11,9 @@ use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadingRow; use Maatwebsite\Excel\Concerns\WithMapping; +use Maatwebsite\Excel\Concerns\ShouldAutoSize; -class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping +class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping, ShouldAutoSize { use Exportable; @@ -58,6 +59,20 @@ class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping 6 => 'EXPIRED' ]; + switch ($transaction->owner_type) { + case "App\Models\Booking": + $marking = $transaction->booking->company->reference; + break; + case "App\Models\Transaction": + $marking = $transaction->transactions()->first()->booking->company->reference; + break; + case "App\Models\Wallet": + $marking = $transaction->owner->owner->reference; + break; + default: + $marking = ''; + } + return [ $transaction->bill_no, $transaction->owner_id, @@ -75,6 +90,7 @@ class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping $transactionStatus[$transaction->status], \PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel($transaction->created_at), \PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel($transaction->updated_at), + $marking ]; } } \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.php b/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.php index af4d2d07..29c1728c 100644 --- a/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.php @@ -39,7 +39,8 @@ class ExportsWalletTransactions implements FromQuery, WithHeadings, WithHeadingR 'DetailDescription', 'Qty', 'UnitPrice', - 'AccNo' + 'AccNo', + 'DeptNo' ]; } @@ -80,7 +81,7 @@ class ExportsWalletTransactions implements FromQuery, WithHeadings, WithHeadingR } /** - * @param Company $transaction + * @param Transaction $transaction * * @return array */ @@ -99,7 +100,8 @@ class ExportsWalletTransactions implements FromQuery, WithHeadings, WithHeadingR 'CREDIT SALES', 1, $transaction->amount, - '500-0000' + '500-0000', + 'WALLET' ]; } } \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php new file mode 100644 index 00000000..0fdbf6f9 --- /dev/null +++ b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php @@ -0,0 +1,61 @@ + 'Retrieve Notifications', + 'message' => 'You have successfully retrieved a list of Notifications' + ]; + } + + /** @var ListsNotification */ + private $listsNotification; + + /** + * ListNotificationsLogic constructor. + * @param ListsNotification $listsNotification + */ + public function __construct( + ListsNotification $listsNotification + ) + { + $this->listsNotification = $listsNotification; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $filters = [ + // 'target_id'=>auth()->user()->id, + // 'per_page'=>$request->route('per_page') + ]; + + $notifications = $this->listsNotification->execute($filters); + + return $this->collectionResponse(NotificationResource::collection($notifications)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php new file mode 100644 index 00000000..40dc4f3c --- /dev/null +++ b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php @@ -0,0 +1,101 @@ +title = $title; + $this->description = $description; + $this->subject = $subject; + $this->target = $target; + $this->causer = $causer; + $this->status = $status; + } + + /** + * @return int + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return int + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return Notifiable + */ + public function getSubject(): Notifiable + { + return $this->subject; + } + + /** + * @return Notifiable + */ + public function getTarget(): Notifiable + { + return $this->target; + } + + /** + * @return Notifiable + */ + public function getCauser(): Notifiable + { + return $this->causer; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + +} diff --git a/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php new file mode 100644 index 00000000..d6b077f8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php @@ -0,0 +1,27 @@ +createsNotification = $createsNotification; + } + + public function execute(NotificationObject $object) + { + $notification = $this->createsNotification->execute($object); + return $notification; + } +} diff --git a/app/Classes/Modules/Notifications/Services/CreatesNotification.php b/app/Classes/Modules/Notifications/Services/CreatesNotification.php new file mode 100644 index 00000000..4f5ca5fd --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/CreatesNotification.php @@ -0,0 +1,30 @@ +title = $object->getTitle(); + $model->description = $object->getDescription(); + $model->status = $object->getStatus(); + $model->subject_type = get_class($object->getSubject()); + $model->subject_id = $object->getSubject()->id; + $model->target_type = get_class($object->getTarget()); + $model->target_id = $object->getTarget()->id; + $model->causer_type = get_class($object->getCauser()); + $model->causer_id = $object->getCauser()->id; + $model->save(); + + return $model; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/Services/ListsNotification.php b/app/Classes/Modules/Notifications/Services/ListsNotification.php new file mode 100644 index 00000000..707e7ae8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/ListsNotification.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 3dde2e45..0aa0fb7f 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -87,7 +87,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $service_charge = 0; foreach ($this->createSupplierTransactionProcessor->getBills() as $key => $row) { - $group->transaction()->sync($row->id, false); + $group->transactions()->sync($row->id, false); $issuer = $row->issuer; $receiver = $row->receiver; $amount += $row->amount; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php new file mode 100644 index 00000000..b19a7159 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php @@ -0,0 +1,72 @@ + 'Delete Group Transaction', + 'message' => 'You have successfully deleted this Group Transaction' + ]; + } + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + public function __construct( + UpdatesTransactionStatus $updatesTransactionStatus, + FetchesGroup $fetchesGroup, + DeletesTransaction $deletesTransaction + ) + { + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; + $this->deletesTransaction = $deletesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $items = $group->transactions()->get(); + + foreach($items as $item) { + $bill = $item; + $payment = $bill->owner; + $group->transactions()->detach($bill->id); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::APPROVED); + $this->deletesTransaction->execute($bill); + } + + $group->delete(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php new file mode 100644 index 00000000..5cf99bbe --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php @@ -0,0 +1,42 @@ +listsGroups = $listsGroups; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Groups', + 'message' => 'You have successfully retrieved a list of groups' + ]; + } + + /** @var ListsGroups */ + private $listsGroups; + + public function logic(Request $request) : JsonResponse + { + $query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(GroupResource::collection($query)); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php new file mode 100644 index 00000000..e353f06a --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php @@ -0,0 +1,141 @@ + 'Update Group Transaction', + 'message' => 'You have successfully updated this Group Transaction' + ]; + } + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + + public function __construct( + FetchesGroup $fetchesGroup, + FetchesCompany $fetchesCompany, + CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, + UpdatesTransaction $updatesTransaction, + CalculatesTransactionTransferFee $calculatesTransactionTransferFee + ) + { + $this->fetchesGroup = $fetchesGroup; + $this->fetchesCompany = $fetchesCompany; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->updatesTransaction = $updatesTransaction; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $transactions = $group->transactions()->get(); + + $rate = $request->input('rate'); + + $supplier = $this->fetchesCompany->execute(['id' => $request->input('supplier_id')]); + + foreach($transactions as $transaction) { + + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($transaction->original_amount, $rate, $constant); + + $object = new TransactionObject( + $transaction->bill_no, + TransactionType::BILL, + $supplier->id, + 1, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount * (1 / $rate), + $transaction->original_amount, + 1, + $transaction->original_currency_id, + $rate, + 0, + $serviceCharge, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $billTransaction = $this->updatesTransaction->execute($transaction, $object); + + $transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + $transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->amount, $constant); + + $object = new TransactionObject( + $transferTransaction->bill_no, + TransactionType::TRANSFER_FEE, + 1, + $supplier->id, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount, + $transaction->original_amount, + $transaction->original_currency_id, + $transaction->original_currency_id, + 1, + 0, + $transferFee, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $this->updatesTransaction->execute($transferTransaction, $object); + } + + $group->issuer = $supplier; + $group->amount = $group->transactions()->sum('amount'); + $group->currency_rate = $rate; + $group->tax = $group->transactions()->sum('tax'); + $group->service_charge = $group->transactions()->sum('service_charge'); + + $group->save(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php index 75516fdf..db443184 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php @@ -97,7 +97,7 @@ class CreateSupplierTransactionProcessor $this->pushBill($billTransaction); $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); - $transferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount, $constant); + $transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->amount, $constant); $object = new TransactionObject($transferFeeNumber, TransactionType::TRANSFER_FEE, 1, $supplier->id, $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, $payment->original_amount, $payment->original_amount, $payment->original_currency_id, $payment->original_currency_id, diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php index e04edee2..29751d80 100644 --- a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -31,7 +31,7 @@ class CalculatesTransactionServiceCharge return 0; } - $transfer_fee = $this->calculatesTransactionTransferFee->execute($amount, $service_charge); + $transfer_fee = $this->calculatesTransactionTransferFee->execute(($amount * (1 / $rate)), $service_charge); return $service_charge->detail->amount->type === 'percentage' ? (($amount + $transfer_fee) * ( (float) $service_charge->detail->amount->value /100) * (1/$rate)) : (float) $service_charge->detail->amount->value; } diff --git a/app/Classes/Modules/Transactions/Services/FetchesGroup.php b/app/Classes/Modules/Transactions/Services/FetchesGroup.php new file mode 100644 index 00000000..6533664b --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesGroup.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/ListsGroups.php b/app/Classes/Modules/Transactions/Services/ListsGroups.php new file mode 100644 index 00000000..f9126739 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsGroups.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php index 9bbe6073..c60cbf54 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -102,7 +102,7 @@ class TopUpWalletLogic extends AbstractControllerLogic throw new MalformedRequestException('Top up credit value must be greater than zero.'); } - $billPlzBill = $this->createsBillplzBill->execute($user->name, $user->email, 'This payment is credit topup for company ref. ' . $company->reference, $amount, $billNumber, $request->input('bank_code'), true); + $billPlzBill = $this->createsBillplzBill->execute($company->name, $user->email, 'This payment is credit topup for company ref. ' . $company->reference, $amount, $billNumber, $request->input('bank_code'), true); $transaction_object = new TransactionObject($billNumber, TransactionType::TOP_UP, 1, $company->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], $billPlzBill->id); diff --git a/app/Http/Controllers/Companies/UpdateCompanyStatusController.php b/app/Http/Controllers/Companies/UpdateCompanyStatusController.php new file mode 100644 index 00000000..43b3ba3c --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyStatusController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Notifications/ListNotificationsController.php b/app/Http/Controllers/Notifications/ListNotificationsController.php new file mode 100644 index 00000000..58455fc2 --- /dev/null +++ b/app/Http/Controllers/Notifications/ListNotificationsController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/DeleteGroupController.php b/app/Http/Controllers/Transactions/DeleteGroupController.php new file mode 100644 index 00000000..14ba54f9 --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListGroupsController.php b/app/Http/Controllers/Transactions/ListGroupsController.php new file mode 100644 index 00000000..730633e9 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/UpdateGroupController.php b/app/Http/Controllers/Transactions/UpdateGroupController.php new file mode 100644 index 00000000..db0b3a17 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 0eeb9670..0adfa65d 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -31,6 +31,7 @@ class BookingResource extends JsonResource 'service' => new ServiceTypeResource($this->service), 'marking' => $this->marking, 'amount' => $this->fix_amount, + 'amount' => $this->fix_amount, 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php new file mode 100644 index 00000000..2d628d19 --- /dev/null +++ b/app/Http/Resources/GroupResource.php @@ -0,0 +1,29 @@ + $this->id, + 'original_amount' => (double) $this->original_amount, + 'original_currency' => new CurrencyResource($this->original_currency), + 'amount' => (double) $this->amount, + 'currency' => new CurrencyResource($this->currency), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float) $this->currency_rate, + 'transactions' => TransactionResource::collection($this->transactions()->get()), + ]; + } +} diff --git a/app/Http/Resources/NotificationResource.php b/app/Http/Resources/NotificationResource.php new file mode 100644 index 00000000..564b7b31 --- /dev/null +++ b/app/Http/Resources/NotificationResource.php @@ -0,0 +1,30 @@ + $this->id, + 'title' => $this->title, + 'description' => $this->description, + 'long_ago' => $this->created_at->diffForHumans(), + 'created_at' => $this->created_at->format('d-m-Y') + ]; + + } +} diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 30ba223c..e35dcc36 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -30,6 +30,7 @@ class TransactionResource extends JsonResource 'payment_method' => (float) $this->payment_method, 'recipient_bank_account' => new BankResource($booking->bank), 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, 'currency' => new CurrencyResource($this->currency), diff --git a/app/Models/AbstractModel.php b/app/Models/AbstractModel.php index 7a7c9c06..47d8754b 100644 --- a/app/Models/AbstractModel.php +++ b/app/Models/AbstractModel.php @@ -3,11 +3,37 @@ namespace App\Models; +use App\Classes\General\Interfaces\Notifiable; use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; +use Illuminate\Database\Eloquent\Relations\MorphTo; -class AbstractModel extends Model +class AbstractModel extends Model implements Notifiable { use LogsActivity; protected static $logFillable = true; + + /** + * @return MorphTo + */ + public function subject(): MorphTo + { + return $this->MorphTo('subject'); + } + + /** + * @return MorphTo + */ + public function target(): MorphTo + { + return $this->MorphTo('target'); + } + + /** + * @return MorphTo + */ + public function causer(): MorphTo + { + return $this->MorphTo('causer'); + } } \ No newline at end of file diff --git a/app/Models/Group.php b/app/Models/Group.php index eff309e2..6e785faa 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -3,11 +3,28 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Group extends Model { - public function transaction() + public function transactions() { - return $this->belongsToMany('App\Models\Transaction', 'group_transaction'); + return $this->belongsToMany(Transaction::class, GroupTransaction::class); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); } } diff --git a/app/Models/GroupTransaction.php b/app/Models/GroupTransaction.php index c8622ef9..9ab72d18 100644 --- a/app/Models/GroupTransaction.php +++ b/app/Models/GroupTransaction.php @@ -3,8 +3,25 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class GroupTransaction extends Model { - // + protected $table = 'group_transactions'; + + /** + * @return BelongsTo + */ + public function group(): BelongsTo + { + return $this->BelongsTo(Group::class, 'group_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function transaction(): BelongsTo + { + return $this->BelongsTo(Transaction::class, 'transaction_id', 'id'); + } } diff --git a/app/Models/Notification.php b/app/Models/Notification.php new file mode 100644 index 00000000..06bd6024 --- /dev/null +++ b/app/Models/Notification.php @@ -0,0 +1,18 @@ +BelongsTo(Package::class, 'package_id', 'id'); + } +} diff --git a/database/migrations/2022_03_20_170641_create_group_transactions_table.php b/database/migrations/2022_03_20_170641_create_group_transactions_table.php index 6ce7cedc..53f33356 100644 --- a/database/migrations/2022_03_20_170641_create_group_transactions_table.php +++ b/database/migrations/2022_03_20_170641_create_group_transactions_table.php @@ -13,7 +13,8 @@ class CreateGroupTransactionsTable extends Migration */ public function up() { - Schema::create('group_transaction', function (Blueprint $table) { + Schema::create('group_transactions', function (Blueprint $table) { + $table->id(); $table->foreignId('group_id')->unsigned(); $table->foreignId('transaction_id')->unsigned(); }); @@ -26,6 +27,6 @@ class CreateGroupTransactionsTable extends Migration */ public function down() { - Schema::dropIfExists('group_transaction'); + Schema::dropIfExists('group_transactions'); } } diff --git a/database/migrations/2022_04_15_211421_create_notifications_table.php b/database/migrations/2022_04_15_211421_create_notifications_table.php new file mode 100644 index 00000000..d14cdc89 --- /dev/null +++ b/database/migrations/2022_04_15_211421_create_notifications_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('title'); + $table->text('description'); + $table->morphs('subject'); + $table->morphs('target'); + $table->morphs('causer'); + $table->integer('status')->default(ApprovalStatus::APPROVED); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/resources/assets/sass/modules/_typography.scss b/resources/assets/sass/modules/_typography.scss index 605b8e7c..aa4506a9 100644 --- a/resources/assets/sass/modules/_typography.scss +++ b/resources/assets/sass/modules/_typography.scss @@ -316,6 +316,12 @@ hr{ background-color: $color-primary-lighter !important; } +.bg-primary-lighter-hover { + &:hover { + background-color: $color-primary-lighter !important; + } +} + /* Complete ------------------------------------ */ diff --git a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue index cf8b727e..f08ea597 100644 --- a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue @@ -148,7 +148,6 @@
- {{ data.company.id }}
diff --git a/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue b/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue index ad4c3e42..a88fd5a9 100644 --- a/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue +++ b/resources/assets/vue/components/bookings/elements/CurrencyOrderComponent.vue @@ -40,7 +40,7 @@
Currency Order Placed
-
Are you sure you that the currency order has been placed with the supplier?
+
Are you sure that the currency order has been placed with the supplier?
diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index b73081b9..de39dfb0 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -219,7 +219,7 @@
-
+
@@ -249,12 +249,25 @@ }, computed: { totalRequestedRefund() { + let vm = this; var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) { TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; }); + return TotalRequestedRefund; }, + totalRequestedConvertRefund() { + let vm = this; + var TotalRequestedRefund = 0; + this.data.transaction_refunds.forEach(function(refunds) { + TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; + }); + if (vm.data.booking.fixed_currency.id != 1 && this.data.transaction_refunds[0]) { + TotalRequestedRefund = (TotalRequestedRefund * this.data.transaction_refunds[0].currency_rate); + } + return ((Math.round((TotalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); + }, totalRefunds() { var TotalRequestedRefund = 0; this.data.transaction_refunds.forEach(function(refunds) { diff --git a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue index 5af5548c..ff8452a5 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue @@ -1,5 +1,5 @@