/** * @Route("/rooms/{id}", name="showRoom") * @param string $id * @param Request $request * @throws \Exception * @return \Symfony\Component\HttpFoundation\Response */ public function roomsAction($id, Request $request) { if ($id == 'random') { $page = $this->getDoctrine()->getRepository('AppBundle:Pages')->getRandomPage(); if (!$page) { return $this->render('default/empty.html.twig'); } } else { $page = $this->getDoctrine()->getRepository('AppBundle:Pages')->find($id); if (!$page) { throw $this->createNotFoundException('No page found for request param ' . $id); } } $imagesCollector = new ImagesViewCollector(); $bookingEntity = new Booking(); $calculator = new Calculator(); $context = new CalculationContext(); $context->setPricePerNight($page->getRawValue('priceNight')); $now = new \DateTime(); $context->setCheckInDate($now->format('Y-m-d')); $context->setCheckOutDate($now->modify('+1 day')->format('Y-m-d')); $calcResult = $calculator->calculate($context); $bookingEntity->setGuestsCount($calcResult['guestsCount']); $bookingEntity->setPriceString($calcResult['pricePerNight']); $bookingEntity->setCheckinDate($calcResult['checkinDate']); $bookingEntity->setCheckoutDate($calcResult['checkoutDate']); $bookingEntity->setPage($page); $bookingEntity->setPageId($page->getId()); $form = $this->createForm(new BookingForm('/add-booking/' . $page->getId()), $bookingEntity); $form->handleRequest($request); return $this->render('default/index.html.twig', array('page' => $page, 'images' => $imagesCollector->collect($page), 'bookingCalc' => $calcResult, 'form' => $form->createView())); }
/** * @return WorkingMonth[] */ public function findProspectiveWorkingMonths() { $startMonth = new \DateTime(); $startMonth->modify('first day of this month'); $qb = parent::createQueryBuilder('e'); $qb->where('e.date >= :startMonth')->andWhere('e.isDeleted = 0')->setParameter('startMonth', $startMonth->format('Y-m-d')); return $qb->getQuery()->getResult(); }
/** * Printa un calendario según el año y mes que se le pasan del qual se puede realizar una reserva. * @Route("/show/{year}/{mes}", name="calendario_mes") */ public function mesAction($year, $mes) { //Objeto DateTime para ponerlo al primer dia del año y mes determinados $data = new \DateTime(); $data->setDate($year, $mes, 1); $cantidad_dias = $data->format('t'); // //array con los dias del mes en formato [1]Miércoles, [2]Jueves según mes y año $diasMes = []; for ($i = 1; $i <= $cantidad_dias; $i++) { $dia = $this->traduccionDia($data->format('l')); $diasMes[$i] = $dia; //añade el primer dia del mes según Martes, Lunes... $data->modify('tomorrow'); } // $em = $this->getDoctrine()->getManager(); //array de las fiestas de un año y mes determinados $fiestas = $em->getRepository('CineticExcepcionBundle:Fiesta')->findAllFromYearAndMonth($year, $mes); // //array de las excepciones en un año y mes determinados $excepciones = $em->getRepository('CineticExcepcionBundle:Excepcion')->findAllFromYearAndMonth($year, $mes); // //array de las reservas en un año y mes determinados $reservas = $em->getRepository('CineticReservaBundle:Reserva')->findAllFromYearAndMonth($year, $mes); // //array que relaciona numero del dia con las franjas o no del objeto $diasObjeto = []; for ($i = 1; $i <= $cantidad_dias; $i++) { //en primer lugar miro si existe una fiestaObjeto en este dia numero $i $fiestaObjeto = $this->buscarDia($fiestas, $i); if ($fiestaObjeto) { $diasObjeto[$i] = $fiestaObjeto; } else { //en segundo lugar miro si existe una ExcepcionObjeto en esta dia numero $i $excepcionObjeto = $this->buscarDia($excepciones, $i); if ($excepcionObjeto) { $diasObjeto[$i] = $excepcionObjeto; } else { $diasObjeto[$i] = $em->getRepository('CineticDiaBundle:Dia')->findOneByNombre($diasMes[$i]); } } } //array que mira si hay dias reservados en este mes $diasReservados = []; for ($i = 1; $i <= $cantidad_dias; $i++) { $reservaObjeto = $this->buscarDia($reservas, $i); if ($reservaObjeto) { $diasReservados[$i] = $reservaObjeto; } } // return $this->render('calendario/mes.html.twig', array('year' => $year, 'mes' => $mes, 'diasMes' => $diasMes, 'diasObjeto' => $diasObjeto, 'diasReservados' => $diasReservados)); }
/** * Exibe os detalhes do produto e seuas estatisticas * * @Route("/{id}", name="produto_show") * @Method("GET") * @Template() */ public function showAction($id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('ProdutoBundle:Produto')->find($id); $data = new \DateTime(); $data->modify('+1 month'); //starta o indicador como 0 $indicador = 0; //retorna o indicador baseado no mes seguinte $indicadorProxMes = $em->getRepository('ProdutoBundle:EstatisticaMes')->findOneBy(array('mes' => $data->format('m'))); if (is_object($indicadorProxMes)) { $indicador = $indicadorProxMes->getIndicador(); } //Busca o total de vendas dando um SUM pela qtdVenda dos produtos $totVendas = $em->getRepository('ProdutoBundle:Produto')->getTotVendas(); //calculo do mix (tot_venda_produto/tot_venda) $mix = $entity->getQtdVenda() / $totVendas * 100; //multiplica o mix pelo indicador $estatistica = $mix * $indicadorProxMes->getIndicador(); if (!$entity) { throw $this->createNotFoundException('Unable to find Produto entity.'); } $deleteForm = $this->createDeleteForm($id); return array('entity' => $entity, 'delete_form' => $deleteForm->createView(), 'indicador' => $indicador, 'tot_vendas' => $totVendas, 'part_produto' => $mix, 'estatistica' => $estatistica); }
/** * @Route("/addincome",name= "addincome") * @Method("POST") * @Template() * */ public function addincomeAction(Request $request) { $billpg = $this->container->getParameter('cod.billpg'); //4 $em = $this->getDoctrine()->getManager(); $saleid = $this->get('request')->request->get('saleid'); $value = $this->get('request')->request->get('value'); $parc = $this->get('request')->request->get('parc'); $tpay = $this->get('request')->request->get('tpay'); $date = $this->get('request')->request->get('date'); $dat = new \DateTime($date); $dat->setTime(date("H"), date("i")); $tpayment = $em->getRepository('UerptpaymentBundle:tpayment')->find($tpay); $valueb = $value / $parc; $tax = $tpayment->getTax() * $valueb / 100; $valuel = $valueb - $tax; $status = $tpayment->getDefaultstatus(); $idays = $tpayment->getDays(); // $dat->modify("+".$idays." days"); $entitya = $em->getRepository('UerpBankBundle:BankAccount')->find($tpayment->getBank()); if (!$entitya) { throw $this->createNotFoundException('Unable to find account entity.'); } $bal = 0.0; for ($i = 0; $i < $parc; $i++) { $datd = new \DateTime($date); $datd->setTime(date("H"), date("i")); $p = $i + 1; $addday = $idays * $p; $datd->modify("+" . $addday . " days"); // dump($da); die; $incomes = new incomes(); $incomes->setSaleId($saleid); $incomes->setValueb($valueb); $incomes->setValuel($valuel); $bal = $bal + $valuel; $incomes->setTax($tax); $incomes->setBank($entitya); $incomes->setDate($datd); $incomes->setParc($p . "/" . $parc); $incomes->setStatus($status); $incomes->setTpayment($tpayment); $em->persist($incomes); } if ($status->getId() == $billpg) { $balance = $entitya->getBalance() + $bal; $entitya->setBalance($balance); } $em->flush(); $response = new Response(); $response->setContent(json_encode(array('id' => $incomes->getId()))); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * @Route("/create", name="admin.frontend.attendance.create") * @Template() */ public function createAction(Request $request) { $breadcrumbs = $this->get("white_october_breadcrumbs"); $breadcrumbs->addItem('Dashboard', $this->get("router")->generate("admin.frontend.dashboard")); $breadcrumbs->addItem('Attendance', $this->get("router")->generate("admin.frontend.attendance.index")); $breadcrumbs->addItem('Week of attendance'); $session = $this->get('session'); $staffId = $session->get('staffId'); $week = $session->get('week'); /** @var $em EntityManager */ $em = $this->getDoctrine()->getManager(); /** @var $staff Staff */ $staff = null; if ($staffId) { $staff = $em->getRepository('AdminFrontendBundle:Staff')->find($staffId); } $selectDate = new \DateTime($week); $filterForm = $this->createForm(AttendanceCreateFilterType::class, ['staff' => $staff, 'week' => $week]); $filterForm->handleRequest($request); if ($filterForm->isSubmitted() && $filterForm->isValid()) { $staff = $filterForm->get('staff')->getData(); $week = $filterForm->get('week')->getData(); $session->set('staffId', $staff->getId()); $session->set('week', $week); return $this->redirect($this->generateUrl('admin.frontend.attendance.create')); } $form = null; $weekDates = []; if ($staff && $week) { $data = []; $week = $selectDate->format("W"); $week_number = $week; $year = $selectDate->format('Y'); for ($day = 0; $day < 7; $day++) { $date = date('Y-m-d', strtotime($year . "W" . $week_number . ($day + 1))); $dateFormat = date('d.m.Y', strtotime($year . "W" . $week_number . ($day + 1))); $weekDates[] = $dateFormat; $qb = $em->createQueryBuilder(); $query = $qb->select('a')->from('AdminFrontendBundle:Attendance', 'a')->where('a.staff = :staff')->andWhere('DATE(a.startTime) = :startTime')->setParameter('startTime', $date)->setParameter('staff', $staff); $results = $query->getQuery()->getResult(); for ($i = 0; $i < 5; $i++) { /** @var $attendance Attendance */ $attendance = isset($results[$i]) ? $results[$i] : null; $project = $attendance ? $attendance->getProject() : null; $timeFrom = $attendance ? $attendance->getStartTime()->format('H:i') : null; $timeTo = $attendance ? $attendance->getEndTime()->format('H:i') : null; $km = $attendance ? $attendance->getAmountOfKm() : null; $payType = $attendance ? $attendance->getPayType() : null; $data['project_' . $i . '_' . $day] = $project; $data['time_from_' . $i . '_' . $day] = $timeFrom; $data['time_to_' . $i . '_' . $day] = $timeTo; $data['km_' . $i . '_' . $day] = $km; $data['pay_type_' . $i . '_' . $day] = $payType; } } $form = $this->createForm(AttendaceType::class, $data, ['weekDates' => $weekDates]); $form->handleRequest($request); if ($form->isSubmitted()) { if ($form->isValid()) { for ($day = 0; $day < 7; $day++) { $date = date('Y-m-d', strtotime($year . "W" . $week_number . ($day + 1))); $qb = $em->createQueryBuilder(); $query = $qb->select('a')->from('AdminFrontendBundle:Attendance', 'a')->where('a.staff = :staff')->andWhere('DATE(a.startTime) = :startTime')->setParameter('startTime', $date)->setParameter('staff', $staff); $results = $query->getQuery()->getResult(); /** @var $attendance Attendance */ foreach ($results as $attendance) { $attendanceLog = new AttendanceLog(); if ($attendance->getAmountOfKm()) { $attendanceLog->setAmountOfKm($attendance->getAmountOfKm()); } $attendanceLog->setCreatedAt(new \DateTime()); $attendanceLog->setEndTime($attendance->getEndTime()); $attendanceLog->setStartTime($attendance->getStartTime()); $attendanceLog->setnoInvoiced($attendance->getnoInvoiced()); $attendanceLog->setProject($attendance->getProject()); $attendanceLog->setStaff($attendance->getStaff()); $attendanceLog->setUser($this->getUser()); $attendanceLog->setDeleted(true); $em->persist($attendanceLog); $em->remove($attendance); $em->flush(); } for ($index = 0; $index < 5; $index++) { $projecField = 'project_' . $index . '_' . $day; $timeFromField = 'time_from_' . $index . '_' . $day; $timeToField = 'time_to_' . $index . '_' . $day; $kmField = 'km_' . $index . '_' . $day; $payTypeField = 'pay_type_' . $index . '_' . $day; /** @var $project Project */ $project = $form->has($projecField) ? $form->get($projecField)->getData() : null; $timeFrom = $form->has($timeFromField) ? $form->get($timeFromField)->getData() : null; $timeTo = $form->has($timeToField) ? $form->get($timeToField)->getData() : null; $km = $form->has($kmField) ? $form->get($kmField)->getData() : null; $payType = $form->has($payTypeField) ? $form->get($payTypeField)->getData() : null; if ($project && $timeFrom && $timeTo) { $timeFromDate = new \DateTime($date . ' ' . $timeFrom . ':00'); $timeToDate = new \DateTime($date . ' ' . $timeTo . ':00'); if ($timeToDate < $timeFromDate) { $timeToDate->modify('+1 day'); } $attendance = new Attendance(); $attendance->setProject($project); $attendance->setStaff($staff); $attendance->setStartTime($timeFromDate); $attendance->setEndTime($timeToDate); $attendance->setUser($this->getUser()); $attendance->setCreatedAt(new \DateTime()); $attendance->setPayType($payType); if ($km) { $attendance->setAmountOfKm($km); } $em->persist($attendance); $attendanceLog = new AttendanceLog(); if ($km) { $attendanceLog->setAmountOfKm($km); } $attendanceLog->setCreatedAt(new \DateTime()); $attendanceLog->setEndTime($attendance->getEndTime()); $attendanceLog->setStartTime($attendance->getStartTime()); $attendanceLog->setnoInvoiced($attendance->getnoInvoiced()); $attendanceLog->setProject($attendance->getProject()); $attendanceLog->setStaff($attendance->getStaff()); $attendanceLog->setUser($this->getUser()); $attendanceLog->setDeleted(false); $em->persist($attendanceLog); $em->flush(); } } } $this->addFlash('success', $this->get('translator')->trans('Attendance was save')); return $this->redirect($this->generateUrl('admin.frontend.attendance.create')); } } } return ['form' => $form ? $form->createView() : $form, 'filterForm' => $filterForm->createView(), 'selectedDate' => $selectDate->format('Y-m-d'), 'weekDates' => $weekDates, 'staff' => $staff]; }
/** * @Template() * Note la meteo: pluie + soleil * http://localhost/Wind/web/app_dev.php/admin/BO/ajax/spot/meteo/note/save/1 */ public function spotSaveMeteoNoteAction($id) { $em = $this->container->get('doctrine.orm.entity_manager'); $spot = $em->find('LaPoizWindBundle:Spot', $id); if (!$spot) { return $this->container->get('templating')->renderResponse('LaPoizWindBundle:Default:errorBlock.html.twig', array('errMessage' => "Spot not find !")); } $tabNotes = array(); $tabListePrevisionDate = array(); // tableau des liste des PrevisionDate, cahque cellule correspondant à une dateprev // Pour les 7 prochains jours $day = new \DateTime("now"); for ($nbPrevision = 0; $nbPrevision < 7; $nbPrevision++) { $tabNotes[$day->format('Y-m-d')] = -1; $tabListePrevisionDate[$day->format('Y-m-d')] = array(); $day->modify('+1 day'); } //********** Meteo ********** // On efface les vielle données ManageNote::deleteOldData($spot, $em); //list des PrevisionDate pour les prochain jour, pour le spot pour tous les websites $listALlPrevisionDate = $this->getDoctrine()->getRepository('LaPoizWindBundle:PrevisionDate')->getPrevDateAllWebSiteNextDays($spot); foreach ($listALlPrevisionDate as $previsionDate) { // ajouter au tableau de la cellule du jour de $tabListePrevisionDate $tabListePrevisionDate[$previsionDate->getDatePrev()->format('Y-m-d')][] = $previsionDate; } foreach ($tabNotes as $keyDate => $note) { if ($tabListePrevisionDate[$keyDate] != null && count($tabListePrevisionDate[$keyDate]) > 0) { $noteDate = ManageNote::getNotesDate($spot, \DateTime::createFromFormat('Y-m-d', $keyDate), $em); $noteDate->setNoteMeteo(NoteMeteo::calculNoteMeteo($tabListePrevisionDate[$keyDate])); $noteDate->setNoteWind(NoteWind::calculNoteWind($tabListePrevisionDate[$keyDate])); $noteDate->setNoteTemp(NoteTemp::calculNoteTemp($tabListePrevisionDate[$keyDate])); $em->persist($noteDate); } } $em->flush(); return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice/Spot/Ajax:displayNote.html.twig', array('spot' => $spot, 'message' => "", 'saveSuccess' => true)); }
private function watchWaiting(InputInterface $input, OutputInterface $output) { $now = new \DateTime(); $output->writeln(sprintf('<info>%s</info>', 'Check waiting jobs')); $i = 0; while ($jobs = $this->loadWaitingJobs($i)) { foreach ($jobs as $job) { $i++; // check sapi connection if (!$this->sapiPing($job, $this->encryptor)) { $message = 'SAPI connect failed'; $this->logger->info($message, array('job' => $job->getId(), 'project' => $job->getProject(), 'params' => $job->getRawParams())); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=red>[ERROR] %s</fg=red>', $job->getId(), $message)); continue; } $sapiClient = $this->createJobSapiClient($job); $jobManager = $this->jobManagerFactory->createJobManager(new StorageApi\Token($sapiClient)); try { $esJob = $jobManager->findJobByIdForWatchdog($job->getId()); if (!$esJob) { $message = 'Job load from ES failed'; $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=red>[ERROR] %s</fg=red>', $job->getId(), $message)); continue; } } catch (\InvalidArgumentException $e) { $message = 'Job load from ES failed'; $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=red>[ERROR] %s</fg=red>', $job->getId(), $message)); continue; } // clean jobs of deleted orchestrations $orchestration = $this->orchestrationManager->findDeletedOrchestrations(array('id' => $esJob->getOrchestrationId()), false); $orchestration = reset($orchestration); if ($orchestration) { $updateJob = $this->syrupJobMapper->get($esJob->getId()); if ($updateJob->getComponent() !== KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME) { continue; } $updateJob->setStatus(Metadata\Job::STATUS_CANCELLED); $this->syrupJobMapper->update($updateJob); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=yellow>[deleted orchestration]</fg=yellow> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); continue; } $orchestrations = $this->orchestrationManager->findOrchestrations(array('id' => $esJob->getOrchestrationId()), false); /** * @var Orchestration $orchestration */ $orchestration = reset($orchestrations); if (!$orchestration) { $message = 'Orchestration load failed'; $this->logger->critical($message, array('job' => $job->getId(), 'orchestrationId' => $esJob->getOrchestrationId(), 'projectId' => $esJob->getProjectId(), 'project' => $esJob->getTokenOwnerName())); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=red>[ERROR] %s</fg=red>', $job->getId(), $message)); continue; } $componentsList = new KbcComponentsList($sapiClient); // waiting duration check if ($esJob->getInitializedBy() === 'manually') { /** * @var StorageApi\Notification[] $notifications */ $notifications = array_filter($orchestration->getNotifications(), function (StorageApi\Notification $row) { return $row->getChannel() === Metadata\Job::STATUS_WAITING; }); if ($notifications) { foreach ($notifications as $notification) { if ($notification->getEmail() !== $esJob->getInitiatorTokenDesc()) { continue; } $date = new \DateTime($job->getCreatedTime()); $date->modify(sprintf('+%d minutes', $notification->getParameter('timeout', 0))); if ($date > $now) { continue; } $events = StorageApi\EventLoader::longWaitingEvents($esJob, $notification, $sapiClient); if ($events) { $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=yellow>[already notified]</fg=yellow> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } else { $this->mailer->sendLongWaitingMessage($esJob, $orchestration, $notification, $componentsList); $this->logLongWaiting($esJob, $sapiClient, $notification); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=green>[notified]</fg=green> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } } } else { // log waiting for default timeout $date = new \DateTime($job->getCreatedTime()); $date->modify(sprintf('+%d minutes', self::WAIT_LIMIT_MINUTES)); if ($date <= $now) { $events = StorageApi\EventLoader::longWaitingEventsAll($esJob, $sapiClient); if ($events) { $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=yellow>[system already notified]</fg=yellow> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } else { $this->logLongWaiting($esJob, $sapiClient, null); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=green>[system notified]</fg=green> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } } } } else { /** * @var StorageApi\Notification[] $notifications */ $notifications = array_filter($orchestration->getNotifications(), function (StorageApi\Notification $row) { return $row->getChannel() === Metadata\Job::STATUS_WAITING; }); if ($notifications) { foreach ($notifications as $notification) { $date = new \DateTime($job->getCreatedTime()); $date->modify(sprintf('+%d minutes', $notification->getParameter('timeout', 0))); if ($date > $now) { continue; } $events = StorageApi\EventLoader::longWaitingEvents($esJob, $notification, $sapiClient); if ($events) { $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=yellow>[already notified]</fg=yellow> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } else { $this->mailer->sendLongWaitingMessage($esJob, $orchestration, $notification, $componentsList); $this->logLongWaiting($esJob, $sapiClient, $notification); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=green>[notified]</fg=green> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } } } else { // log waiting for default timeout $date = new \DateTime($job->getCreatedTime()); $date->modify(sprintf('+%d minutes', self::WAIT_LIMIT_MINUTES)); if ($date <= $now) { $events = StorageApi\EventLoader::longWaitingEventsAll($esJob, $sapiClient); if ($events) { $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=yellow>[system already notified]</fg=yellow> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } else { $this->logLongWaiting($esJob, $sapiClient, null); $output->writeln(sprintf('<fg=white>%s</fg=white> <fg=green>[system notified]</fg=green> <fg=white>%s %s</fg=white>', $esJob->getId(), $esJob->getOrchestrationId(), $esJob->getOrchestrationName())); } } } } } } }
public function findCurrentEditionBySchool($schoolId) { $now = new \DateTime(); $qb = $this->createQueryBuilder('e')->where('e.dateOfEvent <= :today')->setParameter('today', $now->format("Y-m-d"))->andWhere('e.dateOfEvent >= :fourDaysAgo')->setParameter('fourDaysAgo', $now->modify('-4 day')->format("Y-m-d"))->join('e.schools', 's')->andWhere('s.id = :schoolId')->setParameter('schoolId', $schoolId)->orderBy('e.dateOfEvent', 'DESC'); return $qb->getQuery()->getSingleResult(); }