Added view rights against plant on view report and Updated alignments and load available item code logic on resource
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,6 +167,7 @@ class WeightValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
@@ -180,18 +175,33 @@ class WeightValidationResource extends Resource
|
||||
// $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) {
|
||||
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'),
|
||||
@@ -243,6 +253,7 @@ class WeightValidationResource extends Resource
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
@@ -257,6 +268,12 @@ class WeightValidationResource extends Resource
|
||||
|
||||
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 Code'])) {
|
||||
@@ -295,7 +312,6 @@ class WeightValidationResource extends Resource
|
||||
$query->where('scanned_by', $data['Scanned By']);
|
||||
}
|
||||
|
||||
|
||||
if (! empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
@@ -309,6 +325,12 @@ class WeightValidationResource 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 Code'])) {
|
||||
@@ -361,7 +383,7 @@ class WeightValidationResource extends Resource
|
||||
}
|
||||
|
||||
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')
|
||||
@@ -435,10 +458,10 @@ class WeightValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
@@ -497,31 +522,23 @@ class WeightValidationResource extends Resource
|
||||
}
|
||||
|
||||
if (! empty($materialCode)) {
|
||||
if(Str::length($materialCode) < 6 || !ctype_alnum($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,20 +547,16 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -560,6 +573,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -575,6 +589,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -590,6 +605,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -605,6 +621,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -635,6 +652,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -671,6 +689,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -695,6 +714,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -709,6 +729,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -729,10 +750,11 @@ class WeightValidationResource extends Resource
|
||||
|
||||
$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]);
|
||||
@@ -750,12 +772,9 @@ class WeightValidationResource extends Resource
|
||||
$masItem = Item::where('plant_id', $plantId)->where('code', $materialCode)->first();
|
||||
if ($recordExist) {
|
||||
$skipUpd = $recordExist->vehicle_number ?? null;
|
||||
if($skipUpd)
|
||||
{
|
||||
if ($skipUpd) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($masItem) {
|
||||
$recordExist->update([
|
||||
'item_id' => $masItem->id,
|
||||
@@ -767,8 +786,7 @@ class WeightValidationResource extends Resource
|
||||
$updated++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($masItem) {
|
||||
WeightValidation::create([
|
||||
'item_id' => $masItem->id,
|
||||
@@ -779,12 +797,9 @@ class WeightValidationResource extends Resource
|
||||
// 'heat_number' => $heatNumber,
|
||||
'obd_weight' => $actualWeight,
|
||||
]);
|
||||
if (in_array($lineNumber, $availLines))
|
||||
{
|
||||
if (in_array($lineNumber, $availLines)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$inserted++;
|
||||
}
|
||||
}
|
||||
@@ -795,7 +810,7 @@ class WeightValidationResource extends Resource
|
||||
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,6 +913,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user