This commit is contained in:
Sampanna Rimal
2024-09-11 12:32:15 +05:45
parent 82fab174dc
commit afb2c202d6
170 changed files with 3352 additions and 363 deletions

View File

@ -0,0 +1,97 @@
<?php
namespace Modules\Stock\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Product\Repositories\ProductRepository;
use Modules\Stock\Models\Stock;
use Modules\Stock\Repositories\StockLocationRepository;
use Modules\Stock\Repositories\StockRepository;
class StockController extends Controller
{
private $stockRepository;
private $productRepository;
private $stockLocationRepository;
public function __construct(StockRepository $stockRepository,
StockLocationRepository $stockLocationRepository,
ProductRepository $productRepository)
{
$this->stockRepository = $stockRepository;
$this->productRepository = $productRepository;
$this->stockLocationRepository = $stockLocationRepository;
}
public function index()
{
$data['title'] = 'Stocks List';
$data['stocks'] = $this->stockRepository->findAll();
return view('stock::stock.index', $data);
}
public function create()
{
$data['title'] = 'Create Stock';
$data['stockLocation'] = $this->stockLocationRepository->pluck();
$data['product'] = $this->productRepository->pluck();
$data['status'] = Stock::STATUS;
return view('stock::stock.create', $data);
}
public function store(Request $request): RedirectResponse
{
$request->request->add(['slug' => slugify($request->title)]);
$inputData = $request->all();
$this->stockRepository->create($inputData);
toastr()->success('Stock Created Successfully');
return redirect()->route('stock.index');
}
public function show($id)
{
$data['title'] = 'Show Stock';
$data['status'] = Stock::STATUS;
$data['stock'] = $this->stockRepository->getStockById($id);
return view('stock::stock.show', $data);
}
public function edit($id)
{
$data['title'] = 'Edit Stock';
$data['stockLocation'] = $this->stockLocationRepository->pluck();
$data['product'] = $this->productRepository->pluck();
$data['status'] = Stock::STATUS;
$data['stock'] = $this->stockRepository->getStockById($id);
return view('stock::stock.edit', $data);
}
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->stockRepository->update($id, $inputData);
return redirect()->route('stock.index');
}
public function destroy($id)
{
try {
$stock = $this->stockRepository->getStockById($id);
$stock->delete();
toastr()->success('Stock Deleted Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Stock Deleted Successfully']);
}
}

View File

@ -0,0 +1,84 @@
<?php
namespace Modules\Stock\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Stock\Models\StockLocation;
use Modules\Stock\Repositories\StockLocationRepository;
class StockLocationController extends Controller
{
private $stockLocationRepository;
public function __construct(StockLocationRepository $stockLocationRepository)
{
$this->stockLocationRepository = $stockLocationRepository;
}
public function index()
{
$data['title'] = 'Stocks List';
$data['stockLocations'] = $this->stockLocationRepository->findAll();
return view('stock::stockLocation.index', $data);
}
public function create()
{
$data['title'] = 'Create StockLocation';
$data['status'] = StockLocation::STATUS;
return view('stock::stockLocation.create', $data);
}
public function store(Request $request): RedirectResponse
{
$request->request->add(['slug' => slugify($request->title)]);
$inputData = $request->all();
$this->stockLocationRepository->create($inputData);
toastr()->success('StockLocation Created Successfully');
return redirect()->route('stockLocation.index');
}
public function show($id)
{
$data['title'] = 'Show StockLocation';
$data['status'] = StockLocation::STATUS;
$data['stockLocation'] = $this->stockLocationRepository->getStockLocationById($id);
return view('stock::stockLocation.show', $data);
}
public function edit($id)
{
$data['title'] = 'Edit StockLocation';
$data['status'] = StockLocation::STATUS;
$data['stockLocation'] = $this->stockLocationRepository->getStockLocationById($id);
return view('stock::stockLocation.edit', $data);
}
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->stockLocationRepository->update($id, $inputData);
return redirect()->route('stockLocation.index');
}
public function destroy($id)
{
try {
$stock = $this->stockLocationRepository->getStockLocationById($id);
$stock->delete();
toastr()->success('Stock Location Deleted Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Stock Location Deleted Successfully']);
}
}

View File

View File

View File

@ -0,0 +1,27 @@
<?php
namespace Modules\Stock\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Model;
use Modules\Product\Models\Product;
class Stock extends Model
{
use StatusTrait;
protected $table = 'tbl_stocks';
protected $guarded = [];
protected $appends = ['status_name'];
public function stockLocation()
{
return $this->belongsTo(StockLocation::class, 'stocklocation_id');
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
}

View File

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

View File

View File

View File

@ -0,0 +1,32 @@
<?php
namespace Modules\Stock\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,49 @@
<?php
namespace Modules\Stock\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('Stock', '/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('Stock', '/routes/api.php'));
}
}

View File

@ -0,0 +1,123 @@
<?php
namespace Modules\Stock\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Stock\Repositories\StockInterface;
use Modules\Stock\Repositories\StockRepository;
class StockServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Stock';
protected string $moduleNameLower = 'stock';
/**
* 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);
$this->app->bind(StockInterface::class, StockRepository::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

View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Stock\Repositories;
interface StockInterface
{
public function findAll();
public function getStockById($StockId);
public function getStockByEmail($email);
public function delete($StockId);
public function create($StockDetails);
public function update($StockId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,15 @@
<?php
namespace Modules\Stock\Repositories;
interface StockLocationInterface
{
public function findAll();
public function getStockLocationById($StockLocationId);
public function getStockLocationByEmail($email);
public function delete($StockLocationId);
public function create($StockLocationDetails);
public function update($StockLocationId, array $newDetails);
public function pluck();
}

View File

@ -0,0 +1,46 @@
<?php
namespace Modules\Stock\Repositories;
use Modules\Stock\Models\StockLocation;
class StockLocationRepository implements StockLocationInterface
{
public function findAll()
{
return StockLocation::when(true, function ($query) {
})->paginate(20);
}
public function getStockLocationById($StockLocationId)
{
return StockLocation::findOrFail($StockLocationId);
}
public function getStockLocationByEmail($email)
{
return StockLocation::where('email', $email)->first();
}
public function delete($StockLocationId)
{
StockLocation::destroy($StockLocationId);
}
public function create($StockLocationDetails)
{
return StockLocation::create($StockLocationDetails);
}
public function update($StockLocationId, array $newDetails)
{
return StockLocation::whereId($StockLocationId)->update($newDetails);
}
public function pluck()
{
return StockLocation::pluck('title', 'id');
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Modules\Stock\Repositories;
use Modules\Stock\Models\Stock;
class StockRepository implements StockInterface
{
public function findAll()
{
return Stock::when(true, function ($query) {
})->paginate(20);
}
public function getStockById($StockId)
{
return Stock::findOrFail($StockId);
}
public function getStockByEmail($email)
{
return Stock::where('email', $email)->first();
}
public function delete($StockId)
{
Stock::destroy($StockId);
}
public function create($StockDetails)
{
return Stock::create($StockDetails);
}
public function update($StockId, array $newDetails)
{
return Stock::whereId($StockId)->update($newDetails);
}
public function pluck()
{
return Stock::pluck('title', 'id');
}
}