Updated get latest update_count in post method functionality
This commit is contained in:
@@ -236,7 +236,6 @@ class TestingPanelController extends Controller
|
||||
{
|
||||
foreach ($item['serial_numbers'] as $serial)
|
||||
{
|
||||
|
||||
//For update_count calculation
|
||||
$updateCount = [
|
||||
'plant_id' => $plantId,
|
||||
@@ -247,17 +246,22 @@ class TestingPanelController extends Controller
|
||||
'rework_count' => $serial['rework_count'] ?? 0,
|
||||
];
|
||||
|
||||
// Find the current max update_count for this composite key
|
||||
// $maxUpdateCount = \App\Models\TestingPanelReading::where($updateCount)->max('update_count');
|
||||
$maxUpdateCount = TestingPanelReading::where($updateCount)
|
||||
->select(TestingPanelReading::raw('MAX(CAST(update_count AS INTEGER)) AS max_update_count'))
|
||||
->value('max_update_count');
|
||||
// // Find the current max update_count for this composite key //updated_at
|
||||
// // $maxUpdateCount = \App\Models\TestingPanelReading::where($updateCount)->max('update_count');
|
||||
// $maxUpdateCount = TestingPanelReading::where($updateCount)->orderByDesc('update_count')->select('update_count')->first();
|
||||
// // ->select(TestingPanelReading::raw('MAX(CAST(update_count AS INTEGER)) AS 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');
|
||||
|
||||
// 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 =
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
|
||||
Reference in New Issue
Block a user