64 lines
2.4 KiB
PHP
64 lines
2.4 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 ImportMonthlyP2PLiquiloans 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'],
|
|
'total_investment' => $row['total_investment'],
|
|
'principal_redemption' => $row['principal_redemption'],
|
|
'interest_paidout' => $row['interest_paid_out'],
|
|
'net_principal_investment' => $row['net_principal_investment'],
|
|
'capitalised_interest' => $row['capitalised_interest'],
|
|
'accrued_interest' => $row['accrued_interest'],
|
|
'portfolio_value' => $row['portfolio_value'],
|
|
'absolute_return_in_rs' => $row['absolute_return_in_rs'],
|
|
'absolute_return_in_pct' => $row['absolute_return'],
|
|
'annualised_return' => $row['annualised_return'],
|
|
]);
|
|
}
|
|
}
|
|
}
|