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; // dd($backTable); 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'])->exists(); // 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 // dd($request->all()); // $userID .= '';F $product_name = ''; $getMarketplaceBuyerUnit = MarketplaceBuyerForm::where('id', $buyerId)->first(); // $userID .= $getMarketplaceBuyerUnit->user_id; $marketPlaceId = $getMarketplaceBuyerUnit->associated_id; $getUnits = (int)$getMarketplaceBuyerUnit->no_of_units_you_wish_to_buy ?? 0; $getBuyingPurchaseValue = (int)$getMarketplaceBuyerUnit->getAttributes()['total_purchase_value']; if (MarketplaceAlternativeInvestmentFundSeller::where('id', $marketPlaceId)->exists() && $getMarketplaceBuyerUnit->table == 'marketplace_aif_sellers') { $getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id', $marketPlaceId)->first(); $product_name .= $getAIFData->name_of_the_aif_fund; if ($status == 'Sold') { $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']); } } } else if (MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->exists() && $getMarketplaceBuyerUnit->table == 'marketplace_fre_sellers') { // dd('inside'); $getFREData = MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->first(); $product_name .= $getFREData->property_name; if ($status == 'Sold') { if ((int)$getFREData->current_market_value_of_the_property <= 0) { return response()->json(['status' => 400, 'message' => 'Product cannot be sold. because product has no value.']); } $freValue = (int)$getFREData->current_market_value_of_the_property; $nowValue = $freValue - $getBuyingPurchaseValue; $percentage = ($freValue - $getBuyingPurchaseValue) / $freValue * 100; $expectedSellingPrice = (int)$getFREData->expected_selling_price; $updateExpectedSellingPrice = $expectedSellingPrice * ($percentage / 100); // dd($percentage,$updateExpectedSellingPrice); if ($nowValue <= 0) { $updatePrice = MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->update([ 'current_market_value_of_the_property' => 0, 'expected_selling_price' => 0, ]); } else if ($nowValue > 0) { $updatePrice = MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->update([ 'current_market_value_of_the_property' => $nowValue, 'expected_selling_price' => $updateExpectedSellingPrice, ]); } } // else{ // return response()->json(['status' => 400, 'message' => 'Bid price is more than seller price with ₹'.abs($nowValue)]); // } } $user = User::find($getMarketplaceBuyerUnit->users_id); // $productName = $data->security_name ?? $data->property_name ?? $data->name_of_the_aif_fund; $notify['message'] = "Your BID status for ($product_name) product has been changed to $status !"; $user->notify(new UserAdmin($notify)); // dd('outside'); // } // $user = User::find($userID); // // $productName = $data->security_name ?? $data->property_name ?? $data->name_of_the_aif_fund; // $notify['message'] = "Your BID status for ($product_name) product has been changed to $status !"; // $user->notify(new UserAdmin($notify)); // } // dd('hello'); $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(); $tableName = 'marketplace_fre_sellers'; } elseif ($table == 2) { $data = MarketplaceAlternativeInvestmentFundSeller::with('seller')->where('id', $id)->firstOrFail(); $tableName = 'marketplace_aif_sellers'; } elseif ($table == 3) { $data = MarketplaceOtherProductsSeller::with('seller')->where('id', $id)->firstOrFail(); } $anyOneBuyed = MarketplaceBuyerForm::where(['associated_id' => $id, 'table' => $tableName])->exists(); // dd($data); return view('Admin.Pages.pre_owned_investment.pending_investment_view', compact('data', 'table', 'anyOneBuyed')); } 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', 'buyer')->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', 'buyer')->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(); $marketPlaceBuyerFrom = MarketplaceBuyerForm::where('status', 'Sold')->get(); $newData = collect(); foreach ($marketPlaceBuyerFrom as $item) { if ($item->table == 'marketplace_fre_sellers') { $item['data'] = MarketplaceFractionalRealEstateSeller::with('seller.users', 'company',)->where('id', $item->associated_id)->first(); $newData->push($item); // dd( $item['data']); } else if ($item->table == 'marketplace_aif_sellers') { $item['data'] = MarketplaceAlternativeInvestmentFundSeller::with('seller', 'company',)->where('id', $item->associated_id)->first(); $newData->push($item); } } // dd($newData); // $completedData = collect(); // $aifBuyerForm->each(function($value) use($completedData){ // $completedData[] = $value; // }); // $freBuyerForm->each(function($value) use($completedData){ // $completedData[] = $value; // }); // $newData = $completedData->sortBy('buyer.updated_at'); $companies = Company::active()->pluck('company_name', 'id'); // dd($newData[0]); // return view('Admin.Pages.pre_owned_investment.transactions', compact('aifBuyerForm', 'freBuyerForm', 'opBuyerForm', 'companies','newData')); return view('Admin.Pages.pre_owned_investment.transactions', compact('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) { // dd($request->all()); $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); } } }