725 lines
35 KiB
PHP
725 lines
35 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\MarketplaceAlternativeInvestmentFundSeller;
|
|
use App\Models\MarketplaceBuyerForm;
|
|
use App\Models\MarketplaceFractionalRealEstateSeller;
|
|
use App\Models\MarketplaceOtherProductsSeller;
|
|
use App\Models\MarketplaceSellerForm;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use App\Models\User as ModelsUser;
|
|
use App\Notifications\UserAdmin;
|
|
|
|
class MarketPlaceController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$spotlightMarketPlaceListed = $this->spotlightInvestment()['data'];
|
|
$featuredMarketplaceListed = $this->featuredInvestments();
|
|
$nonFeaturedMarketplaceListed = $this->nonFeaturedInvestments();
|
|
// dd($nonFeaturedMarketplaceListed);
|
|
return view('Frontend.Pages.marketplace.index', compact('spotlightMarketPlaceListed', 'featuredMarketplaceListed', 'nonFeaturedMarketplaceListed'));
|
|
}
|
|
|
|
public function deleteBid(Request $request)
|
|
{
|
|
// dd($request->id);
|
|
try{
|
|
$id = $request->id;
|
|
if($id)
|
|
{
|
|
if(MarketplaceBuyerForm::where('id',(int)$id)->delete())
|
|
{
|
|
return response()->json(['status'=>200,'message'=>'Bid deleted successful']);
|
|
}
|
|
}
|
|
}catch(\Exception $e){
|
|
return response()->json(['status'=>400,'message'=>$e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
public function spotlightInvestment()
|
|
{
|
|
$data = null;
|
|
if (MarketplaceFractionalRealEstateSeller::where('listing_status', 'Spotlight')->exists()) {
|
|
$data = MarketplaceFractionalRealEstateSeller::where('listing_status', 'Spotlight')->first();
|
|
$table = 'fractional-real-estate';
|
|
} elseif (MarketplaceAlternativeInvestmentFundSeller::where('listing_status', 'Spotlight')->exists()) {
|
|
$data = MarketplaceAlternativeInvestmentFundSeller::where('listing_status', 'Spotlight')->first();
|
|
$table = 'alternative-investment-fund';
|
|
} elseif (MarketplaceOtherProductsSeller::where('listing_status', 'Spotlight')->exists()) {
|
|
$data = MarketplaceOtherProductsSeller::where('listing_status', 'Spotlight')->first();
|
|
$table = 'other-products';
|
|
}
|
|
if ($data) {
|
|
$expectedSale = $data->getRawOriginal('expected_selling_price') ?? $data->getRawOriginal('expected_sale_per_unit') ?? $data->getRawOriginal('expected_sale_price_per_unit');
|
|
$data = [
|
|
'data' => [
|
|
'product_name' => $data->property_name ?? $data->name_of_the_aif_fund ?? $data->security_name,
|
|
'expected_sale' => $this->IND_money_format($expectedSale),
|
|
'category' => $data->type_of_fund ?? $data->product_category ?? 'Fractional Real Estate',
|
|
'slug' => $data->slug,
|
|
'table' => $table
|
|
]
|
|
];
|
|
} else {
|
|
$data = [
|
|
'data' => []
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function featuredInvestments()
|
|
{
|
|
$freMarketplace['fractional-real-estate'] = MarketplaceFractionalRealEstateSeller::where(['status' => 'Approved', 'listing_status' => 'Featured'])
|
|
->select('id', 'property_name', 'asset_type', 'fractional_real_estate_platform', 'property_address', 'expected_selling_price', 'annual_rental_yield_earned', 'slug', 'rental_escalation', 'property_grade', 'latest_valuation_date', 'current_market_value_of_the_property', 'id as sold_status', 'id as category', 'id as discount', 'id as bid')
|
|
->get();
|
|
$aifMarketplace['alternative-investment-fund'] = MarketplaceAlternativeInvestmentFundSeller::where(['status' => 'Approved', 'listing_status' => 'Featured'])
|
|
->select('id', 'name_of_the_aif_fund', 'current_or_latest_nav', 'credit_rating', 'fund_category', 'type_of_fund', 'expected_sale_per_unit', 'no_of_units_you_wish_to_sell', 'latest_valuation_date', 'slug', 'id as sold_status', 'id as discount', 'id as bid')
|
|
->get();
|
|
$opMarketplace['other-products'] = MarketplaceOtherProductsSeller::where(['status' => 'Approved', 'listing_status' => 'Featured'])
|
|
->select('id', 'face_value_per_unit', 'security_name', 'product_category', 'instrument_issuer', 'no_of_units_offered_for_sale', 'expected_sale_price_per_unit', 'slug', 'principal_repaid', 'id as sold_status', 'payout_frequency', 'id as discount', 'id as bid')
|
|
->get();
|
|
$marketplaceListed = [];
|
|
array_push($marketplaceListed, $freMarketplace);
|
|
array_push($marketplaceListed, $aifMarketplace);
|
|
array_push($marketplaceListed, $opMarketplace);
|
|
// dd($freMarketplace['fractional-real-estate']);
|
|
|
|
// $marketplaceListed = [];
|
|
|
|
|
|
|
|
|
|
return [
|
|
'data' => $marketplaceListed
|
|
];
|
|
|
|
// return [
|
|
// 'fractional-real-estate' => $freMarketplace,
|
|
// 'alternative-investment-fund' => $aifMarketplace,
|
|
// 'other-products' => $opMarketplace
|
|
// ];
|
|
}
|
|
|
|
public function nonFeaturedInvestments()
|
|
{
|
|
$freMarketplace['fractional-real-estate'] = MarketplaceFractionalRealEstateSeller::where(['status' => 'Approved', 'listing_status' => 'Non-Featured'])->select('id', 'property_name', 'asset_type', 'fractional_real_estate_platform', 'property_address', 'expected_selling_price', 'annual_rental_yield_earned', 'latest_valuation_date', 'slug', 'rental_escalation', 'property_grade', 'current_market_value_of_the_property', 'id as sold_status', 'id as category', 'id as discount', 'id as bid')->get();
|
|
$aifMarketplace['alternative-investment-fund'] = MarketplaceAlternativeInvestmentFundSeller::where(['status' => 'Approved', 'listing_status' => 'Non-Featured'])->select('id', 'name_of_the_aif_fund', 'current_or_latest_nav', 'credit_rating', 'fund_category', 'type_of_fund', 'expected_sale_per_unit', 'latest_valuation_date', 'no_of_units_you_wish_to_sell', 'slug', 'id as sold_status', 'id as discount', 'id as bid')
|
|
->get();
|
|
$opMarketplace['other-products'] = MarketplaceOtherProductsSeller::where(['status' => 'Approved', 'listing_status' => 'Non-Featured'])->select('id', 'face_value_per_unit', 'security_name', 'product_category', 'instrument_issuer', 'no_of_units_offered_for_sale', 'expected_sale_price_per_unit', 'slug', 'principal_repaid', 'id as sold_status', 'payout_frequency', 'id as discount', 'id as bid')
|
|
->get();
|
|
$marketplaceListed = [];
|
|
array_push($marketplaceListed, $freMarketplace);
|
|
array_push($marketplaceListed, $aifMarketplace);
|
|
array_push($marketplaceListed, $opMarketplace);
|
|
|
|
// return $marketplaceListed;
|
|
return [
|
|
'data' => $marketplaceListed
|
|
];
|
|
// return [
|
|
// 'fractional-real-estate' => $freMarketplace,
|
|
// 'alternative-investment-fund' => $aifMarketplace,
|
|
// 'other-products' => $opMarketplace
|
|
// ];
|
|
}
|
|
|
|
public function viewOffering(Request $request, $slug)
|
|
{
|
|
// dd('helo');
|
|
// dd($request->all());
|
|
$offering = $this->viewOfferingData($slug);
|
|
// dd($offering);
|
|
// $status = MarketplaceBuyerForm::where(['associated_id'=>$offering['data']->id,'status'=>'Sold'])->exists() ? 'SOLD':'OPEN';
|
|
$status = '';
|
|
$checkBIDExist = MarketplaceBuyerForm::where('associated_id', $offering['data']->id)->where('status', 'Sold')->first();
|
|
// dd($checkBIDExist);
|
|
if ($checkBIDExist) {
|
|
$buyerData = MarketplaceBuyerForm::where('associated_id', $offering['data']->id)->where('status', 'Sold')->get();
|
|
// dd($buyerData[0]->associated_id);
|
|
if (MarketplaceAlternativeInvestmentFundSeller::where('id', $buyerData[0]->associated_id)->exists() && $offering['type'] == 'alternative-investment-funds') {
|
|
$totalSellUnits = 0;
|
|
$buyerData->each(function ($data) use ($totalSellUnits) {
|
|
return $totalSellUnits += (int)$data->no_of_units_you_wish_to_buy;
|
|
});
|
|
$getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id', $buyerData[0]->associated_id)->first();
|
|
$aifData = (int)$getAIFData->no_of_units_you_wish_to_sell;
|
|
$remainUnits = $aifData - $totalSellUnits;
|
|
if ($remainUnits <= 0) {
|
|
$status .= 'SOLD';
|
|
}else{
|
|
$status .= 'OPEN';
|
|
}
|
|
} elseif (MarketplaceFractionalRealEstateSeller::where('id', $buyerData[0]->associated_id)->exists() && $offering['type'] == 'fractional-real-estate') {
|
|
$freData = MarketplaceFractionalRealEstateSeller::where('id', $buyerData[0]->associated_id)->first();
|
|
if($freData->current_market_value_of_the_property <= 0)
|
|
{
|
|
$status .= 'SOLD';
|
|
}
|
|
else{
|
|
$status .= 'OPEN';
|
|
}
|
|
}
|
|
} else {
|
|
$status .= 'OPEN';
|
|
}
|
|
// dd($status);
|
|
$invested = $offering['invested'];
|
|
|
|
|
|
$totalInterestedBuyers = $offering['total-interested-buyers'];
|
|
$type = $offering['type'];
|
|
$ownProduct = $offering['own-product'];
|
|
$logged_in = auth()->guard('users')->check() == true ? true : false;
|
|
// dd($status);
|
|
// dd('offering',$offering['invested_data']);
|
|
$investedData = $offering['invested_data'];
|
|
|
|
|
|
return view('Frontend.Pages.marketplace.view-offering', compact(
|
|
'offering',
|
|
'type',
|
|
'invested',
|
|
'totalInterestedBuyers',
|
|
'logged_in',
|
|
'ownProduct',
|
|
'investedData',
|
|
'status'
|
|
));
|
|
}
|
|
|
|
public function viewOfferingData($slug)
|
|
{
|
|
// if(auth()->guard('users')->id())
|
|
// {
|
|
// }
|
|
$user_id = auth()->guard('users')->id();
|
|
$offering = array();
|
|
if (!auth()->guard('users')->check()) {
|
|
$offering['invested'] = false;
|
|
};
|
|
// $bidFor = '';
|
|
if (MarketplaceFractionalRealEstateSeller::where('slug', $slug)->exists()) {
|
|
// $bidFor .= 'fractional-real-estate';
|
|
$offering['type'] = 'fractional-real-estate';
|
|
$marketFRE = MarketplaceFractionalRealEstateSeller::where('slug', $slug)->first();
|
|
// if($user_id){
|
|
$offering['own-product'] = $user_id != null ? MarketplaceSellerForm::where(['id' => $marketFRE->seller_forms_id, 'users_id' => $user_id])->exists() : '';
|
|
// }
|
|
$offering['data'] = $marketFRE;
|
|
$offering['invested'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_fre_sellers')['interested-status'];
|
|
$offering['invested_data'] = $this->checkInvestmentInterestedData($offering['data'], 'marketplace_fre_sellers')['interested-status-data'];
|
|
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_fre_sellers')['total-interested-buyers'];
|
|
} elseif (MarketplaceAlternativeInvestmentFundSeller::where('slug', $slug)->exists()) {
|
|
// $bidFor .= 'alternative-investment-funds';
|
|
$offering['type'] = 'alternative-investment-funds';
|
|
$marketAIF = MarketplaceAlternativeInvestmentFundSeller::where('slug', $slug)->first();
|
|
$offering['own-product'] = $user_id != null ? MarketplaceSellerForm::where(['id' => $marketAIF->seller_forms_id, 'users_id' => $user_id])->exists() : '';
|
|
$offering['data'] = $marketAIF;
|
|
$offering['invested'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_aif_sellers')['interested-status'];
|
|
$offering['invested_data'] = $this->checkInvestmentInterestedData($offering['data'], 'marketplace_aif_sellers')['interested-status-data'];
|
|
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_aif_sellers')['total-interested-buyers'];
|
|
} elseif (MarketplaceOtherProductsSeller::where('slug', $slug)->exists()) {
|
|
$offering['type'] = 'other-products';
|
|
$marketOP = MarketplaceOtherProductsSeller::where('slug', $slug)->first();
|
|
$offering['own-product'] = $user_id != null ? MarketplaceSellerForm::where(['id' => $marketOP->seller_forms_id, 'users_id' => $user_id])->exists() : '';
|
|
$offering['data'] = $marketOP;
|
|
$offering['invested'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_op_sellers')['interested-status'];
|
|
$offering['invested_data'] = $this->checkInvestmentInterestedData($offering['data'], 'marketplace_op_sellers')['interested-status-data'];
|
|
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_op_sellers')['total-interested-buyers'];
|
|
}
|
|
return $offering;
|
|
}
|
|
|
|
|
|
public function checkInvestmentInterestedData($offering, $table)
|
|
{
|
|
$interestedStatus = false;
|
|
if (auth()->guard('users')->check()) {
|
|
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => auth()->guard('users')->user()->id, 'table' => $table, 'associated_id' => $offering->id])->where('status', '!=', 'Sold')->first();
|
|
}
|
|
return ['interested-status-data' => $interestedStatus];
|
|
}
|
|
|
|
public function checkInvestmentInterested($offering, $table)
|
|
{
|
|
$interestedStatus = false;
|
|
if (auth()->guard('users')->check()) {
|
|
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => auth()->guard('users')->user()->id, 'table' => $table, 'associated_id' => $offering->id])->where('status', '!=', 'Sold')->exists();
|
|
}
|
|
$totalInterestedBuyers = MarketplaceBuyerForm::where(['table' => $table, 'associated_id' => $offering->id])->count();
|
|
return [
|
|
'total-interested-buyers' => $totalInterestedBuyers . ' buyer(s) interested!',
|
|
'interested-status' => $interestedStatus
|
|
];
|
|
}
|
|
|
|
public function buyerForm($slug)
|
|
{
|
|
$offering = $this->viewOfferingData($slug);
|
|
|
|
$table = $offering['type'];
|
|
$id = $offering['data']->id;
|
|
$userData = array();
|
|
$user = ModelsUser::find(auth()->guard('users')->user()->id);
|
|
$dataOfBuyerForm = MarketplaceBuyerForm::first();
|
|
$userData = (object)[
|
|
'name' => $user->name ?? null,
|
|
'contact_number' => $user->contact_number ?? null,
|
|
'email' => $user->email ?? $user->email,
|
|
];
|
|
return view('Frontend.Pages.profile.market-list.buyer-form', compact('table', 'id', 'userData','dataOfBuyerForm'));
|
|
}
|
|
|
|
//editBuyerForm start by hritik on 5-4-2024
|
|
public function editBuyerForm($slug)
|
|
{
|
|
$offering = $this->viewOfferingData($slug);
|
|
$investedData = $offering['invested_data'];
|
|
$table = $offering['type'];
|
|
$id = $offering['data']->id;
|
|
$userData = array();
|
|
$user = ModelsUser::find(auth()->guard('users')->user()->id);
|
|
$dataOfBuyerForm = MarketplaceBuyerForm::first();
|
|
$userData = (object)[
|
|
'name' => $user->name ?? null,
|
|
'contact_number' => $user->contact_number ?? null,
|
|
'email' => $user->email ?? $user->email,
|
|
];
|
|
return view('Frontend.Pages.profile.market-list.edit-buyer-form', compact('table', 'id', 'userData', 'investedData'));
|
|
}
|
|
|
|
public function buyerFormSubmit(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
if($request->table == 'alternative-investment-funds')
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'no_of_units_you_wish_to_buy' => 'required|numeric',
|
|
'offer_price_per_unit' => 'required|numeric',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
}else
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'email_id' => 'required',
|
|
// 'no_of_units_you_wish_to_buy' => 'required|numeric',
|
|
// 'offer_price_per_unit' => 'required|numeric',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$validationMessage = $this->validationError($validator);
|
|
if ($validationMessage) {
|
|
return response()->json(['status' => 400, 'message' => $validationMessage]);
|
|
}
|
|
|
|
if ($request->table == 'fractional-real-estate') {
|
|
$table = 'marketplace_fre_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('property_name');
|
|
} elseif ($request->table == 'alternative-investment-funds') {
|
|
$table = 'marketplace_aif_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('name_of_the_aif_fund');
|
|
} elseif ($request->table == 'other-products') {
|
|
$table = 'marketplace_op_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
|
|
}
|
|
|
|
$buyerForm = MarketplaceBuyerForm::create([
|
|
'users_id' => auth()->guard('users')->user()->id,
|
|
'associated_id' => $request->id,
|
|
'table' => $table,
|
|
'name' => $request->name,
|
|
'city' => $request->city,
|
|
'country' => $request->country,
|
|
'contact_number' => $request->contact_number,
|
|
'email_id' => $request->email_id,
|
|
'no_of_units_you_wish_to_buy' => $request->no_of_units_you_wish_to_buy ?? 0,
|
|
'offer_price_per_unit' => $request->offer_price_per_unit ?? 0,
|
|
'total_purchase_value' => $request->total_purchase_value,
|
|
]);
|
|
if ($buyerForm) {
|
|
$name = auth()->guard('users')->user()->name;
|
|
$notify['message'] = "$name has submitted a buyer form for $productName!";
|
|
$type = 'Buyer Form';
|
|
$users = ModelsUser::admins()->get();
|
|
foreach ($users as $data) {
|
|
$data->notify(new UserAdmin($notify, $type));
|
|
}
|
|
return response()->json(['status' => 200, 'message' => "Buyer Form Submitted For Review"]);
|
|
}
|
|
return response()->json(['status' => 400, 'message' => "Buyer Form Could Not Be Submitted!"]);
|
|
}
|
|
|
|
//update form start
|
|
public function buyerFormSubmitUpdate(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
if ($request->table == 'alternative-investment-funds')
|
|
$validator = Validator::make($request->all(), [
|
|
'marketplaceBuyerFormId' => 'required',
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'no_of_units_you_wish_to_buy' => 'required|numeric',
|
|
'offer_price_per_unit' => 'required|numeric',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
else {
|
|
$validator = Validator::make($request->all(), [
|
|
'marketplaceBuyerFormId' => 'required',
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'total_purchase_value' => 'required',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
}
|
|
|
|
$validationMessage = $this->validationError($validator);
|
|
if ($validationMessage) {
|
|
return response()->json(['status' => 400, 'message' => $validationMessage]);
|
|
}
|
|
|
|
if ($request->table == 'fractional-real-estate') {
|
|
$table = 'marketplace_fre_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('property_name');
|
|
} elseif ($request->table == 'alternative-investment-funds') {
|
|
$table = 'marketplace_aif_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('name_of_the_aif_fund');
|
|
} elseif ($request->table == 'other-products') {
|
|
$table = 'marketplace_op_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
|
|
}
|
|
|
|
$checkAlreadySold = MarketplaceBuyerForm::where(['id' => $request->marketplaceBuyerFormId, 'status' => 'Sold'])->doesntExist();
|
|
if ($checkAlreadySold) {
|
|
$buyerForm = MarketplaceBuyerForm::where('id', $request->marketplaceBuyerFormId)->update([
|
|
'users_id' => auth()->guard('users')->user()->id,
|
|
'associated_id' => $request->id,
|
|
'table' => $table,
|
|
'name' => $request->name,
|
|
'city' => $request->city,
|
|
'country' => $request->country,
|
|
'contact_number' => $request->contact_number,
|
|
'email_id' => $request->email_id,
|
|
'no_of_units_you_wish_to_buy' => $request->no_of_units_you_wish_to_buy ?? 0,
|
|
'offer_price_per_unit' => $request->offer_price_per_unit ?? 0,
|
|
'total_purchase_value' => $request->total_purchase_value,
|
|
]);
|
|
if ($buyerForm) {
|
|
}
|
|
$name = auth()->guard('users')->user()->name;
|
|
$notify['message'] = "$name has Updated a buyer form for $productName!";
|
|
$type = 'Buyer Form';
|
|
$users = ModelsUser::admins()->get();
|
|
foreach ($users as $data) {
|
|
$data->notify(new UserAdmin($notify, $type));
|
|
}
|
|
return response()->json(['status' => 200, 'message' => "Buyer Form Updated For Successfully"]);
|
|
} else {
|
|
return response()->json(['status' => 400, 'message' => "This product has been already sold to you"]);
|
|
}
|
|
return response()->json(['status' => 400, 'message' => "Buyer Form Could Not Be Updated!"]);
|
|
}
|
|
|
|
//update formm end
|
|
public function buyerFormAPI($slug)
|
|
{
|
|
$offering = $this->viewOfferingData($slug);
|
|
$table = $offering['type'];
|
|
$id = $offering['data']->id;
|
|
$userData = array();
|
|
$user = ModelsUser::find(request()->user()->id);
|
|
$userData = (object)[
|
|
'name' => $user->name ?? null,
|
|
'contact_number' => $user->contact_number ?? null,
|
|
'email' => $user->email ?? $user->email,
|
|
];
|
|
$data['data'] = [
|
|
'table' => $offering['type'],
|
|
'id' => $offering['data']->id,
|
|
'user' => $userData
|
|
];
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function buyerFormSubmitAPI(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'no_of_units_you_wish_to_buy' => 'required|numeric',
|
|
'offer_price_per_unit' => 'required|numeric',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
|
|
|
|
$validationMessage = $this->validationError($validator);
|
|
if ($validationMessage) {
|
|
return response()->json(['status' => 400, 'message' => $validationMessage], 400);
|
|
}
|
|
|
|
if ($request->table == 'fractional-real-estate') {
|
|
$table = 'marketplace_fre_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('property_name');
|
|
} elseif ($request->table == 'alternative-investment-funds') {
|
|
$table = 'marketplace_aif_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('name_of_the_aif_fund');
|
|
} elseif ($request->table == 'other-products') {
|
|
$table = 'marketplace_op_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
|
|
}
|
|
|
|
$buyerForm = MarketplaceBuyerForm::create([
|
|
'users_id' => $request->user()->id,
|
|
'associated_id' => $request->id,
|
|
'table' => $table,
|
|
'name' => $request->name,
|
|
'city' => $request->city,
|
|
'country' => $request->country,
|
|
'contact_number' => $request->contact_number,
|
|
'email_id' => $request->email_id,
|
|
'no_of_units_you_wish_to_buy' => $request->no_of_units_you_wish_to_buy,
|
|
'offer_price_per_unit' => $request->offer_price_per_unit,
|
|
// 'total_purchase_value' => $request->total_purchase_value,
|
|
'total_purchase_value' => $request->no_of_units_you_wish_to_buy * $request->offer_price_per_unit
|
|
]);
|
|
$user = ModelsUser::find($request->user()->id);
|
|
if ($buyerForm) {
|
|
$name = $user->name;
|
|
$notify['message'] = "$name has submitted a buyer form for $productName!";
|
|
$type = 'Buyer Form';
|
|
$users = ModelsUser::admins()->get();
|
|
foreach ($users as $data) {
|
|
$data->notify(new UserAdmin($notify, $type));
|
|
}
|
|
return response()->json(['status' => 200, 'message' => "Buyer Form Submitted For Review"]);
|
|
}
|
|
return response()->json(['status' => 400, 'message' => "Buyer Form Could Not Be Submitted!"], 400);
|
|
}
|
|
|
|
//buyer form updated api start
|
|
|
|
public function buyerFormSubmitUpdateAPI(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'marketplaceBuyerFormId' => 'required|numeric',
|
|
'id' => 'required',
|
|
'table' => 'required',
|
|
'name' => 'required',
|
|
'city' => 'required',
|
|
'country' => 'required',
|
|
'contact_number' => 'required|numeric|digits:10',
|
|
'email_id' => 'required',
|
|
'no_of_units_you_wish_to_buy' => 'required|numeric',
|
|
'offer_price_per_unit' => 'required|numeric',
|
|
], [
|
|
'required' => 'The :attribute field must be required',
|
|
'numeric' => 'The :attribute field must be in digits',
|
|
'digits' => 'The :attribute field must have 10 digits',
|
|
]);
|
|
|
|
|
|
$validationMessage = $this->validationError($validator);
|
|
if ($validationMessage) {
|
|
return response()->json(['status' => 400, 'message' => $validationMessage], 400);
|
|
}
|
|
|
|
if ($request->table == 'fractional-real-estate') {
|
|
$table = 'marketplace_fre_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('property_name');
|
|
} elseif ($request->table == 'alternative-investment-funds') {
|
|
$table = 'marketplace_aif_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('name_of_the_aif_fund');
|
|
} elseif ($request->table == 'other-products') {
|
|
$table = 'marketplace_op_sellers';
|
|
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
|
|
}
|
|
|
|
$buyerForm = MarketplaceBuyerForm::where('id', $request->marketplaceBuyerFormId)->update([
|
|
'users_id' => $request->user()->id,
|
|
'associated_id' => $request->id,
|
|
'table' => $table,
|
|
'name' => $request->name,
|
|
'city' => $request->city,
|
|
'country' => $request->country,
|
|
'contact_number' => $request->contact_number,
|
|
'email_id' => $request->email_id,
|
|
'no_of_units_you_wish_to_buy' => $request->no_of_units_you_wish_to_buy,
|
|
'offer_price_per_unit' => $request->offer_price_per_unit,
|
|
// 'total_purchase_value' => $request->total_purchase_value,
|
|
'total_purchase_value' => $request->no_of_units_you_wish_to_buy * $request->offer_price_per_unit
|
|
]);
|
|
$user = ModelsUser::find($request->user()->id);
|
|
if ($buyerForm) {
|
|
$name = $user->name;
|
|
$notify['message'] = "$name has submitted a buyer form for $productName!";
|
|
$type = 'Buyer Form';
|
|
$users = ModelsUser::admins()->get();
|
|
foreach ($users as $data) {
|
|
$data->notify(new UserAdmin($notify, $type));
|
|
}
|
|
return response()->json(['status' => 200, 'message' => "Buyer Form Updated For Review"]);
|
|
}
|
|
return response()->json(['status' => 400, 'message' => "Buyer Form Could Not Be Submitted!"], 400);
|
|
}
|
|
|
|
//buyer form update api end
|
|
public function viewOfferingDataAPI($slug)
|
|
{
|
|
$offering = array();
|
|
// dd(request()->user());
|
|
if (request()->user()) {
|
|
$offering['invested'] = false;
|
|
};
|
|
if (MarketplaceFractionalRealEstateSeller::where('slug', $slug)->exists()) {
|
|
$offering['type'] = 'fractional-real-estate';
|
|
$marketFRE = MarketplaceFractionalRealEstateSeller::where('slug', $slug)->first();
|
|
$offering['own-product'] = MarketplaceSellerForm::where(['id' => $marketFRE->seller_forms_id, 'users_id' => auth('sanctum')->id()])->exists();
|
|
$offering['data'] = $marketFRE;
|
|
// dd($marketFRE);
|
|
|
|
|
|
$offering['invested'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_fre_sellers')['interested-status'];
|
|
$offering['invested-data'] = $this->checkInvestmentInterestedDataAPI($offering['data'], 'marketplace_fre_sellers')['interested-status-data']; //new added
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_fre_sellers')['total-interested-buyers'];
|
|
} elseif (MarketplaceAlternativeInvestmentFundSeller::where('slug', $slug)->exists()) {
|
|
$offering['type'] = 'alternative-investment-funds';
|
|
$marketAIF = MarketplaceAlternativeInvestmentFundSeller::where('slug', $slug)->first();
|
|
$offering['own-product'] = MarketplaceSellerForm::where(['id' => $marketAIF->seller_forms_id, 'users_id' => auth('sanctum')->id()])->exists();
|
|
$offering['data'] = $marketAIF;
|
|
|
|
$offering['invested'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_aif_sellers')['interested-status'];
|
|
$offering['invested-data'] = $this->checkInvestmentInterestedDataAPI($offering['data'], 'marketplace_aif_sellers')['interested-status-data'];
|
|
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_aif_sellers')['total-interested-buyers'];
|
|
} elseif (MarketplaceOtherProductsSeller::where('slug', $slug)->exists()) {
|
|
$offering['type'] = 'other-products';
|
|
$marketOP = MarketplaceOtherProductsSeller::where('slug', $slug)->first();
|
|
$offering['own-product'] = MarketplaceSellerForm::where(['id' => $marketOP->seller_forms_id, 'users_id' => auth('sanctum')->id()])->exists();
|
|
$offering['data'] = $marketOP;
|
|
|
|
$offering['invested'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_op_sellers')['interested-status'];
|
|
$offering['invested-data'] = $this->checkInvestmentInterestedDataAPI($offering['data'], 'marketplace_op_sellers')['interested-status-data'];
|
|
$offering['total-interested-buyers'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_op_sellers')['total-interested-buyers'];
|
|
}
|
|
return $offering;
|
|
}
|
|
|
|
|
|
public function checkInvestmentInterestedDataAPI($offering, $table)
|
|
{
|
|
$interestedStatus = null;
|
|
if (request()->user()) {
|
|
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => request()->user()->id, 'table' => $table, 'associated_id' => $offering->id])->first();
|
|
}
|
|
return ['interested-status-data' => $interestedStatus];
|
|
}
|
|
|
|
public function checkInvestmentInterestedAPI($offering, $table)
|
|
{
|
|
$interestedStatus = false;
|
|
if (request()->user()) {
|
|
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => request()->user()->id, 'table' => $table, 'associated_id' => $offering->id])->exists();
|
|
}
|
|
$totalInterestedBuyers = MarketplaceBuyerForm::where(['table' => $table, 'associated_id' => $offering->id])->count();
|
|
return [
|
|
'total-interested-buyers' => $totalInterestedBuyers . ' buyer(s) interested!',
|
|
'interested-status' => $interestedStatus
|
|
];
|
|
}
|
|
|
|
function IND_money_format($number)
|
|
{
|
|
$decimal = (string)($number - floor($number));
|
|
$money = floor($number);
|
|
$length = strlen($money);
|
|
$delimiter = '';
|
|
$money = strrev($money);
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
if (($i == 3 || ($i > 3 && ($i - 1) % 2 == 0)) && $i != $length) {
|
|
$delimiter .= ',';
|
|
}
|
|
$delimiter .= $money[$i];
|
|
}
|
|
|
|
$result = strrev($delimiter);
|
|
$decimal = preg_replace("/0\./i", ".", $decimal);
|
|
$decimal = substr($decimal, 0, 3);
|
|
|
|
if ($decimal != '0') {
|
|
$result = $result . $decimal;
|
|
}
|
|
|
|
return '₹ ' . $result;
|
|
}
|
|
|
|
public function validationError($validator)
|
|
{
|
|
if ($validator->fails()) {
|
|
$errors = $validator->errors();
|
|
$messages = '';
|
|
foreach ($errors->all() as $message) {
|
|
$messages .= $message . '</br>';
|
|
}
|
|
return $messages;
|
|
}
|
|
}
|
|
}
|