1
0
forked from poc/pds

Updated get latest update_count in post method functionality

This commit is contained in:
dhanabalan
2025-07-05 21:15:50 +05:30
parent 3a0185391a
commit cefebd9f86

View File

@@ -236,7 +236,6 @@ class TestingPanelController extends Controller
{ {
foreach ($item['serial_numbers'] as $serial) foreach ($item['serial_numbers'] as $serial)
{ {
//For update_count calculation //For update_count calculation
$updateCount = [ $updateCount = [
'plant_id' => $plantId, 'plant_id' => $plantId,
@@ -247,16 +246,21 @@ class TestingPanelController extends Controller
'rework_count' => $serial['rework_count'] ?? 0, 'rework_count' => $serial['rework_count'] ?? 0,
]; ];
// Find the current max update_count for this composite key // // Find the current max update_count for this composite key //updated_at
// $maxUpdateCount = \App\Models\TestingPanelReading::where($updateCount)->max('update_count'); // // $maxUpdateCount = \App\Models\TestingPanelReading::where($updateCount)->max('update_count');
$maxUpdateCount = TestingPanelReading::where($updateCount) // $maxUpdateCount = TestingPanelReading::where($updateCount)->orderByDesc('update_count')->select('update_count')->first();
->select(TestingPanelReading::raw('MAX(CAST(update_count AS INTEGER)) AS max_update_count')) // // ->select(TestingPanelReading::raw('MAX(CAST(update_count AS INTEGER)) AS max_update_count'))->value('max_update_count');
->value('max_update_count'); // // ->value('update_count')
$newUpdateCount = ($maxUpdateCount == null || $maxUpdateCount == '') ? 0 : $maxUpdateCount + 1; // First, get the maximum length
$maxLength = TestingPanelReading::where($updateCount)->selectRaw('MAX(LENGTH(update_count)) as max_length')->value('max_length');
$updateCountString = (string) $newUpdateCount; // Then, get all records with that length
$lastUpdateCount = TestingPanelReading::where($updateCount)->whereRaw('LENGTH(update_count) = ?', [$maxLength])->orderByDesc('update_count')->select('update_count')->first();//->get();
$newUpdateCount = ($lastUpdateCount == null || $lastUpdateCount == '') ? 0 : (int)$lastUpdateCount?->update_count + 1;//$maxUpdateCount?->update_count
$updateCountString = (string)$newUpdateCount;
$row = $row =
[ [