diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index cff7f589..0729f90b 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -26,7 +26,23 @@ class AdminController extends Controller { Log::saveLog('Affichage du tableau de bord'); - return view('admin.dashboard'); + $futureEvent_to_filtered = \App\Schedule::all()->sortBy('date'); + $futureEvent_to_filtered_pass_1 = collect(); + $futureEvent = collect(); + + foreach ($futureEvent_to_filtered as $day) { + if ($day->date >= date('Y-m-d')) { + $futureEvent_to_filtered_pass_1->push($day); + } + } + + foreach ($futureEvent_to_filtered_pass_1 as $day) { + if ($day->date <= date('Y-m-d',strtotime("+2 week"))) { + $futureEvent->push($day); + } + } + + return view('admin.dashboard',['futureEvent' => $futureEvent,'userClasse' => \Auth::User()->getClasse()->forPage(1,6)]); } public function update() diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 93024b40..957259ff 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -191,9 +191,6 @@ class CalendarController extends Controller ''. ''. ''. - '
'. - "L'activité auras lieux a l'escadron entre 18h30 et 21h30". - '
'. ''.$date->data['event_desc']. '
' ); @@ -445,14 +442,14 @@ class CalendarController extends Controller $schedule->save(); /** Logs and Notification */ - Log::saveLog("Ajout de l'activité, ".$schedule->name." à l'horaire le ".$schedule->date); + Log::saveLog("Ajout de l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date); $userToNotify = $schedule->getUserToNotify(); - \Notification::send($userToNotify, new Alert(\Auth::User()->id,"Ajout de l'activité, ".$schedule->name." à l'horaire le ".$schedule->date,"/admin/calendar")); + \Notification::send($userToNotify, new Alert(\Auth::User()->id,"Ajout de l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date,"/admin/calendar")); if(\App\Config::where('name','is_schedule_build')->first()->state == 1) { - \Notification::send($userToNotify, new mail(\Auth::User(),"Ajout d'une activité a l'horaire",\Auth::User()->fullname()." à ajouté l'activité, ".$schedule->name." à l'horaire le ".$schedule->date)); + \Notification::send($userToNotify, new mail(\Auth::User(),"Ajout d'une activité a l'horaire",\Auth::User()->fullname()." à ajouté l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date)); } return redirect('/admin/calendar'); diff --git a/app/Http/Controllers/ConfigController.php b/app/Http/Controllers/ConfigController.php index 73dc2c2b..03597fc2 100644 --- a/app/Http/Controllers/ConfigController.php +++ b/app/Http/Controllers/ConfigController.php @@ -14,7 +14,7 @@ class ConfigController extends Controller */ public function index() { - // + return view ('admin.configs.general',['configs' => Config::all()]); } /** @@ -67,9 +67,19 @@ class ConfigController extends Controller * @param \App\Config $config * @return \Illuminate\Http\Response */ - public function update(Request $request, Config $config) + public function update() { - // + $config = Config::all()->where('name',request('perm'))->first(); + + if (request('value') == "true") { + $config->state = 1; + } else { + $config->state = 0; + } + + $config->save(); + + \App\Log::saveLog('Modification de la configuration du site'); } /** diff --git a/app/Http/Controllers/ECCController.php b/app/Http/Controllers/ECCController.php index 4b0e298d..f79e408d 100644 --- a/app/Http/Controllers/ECCController.php +++ b/app/Http/Controllers/ECCController.php @@ -247,25 +247,43 @@ class ECCController extends Controller foreach ($items_array as $item_array) { if ($item_array != "") { - $items->push(\App\Item::find($item_array)); + $item_array_ex = explode(":",$item_array); + $this_item = \App\Item::find($item_array_ex[0]); + $this_item->quantity = $item_array_ex[1]; + $items->push($this_item); } } } + return view('ecc.booking',['schedule' => $schedule, 'periode' => $periode, 'niveau' => $niveau, 'items' => $items, 'dispo_item' => $schedule->getInventory($periode)]); } public function booking_add($id,$periode,$niveau) { $schedule = Schedule::find($id); - + $id_to_modify = "passet"; + $qt_to_add = 0; $periode_item = 'n'.$niveau.'_p'.$periode.'_item'; if (isset($schedule->$periode_item)) { $array_items = explode("-",$schedule->$periode_item); - array_push($array_items,request('add')); + for ($i=0; $i < count($array_items); $i++) { + $array_item_id = explode(":",$array_items[$i]); + + if ($array_item_id[0] == request('add')) { + $id_to_modify = $i; + $qt_to_add = $array_item_id[1]; + } + } + if ($id_to_modify === "passet") { + array_push($array_items,request('add').":".request('qt')); + } else { + $toadd = $qt_to_add+request('qt'); + $array_items[$id_to_modify] = request('add').":".$toadd; + } } else { $array_items = []; - array_push($array_items,request('add')); + array_push($array_items,request('add').":".request('qt')); } $final_items = implode("-",$array_items); @@ -273,7 +291,7 @@ class ECCController extends Controller $schedule->$periode_item = $final_items; $schedule->save(); - + return redirect('/ecc/inventory/'.$id.'/'.$niveau.'/'.$periode); } diff --git a/app/Http/Controllers/InventoryController.php b/app/Http/Controllers/InventoryController.php index 6c648870..589c79c0 100644 --- a/app/Http/Controllers/InventoryController.php +++ b/app/Http/Controllers/InventoryController.php @@ -54,15 +54,29 @@ class InventoryController extends Controller public function store($id,$periode,$niveau) { $schedule = Schedule::find($id); - + $id_to_modify = "passet"; + $qt_to_add = 0; $periode_item = 'n'.$niveau.'_p'.$periode.'_item'; if (isset($schedule->$periode_item)) { $array_items = explode("-",$schedule->$periode_item); - array_push($array_items,request('add')); + for ($i=0; $i < count($array_items); $i++) { + $array_item_id = explode(":",$array_items[$i]); + + if ($array_item_id[0] == request('add')) { + $id_to_modify = $i; + $qt_to_add = $array_item_id[1]; + } + } + if ($id_to_modify === "passet") { + array_push($array_items,request('add').":".request('qt')); + } else { + $toadd = $qt_to_add+request('qt'); + $array_items[$id_to_modify] = request('add').":".$toadd; + } } else { $array_items = []; - array_push($array_items,request('add')); + array_push($array_items,request('add').":".request('qt')); } $final_items = implode("-",$array_items); @@ -70,7 +84,7 @@ class InventoryController extends Controller $schedule->$periode_item = $final_items; $schedule->save(); - + return redirect('/admin/inventory/'.$id.'/'.$periode.'/'.$niveau); } @@ -91,10 +105,14 @@ class InventoryController extends Controller foreach ($items_array as $item_array) { if ($item_array != "") { - $items->push(Item::find($item_array)); + $item_array_ex = explode(":",$item_array); + $this_item = Item::find($item_array_ex[0]); + $this_item->quantity = $item_array_ex[1]; + $items->push($this_item); } } } + return view('admin.inventory.show',['schedule' => $schedule, 'periode' => $periode, 'niveau' => $niveau, 'items' => $items, 'dispo_item' => $schedule->getInventory($periode)]); } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 0b14f58e..f7501d01 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -39,6 +39,7 @@ class ItemController extends Controller $item->name = request('name'); $item->desc = request('desc'); + $item->quantiy = request('qt'); $item->save(); @@ -82,6 +83,7 @@ class ItemController extends Controller $item->name = request('name'); $item->desc = request('desc'); + $item->quantity = request('qt'); $item->save(); diff --git a/app/Http/helpers.php b/app/Http/helpers.php new file mode 100644 index 00000000..cf472355 --- /dev/null +++ b/app/Http/helpers.php @@ -0,0 +1,19 @@ +get('https://status.c-cms.cf/api/v1/incidents'); + + $isBroken = false; + + $incidents_decode = json_decode($incidents->getBody(),true); + + foreach ($incidents_decode['data'] as $incident) { + if (!$incident['is_resolved']) { + $isBroken = true; + } + } + + return $isBroken; +} \ No newline at end of file diff --git a/app/Schedule.php b/app/Schedule.php index 28fb64e0..c438722f 100644 --- a/app/Schedule.php +++ b/app/Schedule.php @@ -13,8 +13,10 @@ class Schedule extends Model public function getInventory($periode) { - $dispo = []; - $used = []; + $dispo_id = []; + $dispo_qt = []; + $used_id = []; + $used_qt = []; $dispo_item = collect(); $string_periode = 'p'.$periode; @@ -22,34 +24,72 @@ class Schedule extends Model $inventory = Item::all(); foreach ($inventory as $item) { - array_push($dispo, $item->id); + array_push($dispo_id, $item->id); + array_push($dispo_qt, $item->quantity); } $n1 = 'n1_'.$string_periode.'_item'; $items_array = explode("-",$this->$n1); - - foreach ($items_array as $item_array) { - array_push($used,$item_array); + if ($items_array[0] == "") { + unset($items_array[0]); + } + $items_array = array_values($items_array); + if ($items_array != "") { + foreach ($items_array as $item_array) { + $items_for = explode(":",$item_array); + array_push($used_id,$items_for[0]); + array_push($used_qt,$items_for[1]); + } } $n2 = 'n2_'.$string_periode.'_item'; $items_array = explode("-",$this->$n2); + if ($items_array[0] == "") { + unset($items_array[0]); + } + $items_array = array_values($items_array); - foreach ($items_array as $item_array) { - array_push($used,$item_array); + if ($items_array != "") { + foreach ($items_array as $item_array) { + $items_for = explode(":",$item_array); + array_push($used_id,$items_for[0]); + array_push($used_qt,$items_for[1]); + } } $n3 = 'n3_'.$string_periode.'_item'; $items_array = explode("-",$this->$n3); - - foreach ($items_array as $item_array) { - array_push($used,$item_array); + if ($items_array[0] == "") { + unset($items_array[0]); + } + $items_array = array_values($items_array); + if ($items_array != "") { + foreach ($items_array as $item_array) { + $items_for = explode(":",$item_array); + array_push($used_id,$items_for[0]); + array_push($used_qt,$items_for[1]); + } } - $dispo = array_diff($dispo,$used); - - foreach ($dispo as $key) { - $dispo_item->push(Item::find($key)); + for ($i=0; $i < count($used_id); $i++) { + for ($e=0; $e < count($dispo_id); $e++) { + if (isset($dispo_id[0])) { + if ($used_id[$i] == $dispo_id[$e]) { + $dispo_qt[$e] = $dispo_qt[$e] - $used_qt[$i]; + if ($dispo_qt[$e] < 1) { + unset($dispo_id[$e]); + unset($dispo_qt[$e]); + } + } + } + } + } + $dispo_id = array_values($dispo_id); + $dispo_qt = array_values($dispo_qt); + for ($i=0; $i < count($dispo_id); $i++) { + $this_item = Item::find($dispo_id[$i]); + $this_item->quantity = $dispo_qt[$i]; + $dispo_item->push($this_item); } return $dispo_item; diff --git a/composer.json b/composer.json index bf2e145f..0d801e5b 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ ], "psr-4": { "App\\": "app/" - } + }, + "files": ["app/Http/helpers.php"] }, "autoload-dev": { "psr-4": { diff --git a/database/migrations/2018_09_07_104706_create_items_table.php b/database/migrations/2018_09_07_104706_create_items_table.php index f9cc159f..1e5c5ef3 100644 --- a/database/migrations/2018_09_07_104706_create_items_table.php +++ b/database/migrations/2018_09_07_104706_create_items_table.php @@ -15,6 +15,7 @@ class CreateItemsTable extends Migration { Schema::create('items', function (Blueprint $table) { $table->increments('id'); + $table->integer('quantity'); $table->string('name'); $table->string('desc'); $table->timestamps(); diff --git a/public/assets/js/calendar/calendar.js b/public/assets/js/calendar/calendar.js index ee00ec70..50c6cbb4 100644 --- a/public/assets/js/calendar/calendar.js +++ b/public/assets/js/calendar/calendar.js @@ -98,7 +98,7 @@ function switchType() eventBeginTime.value = "18:30"; eventEndTime.value = "21:45"; eventLocation.value = "Escadron"; - tinymce.get('event_desc').setContent("Lors des soirées d'instruction, les cadets auronts la possibilité de participer par niveau a des activitées en lien avec le programme des cadets, que ce soit des activitées de tir, marche militaire, musique, pilotage, leadership et plus, a tous les coups le plaisir est au rendez-vous."); + tinymce.get('event_desc').setContent("Lors des soirées d'instruction, les cadets auront la possibilité de participer par niveau à des activités en lien avec le programme des cadets, qu'il s'agisse d'activités de tir, de marche militaire, de musique, de pilotage, de leadership et plus, dans une ambiance plaisante."); var n1_p1_plandone = document.getElementById('n1_p1_plandone'); var n1_p2_plandone = document.getElementById('n1_p2_plandone'); diff --git a/resources/views/admin/calendar/calendar_display.blade.php b/resources/views/admin/calendar/calendar_display.blade.php index c3556361..4beddf68 100644 --- a/resources/views/admin/calendar/calendar_display.blade.php +++ b/resources/views/admin/calendar/calendar_display.blade.php @@ -16,11 +16,6 @@ - @if (!\App\Config::find(1)->state) -| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Item | Description | ||
|---|---|---|---|---|---|
| {{$item}} | +@php $quantity = explode(":",$item); @endphp {{$quantity[1]}} | {{\App\Item::find($item)->name}} | {{\App\Item::find($item)->desc}} |
| ID | +Quantité | Nom | Description | @@ -22,7 +22,7 @@ | |
|---|---|---|---|---|---|
| {{$item->id}} | +{{$item->quantity}} | {{$item->name}} | {{$item->desc}} | Modifier | diff --git a/resources/views/admin/inventory/show.blade.php b/resources/views/admin/inventory/show.blade.php index 3eee5940..ffec31bc 100644 --- a/resources/views/admin/inventory/show.blade.php +++ b/resources/views/admin/inventory/show.blade.php @@ -19,6 +19,7 @@|
| Nom | Description | +Quantité | |||
| {{$item->name}} | {{$item->desc}} | -+ | {{$item->quantity}} | +Nom | Description | +Quantité | @foreach ($dispo_item as $item) @if ($item !== null)
| + | {{$item->name}} | {{$item->desc}} | +
| Quantité | Nom | Description | @@ -17,9 +18,10 @@ | ||
|---|---|---|---|---|---|
| {{$item->quantity}} | {{$item->name}} | {{$item->desc}} | -+ | Nom | Description | +Quantité | @foreach ($dispo_item as $item)
| + | {{$item->name}} | {{$item->desc}} | - +