Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddprtma committed Oct 4, 2023
2 parents 0289ec2 + 3883db2 commit beccd0a
Show file tree
Hide file tree
Showing 24 changed files with 718 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public function redirectTo(){
$role = Auth::user()->sebagai;
switch($role){
case 'owner':
<<<<<<< HEAD
return '/suppliers';
break;
case 'pegawai':
return '/products';
break;
case 'member':
return '/cart';
break;

=======
return '/admin';
break;
case 'pegawai':
Expand All @@ -41,6 +52,7 @@ public function redirectTo(){
return '/';
break;

>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
default:
return '/';
break;
Expand Down
14 changes: 14 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,27 @@ public function redirectTo(){
$role = Auth::user()->sebagai;
switch($role){
case 'owner':
<<<<<<< HEAD
return '/suppliers';
break;
case 'pegawai':
return '/products';
break;
case 'member':
<<<<<<< HEAD
return '/';
=======
return '/cart';
=======
return '/admin';
break;
case 'pegawai':
return '/admin';
break;
case 'member':
return '/';
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
>>>>>>> 3883db2fbf479467fbe042fbcac36c4e9b996206
break;

default:
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/BuyerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Http\Controllers;

use App\Buyer;
<<<<<<< HEAD
=======
use Illuminate\Support\Facades\DB;
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
use Illuminate\Http\Request;
class BuyerController extends Controller
Expand All @@ -16,9 +19,13 @@ class BuyerController extends Controller
public function index()
{
//
<<<<<<< HEAD
$result = Buyer::all();
=======
$result = DB::table('users')
->where('sebagai','=','member')
->get();
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
return view('buyer.index',['data' => $result]);
}

Expand Down
64 changes: 63 additions & 1 deletion app/Http/Controllers/MedicineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;

<<<<<<< HEAD
=======
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
class MedicineController extends Controller
{
/**
Expand Down Expand Up @@ -149,7 +152,11 @@ public function coba1(){
// aggregate count
// $result = DB::table('medicines')
<<<<<<< HEAD
// -> count();
=======
// -> count();
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
// result 16

// aggregate max
Expand All @@ -162,7 +169,11 @@ public function coba1(){
// -> count();
// result 11

<<<<<<< HEAD
// // join
=======
// // join
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
// $result = DB::table('medicines')
// -> join('categories','medicines.category_id','=','categories.id')
// -> orderBy('price','DESC')
Expand All @@ -183,7 +194,11 @@ public function coba1(){
public function coba2(){
// query 1 table
<<<<<<< HEAD
// query builder categories
=======
// query builder categories
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
$result = DB::table('categories')
-> get();

Expand Down Expand Up @@ -221,15 +236,23 @@ public function coba2(){
$result = Category::select('medicines.category_id')
->join('medicines', 'medicines.category_id','=','categories.id')
->count();
<<<<<<< HEAD
=======
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
// query builder medicines & category
// Tampilkan nama kategori yang tidak memiliki data medicines satupun
$result = DB::table('categories')
-> select('category_name')
->whereNotIn('id', DB::table('medicines') ->select('category_id'))
-> get();
<<<<<<< HEAD
// query eloquent medicines & category
=======
// query eloquent medicines & category
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
$result = Category::select('category_name')
->whereNotIn('id', DB::table('medicines') ->select('category_id'))
-> get();
Expand All @@ -242,7 +265,11 @@ public function coba2(){
->groupBy('c.id','c.category_name')
->get();

<<<<<<< HEAD
// query eloquent medicines & category
=======
// query eloquent medicines & category
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
$result = Medicine:: select('c.id','c.category_name',DB::raw('IFNULL(avg(medicines.price),0) as RataRataHarga'))
->rightjoin('categories as c','c.id','=','medicines.category_id')
->groupBy('c.id','c.category_name')
Expand All @@ -257,7 +284,11 @@ public function coba2(){
->having(DB::raw('count(m.category_id)'),'=',1)
->get();
<<<<<<< HEAD
// query eloquent medicines & category
=======
// query eloquent medicines & category
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
$result = Category::select('categories.category_name')
->join('medicines as m','m.category_id','=','categories.id')
->groupBy('categories.category_name')
Expand Down Expand Up @@ -296,7 +327,11 @@ public function coba2(){

public function obattermahal(){
$hasilTermahal = Medicine::orderBy('price','DESC')->first();
<<<<<<< HEAD
return view('report.maxpricemedicine',['result'=>$hasilTermahal]);
=======
return view('report.maxpricemedicine',['data'=>$hasilTermahal]);
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
public function showInfo(){
Expand All @@ -305,7 +340,11 @@ public function showInfo(){
'status'=>'oke',
'msg'=>"<div class='alert alert-info'>
Did you know? <br> The most expensive product is ".$obatTermahal -> name. " with price Rp. ".$obatTermahal -> price."</div>"
<<<<<<< HEAD
),200);
=======
),200);
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}

public function front_index(){
Expand All @@ -314,6 +353,25 @@ public function front_index(){
}

public function addToCart($id){
<<<<<<< HEAD
$p = Medicine::find($id);
$cart = session()->get('cart');
if(!isset($cart[$id])){
$cart[$id]=[
"name"=>$p->name,
"quantity"=>1,
"price"=>$p->price,
"image"=>$p->image
];
}
else{
$cart[$id]['quantity']++;
}
session()->put('cart',$cart);
return redirect()->back()->with('success', 'Product ' . $cart[$id]['name'] . " jumlah " . $cart[$id]['quantity']. " berhasil ditambahkam");
=======
if(Gate::allows('isMember', Auth::user())){
$p = Medicine::find($id);
$cart = session()->get('cart');
Expand All @@ -333,14 +391,17 @@ public function addToCart($id){
}
else{
Auth::logout();
return redirect()->route('cart')->with('error', 'You are no a member');
return redirect()->route('cart')->with('error', 'You are not a member');
}
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
public function cart(){
return view('frontend.cart');
}
<<<<<<< HEAD
=======
public function mostbuymedicine(){
$data = Medicine:: select('medicines.name','medicines.form','medicines.price',DB::raw('IFNULL(sum(t.quantity),0) as totalbeli'))
->rightjoin('medicine_transaction as t','t.medicine_id','=','medicines.id')
Expand All @@ -352,4 +413,5 @@ public function mostbuymedicine(){
return view('report.mostbuymedicine',['data'=>$data]);
}

>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public function destroy(Transaction $transaction)
// public function showAjax(Request $request)
// {
// $id=$request->id;
<<<<<<< HEAD

=======

>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
// return response()->json(array(
// 'msg'=>$id
// ),200);
Expand All @@ -113,8 +117,13 @@ public function submit_front(){
$cart = session()->get('cart');
$user = Auth::user();
$t = new Transaction;
<<<<<<< HEAD
$t->user_id = $user->id;
$t->buyer_id = 1;
=======
$t->buyer_id = 1;
$t->user_id = $user->id;
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
$t->transaction_date = Carbon::now()->format('Y-m-d H:i:m');
$t->save();
Expand All @@ -123,7 +132,11 @@ public function submit_front(){
$t->save();
session()->forget('cart');
<<<<<<< HEAD
return redirect('/');
=======
return redirect()->route('cart')->with('status', 'Data berhasil di checkout dan masuk di dashboard :D');
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}

public function print_detail($id){
Expand All @@ -132,6 +145,8 @@ public function print_detail($id){
$name = "laporan-pemesanan".$transaction->id.$transaction->transaction_date.".pdf";
return $pdf->download($name);
}
<<<<<<< HEAD
=======

public function mostbuycustomer(){
$data = Transaction::select('u.id', 'u.name', DB::raw('IFNULL(sum(transactions.total),0) as totalpembeli'))
Expand All @@ -143,4 +158,5 @@ public function mostbuycustomer(){

return view('report.mostbuycustomer',['data'=>$data]);
}
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function boot()
? Response::allow()
: Response::deny("Anda harus menjadi member terlebih dahulu"));
});
<<<<<<< HEAD
=======

Gate::define('isMember',function($user){
if($user->sebagai =='member'){
Expand All @@ -59,5 +61,6 @@ public function boot()
return false;

});
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
}
4 changes: 4 additions & 0 deletions app/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function insertProduct($cart,$user){
$total=0;
foreach($cart as $id=>$detail){
$total += $detail['price'] * $detail['quantity'];
<<<<<<< HEAD
$this->medicines()->attach($id,['quantity' => $detail['quantity'], 'subtotal' => $detail['price']]);
=======
$this->medicines()->attach($id,['quantity' => $detail['quantity'], 'price' => $detail['price'], 'subtotal'=>($detail['price'] * $detail['quantity'])]);
>>>>>>> f7a2feb6ed956033dc000ae28e8a7a221ef27032
}
return $total;
}
Expand Down
27 changes: 27 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit beccd0a

Please sign in to comment.