44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\StockEntry;
|
|
use App\Models\StockEntryStatusHistory;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StockEntryStatusController extends Controller
|
|
{
|
|
/**
|
|
* Store a new status history record for a given stock entry.
|
|
*/
|
|
public function store(Request $request, StockEntry $stockEntry)
|
|
{
|
|
$data = $request->validate([
|
|
'status' => [
|
|
'required',
|
|
'integer',
|
|
// ensure the status ID exists in your statuses table
|
|
Rule::exists('stock_entries_status', 'id'),
|
|
],
|
|
'count' => ['nullable', 'integer', 'min:0'],
|
|
]);
|
|
|
|
// Create the history record
|
|
$history = StockEntryStatusHistory::create([
|
|
'stock_entries_id' => $stockEntry->id,
|
|
'stock_entries_status_id' => $data['status'],
|
|
'status_note' => isset($data['count'])
|
|
? "Count: {$data['count']}"
|
|
: null,
|
|
'section_id' => null
|
|
]);
|
|
|
|
return response()->json([
|
|
'message' => 'Status updated successfully.',
|
|
'history' => $history,
|
|
], 201);
|
|
}
|
|
}
|