Files
exchange-2.0/app/Classes/Modules/Imports/Services/ImportsDebtor.php
T
2022-04-06 10:55:29 +08:00

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 [
];
}
}