82 lines
2.6 KiB
PHP
82 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Sales;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Customer;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CustomerController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$customers = Customer::paginate(15);
|
|
|
|
return view('sales.customers.index', compact('customers'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('sales.customers.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'email' => 'nullable|email|max:255',
|
|
'phone' => 'nullable|string|max:50',
|
|
'whatsapp_number' => 'nullable|string|max:20',
|
|
'address' => 'nullable|string',
|
|
'contact_person' => 'nullable|string|max:255',
|
|
'tax_number' => 'nullable|string|max:50',
|
|
'credit_limit' => 'nullable|numeric|min:0',
|
|
'is_active' => 'nullable|boolean',
|
|
]);
|
|
|
|
$validated['is_active'] = (bool) $request->input('is_active', 1);
|
|
|
|
Customer::create($validated);
|
|
|
|
return redirect()->route('sales.customers.index')->with('success', 'Customer created successfully.');
|
|
}
|
|
|
|
public function show(Customer $customer)
|
|
{
|
|
return view('sales.customers.show', compact('customer'));
|
|
}
|
|
|
|
public function edit(Customer $customer)
|
|
{
|
|
return view('sales.customers.edit', compact('customer'));
|
|
}
|
|
|
|
public function update(Request $request, Customer $customer)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'email' => 'nullable|email|max:255',
|
|
'phone' => 'nullable|string|max:50',
|
|
'whatsapp_number' => 'nullable|string|max:20',
|
|
'address' => 'nullable|string',
|
|
'contact_person' => 'nullable|string|max:255',
|
|
'tax_number' => 'nullable|string|max:50',
|
|
'credit_limit' => 'nullable|numeric|min:0',
|
|
'is_active' => 'nullable|boolean',
|
|
]);
|
|
|
|
$validated['is_active'] = (bool) $request->input('is_active', 0);
|
|
|
|
$customer->update($validated);
|
|
|
|
return redirect()->route('sales.customers.index')->with('success', 'Customer updated successfully.');
|
|
}
|
|
|
|
public function destroy(Customer $customer)
|
|
{
|
|
$customer->delete();
|
|
|
|
return redirect()->route('sales.customers.index')->with('success', 'Customer deleted successfully.');
|
|
}
|
|
}
|