67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Portal\Http\Controllers\Supplier;
|
|
|
|
use App\Transaction;
|
|
use App\Utils\ProductUtil;
|
|
use App\Utils\TransactionUtil;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Portal\Http\Controllers\BasePortalController;
|
|
|
|
class PurchaseOrderController extends BasePortalController
|
|
{
|
|
public function __construct(
|
|
protected TransactionUtil $transactionUtil,
|
|
protected ProductUtil $productUtil
|
|
) {}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$this->ensureCrmSubscription();
|
|
$statuses = $this->productUtil->orderStatuses();
|
|
|
|
$orders = Transaction::where('business_id', $this->businessId())
|
|
->where('type', 'purchase_order')
|
|
->where('contact_id', $this->contactId())
|
|
->orderByDesc('transaction_date')
|
|
->paginate(20);
|
|
|
|
return view('portal::supplier.purchase_orders.index', compact('orders', 'statuses'));
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$this->ensureCrmSubscription();
|
|
$order = Transaction::where('business_id', $this->businessId())
|
|
->where('type', 'purchase_order')
|
|
->where('contact_id', $this->contactId())
|
|
->with(['purchase_lines', 'purchase_lines.product', 'purchase_lines.variations'])
|
|
->findOrFail($id);
|
|
|
|
return view('portal::supplier.purchase_orders.show', compact('order'));
|
|
}
|
|
|
|
public function acknowledge(Request $request, $id)
|
|
{
|
|
$this->ensureCrmSubscription();
|
|
$request->validate([
|
|
'expected_delivery_date' => 'required|date|after_or_equal:today',
|
|
'supplier_response_status' => 'required|in:accepted,declined',
|
|
]);
|
|
|
|
$order = Transaction::where('business_id', $this->businessId())
|
|
->where('type', 'purchase_order')
|
|
->where('contact_id', $this->contactId())
|
|
->findOrFail($id);
|
|
|
|
$order->supplier_acknowledged_at = now();
|
|
$order->expected_delivery_date = $request->expected_delivery_date;
|
|
$order->supplier_response_status = $request->supplier_response_status;
|
|
$order->save();
|
|
|
|
return redirect()
|
|
->action([self::class, 'show'], [$id])
|
|
->with('status', ['success' => 1, 'msg' => __('portal::lang.po_response_saved')]);
|
|
}
|
|
}
|