bugs fixing

This commit is contained in:
meghamalore
2024-06-25 15:21:21 +05:30
parent 164bef8d0d
commit d59125ae6e
2 changed files with 68 additions and 49 deletions

View File

@@ -208,65 +208,83 @@ class OverviewController extends Controller
// }else
// dd($request->all());
// $userID .= '';F
$product_name = '';
$getMarketplaceBuyerUnit = MarketplaceBuyerForm::where('id', $buyerId)->first();
// $userID .= $getMarketplaceBuyerUnit->user_id;
$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() && $getMarketplaceBuyerUnit->table == 'marketplace_aif_sellers')
{
$getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->first();
$product_name .= $getAIFData->name_of_the_aif_fund;
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() && $getMarketplaceBuyerUnit->table == 'marketplace_aif_sellers')
$oldUnit = (int)$getAIFData->no_of_units_you_wish_to_sell;
$newUnits = $oldUnit - (int)$getUnits;
if($newUnits >= 0)
{
$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() && $getMarketplaceBuyerUnit->table == 'marketplace_fre_sellers')
{
// 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,
$updateUnits = MarketplaceAlternativeInvestmentFundSeller::where('id',$marketPlaceId)->update([
'no_of_units_you_wish_to_sell' => $newUnits,
]);
}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');
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() && $getMarketplaceBuyerUnit->table == 'marketplace_fre_sellers')
{
// dd('inside');
$getFREData = MarketplaceFractionalRealEstateSeller::where('id',$marketPlaceId)->first();
$product_name .= $getFREData->property_name;
if($status == 'Sold'){
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)]);
// }
}
$user = User::find($getMarketplaceBuyerUnit->users_id);
// $productName = $data->security_name ?? $data->property_name ?? $data->name_of_the_aif_fund;
$notify['message'] = "Your BID status for ($product_name) product has been changed to $status !";
$user->notify(new UserAdmin($notify));
// dd('outside');
// }
// $user = User::find($userID);
// // $productName = $data->security_name ?? $data->property_name ?? $data->name_of_the_aif_fund;
// $notify['message'] = "Your BID status for ($product_name) product has been changed to $status !";
// $user->notify(new UserAdmin($notify));
// }
// dd('hello');
$alreadySold = MarketplaceBuyerForm::where('id', $buyerId)->update([
'status' => $status
]);
return response()->json(['status' => 200, 'message' => 'Status Changed!']);
}