71 lines
2.2 KiB
PHP
71 lines
2.2 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;
|
|
|
|
class ObjectivesController extends Controller
|
|
{
|
|
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();
|
|
}
|
|
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,
|
|
]);
|
|
$objectif["id"] = $o->id;
|
|
unset($objectif["user_id"]);
|
|
}
|
|
|
|
return $objectif;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|