- Add status checker + admin secure packages + upgrade enum + add sentry + upgrade to sitemap generator + bump to CRMV2 - Set customer role enum and user role enum - Update customer migration to set roles - phpcbf - faker local to fr - update lang - composer update - bump laravel ui - Redo all user crud - npm bump - Create admin command - rearrange views - redo all auth system - redo customer pro bo
176 lines
5.8 KiB
PHP
176 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Objectives;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class ObjectivesController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$filter_tc_id = $request->query('filter_tc_id');
|
|
|
|
$objectives = $this->filterObjectives($request);
|
|
|
|
$objectives->with(['customer', 'status']);
|
|
$objectives = $objectives->paginate(10);
|
|
|
|
return view('bo.objectives.index', compact('objectives', 'filter_tc_id'));
|
|
}
|
|
|
|
protected function filterObjectives(Request $request)
|
|
{
|
|
|
|
$objectives = Objectives::query();
|
|
|
|
if ($request->unfilter) {
|
|
Session::remove('objectives.filter_tc_id');
|
|
}
|
|
|
|
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();
|
|
}
|
|
if ($request->filter_tc_id) {
|
|
Session::put('objectives.filter_tc_id', $request->filter_tc_id);
|
|
Session::save();
|
|
}
|
|
|
|
if (Session::has('objectives.sort_col') and Session::has('objectives.sort_way')) {
|
|
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;
|
|
case 'customer_id':
|
|
$objectives = $objectives->orderBy('customer_id', Session::get('objectives.sort_way'));
|
|
break;
|
|
case 'tc_id':
|
|
$objectives = $objectives->select('objectives.*');
|
|
$objectives = $objectives->leftJoin('customers', 'customers.id', '=', 'objectives.customer_id');
|
|
$objectives = $objectives->orderBy('customers.tc_id', Session::get('objectives.sort_way'));
|
|
break;
|
|
}//end switch
|
|
|
|
if (Session::has('objectives.filter_tc_id')) {
|
|
if (
|
|
Session::has('objectives.sort_col')
|
|
and Session::has('objectives.sort_way')
|
|
and Session::get('objectives.sort_col') == 'tc_id'
|
|
) {
|
|
$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'));
|
|
}
|
|
}
|
|
}//end if
|
|
|
|
return $objectives;
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
return redirect()->route('bo.objectives.index');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param integer $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$objectif = Objectives::findOrFail($id);
|
|
$objectif->load(['customer', 'status']);
|
|
return view('bo.objectives.show', compact('objectif'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param integer $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
return redirect()->route('bo.objectives.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Request $request)
|
|
{
|
|
$deleteOk = 0;
|
|
|
|
if ($request->id !== null) {
|
|
$objectif = Objectives::findOrFail($request->id);
|
|
if ($objectif->customer_id == Auth::guard('frontend')->user()->id) {
|
|
$objectif->delete();
|
|
} else {
|
|
$deleteOk = 3;
|
|
}
|
|
} else {
|
|
$deleteOk = 2;
|
|
}
|
|
|
|
return $deleteOk;
|
|
}
|
|
}
|