Gunawan19621
1 year ago
32 changed files with 364 additions and 519 deletions
@ -1,178 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Dompdf\Dompdf; |
||||
use App\Models\m_asset; |
||||
use BaconQrCode\Writer; |
||||
use Barryvdh\DomPDF\PDF; |
||||
use App\Models\m_warehouse; |
||||
use App\Exports\AssetExport; |
||||
use Illuminate\Http\Request; |
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Support\Facades\Auth; |
||||
use Illuminate\Support\Facades\File; |
||||
use Maatwebsite\Excel\Facades\Excel; |
||||
use BaconQrCode\Renderer\ImageRenderer; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode; |
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle; |
||||
|
||||
|
||||
class M_assetController extends Controller |
||||
{ |
||||
/** |
||||
* Display a listing of the resource. |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$data = [ |
||||
'asset' => m_asset::get(), |
||||
'warehouse' => m_warehouse::all(), |
||||
'active' => 'menu-asset', |
||||
]; |
||||
return view('dashboard.Master_Data.Asset.index', $data); |
||||
} |
||||
|
||||
/** |
||||
* Show the form for creating a new resource. |
||||
*/ |
||||
public function create() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Store a newly created resource in storage. |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$latestAsset = \App\Models\m_asset::latest()->first(); |
||||
$currentYear = date("Y-m-d"); |
||||
if ($latestAsset == null) { |
||||
$nomorUrut = 1; |
||||
} else { |
||||
$lastCode = substr($latestAsset->seri, 7); |
||||
$nomorUrut = intval($lastCode) + 1; |
||||
} |
||||
$seri = 'AST' . $currentYear . '-' . str_pad($nomorUrut, STR_PAD_LEFT); |
||||
$request->validate([ |
||||
'name' => 'required', |
||||
'description' => 'required', |
||||
'warehouse_id' => 'required', |
||||
'date' => 'required', |
||||
'qr_count' => 'nullable' |
||||
]); |
||||
// dd($request); |
||||
try { |
||||
$currentUser = Auth::user(); |
||||
$validatedData = $request->except('_token'); |
||||
$validatedData['seri'] = $seri; |
||||
$validatedData['created_by'] = $currentUser->fullname; |
||||
$validatedData['updated_by'] = $currentUser->fullname; |
||||
\App\Models\m_asset::create($validatedData); |
||||
return redirect()->back()->with('success', 'Data asset berhasil ditambah.'); |
||||
} catch (\Throwable $th) { |
||||
return redirect()->back()->with('error', 'Data asset gagal ditambah.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Display the specified resource. |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
$data = [ |
||||
'asset' => m_asset::find($id), |
||||
'warehouse' => m_warehouse::all(), |
||||
'active' => 'menu-asset', |
||||
]; |
||||
return view('dashboard.Master_Data.Asset.show', $data); |
||||
} |
||||
|
||||
// Menampilkan data QR |
||||
// public function QR($id) |
||||
// { |
||||
// $asset = m_asset::find($id); |
||||
// return QrCode::generate( |
||||
// 'Hello, World!', |
||||
// ); |
||||
// } |
||||
|
||||
/** |
||||
* Show the form for editing the specified resource. |
||||
*/ |
||||
public function edit() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Update the specified resource in storage. |
||||
*/ |
||||
public function update(Request $request, $id) |
||||
{ |
||||
$request->validate([ |
||||
'name' => 'required', |
||||
'description' => 'required', |
||||
'warehouse_id' => 'required', |
||||
'date' => 'required', |
||||
]); |
||||
try { |
||||
$asset = m_asset::findOrFail($id); |
||||
$asset->update($request->all()); |
||||
return redirect()->back()->with('success', 'Data asset berhasil diperbaharui'); |
||||
} catch (\Throwable $th) { |
||||
return redirect()->back()->with('error', 'Data asset gagal diperbaharui'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Remove the specified resource from storage. |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
// dd("oke"); |
||||
try { |
||||
$asset = m_asset::findOrFail($id); |
||||
$asset->delete(); |
||||
return redirect()->back()->with('success', 'Data asset berhasil dihapus'); |
||||
} catch (\Throwable $th) { |
||||
return redirect()->back()->with('error', 'Data asset gagal dihapus'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Cetak PDF. |
||||
*/ |
||||
public function cetakpdf() |
||||
{ |
||||
// dd('oke'); |
||||
$asset = m_asset::all(); |
||||
|
||||
// Buat objek Dompdf |
||||
$dompdf = new Dompdf(); |
||||
// Render tampilan ke PDF |
||||
$html = view('dashboard.Master_Data.Asset.asset_pdf', compact('asset'))->render(); |
||||
|
||||
// Muat HTML ke Dompdf |
||||
$dompdf->loadHtml($html); |
||||
|
||||
// Atur ukuran dan orientasi kertas |
||||
$dompdf->setPaper('A4', 'portrait'); |
||||
|
||||
// Render PDF |
||||
$dompdf->render(); |
||||
|
||||
// Tampilkan PDF di browser |
||||
return $dompdf->stream('Laporan Assets'); |
||||
} |
||||
|
||||
/** |
||||
* Cetak Exel. |
||||
*/ |
||||
public function export() |
||||
{ |
||||
return Excel::download(new AssetExport, 'Laporan Assets.xlsx'); |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Requests\Transfer; |
||||
|
||||
use Illuminate\Foundation\Http\FormRequest; |
||||
|
||||
class ValidasiCreateTransfer extends FormRequest |
||||
{ |
||||
/** |
||||
* Determine if the user is authorized to make this request. |
||||
*/ |
||||
public function authorize(): bool |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Get the validation rules that apply to the request. |
||||
* |
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
||||
*/ |
||||
public function rules(): array |
||||
{ |
||||
return [ |
||||
'peti_id' => 'nullable', // Optional, peti_id harus ada di tabel petis |
||||
'source_warehouse' => 'nullable', // Optional, source_warehouse harus ada di tabel m_warehouses |
||||
'destination_warehouse' => 'nullable', // Optional, destination_warehouse harus ada di tabel m_warehouses |
||||
'name_customer' => 'nullable', // Optional, name_customer harus ada di tabel customers |
||||
'date' => 'nullable', // Optional, harus berupa tanggal |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Requests\Transfer; |
||||
|
||||
use Illuminate\Foundation\Http\FormRequest; |
||||
|
||||
class ValidasiUpdateTransfer extends FormRequest |
||||
{ |
||||
/** |
||||
* Determine if the user is authorized to make this request. |
||||
*/ |
||||
public function authorize(): bool |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Get the validation rules that apply to the request. |
||||
* |
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
||||
*/ |
||||
public function rules(): array |
||||
{ |
||||
return [ |
||||
// |
||||
]; |
||||
} |
||||
} |
@ -1,27 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use App\Traits\UUID; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
||||
class BarangKeluar extends Model |
||||
{ |
||||
use HasFactory, UUID; |
||||
protected $table = 'barang_keluars'; |
||||
|
||||
protected $fillable = [ |
||||
'asset_id', |
||||
'jumlah', |
||||
'tanggal_keluar', |
||||
'penerima_barang', |
||||
'exit_warehouse', |
||||
'keterangan', |
||||
]; |
||||
|
||||
public function asset() |
||||
{ |
||||
return $this->belongsTo(m_asset::class, 'asset_id'); |
||||
} |
||||
} |
@ -1,24 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use App\Traits\UUID; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
||||
class BarangMasuk extends Model |
||||
{ |
||||
use HasFactory, UUID; |
||||
protected $table = 'barang_masuks'; |
||||
|
||||
protected $fillable = [ |
||||
'asset_id', |
||||
'jumlah', |
||||
'tanggal_masuk', |
||||
'asal_barang', |
||||
'pengiriman_barang', |
||||
'penerima_barang', |
||||
'enter_warehouse', |
||||
'keterangan', |
||||
]; |
||||
} |
@ -1,30 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use App\Traits\UUID; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
||||
class m_asset extends Model |
||||
{ |
||||
use HasFactory, SoftDeletes, UUID; |
||||
protected $table = 'm_assets'; |
||||
|
||||
protected $fillable = [ |
||||
'seri', |
||||
'name', |
||||
'description', |
||||
'warehouse_id', |
||||
'date', |
||||
'qr_count', |
||||
'created_by', |
||||
'updated_by', |
||||
]; |
||||
|
||||
public function warehouse() |
||||
{ |
||||
return $this->belongsTo(m_warehouse::class, 'warehouse_id'); |
||||
} |
||||
} |
@ -1,38 +0,0 @@
|
||||
<?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 |
||||
{ |
||||
Schema::create('m_assets', function (Blueprint $table) { |
||||
$table->uuid('id')->primary(); |
||||
$table->string('seri', 50)->nullable(); |
||||
$table->string('name', 200)->nullable(); |
||||
$table->text('description')->nullable(); |
||||
// $table->unsignedBigInteger('warehouse_id')->nullable(); |
||||
// $table->foreign('warehouse_id')->references('id')->on('m_warehouses')->onDelete('set null'); |
||||
$table->foreignUuid('warehouse_id')->nullable()->constrained('m_warehouses')->onDelete('set null'); |
||||
$table->date('date')->nullable(); |
||||
$table->string('qr_count', 255)->nullable(); |
||||
$table->timestamps(); |
||||
$table->softDeletes(); |
||||
$table->string('created_by', 200)->nullable(); |
||||
$table->string('updated_by', 200)->nullable(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Reverse the migrations. |
||||
*/ |
||||
public function down(): void |
||||
{ |
||||
Schema::dropIfExists('m_assets'); |
||||
} |
||||
}; |
@ -1,37 +0,0 @@
|
||||
<?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 |
||||
{ |
||||
Schema::create('barang_masuks', function (Blueprint $table) { |
||||
$table->uuid('id')->primary(); |
||||
// $table->bigInteger('asset_id')->unsigned()->nullable(); |
||||
// $table->foreign('asset_id')->references('id')->on('m_assets')->onDelete('set null'); |
||||
$table->foreignUuid('asset_id')->nullable()->constrained('m_assets')->onDelete('set null'); |
||||
$table->integer('jumlah')->nullable(); |
||||
$table->date('tanggal_masuk')->nullable(); |
||||
$table->string('asal_barang', 200)->nullable(); |
||||
$table->string('pengiriman_barang', 200)->nullable(); |
||||
$table->string('penerima_barang', 200)->nullable(); |
||||
$table->string('enter_warehouse', 200)->nullable(); |
||||
$table->string('keterangan', 255)->nullable(); |
||||
$table->timestamps(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Reverse the migrations. |
||||
*/ |
||||
public function down(): void |
||||
{ |
||||
Schema::dropIfExists('barang_masuks'); |
||||
} |
||||
}; |
@ -1,36 +0,0 @@
|
||||
<?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 |
||||
{ |
||||
Schema::create('barang_keluars', function (Blueprint $table) { |
||||
$table->uuid('id')->primary(); |
||||
// $table->bigInteger('assets_id')->unsigned()->nullable(); |
||||
// $table->foreign('assets_id')->references('id')->on('m_assets')->onDelete('set null'); |
||||
$table->foreignUuid('assets_id')->nullable()->constrained('m_assets')->onDelete('set null'); |
||||
|
||||
$table->integer('jumlah')->nullable(); |
||||
$table->date('tanggal_keluar')->nullable(); |
||||
$table->string('penerima_barang', 200)->nullable(); |
||||
$table->string('exit_warehouse', 200)->nullable(); |
||||
$table->string('keterangan', 255)->nullable(); |
||||
$table->timestamps(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Reverse the migrations. |
||||
*/ |
||||
public function down(): void |
||||
{ |
||||
Schema::dropIfExists('barang_keluars'); |
||||
} |
||||
}; |
@ -0,0 +1,55 @@
|
||||
<?php |
||||
|
||||
namespace Database\Seeders; |
||||
|
||||
use Illuminate\Support\Str; |
||||
use Illuminate\Database\Seeder; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents; |
||||
|
||||
class PetiSeeder extends Seeder |
||||
{ |
||||
/** |
||||
* Run the database seeds. |
||||
*/ |
||||
// public function run(): void |
||||
// { |
||||
// // |
||||
// } |
||||
public function run() |
||||
{ |
||||
// Generate 5 dummy data |
||||
for ($i = 0; $i < 5; $i++) { |
||||
DB::table('petis')->insert([ |
||||
'id' => Str::uuid(), |
||||
'id_incre' => $i + 1, // Increment id_incre from 1 to 5 |
||||
'tipe_peti_id' => $this->getRandomId('type_petis'), |
||||
'warna' => 'Dummy Warna ' . ($i + 1), |
||||
'fix_lot' => 'Dummy Fix Lot ' . ($i + 1), |
||||
'packing_no' => rand(1, 100), |
||||
'customer_id' => $this->getRandomId('customers'), |
||||
'jumlah' => rand(1, 10), |
||||
'date_pembuatan' => now(), |
||||
'warehouse_id' => $this->getRandomId('m_warehouses'), |
||||
'kondisipeti_id' => $this->getRandomId('kondisi_petis'), |
||||
'created_at' => now(), |
||||
'updated_at' => now(), |
||||
'created_by' => 'Seeder', |
||||
'updated_by' => 'Seeder', |
||||
]); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Get a random ID from a specific table |
||||
* |
||||
* @param string $tableName |
||||
* @return string|null |
||||
*/ |
||||
private function getRandomId($tableName) |
||||
{ |
||||
$record = DB::table($tableName)->inRandomOrder()->first(); |
||||
|
||||
return $record ? $record->id : null; |
||||
} |
||||
} |
Loading…
Reference in new issue