- Refactor New Quote page to enterprise data-entry layout (2-column, dense) - Add Payment Terms dropdown (COD, NET 15, NET 30, NET 60) - Fix sidebar menu active states and route names - Fix brand filter badge visibility on brands page - Remove company_name references (use business instead) - Polish Promotions page layout - Fix double-click issue on sidebar menu collapse - Make all searches case-insensitive (like -> ilike for PostgreSQL)
126 lines
4.5 KiB
PHP
126 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Seller\Processing;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Business;
|
|
use App\Models\Processing\ProcBiomassLot;
|
|
use App\Models\Processing\ProcVendor;
|
|
use App\Models\Product;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BiomassController extends Controller
|
|
{
|
|
public function index(Request $request, Business $business)
|
|
{
|
|
$query = ProcBiomassLot::forBusiness($business->id)
|
|
->with('product')
|
|
->orderByDesc('created_at');
|
|
|
|
if ($request->filled('status')) {
|
|
$query->where('status', $request->status);
|
|
}
|
|
|
|
if ($request->filled('search')) {
|
|
$query->where('lot_number', 'ilike', '%'.$request->search.'%');
|
|
}
|
|
|
|
$biomassLots = $query->paginate(25);
|
|
|
|
return view('seller.processing.biomass.index', compact('business', 'biomassLots'));
|
|
}
|
|
|
|
public function create(Request $request, Business $business)
|
|
{
|
|
$vendors = ProcVendor::forBusiness($business->id)->active()->get();
|
|
$products = Product::where('business_id', $business->id)->get(); // Biomass product types
|
|
|
|
return view('seller.processing.biomass.create', compact('business', 'vendors', 'products'));
|
|
}
|
|
|
|
public function store(Request $request, Business $business)
|
|
{
|
|
$validated = $request->validate([
|
|
'lot_number' => 'required|string|max:100',
|
|
'product_id' => 'nullable|exists:products,id',
|
|
'source_type' => 'required|in:internal,external_vendor,internal_business',
|
|
'source_id' => 'nullable|integer',
|
|
'wet_weight' => 'required|numeric|min:0',
|
|
'dry_weight' => 'nullable|numeric|min:0',
|
|
'moisture_percent' => 'nullable|numeric|min:0|max:100',
|
|
'thc_percent' => 'nullable|numeric|min:0|max:100',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
|
|
$validated['business_id'] = $business->id;
|
|
$validated['status'] = 'available';
|
|
|
|
ProcBiomassLot::create($validated);
|
|
|
|
return redirect()
|
|
->route('seller.processing.biomass.index', $business)
|
|
->with('success', 'Biomass lot created successfully.');
|
|
}
|
|
|
|
public function show(Request $request, Business $business, ProcBiomassLot $biomass)
|
|
{
|
|
$this->authorizeForBusiness($biomass, $business);
|
|
|
|
$biomass->load(['product', 'extractionRunInputs.extractionRun']);
|
|
|
|
return view('seller.processing.biomass.show', compact('business', 'biomass'));
|
|
}
|
|
|
|
public function edit(Request $request, Business $business, ProcBiomassLot $biomass)
|
|
{
|
|
$this->authorizeForBusiness($biomass, $business);
|
|
|
|
$vendors = ProcVendor::forBusiness($business->id)->active()->get();
|
|
$products = Product::where('business_id', $business->id)->get();
|
|
|
|
return view('seller.processing.biomass.edit', compact('business', 'biomass', 'vendors', 'products'));
|
|
}
|
|
|
|
public function update(Request $request, Business $business, ProcBiomassLot $biomass)
|
|
{
|
|
$this->authorizeForBusiness($biomass, $business);
|
|
|
|
$validated = $request->validate([
|
|
'lot_number' => 'required|string|max:100',
|
|
'product_id' => 'nullable|exists:products,id',
|
|
'source_type' => 'required|in:internal,external_vendor,internal_business',
|
|
'source_id' => 'nullable|integer',
|
|
'wet_weight' => 'required|numeric|min:0',
|
|
'dry_weight' => 'nullable|numeric|min:0',
|
|
'moisture_percent' => 'nullable|numeric|min:0|max:100',
|
|
'thc_percent' => 'nullable|numeric|min:0|max:100',
|
|
'status' => 'required|in:available,allocated,depleted,quarantined',
|
|
'notes' => 'nullable|string',
|
|
]);
|
|
|
|
$biomass->update($validated);
|
|
|
|
return redirect()
|
|
->route('seller.processing.biomass.show', [$business, $biomass])
|
|
->with('success', 'Biomass lot updated successfully.');
|
|
}
|
|
|
|
public function destroy(Request $request, Business $business, ProcBiomassLot $biomass)
|
|
{
|
|
$this->authorizeForBusiness($biomass, $business);
|
|
|
|
$biomass->delete();
|
|
|
|
return redirect()
|
|
->route('seller.processing.biomass.index', $business)
|
|
->with('success', 'Biomass lot deleted successfully.');
|
|
}
|
|
|
|
protected function authorizeForBusiness(ProcBiomassLot $biomass, Business $business): void
|
|
{
|
|
if ($biomass->business_id !== $business->id) {
|
|
abort(403, 'Unauthorized access to this biomass lot.');
|
|
}
|
|
}
|
|
}
|