From d01bf2fca72c87802c78c00375731aa729be2ce6 Mon Sep 17 00:00:00 2001 From: Mathieu Lagace Date: Wed, 28 Aug 2019 12:57:51 -0400 Subject: [PATCH 1/3] Add ItemCategory form --- app/Http/Controllers/InventoryController.php | 5 + .../Controllers/ItemCategoryController.php | 69 +++++++++-- app/Item.php | 18 +++ .../views/admin/inventory/index.blade.php | 9 +- .../admin/inventory/management.blade.php | 42 +++++++ resources/views/admin/item/add.blade.php | 88 +++++++------- .../views/admin/itemcategory/add.blade.php | 64 ++++++++++ .../views/admin/itemcategory/edit.blade.php | 64 ++++++++++ .../views/admin/itemcategory/index.blade.php | 113 ++++++++++++++++++ .../views/layouts/admin/sidebar.blade.php | 10 +- routes/api.php | 3 + routes/web.php | 16 ++- 12 files changed, 437 insertions(+), 64 deletions(-) create mode 100644 resources/views/admin/inventory/management.blade.php create mode 100644 resources/views/admin/itemcategory/add.blade.php create mode 100644 resources/views/admin/itemcategory/edit.blade.php create mode 100644 resources/views/admin/itemcategory/index.blade.php diff --git a/app/Http/Controllers/InventoryController.php b/app/Http/Controllers/InventoryController.php index 589c79c0..6d8f348a 100644 --- a/app/Http/Controllers/InventoryController.php +++ b/app/Http/Controllers/InventoryController.php @@ -29,6 +29,11 @@ class InventoryController extends Controller { // } + + public function management() + { + return view('admin.inventory.management'); + } public function booking() { diff --git a/app/Http/Controllers/ItemCategoryController.php b/app/Http/Controllers/ItemCategoryController.php index 72cd6ae8..29d7daaa 100644 --- a/app/Http/Controllers/ItemCategoryController.php +++ b/app/Http/Controllers/ItemCategoryController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Item; use App\ItemCategory; use Illuminate\Http\Request; @@ -14,7 +15,7 @@ class ItemCategoryController extends Controller */ public function index() { - // + return view('admin.itemcategory.index',['categories' => ItemCategory::all()]); } /** @@ -24,7 +25,7 @@ class ItemCategoryController extends Controller */ public function create() { - // + return view('admin.itemcategory.add'); } /** @@ -33,9 +34,32 @@ class ItemCategoryController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ - public function store(Request $request) + public function store() { - // + $c = new ItemCategory(); + + $c->name = \request('name'); + $c->desc = \request('desc'); + if (\request('is_training') == 1) + { + $c->is_training = 1; + } + else + { + $c->is_training = 0; + } + if (\request('is_op_appro') == 1) + { + $c->is_op_appro = 1; + } + else + { + $c->is_op_appro = 0; + } + + $c->save(); + + return redirect('/admin/inventory/management/category/')->with('success','Catégorie ajouté avec succès'); } /** @@ -55,9 +79,9 @@ class ItemCategoryController extends Controller * @param \App\ItemCategory $itemCategory * @return \Illuminate\Http\Response */ - public function edit(ItemCategory $itemCategory) + public function edit($id) { - // + return view('admin.itemcategory.edit',['category' => ItemCategory::find($id)]); } /** @@ -67,9 +91,32 @@ class ItemCategoryController extends Controller * @param \App\ItemCategory $itemCategory * @return \Illuminate\Http\Response */ - public function update(Request $request, ItemCategory $itemCategory) + public function update($id) { - // + $c = ItemCategory::find($id); + + $c->name = \request('name'); + $c->desc = \request('desc'); + if (\request('is_training') == 1) + { + $c->is_training = 1; + } + else + { + $c->is_training = 0; + } + if (\request('is_op_appro') == 1) + { + $c->is_op_appro = 1; + } + else + { + $c->is_op_appro = 0; + } + + $c->save(); + + return redirect('/admin/inventory/management/category/')->with('success','Catégorie modifié avec succès'); } /** @@ -78,8 +125,10 @@ class ItemCategoryController extends Controller * @param \App\ItemCategory $itemCategory * @return \Illuminate\Http\Response */ - public function destroy(ItemCategory $itemCategory) + public function destroy($id) { - // + $c = ItemCategory::find($id); + + $c->delete(); } } diff --git a/app/Item.php b/app/Item.php index 8637119e..00041aa0 100644 --- a/app/Item.php +++ b/app/Item.php @@ -31,4 +31,22 @@ class Item extends Model { return \App\ItemCategory::find($this->category_id); } + + public function available() + { + + return $this->quantity - $this->booked(); + } + + public function booked() + { + $nbBooked = 0; + + foreach ($this->bookings() as $b) + { + $nbBooked = $nbBooked + $b->amount; + } + + return $nbBooked; + } } diff --git a/resources/views/admin/inventory/index.blade.php b/resources/views/admin/inventory/index.blade.php index d0a74f31..b89ec947 100644 --- a/resources/views/admin/inventory/index.blade.php +++ b/resources/views/admin/inventory/index.blade.php @@ -8,7 +8,10 @@
- Ajouter un item a l'inventaire +
@@ -16,6 +19,8 @@ + + @@ -26,6 +31,8 @@ + +
# Nom CategorieQuantité TotalQuantité Disponible Description Action
{{$item->official_number}} {{$item->name}} {{$item->category()->name}}{{$item->quantity}}{{$item->available()}} {!! $item->desc !!}
diff --git a/resources/views/admin/inventory/management.blade.php b/resources/views/admin/inventory/management.blade.php new file mode 100644 index 00000000..2c60fa9b --- /dev/null +++ b/resources/views/admin/inventory/management.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.admin.main') + +@section('content') +
+
+
+ Gestion de l'inventaire + +
+
+
+
+
+
+

Catégorie

+

Gestion des catégories de l'inventaire

+
+
+
+
+

+ Les catégories permettent de diviser l'inventaire et de définir les permissions d'accès aux items +

+
+ +
+
+
+
+
+
+
+
+@endsection + +@section('custom_scripts') + +@endsection diff --git a/resources/views/admin/item/add.blade.php b/resources/views/admin/item/add.blade.php index 95e09843..a4b045d2 100644 --- a/resources/views/admin/item/add.blade.php +++ b/resources/views/admin/item/add.blade.php @@ -9,52 +9,52 @@
- @csrf -
-
-
- - + @csrf +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ +
+
+
+
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- -
- -
-
-
- -
-
diff --git a/resources/views/admin/itemcategory/add.blade.php b/resources/views/admin/itemcategory/add.blade.php new file mode 100644 index 00000000..e4aba9cc --- /dev/null +++ b/resources/views/admin/itemcategory/add.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin.main') + +@section('content') +
+
+
+ Ajouter une catégorie + +
+
+
+ @csrf +
+
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+
+@endsection + +@section('custom_scripts') + +@endsection diff --git a/resources/views/admin/itemcategory/edit.blade.php b/resources/views/admin/itemcategory/edit.blade.php new file mode 100644 index 00000000..a73e7513 --- /dev/null +++ b/resources/views/admin/itemcategory/edit.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin.main') + +@section('content') +
+
+
+ Modifier une catégorie + +
+
+
+ @csrf +
+
+
+ + +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+
+@endsection + +@section('custom_scripts') + +@endsection diff --git a/resources/views/admin/itemcategory/index.blade.php b/resources/views/admin/itemcategory/index.blade.php new file mode 100644 index 00000000..cb6f1f4d --- /dev/null +++ b/resources/views/admin/itemcategory/index.blade.php @@ -0,0 +1,113 @@ +@extends('layouts.admin.main') + +@section('content') +
+
+
+ Gestion de l'inventaire + +
+
+
+ +
+ + + + + + + + + + + + + @foreach ($categories as $category) + + + + + + + + + @endforeach + + +
IDNomDescriptionDisponible pour l'instructionRéservé a l'officer d'approvisionnementAction
{{$category->id}}{{$category->name}}{!! $category->desc !!} + @if($category->is_training == 1) + + @else + + @endif + + @if($category->is_op_appro == 1) + + @else + + @endif + +
+   Modifier + +
+
+
+
+
+
+
+@endsection + +@section('custom_scripts') + + +@endsection diff --git a/resources/views/layouts/admin/sidebar.blade.php b/resources/views/layouts/admin/sidebar.blade.php index b9461abe..906773aa 100644 --- a/resources/views/layouts/admin/sidebar.blade.php +++ b/resources/views/layouts/admin/sidebar.blade.php @@ -81,13 +81,13 @@ - -
- - - - - -
- Outils -
- - - +
\ No newline at end of file diff --git a/resources/views/layouts/public/activity.blade.php b/resources/views/layouts/public/activity.blade.php index 50b02097..2259a34a 100644 --- a/resources/views/layouts/public/activity.blade.php +++ b/resources/views/layouts/public/activity.blade.php @@ -2,12 +2,12 @@ @foreach ($activities as $activity)
-
- +
+

{{$activity->name}}

-

{{$activity->public_body}}

+

{!! $activity->public_body !!}

Plus d'information
diff --git a/resources/views/layouts/public/news.blade.php b/resources/views/layouts/public/news.blade.php index ef5a56dc..0668188f 100644 --- a/resources/views/layouts/public/news.blade.php +++ b/resources/views/layouts/public/news.blade.php @@ -10,7 +10,7 @@ @foreach ($news as $new)

{{ $new->title }}

-

{{ $new->body }}

+
{!! $new->body !!}
{{ \App\User::find($new->user_id)->fullname()}}, {{$new->created_at}} Voir plus!
diff --git a/resources/views/public/activity.blade.php b/resources/views/public/activity.blade.php index 7c29d148..2d1f3a42 100644 --- a/resources/views/public/activity.blade.php +++ b/resources/views/public/activity.blade.php @@ -1,7 +1,7 @@ @extends('layouts.public.main') @section('content') -