100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class MarketplaceBuyerForm extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['users_id', 'associated_id', 'table', 'name', 'city', 'country', 'contact_number', 'email_id', 'no_of_units_you_wish_to_buy', 'offer_price_per_unit', 'total_purchase_value','complete_units_sold','complete_sale_value','commission_earned','date_of_sale','platform','final_purchase_value'];
|
|
|
|
protected $appends = ['fund_category'];
|
|
|
|
|
|
public function scopeAlernativeInvestmentFund($query)
|
|
{
|
|
return $query->where([
|
|
'users_id' => auth()->guard('users')->user()->id ?? request()->user()->id,
|
|
'table' => 'marketplace_aif_sellers',
|
|
]);
|
|
}
|
|
|
|
public function scopeFractionalRealEstate($query)
|
|
{
|
|
return $query->where([
|
|
'users_id' => auth()->guard('users')->user()->id ?? request()->user()->id,
|
|
'table' => 'marketplace_fre_sellers',
|
|
]);
|
|
}
|
|
|
|
public function scopeOtherProducts($query)
|
|
{
|
|
return $query->where([
|
|
'users_id' => auth()->guard('users')->user()->id ?? request()->user()->id,
|
|
'table' => 'marketplace_op_sellers',
|
|
]);
|
|
}
|
|
|
|
public function scopeSold($query)
|
|
{
|
|
return $query->where('marketplace_buyer_forms.status', 'Sold');
|
|
}
|
|
|
|
public function getFundCategoryAttribute($value){
|
|
return 123;
|
|
return $this->attributes['name_of_the_aif_fund'];
|
|
|
|
// return $this->get_money_format($value);
|
|
}
|
|
|
|
public function getOfferPricePerUnitAttribute($value)
|
|
{
|
|
return $this->IND_money_format($value) ;
|
|
}
|
|
|
|
public function getTotalPurchaseValueAttribute($value)
|
|
{
|
|
return $this->IND_money_format($value) ;
|
|
}
|
|
|
|
public function IND_money_format($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;
|
|
}
|
|
|
|
public function company(){
|
|
return $this->belongsTo(Company::class,'platform');
|
|
}
|
|
|
|
public function freSellerData(){
|
|
return $this->hasOne(MarketplaceFractionalRealEstateSeller::class,'id','associated_id');
|
|
}
|
|
public function aifSellerData(){
|
|
return $this->hasOne(MarketplaceAlternativeInvestmentFundSeller::class,'id','associated_id');
|
|
}
|
|
}
|