<?php

namespace App\Http\Controllers;

use App\Models\BBJahesh;

use Carbon\Carbon;
use Illuminate\Http\Request;
use Hekmatinasser\Verta\Verta;

class BB_Jahesh_Controller extends Controller
{
    public function index(){
        $allrecords = BBJahesh::all();
        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => $allrecords
        ], 200);
    }
    public function update(Request $request)
    {
        //rz::::maxter
        $request->validate([
            'id' => 'required|integer|exists:b_b_jaheshes,id'
            ]);
        $id = $request->id;
        $validrecs = array_filter($request->all());
        // $id = $request->id;
        $uprecords = BBJahesh::find($id);
    
        // $uprecords->fill($validrecs);
        $uprecords->project_count_done = $request->project_count_done;
        $uprecords->last_updated_at_fa = verta(Carbon::now())->format('Y/n/j');
        $uprecords->project_progress = ($uprecords->project_count_done/(float)$uprecords->project_count_all)*100;
        $uprecords->save();


        return response()->json([
            'status' => 'succeed',
            'message' => '',
            'data' => 1
        ], 200);

    }

}
