From 4eea725335fb7eea90f5538adc736e8e32a93cfb Mon Sep 17 00:00:00 2001 From: Olivier Legat Date: Wed, 21 Apr 2021 11:55:51 +0200 Subject: [PATCH] ajout champ TVA dans le BO --- .../Controllers/Bo/ProductsController.php | 167 +++++++++--------- resources/views/bo/products/create.blade.php | 13 ++ resources/views/bo/products/edit.blade.php | 13 ++ 3 files changed, 112 insertions(+), 81 deletions(-) diff --git a/app/Http/Controllers/Bo/ProductsController.php b/app/Http/Controllers/Bo/ProductsController.php index 27e9a2f2..b9866d8c 100644 --- a/app/Http/Controllers/Bo/ProductsController.php +++ b/app/Http/Controllers/Bo/ProductsController.php @@ -8,6 +8,7 @@ use App\Models\FoodProduct; use App\Models\Product; use App\Models\Range; use App\Models\Tag; +use App\Models\TaxRate; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -21,12 +22,12 @@ class ProductsController extends Controller $ranges = Range::all(); $filter_range = $request->query('filter_range'); - $filter_name = $request->query('filter_name'); + $filter_name = $request->query('filter_name'); $products = new Product(); if (!empty($filter_name)) { - $products = $products->where('name', 'like', '%'.$filter_name.'%'); + $products = $products->where('name', 'like', '%' . $filter_name . '%'); } if (!empty($filter_range)) { $products = $products->where('range_id', $filter_range); @@ -35,17 +36,17 @@ class ProductsController extends Controller //ici récupération des infos additionnelles pour affichage dans la liste // @todo : parametrer l'occurence de ces affichages car ça n'aura aucun sens selon le type de produit - foreach($products as &$product) { + foreach ($products as &$product) { $product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type); if ($product->additionnalProductInfo === null) { //n'existe pas on renseigne un vide - $product_type = $product->product_type; - $modelClass = 'App\Models\\' . ucfirst($product_type); + $product_type = $product->product_type; + $modelClass = 'App\Models\\' . ucfirst($product_type); $product->$product_type = new $modelClass(); } } unset($product); - return view('bo.products.index', compact('products','ranges','filter_name','filter_range')); + return view('bo.products.index', compact('products', 'ranges', 'filter_name', 'filter_range')); } /** @@ -57,11 +58,12 @@ class ProductsController extends Controller abort(404, "Cette page n'existe pas."); //return redirect()->route('bo.products.index'); } - $modelClass = 'App\Models\\' . ucfirst($product_type); - $product = new Product(); + $modelClass = 'App\Models\\' . ucfirst($product_type); + $product = new Product(); $product->$product_type = new $modelClass(); - $ranges = Range::all(); - return view('bo.products.create', compact('product_type', 'product', 'ranges')); + $ranges = Range::all(); + $taxes = TaxRate::all(); + return view('bo.products.create', compact('product_type', 'product', 'ranges', 'taxes')); } /** @@ -72,21 +74,22 @@ class ProductsController extends Controller public function store(Request $request) { //products fields - $name = $request->name; - $description = $request->description; - $picture = $request->picture; + $name = $request->name; + $description = $request->description; + $picture = $request->picture; $picture_large = $request->picture_large; - $price = $request->price; - $priceBuy = $request->price_buy; - $stock = $request->stock; - $reference = $request->reference; - $sell_unit = $request->sell_unit; - $weight = $request->weight; - $weight_unit = $request->weight_unit; - $status = $request->status === null ? 0 : 1; - $star = $request->star === null ? 0 : 1; - $slug = Str::slug($name); - $rangeId = $request->range_id; + $price = $request->price; + $priceBuy = $request->price_buy; + $stock = $request->stock; + $reference = $request->reference; + $sell_unit = $request->sell_unit; + $weight = $request->weight; + $weight_unit = $request->weight_unit; + $status = $request->status === null ? 0 : 1; + $star = $request->star === null ? 0 : 1; + $slug = Str::slug($name); + $rangeId = $request->range_id; + $taxRateId = $request->tax_rate_id; $request->validate([ 'name' => 'required|string|max:255', @@ -110,20 +113,21 @@ class ProductsController extends Controller "\" éxiste déjà. Veuillez changer le nom du produit."); } - $product = new Product(); - $product->name = $name; + $product = new Product(); + $product->name = $name; $product->description = $description; - $product->price = $price; - $product->price_buy = $priceBuy; - $product->stock = $stock; - $product->reference = $reference; - $product->sell_unit = $sell_unit; - $product->weight = $weight; + $product->price = $price; + $product->price_buy = $priceBuy; + $product->stock = $stock; + $product->reference = $reference; + $product->sell_unit = $sell_unit; + $product->weight = $weight; $product->weight_unit = $weight_unit; - $product->slug = $slug; - $product->status = $status; - $product->star = $star; - $product->range_id = $rangeId; + $product->slug = $slug; + $product->status = $status; + $product->star = $star; + $product->range_id = $rangeId; + $product->tax_rate_id = $taxRateId; $product->save(); // Check si le slug existe dans la table old_slugs, auquel cas il est attribué a ce nouveau produit @@ -173,20 +177,21 @@ class ProductsController extends Controller */ public function edit($id) { - $product = Product::findOrFail($id); + $product = Product::findOrFail($id); $product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type); //above lines equivalent to : //$product = Product::with('additionnalProductInfo')->findOrFail($id); if ($product->additionnalProductInfo === null) { //n'existe pas on renseigne un vide - $product_type = $product->product_type; - $modelClass = 'App\Models\\' . ucfirst($product_type); + $product_type = $product->product_type; + $modelClass = 'App\Models\\' . ucfirst($product_type); $product->$product_type = new $modelClass(); } - $ranges = Range::all(); + $ranges = Range::all(); + $taxes = TaxRate::all(); $existingTags = Tag::all(); $selectedtags = $product->tags; @@ -194,7 +199,7 @@ class ProductsController extends Controller $selectedProds = $product->products; $existingProds = $existingProds->diff($selectedProds); - return view('bo.products.edit', compact('product', 'ranges','existingTags', 'selectedtags', 'existingProds', 'selectedProds')); + return view('bo.products.edit', compact('product', 'ranges', 'taxes', 'existingTags', 'selectedtags', 'existingProds', 'selectedProds')); } /** @@ -206,22 +211,23 @@ class ProductsController extends Controller $product = Product::findOrFail($id); - $name = $request->name; - $description = $request->description; - $picture = $request->picture; + $name = $request->name; + $description = $request->description; + $picture = $request->picture; $picture_large = $request->picture_large; - $price = $request->price; - $priceBuy = $request->price_buy; - $stock = $request->stock; - $reference = $request->reference; - $sell_unit = $request->sell_unit; - $weight = $request->weight; - $weight_unit = $request->weight_unit; - $status = $request->status === null ? 0 : 1; - $star = $request->star === null ? 0 : 1; - $slug = Str::slug($name); - $rangeId = $request->range_id; - $tags = $request->tags; + $price = $request->price; + $priceBuy = $request->price_buy; + $stock = $request->stock; + $reference = $request->reference; + $sell_unit = $request->sell_unit; + $weight = $request->weight; + $weight_unit = $request->weight_unit; + $status = $request->status === null ? 0 : 1; + $star = $request->star === null ? 0 : 1; + $slug = Str::slug($name); + $rangeId = $request->range_id; + $taxRateId = $request->tax_rate_id; + $tags = $request->tags; $request->validate([ 'name' => 'required|string|max:255', @@ -274,25 +280,26 @@ class ProductsController extends Controller if ($product->slug != $slug) { $exist = OldSlug::where('slug', $product->slug)->first(); if ($exist === null) { - $oldSlug = new OldSlug(); + $oldSlug = new OldSlug(); $oldSlug->product_id = $product->id; - $oldSlug->slug = $product->slug; + $oldSlug->slug = $product->slug; $oldSlug->save(); } } $product->description = $description; - $product->price = $price; - $product->price_buy = $priceBuy; - $product->stock = $stock; - $product->reference = $reference; - $product->sell_unit = $sell_unit; - $product->weight = $weight; + $product->price = $price; + $product->price_buy = $priceBuy; + $product->stock = $stock; + $product->reference = $reference; + $product->sell_unit = $sell_unit; + $product->weight = $weight; $product->weight_unit = $weight_unit; - $product->slug = $slug; - $product->status = $status; - $product->star = $star; - $product->range_id = $rangeId; + $product->slug = $slug; + $product->status = $status; + $product->star = $star; + $product->range_id = $rangeId; + $product->tax_rate_id = $taxRateId; $product->save(); // Check si le slug existe dans la table old_slug, auquel cas il est attribué a ce nouveau produit @@ -311,11 +318,11 @@ class ProductsController extends Controller } //tags associés - if(!empty($tags)) { + if (!empty($tags)) { $arTagIds = array(); - foreach($tags as $tag) { + foreach ($tags as $tag) { $oTag = json_decode($tag); - if(empty($oTag->id)) { + if (empty($oTag->id)) { //we need a new tag $arTagIds[] = $this->storeTag($oTag); } else { @@ -327,7 +334,7 @@ class ProductsController extends Controller } //produits associés - if(!empty($request->prods)) { + if (!empty($request->prods)) { $productIds = explode(",", $request->prods); //prise en charge de la liaison avec les produits $product->products()->sync($productIds); @@ -343,12 +350,12 @@ class ProductsController extends Controller public function storeTag($oTag) { $slug = Str::slug($oTag->label); - $tag = Tag::where('slug', $slug)->first(); - if($tag === null) { + $tag = Tag::where('slug', $slug)->first(); + if ($tag === null) { //si on pas encore ce tag on le crée - $tag = new Tag(); + $tag = new Tag(); $tag->label = $oTag->label; - $tag->slug = Str::slug($oTag->label); + $tag->slug = Str::slug($oTag->label); $tag->save(); } return $tag->id; @@ -385,8 +392,8 @@ class ProductsController extends Controller 'product_id' => $product_id, ]); - if(!empty($request->no_art)) { - $foodProduct->no_art = $request->no_art; + if (!empty($request->no_art)) { + $foodProduct->no_art = $request->no_art; } $foodProduct->ingredients = $request->ingredients; $foodProduct->preparation = $request->preparation; @@ -428,7 +435,6 @@ class ProductsController extends Controller $foodProduct->save(); - } /** @@ -481,7 +487,6 @@ class ProductsController extends Controller $foodProduct->save(); - } /** @@ -497,7 +502,7 @@ class ProductsController extends Controller */ public function starred() { - $products = Product::where('star',1)->paginate(10); + $products = Product::where('star', 1)->paginate(10); return view('bo.products.starred', compact('products')); } } diff --git a/resources/views/bo/products/create.blade.php b/resources/views/bo/products/create.blade.php index 9299c587..227cc4df 100644 --- a/resources/views/bo/products/create.blade.php +++ b/resources/views/bo/products/create.blade.php @@ -43,6 +43,17 @@ +
+ + +
+
+ +
@@ -51,6 +62,8 @@
+
+
diff --git a/resources/views/bo/products/edit.blade.php b/resources/views/bo/products/edit.blade.php index 74aef500..338bc3e0 100644 --- a/resources/views/bo/products/edit.blade.php +++ b/resources/views/bo/products/edit.blade.php @@ -67,6 +67,17 @@
+
+ + +
+
+
+
@@ -75,6 +86,8 @@
+
+