Merge pull request 'ranjith-dev' (#710) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s
Reviewed-on: #710
This commit was merged in pull request #710.
This commit is contained in:
264
app/Filament/Imports/ImportTransitImporter.php
Normal file
264
app/Filament/Imports/ImportTransitImporter.php
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\ImportTransit;
|
||||||
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
|
use Filament\Actions\Imports\Importer;
|
||||||
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class ImportTransitImporter extends Importer
|
||||||
|
{
|
||||||
|
protected static ?string $model = ImportTransit::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ImportColumn::make('cri_rfq_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('CRI RFQ Number')
|
||||||
|
->example('RFQ-IMP-C.R.I-2025-A')
|
||||||
|
->label('CRI RFQ Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('mail_received_date')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Mail Received Date')
|
||||||
|
->example('2024-01-01')
|
||||||
|
->label('Mail Received Date'),
|
||||||
|
ImportColumn::make('pricol_ref_number')
|
||||||
|
->exampleHeader('Pricol Ref Number')
|
||||||
|
->example('ENQ-1649')
|
||||||
|
->label('Pricol Ref Number'),
|
||||||
|
ImportColumn::make('requester')
|
||||||
|
->exampleHeader('Requester')
|
||||||
|
->example('Mr.Sathish.K')
|
||||||
|
->label('Requester'),
|
||||||
|
ImportColumn::make('shipper')
|
||||||
|
->exampleHeader('Shipper')
|
||||||
|
->example('Zhejiang shenneng technology co.,ltd')
|
||||||
|
->label('Shipper'),
|
||||||
|
ImportColumn::make('shipper_location')
|
||||||
|
->exampleHeader('Shipper Location')
|
||||||
|
->example('China')
|
||||||
|
->label('Shipper Location'),
|
||||||
|
ImportColumn::make('shipper_invoice')
|
||||||
|
->exampleHeader('Shipper Invoice')
|
||||||
|
->example('SNINDIA250618')
|
||||||
|
->label('Shipper Invoice'),
|
||||||
|
ImportColumn::make('shipper_invoice_date')
|
||||||
|
->exampleHeader('Shipper Invoice Date')
|
||||||
|
->example('2024-01-02')
|
||||||
|
->label('Shipper Invoice Date'),
|
||||||
|
ImportColumn::make('inv_value')
|
||||||
|
->exampleHeader('Inv Value')
|
||||||
|
->example('10000')
|
||||||
|
->label('Inv Value'),
|
||||||
|
ImportColumn::make('freight_charge')
|
||||||
|
->exampleHeader('Freight Charge')
|
||||||
|
->example('500')
|
||||||
|
->label('Freight Charge'),
|
||||||
|
ImportColumn::make('customs_agent_name')
|
||||||
|
->exampleHeader('Customs Agent Name')
|
||||||
|
->example('Pricol Logistics')
|
||||||
|
->label('Customs Agent Name'),
|
||||||
|
ImportColumn::make('eta_date')
|
||||||
|
->exampleHeader('ETA Date')
|
||||||
|
->example('2024-01-10')
|
||||||
|
->label('ETA Date'),
|
||||||
|
ImportColumn::make('status')
|
||||||
|
->exampleHeader('Status')
|
||||||
|
->example('Receipted')
|
||||||
|
->label('Status'),
|
||||||
|
ImportColumn::make('insurance_status')
|
||||||
|
->exampleHeader('Insurance Status')
|
||||||
|
->example('Receipted')
|
||||||
|
->label('Insurance Status'),
|
||||||
|
ImportColumn::make('delivery_location')
|
||||||
|
->exampleHeader('Delivery Location')
|
||||||
|
->example('Arasur Hub')
|
||||||
|
->label('Delivery Location'),
|
||||||
|
ImportColumn::make('etd_date')
|
||||||
|
->exampleHeader('ETD Date')
|
||||||
|
->example('2024-01-05')
|
||||||
|
->label('ETD Date'),
|
||||||
|
ImportColumn::make('mode')
|
||||||
|
->exampleHeader('Mode')
|
||||||
|
->example('LCL')
|
||||||
|
->label('Mode'),
|
||||||
|
ImportColumn::make('inco_terms')
|
||||||
|
->exampleHeader('Inco Terms')
|
||||||
|
->example('FOB')
|
||||||
|
->label('Inco Terms'),
|
||||||
|
ImportColumn::make('port_of_loading')
|
||||||
|
->exampleHeader('Port of Loading')
|
||||||
|
->example('NINGBO')
|
||||||
|
->label('Port of Loading'),
|
||||||
|
ImportColumn::make('port_of_discharge')
|
||||||
|
->exampleHeader('Port of Discharge')
|
||||||
|
->example('CHENNAI')
|
||||||
|
->label('Port of Discharge'),
|
||||||
|
ImportColumn::make('delivery_city')
|
||||||
|
->exampleHeader('Delivery City')
|
||||||
|
->example('COIMBATORE')
|
||||||
|
->label('Delivery City'),
|
||||||
|
ImportColumn::make('packages')
|
||||||
|
->exampleHeader('Packages')
|
||||||
|
->example('450')
|
||||||
|
->label('Packages'),
|
||||||
|
ImportColumn::make('type_of_package')
|
||||||
|
->exampleHeader('Type of Package')
|
||||||
|
->example('PKG')
|
||||||
|
->label('Type of Package'),
|
||||||
|
ImportColumn::make('gross_weight')
|
||||||
|
->exampleHeader('Gross Weight')
|
||||||
|
->example('5000')
|
||||||
|
->label('Gross Weight'),
|
||||||
|
ImportColumn::make('volume')
|
||||||
|
->exampleHeader('Volume')
|
||||||
|
->example('50')
|
||||||
|
->label('Volume'),
|
||||||
|
ImportColumn::make('bill_number')
|
||||||
|
->exampleHeader('Bill Number')
|
||||||
|
->example('BL12345')
|
||||||
|
->label('Bill Number'),
|
||||||
|
ImportColumn::make('bill_received_date')
|
||||||
|
->exampleHeader('Bill Received Date')
|
||||||
|
->example('2024-01-15')
|
||||||
|
->label('Bill Received Date'),
|
||||||
|
ImportColumn::make('vessel_number')
|
||||||
|
->exampleHeader('Vessel Number')
|
||||||
|
->example('XIN WEN ZHOU')
|
||||||
|
->label('Vessel Number'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveRecord(): ?ImportTransit
|
||||||
|
{
|
||||||
|
$warnMsg = [];
|
||||||
|
$criRfqNumber = trim($this->data['cri_rfq_number']) ?? '';
|
||||||
|
$mailRecDate = trim($this->data['mail_received_date']) ?? '';
|
||||||
|
$pricolRefNumber = trim($this->data['pricol_ref_number']) ?? '';
|
||||||
|
$requester = trim($this->data['requester']) ?? '';
|
||||||
|
$shipper = trim($this->data['shipper']) ?? '';
|
||||||
|
$shipperLocation = trim($this->data['shipper_location']) ?? '';
|
||||||
|
$shipperInvoice = trim($this->data['shipper_invoice']) ?? '';
|
||||||
|
$shipperInvoiceDt = trim($this->data['shipper_invoice_date']) ?? '';
|
||||||
|
$invValue = trim($this->data['inv_value']) ?? '';
|
||||||
|
$freightCharge = trim($this->data['freight_charge']) ?? '';
|
||||||
|
$customsAgentname = trim($this->data['customs_agent_name']) ?? '';
|
||||||
|
$etaDate = trim($this->data['eta_date']) ?? '';
|
||||||
|
$status = trim($this->data['status']) ?? '';
|
||||||
|
$deliveryLocation = trim($this->data['delivery_location']) ?? '';
|
||||||
|
$etdDate = trim($this->data['etd_date']) ?? '';
|
||||||
|
$mode = trim($this->data['mode']) ?? '';
|
||||||
|
$incoTerms = trim($this->data['inco_terms']) ?? '';
|
||||||
|
$portOfLoading = trim($this->data['port_of_loading']) ?? '';
|
||||||
|
$portOfDischarge = trim($this->data['port_of_discharge']) ?? '';
|
||||||
|
$deliveryCity = trim($this->data['delivery_city']) ?? '';
|
||||||
|
$packages = trim($this->data['packages']) ?? '';
|
||||||
|
$typeOfPackage = trim($this->data['type_of_package']) ?? '';
|
||||||
|
$grossWeight = trim($this->data['gross_weight']) ?? '';
|
||||||
|
$volume = trim($this->data['volume']) ?? '';
|
||||||
|
$billNo = trim($this->data['bill_number']) ?? '';
|
||||||
|
$billReceivedDate = trim($this->data['bill_received_date']) ?? '';
|
||||||
|
$vesselNumber = trim($this->data['vessel_number']) ?? '';
|
||||||
|
|
||||||
|
$createdBy = Filament::auth()->user()?->name ?? '';
|
||||||
|
$updatedBy = $createdBy;
|
||||||
|
|
||||||
|
if (! empty($warnMsg)) {
|
||||||
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImportTransit::updateOrCreate([
|
||||||
|
'cri_rfq_number' => $criRfqNumber,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mail_received_date' => $this->formatDate($mailRecDate),
|
||||||
|
'shipper_invoice_date' => $this->formatDate($shipperInvoiceDt),
|
||||||
|
'eta_date' => $this->formatDate($etaDate),
|
||||||
|
'etd_date' => $this->formatDate($etdDate),
|
||||||
|
'bill_received_date' => $this->formatDate($billReceivedDate),
|
||||||
|
'pricol_ref_number' => $pricolRefNumber,
|
||||||
|
'requester' => $requester,
|
||||||
|
'shipper' => $shipper,
|
||||||
|
'shipper_location' => $shipperLocation,
|
||||||
|
'shipper_invoice' => $shipperInvoice,
|
||||||
|
'inv_value' => $invValue,
|
||||||
|
'freight_charge' => $freightCharge,
|
||||||
|
'custom_agent_name' => $customsAgentname,
|
||||||
|
'status' => $status,
|
||||||
|
'delivery_location' => $deliveryLocation,
|
||||||
|
'mode' => $mode,
|
||||||
|
'inco_terms' => $incoTerms,
|
||||||
|
'port_of_loading' => $portOfLoading,
|
||||||
|
'port_of_discharge' => $portOfDischarge,
|
||||||
|
'delivery_city' => $deliveryCity,
|
||||||
|
'packages' => $packages,
|
||||||
|
'type_of_package' => $typeOfPackage,
|
||||||
|
'gross_weight' => $grossWeight,
|
||||||
|
'volume' => $volume,
|
||||||
|
'bill_number' => $billNo,
|
||||||
|
'vessel_number' => $vesselNumber,
|
||||||
|
// 'created_at' => $createdAt ?? null,
|
||||||
|
// 'updated_at' => $updatedAt ?? null,
|
||||||
|
'created_by' => $createdBy ?? null,
|
||||||
|
'updated_by' => $updatedBy ?? null,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// return new ImportTransit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatDate($date): ?string
|
||||||
|
{
|
||||||
|
if (blank($date)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/\d/', $date)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$date = trim($date);
|
||||||
|
|
||||||
|
// Excel numeric date (e.g. 46000)
|
||||||
|
if (is_numeric($date)) {
|
||||||
|
return Carbon::instance(
|
||||||
|
\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject((float)$date)
|
||||||
|
)->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try common formats explicitly
|
||||||
|
$formats = ['d-m-Y', 'd/m/Y', 'Y-m-d', 'm/d/Y', 'd.m.Y'];
|
||||||
|
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
try {
|
||||||
|
return Carbon::createFromFormat($format, $date)->format('Y-m-d');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
{
|
||||||
|
$body = 'Your import transit import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||||
|
|
||||||
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Exports\ImportTransitExporter;
|
use App\Filament\Exports\ImportTransitExporter;
|
||||||
|
use App\Filament\Imports\ImportTransitImporter;
|
||||||
use App\Filament\Resources\ImportTransitResource\Pages;
|
use App\Filament\Resources\ImportTransitResource\Pages;
|
||||||
use App\Filament\Resources\ImportTransitResource\RelationManagers;
|
use App\Filament\Resources\ImportTransitResource\RelationManagers;
|
||||||
use App\Models\ImportTransit;
|
use App\Models\ImportTransit;
|
||||||
@@ -22,6 +23,7 @@ use Filament\Notifications\Notification;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
// use PhpOffice\PhpSpreadsheet\IOFactory;
|
// use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
class ImportTransitResource extends Resource
|
class ImportTransitResource extends Resource
|
||||||
@@ -73,6 +75,16 @@ class ImportTransitResource extends Resource
|
|||||||
->afterStateUpdated(function (callable $set) {
|
->afterStateUpdated(function (callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
|
Forms\Components\DatePicker::make('inv_value')
|
||||||
|
->label('Inv Value')
|
||||||
|
->afterStateUpdated(function (callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
|
Forms\Components\TextInput::make('freight_charge')
|
||||||
|
->label('Freight Charge')
|
||||||
|
->afterStateUpdated(function (callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('customs_agent_name')
|
Forms\Components\TextInput::make('customs_agent_name')
|
||||||
->label('Customs Agent Name')
|
->label('Customs Agent Name')
|
||||||
->afterStateUpdated(function (callable $set) {
|
->afterStateUpdated(function (callable $set) {
|
||||||
@@ -97,6 +109,11 @@ class ImportTransitResource extends Resource
|
|||||||
->afterStateUpdated(function (callable $set) {
|
->afterStateUpdated(function (callable $set) {
|
||||||
$set('updated_by', Filament::auth()->user()?->name);
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
}),
|
}),
|
||||||
|
Forms\Components\TextInput::make('insurance_status')
|
||||||
|
->label('Insurance Status')
|
||||||
|
->afterStateUpdated(function (callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('delivery_location')
|
Forms\Components\TextInput::make('delivery_location')
|
||||||
->label('Delivery Location')
|
->label('Delivery Location')
|
||||||
->afterStateUpdated(function (callable $set) {
|
->afterStateUpdated(function (callable $set) {
|
||||||
@@ -232,6 +249,16 @@ class ImportTransitResource extends Resource
|
|||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('shipper_invoice_date')
|
Tables\Columns\TextColumn::make('shipper_invoice_date')
|
||||||
->label('Shipper Invoice Date')
|
->label('Shipper Invoice Date')
|
||||||
|
->date()
|
||||||
|
->formatStateUsing(fn ($state) => $state?->format('Y-m-d'))
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('inv_value')
|
||||||
|
->label('Inv Value')
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('freight_charge')
|
||||||
|
->label('Freight Charge')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('customs_agent_name')
|
Tables\Columns\TextColumn::make('customs_agent_name')
|
||||||
@@ -240,18 +267,24 @@ class ImportTransitResource extends Resource
|
|||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('eta_date')
|
Tables\Columns\TextColumn::make('eta_date')
|
||||||
->label('ETA Date')
|
->label('ETA Date')
|
||||||
|
->date()
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('status')
|
Tables\Columns\TextColumn::make('status')
|
||||||
->label('Status')
|
->label('Status')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('insurance_status')
|
||||||
|
->label('Insurance Status')
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('delivery_location')
|
Tables\Columns\TextColumn::make('delivery_location')
|
||||||
->label('Delivery Location')
|
->label('Delivery Location')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('etd_date')
|
Tables\Columns\TextColumn::make('etd_date')
|
||||||
->label('ETD Date')
|
->label('ETD Date')
|
||||||
|
->date()
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('mode')
|
Tables\Columns\TextColumn::make('mode')
|
||||||
@@ -352,297 +385,304 @@ class ImportTransitResource extends Resource
|
|||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Tables\Actions\Action::make('Import Transit')
|
// Tables\Actions\Action::make('Import Transit')
|
||||||
|
// ->label('Import Transit')
|
||||||
|
// ->form([
|
||||||
|
// FileUpload::make('import_transit_file')
|
||||||
|
// ->label('Import Transit')
|
||||||
|
// // ->required()
|
||||||
|
// ->preserveFilenames()
|
||||||
|
// ->storeFiles(false)
|
||||||
|
// ->reactive()
|
||||||
|
// ->required()
|
||||||
|
// ->disk('local')
|
||||||
|
// // ->visible(fn (Get $get) => !empty($get('plant_id')))
|
||||||
|
// ->directory('uploads/ImportTransit'),
|
||||||
|
// ])
|
||||||
|
// ->action(function (array $data) {
|
||||||
|
// $uploadedFile = $data['import_transit_file'];
|
||||||
|
|
||||||
|
// $disk = Storage::disk('local');
|
||||||
|
|
||||||
|
// $user = Filament::auth()->user();
|
||||||
|
|
||||||
|
// $operatorName = $user->name;
|
||||||
|
|
||||||
|
// // Get original filename
|
||||||
|
// $originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
||||||
|
|
||||||
|
// $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
||||||
|
|
||||||
|
// // Store manually using storeAs to keep original name
|
||||||
|
// $path = $uploadedFile->storeAs('uploads/ImportTransit', $originalName, 'local'); // returns relative path
|
||||||
|
|
||||||
|
// $fullPath = Storage::disk('local')->path($path);
|
||||||
|
|
||||||
|
// if ($fullPath && file_exists($fullPath)) {
|
||||||
|
// $rows = Excel::toArray(null, $fullPath)[0];
|
||||||
|
|
||||||
|
// if ((count($rows) - 1) <= 0) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Records Not Found')
|
||||||
|
// ->body("Import the valid 'Import Transit' file to proceed..!")
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
|
||||||
|
// if ($disk->exists($path))
|
||||||
|
// {
|
||||||
|
// $disk->delete($path);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $invalidCriNo = [];
|
||||||
|
|
||||||
|
// foreach ($rows as $index => $row)
|
||||||
|
// {
|
||||||
|
// if ($index == 0) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $rowNumber = $index + 1;
|
||||||
|
|
||||||
|
// $criRfqNo = trim($row[1] ?? '');
|
||||||
|
// $mailRcvdDate = trim($row[2] ?? '');
|
||||||
|
// $pricolRefNo = trim($row[3] ?? '');
|
||||||
|
// $requester = trim($row[4] ?? '');
|
||||||
|
// $shipper = trim($row[5] ?? '');
|
||||||
|
// $shipperLocation = trim($row[6] ?? '');
|
||||||
|
// $shipperInv = trim($row[7] ?? '');
|
||||||
|
// $shipperInvDate = trim($row[8] ?? '');
|
||||||
|
// $cha = trim($row[9] ?? '');
|
||||||
|
// $eta = trim($row[10] ?? '');
|
||||||
|
// $status = trim($row[11] ?? '');
|
||||||
|
// $dlyLoc = trim($row[12] ?? '');
|
||||||
|
// $etd = trim($row[13] ?? '');
|
||||||
|
// $mode = trim($row[14] ?? '');
|
||||||
|
// $incoTerms = trim($row[15] ?? '');
|
||||||
|
// $portOfLoading = trim($row[16] ?? '');
|
||||||
|
// $portOfDischarge = trim($row[17] ?? '');
|
||||||
|
// $deliveryCity = trim($row[18] ?? '');
|
||||||
|
// $packages = trim($row[19] ?? '');
|
||||||
|
// $typeOfPkg = trim($row[20] ?? '');
|
||||||
|
// $grossWeight = trim($row[21] ?? '');
|
||||||
|
// $volumeWeight = trim($row[22] ?? '');
|
||||||
|
// $blNo = trim($row[23] ?? '');
|
||||||
|
// $blRcvdDate = trim($row[24] ?? '');
|
||||||
|
// $vesselNo = trim($row[25] ?? '');
|
||||||
|
|
||||||
|
// if (empty($criRfqNo)) {
|
||||||
|
// $invalidCriNo[] = $rowNumber;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (! empty($invalidCriNo)){
|
||||||
|
|
||||||
|
// $errorMsg = '';
|
||||||
|
|
||||||
|
// if (! empty($invalidCriNo)) {
|
||||||
|
// $errorMsg .= 'Missing CRI Rfq No in rows: '.implode(', ', $invalidCriNo).'<br>';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Missing Mandatory Fields')
|
||||||
|
// ->body($errorMsg)
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
|
||||||
|
// if ($disk->exists($path)) {
|
||||||
|
// $disk->delete($path);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // $spreadsheet = IOFactory::load($fullPath);
|
||||||
|
|
||||||
|
// // foreach ($spreadsheet->getAllSheets() as $sheet) {
|
||||||
|
// // $state = $sheet->getSheetState();
|
||||||
|
// // if ($state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_HIDDEN ||
|
||||||
|
// // $state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_VERYHIDDEN) {
|
||||||
|
// // Notification::make()
|
||||||
|
// // ->title('Import Failed')
|
||||||
|
// // ->body("Hidden sheet found: \"{$sheet->getTitle()}\". Please remove all hidden sheets and try again.")
|
||||||
|
// // ->danger()
|
||||||
|
// // ->send();
|
||||||
|
// // return;
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// foreach ($rows as $index => $row)
|
||||||
|
// {
|
||||||
|
// if ($index == 0) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $rowNumber = $index + 1;
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $formattedDate = null;
|
||||||
|
// $formattedShipperDate = null;
|
||||||
|
// $etaDate = null;
|
||||||
|
// $etdDate = null;
|
||||||
|
// $formattedBlRcvdDate = null;
|
||||||
|
|
||||||
|
// $criRfqNo = trim($row[1] ?? '');
|
||||||
|
// $mailRcvdDate = trim($row[2] ?? '');
|
||||||
|
// $pricolRefNo = trim($row[3] ?? '');
|
||||||
|
// $requester = trim($row[4] ?? '');
|
||||||
|
// $shipper = trim($row[5] ?? '');
|
||||||
|
// $shipperLocation = trim($row[6] ?? '');
|
||||||
|
// $shipperInv = trim($row[7] ?? '');
|
||||||
|
// $shipperInvDate = trim($row[8] ?? '');
|
||||||
|
// $cha = trim($row[9] ?? '');
|
||||||
|
// $eta = trim($row[10] ?? '');
|
||||||
|
// $status = trim($row[11] ?? '');
|
||||||
|
// $dlyLoc = trim($row[12] ?? '');
|
||||||
|
// $etd = trim($row[13] ?? '');
|
||||||
|
// $mode = trim($row[14] ?? '');
|
||||||
|
// $incoTerms = trim($row[15] ?? '');
|
||||||
|
// $portOfLoading = trim($row[16] ?? '');
|
||||||
|
// $portOfDischarge = trim($row[17] ?? '');
|
||||||
|
// $deliveryCity = trim($row[18] ?? '');
|
||||||
|
// $packages = trim($row[19] ?? '');
|
||||||
|
// $typeOfPkg = trim($row[20] ?? '');
|
||||||
|
// $grossWeight = trim($row[21] ?? '');
|
||||||
|
// $volumeWeight = trim($row[22] ?? '');
|
||||||
|
// $blNo = trim($row[23] ?? '');
|
||||||
|
// $blRcvdDate = trim($row[24] ?? '');
|
||||||
|
// $vesselNo = trim($row[25] ?? '');
|
||||||
|
|
||||||
|
|
||||||
|
// if (! empty($mailRcvdDate)) {
|
||||||
|
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $mailRcvdDate)) {
|
||||||
|
// [$day, $month, $year] = preg_split('/[-\/]/', $mailRcvdDate);
|
||||||
|
// $formattedDate = "{$year}-{$month}-{$day}";
|
||||||
|
// } elseif (is_numeric($mailRcvdDate)) {
|
||||||
|
// $formattedDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($mailRcvdDate)->format('Y-m-d');
|
||||||
|
// } else {
|
||||||
|
// $formattedDate = date('Y-m-d', strtotime($mailRcvdDate));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (! empty($shipperInvDate)) {
|
||||||
|
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $shipperInvDate)) {
|
||||||
|
// [$day, $month, $year] = preg_split('/[-\/]/', $shipperInvDate);
|
||||||
|
// $formattedShipperDate = "{$year}-{$month}-{$day}";
|
||||||
|
// } elseif (is_numeric($shipperInvDate)) {
|
||||||
|
// $formattedShipperDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($shipperInvDate)->format('Y-m-d');
|
||||||
|
// } else {
|
||||||
|
// $formattedShipperDate = date('Y-m-d', strtotime($shipperInvDate));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (! empty($eta)) {
|
||||||
|
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $eta)) {
|
||||||
|
// [$day, $month, $year] = preg_split('/[-\/]/', $eta);
|
||||||
|
// $etaDate = "{$year}-{$month}-{$day}";
|
||||||
|
// } elseif (is_numeric($eta)) {
|
||||||
|
// $etaDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($eta)->format('Y-m-d');
|
||||||
|
// } else {
|
||||||
|
// $etaDate = date('Y-m-d', strtotime($eta));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (! empty($etd)) {
|
||||||
|
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $etd)) {
|
||||||
|
// [$day, $month, $year] = preg_split('/[-\/]/', $etd);
|
||||||
|
// $etdDate = "{$year}-{$month}-{$day}";
|
||||||
|
// } elseif (is_numeric($etd)) {
|
||||||
|
// $etdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($etd)->format('Y-m-d');
|
||||||
|
// } else {
|
||||||
|
// $etdDate = date('Y-m-d', strtotime($etd));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (! empty($blRcvdDate)) {
|
||||||
|
// if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $blRcvdDate)) {
|
||||||
|
// [$day, $month, $year] = preg_split('/[-\/]/', $blRcvdDate);
|
||||||
|
// $formattedBlRcvdDate = "{$year}-{$month}-{$day}";
|
||||||
|
// } elseif (is_numeric($blRcvdDate)) {
|
||||||
|
// $formattedBlRcvdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($blRcvdDate)->format('Y-m-d');
|
||||||
|
// } else {
|
||||||
|
// $formattedBlRcvdDate = date('Y-m-d', strtotime($blRcvdDate));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $inserted = ImportTransit::updateOrCreate(
|
||||||
|
// [
|
||||||
|
// 'cri_rfq_number' => $criRfqNo,
|
||||||
|
// ],
|
||||||
|
// [
|
||||||
|
// 'mail_received_date' => $formattedDate ?? null,
|
||||||
|
// 'pricol_ref_number' => $pricolRefNo ?? null,
|
||||||
|
// 'requester' => $requester ?? null,
|
||||||
|
// 'shipper' => $shipper ?? null,
|
||||||
|
// 'shipper_location' => $shipperLocation ?? null,
|
||||||
|
// 'shipper_invoice' => $shipperInv ?? null,
|
||||||
|
// 'shipper_invoice_date' => $formattedShipperDate ?? null,
|
||||||
|
// 'customs_agent_name' => $cha ?? null,
|
||||||
|
// 'eta_date' => $etaDate ?? null,
|
||||||
|
// 'status' => $status ?? null,
|
||||||
|
// 'delivery_location' => $dlyLoc ?? null,
|
||||||
|
// 'etd_date' => $etdDate ?? null,
|
||||||
|
// 'mode' => $mode ?? null,
|
||||||
|
// 'inco_terms' => $incoTerms ?? null,
|
||||||
|
// 'port_of_loading' => $portOfLoading ?? null,
|
||||||
|
// 'port_of_discharge' => $portOfDischarge ?? null,
|
||||||
|
// 'delivery_city' => $deliveryCity ?? null,
|
||||||
|
// 'packages' => $packages ?? null,
|
||||||
|
// 'type_of_package' => $typeOfPkg ?? null,
|
||||||
|
// 'gross_weight' => $grossWeight ?? null,
|
||||||
|
// 'volume' => $volumeWeight ?? null,
|
||||||
|
// 'bill_number' => $blNo ?? null,
|
||||||
|
// 'bill_received_date' => $formattedBlRcvdDate ?? null,
|
||||||
|
// 'vessel_number' => $vesselNo ?? null,
|
||||||
|
// 'created_by' => $operatorName,
|
||||||
|
// ]
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// catch (\Exception $e) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Import Failed')
|
||||||
|
// ->body("Error occurred while processing row. Error : {$e->getMessage()}")
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (! $inserted) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Failed')
|
||||||
|
// ->body("Records insertion failed!")
|
||||||
|
// ->success()
|
||||||
|
// ->send();
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Success')
|
||||||
|
// ->body("Records inserted successfully!")
|
||||||
|
// ->success()
|
||||||
|
// ->send();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// catch (\Exception $e) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Import Failed')
|
||||||
|
// ->body("No records were inserted. Error : {$e->getMessage()}")
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// ->visible(function () {
|
||||||
|
// return Filament::auth()->user()->can('view import transit');
|
||||||
|
// }),
|
||||||
|
ImportAction::make()
|
||||||
->label('Import Transit')
|
->label('Import Transit')
|
||||||
->form([
|
->color('warning')
|
||||||
FileUpload::make('import_transit_file')
|
->importer(ImportTransitImporter::class)
|
||||||
->label('Import Transit')
|
|
||||||
// ->required()
|
|
||||||
->preserveFilenames()
|
|
||||||
->storeFiles(false)
|
|
||||||
->reactive()
|
|
||||||
->required()
|
|
||||||
->disk('local')
|
|
||||||
// ->visible(fn (Get $get) => !empty($get('plant_id')))
|
|
||||||
->directory('uploads/ImportTransit'),
|
|
||||||
])
|
|
||||||
->action(function (array $data) {
|
|
||||||
$uploadedFile = $data['import_transit_file'];
|
|
||||||
|
|
||||||
$disk = Storage::disk('local');
|
|
||||||
|
|
||||||
$user = Filament::auth()->user();
|
|
||||||
|
|
||||||
$operatorName = $user->name;
|
|
||||||
|
|
||||||
// Get original filename
|
|
||||||
$originalName = $uploadedFile->getClientOriginalName(); // e.g. 3RA0018732.xlsx
|
|
||||||
|
|
||||||
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
|
|
||||||
|
|
||||||
// Store manually using storeAs to keep original name
|
|
||||||
$path = $uploadedFile->storeAs('uploads/ImportTransit', $originalName, 'local'); // returns relative path
|
|
||||||
|
|
||||||
$fullPath = Storage::disk('local')->path($path);
|
|
||||||
|
|
||||||
if ($fullPath && file_exists($fullPath)) {
|
|
||||||
$rows = Excel::toArray(null, $fullPath)[0];
|
|
||||||
|
|
||||||
if ((count($rows) - 1) <= 0) {
|
|
||||||
Notification::make()
|
|
||||||
->title('Records Not Found')
|
|
||||||
->body("Import the valid 'Import Transit' file to proceed..!")
|
|
||||||
->danger()
|
|
||||||
->send();
|
|
||||||
|
|
||||||
if ($disk->exists($path))
|
|
||||||
{
|
|
||||||
$disk->delete($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$invalidCriNo = [];
|
|
||||||
|
|
||||||
foreach ($rows as $index => $row)
|
|
||||||
{
|
|
||||||
if ($index == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rowNumber = $index + 1;
|
|
||||||
|
|
||||||
$criRfqNo = trim($row[1] ?? '');
|
|
||||||
$mailRcvdDate = trim($row[2] ?? '');
|
|
||||||
$pricolRefNo = trim($row[3] ?? '');
|
|
||||||
$requester = trim($row[4] ?? '');
|
|
||||||
$shipper = trim($row[5] ?? '');
|
|
||||||
$shipperLocation = trim($row[6] ?? '');
|
|
||||||
$shipperInv = trim($row[7] ?? '');
|
|
||||||
$shipperInvDate = trim($row[8] ?? '');
|
|
||||||
$cha = trim($row[9] ?? '');
|
|
||||||
$eta = trim($row[10] ?? '');
|
|
||||||
$status = trim($row[11] ?? '');
|
|
||||||
$dlyLoc = trim($row[12] ?? '');
|
|
||||||
$etd = trim($row[13] ?? '');
|
|
||||||
$mode = trim($row[14] ?? '');
|
|
||||||
$incoTerms = trim($row[15] ?? '');
|
|
||||||
$portOfLoading = trim($row[16] ?? '');
|
|
||||||
$portOfDischarge = trim($row[17] ?? '');
|
|
||||||
$deliveryCity = trim($row[18] ?? '');
|
|
||||||
$packages = trim($row[19] ?? '');
|
|
||||||
$typeOfPkg = trim($row[20] ?? '');
|
|
||||||
$grossWeight = trim($row[21] ?? '');
|
|
||||||
$volumeWeight = trim($row[22] ?? '');
|
|
||||||
$blNo = trim($row[23] ?? '');
|
|
||||||
$blRcvdDate = trim($row[24] ?? '');
|
|
||||||
$vesselNo = trim($row[25] ?? '');
|
|
||||||
|
|
||||||
if (empty($criRfqNo)) {
|
|
||||||
$invalidCriNo[] = $rowNumber;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! empty($invalidCriNo)){
|
|
||||||
|
|
||||||
$errorMsg = '';
|
|
||||||
|
|
||||||
if (! empty($invalidCriNo)) {
|
|
||||||
$errorMsg .= 'Missing CRI Rfq No in rows: '.implode(', ', $invalidCriNo).'<br>';
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::make()
|
|
||||||
->title('Missing Mandatory Fields')
|
|
||||||
->body($errorMsg)
|
|
||||||
->danger()
|
|
||||||
->send();
|
|
||||||
|
|
||||||
if ($disk->exists($path)) {
|
|
||||||
$disk->delete($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// $spreadsheet = IOFactory::load($fullPath);
|
|
||||||
|
|
||||||
// foreach ($spreadsheet->getAllSheets() as $sheet) {
|
|
||||||
// $state = $sheet->getSheetState();
|
|
||||||
// if ($state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_HIDDEN ||
|
|
||||||
// $state == \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::SHEETSTATE_VERYHIDDEN) {
|
|
||||||
// Notification::make()
|
|
||||||
// ->title('Import Failed')
|
|
||||||
// ->body("Hidden sheet found: \"{$sheet->getTitle()}\". Please remove all hidden sheets and try again.")
|
|
||||||
// ->danger()
|
|
||||||
// ->send();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach ($rows as $index => $row)
|
|
||||||
{
|
|
||||||
if ($index == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rowNumber = $index + 1;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
$formattedDate = null;
|
|
||||||
$formattedShipperDate = null;
|
|
||||||
$etaDate = null;
|
|
||||||
$etdDate = null;
|
|
||||||
$formattedBlRcvdDate = null;
|
|
||||||
|
|
||||||
$criRfqNo = trim($row[1] ?? '');
|
|
||||||
$mailRcvdDate = trim($row[2] ?? '');
|
|
||||||
$pricolRefNo = trim($row[3] ?? '');
|
|
||||||
$requester = trim($row[4] ?? '');
|
|
||||||
$shipper = trim($row[5] ?? '');
|
|
||||||
$shipperLocation = trim($row[6] ?? '');
|
|
||||||
$shipperInv = trim($row[7] ?? '');
|
|
||||||
$shipperInvDate = trim($row[8] ?? '');
|
|
||||||
$cha = trim($row[9] ?? '');
|
|
||||||
$eta = trim($row[10] ?? '');
|
|
||||||
$status = trim($row[11] ?? '');
|
|
||||||
$dlyLoc = trim($row[12] ?? '');
|
|
||||||
$etd = trim($row[13] ?? '');
|
|
||||||
$mode = trim($row[14] ?? '');
|
|
||||||
$incoTerms = trim($row[15] ?? '');
|
|
||||||
$portOfLoading = trim($row[16] ?? '');
|
|
||||||
$portOfDischarge = trim($row[17] ?? '');
|
|
||||||
$deliveryCity = trim($row[18] ?? '');
|
|
||||||
$packages = trim($row[19] ?? '');
|
|
||||||
$typeOfPkg = trim($row[20] ?? '');
|
|
||||||
$grossWeight = trim($row[21] ?? '');
|
|
||||||
$volumeWeight = trim($row[22] ?? '');
|
|
||||||
$blNo = trim($row[23] ?? '');
|
|
||||||
$blRcvdDate = trim($row[24] ?? '');
|
|
||||||
$vesselNo = trim($row[25] ?? '');
|
|
||||||
|
|
||||||
|
|
||||||
if (! empty($mailRcvdDate)) {
|
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $mailRcvdDate)) {
|
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $mailRcvdDate);
|
|
||||||
$formattedDate = "{$year}-{$month}-{$day}";
|
|
||||||
} elseif (is_numeric($mailRcvdDate)) {
|
|
||||||
$formattedDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($mailRcvdDate)->format('Y-m-d');
|
|
||||||
} else {
|
|
||||||
$formattedDate = date('Y-m-d', strtotime($mailRcvdDate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! empty($shipperInvDate)) {
|
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $shipperInvDate)) {
|
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $shipperInvDate);
|
|
||||||
$formattedShipperDate = "{$year}-{$month}-{$day}";
|
|
||||||
} elseif (is_numeric($shipperInvDate)) {
|
|
||||||
$formattedShipperDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($shipperInvDate)->format('Y-m-d');
|
|
||||||
} else {
|
|
||||||
$formattedShipperDate = date('Y-m-d', strtotime($shipperInvDate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! empty($eta)) {
|
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $eta)) {
|
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $eta);
|
|
||||||
$etaDate = "{$year}-{$month}-{$day}";
|
|
||||||
} elseif (is_numeric($eta)) {
|
|
||||||
$etaDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($eta)->format('Y-m-d');
|
|
||||||
} else {
|
|
||||||
$etaDate = date('Y-m-d', strtotime($eta));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! empty($etd)) {
|
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $etd)) {
|
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $etd);
|
|
||||||
$etdDate = "{$year}-{$month}-{$day}";
|
|
||||||
} elseif (is_numeric($etd)) {
|
|
||||||
$etdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($etd)->format('Y-m-d');
|
|
||||||
} else {
|
|
||||||
$etdDate = date('Y-m-d', strtotime($etd));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! empty($blRcvdDate)) {
|
|
||||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $blRcvdDate)) {
|
|
||||||
[$day, $month, $year] = preg_split('/[-\/]/', $blRcvdDate);
|
|
||||||
$formattedBlRcvdDate = "{$year}-{$month}-{$day}";
|
|
||||||
} elseif (is_numeric($blRcvdDate)) {
|
|
||||||
$formattedBlRcvdDate = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($blRcvdDate)->format('Y-m-d');
|
|
||||||
} else {
|
|
||||||
$formattedBlRcvdDate = date('Y-m-d', strtotime($blRcvdDate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$inserted = ImportTransit::updateOrCreate(
|
|
||||||
[
|
|
||||||
'cri_rfq_number' => $criRfqNo,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'mail_received_date' => $formattedDate ?? null,
|
|
||||||
'pricol_ref_number' => $pricolRefNo ?? null,
|
|
||||||
'requester' => $requester ?? null,
|
|
||||||
'shipper' => $shipper ?? null,
|
|
||||||
'shipper_location' => $shipperLocation ?? null,
|
|
||||||
'shipper_invoice' => $shipperInv ?? null,
|
|
||||||
'shipper_invoice_date' => $formattedShipperDate ?? null,
|
|
||||||
'customs_agent_name' => $cha ?? null,
|
|
||||||
'eta_date' => $etaDate ?? null,
|
|
||||||
'status' => $status ?? null,
|
|
||||||
'delivery_location' => $dlyLoc ?? null,
|
|
||||||
'etd_date' => $etdDate ?? null,
|
|
||||||
'mode' => $mode ?? null,
|
|
||||||
'inco_terms' => $incoTerms ?? null,
|
|
||||||
'port_of_loading' => $portOfLoading ?? null,
|
|
||||||
'port_of_discharge' => $portOfDischarge ?? null,
|
|
||||||
'delivery_city' => $deliveryCity ?? null,
|
|
||||||
'packages' => $packages ?? null,
|
|
||||||
'type_of_package' => $typeOfPkg ?? null,
|
|
||||||
'gross_weight' => $grossWeight ?? null,
|
|
||||||
'volume' => $volumeWeight ?? null,
|
|
||||||
'bill_number' => $blNo ?? null,
|
|
||||||
'bill_received_date' => $formattedBlRcvdDate ?? null,
|
|
||||||
'vessel_number' => $vesselNo ?? null,
|
|
||||||
'created_by' => $operatorName,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (\Exception $e) {
|
|
||||||
Notification::make()
|
|
||||||
->title('Import Failed')
|
|
||||||
->body("Error occurred while processing row. Error : {$e->getMessage()}")
|
|
||||||
->danger()
|
|
||||||
->send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! $inserted) {
|
|
||||||
Notification::make()
|
|
||||||
->title('Failed')
|
|
||||||
->body("Records insertion failed!")
|
|
||||||
->success()
|
|
||||||
->send();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Notification::make()
|
|
||||||
->title('Success')
|
|
||||||
->body("Records inserted successfully!")
|
|
||||||
->success()
|
|
||||||
->send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\Exception $e) {
|
|
||||||
Notification::make()
|
|
||||||
->title('Import Failed')
|
|
||||||
->body("No records were inserted. Error : {$e->getMessage()}")
|
|
||||||
->danger()
|
|
||||||
->send();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
->visible(function () {
|
->visible(function () {
|
||||||
return Filament::auth()->user()->can('view import transit');
|
return Filament::auth()->user()->can('view import transit');
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ class ImportTransit extends Model
|
|||||||
|
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'mail_received_date' => 'date',
|
||||||
|
'shipper_invoice_date' => 'date',
|
||||||
|
'eta_date' => 'date',
|
||||||
|
'etd_date' => 'date',
|
||||||
|
'bill_received_date' => 'date',
|
||||||
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'cri_rfq_number',
|
'cri_rfq_number',
|
||||||
'mail_received_date',
|
'mail_received_date',
|
||||||
@@ -22,6 +30,7 @@ class ImportTransit extends Model
|
|||||||
'customs_agent_name',
|
'customs_agent_name',
|
||||||
'eta_date',
|
'eta_date',
|
||||||
'status',
|
'status',
|
||||||
|
'insurance_status',
|
||||||
'delivery_location',
|
'delivery_location',
|
||||||
'etd_date',
|
'etd_date',
|
||||||
'mode',
|
'mode',
|
||||||
@@ -38,6 +47,8 @@ class ImportTransit extends Model
|
|||||||
'vessel_number',
|
'vessel_number',
|
||||||
'remark',
|
'remark',
|
||||||
'is_transit_identified',
|
'is_transit_identified',
|
||||||
|
'inv_value',
|
||||||
|
'freight_charge',
|
||||||
'created_at',
|
'created_at',
|
||||||
'created_by',
|
'created_by',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?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 import_transits
|
||||||
|
ADD COLUMN inv_value TEXT DEFAULT NULL
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql1);
|
||||||
|
|
||||||
|
$sql2 = <<<'SQL'
|
||||||
|
ALTER TABLE import_transits
|
||||||
|
ADD COLUMN freight_charge TEXT DEFAULT NULL
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql2);
|
||||||
|
|
||||||
|
$sql3 = <<<'SQL'
|
||||||
|
ALTER TABLE import_transits
|
||||||
|
ADD COLUMN insurance_status TEXT DEFAULT NULL
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Schema::table('import_transits', function (Blueprint $table) {
|
||||||
|
// //
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user