48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Client;
|
|
use App\Models\Customers;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\GoogleAdsService;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CompareCustomer extends Command
|
|
{
|
|
protected $signature = 'customer:compare-customers';
|
|
protected $description = 'Compare customer details';
|
|
public function handle()
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$customers = Customers::all();
|
|
|
|
foreach ($customers as $customer) {
|
|
$cleanedInput = preg_replace('/[^A-Za-z0-9]/', '', $customer->company_name);
|
|
$client = Client::whereRaw("REGEXP_REPLACE(name, '[^A-Za-z0-9]', '') = ?", [$cleanedInput])
|
|
->first();
|
|
|
|
if ($client) {
|
|
// Update exact match
|
|
$client->update([
|
|
'sql_acc_code' => $customer->sql_acc_code,
|
|
]);
|
|
} else {
|
|
$this->info("Skipped Match Found for: {$customer->company_name}");
|
|
}
|
|
}
|
|
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
Log::error('Error project linkage : '.$e->getMessage(), [
|
|
'trace' => $e->getTraceAsString(),
|
|
]);
|
|
return 1;
|
|
}
|
|
}
|
|
}
|