Update TimekeepingController.php
This commit is contained in:
		
							parent
							
								
									5b66eaeb28
								
							
						
					
					
						commit
						0b63632e1b
					
				| 
						 | 
				
			
			@ -114,17 +114,47 @@ class TimekeepingController extends Controller
 | 
			
		|||
        if ($user_id == "") {
 | 
			
		||||
            return response()->json(['status' => false, 'message' => 'User not found!']);
 | 
			
		||||
        }
 | 
			
		||||
        Notes::insert([
 | 
			
		||||
            [
 | 
			
		||||
                "n_user_id" => $user_id,
 | 
			
		||||
                "n_day" => $day,
 | 
			
		||||
                "n_month" => $month,
 | 
			
		||||
                "n_year" => $year,
 | 
			
		||||
                "n_time_type" => $time_type,
 | 
			
		||||
                "n_reason" => $reason,
 | 
			
		||||
                "n_note" => $note
 | 
			
		||||
            ]
 | 
			
		||||
        // Notes::insert([
 | 
			
		||||
        //     [
 | 
			
		||||
        //         "n_user_id" => $user_id,
 | 
			
		||||
        //         "n_day" => $day,
 | 
			
		||||
        //         "n_month" => $month,
 | 
			
		||||
        //         "n_year" => $year,
 | 
			
		||||
        //         "n_time_type" => $time_type,
 | 
			
		||||
        //         "n_reason" => $reason,
 | 
			
		||||
        //         "n_note" => $note
 | 
			
		||||
        //     ]
 | 
			
		||||
        // ]);
 | 
			
		||||
 | 
			
		||||
        $existingNote = Notes::where('n_user_id', $user_id)
 | 
			
		||||
            ->where('n_day', $day)
 | 
			
		||||
            ->where('n_month', $month)
 | 
			
		||||
            ->where('n_year', $year)
 | 
			
		||||
            ->where('n_reason', $reason)
 | 
			
		||||
            ->first();
 | 
			
		||||
 | 
			
		||||
        if ($existingNote) {
 | 
			
		||||
            // Cập nhật bản ghi nếu đã tồn tại
 | 
			
		||||
            $existingNote->update([
 | 
			
		||||
                'n_day' => $day,
 | 
			
		||||
                'n_month' => $month,
 | 
			
		||||
                'n_year' => $year,
 | 
			
		||||
                'n_time_type' => $time_type,
 | 
			
		||||
                'n_reason' => $reason,
 | 
			
		||||
                'n_note' => $note
 | 
			
		||||
            ]);
 | 
			
		||||
        } else {
 | 
			
		||||
            // Chèn bản ghi mới nếu không tồn tại
 | 
			
		||||
            Notes::create([
 | 
			
		||||
                'n_user_id' => $user_id,
 | 
			
		||||
                'n_day' => $day,
 | 
			
		||||
                'n_month' => $month,
 | 
			
		||||
                'n_year' => $year,
 | 
			
		||||
                'n_time_type' => $time_type,
 | 
			
		||||
                'n_reason' => $reason,
 | 
			
		||||
                'n_note' => $note
 | 
			
		||||
            ]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->createOrUpdateRecordForCurrentMonth($month, $year);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue