Files
nnterp-react-admin/check_imei.php

46 lines
1.4 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
// Connect explicitly to tnchub
config(['database.connections.tnchub' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => 'tnchub',
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
]]);
$rows = DB::connection('tnchub')->table('product_warehouse')
->whereNotNull('imei_number')
->where('imei_number', '!=', '')
->get();
$mismatches = [];
foreach ($rows as $row) {
// some imei strings might have spaces
$imeis = array_filter(array_map('trim', explode(',', $row->imei_number)));
$count = count($imeis);
$qty = (int)$row->qty;
if ($count !== $qty) {
$mismatches[] = [
'product_id' => $row->product_id ?? 'N/A',
'warehouse_id' => $row->warehouse_id ?? 'N/A',
'qty' => $qty,
'imei_count' => $count,
'imei_string' => $row->imei_number
];
}
}
if (empty($mismatches)) {
echo "All " . count($rows) . " items with IMEI numbers are perfectly aligned! (qty == number of IMEIs)\n";
} else {
echo "Found " . count($mismatches) . " mismatches out of " . count($rows) . " items:\n";
foreach ($mismatches as $m) {
echo "Product ID: {$m['product_id']} | Warehouse ID: {$m['warehouse_id']} | Qty: {$m['qty']} | IMEI Count: {$m['imei_count']}\n";
}
}