5 Commits

Author SHA1 Message Date
dhanabalan
de6e38bc5f Added import and export permissions 2025-05-24 19:21:28 +05:30
dhanabalan
af5ede975b Policy file added 2025-05-24 19:20:17 +05:30
dhanabalan
7ea8231c90 Importer file added 2025-05-24 19:16:53 +05:30
dhanabalan
1bf5f0b31a Exporter file added 2025-05-24 19:16:10 +05:30
dhanabalan
9347dbf466 Updated report columns and filter func. and Added import obd invoice, import obd weight invoice, export obd weight invoice 2025-05-24 19:15:05 +05:30
5 changed files with 999 additions and 14 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Exports;
use App\Models\WeightValidation;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class WeightValidationExporter extends Exporter
{
protected static ?string $model = WeightValidation::class;
public static function getColumns(): array
{
static $rowNumber = 0;
return [
// ExportColumn::make('id')
// ->label('ID'),
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('item.code')
->label('ITEM CODE'),
ExportColumn::make('obd_number')
->label('OBD NUMBER'),
ExportColumn::make('line_number')
->label('LINE NUMBER'),
ExportColumn::make('batch_number')
->label('BATCH NUMBER'),
ExportColumn::make('heat_number')
->label('HEAT NUMBER'),
ExportColumn::make('obd_weight')
->label('ACTUAL WEIGHT'),
ExportColumn::make('vehicle_number')
->label('VEHICLE NUMBER'),
ExportColumn::make('bundle_number')
->label('BUNDLE NUMBER'),
ExportColumn::make('picked_weight')
->label('PICKED WEIGHT'),
ExportColumn::make('scanned_by')
->label('SCANNED BY'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
];
}
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.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}
return $body;
}
}

View File

@@ -0,0 +1,191 @@
<?php
namespace App\Filament\Imports;
use App\Models\Item;
use App\Models\Plant;
use App\Models\WeightValidation;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Str;
class WeightValidationImporter extends Importer
{
protected static ?string $model = WeightValidation::class;
public static function getColumns(): array
{
return [
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('Item Code')
->example('123456')
->label('ITEM CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('PLANT NAME')
->relationship(resolveUsing: 'name')
->rules(['required']),
ImportColumn::make('obd_number')
->requiredMapping()
->exampleHeader('OBD Number')
->example('3RA00352')
->label('OBD Number')
->rules(['required']),
ImportColumn::make('line_number')
->requiredMapping()
->exampleHeader('Line Number')
->example('1')
->label('Line Number')
->rules(['required']),
ImportColumn::make('batch_number')
->requiredMapping()
->exampleHeader('Batch Number')
->example('2021217')
->label('Batch Number')
->rules(['required']),
ImportColumn::make('heat_number')
->requiredMapping()
->exampleHeader('Heat Number')
->example('RSL-D1390')
->label('Heat Number')
->rules(['required']),
ImportColumn::make('obd_weight')
->requiredMapping()
->exampleHeader('Actual Weight')
->example('3540.00')
->label('Actual Weight')
->rules(['required']),
ImportColumn::make('vehicle_number')
->requiredMapping()
->exampleHeader('Vehicle Number')
->example('TN54AB1234')
->label('Vehicle Number')
->rules(['required']),
ImportColumn::make('bundle_number')
->requiredMapping()
->exampleHeader('Bundle Number')
->example('1')
->label('Bundle Number')
->rules(['required']),
ImportColumn::make('picked_weight')
->requiredMapping()
->exampleHeader('Picked Weight')
->example('1')
->label('Picked Weight')
->rules(['required']),
ImportColumn::make('scanned_by')
->requiredMapping()
->exampleHeader('Scanned By')
->example('User-1')
->label('Scanned By')
->rules(['required']),
];
}
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";
}
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";
}
$obdNum = $this->data['obd_number'];
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";
}
$batchNum = $this->data['batch_number'];
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";
}
$actWeight = $this->data['obd_weight'];
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";
}
$bundleNum = $this->data['bundle_number'];
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";
}
$scanBy = $this->data['scanned_by'];
if (Str::length($scanBy) < 3 || !ctype_alnum($scanBy)) {
$warnMsg[] = "Invalid scanned by name found";
}
if (!empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return WeightValidation::updateOrCreate([
'plant_id' => $plant->id,
'obd_number' => $obdNum,
'line_number' => $lineNum
],
[
'item_id' => $item->id,
'batch_number' => $batchNum,
'heat_number' => $heatNum,
'obd_weight' => $actWeight,
'vehicle_number' => $vehicleNum,
'bundle_number' => $bundleNum,
'picked_weight' => $pickWeight,
'scanned_by' => $scanBy
]
);
// return WeightValidation::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
// return new WeightValidation();
}
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.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
}
return $body;
}
}

View File

@@ -2,16 +2,32 @@
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\Plant;
use App\Models\WeightValidation;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
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 Filament\Tables\Actions\ImportAction;
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;
class WeightValidationResource extends Resource
{
@@ -63,26 +79,72 @@ class WeightValidationResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item.id')
->numeric()
->sortable(),
// Tables\Columns\TextColumn::make('id')
// ->label('ID')
// ->numeric()
// ->sortable(),
Tables\Columns\TextColumn::make('No.')
->label('No.')
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->label('Plant')
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->searchable(),
Tables\Columns\TextColumn::make('item.code')
->label('Item Code')
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('obd_number')
->label('OBD Number')
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('line_number')
->label('Line Number')
->alignCenter(),
Tables\Columns\TextColumn::make('batch_number')
->label('Batch Number')
->alignCenter(),
Tables\Columns\TextColumn::make('heat_number')
->label('Heat Number')
->alignCenter(),
Tables\Columns\TextColumn::make('obd_weight')
->label('Actual Weight')
->alignCenter(),
Tables\Columns\TextColumn::make('vehicle_number')
->label('Vehicle Number')
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('bundle_number')
->label('Bundle Number')
->alignCenter(),
Tables\Columns\TextColumn::make('picked_weight')
->label('Picked Weight')
->alignCenter(),
Tables\Columns\TextColumn::make('scanned_by')
->label('Scanned By')
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->label('Create At')
->dateTime()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime()
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
@@ -99,6 +161,561 @@ class WeightValidationResource extends Resource
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
Tables\Actions\Action::make('Import OBD Number')
->label('Import OBD Weight Invoice')
->form([
Select::make('plant_id')
->options(Plant::pluck('name', 'id')->toArray())
->label('Select Plant')
->required()
->default(function () {
return optional(WeightValidation::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('invoice_obd_number', null);
})
->reactive(),
FileUpload::make('invoice_obd_number')
->label('Import OBD Weight Invoice')
// ->required()
->preserveFilenames() // <- this keeps the original filename
->storeFiles(false) // prevent auto-storing, we will store manually
->reactive()
->required()
->disk('local') //'local' refers to the local storage disk defined in config/filesystems.php, typically pointing to storage/app.
->visible(fn (Get $get) => !empty($get('plant_id')))
->directory('uploads/temp'),
])
->action(function (array $data) {
$uploadedFile = $data['invoice_obd_number'];
$disk = Storage::disk('local');
$plantId = $data['plant_id'];
// Get original filename
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
// Store manually using storeAs to keep original name
$path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path
// uploads/temp/3RA0018735.xlsx
$fullPath = Storage::disk('local')->path($path);
// /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();
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))
{
$disk->delete($path);
}
return;
}
// if($totQuan > 0) {
// Notification::make()
// ->title('OBD invoice already exist in database for selected plant.')
// ->danger()
// ->send();
// if ($disk->exists($path))
// {
// $disk->delete($path);
// }
// return;
// }
if ($fullPath && file_exists($fullPath)) {
$rows = Excel::toArray(null, $fullPath)[0];
if((count($rows) - 1) <= 0) {
Notification::make()
->title('Records Not Found')
->body("Import the valid 'OBD Invoice' file to proceed..!")
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$invalidMatCodes = [];
$invalidLines = [];
$duplicateLines = [];
$invalidBatch = [];
$invalidHeat = [];
$invalidWeight = [];
$materialCodes = [];
$lineNumbers = [];
$validRowsFound = false;
foreach ($rows as $index => $row)
{
if ($index === 0) continue; // Skip header
$materialCode = trim($row[0]);
$lineNumber = trim($row[1]);
$batchNumber = trim($row[2]);
$heatNumber = trim($row[3]);
$actualWeight = trim($row[4]);
if (empty($materialCode)) {
continue;
}
if (!empty($materialCode)) {
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
{
$invalidMatCodes[] = $materialCode;
continue;
}
else
{
$materialCodes[] = $materialCode;
$validData = true;
if(Str::length($lineNumber) < 1 || !is_numeric($lineNumber))
{
$validData = false;
$invalidLines[] = $materialCode;
}
else if (in_array($lineNumber, $lineNumbers))
{
$duplicateLines[] = $materialCode;
}
else
{
$lineNumbers[] = $lineNumber;
}
if(Str::length($batchNumber) < 8 || !is_numeric($batchNumber))//ctype_alnum
{
$validData = false;
$invalidBatch[] = $materialCode;
}
if(Str::length($heatNumber) < 4)
{
$validData = false;
$invalidHeat[] = $materialCode;
}
if(Str::length($actualWeight) < 1 || !is_numeric($actualWeight))//ctype_alnum
{
$validData = false;
$invalidWeight[] = $materialCode;
}
if ($validData)
{
$validRowsFound = true;
}
}
}
else
{
continue;
}
}
$uniqueInvalidCodes = array_unique($invalidMatCodes);
if (!empty($uniqueInvalidCodes)) {
Notification::make()
->title('Invalid: Item Codes')
->body('The following item codes should contain minimum 6 digit alpha numeric values:<br>' . implode(', ', $uniqueInvalidCodes))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidLines = array_unique($invalidLines);
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();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueDupLines = array_unique($duplicateLines);
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();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidBatch = array_unique($invalidBatch);
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();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidHeat = array_unique($invalidHeat);
if (!empty($uniqueInvalidHeat)) {
Notification::make()
->title('Invalid: Heat Numbers')
->body('Heat number should contain minimum 4 characters!<br>Following item codes has invalid heat number:<br>' . implode(', ', $uniqueInvalidHeat))
->danger()
->seconds(2)
->send();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueInvalidWeight = array_unique($invalidWeight);
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();
if ($disk->exists($path)) {
$disk->delete($path);
}
return;
}
$uniqueCodes = array_unique($materialCodes);
//itemNotFound.
$matchedItems = Item::whereIn('code', $uniqueCodes)->get();
// // Get all codes that exist in the database for the given plant_id
// $existingCodes = StickerMaster::where('plant_id', $plantId)
// ->whereHas('item', function ($query) use ($uniqueCodes) {
// $query->whereIn('code', $uniqueCodes);
// })
// ->with('item') // Eager load for performance
// ->get()
// ->pluck('item.code')
// ->toArray();
$matchedCodes = $matchedItems->pluck('code')->toArray(); //item.code
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
if (!empty($missingCodes)) {
$missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>' . implode(', ', $missingCodes);
Notification::make()
->title('Unknown: Item Codes')
->body($message)
->danger()
->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);
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
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
->seconds(2)
->send();
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) {
$query->whereNull('vehicle_number')->orWhere('vehicle_number', '');
})->pluck('line_number')->toArray();
$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) {
$query->whereNull('vehicle_number')->orWhere('vehicle_number', '');
})
->forceDelete();
$inserted = 0;
// $updated = 0;
foreach ($rows as $index => $row)
{
// Skip header
if ($index === 0) { continue; }
$materialCode = trim($row[0]);
$lineNumber = trim($row[1]);
$batchNumber = trim($row[2]);
$heatNumber = trim($row[3]);
$actualWeight = trim($row[4]);
if (empty($materialCode) || Str::length($materialCode) < 6) {
continue;
}
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) {
$skipUpd = $recordExist->vehicle_number ?? null;
if($skipUpd)
{
continue;
}
else
{
if ($masItem) {
$recordExist->update([
'item_id' => $masItem->id,
'batch_number' => $batchNumber,
'heat_number' => $heatNumber,
'obd_weight' => $actualWeight,
'updated_at' => now(),
]);
$updated++;
}
}
}
else {
if ($masItem) {
WeightValidation::create([
'item_id' => $masItem->id,
'plant_id' => $plantId,
'obd_number' => $originalNameOnly,
'line_number' => $lineNumber,
'batch_number' => $batchNumber,
'heat_number' => $heatNumber,
'obd_weight' => $actualWeight,
]);
if (in_array($lineNumber, $availLines))
{
continue;
}
else
{
$inserted++;
}
}
}
}
}
if($updateInv) {
if ($updated > 0) {
Notification::make()
->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()
->seconds(1)
->send();
// Update total quantity in the form
$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 ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else if ($inserted > 0) {
Notification::make()
->title("Start the scanning process!")
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info()
// ->success()
->seconds(1)
->send();
// Update total quantity in the form
$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 ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else {
Notification::make()
->title("Import Failed: OBD Invoice")
->body("No exist records were updated for imported OBD Invoice : '$originalNameOnly'.")
->danger()
->seconds(2)
->send();
$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 ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return;
}
}
else {
if ($inserted > 0) {
Notification::make()
->title("Start the scanning process!")
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
->info()
// ->success()
->seconds(1)
->send();
// Update total quantity in the form
$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 ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
else
{
if ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
}
}
else {
Notification::make()
->title("Import Failed: OBD Invoice")
->body("No new records were inserted for imported OBD Invoice : '$originalNameOnly'.")
->danger()
->seconds(2)
->send();
$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 ($disk->exists($path)) {
$disk->delete($path);
}
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
return;
}
}
}
})
->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() {
return Filament::auth()->user()->can('view import weight validation');
}),
ExportAction::make()
->label('Export OBD Invoices')
->color('warning')
->exporter(WeightValidationExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export weight validation');
}),
]);
}

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\WeightValidation;
use App\Models\User;
class WeightValidationPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any WeightValidation');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('view WeightValidation');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create WeightValidation');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('update WeightValidation');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('delete WeightValidation');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any WeightValidation');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('restore WeightValidation');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any WeightValidation');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('replicate WeightValidation');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder WeightValidation');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, WeightValidation $weightvalidation): bool
{
return $user->checkPermissionTo('force-delete WeightValidation');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any WeightValidation');
}
}

View File

@@ -52,6 +52,8 @@ class PermissionSeeder extends Seeder
Permission::updateOrCreate(['name' => 'view export production plan']);
Permission::updateOrCreate(['name' => 'view import quality validation']);
Permission::updateOrCreate(['name' => 'view export quality validation']);
Permission::updateOrCreate(['name' => 'view import obd weight validation']);
Permission::updateOrCreate(['name' => 'view import weight validation']);
Permission::updateOrCreate(['name' => 'view export weight validation']);
}
}