2024-03-28 14:52:40 +05:30
< ? 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 ();
2024-05-24 19:33:10 +05:30
// dd($nonFeaturedMarketplaceListed);
2024-03-28 14:52:40 +05:30
return view ( 'Frontend.Pages.marketplace.index' , compact ( 'spotlightMarketPlaceListed' , 'featuredMarketplaceListed' , 'nonFeaturedMarketplaceListed' ));
}
2024-06-03 12:55:29 +05:30
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 ()]);
}
}
2024-03-28 14:52:40 +05:30
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 ()
{
2024-04-08 19:31:31 +05:30
$freMarketplace [ 'fractional-real-estate' ] = MarketplaceFractionalRealEstateSeller :: where ([ 'status' => 'Approved' , 'listing_status' => 'Featured' ])
2024-04-08 13:45:25 +05:30
-> 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' )
2024-03-28 14:52:40 +05:30
-> get ();
$aifMarketplace [ 'alternative-investment-fund' ] = MarketplaceAlternativeInvestmentFundSeller :: where ([ 'status' => 'Approved' , 'listing_status' => 'Featured' ])
2024-04-08 13:45:25 +05:30
-> 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' )
2024-03-28 14:52:40 +05:30
-> 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 );
2024-05-07 14:57:06 +05:30
// dd($freMarketplace['fractional-real-estate']);
2024-03-28 14:52:40 +05:30
2024-04-29 17:15:31 +05:30
// $marketplaceListed = [];
2024-05-07 16:45:56 +05:30
2024-04-29 17:15:31 +05:30
2024-03-28 14:52:40 +05:30
return [
'data' => $marketplaceListed
];
// return [
// 'fractional-real-estate' => $freMarketplace,
// 'alternative-investment-fund' => $aifMarketplace,
// 'other-products' => $opMarketplace
// ];
}
public function nonFeaturedInvestments ()
{
2024-04-08 13:45:25 +05:30
$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' )
2024-03-28 14:52:40 +05:30
-> 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
// ];
}
2024-04-11 11:48:48 +05:30
public function viewOffering ( Request $request , $slug )
2024-03-28 14:52:40 +05:30
{
2024-04-11 11:48:48 +05:30
// dd('helo');
// dd($request->all());
2024-03-28 14:52:40 +05:30
$offering = $this -> viewOfferingData ( $slug );
2024-05-16 11:53:28 +05:30
// dd($offering);
2024-04-26 12:23:43 +05:30
// $status = MarketplaceBuyerForm::where(['associated_id'=>$offering['data']->id,'status'=>'Sold'])->exists() ? 'SOLD':'OPEN';
$status = '' ;
2024-05-29 16:29:37 +05:30
$checkBIDExist = MarketplaceBuyerForm :: where ( 'associated_id' , $offering [ 'data' ] -> id ) -> where ( 'status' , 'Sold' ) -> first ();
2024-05-16 11:53:28 +05:30
// dd($checkBIDExist);
2024-05-07 16:45:56 +05:30
if ( $checkBIDExist ) {
2024-04-26 12:23:43 +05:30
$buyerData = MarketplaceBuyerForm :: where ( 'associated_id' , $offering [ 'data' ] -> id ) -> where ( 'status' , 'Sold' ) -> get ();
2024-05-16 11:53:28 +05:30
// dd($buyerData[0]->associated_id);
if ( MarketplaceAlternativeInvestmentFundSeller :: where ( 'id' , $buyerData [ 0 ] -> associated_id ) -> exists () && $offering [ 'type' ] == 'alternative-investment-funds' ) {
2024-04-26 12:23:43 +05:30
$totalSellUnits = 0 ;
2024-05-07 16:45:56 +05:30
$buyerData -> each ( function ( $data ) use ( $totalSellUnits ) {
2024-04-26 12:23:43 +05:30
return $totalSellUnits += ( int ) $data -> no_of_units_you_wish_to_buy ;
});
2024-05-07 16:45:56 +05:30
$getAIFData = MarketplaceAlternativeInvestmentFundSeller :: where ( 'id' , $buyerData [ 0 ] -> associated_id ) -> first ();
2024-04-26 12:23:43 +05:30
$aifData = ( int ) $getAIFData -> no_of_units_you_wish_to_sell ;
$remainUnits = $aifData - $totalSellUnits ;
2024-05-07 16:45:56 +05:30
if ( $remainUnits <= 0 ) {
2024-04-26 12:23:43 +05:30
$status .= 'SOLD' ;
2024-05-16 11:53:28 +05:30
} else {
$status .= 'OPEN' ;
2024-04-26 12:23:43 +05:30
}
2024-05-16 11:53:28 +05:30
} elseif ( MarketplaceFractionalRealEstateSeller :: where ( 'id' , $buyerData [ 0 ] -> associated_id ) -> exists () && $offering [ 'type' ] == 'fractional-real-estate' ) {
2024-05-07 18:52:18 +05:30
$freData = MarketplaceFractionalRealEstateSeller :: where ( 'id' , $buyerData [ 0 ] -> associated_id ) -> first ();
2024-05-09 15:42:22 +05:30
if ( $freData -> current_market_value_of_the_property <= 0 )
2024-05-07 18:52:18 +05:30
{
$status .= 'SOLD' ;
}
2024-05-16 11:53:28 +05:30
else {
$status .= 'OPEN' ;
}
2024-04-26 12:23:43 +05:30
}
2024-05-07 16:45:56 +05:30
} else {
2024-04-26 12:23:43 +05:30
$status .= 'OPEN' ;
}
2024-04-11 11:48:48 +05:30
// dd($status);
2024-03-28 14:52:40 +05:30
$invested = $offering [ 'invested' ];
2024-04-05 17:39:33 +05:30
2024-05-07 16:45:56 +05:30
2024-03-28 14:52:40 +05:30
$totalInterestedBuyers = $offering [ 'total-interested-buyers' ];
$type = $offering [ 'type' ];
$ownProduct = $offering [ 'own-product' ];
$logged_in = auth () -> guard ( 'users' ) -> check () == true ? true : false ;
2024-05-16 11:53:28 +05:30
// dd($status);
2024-06-13 15:26:33 +05:30
// dd($offering);
2024-04-09 19:42:10 +05:30
$investedData = $offering [ 'invested_data' ];
2024-05-07 16:45:56 +05:30
return view ( 'Frontend.Pages.marketplace.view-offering' , compact (
'offering' ,
'type' ,
'invested' ,
'totalInterestedBuyers' ,
'logged_in' ,
'ownProduct' ,
'investedData' ,
'status'
));
2024-03-28 14:52:40 +05:30
}
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 ;
};
2024-05-07 16:45:56 +05:30
// $bidFor = '';
2024-03-28 14:52:40 +05:30
if ( MarketplaceFractionalRealEstateSeller :: where ( 'slug' , $slug ) -> exists ()) {
2024-05-07 16:45:56 +05:30
// $bidFor .= 'fractional-real-estate';
2024-03-28 14:52:40 +05:30
$offering [ 'type' ] = 'fractional-real-estate' ;
2024-06-13 15:26:33 +05:30
$marketFRE = MarketplaceFractionalRealEstateSeller :: with ( 'company' ) -> where ( 'slug' , $slug ) -> first ();
2024-03-28 14:52:40 +05:30
// 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' ];
2024-04-09 19:42:10 +05:30
$offering [ 'invested_data' ] = $this -> checkInvestmentInterestedData ( $offering [ 'data' ], 'marketplace_fre_sellers' )[ 'interested-status-data' ];
2024-04-05 17:39:33 +05:30
2024-03-28 14:52:40 +05:30
$offering [ 'total-interested-buyers' ] = $this -> checkInvestmentInterested ( $offering [ 'data' ], 'marketplace_fre_sellers' )[ 'total-interested-buyers' ];
} elseif ( MarketplaceAlternativeInvestmentFundSeller :: where ( 'slug' , $slug ) -> exists ()) {
2024-05-07 16:45:56 +05:30
// $bidFor .= 'alternative-investment-funds';
2024-03-28 14:52:40 +05:30
$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' ];
2024-04-09 19:42:10 +05:30
$offering [ 'invested_data' ] = $this -> checkInvestmentInterestedData ( $offering [ 'data' ], 'marketplace_aif_sellers' )[ 'interested-status-data' ];
2024-05-07 16:45:56 +05:30
2024-03-28 14:52:40 +05:30
$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' ];
2024-04-09 19:42:10 +05:30
$offering [ 'invested_data' ] = $this -> checkInvestmentInterestedData ( $offering [ 'data' ], 'marketplace_op_sellers' )[ 'interested-status-data' ];
2024-04-05 17:39:33 +05:30
2024-03-28 14:52:40 +05:30
$offering [ 'total-interested-buyers' ] = $this -> checkInvestmentInterested ( $offering [ 'data' ], 'marketplace_op_sellers' )[ 'total-interested-buyers' ];
}
return $offering ;
}
2024-04-05 17:39:33 +05:30
public function checkInvestmentInterestedData ( $offering , $table )
{
$interestedStatus = false ;
if ( auth () -> guard ( 'users' ) -> check ()) {
2024-05-13 14:00:37 +05:30
$interestedStatus = MarketplaceBuyerForm :: where ([ 'users_id' => auth () -> guard ( 'users' ) -> user () -> id , 'table' => $table , 'associated_id' => $offering -> id ]) -> where ( 'status' , '!=' , 'Sold' ) -> first ();
2024-04-05 17:39:33 +05:30
}
2024-05-07 16:45:56 +05:30
return [ 'interested-status-data' => $interestedStatus ];
2024-04-05 17:39:33 +05:30
}
2024-03-28 14:52:40 +05:30
public function checkInvestmentInterested ( $offering , $table )
{
$interestedStatus = false ;
if ( auth () -> guard ( 'users' ) -> check ()) {
2024-05-13 14:00:37 +05:30
$interestedStatus = MarketplaceBuyerForm :: where ([ 'users_id' => auth () -> guard ( 'users' ) -> user () -> id , 'table' => $table , 'associated_id' => $offering -> id ]) -> where ( 'status' , '!=' , 'Sold' ) -> exists ();
2024-03-28 14:52:40 +05:30
}
$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 );
2024-06-11 14:55:45 +05:30
// dd($offering);
$max = $offering [ 'type' ] == 'alternative-investment-funds' ? ( int ) $offering [ 'data' ] -> no_of_units_you_wish_to_sell : null ;
2024-05-07 16:45:56 +05:30
2024-03-28 14:52:40 +05:30
$table = $offering [ 'type' ];
$id = $offering [ 'data' ] -> id ;
$userData = array ();
$user = ModelsUser :: find ( auth () -> guard ( 'users' ) -> user () -> id );
2024-05-14 12:01:46 +05:30
$dataOfBuyerForm = MarketplaceBuyerForm :: first ();
2024-03-28 14:52:40 +05:30
$userData = ( object )[
'name' => $user -> name ? ? null ,
'contact_number' => $user -> contact_number ? ? null ,
'email' => $user -> email ? ? $user -> email ,
];
2024-06-11 14:55:45 +05:30
return view ( 'Frontend.Pages.profile.market-list.buyer-form' , compact ( 'table' , 'id' , 'userData' , 'dataOfBuyerForm' , 'max' ));
2024-03-28 14:52:40 +05:30
}
2024-04-05 17:39:33 +05:30
//editBuyerForm start by hritik on 5-4-2024
public function editBuyerForm ( $slug )
{
$offering = $this -> viewOfferingData ( $slug );
2024-04-09 19:42:10 +05:30
$investedData = $offering [ 'invested_data' ];
2024-04-05 17:39:33 +05:30
$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 ,
];
2024-05-07 16:45:56 +05:30
return view ( 'Frontend.Pages.profile.market-list.edit-buyer-form' , compact ( 'table' , 'id' , 'userData' , 'investedData' ));
2024-04-05 17:39:33 +05:30
}
2024-03-28 14:52:40 +05:30
public function buyerFormSubmit ( Request $request )
{
2024-05-07 16:45:56 +05:30
// 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' ,
]);
}
2024-03-28 14:52:40 +05:30
$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 ,
2024-05-07 16:45:56 +05:30
'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 ,
2024-03-28 14:52:40 +05:30
'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! " ]);
}
2024-04-05 17:39:33 +05:30
//update form start
public function buyerFormSubmitUpdate ( Request $request )
{
2024-05-07 16:45:56 +05:30
// 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' ,
]);
}
2024-04-05 17:39:33 +05:30
$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' );
}
2024-05-07 16:45:56 +05:30
$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 ) {
}
2024-04-05 17:39:33 +05:30
$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 " ]);
2024-05-07 16:45:56 +05:30
} else {
return response () -> json ([ 'status' => 400 , 'message' => " This product has been already sold to you " ]);
2024-04-05 17:39:33 +05:30
}
return response () -> json ([ 'status' => 400 , 'message' => " Buyer Form Could Not Be Updated! " ]);
}
2024-05-07 16:45:56 +05:30
2024-04-05 17:39:33 +05:30
//update formm end
2024-03-28 14:52:40 +05:30
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,
2024-06-25 15:20:10 +05:30
'total_purchase_value' => ( $request -> no_of_units_you_wish_to_buy == 0 && $request -> offer_price_per_unit == 0 ) ? $request -> total_purchase_value : $request -> no_of_units_you_wish_to_buy * $request -> offer_price_per_unit ,
2024-03-28 14:52:40 +05:30
]);
$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 );
}
2024-04-09 15:48:30 +05:30
//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' );
}
2024-05-07 16:45:56 +05:30
$buyerForm = MarketplaceBuyerForm :: where ( 'id' , $request -> marketplaceBuyerFormId ) -> update ([
2024-04-09 15:48:30 +05:30
'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,
2024-06-25 15:50:03 +05:30
'total_purchase_value' => ( $request -> no_of_units_you_wish_to_buy == 0 && $request -> offer_price_per_unit == 0 ) ? $request -> total_purchase_value : $request -> no_of_units_you_wish_to_buy * $request -> offer_price_per_unit
2024-04-09 15:48:30 +05:30
]);
$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
2024-03-28 14:52:40 +05:30
public function viewOfferingDataAPI ( $slug )
{
$offering = array ();
2024-04-09 15:48:30 +05:30
// dd(request()->user());
2024-03-28 14:52:40 +05:30
if ( request () -> user ()) {
$offering [ 'invested' ] = false ;
};
if ( MarketplaceFractionalRealEstateSeller :: where ( 'slug' , $slug ) -> exists ()) {
$offering [ 'type' ] = 'fractional-real-estate' ;
2024-06-25 15:20:10 +05:30
$marketFRE = MarketplaceFractionalRealEstateSeller :: with ( 'company' ) -> where ( 'slug' , $slug ) -> first ();
2024-03-28 14:52:40 +05:30
$offering [ 'own-product' ] = MarketplaceSellerForm :: where ([ 'id' => $marketFRE -> seller_forms_id , 'users_id' => auth ( 'sanctum' ) -> id ()]) -> exists ();
$offering [ 'data' ] = $marketFRE ;
2024-05-17 16:47:12 +05:30
// dd($marketFRE);
2024-04-09 15:48:30 +05:30
2024-03-28 14:52:40 +05:30
$offering [ 'invested' ] = $this -> checkInvestmentInterestedAPI ( $offering [ 'data' ], 'marketplace_fre_sellers' )[ 'interested-status' ];
2024-04-09 15:48:30 +05:30
$offering [ 'invested-data' ] = $this -> checkInvestmentInterestedDataAPI ( $offering [ 'data' ], 'marketplace_fre_sellers' )[ 'interested-status-data' ]; //new added
2024-03-28 14:52:40 +05:30
$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 ;
2024-04-09 15:48:30 +05:30
2024-03-28 14:52:40 +05:30
$offering [ 'invested' ] = $this -> checkInvestmentInterestedAPI ( $offering [ 'data' ], 'marketplace_aif_sellers' )[ 'interested-status' ];
2024-04-09 15:48:30 +05:30
$offering [ 'invested-data' ] = $this -> checkInvestmentInterestedDataAPI ( $offering [ 'data' ], 'marketplace_aif_sellers' )[ 'interested-status-data' ];
2024-05-07 16:45:56 +05:30
2024-03-28 14:52:40 +05:30
$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 ;
2024-04-09 15:48:30 +05:30
2024-03-28 14:52:40 +05:30
$offering [ 'invested' ] = $this -> checkInvestmentInterestedAPI ( $offering [ 'data' ], 'marketplace_op_sellers' )[ 'interested-status' ];
2024-04-09 15:48:30 +05:30
$offering [ 'invested-data' ] = $this -> checkInvestmentInterestedDataAPI ( $offering [ 'data' ], 'marketplace_op_sellers' )[ 'interested-status-data' ];
2024-03-28 14:52:40 +05:30
$offering [ 'total-interested-buyers' ] = $this -> checkInvestmentInterestedAPI ( $offering [ 'data' ], 'marketplace_op_sellers' )[ 'total-interested-buyers' ];
}
return $offering ;
}
2024-04-09 15:48:30 +05:30
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 ();
}
2024-05-07 16:45:56 +05:30
return [ 'interested-status-data' => $interestedStatus ];
2024-04-09 15:48:30 +05:30
}
2024-03-28 14:52:40 +05:30
public function checkInvestmentInterestedAPI ( $offering , $table )
{
$interestedStatus = false ;
if ( request () -> user ()) {
2024-06-25 16:52:46 +05:30
$interestedStatus = MarketplaceBuyerForm :: where ([ 'users_id' => request () -> user () -> id , 'table' => $table , 'associated_id' => $offering -> id ]) -> where ( 'status' , '!=' , 'Sold' ) -> exists ();
2024-03-28 14:52:40 +05:30
}
$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 ;
}
}
}