|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers; |
| 4 | + |
| 5 | +use App\Models\Asset; |
| 6 | +use App\Models\AssignAsset; |
| 7 | +use App\Models\Employee; |
| 8 | +use Illuminate\Http\Request; |
| 9 | + |
| 10 | +use App\Http\Requests; |
| 11 | + |
| 12 | +class AssetController extends Controller |
| 13 | +{ |
| 14 | + |
| 15 | + public function addAsset() |
| 16 | + { |
| 17 | + return view('hrms.asset.add_asset'); |
| 18 | + } |
| 19 | + |
| 20 | + Public function processAsset(Request $request) |
| 21 | + { |
| 22 | + |
| 23 | + $asset = new Asset; |
| 24 | + $asset->name = $request->name; |
| 25 | + $asset->description = $request->description; |
| 26 | + $asset->save(); |
| 27 | + \Session::flash('flash_message', 'Asset successfully added!'); |
| 28 | + return redirect()->back(); |
| 29 | + |
| 30 | + } |
| 31 | + public function showAsset() |
| 32 | + { |
| 33 | + $assets = Asset::paginate(5); |
| 34 | + return view('hrms.asset.show_asset', compact('assets')); |
| 35 | + } |
| 36 | + |
| 37 | + public function showEdit($id) |
| 38 | + { |
| 39 | + $result = Asset::whereid($id)->first(); |
| 40 | + return view('hrms.asset.add_asset', compact('result')); |
| 41 | + } |
| 42 | + |
| 43 | + public function doEdit(Request $request, $id) |
| 44 | + { |
| 45 | + $name = $request->name; |
| 46 | + $description = $request->description; |
| 47 | + |
| 48 | + $edit = Asset::findOrFail($id); |
| 49 | + if (!empty($name)) { |
| 50 | + $edit->name = $name; |
| 51 | + } |
| 52 | + if (!empty($description)) { |
| 53 | + $edit->description = $description; |
| 54 | + } |
| 55 | + $edit->save(); |
| 56 | + \Session::flash('flash_message', 'Asset successfully updated!'); |
| 57 | + return redirect('asset-listing'); |
| 58 | + } |
| 59 | + |
| 60 | + public function doDelete($id) |
| 61 | + { |
| 62 | + $asset = Asset::find($id); |
| 63 | + $asset->delete(); |
| 64 | + \Session::flash('flash_message', 'Asset successfully Deleted!'); |
| 65 | + return redirect('asset-listing'); |
| 66 | + } |
| 67 | + public function doAssign() |
| 68 | + { |
| 69 | + $emps = Employee::get(); |
| 70 | + $assets = Asset::get(); |
| 71 | + return view('hrms.asset.assign_asset',compact('emps','assets')); |
| 72 | + } |
| 73 | + public function processAssign(Request $request) |
| 74 | + { |
| 75 | + $assignment = new AssignAsset(); |
| 76 | + $assignment->emp_id = $request->emp_id; |
| 77 | + $assignment->asset_id = $request->asset_id; |
| 78 | + $assignment->doa = date_format(date_create($request->doa), 'Y-m-d'); |
| 79 | + $assignment->dor = date_format(date_create($request->dor), 'Y-m-d'); |
| 80 | + $assignment->save(); |
| 81 | + |
| 82 | + \Session::flash('flash_message', 'Asset successfully assigned!'); |
| 83 | + return redirect()->back(); |
| 84 | + } |
| 85 | + |
| 86 | + public function showAssignment() |
| 87 | + { |
| 88 | + $assets = AssignAsset::with(['employee', 'asset'])->paginate(5); |
| 89 | + return view('hrms.asset.show_assignment', compact('assets')); |
| 90 | + } |
| 91 | + |
| 92 | + public function showEditAssign($id) |
| 93 | + |
| 94 | + { |
| 95 | + $assigns = AssignAsset::with(['employee', 'asset'])->where('id', $id)->first(); |
| 96 | + |
| 97 | + $emps = Employee::get(); |
| 98 | + $assets = Asset::get(); |
| 99 | + return view('hrms.asset.edit_asset_assignment', compact('assigns','emps','assets')); |
| 100 | + } |
| 101 | + |
| 102 | + public function doEditAssign($id,Request $request) |
| 103 | + |
| 104 | + { |
| 105 | + $assignment= AssignAsset::with(['employee', 'asset'])->where('id', $id)->first(); |
| 106 | + $assignment->emp_id = $request->emp_id; |
| 107 | + $assignment->asset_id = $request->asset_id; |
| 108 | + $assignment->doa = date_format(date_create($request->doa), 'Y-m-d'); |
| 109 | + $assignment->dor = date_format(date_create($request->dor), 'Y-m-d'); |
| 110 | + $assignment->save(); |
| 111 | + |
| 112 | + |
| 113 | + \Session::flash('flash_message', 'Asset Assignment successfully updated!'); |
| 114 | + return redirect('assignment-listing'); |
| 115 | + } |
| 116 | + |
| 117 | + |
| 118 | + public function doDeleteAssign($id) |
| 119 | + { |
| 120 | + $assign = AssignAsset::find($id); |
| 121 | + $assign->delete(); |
| 122 | + |
| 123 | + \Session::flash('flash_message', 'Asset Assignment successfully Deleted!'); |
| 124 | + return redirect('assignment-listing'); |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments