427 lines
20 KiB
PHP
427 lines
20 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use Mail;
|
|
use App\Models\User;
|
|
use App\Models\Company;
|
|
use App\Mail\SentBuyerMail;
|
|
use Illuminate\Http\Request;
|
|
use App\Notifications\UserAdmin;
|
|
use App\Models\Admin\BuyerSentMail;
|
|
use App\Models\MarketplaceBuyerForm;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\MarketplaceSellerForm;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use App\Models\MarketplaceOtherProductsSeller;
|
|
use App\Models\MarketplaceFractionalRealEstateSeller;
|
|
use App\Models\MarketplaceAlternativeInvestmentFundSeller;
|
|
use App\Exports\InvestmentExport;
|
|
use Excel;
|
|
|
|
class OverviewController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$check = checkSidebarAccess('overview');
|
|
if (!$check) {
|
|
abort(404);
|
|
}
|
|
$totalSellerProfile = MarketplaceSellerForm::count();
|
|
$completedTransactions = MarketplaceBuyerForm::where('status', 'Sold')->count();
|
|
$totalInvestmentListed = MarketplaceAlternativeInvestmentFundSeller::count() + MarketplaceFractionalRealEstateSeller::count() + MarketplaceOtherProductsSeller::count();
|
|
$aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::where('status', 'Approved')->latest()->get();
|
|
$freMarketPlace = MarketplaceFractionalRealEstateSeller::where('status', 'Approved')->latest()->get();
|
|
// dd($freMarketPlace);
|
|
$opMarketPlace = MarketplaceOtherProductsSeller::where('status', 'Approved')->latest()->get();
|
|
$allMarketPlace = collect();
|
|
foreach($aifMarketPlace as $data)
|
|
{
|
|
$data->table = 'marketplace_aif_sellers';
|
|
$allMarketPlace->push($data);
|
|
}
|
|
foreach($freMarketPlace as $data)
|
|
{
|
|
$data->table = 'marketplace_fre_sellers';
|
|
$allMarketPlace->push($data);
|
|
}
|
|
|
|
$allMarketPlace = $allMarketPlace->sortByDesc('created_at');
|
|
// dd($allMarketPlace);
|
|
return view('Admin.Pages.pre_owned_investment.pre_owned_investment', compact('aifMarketPlace', 'freMarketPlace', 'opMarketPlace', 'totalSellerProfile', 'completedTransactions', 'totalInvestmentListed','allMarketPlace'));
|
|
}
|
|
|
|
public function downloadInvestment()
|
|
{
|
|
|
|
// $aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::with(['seller' => function($query){$query->select('name as SellerName','email as Email','contact_number as Contact')->get();}])->where('status', 'Approved')->latest()->select('name_of_the_aif_fund as Product','expected_sale_per_unit as ExpectedSellingPrice','listing_status as ListingStatus')->get();
|
|
$aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('status', 'Approved')->latest()->get();
|
|
$freMarketPlace = MarketplaceFractionalRealEstateSeller::with('seller')->where('status', 'Approved')->latest()->get();
|
|
// $aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('status', 'Approved')->latest()->get();
|
|
// $freMarketPlace = MarketplaceFractionalRealEstateSeller::with('seller')->where('status', 'Approved')->latest()->get();
|
|
$allMarketPlace = collect();
|
|
$newData = [];
|
|
$count = 0;
|
|
foreach($aifMarketPlace as $data)
|
|
{
|
|
// $data['table'] = 'marketplace_aif_sellers';
|
|
// $newData[$count]['Product'] = $data->name_of_the_aif_fund;
|
|
// $newData[$count]['ExpectedSellingPrice'] = $data->expected_sale_per_unit ;
|
|
// $newData[$count]['SellerName'] = $data->seller->name;
|
|
// $newData[$count]['Email'] = $data->seller->email;
|
|
// $newData[$count]['Contact'] = $data->seller->contact_number;
|
|
// $newData[$count]['ListingStatus'] = $data->listing_status;
|
|
// $newData[$count]['CreatedAt'] = $data->created_at->format('F d, o');
|
|
$newData = array(
|
|
"Product" => $data->name_of_the_aif_fund,
|
|
"ExpectedSellingPrice" => $data->expected_sale_per_unit,
|
|
"SellerName" => $data->seller->name,
|
|
"Email" => $data->seller->email,
|
|
"Contact" => $data->seller->contact_number,
|
|
"ListingStatus" => $data->listing_status,
|
|
"CreatedAt" => $data->created_at->format('F d, o')
|
|
);
|
|
$allMarketPlace->push($newData);
|
|
$count++;
|
|
}
|
|
foreach($freMarketPlace as $data)
|
|
{
|
|
// $newData[$count]['Product'] = $data->property_name;
|
|
// $newData[$count]['ExpectedSellingPrice'] = $data->expected_selling_price ;
|
|
// $newData[$count]['SellerName'] = $data->seller->name;
|
|
// $newData[$count]['Email'] = $data->seller->email;
|
|
// $newData[$count]['Contact'] = $data->seller->contact_number;
|
|
// $newData[$count]['ListingStatus'] = $data->listing_status;
|
|
// $newData[$count]['CreatedAt'] = $data->created_at->format('F d, o');
|
|
$newData = array(
|
|
"Product" => $data->property_name,
|
|
"ExpectedSellingPrice" => $data->expected_selling_price ,
|
|
"SellerName" => $data->seller->name,
|
|
"Email" => $data->seller->email,
|
|
"Contact" => $data->seller->contact_number,
|
|
"ListingStatus" => $data->listing_status,
|
|
"CreatedAt" => $data->created_at->format('F d, o')
|
|
);
|
|
$allMarketPlace->push($newData);
|
|
$count++;
|
|
}
|
|
// dd($allMarketPlace->sortByDesc('created_at'));
|
|
// return $allMarketPlace->sortByDesc('created_at');
|
|
// dd($allMarketPlace);
|
|
|
|
return Excel::download(new InvestmentExport($allMarketPlace), 'investmentExport.xlsx');
|
|
}
|
|
|
|
public function interestedBuyers($id, $table)
|
|
{
|
|
$interestedBuyers = MarketplaceBuyerForm::where(['associated_id' => $id, 'table' => $table])->orderBy('updated_at','DESC')->get();
|
|
|
|
if ($table == 'marketplace_fre_sellers') {
|
|
$data = MarketplaceFractionalRealEstateSeller::with('seller')->where('id', $id)->firstOrFail();
|
|
} elseif ($table == 'marketplace_aif_sellers') {
|
|
$data = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('id', $id)->firstOrFail();
|
|
} elseif ($table == 'marketplace_op_sellers') {
|
|
$data = MarketplaceOtherProductsSeller::with('seller')->where('id', $id)->firstOrFail();
|
|
} else {
|
|
abort(404);
|
|
}
|
|
$backId = $id;
|
|
$backTable = $table;
|
|
return view('Admin.Pages.pre_owned_investment.interested-buyers', compact('interestedBuyers', 'data', 'backId', 'backTable'));
|
|
}
|
|
|
|
public function listingFeaturedStatus(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
$listingStatus = $request->listing_status;
|
|
$id = $request->id;
|
|
$table = $request->table;
|
|
|
|
if (!($table == 'marketplace_aif_sellers' || $table == 'marketplace_fre_sellers' || $table == 'marketplace_op_sellers')) {
|
|
abort(404);
|
|
}
|
|
|
|
if ($listingStatus == 'Spotlight') {
|
|
$checkSpotlightExists = MarketplaceFractionalRealEstateSeller::where('listing_status', 'Spotlight')->exists() || MarketplaceAlternativeInvestmentFundSeller::where('listing_status', 'Spotlight')->exists() || MarketplaceOtherProductsSeller::where('listing_status', 'Spotlight')->exists();
|
|
if ($checkSpotlightExists) {
|
|
return response()->json(['status' => 400, 'message' => 'An Investment Already Listed With Spotlight!']);
|
|
}
|
|
}
|
|
|
|
|
|
$data = \DB::table($table)->join('marketplace_seller_forms', $table . '.seller_forms_id', 'marketplace_seller_forms.id')->where($table . '.id', $id)->first();
|
|
|
|
$changeListingStatus = \DB::table($table)->where('id', $id)->update([
|
|
'listing_status' => $listingStatus
|
|
]);
|
|
// if ($changeListingStatus && $listingStatus != 'Hide') {
|
|
if ($listingStatus != 'Hide') {
|
|
if( $listingStatus != 'Non-Featured')
|
|
{
|
|
$user = User::find($data->users_id);
|
|
$productName = $data->security_name ?? $data->property_name ?? $data->name_of_the_aif_fund;
|
|
$notify['message'] = "Congratulations, Your investment($productName) has been assigned to $listingStatus section!";
|
|
$user->notify(new UserAdmin($notify));
|
|
return response()->json(['status' => 200, 'message' => 'Listing Status Changed!']);
|
|
}
|
|
}
|
|
// dd($changeListingStatus);
|
|
// return response()->json(['status' => 400, 'message' => 'Error Changing Listing Status!']);
|
|
return response()->json(['status' => 200, 'message' => 'Listing Status Changed!']);
|
|
}
|
|
|
|
public function changeStatusBuyer(Request $request)
|
|
{
|
|
$status = $request->status;
|
|
$buyerId = $request->buyer_id;
|
|
// if ($status == 'Sold') {
|
|
// $alreadySold = MarketplaceBuyerForm::where('status', 'Sold')->exists();
|
|
// if ($alreadySold) {
|
|
// return response()->json(['status' => 400, 'message' => 'This product has already been Sold']);
|
|
// }
|
|
// }
|
|
// $checkAlreadySold = MarketplaceBuyerForm::where(['id'=>$buyerId,'status'=>'Sold'])->first();
|
|
// if($checkAlreadySold)
|
|
// {
|
|
// $marketPlaceId = $checkAlreadySold->associated_id;
|
|
// if(MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->exists())
|
|
// {
|
|
// $getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first();
|
|
// $oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell;
|
|
// $newUnits = (int)$checkAlreadySold->no_of_units_you_wish_to_buy + $oldUnit;
|
|
// $updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([
|
|
// 'no_of_units_you_wish_to_sell' => $newUnits,
|
|
// ]);
|
|
|
|
// }
|
|
// // elseif(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists())
|
|
// // {
|
|
// // $getAIFData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first();
|
|
// // $oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell;
|
|
// // $newUnits = (int)$checkAlreadySold->no_of_units_you_wish_to_buy + $oldUnit;
|
|
// // $updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([
|
|
// // 'no_of_units_you_wish_to_sell' => $newUnits,
|
|
// // ]);
|
|
|
|
// // }
|
|
// }else
|
|
|
|
|
|
if($status == 'Sold'){
|
|
$getMarketplaceBuyerUnit = MarketplaceBuyerForm::where('id', $buyerId)->first();
|
|
$marketPlaceId = $getMarketplaceBuyerUnit->associated_id;
|
|
$getUnits = (int)$getMarketplaceBuyerUnit->no_of_units_you_wish_to_buy;
|
|
if(MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->exists())
|
|
{
|
|
$getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first();
|
|
$oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell;
|
|
$newUnits = $oldUnit - (int)$getUnits;
|
|
if($newUnits >= 0)
|
|
{
|
|
$updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([
|
|
'no_of_units_you_wish_to_sell' => $newUnits,
|
|
]);
|
|
}
|
|
else{
|
|
return response()->json(['status' => 400, 'message' => 'Bid units is more than seller units with '.abs($newUnits).' units']);
|
|
}
|
|
|
|
}
|
|
}
|
|
$alreadySold = MarketplaceBuyerForm::where('id', $buyerId)->update([
|
|
'status' => $status
|
|
]);
|
|
return response()->json(['status' => 200, 'message' => 'Status Changed!']);
|
|
}
|
|
|
|
public function listingTransfer()
|
|
{
|
|
$check = checkSidebarAccess('investment-`listing-transfer`');
|
|
if (!$check) {
|
|
abort(404);
|
|
}
|
|
// $freMarketPlace = MarketplaceFractionalRealEstateSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
// $aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
// $opMarketPlace = MarketplaceOtherProductsSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
// dd($aifMarketPlace[29]);
|
|
|
|
|
|
//new by hritik
|
|
$freMarketPlace = MarketplaceFractionalRealEstateSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
$aifMarketPlace = MarketplaceAlternativeInvestmentFundSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
$opMarketPlace = MarketplaceOtherProductsSeller::with('seller')->orderBy('created_at', 'desc')->get();
|
|
|
|
$combinedData = collect();
|
|
foreach ($freMarketPlace as $freData) {
|
|
$freData->table = 'marketplace_fre_sellers';
|
|
$combinedData->push($freData);
|
|
}
|
|
foreach ($aifMarketPlace as $aifData) {
|
|
$aifData->table = 'marketplace_aif_sellers';
|
|
$combinedData->push($aifData);
|
|
}
|
|
foreach ($opMarketPlace as $opData) {
|
|
$opData->table = 'marketplace_op_sellers';
|
|
$combinedData->push($opData);
|
|
}
|
|
|
|
$combinedData = $combinedData->sortByDesc('created_at');
|
|
|
|
//new end
|
|
// dd($combinedData);
|
|
|
|
return view(
|
|
'Admin.Pages.pre_owned_investment.pre_owned_investmentV2',
|
|
compact('freMarketPlace', 'aifMarketPlace', 'opMarketPlace', 'combinedData')
|
|
);
|
|
}
|
|
|
|
public function listingDetails($id, $table)
|
|
{
|
|
$table = [
|
|
'marketplace_fre_sellers' => 1,
|
|
'marketplace_aif_sellers' => 2,
|
|
'marketplace_op_sellers' => 3,
|
|
][$table];
|
|
|
|
if ($table == 1) {
|
|
$data = MarketplaceFractionalRealEstateSeller::with('seller', 'company')->where('id', $id)->firstOrFail();
|
|
} elseif ($table == 2) {
|
|
$data = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('id', $id)->firstOrFail();
|
|
} elseif ($table == 3) {
|
|
$data = MarketplaceOtherProductsSeller::with('seller')->where('id', $id)->firstOrFail();
|
|
}
|
|
|
|
return view('Admin.Pages.pre_owned_investment.pending_investment_view', compact('data', 'table'));
|
|
}
|
|
|
|
public function listingStatus(Request $request)
|
|
{
|
|
|
|
$table = [
|
|
'marketplace_fre_sellers' => 1,
|
|
'marketplace_aif_sellers' => 2,
|
|
'marketplace_op_sellers' => 3,
|
|
][$request->table];
|
|
|
|
if ($table == 1) {
|
|
MarketplaceFractionalRealEstateSeller::where('id', $request->id)->update(['status' => $request->status]);
|
|
$userId = MarketplaceFractionalRealEstateSeller::with('seller')->where('id', $request->id)->firstOrFail();;
|
|
} elseif ($table == 2) {
|
|
MarketplaceAlternativeInvestmentFundSeller::where('id', $request->id)->update(['status' => $request->status]);
|
|
$userId = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('id', $request->id)->firstOrFail();;
|
|
} elseif ($table == 3) {
|
|
MarketplaceOtherProductsSeller::where('id', $request->id)->update(['status' => $request->status]);
|
|
$userId = MarketplaceOtherProductsSeller::with('seller')->where('id', $request->id)->firstOrFail();;
|
|
}
|
|
if (!$table) {
|
|
return response()->json(['status' => 400, 'message' => 'Error Changing status']);
|
|
}
|
|
if ($request->status != 'Pending') {
|
|
$user = User::find($userId->seller->users_id);
|
|
$productName = $userId->property_name ?? $userId->name_of_the_aif_fund ?? $userId->security_name;
|
|
$notify['message'] = "Your Investment($productName) has been $request->status for marketplace listing!";
|
|
$user->notify(new UserAdmin($notify));
|
|
}
|
|
return response()->json(['status' => 200, 'message' => 'Status Changed']);
|
|
}
|
|
|
|
public function total_investment_on_sale()
|
|
{
|
|
return view('Admin.Pages.pre_owned_investment.total_investment_on_sale');
|
|
}
|
|
|
|
public function transactions()
|
|
{
|
|
$check = checkSidebarAccess('completed-transaction');
|
|
if (!$check) {
|
|
abort(404);
|
|
}
|
|
$aifBuyerForm = MarketplaceAlternativeInvestmentFundSeller::with('seller', 'company')->join('marketplace_buyer_forms', 'marketplace_aif_sellers.id', 'marketplace_buyer_forms.associated_id')
|
|
->latest('marketplace_aif_sellers.created_at')->get();
|
|
$freBuyerForm = MarketplaceFractionalRealEstateSeller::with('seller', 'company')->join('marketplace_buyer_forms', 'marketplace_fre_sellers.id', 'marketplace_buyer_forms.associated_id')->latest('marketplace_fre_sellers.created_at')->get();
|
|
$opBuyerForm = MarketplaceOtherProductsSeller::with('seller', 'company')->join('marketplace_buyer_forms', 'marketplace_op_sellers.id', 'marketplace_buyer_forms.associated_id')->latest('marketplace_op_sellers.created_at')->get();
|
|
$completedData = collect();
|
|
$aifBuyerForm->each(function($value) use($completedData){
|
|
$completedData[] = $value;
|
|
});
|
|
$freBuyerForm->each(function($value) use($completedData){
|
|
$completedData[] = $value;
|
|
});
|
|
// $latestArray = array_merge($aifBuyerForm->toArray(),$freBuyerForm->toArray());
|
|
$newData = $completedData->sortBy('created_at');
|
|
|
|
$companies = Company::active()->pluck('company_name', 'id');
|
|
return view('Admin.Pages.pre_owned_investment.transactions', compact('aifBuyerForm', 'freBuyerForm', 'opBuyerForm', 'companies','newData'));
|
|
}
|
|
|
|
// public function manage_seller_profile()
|
|
// {
|
|
// return view('Admin.Pages.pre_owned_investment.manage_seller_profile');
|
|
// }
|
|
|
|
public function approved_investment_view($id)
|
|
{
|
|
$id = $id;
|
|
return view('Admin.Pages.pre_owned_investment.approved_investment_view', compact('id'));
|
|
}
|
|
|
|
public function replyMail(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'subject' => 'required',
|
|
'reply' => 'required',
|
|
], [
|
|
'required' => "This :attribute field is required",
|
|
]);
|
|
|
|
$validate = validationErrorMessage($validator);
|
|
if ($validate) {
|
|
return response()->json(['status' => 400, 'message' => $validate]);
|
|
}
|
|
|
|
$data['subject'] = $request->subject;
|
|
$data['message'] = $request->reply;
|
|
$email = $request->email_send;
|
|
Mail::to($email)->send(new SentBuyerMail($data));
|
|
|
|
$sendData = BuyerSentMail::create([
|
|
'subject' => $request->subject,
|
|
'content' => $request->reply,
|
|
'sent_by' => auth()->user()->id,
|
|
'marketplace_buyer_forms_id' => $request->marketplace_buyer_form_id,
|
|
]);
|
|
if ($sendData) {
|
|
return response()->json(['status' => 200, 'message' => "Mail send Successfully"]);
|
|
} else {
|
|
return response()->json(['status' => 201, 'message' => "Mail not send"]);
|
|
}
|
|
}
|
|
|
|
public function viewReplyMail($id, $return, $table)
|
|
{
|
|
$replies = BuyerSentMail::with('users')->where('marketplace_buyer_forms_id', '=', $id)->get();
|
|
$backRoute = $backRoute = route('interest-buyers', ['id' => $return, 'table' => $table]);
|
|
return view('Admin.Pages.pre_owned_investment.partial.mails-reply', compact('replies', 'backRoute'));
|
|
}
|
|
|
|
public function updateCompleteTransaction(Request $request)
|
|
{
|
|
|
|
$completedTransactionUpdated = MarketplaceBuyerForm::where('id', $request->buyer_id)->update([
|
|
'complete_units_sold' => $request->final_units_sold,
|
|
'complete_sale_value' => $request->final_sale_value,
|
|
'commission_earned' => $request->commission_earned,
|
|
'date_of_sale' => $request->date_of_sale,
|
|
'platform' => $request->platform,
|
|
'final_purchase_value' => $request->final_purchase_value,
|
|
]);
|
|
|
|
if ($completedTransactionUpdated) {
|
|
return response()->json(['status' => 200, 'message' => 'Transaction Updated!'], 200);
|
|
} else {
|
|
return response()->json(["status" => 400, 'message' => 'Transaction Cannot Be Updated!'], 400);
|
|
}
|
|
}
|
|
}
|