restaurant changes

This commit is contained in:
Sampanna Rimal
2024-09-19 18:33:08 +05:45
parent 0b438e302d
commit 2fa9d47a73
115 changed files with 3489 additions and 67 deletions

View File

@ -0,0 +1,105 @@
<?php
namespace Modules\Ingredient\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Ingredient\Models\IngredientCategory;
use Modules\Ingredient\Repositories\IngredientCategoryRepository;
class IngredientCategoryController extends Controller
{
private $ingredientCategoryRepository;
/**
* Display a listing of the resource.
*/
public function __construct(
IngredientCategoryRepository $ingredientCategoryRepository) {
$this->ingredientCategoryRepository = $ingredientCategoryRepository;
}
public function index()
{
$data['title'] = 'Categories List';
$data['categories'] = $this->ingredientCategoryRepository->findAll();
return view('ingredient::ingredientCategory.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create IngredientCategory';
$data['status'] = IngredientCategory::STATUS;
return view('ingredient::ingredientCategory.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$request->request->add(['slug' => slugify($request->title)]);
$inputData = $request->all();
$this->ingredientCategoryRepository->create($inputData);
toastr()->success('IngredientCategory Created Succesfully');
return redirect()->route('ingredientCategory.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show IngredientCategory';
$data['status'] = IngredientCategory::STATUS;
$data['category'] = $this->ingredientCategoryRepository->getIngredientCategoryById($id);
return view('ingredient::ingredientCategory.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit IngredientCategory';
$data['status'] = IngredientCategory::STATUS;
$data['category'] = $this->ingredientCategoryRepository->getIngredientCategoryById($id);
return view('ingredient::ingredientCategory.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->ingredientCategoryRepository->update($id, $inputData);
return redirect()->route('ingredientCategory.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$IngredientCategoryModel = $this->ingredientCategoryRepository->getIngredientCategoryById($id);
$IngredientCategoryModel->delete();
toastr()->success('Ingredient Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'IngredientCategory Delete Succesfully']);
}
}

View File

@ -0,0 +1,152 @@
<?php
namespace Modules\Ingredient\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Ingredient\Models\Unit;
use Modules\Ingredient\Models\Ingredient;
use Modules\Ingredient\Repositories\IngredientCategoryRepository;
use Modules\Ingredient\Repositories\UnitRepository;
use Modules\Ingredient\Repositories\IngredientInterface;
use Modules\Ingredient\Repositories\IngredientRepository;
use Modules\Supplier\Models\Supplier;
use Modules\Supplier\Repositories\SupplierRepository;
class IngredientController extends Controller
{
private $ingredientRepository;
private $ingredientCategoryRepository;
private $unitRepository;
private $supplierRepository;
/**
* Display a listing of the resource.
*/
public function __construct(IngredientRepository $ingredientRepository,
IngredientCategoryRepository $ingredientCategoryRepository,
SupplierRepository $supplierRepository,
UnitRepository $unitRepository)
{
$this->ingredientRepository = $ingredientRepository;
$this->ingredientCategoryRepository = $ingredientCategoryRepository;
$this->unitRepository = $unitRepository;
$this->supplierRepository = $supplierRepository;
}
public function index()
{
$data['title'] = "Ingredient Lists";
$data['ingredients'] = $this->ingredientRepository->findAll();
return view('ingredient::ingredient.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Ingredient';
$data['ingredientCategory'] = $this->ingredientCategoryRepository->pluck();
$data['unit'] = $this->unitRepository->pluck();
$data['supplier'] = $this->supplierRepository->pluck();
$data['status'] = Ingredient::STATUS;
return view('ingredient::ingredient.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
$this->ingredientRepository->create($inputData);
toastr()->success('Ingredient Created Succesfully');
return redirect()->route('ingredient.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Ingredient';
$data['ingredient'] = $this->ingredientRepository->getIngredientById($id);
$data['status'] = Ingredient::STATUS;
return view('ingredient::ingredient.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Show Ingredient';
$data['ingredientCategory'] = $this->ingredientCategoryRepository->pluck();
$data['unit'] = $this->unitRepository->pluck();
$data['supplier'] = $this->supplierRepository->pluck();
$data['ingredient'] = $this->ingredientRepository->getIngredientById($id);
$data['status'] = Ingredient::STATUS;
return view('ingredient::ingredient.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->ingredientRepository->update($id, $inputData);
return redirect()->route('ingredient.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$IngredientModel = $this->ingredientRepository->getIngredientById($id);
$IngredientModel->delete();
toastr()->success('Ingredient Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Ingredient Delete Succesfully']);
}
public function getIngredientDetail(Request $request)
{
try {
$ingredientModel = $this->ingredientRepository->getIngredientById($request->id);
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json([
'status' => true,
'data' => $ingredientModel,
]);
}
public function getIngredientsByCategory(Request $request)
{
$ingredientCategoryId = $request->ingredient_category_id;
try {
$ingredients = $this->ingredientRepository->getIngredientsByCategory($ingredientCategoryId);
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['ingredients' => $ingredients]);
}
}

View File

@ -0,0 +1,111 @@
<?php
namespace Modules\Ingredient\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Ingredient\Models\Unit;
use Modules\Ingredient\Repositories\UnitRepository;
class UnitController extends Controller
{
private $unitRepository;
/**
* Display a listing of the resource.
*/
public function __construct(
UnitRepository $unitRepository)
{
$this->unitRepository = $unitRepository;
}
public function index()
{
$data['title'] = 'Unit List';
$data['units'] = $this->unitRepository->findAll();
return view('ingredient::unit.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Unit';
$data['status'] = Unit::STATUS;
return view('ingredient::unit.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$request->request->add(['slug' => slugify($request->title)]);
$inputData = $request->all();
$this->unitRepository->create($inputData);
toastr()->success('Unit Created Succesfully');
return redirect()->route('unit.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Fabric Category';
$data['status'] = Unit::STATUS;
$data['unit'] = $this->unitRepository->getUnitById($id);
return view('ingredient::unit.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Fabric Category';
$data['status'] = Unit::STATUS;
$data['unit'] = $this->unitRepository->getUnitById($id);
return view('ingredient::unit.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->unitRepository->update($id, $inputData);
return redirect()->route('unit.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$UnitModel = $this->unitRepository->getUnitById($id);
$UnitModel->delete();
toastr()->success('Fabric Category Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Fabric Category Delete Succesfully']);
}
}

View File

View File

@ -0,0 +1,33 @@
<?php
namespace Modules\Ingredient\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
use Modules\Supplier\Models\Supplier;
class Ingredient extends Model
{
USE StatusTrait;
protected $table = 'tbl_ingredients';
protected $guarded = [];
protected $appends = ['status_name'];
public function category()
{
return $this->belongsTo(IngredientCategory::class, 'ingredient_category_id');
}
public function unit()
{
return $this->belongsTo(Unit::class, 'unit_id');
}
public function supplier()
{
return $this->belongsTo(Supplier::class, 'supplier_id');
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Modules\Ingredient\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
class IngredientCategory extends Model
{
USE StatusTrait;
protected $table = 'tbl_ingredient_categories';
protected $guarded = [];
protected $appends = ['status_name'];
}

View File

@ -0,0 +1,16 @@
<?php
namespace Modules\Ingredient\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model
{
USE StatusTrait;
protected $table = 'tbl_units';
protected $guarded = [];
protected $appends = ['status_name'];
}

View File

@ -0,0 +1,32 @@
<?php
namespace Modules\Ingredient\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*
* @return void
*/
protected function configureEmailVerification(): void
{
}
}

View File

@ -0,0 +1,120 @@
<?php
namespace Modules\Ingredient\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class IngredientServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Ingredient';
protected string $moduleNameLower = 'ingredient';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*
* @return array<string>
*/
public function provides(): array
{
return [];
}
/**
* @return array<string>
*/
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
}
}
return $paths;
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Modules\Ingredient\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path('Ingredient', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Ingredient', '/routes/api.php'));
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Ingredient\Repositories;
interface IngredientCategoryInterface
{
public function findAll();
public function getIngredientCategoryById($IngredientCategoryId);
public function getIngredientCategoryByEmail($email);
public function delete($IngredientCategoryId);
public function create($IngredientCategoryDetails);
public function update($IngredientCategoryId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,46 @@
<?php
namespace Modules\Ingredient\Repositories;
use Modules\Ingredient\Models\IngredientCategory;
class IngredientCategoryRepository implements IngredientCategoryInterface
{
public function findAll()
{
return IngredientCategory::when(true, function ($query) {
})->paginate(20);
}
public function getIngredientCategoryById($IngredientCategoryId)
{
return IngredientCategory::findOrFail($IngredientCategoryId);
}
public function getIngredientCategoryByEmail($email)
{
return IngredientCategory::where('email', $email)->first();
}
public function delete($IngredientCategoryId)
{
IngredientCategory::destroy($IngredientCategoryId);
}
public function create($IngredientCategoryDetails)
{
return IngredientCategory::create($IngredientCategoryDetails);
}
public function update($IngredientCategoryId, array $newDetails)
{
return IngredientCategory::whereId($IngredientCategoryId)->update($newDetails);
}
public function pluck()
{
return IngredientCategory::pluck('title', 'id');
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Modules\Ingredient\Repositories;
interface IngredientInterface
{
public function findAll();
public function getIngredientById($IngredientId);
public function getIngredientByEmail($email);
public function getIngredientsByCategory($categoryId);
public function delete($IngredientId);
public function create($IngredientDetails);
public function update($IngredientId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,52 @@
<?php
namespace Modules\Ingredient\Repositories;
use Modules\Ingredient\Models\Ingredient;
class IngredientRepository implements IngredientInterface
{
public function findAll()
{
return Ingredient::when(true, function ($query) {
})->paginate(20);
}
public function getIngredientById($IngredientId)
{
return Ingredient::findOrFail($IngredientId);
}
public function getIngredientByEmail($email)
{
return Ingredient::where('email', $email)->first();
}
public function getIngredientsByCategory($ingredientCategoryId)
{
return Ingredient::where('ingredient_category_id', $ingredientCategoryId)->pluck('name', 'id');
}
public function delete($IngredientId)
{
Ingredient::destroy($IngredientId);
}
public function create($IngredientDetails)
{
return Ingredient::create($IngredientDetails);
}
public function update($IngredientId, array $newDetails)
{
return Ingredient::whereId($IngredientId)->update($newDetails);
}
public function pluck()
{
return Ingredient::pluck('name', 'id');
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Ingredient\Repositories;
interface UnitInterface
{
public function findAll();
public function getUnitById($UnitId);
public function getUnitByEmail($email);
public function delete($UnitId);
public function create($UnitDetails);
public function update($UnitId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,46 @@
<?php
namespace Modules\Ingredient\Repositories;
use Modules\Ingredient\Models\Unit;
class UnitRepository implements UnitInterface
{
public function findAll()
{
return Unit::when(true, function ($query) {
})->paginate(20);
}
public function getUnitById($UnitId)
{
return Unit::findOrFail($UnitId);
}
public function getUnitByEmail($email)
{
return Unit::where('email', $email)->first();
}
public function delete($UnitId)
{
Unit::destroy($UnitId);
}
public function create($UnitDetails)
{
return Unit::create($UnitDetails);
}
public function update($UnitId, array $newDetails)
{
return Unit::whereId($UnitId)->update($newDetails);
}
public function pluck()
{
return Unit::pluck('title', 'id');
}
}