diff --git a/app/Http/Controllers/Admin/OverviewController.php b/app/Http/Controllers/Admin/OverviewController.php index f986c66..b3b268b 100644 --- a/app/Http/Controllers/Admin/OverviewController.php +++ b/app/Http/Controllers/Admin/OverviewController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin; use Mail; use App\Models\User; use App\Models\Company; -use App\Mail\SentBuyerMail; +use App\Mail\SentBuyerMail; use Illuminate\Http\Request; use App\Notifications\UserAdmin; use App\Models\Admin\BuyerSentMail; @@ -35,25 +35,23 @@ class OverviewController extends Controller // dd($freMarketPlace); $opMarketPlace = MarketplaceOtherProductsSeller::where('status', 'Approved')->latest()->get(); $allMarketPlace = collect(); - foreach($aifMarketPlace as $data) - { + foreach ($aifMarketPlace as $data) { $data->table = 'marketplace_aif_sellers'; $allMarketPlace->push($data); } - foreach($freMarketPlace as $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')); + 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(); @@ -62,8 +60,7 @@ class OverviewController extends Controller $allMarketPlace = collect(); $newData = []; $count = 0; - foreach($aifMarketPlace as $data) - { + 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 ; @@ -84,8 +81,7 @@ class OverviewController extends Controller $allMarketPlace->push($newData); $count++; } - foreach($freMarketPlace as $data) - { + foreach ($freMarketPlace as $data) { // $newData[$count]['Product'] = $data->property_name; // $newData[$count]['ExpectedSellingPrice'] = $data->expected_selling_price ; // $newData[$count]['SellerName'] = $data->seller->name; @@ -95,7 +91,7 @@ class OverviewController extends Controller // $newData[$count]['CreatedAt'] = $data->created_at->format('F d, o'); $newData = array( "Product" => $data->property_name, - "ExpectedSellingPrice" => $data->expected_selling_price , + "ExpectedSellingPrice" => $data->expected_selling_price, "SellerName" => $data->seller->name, "Email" => $data->seller->email, "Contact" => $data->seller->contact_number, @@ -114,7 +110,7 @@ class OverviewController extends Controller public function interestedBuyers($id, $table) { - $interestedBuyers = MarketplaceBuyerForm::where(['associated_id' => $id, 'table' => $table])->orderBy('updated_at','DESC')->get(); + $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(); @@ -157,8 +153,7 @@ class OverviewController extends Controller ]); // if ($changeListingStatus && $listingStatus != 'Hide') { if ($listingStatus != 'Hide') { - if( $listingStatus != 'Non-Featured') - { + 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!"; @@ -193,7 +188,7 @@ class OverviewController extends Controller // $updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([ // 'no_of_units_you_wish_to_sell' => $newUnits, // ]); - + // } // // elseif(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists()) // // { @@ -206,7 +201,7 @@ class OverviewController extends Controller // // } // }else - + // dd($request->all()); // $userID .= '';F $product_name = ''; @@ -215,32 +210,26 @@ class OverviewController extends Controller $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(); + 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'){ + 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([ + 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 { + 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') - { + } else if (MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->exists() && $getMarketplaceBuyerUnit->table == 'marketplace_fre_sellers') { // dd('inside'); - $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first(); + $getFREData = MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->first(); $product_name .= $getFREData->property_name; - if($status == 'Sold'){ - if((int)$getFREData->current_market_value_of_the_property <= 0) - { + 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; @@ -251,17 +240,16 @@ class OverviewController extends Controller $expectedSellingPrice = (int)$getFREData->expected_selling_price; $updateExpectedSellingPrice = $expectedSellingPrice * ($percentage / 100); // dd($percentage,$updateExpectedSellingPrice); - if($nowValue <= 0) - { - $updatePrice = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->update([ + 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([ + ]); + } else if ($nowValue > 0) { + $updatePrice = MarketplaceFractionalRealEstateSeller::where('id', $marketPlaceId)->update([ 'current_market_value_of_the_property' => $nowValue, 'expected_selling_price' => $updateExpectedSellingPrice, - ]); + ]); } } // else{ @@ -272,19 +260,19 @@ class OverviewController extends Controller // $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'); + // 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)); + // $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!']); } @@ -347,10 +335,10 @@ class OverviewController extends Controller } elseif ($table == 3) { $data = MarketplaceOtherProductsSeller::with('seller')->where('id', $id)->firstOrFail(); } - $anyOneBuyed = MarketplaceBuyerForm::where(['associated_id'=>$id,'table'=>$tableName])->exists(); + $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')); + return view('Admin.Pages.pre_owned_investment.pending_investment_view', compact('data', 'table', 'anyOneBuyed')); } public function listingStatus(Request $request) @@ -401,17 +389,15 @@ class OverviewController extends Controller // $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(); + $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(); + 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(); + } else if ($item->table == 'marketplace_aif_sellers') { + $item['data'] = MarketplaceAlternativeInvestmentFundSeller::with('seller', 'company',)->where('id', $item->associated_id)->first(); $newData->push($item); } } @@ -428,7 +414,7 @@ class OverviewController extends Controller $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')); + return view('Admin.Pages.pre_owned_investment.transactions', compact('companies', 'newData')); } // public function manage_seller_profile() @@ -499,4 +485,4 @@ class OverviewController extends Controller return response()->json(["status" => 400, 'message' => 'Transaction Cannot Be Updated!'], 400); } } -} \ No newline at end of file +}