From 5a6f82f8a3f43ec09e3cc2fc3ae60c60d2b4e3e5 Mon Sep 17 00:00:00 2001 From: Ritikesh yadav Date: Thu, 16 May 2024 11:53:28 +0530 Subject: [PATCH] fixing bid issue --- .../Controllers/Admin/OverviewController.php | 12 ++++++------ .../Frontend/MarketPlaceController.php | 19 ++++++++++++------- ...etplaceAlternativeInvestmentFundSeller.php | 17 ++++++++++------- .../MarketplaceFractionalRealEstateSeller.php | 5 ++++- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Admin/OverviewController.php b/app/Http/Controllers/Admin/OverviewController.php index 409d0b6..490b930 100644 --- a/app/Http/Controllers/Admin/OverviewController.php +++ b/app/Http/Controllers/Admin/OverviewController.php @@ -181,9 +181,9 @@ class OverviewController extends Controller // return response()->json(['status' => 400, 'message' => 'This product has already been Sold']); // } // } - $checkAlreadySold = MarketplaceBuyerForm::where(['id'=>$buyerId,'status'=>'Sold'])->exists(); - if(!$checkAlreadySold) - { + // $checkAlreadySold = MarketplaceBuyerForm::where(['id'=>$buyerId,'status'=>'Sold'])->exists(); + // if(!$checkAlreadySold) + // { // $marketPlaceId = $checkAlreadySold->associated_id; // if(MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->exists()) // { @@ -213,7 +213,7 @@ 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()) + if(MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->exists() && $getMarketplaceBuyerUnit->table == 'marketplace_aif_sellers') { $getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first(); $oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell; @@ -228,7 +228,7 @@ class OverviewController extends Controller return response()->json(['status' => 400, 'message' => 'Bid units is more than seller units with '.abs($newUnits).' units']); } - }else if(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists()) + }else if(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists() && $getMarketplaceBuyerUnit->table == 'marketplace_fre_sellers') { // dd('inside'); $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first(); @@ -262,7 +262,7 @@ class OverviewController extends Controller } // dd('outside'); } - } + // } // dd('hello'); $alreadySold = MarketplaceBuyerForm::where('id', $buyerId)->update([ 'status' => $status diff --git a/app/Http/Controllers/Frontend/MarketPlaceController.php b/app/Http/Controllers/Frontend/MarketPlaceController.php index 4ad52f1..964b325 100644 --- a/app/Http/Controllers/Frontend/MarketPlaceController.php +++ b/app/Http/Controllers/Frontend/MarketPlaceController.php @@ -117,14 +117,15 @@ class MarketPlaceController extends Controller // dd('helo'); // dd($request->all()); $offering = $this->viewOfferingData($slug); - // dd($offering['data']->id); + // 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')->exists(); + $checkBIDExist = MarketplaceBuyerForm::where('associated_id', $offering['data']->id)->where('status', 'Sold')->get(); + // dd($checkBIDExist); if ($checkBIDExist) { $buyerData = MarketplaceBuyerForm::where('associated_id', $offering['data']->id)->where('status', 'Sold')->get(); - // dd($buyerData->toArray()); - if (MarketplaceAlternativeInvestmentFundSeller::where('id', $buyerData[0]->associated_id)->exists()) { + // 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; @@ -134,15 +135,18 @@ class MarketPlaceController extends Controller $remainUnits = $aifData - $totalSellUnits; if ($remainUnits <= 0) { $status .= 'SOLD'; + }else{ + $status .= 'OPEN'; } - $status .= 'OPEN'; - } elseif (MarketplaceFractionalRealEstateSeller::where('id', $buyerData[0]->associated_id)->exists()) { + } 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'; } - $status .= 'OPEN'; + else{ + $status .= 'OPEN'; + } } } else { $status .= 'OPEN'; @@ -155,6 +159,7 @@ class MarketPlaceController extends Controller $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']; diff --git a/app/Models/MarketplaceAlternativeInvestmentFundSeller.php b/app/Models/MarketplaceAlternativeInvestmentFundSeller.php index 129b56b..262446a 100644 --- a/app/Models/MarketplaceAlternativeInvestmentFundSeller.php +++ b/app/Models/MarketplaceAlternativeInvestmentFundSeller.php @@ -107,8 +107,9 @@ class MarketplaceAlternativeInvestmentFundSeller extends Model if($remainUnits <= 0) { return 'SOLD'; + }else{ + return 'OPEN'; } - return 'OPEN'; } }else{ return 'OPEN'; @@ -144,17 +145,19 @@ class MarketplaceAlternativeInvestmentFundSeller extends Model // $bids = MarketplaceBuyerForm::where(['associated_id' => $this->id, 'table' => 'marketplace_aif_sellers'])->get(); $bidArray = collect(); $bids->each(function($value) use ($bidArray,$values){ - if($value->no_of_units_you_wish_to_buy < $values->no_of_units_you_wish_to_sell) - { - // $bidArray->push($value->getAttributes()['total_purchase_value']); - $bidArray->push($value->getAttributes()['offer_price_per_unit']); - } + $bidArray->push($value->getAttributes()['offer_price_per_unit']); + // if($value->no_of_units_you_wish_to_buy < $values->no_of_units_you_wish_to_sell) + // { + // // $bidArray->push($value->getAttributes()['total_purchase_value']); + // $bidArray->push($value->getAttributes()['offer_price_per_unit']); + // } }); $noOfUnitHeld = (int)$values->current_or_latest_nav; // $nav = intval($noOfUnitHeld) * intval($values->current_or_latest_nav); $highestBid = intval($bidArray->max()); // $bid = ($highestBid - $nav)/(int)$nav * 100 ; - $bid = ($highestBid - $noOfUnitHeld)/(int)$noOfUnitHeld * 100 ; + $bid = $highestBid != 0 ? ($highestBid - (int)$noOfUnitHeld)/(int)$noOfUnitHeld * 100 : 0 ; + // dd($bid); if(count($bids)) { return round($bid,3); diff --git a/app/Models/MarketplaceFractionalRealEstateSeller.php b/app/Models/MarketplaceFractionalRealEstateSeller.php index 956b92f..e7cef0d 100644 --- a/app/Models/MarketplaceFractionalRealEstateSeller.php +++ b/app/Models/MarketplaceFractionalRealEstateSeller.php @@ -80,7 +80,8 @@ class MarketplaceFractionalRealEstateSeller extends Model // $buyerData->each(function($data) use($totalSellUnits){ // return $totalSellUnits += (int)$data->no_of_units_you_wish_to_buy; // }); - if(MarketplaceFractionalRealEstateSeller::where('id',$id)->exists()) + // $id = $this->id; + if(MarketplaceBuyerForm::where(['associated_id'=>$id,'table' => 'marketplace_fre_sellers'])->exists()) { $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$id)->first(); // $aifData = (int)$getFREData->no_of_units_you_wish_to_sell; @@ -89,7 +90,9 @@ class MarketplaceFractionalRealEstateSeller extends Model { return 'SOLD'; } + else{ return 'OPEN'; + } }else{ return 'OPEN'; }