87 lines
3.2 KiB
PHP
87 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
use App\Models\Product;
|
|
use App\Models\VentureDebt;
|
|
use App\Models\Table;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class VentureDebtImport 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 [
|
|
// '*.scheme' => 'required|unique:peer_to_peer_lendings,scheme'
|
|
// '*.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.'.scheme.required'] = 'Scheme should not be empty at row ' . $key+1;
|
|
$messages[''.$key.'.scheme.unique'] = 'Scheme 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) {
|
|
$product = Product::create([
|
|
'tables_id' => Table::VentureDebtTable,
|
|
'categories_id' => $this->category_id,
|
|
'total_views' => 0,
|
|
'status' => 0,
|
|
'created_by' => auth()->user()->id
|
|
]);
|
|
|
|
$vd = VentureDebt::create([
|
|
'products_id' => $product->id,
|
|
// 'slug' => Str::slug($row['scheme']),
|
|
'company_name' => $row['company_name'],
|
|
'sector' => $row['sector'],
|
|
'minimum_investment' => $row['minimum_investment'],
|
|
'tenure' => $row['tenure'],
|
|
'total_issue_size' => $row['total_issue_size'],
|
|
'interest_payout' => $row['interest_payout'],
|
|
'principal_payout' => $row['principal_payout'],
|
|
'expected_return' => $row['expected_return'],
|
|
'collateral_cover_multiple' => $row['collateral_cover_multiple'],
|
|
'about_company' => $row['about_the_company'],
|
|
'instrument_type' => $row['instrument_type'],
|
|
'face_per_value_unit' => $row['face_value_per_unit'],
|
|
'prepayment_covenants' => $row['prepayment_covenants'],
|
|
'source_of_funds_repayment_debt' => $row['source_of_funds_for_repayment_of_debt'],
|
|
'minimum_investment_in_int' => $row['minimum_investment_in_int']
|
|
]);
|
|
}
|
|
}
|
|
}
|