changes
This commit is contained in:
0
Modules/Stock/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Stock/app/Http/Controllers/.gitkeep
Normal file
97
Modules/Stock/app/Http/Controllers/StockController.php
Normal file
97
Modules/Stock/app/Http/Controllers/StockController.php
Normal 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']);
|
||||
}
|
||||
}
|
@ -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']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user