Ejemplo n.º 1
0
 public function updateCompany(CompanyService $company, GoogleApiService $google, $user_id, $company_id)
 {
     $retrieve = ['name', 'employee_count', 'tax_vat_number', 'description', 'street_name', 'street_number', 'building_name', 'building_floor', 'building_room', 'city_town', 'province', 'region_state', 'zip_code', 'country', 'founded_date', 'founded_month', 'founded_year', 'contact_first_name', 'contact_last_name', 'contact_title', 'contact_phone', 'contact_email', 'status_message'];
     try {
         $input = Request::only($retrieve);
         $validation = $company->validateCompany($input, $company_id);
         if (!$validation->fails()) {
             $address = $input['street_name'] . ', ' . $input['city_town'] . ', ' . $input['zip_code'] . ', ' . $input['country'];
             $input['lat'] = 0;
             $input['lng'] = 0;
             $geocode = $google->geoCoding($address);
             if ($geocode['status'] == 'OK') {
                 $input['lat'] = $geocode['lat'];
                 $input['lng'] = $geocode['lng'];
                 $response = $company->updateCompany($user_id, $company_id, $input);
                 if (!empty($response)) {
                     return $this->json_response->success($response);
                 }
                 return $this->json_response->error($response);
             } else {
                 return $this->json_response->error(['validation_message' => $geocode['status']]);
             }
         } else {
             return $this->json_response->error(['validation_message' => $validation->messages()]);
         }
     } catch (Exception $e) {
         return $this->json_response->error(['error' => $e->getMessage()]);
     }
 }