mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Imports\Services;
|
|
|
|
use App\Models\Company;
|
|
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
|
use Maatwebsite\Excel\Concerns\WithValidation;
|
|
|
|
class ImportsDebtor implements ToModel, WithHeadingRow, WithBatchInserts, WithValidation
|
|
{
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
public function model($row = [])
|
|
{
|
|
try {
|
|
preg_match_all('/([0-9]{3,4}[a-zA-Z]{3,4})/', $row['desc2'], $matches);
|
|
|
|
foreach ($matches[0] as $match){
|
|
$reference = $match;
|
|
$debtor = $row['code'];
|
|
$company = Company::where('reference', $reference)->whereNull('debtor')->first();
|
|
|
|
if ($company) {
|
|
$company->debtor = $debtor;
|
|
$company->update();
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Exception $exception){
|
|
dd($exception);
|
|
}
|
|
}
|
|
|
|
public function batchSize(): int
|
|
{
|
|
return 100;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
|
|
];
|
|
}
|
|
}
|