diff --git a/app/Http/Controllers/M_assetController.php b/app/Http/Controllers/M_assetController.php index 9e2e019..cd7d875 100644 --- a/app/Http/Controllers/M_assetController.php +++ b/app/Http/Controllers/M_assetController.php @@ -2,14 +2,17 @@ namespace App\Http\Controllers; -use App\Exports\AssetExport; +use Dompdf\Dompdf; use App\Models\m_asset; use Barryvdh\DomPDF\PDF; -use Dompdf\Dompdf; use App\Models\m_warehouse; +use App\Exports\AssetExport; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Facades\Excel; +use Illuminate\Support\Facades\Storage; +// use SimpleSoftwareIO\QrCode\Facades\QrCode; +use SimpleSoftwareIO\QrCode\Facades\QrCode; class M_assetController extends Controller { @@ -36,32 +39,122 @@ class M_assetController extends Controller */ // public function store(Request $request) // { + // $latestAsset = \App\Models\m_asset::latest()->first(); + // // Mendapatkan tahun saat ini + // $currentYear = date("Y"); + // // Menghitung nomor urut untuk kode barang + // if ($latestAsset == null) { + // // Kode pertama + // $nomorUrut = 1; + // } else { + // // Kode berikutnya + // $lastCode = substr($latestAsset->seri, 7); + // $nomorUrut = intval($lastCode) + 1; + // } + // // Menggabungkan semua komponen kode barang + // $seri = 'AST' . $currentYear . str_pad($nomorUrut, STR_PAD_LEFT); + // // Validasi input + // $request->validate([ + // 'name' => 'required', + // 'description' => 'required', + // 'warehouse_id' => 'required', + // 'date' => 'required', + // 'qr_count' => '', + // ]); + // try { + // $currentUser = Auth::user(); + // // Menyiapkan data untuk disimpan + // $validatedData = $request->except('_token'); + // $validatedData['seri'] = $seri; + // $validatedData['created_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai created_by + // $validatedData['updated_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai updated_by + + // // Menyimpan data ke dalam database + // $newAsset = \App\Models\m_asset::create($validatedData); + + // // Membuat QR code dan menyimpannya ke dalam basis data + // $dataForQR = [ + // 'seri' => $newAsset->seri, + // 'name' => $newAsset->name, + // // ... tambahkan lebih banyak data sesuai kebutuhan ... + // ]; + + // $qrCode = QrCode::size(300)->generate(json_encode($dataForQR)); + + // // Menyimpan QR code ke dalam kolom 'qr_code' di tabel asset (perbaikan) + // $newAsset->update(['qr_count' => $qrCode]); + + // return redirect()->back()->with('success', 'Data asset berhasil ditambah.'); + // } catch (\Throwable $th) { + // return redirect()->back()->with('error', 'Data asset gagal ditambah.'); + // } + // } + + // public function store(Request $request) + // { + // $latestAsset = \App\Models\m_asset::latest()->first(); + + // // Mendapatkan tahun saat ini + // $currentYear = date("Y"); + + // // Menghitung nomor urut untuk kode barang + // if ($latestAsset == null) { + // // Kode pertama + // $nomorUrut = 1; + // } else { + // // Kode berikutnya + // $lastCode = substr($latestAsset->seri, 7); + // $nomorUrut = intval($lastCode) + 1; + // } + + // // Menggabungkan semua komponen kode barang + // $seri = 'AST' . $currentYear . str_pad($nomorUrut, STR_PAD_LEFT); + + // // Validasi input // $request->validate([ // 'name' => 'required', // 'description' => 'required', // 'warehouse_id' => 'required', // 'date' => 'required', - // 'qr_count' => 'required', + // 'qr_count' => '', // ]); - // // dd($request); + // try { // $currentUser = Auth::user(); + // // Menyiapkan data untuk disimpan // $validatedData = $request->except('_token'); + // $validatedData['seri'] = $seri; // $validatedData['created_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai created_by // $validatedData['updated_by'] = $currentUser->id; // Menambahkan ID pengguna sebagai updated_by - // dd($validatedData); - // m_asset::create($validatedData); - // return redirect()->back()->with('success', 'Data barang berhasil ditambah.'); + + // // Menyimpan data ke dalam database + // $newAsset = \App\Models\m_asset::create($validatedData); + + // // Generate QR code and save it as an image in the public directory + // $dataForQR = [ + // 'seri' => $newAsset->seri, + // 'name' => $newAsset->name, + // // ... tambahkan lebih banyak data sesuai kebutuhan ... + // ]; + + // $qrCode = QrCode::format('png')->size(300)->generate(json_encode($dataForQR)); + + // // Menyimpan QR code sebagai gambar di direktori penyimpanan publik + // $qrCodePath = 'qr_codes/' . $seri . '.png'; + // Storage::disk('public')->put($qrCodePath, $qrCode); + + // // Menyimpan URL gambar QR code ke dalam kolom 'qr_count' + // $newAsset->update(['qr_count' => $qrCodePath]); + + // return redirect()->back()->with('success', 'Data asset berhasil ditambah.'); // } catch (\Throwable $th) { - // return redirect()->back()->with('error', 'Data barang gagal ditambah.'); + // return redirect()->back()->with('error', 'Data asset gagal ditambah.'); // } - // return redirect()->back()->with('success', 'Data barang berhasil ditambah.'); // } public function store(Request $request) { // dd($request); - // Mendapatkan produk terbaru $latestAsset = \App\Models\m_asset::latest()->first(); // Mendapatkan tahun saat ini $currentYear = date("Y"); @@ -82,7 +175,6 @@ class M_assetController extends Controller 'description' => 'required', 'warehouse_id' => 'required', 'date' => 'required', - 'qr_count' => 'required', ]); try { $currentUser = Auth::user(); @@ -107,6 +199,18 @@ class M_assetController extends Controller public function show($id) { // dd('oke'); + $asset = m_asset::find($id); + $warehouse = m_warehouse::all(); + return view('MasterData.asset.show', compact('asset', 'warehouse')); + } + + // Menampilkan data QR + public function QR($id) + { + $asset = m_asset::find($id); + return QrCode::generate( + 'Hello, World!', + ); } /** diff --git a/composer.json b/composer.json index 35add6e..f5b11e9 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "laravel/framework": "^10.10", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", - "maatwebsite/excel": "^3.1" + "maatwebsite/excel": "^3.1", + "simplesoftwareio/simple-qrcode": "^4.2" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index b8e7377..9aaad52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,62 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "52a35cd301acc3e94305f4149d559010", + "content-hash": "eebc71566b355489dede69a8f81b8d19", "packages": [ + { + "name": "bacon/bacon-qr-code", + "version": "2.0.8", + "source": { + "type": "git", + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/8674e51bb65af933a5ffaf1c308a660387c35c22", + "reference": "8674e51bb65af933a5ffaf1c308a660387c35c22", + "shasum": "" + }, + "require": { + "dasprid/enum": "^1.0.3", + "ext-iconv": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phly/keep-a-changelog": "^2.1", + "phpunit/phpunit": "^7 | ^8 | ^9", + "spatie/phpunit-snapshot-assertions": "^4.2.9", + "squizlabs/php_codesniffer": "^3.4" + }, + "suggest": { + "ext-imagick": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-4": { + "BaconQrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "support": { + "issues": "https://github.com/Bacon/BaconQrCode/issues", + "source": "https://github.com/Bacon/BaconQrCode/tree/2.0.8" + }, + "time": "2022-12-07T17:46:57+00:00" + }, { "name": "barryvdh/laravel-dompdf", "version": "v2.0.1", @@ -219,6 +273,56 @@ ], "time": "2023-08-31T09:50:34+00:00" }, + { + "name": "dasprid/enum", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/DASPRiD/Enum.git", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DASPRiD/Enum/zipball/6faf451159fb8ba4126b925ed2d78acfce0dc016", + "reference": "6faf451159fb8ba4126b925ed2d78acfce0dc016", + "shasum": "" + }, + "require": { + "php": ">=7.1 <9.0" + }, + "require-dev": { + "phpunit/phpunit": "^7 | ^8 | ^9", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "DASPRiD\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "https://dasprids.de/", + "role": "Developer" + } + ], + "description": "PHP 7.1 enum implementation", + "keywords": [ + "enum", + "map" + ], + "support": { + "issues": "https://github.com/DASPRiD/Enum/issues", + "source": "https://github.com/DASPRiD/Enum/tree/1.0.5" + }, + "time": "2023-08-25T16:18:39+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -3958,6 +4062,74 @@ }, "time": "2021-12-11T13:40:54+00:00" }, + { + "name": "simplesoftwareio/simple-qrcode", + "version": "4.2.0", + "source": { + "type": "git", + "url": "https://github.com/SimpleSoftwareIO/simple-qrcode.git", + "reference": "916db7948ca6772d54bb617259c768c9cdc8d537" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SimpleSoftwareIO/simple-qrcode/zipball/916db7948ca6772d54bb617259c768c9cdc8d537", + "reference": "916db7948ca6772d54bb617259c768c9cdc8d537", + "shasum": "" + }, + "require": { + "bacon/bacon-qr-code": "^2.0", + "ext-gd": "*", + "php": ">=7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "~1", + "phpunit/phpunit": "~9" + }, + "suggest": { + "ext-imagick": "Allows the generation of PNG QrCodes.", + "illuminate/support": "Allows for use within Laravel." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "SimpleSoftwareIO\\QrCode\\QrCodeServiceProvider" + ], + "aliases": { + "QrCode": "SimpleSoftwareIO\\QrCode\\Facades\\QrCode" + } + } + }, + "autoload": { + "psr-4": { + "SimpleSoftwareIO\\QrCode\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Simple Software LLC", + "email": "support@simplesoftware.io" + } + ], + "description": "Simple QrCode is a QR code generator made for Laravel.", + "homepage": "https://www.simplesoftware.io/#/docs/simple-qrcode", + "keywords": [ + "Simple", + "generator", + "laravel", + "qrcode", + "wrapper" + ], + "support": { + "issues": "https://github.com/SimpleSoftwareIO/simple-qrcode/issues", + "source": "https://github.com/SimpleSoftwareIO/simple-qrcode/tree/4.2.0" + }, + "time": "2021-02-08T20:43:55+00:00" + }, { "name": "symfony/console", "version": "v6.3.2", diff --git a/database/migrations/2023_09_20_163618_create_m_assets_table.php b/database/migrations/2023_09_20_163618_create_m_assets_table.php index fef152d..5f59556 100644 --- a/database/migrations/2023_09_20_163618_create_m_assets_table.php +++ b/database/migrations/2023_09_20_163618_create_m_assets_table.php @@ -19,7 +19,8 @@ return new class extends Migration $table->bigInteger('warehouse_id')->unsigned(); $table->foreign('warehouse_id')->references('id')->on('m_warehouses'); $table->datetime('date'); - $table->integer('qr_count'); + // $table->integer('qr_count'); + $table->string('qr_count')->nullable(); $table->timestamps(); $table->softDeletes(); $table->string('created_by', 200); diff --git a/resources/views/MasterData/asset.blade.php b/resources/views/MasterData/asset.blade.php index 1549e5e..974ac38 100644 --- a/resources/views/MasterData/asset.blade.php +++ b/resources/views/MasterData/asset.blade.php @@ -57,10 +57,17 @@ {{ $data->description }} {{ $data->warehouse->name }} {{ \Carbon\Carbon::parse($data->date)->format('d-m-Y') }} - {{ $data->qr_count }} + + {!! QrCode::size(80)->generate(route('asset.show', $data->id)) !!} + + + + + + + data-target="#editDataModal{{ $data->id }}"> - + {{-- + onkeypress="return event.charCode >= 48 && event.charCode <= 57" required> --}} +@endsection diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 7067152..821c5c5 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -81,7 +81,8 @@ style="font-size: 13px;"> Reminder Pengembalian -
28
+
+ {{ $reminder }}
diff --git a/resources/views/layouts/main.blade.php b/resources/views/layouts/main.blade.php index 3048404..e1f737e 100644 --- a/resources/views/layouts/main.blade.php +++ b/resources/views/layouts/main.blade.php @@ -48,7 +48,7 @@ diff --git a/routes/web.php b/routes/web.php index 0487b4a..522ec84 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,14 +7,15 @@ use App\Http\Controllers\M_userController; use App\Http\Controllers\M_assetController; use App\Http\Controllers\ProductController; use App\Http\Controllers\ProfileController; +use SimpleSoftwareIO\QrCode\Facades\QrCode; use App\Http\Controllers\PengadaanController; use App\Http\Controllers\TransaksiController; +use App\Http\Controllers\WarehouseController; use App\Http\Controllers\PeminjamanController; use App\Http\Controllers\BarangMasukController; use App\Http\Controllers\BarangKeluarController; use App\Http\Controllers\PengembalianController; use App\Http\Controllers\SettingPlatformController; -use App\Http\Controllers\WarehouseController; /* |-------------------------------------------------------------------------- @@ -43,11 +44,12 @@ Route::middleware('auth')->group(function () { Route::group(['prefix' => 'dashboard'], function () { //Halaman dashboard Route::middleware('auth')->get('', function () { + $reminder = asset_status::whereNull('enter_at')->count(); $jumlahAsset = m_asset::count(); $jumlahPeminjaman = asset_status::count(); // $jumlahPengembalian = asset_status::count(); $jumlahPengembalian = asset_status::whereNotNull('enter_at')->count(); - return view('dashboard.index', compact('jumlahAsset', 'jumlahPeminjaman', 'jumlahPengembalian')); + return view('dashboard.index', compact('jumlahAsset', 'jumlahPeminjaman', 'jumlahPengembalian', 'reminder')); }); //Halaman Transaksi @@ -68,6 +70,13 @@ Route::group(['prefix' => 'dashboard'], function () { Route::get('/hapusAsset/{id}', [M_assetController::class, 'destroy'])->name('hapusAsset.destroy'); Route::get('/assetcetak_pdf', [M_assetController::class, 'cetakpdf'])->name('assetcetakpdf.cetakpdf'); Route::get('/assetexport', [M_assetController::class, 'export'])->name('assetexport.export'); + // Route::get('/assetQR{id}', [M_assetController::class, 'QR'])->name('assetQR.QR'); + // Route::get('assetQR{id}', function () { + // $path = public_path('qrcode/' . time() . '.png'); + + // return QrCode::size(300) + // ->generate('A simple example of QR code', $path); + // })->name('assetQR.QR'); //Halaman Manajemen User Route::middleware('auth')->resource('/user', M_userController::class);