-
Notifications
You must be signed in to change notification settings - Fork 1
/
CouponsController.php
120 lines (107 loc) · 2.39 KB
/
CouponsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Coupon;
use App\User;
use App\Hostel;
use DB;
class CouponsController extends Controller
{
//
public function index()
{
$user = \Auth::user();
if ($user->email == 'admin@ied.com')
{
$coupons = Coupon::all();
return view('coupons.index', compact('coupons'));
}
else
{
$id = $user->id;
$coupon = Coupon::find($id);
$rollno = $coupon->rollno;
$hostel = DB::select("select * from hostels where rollno = '$rollno';");
if($hostel== NULL)
{
$last= -99;
}
else
{
end($hostel);
$last = key($hostel);
}
return view('coupons.show', compact('coupon', 'hostel', 'last'));
}
}
public function showCoupon(Request $request)
{
$coupon = Coupon::find($request->id);
return view('coupons.showCoupon', compact('coupon'));
}
public function save(Request $request)
{
$time = strtotime($request->sdate);
$final = date("Y-m-d", strtotime("+1 month", $time));
Coupon::where('id','=',$request->id)->update([ 'startbalance' => $request->amount, 'start_date' => $request->sdate, 'end_date' => $final]);
if($request->amount == 1700)
{
$breakfast=20;
$lunch=20;
$tea=20;
$dinner=20;
}
elseif($request->amount == 2000)
{
$breakfast=25;
$lunch=25;
$tea=25;
$dinner=25;
}
elseif($request->amount == 2200)
{
$breakfast=30;
$lunch=30;
$tea=30;
$dinner=30;
}
Coupon::where('id','=',$request->id)->update([ 'breakfast' => $breakfast, 'lunch' => $lunch, 'snacks' => $tea, 'dinner' => $dinner]);
return $this->index();
}
public function setCardStatus(Request $request)
{
if($request->blocked == 0)
{
$request->blocked = 1;
}
else
{
$request->blocked = 0;
}
Coupon::where('id','=',$request->id)->update([ 'blocked' => $request->blocked]);
return $this->index();
}
public function show($coupon)
{
$coupon = Coupon::find($coupon);
$rollno = $coupon->rollno;
$hostel = DB::select("select * from hostels where rollno = '$rollno';");
if($hostel== NULL)
{
$last= -99;
}
else
{
end($hostel);
$last = key($hostel);
}
return view('coupons.show', compact('coupon','hostel','last'));
}
public function destroy(Request $request)
{
$coupon = Coupon::find($request->id);
Coupon::findOrFail($coupon->id)->delete();
User::findOrFail($coupon->id)->delete();
return $this->index();
}
}