public function makeBackup()
 {
     $serial_num = BACKUP_LOG::max('serial_num');
     $newSerial_num = sprintf('%08d', $serial_num + 1);
     $currentSerialNum = BACKUP_LOG::find($serial_num);
     $currentSerialNum->serial_num = $newSerial_num;
     $currentSerialNum->save();
     //shell_exec("ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock");
     shell_exec('/Applications/MySQLWorkbench.app/Contents/MacOS/mysqldump   -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' ' . env('DB_DATABASE') . ' > ' . env('BACKUP_PATH') . $newSerial_num . "_user_backup_`date`" . '.sql');
     // TODO: put this in the constants file
     $path = storage_path() . "/app/Backups/";
     // Search for the required file. Returns matching files.
     $sqldump = File::glob($path . $newSerial_num . '_*.sql');
     $newNotification = new Notifications();
     // TODO: Remove magic numbers
     // TODO: Put messages inside the constants file
     if ($sqldump == false) {
         $newNotification->notification = "Backup Failed!";
         $newNotification->body = "User generated Backup failed.";
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'failed_notification', ['message' => 'User generated Backup failed.']);
     } else {
         $newNotification->notification = "Backup successful!";
         $newNotification->body = 'Backup #' . $newSerial_num . ' created.';
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'new_backup_notification', ['message' => 'Backup #' . $newSerial_num . ' created.']);
     }
 }
 /**
  * This function submits the changes made in event progress
  *
  * @param string        POST data (from event progress update)
  *
  * @return  if successful, 'Events Assigned To Me' page for Team Member
  */
 public function EditProgress()
 {
     $input = Request::all();
     $iName = $input['EventID'];
     $user_id = \Auth::user()->id;
     $iPercentage = array();
     $iStatus = array();
     $iTaskID = array();
     if (isset($_POST['doneprogress'])) {
         $today = Carbon::today()->toDateString();
         $em = Quote_Requests::select('*')->where('id', $iName)->first();
         $mailData = ['EventID' => $iName, 'EventType' => $em->EventType, 'DueDate' => $em->DueDate, 'CompletedOn' => $today, 'FirstName' => $em->UserName];
         //send email to customer
         Mail::send('emails.event-complete', $mailData, function ($message) use($em) {
             $message->to($em->Email, 'Test')->subject('Your Event Is Ready!');
         });
         //send a notification to customer
         $newNotification = new Notifications();
         $newNotification->title = 'Event Complete';
         $newNotification->body = $em->EventType . ' planning is complete';
         $newNotification->icon = 'icon';
         $newNotification->link = 'dashboard/events/progresscustomer?EventID=' . $iName;
         $newNotification->readStatus = '0';
         $newNotification->save();
         $message = $em->EventType . ' planning is complete';
         $icon = 'icon';
         $link = 'dashboard/events/progresscustomer?EventID=' . $iName;
         $title = 'Event Complete';
         Pusher::trigger('notifications', 'success_notification', ['message' => $message, 'icon' => $icon, 'link' => $icon, 'title' => $title]);
         return redirect('dashboard/events/myevents')->with('message', 'You Completed The Event');
     } else {
         foreach ($input['percentage'] as $x) {
             $iPercentage[] = $x;
         }
         foreach ($input['status'] as $y) {
             $iStatus[] = $y;
         }
         foreach ($input['taskid'] as $z) {
             $iTaskID[] = $z;
         }
         foreach ($input['taskid'] as $z => $value) {
             $today = Carbon::today()->toDateString();
             Event_Tasks::where('EventID', $iName)->where('id', $iTaskID[$z])->update(['Percentage' => $iPercentage[$z], 'Status' => $iStatus[$z], 'LastUpdated' => $today]);
         }
         return redirect('dashboard/events/myevents')->with('message', 'Record Added Successfully');
     }
 }
 /**
  * This function is to store the reservation details to db.
  * After storing the details this function redirects to the My Reservation view.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function hallReservation()
 {
     try {
         //set the timezone
         date_default_timezone_set("Asia/Colombo");
         $customer_email = Auth::user()->email;
         $customer_id = Customer::where('email', $customer_email)->value('cus_id');
         $customer_name = Customer::where('email', $customer_email)->value('name');
         $hall_name = HALL::where('hall_id', session('hall_selected'))->value('title');
         $event_date = session('event_date');
         //create instance of the HALL_RESERVATION model
         $hall_reservation = new HALL_RESERVATION();
         $hall_reservation->reserve_date = session('event_date');
         $hall_reservation->time_slot = session('timeSlot');
         $hall_reservation->total_amount = session('total_payable');
         $hall_reservation->cus_id = $customer_id;
         $hall_reservation->hall_id = session('hall_selected');
         $hall_reservation->status = 'PENDING';
         $hall_reservation->save();
         //retrieve the reservation id of the last saved reservation
         $res_id = $hall_reservation->hall_reservation_id;
         //delete the reservation details since already stored in the db
         Session::forget(['event_date', 'total_payable', 'hall_selected', 'CanPay']);
         //create an array in order to send the mail view with reservation details
         $data = array('res_id' => $res_id, 'hall_name' => $hall_name, 'event_date' => $event_date, 'name' => $customer_name);
         $job = new SendEmail($data, $customer_email, "initial_reservation_mail");
         $this->dispatch($job);
         //send a initial mail
         /*  Mail::send('emails.InitialRoomReservationMail', $data, function ($message)use($customer_email) {
                         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
         
                         $message->to($customer_email)->subject('Welcome to Amalya Reach!');
                     });*/
         //pusher
         $newNotification = new Notifications();
         $newNotification->notification = "New Reservation";
         $newNotification->body = "Room Reservation has been made";
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'Reservation', ['message' => 'New Hall Reservation has been made']);
         return redirect('myreserv')->with(['hreserv_status' => 'Reservation has been successfully made']);
     } catch (\Exception $e) {
         abort(500, $e->getMessage());
     }
 }
 /**
  * Show Notification
  *
  * @return \Illuminate\Http\Response
  */
 public function ShowNotification(Request $request)
 {
     $newNotification = new Notifications();
     $newNotification->title = $request->input('title');
     $newNotification->body = $request->input('message');
     $newNotification->icon = $request->input('icon');
     $newNotification->link = $request->input('link');
     $newNotification->for = $request->input('for');
     $newNotification->readStatus = '0';
     $newNotification->save();
     $message = $request->input('message');
     $icon = $request->input('icon');
     $link = $request->input('link');
     $title = $request->input('title');
     $for = $request->input('title');
     Pusher::trigger('notifications', 'success_notification', ['message' => $message, 'icon' => $icon, 'link' => $icon, 'title' => $title, 'for' => $for]);
     //return $request->input('message');
 }
 /**
  * This function store the room reservation details to db and clears the session
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function roomReservation(Request $request)
 {
     //set the timezone
     date_default_timezone_set("Asia/Colombo");
     //get the customer details currently logged in
     $customer_email = Auth::user()->email;
     $customer_id = Customer::where('email', $customer_email)->value('cus_id');
     $customer_name = Customer::where('email', $customer_email)->value('name');
     //convert the dates to date time insatance and get the difference
     $datetime1 = new DateTime(session('check_in'));
     $datetime2 = new DateTime(session('check_out'));
     $interval = $datetime1->diff($datetime2);
     //get the requested reservation details from the session
     $no_of_guests = session('adults') + session('kids');
     //formt the number of nights
     $no_of_nights = $interval->format('%d%') + config('constants.ADD_ONE_NIGHT');
     //call the saveReservationDetails function to save the reservation details to the database
     $res_id = $this->saveReservationDetails(session('check_in'), session('check_out'), $no_of_nights, $customer_id);
     //insert the the details to the RES_RMTYPE_CNT_RATE table
     foreach (session('room_types') as $room_type) {
         DB::table('RES_RMTYPE_CNT_RATE')->insert(['room_reservation_id' => $res_id, 'room_type_id' => $room_type, 'rate_code' => session('rate_code' . $room_type), 'count' => session('no_of_rooms' . $room_type)]);
     }
     //create an array with reservation details in ordr to send to the mail view
     $data = array('res_id' => $res_id, 'check_in' => session('check_in'), 'check_out' => session('check_out'), 'nights' => $no_of_nights, 'no_of_rooms' => session('rooms'), 'guests' => $no_of_guests, 'name' => $customer_name);
     //observer design pattern is used here, but this is design pattern is no use full
     /*$sub =  new ReservationRoom();
       $sub->attach(new ReservationTask());
       $sub->clearSession();*/
     //clear session
     $this->clearRoomSession("Full");
     //call the mailfunction send an email
     $this->sendInitialMail($data, $customer_email);
     //send an pusher notification to the admin
     //remove the magic values
     $newNotification = new Notifications();
     $newNotification->notification = "New Reservation";
     $newNotification->body = "Room Reservation has been made";
     $newNotification->readStatus = '0';
     $newNotification->save();
     Pusher::trigger('notifications', 'Reservation', ['message' => 'New Room Reservation has been made']);
     return redirect('myreserv')->with(['reserv_status' => 'Room_Reservation']);
 }
Esempio n. 6
0
 /**
  * Define the application's command schedule.
  * @link http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     /* $schedule->command('queue:listen')->everyMinute();*/
     /*$schedule->command('inspire')
       ->hourly();*/
     // This scheduled task backs up the db at midnight everyday
     $serial_num = BACKUP_LOG::max('serial_num');
     $newSerial_num = sprintf('%08d', $serial_num + 1);
     $currentSerialNum = BACKUP_LOG::find($serial_num);
     $currentSerialNum->serial_num = $newSerial_num;
     $currentSerialNum->save();
     // This shell command will be executed at Midnight everyday
     $schedule->exec('mysqldump -u' . env('DB_USERNAME') . ' -p' . env('DB_PASSWORD') . ' ' . env('DB_DATABASE') . ' > ' . env('BACKUP_PATH') . $newSerial_num . "_scheduled_backup_`date`" . '.sql')->daily();
     /*// This shell command will be executed at the specified time everyday
       // Test this with php artisan schedule:run
       $schedule->exec('mysqldump -u'.env('DB_USERNAME').' -p'.env('DB_PASSWORD').' '.env('DB_DATABASE').' > '.env('BACKUP_PATH').$newSerial_num."_scheduled_backup_`date`".'.sql')
           ->dailyAt("14:34");*/
     $newNotification = new Notifications();
     $newNotification->notification = "Backup successful!";
     $newNotification->body = 'Backup #' . $newSerial_num . ' created.';
     $newNotification->readStatus = '0';
     $newNotification->save();
 }
 /**
  * save a customer inwuiry and send an email to admin email which is hardcoded
  *
  * @param Request $request
  */
 public function saveinquiry(Request $request)
 {
     $inq = new Inquiry();
     $inq->name = $request->input('fullname');
     $inq->company = $request->input('company');
     $inq->email = $request->input('email');
     $inq->message = $request->input('message');
     $inq->status = '1';
     $inq->save();
     // save notification to DB and to pusher
     $newNotification = new Notifications();
     $newNotification->notification = "New Customer Inquiry!";
     $newNotification->body = 'New Customer Inquiry has been made.';
     $newNotification->readStatus = '0';
     $newNotification->save();
     Pusher::trigger('notifications', 'new_backup_notification', ['message' => 'New Customer Inquiry has been made.']);
     // get admin's email
     $email = User::where('role', 'admin')->first()->email;
     Mail::send('emails.inquiry', ['inq' => $inq], function ($message) use($email) {
         $message->from(env('MAIL_FROM'), env('MAIL_NAME'));
         //$message->to("*****@*****.**")->subject('Amalaya Reach Inquiry');
         $message->to($email)->subject('Amalaya Reach Inquiry');
     });
 }
 /**
  * Return user if exists; create and return if doesn't
  *
  * @param $user
  * @return User
  */
 private function findOrCreateUser($user, $provider)
 {
     $authUser = User::where('email', $user->email)->first();
     if ($authUser) {
         Session::put('user_role', $authUser->role);
         return $authUser;
     } else {
         Session::put('user_role', 'customer');
         /**
          * Random Generated Password for Social Logged Users
          *
          * @var string
          */
         $pwd = str_random(8);
         $providerName = "Social Media";
         switch ($provider) {
             case 'facebook':
                 $providerName = "Facebook";
                 break;
             case 'google':
                 $providerName = "Google+";
                 break;
             default:
                 $providerName = "Social Media";
                 break;
         }
         $mailData = ['name' => $user->name, 'pwd' => $pwd, 'provider' => $providerName, 'email' => $user->email];
         $newNotification = new Notifications();
         $title = "New user registered!";
         $message = $user->name . ' just registered using ' . $providerName . '.';
         $icon = "fa-user";
         $link = 'dashboard/users';
         $for = "admin";
         $newNotification->title = $title;
         $newNotification->body = $message;
         $newNotification->icon = $icon;
         $newNotification->link = $link;
         $newNotification->for = $for;
         $newNotification->readStatus = '0';
         $newNotification->save();
         Pusher::trigger('notifications', 'success_notification', ['message' => $message, 'icon' => $icon, 'link' => $link, 'title' => $title, 'for' => $for]);
         //Send Welcome Email
         Mail::send('emails.register-success-social', $mailData, function ($message) use($user) {
             $message->to($user->email)->subject('Welcome to PlanMyEvent.me');
         });
         return User::create(['name' => $user->name, 'email' => $user->email, 'password' => bcrypt($pwd), 'provider_id' => $user->id, 'avatar' => $user->avatar, 'provider' => $provider, 'provider_id' => $user->id, 'role' => 'customer']);
     }
 }
 public function confirm(Request $request)
 {
     $now = new DateTime();
     $rules = array('name' => 'required', 'address' => 'required', 'trans' => 'required', 'phone' => 'required');
     $validator = \Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Response::json(array('result' => false, 'data' => 'กลับไปที่หน้าแรก โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $validator->messages()->all()));
     }
     //$validator->errors()->all()
     $order = new Orders();
     $orders_number = $now->format("YmdHis") . '-' . \Auth::user()->id;
     $cart = Cart::instance('cartoon');
     if ($cart->count() <= 0) {
         if ($validator->fails()) {
             return Response::json(array('result' => false, 'data' => 'กลับไปที่หน้าแรก โปรดตรวจสอบข้อมูลใหม่อีกครั้ง'));
         }
     }
     DB::beginTransaction();
     try {
         $order->orders_number = $orders_number;
         $order->members_id = \Auth::user()->id;
         $order->members_name = $request->input('name');
         $order->address = $request->input('address');
         $order->phone = $request->input('phone');
         $order->ems = $request->input('trans');
         $order->total = $cart->total();
         $order->total_grand = $cart->total() + $request->input('trans');
         $order->created_at = Carbon::now('Asia/Bangkok');
         $order->updated_at = Carbon::now('Asia/Bangkok');
         $order->status = 1;
         $order->save();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         return Response::json(array('result' => false, 'data' => 'ยืนยันผิดพลาด โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $e));
     }
     DB::beginTransaction();
     try {
         $now = Carbon::now('Asia/Bangkok');
         foreach ($cart->content() as $key => $item) {
             $pro = Products_vol::where('code', $item->id)->get()->first();
             $orders_detail = new Orders_detail();
             $orders_detail->orders_number = $order->orders_number;
             $orders_detail->product_vol_code = $item->id;
             $orders_detail->product_vol_name = $pro->name;
             $orders_detail->product_vol_qty = $item->qty;
             $orders_detail->product_vol_per = $pro->price;
             $orders_detail->created_at = $now;
             $orders_detail->updated_at = $now;
             $orders_detail->product_vol_price = $pro->price * $item->qty;
             $orders_detail->save();
             DB::commit();
         }
     } catch (\Exception $e) {
         DB::rollBack();
         return Response::json(array('result' => false, 'data' => 'ยืนยันผิดพลาด โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $e));
     }
     $cart->destroy();
     $this->sendmail($order);
     //save notify
     $notify = new Notifications();
     $notify->members_id = \Auth::user()->id;
     $notify->type = "CREATE_ORDER";
     $notify->status = 0;
     $notify->created_at = $now;
     $notify->updated_at = $now;
     $notify->order_id = $order->id;
     $notify->message = "You have a new order !";
     $notify->save();
     return Response::json(array('result' => true, 'data' => $order));
 }
 public function uploadslip(Request $request)
 {
     $rules = array('payment_slip' => 'required|mimes:jpeg,bmp,png,jpg,gif', 'orders_number' => 'required', 'payment_channel' => 'required', 'payment_price' => 'required', 'payment_date' => 'required', 'payment_time' => 'required');
     $validator = \Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return redirect()->intended('/member')->withErrors(array('error' => 'โปรดตรวจสอบข้อมูลใหม่อีกครั้ง'));
     }
     $now = Carbon::now('Asia/Bangkok');
     $hash = md5($now);
     $user = \Auth::user();
     $imageName = $hash . '-' . $user->id . '.' . $request->file('payment_slip')->getClientOriginalExtension();
     $request->file('payment_slip')->move(base_path() . '/public/images/slip/', $imageName);
     $link = '/images/slip/' . $imageName;
     $slip = Orders_slip::create(['payment_slip' => $link, 'orders_number' => $request->input('orders_number'), 'payment_channel' => $request->input('payment_channel'), 'payment_price' => $request->input('payment_price'), 'payment_date' => $request->input('payment_date'), 'payment_time' => $request->input('payment_time'), 'created_at' => $now, 'updated_at' => $now]);
     if ($slip->id == null) {
         return redirect()->intended('/member')->withErrors(array('error' => 'ยืนยันการชำระเงินผิดพลาด กรุณาลองใหม่อีกครั้ง'));
     }
     $order = Orders::where('orders_number', $request->input('orders_number'))->get()->first();
     $order->status = 2;
     $order->updated_at = $now;
     $order->orders_slip = $slip->id;
     $result = $order->save();
     if ($result) {
         $this->sendmail($order, $link, $slip);
     }
     //save notify
     $notify = new Notifications();
     $notify->members_id = \Auth::user()->id;
     $notify->type = "PAYMENT_CONFIRM";
     $notify->status = 0;
     $notify->created_at = $now;
     $notify->updated_at = $now;
     $notify->order_id = $order->id;
     $notify->message = "You have a new confirm payment !";
     $notify->save();
     return redirect()->intended('/member');
 }