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 @@
namespace App\Http\Controllers;
use App\User;
use App\Barang;
use App\Pembelian;
use App\RequestBarang;
use App\DataRequest;
use App\Http\Requests;
use Illuminate\Http\Request;
use DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use App\User;
class CustomerController extends Controller
{
......@@ -24,35 +30,42 @@ class CustomerController extends Controller
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, [
'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();
$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');
}
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----------------------//
......@@ -63,16 +76,13 @@ class CustomerController extends Controller
return view('adminlte::customer.RequestBarang.index', compact('data_requests'));
}
public function createRequest($id)
{
$data_requests = DataRequest::where('id', $id)->first();
// dd($data_requests);
return view('adminlte::customer.RequestBarang.createRequest')->with('data_requests', $data_requests);
}
public function saveRequest(Request $request)
{
$request_barangs = new RequestBarang();
......@@ -96,18 +106,28 @@ class CustomerController extends Controller
//----------------------------Check Saldo----------------------------//
public function CheckSaldo()
{
$users = User::all();
return view('adminlte::customer.CheckSaldo.index');
}
//----------------------------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();
return view('adminlte::customer.HistoryTransaksi.index')->with('request_barangs', $request_barangs);
$username = Auth::user()->username;
$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;
use Illuminate\Database\Eloquent\Model;
class Petugas extends Model
class Pembelian extends Model
{
protected $table = 'petugass';
protected $table = 'pembelians';
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 @@
@endsection
@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>
@endsection
@section('main-content')
<table class="table table-striped">
<thead>
<tr>
......@@ -24,13 +43,13 @@
<tbody>
@foreach($barangs as $barang)
<tr>
<td>{{$barang->nama}}</td>
<td>{{$barang->jumlah}}</td>
<td>{{$barang->nama_barang}}</td>
<td>{{$barang->stock}}</td>
<td>{{$barang->harga}}</td>
<td>{{$barang->kategori}}</td>
<td>{{$barang->gambar}}</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> -->
</tr>
@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 @@
<tr>
<th>Username</th>
<th>Nama Barang</th>
<th>Kategori</th>
<th>Harga</th>
<th>Jumlah</th>
<th>Total Harga</th>
<th>Status Request</th>
<th>Pengantaran</th>
</tr>
</thead>
<tbody>
@foreach($request_barangs as $requestBarang)
@foreach($request_barang as $requestBarang)
<tr>
<td>{{$requestBarang->username}}</td>
<td>{{$requestBarang->nama_barang}}</td>
<td>{{$requestBarang->kategori}}</td>
<td>{{$requestBarang->harga}}</td>
<td>{{$requestBarang->jumlah}}</td>
<td>{{$requestBarang->total_harga}}</td>
<td>{{$requestBarang->status_request}}</td>
<td>{{$requestBarang->status_pengantaran}}</td>
</tr>
@endforeach
</tbody>
......
......@@ -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('/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('/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")
......
......@@ -51,6 +51,11 @@ Route::group(['middleware' => ['web','auth','admin']], function () {
Route::group(['middleware' => ['web','auth','customer']], function () {
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');
......@@ -58,7 +63,10 @@ Route::group(['middleware' => ['web','auth','customer']], function () {
Route::get('/createRequest/{id}', 'CustomerController@createRequest');
Route::post('/storeRequest', 'CustomerController@storeRequest');
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