/
var
/
www
/
html
/
boaz2
/
src
/
Controller
/
Upload File
HOME
<?php namespace App\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use App\Entity\User; use App\Entity\Cargo; use App\Entity\Depot; use App\Entity\Subcargo; use App\Entity\Loading; use App\Entity\ReleaseOrder; use App\Entity\UserDepot; use DateTime; class LoadController extends AbstractController { /** * @Route("/loading/product/{cargo}", name="loading") */ public function loadingByProduct($cargo = 'AGO') { $em = $this->getDoctrine()->getManager(); $release = $em->getRepository(ReleaseOrder::class)->findAuthorizedNotLoaded($cargo); return $this->render('loading/index.html.twig', ['title' => 'Release Orders', 'release' => $release, 'product' => $cargo, 'type' => '']); } /** * @Route("/loading/cargo/{cargo}", name="loadingByCargo") */ public function loadingByCargo($cargo) { $em = $this->getDoctrine()->getManager(); $release = $em->getRepository(ReleaseOrder::class)->findAuthorizedNotLoadedByCargo($cargo); return $this->render('loading/index.html.twig', ['title' => 'Release Orders', 'release' => $release, 'cargo' => $cargo, 'product' => $cargo, 'type' => '']); } /** * @Route("/loading/release/all/{cargo}", name="loading_all") */ public function loadingAll($cargo = 'AGO') { $em = $this->getDoctrine()->getManager(); $release = $em->getRepository(ReleaseOrder::class)->findAllAuthorized($cargo); return $this->render('loading/index.html.twig', ['title' => 'All Release Orders', 'release' => $release, 'product' => $cargo, 'type' => 'All']); } /** * @Route("/loading/released/depots", name="loading_depots") */ public function depots() { $em = $this->getDoctrine()->getManager(); $depots = $em->getRepository(ReleaseOrder::class)->findDepotsAuthorized(); return $this->json(['depots' => $depots]); } /** * @Route("/loading/{id}", name="addLoad", requirements={"id": "\d+"}) */ public function add($id) { $em = $this->getDoctrine()->getManager(); if(isset($_POST['submit'])) { for ($i=0; $i < $_POST['num']; $i++) { $load = new Loading(); $load->setTruck($_POST['truck'][$i]); $load->setQuantity($_POST['quantity'][$i]); $load->setDate($_POST['date'][$i]); $load->setDates(\DateTime::createFromFormat("m/d/Y", $_POST['date'][$i])); $load->setDetails($_POST['details'][$i]); $load->setWaybill($_POST['waybill'][$i]); $load->setUser($this->getUser()); $load->setRelease($em->getRepository(ReleaseOrder::class)->find($_POST['release'])); $em->persist($load); } $em->flush(); $this->setLoaded($id); return $this->redirectToRoute('addLoad', ['id' => $id]); } $release = $em->getRepository(ReleaseOrder::class)->find($id); $cargo = $release->getCargo(); $subcargo = $this->getDoctrine()->getRepository(Subcargo::class)->findByCargoId($cargo->getId()); $releases = $this->getDoctrine()->getRepository(ReleaseOrder::Class)->findByCargo($cargo->getId()); $releasedTotal = array_reduce($releases, function($accum, $cur){ return $accum + $cur->getQuantity(); }); // calculate the total of all loadings from releases orders attached to current cargo // in order to find the unloaded balance $loadedTotal = array_reduce($releases, function($accum, $cur){ return $accum + array_reduce($cur->getLoading()->toArray(), function($accums, $curs){ return $accums + $curs->getQuantity(); }); }); $unreleased = $cargo->getQuantity() - $releasedTotal; $unloaded = $cargo->getQuantity() - $loadedTotal; $loads = $em->getRepository(Loading::class)->findByRelease($id); // total loaded $total = $em->getRepository(ReleaseOrder::class)->findTotalLoaded($id); return $this->render('loading/load.html.twig', ['title' => 'Loading Information', 'release' => $id, 'releases' => $release, 'load' => $loads, 'total' => $total, 'unreleased' => $unreleased, 'cargo' => $cargo, 'subcargo' => $subcargo, 'unloaded' => $unloaded]); } /** * * Mark release order as loaded */ public function setLoaded($id) { $em = $this->getDoctrine()->getManager(); $release = $em->getRepository(ReleaseOrder::class)->find($id); if (!$release) { return; } $releaseTotal = $em->getRepository(ReleaseOrder::class)->findTotalLoaded($id); if ($release->getQuantity() <= $releaseTotal) { $release->setIsLoaded(true); }else{ $release->setIsLoaded(false); } $em->persist($release); $em->flush(); return true; } /** * @Route("/loading/edit/{id}", name="editLoad") */ public function edit($id = null) { $load = $this->getDoctrine()->getRepository(Loading::class)->find($id); if(isset($_POST['submit'])) { $load->setTruck($_POST['truck']); $load->setQuantity($_POST['quantity']); $load->setDate($_POST['date']); $load->setDates(\DateTime::createFromFormat("m/d/Y", $_POST['date'])); $load->setDetails($_POST['details']); $load->setWaybill($_POST['waybill']); $em = $this->getDoctrine()->getManager(); $em->persist($load); $em->flush(); $this->setLoaded($load->getRelease()->getId()); return $this->redirectToRoute('addLoad', ['id' => $load->getRelease()->getId()]); } return $this->render('loading/edit.html.twig', ['title' => 'Loading Information', 'load' => $load]); } /** * @Route("/loading/list", name="loadList") */ public function list() { $load = $this->getDoctrine()->getRepository(Loading::class)->findAll(); return $this->render('loading/list.html.twig', ['title' => 'Loading Information', 'load' => $load]); } /** * @Route("/loading/delete/{id}", name="deleteload") * **/ public function delete($id) { $this->denyAccessUnlessGranted('ROLE_MANAGEMENT', null, 'Unable to access this page!'); $em = $this->getDoctrine()->getManager(); $load = $em->getRepository(Loading::class)->find($id); $release = $load->getRelease()->getId(); $em->remove($load); $this->setLoaded($release); return $this->redirectToRoute('viewRelease', array('id' => $release)); } /** * @Route("/loading/cargos/{id}", name="viewCargoLoading", requirements={"id": "\d+"}) */ public function cargos($id = null) { $em = $this->getDoctrine()->getManager(); if($id) { $cargo = $em->getRepository(Cargo::class)->find($id); $releases = $em->getRepository(ReleaseOrder::Class)->findByCargo($id); return $this->render('loading/index.html.twig', ['title' => 'All Release Orders', 'release' => $releases, 'cargo' => $cargo, 'type' => 'All']); } $cargo = $em->getRepository(ReleaseOrder::class)->findCargoAuthorizedNotLoaded(); return $this->render('loading/cargos.html.twig', ['title' => 'Cargo List', 'cargo' => $cargo]); } public function checkoutAll() { $em = $this->getDoctrine()->getManager(); $userDepotRepo = $em->getRepository(UserDepot::class); $checks = $userDepotRepo->findNonCheckedOutAll(); if($checks && count($checks)){ foreach ($checks as $check) { $ud = $userDepotRepo->find($check['id']); $ud->setCheckout(new \DateTime('last weekday 17:30')); $em->persist($ud); } $em->flush(); } } /** * @Route("/loading/depots", name="checkin") */ public function checkIn(Request $request) { $this->checkoutAll(); $em = $this->getDoctrine()->getManager(); $depotRepo = $em->getRepository(Depot::class); $userDepotRepo = $em->getRepository(UserDepot::class); $user = $this->getUser(); if($request->getMethod() === 'POST'){ $depot = $depotRepo->find($_POST['depot']); if($depot){ $userDepot = new UserDepot(); $userDepot->setUser($user); $userDepot->setDepot($depot); $userDepot->setCheckin(new DateTime()); $em->persist($userDepot); $em->flush(); return $this->redirectToRoute('checkin'); } } $depots = $depotRepo->findNotCheckedIn(); $checkedIn = $userDepotRepo->findNonCheckedOut($user); // $depot = $em->getRepository(Depot::class)->findNotCheckedIn(); // var_dump($checkedIn);die; return $this->render('loading/depot.html.twig', ['title' => 'Depot Check In', 'depots' => $depots, 'checkin' => $checkedIn]); } /** * @Route("/loading/depots/checkout/{id}", name="checkout") */ public function checkOut(Request $request, Depot $depot) { $em = $this->getDoctrine()->getManager(); $user = $this->getUser(); $userDepot = $em->getRepository(UserDepot::class)->findOneBy(['depot' => $depot, 'checkout' => NULL]); if($userDepot){ $userDepot->setCheckout(new DateTime()); $em->persist($userDepot); $em->flush(); } return $this->redirectToRoute('checkin'); } }