Ejemplo n.º 1
0
 public function checkIn2($userId, $locationId, $sign_in_method, $currentTime = "")
 {
     /*
      Logic: If the user is a monthly user, then leave payment to the scheduled
      agreement already set in Recurly.
      If the user is a daily user, then auto charge for the current day.
      If there is an error with the processing, return an error code, otherwise return
      empty string.
     */
     $this->load->model("issuesmodel");
     $result = "";
     if ($currentTime == "") {
         $currentTime = date(DATE_ISO8601);
     }
     $um = new UserModel();
     $user = $um->init($userId);
     $daysSinceLastCharge = 1000;
     try {
         $account = new Recurly_Account($userId);
         $charges = new Recurly_AdjustmentList($userId, array('type' => 'charge'));
         if (count($charges) > 0) {
             //$then = new DateTime(date("Y-m-d H:i:s O", $charges[0]->start_date));
             //$now = new DateTime(date("Y-m-d H:i:s O"));
             //$interval = $now->diff($then);  // doesn't work with php 5.2
             //$daysSinceLastCharge = (int) $interval->format("%a");
             $then = date("Y-m-d H:i:s O", $charges[0]->start_date);
             $now = date("Y-m-d H:i:s O");
             $interval = utilities::date_diff($then, $now);
             $daysSinceLastCharge = $interval;
         }
         //echo "daysSinceLastCharge = $daysSinceLastCharge<br />";
         //$this->issuesmodel->logMemberIssue($userId, "daysSinceLastCharge = $daysSinceLastCharge");
         $requirePayment = false;
         //$this->issuesmodel->logMemberIssue($userId, "\$requirePayment = " . $requirePayment);
         //$this->issuesmodel->logMemberIssue($userId, "\$user->membership_plan_code = " . $user->membership_plan_code);
         if ($user->membership_plan_code == "daily") {
             // charge for today if they haven't been charged
             $requirePayment = $daysSinceLastCharge > 1;
         }
         //$this->issuesmodel->logMemberIssue($userId, "\$requirePayment = " . $requirePayment);
         if ($requirePayment) {
             // charge for today if they haven't been charged
             // TODO: find the user's current reservation and get the cost from there.
             // If there is not a reservation, check availability.  If availability is
             // good, then get going rate for space.  Otherwise, throw NoAvailableSpace
             // exception.
             $query = $this->db->get("configuration");
             $row = $query->row();
             $dailyRate = $row->daily_rate;
             $details = "[CHK-PARK01-1D]: Charging \$dailyRate for " . date("m-d-Y");
             $this->makeSinglePayment($userId, $dailyRate, $details);
         }
     } catch (Exception $e) {
         $issueId = $this->issuesmodel->logMemberIssue($userId, "About to check-in user, but failed attempting to charge them. " . $e->getMessage(), MemberIssueType::BILLING);
         //$this->issuesmodel->closeMemberIssue($issueId);
     }
     //echo $this->userInfo->id;
     //echo "The date/time is $currentTime<br />";
     //$this->issuesmodel->logMemberIssue($userId, "About to insert into the signin_sheet");
     $this->db->insert("signin_sheet", array("user_id" => $userId, "location_id" => $locationId, "sign_in_method" => $sign_in_method, "sign_in" => $currentTime));
     $result = $this->db->insert_id();
     return $result;
 }