Updated alignments and added orderby query while load plant
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-10 12:45:54 +05:30
parent 6c9408663b
commit aaa9c17e66
36 changed files with 1592 additions and 1574 deletions

View File

@@ -5,155 +5,152 @@ namespace App\Filament\Resources;
use App\Filament\Exports\AlertMailRuleExporter;
use App\Filament\Imports\AlertMailRuleImporter;
use App\Filament\Resources\AlertMailRuleResource\Pages;
use App\Filament\Resources\AlertMailRuleResource\RelationManagers;
use App\Models\AlertMailRule;
use App\Models\InvoiceMaster;
use App\Models\Plant;
use Dotenv\Exception\ValidationException;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException as ValidationValidationException;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class AlertMailRuleResource extends Resource
{
protected static ?string $model = AlertMailRule::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-m-bell-alert';
protected static ?string $navigationGroup = 'Alert Mail';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant')
->label('Plant')
->reactive()
->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();
})
->required(fn ($get) => ! $get('is_active'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
Forms\Components\Select::make('module')
->label('Module')
->required()
->options([
'InvoiceValidation' => 'InvoiceValidation',
'InvoiceDataReport' => 'InvoiceDataReport',
'ProductionQuantities' => 'ProductionQuantities',
'QualityValidation' => 'QualityValidation',
'InvoiceTransit' => 'InvoiceTransit',
]),
Forms\Components\Select::make('rule_name')
->label('Rule Name')
->options([
'InvoiceMail' => 'Invoice Mail',
'SerialInvoiceMail' => 'Serial Invoice Mail',
'MaterialInvoiceMail' => 'Material Invoice Mail',
'ProductionMail' => 'Production Mail',
'InvoiceDataMail' => 'Invoice Data Mail',
'QualityMail' => 'Quality Mail',
'InvoiceTransitMail' => 'Invoice Transit Mail',
Section::make('')
->schema([
Forms\Components\Select::make('plant')
->label('Plant')
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(fn ($get) => ! $get('is_active'))
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
Forms\Components\Select::make('module')
->label('Module')
->required()
->options([
'InvoiceValidation' => 'InvoiceValidation',
'InvoiceDataReport' => 'InvoiceDataReport',
'ProductionQuantities' => 'ProductionQuantities',
'QualityValidation' => 'QualityValidation',
'InvoiceTransit' => 'InvoiceTransit',
]),
Forms\Components\Select::make('rule_name')
->label('Rule Name')
->options([
'InvoiceMail' => 'Invoice Mail',
'SerialInvoiceMail' => 'Serial Invoice Mail',
'MaterialInvoiceMail' => 'Material Invoice Mail',
'ProductionMail' => 'Production Mail',
'InvoiceDataMail' => 'Invoice Data Mail',
'QualityMail' => 'Quality Mail',
'InvoiceTransitMail' => 'Invoice Transit Mail',
])
->required(),
Forms\Components\TextInput::make('email')
->label('Email')
->required(),
Forms\Components\Textarea::make('cc_emails')
->label('CC Emails'),
Forms\Components\Select::make('schedule_type')
->label('Schedule Type')
->options([
'Live' => 'Live',
'Hourly' => 'Hourly',
'Daily' => 'Daily',
]),
Forms\Components\Select::make('receiving_plant_name')
->label('Receiving Plant')
->options(
InvoiceMaster::query()
->whereNotNull('receiving_plant_name')
->select('receiving_plant_name')
->distinct()
->pluck('receiving_plant_name', 'receiving_plant_name')
)
->searchable()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('invoice_master_id', null);
}),
Forms\Components\Select::make('invoice_master_id')
->label('Transporter Name')
->options(function (callable $get) {
$recPlant = $get('receiving_plant_name');
if (! $recPlant) {
return [];
}
return InvoiceMaster::query()
->where('receiving_plant_name', $recPlant)
->whereNotNull('transport_name')
->where('transport_name', '!=', '')
->orderBy('transport_name')
->pluck('transport_name', 'id')
->toArray();
})
->searchable(),
Checkbox::make('is_active')
->label('All Plants Reports')
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
->reactive(),
// Forms\Components\Actions::make([
// Action::make('sendInvoiceData')
// ->label('Invoice Data Report')
// ->action(function ($get) {
// $plantIds = AlertMailRule::where('module', 'InvoiceDataReport')
// ->orderBy('plant')
// ->pluck('plant')
// ->toArray();
// foreach ($plantIds as $plantId) {
// Artisan::call('send:invoice-data-report', [
// 'schedule_type' => 'Daily',
// 'plant' => $plantId,
// ]);
// }
// // Notify user in Filament
// Notification::make()
// ->title('Invoice data report sent successfully!')
// ->success()
// ->send();
// }),
// ]),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->default(fn () => Filament::auth()->user()?->name),
])
->required(),
Forms\Components\TextInput::make('email')
->label('Email')
->required(),
Forms\Components\Textarea::make('cc_emails')
->label('CC Emails'),
Forms\Components\Select::make('schedule_type')
->label('Schedule Type')
->options([
'Live' => 'Live',
'Hourly' => 'Hourly',
'Daily' => 'Daily',
]),
Forms\Components\Select::make('receiving_plant_name')
->label('Receiving Plant')
->options(
InvoiceMaster::query()
->whereNotNull('receiving_plant_name')
->select('receiving_plant_name')
->distinct()
->pluck('receiving_plant_name', 'receiving_plant_name')
)
->searchable()
->reactive()
->afterStateUpdated(function (callable $set) {
$set('invoice_master_id', null);
}),
Forms\Components\Select::make('invoice_master_id')
->label('Transporter Name')
->options(function (callable $get) {
$recPlant = $get('receiving_plant_name');
if (! $recPlant) {
return [];
}
return InvoiceMaster::query()
->where('receiving_plant_name', $recPlant)
->whereNotNull('transport_name')
->where('transport_name', '!=', '')
->orderBy('transport_name')
->pluck('transport_name', 'id')
->toArray();
})
->searchable(),
Checkbox::make('is_active')
->label('All Plants Reports')
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('plant', null) : null)
->reactive(),
// Forms\Components\Actions::make([
// Action::make('sendInvoiceData')
// ->label('Invoice Data Report')
// ->action(function ($get) {
// $plantIds = AlertMailRule::where('module', 'InvoiceDataReport')
// ->orderBy('plant')
// ->pluck('plant')
// ->toArray();
// foreach ($plantIds as $plantId) {
// Artisan::call('send:invoice-data-report', [
// 'schedule_type' => 'Daily',
// 'plant' => $plantId,
// ]);
// }
// // Notify user in Filament
// Notification::make()
// ->title('Invoice data report sent successfully!')
// ->success()
// ->send();
// }),
// ]),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->default(fn () => Filament::auth()->user()?->name),
])
->columns(2),
]);
->columns(2),
]);
}
public static function table(Table $table): Table
@@ -166,6 +163,7 @@ class AlertMailRuleResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant')
@@ -178,6 +176,7 @@ class AlertMailRuleResource extends Resource
if (! $plants) {
$plants = Plant::pluck('name', 'id')->toArray();
}
return $plants[$state] ?? 'All Plants';
}),
Tables\Columns\TextColumn::make('module')
@@ -260,14 +259,14 @@ class AlertMailRuleResource extends Resource
->label('Import Alert Mail Rule')
->color('warning')
->importer(AlertMailRuleImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import alert mail rule');
}),
ExportAction::make()
->label('Export Alert Mail Rule')
->color('warning')
->exporter(AlertMailRuleExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export alert mail rule');
}),
]);

View File

@@ -9,16 +9,16 @@ use App\Models\Block;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
class BlockResource extends Resource
@@ -46,12 +46,11 @@ class BlockResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name');
// Ensure `linestop_id` is not cleared
if (!$nameId) {
if (! $nameId) {
$set('bNameError', 'Scan the valid name.');
return;
}
else
{
} else {
$set('bNameError', null);
}
})
@@ -72,21 +71,21 @@ class BlockResource extends Resource
->reactive()
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Block::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('plant_id');
// Ensure `linestop_id` is not cleared
if (!$nameId) {
if (! $nameId) {
$set('bPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('bPlantError', null);
}
})
@@ -98,7 +97,7 @@ class BlockResource extends Resource
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
])
->columns(2),
]);
}
@@ -117,10 +116,11 @@ class BlockResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('name')
//->unique(ignoreRecord: true)
// ->unique(ignoreRecord: true)
->label('Block')
->alignCenter()
->sortable()
@@ -167,14 +167,14 @@ class BlockResource extends Resource
->label('Import Blocks')
->color('warning')
->importer(BlockImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import block');
}),
ExportAction::make()
->label('Export Blocks')
->color('warning')
->exporter(BlockExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export block');
}),
]);

View File

@@ -43,7 +43,7 @@ class CharacteristicValueResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, $set, callable $get) {
@@ -296,7 +296,7 @@ class CharacteristicValueResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CheckPointNameExporter;
use App\Filament\Imports\CheckPointNameImporter;
use App\Filament\Resources\CheckPointNameResource\Pages;
use App\Filament\Resources\CheckPointNameResource\RelationManagers;
use App\Models\CheckPointName;
use App\Models\Plant;
use Filament\Facades\Filament;
@@ -42,20 +41,20 @@ class CheckPointNameResource extends Resource
->reactive()
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(CheckPointName::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPnPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPnPlantError', null);
$set('created_by', Filament::auth()->user()?->name);
}
@@ -100,6 +99,7 @@ class CheckPointNameResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
// Tables\Columns\TextColumn::make('id')
@@ -156,14 +156,14 @@ class CheckPointNameResource extends Resource
->label('Import Check Point Names')
->color('warning')
->importer(CheckPointNameImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import check point name');
}),
ExportAction::make()
->label('Export Check Point Names')
->color('warning')
->exporter(CheckPointNameExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export check point name');
}),
]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CheckPointTimeExporter;
use App\Filament\Imports\CheckPointTimeImporter;
use App\Filament\Resources\CheckPointTimeResource\Pages;
use App\Filament\Resources\CheckPointTimeResource\RelationManagers;
use App\Models\CheckPointName;
use App\Models\CheckPointTime;
use App\Models\Plant;
@@ -43,20 +42,20 @@ class CheckPointTimeResource extends Resource
->reactive()
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPtPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPtPlantError', null);
$set('created_by', Filament::auth()->user()?->name);
}
@@ -78,17 +77,17 @@ class CheckPointTimeResource extends Resource
})
->rule(function (callable $get) {
return Rule::unique('check_point_times', 'sequence_number')
->where('plant_id', $get('plant_id'))
->ignore($get('id'));
//->where('check_point1_id', $get('check_point1_id'))
//->where('check_point2_id', $get('check_point2_id'))
->where('plant_id', $get('plant_id'))
->ignore($get('id'));
// ->where('check_point1_id', $get('check_point1_id'))
// ->where('check_point2_id', $get('check_point2_id'))
}),
Forms\Components\Select::make('check_point1_id')
->label('Check Point Name 1')
// ->relationship('checkPointNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -101,19 +100,19 @@ class CheckPointTimeResource extends Resource
->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point1_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id');
if (!$checkPoint1) {
if (! $checkPoint1) {
$set('cPtCheckPoint1Error', 'Please select a check point 1 first.');
return;
}
else
{
} else {
if ($checkPoint2 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint1Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null);
return;
}
$set('cPtCheckPoint1Error', null);
@@ -131,7 +130,7 @@ class CheckPointTimeResource extends Resource
// ->relationship('checkPointNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -144,19 +143,19 @@ class CheckPointTimeResource extends Resource
->default(function () {
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point2_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$checkPoint1 = $get('check_point1_id');
$checkPoint2 = $get('check_point2_id');
if (!$checkPoint2) {
if (! $checkPoint2) {
$set('cPtCheckPoint2Error', 'Please select a check point 2 first.');
return;
}
else
{
} else {
if ($checkPoint1 && $checkPoint1 == $checkPoint2) {
$set('cPtCheckPoint2Error', 'Duplicate check point 2 found.');
$set('check_point2_id', null);
return;
}
$set('cPtCheckPoint1Error', null);
@@ -185,32 +184,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $state;
$timeLapseCushioning = $get('time_lapse_cushioning');
if (!$timeLapse) {
if (! $timeLapse) {
$set('cPtTimeLapseError', 'Please enter a valid time lapse!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
elseif(!$timeLapseCushioning)
{
} elseif (! $timeLapseCushioning) {
// $set('cPtTimeLapseError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1);
$set('cPtTimeLapseError', null);
$set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name);
return;
}
elseif ($timeLapseCushioning > $timeLapse) {
} elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseError', 'Must be greater than or equal to time lapse cushioning!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
else
{
} else {
$set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -233,32 +230,30 @@ class CheckPointTimeResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$timeLapse = $get('time_lapse');
$timeLapseCushioning = $state;
if (!$timeLapse) {
if (! $timeLapse) {
$set('cPtTimeLapseCushError', 'Please enter a valid time lapse first.');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
elseif(!$timeLapseCushioning)
{
} elseif (! $timeLapseCushioning) {
// $set('cPtTimeLapseCushError', 'Please enter a valid time lapse cushioning!');
$set('time_lapse_cushioning', 1);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - 1);
$set('max_cushioning', $timeLapse + 1);
$set('created_by', Filament::auth()->user()?->name);
return;
}
elseif ($timeLapseCushioning > $timeLapse) {
} elseif ($timeLapseCushioning > $timeLapse) {
$set('cPtTimeLapseCushError', 'Must be less than or equal to time lapse!');
$set('time_lapse_cushioning', null);
$set('min_cushioning', null);
$set('max_cushioning', null);
return;
}
else
{
} else {
$set('cPtTimeLapseError', null);
$set('cPtTimeLapseCushError', null);
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
@@ -308,6 +303,7 @@ class CheckPointTimeResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
// Tables\Columns\TextColumn::make('id')
@@ -387,14 +383,14 @@ class CheckPointTimeResource extends Resource
->label('Import Check Point Times')
->color('warning')
->importer(CheckPointTimeImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import check point time');
}),
ExportAction::make()
->label('Export Check Point Times')
->color('warning')
->exporter(CheckPointTimeExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export check point time');
}),
]);

View File

@@ -37,7 +37,7 @@ class ClassCharacteristicResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ConfigurationExporter;
use App\Filament\Imports\ConfigurationImporter;
use App\Filament\Resources\ConfigurationResource\Pages;
use App\Filament\Resources\ConfigurationResource\RelationManagers;
use App\Models\Configuration;
use App\Models\Line;
use App\Models\Plant;
@@ -15,18 +14,20 @@ use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class ConfigurationResource extends Resource
{
protected static ?string $model = Configuration::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Master Entries';
protected static ?int $navigationSort = 10;
public static function form(Form $form): Form
@@ -40,20 +41,20 @@ class ConfigurationResource extends Resource
->reactive()
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Configuration::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('cPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('cPlantError', null);
}
})
@@ -68,7 +69,7 @@ class ConfigurationResource extends Resource
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -79,15 +80,14 @@ class ConfigurationResource extends Resource
->default(function () {
return optional(Configuration::latest()->first())->line_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineId = $get('line_id');
if (!$lineId) {
if (! $lineId) {
$set('cLineError', 'Please select a line first.');
return;
}
else
{
} else {
$set('cLineError', null);
}
})
@@ -124,6 +124,7 @@ class ConfigurationResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -186,14 +187,14 @@ class ConfigurationResource extends Resource
->label('Import Configurations')
->color('warning')
->importer(ConfigurationImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import configuration');
}),
ExportAction::make()
->label('Export Configurations')
->color('warning')
->exporter(ConfigurationExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export configuration');
}),
]);

View File

@@ -5,53 +5,54 @@ namespace App\Filament\Resources;
use App\Filament\Exports\DeviceMasterExporter;
use App\Filament\Imports\DeviceMasterImporter;
use App\Filament\Resources\DeviceMasterResource\Pages;
use App\Filament\Resources\DeviceMasterResource\RelationManagers;
use App\Models\DeviceMaster;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class DeviceMasterResource extends Resource
{
protected static ?string $model = DeviceMaster::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->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();
})
->required(),
Forms\Components\TextInput::make('name')
->label('Device Name')
->required(),
Forms\Components\TextInput::make('mac_address')
->label('MAC Address'),
Forms\Components\TextInput::make('ip_address')
->label('IP Address'),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\TextInput::make('name')
->label('Device Name')
->required(),
Forms\Components\TextInput::make('mac_address')
->label('MAC Address'),
Forms\Components\TextInput::make('ip_address')
->label('IP Address'),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
]);
}
@@ -65,6 +66,7 @@ class DeviceMasterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -120,14 +122,14 @@ class DeviceMasterResource extends Resource
->label('Import Device Masters')
->color('warning')
->importer(DeviceMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import device master');
}),
ExportAction::make()
->label('Export Device Masters')
->color('warning')
->exporter(DeviceMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export device master');
}),
]);

View File

@@ -39,7 +39,7 @@ class EbReadingResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\TextInput::make('lcd_segment_check')
@@ -336,7 +336,7 @@ class EbReadingResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -5,25 +5,24 @@ namespace App\Filament\Resources;
use App\Filament\Exports\EquipmentMasterExporter;
use App\Filament\Imports\EquipmentMasterImporter;
use App\Filament\Resources\EquipmentMasterResource\Pages;
use App\Filament\Resources\EquipmentMasterResource\RelationManagers;
use App\Models\EquipmentMaster;
use App\Models\Plant;
use Carbon\Carbon;
use Filament\Forms\Components\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Storage;
use Illuminate\Validation\Rule;
class EquipmentMasterResource extends Resource
{
@@ -45,11 +44,12 @@ class EquipmentMasterResource extends Resource
->relationship('plant', 'name')
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('machine_id')
//->relationship('machine', 'name')
// ->relationship('machine', 'name')
->label('Work Center')
->reactive()
->options(function (callable $get) {
@@ -57,6 +57,7 @@ class EquipmentMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return \App\Models\Machine::where('plant_id', $plantId)->pluck('work_center', 'id');
})
->required(),
@@ -93,19 +94,19 @@ class EquipmentMasterResource extends Resource
$set('attachment', null);
}
}),
//->afterStateUpdated(function ($state, callable $set) {
// if (! $state) {
// return;
// }
// ->afterStateUpdated(function ($state, callable $set) {
// if (! $state) {
// return;
// }
// $model = EquipmentMaster::where('equipment_number', $state)->first();
// $model = EquipmentMaster::where('equipment_number', $state)->first();
// if ($model?->attachment) {
// $set('attachment', $model->attachment);
// } else {
// $set('attachment', null);
// }
// }),
// if ($model?->attachment) {
// $set('attachment', $model->attachment);
// } else {
// $set('attachment', null);
// }
// }),
Forms\Components\TextInput::make('instrument_serial_number')
->label('Instrument Serial Number'),
// Forms\Components\DateTimePicker::make('calibrated_on')
@@ -128,17 +129,17 @@ class EquipmentMasterResource extends Resource
$nextDate = self::calculateNextCalibrationDate($state, $frequency);
$set('next_calibration_date', $nextDate);
}),
// ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $frequency = (int) $get('frequency');
// ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $frequency = (int) $get('frequency');
// if ($state && $frequency != 0) {
// $calibratedOn = $state instanceof Carbon ? $state : Carbon::parse($state);
// $nextDate = $calibratedOn->copy()->addDays($frequency);
// $set('next_calibration_date', $nextDate);
// } else {
// $set('next_calibration_date', null);
// }
// }),
// if ($state && $frequency != 0) {
// $calibratedOn = $state instanceof Carbon ? $state : Carbon::parse($state);
// $nextDate = $calibratedOn->copy()->addDays($frequency);
// $set('next_calibration_date', $nextDate);
// } else {
// $set('next_calibration_date', null);
// }
// }),
Forms\Components\TextInput::make('frequency')
->label('Frequency (days)')
@@ -152,20 +153,20 @@ class EquipmentMasterResource extends Resource
$nextDate = self::calculateNextCalibrationDate($calibratedOn, $state);
$set('next_calibration_date', $nextDate);
}),
// ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $calibratedOn = $get('calibrated_on');
// $frequency = (int) $state;
// ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $calibratedOn = $get('calibrated_on');
// $frequency = (int) $state;
// if ($calibratedOn && $frequency !== 0) {
// $calibratedOn = $calibratedOn instanceof Carbon ? $calibratedOn : Carbon::parse($calibratedOn);
// $nextDate = $calibratedOn->copy()->addDays($frequency);
// $set('next_calibration_date', $nextDate);
// }
// else
// {
// $set('next_calibration_date', null);
// }
// }),
// if ($calibratedOn && $frequency !== 0) {
// $calibratedOn = $calibratedOn instanceof Carbon ? $calibratedOn : Carbon::parse($calibratedOn);
// $nextDate = $calibratedOn->copy()->addDays($frequency);
// $set('next_calibration_date', $nextDate);
// }
// else
// {
// $set('next_calibration_date', null);
// }
// }),
Forms\Components\DateTimePicker::make('next_calibration_date')
->label('Next Calibration Date')
@@ -266,7 +267,7 @@ class EquipmentMasterResource extends Resource
// }
// }
// }),
->action(function ($get, callable $set) {
->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment');
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
@@ -285,16 +286,16 @@ class EquipmentMasterResource extends Resource
->title('PDF uploaded successfully')
->success()
->send();
return;
return;
}
}
else
{
} else {
Notification::make()
->title('No file selected to upload')
->warning()
->send();
return;
return;
}
}),
@@ -303,11 +304,12 @@ class EquipmentMasterResource extends Resource
->action(function ($get) {
$equipmentNumber = $get('equipment_number');
if (!$equipmentNumber) {
if (! $equipmentNumber) {
Notification::make()
->title('No equipment number entered')
->danger()
->send();
return;
}
@@ -321,18 +323,19 @@ class EquipmentMasterResource extends Resource
}
}
if (!$fileToDownload) {
if (! $fileToDownload) {
Notification::make()
->title('PDF not found for this equipment')
->danger()
->send();
return;
}
return response()->download(Storage::disk('local')->path($fileToDownload));
}),
])
->columns(2),
->columns(2),
Forms\Components\Hidden::make('created_by')
->label('Created By')
@@ -342,17 +345,17 @@ class EquipmentMasterResource extends Resource
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
Tables\Columns\TextColumn::make('No.')
->label('No.')
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -449,14 +452,14 @@ class EquipmentMasterResource extends Resource
->label('Import Equipment Masters')
->color('warning')
->importer(EquipmentMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import equipment master');
}),
ExportAction::make()
->label('Export Equipment Masters')
->color('warning')
->exporter(EquipmentMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export equipment master');
}),
]);
@@ -489,25 +492,22 @@ class EquipmentMasterResource extends Resource
protected static function calculateNextCalibrationDate(?string $startDateTime, ?string $durationDays): ?string
{
if (!$startDateTime || !$durationDays) {
if (! $startDateTime || ! $durationDays) {
return null;
}
try
{
try {
$startDateTimeCarbon = Carbon::parse($startDateTime);
$durationDays = str_replace(',', '.', $durationDays);
if(!is_numeric($durationDays))
{
if (! is_numeric($durationDays)) {
return null;
}
$nextCalibrationDate = $startDateTimeCarbon->addDays(floatval($durationDays));
return $nextCalibrationDate->format('Y-m-d H:i:s');
}
catch (\Exception $e)
{
} catch (\Exception $e) {
return null;
}
}

View File

@@ -5,33 +5,28 @@ namespace App\Filament\Resources;
use App\Filament\Exports\GrMasterExporter;
use App\Filament\Imports\GrMasterImporter;
use App\Filament\Resources\GrMasterResource\Pages;
use App\Filament\Resources\GrMasterResource\RelationManagers;
use App\Models\GrMaster;
use App\Models\Item;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Notifications\Notification;
use Filament\Forms\Components\Actions\Action;
use Storage;
use Smalot\PdfParser\Parser;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
use thiagoalessio\TesseractOCR\TesseractOCR;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Smalot\PdfParser\Parser;
use Storage;
use thiagoalessio\TesseractOCR\TesseractOCR;
class GrMasterResource extends Resource
{
@@ -39,6 +34,8 @@ class GrMasterResource extends Resource
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Process Order';
public static function form(Form $form): Form
{
return $form
@@ -49,12 +46,13 @@ class GrMasterResource extends Resource
->relationship('plant', 'name')
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')
->label('Item Code')
//->relationship('item', 'id')
// ->relationship('item', 'id')
->reactive()
->searchable()
->options(function (callable $get) {
@@ -62,6 +60,7 @@ class GrMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
})
->required(),
@@ -72,9 +71,9 @@ class GrMasterResource extends Resource
Forms\Components\TextInput::make('serial_number')
->label('Serial Number')
->rule(function (callable $get) {
return Rule::unique('gr_masters', 'serial_number')
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
return Rule::unique('gr_masters', 'serial_number')
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\FileUpload::make('attachment')
@@ -91,8 +90,7 @@ class GrMasterResource extends Resource
->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment');
if (is_array($uploadedFiles) && count($uploadedFiles) > 0)
{
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
$uploaded = reset($uploadedFiles);
if ($uploaded instanceof TemporaryUploadedFile) {
@@ -100,8 +98,8 @@ class GrMasterResource extends Resource
$safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// $originalName = $uploaded->getClientOriginalName();
// $path = 'uploads/GRNumber/' . $originalName;
$finalFileName = $safeName . '.pdf';
$finalPath = 'uploads/GRNumber/' . $finalFileName;
$finalFileName = $safeName.'.pdf';
$finalPath = 'uploads/GRNumber/'.$finalFileName;
if (Storage::disk('local')->exists($finalPath)) {
Notification::make()
@@ -109,6 +107,7 @@ class GrMasterResource extends Resource
->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
->warning()
->send();
return; // Stop here
}
@@ -118,15 +117,14 @@ class GrMasterResource extends Resource
'local'
);
// $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/' . $storedPath);
$parser = new Parser();
//$pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
// $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/'.$storedPath);
$parser = new Parser;
// $pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
$pdf = $parser->parseFile($fullPath);
$text = $pdf->getText();
//dd($text);
// dd($text);
if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) {
$item1 = $matches[1];
@@ -136,8 +134,7 @@ class GrMasterResource extends Resource
// $item2 = $matches[1];
// dd($item2);
// }
else
{
else {
Notification::make()
->title('Item Code Not Found')
->body('Could not find Item code in uploaded PDF.')
@@ -147,6 +144,7 @@ class GrMasterResource extends Resource
if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath);
}
return;
}
@@ -160,21 +158,19 @@ class GrMasterResource extends Resource
$plant = Plant::find($plant);
if ($item)
{
if ($item) {
$itemCode = $item->code;
}
else
{
} else {
$itemCode = null;
Notification::make()
->title('Item Not Found')
->body("Item not found in uploaded pdf.")
->body('Item not found in uploaded pdf.')
->warning()
->send();
if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath);
}
return;
}
@@ -184,220 +180,219 @@ class GrMasterResource extends Resource
'local'
);
if($itemCode == $item1)
{
if ($itemCode == $item1) {
Notification::make()
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
return;
}
else
{
} else {
Notification::make()
->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
->danger()
->send();
->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
->danger()
->send();
if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath);
}
return;
}
}
}
else
{
} else {
Notification::make()
->title('No file selected to upload')
->warning()
->send();
return;
return;
}
}),
// Action::make('uploadNow1')
// ->label('Upload OCR')
// ->action(function ($get, callable $set) {
// $uploadedFiles = $get('photo');
// Action::make('uploadNow1')
// ->label('Upload OCR')
// ->action(function ($get, callable $set) {
// $uploadedFiles = $get('photo');
// if (is_array($uploadedFiles) && count($uploadedFiles) > 0)
// {
// $uploaded = reset($uploadedFiles);
// if (is_array($uploadedFiles) && count($uploadedFiles) > 0)
// {
// $uploaded = reset($uploadedFiles);
// if ($uploaded instanceof TemporaryUploadedFile) {
// $grNumber = $get('gr_number');
// $safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// // $originalName = $uploaded->getClientOriginalName();
// // $path = 'uploads/GRNumber/' . $originalName;
// $finalFileName = $safeName . '.jpg';
// $finalPath = 'uploads/OCR/' . $finalFileName;
// if ($uploaded instanceof TemporaryUploadedFile) {
// $grNumber = $get('gr_number');
// $safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// // $originalName = $uploaded->getClientOriginalName();
// // $path = 'uploads/GRNumber/' . $originalName;
// $finalFileName = $safeName . '.jpg';
// $finalPath = 'uploads/OCR/' . $finalFileName;
// // if (Storage::disk('local')->exists($finalPath)) {
// // Notification::make()
// // ->title('Duplicate File')
// // ->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
// // ->warning()
// // ->send();
// // return; // Stop here
// // }
// // if (Storage::disk('local')->exists($finalPath)) {
// // Notification::make()
// // ->title('Duplicate File')
// // ->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
// // ->warning()
// // ->send();
// // return; // Stop here
// // }
// $storedPath = $uploaded->storeAs(
// 'uploads/OCR',
// $finalFileName,
// 'local'
// );
// $storedPath = $uploaded->storeAs(
// 'uploads/OCR',
// $finalFileName,
// 'local'
// );
// // $storedPath = $uploaded->storeAs('uploads/OCR', $finalFileName, 'local');
// // $fullPath = storage_path('app/' . $storedPath);
// $storedPath = $uploaded->storeAs('uploads/OCR', $finalFileName, 'local');
// // $storedPath = $uploaded->storeAs('uploads/OCR', $finalFileName, 'local');
// // $fullPath = storage_path('app/' . $storedPath);
// $storedPath = $uploaded->storeAs('uploads/OCR', $finalFileName, 'local');
// $fullPath = storage_path('app/private/' . $storedPath);
// $fullPath = storage_path('app/private/' . $storedPath);
// $text = (new TesseractOCR($fullPath))->lang('eng')->run();
// $text = (new TesseractOCR($fullPath))->lang('eng')->run();
// $rawText = $text;
// $rawText = $text;
// preg_match_all('/\d+/', $rawText, $matches);
// preg_match_all('/\d+/', $rawText, $matches);
// $serialNumbers = $matches[0];
// $serialNumbers = $matches[0];
// $serialNumbers = array_slice($serialNumbers, 0, 4);
// $serialNumbers = array_slice($serialNumbers, 0, 4);
// //dd($serialNumbers);
// //dd($serialNumbers);
// $processOrder = $get('gr_number');
// $processOrder = $get('gr_number');
// $itemId = $get('item_id');
// $itemId = $get('item_id');
// $plant = $get('plant_id');
// $plant = $get('plant_id');
// $item = Item::find($itemId);
// $item = Item::find($itemId);
// $plant = Plant::find($plant);
// $plant = Plant::find($plant);
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/multi.pdf');
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/multi.pdf');
// $outputPath = storage_path('app/private/uploads/StickerTemplateOcr/multi_filled.pdf');
// $outputPath = storage_path('app/private/uploads/StickerTemplateOcr/multi_filled.pdf');
// $storedPath = $uploaded->storeAs(
// 'uploads/GRNumber',
// $finalFileName,
// 'local'
// );
// $storedPath = $uploaded->storeAs(
// 'uploads/GRNumber',
// $finalFileName,
// 'local'
// );
// $pdf = new Fpdi('P', 'mm', [90, 90]);
// $pdf = new Fpdi('P', 'mm', [90, 90]);
// $templateId = $pdf->setSourceFile($templatePath);
// $templatePage = $pdf->importPage(1);
// $templateId = $pdf->setSourceFile($templatePath);
// $templatePage = $pdf->importPage(1);
// $pdf->AddPage();
// $pdf->useTemplate($templatePage, 0, 0, 90, 90);
// $pdf->AddPage();
// $pdf->useTemplate($templatePage, 0, 0, 90, 90);
// $pdf->SetFont('Helvetica', '', 10);
// $pdf->SetTextColor(0, 0, 0);
// $pdf->SetFont('Helvetica', '', 10);
// $pdf->SetTextColor(0, 0, 0);
// $slots = [
// ['x' => 5.7, 'y' => 41.9, 'w' => 46.5, 'h' => 3.5], // 1st serial
// ['x' => 50, 'y' => 41.5, 'w' => 46.6, 'h' => 3.9], // 2nd serial
// ['x' => 5.7, 'y' => 60, 'w' => 46.5, 'h' => 3.5], // 3rd serial
// ['x' => 50, 'y' => 60, 'w' => 46.6, 'h' => 3.5], // 4rd serial
// ];
// $slots = [
// ['x' => 5.7, 'y' => 41.9, 'w' => 46.5, 'h' => 3.5], // 1st serial
// ['x' => 50, 'y' => 41.5, 'w' => 46.6, 'h' => 3.9], // 2nd serial
// ['x' => 5.7, 'y' => 60, 'w' => 46.5, 'h' => 3.5], // 3rd serial
// ['x' => 50, 'y' => 60, 'w' => 46.6, 'h' => 3.5], // 4rd serial
// ];
// $qrSlots = [
// ['x' => 17.3, 'y' => 29.2, 'size' => 11.4],
// ['x' => 61.5, 'y' => 29, 'size' => 11.5],
// ['x' => 17.7, 'y' => 46.7, 'size' => 11.4],
// ['x' => 61.7, 'y' => 46.7, 'size' => 11.4],
// ];
// $qrSlots = [
// ['x' => 17.3, 'y' => 29.2, 'size' => 11.4],
// ['x' => 61.5, 'y' => 29, 'size' => 11.5],
// ['x' => 17.7, 'y' => 46.7, 'size' => 11.4],
// ['x' => 61.7, 'y' => 46.7, 'size' => 11.4],
// ];
// // foreach ($serialNumbers as $i => $serial) {
// // if (isset($slots[$i])) {
// // $pdf->SetFillColor(255, 255, 255); // erase old serial
// // $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// // // $pdf->Write(0, $serial);
// // $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// // }
// // }
// // foreach ($serialNumbers as $i => $serial) {
// // if (isset($slots[$i])) {
// // $pdf->SetFillColor(255, 255, 255); // erase old serial
// // $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// // // $pdf->Write(0, $serial);
// // $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// // }
// // }
// // $pdf->Output('F', $outputPath);
// // return response()->download($outputPath);
// // $pdf->Output('F', $outputPath);
// // return response()->download($outputPath);
// //
// //
// // foreach ($serialNumbers as $i => $serial) {
// // if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
// // foreach ($serialNumbers as $i => $serial) {
// // if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
// // //Generate QR code PNG temporarily
// // $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
// // QrCode::format('png')->size(100)->generate($serial, $qrPath);
// // //Generate QR code PNG temporarily
// // $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
// // QrCode::format('png')->size(100)->generate($serial, $qrPath);
// // //Place QR code above serial
// // $pdf->Image($qrPath, $qrSlots[$i]['x'], $qrSlots[$i]['y'], $qrSlots[$i]['size'], $qrSlots[$i]['size']);
// // //Place QR code above serial
// // $pdf->Image($qrPath, $qrSlots[$i]['x'], $qrSlots[$i]['y'], $qrSlots[$i]['size'], $qrSlots[$i]['size']);
// // //Erase old serial
// // $pdf->SetFillColor(255, 255, 255);
// // $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // //Erase old serial
// // $pdf->SetFillColor(255, 255, 255);
// // $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // //Write new serial number
// // $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// // $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// // }
// // //Write new serial number
// // $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// // $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// // }
// foreach ($serialNumbers as $i => $serial) {
// if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
// foreach ($serialNumbers as $i => $serial) {
// if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
// // Erase old QR completely (slightly larger)
// $pdf->SetFillColor(255, 255, 255);
// $pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F');
// // Erase old QR completely (slightly larger)
// $pdf->SetFillColor(255, 255, 255);
// $pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F');
// // Generate new QR code
// $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
// $qrDir = storage_path('app/private/uploads/QR');
// if (!file_exists($qrDir)) mkdir($qrDir, 0777, true);
// QrCode::format('png')->size(100)->generate($serial, $qrPath);
// // Generate new QR code
// $qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
// $qrDir = storage_path('app/private/uploads/QR');
// if (!file_exists($qrDir)) mkdir($qrDir, 0777, true);
// QrCode::format('png')->size(100)->generate($serial, $qrPath);
// // Place QR code
// $pdf->Image($qrPath, $qrSlots[$i]['x'], $qrSlots[$i]['y'], $qrSlots[$i]['size'], $qrSlots[$i]['size']);
// // Place QR code
// $pdf->Image($qrPath, $qrSlots[$i]['x'], $qrSlots[$i]['y'], $qrSlots[$i]['size'], $qrSlots[$i]['size']);
// // Erase old serial
// $pdf->SetFillColor(255, 255, 255);
// $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // Erase old serial
// $pdf->SetFillColor(255, 255, 255);
// $pdf->Rect($slots[$i]['x'], $slots[$i]['y'], $slots[$i]['w'], $slots[$i]['h'], 'F');
// // Write new serial
// $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// }
// // Write new serial
// $pdf->SetXY($slots[$i]['x'], $slots[$i]['y']);
// $pdf->Cell($slots[$i]['w'], $slots[$i]['h'], $serial, 0, 0, 'L');
// }
// // Save the final PDF
// $pdf->Output('F', $outputPath);
// // Save the final PDF
// $pdf->Output('F', $outputPath);
// // Download
// return response()->download($outputPath);
// }
// }
// else
// {
// Notification::make()
// ->title('No file selected to upload')
// ->warning()
// ->send();
// return;
// }
// }),
// // Download
// return response()->download($outputPath);
// }
// }
// else
// {
// Notification::make()
// ->title('No file selected to upload')
// ->warning()
// ->send();
// return;
// }
// }),
Action::make('downloadAttachment')
->label('Download PDF')
->action(function ($get) {
$equipmentNumber = $get('gr_number');
if (!$equipmentNumber) {
if (! $equipmentNumber) {
Notification::make()
->title('No GR Number entered')
->danger()
->send();
return;
}
@@ -411,17 +406,18 @@ class GrMasterResource extends Resource
}
}
if (!$fileToDownload) {
if (! $fileToDownload) {
Notification::make()
->title('PDF not found for this process order')
->danger()
->send();
return;
}
return response()->download(Storage::disk('local')->path($fileToDownload));
}),
]),
]),
Forms\Components\Hidden::make('created_by')
->label('Created By')
->default(Filament::auth()->user()?->name),
@@ -440,6 +436,7 @@ class GrMasterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -506,14 +503,14 @@ class GrMasterResource extends Resource
->label('Import GR Masters')
->color('warning')
->importer(GrMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import gr master');
}),
ExportAction::make()
->label('Export GR Masters')
->color('warning')
->exporter(GrMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export gr master');
}),
]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\GuardNameExporter;
use App\Filament\Imports\GuardNameImporter;
use App\Filament\Resources\GuardNameResource\Pages;
use App\Filament\Resources\GuardNameResource\RelationManagers;
use App\Models\GuardName;
use App\Models\Plant;
use Filament\Facades\Filament;
@@ -42,20 +41,20 @@ class GuardNameResource extends Resource
->reactive()
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(GuardName::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('GnError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('GnError', null);
$set('created_by', Filament::auth()->user()?->name);
}
@@ -113,6 +112,7 @@ class GuardNameResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
// Tables\Columns\TextColumn::make('id')
@@ -169,14 +169,14 @@ class GuardNameResource extends Resource
->label('Import Guard Names')
->color('warning')
->importer(GuardNameImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import guard name');
}),
ExportAction::make()
->label('Export Guard Names')
->color('warning')
->exporter(GuardNameExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export guard name');
}),
]);

View File

@@ -53,7 +53,7 @@ class GuardPatrolEntryResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id;

View File

@@ -4,24 +4,21 @@ namespace App\Filament\Resources;
use App\Filament\Exports\InvoiceInTransitExporter;
use App\Filament\Resources\InvoiceInTransitResource\Pages;
use App\Filament\Resources\InvoiceInTransitResource\RelationManagers;
use App\Models\InvoiceInTransit;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\FileUpload;
use Storage;
use Maatwebsite\Excel\Facades\Excel;
use Filament\Tables\Actions\ExportAction;
use Carbon\Carbon;
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
use Storage;
class InvoiceInTransitResource extends Resource
{
@@ -37,6 +34,11 @@ class InvoiceInTransitResource extends Resource
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\TextInput::make('receiving_plant')
->label('Receiving Plant'),
@@ -272,8 +274,7 @@ class InvoiceInTransitResource extends Resource
$fullPath = Storage::disk('local')->path($path);
if ($fullPath && file_exists($fullPath))
{
if ($fullPath && file_exists($fullPath)) {
$rows = Excel::toArray(null, $fullPath)[0];
if ((count($rows) - 1) <= 0) {
@@ -305,7 +306,6 @@ class InvoiceInTransitResource extends Resource
$invalidLRBLAWDt = [];
$invalidPenDay = [];
foreach ($rows as $index => $row) {
if ($index == 0) {
continue;
@@ -369,7 +369,7 @@ class InvoiceInTransitResource extends Resource
$plant = Plant::where('code', $plantCode)->first();
//$plantId = $plant->id;
// $plantId = $plant->id;
}
@@ -470,8 +470,7 @@ class InvoiceInTransitResource extends Resource
return;
}
foreach ($rows as $index => $row)
{
foreach ($rows as $index => $row) {
if ($index == 0) {
continue;
}
@@ -504,8 +503,7 @@ class InvoiceInTransitResource extends Resource
throw new \Exception("Invalid plant code : '{$plantCode}'");
}
if (! empty($invoiceDt))
{
if (! empty($invoiceDt)) {
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $invoiceDt)) {
[$day, $month, $year] = preg_split('/[-\/]/', $invoiceDt);
$formattedDate = "{$year}-{$month}-{$day}";
@@ -517,8 +515,7 @@ class InvoiceInTransitResource extends Resource
} else {
$formattedDate = null;
}
if (! empty($LRBAWDt))
{
if (! empty($LRBAWDt)) {
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $LRBAWDt)) {
[$day, $month, $year] = preg_split('/[-\/]/', $LRBAWDt);
$formattedDt = "{$year}-{$month}-{$day}";
@@ -530,8 +527,7 @@ class InvoiceInTransitResource extends Resource
} else {
$formattedDt = null;
}
if (! empty($OBDDate))
{
if (! empty($OBDDate)) {
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) {
[$day, $month, $year] = preg_split('/[-\/]/', $OBDDate);
$formattedDate = "{$year}-{$month}-{$day}";
@@ -577,15 +573,15 @@ class InvoiceInTransitResource extends Resource
->body('Invoice in transit uploaded successfully!')
->success()
->send();
return;
}
else
{
} else {
Notification::make()
->title('Insertion Failed')
->body('Invoice in transit upload failed!')
->success()
->send();
return;
}
}

View File

@@ -56,7 +56,7 @@ class ItemResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Item::latest()->first())->plant_id;
@@ -251,7 +251,7 @@ class ItemResource extends Resource
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->orderBy('code')->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {
@@ -394,7 +394,7 @@ class ItemResource extends Resource
// // ->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();
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
// })
// ->label('Select Plant')
// ->required()

File diff suppressed because it is too large Load Diff

View File

@@ -48,7 +48,7 @@ class LocatorResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Locator::latest()->first())->plant_id;
@@ -194,7 +194,7 @@ class LocatorResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -45,7 +45,7 @@ class MachineResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Machine::latest()->first())->plant_id;

View File

@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MfmMeterExporter;
use App\Filament\Imports\MfmMeterImporter;
use App\Filament\Resources\MfmMeterResource\Pages;
use App\Filament\Resources\MfmMeterResource\RelationManagers;
use App\Models\DeviceMaster;
use App\Models\MfmMeter;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmMeterResource extends Resource
{
@@ -34,35 +33,37 @@ class MfmMeterResource extends Resource
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->label('Plant')
->reactive()
->required()
->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();
}),
Forms\Components\Select::make('device_master_id')
//->relationship('device', 'name')
->options(function ($get) {
$plantId = $get('plant_id');
if (!$plantId) {
return [];
}
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
})
->label('Device Name')
->required(),
Forms\Components\TextInput::make('sequence')
->required(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->label('Plant')
->reactive()
->required()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}),
Forms\Components\Select::make('device_master_id')
// ->relationship('device', 'name')
->options(function ($get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
})
->label('Device Name')
->required(),
Forms\Components\TextInput::make('sequence')
->required(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
]);
}
@@ -71,12 +72,13 @@ class MfmMeterResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
Tables\Columns\TextColumn::make('No.')
->label('No.')
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -121,19 +123,19 @@ class MfmMeterResource extends Resource
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
->headerActions([
ImportAction::make()
->label('Import MFM Meters')
->color('warning')
->importer(MfmMeterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import mfm meter');
}),
ExportAction::make()
->label('Export MFM Meters')
->color('warning')
->exporter(MfmMeterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export mfm meter');
}),
]);

View File

@@ -5,127 +5,128 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MfmParameterExporter;
use App\Filament\Imports\MfmParameterImporter;
use App\Filament\Resources\MfmParameterResource\Pages;
use App\Filament\Resources\MfmParameterResource\RelationManagers;
use App\Models\MfmParameter;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmParameterResource extends Resource
{
protected static ?string $model = MfmParameter::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->reactive()
->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();
})
->afterStateUpdated(function (callable $set) {
$set('device_master_id', null);
$set('mfm_meter_id', null);
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->required(),
Forms\Components\Select::make('device_master_id')
->label('Device Master')
//->relationship('deviceName', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
if (!$plantId) {
return [];
}
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function (callable $set) {
$set('device_master_id', null);
$set('mfm_meter_id', null);
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->required(),
Forms\Components\Select::make('device_master_id')
->label('Device Master')
// ->relationship('deviceName', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
return \App\Models\DeviceMaster::where('plant_id', $plantId)
->pluck('name', 'id');
})
->afterStateUpdated(function (callable $set) {
$set('mfm_meter_id', null);
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->reactive()
->required(),
Forms\Components\Select::make('mfm_meter_id')
->label('Mfm Meter')
// ->relationship('mfmMeter', 'sequence')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
if (!$plantId) {
return [];
}
return \App\Models\DeviceMaster::where('plant_id', $plantId)
->pluck('name', 'id');
})
->afterStateUpdated(function (callable $set) {
$set('mfm_meter_id', null);
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->reactive()
->required(),
Forms\Components\Select::make('mfm_meter_id')
->label('Mfm Meter')
// ->relationship('mfmMeter', 'sequence')
->options(function (callable $get) {
$plantId = $get('plant_id');
return \App\Models\MfmMeter::where('plant_id', $plantId)
->pluck('sequence', 'id');
})
->afterStateUpdated(function (callable $set) {
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->reactive()
->required(),
Forms\Components\TextInput::make('name')
->label('Parameter Name')
->reactive()
->required(),
Forms\Components\TextInput::make('register_id')
->label('Register ID')
->reactive()
->required(),
Forms\Components\TextInput::make('identifier')
->label('Identifier')
->reactive()
->required(),
Forms\Components\TextInput::make('byte_to_convert')
->label('Byte To Convert')
->reactive()
->default(2)
->required(),
Forms\Components\TextInput::make('type_to_convert')
->label('Type To Convert')
->required(),
Forms\Components\TextInput::make('decimal_to_display')
->label('Decimal To Display')
->reactive()
->default(1)
->required(),
if (! $plantId) {
return [];
}
return \App\Models\MfmMeter::where('plant_id', $plantId)
->pluck('sequence', 'id');
})
->afterStateUpdated(function (callable $set) {
$set('name', null);
$set('register_id', null);
$set('identifier', null);
$set('byte_to_convert', null);
$set('type_to_convert', null);
$set('decimal_to_display', null);
})
->reactive()
->required(),
Forms\Components\TextInput::make('name')
->label('Parameter Name')
->reactive()
->required(),
Forms\Components\TextInput::make('register_id')
->label('Register ID')
->reactive()
->required(),
Forms\Components\TextInput::make('identifier')
->label('Identifier')
->reactive()
->required(),
Forms\Components\TextInput::make('byte_to_convert')
->label('Byte To Convert')
->reactive()
->default(2)
->required(),
Forms\Components\TextInput::make('type_to_convert')
->label('Type To Convert')
->required(),
Forms\Components\TextInput::make('decimal_to_display')
->label('Decimal To Display')
->reactive()
->default(1)
->required(),
])
->columns(3),
->columns(3),
]);
}
@@ -139,6 +140,7 @@ class MfmParameterResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -212,14 +214,14 @@ class MfmParameterResource extends Resource
->label('Import MFM Parameters')
->color('warning')
->importer(MfmParameterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import mfm parameter');
}),
ExportAction::make()
->label('Export MFM Parameters')
->color('warning')
->exporter(MfmParameterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export mfm parameter');
}),
]);

View File

@@ -3,7 +3,6 @@
namespace App\Filament\Resources;
use App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource\RelationManagers;
use App\Models\MfmReading;
use App\Models\Plant;
use Filament\Facades\Filament;
@@ -31,7 +30,8 @@ class MfmReadingResource extends Resource
->relationship('plant', 'name')
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('mfm_meter_id')
@@ -72,6 +72,7 @@ class MfmReadingResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -127,9 +128,9 @@ class MfmReadingResource extends Resource
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_y')
->label('Current Y')
->alignCenter()
->sortable(),
->label('Current Y')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_b')
->label('Current B')
->alignCenter()

View File

@@ -49,7 +49,7 @@ class MotorTestingMasterResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(MotorTestingMaster::latest()->first())->plant_id;
@@ -466,7 +466,7 @@ class MotorTestingMasterResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -3,36 +3,36 @@
namespace App\Filament\Resources;
use App\Filament\Resources\OcrValidationResource\Pages;
use App\Filament\Resources\OcrValidationResource\RelationManagers;
use App\Models\Item;
use App\Models\OcrValidation;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use thiagoalessio\TesseractOCR\TesseractOCR;
use setasign\Fpdi\Fpdi;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions\Action;
use Filament\Notifications\Notification;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use setasign\Fpdi\PdfReader;
use setasign\Fpdi\Fpdi;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Storage;
use Filament\Forms\Concerns\InteractsWithForms;
use Smalot\PdfParser\Parser;
use Storage;
class OcrValidationResource extends Resource
{
protected static ?string $model = OcrValidation::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-s-qr-code';
protected static ?string $navigationGroup = 'OCR';
public $camera_capture;
public $serialNumbers = [];
use InteractsWithForms;
@@ -47,12 +47,13 @@ class OcrValidationResource extends Resource
->relationship('plant', 'name')
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')
->label('Item Code')
//->relationship('item', 'id')
->label('Item Code')
// ->relationship('item', 'id')
->reactive()
->searchable()
->options(function (callable $get) {
@@ -60,6 +61,7 @@ class OcrValidationResource extends Resource
if (empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
})
->required(),
@@ -109,13 +111,12 @@ class OcrValidationResource extends Resource
->preserveFilenames()
->reactive(),
Forms\Components\Actions::make([
Action::make('uploadNow')
Action::make('uploadNow')
->label('Upload PDF Now')
->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment');
if (is_array($uploadedFiles) && count($uploadedFiles) > 0)
{
if (is_array($uploadedFiles) && count($uploadedFiles) > 0) {
$uploaded = reset($uploadedFiles);
if ($uploaded instanceof TemporaryUploadedFile) {
@@ -123,8 +124,8 @@ class OcrValidationResource extends Resource
$safeName = preg_replace('/[^A-Za-z0-9_\-]/', '_', $grNumber);
// $originalName = $uploaded->getClientOriginalName();
// $path = 'uploads/GRNumber/' . $originalName;
$finalFileName = $safeName . '.pdf';
$finalPath = 'uploads/OcrGrNumber/' . $finalFileName;
$finalFileName = $safeName.'.pdf';
$finalPath = 'uploads/OcrGrNumber/'.$finalFileName;
if (Storage::disk('local')->exists($finalPath)) {
Notification::make()
@@ -132,6 +133,7 @@ class OcrValidationResource extends Resource
->body("The file '{$finalFileName}' already exists in uploads/GRNumber.")
->warning()
->send();
return;
}
@@ -141,26 +143,22 @@ class OcrValidationResource extends Resource
'local'
);
// $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/' . $storedPath);
$parser = new Parser();
//$pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
// $fullPath = storage_path('app/' . $storedPath);
$fullPath = storage_path('app/private/'.$storedPath);
$parser = new Parser;
// $pdf = $parser->parseContent(file_get_contents($uploaded->getRealPath()));
$pdf = $parser->parseFile($fullPath);
$text = $pdf->getText();
// dd($text);
// dd($text);
//dd($text);
// dd($text);
$item1 = null;
$item2 = null;
if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches))
{
if (preg_match('/Item code\s*:\s*(\S+)/i', $text, $matches)) {
$item1 = $matches[1];
}
else if (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches))
{
} elseif (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches)) {
$item2 = $matches[1];
}
@@ -174,21 +172,19 @@ class OcrValidationResource extends Resource
$plant = Plant::find($plant);
if ($item)
{
if ($item) {
$itemCode = $item->code;
}
else
{
} else {
$itemCode = null;
Notification::make()
->title('Item Not Found')
->body("Item not found in uploaded pdf.")
->body('Item not found in uploaded pdf.')
->warning()
->send();
if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath);
}
return;
}
@@ -198,50 +194,48 @@ class OcrValidationResource extends Resource
'local'
);
if($itemCode == $item1)
{
if ($itemCode == $item1) {
Notification::make()
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
return;
}
if($itemCode == $item2)
{
if ($itemCode == $item2) {
Notification::make()
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
->title('Success')
->body("Gr Number '$processOrder' PDF uploaded successfully.")
->success()
->send();
return;
}
else
{
} else {
Notification::make()
->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
->danger()
->send();
->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
->danger()
->send();
if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath);
}
return;
}
}
}
else
{
} else {
Notification::make()
->title('No file selected to upload')
->warning()
->send();
return;
return;
}
}),
Action::make('uploadNow1')
Action::make('uploadNow1')
->label('Upload OCR')
->action(function ($get, callable $set) {
@@ -256,25 +250,25 @@ class OcrValidationResource extends Resource
->title('Serial numbers cannot be empty!')
->danger()
->send();
return;
}
//$serialNumbers = array_slice($serialNumbers, 0, 4);
// $serialNumbers = array_slice($serialNumbers, 0, 4);
if (count($serials) == 1)
{
if (count($serials) == 1) {
$serialNumbers = $serials;
$grNumber = trim($grNumber);
//$templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
$templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf");
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
$templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf");
if(!file_exists($templatePath))
{
if (! file_exists($templatePath)) {
Notification::make()
->title("Template PDF not found for the Gr Number $grNumber.")
->danger()
->send();
return;
}
@@ -300,17 +294,21 @@ class OcrValidationResource extends Resource
];
foreach ($serialNumbers as $i => $serial) {
if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
if (! isset($slots[$i]) || ! isset($qrSlots[$i])) {
continue;
}
// Erase old QR completely (slightly larger)
$pdf->SetFillColor(255, 255, 255);
$pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F');
$pdf->Rect($qrSlots[$i]['x'] - 1, $qrSlots[$i]['y'] - 1, $qrSlots[$i]['size'] + 2, $qrSlots[$i]['size'] + 2, 'F');
// Generate new QR code
$qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
$qrDir = storage_path('app/private/uploads/QR');
if (!file_exists($qrDir)) mkdir($qrDir, 0777, true);
//QrCode::format('svg')->size(100)->generate($serial, $qrPath);
if (! file_exists($qrDir)) {
mkdir($qrDir, 0777, true);
}
// QrCode::format('svg')->size(100)->generate($serial, $qrPath);
QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath);
// Place QR code
@@ -331,12 +329,11 @@ class OcrValidationResource extends Resource
// Download
return response()->download($outputPath);
}
if(count($serials) == 4)
{
if (count($serials) == 4) {
$serialNumbers = array_slice($serials, 0, 4);
//dd($serialNumbers);
// dd($serialNumbers);
$itemId = $get('item_id');
@@ -348,19 +345,19 @@ class OcrValidationResource extends Resource
$grNumber = trim($grNumber);
//$templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/Single.pdf');
$templatePath = storage_path("app/private/uploads/OcrGrNumber/{$grNumber}.pdf");
// $templatePath = storage_path('app/private/uploads/StickerTemplateOcr/multi.pdf');
//$templatePath = storage_path("app/private/uploads/OcrGrNumber/'$grNumber'.pdf");
// $templatePath = storage_path("app/private/uploads/OcrGrNumber/'$grNumber'.pdf");
if(!file_exists($templatePath))
{
if (! file_exists($templatePath)) {
Notification::make()
->title("Template PDF not found for the Gr Number $grNumber.")
->danger()
->send();
return;
}
@@ -398,17 +395,21 @@ class OcrValidationResource extends Resource
];
foreach ($serialNumbers as $i => $serial) {
if (!isset($slots[$i]) || !isset($qrSlots[$i])) continue;
if (! isset($slots[$i]) || ! isset($qrSlots[$i])) {
continue;
}
// Erase old QR completely (slightly larger)
$pdf->SetFillColor(255, 255, 255);
$pdf->Rect($qrSlots[$i]['x']-1, $qrSlots[$i]['y']-1, $qrSlots[$i]['size']+2, $qrSlots[$i]['size']+2, 'F');
$pdf->Rect($qrSlots[$i]['x'] - 1, $qrSlots[$i]['y'] - 1, $qrSlots[$i]['size'] + 2, $qrSlots[$i]['size'] + 2, 'F');
// Generate new QR code
$qrPath = storage_path("app/private/uploads/QR/qr_$serial.png");
$qrDir = storage_path('app/private/uploads/QR');
if (!file_exists($qrDir)) mkdir($qrDir, 0777, true);
//QrCode::format('svg')->size(100)->generate($serial, $qrPath);
if (! file_exists($qrDir)) {
mkdir($qrDir, 0777, true);
}
// QrCode::format('svg')->size(100)->generate($serial, $qrPath);
QrCode::format('png')->size(300)->errorCorrection('H')->generate($serial, $qrPath);
// Place QR code
@@ -428,13 +429,12 @@ class OcrValidationResource extends Resource
// Download
return response()->download($outputPath);
}
else
{
} else {
Notification::make()
->title('Please capture either 1 or 4 serial numbers.')
->danger()
->send();
return;
}
}),
@@ -443,11 +443,12 @@ class OcrValidationResource extends Resource
->action(function ($get) {
$equipmentNumber = $get('gr_number');
if (!$equipmentNumber) {
if (! $equipmentNumber) {
Notification::make()
->title('No GR Number entered')
->danger()
->send();
return;
}
@@ -461,16 +462,18 @@ class OcrValidationResource extends Resource
}
}
if (!$fileToDownload) {
if (! $fileToDownload) {
Notification::make()
->title('PDF not found for this process order')
->danger()
->send();
return;
}
return response()->download(Storage::disk('local')->path($fileToDownload));
}),
]),
]),
Forms\Components\Field::make('camera_capture')
->view('fields.camera-capture'),
Forms\Components\Hidden::make('created_by')
@@ -481,7 +484,6 @@ class OcrValidationResource extends Resource
]);
}
public static function table(Table $table): Table
{
return $table

View File

@@ -49,7 +49,7 @@ class PalletValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', null);
@@ -279,7 +279,7 @@ class PalletValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {
@@ -529,7 +529,7 @@ class PalletValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required()
->reactive()

View File

@@ -55,7 +55,7 @@ class ProductionLineStopResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(ProductionLineStop::latest()->first())->plant_id;
@@ -430,7 +430,7 @@ class ProductionLineStopResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -54,7 +54,7 @@ class ProductionPlanResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id;
@@ -576,7 +576,7 @@ class ProductionPlanResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -63,7 +63,7 @@ class ProductionQuantityResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () {
@@ -1035,7 +1035,7 @@ class ProductionQuantityResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -56,7 +56,7 @@ class QualityValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function (callable $set, callable $get, $state) {
$set('item_id', null);
@@ -3015,7 +3015,7 @@ class QualityValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -53,7 +53,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
@@ -456,7 +456,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -55,7 +55,7 @@ class SerialValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(SerialValidation::latest()->first())->plant_id;
@@ -332,7 +332,7 @@ class SerialValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->label('Select Plant')
->required()
@@ -1038,7 +1038,7 @@ class SerialValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -10,16 +10,16 @@ use App\Models\Shift;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
class ShiftResource extends Resource
@@ -39,232 +39,229 @@ class ShiftResource extends Resource
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->relationship('plant', 'name')
->required()
// ->nullable()
->reactive()
->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();
})
->default(function () {
return optional(Shift::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Shift::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('block_id', null);
if (!$plantId) {
$set('sPlantError', 'Please select a plant first.');
return;
}
else
{
$set('sPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sPlantError') ? $get('sPlantError') : null)
->hintColor('danger'),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required()
// ->nullable()
->reactive()
->default(function () {
return optional(Shift::latest()->first())->block_id;
})
// ->disabled(fn (Get $get) => !empty($get('id')))
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id')) {
return [];
}
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('block_id', null);
if (! $plantId) {
$set('sPlantError', 'Please select a plant first.');
return \App\Models\Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
// ->afterStateUpdated(fn ($set) => $set('name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$blockId = $get('block_id');
$set('name', null);
if (!$blockId) {
$set('sBlockError', 'Please select a block first.');
return;
}
else
{
$set('sBlockError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sBlockError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sBlockError') ? $get('sBlockError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->placeholder('Scan the valid name')
->autofocus(true)
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name');
$set('start_time', null);
if (!$nameId) {
$set('sNameError', 'Scan the valid name.');
return;
}
else
{
// $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id'))
// ->where('name', $nameId)
// ->latest()
// ->exists();
// if ($exists)
// {
// $set('start_time', null);
// $set('sNameError', 'Scanned name already exist.');
// return;
// }
$set('sNameError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sNameError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null)
->hintColor('danger')
->rule(function (callable $get) {
return Rule::unique('shifts', 'name')
->where('plant_id', $get('plant_id'))
->where('block_id', $get('block_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TimePicker::make('start_time')
->required()
->label('Start Time')
->live()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($state, $get('duration')))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$startTime = $get('start_time');
$set('duration', null);
$set('end_time', self::calculateEndTime($state, $get('duration')));
if (!$startTime) {
$set('sStartTimeError', 'Choose the valid start time.');
return;
}
else
{
// $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id'))
// ->where('name', $get('name'))
// ->latest()
// ->exists();
// if ($exists)
// {
// $set('start_time', null);
// $set('sStartTimeError', null);
// $set('sNameError', 'Scanned name already exist.');
// return;
// }
$set('sStartTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sStartTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sStartTimeError') ? $get('sStartTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('duration')
->required()
->placeholder('Scan the valid duration')
->numeric()
->inputMode('decimal')
->minValue(0.01) // Minimum valid duration
->lazy()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($get('start_time'), $state))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$duration = $get('duration');
// $set('end_time', null);
$set('end_time', self::calculateEndTime($get('start_time'), $state));
if (!$duration) {
$set('sDurationError', 'Scan the valid duration.');
return;
}
else
{
[$hRs, $miNs] = explode('.', $duration) + [0, 0]; // Ensure two parts
$hRs = (int) $hRs;
$miNs = (int) $miNs;
$set('duration', $hRs.'.'.$miNs);
if ($miNs > 60) {
$set('sDurationError', 'Minutes exceeds 1 hour.');
$set('duration', null);
$set('end_time', null);
return;
} else {
$set('sPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sPlantError') ? $get('sPlantError') : null)
->hintColor('danger'),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required()
// ->nullable()
->reactive()
->default(function () {
return optional(Shift::latest()->first())->block_id;
})
// ->disabled(fn (Get $get) => !empty($get('id')))
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (! $get('plant_id')) {
return [];
}
$totalMinutes = $hRs * 60 + $miNs;
return \App\Models\Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
// ->afterStateUpdated(fn ($set) => $set('name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$blockId = $get('block_id');
$set('name', null);
if (! $blockId) {
$set('sBlockError', 'Please select a block first.');
if ($totalMinutes > 1440) {
$set('sDurationError', 'Duration exceeds 24 hours.');
$set('duration', null);
$set('end_time', null);
return;
} else {
$set('sBlockError', null);
}
$set('sDurationError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sDurationError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sDurationError') ? $get('sDurationError') : null)
->hintColor('danger'),
Forms\Components\TimePicker::make('end_time')
->required()
->label('End Time')
->readOnly()
// ->native(false),
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$endTime = $get('end_time');
$set('end_time', self::calculateEndTime($get('start_time'), $state));
if (!$endTime) {
$set('sEndTimeError', 'Choose the valid start time & duration.');
return;
}
else
{
$set('sEndTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sEndTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sEndTimeError') ? $get('sEndTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
})
->extraAttributes(fn ($get) => [
'class' => $get('sBlockError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sBlockError') ? $get('sBlockError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->placeholder('Scan the valid name')
->autofocus(true)
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name');
$set('start_time', null);
if (! $nameId) {
$set('sNameError', 'Scan the valid name.');
return;
} else {
// $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id'))
// ->where('name', $nameId)
// ->latest()
// ->exists();
// if ($exists)
// {
// $set('start_time', null);
// $set('sNameError', 'Scanned name already exist.');
// return;
// }
$set('sNameError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sNameError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null)
->hintColor('danger')
->rule(function (callable $get) {
return Rule::unique('shifts', 'name')
->where('plant_id', $get('plant_id'))
->where('block_id', $get('block_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TimePicker::make('start_time')
->required()
->label('Start Time')
->live()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($state, $get('duration')))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$startTime = $get('start_time');
$set('duration', null);
$set('end_time', self::calculateEndTime($state, $get('duration')));
if (! $startTime) {
$set('sStartTimeError', 'Choose the valid start time.');
return;
} else {
// $exists = Shift::where('plant_id', $get('plant_id'))
// ->where('block_id', $get('block_id'))
// ->where('name', $get('name'))
// ->latest()
// ->exists();
// if ($exists)
// {
// $set('start_time', null);
// $set('sStartTimeError', null);
// $set('sNameError', 'Scanned name already exist.');
// return;
// }
$set('sStartTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sStartTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sStartTimeError') ? $get('sStartTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('duration')
->required()
->placeholder('Scan the valid duration')
->numeric()
->inputMode('decimal')
->minValue(0.01) // Minimum valid duration
->lazy()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($get('start_time'), $state))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$duration = $get('duration');
// $set('end_time', null);
$set('end_time', self::calculateEndTime($get('start_time'), $state));
if (! $duration) {
$set('sDurationError', 'Scan the valid duration.');
return;
} else {
[$hRs, $miNs] = explode('.', $duration) + [0, 0]; // Ensure two parts
$hRs = (int) $hRs;
$miNs = (int) $miNs;
$set('duration', $hRs.'.'.$miNs);
if ($miNs > 60) {
$set('sDurationError', 'Minutes exceeds 1 hour.');
$set('duration', null);
$set('end_time', null);
return;
}
$totalMinutes = $hRs * 60 + $miNs;
if ($totalMinutes > 1440) {
$set('sDurationError', 'Duration exceeds 24 hours.');
$set('duration', null);
$set('end_time', null);
return;
}
$set('sDurationError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sDurationError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sDurationError') ? $get('sDurationError') : null)
->hintColor('danger'),
Forms\Components\TimePicker::make('end_time')
->required()
->label('End Time')
->readOnly()
// ->native(false),
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$endTime = $get('end_time');
$set('end_time', self::calculateEndTime($get('start_time'), $state));
if (! $endTime) {
$set('sEndTimeError', 'Choose the valid start time & duration.');
return;
} else {
$set('sEndTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sEndTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sEndTimeError') ? $get('sEndTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);
}
@@ -282,6 +279,7 @@ class ShiftResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('name')
@@ -347,14 +345,14 @@ class ShiftResource extends Resource
->label('Import Shifts')
->color('warning')
->importer(ShiftImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import shift');
}),
ExportAction::make()
->label('Export Shifts')
->color('warning')
->exporter(ShiftExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export shift');
}),
]);
@@ -387,7 +385,7 @@ class ShiftResource extends Resource
protected static function calculateEndTime(?string $startTime, ?string $duration): ?string
{
if (!$startTime || !$duration) {
if (! $startTime || ! $duration) {
return null;
}
@@ -397,7 +395,7 @@ class ShiftResource extends Resource
// Ensure duration is in a valid numeric format
$duration = str_replace(',', '.', $duration); // Handle decimal formats
if (!is_numeric($duration)) {
if (! is_numeric($duration)) {
return null; // Invalid duration format
}

View File

@@ -2,6 +2,8 @@
namespace App\Filament\Resources;
use App\Filament\Exports\StickerPrintingExporter;
use App\Filament\Imports\StickerPrintingImporter;
use App\Filament\Resources\StickerPrintingResource\Pages;
use App\Models\Plant;
use App\Models\StickerPrinting;
@@ -11,14 +13,11 @@ use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use App\Filament\Exports\StickerPrintingExporter;
use App\Filament\Imports\StickerPrintingImporter;
use Filament\Forms\Components\Actions\Action;
class StickerPrintingResource extends Resource
{
@@ -40,13 +39,14 @@ class StickerPrintingResource extends Resource
->relationship('plant', 'name')
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
$set('reference_number', null);
$set('serial_number', null);
$set('ivPlantError', 'Please select a plant first.');
@@ -64,7 +64,7 @@ class StickerPrintingResource extends Resource
Forms\Components\TextInput::make('reference_number')
->label('Reference Number')
->reactive()
->readOnly(fn (callable $get) => !empty($get('serial_number')))
->readOnly(fn (callable $get) => ! empty($get('serial_number')))
->extraAttributes([
'id' => 'invoice_number_input',
'x-data' => '{ value: "" }',
@@ -82,9 +82,9 @@ class StickerPrintingResource extends Resource
'x-data' => '{ value: "" }',
'x-model' => 'value',
'wire:keydown.enter.prevent' => 'processSno(value)',
//'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
// 'x-on:keydown.enter.prevent' => '$wire.processInvoice(value)',
]),
//->required(),
// ->required(),
Forms\Components\View::make('forms.components.print-button'),
Forms\Components\Hidden::make('created_by')

View File

@@ -5,28 +5,27 @@ namespace App\Filament\Resources;
use App\Filament\Exports\TempLiveReadingExporter;
use App\Filament\Imports\TempLiveReadingImporter;
use App\Filament\Resources\TempLiveReadingResource\Pages;
use App\Filament\Resources\TempLiveReadingResource\RelationManagers;
use App\Models\MfmMeter;
use App\Models\Plant;
use App\Models\TempLiveReading;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class TempLiveReadingResource extends Resource
{
protected static ?string $model = TempLiveReading::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
@@ -34,37 +33,38 @@ class TempLiveReadingResource extends Resource
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->reactive()
->required()
->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();
}),
Forms\Components\Select::make('mfm_meter_id')
->label('MFM Meter ID')
->required()
->reactive()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
return [];
}
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->reactive()
->required()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return MfmMeter::where('plant_id', $plantId)
->pluck('sequence', 'id')
->toArray();
}),
Forms\Components\TextInput::make('register_data')
->label('Register Data')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}),
Forms\Components\Select::make('mfm_meter_id')
->label('MFM Meter ID')
->required()
->reactive()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
return MfmMeter::where('plant_id', $plantId)
->pluck('sequence', 'id')
->toArray();
}),
Forms\Components\TextInput::make('register_data')
->label('Register Data')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(3),
->columns(3),
]);
}
@@ -78,6 +78,7 @@ class TempLiveReadingResource extends Resource
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
@@ -119,18 +120,18 @@ class TempLiveReadingResource extends Resource
Tables\Actions\RestoreBulkAction::make(),
]),
]);
// ->headerActions([
// ImportAction::make()
// ->importer(TempLiveReadingImporter::class)
// ->visible(function() {
// return Filament::auth()->user()->can('view import temp live reading');
// }),
// ExportAction::make()
// ->exporter(TempLiveReadingExporter::class)
// ->visible(function() {
// return Filament::auth()->user()->can('view export temp live reading');
// }),
// ]);
// ->headerActions([
// ImportAction::make()
// ->importer(TempLiveReadingImporter::class)
// ->visible(function() {
// return Filament::auth()->user()->can('view import temp live reading');
// }),
// ExportAction::make()
// ->exporter(TempLiveReadingExporter::class)
// ->visible(function() {
// return Filament::auth()->user()->can('view export temp live reading');
// }),
// ]);
}
public static function getRelations(): array
@@ -139,6 +140,7 @@ class TempLiveReadingResource extends Resource
//
];
}
public static function getNavigationLabel(): string
{
return 'Live Readings';
@@ -149,7 +151,6 @@ class TempLiveReadingResource extends Resource
return 'Live Readings';
}
public static function getPages(): array
{
return [

View File

@@ -63,7 +63,7 @@ class TestingPanelReadingResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(TestingPanelReading::latest()->first())->plant_id;
@@ -480,7 +480,10 @@ class TestingPanelReadingResource extends Resource
->label('Select Plant')
->nullable()
->options(function () {
return Plant::pluck('name', 'id');
// return Plant::pluck('name', 'id');
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -47,7 +47,7 @@ class WeightValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required(),
Forms\Components\Select::make('item_id')
@@ -168,7 +168,7 @@ class WeightValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -406,7 +406,7 @@ class WeightValidationResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->label('Select Plant')
->required()

View File

@@ -45,7 +45,7 @@ class WorkGroupMasterResource extends Resource
->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();
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function ($state, $set, callable $get) {
$plantId = $get('plant_id');