first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
namespace Modules\Product\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Product\Models\Category;
use Modules\Product\Repositories\CategoryRepository;
class CategoryController extends Controller
{
private $categoryRepository;
/**
* Display a listing of the resource.
*/
public function __construct(
CategoryRepository $categoryRepository) {
$this->categoryRepository = $categoryRepository;
}
public function index()
{
$data['title'] = 'Categories List';
$data['categories'] = $this->categoryRepository->findAll();
return view('product::category.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Category';
$data['status'] = Category::STATUS;
return view('product::category.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->categoryRepository->create($inputData);
toastr()->success('Category Created Succesfully');
return redirect()->route('category.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Category';
$data['status'] = Category::STATUS;
$data['category'] = $this->categoryRepository->getCategoryById($id);
return view('product::category.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Category';
$data['status'] = Category::STATUS;
$data['category'] = $this->categoryRepository->getCategoryById($id);
return view('product::category.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->categoryRepository->update($id, $inputData);
return redirect()->route('category.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$CategoryModel = $this->categoryRepository->getCategoryById($id);
$CategoryModel->delete();
toastr()->success('Product Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Category Delete Succesfully']);
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace Modules\Product\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Product\Models\Product;
use Modules\Product\Repositories\CategoryRepository;
use Modules\Product\Repositories\ProductInterface;
use Modules\Product\Repositories\ProductRepository;
use Modules\Product\Repositories\SubCategoryRepository;
use Modules\Product\Repositories\WarehouseRepository;
use Modules\Supplier\Models\Supplier;
use Modules\Supplier\Repositories\SupplierRepository;
class ProductController extends Controller
{
private $productRepository;
private $categoryRepository;
private $subCategoryRepository;
private $warehouseRepository;
private $supplierRepository;
/**
* Display a listing of the resource.
*/
public function __construct(ProductRepository $productRepository,
CategoryRepository $categoryRepository,
SubCategoryRepository $subCategoryRepository,
SupplierRepository $supplierRepository,
WarehouseRepository $warehouseRepository)
{
$this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
$this->subCategoryRepository = $subCategoryRepository;
$this->supplierRepository = $supplierRepository;
$this->warehouseRepository = $warehouseRepository;
}
public function index()
{
$data['title'] = "Product Lists";
$data['products'] = $this->productRepository->findAll();
return view('product::product.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Product';
$data['category'] = $this->categoryRepository->pluck();
$data['subCategory'] = $this->subCategoryRepository->pluck();
$data['supplier'] = $this->supplierRepository->pluck();
$data['warehouse'] = $this->warehouseRepository->pluck();
$data['status'] = Product::STATUS;
return view('product::product.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
$this->productRepository->create($inputData);
toastr()->success('Product Created Succesfully');
return redirect()->route('product.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Product';
$data['product'] = $this->productRepository->getProductById($id);
$data['status'] = Product::STATUS;
return view('product::product.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Show Product';
$data['category'] = $this->categoryRepository->pluck();
$data['subCategory'] = $this->subCategoryRepository->pluck();
$data['supplier'] = $this->supplierRepository->pluck();
$data['warehouse'] = $this->warehouseRepository->pluck();
$data['product'] = $this->productRepository->getProductById($id);
$data['status'] = Product::STATUS;
return view('product::product.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->productRepository->update($id, $inputData);
return redirect()->route('product.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$ProductModel = $this->productRepository->getProductById($id);
$ProductModel->delete();
toastr()->success('Product Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Product Delete Succesfully']);
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace Modules\Product\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Product\Models\SubCategory;
use Modules\Product\Repositories\CategoryRepository;
use Modules\Product\Repositories\SubCategoryRepository;
class SubCategoryController extends Controller
{
private $subCategoryRepository;
private $categoryRepository;
/**
* Display a listing of the resource.
*/
public function __construct(
SubCategoryRepository $subCategoryRepository,
CategoryRepository $categoryRepository)
{
$this->subCategoryRepository = $subCategoryRepository;
$this->categoryRepository = $categoryRepository;
}
public function index()
{
$data['title'] = 'Sub Categories List';
$data['sub_categories'] = $this->subCategoryRepository->findAll();
return view('product::sub_category.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Sub Categories';
$data['status'] = SubCategory::STATUS;
$data['category'] = $this->categoryRepository->pluck();
return view('product::sub_category.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->subCategoryRepository->create($inputData);
toastr()->success('Category Created Succesfully');
return redirect()->route('subCategory.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Category';
$data['status'] = SubCategory::STATUS;
$data['sub_category'] = $this->subCategoryRepository->getSubCategoryById($id);
return view('product::sub_category.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Category';
$data['status'] = SubCategory::STATUS;
$data['category'] = $this->categoryRepository->pluck();
$data['sub_category'] = $this->subCategoryRepository->getSubCategoryById($id);
return view('product::sub_category.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->subCategoryRepository->update($id, $inputData);
return redirect()->route('subCategory.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$SubCategoryModel = $this->subCategoryRepository->getSubCategoryById($id);
$SubCategoryModel->delete();
toastr()->success('Sub Category Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Sub Category Delete Succesfully']);
}
public function getSubCategories(Request $request)
{
$category_id = $request->category_id;
$subcategories = SubCategory::where('category_id',$category_id)->get();
return response()->json(['status'=>200, 'message'=>$subcategories]);
}
}

View File

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

View File

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

View File

@@ -0,0 +1,36 @@
<?php
namespace Modules\Product\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
use Modules\Supplier\Models\Supplier;
class Product extends Model
{
USE StatusTrait;
protected $table = 'tbl_products';
protected $guarded = [];
protected $appends = ['status_name'];
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
public function subCategory()
{
return $this->belongsTo(SubCategory::class, 'sub_category_id');
}
public function warehouse()
{
return $this->belongsTo(Warehouse::class, 'warehouse_id');
}
public function supplier()
{
return $this->belongsTo(Supplier::class, 'supplier_id');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Modules\Product\Models;
use Illuminate\Database\Eloquent\Model;
class ProductStock extends Model
{
protected $table = 'tbl_product_stocks';
protected $guarded = [];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Product\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
class SubCategory extends Model
{
USE StatusTrait;
protected $table = 'tbl_sub_categories';
protected $guarded = [];
protected $appends = ['status_name'];
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
}

View File

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

View File

View File

View File

@@ -0,0 +1,117 @@
<?php
namespace Modules\Product\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Product\Repositories\ProductInterface;
use Modules\Product\Repositories\ProductRepository;
class ProductServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Product';
protected string $moduleNameLower = 'product';
/**
* 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->bind(ProductInterface::class,ProductRepository::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.
*/
public function provides(): array
{
return [];
}
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\Product\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('Product', '/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('Product', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Product\Repositories;
interface CategoryInterface
{
public function findAll();
public function getCategoryById($CategoryId);
public function getCategoryByEmail($email);
public function delete($CategoryId);
public function create($CategoryDetails);
public function update($CategoryId, array $newDetails);
public function pluck();
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Product\Repositories;
use Modules\Product\Models\Category;
class CategoryRepository implements CategoryInterface
{
public function findAll()
{
return Category::when(true, function ($query) {
})->paginate(20);
}
public function getCategoryById($CategoryId)
{
return Category::findOrFail($CategoryId);
}
public function getCategoryByEmail($email)
{
return Category::where('email', $email)->first();
}
public function delete($CategoryId)
{
Category::destroy($CategoryId);
}
public function create($CategoryDetails)
{
return Category::create($CategoryDetails);
}
public function update($CategoryId, array $newDetails)
{
return Category::whereId($CategoryId)->update($newDetails);
}
public function pluck()
{
return Category::pluck('title', 'id');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Product\Repositories;
interface ProductInterface
{
public function findAll();
public function getProductById($ProductId);
public function getProductByEmail($email);
public function delete($ProductId);
public function create($ProductDetails);
public function update($ProductId, array $newDetails);
public function pluck();
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Product\Repositories;
use Modules\Product\Models\Product;
class ProductRepository implements ProductInterface
{
public function findAll()
{
return Product::when(true, function ($query) {
})->paginate(20);
}
public function getProductById($ProductId)
{
return Product::findOrFail($ProductId);
}
public function getProductByEmail($email)
{
return Product::where('email', $email)->first();
}
public function delete($ProductId)
{
Product::destroy($ProductId);
}
public function create($ProductDetails)
{
return Product::create($ProductDetails);
}
public function update($ProductId, array $newDetails)
{
return Product::whereId($ProductId)->update($newDetails);
}
public function pluck()
{
return Product::pluck('name', 'id');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Product\Repositories;
interface SubCategoryInterface
{
public function findAll();
public function getSubCategoryById($SubCategoryId);
public function getSubCategoryByEmail($email);
public function delete($SubCategoryId);
public function create($SubCategoryDetails);
public function update($SubCategoryId, array $newDetails);
public function pluck();
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Product\Repositories;
use Modules\Product\Models\SubCategory;
class SubCategoryRepository implements SubCategoryInterface
{
public function findAll()
{
return SubCategory::when(true, function ($query) {
})->paginate(20);
}
public function getSubCategoryById($SubCategoryId)
{
return SubCategory::findOrFail($SubCategoryId);
}
public function getSubCategoryByEmail($email)
{
return SubCategory::where('email', $email)->first();
}
public function delete($SubCategoryId)
{
SubCategory::destroy($SubCategoryId);
}
public function create($SubCategoryDetails)
{
return SubCategory::create($SubCategoryDetails);
}
public function update($SubCategoryId, array $newDetails)
{
return SubCategory::whereId($SubCategoryId)->update($newDetails);
}
public function pluck()
{
return SubCategory::pluck('title', 'id');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Product\Repositories;
interface WarehouseInterface
{
public function findAll();
public function getWarehouseById($WarehouseId);
public function getWarehouseByEmail($email);
public function delete($WarehouseId);
public function create($WarehouseDetails);
public function update($WarehouseId, array $newDetails);
public function pluck();
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Product\Repositories;
use Modules\Product\Models\Warehouse;
class WarehouseRepository implements WarehouseInterface
{
public function findAll()
{
return Warehouse::when(true, function ($query) {
})->paginate(20);
}
public function getWarehouseById($WarehouseId)
{
return Warehouse::findOrFail($WarehouseId);
}
public function getWarehouseByEmail($email)
{
return Warehouse::where('email', $email)->first();
}
public function delete($WarehouseId)
{
Warehouse::destroy($WarehouseId);
}
public function create($WarehouseDetails)
{
return Warehouse::create($WarehouseDetails);
}
public function update($WarehouseId, array $newDetails)
{
return Warehouse::whereId($WarehouseId)->update($newDetails);
}
public function pluck()
{
return Warehouse::pluck('title', 'id');
}
}