Files
freeu-project/app/Http/Controllers/Admin/ManageSellerProfileController.php
Ritikesh yadav f930836609 fixing issue
2024-05-24 19:33:10 +05:30

100 lines
4.3 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\MarketplaceAlternativeInvestmentFundSeller;
use App\Models\MarketplaceFractionalRealEstateSeller;
use App\Models\MarketplaceOtherProductsSeller;
use App\Models\MarketplaceSellerForm;
use App\Models\MarketplaceBuyerForm;
use Illuminate\Http\Request;
class ManageSellerProfileController extends Controller
{
public function index()
{
$check = checkSidebarAccess('manage-seller-profile');
if(!$check)
{
abort(404);
}
$sellerProfile = MarketplaceSellerForm::query()
->with('users')
->withCount(['aif', 'fre', 'op'])
->latest()
->get();
// dd($sellerProfile->toArray());
return view('Admin.Pages.pre_owned_investment.manage_seller_profile', compact('sellerProfile'));
}
public function sellerDetails($id)
{
$sellerProfile = MarketplaceSellerForm::findOrFail($id);
$freListing = MarketplaceFractionalRealEstateSeller::where('seller_forms_id', $id)->get();
$aifListing = MarketplaceAlternativeInvestmentFundSeller::where('seller_forms_id', $id)->get();
$opListing = MarketplaceOtherProductsSeller::where('seller_forms_id', $id)->get();
$id = $id;
$productsSold = $this->productsSold($sellerProfile);
return view('Admin.Pages.pre_owned_investment.manage_investors', compact('sellerProfile', 'aifListing', 'freListing', 'opListing', 'id', 'productsSold'));
}
public function productsSold($sellerProfile)
{
$sellerId = $sellerProfile->id;
$productsSold = array();
$marketplaceAIFPRoducts = MarketplaceAlternativeInvestmentFundSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceAIFPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_aif_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach ($buyers as $buyerData) {
$buyerArr = array();
$buyerArr['product_name'] = $data->name_of_the_aif_fund;
$buyerArr['buyer'] = $buyerData->name;
$buyerArr['company'] = $data->type_of_fund;
$buyerArr['seller_price'] = $buyerData->total_purchase_value;
array_push($productsSold, $buyerArr);
}
}
$marketplaceFREPRoducts = MarketplaceFractionalRealEstateSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceFREPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_fre_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach ($buyers as $buyerData) {
$buyerArr = array();
$buyerArr['product_name'] = $data->property_name;
$buyerArr['buyer'] = $buyerData->name;
$buyerArr['company'] = $data->asset_type;
$buyerArr['seller_price'] = $buyerData->total_purchase_value;
array_push($productsSold, $buyerArr);
}
}
$marketplaceOPPRoducts = MarketplaceOtherProductsSeller::where('seller_forms_id', $sellerId)->get();
foreach ($marketplaceOPPRoducts as $data) {
$buyers = MarketplaceBuyerForm::where(['table' => 'marketplace_op_sellers', 'status' => 'Sold', 'associated_id' => $data->id])->get();
foreach ($buyers as $buyerData) {
$buyerArr = array();
$buyerArr['product_name'] = $data->property_name;
$buyerArr['buyer'] = $buyerData->name;
$buyerArr['company'] = $buyerData->instrument_type;
$buyerArr['seller_price'] = $buyerData->total_purchase_value;
array_push($productsSold, $buyerArr);
}
}
return $productsSold;
}
public function changeStatus(Request $request)
{
$changeStatus = MarketplaceSellerForm::where('id', $request->id)->update([
'status' => $request->status == 0 ? 1 : 0,
]);
if ($changeStatus) {
return response()->json(['status' => 200, 'message' => 'Status Changed']);
}
return response()->json(['status' => 400, 'message' => 'Error Changing Status']);
}
}