<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use URL;
use Session;
use Illuminate\Support\Facades\Http;
use App\Http\Controllers\DataController;
use App\Models\log_master;
use App\Models\log_details;
class PostController extends Controller
{



    public function index(Request $request)

    {

       $response = Http::get('https://trafiqerp.in/petro_api/oj/key_reg.php',['reg_key'=>$request->reg_key]);

    

        $jsonData = $response->json();
       
       

          return $jsonData;

     

    } 
   


    public function get_data(Request $request)

    {
      $fn_strt_time=date('H:i:s');
      $user_session=Session::get('login_session');


        $urls="https://trafiqerp.in/petro_api/ij/".$request->url1;
       $response = Http::get($urls,['cid'=>$request->cid,'row_id'=>$request->row_id,'CID'=>$request->CID,'b_id'=>$request->b_id]);

        $jsonData = $response->json();
              
        $log_arr=array('user_session'=>$user_session,'log_date_time'=>date('Y-m-d H:i:s'),'page'=>$request->url1,'function'=>'get_data',
'fn_strt_time'=>$fn_strt_time,'fn_end_time'=>date('H:i:s'),'ref_id'=>0,'mode'=>3,'user_id'=>Session::get('user_id'),
'branch_id'=>Session::get('CID'),'company_id'=>Session::get('CID'),'data'=>json_encode($request->all())
);
$dt = new DataController;


$dt->log_insert($log_arr);


       

          return $jsonData;

     

    }
    public function get_data_shdl(Request $request)

    {


        $urls="https://trafiqerp.in/petro_api/ij/".$request->url1;
       $response = Http::get($urls,['cid'=>$request->cid,'row_id'=>$request->row_id,'CID'=>$request->CID,'emp_id'=>$request->emp_id]);

        $jsonData = $response->json();
      
       

          return $jsonData;

     

    }



    
    public function store_data(Request $request)

    {

//dd($request);
        $urls="https://trafiqerp.in/petro_api/ij/".$request->url1;
       $response = Http::get($urls,['json_data'=>$request->json_data]);


        $jsonData = $response->json();
       


          return $jsonData;

     

    }


}
