68 lines
2.6 KiB
PHP
68 lines
2.6 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\MonthlyUpdateIndianFinancialAssets;
|
|
|
|
|
|
class ImportMontlyUpdateIndianFinancialAssets implements ToCollection, WithHeadingRow
|
|
{
|
|
/**
|
|
* @param array $row
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
|
*/
|
|
|
|
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) {
|
|
|
|
MonthlyUpdateIndianFinancialAssets::create([
|
|
'custom_id' => $row['custom_id'] ?? null,
|
|
'investment_date' => $row['investment_date'] ?? null,
|
|
'amount_invested' => $row['amount_invested'] ?? null,
|
|
'total_gross_repaid_amount' => $row['total_gross_repaid_amount'] ?? null,
|
|
'tenure_in_days' => $row['tenure_days'] ?? null,
|
|
'principal_payment_frequency' => $row['principal_payment_frequency'] ?? null,
|
|
'interest_payment_frequency' => $row['interest_payment_frequency'] ?? null,
|
|
'next_repayment_due_date' => $row['next_repayment_due_date'] ?? null,
|
|
'maturity_date' => $row['maturity_date'] ?? null,
|
|
'next_repayment_amount' => $row['next_repayment_amount'] ?? null,
|
|
'expected_irr' => $row['expected_irr'] ?? null,
|
|
]);
|
|
}
|
|
}
|
|
}
|