|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\CustomerRequest;
|
|
|
|
use App\Models\Customer;
|
|
|
|
use App\Models\PackingSlip;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Foundation\Application;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
|
|
class CustomerController extends Controller
|
|
|
|
{
|
|
|
|
public function index(): void {}
|
|
|
|
|
|
|
|
public function store(CustomerRequest $request)
|
|
|
|
{
|
|
|
|
Customer::create($request->validated());
|
|
|
|
|
|
|
|
return redirect()->route('management.index')->with('status', 'Customer created successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(): Factory|View|Application|\Illuminate\View\View
|
|
|
|
{
|
|
|
|
return view('customers.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Customer $customer, ?string $tab = null): RedirectResponse|View
|
|
|
|
{
|
|
|
|
if (! $tab) {
|
|
|
|
return redirect()->route('customers.show', [$customer, 'tab' => 'details']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('customers.show', [
|
|
|
|
'tab' => $tab,
|
|
|
|
'customer' => $customer,
|
|
|
|
'contacts' => $customer->contacts()->get(),
|
|
|
|
'packingSlips' => PackingSlip::where('customer_id', $customer->id)->orderByDesc('date_received')->paginate(15),
|
|
|
|
'shippingEntries' => $customer->shippingEntries()->get(),
|
|
|
|
'today' => Carbon::today()->format('Y-m-d'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(CustomerRequest $request, Customer $customer): RedirectResponse
|
|
|
|
{
|
|
|
|
$customer->update($request->validated());
|
|
|
|
|
|
|
|
return redirect()->route('customers.show', $customer)->with('status', 'Customer updated successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requestDestroy(Request $request): RedirectResponse
|
|
|
|
{
|
|
|
|
$customer = Customer::find($request->id);
|
|
|
|
$customer->delete();
|
|
|
|
|
|
|
|
return redirect()->route('management.index')->with('status', 'Customer deleted successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Customer $customer): RedirectResponse
|
|
|
|
{
|
|
|
|
$customer->delete();
|
|
|
|
|
|
|
|
return redirect()->route('management.index')->with('status', 'Customer deleted successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pdf(Customer $customer, ?bool $paid = false, ?string $created_from = null, ?string $created_until = null): RedirectResponse
|
|
|
|
{
|
|
|
|
dd($customer, $paid, $created_from, $created_until);
|
|
|
|
}
|
|
|
|
}
|