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'),
|
||||
ExportColumn::make('name')
|
||||
->label('NAME'),
|
||||
ExportColumn::make('warehouse_number')
|
||||
->label('WAREHOUSE_NUMBER'),
|
||||
ExportColumn::make('address')
|
||||
->label('ADDRESS'),
|
||||
ExportColumn::make('created_at')
|
||||
@@ -44,10 +46,10 @@ class PlantExporter extends Exporter
|
||||
|
||||
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()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
@@ -37,6 +37,12 @@ class PlantImporter extends Importer
|
||||
->example('Ransar Industries-I')
|
||||
->label('NAME')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('warehouse_number')
|
||||
->requiredMapping()
|
||||
->exampleHeader('WAREHOUSE_NUMBER')
|
||||
->example('001')
|
||||
->label('WAREHOUSE_NUMBER')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('address')
|
||||
->requiredMapping()
|
||||
->exampleHeader('ADDRESS')
|
||||
@@ -53,6 +59,7 @@ class PlantImporter extends Importer
|
||||
$comp = trim($this->data['company']) ?? null;
|
||||
$code = trim($this->data['code']) ?? null;
|
||||
$name = trim($this->data['name']) ?? null;
|
||||
$wareHouseNo = trim($this->data['warehouse_number']) ?? null;
|
||||
$addr = trim($this->data['address']) ?? null;
|
||||
|
||||
if ($comp == null || $comp == '' || ! $comp) {
|
||||
@@ -74,6 +81,13 @@ class PlantImporter extends Importer
|
||||
} elseif (Str::length($name) < 5) {
|
||||
$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) {
|
||||
$warnMsg[] = "Address can't be empty!";
|
||||
} elseif (Str::length($addr) < 5) {
|
||||
@@ -92,6 +106,7 @@ class PlantImporter extends Importer
|
||||
}
|
||||
|
||||
$plantCN = Plant::where('code', $code)->where('name', $name)->first();
|
||||
$plantCW = Plant::where('code', $code)->where('warehouse_number', $wareHouseNo)->first();
|
||||
if (! $plantCN) {
|
||||
$plantCode = Plant::where('code', $code)->first();
|
||||
$plantName = Plant::where('name', $name)->first();
|
||||
@@ -99,6 +114,16 @@ class PlantImporter extends Importer
|
||||
throw new RowImportFailedException('Duplicate plant name found!');
|
||||
} elseif ($plantCode) {
|
||||
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,
|
||||
],
|
||||
[
|
||||
'warehouse_number' => $wareHouseNo,
|
||||
'address' => $addr,
|
||||
'company_id' => $compId,
|
||||
]
|
||||
|
||||
@@ -38,6 +38,7 @@ class PlantResource extends Resource
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('code')
|
||||
->label('Code')
|
||||
->required()
|
||||
->unique(ignoreRecord: true)
|
||||
->integer()
|
||||
@@ -78,7 +79,8 @@ class PlantResource extends Resource
|
||||
->hint(fn ($get) => $get('pCodeError') ? $get('pCodeError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('company_id')
|
||||
// ->placeholder('Choose the valid company name')
|
||||
->label('Company')
|
||||
->placeholder('Choose the valid company nany')
|
||||
->relationship('company', 'name')
|
||||
->required()
|
||||
->reactive()
|
||||
@@ -104,9 +106,10 @@ class PlantResource extends Resource
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->label('Name')
|
||||
->placeholder('Scan the valid name')
|
||||
->unique(ignoreRecord: true)
|
||||
->columnSpanFull()
|
||||
// ->columnSpanFull()
|
||||
->reactive()
|
||||
->minLength(5)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
@@ -128,8 +131,38 @@ class PlantResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('pNameError') ? $get('pNameError') : null)
|
||||
->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')
|
||||
->required()
|
||||
->label('Address')
|
||||
->placeholder('Scan the valid address')
|
||||
->unique(ignoreRecord: true)
|
||||
->columnSpanFull()
|
||||
@@ -190,6 +223,11 @@ class PlantResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('warehouse_number')
|
||||
->label('Warehouse Number')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('address')
|
||||
->label('Address')
|
||||
->alignCenter()
|
||||
|
||||
@@ -29,30 +29,30 @@ class PlantController extends Controller
|
||||
public function get_all_data(Request $request)
|
||||
{
|
||||
$expectedUser = env('API_AUTH_USER');
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||
$expectedPw = env('API_AUTH_PW');
|
||||
$header_auth = $request->header('Authorization');
|
||||
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||
|
||||
if ("Bearer " . $expectedToken != $header_auth)
|
||||
{
|
||||
if ('Bearer '.$expectedToken != $header_auth) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Invalid authorization token!'
|
||||
'status_description' => 'Invalid authorization token!',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$plants = Plant::with('company')->orderBy('code')->get();
|
||||
$plantsData = $plants->map(function($plant) {
|
||||
$plantsData = $plants->map(function ($plant) {
|
||||
return [
|
||||
'company' => $plant->company ? $plant->company->name : "", // Get company name
|
||||
'plant_code' => (String)$plant->code,
|
||||
'plant_name' => $plant->name,
|
||||
'plant_address' => $plant->address,
|
||||
'company' => $plant->company ? $plant->company->name : '', // Get company name
|
||||
'plant_code' => (string) $plant->code,
|
||||
'plant_name' => $plant->name,
|
||||
'plant_warehouse_number' => (string) $plant->warehouse_number,
|
||||
'plant_address' => $plant->address,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'plants' => $plantsData
|
||||
'plants' => $plantsData,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class Plant extends Model
|
||||
'company_id',
|
||||
'name',
|
||||
'address',
|
||||
'warehouse_number',
|
||||
];
|
||||
|
||||
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