Merge pull request 'ranjith-dev' (#578) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #578
This commit was merged in pull request #578.
This commit is contained in:
@@ -30,6 +30,8 @@ class PlantExporter extends Exporter
|
|||||||
->label('CODE'),
|
->label('CODE'),
|
||||||
ExportColumn::make('name')
|
ExportColumn::make('name')
|
||||||
->label('NAME'),
|
->label('NAME'),
|
||||||
|
ExportColumn::make('warehouse_number')
|
||||||
|
->label('WAREHOUSE_NUMBER'),
|
||||||
ExportColumn::make('address')
|
ExportColumn::make('address')
|
||||||
->label('ADDRESS'),
|
->label('ADDRESS'),
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
@@ -44,10 +46,10 @@ class PlantExporter extends Exporter
|
|||||||
|
|
||||||
public static function getCompletedNotificationBody(Export $export): string
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
{
|
{
|
||||||
$body = 'Your plant export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
$body = 'Your plant 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;
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ class PlantImporter extends Importer
|
|||||||
->example('Ransar Industries-I')
|
->example('Ransar Industries-I')
|
||||||
->label('NAME')
|
->label('NAME')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
|
ImportColumn::make('warehouse_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('WAREHOUSE_NUMBER')
|
||||||
|
->example('001')
|
||||||
|
->label('WAREHOUSE_NUMBER')
|
||||||
|
->rules(['required']),
|
||||||
ImportColumn::make('address')
|
ImportColumn::make('address')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('ADDRESS')
|
->exampleHeader('ADDRESS')
|
||||||
@@ -53,6 +59,7 @@ class PlantImporter extends Importer
|
|||||||
$comp = trim($this->data['company']) ?? null;
|
$comp = trim($this->data['company']) ?? null;
|
||||||
$code = trim($this->data['code']) ?? null;
|
$code = trim($this->data['code']) ?? null;
|
||||||
$name = trim($this->data['name']) ?? null;
|
$name = trim($this->data['name']) ?? null;
|
||||||
|
$wareHouseNo = trim($this->data['warehouse_number']) ?? null;
|
||||||
$addr = trim($this->data['address']) ?? null;
|
$addr = trim($this->data['address']) ?? null;
|
||||||
|
|
||||||
if ($comp == null || $comp == '' || ! $comp) {
|
if ($comp == null || $comp == '' || ! $comp) {
|
||||||
@@ -74,6 +81,13 @@ class PlantImporter extends Importer
|
|||||||
} elseif (Str::length($name) < 5) {
|
} elseif (Str::length($name) < 5) {
|
||||||
$warnMsg[] = 'Name should contain at least 5 characters!';
|
$warnMsg[] = 'Name should contain at least 5 characters!';
|
||||||
}
|
}
|
||||||
|
if ($wareHouseNo == null || $wareHouseNo == '' || ! $wareHouseNo) {
|
||||||
|
$warnMsg[] = "Warehouse number can't be empty!";
|
||||||
|
} elseif (! is_numeric($wareHouseNo)) {
|
||||||
|
$warnMsg[] = 'Warehouse number should contain only numeric values!';
|
||||||
|
} elseif (Str::length($wareHouseNo) == 3) {
|
||||||
|
$warnMsg[] = 'Warehouse number must contain 3 digits only!';
|
||||||
|
}
|
||||||
if ($addr == null || $addr == '' || ! $addr) {
|
if ($addr == null || $addr == '' || ! $addr) {
|
||||||
$warnMsg[] = "Address can't be empty!";
|
$warnMsg[] = "Address can't be empty!";
|
||||||
} elseif (Str::length($addr) < 5) {
|
} elseif (Str::length($addr) < 5) {
|
||||||
@@ -92,6 +106,7 @@ class PlantImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
$plantCN = Plant::where('code', $code)->where('name', $name)->first();
|
$plantCN = Plant::where('code', $code)->where('name', $name)->first();
|
||||||
|
$plantCW = Plant::where('code', $code)->where('warehouse_number', $wareHouseNo)->first();
|
||||||
if (! $plantCN) {
|
if (! $plantCN) {
|
||||||
$plantCode = Plant::where('code', $code)->first();
|
$plantCode = Plant::where('code', $code)->first();
|
||||||
$plantName = Plant::where('name', $name)->first();
|
$plantName = Plant::where('name', $name)->first();
|
||||||
@@ -99,6 +114,16 @@ class PlantImporter extends Importer
|
|||||||
throw new RowImportFailedException('Duplicate plant name found!');
|
throw new RowImportFailedException('Duplicate plant name found!');
|
||||||
} elseif ($plantCode) {
|
} elseif ($plantCode) {
|
||||||
throw new RowImportFailedException('Duplicate plant code found!');
|
throw new RowImportFailedException('Duplicate plant code found!');
|
||||||
|
} elseif (! $plantCW) {
|
||||||
|
$wareHouse = Plant::where('warehouse_number', $wareHouseNo)->first();
|
||||||
|
if ($wareHouse) {
|
||||||
|
throw new RowImportFailedException('Duplicate warehouse number found!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (! $plantCW) {
|
||||||
|
$wareHouse = Plant::where('warehouse_number', $wareHouseNo)->first();
|
||||||
|
if ($wareHouse) {
|
||||||
|
throw new RowImportFailedException('Duplicate warehouse number found!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +132,7 @@ class PlantImporter extends Importer
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
'warehouse_number' => $wareHouseNo,
|
||||||
'address' => $addr,
|
'address' => $addr,
|
||||||
'company_id' => $compId,
|
'company_id' => $compId,
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class PlantResource extends Resource
|
|||||||
Section::make('')
|
Section::make('')
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('code')
|
Forms\Components\TextInput::make('code')
|
||||||
|
->label('Code')
|
||||||
->required()
|
->required()
|
||||||
->unique(ignoreRecord: true)
|
->unique(ignoreRecord: true)
|
||||||
->integer()
|
->integer()
|
||||||
@@ -78,7 +79,8 @@ class PlantResource extends Resource
|
|||||||
->hint(fn ($get) => $get('pCodeError') ? $get('pCodeError') : null)
|
->hint(fn ($get) => $get('pCodeError') ? $get('pCodeError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\Select::make('company_id')
|
Forms\Components\Select::make('company_id')
|
||||||
// ->placeholder('Choose the valid company name')
|
->label('Company')
|
||||||
|
->placeholder('Choose the valid company nany')
|
||||||
->relationship('company', 'name')
|
->relationship('company', 'name')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
@@ -104,9 +106,10 @@ class PlantResource extends Resource
|
|||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->required()
|
->required()
|
||||||
|
->label('Name')
|
||||||
->placeholder('Scan the valid name')
|
->placeholder('Scan the valid name')
|
||||||
->unique(ignoreRecord: true)
|
->unique(ignoreRecord: true)
|
||||||
->columnSpanFull()
|
// ->columnSpanFull()
|
||||||
->reactive()
|
->reactive()
|
||||||
->minLength(5)
|
->minLength(5)
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -128,8 +131,38 @@ class PlantResource extends Resource
|
|||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('pNameError') ? $get('pNameError') : null)
|
->hint(fn ($get) => $get('pNameError') ? $get('pNameError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
Forms\Components\TextInput::make('warehouse_number')
|
||||||
|
->required()
|
||||||
|
->label('Warehouse Number')
|
||||||
|
->placeholder('Scan the valid warehouse number')
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->reactive()
|
||||||
|
->numeric()
|
||||||
|
->length(3),
|
||||||
|
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
// $codeId = $get('warehouse_number');
|
||||||
|
// // Ensure `linestop_id` is not cleared
|
||||||
|
// if (! $codeId) {
|
||||||
|
// $set('wNumberError', 'Scan the valid warehouse number.');
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// } else {
|
||||||
|
// if (strlen($codeId) != 3) {
|
||||||
|
// $set('wNumberError', 'Warehouse number must be exactly 3 digits!');
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// $set('wNumberError', null);
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// ->extraAttributes(fn ($get) => [
|
||||||
|
// 'class' => $get('wNumberError') ? 'border-red-500' : '',
|
||||||
|
// ])
|
||||||
|
// ->hint(fn ($get) => $get('wNumberError') ? $get('wNumberError') : null)
|
||||||
|
// ->hintColor('danger'),
|
||||||
Forms\Components\Textarea::make('address')
|
Forms\Components\Textarea::make('address')
|
||||||
->required()
|
->required()
|
||||||
|
->label('Address')
|
||||||
->placeholder('Scan the valid address')
|
->placeholder('Scan the valid address')
|
||||||
->unique(ignoreRecord: true)
|
->unique(ignoreRecord: true)
|
||||||
->columnSpanFull()
|
->columnSpanFull()
|
||||||
@@ -190,6 +223,11 @@ class PlantResource extends Resource
|
|||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable()
|
->sortable()
|
||||||
->searchable(),
|
->searchable(),
|
||||||
|
Tables\Columns\TextColumn::make('warehouse_number')
|
||||||
|
->label('Warehouse Number')
|
||||||
|
->alignCenter()
|
||||||
|
->sortable()
|
||||||
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('address')
|
Tables\Columns\TextColumn::make('address')
|
||||||
->label('Address')
|
->label('Address')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
|
|||||||
@@ -29,30 +29,30 @@ class PlantController extends Controller
|
|||||||
public function get_all_data(Request $request)
|
public function get_all_data(Request $request)
|
||||||
{
|
{
|
||||||
$expectedUser = env('API_AUTH_USER');
|
$expectedUser = env('API_AUTH_USER');
|
||||||
$expectedPw = env('API_AUTH_PW');
|
$expectedPw = env('API_AUTH_PW');
|
||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||||
|
|
||||||
if ("Bearer " . $expectedToken != $header_auth)
|
if ('Bearer '.$expectedToken != $header_auth) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid authorization token!'
|
'status_description' => 'Invalid authorization token!',
|
||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
$plants = Plant::with('company')->orderBy('code')->get();
|
$plants = Plant::with('company')->orderBy('code')->get();
|
||||||
$plantsData = $plants->map(function($plant) {
|
$plantsData = $plants->map(function ($plant) {
|
||||||
return [
|
return [
|
||||||
'company' => $plant->company ? $plant->company->name : "", // Get company name
|
'company' => $plant->company ? $plant->company->name : '', // Get company name
|
||||||
'plant_code' => (String)$plant->code,
|
'plant_code' => (string) $plant->code,
|
||||||
'plant_name' => $plant->name,
|
'plant_name' => $plant->name,
|
||||||
'plant_address' => $plant->address,
|
'plant_warehouse_number' => (string) $plant->warehouse_number,
|
||||||
|
'plant_address' => $plant->address,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'plants' => $plantsData
|
'plants' => $plantsData,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Plant extends Model
|
|||||||
'company_id',
|
'company_id',
|
||||||
'name',
|
'name',
|
||||||
'address',
|
'address',
|
||||||
|
'warehouse_number',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function company(): BelongsTo
|
public function company(): BelongsTo
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$sql1 = <<<'SQL'
|
||||||
|
ALTER TABLE plants
|
||||||
|
ADD COLUMN warehouse_number TEXT DEFAULT NULL
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Schema::table('plants', function (Blueprint $table) {
|
||||||
|
// //
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user