src/Scabal/FrontBundle/Controller/FrontController.php line 66

Open in your IDE?
  1. <?php
  2. namespace Scabal\FrontBundle\Controller;
  3. use Scabal\BackBundle\Transformer\Dashboard\TransformDbObjectToJsonSapFormat;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\HttpFoundation\Cookie;
  7. use Symfony\Component\Serializer\Serializer;
  8. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  9. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  10. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. class FrontController extends Controller {
  14.     private $ifArrayIndexExist null;
  15.     private $index 0;
  16.     //var jacketInArray = ['01','02','03','04','05','16'];
  17.     private $jacketInArray = array('01','02','03','04','05','1','2','3','4','5','16');
  18.     private $trouserInArray = array('02','03','04','05','20','2','3','4','5');
  19.     //private $coatInArray = ['16','54'];
  20.     private $coatInArray = array('54');
  21.     private $shirtInArray = array('91');
  22.     private $waistCoatInArray = array('03','04','09','3','4','9','16');
  23.     public function getJacketInArray($garment_set){
  24.         if(in_array($garment_set$this->jacketInArray)){
  25.             return true;
  26.         }else{
  27.             return false;
  28.         }
  29.     }
  30.     public function getTrouserInArray($garment_set){
  31.         if(in_array($garment_set$this->trouserInArray)){
  32.             return true;
  33.         }else{
  34.             return false;
  35.         }
  36.     }
  37.     public function getCoatInArray($garment_set){
  38.         if(in_array($garment_set$this->coatInArray)){
  39.             return true;
  40.         }else{
  41.             return false;
  42.         }
  43.     }
  44.     public function getWaistCoatInArray($garment_set){
  45.         if(in_array($garment_set$this->waistCoatInArray)){
  46.             return true;
  47.         }else{
  48.             return false;
  49.         }
  50.     }
  51.     public function getShirtInArray($garment_set){
  52.         if(in_array($garment_set$this->shirtInArray)){
  53.             return true;
  54.         }else{
  55.             return false;
  56.         }
  57.     }
  58.     public function loginAction(Request $request) {
  59.         $results = array();
  60.         $encoders = array(new XmlEncoder(), new JsonEncoder());
  61.         $normalizers = array(new ObjectNormalizer());
  62.         $serializer = new Serializer($normalizers$encoders);
  63.         $cookies $request->cookies;
  64.         if($request->getSession()->isStarted() && $cookies->get('myFavorite') != null){
  65.             $jsonContent $serializer->serialize('active''json');
  66.             $cookieAlreadyLogged = new Cookie('alreadyconnected'$jsonContent,0,'/',nullfalsefalse);
  67.             $language $request->getLocale();
  68.             switch ($language) {
  69.                 case 'fr':
  70.                     $message = array('message' => ' VOUS ETES DEJA CONNECTE''class' => 'notif-erreur''title' => 'ATTENTION !');
  71.                     break;
  72.                 case 'en':
  73.                     $message = array('message' => ' YOU ARE ALREADY LOGGED''class' => 'notif-erreur''title' => 'WARNING !');
  74.                     break;
  75.                 case 'de':
  76.                     $message = array('message' => ' SIE SIND BEREITS ANGESCHLOSSEN''class' => 'notif-erreur''title' => 'AUFMERKSAMKEIT !');
  77.                     break;
  78.                 case 'nl':
  79.                     $message = array('message' => ' U BENT AL VERBONDEN''class' => 'notif-erreur''title' => 'AANDACHT !');
  80.                     break;
  81.                 default:
  82.                     $message = array('message' => ' YOU ARE ALREADY LOGGED''class' => 'notif-erreur''title' => 'WARNING !');
  83.                     break;
  84.             }
  85.             $request->getSession()->getFlashBag()->set('notice', array (
  86.                 'class' => $message['class'],
  87.                 'title' => $message['title'],
  88.                 'message' => $message['message']
  89.             ));
  90.         }else{
  91.             $jsonContent $serializer->serialize('notactive''json');
  92.             $cookieAlreadyLogged = new Cookie('alreadyconnected'$jsonContent,0,'/',nullfalsefalse);
  93.         }
  94.         try {
  95.             $repository $this->getDoctrine()->getManager()->getRepository('Scabal\BackBundle\Entity\Maintenance');
  96.             $lightbox $repository->findByIsActive('1');
  97.             if(isset($lightbox) & empty($lightbox)){
  98.                 $jsonContent $serializer->serialize('notactive''json');
  99.                 $cookieMaintenance = new Cookie('maintenancewebsite'$jsonContent,0,'/',nullfalsefalse);
  100.             }else{
  101.                 if(isset($lightbox)){
  102.                     $jsonEncode $serializer->serialize($lightbox'json');
  103.                     $this->ifArrayIndexExist json_decode($jsonEncode);
  104.                     if(array_key_exists($this->index, (array)$this->ifArrayIndexExist)){
  105.                         $results = (array)$this->ifArrayIndexExist[0];
  106.                         $timeStampStartDate =  isset($results['startAt']->timestamp) ? $results['startAt']->timestamp null;
  107.                         $timeStampEndDate = isset($results['finishAt']->timestamp) ? $results['finishAt']->timestamp null;
  108.                         unset($results['id']);
  109.                         unset($results['isActive']);
  110.                         unset($results['createAt']);
  111.                         unset($results['startAt']);
  112.                         unset($results['finishAt']);
  113.                         unset($results['reference']);
  114.                     }else{
  115.                         $results = (array)$this->ifArrayIndexExist;
  116.                         $timeStampStartDate 0;
  117.                     }
  118.                     if(time() >= $timeStampStartDate  && time() <= $timeStampEndDate){
  119.                         $v1 = (array)$lightbox[0]->getStartAt();
  120.                         $v2 = (array)$lightbox[0]->getFinishAt();
  121.                         $datetime1 = new \DateTime($v1['date']);
  122.                         $datetime2 = new \DateTime($v2['date']);
  123.                         $since_start $datetime1->diff($datetime2);
  124.                         $minutes $since_start->days 24 60;
  125.                         $minutes += $since_start->60;
  126.                         $minutes += $since_start->i;
  127.                         $time $minutes 60 1000;
  128.                         $jsonContent $serializer->serialize('active''json');
  129.                         $cookieMaintenance = new Cookie('maintenancewebsite'$jsonContent$timeStampStartDate $time,'/',nullfalsefalse);
  130.                     }else{
  131.                         $jsonContent $serializer->serialize('notactive''json');
  132.                         $cookieMaintenance = new Cookie('maintenancewebsite'$jsonContent,0,'/',nullfalsefalse);
  133.                     }
  134.                 }
  135.             }
  136.         } catch (Exception $e) {
  137.             //todo
  138.         }
  139.         $authenticationUtils $this->get('security.authentication_utils');
  140.         $response $this->render('ScabalFrontBundle:Front:login.html.twig', array(
  141.             'last_username' => $authenticationUtils->getLastUsername(),
  142.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  143.             'results' => $results,
  144.             'csrf_token' => false
  145.         ));
  146.         $response->headers->setCookie($cookieMaintenance);
  147.         $response->headers->setCookie($cookieAlreadyLogged);
  148.         return $response;
  149.     }
  150.     public function logoutAction(Request $request) {
  151.         $this->get('security.token_storage')->setToken(null);
  152.         $request->getSession()->invalidate();
  153.         return $this->redirect($this->generateUrl('login'));
  154.     }
  155.     public function logoutbrandAction(Request $request) {
  156.         $session $request->getSession()->get('bypass');
  157.         $url null;
  158.         if(count($session) > 0){
  159.             if(count($session->getUrl()) > 0){
  160.                 $url $session->getUrl();
  161.                 $request->getSession()->invalidate();
  162.                 $cookies  $request->cookies->all();
  163.                 if(count($cookies) > 0){
  164.                     $response = new RedirectResponse($url);
  165.                     foreach ($cookies as $key => $value){
  166.                         $response->headers->clearCookie($key);
  167.                     }
  168.                     return $response;
  169.                 }
  170.             }
  171.         }
  172.         return null;
  173.     }
  174.     public function orderAction() {
  175.         return $this->render 'ScabalFrontBundle:Front:order.html.twig', array() );
  176.         // ...
  177.     }
  178.     public function orderv2Action() {
  179.         return $this->render 'ScabalFrontBundle:Front:orderv2.html.twig', array() );
  180.         // ...
  181.     }
  182.     public function orderv3Action() {
  183.         return $this->render 'ScabalFrontBundle:Front:orderv3.html.twig', array() );
  184.         // ...
  185.     }
  186.     public function dashboardAction() {
  187.         return $this->render 'ScabalFrontBundle:Front:dashboard.html.twig', array());
  188.         // ...
  189.     }
  190.     public function clientsAction() {
  191.         return $this->render 'ScabalFrontBundle:Front:clients.html.twig', array () );
  192.         // ...
  193.     }
  194.     public function faqAction() {
  195.         return $this->render 'ScabalFrontBundle:Front:faq.html.twig', array () );
  196.         // ...
  197.     }
  198.     public function settingsAction() {
  199.         return $this->render 'ScabalFrontBundle:Front:settings.html.twig', array () );
  200.         // ...
  201.     }
  202.     public function deliveryAction() {
  203.         return $this->render 'ScabalFrontBundle:Front:delivery.html.twig', array () );
  204.         // ...
  205.     }
  206.     public function resetAction() {
  207.         return $this->render 'ScabalFrontBundle:Front:reset.html.twig', array () );
  208.         // ...
  209.     }
  210.     public function brandAction(Request $request) {
  211.         $response $this->render('ScabalFrontBundle:Front:brand.html.twig', array ());
  212.         $response->headers->removeCookie('myFavorite');
  213.         $response->headers->removeCookie('alreadyconnected');
  214.         $response->headers->clearCookie('REMEMBERME');
  215.         return $response;
  216.     }
  217.     public function viewerAction(Request $request,$order,$type) {
  218.         /**
  219.          * Retrieve user
  220.          **/
  221.         $user = array(
  222.             "name" => $this->get('security.token_storage')->getToken()->getUser()->getName(),
  223.             "kunnr" => $this->get('security.token_storage')->getToken()->getUser()->getKunnr()
  224.         );
  225.         $jacket false;
  226.         $trouser false;
  227.         $waistcoat false;
  228.         $coat false;
  229.         $shirt false;
  230.         $query 'id_order='.$order.'&order_type='.$type;
  231.         $currentUrl $request->getUri ();
  232.         if (strstr $currentUrl'localhost' )) {
  233.             $urlItems $this->container->getParameter 'api_get_order_item_details' );
  234.         } else {
  235.             $urlItems $this->container->getParameter 'api_dashboard_get_item_details').$query;
  236.         }
  237.         $responseItems $this->get("http")->getDataToWebServiceUtf8$urlItems );
  238.         $responseItems json_decode($responseItems);
  239.  
  240.         /*
  241.             TEMPORARY FIX 27-01-2023
  242.             Same problem as in the resume, SAP sends numbers wrong
  243.             ex: 1,00- insteadof -1,00
  244.         */
  245.         foreach ($responseItems->MEASURES as &$measure){
  246.             if (substr($measure->measure_value, -1) == '-'){
  247.                 $measure->measure_value substr($measure->measure_value0, -1);
  248.                 $measure->measure_value "-".$measure->measure_value;
  249.             }
  250.         }
  251.         $garment_set $responseItems->MAIN_DATA[0]->garment_set;
  252.         $jacket $this->getJacketInArray($garment_set);
  253.         $trouser $this->getTrouserInArray($garment_set);
  254.         $waistcoat $this->getWaistCoatInArray($garment_set);
  255.         $coat $this->getCoatInArray($garment_set);
  256.         $shirt $this->getShirtInArray($garment_set);
  257.         if($responseItems->MAIN_DATA[0]->price_tot && !$this->getUser()->getShouldHidePrice()){
  258.             $data json_decode($request->cookies->get('myFavorite'));
  259.             $price_visibility $data->price_visibility;
  260.             $customer $data->idClient;
  261.             $queryMargins 'id_customer='.$customer;
  262.             if (strstr $currentUrl'localhost' )) {
  263.                 $urlMargins $this->container->getParameter 'api_dashboard_get_margins_demo' );
  264.             } else {
  265.                 $urlMargins $this->container->getParameter 'api_dashboard_get_margins').$queryMargins;
  266.             }
  267.             $responseMargins $this->get("http")->getDataToWebServiceUtf8$urlMargins );
  268.             $responseMargins json_decode($responseMargins);
  269.             $prodtype $responseItems->MAIN_DATA[0]->prodtype;
  270.             $branding $responseItems->MAIN_DATA[0]->branding;
  271.             $zusage $responseItems->MAIN_DATA[0]->zusage;
  272.             $marge_factor null;
  273.             $extra_charge null;
  274.             $dataMargins = (array)$responseMargins->MARGINS;
  275.             switch ($price_visibility) {
  276.                 case 'P':
  277.                     foreach ($dataMargins as $dataMargin) {
  278.                         $dataMargin = (array)$dataMargin;
  279.                         if($dataMargin['permission'] == $prodtype && $dataMargin['branding'] == $branding && $dataMargin['zusage'] == $zusage){
  280.                             $marge_factor $dataMargin['marge_factor'];
  281.                             $extra_charge $dataMargin['extra_charge'];
  282.                         }
  283.                     }
  284.                     $responseItems->MAIN_DATA[0]->price_tot = (($responseItems->MAIN_DATA[0]->price_tot $marge_factor) + $extra_charge);
  285.                     $price true;
  286.                     break;
  287.                 case 'S':
  288.                     foreach ($dataMargins as $dataMargin) {
  289.                         $dataMargin = (array)$dataMargin;
  290.                         if($dataMargin['permission'] == $prodtype && $dataMargin['branding'] == $branding && $dataMargin['zusage'] == $zusage){
  291.                             $marge_factor $dataMargin['marge_factor'];
  292.                             $extra_charge $dataMargin['extra_charge'];
  293.                         }
  294.                     }
  295.                     $responseItems->MAIN_DATA[0]->price_tot = ($responseItems->MAIN_DATA[0]->price_tot $extra_charge);
  296.                     $price true;
  297.                     break;
  298.                 default:
  299.                     $price false;
  300.                     break;
  301.             }
  302.         }else{
  303.             $price false;
  304.         }
  305.         if(property_exists($responseItems'PDF_INFO')){
  306.             if($responseItems->PDF_INFO->zdate 0){
  307.                 $now = new \DateTime($responseItems->PDF_INFO->zdate);
  308.                 $responseItems->PDF_INFO->zdate $now->format('d/m/Y');
  309.             }else if($responseItems->MAIN_DATA[0]->order_type == 'DRAFT'){
  310.                 $now = new \DateTime();
  311.                 $responseItems->PDF_INFO->zdate $now->format('d/m/Y');
  312.             }
  313.         }else{
  314.             $responseItems->PDF_INFO = new \stdClass();
  315.             if($responseItems->MAIN_DATA[0]->order_type == 'DRAFT'){
  316.                 $now = new \DateTime();
  317.                 $responseItems->PDF_INFO->zdate $now->format('d/m/Y');
  318.             }else{
  319.                 $responseItems->PDF_INFO->zdate 0;
  320.             }
  321.             $responseItems->PDF_INFO->bunch_id '';
  322.             $responseItems->PDF_INFO->bunch_name '';
  323.         }
  324.         $html $this->renderView('ScabalFrontBundle:Front:viewer.html.twig', array(
  325.             'MAINDATA'  => $responseItems->MAIN_DATA,
  326.             'MEASURES'  => $responseItems->MEASURES,
  327.             'OPTIONS'  => $responseItems->OPTIONS,
  328.             'SIZESQUANTITY' =>  $responseItems->SIZES_QUANTITY,
  329.             'INITIALS' => $responseItems->INITIALS,
  330.             'order' => $order,
  331.             'type' => $type,
  332.             'PRICE' => $price,
  333.             'BASEDIR' => $this->getParameter('base_dir'),
  334.             'USER' => $user,
  335.             'INFO' => $responseItems->PDF_INFO,
  336.             'JACKET' => $jacket,
  337.             'TROUSER' => $trouser,
  338.             'WAISTCOAT' => $waistcoat,
  339.             'COAT' => $coat,
  340.             'SHIRT' => $shirt,
  341.         ));
  342.         $snappy $this->get('knp_snappy.pdf');
  343.         $snappy->setTimeout(300);
  344.         $snappy->setOption('footer-center''Page [page]/[toPage]');
  345.         $filename $order.'_'.$type.'_'.date('m-d-Y');
  346.         return new Response(
  347.             $snappy->getOutputFromHtml($html, array(
  348.                 'images' => true,
  349.                 'enable-javascript' => true,
  350.                 'enable-external-links' => true,
  351.                 'enable-internal-links' => true
  352.             )),
  353.             200,
  354.             array(
  355.                 'Content-Type'          => 'application/pdf',
  356.                 'Content-Disposition'   => 'attachment; filename="'.$filename.'".pdf"'
  357.             )
  358.         );
  359.     }
  360.     public function viewerwebAction(Request $request,$order,$type) {
  361.         /**
  362.          * Retrieve user
  363.          **/
  364.         $user = array(
  365.             "name" => $this->get('security.token_storage')->getToken()->getUser()->getName(),
  366.             "kunnr" => $this->get('security.token_storage')->getToken()->getUser()->getKunnr()
  367.         );
  368.         $jacket false;
  369.         $trouser false;
  370.         $waistcoat false;
  371.         $coat false;
  372.         $shirt false;
  373.         $em $this->getDoctrine()->getManager();
  374.         $repository $em->getRepository('ScabalBackBundle:Dashboard\Drafts\Drafts');
  375.         $result $repository->scabalFindByIdDraftAndTypeProduct($order);
  376.         $dbTransformer = new TransformDbObjectToJsonSapFormat();
  377.         $response $dbTransformer->scabalTransformItemDetailsDraftData($result);
  378.         $responseItems json_decode($response);
  379.         $garment_set $responseItems->maindata->garment_set;
  380.         $jacket $this->getJacketInArray($garment_set);
  381.         $trouser $this->getTrouserInArray($garment_set);
  382.         $waistcoat $this->getWaistCoatInArray($garment_set);
  383.         $coat $this->getCoatInArray($garment_set);
  384.         $shirt $this->getShirtInArray($garment_set);
  385.         $price false;
  386.         $responseItems->PDF_INFO = new \stdClass();
  387.         if($type == 'draft'){
  388.             $now = new \DateTime();
  389.             $responseItems->PDF_INFO->zdate $now->format('d/m/Y');
  390.         }else{
  391.             $responseItems->PDF_INFO->zdate 0;
  392.         }
  393.         $responseItems->PDF_INFO->bunch_id '';
  394.         $responseItems->PDF_INFO->bunch_name '';
  395.         if(!property_exists($responseItems,'maindata')){
  396.             $responseItems->maindata = array();
  397.         }
  398.         if(!property_exists($responseItems,'measures')){
  399.             $responseItems->measures = array();
  400.         }
  401.         if(!property_exists($responseItems,'options')){
  402.             $responseItems->options = array();
  403.         }
  404.         if(!property_exists($responseItems,'sizes_quantity')){
  405.             $responseItems->sizes_quantity = array();
  406.         }
  407.         if(!property_exists($responseItems,'initials')){
  408.             $responseItems->initials = array();
  409.         }
  410.         $html $this->renderView('ScabalFrontBundle:Front:viewerweb.html.twig', array(
  411.             'MAINDATA'  => $responseItems->maindata,
  412.             'MEASURES'  => $responseItems->measures,
  413.             'OPTIONS'  => $responseItems->options,
  414.             'SIZESQUANTITY' =>  $responseItems->sizes_quantity,
  415.             'INITIALS' =>  $responseItems->initials,
  416.             'ORDER' => $order,
  417.             'TYPE' => $type,
  418.             'PRICE' => $price,
  419.             'BASEDIR' => $this->getParameter('base_dir'),
  420.             'USER' => $user,
  421.             'INFO' => $responseItems->PDF_INFO,
  422.             'JACKET' => $jacket,
  423.             'TROUSER' => $trouser,
  424.             'WAISTCOAT' => $waistcoat,
  425.             'COAT' => $coat,
  426.             'SHIRT' => $shirt,
  427.         ));
  428.         $snappy $this->get('knp_snappy.pdf');
  429.         $snappy->setTimeout(300);
  430.         $snappy->setOption('footer-center''Page [page]/[toPage]');
  431.         $filename $order.'_'.$type.'_'.date('m-d-Y');
  432.         return new Response(
  433.             $snappy->getOutputFromHtml($html, array(
  434.                 'images' => true,
  435.                 'enable-javascript' => true,
  436.                 'enable-external-links' => true,
  437.                 'enable-internal-links' => true
  438.             )),
  439.             200,
  440.             array(
  441.                 'Content-Type'          => 'application/pdf',
  442.                 'Content-Disposition'   => 'attachment; filename="'.$filename.'".pdf"'
  443.             )
  444.         );
  445.     }
  446.     public function garmentReturnAction() {
  447.         return $this->render 'ScabalFrontBundle:Front:garmentReturn.html.twig', array() );
  448.         // ...
  449.     }
  450. }