diff --git a/app/Http/Controllers/Admin/OverviewController.php b/app/Http/Controllers/Admin/OverviewController.php index d5308e9..5e61c89 100644 --- a/app/Http/Controllers/Admin/OverviewController.php +++ b/app/Http/Controllers/Admin/OverviewController.php @@ -208,59 +208,60 @@ class OverviewController extends Controller // }else // dd($request->all()); - // if($status == 'Sold'){ - $getMarketplaceBuyerUnit = MarketplaceBuyerForm::where('id', $buyerId)->first(); - $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()) - { - $getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first(); - $oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell; - $newUnits = $oldUnit - (int)$getUnits; - if($newUnits >= 0) + if($status == 'Sold'){ + $getMarketplaceBuyerUnit = MarketplaceBuyerForm::where('id', $buyerId)->first(); + $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()) { - $updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([ - 'no_of_units_you_wish_to_sell' => $newUnits, + $getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first(); + $oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell; + $newUnits = $oldUnit - (int)$getUnits; + if($newUnits >= 0) + { + $updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([ + 'no_of_units_you_wish_to_sell' => $newUnits, + ]); + } + else{ + return response()->json(['status' => 400, 'message' => 'Bid units is more than seller units with '.abs($newUnits).' units']); + } + + }else if(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists()) + { + // dd('inside'); + $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first(); + if((int)$getFREData->current_market_value_of_the_property <= 0) + { + return response()->json(['status' => 400, 'message' => 'Product cannot be sold. because product has no value.']); + } + $freValue = (int)$getFREData->current_market_value_of_the_property; + $nowValue = $freValue - $getBuyingPurchaseValue; + + $percentage = ($freValue - $getBuyingPurchaseValue) / $freValue * 100; + + $expectedSellingPrice = (int)$getFREData->expected_selling_price; + $updateExpectedSellingPrice = $expectedSellingPrice * ($percentage / 100); + // dd($percentage,$updateExpectedSellingPrice); + if($nowValue <= 0) + { + $updatePrice = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->update([ + 'current_market_value_of_the_property' => 0, + 'expected_selling_price' => 0, ]); + }else if($nowValue > 0){ + $updatePrice = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->update([ + 'current_market_value_of_the_property' => $nowValue, + 'expected_selling_price' => $updateExpectedSellingPrice, + ]); + } + // else{ + // return response()->json(['status' => 400, 'message' => 'Bid price is more than seller price with ₹'.abs($nowValue)]); + // } } - else{ - return response()->json(['status' => 400, 'message' => 'Bid units is more than seller units with '.abs($newUnits).' units']); - } - - }else if(MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->exists()) - { - // dd('inside'); - $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first(); - if((int)$getFREData->current_market_value_of_the_property <= 0) - { - return response()->json(['status' => 400, 'message' => 'Product cannot be sold. because product has no value.']); - } - $freValue = (int)$getFREData->current_market_value_of_the_property; - $nowValue = $freValue - $getBuyingPurchaseValue; - - $percentage = ($freValue - $getBuyingPurchaseValue) / $freValue * 100; - - $expectedSellingPrice = (int)$getFREData->expected_selling_price; - $updateExpectedSellingPrice = $expectedSellingPrice * ($percentage / 100); - // dd($percentage,$updateExpectedSellingPrice); - if($nowValue <= 0) - { - $updatePrice = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->update([ - 'current_market_value_of_the_property' => 0, - 'expected_selling_price' => 0, - ]); - }else if($nowValue > 0){ - $updatePrice = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->update([ - 'current_market_value_of_the_property' => $nowValue, - 'expected_selling_price' => $updateExpectedSellingPrice, - ]); - } - // else{ - // return response()->json(['status' => 400, 'message' => 'Bid price is more than seller price with ₹'.abs($nowValue)]); - // } + // dd('outside'); } - // dd('outside'); } // dd('hello'); $alreadySold = MarketplaceBuyerForm::where('id', $buyerId)->update([ diff --git a/resources/views/Frontend/Pages/profile/market-list/buyer-form.blade.php b/resources/views/Frontend/Pages/profile/market-list/buyer-form.blade.php index 2d50c1e..c4264db 100644 --- a/resources/views/Frontend/Pages/profile/market-list/buyer-form.blade.php +++ b/resources/views/Frontend/Pages/profile/market-list/buyer-form.blade.php @@ -62,10 +62,12 @@