public function index(Client $clients)
 {
     $plan = $clients->service_plan()->select('id', 'start_date', 'hours_available_month', 'hours_available_year', 'standard_rate')->first();
     $plan_array = $plan->toArray();
     $plan_array['start_date'] = $plan->start_date->timestamp * 1000;
     return json_encode($plan_array);
 }
 public function getClientDashboard($client_id = null)
 {
     if (!$client_id) {
         return null;
     }
     $client = \RTMatt\MonthlyService\Client::find($client_id);
     return view("rtclientdashboard::components.dashboard-component", ['dashboard_data' => $client->getServiceReport(), 'dashboard_id' => $client->id, 'admin_mode' => true]);
 }
 /** @test */
 public function it_returns_client_services_object_and_200_when_all_is_well()
 {
     $plan = factory(ServicePlan::class, 1)->create();
     $client = Client::find($plan->client_id);
     $key = $client->generateApiKey();
     $header = $key->api_name . ":" . \Hash::make($key->api_secret_key);
     $header_encoded = base64_encode($header);
     $response = $this->get(route('client-services-summary'), ['HTTP_Authorization' => $header_encoded])->seeJsonStructure(['last_backup', 'monthly', 'annual', 'description']);
     $this->assertResponseOk();
 }
 public function getIndex()
 {
     $master_layout = config('rtclientmanager.layout_file');
     $layout_section = config('rtclientmanager.layout_section');
     $clients = \RTMatt\MonthlyService\Client::all();
     if (!view()->exists($master_layout)) {
         $master_layout = 'rtclientmanager::layouts.admin';
     }
     $admin_mode = true;
     return view('rtclientmanager::manager.client-manager', compact('master_layout', 'clients', 'admin_mode', 'layout_section'));
 }
 public function store(Request $request)
 {
     $this->validate($request, ['actual' => 'required', 'expected' => 'required', 'contact_email' => 'email', 'attachment' => 'image'], ['actual.required' => 'Please tell us what\'s happening', 'expected.required' => 'Please tell us what should happen', 'contact_email.email' => 'Please enter a valid email address we can use to contact you', 'attachment.image' => 'Please only attach images in a valid format (jpg, jpeg, png, gif)']);
     if ($client = Client::getFromAuth($request->header('authorization'))) {
         $request->merge(['client_id' => $client->id]);
     }
     try {
         \RTMatt\MonthlyService\PriorityAlertProcessor::process($request->all());
     } catch (\Exception $e) {
         dd($e);
         return response('An error occurred processing the request', 500);
     }
     return response("Alert processed", 200);
 }
 public function getServicesSummary(Request $request)
 {
     $authorization = $request->header('authorization');
     list($auth_name, $auth_key) = \RTMatt\MonthlyService\Helpers\RTBasicAuthorizationParser::create($authorization)->getParsedValues();
     $client = Client::getByAPIName($auth_name);
     if (!$client) {
         return response('Unable to find client data for supplied API key', 404);
     }
     if (!$client->hasActivePlan()) {
         return response("Owner of API key does not have an active plan", 204);
     }
     $report = $client->getServiceReport();
     if ($report->last_backup instanceof Carbon) {
         $report->last_backup = $report->last_backup->diffForHumans();
     }
     return json_encode($report);
 }
 public function test($client_id = null)
 {
     if (!$client_id) {
         $rt_client = \RTMatt\MonthlyService\Client::first();
     } else {
         $rt_client = \RTMatt\MonthlyService\Client::find($client_id);
     }
     if (!$rt_client) {
         return "No client found";
     }
     $key = $rt_client->api_key;
     $username = $key->api_name;
     $password = \Hash::make($key->api_secret_key);
     $client = new Client(['base_uri' => config('rtclientdashboard.api_base_url')]);
     $response = $client->request('GET', route('client-services-summary'), ['auth' => [$username, $password]]);
     $dashboard_data = json_decode($response->getBody()->getContents());
     $auth = base64_encode("{$username}:{$password}");
     return view('rtclientdashboard::dashboard', compact('dashboard_data', 'rt_client', 'client_id', 'auth'));
 }
示例#8
0
 /**
  * @param $fields
  *
  * @return static
  */
 private function createClient($attributes = [])
 {
     $fields = $this->getFields($attributes);
     $client = \RTMatt\MonthlyService\Client::create($fields);
     return $client;
 }
示例#9
0
 public static function serviceReport($client_id)
 {
     $client = Client::findOrFail($client_id);
     return $client->getServiceReport();
 }