Merge branch 'main' of https://github.com/WDI-Ideas/cheerstothe_season_laravel11 into sayli
This commit is contained in:
@@ -85,9 +85,11 @@ class StripeWebhookController extends Controller
|
||||
|
||||
|
||||
$isReferralSubscription = $metadata->is_referral_subscription;
|
||||
$isCustomReferralCodeApplied = $metadata->isCustomReferralCodeApplied;
|
||||
|
||||
$referralUserId = $metadata->referral_user_id;
|
||||
|
||||
if ($isReferralSubscription == 1) {
|
||||
if ($isReferralSubscription == 1 && $isCustomReferralCodeApplied == 0) {
|
||||
//who has refer the Subscription to Current user
|
||||
Log::info("Referral User Subscription Updating Function Starts");
|
||||
|
||||
@@ -180,7 +182,8 @@ class StripeWebhookController extends Controller
|
||||
]);
|
||||
|
||||
$id = Subscriptions::updateOrCreate(
|
||||
['iam_principal_xid' => $userId, 'subscription_product_xid' => $subscriptionProductId],
|
||||
['iam_principal_xid' => $userId,
|
||||
'subscription_product_xid' => $subscriptionProductId],
|
||||
[
|
||||
'subscription_id' => $subscriptionData->subscription,
|
||||
'amount' => $amountSubtotalDollars,
|
||||
@@ -197,7 +200,7 @@ class StripeWebhookController extends Controller
|
||||
]
|
||||
);
|
||||
|
||||
if ($isReferralSubscription == 1) {
|
||||
if ($isReferralSubscription == 1 && $isCustomReferralCodeApplied == 1) {
|
||||
|
||||
Log::info("new User Subscription Updating Function Starts");
|
||||
|
||||
@@ -243,6 +246,7 @@ class StripeWebhookController extends Controller
|
||||
'iam_principal_xid' => $referralUserId, //Referral User Xid
|
||||
'referred_user_xid' => $userId, // new user Id
|
||||
'referred_date_time' => Carbon::now(),
|
||||
'isCustomReferralCodeApplied' =>$isCustomReferralCodeApplied
|
||||
]);
|
||||
Log::info("Created entry in Referral User table");
|
||||
|
||||
@@ -256,9 +260,6 @@ class StripeWebhookController extends Controller
|
||||
|
||||
onesignalhelper::sendNotificationApi($getUserData->one_signal_player_id, $title, $message, $content_type, $image = null, $id = null);
|
||||
|
||||
|
||||
|
||||
|
||||
Log::info('Subscription Taken Successfully by ');
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\APIs\Customer_API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CustomReferralCode;
|
||||
use App\Models\Faq;
|
||||
use App\Models\IamPrincipal;
|
||||
use App\Models\SubscriptionProducts;
|
||||
@@ -28,12 +29,12 @@ class SubscriptionController extends Controller
|
||||
{
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
|
||||
$getCustomToken = CustomReferralCode::where('is_active',1)->first();
|
||||
// $token = true;
|
||||
|
||||
// dd($token, Session::get('vendorToken'));
|
||||
if ($token) {
|
||||
// $user_id = 54;
|
||||
// $user_id = 104;
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$dateTime = now();
|
||||
@@ -56,7 +57,7 @@ class SubscriptionController extends Controller
|
||||
$productList = SubscriptionProducts::where('is_active', 1)->first();
|
||||
$faqs = Faq::where('faq_category_id',3)->where('is_active','1')->get(); //getting only subscription faqS
|
||||
|
||||
return view('Admin.pages.subscriptions.list-of-products', compact('productList', 'userData','faqs'));
|
||||
return view('Admin.pages.subscriptions.list-of-products', compact('productList', 'userData','faqs','getCustomToken'));
|
||||
} else {
|
||||
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
||||
}
|
||||
@@ -242,9 +243,18 @@ class SubscriptionController extends Controller
|
||||
|
||||
public function subscriptionToPlan(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
dd($request->all());
|
||||
|
||||
try {
|
||||
$isCustomReferralCodeApplied = 0;
|
||||
$customReferralCode = CustomReferralCode::where('is_active',1)->first();
|
||||
|
||||
if($customReferralCode && $customReferralCode->referral_code &&
|
||||
$customReferralCode->referral_code == $request->referral_code_to_check){
|
||||
$isCustomReferralCodeApplied = 1;
|
||||
}else{
|
||||
$isCustomReferralCodeApplied = 0;
|
||||
}
|
||||
$isReferralSubscription = 0;
|
||||
$referralUserId = $request->referral_user_id;
|
||||
if ($referralUserId && $referralUserId != null) {
|
||||
@@ -288,6 +298,7 @@ class SubscriptionController extends Controller
|
||||
|
||||
'is_referral_subscription' => $isReferralSubscription,
|
||||
'referral_user_id' => $referralUserId,
|
||||
'isCustomReferralCodeApplied'=> $isCustomReferralCodeApplied
|
||||
|
||||
],
|
||||
'success_url' => route('thankyou'),
|
||||
@@ -409,10 +420,13 @@ class SubscriptionController extends Controller
|
||||
$referralCode = $request->input('referral_code');
|
||||
$currentUserId = $request->input('current_iam_principal_xid');
|
||||
$code = IamPrincipal::where('referral_code', $referralCode)->where('id', '!=', $currentUserId)->where('principal_type_xid', 3)->first();
|
||||
|
||||
if ($code) {
|
||||
return response()->json(['success' => true, 'message' => 'Successfully applied referral code!', 'referralUserId' => $code->id]);
|
||||
} else {
|
||||
$customCode = CustomReferralCode::where('is_active',1)->where('referral_code',$referralCode)->first();
|
||||
if ($code ) {
|
||||
return response()->json(['success' => true, 'message' => 'Successfully applied referral code!', 'referralUserId' => $code->id ,'referral_code'=>$referralCode]);
|
||||
} else if( $customCode) {
|
||||
return response()->json(['success' => true, 'message' => 'Successfully applied referral code!', 'referralUserId' => $customCode->id ,'referral_code'=>$referralCode]);
|
||||
|
||||
}else{
|
||||
return response()->json(['success' => false, 'message' => 'Invalid referral code.']);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CustomReferralCode;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\IamPrincipal;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -32,6 +33,7 @@ class DashboardController extends Controller
|
||||
->orderBy(DB::raw("DATE(created_at)"))
|
||||
->pluck('count', 'date')
|
||||
->toArray();
|
||||
$customReferralCode = CustomReferralCode::where('is_active',1)->first();
|
||||
|
||||
$start_date = now()->subDays(7)->startOfDay();
|
||||
$end_date = now()->endOfDay();
|
||||
@@ -148,6 +150,7 @@ class DashboardController extends Controller
|
||||
|
||||
|
||||
return view('Admin.dashboard', compact(
|
||||
'customReferralCode',
|
||||
'customerCount',
|
||||
'restaurantCount',
|
||||
'dataMonthlyWithType3',
|
||||
@@ -163,11 +166,45 @@ class DashboardController extends Controller
|
||||
'formattedDefaultData',
|
||||
'quarterlyData',
|
||||
'yearlyData'
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
Created By : Hritik
|
||||
Created at : 02 Aug 2024
|
||||
Use : To Store or Update Custom Referral Code
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function createOrUpdateReferralCode(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
if($request->id){
|
||||
CustomReferralCode::updateOrCreate(['id', $request->id], [
|
||||
'referral_code' => $request->referral_code,
|
||||
]);
|
||||
}else{
|
||||
CustomReferralCode::updateOrCreate([
|
||||
'referral_code' => $request->referral_code,
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['status_code' => 200]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
\Log::error('Storing Referral Code function failed: ' . $e->getMessage());
|
||||
return response()->json(['error' => 'Something went wrong while storing Data.', 'status_code' => 500], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 08 July 2024
|
||||
|
||||
14
app/Models/CustomReferralCode.php
Normal file
14
app/Models/CustomReferralCode.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomReferralCode extends Model
|
||||
{
|
||||
protected $table = 'custom_referral_code';
|
||||
|
||||
use HasFactory;
|
||||
protected $guarded = [ ];
|
||||
}
|
||||
@@ -1181,6 +1181,23 @@ div#zero-config_filter {
|
||||
font-weight: 700;
|
||||
gap: 3px;
|
||||
}
|
||||
.download-btn-cancel {
|
||||
cursor: pointer;
|
||||
color: #000;
|
||||
padding: 10px;
|
||||
background: #fb2020;
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 50%;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
gap: 3px;
|
||||
}
|
||||
.download-btn-cancel:hover {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.download-btn-custom img {
|
||||
width: 17px;
|
||||
|
||||
@@ -12,6 +12,52 @@
|
||||
<h6 class="card-title">Dashboard</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 d-flex align-items-center gap-3 p-0 mb-4">
|
||||
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@if(!$customReferralCode )
|
||||
<form id="create_custom_referral_code" enctype="multipart/form-data">
|
||||
{{ csrf_field() }}
|
||||
<h5>Create Custom Referral Code:-
|
||||
|
||||
</h5>
|
||||
|
||||
<input type="text" class="form-control" name="referral_code"
|
||||
id="referral_code" value="" placeholder="Enter Referral Code"
|
||||
oninput="this.value = this.value.toUpperCase()" maxlength="15">
|
||||
<div class="">
|
||||
<button id="create_custom_code" type="submit" class="download-btn-custom mt-3 custom-width-10">Submit</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@endif
|
||||
@if($customReferralCode && $customReferralCode->referral_code)
|
||||
<form id="create_custom_referral_code" enctype="multipart/form-data">
|
||||
{{ csrf_field() }}
|
||||
<h5>My Custom Referral Code:-
|
||||
|
||||
</h5>
|
||||
|
||||
<input type="text" class="form-control" name="referral_code"
|
||||
id="referral_code" value="{{$customReferralCode->referral_code}}" placeholder="Enter Referral Code"
|
||||
oninput="this.value = this.value.toUpperCase()" maxlength="15">
|
||||
<input type="hidden" name="id" value="{{$customReferralCode->id}}"/>
|
||||
<div class="d-flex" style="justify-content: space-between;">
|
||||
<button id="create_custom_code" type="submit" class="download-btn-custom mt-3 custom-width-10">Update</button>
|
||||
<button id="create_custom_code" type="submit" class="download-btn-cancel mt-3 custom-width-10">Deactivate Code</button>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="col-12 d-flex align-items-center gap-3 p-0 mb-4">
|
||||
<div class="col-6">
|
||||
@@ -143,21 +189,24 @@
|
||||
{{ $transaction['subscription']['first_name'] ?? 'Deleted' }}
|
||||
{{ $transaction['subscription']['last_name'] ?? 'User' }}
|
||||
</td>
|
||||
<td class="text-start">{{ $transaction['subscription']['id'] ?? 'Deleted User' }}</td>
|
||||
<td class="text-start">$ {{ $transaction['amount'] ?? 'Deleted User'}}</td>
|
||||
<td class="text-start"> {{ $transaction['status'] ?? 'Deleted User'}}</td>
|
||||
<td class="text-start">
|
||||
{{ $transaction['subscription']['id'] ?? 'Deleted User' }}</td>
|
||||
<td class="text-start">$ {{ $transaction['amount'] ?? 'Deleted User' }}
|
||||
</td>
|
||||
<td class="text-start"> {{ $transaction['status'] ?? 'Deleted User' }}
|
||||
</td>
|
||||
<td class="text-start">
|
||||
<a class="view-btn m-0 pointer sub_admin_permission"
|
||||
data-toggle="modal" data-target="#payment-details-modal"
|
||||
data-id="{{ $transaction['id'] ?? 'Deleted User'}}"
|
||||
data-name="{{ $transaction['subscription']['first_name'] ?? 'Deleted User' }}"
|
||||
data-id="{{ $transaction['id'] ?? 'Deleted User' }}"
|
||||
data-name="{{ $transaction['subscription']['first_name'] ?? 'Deleted User' }}"
|
||||
data-price="{{ $transaction['amount'] ?? 'Deleted User' }}"
|
||||
data-subscription-id="{{ $transaction['subscription_id'] ?? 'Deleted User' }}"
|
||||
data-customer-id="{{ $transaction['stripe_customer_id'] ?? 'Deleted User' }}"
|
||||
data-subscription-status="{{ $transaction['status'] ?? 'Deleted User'}}"
|
||||
data-start-date="{{ $transaction['current_period_start'] ?? 'Deleted User'}}"
|
||||
data-end-date="{{ $transaction['current_period_end'] ?? 'Deleted User'}}"
|
||||
data-next-date="{{ $transaction['next_payment_date']?? 'Deleted User' }}">View</a>
|
||||
data-subscription-status="{{ $transaction['status'] ?? 'Deleted User' }}"
|
||||
data-start-date="{{ $transaction['current_period_start'] ?? 'Deleted User' }}"
|
||||
data-end-date="{{ $transaction['current_period_end'] ?? 'Deleted User' }}"
|
||||
data-next-date="{{ $transaction['next_payment_date'] ?? 'Deleted User' }}">View</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@@ -223,6 +272,75 @@
|
||||
@endsection
|
||||
|
||||
@section('section_script')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
$.validator.addMethod("lettersOnly", function(value, element) {
|
||||
return this.optional(element) || /^[a-zA-Z\s]+$/.test(value);
|
||||
}, "Please enter only alphabets");
|
||||
|
||||
$.validator.addMethod("numbersOnly", function(value, element) {
|
||||
return this.optional(element) || /^[0-9]+$/.test(value);
|
||||
}, "Please enter only numbers");
|
||||
|
||||
$('#create_custom_referral_code').validate({
|
||||
rules: {
|
||||
referral_code: {
|
||||
required: true,
|
||||
},
|
||||
|
||||
},
|
||||
messages: {
|
||||
referral_code: {
|
||||
required: "Kindly Enter Referral Code.",
|
||||
},
|
||||
|
||||
},
|
||||
errorClass: 'error-message',
|
||||
submitHandler: function(form) {
|
||||
let b_url = url_path;
|
||||
$("#create_custom_code").html("Please Wait...");
|
||||
$("#create_custom_code").prop("disabled", true);
|
||||
var formData = new FormData(form);
|
||||
$.ajax({
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
|
||||
"content"),
|
||||
},
|
||||
type: "post",
|
||||
url: "{{ route('create-update-referral-code') }}",
|
||||
data: formData,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function(result) {
|
||||
|
||||
console.log("result", result);
|
||||
if (result.status_code == 200) {
|
||||
toastr.success('Referral code submitted successfully');
|
||||
setTimeout(function() {
|
||||
window.location.href = b_url +
|
||||
"/dashboard";
|
||||
}, 2000);
|
||||
} else if (result.status_code == 500) {
|
||||
toastr.error(result.message);
|
||||
setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
} else {
|
||||
toastr.error('Something Went Wrong');
|
||||
setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
}
|
||||
$('#create_custom_code').attr('disabled', false);
|
||||
$('#create_custom_code').text('Submit');
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$('#zero-config').DataTable({
|
||||
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" +
|
||||
|
||||
@@ -154,6 +154,8 @@
|
||||
<input type="hidden" name="user_id" value="{{ $userData->id }}" />
|
||||
<input type="hidden" name="subscription_product_xid" value="{{ $productList->id }}" />
|
||||
<input type="hidden" name="referral_user_id" id="referral_user_id" />
|
||||
<input type="hidden" name="referral_code_to_check" id="referral_code_to_check" />
|
||||
|
||||
<div class="main-text">
|
||||
<div>
|
||||
<p class="comm-head">Total Payment</p>
|
||||
@@ -285,9 +287,11 @@
|
||||
var loader = document.getElementById('loader');
|
||||
var resultMessage = document.getElementById('result-message');
|
||||
var referralUserIdToStore = document.getElementById('referral_user_id');
|
||||
var referralCodeToCheck = document.getElementById('referral_code_to_check');
|
||||
|
||||
// Show the loader
|
||||
// Show the loader
|
||||
loader.style.display = 'block';
|
||||
|
||||
resultMessage.innerHTML = '';
|
||||
let base_url = url_path;
|
||||
|
||||
@@ -297,8 +301,6 @@
|
||||
setTimeout(function() {
|
||||
|
||||
}, 100000)
|
||||
|
||||
|
||||
// alert('kindly apply referral code');
|
||||
loader.style.display = 'none';
|
||||
return false;
|
||||
@@ -318,15 +320,16 @@
|
||||
contentType: false,
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
console.log("Result",result);
|
||||
document.getElementById('isCodeNotApplied').style.display = 'none';
|
||||
document.getElementById('isCodeApplied').style.display = 'block';
|
||||
|
||||
resultMessage.innerHTML =
|
||||
'<span class="text-success">Successfully applied Referral code!</span>';
|
||||
|
||||
console.log("success", result);
|
||||
referralUserIdToStore.value = result.referralUserId;
|
||||
|
||||
referralCodeToCheck.value = result.referral_code;
|
||||
loader.style.display = 'none';
|
||||
} else {
|
||||
resultMessage.innerHTML = '<span class="text-danger">Invalid referral code.</span>';
|
||||
|
||||
@@ -65,6 +65,9 @@ Route::group(['middleware' => ['checkStatus']], function () {
|
||||
|
||||
|
||||
Route::get('/dashboard', [DashboardController::class, 'showDashboard'])->name('dashboard');
|
||||
Route::POST('/create-update-referral-code', [DashboardController::class, 'createOrUpdateReferralCode'])->name('create-update-referral-code');
|
||||
|
||||
|
||||
Route::post('/export/recent-transactions', [DashboardController::class, 'exportRecentTransactions'])->name('export.recent.transactions');
|
||||
|
||||
Route::get('/profile', [ManageProfileController::class, 'index'])->name('profile');
|
||||
|
||||
Reference in New Issue
Block a user