71 lines
3.1 KiB
PHP
71 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use App\Models\MonthlyUpdateAlternativeInvestmentFund;
|
|
|
|
class ImportMontlyUpdateAlternativeInvestmentFund implements ToCollection, WithHeadingRow
|
|
{
|
|
/**
|
|
* @param Collection $collection
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
// return null;
|
|
return [
|
|
// '*.issuer' => 'required|unique:bonds,issuer'
|
|
// '*.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 . '.issuer.required'] = 'Issuer should not be empty at row ' . $key + 1;
|
|
$messages['' . $key . '.issuer.unique'] = 'Issuer 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();
|
|
|
|
foreach ($rows as $row) {
|
|
if($row['commitment_amount'] != null && $row['contribution_amount'] != null && $row['contribution_called_amount'] != null && $row['contribution_uncalled_amount'] != null)
|
|
{
|
|
MonthlyUpdateAlternativeInvestmentFund::create([
|
|
'custom_id' => $row['custom_id'] ?? null,
|
|
'commitment_amount' => $row['commitment_amount'] ?? 0,
|
|
'contribution_amount' => $row['contribution_amount'] ?? 0,
|
|
'contribution_called_amount' => $row['contribution_called_amount'] ?? 0,
|
|
'contribution_uncalled_amount' => $row['contribution_uncalled_amount'] ?? 0,
|
|
'date_of_initial_contribution' => getConvertedDate($row['date_of_initial_contribution']) ?? 0,
|
|
'face_value_nav_per_unit' => $row['face_valuenav_per_unit'] ?? 0,
|
|
'principal_capital_repaid' => $row['principal_capital_repaid'] ?? 0,
|
|
'gross_income' => $row['gross_income'] ?? 0,
|
|
'total_fees_paid' => $row['total_fees_paid_set_up_management_operating'] ?? 0,
|
|
'net_income' => $row['net_income'] ?? 0,
|
|
'no_of_units_alloted' => $row['no_of_units_alloted'] ?? 0,
|
|
'no_of_units_redeemed' => $row['no_of_units_redeemed'] ?? 0,
|
|
'current_valuation' => $row['current_valuation'] ?? 0,
|
|
'current_nav' => $row['current_nav'] ?? 0,
|
|
'no_of_units_held' => $row['no_of_units_held'] ?? 0,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|