2021-03-12 14:42:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Objectives;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-05-17 12:22:53 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2021-03-12 14:42:15 +01:00
|
|
|
|
|
|
|
|
class ObjectivesController extends Controller
|
|
|
|
|
{
|
2021-03-30 17:07:16 +02:00
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
2023-08-21 15:24:32 +02:00
|
|
|
$filter_tc_id = $request->query('filter_tc_id');
|
2021-05-26 11:59:45 +02:00
|
|
|
|
2021-05-17 12:22:53 +02:00
|
|
|
$objectives = $this->filterObjectives($request);
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
$objectives->with(['customer', 'status']);
|
2026-03-19 11:21:49 +01:00
|
|
|
$objectives = $this->paginate($objectives);
|
2021-05-17 12:22:53 +02:00
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
return view('bo.objectives.index', compact('objectives', 'filter_tc_id'));
|
2021-05-17 12:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
protected function filterObjectives(Request $request)
|
|
|
|
|
{
|
2021-05-26 11:59:45 +02:00
|
|
|
|
2021-05-17 12:22:53 +02:00
|
|
|
$objectives = Objectives::query();
|
|
|
|
|
|
2021-05-26 11:59:45 +02:00
|
|
|
if ($request->unfilter) {
|
|
|
|
|
Session::remove('objectives.filter_tc_id');
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 12:22:53 +02:00
|
|
|
if ($request->rst) {
|
|
|
|
|
Session::remove('objectives.sort_col');
|
|
|
|
|
Session::remove('objectives.sort_way');
|
|
|
|
|
}
|
|
|
|
|
if ($request->sort_col) {
|
|
|
|
|
Session::put('objectives.sort_col', $request->sort_col);
|
|
|
|
|
Session::save();
|
|
|
|
|
}
|
|
|
|
|
if ($request->sort_way) {
|
|
|
|
|
Session::put('objectives.sort_way', $request->sort_way);
|
|
|
|
|
Session::save();
|
|
|
|
|
}
|
2023-08-21 15:24:32 +02:00
|
|
|
if ($request->filter_tc_id) {
|
2021-05-26 11:59:45 +02:00
|
|
|
Session::put('objectives.filter_tc_id', $request->filter_tc_id);
|
|
|
|
|
Session::save();
|
|
|
|
|
}
|
2021-05-17 12:22:53 +02:00
|
|
|
|
2026-03-19 11:21:49 +01:00
|
|
|
if (Session::has('objectives.sort_col') && Session::has('objectives.sort_way')) {
|
2021-05-17 12:22:53 +02:00
|
|
|
switch (Session::get('objectives.sort_col')) {
|
|
|
|
|
case 'produit':
|
|
|
|
|
$objectives = $objectives->orderBy('produit', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'qualite':
|
|
|
|
|
$objectives = $objectives->orderBy('qualite', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'campagne':
|
|
|
|
|
$objectives = $objectives->orderBy('campagne', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'quantite':
|
|
|
|
|
$objectives = $objectives->orderBy('quantite', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'prix':
|
|
|
|
|
$objectives = $objectives->orderBy('prix', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'echeance':
|
|
|
|
|
$objectives = $objectives->orderBy('echeance', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
case 'status_id':
|
|
|
|
|
$objectives = $objectives->orderBy('status_id', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
2023-08-21 15:24:32 +02:00
|
|
|
case 'customer_id':
|
|
|
|
|
$objectives = $objectives->orderBy('customer_id', Session::get('objectives.sort_way'));
|
2021-05-17 12:22:53 +02:00
|
|
|
break;
|
2021-05-26 11:35:15 +02:00
|
|
|
case 'tc_id':
|
|
|
|
|
$objectives = $objectives->select('objectives.*');
|
2023-08-21 15:24:32 +02:00
|
|
|
$objectives = $objectives->leftJoin('customers', 'customers.id', '=', 'objectives.customer_id');
|
|
|
|
|
$objectives = $objectives->orderBy('customers.tc_id', Session::get('objectives.sort_way'));
|
2021-05-26 11:35:15 +02:00
|
|
|
break;
|
2023-08-21 15:24:32 +02:00
|
|
|
}//end switch
|
2021-05-26 11:59:45 +02:00
|
|
|
|
|
|
|
|
if (Session::has('objectives.filter_tc_id')) {
|
2023-08-21 15:24:32 +02:00
|
|
|
if (
|
|
|
|
|
Session::has('objectives.sort_col')
|
2026-03-19 11:21:49 +01:00
|
|
|
&& Session::has('objectives.sort_way')
|
|
|
|
|
&& Session::get('objectives.sort_col') == 'tc_id'
|
2023-08-21 15:24:32 +02:00
|
|
|
) {
|
|
|
|
|
$objectives = $objectives->where('customers.tc_id', '=', Session::get('objectives.filter_tc_id'));
|
|
|
|
|
} else {
|
|
|
|
|
$objectives = $objectives->select('objectives.*');
|
|
|
|
|
$objectives = $objectives->leftJoin('customers', 'customers.id', '=', 'objectives.customer_id');
|
|
|
|
|
$objectives = $objectives->where('customers.tc_id', '=', Session::get('objectives.filter_tc_id'));
|
|
|
|
|
}
|
2021-05-26 11:59:45 +02:00
|
|
|
}
|
2023-08-21 15:24:32 +02:00
|
|
|
}//end if
|
2021-05-17 12:22:53 +02:00
|
|
|
|
|
|
|
|
return $objectives;
|
2021-03-30 17:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
return view('bo.objectives.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-03-30 17:07:16 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store(Request $request)
|
|
|
|
|
{
|
|
|
|
|
return redirect()->route('bo.objectives.index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the specified resource.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param integer $id
|
2021-03-30 17:07:16 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show($id)
|
|
|
|
|
{
|
2021-05-17 12:22:53 +02:00
|
|
|
$objectif = Objectives::findOrFail($id);
|
2023-08-21 15:24:32 +02:00
|
|
|
$objectif->load(['customer', 'status']);
|
2021-05-17 12:22:53 +02:00
|
|
|
return view('bo.objectives.show', compact('objectif'));
|
2021-03-30 17:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param integer $id
|
2021-03-30 17:07:16 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
return redirect()->route('bo.objectives.index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
2023-08-21 15:24:32 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-03-30 17:07:16 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$deleteOk = 0;
|
|
|
|
|
|
|
|
|
|
if ($request->id !== null) {
|
|
|
|
|
$objectif = Objectives::findOrFail($request->id);
|
2023-08-21 15:24:32 +02:00
|
|
|
if ($objectif->customer_id == Auth::guard('frontend')->user()->id) {
|
2021-03-30 17:07:16 +02:00
|
|
|
$objectif->delete();
|
|
|
|
|
} else {
|
|
|
|
|
$deleteOk = 3;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$deleteOk = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $deleteOk;
|
|
|
|
|
}
|
2021-03-12 14:42:15 +01:00
|
|
|
}
|