66 Commits

Author SHA1 Message Date
785be70629 Merge pull request 'Refactor item code retrieval in WeightValidationResource table method' (#188) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #188
2026-01-14 06:47:41 +00:00
dhanabalan
011632b725 Refactor item code retrieval in WeightValidationResource table method
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Laravel Pint / pint (pull_request) Successful in 2m33s
Laravel Larastan / larastan (pull_request) Failing after 3m17s
2026-01-14 12:17:18 +05:30
e5cb7f3d88 Merge pull request 'ranjith-dev' (#187) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
Reviewed-on: #187
2026-01-14 06:37:24 +00:00
dhanabalan
9540fb95c9 Added view rights against plant on view report and Updated alignments and load available item code logic on resource
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 28s
Laravel Pint / pint (pull_request) Successful in 2m31s
Laravel Larastan / larastan (pull_request) Failing after 3m37s
2026-01-14 11:59:50 +05:30
dhanabalan
96a8311317 Added weight validation table has many relationship
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 11:46:54 +05:30
dhanabalan
1db254c32b Implement feature X to enhance user experience and optimize performance
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 11:37:04 +05:30
dhanabalan
2604896fd8 Added view rights against plant on view report and Updated alignments on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 11:27:31 +05:30
dhanabalan
0a69d515a4 Added view rights against plant on view report and Updated alignments on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 11:02:25 +05:30
dhanabalan
75d87cda29 Added view rights against plant on view report and Updated alignments on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 10:56:14 +05:30
dhanabalan
f611a81da0 Added view rights against plant on view report and Updated alignments and filter query logic on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
2026-01-14 10:43:14 +05:30
dhanabalan
adb61638c9 Added view rights against plant on view report and Updated alignments on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 10:33:59 +05:30
dhanabalan
8c0676e9b8 Added view rights against plant on view report and Updated alignments and filter query logic on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 10:29:43 +05:30
dhanabalan
f9cb090a25 Added view rights against plant on view report and Updated alignments and load available item code logic on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:56:53 +05:30
dhanabalan
f1c0dc738c Added Product Characteristics Master table has many relationship
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:52:41 +05:30
dhanabalan
58175a245e Added view rights against plant on view report and Updated alignments and load available item code logic on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:46:49 +05:30
dhanabalan
d8e722ab0e Added process order table has many relationship
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:42:31 +05:30
dhanabalan
f4a6496411 Added view rights against plant on view report and Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:31:12 +05:30
dhanabalan
4a4259612b Added view rights against plant on view report and Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:26:35 +05:30
dhanabalan
978a23449a Added view rights against plant on view report and Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:23:07 +05:30
dhanabalan
4ad848054f Implement initial structure for code changes and prepare for future updates and Added view rights against plant on view report
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:20:28 +05:30
dhanabalan
041cc11030 Added view rights against plant on view report
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:14:45 +05:30
dhanabalan
511a491be2 Add reactive behavior to form fields and update options based on plant selection
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-14 09:08:36 +05:30
dhanabalan
a0a10cb668 Updated alignment on resource
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
2026-01-14 09:06:45 +05:30
dhanabalan
13912de584 Updated alignment on export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 9s
2026-01-13 16:47:28 +05:30
dhanabalan
63110298e7 Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:46:43 +05:30
dhanabalan
d59fb00e90 Added plant code instead of plant name on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:45:48 +05:30
dhanabalan
bf6b973fd1 Updated alignment and validation logic on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:44:42 +05:30
dhanabalan
2521c04f03 Updated alignment and validation logic on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 9s
2026-01-13 16:43:48 +05:30
dhanabalan
9bed5f6937 Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:42:30 +05:30
dhanabalan
b7b7f88235 Added plant code instead of plant name on export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:41:08 +05:30
dhanabalan
aa781ccc89 Added view rights against plant on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:39:23 +05:30
dhanabalan
2f8d7615a3 Updated alignment on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:38:42 +05:30
dhanabalan
05f059ece1 Added view rights against plant on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:37:24 +05:30
dhanabalan
b2044bc851 Added view rights against plant on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:35:57 +05:30
dhanabalan
0cb5373312 Added view rights against plant on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:34:49 +05:30
dhanabalan
5a74f9a4ca Added view rights against plant on import and export and Validation logic updated
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:33:57 +05:30
dhanabalan
f592852b77 Updated alignments on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:32:47 +05:30
dhanabalan
b9cb492d37 Updated alignments on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:31:43 +05:30
dhanabalan
5bacc0cba7 Updated alignments on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:29:52 +05:30
dhanabalan
bbd8ff91a2 Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:27:47 +05:30
dhanabalan
f05bb3d5b3 Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:27:00 +05:30
dhanabalan
188e13ab99 Updated alignments on import
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:26:10 +05:30
dhanabalan
e917159486 Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:25:07 +05:30
dhanabalan
7f96d9631a Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:23:05 +05:30
dhanabalan
5a218d688d Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:19:20 +05:30
dhanabalan
1e57326e8e Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:18:10 +05:30
dhanabalan
4de209841a Added plant code instead of plant name on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:17:03 +05:30
dhanabalan
5cba017b72 Updated alignments on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:15:06 +05:30
dhanabalan
6b40204e35 Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:13:50 +05:30
dhanabalan
49ab5b14ed Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
2026-01-13 16:13:00 +05:30
dhanabalan
79a09e3a59 Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:06:38 +05:30
dhanabalan
ae954e2d7d Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:05:25 +05:30
dhanabalan
4705b3aebb Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:04:11 +05:30
dhanabalan
3c4a09f571 Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 9s
2026-01-13 16:02:45 +05:30
dhanabalan
7a988b7280 Added view rights against plant
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 16:00:31 +05:30
dhanabalan
47db04a36c Added view rights against plant
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 15:58:28 +05:30
dhanabalan
22c65c4308 Added view rights against plant
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
2026-01-13 15:54:01 +05:30
1dbbd53fc9 Merge pull request 'Updated item code filter option against plant from stickerMaster' (#186) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Reviewed-on: #186
2026-01-13 10:10:36 +00:00
dhanabalan
bec3e9f8bd Updated item code filter option against plant from stickerMaster
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 16s
Laravel Pint / pint (pull_request) Successful in 2m50s
Laravel Larastan / larastan (pull_request) Failing after 3m46s
2026-01-13 15:39:42 +05:30
04d0c2dc82 Merge pull request 'Removed commented notifications' (#185) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Reviewed-on: #185
2026-01-13 09:22:51 +00:00
dhanabalan
26b4cd9363 Removed commented notifications
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 15s
Laravel Pint / pint (pull_request) Successful in 2m26s
Laravel Larastan / larastan (pull_request) Failing after 3m22s
2026-01-13 14:52:27 +05:30
048977a44b Merge pull request 'ranjith-dev' (#183) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #183
2026-01-13 09:21:33 +00:00
8395599d9d Merge pull request 'Update .github/workflows/gemini-pr-review.yaml' (#184) from jothi-patch-1 into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Reviewed-on: #184
2026-01-13 09:18:30 +00:00
dhanabalan
f19765ff7b Added view rights against plant
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 24s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Laravel Larastan / larastan (pull_request) Failing after 3m8s
Laravel Pint / pint (pull_request) Successful in 3m6s
2026-01-13 13:12:36 +05:30
dhanabalan
18fc1d25ac Added plant code instead of plant name on import and export
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 12s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 9s
Laravel Larastan / larastan (pull_request) Failing after 3m3s
Laravel Pint / pint (pull_request) Successful in 2m44s
2026-01-13 11:59:15 +05:30
dhanabalan
0cc969f065 changed gemini pr review yaml logic
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 6m1s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 4m8s
Laravel Pint / pint (pull_request) Successful in 3m1s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 47s
Laravel Larastan / larastan (pull_request) Failing after 3m46s
2026-01-12 15:04:48 +05:30
79 changed files with 6333 additions and 5946 deletions

View File

@@ -24,26 +24,27 @@ class BlockExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('NAME'),
->label('BLOCK NAME'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT')
->enabledByDefault(true),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your block export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your block export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,6 +14,7 @@ class CharacteristicValueExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
@@ -22,30 +23,30 @@ class CharacteristicValueExporter extends Exporter
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
->label('PLANT CODE'),
ExportColumn::make('line.name')
->label('LINE NAME'),
->label('LINE NAME'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
->label('ITEM CODE'),
ExportColumn::make('machine.name')
->label('WORK CENTER'),
->label('WORK CENTER'),
ExportColumn::make('process_order')
->label('PROCESS ORDER'),
->label('PROCESS ORDER'),
ExportColumn::make('coil_number')
->label('COIL NUMBER'),
->label('COIL NUMBER'),
ExportColumn::make('status')
->label('STATUS'),
->label('STATUS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
->enabledByDefault(false)
->label('DELETED AT'),
];
}

View File

@@ -24,8 +24,8 @@ class CheckPointNameExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('CHECK POINT NAME'),
ExportColumn::make('created_at')
@@ -42,10 +42,10 @@ class CheckPointNameExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your check point name export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your check point name export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,8 +24,8 @@ class CheckPointTimeExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('checkPointNames1.name')
->label('CHECK POINT 1'),
ExportColumn::make('checkPointNames2.name')
@@ -50,10 +50,10 @@ class CheckPointTimeExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your check point time export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your check point time export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -17,11 +17,11 @@ class ConfigurationExporter extends Exporter
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT'),
ExportColumn::make('line.name')
@@ -46,10 +46,10 @@ class ConfigurationExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your configuration export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your configuration export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,6 +14,7 @@ class DeviceMasterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
@@ -21,32 +22,32 @@ class DeviceMasterExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('DEVICE NAME'),
->label('DEVICE NAME'),
ExportColumn::make('mac_address')
->label('MAC ADDRESS'),
->label('MAC ADDRESS'),
ExportColumn::make('ip_address')
->label('IP ADDRESS'),
->label('IP ADDRESS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
->enabledByDefault(false)
->label('DELETED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your device master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your device master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -10,116 +10,118 @@ use Filament\Actions\Exports\Models\Export;
class EbReadingExporter extends Exporter
{
protected static ?string $model = EbReading::class;
static $rowNumber = 0;
public static $rowNumber = 0;
public static function getColumns(): array
{
return [
ExportColumn::make('no')
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('lcd_segment_check')
->label('LCD SEGMENT CHECK'),
->label('LCD SEGMENT CHECK'),
ExportColumn::make('meter_serial_no')
->label('METER SERIAL NO'),
->label('METER SERIAL NO'),
ExportColumn::make('eb_date_time')
->label('EB DATE TIME'),
->label('EB DATE TIME'),
ExportColumn::make('ph_seq_of_volt')
->label('PH SEQ OF VOLT'),
->label('PH SEQ OF VOLT'),
ExportColumn::make('ph_assoc_conn_check')
->label('PH ASSOC CONN CHECK'),
->label('PH ASSOC CONN CHECK'),
ExportColumn::make('instantaneous_ph_volt')
->label('INSTANTANEOUS PH VOLT'),
->label('INSTANTANEOUS PH VOLT'),
ExportColumn::make('instantaneous_curr')
->label('INSTANTANEOUS CURR'),
->label('INSTANTANEOUS CURR'),
ExportColumn::make('instantaneous_freq')
->label('INSTANTANEOUS FREQ'),
->label('INSTANTANEOUS FREQ'),
ExportColumn::make('instantaneous_kw_with_sign')
->label('INSTANTANEOUS KW WITH SIGN'),
->label('INSTANTANEOUS KW WITH SIGN'),
ExportColumn::make('instantaneous_kva')
->label('INSTANTANEOUS KVA'),
->label('INSTANTANEOUS KVA'),
ExportColumn::make('instantaneous_kv_ar')
->label('INSTANTANEOUS KV AR'),
->label('INSTANTANEOUS KV AR'),
ExportColumn::make('instantaneous_pf_with_sign')
->label('INSTANTANEOUS PF WITH SIGN'),
->label('INSTANTANEOUS PF WITH SIGN'),
ExportColumn::make('rd_with_elapsed_time_kva')
->label('RD WITH ELAPSED TIME KVA'),
->label('RD WITH ELAPSED TIME KVA'),
ExportColumn::make('cum_active_import_energy')
->label('CUM ACTIVE IMPORT ENERGY'),
->label('CUM ACTIVE IMPORT ENERGY'),
ExportColumn::make('tod1_active_energy_6_9')
->label('TOD1 ACTIVE ENERGY 6-9'),
->label('TOD1 ACTIVE ENERGY 6-9'),
ExportColumn::make('tod2_active_energy_18_21')
->label('TOD2 ACTIVE ENERGY 18-21'),
->label('TOD2 ACTIVE ENERGY 18-21'),
ExportColumn::make('tod3_active_energy_21_22')
->label('TOD3 ACTIVE ENERGY 21-22'),
->label('TOD3 ACTIVE ENERGY 21-22'),
ExportColumn::make('tod4_active_energy_5_6_9_18')
->label('TOD4 ACTIVE ENERGY 5-6-9-18'),
->label('TOD4 ACTIVE ENERGY 5-6-9-18'),
ExportColumn::make('tod5_active_energy_22_5')
->label('TOD5 ACTIVE ENERGY 22-5'),
->label('TOD5 ACTIVE ENERGY 22-5'),
ExportColumn::make('cum_reac_lag_energy')
->label('CUM REAC LAG ENERGY'),
->label('CUM REAC LAG ENERGY'),
ExportColumn::make('cum_reac_lead_energy')
->label('CUM REAC LEAD ENERGY'),
->label('CUM REAC LEAD ENERGY'),
ExportColumn::make('cum_appar_energy')
->label('CUM APPAR ENERGY'),
->label('CUM APPAR ENERGY'),
ExportColumn::make('tod1_appar_energy_6_9')
->label('TOD1 APPAR ENERGY 6-9'),
->label('TOD1 APPAR ENERGY 6-9'),
ExportColumn::make('tod2_appar_energy_18_21')
->label('TOD2 APPAR ENERGY 18-21'),
->label('TOD2 APPAR ENERGY 18-21'),
ExportColumn::make('tod3_appar_energy_21_22')
->label('TOD3 APPAR ENERGY 21-22'),
->label('TOD3 APPAR ENERGY 21-22'),
ExportColumn::make('tod4_appar_energy_5_6_9_18')
->label('TOD4 APPAR ENERGY 5-6-9-18'),
->label('TOD4 APPAR ENERGY 5-6-9-18'),
ExportColumn::make('tod5_appar_energy_22_5')
->label('TOD5 APPAR ENERGY 22-5'),
->label('TOD5 APPAR ENERGY 22-5'),
ExportColumn::make('avg_pow_factor')
->label('AVG POW FACTOR'),
->label('AVG POW FACTOR'),
ExportColumn::make('avg_freq_15min_last_ip')
->label('AVG FREQ 15MIN LAST IP'),
->label('AVG FREQ 15MIN LAST IP'),
ExportColumn::make('net_kv_arh_high')
->label('NET KV ARH HIGH'),
->label('NET KV ARH HIGH'),
ExportColumn::make('net_kv_arh_low')
->label('NET KV ARH LOW'),
->label('NET KV ARH LOW'),
ExportColumn::make('cum_md_kva')
->label('CUM MD KVA'),
->label('CUM MD KVA'),
ExportColumn::make('present_md_kva')
->label('PRESENT MD KVA'),
->label('PRESENT MD KVA'),
ExportColumn::make('present_md_kva_date_time')
->label('PRESENT MD KVA DATE TIME'),
->label('PRESENT MD KVA DATE TIME'),
ExportColumn::make('tod1_md_kva_6_9')
->label('TOD1 MD KVA 6-9'),
->label('TOD1 MD KVA 6-9'),
ExportColumn::make('tod2_md_kva_18_21')
->label('TOD2 MD KVA 18-21'),
->label('TOD2 MD KVA 18-21'),
ExportColumn::make('tod3_md_kva_21_22')
->label('TOD3 MD KVA 21-22'),
->label('TOD3 MD KVA 21-22'),
ExportColumn::make('tod4_md_kva_5_6_9_18')
->label('TOD4 MD KVA 5-6-9-18'),
->label('TOD4 MD KVA 5-6-9-18'),
ExportColumn::make('tod5_md_kva_22_5')
->label('TOD5 MD KVA 22-5'),
->label('TOD5 MD KVA 22-5'),
ExportColumn::make('total_pow_off_hours')
->label('TOTAL POW OFF HOURS'),
->label('TOTAL POW OFF HOURS'),
ExportColumn::make('programming_count')
->label('PROGRAMMING COUNT'),
->label('PROGRAMMING COUNT'),
ExportColumn::make('last_occ_res_event_type')
->label('LAST OCC RES EVENT TYPE'),
->label('LAST OCC RES EVENT TYPE'),
ExportColumn::make('last_occ_res_event_date_time')
->label('LAST OCC RES EVENT DATE TIME'),
->label('LAST OCC RES EVENT DATE TIME'),
ExportColumn::make('tamper_count')
->label('TAMPER COUNT'),
->label('TAMPER COUNT'),
ExportColumn::make('reset_count')
->label('RESET COUNT'),
->label('RESET COUNT'),
ExportColumn::make('last_md_reset_date_time')
->label('LAST MD RESET DATE TIME'),
->label('LAST MD RESET DATE TIME'),
ExportColumn::make('electrician_sign')
->label('ELECTRICIAN SIGN'),
->label('ELECTRICIAN SIGN'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->enabledByDefault(false),
ExportColumn::make('updated_by')
@@ -129,10 +131,10 @@ class EbReadingExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your eb reading export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your eb reading export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,59 +14,60 @@ class EquipmentMasterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('machine.name')
->label('MACHINE NAME'),
->label('MACHINE NAME'),
ExportColumn::make('name')
->label('NAME'),
->label('NAME'),
ExportColumn::make('description')
->label('DESCRIPTION'),
->label('DESCRIPTION'),
ExportColumn::make('make')
->label('MAKE'),
->label('MAKE'),
ExportColumn::make('model')
->label('MODEL'),
->label('MODEL'),
ExportColumn::make('equipment_number')
->label('EQUIPMENT NUMBER'),
->label('EQUIPMENT NUMBER'),
ExportColumn::make('instrument_serial_number')
->label('INSTRUMENT SERIAL NUMBER'),
->label('INSTRUMENT SERIAL NUMBER'),
ExportColumn::make('calibrated_on')
->label('CALIBRATED ON'),
->label('CALIBRATED ON'),
ExportColumn::make('frequency')
->label('FREQUENCY'),
->label('FREQUENCY'),
ExportColumn::make('next_calibration_date')
->label('NEXT CALIBRATION DATE'),
->label('NEXT CALIBRATION DATE'),
ExportColumn::make('calibrated_by')
->label('CALIBRATED BY'),
->label('CALIBRATED BY'),
ExportColumn::make('calibration_certificate')
->label('CALIBRATION CERTIFICATE'),
->label('CALIBRATION CERTIFICATE'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your equipment master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your equipment master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,6 +14,7 @@ class GrMasterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
@@ -21,36 +22,36 @@ class GrMasterExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('item.code')
->label('ITEM'),
->label('ITEM CODE'),
ExportColumn::make('serial_number')
->label('SERIAL NUMBER'),
->label('SERIAL NUMBER'),
ExportColumn::make('gr_number')
->label('GR NUMBER'),
->label('GR NUMBER'),
ExportColumn::make('status')
->label('STATUS'),
->label('STATUS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your gr master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your gr master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,8 +24,8 @@ class GuardNameExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('GUARD NAME'),
ExportColumn::make('identification1')
@@ -46,10 +46,10 @@ class GuardNameExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your guard name export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your guard name export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,8 +24,8 @@ class GuardPatrolEntryExporter extends Exporter
}),
// ExportColumn::make('id')
// ->label('ID'),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('guardNames.name')
->label('GUARD NAME'),
ExportColumn::make('checkPointNames.name')
@@ -54,10 +54,10 @@ class GuardPatrolEntryExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your guard patrol entry export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your guard patrol entry export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,12 +24,12 @@ class LineExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('NAME'),
->label('LINE NAME'),
ExportColumn::make('type')
->label('TYPE'),
->label('LINE TYPE'),
ExportColumn::make('no_of_operation')
->label('NO OF OPERATION'),
ExportColumn::make('workGroup1.name')
@@ -84,10 +84,10 @@ class LineExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your line export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your line export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -22,12 +22,12 @@ class MachineExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('name')
->label('MACHINE'),
->label('MACHINE NAME'),
ExportColumn::make('work_center')
->label('WORK CENTER'),
ExportColumn::make('workGroupMaster.name')
@@ -44,10 +44,10 @@ class MachineExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your machine export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your machine export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,39 +14,40 @@ class MfmMeterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('device.name')
->label('DEVICE NAME'),
->label('DEVICE NAME'),
ExportColumn::make('sequence')
->label('SEQUENCE'),
->label('SEQUENCE'),
ExportColumn::make('name')
->label('NAME'),
->label('METER NAME'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
->label('DELETED AT')
->enabledByDefault(false),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your mfm meter export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your mfm meter export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,48 +14,49 @@ class MfmParameterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('deviceName.name')
->label('Device Name'),
->label('Device Name'),
ExportColumn::make('name')
->label('NAME'),
->label('PARAMETER NAME'),
ExportColumn::make('mfmMeter.name')
->label('MFM METER'),
->label('MFM METER'),
ExportColumn::make('register_id')
->label('REGISTER ID'),
->label('REGISTER ID'),
ExportColumn::make('identifier')
->label('IDENTIFIER'),
->label('IDENTIFIER'),
ExportColumn::make('byte_to_convert')
->label('BYTE TO CONVERT'),
->label('BYTE TO CONVERT'),
ExportColumn::make('type_to_convert')
->label('TYPE TO CONVERT'),
->label('TYPE TO CONVERT'),
ExportColumn::make('decimal_to_display')
->label('DECIMAL TO DISPLAY'),
->label('DECIMAL TO DISPLAY'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your mfm parameter export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your mfm parameter export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -17,13 +17,13 @@ class MotorTestingMasterExporter extends Exporter
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT'),
->label('PLANT CODE'),
ExportColumn::make('item.category')
->label('CATEGORY'),
ExportColumn::make('item.code')
@@ -106,10 +106,10 @@ class MotorTestingMasterExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your motor testing master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your motor testing master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -37,13 +37,13 @@ class ProductionLineStopExporter extends Exporter
ExportColumn::make('stop_min')
->label('STOP MINUTE'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('shift.block.name')
->label('BLOCK'),
->label('BLOCK NAME'),
ExportColumn::make('shift.name')
->label('SHIFT'),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('SHIFT NAME'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('operator_id')
->label('OPERATOR ID'),
ExportColumn::make('created_at')
@@ -58,10 +58,10 @@ class ProductionLineStopExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your production line stop export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your production line stop export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -29,13 +29,13 @@ class ProductionPlanExporter extends Exporter
ExportColumn::make('production_quantity')
->label('PRODUCTION QUANTITY'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('shift.block.name')
->label('BLOCK'),
->label('BLOCK NAME'),
ExportColumn::make('shift.name')
->label('SHIFT'),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('SHIFT NAME'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('operator_id')
->label('OPERATOR ID'),
ExportColumn::make('created_at')
@@ -50,10 +50,10 @@ class ProductionPlanExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your production plan export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your production plan export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -33,13 +33,13 @@ class ProductionQuantityExporter extends Exporter
ExportColumn::make('item.uom')
->label('UNIT OF MEASURE'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('shift.block.name')
->label('BLOCK'),
->label('BLOCK NAME'),
ExportColumn::make('shift.name')
->label('SHIFT'),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('SHIFT NAME'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('sap_msg_status')
->label('SAP MESSAGE STATUS'),
ExportColumn::make('sap_msg_description')
@@ -58,10 +58,10 @@ class ProductionQuantityExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your production quantity export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your production quantity export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,10 +24,10 @@ class QualityValidationExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('production_order')
->label('PRODUCTION ORDER'),
ExportColumn::make('serial_number')
@@ -54,14 +54,14 @@ class QualityValidationExporter extends Exporter
->label('NAME PLATE PUMP'),
ExportColumn::make('name_plate_pumpset')
->label('NAME PLATE PUMPSET'),
ExportColumn::make('warranty_card')
->label('WARRANTY CARD'),
ExportColumn::make('tube_sticker_motor')
->label('TUBE STICKER MOTOR'),
ExportColumn::make('tube_sticker_pump')
->label('TUBE STICKER PUMP'),
ExportColumn::make('tube_sticker_pumpset')
->label('TUBE STICKER PUMPSET'),
ExportColumn::make('warranty_card')
->label('WARRANTY CARD'),
ExportColumn::make('part_validation1')
->label('PART VALIDATION 1'),
ExportColumn::make('part_validation2')
@@ -90,10 +90,10 @@ class QualityValidationExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your quality validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your quality validation export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,15 +14,16 @@ class SerialValidationExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('invoice_number')
->label('INVOICE NUMBER'),
ExportColumn::make('serial_number')
@@ -55,10 +56,10 @@ class SerialValidationExporter extends Exporter
->label('OPERATOR ID'),
ExportColumn::make('created_at')
->label('CREATED AT'),
//->dateTimeFormat('d-m-Y H:i:s'),
// ->dateTimeFormat('d-m-Y H:i:s'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
//->dateTimeFormat('d-m-Y H:i:s'),
// ->dateTimeFormat('d-m-Y H:i:s'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
@@ -67,10 +68,10 @@ class SerialValidationExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your serial validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your serial validation export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -25,11 +25,11 @@ class ShiftExporter extends Exporter
return ++$rowNumber;
}),
ExportColumn::make('block.name')
->label('BLOCK'),
ExportColumn::make('plant.name')
->label('PLANT'),
->label('BLOCK NAME'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('NAME'),
->label('SHIFT NAME'),
ExportColumn::make('start_time')
->label('START TIME'),
ExportColumn::make('duration')
@@ -50,10 +50,10 @@ class ShiftExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your shift export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your shift export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,8 +24,8 @@ class StickerMasterExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT NAME'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
ExportColumn::make('serial_number_motor')
@@ -88,10 +88,10 @@ class StickerMasterExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your sticker master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your sticker master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,18 +24,18 @@ class TestingPanelReadingExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('line.name')
->label('LINE'),
->label('LINE NAME'),
ExportColumn::make('machine.name')
->label('MACHINE'),
->label('MACHINE NAME'),
ExportColumn::make('motorTestingMaster.item.code')
->label('ITEM CODE'),
ExportColumn::make('motorTestingMaster.item.description')
->label('MODEL'),
->label('MODEL DESCRIPTION'),
ExportColumn::make('output')
->label('OUTPUT'),
->label('OUTPUT NAME'),
ExportColumn::make('serial_number')
->label('SERIAL NUMBER'),
ExportColumn::make('winded_serial_number')
@@ -125,7 +125,7 @@ class TestingPanelReadingExporter extends Exporter
ExportColumn::make('rework_count')
->label('REWORK COUNT'),
ExportColumn::make('update_count')
->label('UPDATE COUNT'),
->label('UPDATED COUNT'),
ExportColumn::make('output_flag')
->label('OUTPUT FLAG'),
ExportColumn::make('tested_by')
@@ -146,10 +146,10 @@ class TestingPanelReadingExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your testing panel reading export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your testing panel reading export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -24,8 +24,8 @@ class WeightValidationExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('item.code')
->label('ITEM CODE'),
ExportColumn::make('obd_number')
@@ -58,10 +58,10 @@ class WeightValidationExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your weight validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your weight validation export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -14,6 +14,7 @@ class WorkGroupMasterExporter extends Exporter
public static function getColumns(): array
{
static $rowNumber = 0;
return [
ExportColumn::make('no')
->label('NO')
@@ -21,32 +22,32 @@ class WorkGroupMasterExporter extends Exporter
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('NAME'),
->label('WORK GROUP NAME'),
ExportColumn::make('description')
->label('DESCRIPTION'),
->label('WORK GROUP DESCRIPTION'),
ExportColumn::make('operation_number')
->label('OPERATION NUMBER'),
->label('OPERATION NUMBER'),
ExportColumn::make('created_by')
->label('CREATED BY'),
->label('CREATED BY'),
ExportColumn::make('created_at')
->label('CREATED AT'),
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your work group master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your work group master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;

View File

@@ -8,7 +8,6 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Notification;
use Str;
class BlockImporter extends Importer
@@ -20,16 +19,16 @@ class BlockImporter extends Importer
return [
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Block Name')
->exampleHeader('BLOCK NAME')
->example('Block A')
->label('Block Name')
->label('BLOCK NAME')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('PLANT CODE')
->example('1000')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
];
}
@@ -37,21 +36,28 @@ class BlockImporter extends Importer
public function resolveRecord(): ?Block
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
// $warnMsg[] = "Plant '" . $this->data['plant'] . "' not found";
$plantCod = $this->data['plant'];
$plant = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
// $warnMsg[] = "Plant '" . $plantCod . "' not found";
}
}
if (Str::length($this->data['name']) < 0) {
$warnMsg[] = "Block name not found";
$warnMsg[] = 'Block name not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return Block::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
'plant_id' => $plant->id,
]);
// return Block::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
@@ -63,10 +69,10 @@ class BlockImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your block import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your block import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -20,10 +20,10 @@ class CheckPointNameImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
@@ -43,27 +43,33 @@ class CheckPointNameImporter extends Importer
public function resolveRecord(): ?CheckPointName
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
$plantCod = $this->data['plant'];
$plant = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
}
}
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
$warnMsg[] = "Invalid check point name found";
$warnMsg[] = 'Invalid check point name found';
}
$createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
$warnMsg[] = "Invalid created by name found";
$warnMsg[] = 'Invalid created by name found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return CheckPointName::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
],
[
'created_by' => $this->data['created_by']
'plant_id' => $plant->id,
],
[
'created_by' => $this->data['created_by'],
]
);
// // return CheckPointName::firstOrNew([
@@ -76,10 +82,10 @@ class CheckPointNameImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your check point name import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your check point name import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -21,10 +21,10 @@ class CheckPointTimeImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('checkPointNames1')
->requiredMapping()
@@ -73,50 +73,51 @@ class CheckPointTimeImporter extends Importer
public function resolveRecord(): ?CheckPointTime
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$checkPointNames1 = null;
$checkPointNames2 = null;
if (!$plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
}
else
{
$checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first();
if (!$checkPointNames1) {
$warnMsg[] = "Check point 1 not found";
}
else
{
$checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first();
if (!$checkPointNames2) {
$warnMsg[] = "Check point 2 not found";
}
else
{
if ($checkPointNames1->id === $checkPointNames2->id) {
$warnMsg[] = "Check point 1 and 2 can't be the same";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
} else {
$checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first();
if (! $checkPointNames1) {
$warnMsg[] = 'Check point 1 not found';
} else {
$checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first();
if (! $checkPointNames2) {
$warnMsg[] = 'Check point 2 not found';
} else {
if ($checkPointNames1->id === $checkPointNames2->id) {
$warnMsg[] = "Check point 1 and 2 can't be the same";
}
}
}
}
}
if (Str::length($this->data['sequence_number']) < 1 || !is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) {
$warnMsg[] = "Invalid sequence number found";
if (Str::length($this->data['sequence_number']) < 1 || ! is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) {
$warnMsg[] = 'Invalid sequence number found';
}
if (Str::length($this->data['time_lapse']) < 1 || !is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) {
$warnMsg[] = "Invalid time lapse found";
if (Str::length($this->data['time_lapse']) < 1 || ! is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) {
$warnMsg[] = 'Invalid time lapse found';
}
if (Str::length($this->data['time_lapse_cushioning']) < 1 || !is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) {
$warnMsg[] = "Invalid time lapse cushioning found";
if (Str::length($this->data['time_lapse_cushioning']) < 1 || ! is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) {
$warnMsg[] = 'Invalid time lapse cushioning found';
}
$createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
$warnMsg[] = "Invalid created by name found";
$warnMsg[] = 'Invalid created by name found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -124,12 +125,12 @@ class CheckPointTimeImporter extends Importer
'plant_id' => $plant->id,
'check_point1_id' => $checkPointNames1->id,
'check_point2_id' => $checkPointNames2->id,
'sequence_number' => $this->data['sequence_number']
'sequence_number' => $this->data['sequence_number'],
],
[
'time_lapse' => $this->data['time_lapse'],
'time_lapse_cushioning' => $this->data['time_lapse_cushioning'],
'created_by' => $this->data['created_by']
[
'time_lapse' => $this->data['time_lapse'],
'time_lapse_cushioning' => $this->data['time_lapse_cushioning'],
'created_by' => $this->data['created_by'],
]
);
// // return CheckPointTime::firstOrNew([
@@ -142,10 +143,10 @@ class CheckPointTimeImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your check point time import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your check point time import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -62,15 +62,15 @@ class ConfigurationImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new Configuration();
return new Configuration;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your configuration import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your configuration import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -16,10 +16,10 @@ class DeviceMasterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
@@ -53,15 +53,15 @@ class DeviceMasterImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new DeviceMaster();
return new DeviceMaster;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your device master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your device master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -16,10 +16,10 @@ class EbReadingImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('lcd_segment_check')
->label('LCD Segment Check')
@@ -227,15 +227,15 @@ class EbReadingImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new EbReading();
return new EbReading;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your eb reading import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your eb reading import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -16,17 +16,17 @@ class EquipmentMasterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('machine')
->requiredMapping()
->exampleHeader('Machine Name')
->example('1006378')
->label('Machine Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('name')
->label('Name')
@@ -93,15 +93,15 @@ class EquipmentMasterImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new EquipmentMaster();
return new EquipmentMaster;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your equipment master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your equipment master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -3,14 +3,14 @@
namespace App\Filament\Imports;
use App\Models\GrMaster;
use App\Models\Item;
use App\Models\Plant;
use App\Models\User;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use App\Models\Plant;
use App\Models\Item;
use Str;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use App\Models\User;
class GrMasterImporter extends Importer
{
@@ -21,17 +21,17 @@ class GrMasterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('Item Code')
->example('630214')
->label('Item Code')
->relationship(resolveUsing:'code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('serial_number')
->requiredMapping()
@@ -51,7 +51,7 @@ class GrMasterImporter extends Importer
->example('Admin')
->label('Created By')
->rules(['required']),
//ImportColumn::make('updated_by'),
// ImportColumn::make('updated_by'),
];
}
@@ -63,44 +63,47 @@ class GrMasterImporter extends Importer
// ]);
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
$plantCod = $this->data['plant'];
$plant = null;
$item = null;
if ($plant) {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
}
if (! $item) {
$warnMsg[] = 'Item not found';
}
}
if (!$item) {
$warnMsg[] = "Item not found";
}
if (Str::length($this->data['serial_number']) < 9 || !ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = "Invalid serial number found";
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = 'Invalid serial number found';
}
if (empty($this->data['gr_number'])) {
$warnMsg[] = "GR Number cannot be empty.";
$warnMsg[] = 'GR Number cannot be empty.';
}
$user = User::where('name', $this->data['created_by'])->first();
if (!$user) {
$warnMsg[] = "User not found";
if (! $user) {
$warnMsg[] = 'User not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
else { //if (empty($warnMsg))
} else { // if (empty($warnMsg))
$grMaster = GrMaster::where('plant_id', $plant->id)
->where('serial_number', $this->data['serial_number'])
->latest()
->first();
->where('serial_number', $this->data['serial_number'])
->latest()
->first();
if ($grMaster) {
throw new RowImportFailedException("Serial number already exist!");
throw new RowImportFailedException('Serial number already exist!');
}
}
@@ -113,15 +116,15 @@ class GrMasterImporter extends Importer
]);
return null;
//return new GrMaster();
// return new GrMaster();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your gr master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your gr master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -20,10 +20,10 @@ class GuardNameImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
@@ -54,32 +54,38 @@ class GuardNameImporter extends Importer
public function resolveRecord(): ?GuardName
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
$plantCod = $this->data['plant'];
$plant = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
}
}
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
$warnMsg[] = "Invalid guard name found";
$warnMsg[] = 'Invalid guard name found';
}
if (Str::length($this->data['identification1']) < 5) {
$warnMsg[] = "Invalid identification-1 found";
$warnMsg[] = 'Invalid identification-1 found';
}
$createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
$warnMsg[] = "Invalid created by name found";
$warnMsg[] = 'Invalid created by name found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return GuardName::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
'plant_id' => $plant->id,
],
[
'identification1' => $this->data['identification1'],
'identification2' => $this->data['identification2'],
'created_by' => $this->data['created_by']
[
'identification1' => $this->data['identification1'],
'identification2' => $this->data['identification2'],
'created_by' => $this->data['created_by'],
]
);
@@ -87,15 +93,15 @@ class GuardNameImporter extends Importer
// // // Update existing records, matching them by `$this->data['column_name']`
// // 'email' => $this->data['email'],
// // ]);
//return new GuardName();
// return new GuardName();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your guard name import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your guard name import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -23,10 +23,10 @@ class GuardPatrolEntryImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('guardNames')
->requiredMapping()
@@ -68,61 +68,60 @@ class GuardPatrolEntryImporter extends Importer
public function resolveRecord(): ?GuardPatrolEntry
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$guardNames = null;
$checkPointNames = null;
$patrolDateTime = null; //$fdateTime = null;
if (!$plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
}
else
{
$guardNames = GuardName::where('plant_id', $plant->id)->where('name', $this->data['guardNames'])->first();
if (!$guardNames) {
$warnMsg[] = "Guard name not found";
}
else
{
$checkPointNames = CheckPointName::where('plant_id', $plant->id)->where('name', $this->data['checkPointNames'])->first();
if (!$checkPointNames) {
$warnMsg[] = "Check point name not found";
}
else
{
$patrolTime = $this->data['patrol_time'];//$fromDate = $this->data['from_datetime'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$patrolDateTime = null; // $fdateTime = null;
foreach ($formats as $format) {
try {
$patrolDateTime = Carbon::createFromFormat($format, $patrolTime);
break;
} catch (\Exception $e) {
// Optionally collect warning messages
// $warnMsg[] = "Date format mismatch with format: $format";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
} else {
$guardNames = GuardName::where('plant_id', $plant->id)->where('name', $this->data['guardNames'])->first();
if (! $guardNames) {
$warnMsg[] = 'Guard name not found';
} else {
$checkPointNames = CheckPointName::where('plant_id', $plant->id)->where('name', $this->data['checkPointNames'])->first();
if (! $checkPointNames) {
$warnMsg[] = 'Check point name not found';
} else {
$patrolTime = $this->data['patrol_time']; // $fromDate = $this->data['from_datetime'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
foreach ($formats as $format) {
try {
$patrolDateTime = Carbon::createFromFormat($format, $patrolTime);
break;
} catch (\Exception $e) {
// Optionally collect warning messages
// $warnMsg[] = "Date format mismatch with format: $format";
}
}
}
if (!isset($patrolDateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else
{
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plant->id)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
if ($guardEntryFound) {
$warnMsg[] = "Duplicate guard patrol entry found";
if (! isset($patrolDateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
} else {
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plant->id)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
if ($guardEntryFound) {
$warnMsg[] = 'Duplicate guard patrol entry found';
}
}
}
}
}
}
$createdBy = Filament::auth()->user()->name;// ?? 'Admin'
if (!$createdBy) {
$warnMsg[] = "Invalid created by name found";
$createdBy = Filament::auth()->user()->name; // ?? 'Admin'
if (! $createdBy) {
$warnMsg[] = 'Invalid created by name found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -130,14 +129,15 @@ class GuardPatrolEntryImporter extends Importer
'plant_id' => $plant->id,
'guard_name_id' => $guardNames->id,
'check_point_name_id' => $checkPointNames->id,
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s')
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s'),
],
[
'reader_code' => null,
'created_by' => $createdBy,
'updated_by' => $createdBy
[
'reader_code' => null,
'created_by' => $createdBy,
'updated_by' => $createdBy,
]
);
return null;
// // return GuardPatrolEntry::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
@@ -149,10 +149,10 @@ class GuardPatrolEntryImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your guard patrol entry import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your guard patrol entry import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -87,10 +87,10 @@ class LineImporter extends Importer
->label('Work Group Center 10'),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
];
}
@@ -98,28 +98,33 @@ class LineImporter extends Importer
public function resolveRecord(): ?Line
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
throw new RowImportFailedException("Plant '{$this->data['plant']}' not found");
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
throw new RowImportFailedException('Plant not found');
}
}
if (Str::length($this->data['name'] ?? '') <= 0) {
throw new RowImportFailedException("Line name not found");
throw new RowImportFailedException('Line name not found');
}
if (Str::length($this->data['type'] ?? '') <= 0) {
throw new RowImportFailedException("Line type not found");
throw new RowImportFailedException('Line type not found');
}
$noOfOps = (int) ($this->data['no_of_operation'] ?? 0);
if (($noOfOps == null || $noOfOps == '' || !is_numeric($noOfOps)) && $noOfOps != 0) {
if (($noOfOps == null || $noOfOps == '' || ! is_numeric($noOfOps)) && $noOfOps != 0) {
throw new RowImportFailedException("'No of Operation' is required and must be a number $noOfOps");
}
if ($noOfOps > 10)
{
if ($noOfOps > 10) {
throw new RowImportFailedException("Invalid 'No Of Operation' value: {$noOfOps}, maximum allowed is 10");
}
@@ -130,28 +135,28 @@ class LineImporter extends Importer
$missingGroups[] = "work_group{$i}_id";
}
}
if (!empty($missingGroups)) {
if (! empty($missingGroups)) {
throw new RowImportFailedException(
"Invalid data: Required work groups missing values in: " . implode(', ', $missingGroups)
'Invalid data: Required work groups missing values in: '.implode(', ', $missingGroups)
);
}
// Ensure no extra work groups are filled
$invalidGroups = [];
for ($i = $noOfOps + 1; $i <= 10; $i++) {
if (!empty($this->data["work_group{$i}_id"])) {
if (! empty($this->data["work_group{$i}_id"])) {
$invalidGroups[] = "work_group{$i}_id";
}
}
if (!empty($invalidGroups)) {
if (! empty($invalidGroups)) {
throw new RowImportFailedException(
"Invalid data: Only first {$noOfOps} work groups should be filled, but values found in: " . implode(', ', $invalidGroups)
"Invalid data: Only first {$noOfOps} work groups should be filled, but values found in: ".implode(', ', $invalidGroups)
);
}
for ($i = 1; $i <= 10; $i++) {
$workGroupName = $this->data["work_group{$i}_id"] ?? null;
if (!$workGroupName) {
if (! $workGroupName) {
continue;
}
@@ -159,8 +164,8 @@ class LineImporter extends Importer
->where('plant_id', $plant->id)
->first();
if (!$workGroupRecord) {
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$this->data['plant']}'");
if (! $workGroupRecord) {
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$plantCod}'");
}
$existsInLines = Line::where('plant_id', $plant->id)
@@ -169,35 +174,34 @@ class LineImporter extends Importer
->first();
if ($existsInLines) {
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$this->data['plant']}'";
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$plantCod}'";
}
$this->data["work_group{$i}_id"] = $workGroupRecord->id;
}
if (!empty($warnMsg))
{
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
Line::updateOrCreate(
[
'name' => $this->data['name'],
'plant_id' => $plant->id
'plant_id' => $plant->id,
],
[
'type' => $this->data['type'],
'no_of_operation' => $noOfOps,
'work_group1_id' => $this->data['work_group1_id'] ?? null,
'work_group2_id' => $this->data['work_group2_id'] ?? null,
'work_group3_id' => $this->data['work_group3_id'] ?? null,
'work_group4_id' => $this->data['work_group4_id'] ?? null,
'work_group5_id' => $this->data['work_group5_id'] ?? null,
'work_group6_id' => $this->data['work_group6_id'] ?? null,
'work_group7_id' => $this->data['work_group7_id'] ?? null,
'work_group8_id' => $this->data['work_group8_id'] ?? null,
'work_group9_id' => $this->data['work_group9_id'] ?? null,
'work_group10_id' => $this->data['work_group10_id'] ?? null,
'work_group1_id' => $this->data['work_group1_id'] ?? null,
'work_group2_id' => $this->data['work_group2_id'] ?? null,
'work_group3_id' => $this->data['work_group3_id'] ?? null,
'work_group4_id' => $this->data['work_group4_id'] ?? null,
'work_group5_id' => $this->data['work_group5_id'] ?? null,
'work_group6_id' => $this->data['work_group6_id'] ?? null,
'work_group7_id' => $this->data['work_group7_id'] ?? null,
'work_group8_id' => $this->data['work_group8_id'] ?? null,
'work_group9_id' => $this->data['work_group9_id'] ?? null,
'work_group10_id' => $this->data['work_group10_id'] ?? null,
]
);
@@ -206,10 +210,10 @@ class LineImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your line import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your line import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -10,7 +10,6 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Str;
class LocatorInvoiceValidationImporter extends Importer
@@ -115,53 +114,49 @@ class LocatorInvoiceValidationImporter extends Importer
$scannedBy = $this->data['scanned_by'];
$updatedBy = $this->data['updated_by'];
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code found";
}
else
{
$plant = Plant::where('code', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
else
{
if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) {
$warnMsg[] = "Invalid invoice number found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) {
$warnMsg[] = 'Invalid invoice number found';
}
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
$warnMsg[] = "Invalid serial number found";
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
$warnMsg[] = 'Invalid serial number found';
}
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
$warnMsg[] = "Invalid pallet number found";
$warnMsg[] = 'Invalid pallet number found';
}
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
$warnMsg[] = "Invalid locator number found";
$warnMsg[] = 'Invalid locator number found';
}
if (Str::length($scannedStat) > 0 && $scannedStat != 'Scanned') {
$warnMsg[] = "Invalid scanned status found";
$warnMsg[] = 'Invalid scanned status found';
}
if ($uploadStat != 'Y' && $uploadStat != 'N') {
$warnMsg[] = "Invalid upload status found";
$warnMsg[] = 'Invalid upload status found';
}
$created = User::where('name', $createdBy)->first();
if (!$created) {
$warnMsg[] = "Created by not found";
if (! $created) {
$warnMsg[] = 'Created by not found';
}
if (Str::length($scannedBy) > 0) {
$scanned = User::where('name', $scannedBy)->first();
if (!$scanned) {
$warnMsg[] = "Scanned by not found";
if (! $scanned) {
$warnMsg[] = 'Scanned by not found';
}
}
if (Str::length($updatedBy) > 0) {
$updated = User::where('name', $updatedBy)->first();
if (!$updated) {
$warnMsg[] = "Updated by not found";
if (! $updated) {
$warnMsg[] = 'Updated by not found';
}
}
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
foreach ($formats as $format) {
try {
@@ -173,13 +168,12 @@ class LocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($cDateTime)) {
if (! isset($cDateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
if (Str::length($scannedAt) > 0)
{
if (Str::length($scannedAt) > 0) {
foreach ($formats as $format) {
try {
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
@@ -190,13 +184,12 @@ class LocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($sDateTime)) {
if (! isset($sDateTime)) {
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
}
if (Str::length($updatedAt) > 0)
{
if (Str::length($updatedAt) > 0) {
foreach ($formats as $format) {
try {
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
@@ -207,11 +200,9 @@ class LocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($uDateTime)) {
if (! isset($uDateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else
{
} else {
if (isset($cDateTime) && isset($uDateTime)) {
if ($cDateTime->greaterThan($uDateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
@@ -226,14 +217,14 @@ class LocatorInvoiceValidationImporter extends Importer
// $warnMsg[] = "Invalid locator quantity found";
// }
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
LocatorInvoiceValidation::updateOrCreate(
[
'plant_id' => $plant->id,
'serial_number' => $serialNo
'serial_number' => $serialNo,
],
[
'invoice_number' => $invoiceNo,
@@ -246,9 +237,10 @@ class LocatorInvoiceValidationImporter extends Importer
'updated_at' => (Str::length($updatedAt) > 0) ? $uDateTime->format('Y-m-d H:i:s') : null,
'created_by' => $createdBy,
'scanned_by' => $scannedBy,
'updated_by' => $updatedBy
'updated_by' => $updatedBy,
]
);
return null;
// // return LocatorInvoiceValidation::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
@@ -260,10 +252,10 @@ class LocatorInvoiceValidationImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your locator invoice validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your locator invoice validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -21,9 +21,9 @@ class MachineImporter extends Importer
return [
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Machine')
->exampleHeader('Machine Name')
->example(['1600251'])
->label('Machine')
->label('Machine Name')
->rules(['required']),
ImportColumn::make('work_center')
->requiredMapping()
@@ -41,16 +41,16 @@ class MachineImporter extends Importer
ImportColumn::make('line')
->requiredMapping()
->relationship(resolveUsing: 'name')
->exampleHeader('Line')
->exampleHeader('Line Name')
->example(['4 inch pump line'])
->label('Line')
->label('Line Name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->relationship(resolveUsing: 'name')
->exampleHeader('Plant')
->example(['Ransar Industries-I'])
->label('Plant')
->relationship(resolveUsing: 'code')
->exampleHeader('Plant Code')
->example(['1000'])
->label('Plant Code')
->rules(['required']),
];
}
@@ -58,74 +58,74 @@ class MachineImporter extends Importer
public function resolveRecord(): ?Machine
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$line = null;
$machine = $this->data['name'];
$workCenter = $this->data['work_center'];
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found!";
}
else {
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
if ($line) {
$grpWrkCnr = $line->no_of_operation;
if (!$grpWrkCnr || $grpWrkCnr < 1)//Str::length($grpWrkCnr) < 1)
{
$warnMsg[] = "Group work center line not found!";
}
else if (!$groupWorkCenter) {
$warnMsg[] = "Group work center not found!";
}
else {
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
if ($dupMachine) {
$warnMsg[] = "Duplicate machine name found!";
}
else {
$isValidGroupWork = false;
for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id";
if (!empty($line->$column)) {
if ($line->$column == $groupWorkCenter->id) {
$isValidGroupWork = true;
break;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found!';
} else {
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
if ($line) {
$grpWrkCnr = $line->no_of_operation;
if (! $grpWrkCnr || $grpWrkCnr < 1) {// Str::length($grpWrkCnr) < 1)
$warnMsg[] = 'Group work center line not found!';
} elseif (! $groupWorkCenter) {
$warnMsg[] = 'Group work center not found!';
} else {
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
if ($dupMachine) {
$warnMsg[] = 'Duplicate machine name found!';
} else {
$isValidGroupWork = false;
for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id";
if (! empty($line->$column)) {
if ($groupWorkCenter->id == $line->$column) {
$isValidGroupWork = true;
break;
}
}
}
}
if (!$isValidGroupWork) {
$warnMsg[] = "Group work center does not match with line!";
if (! $isValidGroupWork) {
$warnMsg[] = 'Group work center does not match with line!';
}
}
}
} else {
$warnMsg[] = 'Line not found!';
}
}
else
{
$warnMsg[] = "Line not found!";
}
}
if (Str::length($machine) <= 0) {
$warnMsg[] = "Machine name not found!";
$warnMsg[] = 'Machine name not found!';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
Machine::updateOrCreate(
[
'plant_id' => $plant->id,
'work_center' => $workCenter
'work_center' => $workCenter,
],
[
'line_id' => $line->id,
'name' => $machine,
'work_group_master_id' => $groupWorkCenter->id
'work_group_master_id' => $groupWorkCenter->id,
]
);
return null;
// // return Machine::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
@@ -137,10 +137,10 @@ class MachineImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your machine import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your machine import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -15,18 +15,18 @@ class MfmMeterImporter extends Importer
{
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->requiredMapping()
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('Device Name')
->requiredMapping()
->exampleHeader('Device Name')
->example('REG001')
->label('Device Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('sequence')
->requiredMapping()
@@ -56,15 +56,15 @@ class MfmMeterImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new MfmMeter();
return new MfmMeter;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your mfm meter import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your mfm meter import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -16,24 +16,24 @@ class MfmParameterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('deviceName')
->requiredMapping()
->exampleHeader('Device Name')
->example('REG001')
->label('Device Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('mfmMeter')
->requiredMapping()
->exampleHeader('Mfm Meter Sequence')
->example('1')
->label('Mfm Meter Sequence')
->relationship(resolveUsing:'sequence')
->relationship(resolveUsing: 'sequence')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
@@ -82,15 +82,15 @@ class MfmParameterImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new MfmParameter();
return new MfmParameter;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your mfm parameter import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your mfm parameter import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -24,7 +24,7 @@ class MotorTestingMasterImporter extends Importer
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('Item Code')
->example(['123456','123457','123458'])
->example(['123456', '123457', '123458'])
->label('Item Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
@@ -38,181 +38,181 @@ class MotorTestingMasterImporter extends Importer
->requiredMapping()
->boolean()
->exampleHeader('ISI Model')
->example(['Y','N','Y'])
->example(['Y', 'N', 'Y'])
->label('ISI Model')
->rules(['boolean']),
ImportColumn::make('phase')
->requiredMapping()
->exampleHeader('Phase')
->example(['Single','Three','Single'])
->example(['Single', 'Three', 'Single'])
->label('Phase')
->rules(['required']),
ImportColumn::make('hp')
->requiredMapping()
->exampleHeader('HP')
->example(['5','10','5'])
->example(['5', '10', '5'])
->label('HP')
->rules(['required']),
ImportColumn::make('kw')
->requiredMapping()
->exampleHeader('KW')
->example(['5','7.5','5'])
->example(['5', '7.5', '5'])
->label('KW')
->rules(['required']),
ImportColumn::make('volt')
->requiredMapping()
->exampleHeader('Volt')
->example(['230','380','230'])
->example(['230', '380', '230'])
->label('Volt')
->rules(['required']),
ImportColumn::make('current')
->requiredMapping()
->exampleHeader('Current')
->example(['7','21.8','7'])
->example(['7', '21.8', '7'])
->label('Current')
->rules(['required']),
ImportColumn::make('rpm')
->requiredMapping()
->exampleHeader('RPM')
->example(['2500','3420','2500'])
->example(['2500', '3420', '2500'])
->label('RPM')
->rules(['required']),
ImportColumn::make('torque')
->requiredMapping()
->exampleHeader('Torque')
->example(['0.5','1.25','0.5'])
->example(['0.5', '1.25', '0.5'])
->label('Torque')
->rules(['required']),
ImportColumn::make('frequency')
->requiredMapping()
->exampleHeader('Frequency')
->label('Frequency')
->example(['50','60','50'])
->example(['50', '60', '50'])
->rules(['required']),
ImportColumn::make('connection')
->requiredMapping()
->exampleHeader('Connection')
->label('Connection')
->example(['Star','Star-Delta','Delta'])
->example(['Star', 'Star-Delta', 'Delta'])
->rules(['required']),
ImportColumn::make('ins_res_limit')
->requiredMapping()
->exampleHeader('Insulation Resistance Limit')
->label('Insulation Resistance Limit')
->example(['1000','2','1000'])
->example(['1000', '2', '1000'])
->rules(['required']),
ImportColumn::make('ins_res_type')
->requiredMapping()
->exampleHeader('Insulation Resistance Type')
->label('Insulation Resistance Type')
->example(['O','G','O'])
->example(['O', 'G', 'O'])
->rules(['required']),
ImportColumn::make('routine_test_time')
->requiredMapping()
->exampleHeader('Routine Test Time')
->label('Routine Test Time')
->example(['00:40:00','00:40:00','00:40:00'])
->example(['00:40:00', '00:40:00', '00:40:00'])
->rules(['required']),
ImportColumn::make('res_ry_ll')
->requiredMapping()
->exampleHeader('Resistance RY LL')
->label('Resistance RY LL')
->example(['0.05','0.05','0.05'])
->example(['0.05', '0.05', '0.05'])
->rules(['required']),
ImportColumn::make('res_ry_ul')
->requiredMapping()
->exampleHeader('Resistance RY UL')
->label('Resistance RY UL')
->example(['99','99','99'])
->example(['99', '99', '99'])
->rules(['required']),
ImportColumn::make('res_yb_ll')
->requiredMapping()
->exampleHeader('Resistance YB LL')
->label('Resistance YB LL')
->example(['0.05','0.05','0.05'])
->example(['0.05', '0.05', '0.05'])
->rules(['required']),
ImportColumn::make('res_yb_ul')
->requiredMapping()
->exampleHeader('Resistance YB UL')
->label('Resistance YB UL')
->example(['99','99','99'])
->example(['99', '99', '99'])
->rules(['required']),
ImportColumn::make('res_br_ll')
->requiredMapping()
->exampleHeader('Resistance BR LL')
->label('Resistance BR LL')
->example(['0.05','0.05','0.05'])
->example(['0.05', '0.05', '0.05'])
->rules(['required']),
ImportColumn::make('res_br_ul')
->requiredMapping()
->exampleHeader('Resistance BR UL')
->label('Resistance BR UL')
->example(['99','99','99'])
->example(['99', '99', '99'])
->rules(['required']),
ImportColumn::make('lock_volt_limit')
->requiredMapping()
->exampleHeader('Lock Volt Limit')
->label('Lock Volt Limit')
->example(['80','100','80'])
->example(['80', '100', '80'])
->rules(['required']),
ImportColumn::make('leak_cur_limit')
->requiredMapping()
->exampleHeader('Leak Current Limit')
->label('Leak Current Limit')
->example(['50','50','50'])
->example(['50', '50', '50'])
->rules(['required']),
ImportColumn::make('lock_cur_ll')
->requiredMapping()
->exampleHeader('Lock Current LL')
->label('Lock Current LL')
->example(['10','12.5','10'])
->example(['10', '12.5', '10'])
->rules(['required']),
ImportColumn::make('lock_cur_ul')
->requiredMapping()
->exampleHeader('Lock Current UL')
->label('Lock Current UL')
->example(['15','14.6','15'])
->example(['15', '14.6', '15'])
->rules(['required']),
ImportColumn::make('noload_cur_ll')
->requiredMapping()
->exampleHeader('No Load Current LL')
->label('No Load Current LL')
->example(['3','5.9','3'])
->example(['3', '5.9', '3'])
->rules(['required']),
ImportColumn::make('noload_cur_ul')
->requiredMapping()
->exampleHeader('No Load Current UL')
->label('No Load Current UL')
->example(['15','6.9','15'])
->example(['15', '6.9', '15'])
->rules(['required']),
ImportColumn::make('noload_pow_ll')
->requiredMapping()
->exampleHeader('No Load Power LL')
->label('No Load Power LL')
->example(['250','850','250'])
->example(['250', '850', '250'])
->rules(['required']),
ImportColumn::make('noload_pow_ul')
->requiredMapping()
->exampleHeader('No Load Power UL')
->label('No Load Power UL')
->example(['500','1200','500'])
->example(['500', '1200', '500'])
->rules(['required']),
ImportColumn::make('noload_spd_ll')
->requiredMapping()
->exampleHeader('No Load Speed LL')
->label('No Load Speed LL')
->example(['2000','2500','2000'])
->example(['2000', '2500', '2000'])
->rules(['required']),
ImportColumn::make('noload_spd_ul')
->requiredMapping()
->exampleHeader('No Load Speed UL')
->label('No Load Speed UL')
->example(['4000','3500','4000'])
->example(['4000', '3500', '4000'])
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant')
->example(['1000','1010','1020'])
->example(['1000', '1010', '1020'])
->label('Plant')
->relationship(resolveUsing: 'code')
->rules(['required']),
@@ -237,7 +237,7 @@ class MotorTestingMasterImporter extends Importer
$plantCod = trim($this->data['plant']);
$iCode = trim($this->data['item']);
$sCode = trim($this->data['subassembly_code']);
$isiModel = (trim($this->data['isi_model']) == "1") ? true : false;
$isiModel = (trim($this->data['isi_model']) == '1') ? true : false;
$phase = trim($this->data['phase']);
$kw = trim($this->data['kw']);
$hp = trim($this->data['hp']);
@@ -270,40 +270,25 @@ class MotorTestingMasterImporter extends Importer
$updatedBy = trim($this->data['updated_by']);
$plant = null;
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod))
{
$warnMsg[] = "Invalid plant code found";
}
else if (Str::length($iCode) < 6 || !ctype_alnum($iCode))
{
$warnMsg[] = "Invalid item code found";
}
else if (Str::length($sCode) < 6 || !ctype_alnum($sCode))
{
$warnMsg[] = "Invalid sub-assembly code found";
}
else
{
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} elseif (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
} elseif (Str::length($sCode) < 6 || ! ctype_alnum($sCode)) {
$warnMsg[] = 'Invalid sub-assembly code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
$codeExist = Item::where('code', $iCode)->first();
if ($plant)
{
if ($plant) {
$iCode = Item::where('code', $iCode)->where('plant_id', $plant->id)->first();
}
if (!$plant)
{
$warnMsg[] = "Plant not found";
}
else if (!$codeExist)
{
$warnMsg[] = "Item code not found";
}
else if (!$iCode)
{
$warnMsg[] = "Item code not found for choosed plant";
}
else
{
if (! $plant) {
$warnMsg[] = 'Plant not found';
} elseif (! $codeExist) {
$warnMsg[] = 'Item code not found';
} elseif (! $iCode) {
$warnMsg[] = 'Item code not found for choosed plant';
} else {
// if (Str::length($isiModel) <= 0 || $isiModel == "0" || $isiModel == "1") {
// $warnMsg[] = "Invalid ISI Model found";
// }
@@ -311,125 +296,123 @@ class MotorTestingMasterImporter extends Importer
// {
// $isiModel = ($isiModel == "1");
// }
if (Str::length($phase) <= 0 || ($phase != "Single" && $phase != "Three")) {//!is_string($phase) ||
$warnMsg[] = "Invalid phase found";
if (Str::length($phase) <= 0 || ($phase != 'Single' && $phase != 'Three')) {// !is_string($phase) ||
$warnMsg[] = 'Invalid phase found';
}
if (Str::length($hp) <= 0 || !is_numeric($hp)) {
$warnMsg[] = "Invalid HP found";
if (Str::length($hp) <= 0 || ! is_numeric($hp)) {
$warnMsg[] = 'Invalid HP found';
}
if (Str::length($kw) <= 0 || !is_numeric($kw)) {
$warnMsg[] = "Invalid KW found";
if (Str::length($kw) <= 0 || ! is_numeric($kw)) {
$warnMsg[] = 'Invalid KW found';
}
if (Str::length($volt) <= 0 || !is_numeric($volt)) {
$warnMsg[] = "Invalid volt found";
if (Str::length($volt) <= 0 || ! is_numeric($volt)) {
$warnMsg[] = 'Invalid volt found';
}
if (Str::length($current) <= 0 || !is_numeric($current)) {
$warnMsg[] = "Invalid current found";
if (Str::length($current) <= 0 || ! is_numeric($current)) {
$warnMsg[] = 'Invalid current found';
}
if (Str::length($rpm) <= 0 || !is_numeric($rpm)) {
$warnMsg[] = "Invalid RPM found";
if (Str::length($rpm) <= 0 || ! is_numeric($rpm)) {
$warnMsg[] = 'Invalid RPM found';
}
if (Str::length($torque) <= 0 || !is_numeric($torque)) {
$warnMsg[] = "Invalid torque found";
if (Str::length($torque) <= 0 || ! is_numeric($torque)) {
$warnMsg[] = 'Invalid torque found';
}
if (Str::length($frequency) <= 0 || !is_numeric($frequency)) {
$warnMsg[] = "Invalid frequency found";
if (Str::length($frequency) <= 0 || ! is_numeric($frequency)) {
$warnMsg[] = 'Invalid frequency found';
}
if (Str::length($connection) <= 0 || ($connection != "Star-Delta" && $connection != "Star" && $connection != "Delta")) {
$warnMsg[] = "Invalid connection found";
if (Str::length($connection) <= 0 || ($connection != 'Star-Delta' && $connection != 'Star' && $connection != 'Delta')) {
$warnMsg[] = 'Invalid connection found';
}
if (Str::length($insResLimit) <= 0 || !is_numeric($insResLimit)) {
$warnMsg[] = "Invalid insulation resistance limit found";
if (Str::length($insResLimit) <= 0 || ! is_numeric($insResLimit)) {
$warnMsg[] = 'Invalid insulation resistance limit found';
}
if (Str::length($insResType) <= 0 || ($insResType != "O" && $insResType != "M" && $insResType != "G")) {
$warnMsg[] = "Invalid insulation resistance type found";
if (Str::length($insResType) <= 0 || ($insResType != 'O' && $insResType != 'M' && $insResType != 'G')) {
$warnMsg[] = 'Invalid insulation resistance type found';
}
if (Str::length($routineTestTime) <= 0 || !isValidTimeFormat($routineTestTime)) {
$warnMsg[] = "Invalid routine test time found";
if (Str::length($routineTestTime) <= 0 || ! isValidTimeFormat($routineTestTime)) {
$warnMsg[] = 'Invalid routine test time found';
}
if (Str::length($resRyLl) <= 0 || !is_numeric($resRyLl)) {
$warnMsg[] = "Invalid resistance RY lower limit found";
if (Str::length($resRyLl) <= 0 || ! is_numeric($resRyLl)) {
$warnMsg[] = 'Invalid resistance RY lower limit found';
}
if (Str::length($resRyUl) <= 0 || !is_numeric($resRyUl)) {
$warnMsg[] = "Invalid resistance RY upper limit found";
if (Str::length($resRyUl) <= 0 || ! is_numeric($resRyUl)) {
$warnMsg[] = 'Invalid resistance RY upper limit found';
}
if (Str::length($resYbLl) <= 0 || !is_numeric($resYbLl)) {
$warnMsg[] = "Invalid resistance YB lower limit found";
if (Str::length($resYbLl) <= 0 || ! is_numeric($resYbLl)) {
$warnMsg[] = 'Invalid resistance YB lower limit found';
}
if (Str::length($resYbUl) <= 0 || !is_numeric($resYbUl)) {
$warnMsg[] = "Invalid resistance YB upper limit found";
if (Str::length($resYbUl) <= 0 || ! is_numeric($resYbUl)) {
$warnMsg[] = 'Invalid resistance YB upper limit found';
}
if (Str::length($resBrLl) <= 0 || !is_numeric($resBrLl)) {
$warnMsg[] = "Invalid resistance BR lower limit found";
if (Str::length($resBrLl) <= 0 || ! is_numeric($resBrLl)) {
$warnMsg[] = 'Invalid resistance BR lower limit found';
}
if (Str::length($resBrUl) <= 0 || !is_numeric($resBrUl)) {
$warnMsg[] = "Invalid resistance BR upper limit found";
if (Str::length($resBrUl) <= 0 || ! is_numeric($resBrUl)) {
$warnMsg[] = 'Invalid resistance BR upper limit found';
}
if (Str::length($lockVoltLimit) <= 0 || !is_numeric($lockVoltLimit)) {
$warnMsg[] = "Invalid locked volt limit found";
if (Str::length($lockVoltLimit) <= 0 || ! is_numeric($lockVoltLimit)) {
$warnMsg[] = 'Invalid locked volt limit found';
}
if (Str::length($leakCurLimit) <= 0 || !is_numeric($leakCurLimit)) {
$warnMsg[] = "Invalid leakage current limit found";
if (Str::length($leakCurLimit) <= 0 || ! is_numeric($leakCurLimit)) {
$warnMsg[] = 'Invalid leakage current limit found';
}
if (Str::length($lockCurLl) <= 0 || !is_numeric($lockCurLl)) {
$warnMsg[] = "Invalid locked current lower limit found";
if (Str::length($lockCurLl) <= 0 || ! is_numeric($lockCurLl)) {
$warnMsg[] = 'Invalid locked current lower limit found';
}
if (Str::length($lockCurUl) <= 0 || !is_numeric($lockCurUl)) {
$warnMsg[] = "Invalid locked current upper limit found";
if (Str::length($lockCurUl) <= 0 || ! is_numeric($lockCurUl)) {
$warnMsg[] = 'Invalid locked current upper limit found';
}
if (Str::length($noloadCurLl) <= 0 || !is_numeric($noloadCurLl)) {
$warnMsg[] = "Invalid no load current lower limit found";
if (Str::length($noloadCurLl) <= 0 || ! is_numeric($noloadCurLl)) {
$warnMsg[] = 'Invalid no load current lower limit found';
}
if (Str::length($noloadCurUl) <= 0 || !is_numeric($noloadCurUl)) {
$warnMsg[] = "Invalid no load current upper limit found";
if (Str::length($noloadCurUl) <= 0 || ! is_numeric($noloadCurUl)) {
$warnMsg[] = 'Invalid no load current upper limit found';
}
if (Str::length($noloadPowLl) <= 0 || !is_numeric($noloadPowLl)) {
$warnMsg[] = "Invalid no load power lower limit found";
if (Str::length($noloadPowLl) <= 0 || ! is_numeric($noloadPowLl)) {
$warnMsg[] = 'Invalid no load power lower limit found';
}
if (Str::length($noloadPowUl) <= 0 || !is_numeric($noloadPowUl)) {
$warnMsg[] = "Invalid no load power upper limit found";
if (Str::length($noloadPowUl) <= 0 || ! is_numeric($noloadPowUl)) {
$warnMsg[] = 'Invalid no load power upper limit found';
}
if (Str::length($noloadSpdLl) <= 0 || !is_numeric($noloadSpdLl)) {
$warnMsg[] = "Invalid no load speed lower limit found";
if (Str::length($noloadSpdLl) <= 0 || ! is_numeric($noloadSpdLl)) {
$warnMsg[] = 'Invalid no load speed lower limit found';
}
if (Str::length($noloadSpdUl) <= 0 || !is_numeric($noloadSpdUl)) {
$warnMsg[] = "Invalid no load speed upper limit found";
if (Str::length($noloadSpdUl) <= 0 || ! is_numeric($noloadSpdUl)) {
$warnMsg[] = 'Invalid no load speed upper limit found';
}
$oldCode = MotorTestingMaster::where('item_id', $iCode->id)->where('plant_id', $plant->id)->first();
if ($oldCode) {
$created = $oldCode->created_by ? User::where('name', $oldCode->created_by)->first() : null;
if (!$created) {
$warnMsg[] = "Created by not found on update";
if (! $created) {
$warnMsg[] = 'Created by not found on update';
}
$updated = User::where('name', $updatedBy)->first();
if (!$updated) {
$warnMsg[] = "Updated by not found on update";
if (! $updated) {
$warnMsg[] = 'Updated by not found on update';
}
}
else
{
} else {
$created = User::where('name', $createdBy)->first();
if (!$created) {
$warnMsg[] = "Created by not found";
if (! $created) {
$warnMsg[] = 'Created by not found';
}
$updated = User::where('name', $updatedBy)->first();
if (!$updated) {
$warnMsg[] = "Updated by not found";
if (! $updated) {
$warnMsg[] = 'Updated by not found';
}
}
}
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
MotorTestingMaster::updateOrCreate([
'plant_id' => $plant->id,
'item_id' => $iCode->id
],
'item_id' => $iCode->id,
],
[
'subassembly_code' => $sCode,
'isi_model' => $isiModel,
@@ -465,6 +448,7 @@ class MotorTestingMasterImporter extends Importer
'updated_by' => $updated->name,
]
);
return null;
// // return MotorTestingMaster::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
@@ -476,22 +460,24 @@ class MotorTestingMasterImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your motor testing master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your motor testing master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;
}
}
function isValidTimeFormat($time) {
function isValidTimeFormat($time)
{
// If time starts with a single digit hour without leading zero, pad it
if (preg_match('/^\d(:\d{2}:\d{2})$/', $time, $matches)) {
$time = '0' . $time;
$time = '0'.$time;
}
$dateTime = DateTime::createFromFormat('H:i:s', $time);
return $dateTime && $dateTime->format('H:i:s') === $time;
}

View File

@@ -12,7 +12,6 @@ use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Str;
class PalletValidationImporter extends Importer
{
protected static ?string $model = PalletValidation::class;
@@ -122,49 +121,45 @@ class PalletValidationImporter extends Importer
$scannedBy = $this->data['scanned_by'];
$updatedBy = $this->data['updated_by'];
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code found";
}
else
{
$plant = Plant::where('code', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
else
{
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
$warnMsg[] = "Invalid serial number found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
$warnMsg[] = 'Invalid serial number found';
}
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
$warnMsg[] = "Invalid pallet number found";
$warnMsg[] = 'Invalid pallet number found';
}
if (Str::length($palletStat) > 0 && $palletStat != 'Completed') {
$warnMsg[] = "Invalid pallet status found";
$warnMsg[] = 'Invalid pallet status found';
}
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
$warnMsg[] = "Invalid locator number found";
$warnMsg[] = 'Invalid locator number found';
}
if (Str::length($palletNo) <= 0 && Str::length($locatorNo) <= 0) {
$warnMsg[] = "Pallet and locator number found";
$warnMsg[] = 'Pallet and locator number found';
}
if (Str::length($locatorQty) < 0 || !is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) {
$warnMsg[] = "Invalid locator quantity found";
if (Str::length($locatorQty) < 0 || ! is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) {
$warnMsg[] = 'Invalid locator quantity found';
}
$created = User::where('name', $createdBy)->first();
if (!$created) {
$warnMsg[] = "Created by not found";
if (! $created) {
$warnMsg[] = 'Created by not found';
}
$scanned = User::where('name', $scannedBy)->first();
if (!$scanned) {
$warnMsg[] = "Scanned by not found";
if (! $scanned) {
$warnMsg[] = 'Scanned by not found';
}
$updated = User::where('name', $updatedBy)->first();
if (!$updated) {
$warnMsg[] = "Updated by not found";
if (! $updated) {
$warnMsg[] = 'Updated by not found';
}
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
foreach ($formats as $format) {
try {
@@ -176,7 +171,7 @@ class PalletValidationImporter extends Importer
}
}
if (!isset($cDateTime)) {
if (! isset($cDateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -191,13 +186,12 @@ class PalletValidationImporter extends Importer
}
}
if (!isset($sDateTime)) {
if (! isset($sDateTime)) {
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
foreach ($formats as $format) {
try
{
try {
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
break;
} catch (\Exception $e) {
@@ -206,11 +200,9 @@ class PalletValidationImporter extends Importer
}
}
if (!isset($uDateTime)) {
if (! isset($uDateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else
{
} else {
if (isset($cDateTime) && isset($uDateTime)) {
if ($cDateTime->greaterThan($uDateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
@@ -224,14 +216,14 @@ class PalletValidationImporter extends Importer
// $warnMsg[] = "Invalid locator quantity found";
// }
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
PalletValidation::updateOrCreate(
[
'plant_id' => $plant->id,
'serial_number' => $serialNo
'serial_number' => $serialNo,
],
[
'pallet_number' => $palletNo,
@@ -243,9 +235,10 @@ class PalletValidationImporter extends Importer
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
'created_by' => $createdBy,
'scanned_by' => $scannedBy,
'updated_by' => $updatedBy
'updated_by' => $updatedBy,
]
);
return null;
// // return PalletValidation::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
@@ -257,10 +250,10 @@ class PalletValidationImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your pallet validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your pallet validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -23,7 +23,7 @@ class PlantImporter extends Importer
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->rules(['required']), //, 'integer'
->rules(['required']), // , 'integer'
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Plant Name')
@@ -41,7 +41,7 @@ class PlantImporter extends Importer
->exampleHeader('Company Name')
->example('C.R.I. Pumps Private Limited')
->label('Company Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
];
}
@@ -50,41 +50,40 @@ class PlantImporter extends Importer
{
$warnMsg = [];
$company = Company::where('name', $this->data['company'])->first();
if (!$company) {
$warnMsg[] = "Company name not found";
if (! $company) {
$warnMsg[] = 'Company name not found';
}
if (Str::length($this->data['name']) < 0) {
$warnMsg[] = "Plant name not found";
$warnMsg[] = 'Plant name not found';
}
if (Str::length($this->data['code']) < 4 || !is_numeric($this->data['code']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['code'])) {
$warnMsg[] = "Invalid plant code found";
if (Str::length($this->data['code']) < 4 || ! is_numeric($this->data['code']) || ! preg_match('/^[1-9]\d{3,}$/', $this->data['code'])) {
$warnMsg[] = 'Invalid plant code found';
}
if (Str::length($this->data['address']) < 3) {
$warnMsg[] = "Invalid address found";
$warnMsg[] = 'Invalid address found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
$plantCN = Plant::where('code', $this->data['code'])->where('name', $this->data['name'])->first();
if (!$plantCN) {
if (! $plantCN) {
$plantCode = Plant::where('code', $this->data['code'])->first();
$plantName = Plant::where('name', $this->data['name'])->first();
if ($plantName) {
throw new RowImportFailedException("Duplicate plant name found");
}
else if ($plantCode) {
throw new RowImportFailedException("Duplicate plant code found");
throw new RowImportFailedException('Duplicate plant name found');
} elseif ($plantCode) {
throw new RowImportFailedException('Duplicate plant code found');
}
}
return Plant::updateOrCreate([
'code' => $this->data['code'],
'name' => $this->data['name'],
],
'code' => $this->data['code'],
'name' => $this->data['name'],
],
[
'address' => $this->data['address'],
'company_id' => $company->id
'company_id' => $company->id,
]
);
// return Plant::firstOrNew([
@@ -97,10 +96,10 @@ class PlantImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your plant import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your plant import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -15,6 +15,7 @@ use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Str;
class ProductionLineStopImporter extends Importer
{
@@ -28,7 +29,7 @@ class ProductionLineStopImporter extends Importer
->exampleHeader('From DateTime')
->example(['01-01-2025 00:00:00', '01-01-2025 20:00:00'])
->label('From DateTime')
->rules(['required']), //, 'date_format:"d-m-Y H:i:s"'
->rules(['required']), // , 'date_format:"d-m-Y H:i:s"'
ImportColumn::make('to_datetime')
->requiredMapping()
->exampleHeader('To DateTime')
@@ -45,7 +46,7 @@ class ProductionLineStopImporter extends Importer
ImportColumn::make('stop_min')
->requiredMapping()
->exampleHeader('Stop Min')
->example(['25','0'])
->example(['25', '0'])
->label('Stop Min')
->numeric()
->rules(['required', 'integer']),
@@ -54,14 +55,14 @@ class ProductionLineStopImporter extends Importer
->exampleHeader('Line Stop Code')
->example(['A7R', 'A1R'])
->label('Line Stop Code')
->relationship(resolveUsing:'code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('line')
->requiredMapping()
->exampleHeader('Line Name')
->example(['4 inch pump line', '4 inch pump line'])
->label('Line Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('block_reference')
->requiredMapping() // Or optionalMapping() if not always present
@@ -78,10 +79,10 @@ class ProductionLineStopImporter extends Importer
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example(['Ransar Industries-I', 'Ransar Industries-I'])
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example(['1000', '1000'])
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('operator_id')
->requiredMapping()
@@ -95,61 +96,62 @@ class ProductionLineStopImporter extends Importer
public function resolveRecord(): ?ProductionLineStop
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$line = null;
$block = null;
if (!$plant) {
$warnMsg[] = "Plant not found";
}
else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
//block_reference
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
}
if (!$line) {
$warnMsg[] = "Line not found";
}
$shift = null;
if (!$block) {
$warnMsg[] = "Block not found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
// block_reference
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
}
}
else {
if (! $line) {
$warnMsg[] = 'Line not found';
}
if (! $block) {
$warnMsg[] = 'Block not found';
} elseif ($plant) {
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
}
//$shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (!$shift) {
$warnMsg[] = "Shift not found";
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (! $shift) {
$warnMsg[] = 'Shift not found';
}
$linestop = LineStop::where('code', $this->data['linestop'])->first();
if (!$linestop) {
$warnMsg[] = "Line stop code not found";
if (! $linestop) {
$warnMsg[] = 'Line stop code not found';
}
$stophour = is_numeric($this->data['stop_hour']) && $this->data['stop_hour'] >= 0;
$stopmin = is_numeric($this->data['stop_min']) && $this->data['stop_min'] >= 0 && $this->data['stop_min'] <= 60;
if (!$stophour && !$stopmin) {
$warnMsg[] = "Invalid stop hour/minute found";
}
else if (!$stophour) {
$warnMsg[] = "Invalid stop hour found";
}
else if (!$stopmin) {
$warnMsg[] = "Invalid stop min found";
}
else {
$stophour = (int)$this->data['stop_hour'];
$stopmin = (int)$this->data['stop_min'];
if (! $stophour && ! $stopmin) {
$warnMsg[] = 'Invalid stop hour/minute found';
} elseif (! $stophour) {
$warnMsg[] = 'Invalid stop hour found';
} elseif (! $stopmin) {
$warnMsg[] = 'Invalid stop min found';
} else {
$stophour = (int) $this->data['stop_hour'];
$stopmin = (int) $this->data['stop_min'];
if ($stophour == 0 && $stopmin == 0) {
$warnMsg[] = "Invalid stop hour/minute found";
$warnMsg[] = 'Invalid stop hour/minute found';
}
}
$validHourMin = ($stophour == 0 && $stopmin == 0) ? false : true;
if (!$validHourMin) {
$warnMsg[] = "Invalid stop hour/minute found";
if (! $validHourMin) {
$warnMsg[] = 'Invalid stop hour/minute found';
}
$fromDate = $this->data['from_datetime'];
$toDate = $this->data['to_datetime'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$fdateTime = null;
$tdateTime = null;
@@ -175,14 +177,14 @@ class ProductionLineStopImporter extends Importer
}
// $fDateOnly = '';
if (!isset($fdateTime)) {
if (! isset($fdateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'From DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
// else {
// $fDateOnly = $fdateTime->toDateString();
// }
if (!isset($tdateTime)) {
if (! isset($tdateTime)) {
$warnMsg[] = "Invalid 'To DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -200,11 +202,11 @@ class ProductionLineStopImporter extends Importer
// }
$user = User::where('name', $this->data['operator_id'])->first();
if (!$user) {
$warnMsg[] = "Operator ID not found";
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -213,12 +215,13 @@ class ProductionLineStopImporter extends Importer
'line_id' => $line->id,
'shift_id' => $shift->id,
'linestop_id' => $linestop->id,
'from_datetime' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['from_datetime'],
'to_datetime' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['to_datetime'],
'stop_hour' => (int)$this->data['stop_hour'],
'stop_min' => (int)$this->data['stop_min'],
'from_datetime' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['from_datetime'],
'to_datetime' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['to_datetime'],
'stop_hour' => (int) $this->data['stop_hour'],
'stop_min' => (int) $this->data['stop_min'],
'operator_id' => $this->data['operator_id'],
]);
return null;
// return ProductionLineStop::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
@@ -230,10 +233,10 @@ class ProductionLineStopImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your production line stop import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your production line stop import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -48,7 +48,7 @@ class ProductionPlanImporter extends Importer
->exampleHeader('Line Name')
->example(['4 inch pump line', '4 inch pump line'])
->label('Line Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('block_reference')
->requiredMapping() // Or optionalMapping() if not always present
@@ -58,17 +58,17 @@ class ProductionPlanImporter extends Importer
->rules(['required']), // Or remove if not required
ImportColumn::make('shift')
->requiredMapping()
->exampleHeader('Shift Name') //ID
->example(['Day', 'Night']) //'2', '7'
->exampleHeader('Shift Name') // ID
->example(['Day', 'Night']) // '2', '7'
->label('Shift Name') // ID
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example(['Ransar Industries-I', 'Ransar Industries-I'])
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example(['1000', '1000'])
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('updated_at')
->requiredMapping()
@@ -88,42 +88,51 @@ class ProductionPlanImporter extends Importer
public function resolveRecord(): ?ProductionPlan
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$line = null;
$block = null;
if (!$plant) {
$warnMsg[] = "Plant not found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
else {
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
//block_reference
// block_reference
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
}
if (!$line) {
$warnMsg[] = "Line not found";
if (! $line) {
$warnMsg[] = 'Line not found';
}
$shift = null;
if (!$block) {
$warnMsg[] = "Block not found";
}
else {
if (! $block) {
$warnMsg[] = 'Block not found';
} elseif ($plant) {
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
}
//$shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (!$shift) {
$warnMsg[] = "Shift not found";
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (! $shift) {
$warnMsg[] = 'Shift not found';
}
if (Str::length($this->data['plan_quantity']) < 0 || !is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
$warnMsg[] = "Invalid plan quantity found";
if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
$warnMsg[] = 'Invalid plan quantity found';
}
if (Str::length($this->data['production_quantity']) < 0 || !is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
$warnMsg[] = "Invalid production quantity found";
if (Str::length($this->data['production_quantity']) < 0 || ! is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
$warnMsg[] = 'Invalid production quantity found';
}
$fromDate = $this->data['created_at'];
$toDate = $this->data['updated_at'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$fdateTime = null;
$tdateTime = null;
@@ -149,14 +158,13 @@ class ProductionPlanImporter extends Importer
}
$fDateOnly = '';
if (!isset($fdateTime)) {
if (! isset($fdateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else {
} else {
$fDateOnly = $fdateTime->toDateString();
}
if (!isset($tdateTime)) {
if (! isset($tdateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -174,21 +182,20 @@ class ProductionPlanImporter extends Importer
// }
$user = User::where('name', $this->data['operator_id'])->first();
if (!$user) {
$warnMsg[] = "Operator ID not found";
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
else { //if (empty($warnMsg))
} else { // if (empty($warnMsg))
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
->where('shift_id', $shift->id)
->where('line_id', $line->id)
->whereDate('created_at', $fDateOnly)
->where('shift_id', $shift->id)
->where('line_id', $line->id)
->whereDate('created_at', $fDateOnly)
// ->where('plan_quantity', $productionQuantity->plan_quantity)
->latest()
->first();
->latest()
->first();
if ($productionPlan) {
// if($productionPlan->production_quantity)
@@ -205,6 +212,7 @@ class ProductionPlanImporter extends Importer
'operator_id' => $this->data['operator_id'],
]);
$productionPlan->save();
return null;
}
}
@@ -215,10 +223,11 @@ class ProductionPlanImporter extends Importer
'shift_id' => $shift->id,
'plan_quantity' => $this->data['plan_quantity'],
'production_quantity' => $this->data['production_quantity'],
'created_at' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
'operator_id' => $this->data['operator_id'],
]);
return null;
// return ProductionPlan::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
@@ -230,10 +239,10 @@ class ProductionPlanImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your production plan import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your production plan import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -42,7 +42,7 @@ class ProductionQuantityImporter extends Importer
->exampleHeader('Item Code')
->example(['123456', '123456'])
->label('Item Code')
->relationship(resolveUsing:'code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('serial_number')
->requiredMapping()
@@ -55,27 +55,27 @@ class ProductionQuantityImporter extends Importer
->exampleHeader('Line Name')
->example(['4 inch pump line', '4 inch pump line'])
->label('Line Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('block_reference')
->requiredMapping() // Or optionalMapping() if not always present
->exampleHeader('Block')
->exampleHeader('Block Name')
->example(['Block A', 'Block A'])
->label('Block')
->label('Block Name')
->rules(['required']), // Or remove if not required
ImportColumn::make('shift')
->requiredMapping()
->exampleHeader('Shift Name')
->example(['Day', 'Night'])
->label('Shift Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example(['Ransar Industries-I', 'Ransar Industries-I'])
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example(['1000', '1000'])
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('updated_at')
->requiredMapping()
@@ -95,49 +95,57 @@ class ProductionQuantityImporter extends Importer
public function resolveRecord(): ?ProductionQuantity
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$line = null;
$block = null;
if (!$plant) {
$warnMsg[] = "Plant not found";
$shift = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
else {
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
//block_reference
// block_reference
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
}
if (!$line) {
$warnMsg[] = "Line not found";
if (! $line) {
$warnMsg[] = 'Line not found';
}
$shift = null;
if (!$block) {
$warnMsg[] = "Block not found";
}
else {
if (! $block) {
$warnMsg[] = 'Block not found';
} elseif ($plant) {
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
}
//$shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (!$shift) {
$warnMsg[] = "Shift not found";
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (! $shift) {
$warnMsg[] = 'Shift not found';
}
$item = null;
if ($plant) {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
}
if (!$item) {
$warnMsg[] = "Item not found";
if (! $item) {
$warnMsg[] = 'Item not found';
}
if (Str::length($this->data['serial_number']) < 9 || !ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = "Invalid serial number found";
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = 'Invalid serial number found';
}
if (Str::length($this->data['production_order']) > 0 && (Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14 || !is_numeric($this->data['production_order']))) {
$warnMsg[] = "Invalid production order found";
if (Str::length($this->data['production_order']) > 0 && (Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14 || ! is_numeric($this->data['production_order']))) {
$warnMsg[] = 'Invalid production order found';
}
$fromDate = $this->data['created_at'];
$toDate = $this->data['updated_at'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$fdateTime = null;
$tdateTime = null;
@@ -163,14 +171,14 @@ class ProductionQuantityImporter extends Importer
}
// $fDateOnly = '';
if (!isset($fdateTime)) {
if (! isset($fdateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
// else {
// $fDateOnly = $fdateTime->toDateString();
// }
if (!isset($tdateTime)) {
if (! isset($tdateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -187,21 +195,20 @@ class ProductionQuantityImporter extends Importer
// }
$user = User::where('name', $this->data['operator_id'])->first();
if (!$user) {
$warnMsg[] = "Operator ID not found";
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
else { //if (empty($warnMsg))
} else { // if (empty($warnMsg))
$productionQuan = ProductionQuantity::where('plant_id', $plant->id)
->where('serial_number', $this->data['serial_number'])
->latest()
->first();
->where('serial_number', $this->data['serial_number'])
->latest()
->first();
if ($productionQuan) {
throw new RowImportFailedException("Serial number already exist!");
throw new RowImportFailedException('Serial number already exist!');
}
}
@@ -212,10 +219,11 @@ class ProductionQuantityImporter extends Importer
'line_id' => $line->id,
'item_id' => $item->id,
'production_order' => $this->data['production_order'] ?? null,
'created_at' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
'operator_id' => $this->data['operator_id'],
]);
// ProductionQuantity::updateOrCreate([
// 'serial_number' => $this->data['serial_number'],
// 'plant_id' => $plant->id,
@@ -236,10 +244,10 @@ class ProductionQuantityImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your production quantity import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your production quantity import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;
@@ -259,7 +267,7 @@ class ProductionQuantityImporter extends Importer
'line_id' => $this->resolveLineId($row['line']),
'shift_id' => $this->resolveShiftId($row['shift']),
'plant_id' => $this->resolvePlantId($row['plant']),
'updated_at' => $row['updated_at']
'updated_at' => $row['updated_at'],
]);
} finally {
// Always disable flag even if errors occur

View File

@@ -14,7 +14,6 @@ use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Illuminate\Validation\Rule;
use Str;
class QualityValidationImporter extends Importer
@@ -35,16 +34,16 @@ class QualityValidationImporter extends Importer
->exampleHeader('Item Code')
->example('123456')
->label('Item Code'),
// ->relationship(
// name: 'stickerMaster',
// resolveUsing: function ($state) {
// $state = trim($state);
// $item = Item::where('code', $state)->first();
// return $item
// ? StickerMaster::where('item_id', $item->id)->value('id')
// : null;
// }
// ),
// ->relationship(
// name: 'stickerMaster',
// resolveUsing: function ($state) {
// $state = trim($state);
// $item = Item::where('code', $state)->first();
// return $item
// ? StickerMaster::where('item_id', $item->id)->value('id')
// : null;
// }
// ),
ImportColumn::make('production_order')
->requiredMapping()
->exampleHeader('Production Order')
@@ -101,6 +100,11 @@ class QualityValidationImporter extends Importer
->exampleHeader('Name Plate PumpSet')
->example('1')
->label('Name Plate PumpSet'),
ImportColumn::make('warranty_card')
->requiredMapping()
->exampleHeader('Warranty Card')
->example('1')
->label('Warranty Card'),
ImportColumn::make('tube_sticker_motor')
->requiredMapping()
->exampleHeader('Tube Sticker Motor')
@@ -116,11 +120,6 @@ class QualityValidationImporter extends Importer
->exampleHeader('Tube Sticker PumpSet')
->example('1')
->label('Tube Sticker PumpSet'),
ImportColumn::make('warranty_card')
->requiredMapping()
->exampleHeader('Warranty Card')
->example('1')
->label('Warranty Card'),
ImportColumn::make('part_validation1')
->requiredMapping()
->exampleHeader('Part Validation 1')
@@ -156,14 +155,14 @@ class QualityValidationImporter extends Importer
->exampleHeader('Line Name')
->example('4 inch pump line')
->label('Line Name')
->relationship(resolveUsing:'name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('updated_at')
->requiredMapping()
@@ -183,35 +182,41 @@ class QualityValidationImporter extends Importer
public function resolveRecord(): ?QualityValidation
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$line = null;
$stickMaster = null;
if (!$plant) {
$warnMsg[] = "Plant not found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
else {
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
$uniqueCode = trim($this->data['sticker_master_id_code']);// stickerMaster.item
$uniqueCode = trim($this->data['sticker_master_id_code']); // stickerMaster.item
$stickMaster = StickerMaster::select('id')->with('item')
->whereHas('item', function ($query) use ($uniqueCode, $plant) {
$query->where('code', $uniqueCode)->where('plant_id', $plant->id);
})->value('id');
}
if (!$line) {
$warnMsg[] = "Line not found";
if (! $line) {
$warnMsg[] = 'Line not found';
}
if (!$stickMaster) {
$warnMsg[] = "Sticker item code not found";
if (! $stickMaster) {
$warnMsg[] = 'Sticker item code not found';
}
if (!is_numeric($this->data['production_order']) || Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14) {
$warnMsg[] = "Invalid production order found";
if (! is_numeric($this->data['production_order']) || Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14) {
$warnMsg[] = 'Invalid production order found';
}
if (!ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
$warnMsg[] = "Invalid serial number found";
if (! ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
$warnMsg[] = 'Invalid serial number found';
}
// dd($stickMaster);
@@ -220,13 +225,13 @@ class QualityValidationImporter extends Importer
// }
$user = User::where('name', $this->data['operator_id'])->first();
if (!$user) {
$warnMsg[] = "Operator ID not found";
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
$fromDate = $this->data['created_at'];
$toDate = $this->data['updated_at'];
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$fdateTime = null;
$tdateTime = null;
@@ -252,14 +257,14 @@ class QualityValidationImporter extends Importer
}
// $fDateOnly = '';
if (!isset($fdateTime)) {
if (! isset($fdateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
// else {
// $fDateOnly = $fdateTime->toDateString();
// }
if (!isset($tdateTime)) {
if (! isset($tdateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -275,41 +280,41 @@ class QualityValidationImporter extends Importer
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
// }
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
QualityValidation::updateOrCreate([
'plant_id' => $plant->id,
'sticker_master_id' => $stickMaster,//->id
'serial_number' => $this->data['serial_number']
'sticker_master_id' => $stickMaster, // ->id
'serial_number' => $this->data['serial_number'],
],
[
'line_id' => $line->id,
'uom' => $this->data['uom'],
'production_order' => $this->data['production_order'],
'serial_number_motor' => $this->data['serial_number_motor'],
'serial_number_pump' => $this->data['serial_number_pump'],
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
'pack_slip_motor' => $this->data['pack_slip_motor'],
'pack_slip_pump' => $this->data['pack_slip_pump'],
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
'name_plate_motor' => $this->data['name_plate_motor'],
'name_plate_pump' => $this->data['name_plate_pump'],
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
'warranty_card' => $this->data['warranty_card'],
'part_validation1' => $this->data['part_validation1'],
'part_validation2' => $this->data['part_validation2'],
'part_validation3' => $this->data['part_validation3'],
'part_validation4' => $this->data['part_validation4'],
'part_validation5' => $this->data['part_validation5'],
'created_at' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
'operator_id' => $this->data['operator_id'],
]);
[
'line_id' => $line->id,
'uom' => $this->data['uom'],
'production_order' => $this->data['production_order'],
'serial_number_motor' => $this->data['serial_number_motor'],
'serial_number_pump' => $this->data['serial_number_pump'],
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
'pack_slip_motor' => $this->data['pack_slip_motor'],
'pack_slip_pump' => $this->data['pack_slip_pump'],
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
'name_plate_motor' => $this->data['name_plate_motor'],
'name_plate_pump' => $this->data['name_plate_pump'],
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
'warranty_card' => $this->data['warranty_card'],
'part_validation1' => $this->data['part_validation1'],
'part_validation2' => $this->data['part_validation2'],
'part_validation3' => $this->data['part_validation3'],
'part_validation4' => $this->data['part_validation4'],
'part_validation5' => $this->data['part_validation5'],
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
'operator_id' => $this->data['operator_id'],
]);
return null;
// return QualityValidation::firstOrNew([
@@ -322,10 +327,10 @@ class QualityValidationImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your quality validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your quality validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -134,55 +134,51 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
$updatedBy = $this->data['updated_by'];
$reworkedBy = $this->data['reworked_by'];
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = "Invalid plant code found";
}
else
{
$plant = Plant::where('code', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
else
{
if (Str::length($invoiceNo) < 5 || !ctype_alnum($invoiceNo)) {
$warnMsg[] = "Invalid invoice number found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) {
$warnMsg[] = 'Invalid invoice number found';
}
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || !ctype_alnum($serialNo)) {
$warnMsg[] = "Invalid serial number found";
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
$warnMsg[] = 'Invalid serial number found';
}
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
$warnMsg[] = "Invalid pallet number found";
$warnMsg[] = 'Invalid pallet number found';
}
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
$warnMsg[] = "Invalid locator number found";
$warnMsg[] = 'Invalid locator number found';
}
if ($scannedStat != 'Scanned') {
$warnMsg[] = "Invalid scanned status found";
$warnMsg[] = 'Invalid scanned status found';
}
if ($uploadStat != 'Y' && $uploadStat != 'N') {
$warnMsg[] = "Invalid upload status found";
$warnMsg[] = 'Invalid upload status found';
}
$created = User::where('name', $createdBy)->first();
if (!$created) {
$warnMsg[] = "Created by not found";
if (! $created) {
$warnMsg[] = 'Created by not found';
}
$scanned = User::where('name', $scannedBy)->first();
if (!$scanned) {
$warnMsg[] = "Scanned by not found";
if (! $scanned) {
$warnMsg[] = 'Scanned by not found';
}
if (Str::length($updatedBy) > 0) {
$updated = User::where('name', $updatedBy)->first();
if (!$updated) {
$warnMsg[] = "Updated by not found";
if (! $updated) {
$warnMsg[] = 'Updated by not found';
}
}
$reworked = User::where('name', $reworkedBy)->first();
if (!$reworked) {
$warnMsg[] = "Reworked by not found";
if (! $reworked) {
$warnMsg[] = 'Reworked by not found';
}
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
foreach ($formats as $format) {
try {
@@ -194,7 +190,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($cDateTime)) {
if (! isset($cDateTime)) {
// throw new \Exception('Invalid date time format');
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -209,7 +205,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($sDateTime)) {
if (! isset($sDateTime)) {
$warnMsg[] = "Invalid 'Scanned DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
@@ -223,11 +219,9 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($uDateTime)) {
if (! isset($uDateTime)) {
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else
{
} else {
if (isset($cDateTime) && isset($uDateTime)) {
if ($cDateTime->greaterThan($uDateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
@@ -245,11 +239,9 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
}
}
if (!isset($rDateTime)) {
if (! isset($rDateTime)) {
$warnMsg[] = "Invalid 'Reworked DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
else
{
} else {
if (isset($cDateTime) && isset($rDateTime)) {
if ($cDateTime->greaterThan($rDateTime)) {
$warnMsg[] = "'Created DataTime' is greater than 'Reworked DateTime'.";
@@ -260,10 +252,10 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
}
// if (!is_numeric($locatorQuantity) || $locatorQuantity < 0 || $locatorQuantity > 2) {
// $warnMsg[] = "Invalid locator quantity found";
// $warnMsg[] = "Invalid locator quantity found";
// }
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -283,10 +275,11 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
'created_by' => $createdBy,
'scanned_by' => $scannedBy,
'updated_by' => $updatedBy,
'reworked_by' => $reworkedBy
]
);
return null;
'reworked_by' => $reworkedBy,
]
);
return null;
// // return ReworkLocatorInvoiceValidation::firstOrNew([
// // // Update existing records, matching them by `$this->data['column_name']`
// // 'email' => $this->data['email'],
@@ -297,10 +290,10 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your rework locator invoice validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your rework locator invoice validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -18,79 +18,89 @@ class ShiftImporter extends Importer
public static function getColumns(): array
{
return [
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Shift Name')
->example('Day')
->label('Shift Name')
->rules(['required']),
ImportColumn::make('start_time')
->requiredMapping()
->exampleHeader('Start Time')
->example('08:00:00')
->label('Start Time')
->rules(['required']),
ImportColumn::make('duration')
->requiredMapping()
->numeric()
->exampleHeader('Shift Duration')
->example('11.30')
->label('Shift Duration')
->rules(['required']),
ImportColumn::make('end_time')
->requiredMapping()
->exampleHeader('End Time')
->example('19:30:00')
->label('End Time')
->rules(['required']),
ImportColumn::make('block')
->requiredMapping()
->exampleHeader('Block Name')
->example('Block A')
->label('Block Name')
->relationship(resolveUsing:'name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->rules(['required']),
ImportColumn::make('status')
->requiredMapping()
->exampleHeader('Active Status')
->example('Active')
->label('Active Status')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Shift Name')
->example('Day')
->label('Shift Name')
->rules(['required']),
ImportColumn::make('start_time')
->requiredMapping()
->exampleHeader('Start Time')
->example('08:00:00')
->label('Start Time')
->rules(['required']),
ImportColumn::make('duration')
->requiredMapping()
->numeric()
->exampleHeader('Shift Duration')
->example('11.30')
->label('Shift Duration')
->rules(['required']),
ImportColumn::make('end_time')
->requiredMapping()
->exampleHeader('End Time')
->example('19:30:00')
->label('End Time')
->rules(['required']),
ImportColumn::make('block')
->requiredMapping()
->exampleHeader('Block Name')
->example('Block A')
->label('Block Name')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('status')
->requiredMapping()
->exampleHeader('Active Status')
->example('Active')
->label('Active Status')
->rules(['required']),
];
}
public function resolveRecord(): ?Shift
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
if (!$block) {
$warnMsg[] = "Block not found";
}
if (Str::length($this->data['duration']) < 0 || !is_numeric($this->data['duration'])) {
$warnMsg[] = "Invalid duration found";
}
if (Str::length($this->data['start_time']) < 0) {
$warnMsg[] = "Invalid start time found";
}
if (Str::length($this->data['end_time']) < 0) {
$warnMsg[] = "Invalid end time found";
}
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
$warnMsg[] = "Invalid shift status found";
$plantCod = $this->data['plant'];
$plant = null;
$block = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
if (!empty($warnMsg)) {
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
}
if (! $block) {
$warnMsg[] = 'Block not found';
}
if (Str::length($this->data['duration']) < 0 || ! is_numeric($this->data['duration'])) {
$warnMsg[] = 'Invalid duration found';
}
if (Str::length($this->data['start_time']) < 0) {
$warnMsg[] = 'Invalid start time found';
}
if (Str::length($this->data['end_time']) < 0) {
$warnMsg[] = 'Invalid end time found';
}
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
$warnMsg[] = 'Invalid shift status found';
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -105,8 +115,9 @@ class ShiftImporter extends Importer
'start_time' => $this->data['start_time'],
'duration' => $this->data['duration'],
'end_time' => $this->data['end_time'],
'status' => $this->data['status']
'status' => $this->data['status'],
]);
return $shift;
} else {
// Safe to create new
@@ -117,7 +128,7 @@ class ShiftImporter extends Importer
'start_time' => $this->data['start_time'],
'duration' => $this->data['duration'],
'end_time' => $this->data['end_time'],
'status' => $this->data['status']
'status' => $this->data['status'],
]);
}
// return Shift::firstOrNew([
@@ -130,10 +141,10 @@ class ShiftImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your shift import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your shift import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -151,10 +151,10 @@ class StickerMasterImporter extends Importer
->example(''),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('PLANT NAME')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
];
}
@@ -162,107 +162,111 @@ class StickerMasterImporter extends Importer
public function resolveRecord(): ?StickerMaster
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
$item = null;
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
else
{
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
if (!$item) {
$warnMsg[] = "Item code not found";
}
else
{
if (! $item) {
$warnMsg[] = 'Item code not found';
} else {
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
$warnMsg[] = "Serial number motor must be 1 or empty";
$warnMsg[] = 'Serial number motor must be 1 or empty';
}
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
$warnMsg[] = "Serial number pump must be 1 or empty";
$warnMsg[] = 'Serial number pump must be 1 or empty';
}
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
$warnMsg[] = "Serial number pumpset must be 1 or empty";
$warnMsg[] = 'Serial number pumpset must be 1 or empty';
}
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
$warnMsg[] = "Pack slip motor must be 1 or empty";
$warnMsg[] = 'Pack slip motor must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
$warnMsg[] = "Pack slip pump must be 1 or empty";
$warnMsg[] = 'Pack slip pump must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
$warnMsg[] = "Pack slip pumpset must be 1 or empty";
$warnMsg[] = 'Pack slip pumpset must be 1 or empty';
}
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
$warnMsg[] = "Name plate motor must be 1 or empty";
$warnMsg[] = 'Name plate motor must be 1 or empty';
}
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
$warnMsg[] = "Name plate pump must be 1 or empty";
$warnMsg[] = 'Name plate pump must be 1 or empty';
}
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
$warnMsg[] = "Name plate pumpset must be 1 or empty";
$warnMsg[] = 'Name plate pumpset must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
$warnMsg[] = "Tube sticker motor must be 1 or empty";
$warnMsg[] = 'Tube sticker motor must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
$warnMsg[] = "Tube sticker pump must be 1 or empty";
$warnMsg[] = 'Tube sticker pump must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
$warnMsg[] = "Tube sticker pumpset must be 1 or empty";
$warnMsg[] = 'Tube sticker pumpset must be 1 or empty';
}
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
$warnMsg[] = "Warranty card must be 1 or empty";
$warnMsg[] = 'Warranty card must be 1 or empty';
}
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
$warnMsg[] = "Invalid panel box code found";
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) {
$warnMsg[] = 'Invalid panel box code found';
}
if (Str::length($this->data['load_rate']) < 0 || !is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
$warnMsg[] = "Load rate must be greater than or equal to 0";
if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
$warnMsg[] = 'Load rate must be greater than or equal to 0';
}
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
}
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
$warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
}
}
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
StickerMaster::updateOrCreate([
'item_id' => $item->id,
'plant_id' => $plant->id
'plant_id' => $plant->id,
],
[
'serial_number_motor' => $this->data['serial_number_motor'],
'serial_number_pump' => $this->data['serial_number_pump'],
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
'pack_slip_motor' => $this->data['pack_slip_motor'],
'pack_slip_pump' => $this->data['pack_slip_pump'],
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
'name_plate_motor' => $this->data['name_plate_motor'],
'name_plate_pump' => $this->data['name_plate_pump'],
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
'warranty_card' => $this->data['warranty_card'],
'part_validation1' => $this->data['part_validation1'],
'part_validation2' => $this->data['part_validation2'],
'part_validation3' => $this->data['part_validation3'],
'part_validation4' => $this->data['part_validation4'],
'part_validation5' => $this->data['part_validation5'],
'laser_part_validation1' => $this->data['laser_part_validation1'],
'laser_part_validation2' => $this->data['laser_part_validation2'],
'panel_box_code' => $this->data['panel_box_code'],
'load_rate' => $this->data['load_rate'],
'bundle_quantity' => $this->data['bundle_quantity'],
'material_type' => $this->data['material_type']
]);
[
'serial_number_motor' => $this->data['serial_number_motor'],
'serial_number_pump' => $this->data['serial_number_pump'],
'serial_number_pumpset' => $this->data['serial_number_pumpset'],
'pack_slip_motor' => $this->data['pack_slip_motor'],
'pack_slip_pump' => $this->data['pack_slip_pump'],
'pack_slip_pumpset' => $this->data['pack_slip_pumpset'],
'name_plate_motor' => $this->data['name_plate_motor'],
'name_plate_pump' => $this->data['name_plate_pump'],
'name_plate_pumpset' => $this->data['name_plate_pumpset'],
'tube_sticker_motor' => $this->data['tube_sticker_motor'],
'tube_sticker_pump' => $this->data['tube_sticker_pump'],
'tube_sticker_pumpset' => $this->data['tube_sticker_pumpset'],
'warranty_card' => $this->data['warranty_card'],
'part_validation1' => $this->data['part_validation1'],
'part_validation2' => $this->data['part_validation2'],
'part_validation3' => $this->data['part_validation3'],
'part_validation4' => $this->data['part_validation4'],
'part_validation5' => $this->data['part_validation5'],
'laser_part_validation1' => $this->data['laser_part_validation1'],
'laser_part_validation2' => $this->data['laser_part_validation2'],
'panel_box_code' => $this->data['panel_box_code'],
'load_rate' => $this->data['load_rate'],
'bundle_quantity' => $this->data['bundle_quantity'],
'material_type' => $this->data['material_type'],
]);
return null;
// return StickerMaster::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
@@ -274,10 +278,10 @@ class StickerMasterImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your sticker master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your sticker master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -2,15 +2,14 @@
namespace App\Filament\Imports;
use App\Models\Plant;
use App\Models\StickerPrinting;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use App\Models\Plant;
use App\Models\User;
use Str;
use Filament\Facades\Filament;
use Str;
class StickerPrintingImporter extends Importer
{
@@ -49,33 +48,29 @@ class StickerPrintingImporter extends Importer
// ]);
$warnMsg = [];
$plant = Plant::where('code', $this->data['plant'])->first();
if (Str::length($this->data['serial_number']) < 9 || !ctype_alnum($this->data['serial_number'])) {
$warnMsg[] = "Invalid serial number found";
}
$existing = StickerPrinting::where('plant_id', $plant->id)
->where('serial_number', $this->data['serial_number'])
->first();
if ($existing) {
$warnMsg[] = "Serial number already exists for this plant!";//throw new RowImportFailedException("Serial number already exists for this plant!");
}
$plantCod = $this->data['plant'];
$plant = null;
$serial = $this->data['serial_number'];
// --- Check duplicate in DB ---
$existsInDB = StickerPrinting::where('plant_id', $plant->id)
->where('serial_number', $serial)
->first();
if ($existsInDB) {
//throw new RowImportFailedException("Serial number '{$serial}' already exists in DB for this plant!");
$warnMsg[] = "Serial number '{$serial}' already exists in DB for this plant!";
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found!';
}
}
if (!empty($warnMsg)) {
if (Str::length($serial) < 9 || ! ctype_alnum($serial)) {
$warnMsg[] = 'Invalid serial number found';
} elseif ($plant) {
$existing = StickerPrinting::where('plant_id', $plant->id)->where('serial_number', $serial)->first();
if ($existing) {
$warnMsg[] = "Serial number '{$serial}' already exists for plant '{$plantCod}'!"; // throw new RowImportFailedException("Serial number already exists for this plant!");
}
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
@@ -84,21 +79,21 @@ class StickerPrintingImporter extends Importer
'reference_number' => $this->data['reference_number'],
'serial_number' => $this->data['serial_number'],
'created_at' => now(),
'updated_at' =>now(),
'updated_at' => now(),
'created_by' => Filament::auth()->user()?->name,
]);
return null;
//return new StickerPrinting();
// return new StickerPrinting();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your sticker printing import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your sticker printing import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -80,11 +80,17 @@ class TestingPanelReadingImporter extends Importer
->rules(['required']),
ImportColumn::make('line')
->requiredMapping()
->relationship()
->relationship(resolveUsing: 'name')
->exampleHeader('Line Name')
->example(['4 inch pump line'])
->label('Line Name')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->relationship()
->relationship(resolveUsing: 'code')
->exampleHeader('Plant Code')
->example(['1000'])
->label('Plant Code')
->rules(['required']),
ImportColumn::make('tested_by'),
ImportColumn::make('updated_by'),
@@ -101,15 +107,15 @@ class TestingPanelReadingImporter extends Importer
// 'email' => $this->data['email'],
// ]);
return new TestingPanelReading();
return new TestingPanelReading;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your testing panel reading import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your testing panel reading import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -29,19 +29,19 @@ class UserImporter extends Importer
->exampleHeader('Name')
->example('RAW00001')
->label('Name')
->rules(['required']),//, 'max:255'
->rules(['required']), // , 'max:255'
ImportColumn::make('email')
->requiredMapping()
->exampleHeader('E-Mail')
->example('RAW00001@cripumps.com')
->label('E-Mail')
->rules(['required', 'email']),//, 'max:255'
->rules(['required', 'email']), // , 'max:255'
ImportColumn::make('password')
->requiredMapping()
->exampleHeader('Password')
->example('RAW00001')
->label('Password')
->rules(['required']),//, 'max:255'
->rules(['required']), // , 'max:255'
ImportColumn::make('roles')
->requiredMapping()
->exampleHeader('Roles')
@@ -54,65 +54,61 @@ class UserImporter extends Importer
public function resolveRecord(): ?User
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$plant = null;
if (Str::length($this->data['plant']) > 0) {
if (Str::length($this->data['plant']) < 4 || !is_numeric($this->data['plant']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['plant'])) {
$warnMsg[] = "Invalid plant code found!";
}
else {
$plant = Plant::where('code', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
else {
$plant = $plant->id ?? null;
}
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found!';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plant = $plant->id ?? null;
}
}
if (Str::length($this->data['name']) < 1) {
$warnMsg[] = "User name not found!";
if (Str::length($this->data['name']) < 3) {
$warnMsg[] = 'Invalid user name found!';
}
// || !is_numeric($this->data['code']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['code'])
if (Str::length($this->data['email']) < 5) {
$warnMsg[] = "Invalid email found!";
$warnMsg[] = 'Invalid email found!';
}
if (Str::length($this->data['password']) < 3) {
$warnMsg[] = "Invalid password found!";
$warnMsg[] = 'Invalid password found!';
}
// Validate roles if provided
$roles = [];
if (!empty($this->data['roles'])) {
if (! empty($this->data['roles'])) {
$roles = collect(explode(',', $this->data['roles']))
->map(fn($role) => trim($role))
->map(fn ($role) => trim($role))
->filter()
->toArray();
foreach ($roles as $roleName) {
if (!Role::where('name', $roleName)->exists()) {
if (! Role::where('name', $roleName)->exists()) {
$warnMsg[] = "Role : '{$roleName}' does not exist!";
}
}
}
else {
$warnMsg[] = "User roles not found!";
} else {
$warnMsg[] = 'User roles not found!';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
$user = User::updateOrCreate([
'email' => $this->data['email'],
],
[
'name' => $this->data['name'],
'password' => $this->data['password'],
'plant_id' => $plant,
]);
[
'name' => $this->data['name'],
'password' => $this->data['password'],
'plant_id' => $plant,
]);
// Assign roles
if (!empty($roles)) {
if (! empty($roles)) {
$user->syncRoles($roles);
}
@@ -122,15 +118,15 @@ class UserImporter extends Importer
// 'email' => $this->data['email'],
// ]);
//return new User();
// return new User();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your user import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your user import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -75,10 +75,10 @@ class WeightValidationImporter extends Importer
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('PLANT NAME')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('scanned_by')
->requiredMapping()
@@ -92,82 +92,95 @@ class WeightValidationImporter extends Importer
public function resolveRecord(): ?WeightValidation
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
}
$item = null;
if ($plant) {
if (Str::length($this->data['item']) < 6 || !ctype_alnum($this->data['item'])) {
$warnMsg[] = "Invalid item code found";
$plantCod = $this->data['plant'];
$iCode = $this->data['item'];
$plantId = null;
$itemId = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plantId = $plant->id;
}
else
{
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
if (!$item) {
$warnMsg[] = "Item code not found";
}
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
$warnMsg[] = 'Invalid item code found';
} else {
$itemCode = Item::where('code', $iCode)->first();
if (! $itemCode) {
$warnMsg[] = 'Item code not found';
} else {
if ($plantId) {
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
if (! $itemAgainstPlant) {
$warnMsg[] = 'Item code not found for the given plant';
} else {
$itemId = $itemAgainstPlant->id;
}
}
}
}
else { //if (!$item)
$warnMsg[] = "Item code not found";
}
$obdNum = $this->data['obd_number'];
if (Str::length($obdNum) < 8 || !ctype_alnum($obdNum)) {
$warnMsg[] = "Invalid OBD number found";
if (Str::length($obdNum) < 8 || ! ctype_alnum($obdNum)) {
$warnMsg[] = 'Invalid OBD number found';
}
$lineNum = $this->data['line_number'];
if (Str::length($lineNum) < 1 || !is_numeric($lineNum)) {
$warnMsg[] = "Invalid line number found";
if (Str::length($lineNum) < 1 || ! is_numeric($lineNum)) {
$warnMsg[] = 'Invalid line number found';
}
$batchNum = $this->data['batch_number'];
if (Str::length($batchNum) < 8 || !is_numeric($batchNum)) {
$warnMsg[] = "Invalid batch number found";
if (Str::length($batchNum) < 8 || ! is_numeric($batchNum)) {
$warnMsg[] = 'Invalid batch number found';
}
$heatNum = $this->data['heat_number'];
if (Str::length($heatNum) < 4) {
$warnMsg[] = "Invalid heat number found";
$warnMsg[] = 'Invalid heat number found';
}
$actWeight = $this->data['obd_weight'];
if (Str::length($actWeight) < 1 || !is_numeric($actWeight)) {
$warnMsg[] = "Invalid actual weight found";
if (Str::length($actWeight) < 1 || ! is_numeric($actWeight)) {
$warnMsg[] = 'Invalid actual weight found';
}
$vehicleNum = $this->data['vehicle_number'];
if (Str::length($vehicleNum) < 10 || !ctype_alnum($vehicleNum)) {
$warnMsg[] = "Invalid vehicle number found";
if (Str::length($vehicleNum) < 10 || ! ctype_alnum($vehicleNum)) {
$warnMsg[] = 'Invalid vehicle number found';
}
$bundleNum = $this->data['bundle_number'];
if (Str::length($bundleNum) < 1 || !is_numeric($bundleNum)) {
$warnMsg[] = "Invalid bundle number found";
if (Str::length($bundleNum) < 1 || ! is_numeric($bundleNum)) {
$warnMsg[] = 'Invalid bundle number found';
}
$pickWeight = $this->data['picked_weight'];
if (Str::length($pickWeight) < 1 || !is_numeric($pickWeight)) {
$warnMsg[] = "Invalid picked weight found";
if (Str::length($pickWeight) < 1 || ! is_numeric($pickWeight)) {
$warnMsg[] = 'Invalid picked weight found';
}
$scanBy = $this->data['scanned_by'];
if (Str::length($scanBy) < 3 || !ctype_alnum($scanBy)) {
$warnMsg[] = "Invalid scanned by name found";
if (Str::length($scanBy) < 3 || ! ctype_alnum($scanBy)) {
$warnMsg[] = 'Invalid scanned by name found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return WeightValidation::updateOrCreate([
'plant_id' => $plant->id,
'obd_number' => $obdNum,
'line_number' => $lineNum
],
'plant_id' => $plantId,
'obd_number' => $obdNum,
'line_number' => $lineNum,
],
[
'item_id' => $item->id,
'item_id' => $itemId,
'batch_number' => $batchNum,
'heat_number' => $heatNum,
'obd_weight' => $actWeight,
'vehicle_number' => $vehicleNum,
'bundle_number' => $bundleNum,
'picked_weight' => $pickWeight,
'scanned_by' => $scanBy
'scanned_by' => $scanBy,
]
);
// return WeightValidation::firstOrNew([
@@ -180,10 +193,10 @@ class WeightValidationImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your weight validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your weight validation import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -20,22 +20,22 @@ class WorkGroupMasterImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing:'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Name')
->exampleHeader('Work Group Name')
->example('RMGCEABC')
->label('Name')
->label('Work Group Name')
->rules(['required']),
ImportColumn::make('description')
->requiredMapping()
->exampleHeader('Description')
->exampleHeader('Work Group Description')
->example('Testing Model 1')
->label('Description')
->label('Work Group Description')
->rules(['required']),
ImportColumn::make('operation_number')
->requiredMapping()
@@ -52,8 +52,6 @@ class WorkGroupMasterImporter extends Importer
];
}
public function resolveRecord(): ?WorkGroupMaster
{
// return WorkGroupMaster::firstOrNew([
@@ -61,75 +59,81 @@ class WorkGroupMasterImporter extends Importer
// 'email' => $this->data['email'],
// ]);
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found";
$plantCod = $this->data['plant'];
$plantId = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$plantId = $plant->id;
}
}
if (Str::length($this->data['name']) <= 0) { //|| !ctype_alnum($this->data['description'])
$warnMsg[] = "Invalid name found";
if (Str::length($this->data['name']) <= 0) { // || !ctype_alnum($this->data['description'])
$warnMsg[] = 'Invalid work group name found';
}
if (Str::length(trim($this->data['description'])) <= 0) {
$warnMsg[] = "Invalid description found";
$warnMsg[] = 'Invalid work group description found';
}
$desc = trim($this->data['description']);
if (Str::length($desc) > 44) {
$warnMsg[] = "Description should be less than 44 digits.";
$warnMsg[] = ' work group description should be less than 44 digits.';
}
if (Str::length($this->data['operation_number']) <= 0) {
$warnMsg[] = "Invalid operation number found";
$warnMsg[] = 'Invalid operation number found';
}
if(!is_numeric($this->data['operation_number']))
{
$warnMsg[] = "Invalid operation number found must be numeric";
if (! is_numeric($this->data['operation_number'])) {
$warnMsg[] = 'Invalid operation number found must be numeric';
}
$user = User::where('name', $this->data['created_by'])->first();
if (!$user) {
$warnMsg[] = "Operator ID not found";
if (! $user) {
$warnMsg[] = 'Operator ID not found';
}
if (!empty($warnMsg)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
else
{
//Check (plant_id, name)
$existingByName = WorkGroupMaster::where('plant_id', $plant->id)
} else {
// Check (plant_id, name)
$existingByName = WorkGroupMaster::where('plant_id', $plantId)
->where('name', $this->data['name'])
->first();
if ($existingByName) {
throw new RowImportFailedException("Work group name already exists for this plant!");
throw new RowImportFailedException('Work group name already exists for this plant!');
}
//Check (plant_id, operation_number)
$existingByOpNum = WorkGroupMaster::where('plant_id', $plant->id)
// Check (plant_id, operation_number)
$existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
->where('operation_number', $this->data['operation_number'])
->where('name', $this->data['name'])
->first();
if ($existingByOpNum) {
throw new RowImportFailedException("Operation number already exists for this plant!");
throw new RowImportFailedException('Operation number already exists for this plant!');
}
//Check (plant_id)
$existingByOperator = WorkGroupMaster::where('plant_id', $plant->id)
// Check (plant_id)
$existingByOperator = WorkGroupMaster::where('plant_id', $plantId)
->where('name', $this->data['name'])
->first();
if ($existingByOperator) {
throw new RowImportFailedException("Already work group name assigned to another plant!");
throw new RowImportFailedException('Already work group name assigned to another plant!');
}
}
WorkGroupMaster::updateOrCreate([
'plant_id' => $plant->id,
'plant_id' => $plantId,
'name' => $this->data['name'],
'description' => $this->data['description'],
'operation_number' => $this->data['operation_number'],
@@ -138,15 +142,15 @@ class WorkGroupMasterImporter extends Importer
return null;
//return new WorkGroupMaster();
// return new WorkGroupMaster();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your work group master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your work group master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;

View File

@@ -5,26 +5,25 @@ namespace App\Filament\Resources;
use App\Filament\Exports\CharacteristicValueExporter;
use App\Filament\Imports\CharacteristicValueImporter;
use App\Filament\Resources\CharacteristicValueResource\Pages;
use App\Filament\Resources\CharacteristicValueResource\RelationManagers;
use App\Models\CharacteristicValue;
use App\Models\Item;
use App\Models\Line;
use App\Models\Machine;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Facades\Filament;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
class CharacteristicValueResource extends Resource
{
@@ -65,7 +64,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('line_id')
->label('Line')
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -86,7 +85,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('item_id')
->label('Item')
->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) {
if (! $get('plant_id') || ! $get('line_id')) {
return [];
}
@@ -107,7 +106,7 @@ class CharacteristicValueResource extends Resource
Forms\Components\Select::make('machine_id')
->label('Machine')
->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id') || !$get('item_id')) {
if (! $get('plant_id') || ! $get('line_id') || ! $get('item_id')) {
return [];
}
@@ -192,7 +191,7 @@ class CharacteristicValueResource extends Resource
->label('Status')
->options([
'Ok' => 'OK',
'NotOk' => 'Not Ok'
'NotOk' => 'Not Ok',
])
->reactive()
->required(),
@@ -287,186 +286,198 @@ class CharacteristicValueResource extends Resource
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Line')
->label('Select Line')
->nullable()
->options(function (callable $get) {
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Line')
->label('Select Line')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
if (empty($plantId)) {
return [];
}
return Line::where('plant_id', $plantId)->pluck('name', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
if (empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
Select::make('Machine')
->label('Select Machine')
->nullable()
->options(function (callable $get) {
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
Select::make('Machine')
->label('Select Machine')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
$lineId = $get('Line');
if(empty($plantId) || empty($lineId)) {
if (empty($plantId) || empty($lineId)) {
return [];
}
return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
TextInput::make('process_order')
->label('Process Order')
->placeholder('Enter Process Order'),
TextInput::make('coil_number')
->label('Coil Number')
->placeholder(placeholder: 'Enter Coil Number'),
Select::make('status')
->label('Status')
->options([
'Ok' => 'OK',
'NotOk' => 'Not Ok'
]),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['Machine']) && empty($data['process_order']) && empty($data['coil_number']) && empty($data['status']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
TextInput::make('process_order')
->label('Process Order')
->placeholder('Enter Process Order'),
TextInput::make('coil_number')
->label('Coil Number')
->placeholder(placeholder: 'Enter Coil Number'),
Select::make('status')
->label('Status')
->options([
'Ok' => 'OK',
'NotOk' => 'Not Ok',
]),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['Machine']) && empty($data['process_order']) && empty($data['coil_number']) && empty($data['status']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Line'])) {
$query->where('line_id', $data['Line']);
}
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (! empty($data['Line'])) {
$query->where('line_id', $data['Line']);
}
if (!empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']);
}
if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (!empty($data['process_order'])) {
$query->where('process_order', $data['process_order']);
}
if (! empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']);
}
if (!empty($data['coil_number'])) {
$query->where('coil_number', $data['coil_number']);
}
if (! empty($data['process_order'])) {
$query->where('process_order', $data['process_order']);
}
if (!empty($data['status'])) {
$query->where('status', $data['status']);
}
if (! empty($data['coil_number'])) {
$query->where('coil_number', $data['coil_number']);
}
if (!empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['status'])) {
$query->where('status', $data['status']);
}
if (!empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
//$query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
// $query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Item'])) {
$indicators[] = 'Item: ' . Item::where('id', $data['Item'])->value('code');
}
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
}
if (!empty($data['Machine'])) {
$indicators[] = 'Machine: ' . Machine::where('id', $data['Machine'])->value('work_center');
}
if (! empty($data['Item'])) {
$indicators[] = 'Item: '.Item::where('id', $data['Item'])->value('code');
}
if (!empty($data['process_order'])) {
$indicators[] = 'Process Order: ' . $data['process_order'];
}
if (! empty($data['Machine'])) {
$indicators[] = 'Machine: '.Machine::where('id', $data['Machine'])->value('work_center');
}
if (!empty($data['coil_number'])) {
$indicators[] = 'Coil Number: ' . $data['coil_number'];
}
if (! empty($data['process_order'])) {
$indicators[] = 'Process Order: '.$data['process_order'];
}
if (!empty($data['status'])) {
$indicators[] = 'Status: ' . $data['status'];
}
if (! empty($data['coil_number'])) {
$indicators[] = 'Coil Number: '.$data['coil_number'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
}
if (! empty($data['status'])) {
$indicators[] = 'Status: '.$data['status'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
return $indicators;
})
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([

View File

@@ -5,23 +5,22 @@ namespace App\Filament\Resources;
use App\Filament\Exports\EbReadingExporter;
use App\Filament\Imports\EbReadingImporter;
use App\Filament\Resources\EbReadingResource\Pages;
use App\Filament\Resources\EbReadingResource\RelationManagers;
use App\Models\EbReading;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Filament\Facades\Filament;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\DateTimePicker;
class EbReadingResource extends Resource
{
@@ -39,6 +38,7 @@ class EbReadingResource 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();
})
->required(),
@@ -154,6 +154,7 @@ class EbReadingResource 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')
@@ -334,6 +335,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();
})
->reactive()
@@ -359,19 +361,25 @@ class EbReadingResource extends Resource
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['created_from'])) {
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['created_to'])) {
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (!empty($data['electrician_sign'])) {
if (! empty($data['electrician_sign'])) {
$query->where('electrician_sign', $data['electrician_sign']);
}
@@ -379,24 +387,30 @@ class EbReadingResource extends Resource
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['electrician_sign'])) {
$indicators[] = 'Created By: ' . $data['electrician_sign'];
if (! empty($data['electrician_sign'])) {
$indicators[] = 'Created By: '.$data['electrician_sign'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -415,14 +429,14 @@ class EbReadingResource extends Resource
->label('Import EB Readings')
->color('warning')
->importer(EbReadingImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import eb reading');
}),
ExportAction::make()
->label('Export EB Readings')
->color('warning')
->exporter(EbReadingExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export eb reading');
}),
]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\GuardPatrolEntryExporter;
use App\Filament\Imports\GuardPatrolEntryImporter;
use App\Filament\Resources\GuardPatrolEntryResource\Pages;
use App\Filament\Resources\GuardPatrolEntryResource\RelationManagers;
use App\Models\CheckPointName;
use App\Models\Configuration;
use App\Models\GuardName;
@@ -17,7 +16,6 @@ use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
@@ -54,21 +52,21 @@ class GuardPatrolEntryResource 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();
})
->default(function () {
return optional(GuardPatrolEntry::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('gPePlantError', 'Please select a plant first.');
$set('gPePlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('patrol_time', now()->format('Y-m-d H:i:s'));
$set('updated_by', Filament::auth()->user()?->name);
$set('gPePlantError', null);
@@ -84,7 +82,7 @@ class GuardPatrolEntryResource extends Resource
// ->relationship('guardNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -97,15 +95,14 @@ class GuardPatrolEntryResource extends Resource
->default(function () {
return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->guard_name_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$guardName = $get('guard_name_id');
if (!$guardName) {
if (! $guardName) {
$set('gPeGuardNameError', 'Please select a guard name first.');
return;
}
else
{
} else {
$set('patrol_time', now()->format('Y-m-d H:i:s'));
$set('updated_by', Filament::auth()->user()?->name);
$set('gPeGuardNameError', null);
@@ -116,7 +113,7 @@ class GuardPatrolEntryResource extends Resource
])
->hint(fn ($get) => $get('gPeGuardNameError') ? $get('gPeGuardNameError') : null)
->hintColor('danger'),
Forms\Components\Hidden::make('check_point_name')//TextInput
Forms\Components\Hidden::make('check_point_name')// TextInput
->label('Check Point Name')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -131,7 +128,7 @@ class GuardPatrolEntryResource extends Resource
// ->relationship('checkPointNames', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -144,16 +141,15 @@ class GuardPatrolEntryResource extends Resource
// ->default(function () {
// return optional(GuardPatrolEntry::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point_name_id;
// })
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$checkPointName = $get('check_point_name_id');
if (!$checkPointName) {
if (! $checkPointName) {
$set('check_point_name_id', null);
$set('gPeCheckPointNameError', 'Please select a check point name first.');
return;
}
else
{
} else {
$set('patrol_time', now()->format('Y-m-d H:i:s'));
$set('updated_by', Filament::auth()->user()?->name);
$set('gPeCheckPointNameError', null);
@@ -173,11 +169,10 @@ class GuardPatrolEntryResource extends Resource
}),
Forms\Components\TextInput::make('reader_code')
->label('Reader Code')
->hidden(fn (Get $get) => !$get('id'))
->hidden(fn (Get $get) => ! $get('id'))
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
if(!$get('id'))
{
if (! $get('id')) {
$set('patrol_time', now()->format('Y-m-d H:i:s'));
}
$set('updated_by', Filament::auth()->user()?->name);
@@ -186,7 +181,7 @@ class GuardPatrolEntryResource extends Resource
->label('Patrol Time')
->reactive()
->default(fn () => now())
->readOnly(fn (Get $get) => !$get('id'))
->readOnly(fn (Get $get) => ! $get('id'))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
@@ -225,6 +220,7 @@ class GuardPatrolEntryResource 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')
@@ -235,11 +231,11 @@ class GuardPatrolEntryResource extends Resource
->label('Plant')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('guardNames.name') //guard_name_id
Tables\Columns\TextColumn::make('guardNames.name') // guard_name_id
->label('Guard Name')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('checkPointNames.name') //check_point_name_id
Tables\Columns\TextColumn::make('checkPointNames.name') // check_point_name_id
->label('Check Point Name')
->alignCenter()
->sortable(),
@@ -288,18 +284,19 @@ 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();
})
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('sticker_master_id', null);
// $set('sap_msg_status', null);
// }),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('sticker_master_id', null);
// $set('sap_msg_status', null);
// }),
Select::make('Guard Name')
->label('Select Guard Name')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -310,7 +307,7 @@ class GuardPatrolEntryResource extends Resource
->label('Select Check Point Name')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -322,11 +319,11 @@ class GuardPatrolEntryResource extends Resource
->placeholder('Select Created By')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return GuardPatrolEntry::where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get()->unique('created_by')->pluck('created_by', 'created_by')->toArray();//, 'id'
return GuardPatrolEntry::where('plant_id', $plantId)->orderBy('patrol_time', 'asc')->get()->unique('created_by')->pluck('created_by', 'created_by')->toArray(); // , 'id'
})
->reactive(),
DateTimePicker::make(name: 'From Patrol Time')
@@ -341,66 +338,78 @@ class GuardPatrolEntryResource extends Resource
->placeholder(placeholder: 'Select To Patrol Time')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
//Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Guard Name']) && empty($data['Check Point Name']) && empty($data['Created By']) && empty($data['From Patrol Time']) && empty($data['To Patrol Time'])) {
return $query->whereRaw('1 = 0');
}
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Guard Name']) && empty($data['Check Point Name']) && empty($data['Created By']) && empty($data['From Patrol Time']) && empty($data['To Patrol Time'])) {
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Guard Name'])) {
$query->where('guard_name_id', $data['Guard Name']);
}
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Check Point Name'])) {
$query->where('check_point_name_id', $data['Check Point Name']);
}
if (! empty($data['Guard Name'])) {
$query->where('guard_name_id', $data['Guard Name']);
}
if (!empty($data['Created By'])) {
$query->where('created_by', $data['Created By']);
}
if (! empty($data['Check Point Name'])) {
$query->where('check_point_name_id', $data['Check Point Name']);
}
if (!empty($data['From Patrol Time'])) {
$query->where('patrol_time', '>=', $data['From Patrol Time']);
}
if (! empty($data['Created By'])) {
$query->where('created_by', $data['Created By']);
}
if (!empty($data['To Patrol Time'])) {
$query->where('patrol_time', '<=', $data['To Patrol Time']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (! empty($data['From Patrol Time'])) {
$query->where('patrol_time', '>=', $data['From Patrol Time']);
}
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if (! empty($data['To Patrol Time'])) {
$query->where('patrol_time', '<=', $data['To Patrol Time']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Guard Name'])) {
$indicators[] = 'Guard Name: ' . GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
}
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Check Point Name'])) {
$indicators[] = 'Check Point Name: ' . CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Created By'])) {
$indicators[] = 'Created By: ' . $data['Created By'];
}
if (! empty($data['Guard Name'])) {
$indicators[] = 'Guard Name: '.GuardName::where('plant_id', $data['Plant'])->where('id', $data['Guard Name'])->value('name');
}
if (!empty($data['From Patrol Time'])) {
$indicators[] = 'From: ' . $data['From Patrol Time'];
}
if (! empty($data['Check Point Name'])) {
$indicators[] = 'Check Point Name: '.CheckPointName::where('plant_id', $data['Plant'])->where('id', $data['Check Point Name'])->value('name');
}
if (!empty($data['To Patrol Time'])) {
$indicators[] = 'To: ' . $data['To Patrol Time'];
}
if (! empty($data['Created By'])) {
$indicators[] = 'Created By: '.$data['Created By'];
}
return $indicators;
})
if (! empty($data['From Patrol Time'])) {
$indicators[] = 'From: '.$data['From Patrol Time'];
}
if (! empty($data['To Patrol Time'])) {
$indicators[] = 'To: '.$data['To Patrol Time'];
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -422,6 +431,7 @@ class GuardPatrolEntryResource extends Resource
// ->options(Plant::pluck('name', 'id')->toArray())
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->label('Select Plant')
@@ -433,12 +443,11 @@ class GuardPatrolEntryResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('guard_patrol_entry', null);
if (!$plantId) {
if (! $plantId) {
$set('gPeSelectPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('gPeSelectPlantError', null);
}
})
@@ -455,7 +464,7 @@ class GuardPatrolEntryResource extends Resource
->reactive()
->required()
->disk('local')
->visible(fn (Get $get) => !empty($get('plant_id')))
->visible(fn (Get $get) => ! empty($get('plant_id')))
->directory('uploads/temp')
// Allow only .xlsx and .xls
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'])
@@ -465,7 +474,7 @@ class GuardPatrolEntryResource extends Resource
])
// Server-side validation for extra safety
->rules(['mimes:xlsx,xls']),
])
])
->action(function (array $data) {
$uploadedFile = $data['guard_patrol_entry'];
@@ -482,21 +491,20 @@ class GuardPatrolEntryResource extends Resource
$folderPath = Configuration::where('c_name', 'GUARD_PATROL_ENTRY_FOLDER_PATH')->where('plant_id', $plantId)->value('c_value');
if(!$folderPath)
{
if (! $folderPath) {
Notification::make()
->title('Upload Folder Path Not Found!')
->body('Please set the folder path in configuration for Guard Patrol Entry.')
->danger()
->send();
return;
}
$fullFolderPath = "uploads/$folderPath";
// Check if the folder exists, if not, create it
if (!Storage::disk('local')->exists($fullFolderPath))
{
if (! Storage::disk('local')->exists($fullFolderPath)) {
Storage::disk('local')->makeDirectory($fullFolderPath);
}
@@ -504,12 +512,10 @@ class GuardPatrolEntryResource 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)
{
if ((count($rows) - 1) <= 0) {
Notification::make()
->title('Invalid Guard Patrol Entry Found')
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
@@ -519,19 +525,21 @@ class GuardPatrolEntryResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidRows=[];
$invalidGuardCheckPoints=[];
$unknownGuards=[];
$unknownCheckPoints=[];
$invalidPatrolTimes=[];
$invalidRows = [];
$invalidGuardCheckPoints = [];
$unknownGuards = [];
$unknownCheckPoints = [];
$invalidPatrolTimes = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
foreach ($rows as $index => $row) {
if ($index === 0) {
continue;
} // Skip header
$rowNumber = trim($row[0]);
$guardName = trim($row[1]);
@@ -539,35 +547,34 @@ class GuardPatrolEntryResource extends Resource
$readerCode = trim($row[3]);
$patrolTime = trim($row[4]);
if (empty($rowNumber)) { continue; }
if (empty($rowNumber)) {
continue;
}
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
$invalidRows[] = $rowNumber;
continue;
}
else
{
if(Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3)
{
} else {
if (Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3) {
$invalidGuardCheckPoints[] = $rowNumber;
continue;
}
else
{
} else {
$isValidRow = true;
$guardNames = GuardName::where('plant_id', $plantId)->where('name', $guardName)->first();
if (!$guardNames) {
if (! $guardNames) {
$unknownGuards[] = $guardName;
$isValidRow = false;
}
$checkPointNames = CheckPointName::where('plant_id', $plantId)->where('name', $checkPointName)->first();
if (!$checkPointNames) {
if (! $checkPointNames) {
$unknownCheckPoints[] = $checkPointName;
$isValidRow = false;
}
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$patrolDateTime = null;
foreach ($formats as $format) {
try {
@@ -579,13 +586,13 @@ class GuardPatrolEntryResource extends Resource
}
}
if (!isset($patrolDateTime)) {
if (! isset($patrolDateTime)) {
$invalidPatrolTimes[] = $rowNumber;
$isValidRow = false;
//$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
// $warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
}
if ($isValidRow && !$validRowsFound) {
if ($isValidRow && ! $validRowsFound) {
$validRowsFound = true;
}
}
@@ -593,38 +600,40 @@ class GuardPatrolEntryResource extends Resource
}
$uniqueInvalidRows = array_unique($invalidRows);
if (!empty($uniqueInvalidRows)) {
if (! empty($uniqueInvalidRows)) {
Notification::make()
->title('Invalid Guard Patrol Entry Found')
->body('The following rows contain empty values (Guard name or Check point name or Reader code or Patrol time):<br>' . implode(', ', $uniqueInvalidRows))
->body('The following rows contain empty values (Guard name or Check point name or Reader code or Patrol time):<br>'.implode(', ', $uniqueInvalidRows))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
//should contain minimum 13 digit alpha numeric values
// should contain minimum 13 digit alpha numeric values
$uniqueInvalidGuardCheckPoints = array_unique($invalidGuardCheckPoints);
if (!empty($uniqueInvalidGuardCheckPoints)) {
if (! empty($uniqueInvalidGuardCheckPoints)) {
Notification::make()
->title('Invalid Guard Patrol Entry Found')
->body('The following rows contain invalid values (Guard name or Check point name or Reader code or Patrol time):<br>' . implode(', ', $uniqueInvalidGuardCheckPoints))
->body('The following rows contain invalid values (Guard name or Check point name or Reader code or Patrol time):<br>'.implode(', ', $uniqueInvalidGuardCheckPoints))
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidDataFound = false;
$uniqueUnknownGuards = array_unique($unknownGuards);
if (!empty($uniqueUnknownGuards)) {
if (! empty($uniqueUnknownGuards)) {
Notification::make()
->title('Unknown Guard Names Found')
->body("The following guard names aren't exist in master data:<br>" . implode(', ', $uniqueUnknownGuards))
->body("The following guard names aren't exist in master data:<br>".implode(', ', $uniqueUnknownGuards))
->danger()
->send();
if ($disk->exists($path)) {
@@ -634,10 +643,10 @@ class GuardPatrolEntryResource extends Resource
}
$uniqueUnknownCheckPoints = array_unique($unknownCheckPoints);
if (!empty($uniqueUnknownCheckPoints)) {
if (! empty($uniqueUnknownCheckPoints)) {
Notification::make()
->title('Unknown Check Point Names Found')
->body("The following check point names aren't exist in master data:<br>" . implode(', ', $uniqueUnknownCheckPoints))
->body("The following check point names aren't exist in master data:<br>".implode(', ', $uniqueUnknownCheckPoints))
->danger()
->send();
if ($disk->exists($path)) {
@@ -647,10 +656,10 @@ class GuardPatrolEntryResource extends Resource
}
$uniqueInvalidPatrolTimes = array_unique($invalidPatrolTimes);
if (!empty($uniqueInvalidPatrolTimes)) {
if (! empty($uniqueInvalidPatrolTimes)) {
Notification::make()
->title('Invalid Patrol Time Format Found')
->body("The following rows contains invalid patrol time format (Expected 'DD-MM-YYYY HH:MM:SS'):<br>" . implode(', ', $uniqueInvalidPatrolTimes))
->body("The following rows contains invalid patrol time format (Expected 'DD-MM-YYYY HH:MM:SS'):<br>".implode(', ', $uniqueInvalidPatrolTimes))
->danger()
->send();
if ($disk->exists($path)) {
@@ -663,24 +672,26 @@ class GuardPatrolEntryResource extends Resource
return;
}
if (!$validRowsFound) {
if (! $validRowsFound) {
Notification::make()
->title('Invalid Guard Patrol Entry Found')
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
->danger()
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$validCnt = 0;
$dupCnt = 0;
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
foreach ($rows as $index => $row) {
if ($index === 0) {
continue;
} // Skip header
$rowNumber = trim($row[0]);
$guardName = trim($row[1]);
@@ -688,7 +699,9 @@ class GuardPatrolEntryResource extends Resource
$readerCode = trim($row[3]);
$patrolTime = trim($row[4]);
if (empty($rowNumber)) { continue; }
if (empty($rowNumber)) {
continue;
}
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
continue;
@@ -696,7 +709,7 @@ class GuardPatrolEntryResource extends Resource
$isValidRow = true;
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
$formats = ['d-m-Y H:i:s', 'd-m-Y H:i']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
$patrolDateTime = null;
foreach ($formats as $format) {
try {
@@ -707,7 +720,7 @@ class GuardPatrolEntryResource extends Resource
}
}
if (!isset($patrolDateTime)) {
if (! isset($patrolDateTime)) {
$isValidRow = false;
}
@@ -718,23 +731,22 @@ class GuardPatrolEntryResource extends Resource
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plantId)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
if ($guardEntryFound) {
//$warnMsg[] = "Duplicate guard patrol entry found";
// $warnMsg[] = "Duplicate guard patrol entry found";
$dupCnt++;
continue;
}
else
{
} else {
$validCnt++;
GuardPatrolEntry::updateOrCreate([
'plant_id' => $plantId,
'guard_name_id' => $guardNames->id,
'check_point_name_id' => $checkPointNames->id,
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s')
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s'),
],
[
'reader_code' => $readerCode,
'created_by' => $user,
'updated_by' => $user
[
'reader_code' => $readerCode,
'created_by' => $user,
'updated_by' => $user,
]
);
$validRowsFound = true;
@@ -742,31 +754,25 @@ class GuardPatrolEntryResource extends Resource
}
}
if (!$validRowsFound && $dupCnt > 0) {
if (! $validRowsFound && $dupCnt > 0) {
Notification::make()
->title('Duplicate Guard Patrol Entry Found')
->body("Uploaded excel sheet contains '{$dupCnt}' duplicate entries!<br>Please check the uploaded file and try again.")
->danger()
->send();
if ($disk->exists($path))
{
if ($disk->exists($path)) {
$disk->delete($path);
}
}
else if ($validRowsFound && $validCnt > 0)
{
//session(['guard_patrol_entry_path' => $fullPath]);
} elseif ($validRowsFound && $validCnt > 0) {
// session(['guard_patrol_entry_path' => $fullPath]);
Notification::make()
->title("Success: '{$validCnt}' guard patrol entries imported successfully.")
->success()
->send();
if ($disk->exists($path))
{
if ($disk->exists($path)) {
$disk->delete($path);
}
}
else
{
} else {
Notification::make()
->title('Failed: Something went wrong while uploading guard patrol entries!')
->danger()
@@ -777,7 +783,7 @@ class GuardPatrolEntryResource extends Resource
}
}
})
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import guard patrol entries');
}),
ImportAction::make()
@@ -785,14 +791,14 @@ class GuardPatrolEntryResource extends Resource
// ->hidden()
->color('warning')
->importer(GuardPatrolEntryImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import guard patrol entry');
}),
ExportAction::make()
->label('Export Guard Patrol Entry')
->color('warning')
->exporter(GuardPatrolEntryExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export guard patrol entry');
}),
]);

View File

@@ -1181,6 +1181,12 @@ class InvoiceValidationResource extends Resource
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (! empty($data['invoice_number'])) {
@@ -1218,6 +1224,12 @@ class InvoiceValidationResource extends Resource
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (! empty($data['invoice_number'])) {

View File

@@ -293,20 +293,18 @@ class ItemResource extends Resource
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (
empty($data['Plant']) &&
empty($data['code']) &&
empty($data['description']) &&
empty($data['uom']) &&
empty($data['category']) &&
empty($data['created_from']) &&
empty($data['created_to'])
) {
if (empty($data['Plant']) && empty($data['code']) && empty($data['description']) && empty($data['uom']) && empty($data['category']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (! empty($data['code'])) {
@@ -338,6 +336,12 @@ class ItemResource extends Resource
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (! empty($data['code'])) {

File diff suppressed because it is too large Load Diff

View File

@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
use App\Filament\Exports\LocatorExporter;
use App\Filament\Imports\LocatorImporter;
use App\Filament\Resources\LocatorResource\Pages;
use App\Filament\Resources\LocatorResource\RelationManagers;
use App\Models\Locator;
use App\Models\PalletValidation;
use App\Models\Plant;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Tables\Actions\ImportAction;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
@@ -48,25 +47,25 @@ class LocatorResource 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();
})
->default(function () {
return optional(Locator::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('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');
// Ensure `linestop_id` is not cleared
if (!$plantId) {
if (! $plantId) {
$set('locPlantError', 'Please select a plant first.');
$set('locator_number', null);
$set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name);
return;
}
else
{
} else {
$set('locPlantError', null);
$set('locator_number', null);
$set('locator_quantity', 0);
@@ -86,21 +85,20 @@ class LocatorResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$locator = $get('locator_number');
if (!$plantId) {
if (! $plantId) {
$set('locNameError', 'Please select a plant first.');
$set('locator_number', null);
$set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name);
return;
}
else if (!$locator || Str::length($locator) < 7) {
} elseif (! $locator || Str::length($locator) < 7) {
$set('locNameError', 'Please scan the valid locator number.');
$set('locator_quantity', 0);
$set('operator_id', Filament::auth()->user()?->name);
return;
}
else
{
} else {
$set('locNameError', null);
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
$set('operator_id', Filament::auth()->user()?->name);
@@ -145,6 +143,7 @@ class LocatorResource 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')
@@ -184,149 +183,163 @@ class LocatorResource extends Resource
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
// ->options(function () {
// return Plant::pluck('name', 'id');
// })
->options(function (callable $get) {
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
// ->options(function () {
// return Plant::pluck('name', 'id');
// })
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {
$set('locator_number', null);
$set('locator_quantity', null);
$set('created_from', null);
$set('created_to', null);
$set('created_by', null);
$set('updated_from', null);
$set('updated_to', null);
}),
Select::make('locator_number')
->label('Locator Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (! $plantId) {
return [];
}
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
// ->whereNotNull('locator_number')
// ->where('locator_number','!=', '')
})
->searchable()
->reactive(),
Select::make('locator_quantity')
->label('Locator Quantity')
->options([
0 => 0,
1 => 1,
2 => 2,
])
->reactive(),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
TextInput::make('created_by')
->label('Created By')
->reactive()
->placeholder(placeholder: 'Enter Created By'),
DateTimePicker::make(name: 'updated_from')
->label('Updated From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('updated_to')
->label('Updated To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['locator_number']) && $data['locator_quantity'] == null && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {
return $query->whereRaw('1 = 0');
}
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void {
$set('locator_number', null);
$set('locator_quantity', null);
$set('created_from', null);
$set('created_to', null);
$set('created_by', null);
$set('updated_from', null);
$set('updated_to', null);
}),
Select::make('locator_number')
->label('Locator Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
return [];
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
// ->whereNotNull('locator_number')
// ->where('locator_number','!=', '')
})
->searchable()
->reactive(),
Select::make('locator_quantity')
->label('Locator Quantity')
->options([
0 => 0,
1 => 1,
2 => 2,
])
->reactive(),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
TextInput::make('created_by')
->label('Created By')
->reactive()
->placeholder(placeholder: 'Enter Created By'),
DateTimePicker::make(name: 'updated_from')
->label('Updated From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('updated_to')
->label('Updated To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['locator_number']) && $data['locator_quantity'] == null && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['locator_number'])) {
$query->where('locator_number', $data['locator_number']);
}
if (!empty($data['locator_number'])) {
$query->where('locator_number', $data['locator_number']);
}
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$query->where('locator_quantity', $data['locator_quantity']); // (int)
}
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
$query->where('locator_quantity', $data['locator_quantity']);//(int)
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (!empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (! empty($data['created_by'])) {
$query->where('operator_id', $data['created_by']);
}
if (!empty($data['created_by'])) {
$query->where('operator_id', $data['created_by']);
}
if (! empty($data['updated_from'])) {
$query->where('updated_at', '>=', $data['updated_from']);
}
if (!empty($data['updated_from'])) {
$query->where('updated_at', '>=', $data['updated_from']);
}
if (! empty($data['updated_to'])) {
$query->where('updated_at', '<=', $data['updated_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['updated_to'])) {
$query->where('updated_at', '<=', $data['updated_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['locator_number'])) {
$indicators[] = 'Locator Number: ' . $data['locator_number'];
}
if (! empty($data['locator_number'])) {
$indicators[] = 'Locator Number: '.$data['locator_number'];
}
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
}
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$indicators[] = 'Locator Quantity: '.$data['locator_quantity'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
}
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
if (!empty($data['created_by'])) {
$indicators[] = 'Created By: ' . $data['created_by'];
}
if (! empty($data['created_by'])) {
$indicators[] = 'Created By: '.$data['created_by'];
}
if (!empty($data['updated_from'])) {
$indicators[] = 'Updated From: ' . $data['updated_from'];
}
if (! empty($data['updated_from'])) {
$indicators[] = 'Updated From: '.$data['updated_from'];
}
if (!empty($data['updated_to'])) {
$indicators[] = 'Updated To: ' . $data['updated_to'];
}
if (! empty($data['updated_to'])) {
$indicators[] = 'Updated To: '.$data['updated_to'];
}
return $indicators;
})
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -345,14 +358,14 @@ class LocatorResource extends Resource
->label('Import Locators')
->color('warning')
->importer(LocatorImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import locator');
}),
ExportAction::make()
->label('Export Locators')
->color('warning')
->exporter(LocatorExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export locator');
}),
]);

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MachineExporter;
use App\Filament\Imports\MachineImporter;
use App\Filament\Resources\MachineResource\Pages;
use App\Filament\Resources\MachineResource\RelationManagers;
use App\Models\Line;
use App\Models\Machine;
use App\Models\Plant;
@@ -16,11 +15,11 @@ 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;
use Illuminate\Validation\Rule;
use Str;
@@ -45,22 +44,22 @@ class MachineResource 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();
})
->default(function () {
return optional(Machine::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('mPlantError', 'Please select a plant first.');
$set('line_id', null);
$set('work_group_master_id', null);
return;
}
else
{
} else {
$set('mPlantError', null);
}
})
@@ -75,7 +74,7 @@ class MachineResource extends Resource
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -84,16 +83,15 @@ class MachineResource extends Resource
->default(function () {
return optional(Machine::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('mLineError', 'Please select a line first.');
$set('work_group_master_id', null);
return;
}
else
{
} else {
// $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// {
@@ -115,7 +113,7 @@ class MachineResource extends Resource
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) {
if (! $get('plant_id') || ! $get('line_id')) {
return [];
}
@@ -123,7 +121,7 @@ class MachineResource extends Resource
$workGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id";
if (!empty($line->$column)) {
if (! empty($line->$column)) {
$workGroupIds[] = $line->$column;
}
}
@@ -133,15 +131,14 @@ class MachineResource extends Resource
->default(function () {
return optional(Machine::latest()->first())->work_group_master_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('mGroupWorkError', 'Please select a line first.');
return;
}
else
{
} else {
// $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// {
@@ -164,7 +161,7 @@ class MachineResource extends Resource
->required()
->rule(function (callable $get) {
return Rule::unique('machines', 'name')
//->where('line_id', $get('line_id'))
// ->where('line_id', $get('line_id'))
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
}),
@@ -194,6 +191,7 @@ class MachineResource 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')
@@ -254,14 +252,14 @@ class MachineResource extends Resource
->label('Import Machines')
->color('warning')
->importer(MachineImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import machine');
}),
ExportAction::make()
->label('Export Machines')
->color('warning')
->exporter(MachineExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export machine');
}),
]);

View File

@@ -36,30 +36,84 @@ class MfmParameterResource extends Resource
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')
//->relationship('deviceName', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
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')
// ->relationship('mfmMeter', 'sequence')
->options(function (callable $get) {
$plantId = $get('plant_id');
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')
@@ -67,6 +121,7 @@ class MfmParameterResource extends Resource
->required(),
Forms\Components\TextInput::make('decimal_to_display')
->label('Decimal To Display')
->reactive()
->default(1)
->required(),
])

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MotorTestingMasterExporter;
use App\Filament\Imports\MotorTestingMasterImporter;
use App\Filament\Resources\MotorTestingMasterResource\Pages;
use App\Filament\Resources\MotorTestingMasterResource\RelationManagers;
use App\Models\Configuration;
use App\Models\Item;
use App\Models\MotorTestingMaster;
@@ -20,12 +19,12 @@ 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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Validation\Rule;
class MotorTestingMasterResource extends Resource
@@ -49,20 +48,20 @@ class MotorTestingMasterResource 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();
})
->default(function () {
return optional(MotorTestingMaster::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('mTmError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('mTmError', null);
}
})
@@ -78,10 +77,10 @@ class MotorTestingMasterResource extends Resource
->reactive(),
Forms\Components\Select::make('item_id')
->label('Item Code')
//->relationship('item', 'name')
// ->relationship('item', 'name')
->options(function (callable $get) {
$plantId = $get('plant_id');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -106,19 +105,19 @@ class MotorTestingMasterResource extends Resource
->minLength(6)
->afterStateUpdated(function ($state, callable $set, callable $get) {
$code = $get('subassembly_code');
if (!$code) {
if (! $code) {
$set('iCodeError', 'Scan the valid Subassembly Code.');
return;
}
else
{
} else {
if (strlen($code) < 6) {
$set('iCodeError', 'Subassembly code must be at least 6 digits.');
return;
}
else if (!preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
$set('code',null);
} elseif (! preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
$set('code', null);
$set('iCodeError', 'Subassembly code must contain only alpha-numeric characters.');
return;
}
$set('iCodeError', null);
@@ -143,24 +142,21 @@ class MotorTestingMasterResource extends Resource
Forms\Components\Select::make('phase')
->label('Phase')
->options(function (callable $get) {
$plantId = $get('plant_id');
$plantId = $get('plant_id');
if ($plantId)
{
return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
else
{
return Configuration::where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
})
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
} else {
return Configuration::where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
})
->selectablePlaceholder(false)
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -197,16 +193,13 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false)
->options(function (callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
else
{
->where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
} else {
return Configuration::where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at')
->pluck('c_value', 'c_value')
@@ -230,16 +223,13 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false)
->options(function (callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'INSULATION_RESISTANCE_TYPE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
else
{
->where('c_name', 'INSULATION_RESISTANCE_TYPE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
} else {
return Configuration::where('c_name', 'INSULATION_RESISTANCE_TYPE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
@@ -317,6 +307,7 @@ class MotorTestingMasterResource 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')
@@ -474,6 +465,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();
})
->reactive()
@@ -488,6 +480,7 @@ class MotorTestingMasterResource extends Resource
->nullable()
->options(function (callable $get) {
$pId = $get('Plant');
return Item::whereHas('motorTestingMasters', function ($query) use ($pId) {
if ($pId) {
$query->where('plant_id', $pId);
@@ -505,7 +498,7 @@ class MotorTestingMasterResource extends Resource
->options([
'All' => 'All',
'Y' => 'Y',
'N' => 'N'
'N' => 'N',
])
->default(null)
->inlineLabel(false)
@@ -516,16 +509,13 @@ class MotorTestingMasterResource extends Resource
->options(function (callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
else
{
} else {
return Configuration::where('c_name', 'MOTOR_PHASE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
@@ -544,16 +534,13 @@ class MotorTestingMasterResource extends Resource
->nullable()
->options(function (callable $get) {
$plantId = $get('plant_id');
if ($plantId)
{
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
else
{
} else {
return Configuration::where('c_name', 'MOTOR_CONNECTION')
->orderBy('created_at')
->pluck('c_value', 'c_value')
@@ -571,12 +558,9 @@ class MotorTestingMasterResource extends Resource
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId)
{
if (! $plantId) {
return MotorTestingMaster::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
}
else
{
} else {
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
}
})
@@ -597,12 +581,9 @@ class MotorTestingMasterResource extends Resource
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId)
{
if (! $plantId) {
return MotorTestingMaster::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
}
else
{
} else {
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
}
})
@@ -625,127 +606,139 @@ class MotorTestingMasterResource extends Resource
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Item'])) {
if (! empty($data['Item'])) {
$itemIds = Item::where('id', $data['Item'])
->pluck('id')
->toArray();
if (!empty($itemIds)) {
if (! empty($itemIds)) {
$query->whereIn('item_id', $itemIds);
}
}
if (!empty($data['description'])) {
if (! empty($data['description'])) {
$pId = $data['Plant'] ?? null;
$descIds = Item::where('description', 'like', '%' . $data['description'] . '%')->whereHas('motorTestingMasters', function ($query) use ($pId) {
if ($pId) { $query->where('plant_id', $pId); }
})->pluck('id')->toArray();
$descIds = Item::where('description', 'like', '%'.$data['description'].'%')->whereHas('motorTestingMasters', function ($query) use ($pId) {
if ($pId) {
$query->where('plant_id', $pId);
}
})->pluck('id')->toArray();
if (!empty($descIds)) {
if (! empty($descIds)) {
$query->whereIn('item_id', $descIds);
}
}
if ($data['isi_type'] == 'Y') {
$query->where('isi_model', true);
}
else if ($data['isi_type'] == 'N') {
} elseif ($data['isi_type'] == 'N') {
$query->where('isi_model', false);
}
if (!empty($data['phase_type'])) {
if (! empty($data['phase_type'])) {
$query->where('phase', $data['phase_type']);
}
if (!empty($data['connection_type'])) {
if (! empty($data['connection_type'])) {
$query->where('connection', $data['connection_type']);
}
if (!empty($data['created_by'])) {
if (! empty($data['created_by'])) {
$query->where('created_by', $data['created_by']);
}
if (!empty($data['created_from'])) {
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['created_to'])) {
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (!empty($data['updated_by'])) {
if (! empty($data['updated_by'])) {
$query->where('updated_by', $data['updated_by']);
}
if (!empty($data['updated_from'])) {
if (! empty($data['updated_from'])) {
$query->where('updated_at', '>=', $data['updated_from']);
}
if (!empty($data['updated_to'])) {
if (! empty($data['updated_to'])) {
$query->where('updated_at', '<=', $data['updated_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Item'])) {
if (! empty($data['Item'])) {
$itemCode = Item::find($data['Item'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: ' . $itemCode;
$indicators[] = 'Item Codes: '.$itemCode;
}
if (!empty($data['description'])) {
$indicators[] = 'Description: ' . $data['description'];
if (! empty($data['description'])) {
$indicators[] = 'Description: '.$data['description'];
}
if ($data['isi_type'] == 'Y') {
$indicators[] = 'ISI Model: Yes';
}
else if ($data['isi_type'] == 'N') {
} elseif ($data['isi_type'] == 'N') {
$indicators[] = 'ISI Model: No';
}
if (!empty($data['phase_type'])) {
$indicators[] = 'Phase: ' . $data['phase_type'];
if (! empty($data['phase_type'])) {
$indicators[] = 'Phase: '.$data['phase_type'];
}
if (!empty($data['connection_type'])) {
$indicators[] = 'Connection: ' . $data['connection_type'];
if (! empty($data['connection_type'])) {
$indicators[] = 'Connection: '.$data['connection_type'];
}
if (!empty($data['created_by'])) {
$indicators[] = 'Created By: ' . $data['created_by'];
if (! empty($data['created_by'])) {
$indicators[] = 'Created By: '.$data['created_by'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'Created From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'Created From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'Created To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'Created To: '.$data['created_to'];
}
if (!empty($data['updated_by'])) {
$indicators[] = 'Updated By: ' . $data['updated_by'];
if (! empty($data['updated_by'])) {
$indicators[] = 'Updated By: '.$data['updated_by'];
}
if (!empty($data['updated_from'])) {
$indicators[] = 'Updated From: ' . $data['updated_from'];
if (! empty($data['updated_from'])) {
$indicators[] = 'Updated From: '.$data['updated_from'];
}
if (!empty($data['updated_to'])) {
$indicators[] = 'Updated To: ' . $data['updated_to'];
if (! empty($data['updated_to'])) {
$indicators[] = 'Updated To: '.$data['updated_to'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -764,14 +757,14 @@ class MotorTestingMasterResource extends Resource
->label('Import Motor Testing Masters')
->color('warning')
->importer(MotorTestingMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import motor testing master');
}),
ExportAction::make()
->label('Export Motor Testing Masters')
->color('warning')
->exporter(MotorTestingMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export motor testing master');
}),
]);

View File

@@ -5,31 +5,24 @@ namespace App\Filament\Resources;
use App\Filament\Exports\PalletValidationExporter;
use App\Filament\Imports\PalletValidationImporter;
use App\Filament\Resources\PalletValidationResource\Pages;
use App\Filament\Resources\PalletValidationResource\RelationManagers;
use App\Models\Item;
use App\Models\LocatorInvoiceValidation;
use App\Models\PalletValidation;
use App\Models\Plant;
use App\Models\StickerMaster;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Actions;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Log;
use Filament\Tables\Actions\Action;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
class PalletValidationResource extends Resource
{
@@ -47,148 +40,147 @@ class PalletValidationResource extends Resource
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->required()
->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 ($state, callable $set) {
$set('pallet_number', null);
$set('serial_number', null);
$set('removeSno_number', null);
$set('Sno_quantity', 0);
$set('pending_pallet_list', null);
}),
Forms\Components\TextInput::make('pallet_number')
->label('Scan Pallet No')
->reactive()
->required()
->readonly() //fn ($get) => (bool)$get('pallet_number_locked') || $get('serial_number') || $get('removeSno_number')
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
])
->suffixAction(fn ($get,$set) =>
Forms\Components\Actions\Action::make('addPallet')
->label('')
->button()
->icon('heroicon-o-plus')
->color('primary')
->extraAttributes([
'class' => 'p-1 w-7 h-7',
])
->action(function ($get, $set, $livewire) {
$plantId = $get('plant_id');
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->required()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
session(['pallet_clicked_time' => now()->toDateTimeString()]);
session(['pallet_created_by' => Filament::auth()->user()->name]);
$year = now()->format('y');
$month = now()->format('m');
$prefix = "EP-{$year}{$month}";
$lastPallet1 = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); //->where('plant_id', $plantId)
$lastPallet2 = LocatorInvoiceValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first();
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
if ($lastPallet1 && $lastPallet2) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
if (intval($serialPart1) > intval($serialPart2)) {
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
} else {
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
}
}
else if ($lastPallet1) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
// OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
}
else if ($lastPallet2) {
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
// OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
}
$newPalletNumber = "{$prefix}{$newNumber}";
$set('pallet_number', $newPalletNumber);
$set('pallet_number_locked', true);
$set('plant_id', $plantId);
$livewire->redirectToQrPdf($newPalletNumber);
})
),
Forms\Components\TextInput::make('serial_number')
->label('Scan Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('removeSno_number'))
->extraAttributes([
'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()',
]),
Forms\Components\TextInput::make('removeSno_number')
->label('Remove Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => !$get('pallet_number') || $get('serial_number'))
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processRemoveSNo()',
]),
Forms\Components\TextInput::make('Sno_quantity')
->label('SNo. Quantity')
->readOnly()
->default('0'),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('scanned_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('pallet_number_locked')
->default(false),
Forms\Components\Select::make('pending_pallet_list')
->label('Pending Pallet List')
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', $state);
$set('pallet_number_locked', false);
})
->options(function ($get) {
$plantId = $get('plant_id');
if (!$plantId) {
return [];
}
return PalletValidation::query()
->where('plant_id', $plantId)
->where(function($query) {
$query->whereNull('pallet_status')
->orWhere('pallet_status', '');
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->whereNotNull('pallet_number')
->orderBy('pallet_number', 'asc')
->pluck('pallet_number')
->unique()
->mapWithKeys(fn($number) => [$number => $number])
->toArray();
}),
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', null);
$set('serial_number', null);
$set('removeSno_number', null);
$set('Sno_quantity', 0);
$set('pending_pallet_list', null);
}),
Forms\Components\TextInput::make('pallet_number')
->label('Scan Pallet No')
->reactive()
->required()
->readonly() // fn ($get) => (bool)$get('pallet_number_locked') || $get('serial_number') || $get('removeSno_number')
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
])
->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addPallet')
->label('')
->button()
->icon('heroicon-o-plus')
->color('primary')
->extraAttributes([
'class' => 'p-1 w-7 h-7',
])
->action(function ($get, $set, $livewire) {
$plantId = $get('plant_id');
Forms\Components\View::make('forms.components.save-pallet-button')
])
->columns(5),
session(['pallet_clicked_time' => now()->toDateTimeString()]);
session(['pallet_created_by' => Filament::auth()->user()->name]);
$year = now()->format('y');
$month = now()->format('m');
$prefix = "EP-{$year}{$month}";
$lastPallet1 = PalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); // ->where('plant_id', $plantId)
$lastPallet2 = LocatorInvoiceValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first();
$newNumber = '001'; // $lastPallet ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) : '001';
if ($lastPallet1 && $lastPallet2) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
if (intval($serialPart1) > intval($serialPart2)) {
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
} else {
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
}
} elseif ($lastPallet1) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
// OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
} elseif ($lastPallet2) {
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
// OR
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
}
$newPalletNumber = "{$prefix}{$newNumber}";
$set('pallet_number', $newPalletNumber);
$set('pallet_number_locked', true);
$set('plant_id', $plantId);
$livewire->redirectToQrPdf($newPalletNumber);
})
),
Forms\Components\TextInput::make('serial_number')
->label('Scan Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('removeSno_number'))
->extraAttributes([
'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()',
]),
Forms\Components\TextInput::make('removeSno_number')
->label('Remove Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('serial_number'))
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processRemoveSNo()',
]),
Forms\Components\TextInput::make('Sno_quantity')
->label('SNo. Quantity')
->readOnly()
->default('0'),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('scanned_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('pallet_number_locked')
->default(false),
Forms\Components\Select::make('pending_pallet_list')
->label('Pending Pallet List')
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', $state);
$set('pallet_number_locked', false);
})
->options(function ($get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
return PalletValidation::query()
->where('plant_id', $plantId)
->where(function ($query) {
$query->whereNull('pallet_status')
->orWhere('pallet_status', '');
})
->whereNotNull('pallet_number')
->orderBy('pallet_number', 'asc')
->pluck('pallet_number')
->unique()
->mapWithKeys(fn ($number) => [$number => $number])
->toArray();
}),
Forms\Components\View::make('forms.components.save-pallet-button'),
])
->columns(5),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
@@ -199,8 +191,7 @@ class PalletValidationResource extends Resource
public static function table(Table $table): Table
{
return $table
->columns([
->columns([
// Tables\Columns\TextColumn::make('id')
// ->label('ID')
// ->numeric()
@@ -212,6 +203,7 @@ class PalletValidationResource 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')
@@ -286,6 +278,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();
})
->reactive()
@@ -306,19 +299,20 @@ class PalletValidationResource extends Resource
->label('Pallet Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return PalletValidation::where('plant_id', $plantId)
// ->whereNotNull('pallet_number')
// ->where('pallet_number', '!=', '')
->where('pallet_number', 'like', 'EP-' . '%')
->where('pallet_number', 'like', 'EP-'.'%')
// ->where(function($query) {
// $query->where('pallet_number', '!=', null)->where('pallet_number', '!=', '');
// })
->orderBy('pallet_number', 'desc')
->get()
//->unique('pallet_number')
// ->unique('pallet_number')
->pluck('pallet_number', 'pallet_number')
->toArray();
})
@@ -336,12 +330,13 @@ class PalletValidationResource extends Resource
->label('Locator Number')
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return PalletValidation::where('plant_id', $plantId)
->whereNotNull('locator_number')
->where('locator_number','!=', '')
->where('locator_number', '!=', '')
->orderBy('locator_number', 'asc')
->get()
->unique('locator_number')
@@ -391,23 +386,29 @@ class PalletValidationResource extends Resource
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) { //$plant = $data['Plant'] ?? null
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['pallet_number'])) {
if (! empty($data['pallet_number'])) {
$query->where('pallet_number', $data['pallet_number']);
}
if (!empty($data['serial_number'])) {
if (! empty($data['serial_number'])) {
$query->where('serial_number', $data['serial_number']);
}
if (!empty($data['pallet_status'])) {
if (! empty($data['pallet_status'])) {
$query->where('pallet_status', $data['pallet_status']);
}
if (!empty($data['locator_number'])) {
if (! empty($data['locator_number'])) {
$query->where('locator_number', $data['locator_number']);
}
@@ -415,87 +416,93 @@ class PalletValidationResource extends Resource
// $query->where('locator_quantity', $data['locator_quantity']);
// }
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
$query->where('locator_quantity', $data['locator_quantity']);//(int)
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$query->where('locator_quantity', $data['locator_quantity']); // (int)
}
if (!empty($data['created_from'])) {
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['created_to'])) {
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (!empty($data['created_by'])) {
if (! empty($data['created_by'])) {
$query->where('created_by', $data['created_by']);
}
if (!empty($data['scanned_from'])) {
if (! empty($data['scanned_from'])) {
$query->where('scanned_at', '>=', $data['scanned_from']);
}
if (!empty($data['scanned_to'])) {
if (! empty($data['scanned_to'])) {
$query->where('scanned_at', '<=', $data['scanned_to']);
}
if (!empty($data['scanned_by'])) {
if (! empty($data['scanned_by'])) {
$query->where('scanned_by', $data['scanned_by']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['pallet_number'])) {
$indicators[] = 'Pallet Number: ' . $data['pallet_number'];
if (! empty($data['pallet_number'])) {
$indicators[] = 'Pallet Number: '.$data['pallet_number'];
}
if (!empty($data['serial_number'])) {
$indicators[] = 'Serial Number: ' . $data['serial_number'];
if (! empty($data['serial_number'])) {
$indicators[] = 'Serial Number: '.$data['serial_number'];
}
if (!empty($data['pallet_status'])) {
$indicators[] = 'Pallet Status: ' . $data['pallet_status'];
if (! empty($data['pallet_status'])) {
$indicators[] = 'Pallet Status: '.$data['pallet_status'];
}
if (!empty($data['locator_number'])) {
$indicators[] = 'Locator Number: ' . $data['locator_number'];
if (! empty($data['locator_number'])) {
$indicators[] = 'Locator Number: '.$data['locator_number'];
}
// if (!empty($data['locator_quantity'])) {
// $indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
// }
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { //isset($data['locator_quantity']) &&
$indicators[] = 'Locator Quantity: ' . $data['locator_quantity'];
if ($data['locator_quantity'] != null && $data['locator_quantity'] != '') { // isset($data['locator_quantity']) &&
$indicators[] = 'Locator Quantity: '.$data['locator_quantity'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
if (!empty($data['created_by'])) {
$indicators[] = 'Created By: ' . $data['created_by'];
if (! empty($data['created_by'])) {
$indicators[] = 'Created By: '.$data['created_by'];
}
if (!empty($data['scanned_from'])) {
$indicators[] = 'Scanned From: ' . $data['scanned_from'];
if (! empty($data['scanned_from'])) {
$indicators[] = 'Scanned From: '.$data['scanned_from'];
}
if (!empty($data['scanned_to'])) {
$indicators[] = 'Scanned To: ' . $data['scanned_to'];
if (! empty($data['scanned_to'])) {
$indicators[] = 'Scanned To: '.$data['scanned_to'];
}
if (!empty($data['scanned_by'])) {
$indicators[] = 'Scanned By: ' . $data['scanned_by'];
if (! empty($data['scanned_by'])) {
$indicators[] = 'Scanned By: '.$data['scanned_by'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -515,64 +522,66 @@ class PalletValidationResource extends Resource
->label('Re-Print Pallet QR')
->form([
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('plant')
->label('Select Plant')
// ->options(Plant::pluck('name', 'id')->toArray())
->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()
->reactive()
->columnSpan(2),
Forms\Components\Select::make('pallet_list')
->label('Select Pallet')
->searchable()
->required()
->reactive()
->columnSpan(1)
//->optionsLimit(500)
->options(function (callable $get) {
$plantId = $get('plant');
->schema([
Forms\Components\Select::make('plant')
->label('Select Plant')
// ->options(Plant::pluck('name', 'id')->toArray())
->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::pluck('name', 'id')->toArray();
})
->required()
->reactive()
->columnSpan(2),
Forms\Components\Select::make('pallet_list')
->label('Select Pallet')
->searchable()
->required()
->reactive()
->columnSpan(1)
// ->optionsLimit(500)
->options(function (callable $get) {
$plantId = $get('plant');
return PalletValidation::query()->where('plant_id', $plantId)
// ->whereNotNull('pallet_number')
// ->where('pallet_number', '!=', '')
->where('pallet_number', 'like', 'EP-' . '%')
->select('pallet_number')
->distinct()
->orderBy('pallet_number', 'desc')
->pluck('pallet_number', 'pallet_number')
->toArray();
}),
])
->columns(['default' => 1, 'sm' => 3]),
if (! $plantId) {
return [];
}
return PalletValidation::query()->where('plant_id', $plantId)
// ->whereNotNull('pallet_number')
// ->where('pallet_number', '!=', '')
->where('pallet_number', 'like', 'EP-'.'%')
->select('pallet_number')
->distinct()
->orderBy('pallet_number', 'desc')
->pluck('pallet_number', 'pallet_number')
->toArray();
}),
])
->columns(['default' => 1, 'sm' => 3]),
])
->action(function (array $data) {
->action(function (array $data) {
$selectedPalletNumber = $data['pallet_list'];
return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]);
})
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view reprint pallet number');
}),
ImportAction::make()
->importer(PalletValidationImporter::class)
->label('Import Pallet')
->color('warning')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import pallet validation');
}),
ExportAction::make()
->exporter(PalletValidationExporter::class)
->label('Export Pallet')
->color('warning')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export pallet validation');
}),
]);

View File

@@ -5,11 +5,15 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ProcessOrderExporter;
use App\Filament\Imports\ProcessOrderImporter;
use App\Filament\Resources\ProcessOrderResource\Pages;
use App\Models\Item;
use App\Models\Plant;
use App\Models\ProcessOrder;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
@@ -18,19 +22,13 @@ use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Smalot\PdfParser\Parser;
use Storage;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use App\Models\Line;
use Filament\Forms\Components\TextInput;
use App\Models\Item;
use App\Models\User;
// use App\Models\PalletValidation;
// use Dom\Text;
@@ -173,16 +171,16 @@ class ProcessOrderResource extends Resource
$plantId = $get('plant_id');
$itemId = $get('item_id');
$processOrder = $value;
//$currentId = $get('id'); // current editing record id
// $currentId = $get('id'); // current editing record id
if (! $plantId || ! $processOrder) {
return;
}
$existing = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('item_id', '!=', $itemId)
->first();
$existing = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)
->where('item_id', '!=', $itemId)
->first();
if ($existing) {
@@ -288,14 +286,14 @@ class ProcessOrderResource extends Resource
->disk('local')
->directory('uploads/temp')
->preserveFilenames()
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view process order packing slip');
})
->reactive(),
Forms\Components\Actions::make([
Action::make('uploadNow')
->label('Upload PDF Now')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view process order packing slip');
})
->action(function ($get, callable $set) {
@@ -385,7 +383,7 @@ class ProcessOrderResource extends Resource
Action::make('downloadAttachment')
->label('Download PDF')
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view process order packing slip');
})
->action(function ($get) {
@@ -482,6 +480,7 @@ class ProcessOrderResource 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')
@@ -561,133 +560,141 @@ class ProcessOrderResource extends Resource
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Search by Item Code')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
return Item::whereHas('processOrders', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('code', 'id');
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
TextInput::make('process_order')
->label('Process Order')
->placeholder('Enter Process Order'),
TextInput::make('sfg_number')
->label('Sfg Number')
->placeholder(placeholder: 'Enter Sfg Number'),
TextInput::make('machine_name')
->label('Machine Name')
->placeholder(placeholder: 'Enter Machine Name'),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Item']) && empty($data['process_order']) && empty($data['sfg_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['machine_name'])) {
return $query->whereRaw('1 = 0');
}
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
TextInput::make('process_order')
->label('Process Order')
->placeholder('Enter Process Order'),
TextInput::make('sfg_number')
->label('Sfg Number')
->placeholder(placeholder: 'Enter Sfg Number'),
TextInput::make('machine_name')
->label('Machine Name')
->placeholder(placeholder: 'Enter Machine Name'),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Item']) && empty($data['process_order']) && empty($data['sfg_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['machine_name'])) {
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['process_order'])) {
$query->where('process_order', $data['process_order']);
}
if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (!empty($data['sfg_number'])) {
$query->where('sfg_number', $data['sfg_number']);
}
if (! empty($data['process_order'])) {
$query->where('process_order', $data['process_order']);
}
if (!empty($data['machine_name'])) {
// $query->where('machine_name', $data['machine_name']);
$query->where('machine_name', 'like', '%' . $data['machine_name'] . '%');
}
if (! empty($data['sfg_number'])) {
$query->where('sfg_number', $data['sfg_number']);
}
if (!empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['machine_name'])) {
// $query->where('machine_name', $data['machine_name']);
$query->where('machine_name', 'like', '%'.$data['machine_name'].'%');
}
if (!empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
//$query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
// $query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Item'])) {
$indicators[] = 'Item: ' . Item::where('id', $data['Item'])->value('code');
}
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['process_order'])) {
$indicators[] = 'Process Order: ' . $data['process_order'];
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['sfg_number'])) {
$indicators[] = 'Sfg Number: ' . $data['sfg_number'];
}
if (! empty($data['Item'])) {
$indicators[] = 'Item: '.Item::where('id', $data['Item'])->value('code');
}
if (!empty($data['machine_name'])) {
$indicators[] = 'Machine Name: ' . $data['machine_name'];
}
if (! empty($data['process_order'])) {
$indicators[] = 'Process Order: '.$data['process_order'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
}
if (! empty($data['sfg_number'])) {
$indicators[] = 'Sfg Number: '.$data['sfg_number'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
}
if (! empty($data['machine_name'])) {
$indicators[] = 'Machine Name: '.$data['machine_name'];
}
return $indicators;
})
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -730,16 +737,16 @@ class ProcessOrderResource extends Resource
->required()
->searchable()
->options(function (callable $get) {
$plantId = $get('plant');
$plantId = $get('plant');
if(empty($plantId)) {
return [];
}
if (empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
@@ -763,30 +770,31 @@ class ProcessOrderResource extends Resource
->required()
->searchable()
->options(function (callable $get) {
$plantId = $get('plant');
$itemId = $get('Item');
$processOrder = $get('process_order');
$plantId = $get('plant');
$itemId = $get('Item');
$processOrder = $get('process_order');
if(empty($plantId) || empty($itemId) || empty($processOrder)) {
return [];
}
if (empty($plantId) || empty($itemId) || empty($processOrder)) {
return [];
}
return ProcessOrder::where('plant_id', $plantId)
->where('item_id', $itemId)
->where('process_order', $processOrder)
->pluck('coil_number', 'coil_number');
return ProcessOrder::where('plant_id', $plantId)
->where('item_id', $itemId)
->where('process_order', $processOrder)
->pluck('coil_number', 'coil_number');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant');
$itemId = $get('Item');
$processOrder = $get('process_order');
if(!$plantId || !$itemId || !$processOrder || !$state) {
if (! $plantId || ! $itemId || ! $processOrder || ! $state) {
$set('received_quantity', null);
$set('machine_name', null);
return;
}
@@ -815,12 +823,13 @@ class ProcessOrderResource extends Resource
// })
->action(function (array $data) {
$username = Filament::auth()->user()->name;
return redirect()->route('download-reprint-process-pdf', [
'plant' => $data['plant'],
'item' => $data['Item'],
'plant' => $data['plant'],
'item' => $data['Item'],
'process_order' => $data['process_order'],
'coil_number' => $data['coil_number'],
'name' => $username,
'coil_number' => $data['coil_number'],
'name' => $username,
]);
})
->visible(function () {

View File

@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
use App\Filament\Exports\ProductCharacteristicsMasterExporter;
use App\Filament\Imports\ProductCharacteristicsMasterImporter;
use App\Filament\Resources\ProductCharacteristicsMasterResource\Pages;
use App\Filament\Resources\ProductCharacteristicsMasterResource\RelationManagers;
use App\Models\Item;
use App\Models\Line;
use App\Models\Machine;
@@ -14,19 +13,19 @@ use App\Models\ProductCharacteristicsMaster;
use App\Models\WorkGroupMaster;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
class ProductCharacteristicsMasterResource extends Resource
{
@@ -45,13 +44,14 @@ class ProductCharacteristicsMasterResource 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();
})
->reactive()
->required(),
Forms\Components\Select::make('item_id')
->label('Item Code')
//->relationship('item', 'code')
// ->relationship('item', 'code')
->searchable()
->reactive()
->options(function (callable $get) {
@@ -59,6 +59,7 @@ class ProductCharacteristicsMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
})
->required(),
@@ -70,23 +71,24 @@ class ProductCharacteristicsMasterResource extends Resource
if (empty($plantId)) {
return [];
}
return Line::where('plant_id', $plantId)->pluck('name', 'id');
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('machine_id', null);
if (!$get('work_group_master_id')) {
if (! $get('work_group_master_id')) {
$set('machine_id', null);
}
})
->required(),
// ->relationship('line', 'name'),
// ->relationship('line', 'name'),
Forms\Components\Select::make('work_group_master_id')
->label('Group Work Center')
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) {
if (! $get('plant_id') || ! $get('line_id')) {
return [];
}
@@ -94,23 +96,22 @@ class ProductCharacteristicsMasterResource extends Resource
$workGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id";
if (!empty($line->$column)) {
if (! empty($line->$column)) {
$workGroupIds[] = $line->$column;
}
}
return WorkGroupMaster::where('plant_id', $get('plant_id'))->whereIn('id', $workGroupIds)->pluck('name', 'id')->toArray();
})
->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('mGroupWorkError', 'Please select a line first.');
$set('machine_id', null);
return;
}
else
{
} else {
// $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// {
@@ -130,7 +131,7 @@ class ProductCharacteristicsMasterResource extends Resource
->hintColor('danger'),
Forms\Components\Select::make('machine_id')
->label('Work Center')
//->relationship('machine', 'name'),
// ->relationship('machine', 'name'),
->searchable()
->reactive()
->options(function (callable $get) {
@@ -148,7 +149,7 @@ class ProductCharacteristicsMasterResource extends Resource
->pluck('work_center', 'id');
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
if (!$get('plant_id') || !$get('line_id') || !$get('work_group_master_id')) {
if (! $get('plant_id') || ! $get('line_id') || ! $get('work_group_master_id')) {
$set('machine_id', null);
}
})
@@ -157,7 +158,7 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Characteristics Type')
->options([
'Product' => 'Product',
'Process' => 'Process',
'Process' => 'Process',
])
->reactive()
->required(),
@@ -167,7 +168,7 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Inspection Type')
->options([
'Visual' => 'Visual',
'Value' => 'Value',
'Value' => 'Value',
])
->reactive()
->required(),
@@ -208,9 +209,9 @@ class ProductCharacteristicsMasterResource extends Resource
$upper = $get('upper');
$middle = $value;
if (!is_null($lower) && !is_null($upper) && !is_null($middle)) {
if (!($lower <= $middle && $middle <= $upper)) {
$fail("Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper).");
if (! is_null($lower) && ! is_null($upper) && ! is_null($middle)) {
if (! ($lower <= $middle && $middle <= $upper)) {
$fail('Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper).');
}
}
};
@@ -233,6 +234,7 @@ class ProductCharacteristicsMasterResource 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')
@@ -317,201 +319,207 @@ class ProductCharacteristicsMasterResource extends Resource
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->nullable()
->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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Line')
->label('Select Line')
->nullable()
->options(function (callable $get) {
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Line')
->label('Select Line')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
if (empty($plantId)) {
return [];
}
return Line::where('plant_id', $plantId)->pluck('name', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
}),
Select::make('Item')
->label('Search by Item Code')
->nullable()
->searchable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
return Item::whereHas('productCharacteristicsMasters', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('code', 'id');
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
Select::make('work_group_master')
->label('Select Work Group Master')
->nullable()
->options(function (callable $get) {
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('process_order', null);
// }),
Select::make('work_group_master')
->label('Select Work Group Master')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if(empty($plantId)) {
if (empty($plantId)) {
return [];
}
return WorkGroupMaster::where('plant_id', $plantId)->pluck('name', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Machine', null);
}),
Select::make('Machine')
->label('Select Machine')
->nullable()
->options(function (callable $get) {
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Machine', null);
}),
Select::make('Machine')
->label('Select Machine')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
$lineId = $get('Line');
if(empty($plantId) || empty($lineId)) {
if (empty($plantId) || empty($lineId)) {
return [];
}
return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id');
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->reactive(),
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('process_order', null);
// }),
// TextInput::make('process_order')
// ->label('Process Order')
// ->placeholder('Enter Process Order'),
// TextInput::make('coil_number')
// ->label('Coil Number')
// ->placeholder(placeholder: 'Enter Coil Number'),
Select::make('characteristics_type')
->label('Characteristics Type')
->options([
'Product' => 'Product',
'Process' => 'Process'
]),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['work_group_master']) && empty($data['Machine']) && empty($data['characteristics_type']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
// TextInput::make('process_order')
// ->label('Process Order')
// ->placeholder('Enter Process Order'),
// TextInput::make('coil_number')
// ->label('Coil Number')
// ->placeholder(placeholder: 'Enter Coil Number'),
Select::make('characteristics_type')
->label('Characteristics Type')
->options([
'Product' => 'Product',
'Process' => 'Process',
]),
DateTimePicker::make(name: 'created_from')
->label('Created From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['work_group_master']) && empty($data['Machine']) && empty($data['characteristics_type']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Line'])) {
$query->where('line_id', $data['Line']);
}
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (! empty($data['Line'])) {
$query->where('line_id', $data['Line']);
}
if (!empty($data['work_group_master'])) {
$query->where('work_group_master_id', $data['work_group_master']);
}
if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (!empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']);
}
if (! empty($data['work_group_master'])) {
$query->where('work_group_master_id', $data['work_group_master']);
}
if (!empty($data['characteristics_type'])) {
$query->where('characteristics_type', $data['characteristics_type']);
}
if (! empty($data['Machine'])) {
$query->where('machine_id', $data['Machine']);
}
if (!empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['characteristics_type'])) {
$query->where('characteristics_type', $data['characteristics_type']);
}
if (!empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
//$query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
// $query->orderBy('created_at', 'asc');
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Item'])) {
$indicators[] = 'Item: ' . Item::where('id', $data['Item'])->value('code');
}
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
}
if (!empty($data['work_group_master'])) {
$indicators[] = 'Work Group Master: ' . WorkGroupMaster::where('id', $data['work_group_master'])->value('name');
}
if (! empty($data['Item'])) {
$indicators[] = 'Item: '.Item::where('id', $data['Item'])->value('code');
}
if (!empty($data['Machine'])) {
$indicators[] = 'Machine: ' . Machine::where('id', $data['Machine'])->value('work_center');
}
if (! empty($data['work_group_master'])) {
$indicators[] = 'Work Group Master: '.WorkGroupMaster::where('id', $data['work_group_master'])->value('name');
}
if (!empty($data['characteristics_type'])) {
$indicators[] = 'Characteristics Type: ' . $data['characteristics_type'];
}
if (! empty($data['Machine'])) {
$indicators[] = 'Machine: '.Machine::where('id', $data['Machine'])->value('work_center');
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
}
if (! empty($data['characteristics_type'])) {
$indicators[] = 'Characteristics Type: '.$data['characteristics_type'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
return $indicators;
})
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -530,14 +538,14 @@ class ProductCharacteristicsMasterResource extends Resource
->label('Import Product Characteristics Masters')
->color('warning')
->importer(ProductCharacteristicsMasterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import product characteristics master');
}),
ExportAction::make()
->label('Export Product Characteristics Masters')
->color('warning')
->exporter(ProductCharacteristicsMasterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export product characteristics master');
}),
]);

View File

@@ -6,30 +6,28 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionLineStopExporter;
use App\Filament\Imports\ProductionLineStopImporter;
use App\Filament\Resources\ProductionLineStopResource\Pages;
use App\Filament\Resources\ProductionLineStopResource\RelationManagers;
use App\Models\Block;
use App\Models\Line;
use App\Models\LineStop;
use App\Models\Plant;
use App\Models\ProductionLineStop;
use App\Models\Shift;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
class ProductionLineStopResource extends Resource
{
@@ -56,22 +54,22 @@ class ProductionLineStopResource 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();
})
->default(function () {
return optional(ProductionLineStop::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('block_name', null);
if (!$plantId) {
if (! $plantId) {
$set('plsPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('plsPlantError', null);
}
})
@@ -85,29 +83,28 @@ class ProductionLineStopResource extends Resource
// ->nullable()
->label('Block')
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
// return \App\Models\Block::where('plant_id', $get('plant_id'))
return Block::where('plant_id', $get('plant_id'))
// return \App\Models\Block::where('plant_id', $get('plant_id'))
return Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive()
->default(function () {
$latestShiftId = optional(ProductionLineStop::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionLineStop::where('id', $get('id'))->first();
// $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
if ($getBlock->block_id) {
$set('block_name', $getBlock->block_id);
$set('plsBlockError', null);
}
@@ -116,12 +113,11 @@ class ProductionLineStopResource extends Resource
$blockId = $get('block_name');
$set('shift_id', null);
if (!$blockId) {
if (! $blockId) {
$set('plsBlockError', 'Please select a block first.');
return;
}
else
{
} else {
$set('plsBlockError', null);
}
})
@@ -135,12 +131,12 @@ class ProductionLineStopResource extends Resource
->required()
// ->nullable()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) {
if (! $get('plant_id') || ! $get('block_name')) {
return [];
}
return Shift::where('plant_id', $get('plant_id'))
->where('block_id', $get('block_name'))
return Shift::where('plant_id', $get('plant_id'))
->where('block_id', $get('block_name'))
->pluck('name', 'id')
->toArray();
})
@@ -150,11 +146,9 @@ class ProductionLineStopResource extends Resource
})
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionLineStop::where('id', $get('id'))->first();
if($getShift->shift_id)
{
if ($getShift->shift_id) {
$set('shift_id', $getShift->shift_id);
$set('plsShiftError', null);
}
@@ -163,12 +157,11 @@ class ProductionLineStopResource extends Resource
$shiftId = $get('shift_id');
$set('line_id', null);
if (!$shiftId) {
if (! $shiftId) {
$set('plsShiftError', 'Please select a shift first.');
return;
}
else
{
} else {
$set('plsShiftError', null);
}
})
@@ -182,12 +175,12 @@ class ProductionLineStopResource extends Resource
->required()
// ->nullable()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
return [];
}
// return \App\Models\Line::where('plant_id', $get('plant_id'))
return Line::where('plant_id', $get('plant_id'))
// return \App\Models\Line::where('plant_id', $get('plant_id'))
return Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
@@ -196,11 +189,9 @@ class ProductionLineStopResource extends Resource
return optional(ProductionLineStop::latest()->first())->line_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionLineStop::where('id', $get('id'))->first();
if($getShift->line_id)
{
if ($getShift->line_id) {
$set('line_id', $getShift->line_id);
$set('plsLineError', null);
}
@@ -210,12 +201,11 @@ class ProductionLineStopResource extends Resource
$set('linestop_id', null);
$set('lineStop_reason', null);
if (!$lineId) {
if (! $lineId) {
$set('plsLineError', 'Please select a line first.');
return;
}
else
{
} else {
$set('plsLineError', null);
}
})
@@ -251,8 +241,9 @@ class ProductionLineStopResource extends Resource
$lineStopId = $get('linestop_id'); // Get entered linestop_id
// Ensure `linestop_id` is not cleared
if (!$lineStopId) {
if (! $lineStopId) {
$set('lineStop_reason', null);
return;
}
@@ -275,16 +266,14 @@ class ProductionLineStopResource extends Resource
->before('to_datetime')
->reactive()
// ->closeOnDateSelection()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set)
),
->afterStateUpdated(fn ($state, callable $set, callable $get) => self::updateStopDuration($get, $set)
),
Forms\Components\DateTimePicker::make('to_datetime')
->label('To DateTime')
->required()
->after('from_datetime')
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set) //self means it calling the function within the class
->afterStateUpdated(fn ($state, callable $set, callable $get) => self::updateStopDuration($get, $set) // self means it calling the function within the class
)
->extraAttributes(fn ($get) => [
'class' => $get('plsToDateError') ? 'border-red-500' : '',
@@ -293,7 +282,7 @@ class ProductionLineStopResource extends Resource
->hintColor('danger'),
Forms\Components\TextInput::make('stop_hour')
->required()
->label( 'Stop Hour')
->label('Stop Hour')
// ->dehydrated(false) // Don't send to backend
->readOnly(true)
->numeric(),
@@ -318,24 +307,21 @@ class ProductionLineStopResource extends Resource
$from = $get('from_datetime');
$to = $get('to_datetime');
// Carbon is a PHP date and time library.
// Carbon is a PHP date and time library.
if ($from && $to) {
$fromTime = Carbon::parse($from); //Carbon::parse($from) converts the from datetime string into a Carbon objec
$fromTime = Carbon::parse($from); // Carbon::parse($from) converts the from datetime string into a Carbon objec
$toTime = Carbon::parse($to);
if ($fromTime->lt($toTime)) {
$diffInMinutes = $fromTime->diffInMinutes($toTime);
// $set('stop_hour', floor($diffInMinutes / 60));
// $set('stop_min', $diffInMinutes % 60);
if((floor($diffInMinutes / 60) === 0.0) && ($diffInMinutes % 60 === 0))
{
if ((floor($diffInMinutes / 60) === 0.0) && ($diffInMinutes % 60 === 0)) {
$set('stop_hour', null);
$set('stop_min', null);
$set('plsToDateError', 'Time difference must be atlease a minute.');
}
else
{
} else {
$set('stop_hour', floor($diffInMinutes / 60));
$set('stop_min', $diffInMinutes % 60);
$set('plsToDateError', null);
@@ -363,6 +349,7 @@ class ProductionLineStopResource 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('linestop.code')
@@ -433,8 +420,7 @@ class ProductionLineStopResource extends Resource
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
//plant
// plant
Select::make('Plant')
->label('Select Plant')
->nullable()
@@ -443,6 +429,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();
})
->reactive()
@@ -453,31 +440,33 @@ class ProductionLineStopResource extends Resource
$set('line_stop_id', null);
}),
//line
// line
Select::make('Line')
->label('Select line')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Line::where('plant_id', $plantId)
->pluck('name', 'id');
->pluck('name', 'id');
})
->reactive(),
//block
// block
Select::make('Block')
->label('Select Block')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
})
->reactive()
@@ -485,7 +474,7 @@ class ProductionLineStopResource extends Resource
$set('Shift', null);
}),
//shift
// shift
Select::make('Shift')
->label('Select Shift')
->nullable()
@@ -493,7 +482,7 @@ class ProductionLineStopResource extends Resource
$plantId = $get('Plant');
$blockId = $get('Block');
if (!$plantId || !$blockId) {
if (! $plantId || ! $blockId) {
return []; // Return empty if plant or block is not selected
}
@@ -503,12 +492,13 @@ class ProductionLineStopResource extends Resource
})
->reactive(),
Select::make('line_stop_id') //linestop_id
Select::make('line_stop_id') // linestop_id
->label('Search by Line Stop Code')
->nullable()
// ->options(fn () => LineStop::orderBy('code')->whereHas('productionLineStops')->pluck('code', 'id'))
->options(function (callable $get) {
$pId = $get('Plant');
return LineStop::orderBy('code')->whereHas('productionLineStops', function ($query) use ($pId) {
if ($pId) {
$query->where('plant_id', $pId);
@@ -535,19 +525,25 @@ class ProductionLineStopResource extends Resource
return $query->whereRaw('1 = 0');
}
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift);
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $data['Shift']);
}
if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line);
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $data['Line']);
}
if ($code = $data['line_stop_id'] ?? null) {
if (! empty($data['line_stop_id'])) { // if ($code = $data['line_stop_id'] ?? null) {
// Find the linestop_id by code entered
// $lineStop = \App\Models\LineStop::where('code', 'like', "%{$code}%")->first();
@@ -558,48 +554,54 @@ class ProductionLineStopResource extends Resource
// // If no match found, you can either handle it as an error or return no results
// $query->where('linestop_id', null); // This will return no results if no match
// }
$query->where('linestop_id', $code);
$query->where('linestop_id', $data['line_stop_id']);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $data['created_from']);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $data['created_to']);
}
// return $query;
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Shift'])) {
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name');
if (! empty($data['Shift'])) {
$indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
}
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
if (!empty($data['line_stop_id'])) {
if (! empty($data['line_stop_id'])) {
$lineStopCod = LineStop::find($data['line_stop_id'])->code ?? 'Unknown';
$indicators[] = 'Line Stop Code: ' . $lineStopCod;
$indicators[] = 'Line Stop Code: '.$lineStopCod;
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -611,7 +613,7 @@ class ProductionLineStopResource extends Resource
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export')
FilamentExportBulkAction::make('export'),
]),
])
->headerActions([
@@ -619,14 +621,14 @@ class ProductionLineStopResource extends Resource
->label('Import Production Line Stops')
->color('warning')
->importer(ProductionLineStopImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import production line stop');
}),
ExportAction::make()
->label('Export Production Line Stops')
->color('warning')
->exporter(ProductionLineStopExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export production line stop');
}),
]);

View File

@@ -6,7 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
use App\Filament\Exports\ProductionPlanExporter;
use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
use App\Models\Block;
use App\Models\Line;
use App\Models\Plant;
@@ -16,19 +15,18 @@ use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Filters\Filter;
use Illuminate\Support\Facades\Request;
class ProductionPlanResource extends Resource
{
@@ -55,22 +53,22 @@ class ProductionPlanResource 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();
})
->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$set('block_name', null);
if (!$plantId) {
if (! $plantId) {
$set('ppPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('ppPlantError', null);
}
})
@@ -84,7 +82,7 @@ class ProductionPlanResource extends Resource
// ->nullable()
->label('Block')
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -95,16 +93,15 @@ class ProductionPlanResource extends Resource
->reactive()
->default(function () {
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('id'))->first();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
if ($getBlock->block_id) {
$set('block_name', $getBlock->block_id);
$set('ppBlockError', null);
}
@@ -113,12 +110,11 @@ class ProductionPlanResource extends Resource
$blockId = $get('block_name');
$set('shift_id', null);
if (!$blockId) {
if (! $blockId) {
$set('ppBlockError', 'Please select a block first.');
return;
}
else
{
} else {
$set('ppBlockError', null);
}
})
@@ -133,7 +129,7 @@ class ProductionPlanResource extends Resource
// ->nullable()
->autofocus(true)
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) {
if (! $get('plant_id') || ! $get('block_name')) {
return [];
}
@@ -148,11 +144,9 @@ class ProductionPlanResource extends Resource
})
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->shift_id)
{
if ($getShift->shift_id) {
$set('shift_id', $getShift->shift_id);
$set('ppShiftError', null);
}
@@ -161,12 +155,11 @@ class ProductionPlanResource extends Resource
$curShiftId = $get('shift_id');
$set('line_id', null);
if (!$curShiftId) {
if (! $curShiftId) {
$set('ppShiftError', 'Please select a shift first.');
return;
}
else
{
} else {
$set('ppShiftError', null);
}
})
@@ -185,7 +178,7 @@ class ProductionPlanResource extends Resource
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
return [];
}
@@ -198,17 +191,13 @@ class ProductionPlanResource extends Resource
// return optional(ProductionPlan::latest()->first())->line_id;
// })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionPlan::where('id', $get('id'))->first();
if($getShift->line_id)
{
if ($getShift->line_id) {
$set('line_id', $getShift->line_id);
$set('ppLineError', null);
}
}
else
{
} else {
$currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT);
$set('update_date', null);
@@ -217,44 +206,39 @@ class ProductionPlanResource extends Resource
$lineId = $get('line_id');
// $set('plan_quantity', null);
if (!$lineId) {
if (! $lineId) {
$set('ppLineError', 'Please select a line first.');
return;
}
else
{
$isUpdate = !empty($get('id'));
if (!$isUpdate)
{
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->whereDate('created_at', today())
->latest()
->exists();
if ($exists)
{
$set('line_id', null);
$set('ppLineError', 'Production plan already updated.');
return;
}
else
{
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
return;
} else {
$isUpdate = ! empty($get('id'));
if (! $isUpdate) {
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->whereDate('created_at', Carbon::yesterday())
->whereDate('created_at', today())
->latest()
->exists();
if ($existShifts) //if ($existShifts->count() > 0)
{
//$currentDate = date('Y-m-d');
if ($exists) {
$set('line_id', null);
$set('ppLineError', 'Production plan already updated.');
return;
} else {
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->whereDate('created_at', Carbon::yesterday())
->latest()
->exists();
if ($existShifts) { // if ($existShifts->count() > 0)
// $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = Shift::where('id', $get('shift_id'))
->first();
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs;
@@ -262,27 +246,26 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs;
$from_dt = $yesterday . ' ' . $shiftId->start_time;
$from_dt = $yesterday.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
//echo "Choosed a valid shift...";
// echo "Choosed a valid shift...";
$set('line_id', null);
$set('ppLineError', 'Production plan already updated.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
else
{
} else {
$currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id'))
->first();
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs;
@@ -290,33 +273,33 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs;
$from_dt = $currentDate . ' ' . $shiftId->start_time;
$from_dt = $currentDate.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
//echo "Choosed a valid shift...";
if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
// echo "Choosed a valid shift...";
$set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
}
$set('ppLineError', null);
return;
}
else
{
//$currentDate = date('Y-m-d');
} else {
// $currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = Shift::where('id', $get('shift_id'))
->first();
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs;
@@ -324,30 +307,29 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs;
$from_dt = $yesterday . ' ' . $shiftId->start_time;
$from_dt = $yesterday.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
//echo "Choosed a valid shift...";
// echo "Choosed a valid shift...";
// here i'm updating created as yesterday
$set('created_at', $from_dt);
$set('update_date', '1');
$set('ppLineError', null);
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
else
{
} else {
$currentDate = date('Y-m-d');
$shiftId = Shift::where('id', $get('shift_id'))
->first();
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
$hRs = (int) $hRs;
@@ -355,24 +337,26 @@ class ProductionPlanResource extends Resource
$totalMinutes = $hRs * 60 + $miNs;
$from_dt = $currentDate . ' ' . $shiftId->start_time;
$from_dt = $currentDate.' '.$shiftId->start_time;
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
$currentDateTime = date('Y-m-d H:i:s');
// Check if current date time is within the range
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
//echo "Choosed a valid shift...";
if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
// echo "Choosed a valid shift...";
$set('line_id', null);
$set('ppLineError', 'Choosed a invalid shift.');
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
return;
}
}
$set('ppLineError', null);
return;
}
@@ -449,21 +433,18 @@ class ProductionPlanResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get) {
$planQuan = $get('plan_quantity');
if(!$get('update_date') )
{
if(!$get('id'))
{
if (! $get('update_date')) {
if (! $get('id')) {
$currentDT = Carbon::now()->toDateTimeString();
$set('created_at', $currentDT);
}
}
if (!$planQuan) {
if (! $planQuan) {
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
return;
}
else
{
} else {
$set('ppPlanQuanError', null);
}
})
@@ -476,7 +457,7 @@ class ProductionPlanResource extends Resource
->required()
->integer()
->label('Production Quantity')
->readOnly(fn (callable $get) => !$get('id'))
->readOnly(fn (callable $get) => ! $get('id'))
->default(0),
Forms\Components\TextInput::make('id')
->hidden()
@@ -493,7 +474,7 @@ class ProductionPlanResource extends Resource
->readOnly(),
Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name),
])
])
->columns(2),
]);
}
@@ -529,6 +510,7 @@ class ProductionPlanResource 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('plan_quantity')
@@ -544,7 +526,7 @@ class ProductionPlanResource extends Resource
Tables\Columns\TextColumn::make('line.name')
->label('Line')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('shift.block.name')
->label('Block')
->alignCenter()
@@ -552,11 +534,11 @@ class ProductionPlanResource extends Resource
Tables\Columns\TextColumn::make('shift.name')
->label('Shift')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
@@ -584,7 +566,7 @@ class ProductionPlanResource extends Resource
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
//plant
// plant
Select::make('Plant')
->label('Select Plant')
->nullable()
@@ -593,6 +575,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();
})
->reactive()
@@ -602,31 +585,33 @@ class ProductionPlanResource extends Resource
$set('Shift', null);
}),
//line
// line
Select::make('Line')
->label('Select line')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Line::where('plant_id', $plantId)
->pluck('name', 'id');
->pluck('name', 'id');
})
->reactive(),
//block
// block
Select::make('Block')
->label('Select Block')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
})
->reactive()
@@ -634,7 +619,7 @@ class ProductionPlanResource extends Resource
$set('Shift', null);
}),
//shift
// shift
Select::make('Shift')
->label('Select Shift')
->nullable()
@@ -642,7 +627,7 @@ class ProductionPlanResource extends Resource
$plantId = $get('Plant');
$blockId = $get('Block');
if (!$plantId || !$blockId) {
if (! $plantId || ! $blockId) {
return []; // Return empty if plant or block is not selected
}
@@ -669,52 +654,65 @@ class ProductionPlanResource extends Resource
return $query->whereRaw('1 = 0');
}
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift);
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $data['Shift']);
}
if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line);
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $data['Line']);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $data['created_from']);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $data['created_to']);
}
return $query;
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Shift'])) {
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name');
if (! empty($data['Shift'])) {
$indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
}
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -726,7 +724,7 @@ class ProductionPlanResource extends Resource
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
FilamentExportBulkAction::make('export')
FilamentExportBulkAction::make('export'),
]),
])
->headerActions([
@@ -734,14 +732,14 @@ class ProductionPlanResource extends Resource
->label('Import Production Plans')
->color('warning')
->importer(ProductionPlanImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import production plan');
}),
ExportAction::make()
->label('Export Production Plans')
->color('warning')
->exporter(ProductionPlanExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export production plan');
}),
]);

View File

@@ -6,8 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction as ActionsFilam
use App\Filament\Exports\ProductionQuantityExporter;
use App\Filament\Imports\ProductionQuantityImporter;
use App\Filament\Resources\ProductionQuantityResource\Pages;
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
use App\Forms\Components\PlantSelect;
use App\Models\Block;
use App\Models\Item;
use App\Models\Line;
@@ -18,41 +16,36 @@ use Carbon\Carbon;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
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\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Livewire\Livewire;
// use Filament\Forms\Components\View;
use Filament\Tables\Actions\FilamentExportBulkAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
// use Filament\Forms\Components\View;
use Livewire\Livewire;
class ProductionQuantityResource extends Resource
{
protected static ?string $model = ProductionQuantity::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
// protected static ?string $navigationParentItem = 'Display Transactions';
// protected static string $view = 'filament.pages.hourly-production';
// protected static string $view = 'filament.pages.hourly-production';
protected static ?string $navigationGroup = 'Production';
protected static ?int $navigationSort = 1;
// public $plant_id;
public static function form(Form $form): Form
{
@@ -64,30 +57,29 @@ class ProductionQuantityResource extends Resource
->relationship('plant', 'name')
->required()
// ->nullable()
->reactive()
->reactive()
// ->statePath('filters')
->columnSpan(2) //1
->options(function (callable $get) {
->columnSpan(2) // 1
->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(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
->default(function () {
return optional(ProductionQuantity::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => ! empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
$plantId = $get('plant_id');
$set('block_name', null);
if (!$plantId)
{
if (! $plantId) {
$set('pqPlantError', 'Please select a plant first.');
return;
}
else
{
} else {
$set('validationError', null);
$set('pqPlantError', null);
}
@@ -127,7 +119,7 @@ class ProductionQuantityResource extends Resource
// ->nullable()
->columnSpan(1)
->options(function (callable $get) {
if (!$get('plant_id')) {
if (! $get('plant_id')) {
return [];
}
@@ -138,15 +130,14 @@ class ProductionQuantityResource extends Resource
->reactive()
->default(function () {
$latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionQuantity::where('id', $get('id'))->first();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
if ($getBlock->block_id) {
$set('block_name', $getBlock->block_id);
$set('pqBlockError', null);
}
@@ -158,12 +149,11 @@ class ProductionQuantityResource extends Resource
// session(['select_plant' => $get('plant_id')]);
// session()->forget('select_line');
if (!$blockId) {
if (! $blockId) {
$set('pqBlockError', 'Please select a block first.');
return;
}
else
{
} else {
$set('validationError', null);
$set('pqBlockError', null);
}
@@ -179,7 +169,7 @@ class ProductionQuantityResource extends Resource
->columnSpan(1)
// ->nullable()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name')) {
if (! $get('plant_id') || ! $get('block_name')) {
return [];
}
@@ -192,13 +182,11 @@ class ProductionQuantityResource extends Resource
->default(function () {
return optional(ProductionQuantity::latest()->first())->shift_id;
})
//->afterStateUpdated(fn ($set) => $set('line_id', null))
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->shift_id)
{
if ($getShift->shift_id) {
$set('shift_id', $getShift->shift_id);
$set('pqShiftError', null);
}
@@ -207,12 +195,11 @@ class ProductionQuantityResource extends Resource
$curShiftId = $get('shift_id');
$set('line_id', null);
if (!$curShiftId) {
if (! $curShiftId) {
$set('pqShiftError', 'Please select a shift first.');
return;
}
else
{
} else {
$set('validationError', null);
$set('pqShiftError', null);
}
@@ -233,7 +220,7 @@ class ProductionQuantityResource extends Resource
// ->toArray() // Convert collection to array
// )
->options(function (callable $get) {
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
return [];
}
@@ -246,11 +233,9 @@ class ProductionQuantityResource extends Resource
return optional(ProductionQuantity::latest()->first())->line_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
if ($get('id')) {
$getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->line_id)
{
if ($getShift->line_id) {
$set('line_id', $getShift->line_id);
$set('pqLineError', null);
}
@@ -259,16 +244,15 @@ class ProductionQuantityResource extends Resource
$lineId = $get('line_id');
$set('item_code', null);
// session(['select_line' => $get('line_id')]);
// session(['select_line' => $get('line_id')]);
session(['select_line' => $state]);
if (!$lineId) {
if (! $lineId) {
$set('pqLineError', 'Please select a line first.');
return;
}
else
{
} else {
$set('validationError', null);
$set('pqLineError', null);
$set('item_id', null);
@@ -276,7 +260,7 @@ class ProductionQuantityResource extends Resource
$set('serial_number', null);
$exists = ProductionQuantity::where('plant_id', $get('plant_id'))
//->where('shift_id', $get('shift_id'))
// ->where('shift_id', $get('shift_id'))
->where('line_id', $get('line_id'))
->latest() // Orders by created_at DESC
->first();
@@ -296,7 +280,7 @@ class ProductionQuantityResource extends Resource
// 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js
// ])
->extraAttributes([
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })"
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })",
])
->extraAttributes(fn ($get) => [
'class' => $get('pqLineError') ? 'border-red-500' : '',
@@ -319,7 +303,7 @@ class ProductionQuantityResource extends Resource
->minLength(7)
->maxLength(14)
->columnSpan(2)
//->rules(['regex:/^[1-9][0-9]{6,}$/'])
// ->rules(['regex:/^[1-9][0-9]{6,}$/'])
// ->disabled(function ($get) {
// return $get('item_code');
// })
@@ -328,21 +312,20 @@ class ProductionQuantityResource extends Resource
// $latestProductionOrder = ProductionQuantity::latest()->first()->production_order;
// return $latestProductionOrder ?? null;
$latestProduction = ProductionQuantity::latest()->first();
return $latestProduction ? $latestProduction->production_order : null;
})
->afterStateUpdated(function ($state, callable $get, callable $set): void {
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
{
if (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) {
$set('item_code', null);
$set('item_id', null);
$set('serial_number', null);
$set('production_order', null);
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits.");
$set('prodOrdError', 'Must be a numeric value with 7 to 14 digits.');
$set('validationError', null);
return;
}
else
{
} else {
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
@@ -350,6 +333,7 @@ class ProductionQuantityResource extends Resource
$set('production_order', $state);
$set('prodOrdError', null);
$set('validationError', null);
return;
// if (empty($state)) {
// }
@@ -923,17 +907,17 @@ class ProductionQuantityResource extends Resource
->required(),
Forms\Components\Hidden::make('sap_msg_status'),
Forms\Components\Hidden::make('sap_msg_description'),
//->unique(ignoreRecord: true),
// ->autocapitalize('characters'),
// ->columnSpanFull(),
Forms\Components\TextInput::make('recent_qr') //item_description
// ->unique(ignoreRecord: true),
// ->autocapitalize('characters'),
// ->columnSpanFull(),
Forms\Components\TextInput::make('recent_qr') // item_description
->label('Last scanned QR')
->reactive()
->columnSpan(2)
->default(function () {
// Get the latest 'item_id' foreign key from 'production_quantities' table
$latestProductionQuantity = ProductionQuantity::latest()->first();
if (!$latestProductionQuantity) {
if (! $latestProductionQuantity) {
return null; // Return null if no production quantities exist
}
@@ -953,7 +937,7 @@ class ProductionQuantityResource extends Resource
Forms\Components\Hidden::make('operator_id')
->default(Filament::auth()->user()->name),
])
->columns(12), //6
->columns(12), // 6
]);
}
@@ -971,20 +955,21 @@ class ProductionQuantityResource 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('production_order')
->label('Production Order')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('item.code')
->label('Item Code')
->alignCenter()
->sortable(),// ->searchable(),
->sortable(), // ->searchable(),
Tables\Columns\TextColumn::make('item.uom')
->label('Unit of Measure')
->alignCenter()
@@ -1040,7 +1025,7 @@ class ProductionQuantityResource extends Resource
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
//plant
// plant
Select::make('Plant')
->label('Select Plant')
->nullable()
@@ -1049,6 +1034,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();
})
->reactive()
@@ -1061,34 +1047,36 @@ class ProductionQuantityResource extends Resource
$set('operator_id', null);
}),
//line
// line
Select::make('Line')
->label('Select line')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Line::where('plant_id', $plantId)
->pluck('name', 'id');
->pluck('name', 'id');
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('operator_id', null);
}),
//block
// block
Select::make('Block')
->label('Select Block')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return [];
}
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
})
->reactive()
@@ -1097,7 +1085,7 @@ class ProductionQuantityResource extends Resource
$set('operator_id', null);
}),
//shift
// shift
Select::make('Shift')
->label('Select Shift')
->nullable()
@@ -1105,7 +1093,7 @@ class ProductionQuantityResource extends Resource
$plantId = $get('Plant');
$blockId = $get('Block');
if (!$plantId || !$blockId) {
if (! $plantId || ! $blockId) {
return []; // Return empty if plant or block is not selected
}
@@ -1132,11 +1120,10 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
return Item::distinct()->whereHas('productionQuantities')->pluck('code', 'id');
}
else {
return Item::where('plant_id', $plantId)->whereHas('productionQuantities')->distinct()->pluck('code', 'id');
if (! $plantId) {
return Item::whereHas('productionQuantities')->distinct()->pluck('code', 'id');
} else {
return Item::whereHas('productionQuantities')->where('plant_id', $plantId)->distinct()->pluck('code', 'id');
}
// return Item::whereHas('stickerMasters', function ($query) use ($pId) {
// if ($pId) {
@@ -1154,10 +1141,9 @@ class ProductionQuantityResource extends Resource
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId ) {
if (! $plantId) {
return ProductionQuantity::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
}
else {
} else {
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
}
})
@@ -1171,24 +1157,15 @@ class ProductionQuantityResource extends Resource
$plantId = $get('Plant');
$lineId = $get('Line');
$shiftId = $get('Shift');
if (!$plantId && !$lineId && !$shiftId)
{
if (! $plantId && ! $lineId && ! $shiftId) {
return ProductionQuantity::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && !$lineId && !$shiftId)
{
} elseif ($plantId && ! $lineId && ! $shiftId) {
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && $lineId && !$shiftId)
{
} elseif ($plantId && $lineId && ! $shiftId) {
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else if ($plantId && !$lineId && $shiftId)
{
} elseif ($plantId && ! $lineId && $shiftId) {
return ProductionQuantity::where('plant_id', $plantId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
else// if ($plantId && $lineId && $shiftId)
{
} else { // if ($plantId && $lineId && $shiftId)
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
}
})
@@ -1212,44 +1189,50 @@ class ProductionQuantityResource extends Resource
return $query->whereRaw('1 = 0');
}
if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $plant);
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $shift);
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
$query->where('shift_id', $data['Shift']);
}
if ($line = $data['Line'] ?? null) {
$query->where('line_id', $line);
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
$query->where('line_id', $data['Line']);
}
if (!empty($data['production_order'])) {
$query->where('production_order', 'like', '%' . $data['production_order'] . '%');
if (! empty($data['production_order'])) {
$query->where('production_order', 'like', '%'.$data['production_order'].'%');
}
if (!empty($data['serial_number'])) {
$query->where('serial_number', 'like', '%' . $data['serial_number'] . '%');
if (! empty($data['serial_number'])) {
$query->where('serial_number', 'like', '%'.$data['serial_number'].'%');
}
if (!empty($data['Item'])) {
if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
if (!empty($data['sap_msg_status'])) {
if (! empty($data['sap_msg_status'])) {
$query->where('sap_msg_status', $data['sap_msg_status']);
}
if (!empty($data['operator_id'])) {
if (! empty($data['operator_id'])) {
$query->where('operator_id', $data['operator_id']);
}
if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $from);
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
$query->where('created_at', '>=', $data['created_from']);
}
if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $to);
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
$query->where('created_at', '<=', $data['created_to']);
}
// return $query;
@@ -1257,48 +1240,54 @@ class ProductionQuantityResource extends Resource
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Shift'])) {
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name');
if (! empty($data['Shift'])) {
$indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
}
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
}
if (!empty($data['production_order'])) {
$indicators[] = 'Production Order: ' . $data['production_order'];
if (! empty($data['production_order'])) {
$indicators[] = 'Production Order: '.$data['production_order'];
}
if (!empty($data['serial_number'])) {
$indicators[] = 'Serial Number: ' . $data['serial_number'];
if (! empty($data['serial_number'])) {
$indicators[] = 'Serial Number: '.$data['serial_number'];
}
if (!empty($data['Item'])) {
$indicators[] = 'Item Code: ' . Item::where('id', $data['Item'])->value('code');
if (! empty($data['Item'])) {
$indicators[] = 'Item Code: '.Item::where('id', $data['Item'])->value('code');
}
if (!empty($data['sap_msg_status'])) {
$indicators[] = 'SAP Message Status: ' . $data['sap_msg_status'];
if (! empty($data['sap_msg_status'])) {
$indicators[] = 'SAP Message Status: '.$data['sap_msg_status'];
}
if (!empty($data['operator_id'])) {
$indicators[] = 'Created By: ' . $data['operator_id'];
if (! empty($data['operator_id'])) {
$indicators[] = 'Created By: '.$data['operator_id'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
})
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -1311,7 +1300,7 @@ class ProductionQuantityResource extends Resource
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
ActionsFilamentExportBulkAction::make('export')
->defaultPageOrientation('landscape'),
->defaultPageOrientation('landscape'),
]),
])
->headerActions([
@@ -1319,16 +1308,16 @@ class ProductionQuantityResource extends Resource
->label('Import Production Quantities')
->color('warning')
->importer(ProductionQuantityImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import production quantities');
}),
// ->chunkSize(250),
// ->maxRows(100000),
// ->chunkSize(250),
// ->maxRows(100000),
ExportAction::make()
->label('Export Production Quantities')
->color('warning')
->exporter(ProductionQuantityExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export production quantities');
}),
]);
@@ -1370,7 +1359,6 @@ class ProductionQuantityResource extends Resource
return 'Production Reports';
}
// public function triggerChartUpdate(): void
// {
// if (session()->has('select_plant') && session()->has('select_line')) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -620,7 +620,17 @@ class StickerMasterResource extends Resource
->options(function (callable $get) {
$plantId = $get('Plant');
return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
if (! $plantId) {
return [];
}
return Item::whereHas('stickerMasters', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('code', 'id');
// return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
})
->searchable()
->reactive(),
@@ -649,19 +659,18 @@ class StickerMasterResource extends Resource
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (
empty($data['Plant']) &&
empty($data['item_id']) &&
empty($data['material_type']) &&
empty($data['panel_box_code']) &&
empty($data['created_from']) &&
empty($data['created_to'])
) {
if (empty($data['Plant']) && empty($data['item_id']) && empty($data['material_type']) && empty($data['panel_box_code']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (! empty($data['item_id'])) {
@@ -690,6 +699,12 @@ class StickerMasterResource extends Resource
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (! empty($data['item_id'])) {
@@ -878,9 +893,9 @@ class StickerMasterResource extends Resource
$disk->makeDirectory($directory, 0755, true);
}
// $fullPath = Storage::disk('local')->path($directory);
// $fullPath = Storage::disk('local')->path($directory);
// $directory = "uploads/PartValidation/{$plantCode}";
// $directory = "uploads/PartValidation/{$plantCode}";
// $disk = Storage::disk('local');
// if (! $disk->exists($directory)) {

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,10 @@ namespace App\Filament\Resources;
use App\Filament\Exports\WeightValidationExporter;
use App\Filament\Imports\WeightValidationImporter;
use App\Filament\Resources\WeightValidationResource\Pages;
use App\Filament\Resources\WeightValidationResource\RelationManagers;
use App\Models\Item;
use App\Models\Line;
use App\Models\Plant;
use App\Models\QualityValidation;
use App\Models\StickerMaster;
use App\Models\WeightValidation;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
@@ -26,14 +22,13 @@ use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;
use Str;
use Filament\Tables\Filters\Filter;
class WeightValidationResource extends Resource
{
@@ -51,6 +46,7 @@ class WeightValidationResource 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();
})
->required(),
@@ -80,7 +76,7 @@ class WeightValidationResource extends Resource
Forms\Components\TextInput::make('picked_weight')
->label('Picked Weight'),
Forms\Components\TextInput::make('scanned_by')
->label('Scanned By')
->label('Scanned By'),
]);
}
@@ -98,6 +94,7 @@ class WeightValidationResource 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')
@@ -157,9 +154,6 @@ class WeightValidationResource extends Resource
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
// ->filters([
// Tables\Filters\TrashedFilter::make(),
// ])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
@@ -173,25 +167,41 @@ 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();
})
->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('sticker_master_id', null);
// $set('sap_msg_status', null);
// }),
Select::make('Item Code')
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $set('sticker_master_id', null);
// $set('sap_msg_status', null);
// }),
Select::make('Item Code')
->label('Search by Item Code')
->nullable()
// ->options(function (callable $get) {
// $plantId = $get('Plant');
// if (! $plantId) {
// return [];
// }
// return Item::where('plant_id', $plantId)->pluck('code', 'id');
// })
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
return Item::where('plant_id', $plantId)->pluck('code', 'id');
return Item::whereHas('weightValidations', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('code', 'id');
})
->searchable()
->reactive(),
TextInput::make('Obd Number')
->label('OBD Number')
->placeholder('Enter OBD Number'),
@@ -201,7 +211,7 @@ class WeightValidationResource extends Resource
->options(function (callable $get) {
$plantId = $get('Plant');
if (!$plantId) {
if (! $plantId) {
return [];
}
@@ -243,125 +253,137 @@ class WeightValidationResource extends Resource
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
//Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Item Code']) && empty($data['Line']) && empty($data['Obd Number']) && empty($data['Batch']) && empty($data['Actual Weight']) && empty($data['Vehicle Number']) && empty($data['Heat Number']) && empty($data['Bundle Number']) && empty($data['Scanned By']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Item Code']) && empty($data['Line']) && empty($data['Obd Number']) && empty($data['Batch']) && empty($data['Actual Weight']) && empty($data['Vehicle Number']) && empty($data['Heat Number']) && empty($data['Bundle Number']) && empty($data['Scanned By']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
if (!empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
}
if (! empty($data['Plant'])) {
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Item Code'])) {
$query->where('item_id', $data['Item Code']);
}
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (!empty($data['Line'])) {
$query->where('line_number', $data['Line']);
}
if (! empty($data['Item Code'])) {
$query->where('item_id', $data['Item Code']);
}
if (!empty($data['Obd Number'])) {
$query->where('obd_number', $data['Obd Number']);
}
if (! empty($data['Line'])) {
$query->where('line_number', $data['Line']);
}
if (!empty($data['Batch'])) {
$query->where('batch_number', $data['Batch']);
}
if (! empty($data['Obd Number'])) {
$query->where('obd_number', $data['Obd Number']);
}
if (!empty($data['Actual Weight'])) {
$query->where('actual_weight', $data['Actual Weight']);
}
if (! empty($data['Batch'])) {
$query->where('batch_number', $data['Batch']);
}
if (!empty($data['Vehicle Number'])) {
$query->where('vehicle_number',$data['Vehicle Number']);
}
if (! empty($data['Actual Weight'])) {
$query->where('actual_weight', $data['Actual Weight']);
}
if (!empty($data['Heat Number'])) {
$query->where('heat_number',$data['Heat Number']);
}
if (! empty($data['Vehicle Number'])) {
$query->where('vehicle_number', $data['Vehicle Number']);
}
if (!empty($data['Bundle Number'])) {
$query->where('bundle_number',$data['Bundle Number']);
}
if (! empty($data['Heat Number'])) {
$query->where('heat_number', $data['Heat Number']);
}
if (!empty($data['Scanned By'])) {
$query->where('scanned_by', $data['Scanned By']);
}
if (! empty($data['Bundle Number'])) {
$query->where('bundle_number', $data['Bundle Number']);
}
if (! empty($data['Scanned By'])) {
$query->where('scanned_by', $data['Scanned By']);
}
if (!empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (!empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (!empty($data['Plant'])) {
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
}
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if (!empty($data['Item Code'])) {
$indicators[] = 'Item Code: ' . $data['Item Code'];
}
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (!empty($data['Line'])) {
$indicators[] = 'Line: ' . $data['Line'];
}
if (! empty($data['Item Code'])) {
$indicators[] = 'Item Code: '.Item::where('id', $data['Item Code'])->value('code');
}
if (!empty($data['Obd Number'])) {
$indicators[] = 'OBD Number: ' . $data['Obd Number'];
}
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.$data['Line'];
}
if (!empty($data['Batch'])) {
$indicators[] = 'Batch Number: ' . $data['Batch'];
}
if (! empty($data['Obd Number'])) {
$indicators[] = 'OBD Number: '.$data['Obd Number'];
}
if (!empty($data['Actual Weight'])) {
$indicators[] = 'Actual Weight: ' . $data['Actual Weight'];
}
if (! empty($data['Batch'])) {
$indicators[] = 'Batch Number: '.$data['Batch'];
}
if (!empty($data['Vehicle Number'])) {
$indicators[] = 'Vehicle Number: ' . $data['Vehicle Number'];
}
if (! empty($data['Actual Weight'])) {
$indicators[] = 'Actual Weight: '.$data['Actual Weight'];
}
if (!empty($data['Heat Number'])) {
$indicators[] = 'Heat Number: ' . $data['Heat Number'];
}
if (! empty($data['Vehicle Number'])) {
$indicators[] = 'Vehicle Number: '.$data['Vehicle Number'];
}
if (!empty($data['Bundle Number'])) {
$indicators[] = 'Bundle Number: ' . $data['Bundle Number'];
}
if (! empty($data['Heat Number'])) {
$indicators[] = 'Heat Number: '.$data['Heat Number'];
}
if (!empty($data['Scanned By'])) {
$indicators[] = 'Scanned By: ' . $data['Scanned By'];
}
if (! empty($data['Bundle Number'])) {
$indicators[] = 'Bundle Number: '.$data['Bundle Number'];
}
if (!empty($data['created_from'])) {
$indicators[] = 'From: ' . $data['created_from'];
}
if (! empty($data['Scanned By'])) {
$indicators[] = 'Scanned By: '.$data['Scanned By'];
}
if (!empty($data['created_to'])) {
$indicators[] = 'To: ' . $data['created_to'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (!empty($data['sticker_master_id'])) {
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: ' . $itemCode;
}
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
})
if (! empty($data['sticker_master_id'])) {
$itemCode = Item::find($data['sticker_master_id'])->code ?? 'Unknown';
$indicators[] = 'Item Codes: '.$itemCode;
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->actions([
@@ -383,6 +405,7 @@ class WeightValidationResource extends Resource
// ->options(Plant::pluck('name', 'id')->toArray())
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->label('Select Plant')
@@ -401,8 +424,8 @@ class WeightValidationResource extends Resource
->storeFiles(false) // prevent auto-storing, we will store manually
->reactive()
->required()
->disk('local') //'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app.
->visible(fn (Get $get) => !empty($get('plant_id')))
->disk('local') // 'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app.
->visible(fn (Get $get) => ! empty($get('plant_id')))
->directory('uploads/temp'),
])
->action(function (array $data) {
@@ -425,20 +448,20 @@ class WeightValidationResource extends Resource
// /home/iot-dev/projects/pds/storage/app/private/uploads/temp/3RA0018735.xlsx
$totQuan = WeightValidation::where('obd_number',$originalNameOnly)->where('plant_id', $plantId)->count();
$scanSQuan = WeightValidation::where('obd_number',$originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
$totQuan = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scanSQuan = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if($totQuan == $scanSQuan && $totQuan > 0) {
if ($totQuan == $scanSQuan && $totQuan > 0) {
Notification::make()
->title('Completed: OBD invoice')
->body('OBD invoice already completed the scanning process for selected plant.')
->danger()
->send();
if ($disk->exists($path))
{
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
@@ -458,7 +481,7 @@ class WeightValidationResource extends Resource
if ($fullPath && file_exists($fullPath)) {
$rows = Excel::toArray(null, $fullPath)[0];
if((count($rows) - 1) <= 0) {
if ((count($rows) - 1) <= 0) {
Notification::make()
->title('Records Not Found')
->body("Import the valid 'OBD Invoice' file to proceed..!")
@@ -469,6 +492,7 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
@@ -482,9 +506,10 @@ class WeightValidationResource extends Resource
$lineNumbers = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
foreach ($rows as $index => $row) {
if ($index === 0) {
continue;
} // Skip header
$materialCode = trim($row[0]);
$lineNumber = trim($row[1]);
@@ -496,32 +521,24 @@ class WeightValidationResource extends Resource
continue;
}
if (!empty($materialCode)) {
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
{
if (! empty($materialCode)) {
if (Str::length($materialCode) < 6 || ! ctype_alnum($materialCode)) {
$invalidMatCodes[] = $materialCode;
continue;
}
else
{
} else {
$materialCodes[] = $materialCode;
$validData = true;
if(Str::length($lineNumber) < 1 || !is_numeric($lineNumber))
{
if (Str::length($lineNumber) < 1 || ! is_numeric($lineNumber)) {
$validData = false;
$invalidLines[] = $materialCode;
}
else if (in_array($lineNumber, $lineNumbers))
{
} elseif (in_array($lineNumber, $lineNumbers)) {
$duplicateLines[] = $materialCode;
}
else
{
} else {
$lineNumbers[] = $lineNumber;
}
if(Str::length($batchNumber) < 8 || !is_numeric($batchNumber))//ctype_alnum
{
if (Str::length($batchNumber) < 8 || ! is_numeric($batchNumber)) {// ctype_alnum
$validData = false;
$invalidBatch[] = $materialCode;
}
@@ -530,29 +547,25 @@ class WeightValidationResource extends Resource
// $validData = false;
// $invalidHeat[] = $materialCode;
// }
if(Str::length($actualWeight) < 1 || !is_numeric($actualWeight))//ctype_alnum
{
if (Str::length($actualWeight) < 1 || ! is_numeric($actualWeight)) {// ctype_alnum
$validData = false;
$invalidWeight[] = $materialCode;
}
if ($validData)
{
if ($validData) {
$validRowsFound = true;
}
}
}
else
{
} else {
continue;
}
}
$uniqueInvalidCodes = array_unique($invalidMatCodes);
if (!empty($uniqueInvalidCodes)) {
if (! empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>'.implode(', ', $uniqueInvalidCodes))
->danger()
->seconds(2)
->send();
@@ -560,51 +573,55 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidLines = array_unique($invalidLines);
if (!empty($uniqueInvalidLines)) {
if (! empty($uniqueInvalidLines)) {
Notification::make()
->title('Invalid: Line Numbers')
->body('Line number should contain minimum 1 digit numeric values!<br>Following item codes has invalid line number:<br>' . implode(', ', $uniqueInvalidLines))
->danger()
->seconds(2)
->send();
->title('Invalid: Line Numbers')
->body('Line number should contain minimum 1 digit numeric values!<br>Following item codes has invalid line number:<br>'.implode(', ', $uniqueInvalidLines))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueDupLines = array_unique($duplicateLines);
if (!empty($uniqueDupLines)) {
if (! empty($uniqueDupLines)) {
Notification::make()
->title('Duplicate: Line Numbers')
->body('The following item codes contains duplicate line numbers in invoice excel:<br>' . implode(', ', $uniqueDupLines))
->danger()
->seconds(2)
->send();
->title('Duplicate: Line Numbers')
->body('The following item codes contains duplicate line numbers in invoice excel:<br>'.implode(', ', $uniqueDupLines))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidBatch = array_unique($invalidBatch);
if (!empty($uniqueInvalidBatch)) {
if (! empty($uniqueInvalidBatch)) {
Notification::make()
->title('Invalid: Batch Numbers')
->body('Batch number should contain minimum 8 digit numeric values!<br>Following item codes has invalid batch number:<br>' . implode(', ', $uniqueInvalidBatch))
->danger()
->seconds(2)
->send();
->title('Invalid: Batch Numbers')
->body('Batch number should contain minimum 8 digit numeric values!<br>Following item codes has invalid batch number:<br>'.implode(', ', $uniqueInvalidBatch))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
@@ -624,23 +641,24 @@ class WeightValidationResource extends Resource
// }
$uniqueInvalidWeight = array_unique($invalidWeight);
if (!empty($uniqueInvalidWeight)) {
if (! empty($uniqueInvalidWeight)) {
Notification::make()
->title('Invalid: Actual Weights')
->body('Actual weight should contain minimum 1 digit numeric value!<br>Following item codes has invalid actual weight:<br>' . implode(', ', $uniqueInvalidWeight))
->danger()
->seconds(2)
->send();
->title('Invalid: Actual Weights')
->body('Actual weight should contain minimum 1 digit numeric value!<br>Following item codes has invalid actual weight:<br>'.implode(', ', $uniqueInvalidWeight))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueCodes = array_unique($materialCodes);
//itemNotFound.
// itemNotFound.
$matchedItems = Item::whereIn('code', $uniqueCodes)->get();
// // Get all codes that exist in the database for the given plant_id
@@ -653,37 +671,13 @@ class WeightValidationResource extends Resource
// ->pluck('item.code')
// ->toArray();
$matchedCodes = $matchedItems->pluck('code')->toArray(); //item.code
$matchedCodes = $matchedItems->pluck('code')->toArray(); // item.code
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes)) {
if (! empty($missingCodes)) {
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
//plantNotFound
$matchedItems = Item::whereIn('code', $uniqueCodes)->where('plant_id', $plantId)->get();
$matchedCodes = $matchedItems->pluck('code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes)) {
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>' . implode(', ', $missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>'.implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
@@ -695,10 +689,36 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (!$validRowsFound) {
// plantNotFound
$matchedItems = Item::whereIn('code', $uniqueCodes)->where('plant_id', $plantId)->get();
$matchedCodes = $matchedItems->pluck('code')->toArray();
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (! empty($missingCodes)) {
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database for choosed plant." : 'The following item codes are not found in database for choosed plant:<br>'.implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
if (! $validRowsFound) {
Notification::make()
->title('Invalid OBD Invoice')
->danger() // This makes the notification red to indicate an error
@@ -709,30 +729,32 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$updateInv = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->first()?->exists();
$availLines = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function($query) {
$availLines = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function ($query) {
$query->whereNull('vehicle_number')->orWhere('vehicle_number', '');
})->pluck('line_number')->toArray();
$updated = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function($query) {
$updated = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function ($query) {
$query->whereNull('vehicle_number')->orWhere('vehicle_number', '');
})->count();
WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function($query) {
WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where(function ($query) {
$query->whereNull('vehicle_number')->orWhere('vehicle_number', '');
})
->forceDelete();
->forceDelete();
$inserted = 0;
// $updated = 0;
foreach ($rows as $index => $row)
{
foreach ($rows as $index => $row) {
// Skip header
if ($index === 0) { continue; }
if ($index === 0) {
continue;
}
$materialCode = trim($row[0]);
$lineNumber = trim($row[1]);
@@ -744,31 +766,27 @@ class WeightValidationResource extends Resource
continue;
}
if (!empty($materialCode)) {
if (! empty($materialCode)) {
$recordExist = WeightValidation::where('plant_id', $plantId)->where('obd_number', $originalNameOnly)->where('line_number', $lineNumber)->first();
$masItem = Item::where('plant_id', $plantId)->where('code', $materialCode)->first();
if($recordExist) {
if ($recordExist) {
$skipUpd = $recordExist->vehicle_number ?? null;
if($skipUpd)
{
if ($skipUpd) {
continue;
}
else
{
} else {
if ($masItem) {
$recordExist->update([
'item_id' => $masItem->id,
'batch_number' => $batchNumber,
//'heat_number' => $heatNumber,
// 'heat_number' => $heatNumber,
'obd_weight' => $actualWeight,
'updated_at' => now(),
]);
$updated++;
}
}
}
else {
} else {
if ($masItem) {
WeightValidation::create([
'item_id' => $masItem->id,
@@ -776,15 +794,12 @@ class WeightValidationResource extends Resource
'obd_number' => $originalNameOnly,
'line_number' => $lineNumber,
'batch_number' => $batchNumber,
//'heat_number' => $heatNumber,
// 'heat_number' => $heatNumber,
'obd_weight' => $actualWeight,
]);
if (in_array($lineNumber, $availLines))
{
if (in_array($lineNumber, $availLines)) {
continue;
}
else
{
} else {
$inserted++;
}
}
@@ -792,10 +807,10 @@ class WeightValidationResource extends Resource
}
}
if($updateInv) {
if ($updateInv) {
if ($updated > 0) {
Notification::make()
->title("Start the scanning process!")
->title('Start the scanning process!')
->body("'$updated' OBD lines were updated and<br>'$inserted' OBD lines were inserted for<br>imported OBD Invoice : '$originalNameOnly'.")
->info()
// ->success()
@@ -806,24 +821,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity)
{
if ($totalQuantity === $scannedQuantity) {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
} else {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else if ($inserted > 0) {
} elseif ($inserted > 0) {
Notification::make()
->title("Start the scanning process!")
->title('Start the scanning process!')
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info()
// ->success()
@@ -834,24 +845,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity)
{
if ($totalQuantity === $scannedQuantity) {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
} else {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else {
} else {
Notification::make()
->title("Import Failed: OBD Invoice")
->title('Import Failed: OBD Invoice')
->body("No exist records were updated for imported OBD Invoice : '$originalNameOnly'.")
->danger()
->seconds(2)
@@ -863,14 +870,14 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return;
}
}
else {
} else {
if ($inserted > 0) {
Notification::make()
->title("Start the scanning process!")
->title('Start the scanning process!')
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info()
// ->success()
@@ -881,24 +888,20 @@ class WeightValidationResource extends Resource
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
if ($totalQuantity === $scannedQuantity)
{
if ($totalQuantity === $scannedQuantity) {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
} else {
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else {
} else {
Notification::make()
->title("Import Failed: OBD Invoice")
->title('Import Failed: OBD Invoice')
->body("No new records were inserted for imported OBD Invoice : '$originalNameOnly'.")
->danger()
->seconds(2)
@@ -910,27 +913,28 @@ class WeightValidationResource extends Resource
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return;
}
}
}
})
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import obd number validations');
}),
ImportAction::make()
->label('Import OBD Invoice')
->color('warning')
->importer(WeightValidationImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import weight validation');
}),
ExportAction::make()
->label('Export OBD Invoices')
->color('warning')
->exporter(WeightValidationExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export weight validation');
}),
]);

View File

@@ -3,15 +3,15 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Item extends Model
{
use SoftDeletes;
protected $fillable = [
"plant_id",
'plant_id',
'category',
'code',
'description',
@@ -43,4 +43,19 @@ class Item extends Model
{
return $this->hasMany(TestingPanelReading::class);
}
public function processOrders()
{
return $this->hasMany(ProcessOrder::class);
}
public function productCharacteristicsMasters()
{
return $this->hasMany(ProductCharacteristicsMaster::class);
}
public function weightValidations()
{
return $this->hasMany(WeightValidation::class);
}
}