mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'dillon/63.7-company-with-multiple-employees' into 'master'
Allow user account to see and use all vouchers that belongs to all employees... See merge request CIEFWorldwideSdnBhd/exchange-2.0!176
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ class CreateVoucherifyCustomerObject implements DataTransferObject
|
||||
*/
|
||||
public function getAcquisitionChannel(): string
|
||||
{
|
||||
if(!$this->isNew){
|
||||
return "";
|
||||
}
|
||||
// if(!$this->isNew){
|
||||
// return "";
|
||||
// }
|
||||
return $this->acquisitionChannel;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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.
|
||||
|
||||
+19
-2
@@ -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);
|
||||
|
||||
+3
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user