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
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
use App\Exports\MotorFreeRunExport;
|
||||||
use App\Exports\TestingPanelReadingExport;
|
|
||||||
use App\Filament\Exports\TestingPanelReadingExporter;
|
use App\Filament\Exports\TestingPanelReadingExporter;
|
||||||
use App\Filament\Imports\TestingPanelReadingImporter;
|
use App\Filament\Imports\TestingPanelReadingImporter;
|
||||||
use App\Filament\Resources\TestingPanelReadingResource\Pages;
|
use App\Filament\Resources\TestingPanelReadingResource\Pages;
|
||||||
@@ -23,19 +22,24 @@ use Filament\Forms\Components\Select;
|
|||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
use Filament\Notifications\Collection as NotificationsCollection;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Actions\Action;
|
||||||
use Filament\Tables\Actions\BulkAction;
|
use Filament\Tables\Actions\BulkAction;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
|
||||||
use Filament\Tables\Actions\ExportAction;
|
|
||||||
use Filament\Tables\Filters\Filter;
|
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
|
||||||
use Filament\Tables\Actions\Action;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Response;
|
||||||
|
// use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
// use App\Exports\TestingPanelReadingExport;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory; // For loading Excel file
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
class TestingPanelReadingResource extends Resource
|
class TestingPanelReadingResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -58,23 +62,23 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(TestingPanelReading::latest()->first())->plant_id;
|
return optional(TestingPanelReading::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) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
$set('tPrError', 'Please select a plant first.');
|
$set('tPrError', 'Please select a plant first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
@@ -91,9 +95,10 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->relationship('line', 'name')
|
->relationship('line', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Line::where('plant_id', $plantId)
|
return Line::where('plant_id', $plantId)
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
@@ -101,7 +106,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(TestingPanelReading::latest()->first())->line_id;
|
return optional(TestingPanelReading::latest()->first())->line_id;
|
||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
|
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
|
||||||
@@ -110,9 +115,10 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->relationship('machine', 'name')
|
->relationship('machine', 'name')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
if (!$lineId) {
|
if (! $lineId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show machines for the selected line
|
// Only show machines for the selected line
|
||||||
return Machine::where('line_id', $lineId)
|
return Machine::where('line_id', $lineId)
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
@@ -121,12 +127,12 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(TestingPanelReading::latest()->first())->machine_id;
|
return optional(TestingPanelReading::latest()->first())->machine_id;
|
||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => !empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->required()
|
->required()
|
||||||
->reactive(),
|
->reactive(),
|
||||||
Forms\Components\Select::make('motor_testing_master_id')
|
Forms\Components\Select::make('motor_testing_master_id')
|
||||||
->label('Item Code')
|
->label('Item Code')
|
||||||
//->relationship('motorTestingMaster', 'item.code')
|
// ->relationship('motorTestingMaster', 'item.code')
|
||||||
// ->options(function (callable $get) {
|
// ->options(function (callable $get) {
|
||||||
// $plantId = $get('plant_id');
|
// $plantId = $get('plant_id');
|
||||||
// if (!$plantId) {
|
// if (!$plantId) {
|
||||||
@@ -141,9 +147,10 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// })
|
// })
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (! $plantId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return MotorTestingMaster::query()
|
return MotorTestingMaster::query()
|
||||||
->join('items', 'motor_testing_masters.item_id', '=', 'items.id')
|
->join('items', 'motor_testing_masters.item_id', '=', 'items.id')
|
||||||
->where('motor_testing_masters.plant_id', $plantId)
|
->where('motor_testing_masters.plant_id', $plantId)
|
||||||
@@ -259,6 +266,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
|
|
||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
{
|
{
|
||||||
|
|
||||||
return $table
|
return $table
|
||||||
->columns([
|
->columns([
|
||||||
// Tables\Columns\TextColumn::make('id')
|
// Tables\Columns\TextColumn::make('id')
|
||||||
@@ -271,6 +279,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
$paginator = $livewire->getTableRecords();
|
$paginator = $livewire->getTableRecords();
|
||||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
}),
|
}),
|
||||||
Tables\Columns\TextColumn::make('plant.name')
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
@@ -463,7 +472,6 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
|
|
||||||
Tables\Filters\TrashedFilter::make(),
|
Tables\Filters\TrashedFilter::make(),
|
||||||
Filter::make('advanced_filters')
|
Filter::make('advanced_filters')
|
||||||
->label('Advanced Filters')
|
->label('Advanced Filters')
|
||||||
@@ -485,8 +493,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->nullable()
|
->nullable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
if (!$plantId)
|
if (! $plantId) {
|
||||||
{
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,14 +516,12 @@ class TestingPanelReadingResource extends Resource
|
|||||||
->whereHas('motorTestingMasters')
|
->whereHas('motorTestingMasters')
|
||||||
->pluck('code', 'id')
|
->pluck('code', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Item::whereHas('motorTestingMasters')
|
return Item::whereHas('motorTestingMasters')
|
||||||
->pluck('code', 'id')
|
->pluck('code', 'id')
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
//return [];
|
// return [];
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
Select::make('machine_name')
|
Select::make('machine_name')
|
||||||
@@ -525,9 +530,10 @@ class TestingPanelReadingResource extends Resource
|
|||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
$lineId = $get('Line');
|
$lineId = $get('Line');
|
||||||
|
|
||||||
if (!$plantId || !$lineId) {
|
if (! $plantId || ! $lineId) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Machine::where('plant_id', $plantId)
|
return Machine::where('plant_id', $plantId)
|
||||||
->where('line_id', $lineId)
|
->where('line_id', $lineId)
|
||||||
->pluck('name', 'id')
|
->pluck('name', 'id')
|
||||||
@@ -548,6 +554,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
if ($plantId) {
|
if ($plantId) {
|
||||||
$query->where('plant_id', $plantId);
|
$query->where('plant_id', $plantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->pluck('description', 'description')->toArray();
|
return $query->pluck('description', 'description')->toArray();
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -595,23 +602,20 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// ->reactive(),
|
// ->reactive(),
|
||||||
//...
|
// ...
|
||||||
Select::make('connection')
|
Select::make('connection')
|
||||||
->label('Connection')
|
->label('Connection')
|
||||||
->required()
|
->required()
|
||||||
->default('Star')
|
->default('Star')
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
if ($plantId)
|
if ($plantId) {
|
||||||
{
|
|
||||||
return Configuration::where('plant_id', $plantId)
|
return Configuration::where('plant_id', $plantId)
|
||||||
->where('c_name', 'MOTOR_CONNECTION')
|
->where('c_name', 'MOTOR_CONNECTION')
|
||||||
->orderBy('created_at')
|
->orderBy('created_at')
|
||||||
->pluck('c_value', 'c_value')
|
->pluck('c_value', 'c_value')
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
||||||
->orderBy('created_at')
|
->orderBy('created_at')
|
||||||
->pluck('c_value', 'c_value')
|
->pluck('c_value', 'c_value')
|
||||||
@@ -620,7 +624,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
})
|
})
|
||||||
->selectablePlaceholder(false)
|
->selectablePlaceholder(false)
|
||||||
->reactive(),
|
->reactive(),
|
||||||
//..
|
// ..
|
||||||
TextInput::make('remark')
|
TextInput::make('remark')
|
||||||
->label('Remark')
|
->label('Remark')
|
||||||
->reactive(),
|
->reactive(),
|
||||||
@@ -657,7 +661,7 @@ class TestingPanelReadingResource extends Resource
|
|||||||
|
|
||||||
// dd($data);
|
// dd($data);
|
||||||
// Hide all records initially if no filters are applied
|
// Hide all records initially if no filters are applied
|
||||||
if (empty($data['Plant']) && empty($data['Line']) && empty($data['item_code']) && empty($data['machine_name']) && empty($data['item_description']) && empty($data['serial_number']) && empty($data['output']) && empty($data['phase']) && empty($data['connection']) && empty($data['remark']) && empty($data['batch_no'])&& empty($data['result']) && empty($data['created_from']) && empty($data['created_to'])) {
|
if (empty($data['Plant']) && empty($data['Line']) && empty($data['item_code']) && empty($data['machine_name']) && empty($data['item_description']) && empty($data['serial_number']) && empty($data['output']) && empty($data['phase']) && empty($data['connection']) && empty($data['remark']) && empty($data['batch_no']) && empty($data['result']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||||
return $query->whereRaw('1 = 0');
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,30 +669,36 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// return $query->whereRaw('1 = 0');
|
// return $query->whereRaw('1 = 0');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!empty($data['Plant'])) {
|
if (! empty($data['Plant'])) {
|
||||||
$query->where('plant_id', $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['Line'])) {
|
if (! empty($data['Line'])) {
|
||||||
$query->where('line_id', $data['Line']);
|
$query->where('line_id', $data['Line']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['item_code'])) {
|
if (! empty($data['item_code'])) {
|
||||||
// $query->where('item_id', $data['item_code']);
|
// $query->where('item_id', $data['item_code']);
|
||||||
$query->whereHas('motorTestingMaster', function ($subQuery) use ($data) {
|
$query->whereHas('motorTestingMaster', function ($subQuery) use ($data) {
|
||||||
$subQuery->where('item_id', $data['item_code']);
|
$subQuery->where('item_id', $data['item_code']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['machine_name'])) {
|
if (! empty($data['machine_name'])) {
|
||||||
$query->where('machine_id', $data['machine_name']);
|
$query->where('machine_id', $data['machine_name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['serial_number'])) {
|
if (! empty($data['serial_number'])) {
|
||||||
$query->where('serial_number', $data['serial_number']);
|
$query->where('serial_number', $data['serial_number']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['item_description'])) {
|
if (! empty($data['item_description'])) {
|
||||||
$item = Item::where('description', $data['item_description'])->first();
|
$item = Item::where('description', $data['item_description'])->first();
|
||||||
|
|
||||||
if ($item) {
|
if ($item) {
|
||||||
@@ -700,9 +710,8 @@ class TestingPanelReadingResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['output']))
|
if (! empty($data['output'])) {
|
||||||
{
|
$query->where('output', $data['output']);
|
||||||
$query->where('output',$data['output']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!empty($data['phase']))
|
// if (!empty($data['phase']))
|
||||||
@@ -713,60 +722,59 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!empty($data['connection']))
|
if (! empty($data['connection'])) {
|
||||||
{
|
// $query->where('connection',$data['connection']);
|
||||||
//$query->where('connection',$data['connection']);
|
|
||||||
$query->whereHas('motorTestingMaster', function ($subQuery) use ($data) {
|
$query->whereHas('motorTestingMaster', function ($subQuery) use ($data) {
|
||||||
$subQuery->where('connection', $data['connection']);
|
$subQuery->where('connection', $data['connection']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['remark']))
|
if (! empty($data['remark'])) {
|
||||||
{
|
$query->where('remark', $data['remark']);
|
||||||
$query->where('remark',$data['remark']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['batch_number']))
|
if (! empty($data['batch_number'])) {
|
||||||
{
|
$query->where('batch_number', $data['batch_number']);
|
||||||
$query->where('batch_number',$data['batch_number']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['result']))
|
if (! empty($data['result'])) {
|
||||||
{
|
|
||||||
$query->where('result', $data['result']);
|
$query->where('result', $data['result']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_from'])) {
|
||||||
if (!empty($data['created_from']))
|
|
||||||
{
|
|
||||||
$query->where('created_at', '>=', $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']);
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->indicateUsing(function (array $data) {
|
->indicateUsing(function (array $data) {
|
||||||
$indicators = [];
|
$indicators = [];
|
||||||
|
|
||||||
if (!empty($data['Plant'])) {
|
if (! empty($data['Plant'])) {
|
||||||
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
$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['Line'])) {
|
|
||||||
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
|
|
||||||
}
|
}
|
||||||
if (!empty($data['item_code'])) {
|
if (! empty($data['Line'])) {
|
||||||
$indicators[] = 'Item Code: ' . Item::where('id', $data['item_code'])->value('code');
|
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
|
||||||
}
|
}
|
||||||
if (!empty($data['machine_name'])) {
|
if (! empty($data['item_code'])) {
|
||||||
$indicators[] = 'Machine: ' . Machine::where('id', $data['machine_name'])->value('name');
|
$indicators[] = 'Item Code: '.Item::where('id', $data['item_code'])->value('code');
|
||||||
}
|
}
|
||||||
if (!empty($data['output'])) {
|
if (! empty($data['machine_name'])) {
|
||||||
$indicators[] = 'Output: ' . $data['output'];
|
$indicators[] = 'Machine: '.Machine::where('id', $data['machine_name'])->value('name');
|
||||||
}
|
}
|
||||||
if (!empty($data['item_description'])) {
|
if (! empty($data['output'])) {
|
||||||
$indicators[] = 'Model: ' . $data['item_description'];
|
$indicators[] = 'Output: '.$data['output'];
|
||||||
|
}
|
||||||
|
if (! empty($data['item_description'])) {
|
||||||
|
$indicators[] = 'Model: '.$data['item_description'];
|
||||||
}
|
}
|
||||||
// if (!empty($data['phase'])) {
|
// if (!empty($data['phase'])) {
|
||||||
// $indicators[] = 'Phase: ' . $data['phase'];
|
// $indicators[] = 'Phase: ' . $data['phase'];
|
||||||
@@ -774,31 +782,30 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// if (!empty($data['connection'])) {
|
// if (!empty($data['connection'])) {
|
||||||
// $indicators[] = 'Connection: ' . $data['connection'];
|
// $indicators[] = 'Connection: ' . $data['connection'];
|
||||||
// }
|
// }
|
||||||
if (!empty($data['remark'])) {
|
if (! empty($data['remark'])) {
|
||||||
$indicators[] = 'Remark: ' . $data['remark'];
|
$indicators[] = 'Remark: '.$data['remark'];
|
||||||
}
|
}
|
||||||
if (!empty($data['batch_number'])) {
|
if (! empty($data['batch_number'])) {
|
||||||
$indicators[] = 'Batch Number: ' . $data['batch_number'];
|
$indicators[] = 'Batch Number: '.$data['batch_number'];
|
||||||
}
|
}
|
||||||
if (!empty($data['result']))
|
if (! empty($data['result'])) {
|
||||||
{
|
$indicators[] = 'Result: '.$data['result'];
|
||||||
$indicators[] = 'Result: ' . $data['result'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['serial_number'])) {
|
if (! empty($data['serial_number'])) {
|
||||||
$indicators[] = 'Serial Number: ' . $data['serial_number'];
|
$indicators[] = 'Serial Number: '.$data['serial_number'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['created_from'])) {
|
if (! empty($data['created_from'])) {
|
||||||
$indicators[] = 'From: ' . $data['created_from'];
|
$indicators[] = 'From: '.$data['created_from'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['created_to'])) {
|
if (! empty($data['created_to'])) {
|
||||||
$indicators[] = 'To: ' . $data['created_to'];
|
$indicators[] = 'To: '.$data['created_to'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $indicators;
|
return $indicators;
|
||||||
})
|
}),
|
||||||
])
|
])
|
||||||
->filtersFormMaxHeight('280px')
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
@@ -810,168 +817,355 @@ class TestingPanelReadingResource extends Resource
|
|||||||
Tables\Actions\DeleteBulkAction::make(),
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
Tables\Actions\RestoreBulkAction::make(),
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
|
|
||||||
|
// BulkAction::make('exportExcel')
|
||||||
|
// ->label('Export Selected to Excel')
|
||||||
|
// ->icon('heroicon-o-document-arrow-down')
|
||||||
|
// ->action(function (Collection $records) {
|
||||||
|
// return Excel::download(
|
||||||
|
// new MotorFreeRunExport($records),
|
||||||
|
// 'Motor_Free_Run_Register.xlsx'
|
||||||
|
// );
|
||||||
|
// }),
|
||||||
|
|
||||||
BulkAction::make('export_pdf')
|
BulkAction::make('export_pdf')
|
||||||
->label('Export Readings PDF')
|
->label('Export Selected to Excel')
|
||||||
->action(function ($records)
|
->action(function ($records) {
|
||||||
{
|
// $ids = $records->pluck('id')->toArray();
|
||||||
//$records->load('item');
|
// $query = TestingPanelReading::whereIn('id', $ids);
|
||||||
$records->load('motorTestingMaster.item');
|
$templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||||
$plantId = $records->first()?->plant_id;
|
|
||||||
|
|
||||||
$plant = $plantId ? Plant::find($plantId) : null;
|
|
||||||
|
|
||||||
// Check if all records are Star-Delta type
|
|
||||||
$isAllStarDelta = $records->every(function ($record) {
|
|
||||||
return $record->motorTestingMaster?->connection === 'Star-Delta';
|
|
||||||
});
|
|
||||||
// $hasStarDelta = $records->contains(function ($record) {
|
|
||||||
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
//dd($isAllStarDelta);
|
|
||||||
if(!$isAllStarDelta)
|
|
||||||
{
|
|
||||||
$mappedData = collect($records)->map(function ($record) {
|
|
||||||
return [
|
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
|
||||||
'Output' => $record['output'] ?? '',
|
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
|
||||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
|
||||||
|
|
||||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
|
||||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
|
||||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
|
||||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
|
||||||
|
|
||||||
// BEFORE FREE RUN
|
|
||||||
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
|
||||||
'Current_Before' => $record['before_fr_cur'] ?? '',
|
|
||||||
'Power_Before' => $record['before_fr_pow'] ?? '',
|
|
||||||
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
|
||||||
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
|
||||||
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
|
||||||
'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
|
||||||
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
|
||||||
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
|
||||||
|
|
||||||
// AFTER FREE RUN
|
|
||||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
|
||||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
|
||||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
|
||||||
'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
|
||||||
'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
|
||||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
|
||||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
|
||||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
|
||||||
|
|
||||||
// LOCKED ROTOR TEST
|
|
||||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
|
||||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
|
||||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
|
||||||
|
|
||||||
// Last 8 columns
|
|
||||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
|
||||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
|
||||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
|
||||||
'Batch_Number' => $record['batch_number'] ?? '',
|
|
||||||
'Batch_Count' => $record['batch_count'] ?? '',
|
|
||||||
'Result' => $record['result'] ?? '',
|
|
||||||
'Remark' => $record['remark'] ?? '',
|
|
||||||
'Tested_By' => $record['tested_by'] ?? '',
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
$mappedData = collect($records)->map(function ($record) {
|
|
||||||
return [
|
|
||||||
//'Date' => $record['created_at'] ?? '',
|
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
|
||||||
'Output' => $record['output'] ?? '',
|
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
|
||||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
|
||||||
|
|
||||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
|
||||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
|
||||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
|
||||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
|
||||||
|
|
||||||
// BEFORE FREE RUN
|
|
||||||
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
|
||||||
'Current_Before' => $record['before_fr_cur'] ?? '',
|
|
||||||
'Power_Before' => $record['before_fr_pow'] ?? '',
|
|
||||||
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
|
||||||
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
|
||||||
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
|
||||||
'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
|
||||||
'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
|
||||||
'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
|
||||||
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
|
||||||
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
|
||||||
|
|
||||||
// AFTER FREE RUN
|
|
||||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
|
||||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
|
||||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
|
||||||
'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
|
||||||
'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
|
||||||
'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
|
||||||
'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
|
||||||
'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
|
||||||
'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
|
||||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
|
||||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
|
||||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
|
||||||
|
|
||||||
// LOCKED ROTOR TEST
|
|
||||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
|
||||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
|
||||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
|
||||||
|
|
||||||
// Last 8 columns
|
|
||||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
|
||||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
|
||||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
|
||||||
'Batch_Number' => $record['batch_number'] ?? '',
|
|
||||||
'Batch_Count' => $record['batch_count'] ?? '',
|
|
||||||
'Result' => $record['result'] ?? '',
|
|
||||||
'Remark' => $record['remark'] ?? '',
|
|
||||||
'Tested_By' => $record['tested_by'] ?? '',
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$view = $isAllStarDelta ? 'exports.export-three-phase-pdf' : 'exports.testingpanel-pdf';
|
|
||||||
|
|
||||||
|
|
||||||
$pdf = Pdf::loadView($view, [
|
|
||||||
'records' => $mappedData,
|
|
||||||
'plant' => $plant,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
|
||||||
// // ['records' => $mappedData]
|
|
||||||
// 'records' => $mappedData,
|
|
||||||
// 'plant' => $plant,
|
|
||||||
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
return response()->streamDownload(
|
|
||||||
fn () => print($pdf->stream()),
|
|
||||||
'TestingPanelReading.pdf'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
return Excel::download(new MotorFreeRunExport($records, $templatePath), 'MotorFreeRunData.xlsx');
|
||||||
})
|
})
|
||||||
->icon('heroicon-o-document-arrow-down'),
|
->icon('heroicon-o-document-arrow-down'),
|
||||||
|
|
||||||
|
// BulkAction::make('export_pdf')
|
||||||
|
// ->label('Export Readings PDF'),
|
||||||
|
// ->action(function ($records)
|
||||||
|
// {
|
||||||
|
// //$records->load('item');
|
||||||
|
// $records->load('motorTestingMaster.item');
|
||||||
|
// $plantId = $records->first()?->plant_id;
|
||||||
|
|
||||||
|
// $plant = $plantId ? Plant::find($plantId) : null;
|
||||||
|
|
||||||
|
// // Check if all records are Star-Delta type
|
||||||
|
// $isAllStarDelta = $records->every(function ($record) {
|
||||||
|
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||||
|
// });
|
||||||
|
// // $hasStarDelta = $records->contains(function ($record) {
|
||||||
|
// // return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// //dd($isAllStarDelta);
|
||||||
|
// if(!$isAllStarDelta)
|
||||||
|
// {
|
||||||
|
// $mappedData = collect($records)->map(function ($record) {
|
||||||
|
// return [
|
||||||
|
// // 'Date' => $record['created_at'] ?? '',
|
||||||
|
// 'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
|
// 'Output' => $record['output'] ?? '',
|
||||||
|
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
|
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
|
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
|
||||||
|
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
|
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
|
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
|
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
|
||||||
|
// // BEFORE FREE RUN
|
||||||
|
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
|
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
|
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
|
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
|
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
|
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
|
// 'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||||
|
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
|
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
|
|
||||||
|
// // AFTER FREE RUN
|
||||||
|
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
|
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
|
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||||
|
// 'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
||||||
|
// 'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
||||||
|
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||||
|
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||||
|
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||||
|
|
||||||
|
// // LOCKED ROTOR TEST
|
||||||
|
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
|
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
|
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
|
|
||||||
|
// // Last 8 columns
|
||||||
|
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||||
|
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||||
|
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||||
|
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||||
|
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||||
|
// 'Result' => $record['result'] ?? '',
|
||||||
|
// 'Remark' => $record['remark'] ?? '',
|
||||||
|
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||||
|
// ];
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $mappedData = collect($records)->map(function ($record) {
|
||||||
|
// return [
|
||||||
|
// //'Date' => $record['created_at'] ?? '',
|
||||||
|
// 'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
|
// 'Output' => $record['output'] ?? '',
|
||||||
|
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
|
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
|
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
|
||||||
|
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
|
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
|
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
|
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
|
||||||
|
// // BEFORE FREE RUN
|
||||||
|
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
|
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
|
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
|
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
|
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
|
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
|
// 'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||||
|
// 'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||||
|
// 'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||||
|
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
|
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
|
|
||||||
|
// // AFTER FREE RUN
|
||||||
|
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
|
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
|
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||||
|
// 'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
||||||
|
// 'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
||||||
|
// 'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
||||||
|
// 'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
||||||
|
// 'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
||||||
|
// 'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
||||||
|
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||||
|
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||||
|
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||||
|
|
||||||
|
// // LOCKED ROTOR TEST
|
||||||
|
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
|
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
|
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
|
|
||||||
|
// // Last 8 columns
|
||||||
|
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||||
|
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||||
|
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||||
|
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||||
|
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||||
|
// 'Result' => $record['result'] ?? '',
|
||||||
|
// 'Remark' => $record['remark'] ?? '',
|
||||||
|
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||||
|
// ];
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $view = $isAllStarDelta ? 'exports.export-three-phase-pdf' : 'exports.testingpanel-pdf';
|
||||||
|
|
||||||
|
// $pdf = Pdf::loadView($view, [
|
||||||
|
// 'records' => $mappedData,
|
||||||
|
// 'plant' => $plant,
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// // $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
||||||
|
// // // ['records' => $mappedData]
|
||||||
|
// // 'records' => $mappedData,
|
||||||
|
// // 'plant' => $plant,
|
||||||
|
|
||||||
|
// // ]);
|
||||||
|
|
||||||
|
// return response()->streamDownload(
|
||||||
|
// fn () => print($pdf->stream()),
|
||||||
|
// 'TestingPanelReading.pdf'
|
||||||
|
// );
|
||||||
|
// // return $pdf->download('TestingPanelReading.pdf');
|
||||||
|
// })
|
||||||
|
|
||||||
|
// ->action(function ($records) {
|
||||||
|
|
||||||
|
// // Load related item data
|
||||||
|
// $records->load('motorTestingMaster.item');
|
||||||
|
|
||||||
|
// $plantId = $records->first()?->plant_id;
|
||||||
|
// $plant = $plantId ? Plant::find($plantId) : null;
|
||||||
|
|
||||||
|
// // Check if all records are Star-Delta type
|
||||||
|
// $isAllStarDelta = $records->every(fn($record) => $record->motorTestingMaster?->connection === 'Star-Delta');
|
||||||
|
|
||||||
|
// // Map records for export
|
||||||
|
// $mappedData = $records->map(function ($record) use ($isAllStarDelta) {
|
||||||
|
|
||||||
|
// if (!$isAllStarDelta) {
|
||||||
|
// return [
|
||||||
|
// 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
|
// 'Output' => $record['output'] ?? '',
|
||||||
|
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
|
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
|
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
|
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
|
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
|
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
|
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
|
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
|
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
|
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
|
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
|
// 'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||||
|
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
|
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
|
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
|
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
|
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||||
|
// 'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
||||||
|
// 'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
||||||
|
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||||
|
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||||
|
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||||
|
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
|
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
|
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
|
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||||
|
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||||
|
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||||
|
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||||
|
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||||
|
// 'Result' => $record['result'] ?? '',
|
||||||
|
// 'Remark' => $record['remark'] ?? '',
|
||||||
|
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||||
|
// ];
|
||||||
|
// } else {
|
||||||
|
// // Star-Delta records
|
||||||
|
// return [
|
||||||
|
// 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
|
// 'Output' => $record['output'] ?? '',
|
||||||
|
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
|
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
|
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
|
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
|
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
|
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
|
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
|
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
|
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
|
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
|
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
|
// 'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||||
|
// 'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||||
|
// 'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||||
|
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
|
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
|
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
|
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
|
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||||
|
// 'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
||||||
|
// 'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
||||||
|
// 'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
||||||
|
// 'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
||||||
|
// 'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
||||||
|
// 'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
||||||
|
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||||
|
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||||
|
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||||
|
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
|
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
|
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
|
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||||
|
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||||
|
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||||
|
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||||
|
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||||
|
// 'Result' => $record['result'] ?? '',
|
||||||
|
// 'Remark' => $record['remark'] ?? '',
|
||||||
|
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // Excel template path
|
||||||
|
// $templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||||
|
|
||||||
|
// // Check if template exists
|
||||||
|
// if (!file_exists($templatePath)) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Template Not Found')
|
||||||
|
// ->danger()
|
||||||
|
// ->body('The Excel template file does not exist. Please upload it first.')
|
||||||
|
// ->send();
|
||||||
|
|
||||||
|
// return; // Stop further execution
|
||||||
|
// }
|
||||||
|
// // Export Excel
|
||||||
|
// // return Excel::download(
|
||||||
|
// // new MotorFreeRunExport(collect($mappedData)),
|
||||||
|
// // 'TestingPanelReading.xlsx',
|
||||||
|
// // \Maatwebsite\Excel\Excel::XLSX,
|
||||||
|
// // [
|
||||||
|
// // 'template' => $templatePath,
|
||||||
|
// // ]
|
||||||
|
// // );
|
||||||
|
// // Load the template
|
||||||
|
// $spreadsheet = IOFactory::load($templatePath);
|
||||||
|
// $sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// // Insert mapped data starting from row 3
|
||||||
|
// $row = 7;
|
||||||
|
// foreach ($mappedData as $dataRow) {
|
||||||
|
// $col = 'A';
|
||||||
|
// foreach ($dataRow as $cell) {
|
||||||
|
// $sheet->setCellValue($col . $row, $cell);
|
||||||
|
// $col++;
|
||||||
|
// }
|
||||||
|
// $row++;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Download the modified template as Excel
|
||||||
|
// $writer = new Xlsx($spreadsheet);
|
||||||
|
// return response()->streamDownload(function() use ($writer) {
|
||||||
|
// $writer->save('php://output');
|
||||||
|
// }, 'TestingPanelReading.xlsx');
|
||||||
|
// })
|
||||||
|
// ->action(function ($records) {
|
||||||
|
|
||||||
|
// // If no template, notify
|
||||||
|
// $templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||||
|
// if (!file_exists($templatePath)) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Template Not Found')
|
||||||
|
// ->danger()
|
||||||
|
// ->body('The Excel template file does not exist. Please upload it first.')
|
||||||
|
// ->send();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Just export the raw data (fast, chunked)
|
||||||
|
// return Excel::download(new MotorFreeRunExport($records->pluck('id')), 'MotorFreeRunData.xlsx');
|
||||||
|
// })
|
||||||
|
// ->icon('heroicon-o-document-arrow-down'), c
|
||||||
|
|
||||||
BulkAction::make('export_isi_pdf')
|
BulkAction::make('export_isi_pdf')
|
||||||
->label('Export ISI Readings PDF')
|
->label('Export ISI Readings PDF')
|
||||||
->action(function ($records)
|
->action(function ($records) {
|
||||||
{
|
// Increase memory and execution time
|
||||||
|
// ini_set('memory_limit', '1024M');
|
||||||
|
// set_time_limit(300);
|
||||||
$records->load('motorTestingMaster.item');
|
$records->load('motorTestingMaster.item');
|
||||||
$plantId = $records->first()?->plant_id;
|
$plantId = $records->first()?->plant_id;
|
||||||
|
|
||||||
@@ -984,13 +1178,12 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||||
// });
|
// });
|
||||||
|
|
||||||
//dd($isAllStarDelta);
|
// dd($isAllStarDelta);
|
||||||
if(!$isAllStarDelta)
|
if (! $isAllStarDelta) {
|
||||||
{
|
|
||||||
$mappedData = collect($records)->map(function ($record) {
|
$mappedData = collect($records)->map(function ($record) {
|
||||||
return [
|
return [
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
// 'Date' => $record['created_at'] ?? '',
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
'Output' => $record['output'] ?? '',
|
'Output' => $record['output'] ?? '',
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
@@ -1024,13 +1217,11 @@ class TestingPanelReadingResource extends Resource
|
|||||||
'Remark' => $record['remark'] ?? '',
|
'Remark' => $record['remark'] ?? '',
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$mappedData = collect($records)->map(function ($record) {
|
$mappedData = collect($records)->map(function ($record) {
|
||||||
return [
|
return [
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
// 'Date' => $record['created_at'] ?? '',
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
'Output' => $record['output'] ?? '',
|
'Output' => $record['output'] ?? '',
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
@@ -1070,7 +1261,6 @@ class TestingPanelReadingResource extends Resource
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$view = $isAllStarDelta ? 'exports.export-isi-three-phase-pdf' : 'exports.export-isi-pdf';
|
$view = $isAllStarDelta ? 'exports.export-isi-three-phase-pdf' : 'exports.export-isi-pdf';
|
||||||
|
|
||||||
$pdf = Pdf::loadView($view, [
|
$pdf = Pdf::loadView($view, [
|
||||||
@@ -1086,24 +1276,27 @@ class TestingPanelReadingResource extends Resource
|
|||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
return response()->streamDownload(
|
return response()->streamDownload(
|
||||||
fn () => print($pdf->stream()),
|
fn () => print ($pdf->stream()),
|
||||||
'TestingPanelReading.pdf'
|
'TestingPanelReading.pdf'
|
||||||
);
|
);
|
||||||
|
|
||||||
})
|
})
|
||||||
->icon('heroicon-o-document-arrow-down'),
|
->icon('heroicon-o-document-arrow-down'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
ImportAction::make()
|
ImportAction::make()
|
||||||
|
->label('Import Testing Panel Readings')
|
||||||
|
->color('warning')
|
||||||
->importer(TestingPanelReadingImporter::class)
|
->importer(TestingPanelReadingImporter::class)
|
||||||
->visible(function() {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view import testing panel reading');
|
return Filament::auth()->user()->can('view import testing panel reading');
|
||||||
}),
|
}),
|
||||||
ExportAction::make()
|
ExportAction::make()
|
||||||
|
->label('Export Testing Panel Readings')
|
||||||
|
->color('warning')
|
||||||
->exporter(TestingPanelReadingExporter::class)
|
->exporter(TestingPanelReadingExporter::class)
|
||||||
->visible(function() {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view export testing panel reading');
|
return Filament::auth()->user()->can('view export testing panel reading');
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user