164 lines
6.2 KiB
PHP
164 lines
6.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Modules\PurchaseEntry\Http\Controllers;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Modules\Admin\Repositories\FieldInterface;
|
||
|
use Modules\Supplier\Repositories\SupplierInterface;
|
||
|
use Modules\Ingredient\Repositories\IngredientCategoryInterface;
|
||
|
use Modules\Ingredient\Repositories\IngredientInterface;
|
||
|
use Modules\Ingredient\Repositories\UnitInterface;
|
||
|
use Modules\PurchaseEntry\Models\PurchaseEntry;
|
||
|
use Modules\PurchaseEntry\Repositories\PurchaseEntryInterface;
|
||
|
use Modules\Stock\Repositories\StockInterface;
|
||
|
|
||
|
class PurchaseEntryController extends Controller
|
||
|
{
|
||
|
|
||
|
private $ingredientRepository;
|
||
|
private $supplierRepository;
|
||
|
private $purchaseEntryRepository;
|
||
|
private $ingredientCategoryRepository;
|
||
|
private $stockRepository;
|
||
|
private $unitRepository;
|
||
|
private $fieldRepository;
|
||
|
|
||
|
public function __construct( IngredientInterface $ingredientRepository,
|
||
|
SupplierInterface $supplierRepository,
|
||
|
PurchaseEntryInterface $purchaseEntryRepository,
|
||
|
IngredientCategoryInterface $ingredientCategoryRepository,
|
||
|
StockInterface $stockRepository,
|
||
|
FieldInterface $fieldRepository,
|
||
|
UnitInterface $unitRepository)
|
||
|
{
|
||
|
$this->ingredientRepository = $ingredientRepository;
|
||
|
$this->unitRepository = $unitRepository;
|
||
|
$this->supplierRepository = $supplierRepository;
|
||
|
$this->purchaseEntryRepository = $purchaseEntryRepository;
|
||
|
$this->ingredientCategoryRepository = $ingredientCategoryRepository;
|
||
|
$this->stockRepository = $stockRepository;
|
||
|
$this->fieldRepository = $fieldRepository;
|
||
|
|
||
|
|
||
|
}
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function index(Request $request)
|
||
|
{
|
||
|
$filters = $request->all();
|
||
|
$data['title'] = 'Purchase Entries';
|
||
|
$data['stockList'] = $this->stockRepository->pluck();
|
||
|
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||
|
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||
|
$data['purchaseEntries'] = $this->purchaseEntryRepository->findAll($filters);
|
||
|
return view('purchaseEntry::purchaseEntry.index', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for creating a new resource.
|
||
|
*/
|
||
|
public function create()
|
||
|
{
|
||
|
$data['title'] = 'New Purchase Entry';
|
||
|
$data['stockList'] = $this->stockRepository->pluck();
|
||
|
$data['unitList'] = $this->unitRepository->pluck();
|
||
|
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||
|
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||
|
$data['supplierList'] = $this->supplierRepository->pluck();
|
||
|
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
|
||
|
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||
|
$data['editable'] = false;
|
||
|
|
||
|
return view('purchaseEntry::purchaseEntry.create', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*/
|
||
|
public function store(Request $request): RedirectResponse
|
||
|
{
|
||
|
$this->purchaseEntryRepository->create($request);
|
||
|
|
||
|
return redirect()->route('purchaseEntry.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the specified resource.
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
return view('purchaseEntry::purchaseEntry.show');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for editing the specified resource.
|
||
|
*/
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$data['supplierList'] = $this->supplierRepository->pluck();
|
||
|
$data['ingredientCategoryList'] = $this->ingredientCategoryRepository->pluck();
|
||
|
$data['stockList'] = $this->stockRepository->pluck();
|
||
|
$data['unitList'] = $this->unitRepository->pluck();
|
||
|
$data['ingredientList'] = $this->ingredientRepository->pluck();
|
||
|
$data['sizes'] = $this->fieldRepository->getDropdownByAlias('size');
|
||
|
$data['paymentModes'] = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||
|
$data['order'] = PurchaseEntry::with('orderDetails')->find($id);
|
||
|
$data['id'] = $id;
|
||
|
$data['editable'] = true;
|
||
|
$data['title'] = "Edit Purchase Entry";
|
||
|
return view('purchaseEntry::purchaseEntry.edit');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(Request $request, $id): RedirectResponse
|
||
|
{
|
||
|
$this->purchaseEntryRepository->update($id,$request);
|
||
|
return redirect()->route('purchaseEntry.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
return $this->purchaseEntryRepository->delete($id);
|
||
|
}
|
||
|
|
||
|
public function clonePurchaseIngredient(Request $request)
|
||
|
{
|
||
|
$data = [];
|
||
|
$numInc = $request->numberInc;
|
||
|
$script = true;
|
||
|
$ingredientList= $this->ingredientRepository->pluck('id');
|
||
|
$stockList= $this->stockRepository->pluck('id');
|
||
|
$ingredientCategoryList= $this->ingredientCategoryRepository->pluck('id');
|
||
|
$sizes = $this->fieldRepository->getDropdownByAlias('size');
|
||
|
$paymentModes = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||
|
|
||
|
return response()->json([
|
||
|
'view' => view('purchaseEntry::purchaseEntry.clone-product', compact('data', 'numInc', 'script', 'ingredientList', 'ingredientCategoryList', 'stockList', 'sizes', 'paymentModes'))->render(),
|
||
|
]);
|
||
|
}
|
||
|
public function clonePurchaseProduct(Request $request)
|
||
|
{
|
||
|
$data = [];
|
||
|
$numInc = $request->numberInc;
|
||
|
$script = true;
|
||
|
$ingredientList= $this->ingredientRepository->pluck('id');
|
||
|
$stockList= $this->stockRepository->pluck('id');
|
||
|
$unitList = $this->unitRepository->pluck('id');
|
||
|
$ingredientCategoryList= $this->ingredientCategoryRepository->pluck('id');
|
||
|
$sizes = $this->fieldRepository->getDropdownByAlias('size');
|
||
|
$paymentModes = $this->fieldRepository->getDropdownByAlias('payment-mode');
|
||
|
|
||
|
return response()->json([
|
||
|
'view' => view('purchaseEntry::purchaseEntry.clone-ingredient', compact('data', 'numInc', 'script', 'ingredientList', 'ingredientCategoryList', 'stockList', 'unitList', 'sizes', 'paymentModes'))->render(),
|
||
|
]);
|
||
|
}
|
||
|
}
|