public function putBackup(ServicePlan $service_plan, Request $request) { $timestamp = $request->input('timestamp'); if (empty($timestamp)) { return response("Include a timestamp to log a backup.", 400); } $carbon = \Carbon\Carbon::createFromTimestamp(floor($timestamp / 1000)); $service_plan->update(['last_backup_datetime' => $carbon]); $format = $carbon->toDateTimeString(); return response()->json(['backup_datetime' => $format]); }
/** @test */ public function it_can_retrieve_its_plan() { $client = $this->createClient(); $plan = factory(ServicePlan::class)->create(['client_id' => $client->id]); $plan_obj = ServicePlan::find($plan->id); $this->assertEquals($client->service_plan, $plan_obj); }
public function store(Request $request) { $client_data = $request->only('name', 'primary_contact_name', 'primary_contact_email', 'primary_contact_phone'); $plan_data = $request->only('hours_available_month', 'hours_available_year', 'standard_rate', 'start_date'); $plan_data['start_date'] = \Carbon\Carbon::parse(\Carbon\Carbon::createFromTimestamp($plan_data['start_date'])->format('F Y')); $client = Client::create($client_data); $client->generateApiKey(); $plan_data['client_id'] = $client->id; $client = $client->toArray(); $plan = ServicePlan::create($plan_data); return compact('client'); }
/** @test */ public function it_shows_proper_numbers_for_monthly_usage_and_availability() { $plan = \RTMatt\MonthlyService\ServicePlan::create(['client_id' => $this->client->id, 'start_date' => new \Carbon\Carbon('March 1, 2015'), 'description' => 'This is the plan description ' . str_random(10), 'last_backup_datetime' => new \Carbon\Carbon('3 days ago'), 'hours_available_month' => 5, 'hours_available_year' => 45]); $used_hours = 0; $month_usage = []; foreach ($plan->service_months as $service_month) { $month_hours = rand(0, 5); // echo "\r\n\r\n".$month_hours . "used for ".$service_month->start_date->format('F'); $used_hours += $month_hours; $service_month->update(['hours_used' => $month_hours]); $month_usage[$service_month->start_date->format('F')] = $month_hours; } $client_report = new \RTMatt\MonthlyService\ClientServiceReport($plan); $this->assertTrue(is_array($client_report->monthly)); foreach ($client_report->monthly as $month) { $this->assertInstanceOf('\\RTMatt\\MonthlyService\\ClientMonthUsageReport', $month); $this->assertEquals($month_usage[$month->getReporter()->start_date->format('F')], $month->hours_used); $this->assertEquals(5, $month->hours_available); $this->assertEquals($month_usage[$month->getReporter()->start_date->format('F')] / 5 * 100, $month->percentage_used); } }
/** * @param $client * * @return static * @throws \RTMatt\MonthlyService\Exceptions\ServicePlanNoDateException */ private function createPlan($client, $args = []) { $plan = \RTMatt\MonthlyService\ServicePlan::create(['client_id' => $client->id, 'hours_available_year' => !empty($args['hours_available_year']) ? $args['hours_available_year'] : rand(6, 12), 'hours_available_month' => !empty($args['hours_available_month']) ? $args['hours_available_month'] : rand(1, 5), 'start_date' => !empty($args['start_date']) ? $args['start_date'] : \Carbon\Carbon::now(), 'description' => !empty($args['description']) ? $args['description'] : str_random(200)]); return $plan; }