/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //Get all reports where type = cucm_daily
     $reports = Report::where('type', 'cucm_daily')->get();
     //Get all configured CUCM clusters
     $clusters = $this->cluster->all();
     //Set timestamp for file names
     $timeStamp = Carbon::now('America/New_York')->toDateTimeString();
     //Create array to track attachments
     $attachments = [];
     //Loop reports
     foreach ($reports as $index => $report) {
         $attachments[$index] = $report->path . $report->name . '-' . $timeStamp . '.csv';
         //Persist report to disk
         Storage::put($attachments[$index], $report->csv_headers);
         //Loop each cluster and run the reports
         foreach ($clusters as $cluster) {
             $this->dispatch(new $report->job($cluster, $attachments[$index]));
         }
     }
     //Reports are done running, let's email to results
     $beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
     $beautymail->send('emails.cucmDailyReporting', [], function ($message) use($attachments) {
         //TODO: Create system for users to manage report subscriptions.
         $message->to(['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'])->subject('CUCM Daily Report');
         //Add all reports to email
         foreach ($attachments as $report) {
             $message->attach(storage_path($report));
         }
     });
 }
Пример #2
0
 /**
  * Display recommended product by customer
  *
  * 1. Product has viewed/purchased category/tag
  * 2. Product has size of purchased item
  * @return Response
  */
 public function recommended($user_id = 0)
 {
     //1. Check tag/category viewed
     $stat = \App\Models\StatUserView::userid($user_id)->statabletype(['App\\Models\\Category', 'App\\Models\\Tag'])->get(['statable_id'])->toArray();
     //1b. Get slugs
     $slugs = [];
     $purchased_prods = [];
     $purchased_varians = [];
     foreach ($stat as $key => $value) {
         $slugs[] = \App\Models\Cluster::find($value['statable_id'])['slug'];
     }
     $purchased = \App\Models\TransactionDetail::TransactionSellOn(['paid', 'packed', 'shipping', 'delivered'])->where('transactions.user_id', $user_id)->groupby('varian_id')->with(['varian', 'varian.product', 'varian.product.clusters'])->get()->toArray();
     foreach ($purchased as $key => $value) {
         //2. Check tag/category purchased
         foreach ($value['varian']['product']['clusters'] as $key2 => $value2) {
             $slugs[] = $value2['slug'];
         }
         $purchased_prods[] = $value['varian']['product_id'];
         $purchased_varians[] = $value['varian']['size'];
     }
     //2a. get slug of category/tag
     //2b. get product id
     //2c. get varian size
     $slug = array_unique($slugs);
     $productids = array_unique($purchased_prods);
     $variansize = array_unique($purchased_varians);
     $result = \App\Models\Product::sellable(true);
     if (!empty($slug)) {
         $result = $result->clustersslug($slug);
     }
     if (!empty($productids)) {
         $result = $result->notid($productids);
     }
     if (!empty($variansize)) {
         $result = $result->variansize($variansize);
     }
     $count = count($result->get());
     if (Input::has('skip')) {
         $skip = Input::get('skip');
         $result = $result->skip($skip);
     }
     if (Input::has('take')) {
         $take = Input::get('take');
         $result = $result->take($take);
     }
     $result = $result->with(['varians'])->get()->toArray();
     return new JSend('success', (array) ['count' => $count, 'data' => $result]);
 }
Пример #3
0
 public function resetPhone(Request $request)
 {
     //Get request input
     $phone = $request->input('name');
     $cluster = $request->input('cluster');
     //Get the cluster for the phone
     $cluster = Cluster::where('ip', $cluster)->first();
     //Create AXL client
     $axl = new AxlSoap($cluster);
     //Attempt a phone reset
     $response = $axl->phoneReset($phone);
     //Return response
     if (isset($response->return)) {
         return json_encode($response->return);
     } else {
         return $response;
     }
 }
 public function run()
 {
     Cluster::create(['id' => '1', 'cluster' => '1', 'subcluster' => '2', 'x' => '1', 'y' => '1', 'radar_chart' => 'link1']);
     Cluster::create(['id' => '2', 'cluster' => '1', 'subcluster' => '4', 'x' => '1', 'y' => '2', 'radar_chart' => 'link2']);
     Cluster::create(['id' => '3', 'cluster' => '2', 'subcluster' => '4', 'x' => '2', 'y' => '2', 'radar_chart' => 'link3']);
 }
Пример #5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $status = Input::get('status');
     if ($status == 'comment') {
         $comment_new = User_App_Comment::join('apps', 'apps.id', '=', 'user__app__comments.a_id')->join('users', 'users.id', '=', 'user__app__comments.u_id')->select('user__app__comments.id', 'users.name as user_name', 'users.id as user_id', 'users.img as user_img', 'apps.id as app_id', 'apps.name as app_name', 'apps.img_url as app_img', 'comment', 'user__app__comments.created_at')->orderBy('user__app__comments.created_at', 'desc')->where('user__app__comments.a_id', '=', $id);
         $return_all = $comment_new->get();
         $empty_test = $comment_new->first();
         if (empty($empty_test)) {
             return Response::json(array('message' => 'No comments', 'status' => 'error'));
         }
         return $return_all;
     }
     $app_detail = App::where('id', '=', $id)->first();
     $app_behaviors = App::join('app__behaviors', 'app__behaviors.a_id', '=', 'apps.id')->join('behaviors', 'behaviors.id', '=', 'app__behaviors.b_id')->where('apps.id', '=', $id)->select('behaviors.id', 'behaviors.name', 'behaviors.genre', 'app__behaviors.score')->orderBy('behaviors.genre', 'asc')->orderBy('behaviors.id', 'asc')->get();
     $app_comments = User_App_Comment::join('apps', 'apps.id', '=', 'user__app__comments.a_id')->join('users', 'users.id', '=', 'user__app__comments.u_id')->where('user__app__comments.a_id', '=', $id)->select('user__app__comments.id', 'users.id as user_id', 'users.name as user_name', 'apps.id as app_id', 'apps.name as app_name', 'apps.img_url as app_img', 'comment', 'user__app__comments.created_at as comment_time')->orderBy('user__app__comments.created_at', 'desc')->get();
     $app_favorite_counts = App::join('user__app__favorite', 'user__app__favorite.a_id', '=', 'apps.id')->where('apps.id', '=', $id)->count();
     $app_comment_counts = App::join('user__app__comments', 'user__app__comments.a_id', '=', 'apps.id')->where('apps.id', '=', $id)->count();
     $app_clusters = Cluster::join('apps', 'apps.cl_id', '=', 'clusters.id')->where('apps.id', '!=', $id)->where('clusters.id', '=', $app_detail['cl_id'])->get();
     $app_detail->behaviors = $app_behaviors;
     $app_detail->comments = $app_comments;
     $app_detail->favorite_count = $app_favorite_counts;
     $app_detail->comment_count = $app_comment_counts;
     $app_detail->group_app = $app_clusters;
     if (Auth::check()) {
         $user_id = Auth::user()->id;
         $check_suck = User::join('user__app__favorite', 'user__app__favorite.u_id', '=', 'users.id')->where('user__app__favorite.a_id', '=', $id)->where('user__app__favorite.u_id', '=', $user_id)->first();
         if (empty($check_suck)) {
             $user_favorite = "Not yet";
         } else {
             $user_favorite = "Already";
         }
     } else {
         $user_favorite = "Not login";
     }
     $app_detail->user_favorite = $user_favorite;
     $app_detail->success = 'success';
     return $app_detail;
 }
Пример #6
0
 /** 
  * observe cluster event deleting
  * 1. updated parent + child path
  * 2. Delete Child
  * 3. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function deleting($model)
 {
     $errors = new MessageBag();
     //1. Check varian relationship with transaction
     if ($model->products->count()) {
         $errors->add('cluster', 'Tidak dapat menghapus data yang berhubungan dengan produk varian yang pernah di stok &/ order.');
     }
     //2. Delete Child
     $childs = Cluster::orderBy('path', 'desc')->where('path', 'like', $model->path . ',%')->get();
     foreach ($childs as $child) {
         if (!$child->delete()) {
             $errors->add('cluster', $child->getError());
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
Пример #7
0
 /**
  * boot
  * observing model
  *
  */
 public static function boot()
 {
     parent::boot();
     Tag::observe(new ClusterObserver());
 }
Пример #8
0
 /**
  * Store a cluster
  *
  * @param type
  * @return Response
  */
 public function store($type = null)
 {
     if (!Input::has('category') && !Input::has('tag')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data cluster.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate Cluster Parameter
     if ($type == 'category') {
         $cluster = Input::get('category');
         $cluster_data = \App\Models\Category::findornew($cluster['id']);
     } else {
         $cluster = Input::get('tag');
         $cluster_data = \App\Models\Tag::findornew($cluster['id']);
     }
     //1a. Get original data
     if (is_null($cluster['id'])) {
         $is_new = true;
     } else {
         $is_new = false;
     }
     $cluster_rules = ['category_id' => 'numeric|exists:categories,id', 'name' => 'required|max:255', 'slug' => 'max:255|unique:categories,slug,' . (!is_null($cluster['id']) ? $cluster['id'] : '')];
     //1b. Validate Basic Cluster Parameter
     $validator = Validator::make($cluster, $cluster_rules);
     if (!$validator->passes()) {
         $errors->add('Cluster', $validator->errors());
     } else {
         //if validator passed, save cluster
         $cluster_data = $cluster_data->fill(['name' => $cluster['name'], 'type' => $cluster_data->type, 'category_id' => isset($cluster['category_id']) ? $cluster['category_id'] : 0]);
         if (!$cluster_data->save()) {
             $errors->add('Cluster', $cluster_data->getError());
         }
     }
     //End of validate cluster
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     $final_cluster = \App\Models\Cluster::id($cluster_data['id'])->with(['category', 'products'])->first()->toArray();
     return new JSend('success', (array) $final_cluster);
 }
Пример #9
0
 /**
  * @param $id
  * @return \BladeView|bool|\Illuminate\View\View
  */
 public function euEdit($id)
 {
     if (\Auth::user()->id != $id) {
         if (!\Auth::user()->hasRole(['admins', 'user-managers'])) {
             abort(403);
         }
     }
     $user = $this->user->find($id);
     $clusters = Cluster::lists('name', 'id');
     $page_title = "User | Edit";
     $page_description = trans('admin/users/general.page.edit.description', ['full_name' => $user->full_name]);
     // "Editing user";
     if (!$user->isEditable()) {
         abort(403);
     }
     $roles = $this->role->pushCriteria(new RolesByNamesAscending())->all();
     $perms = $this->perm->pushCriteria(new PermissionsByNamesAscending())->all();
     return view('user.edit', compact('user', 'clusters', 'roles', 'perms', 'page_title', 'page_description'));
 }
Пример #10
0
 /**
  * update 1st version
  *
  * @return void
  * @author 
  **/
 public function pointexpire($id)
 {
     $queue = new Queue();
     $pending = $queue->find($id);
     $parameters = json_decode($pending->parameter, true);
     $messages = json_decode($pending->message, true);
     $errors = new MessageBag();
     //check point expire on that day that havent get cut by transaction (or even left over)
     $points = PointLog::debit(true)->onactive([Carbon::parse($parameters['on'])->startOfDay()->format('Y-m-d H:i:s'), Carbon::parse($parameters['on'])->endOfDay()->format('Y-m-d H:i:s')])->haventgetcut(true)->with(['user'])->get()->toArray();
     foreach ($points as $idx => $point) {
         //1. Check tag/category viewed
         $stat = \App\Models\StatUserView::userid($point['user_id'])->statabletype(['App\\Models\\Category', 'App\\Models\\Tag'])->get(['statable_id'])->toArray();
         //1b. Get slugs
         $slugs = [];
         $purchased_prods = [];
         $purchased_varians = [];
         foreach ($stat as $key => $value) {
             $slugs[] = \App\Models\Cluster::find($value['statable_id'])['slug'];
         }
         $purchased = \App\Models\TransactionDetail::TransactionSellOn(['paid', 'packed', 'shipping', 'delivered'])->where('transactions.user_id', $point['user_id'])->groupby('varian_id')->with(['varian', 'varian.product', 'varian.product.clusters'])->get()->toArray();
         foreach ($purchased as $key => $value) {
             //2. Check tag/category purchased
             foreach ($value['varian']['product']['clusters'] as $key2 => $value2) {
                 $slugs[] = $value2['slug'];
             }
             $purchased_prods[] = $value['varian']['product_id'];
             $purchased_varians[] = $value['varian']['size'];
         }
         //2a. get slug of category/tag
         //2b. get product id
         //2c. get varian size
         $slug = array_unique($slugs);
         $productids = array_unique($purchased_prods);
         $variansize = array_unique($purchased_varians);
         $result = \App\Models\Product::sellable(true);
         if (!empty($slug)) {
             $result = $result->clustersslug($slug);
         }
         if (!empty($productids)) {
             $result = $result->notid($productids);
         }
         if (!empty($variansize)) {
             $result = $result->variansize($variansize);
         }
         $product = $result->orderby('price', 'desc')->take(4)->get()->toArray();
         $data = ['point' => $point, 'balin' => $parameters['store'], 'product' => $product];
         //send mail
         Mail::send('mail.' . $parameters['template'] . '.crm.point', ['data' => $data], function ($message) use($point, $parameters) {
             $message->to($point['user']['email'], $point['user']['name'])->subject(strtoupper($parameters['template']) . ' - POINT REMINDER');
         });
         $pnumber = $pending->process_number + 1;
         $messages['message'][$pnumber] = 'Sukses Mengirim Email ' . (isset($point['user']['name']) ? $point['user']['name'] : '');
         $pending->fill(['process_number' => $pnumber, 'message' => json_encode($messages)]);
         $pending->save();
     }
     return true;
 }