From de008d593e38bd7ed6e768827d64e2f9612c2c52 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Tue, 13 Aug 2024 15:59:07 +0800 Subject: [PATCH 1/6] Minor UI update to show Terms requested by KS --- .../elements/AvailableVouchersComponent.vue | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue index bcfd7219..a5fb4e3b 100644 --- a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue +++ b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue @@ -14,12 +14,43 @@ -->
- - Valid till {{ item.voucher.end_date }} - - - No expiry date - +
+ + Valid till {{ item.voucher.end_date }} + + + No expiry date + +
+
+ Terms +
+ +
+
+
+ Terms & Conditions +
+
+
    +
  1. Vouchers are only valid for purchases made on https://exchange.cief-malaysia.com/.
  2. +
  3. Each voucher is applicable for a single transaction (unless stated otherwise).
  4. +
  5. Each voucher is only applicable for new orders.
  6. +
  7. Voucher codes are to be entered at the checkout or cart page (unless stated otherwise).
  8. +
  9. Vouchers are not valid for promotions or discounted products (unless stated otherwise).
  10. +
  11. Customers should take note of the expiry dates of the voucher(s) that they wish to redeem. Any voucher(s) which have expired will be invalid.
  12. +
  13. Individual vouchers are only valid during its respective promotion period. This guideline overrides any individual voucher policy (unless stated otherwise).
  14. +
  15. CIEF reserves the right to cancel any order if a customer’s purchasing behavior appears to be suspicious or potentially fraudulent.
  16. +
  17. CIEF vouchers are not exchangeable for cash at https://exchange.cief-malaysia.com/.
  18. +
  19. This voucher can only be used and redeemed by a registered customer who has already logged into their account during purchase.
  20. +
  21. CIEF reserves the right to amend the terms & conditions or cancel any vouchers/promotions without prior notice.
  22. +
  23. Additional terms & conditions are stated on the respective promotion banners (e.g., duration, discount amounts, validity for campaigns/promotions or certain services).
  24. +
+ +
+
+
+
From 78c4b4db63950ff1519b5eb19bddf914c5471ccf Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 14 Aug 2024 09:44:19 +0800 Subject: [PATCH 2/6] delete refund --- .../DeleteRefundTransactionLogic.php | 113 ++++++++++++++++++ .../DeleteRefundTransactionController.php | 14 +++ .../elements/PaymentHistoryComponent.vue | 18 +++ routes/transaction.php | 2 + 4 files changed, 147 insertions(+) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php create mode 100644 app/Http/Controllers/Transactions/DeleteRefundTransactionController.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php new file mode 100644 index 00000000..ca8e0af3 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php @@ -0,0 +1,113 @@ + 'Deleted Refund Transaction', + 'message' => 'You have successfully deleted a transaction' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CalculatesBookingRefundAmount */ + private $calculatesBookingRefundAmount; + + /** @var CalculatesBookingPaidAmount */ + private $calculatesBookingPaidAmount; + + /** @var UpdateBookingAmountLogic */ + private $updateBookingAmountLogic; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param DeletesTransaction $deletesTransaction + * @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount + * @param UpdateBookingAmountLogic $updateBookingAmountLogic + * @param calculatesBookingPaidAmount $calculatesBookingPaidAmount + */ + public function __construct(FetchesTransaction $fetchesTransaction, DeletesTransaction $deletesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CalculatesBookingRefundAmount $calculatesBookingRefundAmount, UpdateBookingAmountLogic $updateBookingAmountLogic, CalculatesBookingPaidAmount $calculatesBookingPaidAmount) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->deletesTransaction = $deletesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount; + $this->updateBookingAmountLogic = $updateBookingAmountLogic; + $this->calculatesBookingPaidAmount = $calculatesBookingPaidAmount; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request): JsonResponse + { + // delete refund transaction + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + $this->deletesTransaction->execute($transaction); + + // Update payment_transaction status + $payment_transaction = $transaction->owner; + $this->updatesTransactionStatus->execute($payment_transaction, ApprovalStatus::APPROVED); + + // delete wallet top up transaction + $booking = $transaction->owner->owner; + Transaction::where('type', TransactionType::CREDIT_NOTE) + ->where('amount', $transaction->amount) + ->where('payment_reference', 'like', '%' . $booking->marking . '%') + ->delete(); + + // update back the latest booking amount + $request['fix_amount'] = $this->calculatesBookingPaidAmount->execute($booking); + $request->route()->setParameter('id', $booking->id); + $this->updateBookingAmountLogic->execute($request); + + // if have SUPPLIER_REFUND transaction + $bookingInWhiteForm = $payment_transaction->transactions()->bills()->first(); + if ($bookingInWhiteForm) { + + $whiteFormTransaction = Transaction::where('type', TransactionType::SUPPLIER_REFUND) + ->where('payment_reference', $transaction->payment_reference) + ->first(); + + + Log::info($whiteFormTransaction->id); + + $whiteFormTransaction->delete(); + } + + return $this->response([]); + } +} diff --git a/app/Http/Controllers/Transactions/DeleteRefundTransactionController.php b/app/Http/Controllers/Transactions/DeleteRefundTransactionController.php new file mode 100644 index 00000000..0940ce49 --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteRefundTransactionController.php @@ -0,0 +1,14 @@ +execute($request); + } +} \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index 939865b1..0d893096 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -392,6 +392,24 @@ +
+
+ + + + + +
+
diff --git a/routes/transaction.php b/routes/transaction.php index 51e9ab34..b9f70aa3 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -14,6 +14,8 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status'); Route::put('/{id}/refund/status/update/{status}', 'UpdateRefundTransactionStatusController@update')->name('refund.status.update'); + Route::delete('/refund/{id}/delete', 'DeleteRefundTransactionController@delete')->name('refund.delete'); + route::delete('{id}/bill/delete', 'DeletePaymentProofDocumentController@delete')->name('bill.delete'); Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); From 886a7b2767e4ccc3c9a1b635aea77ab4fe1af1b2 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 14 Aug 2024 09:48:51 +0800 Subject: [PATCH 3/6] delete refund --- .../ControllersLogic/DeleteRefundTransactionLogic.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php index ca8e0af3..65446adf 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteRefundTransactionLogic.php @@ -102,8 +102,7 @@ class DeleteRefundTransactionLogic extends AbstractControllerLogic ->where('payment_reference', $transaction->payment_reference) ->first(); - - Log::info($whiteFormTransaction->id); + // Log::info($whiteFormTransaction->id); $whiteFormTransaction->delete(); } From 6093ce896ef207c1c8b41cb4db848ddcc72e0250 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Tue, 20 Aug 2024 17:21:00 +0800 Subject: [PATCH 4/6] Allow user account to see and use all vouchers that belongs to all employees under the same company in checkout --- .../Filters/HasActiveRewardWithCompany.php | 53 +++++++++++++++++++ ...Reward.php => HasActiveRewardWithUser.php} | 2 +- .../Services/FetchesBookingQuotation.php | 20 ++++++- .../ControllersLogic/ValidateVoucherLogic.php | 21 +++++++- .../ValidateVoucherifyVoucherObject.php | 4 +- .../BookingToVoucherifyProcessor.php | 21 +++++++- app/Http/Resources/VoucherResource.php | 4 +- .../elements/AvailableVouchersComponent.vue | 2 +- .../elements/ListVouchersComponent.vue | 2 +- .../CustomerRewardsAdminSectionComponent.vue | 2 +- .../CustomerRewardsSectionComponent.vue | 2 +- 11 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php rename app/Classes/General/Eloquent/Filters/{HasActiveReward.php => HasActiveRewardWithUser.php} (96%) diff --git a/app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php b/app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php new file mode 100644 index 00000000..c9ff1f53 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php @@ -0,0 +1,53 @@ +type, RoleTypes::ADMIN_ROLES)){ + // $userId = $value !== 1 ? $value : Auth::user()->id; + $userId = $value; + $user = User::where('id', $userId)->first(); + $users = $user->company()->first()->employees; + $userIds = $users->pluck('id'); + + return $builder->whereIn('user_id', $userIds) + ->where(function ($query) { + $query->whereHas('reward', function ($subquery) { + $subquery->where('is_active', true); + }) + ->orWhereDoesntHave('reward'); + }) + ->whereDoesntHave('voucher.redemptions.transaction.booking.company.employees', function ($query) use ($userId) { + $query->where('user_id', $userId); + }); + } + else{ + $user = User::where('id', Auth::user()->id)->first(); + $users = $user->company()->first()->employees; + $userIds = $users->pluck('id'); + + return $builder->whereIn('user_id', $userIds) + ->where(function ($query) { + $query->whereHas('reward', function ($subquery) { + $subquery->where('is_active', true); + }) + ->orWhereDoesntHave('reward'); + }) + ->whereDoesntHave('voucher.redemptions.transaction.owner'); + } + } +} diff --git a/app/Classes/General/Eloquent/Filters/HasActiveReward.php b/app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php similarity index 96% rename from app/Classes/General/Eloquent/Filters/HasActiveReward.php rename to app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php index 5770ca6e..72d0d6e2 100644 --- a/app/Classes/General/Eloquent/Filters/HasActiveReward.php +++ b/app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php @@ -6,7 +6,7 @@ use App\Classes\ValueObjects\Constants\RoleTypes; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; -class HasActiveReward implements Filter +class HasActiveRewardWithUser implements Filter { /** diff --git a/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php b/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php index e5535e2a..feafba19 100644 --- a/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php +++ b/app/Classes/Modules/Bookings/Services/FetchesBookingQuotation.php @@ -70,8 +70,24 @@ class FetchesBookingQuotation //Voucherify if($voucherCode){ - $employee = $company->employees()->first(); - $validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee); + $employeeWhoOwnsTheVoucher = null; + + $employees = $company->first()->employees; + foreach($employees as $singleEmployee){ + $userRewards = $singleEmployee->rewards; + foreach($userRewards as $userReward){ + if ($userReward->voucher && $userReward->voucher->code === $voucherCode) { + Log::info('1. Company with multiple employees: ' . json_encode($singleEmployee) . ", voucher: " . $voucherCode); + $employeeWhoOwnsTheVoucher = $singleEmployee; + } + } + } + + if(!$employeeWhoOwnsTheVoucher){ + $employeeWhoOwnsTheVoucher = $company->employees()->first(); + } + + $validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employeeWhoOwnsTheVoucher); $result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject); $voucher = [ "code" => $result->code, diff --git a/app/Classes/Modules/Vouchers/ControllersLogic/ValidateVoucherLogic.php b/app/Classes/Modules/Vouchers/ControllersLogic/ValidateVoucherLogic.php index 30e7fe12..4530292f 100644 --- a/app/Classes/Modules/Vouchers/ControllersLogic/ValidateVoucherLogic.php +++ b/app/Classes/Modules/Vouchers/ControllersLogic/ValidateVoucherLogic.php @@ -10,6 +10,7 @@ use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherOb use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Models\Booking; +use Illuminate\Support\Facades\Log; class ValidateVoucherLogic extends AbstractControllerLogic { @@ -42,11 +43,27 @@ class ValidateVoucherLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { + $employeeWhoOwnsTheVoucher = null; $booking = Booking::find($request->input('itemId')); - $employee = $booking->company->employees()->first(); + $employees = $booking->company->employees()->get(); + + foreach($employees as $singleEmployee){ + $userRewards = $singleEmployee->rewards; + foreach($userRewards as $userReward){ + if ($userReward->voucher && $userReward->voucher->code === $request->input('voucherCode')) { + Log::info('2. Company with multiple employees: ' . json_encode($singleEmployee) . ", voucher: " . $request->input('voucherCode')); + $employeeWhoOwnsTheVoucher = $singleEmployee; + } + } + } + + if(!$employeeWhoOwnsTheVoucher){ + $employeeWhoOwnsTheVoucher = $booking->company->employees()->first(); + } + $amount = $this->floatvalue($request->input('amount')); - $validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($booking->company_id, $request->input('voucherCode'), $amount, $employee); + $validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($booking->company_id, $request->input('voucherCode'), $amount, $employeeWhoOwnsTheVoucher); $result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject); return $this->response(['data' => $result]); } diff --git a/app/Classes/Modules/Vouchers/DataTransferObjects/ValidateVoucherifyVoucherObject.php b/app/Classes/Modules/Vouchers/DataTransferObjects/ValidateVoucherifyVoucherObject.php index b48bee16..956afc00 100644 --- a/app/Classes/Modules/Vouchers/DataTransferObjects/ValidateVoucherifyVoucherObject.php +++ b/app/Classes/Modules/Vouchers/DataTransferObjects/ValidateVoucherifyVoucherObject.php @@ -17,8 +17,8 @@ class ValidateVoucherifyVoucherObject implements DataTransferObject /** @var float */ private $amount; - /** @var User */ - private $user; + /** @var User */ + private $user; //this will affect certain voucher that limit user redemption e.g. one user one redemption per campaign /** * ValidateVoucherifyVoucherObject constructor. diff --git a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php index 6f89916b..90fba55a 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php @@ -83,7 +83,24 @@ class BookingToVoucherifyProcessor $voucherify_customer_id = ""; $voucherify_order_id = ""; if($voucherCode){ - $redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $transaction->id, $voucherCode, $amount, $user); + $employeeWhoOwnsTheVoucher = null; + + $employees = $user->company()->first()->employees; + foreach($employees as $singleEmployee){ + $userRewards = $singleEmployee->rewards; + foreach($userRewards as $userReward){ + if ($userReward->voucher && $userReward->voucher->code === $voucherCode) { + Log::info('3. Company with multiple employees: ' . json_encode($singleEmployee) . ", voucher: " . $voucherCode); + $employeeWhoOwnsTheVoucher = $singleEmployee; + } + } + } + + if(!$employeeWhoOwnsTheVoucher){ + $employeeWhoOwnsTheVoucher = $user; + } + + $redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $transaction->id, $voucherCode, $amount, $employeeWhoOwnsTheVoucher); $redeemVoucherResult = $this->redeemsVoucherifyVoucher->execute($redeemVoucherifyVoucherObject); // Log::info('redeemVoucherResult: '.json_encode($redeemVoucherResult)); @@ -101,7 +118,7 @@ class BookingToVoucherifyProcessor $voucher = $this->recordVoucherInfo($redeemedVoucher); $this->createsVoucherRedemption->execute($transaction, $voucher, $redemptionId, $voucherDiscountAmount); - $this->recordVoucherForUserInfo($user, $voucher); + $this->recordVoucherForUserInfo($employeeWhoOwnsTheVoucher, $voucher); } else{ $createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $transaction->id, $amount, true, $transaction->type == TransactionType::TOP_UP); diff --git a/app/Http/Resources/VoucherResource.php b/app/Http/Resources/VoucherResource.php index 3f3112bb..7e372d5f 100644 --- a/app/Http/Resources/VoucherResource.php +++ b/app/Http/Resources/VoucherResource.php @@ -4,6 +4,7 @@ namespace App\Http\Resources; use ArrayObject; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Facades\Log; class VoucherResource extends JsonResource { @@ -16,7 +17,8 @@ class VoucherResource extends JsonResource public function toArray($request) { $filteredRedemptions = new ArrayObject([]); - if ($request->has('filters') && str_contains($request->input('filters'), "has_active_reward")) { + if ($request->has('filters') && (str_contains($request->input('filters'), "has_active_reward_with_user") )) { + //|| str_contains($request->input('filters'), "has_active_reward_with_company") $filteredRedemptions = new ArrayObject([]); } else{ diff --git a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue index a5fb4e3b..3fff52e8 100644 --- a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue +++ b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue @@ -95,7 +95,7 @@ fetchVouchers(){ this.isLoading = true; if(this.employee){ - this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward': this.employee.id} ), 'get', this.section, false, false); + this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward_with_company': this.employee.id} ), 'get', this.section, false, false); } }, successHandler(response){ diff --git a/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue b/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue index e55e5151..3b2eb5a0 100644 --- a/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue +++ b/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue @@ -76,7 +76,7 @@ fetchVouchers(){ this.isLoading = true; if(this.employee){ - this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward': this.employee.id} ), 'get', this.section, false, false); + this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward_with_company': this.employee.id} ), 'get', this.section, false, false); } }, successHandler(response){ diff --git a/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue index f28c88dd..7300f3ba 100644 --- a/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue @@ -57,7 +57,7 @@
- + diff --git a/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue index 83567aaf..7a97f22f 100644 --- a/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue @@ -52,7 +52,7 @@
- + From 2905edef5e2d3b831b22cf8f5037bd2d1d8ff3a8 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 21 Aug 2024 22:04:09 +0800 Subject: [PATCH 5/6] Amendment meant to resolve merge conflict in development branch from branch dillon/63.6-company-with-multiple-employees --- .../Eloquent/Filters/HasActiveReward.php | 27 +++++++++++++++++++ .../Filters/HasActiveRewardForAdmin.php | 26 ++++++++++++++++++ ...pany.php => HasVouchersAllWithCompany.php} | 2 +- ...ithUser.php => HasVouchersAllWithUser.php} | 2 +- app/Http/Resources/VoucherResource.php | 4 +-- .../elements/AvailableVouchersComponent.vue | 2 +- .../elements/ListVouchersComponent.vue | 2 +- .../CustomerRewardsAdminSectionComponent.vue | 9 +++++-- .../CustomerRewardsSectionComponent.vue | 15 +++++++---- 9 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/HasActiveReward.php create mode 100644 app/Classes/General/Eloquent/Filters/HasActiveRewardForAdmin.php rename app/Classes/General/Eloquent/Filters/{HasActiveRewardWithCompany.php => HasVouchersAllWithCompany.php} (97%) rename app/Classes/General/Eloquent/Filters/{HasActiveRewardWithUser.php => HasVouchersAllWithUser.php} (96%) diff --git a/app/Classes/General/Eloquent/Filters/HasActiveReward.php b/app/Classes/General/Eloquent/Filters/HasActiveReward.php new file mode 100644 index 00000000..26385b96 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/HasActiveReward.php @@ -0,0 +1,27 @@ +where('user_id', Auth::user()->id) //cief todo: should not use Auth::user()->id + ->where(function ($query) { + $query->whereHas('reward', function ($subquery) { + $subquery->where('is_active', true); + }); + // ->orWhereDoesntHave('reward'); + }); + } + +} diff --git a/app/Classes/General/Eloquent/Filters/HasActiveRewardForAdmin.php b/app/Classes/General/Eloquent/Filters/HasActiveRewardForAdmin.php new file mode 100644 index 00000000..5d69aa4b --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/HasActiveRewardForAdmin.php @@ -0,0 +1,26 @@ +where('user_id', $value) + ->where(function ($query) { + $query->whereHas('reward', function ($subquery) { + $subquery->where('is_active', true); + }); + // ->orWhereDoesntHave('reward'); + }); + } + +} diff --git a/app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php b/app/Classes/General/Eloquent/Filters/HasVouchersAllWithCompany.php similarity index 97% rename from app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php rename to app/Classes/General/Eloquent/Filters/HasVouchersAllWithCompany.php index c9ff1f53..be4d335b 100644 --- a/app/Classes/General/Eloquent/Filters/HasActiveRewardWithCompany.php +++ b/app/Classes/General/Eloquent/Filters/HasVouchersAllWithCompany.php @@ -7,7 +7,7 @@ use App\Models\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; -class HasActiveRewardWithCompany implements Filter +class HasVouchersAllWithCompany implements Filter { /** diff --git a/app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php b/app/Classes/General/Eloquent/Filters/HasVouchersAllWithUser.php similarity index 96% rename from app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php rename to app/Classes/General/Eloquent/Filters/HasVouchersAllWithUser.php index 72d0d6e2..79a02914 100644 --- a/app/Classes/General/Eloquent/Filters/HasActiveRewardWithUser.php +++ b/app/Classes/General/Eloquent/Filters/HasVouchersAllWithUser.php @@ -6,7 +6,7 @@ use App\Classes\ValueObjects\Constants\RoleTypes; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; -class HasActiveRewardWithUser implements Filter +class HasVouchersAllWithUser implements Filter { /** diff --git a/app/Http/Resources/VoucherResource.php b/app/Http/Resources/VoucherResource.php index 7e372d5f..55cc2b56 100644 --- a/app/Http/Resources/VoucherResource.php +++ b/app/Http/Resources/VoucherResource.php @@ -17,8 +17,8 @@ class VoucherResource extends JsonResource public function toArray($request) { $filteredRedemptions = new ArrayObject([]); - if ($request->has('filters') && (str_contains($request->input('filters'), "has_active_reward_with_user") )) { - //|| str_contains($request->input('filters'), "has_active_reward_with_company") + if ($request->has('filters') && (str_contains($request->input('filters'), "has_vouchers_all_with_user") )) { + //|| str_contains($request->input('filters'), "has_vouchers_all_with_company") $filteredRedemptions = new ArrayObject([]); } else{ diff --git a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue index 3fff52e8..0d52ff13 100644 --- a/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue +++ b/resources/assets/vue/components/bookings/elements/AvailableVouchersComponent.vue @@ -95,7 +95,7 @@ fetchVouchers(){ this.isLoading = true; if(this.employee){ - this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward_with_company': this.employee.id} ), 'get', this.section, false, false); + this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_vouchers_all_with_company': this.employee.id} ), 'get', this.section, false, false); } }, successHandler(response){ diff --git a/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue b/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue index 3b2eb5a0..cc8afbf2 100644 --- a/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue +++ b/resources/assets/vue/components/bookings/elements/ListVouchersComponent.vue @@ -76,7 +76,7 @@ fetchVouchers(){ this.isLoading = true; if(this.employee){ - this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_active_reward_with_company': this.employee.id} ), 'get', this.section, false, false); + this.submit(route('api.voucher.user.list') + '?filters=' + JSON.stringify( { 'has_vouchers_all_with_company': this.employee.id} ), 'get', this.section, false, false); } }, successHandler(response){ diff --git a/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue index 7300f3ba..d41c2b63 100644 --- a/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerRewardsAdminSectionComponent.vue @@ -57,7 +57,7 @@
- + @@ -74,10 +74,15 @@
- + + +
diff --git a/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue index 7a97f22f..f6143340 100644 --- a/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerRewardsSectionComponent.vue @@ -19,7 +19,7 @@
-
+
@@ -52,7 +52,7 @@
- + @@ -69,11 +69,16 @@
- + +
From 8c9264b26a015d9b17723e65f29f103eea846b84 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 23 Aug 2024 12:24:18 +0800 Subject: [PATCH 6/6] Solve a problem where voucher cannot be added to a user account if user does not exist at Voucherify --- .../General/Eloquent/Filters/RandomName.php | 20 ------------------- .../ControllersLogic/CreateVoucherLogic.php | 14 ++++++++++++- .../CreateVoucherifyCustomerObject.php | 6 +++--- .../NewCustomerToVoucherifyProcessor.php | 4 +++- 4 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 app/Classes/General/Eloquent/Filters/RandomName.php diff --git a/app/Classes/General/Eloquent/Filters/RandomName.php b/app/Classes/General/Eloquent/Filters/RandomName.php deleted file mode 100644 index 54024e96..00000000 --- a/app/Classes/General/Eloquent/Filters/RandomName.php +++ /dev/null @@ -1,20 +0,0 @@ -where('is_active', $value); - } - -} diff --git a/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php b/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php index 5c85895a..e345ebcf 100644 --- a/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php +++ b/app/Classes/Modules/Vouchers/ControllersLogic/CreateVoucherLogic.php @@ -11,6 +11,7 @@ use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher; use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyVoucherInACampaign; use App\Classes\Modules\Vouchers\Services\Voucherify\ListsVoucherifyVouchers; use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyCampaign; +use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyProcessor; use App\Classes\Modules\Vouchers\Services\CreatesVoucher; use App\Classes\Modules\Vouchers\Services\FetchesVoucher; use App\Classes\Modules\Vouchers\Services\UpdatesVoucherCampaign; @@ -75,6 +76,9 @@ class CreateVoucherLogic extends AbstractControllerLogic /** @var UpdatesVoucherCampaign */ private $updatesVoucherCampaign; + /** @var NewCustomerToVoucherifyProcessor */ + private $newCustomerToVoucherifyProcessor; + /** * CreateVoucherLogic constructor. * @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher @@ -87,8 +91,9 @@ class CreateVoucherLogic extends AbstractControllerLogic * @param CreatesKeyValuePair $createsKeyValuePair * @param UpdatesKeyValuePair $updatesKeyValuePair * @param UpdatesVoucherCampaign $updatesVoucherCampaign + * @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor */ - public function __construct(CreatesUserReward $createsUserReward, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, CreateVoucherProcessor $createVoucherProcessor, CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign, CanCreateVoucher $canCreateVoucher, ListsVoucherifyVouchers $listsVoucherifyVouchers, FetchesVoucherifyCampaign $fetchesVoucherifyCampaign, CreatesKeyValuePair $createsKeyValuePair, UpdatesKeyValuePair $updatesKeyValuePair, UpdatesVoucherCampaign $updatesVoucherCampaign) + public function __construct(CreatesUserReward $createsUserReward, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, CreateVoucherProcessor $createVoucherProcessor, CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign, CanCreateVoucher $canCreateVoucher, ListsVoucherifyVouchers $listsVoucherifyVouchers, FetchesVoucherifyCampaign $fetchesVoucherifyCampaign, CreatesKeyValuePair $createsKeyValuePair, UpdatesKeyValuePair $updatesKeyValuePair, UpdatesVoucherCampaign $updatesVoucherCampaign, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor) { $this->createsUserReward = $createsUserReward; $this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher; @@ -100,6 +105,7 @@ class CreateVoucherLogic extends AbstractControllerLogic $this->createsKeyValuePair = $createsKeyValuePair; $this->updatesKeyValuePair = $updatesKeyValuePair; $this->updatesVoucherCampaign = $updatesVoucherCampaign; + $this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor; } /** @@ -129,6 +135,12 @@ class CreateVoucherLogic extends AbstractControllerLogic $user = $userParam ? $userParam : $user; } + //Voucherify - To check if user exist at Voucherify, create if not exist + $voucherify_entity = $user->voucherifyEntities()->first(); + if(!$voucherify_entity){ + $this->newCustomerToVoucherifyProcessor->execute($user->company()->first()->id, $user, false); + } + //Voucherify - creates new voucher at voucherify if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 ) { $result = $this->newVoucherifyVoucherIssuanceHandler($voucherCodeInput); diff --git a/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyCustomerObject.php b/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyCustomerObject.php index 9678dafe..e61d1d00 100644 --- a/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyCustomerObject.php +++ b/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyCustomerObject.php @@ -65,9 +65,9 @@ class CreateVoucherifyCustomerObject implements DataTransferObject */ public function getAcquisitionChannel(): string { - if(!$this->isNew){ - return ""; - } + // if(!$this->isNew){ + // return ""; + // } return $this->acquisitionChannel; } diff --git a/app/Classes/Modules/Vouchers/Processors/Voucherify/NewCustomerToVoucherifyProcessor.php b/app/Classes/Modules/Vouchers/Processors/Voucherify/NewCustomerToVoucherifyProcessor.php index 006bcd94..3fd2ccee 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/NewCustomerToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/NewCustomerToVoucherifyProcessor.php @@ -44,7 +44,9 @@ class NewCustomerToVoucherifyProcessor $createVoucherifyCustomerObject = new CreateVoucherifyCustomerObject($companyId, $user, $isNew); $result = $this->createsVoucherifyCustomer->execute($createVoucherifyCustomerObject); - if($result && isset($result->id)){ + $voucherify_entity = $user->voucherifyEntities()->get(); + + if($result && isset($result->id) && count($voucherify_entity) === 0){ $voucherEntityObject = new VoucherEntityObject($result->id, VoucherifyEntityType::CUSTOMER); $this->createsVoucherEntityMapping->execute($createVoucherifyCustomerObject->getUser(), $voucherEntityObject); }