Ejemplo n.º 1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $posts = Post::orderBy('created_at', 'desc')->take(5)->get();
     $reservations = Reservation::where('valide', '<', 2)->get();
     $velos = Velo::all();
     return view('admin.dashboard')->with(['posts' => $posts, 'reservations' => $reservations, 'velos' => $velos]);
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function storeSession(Request $request)
 {
     $request->session()->put('date', $request['f-reservation_date']);
     $request->session()->put('time', $request['f-reservation_time']);
     $request->session()->put('pax', $request['f-reservation_persons']);
     $request->session()->put('name', $request['f-user_name']);
     $request->session()->put('email', $request['f-user_email']);
     $tableNumbersTaken = array();
     $data = $request->session()->all();
     $pax = $data['pax'];
     $date = $data['date'];
     $tables = Tables::where("pax", "{$pax}")->get();
     foreach ($tables as $table) {
         $tableNumbersFree = explode(',', $table->table_nrs);
     }
     $reservations = Reservation::where('pax', "{$pax}")->where('date', "{$date}")->get();
     foreach ($reservations as $reservation) {
         array_push($tableNumbersTaken, $reservation->table);
     }
     $tableReserve = array_diff($tableNumbersFree, $tableNumbersTaken);
     $request->session()->put('freetable', $tableReserve);
     $data = $request->session()->all();
     $items = array();
     foreach ($data as $key => $value) {
         $items = $value;
     }
     $result = array_combine($items, $items);
     return \View::make('reservation/table', compact('result', $result));
 }
Ejemplo n.º 3
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $customer = \Auth::User();
     $reservations = Reservation::where('customer_id', $customer->id)->get();
     $cruises = collect([]);
     foreach ($reservations as $reservation) {
         $cruises->push(Cruise::where('id', $reservation->cruise_id)->first());
     }
     $ports = Port::all();
     return view('pages.reservation', compact('customer', 'reservations', 'cruises', 'ports'));
 }
Ejemplo n.º 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get all reservations that are still valid.
     $reservations = Reservation::where('State', '=', 'fresh')->get();
     // Get the configuration information.
     $config = Configuration::find(0);
     foreach ($reservations as $reservation) {
         // Check if they should become expired.
         if (date('Y-m-d', strtotime($reservation->Created) + 86400 * $config->ReservationLife) < date('Y-m-d')) {
             $reservation->State = 'late';
             $reservation->save();
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Define the application's command schedule.
  * call this ' * * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1 '
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->call(function () {
         $reservations = Reservation::where('end_date', '<', Carbon::now())->where('status', Reservation::STATUS_ACCEPTED)->get();
         foreach ($reservations as $reservation) {
             $reservation->status = Reservation::STATUS_DONE;
             if ($reservation->save()) {
                 $room = $reservation->room;
                 $count = (int) $room->occupants - 1;
                 $count = $count > 0 ? $count : 0;
                 $room->occupants = $count;
                 $room->save();
             }
         }
     })->daily();
 }
 /**
  * Check available rooms
  *
  * @return array
  */
 public function checkAvailability(Request $request)
 {
     //add params start_date, end_date
     //Start date_input
     $input = $request->all();
     $currentOccupants = [];
     $rooms = Room::all();
     $check_date = Reservation::whereBetween('start_date', [$input['start_date'], $input['end_date']])->get();
     foreach ($rooms as $index => $room) {
         # code...
         $currentOccupants[$index] = Reservation::where('room_id', $room->id)->where('status', 'accepted')->where('start_date', '<=', [$input['start_date']])->where('end_date', '>=', [$input['end_date']])->count();
     }
     // //EOF date_input
     //display all_table
     $all_table = Room::where('availability', 'vacant')->get();
     // return view('welcome')->with('table',$table);
     return view('welcome')->with(compact('check_date', 'input', 'all_table', 'currentOccupants'));
 }
Ejemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $nbRes = Reservation::where('user_id', '=', Auth::user()->id)->where('valide', '<=', 1)->count();
     if ($nbRes < 3) {
         $velo = Velo::findOrFail($request->input('idVelo'));
         // Création d'une nouvelle reservation
         $reservation = new Reservation(['valide' => 0]);
         $reservation->user()->associate(Auth::user());
         $reservation->velo()->associate($velo);
         $reservation->save();
         // Création des demi journéées choisies
         $values = $request->all();
         $keys = array_keys($values);
         $newDJ = array();
         unset($keys[0]);
         //on retire le token
         for ($i = 1; $i < sizeof($values) - 2; $i += 2) {
             // -2 pour retirer le veloId
             //control des champs
             $regles = array($keys[$i] => 'required', $keys[$i + 1] => 'required');
             $validation = Validator::make($values, $regles);
             if ($validation->fails()) {
                 Session::flash('info', 'Le formulaire envoyé comportait des champs vides !');
                 $reservation->delete();
                 foreach ($newDJ as $dj) {
                     $dj->delete();
                 }
                 return redirect()->back();
             } else {
                 //formattage de la date
                 $date = explode('-', $values[$keys[$i]]);
                 $date = $date[2] . '-' . $date[1] . '-' . $date[0];
                 $demijournee = new Demijournee(['date' => $date, 'periode' => $values[$keys[$i + 1]]]);
                 $demijournee->reservation()->associate($reservation);
                 $demijournee->save();
                 $newDJ[] = $demijournee;
             }
         }
         return redirect()->route('location.show', ['location' => $reservation->id]);
     } else {
         Session::flash('info', 'Vous ne pouvez pas avoir plus de trois réservations en attente ! Merci de votre compréhension.');
         return redirect()->back();
     }
 }
 public function cron()
 {
     $reservations = Reservation::where('end_date', '<', Carbon::now())->where('status', Reservation::STATUS_ACCEPTED)->get();
     foreach ($reservations as $reservation) {
         $reservation->status = Reservation::STATUS_DONE;
         if ($reservation->save()) {
             $room = $reservation->room;
             $count = (int) $room->occupants - 1;
             $count = $count > 0 ? $count : 0;
             $room->occupants = $count;
             if ($room->save()) {
                 return 'success';
             } else {
                 return 'error room';
             }
         } else {
             return 'error reservation';
         }
     }
 }
Ejemplo n.º 9
0
 public function something()
 {
     $date = date('d/m/Y', strtotime($request->get('date')));
     $time = $request->get('time');
     $reservations = Reservation::where('reservation_date', $date)->where('time', $time)->get();
     $ids = [];
     foreach ($reservations as $reservation) {
         $amenity = $reservation->amenityLoad()->first();
         if ($amenity->quantity < $amenity->limit) {
             $ids[] = $amenity->id;
         }
     }
     $rooms = null;
     $available = null;
     if (count($ids) == 0) {
         $rooms = Amenity::all();
     } else {
         $rooms = Amenity::whereNotIn('id', $ids)->room()->get();
     }
 }
Ejemplo n.º 10
0
 public function dataSelection($room, $block, $year, $month, $day, $atention, $medic)
 {
     $date = $year . "-" . $month . "-" . $day;
     $checkRoom = ReservationInfo::where('reservationDate', '=', $date)->where('block_id', '=', $block)->where('room', '=', $room)->count();
     if ($checkRoom == 0) {
         //revisar si el medico tiene ocupada esas horas
         $findMedicConflict = Reservation::where('medic_id', $medic)->where('reservationDate', $date)->get();
         $checkMedic = 0;
         foreach ($findMedicConflict as $register) {
             $checkMedic += $register->ReservationsInfo->where('block_id', $block)->count();
         }
         if ($checkMedic == 0) {
             //
             $atention = Atention::find($atention);
             $numberOfBlocks = $atention->block_numbers;
             for ($i = 1; $i < $numberOfBlocks; $i++) {
                 $nextBlock = $block + $i;
                 $checkRoom = ReservationInfo::where('reservationDate', '=', $date)->where('block_id', '=', $nextBlock)->where('room', '=', $room)->count();
                 if ($checkRoom > 0) {
                     //cortar con un return, ya que hay una hora tomada despues
                     //que impide hacer la reserva en el bloque seleccionado
                     return response()->json(['estado' => 'invalido', 'mensaje' => 'La sala esta ocupada']);
                 }
                 $checkMedic = 0;
                 foreach ($findMedicConflict as $register) {
                     $checkMedic += $register->ReservationsInfo->where('block_id', $nextBlock)->count();
                 }
                 if ($checkMedic > 0) {
                     //medico ocupado
                     return response()->json(['estado' => 'invalido', 'mensaje' => 'El medico esta ocupado en uno de los bloques']);
                 }
             }
             $initialBlock = Block::find($block);
             $lastBlockId = $block + $numberOfBlocks - 1;
             $encontro = false;
             $lastBlock;
             while ($encontro == false) {
                 if (!($lastBlock = Block::find($lastBlockId))) {
                     $lastBlockId--;
                 } else {
                     $encontro = true;
                 }
             }
             $respuesta = ['estado' => 'valido', 'inicio' => $initialBlock->startBlock, 'fin' => $lastBlock->finishBlock, 'bloques' => $numberOfBlocks, 'blolqueInicial' => $initialBlock->id, 'bloqueFinal' => $lastBlock->id];
             return response()->json($respuesta);
         } else {
             //el medico esta ocupado en ese bloque
             return response()->json(['estado' => 'invalido', 'mensaje' => 'El medico esta ocupado a esa hora']);
         }
     } else {
         //la sala esta ocupada en ese horario
         return response()->json(['estado' => 'invalido', 'mensaje' => 'La sala esta ocupada a esa hora']);
     }
 }
Ejemplo n.º 11
0
 /**
  * Responds to requests to POST /rooms/delete/
  */
 public function postDoDelete(Request $request)
 {
     $this->validate($request, ['delete_id' => 'required|integer']);
     $user = \Auth::user();
     $delete_room = \App\Room::find($request->delete_id);
     $reservations = \App\Reservation::where('room_id', $delete_room->id)->get();
     $timeslots = \App\Timeslot::where('room_id', $delete_room->id)->get();
     if ($user->user_role == 'admin') {
         foreach ($reservations as $reservation) {
             $reservation->delete();
         }
         foreach ($timeslots as $timeslot) {
             $timeslot->delete();
         }
         $delete_room->delete();
         \Session::flash('flash_message', $delete_room->room_name . ' has been deleted.');
         return redirect('/rooms');
     } else {
         \Session::flash('flash_message', 'You don&#39;t have the previlege to delete this room.');
         return redirect('/rooms');
     }
 }
$reservations = array();
if (!isset($startDate) && !isset($endDate)) {
    $startDate = date('Y-m-d', strtotime(date('Y-m-d') . '-1 days'));
    $endDate = date('Y-m-d H:i:s');
}
// By default reservation Code will take more importance than any other parameter.
if (isset($reservationCode) && $reservationCode != '') {
    $reservations = Reservation::where('Id', '=', $reservationCode)->get();
} else {
    if (isset($institutionId) && $institutionId != 0) {
        $reservations = Reservation::where('CreditorType', '=', 2)->where('CreditorId', '=', $institutionId)->where('Created', '>', $startDate . ' 00:00:00')->where('Created', '<', $endDate . '23:59:00')->get();
    } else {
        if (isset($clientId) && $clientId != '') {
            $reservations = Reservation::where('CreditorType', '=', 2)->where('CreditorId', '=', $institutionId)->where('Created', '>', $startDate . ' 00:00:00')->where('Created', '<', $endDate . '23:59:00')->get();
        } else {
            $reservations = Reservation::where('Created', '>', $startDate . ' 00:00:00')->where('Created', '<', $endDate . '23:59:00')->get();
        }
    }
}
function reservationState($reservation)
{
    switch ($reservation->State) {
        case 'fresh':
            return 'Reservacion valida.';
            break;
        case 'delete':
            return 'Reservacion eliminada.';
            break;
        case 'used':
            return 'Reservacion usada.';
            break;
 public function download()
 {
     $reservations = Reservation::where('status', Reservation::STATUS_ACCEPTED)->get();
     $total_earnings = 0;
     foreach ($reservations as $reservation) {
         $days = new Carbon($reservation->start_date);
         $days = $days->diffInDays(new Carbon($reservation->end_date));
         if ($days == 0) {
             $days = 1;
         }
         $total_price = (int) $days * (double) $reservation->price;
         $total_earnings += $total_price;
     }
     $reservations = Reservation::where('status', Reservation::STATUS_ACCEPTED)->paginate(10);
     $data = [];
     $all_data = array();
     foreach ($reservations as $reservation) {
         $days = new Carbon($reservation->start_date);
         $days = $days->diffInDays(new Carbon($reservation->end_date));
         if ($days == 0) {
             $days = 1;
         }
         $total_price = (int) $days * (double) $reservation->price;
         $all_data[] = array('person' => $reservation->person->first_name . ' ' . $reservation->person->last_name, 'days' => $days, 'total_price' => $total_price);
     }
     Excel::create('Earnings_Overview_' . Carbon::now()->toDateString(), function ($excel) use($all_data, $total_earnings, $reservations) {
         $excel->sheet('New sheet', function ($sheet) use($all_data, $total_earnings, $reservations) {
             $sheet->loadView('excel.template')->with(compact('all_data', 'reservations', 'total_earnings'));
         });
     })->download('xls');
 }
Ejemplo n.º 14
0
 public function history()
 {
     $data['content'] = \App\Reservation::where('patient_id', Auth::id())->get();
     return view('frontend.pages.patient.history', compact('data'));
 }
Ejemplo n.º 15
0
 /**
  * Function that deletes Transaction.
  *
  * @return Response
  */
 public function deleteAuthenticated()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('id' => 'required'));
     $response = array();
     if ($validator->fails()) {
         $response['state'] = 'Error';
         $response['error'] = 'La identification de la transaccion es necesaria!';
         return response()->json($response);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         $response['state'] = 'No Autorizado';
         $response['error'] = 'Usuario no autorizado!';
         return response()->json($response);
     }
     // Verify the user first.
     $userToVerify = User::where('Username', '=', Input::get('username'))->first();
     if (!$userToVerify) {
         $response['state'] = 'Error';
         $response['error'] = 'Este usuario no existe!';
         return response()->json($response);
     }
     if (Auth::validate(array('Username' => Input::get('username'), 'password' => Input::get('password') . $userToVerify->Salt, 'Type' => 1))) {
         // If user was verified make sure user has permission to withdraw money.
         $permissions = json_decode(UserLevel::find($userToVerify->UserLevel)->Permissions);
         if ($permissions->permissions->cashbox->delete->can != "true") {
             $response['state'] = 'Error';
             $response['d'] = $permissions->permissions->cashbox->delete->can;
             $response['error'] = 'Este usuario no tiene permitido eliminar transacciones!';
             return response()->json($response);
         }
     } else {
         $response['state'] = 'Error';
         $response['error'] = 'Usuario o contraseña incorrectos!';
         return response()->json($response);
     }
     // Get transaction Data.
     $transaction = CashboxTransaction::find(Input::get('id'));
     if (!$transaction) {
         $response['state'] = 'Fail';
         $response['error'] = 'Esta transaccion no existe!';
         return response()->json($response);
     }
     // Get cashbox.
     $cashbox = Cashbox::find($transaction->CashboxId);
     // Get worker.
     $worker = Worker::find(User::find($cashbox->UserId)->TypeId);
     if ($transaction->Type == 1 || $transaction->Type == 8) {
         // Get sale.
         $sale = Sale::where('TransactionId', '=', $transaction->Id)->first();
         // Get items in sale.
         $items = SaleBreakdown::where('SaleId', '=', $sale->Id)->get();
         // Loop trough sales breakdown and add products and materials back to stock.
         foreach ($items as $item) {
             $product = Stock::where('Code', '=', $item->Code)->where('BranchId', '=', $sale->BranchId)->first();
             if (!$product) {
                 $service = Service::where('Code', '=', $item->Code)->where('BranchId', '=', $sale->BranchId)->first();
                 // Get materials.
                 $materials = json_decode($service->Materials);
                 foreach ($materials as $material => $quantity) {
                     // Update Stock.
                     $product = Stock::where('Code', '=', $material)->where('BranchId', '=', $sale->BranchId)->first();
                     $product->AverageCost = ($product->AverageCost * $product->Quantity + $product->Cost * $quantity) / ($product->Quantity + $quantity);
                     $product->Quantity += $quantity;
                     $product->save();
                 }
             } else {
                 // Update product.
                 $product->AverageCost = ($product->AverageCost * $product->Quantity + $item->Cost * $item->Quantity) / ($product->Quantity + $item->Quantity);
                 $product->Quantity += $item->Quantity;
                 $product->save();
             }
             // Delete item.
             $item->delete();
         }
         // Now delete sale and trasaction.
         $sale->delete();
         $transaction->delete();
         // Now return transaction data.
         $response['state'] = 'Success';
         $response['message'] = 'Transaccion eliminada!';
         return response()->json($response);
     } else {
         if ($transaction->Type == 7) {
             // Get the cash receipt.
             $receipt = CashReceipt::where('TransactionId', '=', $transaction->Id)->first();
             // Get the contract.
             $contract = Contract::find($receipt->TypeId);
             // Now delete receipt.
             $receipt->delete();
             // Delete transaction.
             $transaction->delete();
             // If contract is not in late state then that means we might need to update the state.
             if ($contract->State != 'late') {
                 // Get today's date.
                 $today = date_create(date('Y-m-d'));
                 // Get the contract Payments.
                 $contractPayments = CashReceipt::where('Type', '=', 1)->where('TypeId', '=', $contract->Id)->get();
                 // Get the amount of time that has passed since contract has been created.
                 $time = date_diff($today, date_create($contract->StartDate));
                 // Check how many intervals have passed.
                 $passedIntervals = 0;
                 if ($contract->QuotaInterval == 'mensuales') {
                     $passedIntervals = floor($time->format('%m'));
                 } else {
                     if ($contract->QuotaInterval == 'quincenales') {
                         /* 1 Month has an average of 4.34524 weeks*/
                         $passedIntervals = floor($time->format('%a') / 7) / 4.34524;
                         $decimal = $passedIntervals - floor($passedIntervals);
                         if ($decimal >= 0.5) {
                             $passedIntervals = floor($passedIntervals) * 2 + 1;
                         } else {
                             $passedIntervals = floor($passedIntervals) * 2;
                         }
                     } else {
                         if ($contract->QuotaInterval == 'semanales') {
                             $passedIntervals = floor($time->format('%a') / 7);
                         }
                     }
                 }
                 // Now finally get the expected payment.
                 $expectedPayment = $passedIntervals * $contract->Quota;
                 // If it is over the Debt of the contract reset it to contract value.
                 if ($expectedPayment > $contract->Debt) {
                     $expectedPayment = $contract->Debt;
                 }
                 // Calculate real payments.
                 $realPayment = 0;
                 foreach ($contractPayments as $contractPayment) {
                     $realPayment += $contractPayment->Value;
                 }
                 if ($realPayment < $expectedPayment) {
                     $contract->State = 'late';
                     $contract->save();
                 }
             }
             // Now return transaction data.
             $response['state'] = 'Success';
             $response['message'] = 'Pago a contrato eliminado!';
             return response()->json($response);
         } else {
             if ($transaction->Type == 9) {
                 // If it's a reservation get the reservation with this transaction Id.
                 $reservation = Reservation::where('TransactionId', '=', $transaction->Id)->first();
                 $reservation->State = 'deleted';
                 $reservation->save();
                 // Now delete transaction.
                 $transaction->delete();
                 // Now return transaction data.
                 $response['state'] = 'Success';
                 $response['message'] = 'Deposito y reservacion eliminados!';
                 return response()->json($response);
             } else {
                 // Check if this is a payment for a provider bill.
                 if ($transaction->Type == 2) {
                     // Get the provider bill information.
                     $providerBillPayment = ProviderBillPayment::where('TransactionId', '=', $transaction->Id)->first();
                     // Get the provider bill and provider.
                     $providerBill = ProviderBill::find($providerBillPayment->ProviderBillId);
                     // Check if bill has credit.
                     if ($providerBill->Credit) {
                         // Set as unpaid (No way you can delete a payment and still stay paid -.-).
                         $providerBill->State = 1;
                         $providerBill->save();
                         // Delete payment.
                         $providerBillPayment->delete();
                         $response['message'] = 'Transaccion eliminada!';
                     } else {
                         // Get sale breakdown.
                         $items = ProviderBillBreakdown::where('ProviderBillId', '=', $providerBill->Id)->get();
                         $response['items'] = $items;
                         // Get the branch of the current worker.
                         $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
                         // Loop through them and update stock.
                         foreach ($items as $item) {
                             // Get product.
                             $product = Stock::where('Code', '=', $item->Code)->where('BranchId', '=', $branchId)->first();
                             // Update it.
                             $totalAfter = $product->Quantity - $item->Quantity;
                             $product->AverageCost = ($product->AverageCost * $product->Quantity - $item->CurrentCost * $item->Quantity) / $totalAfter;
                             $product->Quantity -= $item->Quantity;
                             $product->save();
                             //Delete breakdown.
                             $item->delete();
                         }
                         // Delete transaction, bill, and billpayment.
                         $response['message'] = 'Transaccion eliminada! Al ser el unico pago de una factura de contado se ha eliminado tambien la factura del Proveedor y retirado los productos del Inventario.';
                         $providerBill->delete();
                         $providerBillPayment->delete();
                         $transaction->delete();
                     }
                     // Return what we have.
                     $response['state'] = 'Success';
                 } else {
                     // No special action needed just delete it.
                     $transaction->delete();
                     $response['message'] = 'Transaccion eliminada!';
                     $response['state'] = 'Success';
                 }
                 return response()->json($response);
             }
         }
     }
 }