Updated alignments and added orderby query while load plant
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
This commit is contained in:
@@ -4,24 +4,21 @@ namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\InvoiceInTransitExporter;
|
||||
use App\Filament\Resources\InvoiceInTransitResource\Pages;
|
||||
use App\Filament\Resources\InvoiceInTransitResource\RelationManagers;
|
||||
use App\Models\InvoiceInTransit;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Carbon\Carbon;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date as ExcelDate;
|
||||
use Storage;
|
||||
|
||||
class InvoiceInTransitResource extends Resource
|
||||
{
|
||||
@@ -37,6 +34,11 @@ class InvoiceInTransitResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('receiving_plant')
|
||||
->label('Receiving Plant'),
|
||||
@@ -272,8 +274,7 @@ class InvoiceInTransitResource extends Resource
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
@@ -305,7 +306,6 @@ class InvoiceInTransitResource extends Resource
|
||||
$invalidLRBLAWDt = [];
|
||||
$invalidPenDay = [];
|
||||
|
||||
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
@@ -369,7 +369,7 @@ class InvoiceInTransitResource extends Resource
|
||||
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
|
||||
//$plantId = $plant->id;
|
||||
// $plantId = $plant->id;
|
||||
|
||||
}
|
||||
|
||||
@@ -470,8 +470,7 @@ class InvoiceInTransitResource extends Resource
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -504,8 +503,7 @@ class InvoiceInTransitResource extends Resource
|
||||
throw new \Exception("Invalid plant code : '{$plantCode}'");
|
||||
}
|
||||
|
||||
if (! empty($invoiceDt))
|
||||
{
|
||||
if (! empty($invoiceDt)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $invoiceDt)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $invoiceDt);
|
||||
$formattedDate = "{$year}-{$month}-{$day}";
|
||||
@@ -517,8 +515,7 @@ class InvoiceInTransitResource extends Resource
|
||||
} else {
|
||||
$formattedDate = null;
|
||||
}
|
||||
if (! empty($LRBAWDt))
|
||||
{
|
||||
if (! empty($LRBAWDt)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $LRBAWDt)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $LRBAWDt);
|
||||
$formattedDt = "{$year}-{$month}-{$day}";
|
||||
@@ -530,8 +527,7 @@ class InvoiceInTransitResource extends Resource
|
||||
} else {
|
||||
$formattedDt = null;
|
||||
}
|
||||
if (! empty($OBDDate))
|
||||
{
|
||||
if (! empty($OBDDate)) {
|
||||
if (preg_match('/^\d{2}[-\/]\d{2}[-\/]\d{4}$/', $OBDDate)) {
|
||||
[$day, $month, $year] = preg_split('/[-\/]/', $OBDDate);
|
||||
$formattedDate = "{$year}-{$month}-{$day}";
|
||||
@@ -577,15 +573,15 @@ class InvoiceInTransitResource extends Resource
|
||||
->body('Invoice in transit uploaded successfully!')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('Insertion Failed')
|
||||
->body('Invoice in transit upload failed!')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user