Create function on enter key press and enable cancel action button only
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
namespace App\Filament\Resources\ProductionQuantityResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductionQuantityResource;
|
||||
use App\Models\ProductionQuantity;
|
||||
use App\Models\Shift;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class CreateProductionQuantity extends CreateRecord
|
||||
{
|
||||
@@ -16,29 +20,118 @@ class CreateProductionQuantity extends CreateRecord
|
||||
return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
||||
}
|
||||
|
||||
// public $qr_data;
|
||||
public $qrData, $pId, $bId, $sId, $lId, $iId, $succId, $sNoId, $succStat, $recQr;
|
||||
|
||||
// public function processQr($itemCode)
|
||||
// {
|
||||
// $this->qr_data = $itemCode;
|
||||
// protected static bool $canCreateAnother = false;
|
||||
|
||||
// // Check if the file is uploaded
|
||||
// if (!$this->qr_data) {
|
||||
// Notification::make()
|
||||
// ->title('No QR Found')
|
||||
// ->body("Please, scan the QR code.")
|
||||
// ->danger()
|
||||
// // ->persistent()
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// Notification::make()
|
||||
// ->title('QR Found')
|
||||
// ->body("Valid QR code scanned: {$this->qr_data}.")
|
||||
// ->success()
|
||||
// // ->persistent()
|
||||
// ->send();
|
||||
// }
|
||||
// }
|
||||
public function getFormActions(): array
|
||||
{
|
||||
// return parent::getFormActions(); //return [];
|
||||
return [
|
||||
$this->getCancelFormAction(),
|
||||
];
|
||||
}
|
||||
|
||||
public function processAllValues($formData)
|
||||
{
|
||||
//$formValues = [];
|
||||
$formValues = request()->all(); // This will get all form data from the request
|
||||
//dd($formValues);
|
||||
$this->validateAndProcessForm($formValues); // Process the form values
|
||||
}
|
||||
|
||||
public function validateAndProcessForm($formValues)
|
||||
{
|
||||
$user = Filament::auth()->user();
|
||||
$operatorName = $user->name;
|
||||
// $this->validate();
|
||||
|
||||
try {
|
||||
// Access the nested form data
|
||||
$componentData = json_decode($formValues['components'][0]['snapshot'], true);
|
||||
$formData = $componentData['data']['data'][0]; // Access first item in data array
|
||||
|
||||
// Extract specific values
|
||||
$this->qrData = $formData['item_code'] ?? null;
|
||||
$this->pId = $formData['plant_id'] ?? null;
|
||||
$this->bId = $formData['block_name'] ?? null;
|
||||
$this->sId = $formData['shift_id'] ?? null;
|
||||
$this->lId = $formData['line_id'] ?? null;
|
||||
$this->iId = $formData['item_id'] ?? null;
|
||||
$this->succId = $formData['success_msg'] ?? null;
|
||||
// $this->sNoId = $formData['serial_number'] ?? null;
|
||||
$this->recQr = $formData['recent_qr'] ?? null;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
dd('Error parsing form data:', $e->getMessage(), $formValues);
|
||||
}
|
||||
|
||||
if ($this->succId === null) {
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'recent_qr' => $this->recQr,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title("Invalid QR Found") // {$operatorName}
|
||||
->body("Please, scan the valid QR code.")
|
||||
->danger()
|
||||
// ->persistent()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// // Perform any additional processing or database operations
|
||||
// $this->saveFormData($formValues);
|
||||
|
||||
$parts = explode('|', $this->qrData);
|
||||
$itemCode = trim($parts[0]);
|
||||
$this->sNoId = isset($parts[1]) ? trim($parts[1]) : null;
|
||||
|
||||
ProductionQuantity::create([
|
||||
'plant_id'=> $this->pId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id' => $this->lId,
|
||||
'item_id'=> $this->iId,
|
||||
'serial_number' => $this->sNoId,
|
||||
// 'operator_id'=> $operatorName,
|
||||
]);
|
||||
|
||||
// after success insertion
|
||||
$this->form->fill([
|
||||
'plant_id'=> $this->pId,
|
||||
'block_name'=> $this->bId,
|
||||
'shift_id'=> $this->sId,
|
||||
'line_id'=> $this->lId,
|
||||
'item_id'=> null,
|
||||
'serial_number'=> null,
|
||||
'success_msg'=> null,
|
||||
'recent_qr' => $itemCode.' | '.$this->sNoId,
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title("Valid QR Found") // {$operatorName}
|
||||
->body("Valid QR code scanned: {$this->qrData}.")
|
||||
->success()
|
||||
// ->persistent()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveFormData($formValues)
|
||||
{
|
||||
// Save the form data to the database or perform other operations
|
||||
// For example:
|
||||
$model = ProductionQuantity::create($formValues);
|
||||
|
||||
// // Optionally, you can emit an event or perform a redirect after saving
|
||||
// $this->emit('formSaved', $model->id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user