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\HasSearchRequest;
 | 
			
		||||
use Illuminate\Http\Request;
 | 
			
		||||
use Illuminate\Support\Facades\Storage;
 | 
			
		||||
use Modules\Admin\app\Models\Admin;
 | 
			
		||||
use Modules\Admin\app\Models\Tracking;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +74,6 @@ class TrackingController extends Controller
 | 
			
		|||
                'time_string' => 'required',
 | 
			
		||||
                'status' => 'required',
 | 
			
		||||
            ]);
 | 
			
		||||
 | 
			
		||||
            $payload = $request->only(['name', 'time_string', 'status']);
 | 
			
		||||
            if($request->has('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)
 | 
			
		||||
    {
 | 
			
		||||
        $id = $request->get('id');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -123,6 +123,7 @@ Route::middleware('api')
 | 
			
		|||
    ], function () {
 | 
			
		||||
        Route::get('/', [TrackingController::class, 'get']);
 | 
			
		||||
        Route::post('/scan-create', [TrackingController::class, 'create']);
 | 
			
		||||
        Route::post('/send-image', [TrackingController::class, 'saveImage']);
 | 
			
		||||
        // 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 { 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 { useEffect, useState } from 'react'
 | 
			
		||||
import classes from './Timekeeping.module.css'
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ interface HistoryValue {
 | 
			
		|||
  user_id: number
 | 
			
		||||
  status: string
 | 
			
		||||
  time_string: string
 | 
			
		||||
  image: string
 | 
			
		||||
  created_at: string
 | 
			
		||||
  updated_at: string
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -162,6 +163,7 @@ const Timekeeping = () => {
 | 
			
		|||
                        {total / 60 / 60 < 8 && total !== 0 ? (
 | 
			
		||||
                          <Tooltip
 | 
			
		||||
                            multiline
 | 
			
		||||
                            
 | 
			
		||||
                            label={
 | 
			
		||||
                              <div>
 | 
			
		||||
                                {`Total: ${(total / 60 / 60).toFixed(1)}h`}
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +171,7 @@ const Timekeeping = () => {
 | 
			
		|||
                                  .find((h) => h.day === d)
 | 
			
		||||
                                  ?.values.map((v) => {
 | 
			
		||||
                                    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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue