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
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
This commit is contained in:
@@ -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: '.$data['Item 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');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user