public function cancelVoucher($voucherid) { $percentage_charged = 0; $voucher = Voucher::findOrFail($voucherid); $daysToBooking = Voucher::getDaysToBooking($voucher)->days; $cancellation_policies = CancellationPolicy::where('hotel_id', $voucher->hotel_id)->get(); foreach ($cancellation_policies as $policy) { if ($daysToBooking >= $policy->from && $daysToBooking <= $policy->to) { $percentage_charged = $policy->percentage_charged; break; } else { if (empty($policy->to)) { $percentage_charged = $policy->percentage_charged; break; } } } $bookingAmount = Voucher::getVoucherAmount($voucher); $cancellation_amount = $bookingAmount * $percentage_charged * 0.01; $voucher->val = 0; $voucher->cancellation_amount = $cancellation_amount; $voucher->save(); $agent_user = $voucher->booking->user; $pdf = PDF::loadView('emails/cancellation-voucher', array('voucher' => $voucher)); $pdf->save(public_path() . '/temp-files/cancellation-voucher.pdf'); $hotel = Hotel::findOrFail($voucher->hotel_id); $hotel_users = $hotel->user; Mail::send('emails/cancellation-voucher-mail', array('voucher' => $voucher), function ($message) use($voucher, $agent_user, $hotel_users) { $message->attach(public_path() . '/temp-files/cancellation-voucher.pdf')->subject('Cancellation Voucher :' . $voucher->reference_number)->from('*****@*****.**'); if (!empty($hotel_users)) { foreach ($hotel_users as $hotel_user) { $message->to($hotel_user->email, $hotel_user->first_name); } } if (!empty($agent_user)) { $message->to($agent_user->email, $agent_user->first_name); } }); Booking::getTotalBookingAmount($voucher->booking); return Redirect::back(); }
/** * Update the specified hotel in storage. * * @param int $id * @return Response */ public function update($id) { $hotel = Hotel::findOrFail($id); $validator = Validator::make($data = Input::all(), Hotel::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $hotel->nome_br = $data['nome_br']; $hotel->nome_en = $data['nome_en']; $hotel->descricao_br = $data['descricao_br']; $hotel->descricao_en = $data['descricao_en']; $hotel->estrelas = $data['estrelas']; $hotel->pais_id = $data['pais_id']; $hotel->valor = $data['valor']; $hotel->cidade = $data['cidade']; //$hotel->estado = $data['estado']; $hotel->publicado = $data['publicado']; if (Input::hasFile('imagem')) { $up_success = $this->uploadImage(Input::file('imagem'), 'hoteis'); if ($up_success) { $hotel->imagem = $up_success['filename']; } } $hotel->save(); if (Input::has('caracteristicas')) { $hotel->caracteristicas()->sync(Input::get('caracteristicas')); } if (Input::hasFile('imagens')) { $imagens = Input::file('imagens'); $imagens = array_filter($imagens); foreach ($imagens as $img) { $imginfo = $this->uploadImage($img, 'hoteis'); if ($imginfo) { $imagem = new Imagem(); $imagem->nome = $imginfo['filename']; $imagem->caminho = $imginfo['destinationPath']; $hotel->imagens()->save($imagem); } } } return Redirect::to('admin/hotel/')->with('success', array('Registro salvo.')); }
/** * Update the specified hotel in storage. * * @param int $id * @return Response */ public function update($id) { $hotel = Hotel::findOrFail($id); $validator = Validator::make($data = Input::all(), Hotel::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $hotel->update($data); return Redirect::route('hotels.index'); }