86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
use App\Models\Product;
|
|
use App\Models\LeaseBasedFinancing;
|
|
use App\Models\Table;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
class LeaseBasedFinancingImport 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 [
|
|
// '*.company' => 'required|unique:lease_based_financings,company'
|
|
// '*.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.'.company.required'] = 'Company should not be empty at row ' . $key+1;
|
|
$messages[''.$key.'.company.unique'] = 'Company 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::LeaseBasedFinancingTable,
|
|
'categories_id' => $this->category_id,
|
|
'total_views' => 0,
|
|
'status' => 0,
|
|
'created_by' => auth()->user()->id
|
|
]);
|
|
|
|
|
|
LeaseBasedFinancing::create([
|
|
'products_id' => $product->id,
|
|
'slug' => Str::slug($row['company']),
|
|
'company' => $row['company'],
|
|
'asset_class' => $row['asset_class'],
|
|
'underlying_asset' => $row['underlying_asset'],
|
|
'sector' => $row['sector'],
|
|
'mobility_platform' => $row['mobility_platform'],
|
|
'total_deal_size' => $row['total_deal_size'],
|
|
'minimum_investment' => $row['minimum_investment'],
|
|
'tenure' => $row['tenure'],
|
|
'payout_frequency' => $row['payout_frequency'],
|
|
'pre_tax_return' => $row['pre_tax_return'],
|
|
'minimum_investment_in_int' => $row['minimum_investment_in_int'],
|
|
]);
|
|
}
|
|
}
|
|
}
|