CustomerController.php 4.35 KB
Newer Older
1
<?php
2 3


4 5
namespace App\Http\Controllers;

6
use App\User;
7
use App\Barang;
Yonatan Parapat committed
8
use App\Pembelian;
9 10 11 12 13
use App\RequestBarang;
use App\DataRequest;
use App\Http\Requests;
use Illuminate\Http\Request;

14
use Illuminate\Support\Facades\Auth;
15

16 17
class CustomerController extends Controller
{
Yonatan Parapat committed
18
  
19 20
 	public function BeliBarang()
    {
21 22 23 24
    	$barangs = Barang::all();
        return view('adminlte::customer.BeliBarang.index', compact('barangs'));
    }

Yonatan Parapat committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    public function createPembelian($id)
    {
        $barangs = Barang::where('id', $id)->first();
        return view('adminlte::customer.BeliBarang.createPembelian')->with('barangs', $barangs);
    }

     public function list(){
        // $barangs = Barang::all();
        $key = Input::get('search');
        if(isset($key)){
            $this->data['barang'] = Barang::where('nama_barang','like','%'.$key.'%')->orderBy('id','desc')->paginate(10);
        }else{
            $this->data['barang'] = Barang::orderBy('id','desc')->paginate(10);                   
        }
        $this->data['total'] = DB::table('barangs')->get();               
        return view('adminlte::customer.BeliBarang.index',$this->data);
    }


     public function savePembelian(Request $request)
    {
        $pembelians = new Pembelian();
        $pembelians->user_id = $request->user_id;
        $pembelians->username = $request->username;
        $pembelians->nama_barang = $request->nama_barang;
        $pembelians->kategori = $request->kategori;
        $pembelians->harga =$request->harga;
        $pembelians->jumlah = $request->jumlah;
        $harga = $request->harga;
        $jumlah = $request->jumlah;
        $total_harga = $harga * $jumlah;
        $pembelians->total_harga = $total_harga;
        $pembelians->status_pengantaran = $request->status_pengantaran;
        $pembelians->save();
        return redirect('BeliBarang');
    }


63 64 65
    public function create()
    {
        return view('adminlte::inventori.BeliBarang.create');
66
    }
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
   
    public function store(Request $request)
    {
        $this->validate($request, [
            'nama' => 'required',
            'jumlah' => 'required',
            'harga' => 'required',
            'deskripsi' => 'required',
            'kategori' => 'required',
            'gambar' => 'required',
        ]);

        $barangs = new Barang();
        $barangs->nama = $request['nama'];
        $barangs->jumlah = $request['jumlah'];
        $barangs->harga = $request['harga'];
        $barangs->deskripsi = $request['deskripsi'];
        $barangs->kategori = $request['kategori'];
        $barangs->gambar = $request['gambar'];
        $barangs->save();
        return redirect('BeliBarang');
    }

90 91
  	public function RequestBarang()
    {
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        $data_requests = DataRequest::all();
        return view('adminlte::customer.RequestBarang.index', compact('data_requests'));
    }


    public function createRequest($id)
    {
        $data_requests = DataRequest::where('id', $id)->first();
        return view('adminlte::customer.RequestBarang.createRequest')->with('data_requests', $data_requests);
    }

 


    public function saveRequest(Request $request)
    {
108 109 110 111 112 113 114 115 116 117 118 119 120 121
        $request_barangs = new RequestBarang();
        $request_barangs->user_id = $request->user_id;
        $request_barangs->username = $request->username;
        $request_barangs->nama_barang = $request->nama_barang;
        $request_barangs->kategori = $request->kategori;
        $request_barangs->harga =$request->harga;
        $request_barangs->jumlah = $request->jumlah;
        $harga = $request->harga;
        $jumlah = $request->jumlah;
        $total_harga = $harga * $jumlah;
        $request_barangs->total_harga = $total_harga;
        $request_barangs->status_request = $request->status_request;
        $request_barangs->status_pengantaran = $request->status_pengantaran;
        $request_barangs->save();
122 123 124 125 126 127 128 129 130
        return redirect('RequestBarang');
    }

    public function CheckSaldo()
    {
        $users = User::all();
        return view('adminlte::customer.CheckSaldo.index');
    }
    
Yonatan Parapat committed
131 132 133 134 135
        public function HistoryRequest()
    {
        $request_barangs = RequestBarang::all();
        return view('adminlte::customer.HistoryRequest.index', compact('request_barangs'));
    }
136

Yonatan Parapat committed
137
    public function HistoryPembelian()
138
    {
Yonatan Parapat committed
139 140
        $pembelians = Pembelian::all();
        return view('adminlte::customer.HistoryPembelian.index', compact('pembelians'));
141 142
    }
}