예제 #1
0
 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');
 }
 public function update($service_plan, Request $request)
 {
     $month_string = $request->input('active_month')['name'];
     $plan_keys = $request->only('hours_available_year', 'standard_rate', 'hours_available_month');
     $plan_keys['start_date'] = \Carbon\Carbon::parse($month_string);
     $plan_keys['client_id'] = $service_plan->client_id;
     $plan_keys['last_backup_datetime'] = $service_plan->last_backup_datetime;
     $plan_keys['skip_default_benefits'] = true;
     $new_plan = ServicePlan::create($plan_keys);
     $service_plan->archive($new_plan->id);
     return $new_plan;
 }
 /** @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);
     }
 }
예제 #4
0
 /**
  * @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;
 }