Compare commits
5 Commits
jothi-patc
...
048977a44b
| Author | SHA1 | Date | |
|---|---|---|---|
| 048977a44b | |||
| 8395599d9d | |||
|
|
f19765ff7b | ||
|
|
18fc1d25ac | ||
|
|
0cc969f065 |
@@ -24,8 +24,8 @@ class StickerMasterExporter extends Exporter
|
|||||||
// Increment and return the row number
|
// Increment and return the row number
|
||||||
return ++$rowNumber;
|
return ++$rowNumber;
|
||||||
}),
|
}),
|
||||||
ExportColumn::make('plant.name')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT NAME'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('item.code')
|
ExportColumn::make('item.code')
|
||||||
->label('ITEM CODE'),
|
->label('ITEM CODE'),
|
||||||
ExportColumn::make('serial_number_motor')
|
ExportColumn::make('serial_number_motor')
|
||||||
@@ -88,10 +88,10 @@ class StickerMasterExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
{
|
{
|
||||||
$body = 'Your sticker master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
$body = 'Your sticker master export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
@@ -151,10 +151,10 @@ class StickerMasterImporter extends Importer
|
|||||||
->example(''),
|
->example(''),
|
||||||
ImportColumn::make('plant')
|
ImportColumn::make('plant')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Plant Name')
|
->exampleHeader('Plant Code')
|
||||||
->example('Ransar Industries-I')
|
->example('1000')
|
||||||
->label('PLANT NAME')
|
->label('PLANT CODE')
|
||||||
->relationship(resolveUsing: 'name')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -162,80 +162,83 @@ class StickerMasterImporter extends Importer
|
|||||||
public function resolveRecord(): ?StickerMaster
|
public function resolveRecord(): ?StickerMaster
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
$item = null;
|
$item = null;
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
if (!$plant) {
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
$warnMsg[] = "Plant not found";
|
} else {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||||
if (!$item) {
|
if (! $item) {
|
||||||
$warnMsg[] = "Item code not found";
|
$warnMsg[] = 'Item code not found';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
||||||
$warnMsg[] = "Serial number motor must be 1 or empty";
|
$warnMsg[] = 'Serial number motor must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
|
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
|
||||||
$warnMsg[] = "Serial number pump must be 1 or empty";
|
$warnMsg[] = 'Serial number pump must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
|
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
|
||||||
$warnMsg[] = "Serial number pumpset must be 1 or empty";
|
$warnMsg[] = 'Serial number pumpset must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
|
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
|
||||||
$warnMsg[] = "Pack slip motor must be 1 or empty";
|
$warnMsg[] = 'Pack slip motor must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
|
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
|
||||||
$warnMsg[] = "Pack slip pump must be 1 or empty";
|
$warnMsg[] = 'Pack slip pump must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
|
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
|
||||||
$warnMsg[] = "Pack slip pumpset must be 1 or empty";
|
$warnMsg[] = 'Pack slip pumpset must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
|
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
|
||||||
$warnMsg[] = "Name plate motor must be 1 or empty";
|
$warnMsg[] = 'Name plate motor must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
|
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
|
||||||
$warnMsg[] = "Name plate pump must be 1 or empty";
|
$warnMsg[] = 'Name plate pump must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
|
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
|
||||||
$warnMsg[] = "Name plate pumpset must be 1 or empty";
|
$warnMsg[] = 'Name plate pumpset must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
|
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
|
||||||
$warnMsg[] = "Tube sticker motor must be 1 or empty";
|
$warnMsg[] = 'Tube sticker motor must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
|
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
|
||||||
$warnMsg[] = "Tube sticker pump must be 1 or empty";
|
$warnMsg[] = 'Tube sticker pump must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
|
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
|
||||||
$warnMsg[] = "Tube sticker pumpset must be 1 or empty";
|
$warnMsg[] = 'Tube sticker pumpset must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
|
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
|
||||||
$warnMsg[] = "Warranty card must be 1 or empty";
|
$warnMsg[] = 'Warranty card must be 1 or empty';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
|
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) {
|
||||||
$warnMsg[] = "Invalid panel box code found";
|
$warnMsg[] = 'Invalid panel box code found';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['load_rate']) < 0 || !is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
||||||
$warnMsg[] = "Load rate must be greater than or equal to 0";
|
$warnMsg[] = 'Load rate must be greater than or equal to 0';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
||||||
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
|
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
|
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
|
||||||
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
|
$warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
StickerMaster::updateOrCreate([
|
StickerMaster::updateOrCreate([
|
||||||
'item_id' => $item->id,
|
'item_id' => $item->id,
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'serial_number_motor' => $this->data['serial_number_motor'],
|
'serial_number_motor' => $this->data['serial_number_motor'],
|
||||||
@@ -261,8 +264,9 @@ class StickerMasterImporter extends Importer
|
|||||||
'panel_box_code' => $this->data['panel_box_code'],
|
'panel_box_code' => $this->data['panel_box_code'],
|
||||||
'load_rate' => $this->data['load_rate'],
|
'load_rate' => $this->data['load_rate'],
|
||||||
'bundle_quantity' => $this->data['bundle_quantity'],
|
'bundle_quantity' => $this->data['bundle_quantity'],
|
||||||
'material_type' => $this->data['material_type']
|
'material_type' => $this->data['material_type'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// return StickerMaster::firstOrNew([
|
// return StickerMaster::firstOrNew([
|
||||||
// // Update existing records, matching them by `$this->data['column_name']`
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
@@ -274,10 +278,10 @@ class StickerMasterImporter extends Importer
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your sticker master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
$body = 'Your sticker master import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
@@ -293,20 +293,18 @@ class ItemResource extends Resource
|
|||||||
])
|
])
|
||||||
->query(function ($query, array $data) {
|
->query(function ($query, array $data) {
|
||||||
// Hide all records initially if no filters are applied
|
// Hide all records initially if no filters are applied
|
||||||
if (
|
if (empty($data['Plant']) && empty($data['code']) && empty($data['description']) && empty($data['uom']) && empty($data['category']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||||
empty($data['Plant']) &&
|
|
||||||
empty($data['code']) &&
|
|
||||||
empty($data['description']) &&
|
|
||||||
empty($data['uom']) &&
|
|
||||||
empty($data['category']) &&
|
|
||||||
empty($data['created_from']) &&
|
|
||||||
empty($data['created_to'])
|
|
||||||
) {
|
|
||||||
return $query->whereRaw('1 = 0');
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||||
$query->where('plant_id', $data['Plant']);
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['code'])) {
|
if (! empty($data['code'])) {
|
||||||
@@ -338,6 +336,17 @@ class ItemResource extends Resource
|
|||||||
|
|
||||||
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) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Choose plant to filter records.')
|
||||||
|
// ->danger()
|
||||||
|
// ->seconds(1)
|
||||||
|
// ->send();
|
||||||
|
return 'Plant: Choose plant to filter records.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['code'])) {
|
if (! empty($data['code'])) {
|
||||||
|
|||||||
@@ -649,19 +649,18 @@ class StickerMasterResource extends Resource
|
|||||||
])
|
])
|
||||||
->query(function ($query, array $data) {
|
->query(function ($query, array $data) {
|
||||||
// Hide all records initially if no filters are applied
|
// Hide all records initially if no filters are applied
|
||||||
if (
|
if (empty($data['Plant']) && empty($data['item_id']) && empty($data['material_type']) && empty($data['panel_box_code']) && empty($data['created_from']) && empty($data['created_to'])) {
|
||||||
empty($data['Plant']) &&
|
|
||||||
empty($data['item_id']) &&
|
|
||||||
empty($data['material_type']) &&
|
|
||||||
empty($data['panel_box_code']) &&
|
|
||||||
empty($data['created_from']) &&
|
|
||||||
empty($data['created_to'])
|
|
||||||
) {
|
|
||||||
return $query->whereRaw('1 = 0');
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||||
$query->where('plant_id', $data['Plant']);
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['item_id'])) {
|
if (! empty($data['item_id'])) {
|
||||||
@@ -690,6 +689,17 @@ class StickerMasterResource extends Resource
|
|||||||
|
|
||||||
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) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Choose plant to filter records.')
|
||||||
|
// ->danger()
|
||||||
|
// ->seconds(1)
|
||||||
|
// ->send();
|
||||||
|
return 'Plant: Choose plant to filter records.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['item_id'])) {
|
if (! empty($data['item_id'])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user