Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| SupplierController | |
0.00% |
0 / 60 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
20 | |||
| show | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| edit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
12 | |||
| destroy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\admin; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Models\admin\Supplier; |
| 7 | use App\Service\PosService; |
| 8 | use App\Traits\PosTrait; |
| 9 | use Illuminate\Http\Request; |
| 10 | use Illuminate\Http\Response; |
| 11 | use Illuminate\Support\Facades\Auth; |
| 12 | use Illuminate\Support\Facades\DB; |
| 13 | use Illuminate\Validation\Rule; |
| 14 | |
| 15 | class SupplierController extends Controller |
| 16 | { |
| 17 | use PosTrait; |
| 18 | |
| 19 | /** |
| 20 | * Display a listing of the resource. |
| 21 | * |
| 22 | * @return Response |
| 23 | */ |
| 24 | public function index() |
| 25 | { |
| 26 | $data['suppliers'] = Supplier::query()->orderByDesc('id')->cursor(); |
| 27 | |
| 28 | return view('admin.supplier.manage-supplier')->with($data); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Show the form for creating a new resource. |
| 33 | * |
| 34 | * @return Response |
| 35 | */ |
| 36 | public function create() |
| 37 | { |
| 38 | // |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Store a newly created resource in storage. |
| 43 | * |
| 44 | * @return Response |
| 45 | */ |
| 46 | public function store(Request $request) |
| 47 | { |
| 48 | $data['request'] = $request->validate([ |
| 49 | 'name' => ['required', Rule::unique('suppliers', 'name')], |
| 50 | 'logo' => 'image|mimes:jpg,jpeg,png,svg', |
| 51 | 'email' => ['email', 'nullable'], |
| 52 | 'contact' => 'required', |
| 53 | 'details' => 'nullable', |
| 54 | 'address' => 'required', |
| 55 | ]); |
| 56 | |
| 57 | try { |
| 58 | DB::beginTransaction(); |
| 59 | $data['value'] = |
| 60 | [ |
| 61 | 'created_by' => Auth::user()->id, |
| 62 | 'supplier_code' => 'supplier-' . rand(0, 99999), |
| 63 | ]; |
| 64 | $data = array_merge($data['value'], $data['request']); |
| 65 | $supplier = Supplier::query()->create($data); |
| 66 | if ($request->hasFile('logo')) { |
| 67 | $data['logo'] = $this->FileProcessing($request->file('logo'), PosService::SUPPLIER_LOGO, 200, 100); |
| 68 | $supplier->update(['logo' => $data['logo']]); |
| 69 | } |
| 70 | session()->flash('success', 'Supplier Successfully Inserted'); |
| 71 | DB::commit(); |
| 72 | if ($request->p_page == 'p_page') { |
| 73 | session()->put('supplier', $supplier->id); |
| 74 | |
| 75 | return redirect()->route('admin.purchase.create', ['supplier' => $supplier->id]); |
| 76 | } |
| 77 | |
| 78 | return redirect()->back(); |
| 79 | } catch (\Throwable $e) { |
| 80 | DB::rollBack(); |
| 81 | report($e); |
| 82 | |
| 83 | return back()->withInput()->with('error', 'Could not save the supplier.'); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Display the specified resource. |
| 89 | * |
| 90 | * @param \App\Models\Supplier $supplier |
| 91 | * @return Response |
| 92 | */ |
| 93 | public function show(Supplier $supplier) {} |
| 94 | |
| 95 | /** |
| 96 | * Show the form for editing the specified resource. |
| 97 | * |
| 98 | * @param \App\Models\Supplier $supplier |
| 99 | * @return Response |
| 100 | */ |
| 101 | public function edit(Supplier $supplier) |
| 102 | { |
| 103 | // |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Update the specified resource in storage. |
| 108 | * |
| 109 | * @param \App\Models\Supplier $supplier |
| 110 | * @return Response |
| 111 | */ |
| 112 | public function update(Request $request, Supplier $supplier) |
| 113 | { |
| 114 | $data['request'] = $request->validate([ |
| 115 | 'name' => ['required', Rule::unique('suppliers', 'name')->ignore($supplier->id)], |
| 116 | 'logo' => 'image|mimes:jpg,jpeg,png,svg', |
| 117 | 'email' => ['email', 'nullable'], |
| 118 | 'contact' => 'required', |
| 119 | 'details' => 'nullable', |
| 120 | 'address' => 'required', |
| 121 | ]); |
| 122 | |
| 123 | try { |
| 124 | DB::beginTransaction(); |
| 125 | $data['value'] = |
| 126 | [ |
| 127 | 'created_by' => Auth::user()->id, |
| 128 | 'supplier_code' => 'supplier-' . rand(0, 99999), |
| 129 | ]; |
| 130 | $data = array_merge($data['value'], $data['request']); |
| 131 | if ($request->hasFile('logo')) { |
| 132 | $data['logo'] = $this->FileProcessing($request->file('logo'), PosService::SUPPLIER_LOGO, 200, 100); |
| 133 | } |
| 134 | $supplier->update($data); |
| 135 | |
| 136 | session()->flash('success', 'Supplier Successfully Updated'); |
| 137 | DB::commit(); |
| 138 | |
| 139 | return redirect()->back(); |
| 140 | } catch (\Throwable $e) { |
| 141 | DB::rollBack(); |
| 142 | report($e); |
| 143 | |
| 144 | return back()->withInput()->with('error', 'Could not update the supplier.'); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Remove the specified resource from storage. |
| 150 | * |
| 151 | * @param \App\Models\Supplier $supplier |
| 152 | * @return Response |
| 153 | */ |
| 154 | public function destroy(Supplier $supplier) |
| 155 | { |
| 156 | // |
| 157 | } |
| 158 | } |