painting_cycle)) { // Update or insert into paint_systems $existingRecord = DB::table('paint_systems') ->where('paint_cycle', $lineListData->painting_cycle) ->first(); if ($existingRecord) { DB::table('paint_systems') ->where('paint_cycle', $lineListData->painting_cycle) ->update([ 'paint_cycle' => $lineListData->painting_cycle, 'revision' => $lineListData->rev ?? '', ]); ExecuteSaveTriggerJob::dispatch( 'paint_systems', ['key' => ['id' => $existingRecord->id]], ['id' => $existingRecord->id], ['paint_cycle' => $lineListData->painting_cycle, 'revision' => $lineListData->rev ?? ''], $existingRecord, 'update' ); } else { $insertedId = DB::table('paint_systems')->insertGetId([ 'paint_cycle' => $lineListData->painting_cycle, 'revision' => $lineListData->rev ?? '', 'created_at' => now(), 'updated_at' => now(), ]); $newRecord = DB::table('paint_systems')->find($insertedId); ExecuteSaveTriggerJob::dispatch( 'paint_systems', ['key' => ['id' => $insertedId]], ['id' => $insertedId], ['paint_cycle' => $lineListData->painting_cycle, 'revision' => $lineListData->rev ?? ''], $newRecord, 'insert' ); } // Update or insert into color_systems $colorSystemRecord = DB::table('color_systems') ->where('fluid_code', $lineListData->fluid_code) ->first(); $colorSystemData = [ 'fluid_code_description' => $lineListData->fluid_ru ?? "", 'fluid_code' => $lineListData->fluid_code, 'design_temperature' => $lineListData->design_temperature ?? "", 'working_temperature' => $lineListData->working_temperature ?? "", 'unit' => $lineListData->unit ?? "", 'updated_at' => now(), ]; if ($colorSystemRecord) { DB::table('color_systems') ->where('id', $colorSystemRecord->id) ->update($colorSystemData); ExecuteSaveTriggerJob::dispatch( 'color_systems', ['key' => ['id' => $colorSystemRecord->id]], ['id' => $colorSystemRecord->id], $colorSystemData, $colorSystemRecord, 'update' ); } else { $colorSystemData['created_at'] = now(); $insertedId = DB::table('color_systems')->insertGetId($colorSystemData); $newColorRecord = DB::table('color_systems')->find($insertedId); ExecuteSaveTriggerJob::dispatch( 'color_systems', ['key' => ['id' => $insertedId]], ['id' => $insertedId], $colorSystemData, $newColorRecord, 'insert' ); } $count++; } Log::debug("Sync Paint System $count row update or create"); return [ 'success' => true, 'processed_records' => $count ]; } }