mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 10:49:10 -04:00
ALPHA 3.0.3
This commit is contained in:
154
app/Http/Controllers/InventoryController.php
Normal file
154
app/Http/Controllers/InventoryController.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Item;
|
||||
use App\Schedule;
|
||||
|
||||
class InventoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$items = Item::all();
|
||||
|
||||
return view('admin.inventory.index',[ 'items' => $items]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function booking()
|
||||
{
|
||||
$items = Item::all();
|
||||
$schedules = Schedule::all()->where('type','regular')->sortBy('date');
|
||||
|
||||
$filtered = collect();
|
||||
|
||||
foreach ($schedules as $day) {
|
||||
if ($day->date >= date('Y-m-d')) {
|
||||
$filtered->push($day);
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin.inventory.booking',[ 'items' => $items, 'schedules' => $filtered]);
|
||||
}
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store($id,$periode,$niveau)
|
||||
{
|
||||
$schedule = Schedule::find($id);
|
||||
|
||||
$periode_item = 'n'.$niveau.'_p'.$periode.'_item';
|
||||
|
||||
if (isset($schedule->$periode_item)) {
|
||||
$array_items = explode("-",$schedule->$periode_item);
|
||||
array_push($array_items,request('add'));
|
||||
} else {
|
||||
$array_items = [];
|
||||
array_push($array_items,request('add'));
|
||||
}
|
||||
|
||||
$final_items = implode("-",$array_items);
|
||||
|
||||
$schedule->$periode_item = $final_items;
|
||||
|
||||
$schedule->save();
|
||||
|
||||
return redirect('/admin/inventory/'.$id.'/'.$periode.'/'.$niveau);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id,$periode,$niveau)
|
||||
{
|
||||
$schedule = Schedule::find($id);
|
||||
|
||||
$periode_item = 'n'.$niveau.'_p'.$periode.'_item';
|
||||
$items = collect();
|
||||
if (isset($schedule->$periode_item)) {
|
||||
$items_array = explode("-",$schedule->$periode_item);
|
||||
|
||||
foreach ($items_array as $item_array) {
|
||||
if ($item_array != "") {
|
||||
$items->push(Item::find($item_array));
|
||||
}
|
||||
}
|
||||
}
|
||||
return view('admin.inventory.show',['schedule' => $schedule, 'periode' => $periode, 'niveau' => $niveau, 'items' => $items, 'dispo_item' => $schedule->getInventory($periode)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if (!isset($schedule->data[$periode])) {
|
||||
dd('Null');
|
||||
} else {
|
||||
dd($schedule->data[$periode]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id,$periode,$niveau)
|
||||
{
|
||||
$schedule = Schedule::find($id);
|
||||
$remove = [request('remove')];
|
||||
$periode_item = 'n'.$niveau.'_p'.$periode.'_item';
|
||||
|
||||
if (isset($schedule->$periode_item)) {
|
||||
$array_items = explode("-",$schedule->$periode_item);
|
||||
$array_items = array_diff($array_items,$remove);
|
||||
} else {
|
||||
$array_items = [];
|
||||
$array_items = array_diff($array_items,$remove);
|
||||
}
|
||||
|
||||
$final_items = implode("-",$array_items);
|
||||
$schedule->$periode_item = $final_items;
|
||||
$schedule->save();
|
||||
|
||||
return redirect('/admin/inventory/'.$id.'/'.$periode.'/'.$niveau);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user