Files
freeu-project/app/Imports/AlternativeInvestmentFundImport.php
2024-05-03 13:54:10 +05:30

120 lines
5.8 KiB
PHP

<?php
namespace App\Imports;
use App\Models\AlternativeInvestmentFund;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use App\Models\Product;
use App\Models\Table;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Validator;
class AlternativeInvestmentFundImport implements ToCollection, WithHeadingRow
{
/**
* @param Collection $collection
*/
protected $category_id;
public function __construct($category_id)
{
$this->category_id = $category_id;
}
public function rules(): array
{
// return null;
return [
// '*.name_of_the_fund' => 'required|unique:alternative_investment_funds,fund_name'
// '*.property_name' => 'required|unique:fractional_real_estates,property_name'
// '*.min_investment' => 'required',
// '*.return_rate' => 'required',
];
}
public function customValidationMessages(Collection $rows)
{
$messages = [];
foreach ($rows as $key => $val) {
$messages['' . $key . '.name_of_the_fund.required'] = 'Fund name should not be empty at row ' . $key + 1;
$messages['' . $key . '.name_of_the_fund.unique'] = 'Fund name is not unique at row ' . $key + 1;
}
return $messages;
// return [
// '*.property_name.required' => 'Property name must not be empty!'
// // '*.min_investment.required' => 'Minimun Investment must not be empty!',
// // '*.return_rate.required' => 'Return Rate must not be empty!'
// ];
}
public function collection(Collection $rows)
{
Validator::make($rows->toArray(), $this->rules(), $this->customValidationMessages($rows))->validate();
// dd($rows);
foreach ($rows as $row) {
$product = Product::create([
'tables_id' => Table::AlternativeInvestmentFundTable,
'categories_id' => $this->category_id,
'total_views' => 0,
'status' => 0,
'created_by' => auth()->user()->id,
'description'=> $row['description'] ?? null,
]);
$count = AlternativeInvestmentFund::where('fund_name',$row['name_of_the_fund'])->count();
AlternativeInvestmentFund::create([
'products_id' => $product->id,
'slug' => $count < 1 ? Str::slug($row['name_of_the_fund']) : Str::slug($row['name_of_the_fund']).'-'.$count+1,
'fund_name' => $row['name_of_the_fund'],
'registration_number' => $row['registration_no'] ?? null,
'fund_category' => $row['fund_category_iiiiii'],
'fund_structure' => $row['fund_structure_openclosed'],
'fund_strategy' => $row['fund_strategy'],
'fund_domicile' => $row['fund_domicile'],
'fund_manager_name' => $row['fund_manager_name'],
'website_of_the_fund' => $row['website_of_the_fund'],
'fund_manager_experience' => $row['fund_manager_experience'],
'sponsor' => $row['sponsor'],
'manager' => $row['manager'],
'trustee' => $row['trustee'],
'auditor' => $row['auditor'],
'valuer_tax_advisor' => $row['valuertax_advisor'] ?? null,
'credit_rating' => $row['credit_rating_if_any'] ?? null,
'open_date' => $row['open_date'],
'first_close_date' => $row['1st_close_date'],
'final_close_date' => $row['final_close_date'],
'tenure_from_final_date' => $row['tenure_from_final_close'],
'commitment_period' => $row['commitment_period'],
'native_currency' => $row['native_currency'],
'target_corpus' => $row['target_corpus'],
'investment_manager_contribution' => $row['investment_manager_contribution'] ?? null,
'minimum_capital_commitment' => $row['minimum_capital_commitment'] ?? null,
'intial_drawdown' => $row['initial_drawdown'] ?? null,
'accepting_overseas_investment' => $row['accepting_overseas_investment'] ?? null,
'target_irr' => $row['target_irr'] ?? null,
'management_fees_and_carry' => $row['management_fees_and_carry_set_up_fee_management_fee_performance_fee'] ?? null,
'hurdle_rate' => $row['hurdle_rate'] ?? null,
'other_expenses' => $row['other_expenses'] ?? null,
'focused_sectors_industries' => $row['focused_sectorsindustries_in_which_they_are_investing'] ?? null,
'regions_covered' => $row['regions_coveredgeographical_locations_covered_by_the_fund'] ?? null,
'isin_code' => $row['isin_code'] ?? null,
'focused_real_estate_sectors' => $row['focused_real_estate_sectors'] ?? null,
'rera_complied_property' => $row['rera_compiled_propertyyesno'] ?? null,
'return_on_investment' => $row['return_on_investment'] ?? null,
'valuation_per_sector' => $row['valuation_per_sector'] ?? null,
'focused_funds' => $row['focused_funds'] ?? null,
'trading_strategy' => $row['trading_strategy'] ?? null,
'involved_in_short_selling' => $row['involved_in_short_selling'] ?? null,
'minimum_investment' => $row['minimum_investment'] ?? null,
'return_on_investment_irr_dpi_rvpi_tvpi' => $row['return_on_investment_irr_dpi_rvpi_tvpi'] ?? null,
'valuation_per_security_nav' => $row['valuation_per_security_nav'] ?? null,
'trading_strategy_used' => $row['trading_strategy_used'] ?? null,
]);
}
}
}