public function postSetupBusiness()
 {
     if (Auth::check() && Helper::isNotAnOwner(Helper::userId())) {
         // PAG added permission checking
         $business_data = $_POST;
         $business = new Business();
         $business_check = Business::businessExistsByNameByAddress($business_data['business_name'], $business_data['business_address']);
         if (count($business_check) != 1) {
             $business->name = $business_data['business_name'];
             $business->local_address = $business_data['business_address'];
             $business->industry = $business_data['industry'];
             $business->longitude = $business_data['longitude'];
             $business->latitude = $business_data['latitude'];
             $time_open_arr = Helper::parseTime($business_data['time_open']);
             $business->open_hour = $time_open_arr['hour'];
             $business->open_minute = $time_open_arr['min'];
             $business->open_ampm = $time_open_arr['ampm'];
             $time_close_arr = Helper::parseTime($business_data['time_close']);
             $business->close_hour = $time_close_arr['hour'];
             $business->close_minute = $time_close_arr['min'];
             $business->close_ampm = $time_close_arr['ampm'];
             /*
              * @author CSD
              * @description:
              * set default num terminals to 3 when creating a business
              * set default queue limit to 9999 max
              */
             $business->queue_limit = 9999;
             $business->num_terminals = 1;
             $business->save();
             $business_user = new UserBusiness();
             $business_user->user_id = $business_data['user_id'];
             $business_user->business_id = $business->business_id;
             $business->timezone = $business_data['timezone'];
             /* Timezone is already set in config/app.php
                date_default_timezone_set("Asia/Manila"); // Manila Timezone for now but this depends on business location
                */
             $contents = '
             {
               "box1": {
                 "number": "1",
                 "terminal": "",
                 "rank": ""
               },
               "box2": {
                 "number": "2",
                 "terminal": "",
                 "rank": ""
               },
               "box3": {
                 "number": "3",
                 "terminal": "",
                 "rank": ""
               },
               "box4": {
                 "number": "4",
                 "terminal": "",
                 "rank": ""
               },
               "box5": {
                 "number": "5",
                 "terminal": "",
                 "rank": ""
               },
               "box6": {
                 "number": "6",
                 "terminal": "",
                 "rank": ""
               },
               "get_num": " ",
               "display": "1-6",
               "show_issued": true,
               "ad_image": "",
               "ad_video": "\\/\\/www.youtube.com\\/embed\\/EMnDdH8fdEc",
               "ad_type": "image",
               "turn_on_tv": false,
               "tv_channel": "",
               "date": "' . date("mdy") . '",
               "ticker_message" : "",
               "ticker_message2" : "",
               "ticker_message3" : "",
               "ticker_message4" : "",
               "ticker_message5" : ""
             }
         ';
             File::put(public_path() . '/json/' . $business->business_id . '.json', $contents);
             $business_user->save();
             $branch_id = Branch::createBusinessBranch($business->business_id, $business->name);
             $service_id = Service::createBranchService($branch_id, $business->name);
             /* @CSD Auto issue on business create */
             $issueController = new IssueNumberController();
             $issueController->getMultiple($service_id, 10);
             /* Auto issue end */
             $terminals = Terminal::createBranchServiceTerminal(Auth::user()->user_id, $service_id, $business->num_terminals);
             if ($business->save()) {
                 return json_encode(['success' => 1, 'terminals' => $terminals]);
             } else {
                 return json_encode(['success' => 0, 'error' => 'Something went wrong while saving your business.']);
             }
         } else {
             $error = "Business name already exists with the same business address.";
             return json_encode(['success' => 0, 'error' => $error]);
         }
     } else {
         return json_encode(array('success' => 0, 'error' => 'You are not allowed to access this function or you already have a business account.'));
     }
 }