/
home
/
ubuntu
/
html
/
amply
/
src
/
Controller
/
Upload File
HOME
<?php namespace App\Controller; use App\Controller\Controller; // use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; use App\Entity\Item; use App\Entity\Groups; use App\Entity\Category; use App\Entity\Orders; use App\Entity\Activity; use App\Entity\Subscription; class DefaultController extends Controller { /** * @Route("/", name="homepage") **/ public function indexAction(Request $request) { // return $this->redirectToRoute('app_login'); return $this->render('Default/index.html.twig'); } /** * @Route("/howto", name="howto") **/ public function howTo() { return $this->render('Default/howto.html.twig'); } /** * @Route("/positems", name="positems") */ public function posItemsAction(Request $request) { $user = $this->getUser()->getId(); $products = $this->getDoctrine() ->getRepository(Item::class)->findPointOfSale($user); $response = new JsonResponse(); $response->setData($products); return $response; } /** * @Route("/admin", name="admin") */ public function adminAction(Request $request) { // return new Response('Hello there'); // $products = "Mike"; $user = $this->getUser(); $date = date('d-m-Y'); $tod = new \DateTime($date); $yes = new \DateTime($date); $yes->modify("-1 day"); $now = new \DateTime('now'); $prev = new \DateTime('now'); $em = $this->getDoctrine()->getManager(); $subscription = $em->getRepository(Subscription::class)->findOneBy(['user' => $user]); // Get today's and yesterday's total $today = $em->getRepository(Orders::class)->salesTotal($user->getId(), $tod, $now); $yesterday = $em->getRepository(Orders::class)->salesTotal($user->getId(), $yes, $tod); $dow = date('w'); $tweek = date('d-m-Y', strtotime('-'.$dow.' days')); $lweek = date('d-m-Y', strtotime('-'.$dow.' days')); $bow = new \DateTime($tweek); $bolw = new \DateTime($lweek); $bolw->modify('-7 days'); $m = date('01-m-Y'); $lm = date('01-m-Y'); $bom = new \DateTime($m); $bolm = new \DateTime($m); $bolm->modify('-1 month'); $thisWeekTotal = $em->getRepository(Orders::class)->salesTotal($user->getId(), $bow, $now); $lastWeekTotal = $em->getRepository(Orders::class)->salesTotal($user->getId(), $bolw, $bow); $thisMonthTotal = $em->getRepository(Orders::class)->salesTotal($user->getId(), $bom, $now); $lastMonthTotal = $em->getRepository(Orders::class)->salesTotal($user->getId(), $bolm, $bom); $salesmonth = $em->getRepository(Orders::class)->salesPeriod($user->getId(), date('Y-m-01 H:i:s'), $now->format('Y-m-d H:i:s')); $denominator = $yesterday ?: 1; $increase = $today ? (($today - $yesterday)/$denominator)*100 : 0; $activities = $this->getDoctrine()->getRepository(Activity::class)->findBy(['userId' => $user->getId()], ['date' => 'DESC'], 15); $diff = ''; $stat = ''; // $diff = $prev >= $user->getCreated(); // if user doesn't have a running subscription (cancelled or never subscribed) if (!$subscription || !$subscription->getStatus()) { $prev->modify('-14 days'); $diff = $prev >= $user->getCreated(); $stat = $diff ? 'Expired' : $prev->diff($user->getCreated())->format('%a days left'); } return $this->render('Default/admin.html.twig', ['title' => 'Dashboard', 'activities' => $activities, 'diff' => $diff, 'stat' => $stat, 'subscription' => $subscription, 'today' => $today, 'yesterday' => $yesterday, 'increase' => floor($increase), 'thisweek' => $thisWeekTotal, 'lastweek' => $lastWeekTotal, 'thismonth' => $thisMonthTotal, 'lastmonth' => $lastMonthTotal, 'salesmonth' => json_encode($salesmonth)]); // return $this->render('Default/index.html.twig', array('title' => 'EPOS', 'product' => $products)); } /** * Get all items from database and push to template * @Route("/all", name="get_all") * @return Response */ public function allAction() { $user = $this->getUser(); $cats = $this->getDoctrine()->getRepository(Groups::class)->findAll(); $items = $this->getDoctrine()->getRepository(Item::class)->findAll(); $response = new JsonResponse(); $response->setData($cats); return $response; } /** * @Route("/drinks", name="drinks") */ public function drinksAction(Request $request) { $user = $this->getUser(); // $products = "Mike"; $products = $this->getDoctrine() ->getRepository(Item::class)->findPointOfSaleDrinks(); $response = new JsonResponse(); $response->setData(json_encode($products)); // // set a HTTP response header $response->headers->set('Content-Type', 'application/json'); return $response; // return $this->render('Default/index.html.twig', array('title' => 'EPOS', 'product' => $products)); } /** * @Route("/pos", name="pos") */ public function posAction(Request $request) { $user = $this->getUser()->getId(); $lastOrder = $this->getDoctrine() ->getRepository(Orders::class)->findLastOrder($user); return $this->render('POS/index.html.twig', array('title' => 'EPOS')); } /** * @Route("/pos/drinks", name="posDrinks") */ public function posDrinksAction() { $waiter = $this->getDoctrine() ->getRepository(Staff::class)->findBy(array('role' => 'Waiter')); $table = $this->getDoctrine() ->getRepository(Tables::class)->findAll(); $lastOrder = $this->getDoctrine() ->getRepository(Orders::class)->findLastOrder(); return $this->render('POS/index.html.twig', array('title' => 'EPOS', 'waiter' => $waiter, 'table' => $table)); } }