<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;
use Illuminate\Support\Facades\Input;

class UserController extends Controller
{



    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $users = User::orderBy('id', 'desc')->paginate(20);
        return view('user.index', ['users' => $users]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $user = User::find($id);

        $data = \DB::select(\DB::raw("
                select *
                from Account
                left join CliqaSession
                on CliqaSession.account_id = Account.id
                left join TransactionContainer
                on TransactionContainer.session_id = CliqaSession.id
                left join PaymentTransaction
                on PaymentTransaction.transaction_container_id = TransactionContainer.id
                left join ProductTransaction
                on ProductTransaction.transaction_container_id = TransactionContainer.id
                where Account.id = '$id' and PaymentTransaction.transactionIdentifier is not NULL and ProductTransaction.result_doc is not NULL
                order by TransactionContainer.resolve_date desc;
        "));



        return view('user.show', ['user' => $user, 'data' => $data]);
        //return $data;
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update($id)
    {
        $user = User::find($id);
        $user->enabled = Input::get('enabled');
        $user->save();
        return redirect()->route('user.show', $id);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
