From fbd61aef056ff15a0c6e04dfd33877672ed654ad Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Wed, 8 Nov 2023 10:41:39 +0700 Subject: [PATCH] update master kondisi peti --- app/Http/Controllers/CustomerController.php | 15 ++++- .../Controllers/KondisiPetiController.php | 51 +++++++++++++++ app/Http/Controllers/PetiController.php | 5 ++ .../Requests/ValidasiCreateKondisiPeti.php | 39 +++++++++++ .../Requests/ValidasiUpdateKondisiPeti.php | 39 +++++++++++ app/Imports/CustomerImport.php | 28 ++++++++ app/Models/Kondisi_Peti.php | 13 +++- app/Models/Peti.php | 9 ++- ..._06_022213_create_kondisi_petis_table.php} | 9 ++- ... 2023_11_06_085238_create_petis_table.php} | 4 +- ...06_122033_create_asset_statuses_table.php} | 0 database/seeders/DatabaseSeeder.php | 1 + database/seeders/Kondisi_PetiSeeder.php | 32 +++++++++ public/assets/file/Format Import Customer.csv | 1 + .../Master_Data/Customer/index.blade.php | 42 ++++++++++++ .../Kondisi_Peti/index.blade.php | 65 +++++++++---------- .../Manajemen_Peti/Peti/create.blade.php | 11 ++-- .../Manajemen_Peti/Peti/edit.blade.php | 14 ++-- .../Manajemen_Peti/Peti/index.blade.php | 4 +- .../Manajemen_Peti/Peti/show.blade.php | 4 +- routes/web.php | 2 + 21 files changed, 333 insertions(+), 55 deletions(-) create mode 100644 app/Http/Requests/ValidasiCreateKondisiPeti.php create mode 100644 app/Http/Requests/ValidasiUpdateKondisiPeti.php create mode 100644 app/Imports/CustomerImport.php rename database/migrations/{2023_11_06_022213_create_kondisi__petis_table.php => 2023_11_06_022213_create_kondisi_petis_table.php} (53%) rename database/migrations/{2023_10_28_085238_create_petis_table.php => 2023_11_06_085238_create_petis_table.php} (85%) rename database/migrations/{2023_10_29_122033_create_asset_statuses_table.php => 2023_11_06_122033_create_asset_statuses_table.php} (100%) create mode 100644 database/seeders/Kondisi_PetiSeeder.php create mode 100644 public/assets/file/Format Import Customer.csv diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index b950531..cbb3849 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -2,11 +2,13 @@ namespace App\Http\Controllers; -use App\Http\Requests\ValidasiCreateCustomer; -use App\Http\Requests\ValidasiUpdateCustomer; use App\Models\Customer; use Illuminate\Http\Request; +use App\Imports\CustomerImport; use Illuminate\Support\Facades\Auth; +use Maatwebsite\Excel\Facades\Excel; +use App\Http\Requests\ValidasiCreateCustomer; +use App\Http\Requests\ValidasiUpdateCustomer; class CustomerController extends Controller { @@ -108,4 +110,13 @@ class CustomerController extends Controller return redirect()->back()->with('error', 'Data customer gagal dihapus'); } } + + public function importCustomer(Request $request) + { + // dd('oke'); + //melakukan import file + Excel::import(new CustomerImport, request()->file('file')); + + return redirect()->route('dashboard.customer.index')->with('success', 'Data customer berhasil Di Import'); + } } diff --git a/app/Http/Controllers/KondisiPetiController.php b/app/Http/Controllers/KondisiPetiController.php index dd459aa..bb2e4ff 100644 --- a/app/Http/Controllers/KondisiPetiController.php +++ b/app/Http/Controllers/KondisiPetiController.php @@ -3,14 +3,65 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use App\Http\Requests\ValidasiCreateKondisiPeti; +use App\Http\Requests\ValidasiUpdateKondisiPeti; +use App\Models\Kondisi_Peti; class KondisiPetiController extends Controller { public function index() { $data = [ + 'kondisiPeti' => Kondisi_Peti::all(), 'active' => 'menu-kondisipeti' ]; return view('dashboard.Master_Data.Manajemen_Peti.Kondisi_Peti.index', $data); } + + public function store(ValidasiCreateKondisiPeti $request) + { + // dd('oke'); + // dd($request); + try { + $currentUser = Auth::user(); + $validatedData = $request->except('_token'); + $validatedData['created_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai created_by + $validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by + // dd($validatedData); + Kondisi_Peti::create($validatedData); + return redirect()->back()->with('success', 'Data Kondisi Peti Berhasil Ditambah.'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data Kondisi Peti Gagal Ditambah.'); + } + } + + public function update(ValidasiUpdateKondisiPeti $request, $id) + { + try { + $currentUser = Auth::user(); + $kondisiPeti = Kondisi_Peti::findOrFail($id); + + $validatedData = $request->except('_token'); + $validatedData['updated_by'] = $currentUser->fullname; + + $kondisiPeti->update($validatedData); + + return redirect()->back()->with('success', 'Data Kondisi Peti Berhasil Diperbarui.'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data Kondisi Peti Gagal Diperbarui.'); + } + } + + public function destroy($id) + { + // dd("oke"); + try { + $kondisiPeti = Kondisi_Peti::findOrFail($id); + $kondisiPeti->delete(); + return redirect()->back()->with('success', 'Data kondisi peti berhasil dihapus'); + } catch (\Throwable $th) { + return redirect()->back()->with('error', 'Data kondisi peti gagal dihapus'); + } + } } diff --git a/app/Http/Controllers/PetiController.php b/app/Http/Controllers/PetiController.php index 9938c2f..cb2f63e 100644 --- a/app/Http/Controllers/PetiController.php +++ b/app/Http/Controllers/PetiController.php @@ -9,6 +9,7 @@ use Dompdf\Options; use App\Models\Peti; use App\Models\Customer; use App\Models\Type_peti; +use App\Models\Kondisi_Peti; use Mockery\Matcher\Type; use App\Models\m_warehouse; use Illuminate\Http\Request; @@ -23,6 +24,7 @@ class PetiController extends Controller public function index() { $data = [ + 'kondisiPeti' => Kondisi_Peti::all(), 'peti' => Peti::all(), 'active' => 'menu-peti', ]; @@ -35,6 +37,7 @@ class PetiController extends Controller public function create() { $data = [ + 'kondisiPeti' => Kondisi_Peti::get(), 'typepeti' => Type_peti::all(), 'customer' => Customer::all(), 'warehouse' => m_warehouse::all(), @@ -48,6 +51,7 @@ class PetiController extends Controller */ public function store(ValidasiCreatePeti $request) { + // dd($request->all()); try { $currenttype = Auth::user(); @@ -109,6 +113,7 @@ class PetiController extends Controller public function edit($id) { $data = [ + 'kondisiPeti' => Kondisi_Peti::get(), 'peti' => Peti::findOrFail($id), 'typepeti' => Type_peti::all(), 'customer' => Customer::all(), diff --git a/app/Http/Requests/ValidasiCreateKondisiPeti.php b/app/Http/Requests/ValidasiCreateKondisiPeti.php new file mode 100644 index 0000000..d2f9026 --- /dev/null +++ b/app/Http/Requests/ValidasiCreateKondisiPeti.php @@ -0,0 +1,39 @@ +|string> + */ + public function rules(): array + { + return [ + 'nama_kondisi' => 'required|string', + 'deskripsi_kondisi' => 'required|string', + ]; + } + + public function messages() + { + return [ + 'name.required' => 'Nama Kondisi harus diisi', + 'name.string' => 'Nama Kondisi harus berupa string', + 'description.required' => 'Deskripsi Kondisi harus diisi', + 'description.string' => 'Deskripsi Kondisi harus berupa string', + ]; + } +} diff --git a/app/Http/Requests/ValidasiUpdateKondisiPeti.php b/app/Http/Requests/ValidasiUpdateKondisiPeti.php new file mode 100644 index 0000000..447a369 --- /dev/null +++ b/app/Http/Requests/ValidasiUpdateKondisiPeti.php @@ -0,0 +1,39 @@ +|string> + */ + public function rules(): array + { + return [ + 'nama_kondisi' => 'required|string', + 'deskripsi_kondisi' => 'required|string', + ]; + } + + public function messages() + { + return [ + 'name.required' => 'Nama Kondisi harus diisi', + 'name.string' => 'Nama Kondisi harus berupa string', + 'description.required' => 'Deskripsi Kondisi harus diisi', + 'description.string' => 'Deskripsi Kondisi harus berupa string', + ]; + } +} diff --git a/app/Imports/CustomerImport.php b/app/Imports/CustomerImport.php new file mode 100644 index 0000000..3184249 --- /dev/null +++ b/app/Imports/CustomerImport.php @@ -0,0 +1,28 @@ + $row['name'], + 'code_customer' => $row['code_customer'], + 'lot_no' => $row['lot_no'], + 'no_tlp' => $row['no_tlp'], + 'email' => $row['email'], + 'address' => $row['address'], + ]); + } +} diff --git a/app/Models/Kondisi_Peti.php b/app/Models/Kondisi_Peti.php index 3122248..5bee0a7 100644 --- a/app/Models/Kondisi_Peti.php +++ b/app/Models/Kondisi_Peti.php @@ -2,10 +2,19 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Kondisi_Peti extends Model { - use HasFactory; + use HasFactory, SoftDeletes; + protected $table = 'kondisi_petis'; + + protected $fillable = [ + 'nama_kondisi', + 'deskripsi_kondisi', + 'created_by', + 'updated_by', + ]; } diff --git a/app/Models/Peti.php b/app/Models/Peti.php index eb49a2f..ff48859 100644 --- a/app/Models/Peti.php +++ b/app/Models/Peti.php @@ -2,6 +2,9 @@ namespace App\Models; +use App\Models\Customer; +use App\Models\Type_peti; +use App\Models\Kondisi_Peti; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -18,7 +21,7 @@ class Peti extends Model 'warehouse_id', 'jumlah', 'date_pembuatan', - 'status_disposal', + 'kondisipeti_id', 'packing_no', 'fix_lot', 'created_by', @@ -37,4 +40,8 @@ class Peti extends Model { return $this->belongsTo(Type_peti::class, 'tipe_peti_id')->select('id', 'type', 'size_peti', 'description'); } + public function kondisipeti() + { + return $this->belongsTo(Kondisi_Peti::class, 'kondisipeti_id')->select('id', 'nama_kondisi', 'deskripsi_kondisi'); + } } diff --git a/database/migrations/2023_11_06_022213_create_kondisi__petis_table.php b/database/migrations/2023_11_06_022213_create_kondisi_petis_table.php similarity index 53% rename from database/migrations/2023_11_06_022213_create_kondisi__petis_table.php rename to database/migrations/2023_11_06_022213_create_kondisi_petis_table.php index 55fe3c2..dae6984 100644 --- a/database/migrations/2023_11_06_022213_create_kondisi__petis_table.php +++ b/database/migrations/2023_11_06_022213_create_kondisi_petis_table.php @@ -11,9 +11,14 @@ return new class extends Migration */ public function up(): void { - Schema::create('kondisi__petis', function (Blueprint $table) { + Schema::create('kondisi_petis', function (Blueprint $table) { $table->id(); + $table->string('nama_kondisi', 50); + $table->text('deskripsi_kondisi'); $table->timestamps(); + $table->softDeletes(); + $table->string('created_by', 200)->nullable(); + $table->string('updated_by', 200)->nullable(); }); } @@ -22,6 +27,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('kondisi__petis'); + Schema::dropIfExists('kondisi_petis'); } }; diff --git a/database/migrations/2023_10_28_085238_create_petis_table.php b/database/migrations/2023_11_06_085238_create_petis_table.php similarity index 85% rename from database/migrations/2023_10_28_085238_create_petis_table.php rename to database/migrations/2023_11_06_085238_create_petis_table.php index e87db62..36e9b8d 100644 --- a/database/migrations/2023_10_28_085238_create_petis_table.php +++ b/database/migrations/2023_11_06_085238_create_petis_table.php @@ -24,7 +24,9 @@ return new class extends Migration $table->date('date_pembuatan', 100)->nullable(); $table->unsignedBigInteger('warehouse_id')->nullable(); $table->foreign('warehouse_id')->references('id')->on('m_warehouses')->onDelete('set null'); - $table->string('status_disposal')->nullable(); + $table->unsignedBigInteger('kondisipeti_id')->nullable(); + $table->foreign('kondisipeti_id')->references('id')->on('kondisi_petis')->onDelete('set null'); + // $table->string('status_disposal')->nullable(); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200)->nullable(); diff --git a/database/migrations/2023_10_29_122033_create_asset_statuses_table.php b/database/migrations/2023_11_06_122033_create_asset_statuses_table.php similarity index 100% rename from database/migrations/2023_10_29_122033_create_asset_statuses_table.php rename to database/migrations/2023_11_06_122033_create_asset_statuses_table.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index c0ca39b..b61b386 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -26,6 +26,7 @@ class DatabaseSeeder extends Seeder UserSeeder::class, Type_Peti::class, Customer::class, + Kondisi_PetiSeeder::class, ]); } } diff --git a/database/seeders/Kondisi_PetiSeeder.php b/database/seeders/Kondisi_PetiSeeder.php new file mode 100644 index 0000000..3ef956f --- /dev/null +++ b/database/seeders/Kondisi_PetiSeeder.php @@ -0,0 +1,32 @@ + 'Rusak', + 'deskripsi_kondisi' => 'Barang Rusak', + 'created_by' => 'Seeder', + 'updated_by' => 'Seeder', + ]); + + // Kondisi peti Baik + Kondisi_Peti::create([ + 'nama_kondisi' => 'Ready', + 'deskripsi_kondisi' => 'Barang Siap Bawa', + 'created_by' => 'Seeder', + 'updated_by' => 'Seeder', + ]); + } +} diff --git a/public/assets/file/Format Import Customer.csv b/public/assets/file/Format Import Customer.csv new file mode 100644 index 0000000..b4845a8 --- /dev/null +++ b/public/assets/file/Format Import Customer.csv @@ -0,0 +1 @@ +name,code_customer,lot_no,no_tlp,email,address diff --git a/resources/views/dashboard/Master_Data/Customer/index.blade.php b/resources/views/dashboard/Master_Data/Customer/index.blade.php index 633241c..7130eeb 100644 --- a/resources/views/dashboard/Master_Data/Customer/index.blade.php +++ b/resources/views/dashboard/Master_Data/Customer/index.blade.php @@ -12,6 +12,10 @@ + Tambah data + + Import Customer + @@ -69,4 +73,42 @@ @else @include('pages.user.Master_Data.Customer.index') @endif + + + @endsection diff --git a/resources/views/dashboard/Master_Data/Manajemen_Peti/Kondisi_Peti/index.blade.php b/resources/views/dashboard/Master_Data/Manajemen_Peti/Kondisi_Peti/index.blade.php index da3869f..ada23b2 100644 --- a/resources/views/dashboard/Master_Data/Manajemen_Peti/Kondisi_Peti/index.blade.php +++ b/resources/views/dashboard/Master_Data/Manajemen_Peti/Kondisi_Peti/index.blade.php @@ -26,23 +26,20 @@ - {{-- @php - $notype = 1; + @php + $nokondisi = 1; @endphp - @forelse ($typepeti as $data_typepeti) + @forelse ($kondisiPeti as $data_kondisiPeti) - {{ $notype++ }} - {{ $data_typepeti->type }} - {{ $data_typepeti->size_peti }} - {{ $data_typepeti->description }} + {{ $nokondisi++ }} + {{ $data_kondisiPeti->nama_kondisi }} + {{ $data_kondisiPeti->deskripsi_kondisi }} - - - - + -
@csrf @method('DELETE') @@ -56,7 +53,7 @@ @empty

Data Kosong

- @endforelse --}} + @endforelse @@ -80,17 +77,17 @@ @csrf
- - - - +
- {{-- @foreach ($role as $data) + @foreach ($kondisiPeti as $data)