update timekeeping
This commit is contained in:
		
							parent
							
								
									16bc8b9a7a
								
							
						
					
					
						commit
						bab6052e82
					
				| 
						 | 
					@ -7,6 +7,7 @@ use App\Traits\HasFilterRequest;
 | 
				
			||||||
use App\Traits\HasOrderByRequest;
 | 
					use App\Traits\HasOrderByRequest;
 | 
				
			||||||
use App\Traits\HasSearchRequest;
 | 
					use App\Traits\HasSearchRequest;
 | 
				
			||||||
use Illuminate\Http\Request;
 | 
					use Illuminate\Http\Request;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Storage;
 | 
				
			||||||
use Modules\Admin\app\Models\Admin;
 | 
					use Modules\Admin\app\Models\Admin;
 | 
				
			||||||
use Modules\Admin\app\Models\Tracking;
 | 
					use Modules\Admin\app\Models\Tracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,7 +74,6 @@ class TrackingController extends Controller
 | 
				
			||||||
                'time_string' => 'required',
 | 
					                'time_string' => 'required',
 | 
				
			||||||
                'status' => 'required',
 | 
					                'status' => 'required',
 | 
				
			||||||
            ]);
 | 
					            ]);
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $payload = $request->only(['name', 'time_string', 'status']);
 | 
					            $payload = $request->only(['name', 'time_string', 'status']);
 | 
				
			||||||
            if($request->has('created_at')){
 | 
					            if($request->has('created_at')){
 | 
				
			||||||
              $payload['created_at'] = $request->created_at;              
 | 
					              $payload['created_at'] = $request->created_at;              
 | 
				
			||||||
| 
						 | 
					@ -141,6 +141,38 @@ class TrackingController extends Controller
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function saveImage(Request $request)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $id = $request->get('id');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tracking = Tracking::find($id);
 | 
				
			||||||
 | 
					        // $id = $request->get('id');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $tracking = Tracking::find($id);
 | 
				
			||||||
 | 
					        // $payload = $request->all();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if ($tracking) {
 | 
				
			||||||
 | 
					        //     $tracking->update($payload);
 | 
				
			||||||
 | 
					        // }
 | 
				
			||||||
 | 
					        if ($request->hasFile('image')) {
 | 
				
			||||||
 | 
					            $file = $request->file('image');
 | 
				
			||||||
 | 
					            $filename = $request->file_name;
 | 
				
			||||||
 | 
					            $path = 'screenshot' . "/$filename";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Storage::disk('public')->put(
 | 
				
			||||||
 | 
					                path: $path,
 | 
				
			||||||
 | 
					                contents: $file->get()
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					            $tracking->image = $path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $tracking->save();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return response()->json([
 | 
				
			||||||
 | 
					            'data' => $tracking,
 | 
				
			||||||
 | 
					            'status' => true
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function delete(Request $request)
 | 
					    public function delete(Request $request)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $id = $request->get('id');
 | 
					        $id = $request->get('id');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -123,6 +123,7 @@ Route::middleware('api')
 | 
				
			||||||
    ], function () {
 | 
					    ], function () {
 | 
				
			||||||
        Route::get('/', [TrackingController::class, 'get']);
 | 
					        Route::get('/', [TrackingController::class, 'get']);
 | 
				
			||||||
        Route::post('/scan-create', [TrackingController::class, 'create']);
 | 
					        Route::post('/scan-create', [TrackingController::class, 'create']);
 | 
				
			||||||
 | 
					        Route::post('/send-image', [TrackingController::class, 'saveImage']);
 | 
				
			||||||
        // Route::get('/clear-cache', [SettingController::class, 'clearCache']);
 | 
					        // Route::get('/clear-cache', [SettingController::class, 'clearCache']);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Database\Migrations\Migration;
 | 
				
			||||||
 | 
					use Illuminate\Database\Schema\Blueprint;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Schema;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					return new class extends Migration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Run the migrations.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function up(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::table('tracking', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            //
 | 
				
			||||||
 | 
					            $table->string('image', 255)->default(null);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Reverse the migrations.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function down(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::table('tracking', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            //
 | 
				
			||||||
 | 
					            $table->dropColumn('image');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
import { getTheTimesheet } from '@/api/Admin'
 | 
					import { getTheTimesheet } from '@/api/Admin'
 | 
				
			||||||
import { get } from '@/rtk/helpers/apiService'
 | 
					import { get } from '@/rtk/helpers/apiService'
 | 
				
			||||||
import { Box, Select, Table, Text, Tooltip } from '@mantine/core'
 | 
					import { Box, Image, Select, Table, Text, Tooltip } from '@mantine/core'
 | 
				
			||||||
import { IconCheck, IconX } from '@tabler/icons-react'
 | 
					import { IconCheck, IconX } from '@tabler/icons-react'
 | 
				
			||||||
import { useEffect, useState } from 'react'
 | 
					import { useEffect, useState } from 'react'
 | 
				
			||||||
import classes from './Timekeeping.module.css'
 | 
					import classes from './Timekeeping.module.css'
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ interface HistoryValue {
 | 
				
			||||||
  user_id: number
 | 
					  user_id: number
 | 
				
			||||||
  status: string
 | 
					  status: string
 | 
				
			||||||
  time_string: string
 | 
					  time_string: string
 | 
				
			||||||
 | 
					  image: string
 | 
				
			||||||
  created_at: string
 | 
					  created_at: string
 | 
				
			||||||
  updated_at: string
 | 
					  updated_at: string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -162,6 +163,7 @@ const Timekeeping = () => {
 | 
				
			||||||
                        {total / 60 / 60 < 8 && total !== 0 ? (
 | 
					                        {total / 60 / 60 < 8 && total !== 0 ? (
 | 
				
			||||||
                          <Tooltip
 | 
					                          <Tooltip
 | 
				
			||||||
                            multiline
 | 
					                            multiline
 | 
				
			||||||
 | 
					                            
 | 
				
			||||||
                            label={
 | 
					                            label={
 | 
				
			||||||
                              <div>
 | 
					                              <div>
 | 
				
			||||||
                                {`Total: ${(total / 60 / 60).toFixed(1)}h`}
 | 
					                                {`Total: ${(total / 60 / 60).toFixed(1)}h`}
 | 
				
			||||||
| 
						 | 
					@ -169,7 +171,7 @@ const Timekeeping = () => {
 | 
				
			||||||
                                  .find((h) => h.day === d)
 | 
					                                  .find((h) => h.day === d)
 | 
				
			||||||
                                  ?.values.map((v) => {
 | 
					                                  ?.values.map((v) => {
 | 
				
			||||||
                                    return (
 | 
					                                    return (
 | 
				
			||||||
                                      <p>{v.status + ': ' + v.time_string}</p>
 | 
					                                      <Box style={{display:'flex', alignItems:'center', justifyContent:"space-between"}}><p>{v.status + ': ' + v.time_string}</p> {v.image&&<Image w={100} h={100} src={import.meta.env.VITE_BACKEND_URL+"storage/"+v.image}/>}</Box>
 | 
				
			||||||
                                    )
 | 
					                                    )
 | 
				
			||||||
                                  })}
 | 
					                                  })}
 | 
				
			||||||
                              </div>
 | 
					                              </div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue