StocksNew/Modules/SalesEntry/app/Http/Controllers/SalesEntryController.php

136 lines
4.3 KiB
PHP
Raw Normal View History

2024-09-11 12:32:15 +05:45
<?php
namespace Modules\SalesEntry\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\FieldInterface;
use Modules\Customer\Repositories\CustomerInterface;
use Modules\Product\Repositories\CategoryInterface;
use Modules\Product\Repositories\ProductInterface;
use Modules\SalesEntry\Models\SalesEntry;
use Modules\SalesEntry\Repositories\SalesEntryInterface;
use Modules\Stock\Repositories\StockInterface;
class SalesEntryController extends Controller
{
private $productRepository;
private $customerRepository;
private $salesEntryRepository;
private $categoryRepository;
private $stockRepository;
private $fieldRepository;
public function __construct( ProductInterface $productRepository,
CustomerInterface $customerRepository,
SalesEntryInterface $salesEntryRepository,
CategoryInterface $categoryRepository,
StockInterface $stockRepository,
FieldInterface $fieldRepository )
{
$this->productRepository = $productRepository;
$this->customerRepository = $customerRepository;
$this->salesEntryRepository = $salesEntryRepository;
$this->categoryRepository = $categoryRepository;
$this->stockRepository = $stockRepository;
$this->fieldRepository = $fieldRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Sales Entries';
$data['salesEntries'] = SalesEntry::all();
return view('salesEntry::salesEntry.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'New Sales Entry';
$data['categoryList'] = $this->categoryRepository->pluck();
$data['stockList'] = $this->stockRepository->pluck();
$data['productList'] = $this->productRepository->pluck();
$data['customerList'] = $this->customerRepository->pluck();
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
$data['editable'] = false;
return view('salesEntry::salesEntry.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$this->salesEntryRepository->create($request);
return redirect()->route('salesEntry.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('salesEntry::salesEntry.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['customerList'] = $this->customerRepository->pluck();
$data['categoryList'] = $this->categoryRepository->pluck();
$data['stockList'] = $this->stockRepository->pluck();
$data['productList'] = $this->productRepository->pluck();
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
$data['order'] = SalesEntry::with('orderDetails')->find($id);
$data['id'] = $id;
$data['editable'] = true;
$data['title'] = "Edit Sales Entry";
return view('salesEntry::salesEntry.edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$this->salesEntryRepository->update($id,$request);
return redirect()->route('salesEntry.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
return $this->salesEntryRepository->delete($id);
}
public function cloneSalesProduct(Request $request)
{
$data = [];
$numInc = $request->numberInc;
$script = true;
$productList= $this->productRepository->pluck('id');
$stockList= $this->stockRepository->pluck('id');
$categoryList= $this->categoryRepository->pluck('id');
return response()->json([
'view' => view('salesEntry::salesEntry.clone-product', compact('data', 'numInc', 'script', 'productList'))->render(),
]);
}
}