data['settings'] = Settings::find(1);
$this->data['seo']= (object) array(
'page_title' => 'Profile - '.getenv('APP_NAME'),
'meta_keywords' => '',
'meta_description' => ''
);
$customer = Auth::guard('customer')->user();
$this->data['customer_profile'] = Customers::find($customer->id);
return view('front.customer.profile', $this->data);
}
/*
| Update customer profile
|--------------------------------------------------------------------------
*/
public function updateCustomerProfile(Request $request)
{
if (!Auth::guard('customer')->check()) {
return redirect('/signin');
}
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required',
'mobile_number' => 'required',
'password' => 'required',
'address' => 'required',
'dob' => 'required',
]);
if ($validator->fails()) {
return back()->withErrors($validator)->withInput();
}else{
$customer = Auth::guard('customer')->user();
$update = Customers::find($customer->id);
$update->name = $request->name;
$update->email= $request->email;
$update->mobile_number = $request->mobile_number;
$update->password = Hash::make($request->password);
$update->address = $request->address;
$update->dob = $request->dob;
$update->save();
$request->session()->flash('success', 'Task was successful!');
return back();
}
}
/*
| get customer orders
|--------------------------------------------------------------------------
*/
public function customerOrders(Request $request)
{
$this->data['settings'] = Settings::find(1);
$customer = Auth::guard('customer')->user();
$this->data['seo']= (object) array(
'page_title' => 'Orders - '.env('APP_NAME'),
'meta_keywords' => '',
'meta_description' => ''
);
$orders = TakeawayOrders::where('customer_id',$customer->id)->orderBy('id','desc')->paginate(50);
foreach ($orders as $row) {
$orderItems = DB::table('takeaway_order_details')->where('order_id', $row->id)->get();
$hasNextDayItems = $orderItems->contains('nextday_order', 'yes');
$allItemsNextDay = $orderItems->count() > 0 && $orderItems->every('nextday_order', 'yes');
$row->order_due_tomorrow = $hasNextDayItems;
$row->all_items_nextday = $allItemsNextDay;
}
$this->data['customer_orders'] = $orders;
return view('front.customer.orders', $this->data);
}
/*
| Get customer order
|--------------------------------------------------------------------------
*/
public function getCustomerOrder(Request $request)
{
$customer = Auth::guard('customer')->user();
$customer_order = TakeawayOrders::where('id',$request->id)->first();
if(!empty($customer_order)){
$customer_order->is_nextday = $request->has('nextday') ? ($request->nextday == 1) : null;
}
$customer_order_detail = \App\TakeawayOrderDetails::where('order_id',$customer_order->id)
->when($request->has('nextday'), function($query) use ($request) {
if ($request->nextday == 1) {
$query->where('nextday_order', 'yes');
}
if ($request->nextday == 0) {
$query->where('nextday_order', 'no');
}
})->get();
$customer = Customers::where('id',$customer->id)->first();
$feedback = CustomerFeedback::where('customer_id',$customer->id)->where('order_id',$request->id)->first();
ob_start();
?>
Invoice to
name) ?>
address.', '.$customer->city ?>
mobile_number ?>
Order ID: id ?>
Order Date: created_at)) ?>
Order Type: order_type) ?>
Payment Type: payment_type) ?>
| # |
Item |
Quantity |
Price |
Total |
delivery_charges) ? $customer_order->delivery_charges : 0;
$tax_rate = isset($customer_order->tax_rate) ? $customer_order->tax_rate : 0;
foreach ($customer_order_detail as $row) {
$subtotal += $row->item_total_price;
?>
|
item_name; ?>
platform == 'web' && !empty($row->addons)) { ?>
addons) as $adon) { ?>
item_price == 0) { ?>
item_name; ?>
item_name.' - '.$adon->item_price; ?>
|
quantity; ?> |
price); ?> |
item_total_price); ?> |
special_instructions)) { ?>
Special Instructions
special_instructions; ?>
Subtotal :
Delivery charges :
Tax(%) :
Total :
user();
$this->data['settings'] = Settings::find(1);
$this->data['seo']= (object) array(
'page_title' => 'Reservations - '.env('APP_NAME'),
'meta_keywords' => '',
'meta_description' => ''
);
$this->data['customer_reservations'] = \App\TableReservations::where('customer_id',$customer->id)->get();
return view('front.customer.reservations', $this->data);
}
/*
| save customer feedback
|--------------------------------------------------------------------------
*/
public function saveCustomerFeedack(Request $request)
{
if($request->feedback == ''){
return response()->json([
'status' => 0,
'msg' => 'Feedback is required.'
]);
}
$response = CustomerFeedback::where('customer_id',$request->customer_id)->where('order_id',$request->order_id)->first();
if(!empty($response)){
return response()->json([
'status' => 0,
'msg' => 'Feedback is already given.'
]);
}
$create = new CustomerFeedback;
$create->customer_id = $request->customer_id;
$create->order_id = $request->order_id;
$create->quality = $request->quality;
$create->service = $request->service;
$create->value = $request->value;
$create->feedback = $request->feedback;
$create->average_rating = ($request->quality + $request->service + $request->value) / 3;
$create->created_at = date("Y-m-d H:i:s");
$create->save();
return response()->json([
'status' => 1,
'msg' => 'Thank you for your feedback.'
]);
}
/*
| customerPoints
|--------------------------------------------------------------------------
*/
public function customerPoints(Request $request)
{
$this->data['settings'] = Settings::find(1);
$this->data['seo']= (object) array(
'page_title' => 'Loyalty Points - '.getenv('APP_NAME'),
'meta_keywords' => '',
'meta_description' => ''
);
$customer = Auth::guard('customer')->user();
$lp = \App\LoyaltyPointsCustomers::where('customer_id',$customer->id)->first();
if(!empty($lp)){
$this->data['total_loyalty'] = $lp->total_points;
}
$lpl = \App\LoyaltyPointsLogs::where('type','redeemed')->where('customer_id',$customer->id)->get();
if(!empty($lpl)){
$this->data['total_redeemed'] = $lpl->sum('points');
}
$this->data['loyalty_points'] = \App\LoyaltyPointsLogs::where('type','loyalty')->where('customer_id',$customer->id)->get();
$this->data['redeemed_points'] = \App\LoyaltyPointsLogs::where('type','redeemed')->where('customer_id',$customer->id)->get();
return view('front.customer.points', $this->data);
}
/*
| redeemPoints
|--------------------------------------------------------------------------
*/
public function redeemPoints(Request $request)
{
if (config('app.mod_loyalty') == true && Auth::guard('customer')->check()) {
$lp = \App\LoyaltyPoints::first();
if($lp && !empty($lp)){
if($request->redeem_points == ''){
return response()->json([
'status' => 0,
'msg' => 'Please enter redeem points.'
]);
}
if($request->redeem_points < $lp->minimum_points_used){
return response()->json([
'status' => 0,
'msg' => 'Minimum redeem points should be '.$lp->minimum_points_used
]);
}
if($request->redeem_points > $lp->maximum_points_used){
return response()->json([
'status' => 0,
'msg' => 'Maximum redeem points should be '.$lp->maximum_points_used
]);
}
$authCustomer = Auth::guard('customer')->user();
$customer = Customers::find($authCustomer->id);
$discount = ($request->redeem_points / $lp->redeeming_point) * $lp->redeeming_point_value;
if ($lp->enabled_points == 1 && $lp->disabled_redeeming == 0) {
$lpc = \App\LoyaltyPointsCustomers::where('customer_id',$customer->id)->first();
(empty($lpc)) ? $lpc = new \App\LoyaltyPointsCustomers : '';
$lpc->customer_id = $customer->id;
$lpc->customer_name = $customer->name;
$lpc->customer_email = $customer->email;
$lpc->total_points = $lpc->total_points-$request->redeem_points;
$lpc->save();
Helper::loyalty_points_log($customer->id, $customer->name, 'points redeemed by online order', 'redeemed', $request->redeem_points);
return response()->json([
'status' => 1,
'msg' => 'Points redeemed successfully, you got '.$discount.'% discount.',
'discount' => $discount,
]);
}else{
return response()->json([
'status' => 0,
'msg' => 'Something goes wrong, please try again.'
]);
}
}
}
}
}