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

142 lines
4.8 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.
*/
2024-09-17 16:34:40 +05:45
public function index(Request $request)
2024-09-11 12:32:15 +05:45
{
2024-09-17 16:34:40 +05:45
$filters = $request->all();
2024-09-11 12:32:15 +05:45
$data['title'] = 'Sales Entries';
2024-09-17 16:34:40 +05:45
$data['stockList'] = $this->stockRepository->pluck();
$data['productList'] = $this->productRepository->pluck();
$data['categoryList'] = $this->categoryRepository->pluck();
$data['salesEntries'] = $this->salesEntryRepository->findAll($filters);
2024-09-11 12:32:15 +05:45
return view('salesEntry::salesEntry.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'New Sales Entry';
$data['stockList'] = $this->stockRepository->pluck();
$data['productList'] = $this->productRepository->pluck();
2024-09-17 16:34:40 +05:45
$data['categoryList'] = $this->categoryRepository->pluck();
2024-09-11 12:32:15 +05:45
$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');
2024-09-17 16:34:40 +05:45
$sizes = $this->fieldRepository->getDropdownByAlias('size');
$paymentModes = $this->fieldRepository->getDropdownByAlias('payment-mode');
2024-09-11 12:32:15 +05:45
return response()->json([
2024-09-17 16:34:40 +05:45
'view' => view('salesEntry::salesEntry.clone-product', compact('data', 'numInc', 'script', 'productList', 'categoryList', 'stockList', 'sizes', 'paymentModes'))->render(),
2024-09-11 12:32:15 +05:45
]);
}
}