/**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Apartment $apartment, Lease $lease, Payment $payment)
 {
     //
     $tenants = $lease->tenants->lists('fullname', 'id');
     $tenant = $payment->tenant;
     if ($lease->depositBalance() != 0) {
         $payment_types = ['Rent' => 'Rent', 'Fee' => 'Fee', 'Deposit' => 'Deposit'];
     } else {
         $payment_types = ['Rent' => 'Rent', 'Fee' => 'Fee'];
     }
     return view('payments.edit', ['title' => 'Edit a Payment: ' . $lease->apartment->name . ' Lease: ' . $lease->startdate->format('n/j/y') . ' - ' . $lease->enddate->format('n/j/y'), 'apartment' => $apartment, 'lease' => $lease, 'tenants' => $tenants, 'tenant' => $tenant, 'payment' => $payment, 'payment_types' => $payment_types, 'payment_type' => $payment->payment_type]);
 }
示例#2
0
 /**
  * Test /leases/{leaseId}/terminate
  * @test
  */
 public function terminates_specific_lease()
 {
     $lease = Lease::mine($this->user->id)->active()->get()->last();
     $response = $this->getJson('/leases/' . $lease->uuid . '/terminate', 'DELETE', $this->user);
     $this->assertResponseStatus(200);
     $this->assertObjectHasAttributes($response->data, 'terminated_at');
 }
 /**
  * Creates a new lease and returns some basic details about it.
  * Request might also contain optional $_GET['duration'] parameter, otherwise a default value will be used.
  *
  * @param $string
  * @param Request $request
  * @return mixed
  */
 public function lease($string, Request $request)
 {
     $picker = $this->pickResource($string);
     if ($picker['error']) {
         return $this->respondWithError($picker['error']);
     }
     $resource = Resource::find($picker['resourceId']);
     $leaseParams = Lease::stub($resource->id, null, $request->duration);
     $lease = Lease::create($leaseParams);
     $response = ['leased_at' => Carbon::now(), 'links' => ['rel' => 'details', 'uri' => '/leases/' . $lease->uuid]];
     return $this->respond($response, 201);
 }
示例#4
0
 public function checkAvailability($start, $end)
 {
     // \DB::connection()->enableQueryLog();
     $return = false;
     $start = \Carbon\Carbon::parse($start);
     $end = \Carbon\Carbon::parse($end);
     $leases = \App\Lease::where('apartment_id', $this->id)->where(function ($q) use($start, $end) {
         $q->whereRaw('"' . $start . '" <= enddate');
         $q->whereRaw('"' . $end . '" >= startdate');
     })->get();
     $leases->count() == 0 ? $return = true : ($return = false);
     return $return;
 }
 /**
  * Terminates a specific lease.
  *
  * @param $leaseId
  * @return mixed
  */
 public function terminate($leaseId)
 {
     // Only terminate the lease if it both belongs to user + is active == accessible
     $leases = Lease::accessible($leaseId)->get();
     if ($leases->count() == 0) {
         return $this->respondWithError(201);
     }
     // Terminate the lease
     $lease = $leases->first();
     $lease->expires_at = Carbon::now();
     $lease->save();
     $response = ['terminated_at' => $lease->expires_at];
     return $this->respond($response);
 }
示例#6
0
 public function addSublease(Request $request)
 {
     $input = $request->all();
     $tenant = Tenant::find($input['tenant_id']);
     $lease = Lease::find($input['lease_id']);
     // lease->tenants()->where('tenant_id',$tenant->id)->sync([$tenant->id => ['sublessor_name' => $input['sublessor_name']]]);
     $lease_tenant = $lease->tenants()->where('tenant_id', $tenant->id)->first();
     $lease_tenant->pivot->sublessor_name = $input['sublessor_name'];
     $lease_tenant->pivot->save();
     return redirect()->route('apartments.lease.show', ['name' => $lease->apartment->name, 'id' => $lease->id]);
 }
示例#7
0
 public function terminate(Apartment $apartment, Lease $lease, Request $request)
 {
     $input = $request->all();
     //Set the End Date
     $lease->enddate = Carbon::parse($input['enddate']);
     $lease->save();
     foreach ($lease->details as $detail) {
         $detail_first_day = Carbon::parse('first day of ' . date("F", mktime(0, 0, 0, $detail->month, 10)) . ' ' . $detail->year);
         $detail_last_day = Carbon::parse('last day of ' . date("F", mktime(0, 0, 0, $detail->month, 10)) . ' ' . $detail->year);
         // echo $detail_last_day . ": ";
         if ($detail_last_day >= Carbon::parse('first day of ' . date("F", mktime(0, 0, 0, $lease->enddate->month, 10)) . " " . $lease->enddate->year)) {
             if ($detail_last_day <= Carbon::parse('last day of ' . date("F", mktime(0, 0, 0, $lease->enddate->month, 10)) . " " . $lease->enddate->year)) {
                 //Modify Mulitiplier on Last Month
                 $multiplier = $lease->enddate->day / date('t', strtotime($lease->enddate->format('Y-m-d')));
                 // echo "Modify Multiplier: " . $multiplier . "<br>";
                 $detail->multiplier = $multiplier;
                 $detail->monthly_rent = round($lease->monthly_rent * $multiplier, 2);
                 $detail->monthly_pet_rent = round($lease->pet_rent * $multiplier, 2);
                 $detail->save();
             } else {
                 //Delete Future Lease Details
                 // echo "Delete Future Details<br>";
                 $detail->delete();
             }
         }
     }
     return redirect()->route('apartments.lease.show', ['name' => $lease->apartment->name, 'id' => $lease->id]);
 }