/** * Show the application dashboard. * * @return Response */ public function getCount(\Illuminate\Http\Request $request) { // Validate API Key $apiKey = \App\Models\ApiKey::where('api_key', $request->get('apiKey'))->where('active', 1)->first(); if (!$apiKey) { return \Response::json(['status' => 'Error', 'error' => 'Invalid API Key.'], 401); } // Validate Data if (!$request->has('name')) { return \Response::json(['status' => 'Error', 'error' => 'The name field is required.'], 400); } if (!$request->has('count') && !$request->has('value')) { return \Response::json(['status' => 'Error', 'error' => 'Either the count or value field is required.'], 400); } $user = $apiKey->user; $counter = $user->counters()->where('name', $request->get('name'))->first(); if (!$counter) { $counter = \App\Models\Counter::create(['user_id' => $user->id, 'name' => $request->get('name'), 'type' => $request->has('count') ? \App\Models\Counter::CounterTypeCount : \App\Models\Counter::CounterTypeValue]); } else { if ($counter->type == \App\Models\Counter::CounterTypeCount && !$request->has('count')) { return \Response::json(['status' => 'Error', 'error' => 'Stat "' . $request->get('name') . '" already exists and is a counter stat, but the "count" field was not included.'], 422); } if ($counter->type == \App\Models\Counter::CounterTypeValue && !$request->has('value')) { return \Response::json(['status' => 'Error', 'error' => 'Stat "' . $request->get('name') . '" already exists and is a value stat, but the "value" field was not included.'], 422); } } $bean = \App\Models\Bean::create(['counter_id' => $counter->id, 'value' => $counter->type == \App\Models\Counter::CounterTypeCount ? $request->get('count') : $request->get('value')]); if ($request->has('timestamp')) { $bean->created_at = \Carbon\Carbon::createFromTimestampUTC($request->get('timestamp')); $bean->save(); } return \Response::json(['status' => 'Success'], 200); }
public function rows($id, $counter_id) { if (!($counter = Counter::find($counter_id))) { return $this->try_($counter); } $config = Grids::make($id)->toRowDatasetConfig($id); $filters = $config['source']->custom_filters(); $config['source']->custom_filters($filters + ['test' => 'bills.counter_id = ' . $counter_id]); return $this->dataset($config); }
/** * Show the application dashboard. * * @return Response */ public function getView() { $view = view('graph.view'); $now = \Carbon\Carbon::now('America/Denver'); $units = \App\Models\Counter::$units; $counters = \App\Models\Counter::whereIn('id', explode(',', \Request::get('counterIDs')))->get(); if (\Request::has('interval')) { $interval = intval(\Request::get('interval')); $intervalUnit = substr(\Request::get('interval'), strlen($interval)); if (!in_array($intervalUnit, \App\Models\Counter::$units)) { $intervalUnit = 'w'; } } else { $interval = 1; $intervalUnit = 'w'; } $rangeStart = \Request::has('start') ? \Carbon\Carbon::parse(\Request::get('start'), 'America/Denver') : $now->copy()->subDays(14); $rangeEnd = \Request::has('end') ? \Carbon\Carbon::parse(\Request::get('end'), 'America/Denver') : $now->copy(); if ($rangeEnd > $now) { $rangeEnd = $now->copy(); } if ($rangeEnd < $rangeStart) { $rangeStart = $rangeEnd->copy()->subDays(14); } $dataPoints = []; $currentInterval = $rangeStart->copy(); foreach ($counters as $counter) { $dataPoints[$counter->name] = $counter->graphValues($rangeStart, $rangeEnd, $intervalUnit, $interval); } // dd($dataPoints); $labels = []; foreach (array_keys(array_first($dataPoints, function () { return true; })) as $k) { $labels[] = $k; } $colors = ['RGBA(220, 7, 35, {alpha})', 'RGBA(54, 160, 177, {alpha})', 'RGBA(32, 41, 70, {alpha})']; $datasets = []; $colorIndex = 0; foreach ($dataPoints as $key => $point) { $dataset = ['label' => $key, 'fillColor' => str_replace('{alpha}', '0.2', $colors[$colorIndex]), 'strokeColor' => str_replace('{alpha}', '1', $colors[$colorIndex]), 'pointColor' => str_replace('{alpha}', '1', $colors[$colorIndex]), 'pointStrokeColor' => "#fff", 'pointHighlightFill' => "#fff", 'pointHighlightStroke' => "rgba(220,220,220,1)", 'data' => []]; foreach ($point as $value) { $dataset['data'][] = $value; } $datasets[] = $dataset; $colorIndex++; } $view->labels = $labels; $view->datasets = $datasets; return $view; }
/** * Устанавливает статус для заказа "Оплата подтверждена магазином" self::STATUS_PAID_SHOP * Прикрепляет билеты для заказа * * @param string $message - сообщение для статуса * * @return bool */ public function paid($message = null) { // выдача билетов $tickets_counter = $this->getProduct()->getField('tickets_counter'); for ($i = 0; $i < $tickets_counter; $i++) { Ticket::insert(['request_id' => $this->getId(), 'code' => substr(str_shuffle("012345678901234567890123456789"), 0, 12), 'date_insert' => time()]); } $this->addStatusToShop(self::STATUS_PAID_CLIENT); $this->addStatusToClient(self::STATUS_PAID_SHOP); $this->update(['is_paid' => 1]); $dostavka = $this->getField('dostavka'); switch ($dostavka) { case 1: $this->addStatusToClient(self::STATUS_DOSTAVKA_GET_MYSELF_POLET_WAIT); break; case 2: $this->addStatusToClient(self::STATUS_DOSTAVKA_GET_MYSELF_VOZNESENIE_WAIT); break; case 3: $this->addStatusToClient(['status' => self::STATUS_DOSTAVKA_MOSCOW_WAIT, 'message' => 'Наш посланник пытается с вами связаться для передачи подарка']); break; case 4: $this->addStatusToClient(['status' => self::STATUS_DOSTAVKA_RUSSIA_PREPARE, 'message' => 'Подарок находится в режиме подготовки к отправке']); break; case 5: $this->addStatusToClient(['status' => self::STATUS_DOSTAVKA_WORLD_PREPARE, 'message' => 'Подарок находится в режиме подготовки к отправке']); break; } // отправка письма Application::mail($this->getClient()->getEmail(), 'Ваш подарок', 'new_request_client', ['request' => $this]); Application::mail(\Yii::$app->params['mailer']['payment'], 'Заказ оплачен', 'new_request_shop', ['request' => $this]); // прибавление счетчика \app\models\Counter::inc($this->getProduct()->getPrice()); return true; }
protected function addControls() { $this->addControl(\Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('code')->caption('Cod Contor')->class('form-control data-source integer')->controlsource('code')->controltype('textbox')->maxlength(255))->addControl(\Easy\Form\Combobox::make('~layouts.form.controls.comboboxes.combobox')->name('type_utility_id')->caption('Tip Utilizare')->class('form-control data-source input-group form-select init-on-update-delete')->controlsource('type_utility_id')->controltype('combobox')->enabled('false')->options(Counter::utilitate()))->addControl(\Easy\Form\Combobox::make('~layouts.form.controls.comboboxes.combobox')->name('provider_id')->caption('Denumire Furnizor')->class('form-control data-source input-group form-select init-on-update-delete')->controlsource('provider_id')->controltype('combobox')->enabled('false')->options(['0' => '--Nu exista denumire --']))->addControl(\Easy\Form\Textbox::make('~layouts.form.controls.textboxes.textbox')->name('client_code')->caption('Cod Client')->class('form-control data-source')->controlsource('client_code')->controltype('textbox')->maxlength(255)); }
/** * Show the application dashboard. * * @return Response */ public function getView($counterID) { $counter = \App\Models\Counter::where('id', $counterID)->first(); return view('counter.view', ['counter' => $counter]); }
public static function type_supplier() { return Counter::utilitate(); return ['0' => '--Alege--', '1' => 'Electricitate', '2' => 'Gaze Naturale', '3' => 'Apa Potabila', '4' => 'Energie Termica', '5' => 'Combustibili Lichizi']; }