fixing fractional bid issue

This commit is contained in:
Ritikesh yadav
2024-05-07 16:45:56 +05:30
parent 918ad8eb85
commit 535e1f5d08
6 changed files with 754 additions and 341 deletions

View File

@@ -73,7 +73,7 @@ class MarketPlaceController extends Controller
// $marketplaceListed = [];
return [
@@ -119,45 +119,49 @@ class MarketPlaceController extends Controller
// $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();
if($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())
{
if (MarketplaceAlternativeInvestmentFundSeller::where('id', $buyerData[0]->associated_id)->exists()) {
$totalSellUnits = 0;
$buyerData->each(function($data) use($totalSellUnits){
$buyerData->each(function ($data) use ($totalSellUnits) {
return $totalSellUnits += (int)$data->no_of_units_you_wish_to_buy;
});
$getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id',$buyerData[0]->associated_id)->first();
$getAIFData = MarketplaceAlternativeInvestmentFundSeller::where('id', $buyerData[0]->associated_id)->first();
$aifData = (int)$getAIFData->no_of_units_you_wish_to_sell;
$remainUnits = $aifData - $totalSellUnits;
if($remainUnits <= 0)
{
if ($remainUnits <= 0) {
$status .= 'SOLD';
}
$status .= 'OPEN';
}
elseif(MarketplaceFractionalRealEstateSeller::where('id',$buyerData[0]->associated_id)->exists()){
} elseif (MarketplaceFractionalRealEstateSeller::where('id', $buyerData[0]->associated_id)->exists()) {
$status .= 'SOLD';
}
}else{
} else {
$status .= 'OPEN';
}
// dd($status);
$invested = $offering['invested'];
$totalInterestedBuyers = $offering['total-interested-buyers'];
$type = $offering['type'];
$ownProduct = $offering['own-product'];
$logged_in = auth()->guard('users')->check() == true ? true : false;
// dd('offering',$offering['invested_data']);
$investedData = $offering['invested_data'];
return view('Frontend.Pages.marketplace.view-offering', compact('offering', 'type', 'invested',
'totalInterestedBuyers', 'logged_in', 'ownProduct','investedData', 'status'));
return view('Frontend.Pages.marketplace.view-offering', compact(
'offering',
'type',
'invested',
'totalInterestedBuyers',
'logged_in',
'ownProduct',
'investedData',
'status'
));
}
public function viewOfferingData($slug)
@@ -170,7 +174,9 @@ class MarketPlaceController extends Controller
if (!auth()->guard('users')->check()) {
$offering['invested'] = false;
};
// $bidFor = '';
if (MarketplaceFractionalRealEstateSeller::where('slug', $slug)->exists()) {
// $bidFor .= 'fractional-real-estate';
$offering['type'] = 'fractional-real-estate';
$marketFRE = MarketplaceFractionalRealEstateSeller::where('slug', $slug)->first();
// if($user_id){
@@ -182,13 +188,14 @@ class MarketPlaceController extends Controller
$offering['total-interested-buyers'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_fre_sellers')['total-interested-buyers'];
} elseif (MarketplaceAlternativeInvestmentFundSeller::where('slug', $slug)->exists()) {
// $bidFor .= 'alternative-investment-funds';
$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'];
$offering['invested_data'] = $this->checkInvestmentInterestedData($offering['data'], 'marketplace_aif_sellers')['interested-status-data'];
$offering['total-interested-buyers'] = $this->checkInvestmentInterested($offering['data'], 'marketplace_aif_sellers')['total-interested-buyers'];
} elseif (MarketplaceOtherProductsSeller::where('slug', $slug)->exists()) {
$offering['type'] = 'other-products';
@@ -210,7 +217,7 @@ class MarketPlaceController extends Controller
if (auth()->guard('users')->check()) {
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => auth()->guard('users')->user()->id, 'table' => $table, 'associated_id' => $offering->id])->first();
}
return ['interested-status-data' => $interestedStatus ];
return ['interested-status-data' => $interestedStatus];
}
public function checkInvestmentInterested($offering, $table)
@@ -229,7 +236,7 @@ class MarketPlaceController extends Controller
public function buyerForm($slug)
{
$offering = $this->viewOfferingData($slug);
$table = $offering['type'];
$id = $offering['data']->id;
$userData = array();
@@ -257,26 +264,50 @@ class MarketPlaceController extends Controller
'contact_number' => $user->contact_number ?? null,
'email' => $user->email ?? $user->email,
];
return view('Frontend.Pages.profile.market-list.edit-buyer-form', compact('table', 'id', 'userData','investedData'));
return view('Frontend.Pages.profile.market-list.edit-buyer-form', compact('table', 'id', 'userData', 'investedData'));
}
public function buyerFormSubmit(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',
]);
// 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',
]);
}
$validationMessage = $this->validationError($validator);
@@ -304,8 +335,8 @@ class MarketPlaceController extends Controller
'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,
'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) {
@@ -324,23 +355,41 @@ class MarketPlaceController extends Controller
//update form start
public function buyerFormSubmitUpdate(Request $request)
{
$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',
]);
// 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',
]);
}
$validationMessage = $this->validationError($validator);
if ($validationMessage) {
@@ -358,20 +407,23 @@ class MarketPlaceController extends Controller
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
}
$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,
'offer_price_per_unit' => $request->offer_price_per_unit,
'total_purchase_value' => $request->total_purchase_value,
]);
if ($buyerForm) {
$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) {
}
$name = auth()->guard('users')->user()->name;
$notify['message'] = "$name has Updated a buyer form for $productName!";
$type = 'Buyer Form';
@@ -380,10 +432,12 @@ class MarketPlaceController extends Controller
$data->notify(new UserAdmin($notify, $type));
}
return response()->json(['status' => 200, 'message' => "Buyer Form Updated For Successfully"]);
} else {
return response()->json(['status' => 400, 'message' => "This product has been already sold to you"]);
}
return response()->json(['status' => 400, 'message' => "Buyer Form Could Not Be Updated!"]);
}
//update formm end
public function buyerFormAPI($slug)
{
@@ -507,7 +561,7 @@ class MarketPlaceController extends Controller
$productName = \DB::table($table)->where('id', $request->id)->value('security_name');
}
$buyerForm = MarketplaceBuyerForm::where('id',$request->marketplaceBuyerFormId)->update([
$buyerForm = MarketplaceBuyerForm::where('id', $request->marketplaceBuyerFormId)->update([
'users_id' => $request->user()->id,
'associated_id' => $request->id,
'table' => $table,
@@ -552,7 +606,6 @@ class MarketPlaceController extends Controller
$offering['invested'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_fre_sellers')['interested-status'];
$offering['invested-data'] = $this->checkInvestmentInterestedDataAPI($offering['data'], 'marketplace_fre_sellers')['interested-status-data']; //new added
$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();
@@ -561,9 +614,8 @@ class MarketPlaceController extends Controller
$offering['invested'] = $this->checkInvestmentInterestedAPI($offering['data'], 'marketplace_aif_sellers')['interested-status'];
$offering['invested-data'] = $this->checkInvestmentInterestedDataAPI($offering['data'], 'marketplace_aif_sellers')['interested-status-data'];
$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();
@@ -584,7 +636,7 @@ class MarketPlaceController extends Controller
if (request()->user()) {
$interestedStatus = MarketplaceBuyerForm::where(['users_id' => request()->user()->id, 'table' => $table, 'associated_id' => $offering->id])->first();
}
return ['interested-status-data' => $interestedStatus ];
return ['interested-status-data' => $interestedStatus];
}
public function checkInvestmentInterestedAPI($offering, $table)