public function reservationListAction() { //get societe/location and serving $reponse = new Reponse(); $societe = $this->societe; $locations = $societe->getLocations(); //if location is not defined we take the first in the list $initiallocationid = $locations[0]->getId(); if ($this->getParam('locationid')) { $locationid = $this->getParam('locationid'); } else { $locationid = $initiallocationid; } $this->view->locations = $locations; $mylocation = Object_Location::getById($locationid, 1); if ($mylocation instanceof Object_Location) { //we check if we are in the Editor if ($_POST['action']) { //if REMOVE if ($_POST['action'] == "remove") { foreach ($_POST['id'] as $id) { $myreservation = Object_Reservation::getById($id, 1); if ($myreservation instanceof Object_Reservation) { $myreservation->SetStatus('cancelled'); $myreservation->save(); } } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = ''; } //if EDIT if ($_POST['action'] == "edit") { $myreservation = Object_Reservation::getById($_POST['id'], 1); if ($_POST['data']['guestid']) { $guest = Object_Guest::getById($_POST['data']['guestid'], 1); if ($guest instanceof Object_Guest) { $guest->setLastname($_POST['data']['guestname']); $guest->setTel($_POST['data']['guesttel']); $guest->save(); } } //date update needs to be reworked //$myreservation->setStart($_POST['data']['start']); $myreservation->setPartysize($_POST['data']['partysize']); $myreservation->setBookingref($_POST['data']['bookingref']); $myreservation->setBookingnotes($_POST['data']['bookingnotes']); $myreservation->setStatus($_POST['data']['status']); $myreservation->save(); $data = $_POST['data']; $data['DT_RowId'] = "row_" . $_POST['data']['id']; $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->row = $data; } } else { $reservations = $mylocation->getReservations(); $data = array(); $i = 0; foreach ($reservations as $key => $reservation) { $i++; $resa = $this->formatReservation($reservation); array_push($data, $resa); } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = $data; } } else { $data = array(); $reponse->message = 'TXT_NOT_RESERVATION_LIST'; $reponse->success = false; $reponse->data = $data; } $this->render($reponse); }
public function getListAction() { //get list of reservations $reponse = new Reponse(); $mylocationid = $this->getParam('locationid'); $myservingid = $this->getParam('servingid'); $calendar = $this->getParam('calendar'); $guestid = $this->getParam('guestid'); $cancelled = $this->getParam('cancelled'); $arrived = $this->getParam('arrived'); $mylocation = Object\Location::getById($mylocationid, 1); $myserving = Object\Serving::getById($myservingid, 1); $myguest = Object\Guest::getById($guestid, 1); if ($mylocation instanceof Object\Location || $myserving instanceof Object\Serving || $guest instanceof Object\Guest) { //we check if we are in the Editor if ($_POST['action']) { //if REMOVE if ($_POST['action'] == "remove") { foreach ($_POST['id'] as $id) { $myreservation = Object\Reservation::getById($id, 1); if ($myreservation instanceof Object\Reservation) { $myreservation->SetStatus('Cancelled'); $myreservation->save(); } } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = ''; } //if EDIT if ($_POST['action'] == "edit") { $myreservation = Object_Reservation::getById($_POST['data']['id'], 1); if ($_POST['data']['guestid']) { $guest = Object_Guest::getById($_POST['data']['guestid'], 1); if ($guest instanceof Object_Guest) { $guest->setLastname($_POST['data']['guestname']); $guest->setTel($_POST['data']['guesttel']); $guest->setBookingnotes($_POST['data']['bookingnotes']); $guest->setPreferredlanguage($_POST['data']['preferredlanguage']); $guest->setNewsLetter($_POST['data']['newsLetter']); $guest->save(); } } //date update needs to be reworked $daystart = $myreservation->getStart()->get('dd-MM-YYYY'); $newdatestart = new Zend_Date($daystart . ' ' . $_POST['data']['start'] . ':00', 'dd-MM-YYYY HH:mm:ss'); $myreservation->setBookingref($_POST['data']['bookingref']); $myreservation->setBookingnotes($_POST['data']['bookingnotes']); if ($_POST['data']['status'] == 'Annulé') { $_POST['data']['status'] = "Cancelled"; } $myreservation->setStatus($_POST['data']['status']); if ($_POST['data']['arrived'] == '1') { $arrived = 1; } else { $arrived = 0; } if ($arrived == 1) { $myreservation->setActualpartysize($_POST['data']['partysize']); $myreservation->setPartysize($myreservation->getPartysize()); $myreservation->setActualstart($newdatestart); $myreservation->setStart($myreservation->getStart()); } else { $myreservation->setPartysize($_POST['data']['partysize']); $myreservation->setStart($newdatestart); } //Prework Table input $tableids = explode(',', $_POST['data']['table']); $tablearray = array(); foreach ($tableids as $tableid) { $variable = explode('-', $tableid); $table = $this->selectedLocation->getResource()->getTable($variable[0], $variable[1]); if ($table instanceof Object\Table) { array_push($tablearray, $table); } } $myreservation->setTable($tablearray); $myreservation->setArrived($arrived); $myreservation->save(); $data = $_POST['data']; if ($myreservation->getLocation() instanceof Object_Location) { $data['locationid'] = $myreservation->getLocation()->getId(); $data['locationname'] = $myreservation->getLocation()->getName(); } $data['DT_RowId'] = "row_" . $_POST['data']['id']; $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->row = $data; $reponse->debug = $tablearray; } } else { if (!$calendar) { $date = new Zend_Date(); $calendar = $date->get('dd-MM-YYYY'); } $calendarstart = $calendar . ' ' . '00:00:00'; $calendarend = $calendar . ' ' . '23:59:59'; $calendarstart = new Zend_Date($calendarstart, 'dd-MM-YYYY HH:mm:ss'); $calendarend = new Zend_Date($calendarend, 'dd-MM-YYYY HH:mm:ss'); if ($guestid == '') { if ($myservingid == '') { $reservations = $mylocation->getResource()->getReservationsByDate($calendarstart->getTimestamp(), $calendarend->getTimestamp()); } else { if ($myserving instanceof Object\Serving) { $reservations = $myserving->getReservationsByDate($calendarstart->getTimestamp(), $calendarend->getTimestamp()); } } } else { if ($myguest instanceof Object\Guest) { $reservations = $myguest->getReservationsByGuest($calendarstart->getTimestamp()); } } $data = array(); $i = 0; foreach ($reservations as $key => $reservation) { $i++; $resa = $this->formatReservation($reservation); array_push($data, $resa); } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = $data; } } else { $data = array(); $reponse->message = 'TXT_NOT_RESERVATION_LIST'; $reponse->success = false; $reponse->data = $data; $reponse->debug = 'debug:' . $this->getParam('q'); } $this->render($reponse); }