diff --git a/app/Classes/General/Abstracts/AbstractRule.php b/app/Classes/General/Abstracts/AbstractRule.php index d2e0568b..8a9b6f86 100644 --- a/app/Classes/General/Abstracts/AbstractRule.php +++ b/app/Classes/General/Abstracts/AbstractRule.php @@ -27,7 +27,7 @@ abstract class AbstractRule public function passes(?DataTransferObject $object = null): bool { try { if(!$this->authorized()){ - throw new AccessForbiddenException('You don\'t have permission to preform this action'); + throw new AccessForbiddenException('You don\'t have permission to perform this action'); } $this->validators($object); @@ -36,7 +36,7 @@ abstract class AbstractRule return true; } catch(AccessForbiddenException $exception){ - throw new AccessForbiddenException('You don\'t have permission to preform this action'); + throw new AccessForbiddenException('You don\'t have permission to perform this action'); } catch(\Exception $exception){ throw new RequestValidationException($exception->getMessage()); } diff --git a/app/Classes/General/Interfaces/Remarkable.php b/app/Classes/General/Interfaces/Remarkable.php new file mode 100644 index 00000000..dcbd94ce --- /dev/null +++ b/app/Classes/General/Interfaces/Remarkable.php @@ -0,0 +1,13 @@ +fetchBookingQuotation = $fetchBookingQuotation; $this->fetchesTransaction = $fetchesTransaction; @@ -69,6 +75,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->updateRefundTransactionStatusLogic = $updateRefundTransactionStatusLogic; + $this->createRemarkProcessor = $createRemarkProcessor; } /** @@ -132,6 +139,11 @@ class CreateBookingRefundLogic extends AbstractControllerLogic } + if($request->input('refundRemark')){ + $remarkObject = new RemarkObject($request->input('refundRemark'), Auth()->user()->id); + $this->createRemarkProcessor->execute($this->fetchesTransaction->execute(['id' => $refund_transaction->id]), $remarkObject); + } + return $this->resourceResponse(new TransactionResource($refund_transaction)); } diff --git a/app/Classes/Modules/Exports/Services/ExportsWhiteFormTransactions.php b/app/Classes/Modules/Exports/Services/ExportsWhiteFormTransactions.php new file mode 100644 index 00000000..78579fc1 --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsWhiteFormTransactions.php @@ -0,0 +1,99 @@ +request = $request; + } + + public function headings(): array + { + return [ + 'Bank Name', + 'Bank Details', + 'Bank Acc No.', + 'Order amount', + 'Booking Reference', + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + $start_date = $this->request->input('startDate', null); + if ($start_date) { + $start_date = Carbon::parse($this->request->input('startDate'))->format('Y-m-d'); + } + + $end_date = $this->request->input('endDate', null); + if ($end_date) { + $end_date = Carbon::parse($this->request->input('endDate'))->format('Y-m-d'); + } + + $query = Group::query(); + + // todo-new: confirm this + // $query->where('type', ::PAYMENT)->where('payment_method', '!=', PaymentMethodType::WALLET); + // $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + + if ($start_date && $end_date) { + $query->whereBetween('created_at', [ + Carbon::parse($start_date)->format('Y-m-d 0:00:00'), + Carbon::parse($end_date)->format('Y-m-d 23:59:59') + ]); + } elseif ($start_date && !$end_date) { + $query->where('created_at', '>=', Carbon::parse($start_date)->format('Y-m-d 0:00:00')); + } elseif (!$start_date && $end_date) { + $query->where('created_at', '<=', Carbon::parse($end_date)->format('Y-m-d 23:59:59')); + } + + return $query; + } + + /** + * @param Company $group + * + * @return array + */ + public function map($group): array + { + $supplier = $group->issuerCompany; + $supplerBank = $supplier->banks->first(); + + $bank_name = $supplerBank->bank_name; + $holder_name = $supplerBank->holder_name; + $account_no = $supplerBank->account_no; + + $bookingReference = $group->transactions()->get()->pluck('owner.owner.marking')->toArray(); + + return [ + $bank_name, + $holder_name, + $account_no, + $group->amount, + implode(",", $bookingReference) + ]; + } +} diff --git a/app/Classes/Modules/Remarks/Standards/Rules/CanCreateRemark.php b/app/Classes/Modules/Remarks/Standards/Rules/CanCreateRemark.php index a7d2e5b1..fc51178f 100644 --- a/app/Classes/Modules/Remarks/Standards/Rules/CanCreateRemark.php +++ b/app/Classes/Modules/Remarks/Standards/Rules/CanCreateRemark.php @@ -26,7 +26,7 @@ class CanCreateRemark extends AbstractRule /** * @return bool */ - protected function authorized($object): bool + protected function authorized(): bool { // TODO Set Authorization rules return true; diff --git a/app/Classes/Modules/Remarks/Standards/Rules/CanDeleteRemark.php b/app/Classes/Modules/Remarks/Standards/Rules/CanDeleteRemark.php index 1c61ac9d..7ddece31 100644 --- a/app/Classes/Modules/Remarks/Standards/Rules/CanDeleteRemark.php +++ b/app/Classes/Modules/Remarks/Standards/Rules/CanDeleteRemark.php @@ -13,7 +13,7 @@ class CanDeleteRemark extends AbstractRule /** * @return bool */ - protected function authorized($object): bool + protected function authorized(): bool { // TODO Set Authorization rules return true; diff --git a/app/Classes/Modules/Remarks/Standards/Rules/CanFetchRemark.php b/app/Classes/Modules/Remarks/Standards/Rules/CanFetchRemark.php index 31ae8301..6642611c 100644 --- a/app/Classes/Modules/Remarks/Standards/Rules/CanFetchRemark.php +++ b/app/Classes/Modules/Remarks/Standards/Rules/CanFetchRemark.php @@ -13,7 +13,7 @@ class CanFetchRemark extends AbstractRule /** * @return bool */ - protected function authorized($object): bool + protected function authorized(): bool { // TODO Set Authorization rules return true; diff --git a/app/Classes/Modules/Remarks/Standards/Rules/CanListRemarks.php b/app/Classes/Modules/Remarks/Standards/Rules/CanListRemarks.php index b1372049..4911a53b 100644 --- a/app/Classes/Modules/Remarks/Standards/Rules/CanListRemarks.php +++ b/app/Classes/Modules/Remarks/Standards/Rules/CanListRemarks.php @@ -13,7 +13,7 @@ class CanListRemarks extends AbstractRule /** * @return bool */ - protected function authorized($object): bool + protected function authorized(): bool { // TODO Set Authorization rules return true; diff --git a/app/Classes/Modules/Remarks/Standards/Rules/CanUpdateRemark.php b/app/Classes/Modules/Remarks/Standards/Rules/CanUpdateRemark.php index f6fd6587..8a8c10e8 100644 --- a/app/Classes/Modules/Remarks/Standards/Rules/CanUpdateRemark.php +++ b/app/Classes/Modules/Remarks/Standards/Rules/CanUpdateRemark.php @@ -26,7 +26,7 @@ class CanUpdateRemark extends AbstractRule /** * @return bool */ - protected function authorized($object): bool + protected function authorized(): bool { // TODO Set Authorization rules return true; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupTransferFeeLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupTransferFeeLogic.php new file mode 100644 index 00000000..b4cd4d02 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupTransferFeeLogic.php @@ -0,0 +1,101 @@ + 'Update Group Transfer Fee', + 'message' => 'You have successfully updated transfer fee for this Group Transaction' + ]; + } + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** + * UpdateGroupTransferFeeLogic constructor. + * @param FetchesGroup $fetchesGroup + * @param CreatesTransaction $createsTransaction + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + */ + public function __construct(FetchesGroup $fetchesGroup, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber) + { + $this->fetchesGroup = $fetchesGroup; + $this->createsTransaction = $createsTransaction; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + $supplier = $group->issuerCompany; + $fee = $request->input('fee'); + + $transfer_fee = $group->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + if ($transfer_fee) { + $transfer_fee->amount = $fee; + $transfer_fee->original_amount = $fee; + $transfer_fee->save(); + } else { + $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); + $object = new TransactionObject($transferFeeNumber, TransactionType::TRANSFER_FEE, 1, $supplier->id, + $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $fee, $fee, $group->original_currency_id, $group->original_currency_id, + 1, 0, 0, null, ApprovalStatus::APPROVED); + + $model = new Transaction(); + $model->bill_no = $object->getBillNo(); + $model->type = $object->getTransactionType(); + $model->issuer = $object->getIssuer(); + $model->receiver = $object->getReceiver(); + $model->recipient_bank_account_id = $object->getRecipientBankAccountId(); + $model->payment_method = $object->getPaymentMethod(); + $model->amount = $object->getAmount(); + $model->original_amount = $object->getOriginalAmount(); + $model->currency_id = $object->getCurrencyId(); + $model->original_currency_id = $object->getOriginalCurrencyId(); + $model->currency_rate = $object->getCurrencyRate(); + $model->tax = $object->getTax(); + $model->service_charge = $object->getServiceCharge(); + $model->expires_on = $object->getExpiresOn(); + $model->status = $object->getStatus(); + $model->payment_reference = $object->getPaymentReference(); + + $group->morphTransactions()->save($model); + } + + return $this->resourceResponse(new GroupResource($group)); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php index cc98847a..771113c5 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -100,7 +100,7 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic $booking = $paymentTransaction->owner; - $reference = $refundTransaction->amount == $paymentTransaction->amount ? 'Fully Refund for Ref. ' . $booking->marking : 'Partially Refund for Ref. ' . $booking->marking; + $reference = $refundTransaction->amount - $paymentTransaction->amount < 0.01 ? 'Fully Refund for Ref. ' . $booking->marking : 'Partially Refund for Ref. ' . $booking->marking; $refundAmount = $this->calculatesBookingRefundAmount->calculateRefundAmount($paymentTransaction, $booking->fix_currency_id); @@ -111,10 +111,10 @@ class UpdateRefundTransactionStatusLogic extends AbstractControllerLogic $po_transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); if ($po_transaction) { - $this->updatesTransactionStatus->execute($po_transaction, (float) number_format($po_transaction->amount, 2, '.', '') === (float) number_format((float)$booking->fix_amount - $refundAmount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); + $this->updatesTransactionStatus->execute($po_transaction, (float) number_format($po_transaction->amount, 2, '.', '') === (float) number_format((float)$booking->fix_amount - $refundTransaction->original_amount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); } - $request['fix_amount'] = $booking->fix_amount - $refundAmount; + $request['fix_amount'] = $booking->fix_amount - $refundTransaction->original_amount; $request->route()->setParameter('id', $booking->id); $this->updateBookingAmountLogic->execute($request); } diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index 0f351c7d..7e484c6c 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -19,6 +19,7 @@ use App\Classes\Modules\Exports\Services\ExportsImportedInvoiceMappeds; use App\Models\TransactionMappingLog; use App\Classes\Modules\Exports\Services\ExportsReceiptTransactions; use App\Classes\Modules\Exports\Services\ExportsImportedReceiptMappeds; +use App\Classes\Modules\Exports\Services\ExportsWhiteFormTransactions; class ExportCustomersToExcelController { @@ -54,6 +55,13 @@ class ExportCustomersToExcelController return $response; } + public function whiteFormTransactions(Request $request){ + $exportsTransactions = new ExportsWhiteFormTransactions($request); + $response = $exportsTransactions->download('white-form-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } + public function walletTransactions(Request $request){ $exportsTransactions = new ExportsWalletTransactions($request); $response = $exportsTransactions->download('wallet-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); diff --git a/app/Http/Controllers/Transactions/UpdateGroupTransferFeeController.php b/app/Http/Controllers/Transactions/UpdateGroupTransferFeeController.php new file mode 100644 index 00000000..948dff39 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateGroupTransferFeeController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php index abd017ec..fdddd195 100644 --- a/app/Http/Resources/GroupResource.php +++ b/app/Http/Resources/GroupResource.php @@ -21,6 +21,13 @@ class GroupResource extends JsonResource */ public function toArray($request) { + $transfer_fee = $this->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + if ($transfer_fee) { + $transfer_fee = (float) $transfer_fee->amount; + } else { + $transfer_fee = 0; + } if(!$this->issuerCompany){ dd($this->id); @@ -36,6 +43,7 @@ class GroupResource extends JsonResource '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, + 'transfer_fee' => $transfer_fee, 'transactions' => $this->transactions()->get()->pluck('owner.owner.marking'), 'complete_transactions' => $this->transactions()->whereHasMorph('owner', [Transaction::class], function($query){ return $query->whereHas('booking', function($query){ diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index b431c854..d259d777 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -53,6 +53,7 @@ class TransactionResource extends JsonResource 'value' => $days->gt(Carbon::now()) ? '+' : '-', 'duration' => $days->diff(Carbon::now())->format('%d'), ], + 'remarks' => RemarkResource::collection($this->remarks), 'redemption' => new VoucherRedemptionResource($this->voucherRedemption) ]; } diff --git a/app/Models/Group.php b/app/Models/Group.php index 8cb6cd8a..2b8cceae 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -21,6 +21,14 @@ class Group extends Model implements Documentable return $this->belongsToMany(Transaction::class, GroupTransaction::class); } + /** + * @return MorphMany + */ + public function morphTransactions(): MorphMany + { + return $this->MorphMany(Transaction::class, 'owner'); + } + /** * @return MorphMany */ diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index aba5decc..31b67e69 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; +use App\Classes\General\Interfaces\Remarkable; use App\Classes\General\Interfaces\Transactionable; use App\Classes\General\Interfaces\Voucherifiable; use App\Classes\General\Traits\LogData; @@ -21,7 +22,7 @@ use Staudenmeir\EloquentHasManyDeep\HasTableAlias; use App\Models\StatementTransactionOwner; -class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable +class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable, Remarkable { use HasTableAlias; use SoftDeletes; diff --git a/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue b/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue index e93eb1ad..9a309cde 100644 --- a/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue @@ -216,6 +216,12 @@ {{ group.currency.short_code }} {{formatAmount(group.amount)}} +
+ Nothing To Show Here Yet!
+{{item.content}}
-