-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Jimbow-cl/Dev1
Last commit MVP
- Loading branch information
Showing
31 changed files
with
4,361 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\User; | ||
use App\Models\Voucher; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class AdminController extends Controller | ||
{ | ||
public function displayUser() | ||
{ | ||
$find = User::find(Auth::user()->id); | ||
//Verification que l'admin est bien admin | ||
|
||
if ($find->role === "admin") { | ||
$user = User::select('id', 'firstname', 'lastname', 'voucher','role', 'active')->get(); | ||
return response()->json([ | ||
'success' => true, | ||
'user' => $user | ||
]); | ||
} else { | ||
return response()->json([ | ||
'status' => 'unauthorized' | ||
]); | ||
} | ||
} | ||
public function roleUser(Request $request) | ||
{ | ||
$admin = User::find(Auth::user()->id); | ||
$user = User::where('id', $request->id)->first(); | ||
//Verification que l'admin est bien admin et que le user existe | ||
if ($admin->role === "admin" && $user != null) { | ||
// vérification du rôle donné | ||
switch ($request->role) { | ||
case ('user'): | ||
// Vérification si une carte de réduction existait déja | ||
$voucher = Voucher::where('user_id', $user->id)->first(); | ||
if ($voucher != null) { | ||
$user->voucher = $voucher->value; | ||
|
||
} else { | ||
$user->voucher = null; | ||
} | ||
$user->role = "user"; | ||
$user->save(); | ||
break; | ||
|
||
case ('traincrew'): | ||
$voucher = Voucher::where('user_id', $user->id)->first(); | ||
if ($voucher != null) { | ||
$voucher->value = 100; | ||
$user->voucher = 100; | ||
} | ||
// Vérification si une carte de réduction existait déja | ||
else { | ||
$voucher = new Voucher(); | ||
$voucher->user_id = $user->id; | ||
$voucher->value = 100; | ||
$voucher->save(); | ||
} | ||
|
||
$user->role = "traincrew"; | ||
$user->save(); | ||
|
||
break; | ||
case ('admin'): | ||
$user->role = "admin"; | ||
$user->save(); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return response()->json([]); | ||
} else { | ||
return response()->json([ | ||
'status' => 'unauthorized' | ||
]); | ||
} | ||
} | ||
public function activate(Request $request) | ||
{ | ||
$admin = User::find(Auth::user()->id); | ||
$user = User::where('id', $request->id)->first(); | ||
//Verification que l'admin est bien admin et que le user existe | ||
if ($admin->role === "admin" && $user != null) { | ||
$user->active = !$user->active; | ||
$user->save(); | ||
|
||
return response()->json([]); | ||
} else { | ||
return response()->json([ | ||
'status' => 'unauthorized' | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Order; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class FineController extends Controller | ||
{ | ||
public function create(Request $request) | ||
{ | ||
$user_id = Auth::id(); | ||
$order = Order::where('user_id', $user_id)->where('paiement_id', $request->paiement_id)->first(); | ||
Log::info($order); | ||
$order->status = "PAYED"; | ||
$order->paiement_confirmation_id = $request->paiement_confirmation_id; | ||
$order->save(); | ||
return (response()->json([ | ||
'success' => true, | ||
]) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Voucher; | ||
use GuzzleHttp\Client; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class GareController extends Controller | ||
{ | ||
//Appel de l'Api fourni par la SNCF | ||
|
||
public function appelGare() | ||
{ | ||
$client = new Client([ | ||
'verify' => storage_path('cacert.pem'), | ||
]); | ||
|
||
$response = $client->get('https://ressources.data.sncf.com/api/records/1.0/search/?dataset=liste-des-gares&q=&rows=49&facet=libelle&facet=voyageurs&facet=code_ligne&refine.departemen=ALPES-MARITIMES'); | ||
// Décodage du Json en objet PHP | ||
$jsonData = json_decode($response->getBody()); | ||
|
||
$gares = []; | ||
|
||
foreach ($jsonData->records as $record) { | ||
$gare = $record->fields->libelle; | ||
$codeUic = $record->fields->code_uic; | ||
$codeLigne = $record->fields->code_ligne; | ||
$pk = explode('+', $record->fields->pk)[0]; | ||
|
||
$gares[] = [ | ||
'gare' => $gare, | ||
'code_uic' => $codeUic, | ||
'code_ligne' => $codeLigne, | ||
'point_km' => $pk | ||
]; | ||
} | ||
// Usort, Outil de comparaison. Je retourne le tableau par ordre alphabétique | ||
//strcmp (string Comparaison) entre les deux variables | ||
usort($gares, function ($a, $b) { | ||
return strcmp($a['gare'], $b['gare']); | ||
}); | ||
|
||
return response()->json($gares); | ||
} | ||
|
||
public function calculPrix(Request $request) | ||
{ | ||
if ($request->query('passenger') == null) { | ||
$passenger=1; | ||
}; | ||
// utilisation des Query Params à la place des Pass Params | ||
|
||
$start = $request->query('start'); | ||
$end = $request->query('end'); | ||
$passenger= $request->query('passenger'); | ||
$date = $request->query('date'); | ||
$voucher = 0; | ||
$user_id = Auth::id(); | ||
if ($user_id != null) { | ||
$voucher = Voucher::where('user_id', $user_id)->first(); | ||
// Verification si il existe une Réduction à l'utilisateur: | ||
if ($voucher == null) { | ||
$voucher = 0; | ||
} else { | ||
$voucher = $voucher->value; | ||
} | ||
} | ||
|
||
|
||
$response = $this->appelGare(); // Appel de la fonction appelGare | ||
$stations = json_decode($response->getContent(), true); | ||
|
||
$startStation = null; | ||
$endStation = null; | ||
|
||
// Parcourir le tableau des gares pour trouver les gares correspondantes | ||
foreach ($stations as $station) { | ||
if ($station['code_uic'] === $start) { | ||
$startStation = $station; | ||
// 4 Lignes existes,calcule du Pk pour enlever le nombre de km de départ pour le prix | ||
if ($startStation['code_ligne'] === "930000") { | ||
$startRef = $startStation['point_km'] - 184; | ||
} | ||
if ($startStation['code_ligne'] === "944000") { | ||
$startRef = $startStation['point_km'] - 2; | ||
} | ||
if ($startStation['code_ligne'] === "945000") { | ||
$startRef = $startStation['point_km'] - 9; | ||
} | ||
if ($startStation['code_ligne'] === "946000") { | ||
$startRef = $startStation['point_km'] - 37; | ||
} | ||
} | ||
if ($station['code_uic'] === $end) { | ||
$endStation = $station; | ||
// 4 Lignes existes,calcule du Pk pour enlever le nombre de km de départ pour le prix | ||
if ($endStation['code_ligne'] === "930000") { | ||
$endRef = $endStation['point_km'] - 184; | ||
} | ||
if ($endStation['code_ligne'] === "944000") { | ||
$endRef = $endStation['point_km'] - 2; | ||
} | ||
if ($endStation['code_ligne'] === "945000") { | ||
$endRef = $endStation['point_km'] - 9; | ||
} | ||
if ($endStation['code_ligne'] === "946000") { | ||
$endRef = $endStation['point_km'] - 37; | ||
} | ||
} | ||
} | ||
$differenceKm = abs($endRef - $startRef); | ||
$priceKm = 0.2; | ||
$totalPriceBfVoucher = $differenceKm * $priceKm; | ||
|
||
// Calcul du montant de réduction | ||
if ($voucher != 0) { | ||
$priceVoucher = $totalPriceBfVoucher * $voucher / 100; | ||
} else { | ||
$priceVoucher = 0; | ||
} | ||
|
||
// Calcul du prix total après réduction et ajout des passagers | ||
$totalPrice = ($totalPriceBfVoucher * $passenger) - $priceVoucher; | ||
$totalbf = ($totalPriceBfVoucher * $passenger); | ||
// je préviens juste au cas où le prix est inférieur, d'un minimum de 0€ | ||
if ($totalPrice < 0) { | ||
$totalPrice = 0; | ||
} | ||
$totalPrice = round($totalPrice, 2); | ||
|
||
//Calcul de la première classe | ||
$prix1st = $totalPrice * 1.4; | ||
$prix1st = round($prix1st, 2); | ||
|
||
//Calcul de la troisieme classe | ||
$pri3xrd = $totalPrice * 0.8; | ||
$pri3xrd = round($pri3xrd, 2); | ||
|
||
//Calcul du prix total Premiere | ||
$totalbf1 = $totalbf * 1.4; | ||
$totalbf1 = round($totalbf1, 2); | ||
|
||
//Calcul du prix total Seconde | ||
$totalbf2 = $totalbf; | ||
$totalbf2 = round($totalbf2, 2); | ||
|
||
//Calcul du prix total Troisieme | ||
$totalbf3 = $totalbf * 0.8; | ||
$totalbf3 = round($totalbf3, 2); | ||
//Calcul des reductions | ||
$priceVoucherthree = round(($priceVoucher * 0.8), 2); | ||
$priceVouchertwo = round($priceVoucher, 2); | ||
$priceVoucherone = round(($priceVoucher * 1.4), 2); | ||
return response()->json([ | ||
'depart' => $startStation['gare'], | ||
'arrivee' => $endStation['gare'], | ||
'date' => $date, | ||
'passager' => $passenger, | ||
'discountone' => $priceVoucherone, | ||
'discounttwo' => $priceVouchertwo, | ||
'discountthree' => $priceVoucherthree, | ||
'totalbfone' => $totalbf1, | ||
'totalbftwo' => $totalbf2, | ||
'totalbfthree' => $totalbf3, | ||
'prix1st' => $prix1st, | ||
'prix2nd' => $totalPrice, | ||
'prix3rd' => $pri3xrd, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Order; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class OrderController extends Controller | ||
{ | ||
|
||
// Affichage des Reçu de l'utilisateur | ||
public function read() | ||
{ | ||
$user_id = Auth::id(); | ||
$order = Order::where('user_id', $user_id)->get(); | ||
|
||
return (response()->json([ | ||
'ticket' => $order | ||
])); | ||
} | ||
} |
Oops, something went wrong.