diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteTransactionLogic.php index 56d24523..7fff74f5 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/DeleteTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteTransactionLogic.php @@ -30,7 +30,7 @@ class DeleteTransactionLogic extends AbstractControllerLogic /** - * SuspendTransactionLogic constructor. + * DeleteTransactionLogic constructor. * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus */ diff --git a/app/Classes/Modules/Transactions/ControllersLogic/WaiveTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/WaiveTransactionLogic.php new file mode 100644 index 00000000..61e48ac0 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/WaiveTransactionLogic.php @@ -0,0 +1,65 @@ + 'Waive Transaction', + 'message' => 'You have successfully waived the transaction' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionIsWaived */ + private $updatesTransactionIsWaived; + + /** @var CanWaiveTransaction */ + private $canWaiveTransaction; + + + /** + * WaiveTransactionLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionIsWaived $updatesTransactionIsWaived + * @param CanWaiveTransaction $canWaiveTransaction + */ + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionIsWaived $updatesTransactionIsWaived, CanWaiveTransaction $canWaiveTransaction) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionIsWaived = $updatesTransactionIsWaived; + $this->canWaiveTransaction = $canWaiveTransaction; + } + + + public function logic(Request $request) : JsonResponse + { + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $object = new WaiveTransactionObject($transaction->id, $transaction->bill_no, $transaction->type, $transaction->status); + $this->canWaiveTransaction->passes($object); + + $this->updatesTransactionIsWaived->execute($transaction); + Log::info(Auth::user()->email." waive storage invoice charges with bill_no: ".$transaction->bill_no); + + return $this->response([]); + } +} diff --git a/app/Classes/Modules/Transactions/DataTransferObjects/WaiveTransactionObject.php b/app/Classes/Modules/Transactions/DataTransferObjects/WaiveTransactionObject.php new file mode 100644 index 00000000..452a75d6 --- /dev/null +++ b/app/Classes/Modules/Transactions/DataTransferObjects/WaiveTransactionObject.php @@ -0,0 +1,61 @@ +id = $id; + $this->billNo = $billNo; + $this->type = $type; + $this->status = $status; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getBillNo(): string + { + return $this->billNo; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } +} diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransactionIsWaived.php b/app/Classes/Modules/Transactions/Services/UpdatesTransactionIsWaived.php new file mode 100644 index 00000000..9f9a6ae3 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransactionIsWaived.php @@ -0,0 +1,22 @@ +is_waived = 1; + + return $this->handler($model); + } +} diff --git a/app/Classes/Modules/Transactions/Standards/Rules/CanWaiveTransaction.php b/app/Classes/Modules/Transactions/Standards/Rules/CanWaiveTransaction.php new file mode 100644 index 00000000..5a596acb --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Rules/CanWaiveTransaction.php @@ -0,0 +1,58 @@ +waiveTransactionValidation = $waiveTransactionValidation; + } + + /** + * @return bool + */ + protected function authorized($object): bool + { + $user = Auth()->user(); + if($user){ + $roleToCheck = Auth()->user()->type; + if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) { + return true; + } + } + + return false; + } + + /** + * @param WaiveTransactionObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->waiveTransactionValidation->validate($object); + } + + /** + * @param $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Transactions/Standards/Validators/WaiveTransactionValidation.php b/app/Classes/Modules/Transactions/Standards/Validators/WaiveTransactionValidation.php new file mode 100644 index 00000000..d7a80ef3 --- /dev/null +++ b/app/Classes/Modules/Transactions/Standards/Validators/WaiveTransactionValidation.php @@ -0,0 +1,44 @@ + $object->getId(), + 'billNo' => $object->getBillNo(), + 'type' => $object->getType(), + 'status' => $object->getStatus(), + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'id' => 'required', + 'type' => ['required', 'numeric', 'in:16'], //Only storage invoice (type 16) can be waived + 'status' => ['required', 'numeric', 'in:2'], //Approve storage invoice only, paid invoice stricly forbidden + // 'billNo' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} diff --git a/app/Http/Controllers/Transactions/WaiveTransactionController.php b/app/Http/Controllers/Transactions/WaiveTransactionController.php new file mode 100644 index 00000000..cb36a973 --- /dev/null +++ b/app/Http/Controllers/Transactions/WaiveTransactionController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Resources/TransactionWithStorageResource.php b/app/Http/Resources/TransactionWithStorageResource.php index d9b0822f..d072913a 100644 --- a/app/Http/Resources/TransactionWithStorageResource.php +++ b/app/Http/Resources/TransactionWithStorageResource.php @@ -120,6 +120,7 @@ class TransactionWithStorageResource extends JsonResource ), 'remarks' => RemarkResource::collection($this->remarks), 'storages' => $this->storages ? $this->storages : null, //from middleware + 'is_waived' => (int) $this->is_waived, 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:s:i'), 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y'), 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y') diff --git a/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingVariant2Component.vue b/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingVariant2Component.vue index a8ce2941..dd73291f 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingVariant2Component.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/CustomerPaymentsBillingVariant2Component.vue @@ -68,11 +68,25 @@ +