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)
|
|
|
|
|
{
|
2021-05-17 12:22:53 +02:00
|
|
|
$objectives = $this->filterObjectives($request);
|
|
|
|
|
|
|
|
|
|
$objectives = $objectives->paginate(10);
|
|
|
|
|
|
|
|
|
|
return view('bo.objectives.index', compact('objectives'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function filterObjectives(Request $request) {
|
|
|
|
|
$objectives = Objectives::query();
|
|
|
|
|
|
|
|
|
|
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 (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 'user_id':
|
|
|
|
|
$objectives = $objectives->orderBy('user_id', Session::get('objectives.sort_way'));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @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 int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show($id)
|
|
|
|
|
{
|
2021-05-17 12:22:53 +02:00
|
|
|
$objectif = Objectives::findOrFail($id);
|
|
|
|
|
return view('bo.objectives.show', compact('objectif'));
|
2021-03-30 17:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
|
|
|
|
return view('bo.objectives.edit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param int $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->user_id == Auth::user()->id) {
|
|
|
|
|
$objectif->delete();
|
|
|
|
|
} else {
|
|
|
|
|
$deleteOk = 3;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$deleteOk = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $deleteOk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource or update an existing one
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return array $objectif
|
|
|
|
|
*/
|
2021-03-12 14:42:15 +01:00
|
|
|
public function saveProDatas(Request $request) {
|
|
|
|
|
//save data from Pro dashboard
|
|
|
|
|
$objectif = $request->objectif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($objectif["id"])) {
|
|
|
|
|
$o = Objectives::findOrFail($objectif["id"]);
|
|
|
|
|
$o->produit = $objectif["produit"];
|
|
|
|
|
$o->qualite = $objectif["qualite"];
|
|
|
|
|
$o->quantite = $objectif["quantite"];
|
|
|
|
|
$o->campagne = $objectif["campagne"];
|
|
|
|
|
$o->prix = $objectif["prix"];
|
|
|
|
|
$o->echeance = $objectif["echeance"];
|
|
|
|
|
$o->volume_restant = $objectif["volume_restant"];
|
|
|
|
|
$o->observations = $objectif["observations"];
|
|
|
|
|
$o->save();
|
2021-04-01 16:06:19 +02:00
|
|
|
$objectif["status_id"] = $o->status_id;
|
|
|
|
|
$objectif["status"] = $o->status;
|
2021-03-12 14:42:15 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$o = Objectives::updateOrCreate([
|
|
|
|
|
'produit' => $objectif["produit"],
|
|
|
|
|
'qualite' => $objectif["qualite"],
|
|
|
|
|
'quantite' => $objectif["quantite"],
|
|
|
|
|
'campagne' => $objectif["campagne"],
|
|
|
|
|
'prix' => $objectif["prix"],
|
|
|
|
|
'echeance' => $objectif["echeance"],
|
|
|
|
|
'volume_restant' => $objectif["volume_restant"],
|
|
|
|
|
'observations' => $objectif["observations"],
|
|
|
|
|
'user_id' => Auth::user()->id,
|
2021-04-01 16:06:19 +02:00
|
|
|
'status_id' => 1,
|
2021-03-12 14:42:15 +01:00
|
|
|
]);
|
|
|
|
|
$objectif["id"] = $o->id;
|
2021-04-01 16:06:19 +02:00
|
|
|
$objectif["status_id"] = $o->status_id;
|
|
|
|
|
$objectif["status"] = $o->status;
|
2021-03-12 14:42:15 +01:00
|
|
|
unset($objectif["user_id"]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 16:06:19 +02:00
|
|
|
|
|
|
|
|
|
2021-03-12 14:42:15 +01:00
|
|
|
return $objectif;
|
|
|
|
|
}
|
|
|
|
|
}
|