1. Added import and export actions with labels and warning colors for the following resources:

- LineResource
  - LineStopResource
  - LocatorResource
  - MachineResource
  - MfmMeterResource
  - MfmParameterResource
  - MotorTestingMasterResource
  - PlantResource
  - ProductionLineStopResource
  - ProductionPlanResource
  - ProductionQuantityResource
  - QualityValidationResource
  - SerialValidationResource
  - ShiftResource
  - StickerMasterResource
  - UserResource
  - WorkGroupMasterResource
2. Updated camera capture functionality to ensure overlay canvas size syncs with video size.
This commit is contained in:
dhanabalan
2025-11-13 16:27:48 +05:30
parent d9e1190d92
commit 68cd0b81a2
31 changed files with 641 additions and 108 deletions

View File

@@ -5,11 +5,14 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ItemExporter;
use App\Filament\Imports\ItemImporter;
use App\Filament\Resources\ItemResource\Pages;
use App\Models\InvoiceValidation;
use App\Models\Item;
use App\Models\Plant;
use App\Models\StickerMaster;
use Filament\Actions\Exports\Enums\ExportFormat;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
@@ -21,7 +24,12 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Notifications\Notification;
use Illuminate\Validation\Rule;
use Maatwebsite\Excel\Facades\Excel;
use Storage;
use Str;
class ItemResource extends Resource
{
@@ -243,7 +251,237 @@ class ItemResource extends Resource
]),
])
->headerActions([
// Tables\Actions\Action::make('Import Items')
// ->label('Import Items')
// ->form([
// Select::make('plant_id')
// // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
// ->options(function (callable $get) {
// $userHas = Filament::auth()->user()->plant_id;
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
// })
// ->label('Select Plant')
// ->required()
// // ->default(function () {
// // return optional(InvoiceValidation::latest()->first())->plant_id;
// // })
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('item_code_file', null);
// })
// ->reactive(),
// FileUpload::make('item_code_file')
// ->label('Master Item Code')
// // ->required()
// ->preserveFilenames() // <- this keeps the original filename
// ->storeFiles(false) // prevent auto-storing, we will store manually
// ->reactive()
// ->required()
// ->disk('local') //'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app.
// ->visible(fn (Get $get) => !empty($get('plant_id')))
// ->directory('uploads/temp'),
// ])
// ->action(function (array $data) {
// $uploadedFile = $data['item_code_file'];
// $disk = Storage::disk('local');
// $plantId = $data['plant_id'];
// // Get original filename
// $originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
// $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
// // Store manually using storeAs to keep original name
// $path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
// $fullPath = Storage::disk('local')->path($path);
// if ($fullPath && file_exists($fullPath))
// {
// $rows = Excel::toArray(null, $fullPath)[0];
// if ((count($rows) - 1) <= 0)
// {
// Notification::make()
// ->title('Records Not Found')
// ->body("Import the valid 'Serial Invoice' file to proceed..!")
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// $invalidCategory = [];
// $materialCodes = [];
// $description = [];
// $invalidHourlyQuantity = [];
// $invalidUOM = [];
// $invalidPlantName = [];
// $seenItems = [];
// $uniqueInvalidCodes = [];
// $uniqueDesc = [];
// foreach ($rows as $index => $row)
// {
// if ($index == 0) continue; // Skip header
// $category = trim($row[0]);
// $materialCode = trim($row[1]);
// $desc = trim($row[2]);
// $hourlyQuantity = trim($row[3]);
// $uom = trim($row[4]);
// $plantName = trim($row[5]);
// if (strlen($materialCode) < 6) {
// $uniqueInvalidCodes[] = $materialCode;
// }
// else if (strlen($desc) < 7) {
// $uniqueDesc[] = $desc;
// }
// $key = $plantName . '|' . $materialCode;
// if (isset($seenItems[$key]))
// {
// $materialCodes[] = $materialCode;
// }
// else
// {
// $seenItems[$key] = true;
// }
// }
// if (!empty($uniqueInvalidCodes)) {
// Notification::make()
// ->title('Invalid Item Codes')
// ->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// else if (!empty($uniqueMissingSerials)) {
// Notification::make()
// ->title('Missing Serial Numbers')
// ->body("The following item codes doesn't have valid serial number:<br>" . implode(', ', $uniqueMissingSerials))
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// else if (!empty($uniqueSerialCodes)) {
// Notification::make()
// ->title('Invalid Serial Number')
// ->body('The following serial numbers should contain minimum 9 digit alpha numeric values:<br>' . implode(', ', $uniqueSerialCodes))
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// else if (!empty($duplicateSerialCodes)) {
// Notification::make()
// ->title('Duplicate Serial Numbers')
// ->body('The following serial numbers are already exist in imported excel:<br>' . implode(', ', $duplicateSerialCodes))
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// $uniqueCodes = array_unique($materialCodes);
// $matchedItems = StickerMaster::with('item')
// ->whereHas('item', function ($query) use ($uniqueCodes) {
// $query->whereIn('code', $uniqueCodes);
// })
// ->get();
// $matchedCodes = $matchedItems->pluck('item.code')->toArray();
// $missingCodes = array_diff($uniqueCodes, $matchedCodes);
// if (!empty($missingCodes))
// {
// $missingCount = count($missingCodes);
// $message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
// Notification::make()
// ->title('Unknown Item Codes')
// ->body($message)
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// // Check which codes have a material_type set (not null)
// $invalidCodes = $matchedItems
// ->filter(fn ($sticker) => !empty($sticker->material_type)) //filter invalid
// ->pluck('item.code')
// ->toArray();
// if (count($invalidCodes) > 10)
// {
// Notification::make()
// ->title('Invalid item codes found')
// ->body('' . count($invalidCodes) . 'item codes found have material type.')
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// else if (count($invalidCodes) > 0)
// {
// Notification::make()
// ->title('Invalid item codes found')
// ->body('Material invoice Item Codes found : ' . implode(', ', $invalidCodes))
// ->danger()
// ->send();
// if ($disk->exists($path)) {
// $disk->delete($path);
// }
// return;
// }
// else
// {
// // Save full file path to session
// session(['uploaded_invoice_path' => $fullPath]);
// Notification::make()
// ->title('Serial invoice imported successfully.')
// ->success()
// ->send();
// }
// }
// })
// ->visible(function() {
// return Filament::auth()->user()->can('view import serial invoice');
// }),
ImportAction::make()
->label('Import Items')
->color('warning')
->importer(ItemImporter::class)
->visible(function() {
return Filament::auth()->user()->can('view import item');
@@ -251,7 +489,8 @@ class ItemResource extends Resource
// ->maxRows(100000),
ExportAction::make()
// ->columnMapping(true)
// ->label('Export')
->label('Import Items')
->color('warning')
// ->fileName("Items Report " . date('Y-m-d H:i:s'))
->exporter(ItemExporter::class)
->visible(function() {