2024-03-28 14:52:40 +05:30
< ? php
use App\Models\User ;
use App\Models\Chat ;
use App\Models\Company ;
use App\Models\Content ;
use App\Models\Product ;
use App\Models\Category ;
use App\Models\Admin\Blog ;
use App\Models\Admin\Testimonial ;
use App\Models\MonthlyUpdateMaster ;
use App\Models\MarketplaceBuyerForm ;
use App\Models\MarketplaceSellerForm ;
use App\Models\ProductTrailCommission ;
use App\Models\MonthlyUpdatePeerToPeerLending ;
use App\Models\MarketplaceOtherProductsSeller ;
use App\Models\MonthlyUpdateFractionalRealEstate ;
use App\Models\MonthlyUpdateIndianFinancialAssets ;
use App\Models\MonthlyUpdateAlternativeInvestmentFund ;
use App\Models\MarketplaceFractionalRealEstateSeller ;
use App\Models\MarketplaceAlternativeInvestmentFundSeller ;
// validation error message
if ( ! function_exists ( 'validationErrorMessage' )) {
function validationErrorMessage ( $validator )
{
if ( $validator -> fails ()) {
$errors = $validator -> errors ();
$messages = '' ;
foreach ( $errors -> all () as $message ) {
$messages .= $message . '</br>' ;
}
return $messages ;
}
}
}
function imagePath ( $path = null )
{
if ( env ( 'APP_ENV' ) == 'production' )
{
$finalPath = " https://jerichoalternatives.in/ " ;
}
2024-03-29 12:30:45 +05:30
if ( env ( 'APP_ENV' ) == 'staging' )
2024-03-28 14:52:40 +05:30
{
$finalPath = " https://staging.jerichoalternatives.in/ " ;
}
2024-03-29 12:30:45 +05:30
if ( env ( 'APP_ENV' ) == 'local' )
{
$finalPath = " http://localhost/jericho_28_march/ " ;
}
2024-03-28 14:52:40 +05:30
return $finalPath . $path ;
}
function routeForHandpickedInvestment ( $categoryId )
{
// return $categoryId;
// $routes = [
// // Category::HighYieldFinanceId => 'high-yield-finance.product',
// Category::FractionalRealEstateId => 'fractional-real-estate.product',
// // Category::PeerToPeerLendingId => 'peer-to-peer-lending.product',
// Category::VentureDebtId => 'venture-debts.product',
// Category::IndianResidentialRealEstateID => 'ire.product',
// Category::IndianCommercialRealEstateID => 'ire.product',
// Category::IndianIndustrialRealEstateID => 'ire.product',
// Category::GlobalResidentialRealEstateID => 'gre.product',
// Category::GlobalCommercialRealEstateID => 'gre.product',
// Category::GlobalIndustrialRealEstateID => 'gre.product',
// // Category::LeaseBasedFinancingId => 'lease-based-financing.product',
// // Category::SecuritizedDebtInstrumentId => 'securitized-debt-instrument.product',
// // Category::CleanAndGreenAssetsId => 'clean-and-green-assets.product',
// // Category::InvoiceDiscountingId => 'invoice-discounting.product',
// Category::VentureCapitalFundId => 'alternative-investment-fund.venture-capital-fund-product',
// Category::InfrastructureFundId => 'alternative-investment-fund.venture-capital-fund-product',
// Category::AngelFundId => 'alternative-investment-fund.angel-fund-product',
// Category::PrivateEquityFundId => 'alternative-investment-fund.private-equity-fund-product',
// Category::DebtFundId => 'alternative-investment-fund.debt-fund-product',
// Category::PrivateRealEstateFundId => 'alternative-investment-fund.private-real-estate-fund-product',
// Category::HedgeFundId => 'alternative-investment-fund.hedge-fund-product',
// Category::PrivateInvestmentInPublicEquityFundId => 'alternative-investment-fund.private-investment-public-equity-product',
// Category::SovereignGovernmentBondId => 'bonds.product',
// Category::GlobalMutualFundId => 'mutual-funds.product',
// Category::EquitiesId => 'equities.product',
// Category::GlobalHedgeFundId => 'hedge-funds.product',
// // Category::InfrastructureFundId => 'alternative-investment-fund.',
// //Change below code later
// //
// ];
$routes = [
Category :: HighYieldFinanceId => 'high-yield-finance.product' ,
Category :: FractionalRealEstateId => 'fractional-real-estate.product' ,
Category :: PeerToPeerLendingId => 'peer-to-peer-lending.product' ,
Category :: VentureDebtId => 'venture-debts.product' ,
Category :: IndianResidentialRealEstateID => 'ire.product' ,
Category :: IndianCommercialRealEstateID => 'ire.product' ,
Category :: IndianIndustrialRealEstateID => 'ire.product' ,
Category :: GlobalResidentialRealEstateID => 'gre.product' ,
Category :: GlobalCommercialRealEstateID => 'gre.product' ,
Category :: GlobalIndustrialRealEstateID => 'gre.product' ,
Category :: LeaseBasedFinancingId => 'lease-based-financing.product' ,
Category :: SecuritizedDebtInstrumentId => 'securitized-debt-instrument.product' ,
Category :: CleanAndGreenAssetsId => 'clean-and-green-assets.product' ,
Category :: InvoiceDiscountingId => 'invoice-discounting.product' ,
Category :: VentureCapitalFundId => 'alternative-investment-fund.venture-capital-fund-product' ,
Category :: GlobalVentureCapitalFundId => 'alternative-investment-fund.venture-capital-fund-product' ,
Category :: InfrastructureFundId => 'alternative-investment-fund.infrastructure-fund-product' ,
Category :: FundForDistressedAssetId => 'alternative-investment-fund.fund-for-distressed-asset-product' ,
Category :: AngelFundId => 'alternative-investment-fund.angel-fund-product' ,
Category :: PrivateEquityFundId => 'alternative-investment-fund.private-equity-fund-product' ,
Category :: GlobalPrivateEquityFundId => 'alternative-investment-fund.private-equity-fund-product' ,
Category :: DebtFundId => 'alternative-investment-fund.debt-fund-product' ,
Category :: PrivateRealEstateFundId => 'alternative-investment-fund.private-real-estate-fund-product' ,
Category :: HedgeFundId => 'alternative-investment-fund.hedge-fund-product' ,
Category :: PrivateInvestmentInPublicEquityFundId => 'alternative-investment-fund.private-investment-public-equity-product' ,
Category :: SovereignGovernmentBondId => 'bonds.product' ,
Category :: GlobalMutualFundId => 'mutual-funds.product' ,
Category :: EquitiesId => 'equities.product' ,
Category :: GlobalHedgeFundId => 'hedge-funds.product' ,
];
return $routes [ $categoryId ];
// $condition = array_search($categoryId, $routes);
// return $condition == true ? $condition : 'venture-debts.product';
}
function testimonial ()
{
return Testimonial :: where ( 'is_active' , true ) -> get ();
}
function latestBlog ()
{
return Blog :: where ( 'is_active' , true ) -> take ( 3 ) -> get ();
}
function privacyPolicy ()
{
return Content :: where ( 'type' , 'privacy-policy' ) -> value ( 'content' );
}
function termsConditions ()
{
return Content :: where ( 'type' , 'terms-and-condition' ) -> value ( 'content' );
}
function getAllNotifications ()
{
$user = User :: find ( auth () -> guard ( 'users' ) -> user () -> id );
return $user -> unreadNotifications ;
}
function getAllAdminNotifications ()
{
// $arr = [];
// return $arr;
$user = User :: find ( auth () -> user () -> id );
return $user -> unreadNotifications ;
}
function getUserProfile ()
{
if ( ! auth () -> guard ( 'users' ) -> user ()) {
return [
'name' => false ,
'profile-image' => false
];
}
$user = User :: find ( auth () -> guard ( 'users' ) -> user () -> id );
if ( $user ) {
return [
'name' => $user -> name ,
'profile-image' => $user -> profile_image
];
}
}
function getAdminProfile ()
{
$user = User :: find ( auth () -> user () -> id );
return [
'name' => $user -> name ,
'email' => $user -> email ,
'profile-image' => $user -> profile_image
];
}
function getAllProductNames ( $categoriesId = '' )
{
return Product :: leftJoin ( 'securitized_debt_instruments as sdi' , 'products.id' , 'sdi.products_id' )
-> leftJoin ( 'fractional_real_estates as fre' , 'products.id' , 'fre.products_id' )
-> leftJoin ( 'peer_to_peer_lendings as p2p' , 'products.id' , 'p2p.products_id' )
-> leftJoin ( 'invoice_discountings as id' , 'products.id' , 'id.products_id' )
-> leftJoin ( 'alternative_investment_funds as aif' , 'products.id' , 'aif.products_id' )
-> leftJoin ( 'clean_and_green_assets as caga' , 'products.id' , 'caga.products_id' )
-> leftJoin ( 'high_yield_finances as hyf' , 'products.id' , 'hyf.products_id' )
-> leftJoin ( 'lease_based_financings as lbf' , 'products.id' , 'lbf.products_id' )
-> leftJoin ( 'venture_debts as vd' , 'products.id' , 'vd.products_id' )
-> leftJoin ( 'bonds as bd' , 'products.id' , 'bd.products_id' )
-> leftJoin ( 'funds as fd' , 'products.id' , 'fd.products_id' )
-> leftJoin ( 'stock_funds_real_estate_exchanges as exchange' , 'products.id' , 'exchange.products_id' )
-> leftJoin ( 'real_estates as re' , 'products.id' , 're.products_id' )
-> where ( 'status' , true )
-> when ( $categoriesId !== '' , function ( $query ) use ( $categoriesId ) {
$query -> whereIn ( 'categories_id' , [ $categoriesId ]);
})
-> select ( \DB :: raw ( 'products.id,coalesce(sdi.product_name, p2p.scheme, fre.property_name_and_location,id.company_name,aif.fund_name,caga.project_name,hyf.security_name,lbf.company,sdi.product_name,vd.company_name,bd.issuer,fd.fund_name,exchange.name,re.property_name) as product_name' )) -> get ();
}
function getAllSoldProducts ( $sellerFormId )
{
$productsSold = 0 ;
$marketplaceAIFPRoducts = MarketplaceAlternativeInvestmentFundSeller :: where ( 'seller_forms_id' , $sellerFormId ) -> get ();
foreach ( $marketplaceAIFPRoducts as $data ) {
if ( MarketplaceBuyerForm :: where ([ 'table' => 'marketplace_aif_sellers' , 'status' => 'Sold' , 'associated_id' => $data -> id ]) -> exists ()) {
$productsSold ++ ;
}
}
$marketplaceFREPRoducts = MarketplaceFractionalRealEstateSeller :: where ( 'seller_forms_id' , $sellerFormId ) -> get ();
foreach ( $marketplaceFREPRoducts as $data ) {
if ( MarketplaceBuyerForm :: where ([ 'table' => 'marketplace_fre_sellers' , 'status' => 'Sold' , 'associated_id' => $data -> id ]) -> exists ()) {
$productsSold ++ ;
}
}
$marketplaceOPPRoducts = MarketplaceOtherProductsSeller :: where ( 'seller_forms_id' , $sellerFormId ) -> get ();
foreach ( $marketplaceOPPRoducts as $data ) {
if ( MarketplaceBuyerForm :: where ([ 'table' => 'marketplace_op_sellers' , 'status' => 'Sold' , 'associated_id' => $data -> id ]) -> exists ()) {
$productsSold ++ ;
}
}
return $productsSold ;
}
function totalInvestmentCount ( $id )
{
return MonthlyUpdateMaster :: where ([ 'users_id' => $id , 'holding_status' => 'Holding' ]) -> count ();
}
function totalInvestment ( $id , $type = null )
{
// $user = MonthlyUpdateMaster::where('users_id', $id)->where('holding_status',$type)->get();
$user = MonthlyUpdateMaster :: where ( 'users_id' , $id ) -> when ( $type !== null , function ( $query ) use ( $type ) {
return $query -> where ( 'holding_status' , $type );
}) -> get ();
$productDetails = [];
foreach ( $user as $singleMUM ) {
$dataArr = [
'categories' => $singleMUM -> categories ,
'product_category' => $singleMUM -> product_category ,
'product_name' => $singleMUM -> product_name ,
];
if ( MonthlyUpdateAlternativeInvestmentFund :: where ( 'custom_id' , $singleMUM -> custom_id ) -> exists ()) {
$data = MonthlyUpdateAlternativeInvestmentFund :: where ( 'custom_id' , $singleMUM -> custom_id ) -> latest () -> first ();
$dataArr [ 'total_investment_amount' ] = $data -> getRawOriginal ( 'commitment_amount' );
array_push ( $productDetails , $dataArr );
} elseif ( MonthlyUpdateFractionalRealEstate :: where ( 'custom_id' , $singleMUM -> custom_id ) -> first ()) {
$data = MonthlyUpdateFractionalRealEstate :: where ( 'custom_id' , $singleMUM -> custom_id ) -> latest () -> first ();
$dataArr [ 'total_investment_amount' ] = $data -> getRawOriginal ( 'absolute_return_till_date' );
array_push ( $productDetails , $dataArr );
} elseif ( MonthlyUpdatePeerToPeerLending :: where ( 'custom_id' , $singleMUM -> custom_id ) -> first ()) {
$data = MonthlyUpdatePeerToPeerLending :: where ( 'custom_id' , $singleMUM -> custom_id ) -> latest () -> first ();
if ( $singleMUM -> categories == 'Liquiloans' ) {
$dataArr [ 'total_investment_amount' ] = $data -> getRawOriginal ( 'total_investment' );
} elseif ( $singleMUM -> categories == 'Faircent' ) {
$dataArr [ 'total_investment_amount' ] = $data -> getRawOriginal ( 'all_time_amount_invested' );
} elseif ( $singleMUM -> categories == 'Finance Peer' ) {
$dataArr [ 'total_investment_amount' ] = $data -> getRawOriginal ( 'all_time_investment_added' );
}
array_push ( $productDetails , $dataArr );
} elseif ( MonthlyUpdateIndianFinancialAssets :: where ( 'custom_id' , $singleMUM -> custom_id ) -> first ()) {
$data = MonthlyUpdateIndianFinancialAssets :: where ( 'custom_id' , $singleMUM -> custom_id ) -> latest () -> first ();
$dataArr [ 'total_investment_amount' ] = $data -> amount_invested ;
array_push ( $productDetails , $dataArr );
}
}
$totalInvestment = array_sum ( array_column ( $productDetails , 'total_investment_amount' ));
$totalInvestment = IND_money_format ( $totalInvestment );
return $totalInvestment ;
}
function generateCommissionCount ()
{
return ProductTrailCommission :: whereDate ( 'commission_date' , '<=' , now ()) -> where ( 'commission_earned' , 'No' ) -> count ();
}
function IND_money_format ( $number )
{
$number = ( float ) $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 ;
}
function unreadChats ()
{
$unreadChats = Chat :: groupBy ( 'user_id' ) -> where ( 'read_at' , null ) -> get ();
return count ( $unreadChats );
}
function companyName ( $id )
{
return Company :: where ( 'id' , $id ) -> value ( 'company_name' );
}
function getCategoryIcons ( $categoryId )
{
$category_icons = [
" public/assets/media/FrontendImages/fract-state.svg " => Category :: FractionalRealEstateId ,
" public/assets/media/FrontendImages/capital-funds.svg " => Category :: VentureCapitalFundId ,
" public/assets/media/FrontendImages/comm-real-state.svg " => Category :: IndianCommercialRealEstateID ,
" public/assets/media/FrontendImages/stra-fund.svg " => Category :: HedgeFundId ,
];
$condition = array_search ( $categoryId , $category_icons );
return $condition == true ? $condition : 'public/assets/media/FrontendImages/bay-arrow.svg' ;
}