Commit edd3b7c7 by jhon

Pembelian dan Request Barang

parent f2274a90
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $fillable = [
'name', 'email', 'username','password','saldo',
];
}
...@@ -3,14 +3,20 @@ ...@@ -3,14 +3,20 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\User;
use App\Barang; use App\Barang;
use App\Pembelian;
use App\RequestBarang; use App\RequestBarang;
use App\DataRequest; use App\DataRequest;
use App\Http\Requests; use App\Http\Requests;
use Illuminate\Http\Request; use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use App\User;
class CustomerController extends Controller class CustomerController extends Controller
{ {
...@@ -23,36 +29,43 @@ class CustomerController extends Controller ...@@ -23,36 +29,43 @@ class CustomerController extends Controller
$barangs = Barang::all(); $barangs = Barang::all();
return view('adminlte::customer.BeliBarang.index', compact('barangs')); return view('adminlte::customer.BeliBarang.index', compact('barangs'));
} }
public function create() public function createPembelian($id)
{ {
return view('adminlte::inventori.BeliBarang.create'); $barangs = Barang::where('id', $id)->first();
return view('adminlte::customer.BeliBarang.createPembelian')->with('barangs', $barangs);
} }
public function store(Request $request) public function savePembelian(Request $request)
{ {
$this->validate($request, [ $pembelians = new Pembelian();
'nama' => 'required', $pembelians->user_id = $request->user_id;
'jumlah' => 'required', $pembelians->username = $request->username;
'harga' => 'required', $pembelians->nama_barang = $request->nama_barang;
'deskripsi' => 'required', $pembelians->kategori = $request->kategori;
'kategori' => 'required', $pembelians->harga =$request->harga;
'gambar' => 'required', $pembelians->jumlah = $request->jumlah;
]); $harga = $request->harga;
$jumlah = $request->jumlah;
$barangs = new Barang(); $total_harga = $harga * $jumlah;
$barangs->nama = $request['nama']; $pembelians->total_harga = $total_harga;
$barangs->jumlah = $request['jumlah']; $pembelians->status_pengantaran = $request->status_pengantaran;
$barangs->harga = $request['harga']; $pembelians->save();
$barangs->deskripsi = $request['deskripsi'];
$barangs->kategori = $request['kategori'];
$barangs->gambar = $request['gambar'];
$barangs->save();
return redirect('BeliBarang'); return redirect('BeliBarang');
} }
public function cariBarang(){
$key = Input::get('search');
if(isset($key)){
$this->data['barangs'] = Barang::where('nama_barang','like','%'.$key.'%')->orderBy('id','desc')->paginate(10);
}else{
$this->data['barangs'] = Barang::orderBy('id','desc')->paginate(10);
}
return view('adminlte::customer.BeliBarang.index',$this->data);
}
//----------------------------Data Request----------------------// //----------------------------Data Request----------------------//
...@@ -63,16 +76,13 @@ class CustomerController extends Controller ...@@ -63,16 +76,13 @@ class CustomerController extends Controller
return view('adminlte::customer.RequestBarang.index', compact('data_requests')); return view('adminlte::customer.RequestBarang.index', compact('data_requests'));
} }
public function createRequest($id) public function createRequest($id)
{ {
$data_requests = DataRequest::where('id', $id)->first(); $data_requests = DataRequest::where('id', $id)->first();
// dd($data_requests);
return view('adminlte::customer.RequestBarang.createRequest')->with('data_requests', $data_requests); return view('adminlte::customer.RequestBarang.createRequest')->with('data_requests', $data_requests);
} }
public function saveRequest(Request $request) public function saveRequest(Request $request)
{ {
$request_barangs = new RequestBarang(); $request_barangs = new RequestBarang();
...@@ -96,18 +106,28 @@ class CustomerController extends Controller ...@@ -96,18 +106,28 @@ class CustomerController extends Controller
//----------------------------Check Saldo----------------------------// //----------------------------Check Saldo----------------------------//
public function CheckSaldo() public function CheckSaldo()
{ {
$users = User::all();
return view('adminlte::customer.CheckSaldo.index'); return view('adminlte::customer.CheckSaldo.index');
} }
//----------------------------Histori Transaksi----------------------// //----------------------------Histori Transaksi----------------------//
public function HistoryTransaksi() public function HistoryRequest()
{
$username = Auth::user()->username;
$user = DB::table('users')->where('username' , $username)->first();
$id = $user->id;
$this->data['request_barang'] = DB::table('request_barangs')->where('user_id','=',$id)->get();
return view('adminlte::customer.HistoryRequest.index', $this->data);
}
public function HistoryPembelian()
{ {
$request_barangs = RequestBarang::all(); $username = Auth::user()->username;
return view('adminlte::customer.HistoryTransaksi.index')->with('request_barangs', $request_barangs); $user = DB::table('users')->where('username' , $username)->first();
$id = $user->id;
$this->data['pembelian'] = DB::table('pembelians')->where('user_id','=',$id)->get();
// dd($this->data);
return view('adminlte::customer.HistoryPembelian.index', $this->data);
} }
} }
\ No newline at end of file
...@@ -4,10 +4,14 @@ namespace App; ...@@ -4,10 +4,14 @@ namespace App;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Petugas extends Model class Pembelian extends Model
{ {
protected $table = 'petugass'; protected $table = 'pembelians';
protected $fillable = [ protected $fillable = [
'name', 'email', 'username','password', 'username','nama_barang', 'kategori','jumlah','total_harga','user_id','status_pengantaran',
]; ];
public function user(){
return $this->belongsTo(User::class);
}
} }
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Transaksi extends Model
{
protected $fillable = [
'username', 'nama_barang', 'kategori','jumlah','total_harga','status_pengantaran',
];
}
@extends('adminlte::layouts.app')
@section('htmlheader_title')
Create
@endsection
@section('contentheader_title')
Page Request Barang
@endsection
@section('main-content')
<div class="container">
<div class="row">
<!-- edit form column -->
<form class="form-horizontal" role="form" method="POST" action="{{url('/savePembelian')}}" >
{!! csrf_field() !!}
<div class="col-md-9 personal-info">
<div class="form-group">
<label class="col-md-4 control-label">User ID</label>
<div class="col-lg-6">
<input name="user_id" class="form-control" type="integer" value="{{$user->id}}" readonly>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Username</label>
<div class="col-lg-6">
<input name="username" class="form-control" type="text" value="{{$user->username}}" readonly>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Nama Barang</label>
<div class="col-md-6">
<input name="nama_barang" class="form-control" type="text" value="{{$barangs->nama_barang}}" readonly>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Kategori</label>
<div class="col-md-6">
<input name="kategori" class="form-control" type="text" value="{{$barangs->kategori}}" readonly>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Harga</label>
<div class="col-md-6">
<input name="harga" class="form-control" type="integer" value="{{$barangs->harga}}" readonly>
</div>
</div>
<div class="form-group{{ $errors->has('jumlah') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Jumlah</label>
<div class="col-md-6">
<input type="number" onkeyup="Harga(this.value)" min="1" class="form-control" name="jumlah" value="{{ old('jumlah') }} " required>
@if ($errors->has('jumlah'))
<span class="help-block">
<strong>{{ $errors->first('jumlah') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('total_harga') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Total Harga</label>
<div class="col-md-6">
<span class="form-control" id="total_harga" name="total_harga" value="{{ old('total_harga') }}"></span>
</div>
</div>
<div class="form-group{{ $errors->has('status_pengantaran') ? ' has-error' : '' }}">
<label for="title" class="col-md-4 control-label">Status Pengantaran</label>
<div class="col-md-6">
<select name="status_pengantaran" class="form-control">
<option value="Belum">Belum</option>
</select>
@if ($errors->has('status_pengantaran'))
<span class="help-block">
<strong>{{ $errors->first('status_pengantaran') }}</strong>
</span>
@endif
</div>
</div>
</div>
<div class="col-md-9">
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input type="submit" class="btn btn-primary" value="Save Changes">
<span></span>
</div>
</div>
</div>
</form>
</div>
</div>
<script>function Harga(str)
{
document.getElementById("total_harga").innerHTML = str*{{$barangs->harga}};
return;
}
</script>
@endsection
...@@ -5,10 +5,29 @@ ...@@ -5,10 +5,29 @@
@endsection @endsection
@section('contentheader_title') @section('contentheader_title')
<form action="{{url('/cariBarang')}}">
<div class="form-group">
<label style="margin: 20px 20px 0;font-size: 15px">Search by Username</label>
<input type="text" name="search" placeholder="Nama Barang" id="search" class="form-control" style="font-size: 15px;color:white;background-color:rgba(0,0,0,0.4)"/>
</div>
</form>
<!-- <form action="{{url('/customer/menu')}}">
<div class="form-group">
<label style="margin: 20px 20px 0;font-size: 15px">Search by Nama Menu</label>
<input type="text" name="search" placeholder="Nama Menu" id="search" class="form-control" style="font-size: 15px;color:white;background-color:rgba(0,0,0,0.4)"/>
</div>
<button type="submit" id="button-filter" class="btn btn-danger pull-right" style="margin-right: 20px">
<i class="fa fa-search"></i> Search
</button>
</form> -->
<center>Beli Barang</center> <center>Beli Barang</center>
@endsection @endsection
@section('main-content') @section('main-content')
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
...@@ -24,13 +43,13 @@ ...@@ -24,13 +43,13 @@
<tbody> <tbody>
@foreach($barangs as $barang) @foreach($barangs as $barang)
<tr> <tr>
<td>{{$barang->nama}}</td> <td>{{$barang->nama_barang}}</td>
<td>{{$barang->jumlah}}</td> <td>{{$barang->stock}}</td>
<td>{{$barang->harga}}</td> <td>{{$barang->harga}}</td>
<td>{{$barang->kategori}}</td> <td>{{$barang->kategori}}</td>
<td>{{$barang->gambar}}</td> <td>{{$barang->gambar}}</td>
<td> <td>
<a href="{{ url('/beli', $barang->id) }}" type="submit" button type="button" class="btn btn-warning">Beli</a> <a href="{{ url('/createPembelian', $barang->id) }}" type="submit" button type="button" class="btn btn-warning">Beli</a>
<!-- <a href="{{ url('/delete', $barang->id) }}" <onclick="return confirm('Yakin mau hapus data ini sob?')" class="btn btn-warning">Delete</a> --> <!-- <a href="{{ url('/delete', $barang->id) }}" <onclick="return confirm('Yakin mau hapus data ini sob?')" class="btn btn-warning">Delete</a> -->
</tr> </tr>
@endforeach @endforeach
......
@extends('adminlte::layouts.app')
@section('htmlheader_title')
{{ trans('adminlte_lang::message.home') }}
@endsection
@section('contentheader_title')
<center>Histori Transaksi</center>
@endsection
@section('main-content')
<table class="table table-striped">
<thead>
<tr>
<th>Username</th>
<th>Nama Barang</th>
<th>Kategori</th>
<th>Harga</th>
<th>Jumlah</th>
<th>Total Harga</th>
<th>Pengantaran</th>
</tr>
</thead>
<tbody>
@foreach($pembelian as $pembelians)
<tr>
<td>{{$pembelians->username}}</td>
<td>{{$pembelians->nama_barang}}</td>
<td>{{$pembelians->kategori}}</td>
<td>{{$pembelians->harga}}</td>
<td>{{$pembelians->jumlah}}</td>
<td>{{$pembelians->total_harga}}</td>
<td>{{$pembelians->status_pengantaran}}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
...@@ -14,24 +14,24 @@ ...@@ -14,24 +14,24 @@
<tr> <tr>
<th>Username</th> <th>Username</th>
<th>Nama Barang</th> <th>Nama Barang</th>
<th>Kategori</th>
<th>Harga</th> <th>Harga</th>
<th>Jumlah</th> <th>Jumlah</th>
<th>Total Harga</th> <th>Total Harga</th>
<th>Status Request</th> <th>Status Request</th>
<th>Pengantaran</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($request_barangs as $requestBarang) @foreach($request_barang as $requestBarang)
<tr> <tr>
<td>{{$requestBarang->username}}</td> <td>{{$requestBarang->username}}</td>
<td>{{$requestBarang->nama_barang}}</td> <td>{{$requestBarang->nama_barang}}</td>
<td>{{$requestBarang->kategori}}</td>
<td>{{$requestBarang->harga}}</td> <td>{{$requestBarang->harga}}</td>
<td>{{$requestBarang->jumlah}}</td> <td>{{$requestBarang->jumlah}}</td>
<td>{{$requestBarang->total_harga}}</td> <td>{{$requestBarang->total_harga}}</td>
<td>{{$requestBarang->status_request}}</td> <td>{{$requestBarang->status_request}}</td>
<td>{{$requestBarang->status_pengantaran}}</td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
......
...@@ -40,7 +40,8 @@ ...@@ -40,7 +40,8 @@
<li><a href="{{ url('/BeliBarang') }}"><i class='fa fa-link'></i> <span>Beli Barang</span></a></li> <li><a href="{{ url('/BeliBarang') }}"><i class='fa fa-link'></i> <span>Beli Barang</span></a></li>
<li><a href="{{ url('/RequestBarang') }}"><i class='fa fa-link'></i> <span>Request Barang</span></a></li> <li><a href="{{ url('/RequestBarang') }}"><i class='fa fa-link'></i> <span>Request Barang</span></a></li>
<li><a href="{{ url('/CheckSaldo') }}"><i class='fa fa-link'></i> <span>Check Saldo</span></a></li> <li><a href="{{ url('/CheckSaldo') }}"><i class='fa fa-link'></i> <span>Check Saldo</span></a></li>
<li><a href="{{ url('/HistoryTransaksi') }}"><i class='fa fa-link'></i> <span>History Transaksi</span></a></li> <li><a href="{{ url('/HistoryPembelian') }}"><i class='fa fa-link'></i> <span>History Pembelian</span></a></li>
<li><a href="{{ url('/HistoryRequest') }}"><i class='fa fa-link'></i> <span>History Request</span></a></li>
@elseif(Auth::user()->status=="inventori") @elseif(Auth::user()->status=="inventori")
......
...@@ -51,6 +51,11 @@ Route::group(['middleware' => ['web','auth','admin']], function () { ...@@ -51,6 +51,11 @@ Route::group(['middleware' => ['web','auth','admin']], function () {
Route::group(['middleware' => ['web','auth','customer']], function () { Route::group(['middleware' => ['web','auth','customer']], function () {
Route::get('/BeliBarang', 'CustomerController@BeliBarang'); Route::get('/BeliBarang', 'CustomerController@BeliBarang');
Route::get('/createPembelian/{id}', 'CustomerController@createPembelian');
Route::post('/storePembelian', 'CustomerController@storePembelian');
Route::post('/savePembelian', 'CustomerController@savePembelian');
Route::get('/cariBarang','CustomerController@cariBarang');
Route::get('/CheckSaldo', 'CustomerController@CheckSaldo'); Route::get('/CheckSaldo', 'CustomerController@CheckSaldo');
...@@ -58,7 +63,10 @@ Route::group(['middleware' => ['web','auth','customer']], function () { ...@@ -58,7 +63,10 @@ Route::group(['middleware' => ['web','auth','customer']], function () {
Route::get('/createRequest/{id}', 'CustomerController@createRequest'); Route::get('/createRequest/{id}', 'CustomerController@createRequest');
Route::post('/storeRequest', 'CustomerController@storeRequest'); Route::post('/storeRequest', 'CustomerController@storeRequest');
Route::post('/saveRequest', 'CustomerController@saveRequest'); Route::post('/saveRequest', 'CustomerController@saveRequest');
Route::get('/HistoryTransaksi', 'CustomerController@HistoryTransaksi');
Route::get('/HistoryPembelian', 'CustomerController@HistoryPembelian');
Route::get('/HistoryRequest', 'CustomerController@HistoryRequest');
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment