62 lines
2.3 KiB
PHP
62 lines
2.3 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\MonthlyUpdatePeerToPeerLending;
|
|
|
|
class ImportMonthlyP2PFinancePeer 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) {
|
|
|
|
MonthlyUpdatePeerToPeerLending::create([
|
|
'custom_id' => $row['custom_id'],
|
|
'all_time_investment_added' => $row['all_time_investment_added'],
|
|
'total_active_investments' => $row['total_active_investments'],
|
|
'net_expected_value_at_maturity' => $row['net_expected_value_at_maturity'],
|
|
'net_asset_value' => $row['net_asset_value'],
|
|
'amount_withdrawn' => $row['amount_withdrawn'],
|
|
'interest_paidout' => $row['interest_paidout'],
|
|
'absolute_return_in_rs' => $row['absolute_return_in_rs'],
|
|
'absolute_return' => $row['absolute_return'],
|
|
]);
|
|
}
|
|
}
|
|
}
|