/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $notify_report = false;
     for ($i = 0; $i < count($request->all()); $i++) {
         if ($request->input($i . '.include')) {
             $this->validate($request, [$i . '.id' => 'required', $i . '.member.id' => 'required|numeric', $i . '.position_id' => 'required|numeric', $i . '.project_id' => 'required|numeric', $i . '.target_id' => 'required|numeric', $i . '.output' => 'required|numeric', $i . '.date_start' => 'required|date', $i . '.date_end' => 'required|date', $i . '.hours_worked' => 'required|numeric', $i . '.daily_work_hours' => 'required|numeric', $i . '.output_error' => 'required|numeric']);
             // check if a report is already created
             if (!$notify_report) {
                 $admin = User::where('role', 'admin')->first();
                 $report = Report::where('id', $request->input($i . '.report_id'))->first();
                 // create a notification
                 $notification = new Notification();
                 $notification->message = 'updated a ';
                 $notification->sender_user_id = $request->user()->id;
                 $notification->receiver_user_id = $admin->id;
                 $notification->subscriber = 'admin';
                 $notification->state = 'main.weekly-report';
                 $notification->event_id = $report->id;
                 $notification->event_id_type = 'report_id';
                 $notification->seen = false;
                 $notification->save();
                 $notify = DB::table('reports')->join('users', 'users.id', '=', 'reports.user_id')->join('projects', 'projects.id', '=', 'reports.project_id')->join('notifications', 'notifications.event_id', '=', 'reports.id')->select('reports.*', 'users.*', DB::raw('LEFT(users.first_name, 1) as first_letter'), 'projects.*', 'notifications.*')->where('notifications.id', $notification->id)->first();
                 // foreach ($query as $key => $value) {
                 //     $notify = $value;
                 // }
                 event(new ReportSubmittedBroadCast($notify));
                 $activity_type = ActivityType::where('action', 'update')->first();
                 $activity = new Activity();
                 $activity->report_id = $report->id;
                 $activity->user_id = $request->user()->id;
                 $activity->activity_type_id = $activity_type->id;
                 $activity->save();
                 // report
                 $create_report = true;
             }
             $old_performance = Performance::where('id', $request->input($i . '.id'))->first();
             // record history of the performance
             $performance_history = new PerformanceHistory();
             $performance_history->activity_id = $activity->id;
             $performance_history->performance_id = $old_performance->id;
             $performance_history->report_id = $old_performance->report_id;
             $performance_history->member_id = $old_performance->member_id;
             $performance_history->position_id = $old_performance->position_id;
             $performance_history->department_id = $old_performance->department_id;
             $performance_history->project_id = $old_performance->project_id;
             $performance_history->target_id = $old_performance->target_id;
             $performance_history->date_start = $old_performance->date_start;
             $performance_history->date_end = $old_performance->date_end;
             $performance_history->daily_work_hours = $old_performance->daily_work_hours;
             $performance_history->output = $old_performance->output;
             $performance_history->hours_worked = $old_performance->hours_worked;
             $performance_history->output_error = $old_performance->output_error;
             $performance_history->average_output = $old_performance->average_output;
             $performance_history->productivity = $old_performance->productivity;
             $performance_history->quality = $old_performance->quality;
             $performance_history->quadrant = $old_performance->quadrant;
             $performance_history->save();
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(NotificationRequest $request)
 {
     $notification = new Notification();
     $notification->title = $request->title;
     $notification->content = $request->content;
     $notification->package_id = $request->package_id;
     $notification->save();
 }
 /**
  * Handle the event.
  *
  * @param  BadgeWasEarned  $event
  * @return void
  */
 public function handle(BadgeWasEarned $event)
 {
     $user = $event->user;
     $notification = new Notification();
     $notification->type = "Badge";
     $notification->is_read = false;
     $notification->user_id = $user->id;
     $notification->save();
 }
Ejemplo n.º 4
0
 public function addConnectionNotification($friend)
 {
     $sender = User::findOrFail(Auth::user()->id);
     $notification = new Notification();
     $notification->user_id = $friend->id;
     $notification->title = 'Someone has added you as their connection!';
     $notification->body = $sender->name . ' added you to their connection list, add them back to interact with them if you have not done so already!';
     $notification->save();
 }
 public function addNtf()
 {
     $notification = new Notification();
     $notification->message = 'test';
     $notification->cron = '* * * * * *';
     $notification->receiver_id = 1;
     $notification->save();
     return "added";
 }
Ejemplo n.º 6
0
 public function sentMessageNotification($user)
 {
     $sender = User::findOrFail(Auth::user()->id);
     $notification = new Notification();
     $notification->user_id = $user->id;
     $notification->title = 'You have a new message!!';
     $notification->body = $sender->name . ' has sent you a private message! Go to your inbox to reply now!';
     $notification->save();
 }
Ejemplo n.º 7
0
 public static function add($user_id, $type, $more = null)
 {
     $notification = new Notification();
     $notification->user_id = $user_id;
     $notification->type = $type;
     if ($more != null) {
         $notification->more = json_encode($more);
     }
     $notification->save();
 }
Ejemplo n.º 8
0
 private function save(Notification $notification, array $inputs)
 {
     $notification->track_id = intval($inputs['track_id']);
     $notification->sender_id = intval($inputs['sender_id']);
     $notification->user_id = intval($inputs['friend_id']);
     $notification->sender_name = $inputs['sender_name'];
     $notification->track_cover = $inputs['track_cover'];
     $notification->sender_cover = $inputs['sender_cover'];
     $notification->track_name = $inputs['track_name'];
     $notification->seen = 0;
     $notification->save();
 }
 public function testNotificationDelete()
 {
     $admin = User::find(1);
     $notification = new Notification();
     $notification->title = "Test title 123";
     $notification->type = "Alarm test";
     $notification->notes = "Test property ";
     $notification->data = "Test data ";
     $notification->save();
     $savedNotification = Notification::where('title', '=', 'Test title 123')->first();
     $this->actingAs($admin)->withSession(['foo' => 'bar'])->visit($this->modelUrl . (string) $savedNotification->id)->press('Delete')->seePageIs($this->modelUrl);
 }
Ejemplo n.º 10
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     $notification = new Notification();
     if (Request::has('text') && Request::input('text') != "") {
         $notification->text = Request::input('text');
         $notification->save();
         return Response::make("Success", 201);
     } else {
         // Bad request, missing parameters
         return Response::make("Please provide a notification.", 400);
     }
 }
 /**
  * Handle the event.
  *
  * @param  ShameWasUpdated  $event
  * @return void
  */
 public function handle(ShameWasUpdated $event)
 {
     $shame = $event->shame;
     $users = $shame->follows;
     foreach ($users as $user) {
         $notification = new Notification();
         $notification->type = "Shame";
         $notification->is_read = false;
         $notification->user_id = $user->id;
         $notification->shame_id = $shame->id;
         $notification->save();
     }
 }
Ejemplo n.º 12
0
 public function store($type, $to_follow_uuid, $user, $obj_id, $body = 'follow')
 {
     $notification = new Notification();
     //type 1 is cate
     //type 2 is follow
     //type 3 is reply
     //type 4 is upvote
     $notification->type = $type;
     $notification->recipient = $to_follow_uuid;
     $notification->sender = $user;
     $notification->body = $body;
     $notification->obj_id = $obj_id;
     $notification->save();
 }
 /**
  * Handle the event.
  *
  * @param  CommentWasAdded  $event
  * @return void
  */
 public function handle(CommentWasAdded $event)
 {
     $comment = $event->comment;
     $shame = $comment->shame;
     $users = $shame->follows;
     foreach ($users as $user) {
         $notification = new Notification();
         $notification->type = "Comment";
         $notification->is_read = false;
         $notification->user_id = $user->id;
         $notification->shame_id = $shame->id;
         $notification->comment_id = $comment->id;
         $notification->save();
     }
 }
Ejemplo n.º 14
0
 public function saveNotification($data)
 {
     $notify = new Notification();
     $notification_responce_time = '30';
     $time = date('Y-m-d H:i:s');
     $newtime = strtotime("{$time} + {$notification_responce_time} seconds");
     $expire = date('Y-m-d H:i:s', $newtime);
     $notify->sender_id = $data['sender_id'];
     $notify->reciver_id = $data['reciver_id'];
     $notify->message = $data['message'];
     $notify->type = $data['type'];
     $notify->expired_at = $expire;
     $notify->save();
     return $notify;
 }
Ejemplo n.º 15
0
 public function processRequest($userId, $eventId, $permit)
 {
     if ($permit == 0) {
         $status = 'declined';
         \DB::table('event_user')->where('event_id', '=', $eventId)->where('user_id', '=', $userId)->delete();
     } elseif ($permit == 1) {
         $status = 'approved';
         \DB::table('event_user')->where('event_id', $eventId)->where('user_id', $userId)->update(array('status' => $status));
         $notification = new Notification();
         $notification->user_id = $userId;
         $notification->text = 'You have been accepted for ';
         $notification->object_id = $eventId;
         $notification->save();
     }
     return redirect('/events/' . $eventId);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $this->validate($request, ['title' => 'required', 'type' => 'required', 'notes' => '', 'data' => 'required']);
     $title = $request->Input('title');
     $notes = $request->Input('notes');
     $type = $request->Input('type');
     $data = $request->Input('data');
     $notification = new Notification();
     $notification->title = $title;
     $notification->notes = $notes;
     $notification->type = $type;
     $notification->data = $data;
     $notification->save();
     $redirectURL = route('notifications.show', [$notification->id]);
     return response()->json(['redirectURL' => $redirectURL]);
 }
Ejemplo n.º 17
0
 public function postMessage(Request $request)
 {
     $this->pusher = App::make('pusher');
     $this->user = Auth::user();
     $this->chatChannel = self::DEFAULT_CHAT_CHANNEL;
     $this->friends = Enroll::getFriends(\Auth::user());
     $message = ['text' => e($request->input('chat_text')), 'avatar' => $this->user->profile, 'username' => $this->user->username, 'timestamp' => time() * 1000];
     $this->pusher->trigger(User::findOrFail(e($request->input('to')))->chat_key, 'new-message', $message);
     $this->pusher->trigger(Auth::user()->chat_key, 'new-message', $message);
     $message = new Message();
     $message->from_user_id = $this->user->id;
     $message->to_user_id = e($request->input('to'));
     $message->message = e($request->input('chat_text'));
     $message->save();
     $notification = new Notification();
     $notification->to = e($request->input('to'));
     $notification->from = $this->user->id;
     $notification->save();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $input = $request->input();
     $data = $request->only('to', 'subject');
     $rules = array('to' => 'required', 'subject' => 'required');
     $v = \Validator::make($data, $rules);
     if ($v->fails()) {
         return view('member.notification_create')->withErrors($v)->withInput($input);
     } else {
         $fid = Auth::user()->id;
         $insert = new Notification();
         $insert->from = $fid;
         $insert->to = $input['to'];
         $insert->subject = $input['subject'];
         $insert->message = $input['message'];
         $insert->status = 0;
         $insert->save();
         /*$insert=DB::table('notification')->insert(
         		['from' => $fid, 'to' => $input['to'],'subject' =>$input['subject'], 'message' => $input['message'], 'status' => 0]
         		);*/
         return \Redirect::to('notification');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     \Log::info('Expire notification started @ ' . \Carbon\Carbon::now());
     $tz = new \DateTimeZone('Asia/Kolkata');
     $today = \Carbon\Carbon::now($tz)->format('Y-m-d');
     $posts = Postjob::where(DB::raw('date(post_expire_Dt)'), '=', $today)->get(['id', 'unique_id', 'individual_id', 'corporate_id']);
     foreach ($posts as $post) {
         if ($post->individual_id != null) {
             $uid = User::where('induser_id', '=', $post->individual_id)->pluck('id');
         } else {
             if ($post->corporate_id != null) {
                 $uid = User::where('corpuser_id', '=', $post->corporate_id)->pluck('id');
             }
         }
         $notification = new Notification();
         $notification->from_user = null;
         $notification->to_user = $uid;
         $notification->remark = 'Your post - ' . $post->unique_id . ' getting expired today.';
         $notification->operation = 'job expire';
         $notification->save();
     }
     \Log::info('Expire notification ended @ ' . \Carbon\Carbon::now());
 }
Ejemplo n.º 20
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function notification($me, $user, $review)
 {
     // creating a notification
     $noti = new Notification();
     // notification instance
     $noti->user_id = $user->fr_usr_id;
     // the user who will get this notification
     $noti->subject_type = 'user';
     // user
     $noti->subject_id = $me;
     // the uset who liked the review
     $noti->object_type = 'review';
     // object is review
     $noti->object_id = $review;
     // id of the review in picture
     $noti->type = 'reply';
     // liked - notification type
     $noti->read = '0';
     // default '0' as it is unread
     $noti->time = time();
     // default '0' as it is unread
     $noti->save();
     // saves notification
 }
Ejemplo n.º 21
0
 public function applyForEvent($id)
 {
     $checkIfAdded = \DB::table('event_user')->select('*')->where('user_id', \Auth::id())->where('event_id', $id)->get();
     if (empty($checkIfAdded)) {
         \DB::table('event_user')->insert(array('user_id' => \Auth::id(), 'event_id' => $id, 'status' => 'pending'));
         //Send a notification to the host that someone wants to join
         $event = Event::find($id);
         $host = User::find($event->user_id);
         $notification = new Notification();
         $notification->user_id = $host->id;
         $notification->text = 'Someone asked to join';
         $notification->object_id = $event->id;
         $notification->save();
     }
     return redirect('/events/' . $id);
 }
Ejemplo n.º 22
0
 public function receive(Request $request)
 {
     $data = $request->json()->all();
     if (!$this->verifyArray($data, EmailController::EXPECTED_KEYS)) {
         return response(json_encode(['error' => 'Invalid data']), 400, ['Content-Type' => 'application/json']);
     }
     if ($data['signature'] != hash_hmac('sha256', $data['timestamp'] . $data['token'], env('CONTEXT_IO_SECRET'))) {
         return response(json_encode(['error' => 'Invalid signature']), 400, ['Content-Type' => 'application/json']);
     }
     $isForward = $this->isGmailForwardEmail($data);
     $body = null;
     if ($isForward) {
         $body = $this->downloadBody($data);
         $email = explode(' ', $body)[0];
     } else {
         // TODO: One day, support multiple to addresses and alert all verified addresses (once per account)
         $email = Arr::get($data, 'message_data.addresses.to.0.email');
     }
     // TODO: Make a different email for sending push notifications? Forwards keep the original message exactly as it
     // was. So, the forwarded message isn't from the account that initially received it, it's from the original
     // sender.
     /**
      * @var $email Email
      */
     $email = Email::whereEmail($email)->first();
     if (is_null($email)) {
         return response(json_encode(['error' => 'Unknown email']), 404, ['Content-Type' => 'application/json']);
     }
     if (!$email->user->pb_access_token) {
         return response(json_encode(['error' => 'Pushbullet not authenticated.']), 400, ['Content-Type' => 'application/json']);
     }
     if (!$email->verified) {
         return response(json_encode(['error' => 'Unverified email'], 400, ['Content-Type' => 'application/json']));
     }
     $notification = new Notification();
     if ($email->notifications()->count() < 1) {
         $contextIO = new ContextIO(env('CONTEXT_IO_KEY'), env('CONTEXT_IO_SECRET'));
         $message = $contextIO->getMessageBody(Arr::get($data, 'account_id'), ['label' => 0, 'folder' => Arr::get($data, 'message_data.folders.0'), 'message_id' => Arr::get($data, 'message_data.message_id'), 'type' => 'text/plain']);
         $notification->data = Arr::get($message->getData(), 'bodies.0.content');
     } else {
         $notification->data = null;
     }
     $notification->email_id = $email->id;
     $notification->subject = $this->replaceForwardPrefix(Arr::get($data, 'message_data.subject'));
     $notification->save();
     $this->dispatch(new PushJob($email->user->pb_access_token, $notification->subject));
     return response(json_encode(['status' => 'received']), 200, ['Content-Type' => 'application/json']);
 }
Ejemplo n.º 23
0
 public function create_transaction($domain, Request $request)
 {
     if ($this->user->status == 2) {
         return $this->responseBadRequest('Nhân viên này đang chuyển tiền.');
     } else {
         $this->user->status = 2;
         $this->user->save();
         $transaction = new Transaction();
         $transaction->status = 0;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $request->receiver_id;
         $transaction->receiver_money = User::find($request->receiver_id)->money;
         $transaction->money = $this->user->money;
         $transaction->save();
         $notification = new Notification();
         $notification->product_id = $transaction->id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = $request->receiver_id;
         $notification->type = 3;
         $notification->save();
         $data = array("message" => $notification->actor->name . " vừa chuyển tiền cho bạn và đang chờ bạn xác nhận.", "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
         $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
         Redis::publish('colorme-channel', json_encode($publish_data));
         return $this->respond(['transaction' => ['sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money]]);
     }
 }
Ejemplo n.º 24
0
 public function seekerRequestDone()
 {
     $accepted_job_id = Input::get('accepted_job_id');
     $accepted_job = AcceptedJob::find($accepted_job_id);
     $accepted_job->seeker_confirm_done = 1;
     $job = Job::find($accepted_job->job_id);
     $freelancer = User::find($job->freelancer_info_id);
     $seeker = User::find($accepted_job->seeker_id);
     //notif buat freelancer
     $notification = new Notification();
     $notification->user_id = $freelancer->id;
     $notification->notif = "Proyek untuk job " . $job->judul . " yang direquest oleh " . $seeker->name . " telah selesai";
     $notification->type = 4;
     $notification->save();
     // kalo freelancer juga udah setuju done
     if ($accepted_job->freelancer_confirm_done == 1) {
         // ubah status accepted job ini menjadi done
         $accepted_job->status = 1;
         $accepted_job->waktu_selesai = DB::raw('CURRENT_TIMESTAMP');
         $accepted_job->save();
     } else {
         $accepted_job->save();
     }
     return Redirect::to('seeker/accepted/' . $accepted_job_id);
 }
 public function performanceEdit(Request $request, $reportID)
 {
     $create_notification = false;
     for ($i = 0; $i < count($request->all()); $i++) {
         if ($request->input($i . '.include')) {
             $this->validate($request, [$i . '.id' => 'required|numeric', $i . '.position_id' => 'required|numeric', $i . '.department_id' => 'required|numeric', $i . '.project_id' => 'required|numeric', $i . '.output' => 'required|numeric', $i . '.target_id' => 'required', $i . '.date_start' => 'required|date', $i . '.date_end' => 'required|date', $i . '.hours_worked' => 'required|numeric', $i . '.daily_work_hours' => 'required|numeric', $i . '.output_error' => 'required|numeric', $i . '.message' => 'required']);
             if (!$create_notification) {
                 $admin = User::where('email', '*****@*****.**')->first();
                 $approval = new Approval();
                 $approval->action = 'update';
                 $approval->report_id = $reportID;
                 $approval->status = 'pending';
                 $approval->save();
                 $report = Report::where('id', $request->input($i . '.report_id'))->first();
                 $report->user_id = $request->user()->id;
                 $report->save();
                 // create a notification
                 $notification = new Notification();
                 $notification->message = 'updates ';
                 $notification->receiver_user_id = $admin->id;
                 $notification->sender_user_id = $request->user()->id;
                 $notification->subscriber = 'admin';
                 $notification->state = 'main.approvals';
                 $notification->event_id = $report->id;
                 $notification->event_id_type = 'report_id';
                 $notification->seen = false;
                 $notification->save();
                 $notify = DB::table('reports')->join('users', 'users.id', '=', 'reports.user_id')->join('projects', 'projects.id', '=', 'reports.project_id')->join('notifications', 'notifications.event_id', '=', 'reports.id')->select('reports.*', 'users.*', DB::raw('LEFT(users.first_name, 1) as first_letter'), 'projects.*', 'notifications.*')->where('notifications.id', $notification->id)->first();
                 event(new ReportSubmittedBroadCast($notify));
                 // report
                 $create_notification = true;
             }
             $target = Target::withTrashed()->where('id', $request->input($i . '.target_id'))->first();
             $performance_approval = new PerformanceApproval();
             $performance_approval->approval_id = $approval->id;
             $performance_approval->report_id = $reportID;
             $performance_approval->message = $request->input($i . '.message');
             // $performance_approval->result_id = $request->input($i.'.result_id');
             $performance_approval->performance_id = $request->input($i . '.id');
             $performance_approval->member_id = $request->input($i . '.member_id');
             $performance_approval->position_id = $request->input($i . '.position_id');
             $performance_approval->department_id = $request->input($i . '.department_id');
             $performance_approval->project_id = $request->input($i . '.project_id');
             $performance_approval->target_id = $target->id;
             $performance_approval->date_start = Carbon::parse($request->input($i . '.date_start'));
             $performance_approval->date_end = Carbon::parse($request->input($i . '.date_end'));
             $performance_approval->daily_work_hours = $request->input($i . '.daily_work_hours');
             $performance_approval->output = $request->input($i . '.output');
             $performance_approval->hours_worked = $request->input($i . '.hours_worked');
             $performance_approval->output_error = $request->input($i . '.output_error');
             // Round((Output / Hours Worked) * Daily Work Hours)
             // store the rounded value
             $performance_approval->average_output = round($request->input($i . '.output') / $request->input($i . '.hours_worked') * $request->input($i . '.daily_work_hours'), 2);
             // average output / target output * 100 to convert to percentage
             $performance_approval->productivity = round($performance_approval->average_output / $target->productivity * 100, 1);
             // 1 - output w/error / output * 100 to convert to percentage
             $performance_approval->quality = round((1 - $performance_approval->output_error / $performance_approval->output) * 100, 1);
             // Quadrant
             if ($performance_approval->productivity < 100 && $performance_approval->quality >= $target->quality) {
                 $performance_approval->quadrant = 'Quadrant 1';
             } else {
                 if ($performance_approval->productivity >= 100 && $performance_approval->quality >= $target->quality) {
                     $performance_approval->quadrant = 'Quadrant 2';
                 } else {
                     if ($performance_approval->productivity >= 100 && $performance_approval->quality < $target->quality) {
                         $performance_approval->quadrant = 'Quadrant 3';
                     } else {
                         if ($performance_approval->productivity < 100 && $performance_approval->quality < $target->quality) {
                             $performance_approval->quadrant = 'Quadrant 4';
                         }
                     }
                 }
             }
             // save performance_approval request to database
             $performance_approval->save();
         }
     }
 }
Ejemplo n.º 26
0
 public function confirm_transaction(Request $request)
 {
     $transaction_id = $request->id;
     $status = $request->status;
     $transaction = Transaction::find($transaction_id);
     if ($transaction->status != 0) {
         return json_encode(['error' => 'Giao dịch không ở trạng thái pending', 'status' => transaction_status($transaction->status), 'money' => currency_vnd_format($transaction->receiver->money)]);
     }
     $transaction->status = $status;
     $transaction->sender->status = 0;
     if ($status == 1) {
         $transaction->sender->money = $transaction->sender->money - $transaction->money;
         $transaction->receiver->money = $transaction->receiver->money + $transaction->money;
     }
     $transaction->save();
     $transaction->sender->save();
     $transaction->receiver->save();
     $notification = new Notification();
     $notification->product_id = $transaction->id;
     $notification->actor_id = $transaction->receiver->id;
     $notification->receiver_id = $transaction->sender->id;
     $notification->type = 4;
     $notification->save();
     $data = array("message" => "Bạn chuyển tiền cho " . $transaction->receiver->name . " " . transaction_status_raw($transaction->status), "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
     $publish_data = array("event" => "notification", "data" => $data);
     Redis::publish('colorme-channel', json_encode($publish_data));
     $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
     Redis::publish('colorme-channel', json_encode($publish_data));
     $return_data = array('status' => transaction_status($transaction->status), 'money' => currency_vnd_format($transaction->receiver->money));
     return json_encode($return_data);
 }
Ejemplo n.º 27
0
 public function store_comment(Request $request)
 {
     $comment_content = $request->comment_content;
     $product_id = $request->product_id;
     //send one notifcation to author
     if (Product::find($product_id)->author->id != $this->user->id) {
         $notification = new Notification();
         $notification->product_id = $request->product_id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = Product::find($product_id)->author->id;
         $notification->type = 1;
         $notification->save();
         $data = array("message" => $notification->actor->name . " đã bình luận về bài viết của bạn", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
     }
     $product = Product::find($product_id);
     $already_sent_noti = array();
     //send to all others that involve in the post
     foreach ($product->comments as $comment) {
         $commenter_id = $comment->commenter_id;
         if ($product->author->id != $commenter_id && $commenter_id != $this->user->id && !in_array($commenter_id, $already_sent_noti)) {
             $notification = new Notification();
             $notification->product_id = $request->product_id;
             $notification->actor_id = $this->user->id;
             $notification->receiver_id = $commenter_id;
             $notification->type = 2;
             $notification->save();
             $data = array("message" => $notification->actor->name . " cũng đã bình luận về bài viết mà bạn đã bình luận", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
             $publish_data = array("event" => "notification", "data" => $data);
             Redis::publish('colorme-channel', json_encode($publish_data));
             $already_sent_noti[] = $commenter_id;
         }
     }
     $comment = new Comment();
     $comment->product_id = $product_id;
     $comment->commenter_id = $this->user->id;
     $comment->content = $comment_content;
     $comment->save();
     $view = View::make('components.comment_item', ['comment' => $comment]);
     $contents = $view->render();
     $publish_data = array("event" => "comment", "data" => $contents);
     Redis::publish('colorme-channel', json_encode($publish_data));
     return time_elapsed_string(strtotime($comment->created_at));
 }
Ejemplo n.º 28
0
 public function newLink($id)
 {
     try {
         $newLink = Connections::where('user_id', '=', Auth::user()->induser_id)->where('connection_user_id', '=', $id)->first();
         if ($newLink == null) {
             $connections = new Connections();
             $connections->user_id = Auth::user()->induser_id;
             $connections->connection_user_id = $id;
             $connections->save();
             // notification
             $to_user = User::where('induser_id', '=', $id)->pluck('id');
             if ($to_user != null) {
                 $notification = new Notification();
                 $notification->from_user = Auth::user()->id;
                 $notification->to_user = $to_user;
                 $notification->remark = 'has sent link request.';
                 $notification->operation = 'link request';
                 $notification->save();
             }
         }
     } catch (\Illuminate\Database\QueryException $e) {
         $errorCode = $e->errorInfo[1];
         if ($errorCode == 1062) {
             return redirect('/home');
         }
     }
     return 'success';
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $create_report = false;
     for ($i = 0; $i < count($request->all()); $i++) {
         if ($request->input($i . '.include')) {
             $this->validate($request, [$i . '.member.id' => 'required|numeric', $i . '.position_id' => 'required|numeric', $i . '.project_id' => 'required|numeric', $i . '.target_id' => 'required|numeric', $i . '.output' => 'required|numeric', $i . '.date_start' => 'required|date', $i . '.date_end' => 'required|date', $i . '.hours_worked' => 'required|numeric', $i . '.daily_work_hours' => 'required|numeric', $i . '.output_error' => 'required|numeric']);
             // check if a report is already created
             if (!$create_report) {
                 $admin = User::where('role', 'admin')->first();
                 $report = new Report();
                 $report->user_id = $request->user()->id;
                 $report->department_id = $request->user()->department_id;
                 $report->project_id = $request->input($i . '.project_id');
                 $report->daily_work_hours = $request->input($i . '.daily_work_hours');
                 $report->date_start = $request->input($i . '.date_start');
                 $report->date_end = $request->input($i . '.date_end');
                 $report->save();
                 // create a notification
                 $notification = new Notification();
                 $notification->message = 'submitted a ';
                 $notification->sender_user_id = $request->user()->id;
                 $notification->receiver_user_id = $admin->id;
                 $notification->subscriber = 'admin';
                 $notification->state = 'main.weekly-report';
                 $notification->event_id = $report->id;
                 $notification->event_id_type = 'report_id';
                 $notification->seen = false;
                 $notification->save();
                 $notify = DB::table('reports')->join('users', 'users.id', '=', 'reports.user_id')->join('projects', 'projects.id', '=', 'reports.project_id')->join('notifications', 'notifications.event_id', '=', 'reports.id')->select('reports.*', 'users.*', DB::raw('LEFT(users.first_name, 1) as first_letter'), 'projects.*', 'notifications.*')->where('notifications.id', $notification->id)->first();
                 // foreach ($query as $key => $value) {
                 //     $notify = $value;
                 // }
                 event(new ReportSubmittedBroadCast($notify));
                 $activity_type = ActivityType::where('action', 'create')->first();
                 $activity = new Activity();
                 $activity->report_id = $report->id;
                 $activity->user_id = $request->user()->id;
                 $activity->activity_type_id = $activity_type->id;
                 $activity->save();
                 // report
                 $create_report = true;
             }
             // $target = Target::where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->first();
             $target = Target::withTrashed()->where('id', $request->input($i . '.target_id'))->first();
             $performance = new Performance();
             $performance->report_id = $report->id;
             $performance->member_id = $request->input($i . '.member.id');
             $performance->position_id = $request->input($i . '.position_id');
             $performance->department_id = $request->user()->department_id;
             $performance->project_id = $request->input($i . '.project_id');
             $performance->target_id = $target->id;
             $performance->output = round($request->input($i . '.output'), 2);
             $performance->date_start = $request->input($i . '.date_start');
             $performance->date_end = $request->input($i . '.date_end');
             $performance->hours_worked = round($request->input($i . '.hours_worked'), 2);
             $performance->daily_work_hours = $request->input($i . '.daily_work_hours');
             $performance->output_error = round($request->input($i . '.output_error'), 2);
             // Round((Output / Hours Worked) * Daily Work Hours)
             // store the rounded value
             $performance->average_output = round($request->input($i . '.output') / $request->input($i . '.hours_worked') * $request->input($i . '.daily_work_hours'), 2);
             // average output / target output * 100 to convert to percentage
             $performance->productivity = round($performance->average_output / $target->productivity * 100, 2);
             // 1 - output w/error / output * 100 to convert to percentage
             $performance->quality = round((1 - $performance->output_error / $performance->output) * 100, 2);
             // Quadrant
             if ($performance->productivity < 100 && $performance->quality >= $target->quality) {
                 $performance->quadrant = 'Quadrant 1';
             } else {
                 if ($performance->productivity >= 100 && $performance->quality >= $target->quality) {
                     $performance->quadrant = 'Quadrant 2';
                 } else {
                     if ($performance->productivity >= 100 && $performance->quality < $target->quality) {
                         $performance->quadrant = 'Quadrant 3';
                     } else {
                         if ($performance->productivity < 100 && $performance->quality < $target->quality) {
                             $performance->quadrant = 'Quadrant 4';
                         }
                     }
                 }
             }
             // $performance->type = "weekly";
             $performance->save();
             // fetch target
             // $productivity = Target::where('type', 'Productivity')->where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->where('created_at', '<=', $request->input($i.'.date_end'))->orderBy('created_at', 'desc')->first();
             // if(!$productivity)
             // {
             //      $productivity = Target::where('type', 'Productivity')->where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->first();
             // }
             // $quality = Target::where('type', 'Quality')->where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->where('created_at', '<=', $request->input($i.'.date_end'))->orderBy('created_at', 'desc')->first();
             // if(!$quality)
             // {
             //      $quality = Target::where('type', 'Quality')->where('position_id', $request->input($i.'.position_id'))->where('experience', $request->input($i.'.experience'))->first();
             // }
             // $performance->productivity_id = $productivity->id;
             // $performance->quality_id = $quality->id;
         }
     }
 }
Ejemplo n.º 30
0
 public function addSearchUser(Request $request)
 {
     $group = Group::findOrFail($request['add_group_id']);
     $group->users()->attach($request['add_user_id']);
     $to_user = User::where('induser_id', '=', $request['add_user_id'])->pluck('id');
     if ($to_user != null) {
         $notification = new Notification();
         $notification->from_user = Auth::user()->id;
         $notification->to_user = $to_user;
         $notification->remark = 'has added you to group: ' . $group->group_name;
         $notification->operation = 'group';
         $notification->save();
     }
     return redirect('/group/' . $request['add_group_id']);
 }