%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/silvzytp/dsr_code/app/Http/Controllers/
Upload File :
Create Path :
Current File : //home/silvzytp/dsr_code/app/Http/Controllers/CompareManagerController.php

<?php

namespace App\Http\Controllers;

use DataTables;
use App\Models\User;
use App\Models\MonthlyData;
use Illuminate\Http\Request;
use App\Models\IndividualTarget;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;

class CompareManagerController extends Controller
{
    public function index(){
        Gate::authorize('app.compare.index');

        page_title('Compare Manager');
        $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'), 'Compare Manager'=>''];
        $url = route(routeName().'.compare.get-data');
        return view('global.compare.index', compact('breadcrumb','url'));
    }

        /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function getData(Request $request){
        if ($request->ajax()) {
            $users = User::with('individualTargets')->where('role_id',3)->orderBy('id','desc');

            return DataTables::eloquent($users)
                ->addIndexColumn()
                ->addColumn('profile', function($data){
                    if (file_exists($data->avatar)) {
                        $img = '<img class="avatar-img" src="'.asset($data->avatar).'" >';
                    }else{
                        $img = '<img class="avatar-img" src="'.asset('uploads/images/user.png').'" >';
                    }

                    return $img;
                })
                ->addColumn('created_at', function($data){
                    return date_formats($data->created_at, 'd-M-Y');
                })
                ->addColumn('s_target', function($data){
                    return $data->individualTargets ? $data->individualTargets->sum('s_target') : 'N/A';
                })
                ->addColumn('s_achived', function($data){
                    return MonthlyData::toBase()->where('user_id',$data->id)
                        ->sum('sale_achievment');
                })
                ->addColumn('s_deifict', function($data){
                    $saleAchieved = MonthlyData::toBase()->where('user_id',$data->id)
                        ->sum('sale_achievment');

                    $saleDeficit = ($data->individualTargets->sum('s_target') - $saleAchieved);
                    return $saleDeficit;
                })
                ->addColumn('a_target', function($data){
                    return $data->target;
                })
                ->addColumn('a_achived', function($data){
                    return MonthlyData::toBase()->where('user_id',$data->id)
                        ->sum('revenue_achievment');
                })
                ->addColumn('a_deifict', function($data){
                    $revenueAchievment = MonthlyData::toBase()->where('user_id',$data->id)
                        ->sum('revenue_achievment');
                    $revenueDeficit = ($data->target - $revenueAchievment);
                    return $revenueDeficit;
                })
                ->addColumn('name', function($data){
                    return $data->name;
                })
                ->addColumn('bulk_check', function($data){
                    return '
                        <label class="ui-checkbox">
                            <input type="checkbox" name="checked_data" value="'.$data->id.'">
                            <span class="input-span"></span>
                        </label>
                    ';
                })
                ->rawColumns(['bulk_check','profile'])
                ->make(true);
        }
    }


    public function compareData(Request $request){
        Gate::authorize('app.compare.index');

        page_title('Compare Manager');
        $breadcrumb = ['Dashboard'=>route(routeName().'.dashboard'), 'Compare'=>''];

        if ($request->compare == 'compare') {
            $data = explode(',', $request->manager_id);
            $targets = User::with('individualTargets')->whereIn('id',$data)->get();

        }else{
            return back()->with('error','Please select a compare!');
        }

        return view('global.compare.compare', compact('targets','breadcrumb'));
    }
}

Zerion Mini Shell 1.0