src/Controller/DeliveryslotapiController.php line 2246

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use symfony\Component\Routing\Annotation\Route;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Model\Asset\Service;
  9. use Pimcore\Model\DataObject\Service as DoService;
  10. use Carbon\Carbon;
  11. use Pimcore\Model\User;
  12. use Firebase\JWT\JWT;
  13. use Firebase\JWT\Key;
  14. class DeliveryslotapiController extends FrontendController
  15. {
  16.     /**
  17.      * @Route("/deliveryslots/list")
  18.      */
  19.     public function listAction()
  20.     {
  21.         $today_date strtotime("Y-m-d");
  22.         $cur_time date("H:i");
  23.         $slotsList DataObject\Slots::getList();
  24.         $slotsList->setCondition("slotdate >= ? AND prior_time >= ?",[$today_date$cur_time]);
  25.         // $slotsList->setOffset(0);
  26.         $slotsList->setLimit(100);
  27.         $slotsList->setOrderKey("slotdate");
  28.         $slotsList->setOrder("desc");
  29.         $slotsList->load();
  30.         // $slotsList = DataObject\Slots::getList();
  31.         // $slotsList->setOffset(0);
  32.         // $slotsList->setLimit(10);
  33.         // $slotsList->load();
  34.         // if(count($slotsList) > 0){
  35.             foreach ($slotsList as $key => $blog) {
  36.                 // $location_code = $blog->getlocation_code()->getlocation_code();
  37.                 $location_code = (!empty($blog->getloc_id()) && $blog->getloc_id())?$blog->getloc_id()->getlocation_code():'';
  38.                 $loc_name = (!empty($blog->getloc_id()) && $blog->getloc_id())?$blog->getloc_id()->getlocation_name():'';
  39.                 // foreach($location_codes as $location_code){
  40.                 //     $loc_name = $location_code->getlocation_name();
  41.                 // }
  42.                 
  43.                 $data[] = array(
  44.                     "slotId" => $blog->getId(),
  45.                     "prior_time" => $blog->getprior_time(),
  46.                     "picking_time" => $blog->getpicking_time(),
  47.                     "location_code" => $location_code,
  48.                     "loc_name" => $loc_name,
  49.                     "charge" => $blog->getcharge(),
  50.                     "slotdate" => $blog->getslotdate(),
  51.                     "fromtime" => $blog->getfromtime(),
  52.                     "totime" => $blog->gettotime(),
  53.                     "maxorder" => $blog->getmaxorder(),
  54.                     "ordercount" => $blog->getordercount(),
  55.                     "delivery_mode" => $blog->getdelivery_mode());
  56.             }
  57.         // } else $data[] = [];
  58.         // return $slotsList;
  59.         return $this->json(["success" => true"data" => $data]);
  60.     }
  61.     /**
  62.      * @Route("/holidays/getlist")
  63.      */
  64.     public function getlistAction()
  65.     {
  66.         $slotsList DataObject\Holidays::getList();
  67.         $slotsList->load();
  68.         if(count($slotsList) > 0){
  69.             foreach ($slotsList as $key => $blog) {  
  70.                 
  71.                 $location_codes $blog->getlocation_code();
  72.                 $loc_name '';
  73.                 foreach($location_codes as $location_code){
  74.                     $loc_name .= $location_code->getlocation_name().' ';
  75.                 }
  76.                 $data[] = array(
  77.                     "name" => $blog->getname(),
  78.                     "loc_name" => $loc_name,
  79.                     "holidaydate" => $blog->getHolidaydate());
  80.             }
  81.         } else $data[] = [];
  82.         // return $slotsList;
  83.         return $this->json(["success" => true"data" => $data]);
  84.     }
  85.     public function generateObjFolder($folderName,$location_code){
  86.         $yr date("Y");
  87.         $mt date("M");
  88.         $dy date("d");
  89.         $path "/".$folderName."/".$yr."/".$mt."/".$dy;
  90.         $path "/".$folderName."/".$location_code;
  91.         $object DataObject::getByPath($path);
  92.         if(!$object){
  93.             $path1 "/".$folderName."/".$yr."/".$mt;
  94.             $object1 DataObject::getByPath($path1);
  95.             if(!$object1){
  96.                 $path2 "/".$folderName."/".$yr;
  97.                 $object2 DataObject::getByPath($path2);                
  98.                 if(!$object2){
  99.                     $path3 "/".$folderName;
  100.                     $object3 DataObject::getByPath($path3);                
  101.                     if(!$object3){
  102.                         $createAssetFolder DoService::createFolderByPath($path3);
  103.                         $createAssetFolder DoService::createFolderByPath($path2);
  104.                         $createAssetFolder DoService::createFolderByPath($path1);
  105.                         $createAssetFolder DoService::createFolderByPath($path);
  106.                         $objParentId $createAssetFolder->getId();
  107.                     }else {
  108.                         $createAssetFolder DoService::createFolderByPath($path2);
  109.                         $createAssetFolder DoService::createFolderByPath($path1);
  110.                         $createAssetFolder DoService::createFolderByPath($path);
  111.                         $objParentId $createAssetFolder->getId();
  112.                     }
  113.                 }else {
  114.                     $createAssetFolder DoService::createFolderByPath($path1);
  115.                     $createAssetFolder DoService::createFolderByPath($path);
  116.                     $objParentId $createAssetFolder->getId();
  117.                 }
  118.             } else {
  119.                 $createAssetFolder DoService::createFolderByPath($path);
  120.                 $objParentId $createAssetFolder->getId();
  121.             }
  122.         } else
  123.         $objParentId $object->getId();
  124.         return $objParentId;
  125.     }
  126.     public function generateSlotObjFolder($folderName,$delivery_mode,$location_code){
  127.         $yr date("Y");
  128.         $mt date("M");
  129.         $dy date("d");
  130.         $path "/".$folderName."/".$delivery_mode."/".$location_code;//."/".$date.'-'.$location_code;
  131.         $object DataObject::getByPath($path);
  132.         if(!$object){
  133.             $path1 "/".$folderName."/".$delivery_mode;//."/".$location_code."/".$date;
  134.             $object1 DataObject::getByPath($path1);
  135.             if(!$object1){
  136.                 $path2 "/".$folderName;//."/".$delivery_mode."/".$location_code;
  137.                 $object2 DataObject::getByPath($path2);                
  138.                 if(!$object2){
  139.                     $createAssetFolder DoService::createFolderByPath($path2);
  140.                     $createAssetFolder DoService::createFolderByPath($path1);
  141.                     $createAssetFolder DoService::createFolderByPath($path);
  142.                     $objParentId $createAssetFolder->getId();
  143.                 }else {
  144.                     $createAssetFolder DoService::createFolderByPath($path1);
  145.                     $createAssetFolder DoService::createFolderByPath($path);
  146.                     $objParentId $createAssetFolder->getId();
  147.                 }
  148.             } else {
  149.                 $createAssetFolder DoService::createFolderByPath($path);
  150.                 $objParentId $createAssetFolder->getId();
  151.             }
  152.         } else
  153.         $objParentId $object->getId();
  154.         return $objParentId;
  155.     }
  156.     /**
  157.      * @Route("/deliveryslots/save", methods={"POST"})
  158.      */
  159.     public function saveAction(Request $request)
  160.     {
  161.         $prior_time $request->get('prior_time');
  162.         $location_code $request->get('location_code');
  163.         // $location_codes[] = $location_code;
  164.         $picking_time $request->get('picking_time');
  165.         $delivery_mode $request->get('delivery_mode');
  166.         $charge $request->get('charge');
  167.         $date $request->get('slotdate');
  168.         $message "No data found";
  169.         if($prior_time == "" || $location_code == "" || $picking_time == "" || $delivery_mode == "" || $charge == "" || $date == "")
  170.         {
  171.             $message "Prior Time, Location Code, Picking Time, Delivery Mode, Charge and Date are mandatory!";
  172.         } else {
  173.             /*---- Check Location by Location Code ---------*/
  174.             $locData DataObject\Locations::getBylocation_code($location_code1);
  175.             // echo $locData->getId(); die;
  176.             if(empty($locData) || empty($locData->getId()))
  177.             {
  178.                 $message "Location is not exited, please try with valid location code!";
  179.             } else {
  180.                 $loc_id $locData->getId();
  181.                 $date2 date("m/d/y"strtotime($date));
  182.                 $dates Carbon::createFromFormat('m/d/y'$date2);
  183.                 $createAssetFolder DoService::createFolderByPath('Slots');
  184.                 $objParentId $createAssetFolder->getId();
  185.                 $slotObjectName $date.'-'.$loc_id.'-'.time();
  186.                 $slotObject = new DataObject\Slots(); 
  187.                 $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  188.                 $slotObject->setParentId($objParentId);
  189.                 $slotObject->setPrior_time($prior_time);
  190.                 $slotObject->setPicking_time($picking_time);
  191.                 $slotObject->setDelivery_mode($delivery_mode);
  192.                 $slotObject->setSlotdate($dates);
  193.                 $slotObject->setloc_id(DataObject\Locations::getById($loc_id));
  194.                 $slotObject->setCharge($charge);
  195.                 $slotObject->setPublished(true);
  196.                 $slotObject->save();
  197.                 $message 'Slot Created Successfully';
  198.             }
  199.         }
  200.         return $this->json(["success" => true"data" => $message]);
  201.     }
  202.     public function getWeekDates1($holidaysList$todaydate){
  203.         $jj=0$weekdates = [];
  204.         for($ii=1$ii<15$ii++)
  205.         {
  206.             if($jj >= 7) break;
  207.             if(empty($holidaysList) || !in_array($todaydate$holidaysList)){
  208.                 $weekdates[] = $todaydate;
  209.                 $jj=$jj+1;
  210.             }
  211.             $todaydate date('Y-m-d'strtotime($todaydate ' +1 day'));
  212.         }
  213.         // echo '<pre>'; print_r($weekdates); die;
  214.         return $weekdates;
  215.     }
  216.     public function getWeekDates2($holidaysList$todaydate$delSlotTimesAvailibility){
  217.         $jj=0$weekdates = [];
  218.         $slot_generate_days $delSlotTimesAvailibility['slot_generate_days'];
  219.         $saturday_slot_availability $delSlotTimesAvailibility['saturday_slot_availability'];
  220.         $sunday_slot_availability $delSlotTimesAvailibility['sunday_slot_availability'];
  221.         $totDays $slot_generate_days+7;
  222.         for($ii=1$ii<$totDays$ii++)
  223.         {
  224.             if($jj >= $slot_generate_days) break;
  225.             if(empty($holidaysList) || !in_array($todaydate$holidaysList)){
  226.                 $weekDay date('w'strtotime($todaydate));
  227.                 if(($weekDay == && $sunday_slot_availability == 'Yes') || ($weekDay == && $saturday_slot_availability == 'Yes') || !in_array($weekDay, [0,6]))
  228.                 {
  229.                     $weekdates[] = $todaydate;
  230.                     $jj=$jj+1;
  231.                 }
  232.             }
  233.             $todaydate date('Y-m-d'strtotime($todaydate ' +1 day'));
  234.         }
  235.         // echo '<pre>'; print_r($weekdates); die;
  236.         return $weekdates;
  237.     }
  238.     public function getWeekDates($holidaysList$todaydate$delSlotTimesAvailibility){
  239.         $jj=0$weekdates = [];
  240.         $slot_prepare_days $delSlotTimesAvailibility['slot_prepare_days'];
  241.         $slot_generate_days $delSlotTimesAvailibility['slot_generate_days'];
  242.         $saturday_slot_availability $delSlotTimesAvailibility['saturday_slot_availability'];
  243.         $sunday_slot_availability $delSlotTimesAvailibility['sunday_slot_availability'];
  244.         $todaydate date('Y-m-d'strtotime($todaydate ' +'.$slot_prepare_days.' day'));
  245.         $totDays $slot_generate_days+7;
  246.         for($ii=1$ii<$totDays$ii++)
  247.         {
  248.             if($jj >= $slot_generate_days) break;
  249.             if(empty($holidaysList) || !in_array($todaydate$holidaysList)){
  250.                 $weekDay date('w'strtotime($todaydate));
  251.                 if(($weekDay == && $sunday_slot_availability == 'Yes') || ($weekDay == && $saturday_slot_availability == 'Yes') || !in_array($weekDay, [0,6]))
  252.                 {
  253.                     $weekdates[] = $todaydate;
  254.                     $jj=$jj+1;
  255.                 }
  256.             }
  257.             $todaydate date('Y-m-d'strtotime($todaydate ' +1 day'));
  258.         }
  259.         // echo '<pre>'; print_r($weekdates); die;
  260.         return $weekdates;
  261.     }
  262.     /**
  263.      * @Route("/deliveryslots/saveslots1")
  264.      */
  265.     public function saveslots1Action()
  266.     {
  267.         // echo 'kk'; die;
  268.         $locationsList DataObject\Locations::getList();
  269.         $locationsList->load();
  270.         foreach($locationsList as $location)//Start of Locations Loop
  271.         {
  272.             //echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
  273.             $location_id $location->getId();
  274.             $holidaysList DataObject\Holidays::getList();
  275.             $holidaysList->setCondition("location_code like '%,".$location_id.",%'");
  276.             $holidaysList->load();
  277.             // if(count($holidaysList) > 0)
  278.             // {
  279.                 $holidayDates = [];
  280.                 foreach($holidaysList as $holiday)
  281.                 {
  282.                     $holiday_locations_list $holiday->getLocation_code();
  283.                     $holidaydate $holiday->getHolidaydate();
  284.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  285.                     array_push($holidayDates,$holidayDate);
  286.                 }
  287.                 // echo '<pre>'; print_r($holidayDates);
  288.                 $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"));
  289.                 //echo '<pre>weekdates:'; print_r($weekdates);
  290.                 foreach($weekdates as $weekdate)
  291.                 {
  292.                     $slotsList DataObject\Deliveryslotrules::getList();
  293.                     $slotsList->setCondition("location_code like '%,".$location_id.",%'");
  294.                     $slotsList->load();
  295.                     //echo '<br>slotsList Count:'.count($slotsList);
  296.                     if(count($slotsList) > 0)
  297.                     {
  298.                         foreach($slotsList as $slot)
  299.                         {
  300.                             $prior_time $slot->getprior_time();
  301.                             $location_codes $slot->getlocation_code();
  302.                             $picking_time $slot->getpicking_time();
  303.                             $delivery_mode $slot->getdelivery_mode();
  304.                             $charge $slot->getcharge();
  305.                             $fromtime $slot->getfromtime();
  306.                             $totime $slot->gettotime();
  307.                             $maxorder $slot->getmaxorder();
  308.                             // $ordercount = $slot->getordercount();
  309.                             $date $weekdate;//$slot->getslotdate();
  310.                             $date2 date("m/d/y"strtotime($date));
  311.                             $dates Carbon::createFromFormat('m/d/y'$date2);
  312.                             $location_code_array = [];
  313.                             //echo '<pre>location_codes Count:'.count($location_codes);
  314.                             foreach($location_codes as $location_code){//Location Code loop Starts
  315.                                 if($location_id == $location_code->getId())
  316.                                 {
  317.                                     $location_code_array[] = DataObject\Locations::getById($location_code->getId());
  318.                                     $location_code_id DataObject\Locations::getById($location_code->getId());
  319.                                     $loc_id $location_code->getId();
  320.                                     /*----------- Delivery Slot Times Loop Starts --------*/
  321.                                     $deliveryslottimesList DataObject\Deliveryslottimes::getList();
  322.                                     $deliveryslottimesList->load();
  323.                                     //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  324.                                     if(count($deliveryslottimesList)>0)
  325.                                     {
  326.                                         foreach($deliveryslottimesList as $deliveryslottimes)
  327.                                         {
  328.                                             /*------------ Checking the slot data -------------*/
  329.                                             $slotCheck 1;
  330.                                             $today_date date("Y-m-d"strtotime($weekdate));
  331.                                             $cur_time $prior_time;
  332.                                             $checkDataList DataObject\Slots::getList();
  333.                                             if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  334.                                                 $checkDataList->filterBySlotdate($today_date'=');
  335.                                             }
  336.                                             if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  337.                                                 $checkDataList->filterByprior_time($cur_time'=');
  338.                                             }
  339.                                             if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  340.                                                 $checkDataList->filterBydelivery_mode($delivery_mode'=');
  341.                                             }
  342.                                             // $checkDataList->setCondition("loc_id__id = ".$loc_id);
  343.                                             // $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
  344.                                             $checkDataList->setLimit(100);
  345.                                             $checkDataList->setOrderKey("slotdate");
  346.                                             $checkDataList->setOrder("asc");
  347.                                             $checkDataList->load();
  348.                                             //echo '<br>checkDataList Count:'.count($checkDataList);
  349.                                             $checkData_loc_valid 0$checkData_locs = [];
  350.                                             if(count($checkDataList) > 0)
  351.                                             {
  352.                                                 foreach($checkDataList as $checkData)
  353.                                                 {
  354.                                                     $checkData_locData $checkData->getloc_id();
  355.                                                     $checkData_locId $checkData_locData->getId();
  356.                                                     array_push($checkData_locs$checkData_locId);
  357.                                                 }
  358.                                             }
  359.                                             $checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id$checkData_locs)) || count($checkDataList) <= 0)?1:0;
  360.                                             // echo '<br>checkData_locId:'.$checkData_locId;
  361.                                             // echo '<pre>checkData_locs:';
  362.                                             // print_r($checkData_locs);
  363.                                             // echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
  364.                                             /*------------ End of Checking the slot data -------------*/
  365.                                             if($checkData_loc_valid == 1){
  366.                                                 // $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
  367.                                                 $createAssetFolder DoService::createFolderByPath('Slots');
  368.                                                 $objParentId $createAssetFolder->getId();
  369.                                                 // $holidayObjectName = $location_code.'-'.$name;
  370.                                                 $slotObjectName $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
  371.                                                 $slotObject = new DataObject\Slots(); 
  372.                                                 $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  373.                                                 $slotObject->setParentId($objParentId);
  374.                                                 $slotObject->setPrior_time($prior_time);
  375.                                                 $slotObject->setPicking_time($picking_time);
  376.                                                 $slotObject->setDelivery_mode($delivery_mode);
  377.                                                 // $slotObject->setSlotdate($date2);
  378.                                                 $slotObject->setSlotdate($dates);
  379.                                                 $slotObject->setfromtime($fromtime);
  380.                                                 $slotObject->settotime($totime);
  381.                                                 $slotObject->setmaxorder($maxorder);
  382.                                                 // $slotObject->setLocation_code($location_code_array);
  383.                                                 $slotObject->setCharge($charge);
  384.                                                 $slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
  385.                                                 $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
  386.                                                 $slotObject->setPublished(true);
  387.                                                 $slotObject->save();
  388.                                             }
  389.                                         }
  390.                                     }
  391.                                 }
  392.                                 /*---------- Delivery Slot Time loop ends ------------*/
  393.                             }//Location Code loop ends
  394.                         }
  395.                     }
  396.                 }
  397.             // }
  398.         }//End of Locations Loop
  399.         return $this->json(["success" => true"data" => 'Slot Created for one week Successfully']);
  400.     }
  401.     /**
  402.      * @Route("/deliveryslots/saveslots2")
  403.      */
  404.     public function saveslots2Action()
  405.     {
  406.         // echo 'kk'; die;
  407.         $locationsList DataObject\Locations::getList();
  408.         $locationsList->load();
  409.         foreach($locationsList as $location)//Start of Locations Loop
  410.         {
  411.             //echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
  412.             $location_id $location->getId();
  413.             $holidaysList DataObject\Holidays::getList();
  414.             $holidaysList->setCondition("location_code like '%,".$location_id.",%'");
  415.             $holidaysList->load();
  416.             // if(count($holidaysList) > 0)
  417.             // {
  418.                 $holidayDates = [];
  419.                 foreach($holidaysList as $holiday)
  420.                 {
  421.                     $holiday_locations_list $holiday->getLocation_code();
  422.                     $holidaydate $holiday->getHolidaydate();
  423.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  424.                     array_push($holidayDates,$holidayDate);
  425.                 }
  426.                 // echo '<pre>'; print_r($holidayDates);
  427.                 /*----------- Delivery Slot Times Loop Starts --------*/
  428.                 $deliveryslottimesList DataObject\Deliveryslottimes::getList();
  429.                 $deliveryslottimesList->load();
  430.                 //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  431.                 if(count($deliveryslottimesList)>0)
  432.                 {
  433.                     foreach($deliveryslottimesList as $deliveryslottimes)
  434.                     {
  435.                         $slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
  436.                         $slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
  437.                         $saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
  438.                         $sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
  439.                         $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  440.                         // echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility);
  441.                         $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  442.                         // echo '<pre>weekdates:'; print_r($weekdates);
  443.                         foreach($weekdates as $weekdate)
  444.                         {
  445.                             $slotsList DataObject\Deliveryslotrules::getList();
  446.                             $slotsList->setCondition("location_code like '%,".$location_id.",%'");
  447.                             $slotsList->load();
  448.                             //echo '<br>slotsList Count:'.count($slotsList);
  449.                             if(count($slotsList) > 0)
  450.                             {
  451.                                 foreach($slotsList as $slot)
  452.                                 {
  453.                                     $prior_time $slot->getprior_time();
  454.                                     $location_codes $slot->getlocation_code();
  455.                                     $picking_time $slot->getpicking_time();
  456.                                     $delivery_mode $slot->getdelivery_mode();
  457.                                     $charge $slot->getcharge();
  458.                                     $fromtime $slot->getfromtime();
  459.                                     $totime $slot->gettotime();
  460.                                     $maxorder $slot->getmaxorder();
  461.                                     // $ordercount = $slot->getordercount();
  462.                                     $date $weekdate;//$slot->getslotdate();
  463.                                     $date2 date("m/d/y"strtotime($date));
  464.                                     $dates Carbon::createFromFormat('m/d/y'$date2);
  465.                                     $location_code_array = [];
  466.                                     //echo '<pre>location_codes Count:'.count($location_codes);
  467.                                     foreach($location_codes as $location_code){//Location Code loop Starts
  468.                                         if($location_id == $location_code->getId())
  469.                                         {
  470.                                             $location_code_array[] = DataObject\Locations::getById($location_code->getId());
  471.                                             $location_code_id DataObject\Locations::getById($location_code->getId());
  472.                                             $loc_id $location_code->getId();
  473.                                             /*----------- Delivery Slot Times Loop Starts --------*/
  474.                                             // $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
  475.                                             // $deliveryslottimesList->load();
  476.                                             // //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  477.                                             // if(count($deliveryslottimesList)>0)
  478.                                             // {
  479.                                             //     foreach($deliveryslottimesList as $deliveryslottimes)
  480.                                             //     {
  481.                                                     /*------------ Checking the slot data -------------*/
  482.                                                     $slotCheck 1;
  483.                                                     $today_date date("Y-m-d"strtotime($weekdate));
  484.                                                     $cur_time $prior_time;
  485.                                                     $checkDataList DataObject\Slots::getList();
  486.                                                     if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  487.                                                         $checkDataList->filterBySlotdate($today_date'=');
  488.                                                     }
  489.                                                     if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  490.                                                         $checkDataList->filterByprior_time($cur_time'=');
  491.                                                     }
  492.                                                     if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  493.                                                         $checkDataList->filterBydelivery_mode($delivery_mode'=');
  494.                                                     }
  495.                                                     // $checkDataList->setCondition("loc_id__id = ".$loc_id);
  496.                                                     // $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
  497.                                                     $checkDataList->setLimit(100);
  498.                                                     $checkDataList->setOrderKey("slotdate");
  499.                                                     $checkDataList->setOrder("asc");
  500.                                                     $checkDataList->load();
  501.                                                     //echo '<br>checkDataList Count:'.count($checkDataList);
  502.                                                     $checkData_loc_valid 0$checkData_locs = [];
  503.                                                     if(count($checkDataList) > 0)
  504.                                                     {
  505.                                                         foreach($checkDataList as $checkData)
  506.                                                         {
  507.                                                             $checkData_locData $checkData->getloc_id();
  508.                                                             $checkData_locId $checkData_locData->getId();
  509.                                                             array_push($checkData_locs$checkData_locId);
  510.                                                         }
  511.                                                     }
  512.                                                     $checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id$checkData_locs)) || count($checkDataList) <= 0)?1:0;
  513.                                                     // echo '<br>checkData_locId:'.$checkData_locId;
  514.                                                     // echo '<pre>checkData_locs:';
  515.                                                     // print_r($checkData_locs);
  516.                                                     // echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
  517.                                                     /*------------ End of Checking the slot data -------------*/
  518.                                                     if($checkData_loc_valid == 1){
  519.                                                         // $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
  520.                                                         $createAssetFolder DoService::createFolderByPath('Slots');
  521.                                                         $objParentId $createAssetFolder->getId();
  522.                                                         // $holidayObjectName = $location_code.'-'.$name;
  523.                                                         $slotObjectName $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
  524.                                                         $slotObject = new DataObject\Slots(); 
  525.                                                         $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  526.                                                         $slotObject->setParentId($objParentId);
  527.                                                         $slotObject->setPrior_time($prior_time);
  528.                                                         $slotObject->setPicking_time($picking_time);
  529.                                                         $slotObject->setDelivery_mode($delivery_mode);
  530.                                                         // $slotObject->setSlotdate($date2);
  531.                                                         $slotObject->setSlotdate($dates);
  532.                                                         $slotObject->setfromtime($fromtime);
  533.                                                         $slotObject->settotime($totime);
  534.                                                         $slotObject->setmaxorder($maxorder);
  535.                                                         // $slotObject->setLocation_code($location_code_array);
  536.                                                         $slotObject->setCharge($charge);
  537.                                                         $slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
  538.                                                         $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
  539.                                                         $slotObject->setPublished(true);
  540.                                                         $slotObject->save();
  541.                                                     }
  542.                                             //     }
  543.                                             // }
  544.                                         }
  545.                                         /*---------- Delivery Slot Time loop ends ------------*/
  546.                                     }//Location Code loop ends
  547.                                 }
  548.                             }
  549.                         }
  550.                     }
  551.                 }
  552.             // }
  553.         }//End of Locations Loop
  554.         return $this->json(["success" => true"data" => 'Slot Created for one week Successfully']);
  555.     }
  556.     /**
  557.      * @Route("/deliveryslots/saveslots3")
  558.      */
  559.     public function saveslots3Action()
  560.     {
  561.         // echo 'kk'; die;
  562.         $locationsList DataObject\Locations::getList();
  563.         $locationsList->load();
  564.         foreach($locationsList as $location)//Start of Locations Loop
  565.         {
  566.             //echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
  567.             $location_id $location->getId();
  568.             $holidaysList DataObject\Holidays::getList();
  569.             $holidaysList->setCondition("location_code like '%,".$location_id.",%'");
  570.             $holidaysList->load();
  571.             // if(count($holidaysList) > 0)
  572.             // {
  573.                 $holidayDates = [];
  574.                 foreach($holidaysList as $holiday)
  575.                 {
  576.                     $holiday_locations_list $holiday->getLocation_code();
  577.                     $holidaydate $holiday->getHolidaydate();
  578.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  579.                     array_push($holidayDates,$holidayDate);
  580.                 }
  581.                 // echo '<pre>'; print_r($holidayDates);
  582.                 /*----------- Delivery Slot Times Loop Starts --------*/
  583.                 $deliveryslottimesList DataObject\Deliveryslottimes::getList();
  584.                 $deliveryslottimesList->load();
  585.                 //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  586.                 if(count($deliveryslottimesList)>0)
  587.                 {
  588.                     foreach($deliveryslottimesList as $deliveryslottimes)
  589.                     {
  590.                         // echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
  591.                         $slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
  592.                         $slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
  593.                         $saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
  594.                         $sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
  595.                         $slot_generate_days $slot_generate_days+1
  596.                         $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  597.                         // echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
  598.                         $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  599.                         // echo '<pre>weekdates:'; print_r($weekdates);
  600.                         foreach($weekdates as $weekdate)
  601.                         {
  602.                             $slotsList DataObject\Deliveryslotrules::getList();
  603.                             // $slotsList->setCondition("location_code like '%,".$location_id.",%'");
  604.                             $slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
  605.                             $slotsList->load();
  606.                             //echo '<br>slotsList Count:'.count($slotsList);
  607.                             if(count($slotsList) > 0)
  608.                             {
  609.                                 foreach($slotsList as $slot)
  610.                                 {
  611.                                     $prior_time $slot->getprior_time();
  612.                                     $location_codes $slot->getlocation_ids();//$slot->getlocation_code();
  613.                                     // $picking_time = $slot->getpicking_time();
  614.                                     $delivery_mode $slot->getdelivery_mode();
  615.                                     // $charge = $slot->getcharge();
  616.                                     $fromtime $slot->getfromtime();
  617.                                     $totime $slot->gettotime();
  618.                                     $maxorder $slot->getmaxorder();
  619.                                     // $ordercount = $slot->getordercount();
  620.                                     $date $weekdate;//$slot->getslotdate();
  621.                                     $date2 date("m/d/y"strtotime($date));
  622.                                     $dates Carbon::createFromFormat('m/d/y'$date2);
  623.                                     $location_code_array = [];
  624.                                     // echo '<pre>location_codes Count:'.count($location_codes);
  625.                                     if(!empty($location_codes))
  626.                                     {
  627.                                         foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
  628.                                             if($location_id == $location_id_info)//if($location_id == $location_code->getId())
  629.                                             {
  630.                                                 // $location_code_array[] = DataObject\Locations::getById($location_code->getId());
  631.                                                 // $location_code_id = DataObject\Locations::getById($location_code->getId());
  632.     
  633.                                                 // $loc_id = $location_code->getId();
  634.     
  635.                                                 $location_code_array[] = DataObject\Locations::getById($location_id_info);
  636.                                                 $location_code_id DataObject\Locations::getById($location_id_info);
  637.     
  638.                                                 $loc_id $location_id_info;
  639.     
  640.                                                 /*----------- Delivery Slot Times Loop Starts --------*/
  641.                                                 // $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
  642.                                                 // $deliveryslottimesList->load();
  643.                                                 // //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  644.                                                 // if(count($deliveryslottimesList)>0)
  645.                                                 // {
  646.                                                 //     foreach($deliveryslottimesList as $deliveryslottimes)
  647.                                                 //     {
  648.                                                         /*------------ Checking the slot data -------------*/
  649.                                                         $slotCheck 1;
  650.                                                         $today_date date("Y-m-d"strtotime($weekdate));
  651.                                                         $cur_time $prior_time;
  652.     
  653.                                                         $checkDataList DataObject\Slots::getList();
  654.     
  655.                                                         if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  656.                                                             $checkDataList->filterBySlotdate($today_date'=');
  657.                                                         }
  658.     
  659.                                                         if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  660.                                                             $checkDataList->filterByprior_time($cur_time'=');
  661.                                                         }
  662.     
  663.                                                         if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  664.                                                             $checkDataList->filterBydelivery_mode($delivery_mode'=');
  665.                                                         }
  666.                                                         // $checkDataList->setCondition("loc_id__id = ".$loc_id);
  667.                                                         // $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
  668.     
  669.                                                         $checkDataList->setLimit(100);
  670.                                                         $checkDataList->setOrderKey("slotdate");
  671.                                                         $checkDataList->setOrder("asc");
  672.                                                         $checkDataList->load();
  673.                                                         //echo '<br>checkDataList Count:'.count($checkDataList);
  674.     
  675.                                                         $checkData_loc_valid 0$checkData_locs = [];
  676.                                                         if(count($checkDataList) > 0)
  677.                                                         {
  678.                                                             foreach($checkDataList as $checkData)
  679.                                                             {
  680.                                                                 // $checkData_locData = $checkData->getloc_id();
  681.                                                                 // $checkData_locId = $checkData_locData->getId();
  682.                                                                 $checkData_locId $checkData->getloc_id();
  683.                                                                 array_push($checkData_locs$checkData_locId);
  684.                                                             }
  685.                                                         }
  686.                                                         $checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id$checkData_locs)) || count($checkDataList) <= 0)?1:0;
  687.     
  688.                                                         // echo '<br>checkData_locId:'.$checkData_locId;
  689.                                                         // echo '<pre>checkData_locs:';
  690.                                                         // print_r($checkData_locs);
  691.                                                         // echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
  692.                                                         /*------------ End of Checking the slot data -------------*/
  693.     
  694.                                                         if($checkData_loc_valid == 1){
  695.                                                             // $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
  696.     
  697.                                                             $createAssetFolder DoService::createFolderByPath('Slots');
  698.                                                             $objParentId $createAssetFolder->getId();
  699.     
  700.                                                             // $holidayObjectName = $location_code.'-'.$name;
  701.                                                             $slotObjectName $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
  702.     
  703.                                                             $slotObject = new DataObject\Slots(); 
  704.                                                             $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  705.                                                             $slotObject->setParentId($objParentId);
  706.                                                             $slotObject->setPrior_time($prior_time);
  707.                                                             // $slotObject->setPicking_time($picking_time);
  708.                                                             $slotObject->setDelivery_mode($delivery_mode);
  709.                                                             // $slotObject->setSlotdate($date2);
  710.                                                             $slotObject->setSlotdate($dates);
  711.                                                             $slotObject->setfromtime($fromtime);
  712.                                                             $slotObject->settotime($totime);
  713.                                                             $slotObject->setmaxorder($maxorder);
  714.     
  715.                                                             // $slotObject->setLocation_code($location_code_array);
  716.     
  717.                                                             // $slotObject->setCharge($charge);
  718.                                                             $slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
  719.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
  720.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
  721.                                                             $slotObject->setloc_id($location_id_info);
  722.     
  723.                                                             $slotObject->setPublished(true);
  724.                                                             $slotObject->save();
  725.                                                         }
  726.                                                 //     }
  727.                                                 // }
  728.                                             }
  729.                                             /*---------- Delivery Slot Time loop ends ------------*/
  730.                                         }//Location Code loop ends
  731.                                     }
  732.                                 }
  733.                             }
  734.                         }
  735.                     }
  736.                 }
  737.             // }
  738.         }//End of Locations Loop
  739.         return $this->json(["success" => true"data" => 'Slot Created for one week Successfully']);
  740.     }
  741.     /**
  742.      * @Route("/deliveryslots/saveslots4")
  743.      */
  744.     public function saveslots4Action()
  745.     {
  746.         $locationsList DataObject\Locations::getList();
  747.         $locationsList->load();
  748.         foreach($locationsList as $location)//Start of Locations Loop
  749.         {
  750.             //echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
  751.             $location_id $location->getId();
  752.             $locationName $location->getLocation_name();
  753.             $locationCode $location->getLocation_code();
  754.             /*------ Check Location is Up Country or not --------*/
  755.             $Is_location_up_country = (strpos(strtolower($locationName),"up country") || strpos(strtoupper($locationCode),"UPCTR"))?1:0;
  756.             $holidaysList DataObject\Holidays::getList();
  757.             $holidaysList->setCondition("location_code like '%,".$location_id.",%'");
  758.             $holidaysList->load();
  759.             // if(count($holidaysList) > 0)
  760.             // {
  761.                 $holidayDates = [];
  762.                 foreach($holidaysList as $holiday)
  763.                 {
  764.                     $holiday_locations_list $holiday->getLocation_code();
  765.                     $holidaydate $holiday->getHolidaydate();
  766.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  767.                     array_push($holidayDates,$holidayDate);
  768.                 }
  769.                 // echo '<pre>'; print_r($holidayDates);
  770.                 /*----------- Delivery Slot Times Loop Starts --------*/
  771.                 $deliveryslottimesList DataObject\Deliveryslottimes::getList();
  772.                 $deliveryslottimesList->load();
  773.                 //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  774.                 if(count($deliveryslottimesList)>0)
  775.                 {
  776.                     foreach($deliveryslottimesList as $deliveryslottimes)
  777.                     {
  778.                         // echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
  779.                         $slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
  780.                         $slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
  781.                         $saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
  782.                         $sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
  783.                         $slot_generate_days $slot_generate_days+1;
  784.                         /*--------------------- Up Country Configuration ------------------------*/
  785.                         $is_upcountry_configuration_applicable = ($deliveryslottimes->getis_upcountry_configuration_applicable())?$deliveryslottimes->getis_upcountry_configuration_applicable():'No';
  786.                         $slot_upcountry_prepare_days = ($deliveryslottimes->getupcountry_prepare_days())?$deliveryslottimes->getupcountry_prepare_days():0;
  787.                         $upcountry_slot_generate_days = ($deliveryslottimes->getupcountry_slot_generate_days())?$deliveryslottimes->getupcountry_slot_generate_days():7;
  788.                         $upcountry_saturday_slot_availability = ($deliveryslottimes->getupcountry_saturday_slot_availability())?$deliveryslottimes->getupcountry_saturday_slot_availability():'No';
  789.                         $upcountry_sunday_slot_availability = ($deliveryslottimes->getupcountry_sunday_slot_availability())?$deliveryslottimes->getupcountry_sunday_slot_availability():'No';
  790.                         $upcountry_slot_generate_days $upcountry_slot_generate_days+1
  791.                         if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
  792.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_upcountry_prepare_days,'slot_generate_days'=>$upcountry_slot_generate_days,'saturday_slot_availability'=>$upcountry_saturday_slot_availability,'sunday_slot_availability'=>$upcountry_sunday_slot_availability];
  793.                         else
  794.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  795.                             
  796.                         // echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
  797.                         $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  798.                         // echo '<pre>weekdates:'; print_r($weekdates);
  799.                         foreach($weekdates as $weekdate)
  800.                         {
  801.                             $slotsList DataObject\Deliveryslotrules::getList();
  802.                             // $slotsList->setCondition("location_code like '%,".$location_id.",%'");
  803.                             $slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
  804.                             $slotsList->load();
  805.                             //echo '<br>slotsList Count:'.count($slotsList);
  806.                             if(count($slotsList) > 0)
  807.                             {
  808.                                 foreach($slotsList as $slot)
  809.                                 {
  810.                                     $prior_time $slot->getprior_time();
  811.                                     $location_codes $slot->getlocation_ids();//$slot->getlocation_code();
  812.                                     // $picking_time = $slot->getpicking_time();
  813.                                     $delivery_mode $slot->getdelivery_mode();
  814.                                     // $charge = $slot->getcharge();
  815.                                     $fromtime $slot->getfromtime();
  816.                                     $totime $slot->gettotime();
  817.                                     $maxorder $slot->getmaxorder();
  818.                                     // $ordercount = $slot->getordercount();
  819.                                     $date $weekdate;//$slot->getslotdate();
  820.                                     $date2 date("m/d/y"strtotime($date));
  821.                                     $dates Carbon::createFromFormat('m/d/y'$date2);
  822.                                     $location_code_array = [];
  823.                                     // echo '<pre>location_codes Count:'.count($location_codes);
  824.                                     if(!empty($location_codes))
  825.                                     {
  826.                                         foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
  827.                                             if($location_id == $location_id_info)//if($location_id == $location_code->getId())
  828.                                             {
  829.                                                 // $location_code_array[] = DataObject\Locations::getById($location_code->getId());
  830.                                                 // $location_code_id = DataObject\Locations::getById($location_code->getId());
  831.     
  832.                                                 // $loc_id = $location_code->getId();
  833.     
  834.                                                 $location_code_array[] = DataObject\Locations::getById($location_id_info);
  835.                                                 $location_code_id DataObject\Locations::getById($location_id_info);
  836.     
  837.                                                 $loc_id $location_id_info;
  838.     
  839.                                                 /*----------- Delivery Slot Times Loop Starts --------*/
  840.                                                 // $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
  841.                                                 // $deliveryslottimesList->load();
  842.                                                 // //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  843.                                                 // if(count($deliveryslottimesList)>0)
  844.                                                 // {
  845.                                                 //     foreach($deliveryslottimesList as $deliveryslottimes)
  846.                                                 //     {
  847.                                                         /*------------ Checking the slot data -------------*/
  848.                                                         $slotCheck 1;
  849.                                                         $today_date date("Y-m-d"strtotime($weekdate));
  850.                                                         $cur_time $prior_time;
  851.     
  852.                                                         $checkDataList DataObject\Slots::getList();
  853.     
  854.                                                         if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  855.                                                             $checkDataList->filterBySlotdate($today_date'=');
  856.                                                         }
  857.     
  858.                                                         if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  859.                                                             $checkDataList->filterByprior_time($cur_time'=');
  860.                                                         }
  861.     
  862.                                                         if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  863.                                                             $checkDataList->filterBydelivery_mode($delivery_mode'=');
  864.                                                         }
  865.                                                         // $checkDataList->setCondition("loc_id__id = ".$loc_id);
  866.                                                         // $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
  867.     
  868.                                                         $checkDataList->setLimit(100);
  869.                                                         $checkDataList->setOrderKey("slotdate");
  870.                                                         $checkDataList->setOrder("asc");
  871.                                                         $checkDataList->load();
  872.                                                         //echo '<br>checkDataList Count:'.count($checkDataList);
  873.     
  874.                                                         $checkData_loc_valid 0$checkData_locs = [];
  875.                                                         if(count($checkDataList) > 0)
  876.                                                         {
  877.                                                             foreach($checkDataList as $checkData)
  878.                                                             {
  879.                                                                 // $checkData_locData = $checkData->getloc_id();
  880.                                                                 // $checkData_locId = $checkData_locData->getId();
  881.                                                                 $checkData_locId $checkData->getloc_id();
  882.                                                                 array_push($checkData_locs$checkData_locId);
  883.                                                             }
  884.                                                         }
  885.                                                         $checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id$checkData_locs)) || count($checkDataList) <= 0)?1:0;
  886.     
  887.                                                         // echo '<br>checkData_locId:'.$checkData_locId;
  888.                                                         // echo '<pre>checkData_locs:';
  889.                                                         // print_r($checkData_locs);
  890.                                                         // echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
  891.                                                         /*------------ End of Checking the slot data -------------*/
  892.     
  893.                                                         if($checkData_loc_valid == 1){
  894.                                                             // $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
  895.     
  896.                                                             $createAssetFolder DoService::createFolderByPath('Slots');
  897.                                                             $objParentId $createAssetFolder->getId();
  898.     
  899.                                                             // $holidayObjectName = $location_code.'-'.$name;
  900.                                                             $slotObjectName $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
  901.     
  902.                                                             $slotObject = new DataObject\Slots(); 
  903.                                                             $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  904.                                                             $slotObject->setParentId($objParentId);
  905.                                                             $slotObject->setPrior_time($prior_time);
  906.                                                             // $slotObject->setPicking_time($picking_time);
  907.                                                             $slotObject->setDelivery_mode($delivery_mode);
  908.                                                             // $slotObject->setSlotdate($date2);
  909.                                                             $slotObject->setSlotdate($dates);
  910.                                                             $slotObject->setfromtime($fromtime);
  911.                                                             $slotObject->settotime($totime);
  912.                                                             $slotObject->setmaxorder($maxorder);
  913.     
  914.                                                             // $slotObject->setLocation_code($location_code_array);
  915.     
  916.                                                             // $slotObject->setCharge($charge);
  917.                                                             $slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
  918.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
  919.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
  920.                                                             $slotObject->setloc_id($location_id_info);
  921.     
  922.                                                             $slotObject->setPublished(true);
  923.                                                             $slotObject->save();
  924.                                                         }
  925.                                                 //     }
  926.                                                 // }
  927.                                             }
  928.                                             /*---------- Delivery Slot Time loop ends ------------*/
  929.                                         }//Location Code loop ends
  930.                                     }
  931.                                 }
  932.                             }
  933.                         }
  934.                     }
  935.                 }
  936.             // }
  937.         }//End of Locations Loop
  938.         return $this->json(["success" => true"data" => 'Slot Created for one week Successfully']);
  939.     }
  940.     public function getSettingInfo()
  941.     {
  942.         /*------ Get Settings Class data --------*/
  943.         $dbConnection \Pimcore\Db::get();
  944.         $settingsClassId $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Settings' ");
  945.         $settingsObject "object_".$settingsClassId;
  946.         
  947.         $settingsId $dbConnection->fetchOne(" select * from ".$settingsObject." WHERE setting_flag = 1");
  948.         /*----- End of Get Settings Class data ---------*/
  949.         /*--------------- Settings info ----------------*/
  950.         $settingsInfo DataObject\Settings::getById($settingsId);
  951.         $settingDataId $settingsInfo->getId();
  952.         $setting_deliveryModes $settingsInfo->getdelivery_modes();
  953.         $setting_slot_time_flag = (!empty($settingsInfo->getslottime()))?$settingsInfo->getslottime():"18:00";
  954.         $stg_deliveryslot_config_is_upcountry_configuration_applicable = ($settingsInfo->getdeliveryslot_config_is_upcountry_configuration_applicable())?$settingsInfo->getdeliveryslot_config_is_upcountry_configuration_applicable():'No';
  955.         $stg_delslot_normalloc_morethan_fromtime = ($settingsInfo->getdelslot_normalloc_morethan_fromtime())?$settingsInfo->getdelslot_normalloc_morethan_fromtime():"00:00";
  956.         $stg_delslot_normalloc_lessthaneq_totime = ($settingsInfo->getdelslot_normalloc_lessthaneq_totime())?$settingsInfo->getdelslot_normalloc_lessthaneq_totime():"18:00";
  957.         $stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays = ($settingsInfo->getdelslot_normalloc_bw_from_to_time_extra_generate_slotdays())?$settingsInfo->getdelslot_normalloc_bw_from_to_time_extra_generate_slotdays():1;
  958.         $stg_delslot_normalloc_after_totime_extra_generate_slotdays = ($settingsInfo->getdelslot_normalloc_after_totime_extra_generate_slotdays())?$settingsInfo->getdelslot_normalloc_after_totime_extra_generate_slotdays():2;
  959.         $stg_normalloc_slot_generate_days = ($stg_delslot_normalloc_after_totime_extra_generate_slotdays>$stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays)?$stg_delslot_normalloc_after_totime_extra_generate_slotdays:$stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays;
  960.         $stg_delslot_upcountryloc_morethan_fromtime = ($settingsInfo->getdelslot_upcountryloc_morethan_fromtime())?$settingsInfo->getdelslot_upcountryloc_morethan_fromtime():"00:00";
  961.         $stg_delslot_upcountryloc_lessthaneq_totime = ($settingsInfo->getdelslot_upcountryloc_lessthaneq_totime())?$settingsInfo->getdelslot_upcountryloc_lessthaneq_totime():"11:00";
  962.         $stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays = ($settingsInfo->getdelslot_upcountryloc_bw_from_to_time_extra_generate_slotdays())?$settingsInfo->getdelslot_upcountryloc_bw_from_to_time_extra_generate_slotdays():4;
  963.         $stg_delslot_upcountryloc_after_totime_extra_generate_slotdays = ($settingsInfo->getdelslot_upcountryloc_after_totime_extra_generate_slotdays())?$settingsInfo->getdelslot_upcountryloc_after_totime_extra_generate_slotdays():5;
  964.         $stg_upcountryloc_slot_generate_days = ($stg_delslot_upcountryloc_after_totime_extra_generate_slotdays>$stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays)?$stg_delslot_upcountryloc_after_totime_extra_generate_slotdays:$stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays;
  965.         $stg_is_deliveryfee_config_applicable $settingsInfo->getis_deliveryfee_config_applicable();
  966.         $stg_deliveryfee_config $settingsInfo->getdeliveryfee_config();
  967.         $stg_deliveryfee_config $settingsInfo->getdeliveryfee_config();
  968.         $stg_deliveryfee_config_location_lessthan_charge $settingsInfo->getdeliveryfee_config_location_lessthan_charge();
  969.         $stg_deliveryfee_config_location_greaterthanequal_charge $settingsInfo->getdeliveryfee_config_location_greaterthanequal_charge();
  970.         $stg_deliveryfee_config_upcountry_lessthan_charge $settingsInfo->getdeliveryfee_config_upcountry_lessthan_charge();
  971.         $stg_deliveryfee_config_upcountry_greaterthanequal_charge $settingsInfo->getdeliveryfee_config_upcountry_greaterthanequal_charge();
  972.         /*----------- End of Settings Info -------------*/
  973.         $settingsdata = ['settingDataId'=>$settingDataId,
  974.                         'setting_deliveryModes'=>$setting_deliveryModes,
  975.                         'setting_slot_time_flag'=>$setting_slot_time_flag,
  976.                         'stg_deliveryslot_config_is_upcountry_configuration_applicable'=>$stg_deliveryslot_config_is_upcountry_configuration_applicable,
  977.                         'stg_delslot_normalloc_morethan_fromtime'=>$stg_delslot_normalloc_morethan_fromtime,
  978.                         'stg_delslot_normalloc_lessthaneq_totime'=>$stg_delslot_normalloc_lessthaneq_totime,
  979.                         'stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays'=>$stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays,
  980.                         'stg_delslot_normalloc_after_totime_extra_generate_slotdays'=>$stg_delslot_normalloc_after_totime_extra_generate_slotdays,
  981.                         'stg_normalloc_slot_generate_days'=>$stg_normalloc_slot_generate_days,
  982.                         'stg_delslot_upcountryloc_morethan_fromtime'=>$stg_delslot_upcountryloc_morethan_fromtime,
  983.                         'stg_delslot_upcountryloc_lessthaneq_totime'=>$stg_delslot_upcountryloc_lessthaneq_totime,
  984.                         'stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays'=>$stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays,
  985.                         'stg_delslot_upcountryloc_after_totime_extra_generate_slotdays'=>$stg_delslot_upcountryloc_after_totime_extra_generate_slotdays,
  986.                         'stg_upcountryloc_slot_generate_days'=>$stg_upcountryloc_slot_generate_days,
  987.                         'stg_is_deliveryfee_config_applicable'=>$stg_is_deliveryfee_config_applicable,
  988.                         'stg_deliveryfee_config'=>$stg_deliveryfee_config,
  989.                         'stg_deliveryfee_config_location_lessthan_charge'=>$stg_deliveryfee_config_location_lessthan_charge,
  990.                         'stg_deliveryfee_config_location_greaterthanequal_charge'=>$stg_deliveryfee_config_location_greaterthanequal_charge,
  991.                         'stg_deliveryfee_config_upcountry_lessthan_charge'=>$stg_deliveryfee_config_upcountry_lessthan_charge,
  992.                         'stg_deliveryfee_config_upcountry_greaterthanequal_charge'=>$stg_deliveryfee_config_upcountry_greaterthanequal_charge,
  993.                         ];
  994.         return $settingsdata;
  995.     }
  996.     /**
  997.      * @Route("/deliveryslots/saveslots")
  998.      */
  999.     public function saveslotsAction()
  1000.     {
  1001.         /*--------------- Settings info ----------------*/
  1002.         $settingsInfo SELF::getSettingInfo();
  1003.         /*----------- End of Settings Info -------------*/
  1004.         // echo 'settingsInfo:<pre>';
  1005.         // echo $settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'];
  1006.         // print_r($settingsInfo); die;
  1007.         $locationsList DataObject\Locations::getList();
  1008.         $locationsList->load();
  1009.         foreach($locationsList as $location)//Start of Locations Loop
  1010.         {
  1011.             //echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
  1012.             $location_id $location->getId();
  1013.             $locationName $location->getLocation_name();
  1014.             $locationCode $location->getLocation_code();
  1015.             /*------ Check Location is Up Country or not --------*/
  1016.             $Is_location_up_country = (strpos(strtolower($locationName),"up country") || strpos(strtoupper($locationCode),"UPCTR"))?1:0;
  1017.             $holidaysList DataObject\Holidays::getList();
  1018.             $holidaysList->setCondition("location_code like '%,".$location_id.",%'");
  1019.             $holidaysList->load();
  1020.             // if(count($holidaysList) > 0)
  1021.             // {
  1022.                 $holidayDates = [];
  1023.                 foreach($holidaysList as $holiday)
  1024.                 {
  1025.                     $holiday_locations_list $holiday->getLocation_code();
  1026.                     $holidaydate $holiday->getHolidaydate();
  1027.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  1028.                     array_push($holidayDates,$holidayDate);
  1029.                 }
  1030.                 // echo '<pre>'; print_r($holidayDates);
  1031.                 /*----------- Delivery Slot Times Loop Starts --------*/
  1032.                 $deliveryslottimesList DataObject\Deliveryslottimes::getList();
  1033.                 $deliveryslottimesList->load();
  1034.                 //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  1035.                 if(count($deliveryslottimesList)>0)
  1036.                 {
  1037.                     foreach($deliveryslottimesList as $deliveryslottimes)
  1038.                     {
  1039.                         // echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
  1040.                         $slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
  1041.                         $slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
  1042.                         $saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
  1043.                         $sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
  1044.                         $slot_generate_days $slot_generate_days+$settingsInfo['stg_normalloc_slot_generate_days']; 
  1045.                         /*--------------------- Up Country Configuration ------------------------*/
  1046.                         $is_upcountry_configuration_applicable = ($deliveryslottimes->getis_upcountry_configuration_applicable())?$deliveryslottimes->getis_upcountry_configuration_applicable():'No';
  1047.                         $slot_upcountry_prepare_days = ($deliveryslottimes->getupcountry_prepare_days())?$deliveryslottimes->getupcountry_prepare_days():0;
  1048.                         $upcountry_slot_generate_days = ($deliveryslottimes->getupcountry_slot_generate_days())?$deliveryslottimes->getupcountry_slot_generate_days():7;
  1049.                         $upcountry_saturday_slot_availability = ($deliveryslottimes->getupcountry_saturday_slot_availability())?$deliveryslottimes->getupcountry_saturday_slot_availability():'No';
  1050.                         $upcountry_sunday_slot_availability = ($deliveryslottimes->getupcountry_sunday_slot_availability())?$deliveryslottimes->getupcountry_sunday_slot_availability():'No';
  1051.                         $upcountry_slot_generate_days $upcountry_slot_generate_days+$settingsInfo['stg_upcountryloc_slot_generate_days']; 
  1052.                         if($settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'] == 'Yes' && $Is_location_up_country == 1)//if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
  1053.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_upcountry_prepare_days,'slot_generate_days'=>$upcountry_slot_generate_days,'saturday_slot_availability'=>$upcountry_saturday_slot_availability,'sunday_slot_availability'=>$upcountry_sunday_slot_availability];
  1054.                         else
  1055.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  1056.                         // echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
  1057.                         $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  1058.                         // echo '<pre>weekdates:'; print_r($weekdates);
  1059.                         foreach($weekdates as $weekdate)
  1060.                         {
  1061.                             $slotsList DataObject\Deliveryslotrules::getList();
  1062.                             // $slotsList->setCondition("location_code like '%,".$location_id.",%'");
  1063.                             $slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
  1064.                             $slotsList->load();
  1065.                             //echo '<br>slotsList Count:'.count($slotsList);
  1066.                             if(count($slotsList) > 0)
  1067.                             {
  1068.                                 foreach($slotsList as $slot)
  1069.                                 {
  1070.                                     $prior_time $slot->getprior_time();
  1071.                                     $location_codes $slot->getlocation_ids();//$slot->getlocation_code();
  1072.                                     // $picking_time = $slot->getpicking_time();
  1073.                                     $delivery_mode $slot->getdelivery_mode();
  1074.                                     // $charge = $slot->getcharge();
  1075.                                     $fromtime $slot->getfromtime();
  1076.                                     $totime $slot->gettotime();
  1077.                                     $maxorder $slot->getmaxorder();
  1078.                                     // $ordercount = $slot->getordercount();
  1079.                                     $date $weekdate;//$slot->getslotdate();
  1080.                                     $date2 date("m/d/y"strtotime($date));
  1081.                                     $dates Carbon::createFromFormat('m/d/y'$date2);
  1082.                                     $location_code_array = [];
  1083.                                     // echo '<pre>location_codes Count:'.count($location_codes);
  1084.                                     if(!empty($location_codes))
  1085.                                     {
  1086.                                         foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
  1087.                                             if($location_id == $location_id_info)//if($location_id == $location_code->getId())
  1088.                                             {
  1089.                                                 // $location_code_array[] = DataObject\Locations::getById($location_code->getId());
  1090.                                                 // $location_code_id = DataObject\Locations::getById($location_code->getId());
  1091.     
  1092.                                                 // $loc_id = $location_code->getId();
  1093.     
  1094.                                                 $location_code_array[] = DataObject\Locations::getById($location_id_info);
  1095.                                                 $location_code_id DataObject\Locations::getById($location_id_info);
  1096.     
  1097.                                                 $loc_id $location_id_info;
  1098.     
  1099.                                                 /*----------- Delivery Slot Times Loop Starts --------*/
  1100.                                                 // $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
  1101.                                                 // $deliveryslottimesList->load();
  1102.                                                 // //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
  1103.                                                 // if(count($deliveryslottimesList)>0)
  1104.                                                 // {
  1105.                                                 //     foreach($deliveryslottimesList as $deliveryslottimes)
  1106.                                                 //     {
  1107.                                                         /*------------ Checking the slot data -------------*/
  1108.                                                         $slotCheck 1;
  1109.                                                         $today_date date("Y-m-d"strtotime($weekdate));
  1110.                                                         $cur_time $prior_time;
  1111.     
  1112.                                                         $checkDataList DataObject\Slots::getList();
  1113.     
  1114.                                                         if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  1115.                                                             $checkDataList->filterBySlotdate($today_date'=');
  1116.                                                         }
  1117.     
  1118.                                                         if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  1119.                                                             $checkDataList->filterByprior_time($cur_time'=');
  1120.                                                         }
  1121.     
  1122.                                                         if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  1123.                                                             $checkDataList->filterBydelivery_mode($delivery_mode'=');
  1124.                                                         }
  1125.                                                         // $checkDataList->setCondition("loc_id__id = ".$loc_id);
  1126.                                                         // $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
  1127.     
  1128.                                                         $checkDataList->setLimit(100);
  1129.                                                         $checkDataList->setOrderKey("slotdate");
  1130.                                                         $checkDataList->setOrder("asc");
  1131.                                                         $checkDataList->load();
  1132.                                                         //echo '<br>checkDataList Count:'.count($checkDataList);
  1133.     
  1134.                                                         $checkData_loc_valid 0$checkData_locs = [];
  1135.                                                         if(count($checkDataList) > 0)
  1136.                                                         {
  1137.                                                             foreach($checkDataList as $checkData)
  1138.                                                             {
  1139.                                                                 // $checkData_locData = $checkData->getloc_id();
  1140.                                                                 // $checkData_locId = $checkData_locData->getId();
  1141.                                                                 $checkData_locId $checkData->getloc_id();
  1142.                                                                 array_push($checkData_locs$checkData_locId);
  1143.                                                             }
  1144.                                                         }
  1145.                                                         $checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id$checkData_locs)) || count($checkDataList) <= 0)?1:0;
  1146.     
  1147.                                                         // echo '<br>checkData_locId:'.$checkData_locId;
  1148.                                                         // echo '<pre>checkData_locs:';
  1149.                                                         // print_r($checkData_locs);
  1150.                                                         // echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
  1151.                                                         /*------------ End of Checking the slot data -------------*/
  1152.     
  1153.                                                         if($checkData_loc_valid == 1){
  1154.                                                             // $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
  1155.     
  1156.                                                             $createAssetFolder DoService::createFolderByPath('Slots');
  1157.                                                             $objParentId $createAssetFolder->getId();
  1158.     
  1159.                                                             // $holidayObjectName = $location_code.'-'.$name;
  1160.                                                             $slotObjectName $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
  1161.     
  1162.                                                             $slotObject = new DataObject\Slots(); 
  1163.                                                             $slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName'object'));
  1164.                                                             $slotObject->setParentId($objParentId);
  1165.                                                             $slotObject->setPrior_time($prior_time);
  1166.                                                             // $slotObject->setPicking_time($picking_time);
  1167.                                                             $slotObject->setDelivery_mode($delivery_mode);
  1168.                                                             // $slotObject->setSlotdate($date2);
  1169.                                                             $slotObject->setSlotdate($dates);
  1170.                                                             $slotObject->setfromtime($fromtime);
  1171.                                                             $slotObject->settotime($totime);
  1172.                                                             $slotObject->setmaxorder($maxorder);
  1173.     
  1174.                                                             // $slotObject->setLocation_code($location_code_array);
  1175.     
  1176.                                                             // $slotObject->setCharge($charge);
  1177.                                                             $slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
  1178.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
  1179.                                                             // $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
  1180.                                                             $slotObject->setloc_id($location_id_info);
  1181.     
  1182.                                                             $slotObject->setPublished(true);
  1183.                                                             $slotObject->save();
  1184.                                                         }
  1185.                                                 //     }
  1186.                                                 // }
  1187.                                             }
  1188.                                             /*---------- Delivery Slot Time loop ends ------------*/
  1189.                                         }//Location Code loop ends
  1190.                                     }
  1191.                                 }
  1192.                             }
  1193.                         }
  1194.                     }
  1195.                 }
  1196.             // }
  1197.         }//End of Locations Loop
  1198.         return $this->json(["success" => true"data" => 'Slot Created for one week Successfully']);
  1199.     }
  1200.     /**
  1201.      * @Route("deliveryslots/updateslotordercount", methods={"POST"})
  1202.      */
  1203.     public function updateslotordercountAction(Request $request)
  1204.     {
  1205.         $slotId $request->get('slotId');
  1206.         $ordercount $request->get('ordercount');
  1207.         if($slotId == "" || $ordercount == "")
  1208.         {
  1209.             $message "slotId and ordercount are mandatory!";
  1210.         } else 
  1211.         {
  1212.             $slotruleObject DataObject\Slots::getById($slotId);
  1213.             if(!empty($slotruleObject) && $slotruleObject->getId()){
  1214.                 $slotruleObject->setordercount($ordercount);
  1215.                 $slotruleObject->save();
  1216.                 $message "Slot Updated Successfully!";
  1217.             } else {
  1218.                 $message "This Slot Id ".$slotId." is not existed, Please try with valid Slot Id";
  1219.             }
  1220.         }
  1221.         return $this->json(["success" => true"data" => $message]);
  1222.     }
  1223.     /**
  1224.      * @Route("/deliveryslots/getSlot1/{id}")
  1225.      */
  1226.     public function getSlot1($id)
  1227.     {
  1228.         $slot DataObject\Slots::getById($id);
  1229.         if(isset($slot) && $slot->getId() != ''){
  1230.             // $location_codes = $slot->getlocation_code();
  1231.             $loc_code = (!empty($slot->getloc_id()) && $slot->getloc_id())?$slot->getloc_id()->getlocation_code():'';
  1232.             $loc_name = (!empty($slot->getloc_id()) && $slot->getloc_id())?$slot->getloc_id()->getlocation_name():'';
  1233.             // foreach($location_codes as $location_code){
  1234.             //     $loc_name = $location_code->getlocation_name();
  1235.             // }
  1236.                 $data = array(
  1237.                     "prior_time" => $slot->getprior_time(),
  1238.                     "picking_time" => $slot->getpicking_time(),
  1239.                     "charge" => $slot->getcharge(),
  1240.                     "slotdate" => $slot->getslotdate(),
  1241.                     "loc_code" => $loc_code,
  1242.                     "loc_name" => $loc_name,
  1243.                     "fromtime" => $slot->getfromtime(),
  1244.                     "totime" => $slot->gettotime(),
  1245.                     "maxorder" => $slot->getmaxorder(),
  1246.                     "ordercount" => $slot->getordercount(),
  1247.                     "delivery_mode" => $slot->getdelivery_mode());
  1248.         } else {
  1249.             $data "No data found";
  1250.         }            
  1251.         
  1252.         // return $slotsList;
  1253.         return $this->json(["success" => true"data" => $data]);
  1254.     }
  1255.     /**
  1256.      * @Route("/deliveryslots/getSlot/{id}")
  1257.      */
  1258.     public function getSlot($id)
  1259.     {
  1260.         $slot DataObject\Slots::getById($id);
  1261.         if(isset($slot) && $slot->getId() != ''){
  1262.             
  1263.             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  1264.             $loc_name = (!empty($slotLocationData) && $slotLocationData->getlocation_name())?$slotLocationData->getlocation_name():'';
  1265.             $loc_code = (!empty($slotLocationData) && $slotLocationData->getlocation_code())?$slotLocationData->getlocation_code():'';
  1266.             $data = array(
  1267.                 "prior_time" => $slot->getprior_time(),
  1268.                 // "picking_time" => $slot->getpicking_time(),
  1269.                 // "charge" => $slot->getcharge(),
  1270.                 "slotdate" => date("Y-m-d"strtotime($slot->getslotdate())),//$slot->getslotdate(),
  1271.                 "loc_code" => $loc_code,
  1272.                 "loc_name" => $loc_name,
  1273.                 "fromtime" => $slot->getfromtime(),
  1274.                 "totime" => $slot->gettotime(),
  1275.                 "maxorder" => $slot->getmaxorder(),
  1276.                 "ordercount" => $slot->getordercount(),
  1277.                 "delivery_mode" => $slot->getdelivery_mode());
  1278.         } else {
  1279.             $data "No data found";
  1280.         }            
  1281.         
  1282.         // return $slotsList;
  1283.         return $this->json(["success" => true"data" => $data]);
  1284.     }
  1285.     /**
  1286.      * @Route("/deliveryslots/getStoreslot/{id}")
  1287.      */
  1288.     public function getStoreslot($id)
  1289.     {
  1290.         $data ="No data found";
  1291.         if($id == "")
  1292.         {
  1293.             $data ="Location Code is mandatory!";
  1294.         } else 
  1295.         {
  1296.             /*---- Check Location by Location Code ---------*/
  1297.             $locData DataObject\Locations::getBylocation_code($id1);
  1298.             if(empty($locData) || empty($locData->getId()))
  1299.             {
  1300.                 $data "Location is not exited, please try with valid location code!";
  1301.             } else {
  1302.                 $loc_id $locData->getId();
  1303.                 $today_date date("Y-m-d");
  1304.                 $cur_time date("H:i");
  1305.                 $slotsList DataObject\Slots::getList();
  1306.                 if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  1307.                     $slotsList->filterBySlotdate($today_date'=');
  1308.                 }
  1309.                 if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  1310.                     $slotsList->filterByprior_time($cur_time'>=');
  1311.                 }
  1312.                 $slotsList->setCondition("loc_id__id = ".$loc_id);
  1313.                 $slotsList->setLimit(100);
  1314.                 $slotsList->setOrderKey("slotdate");
  1315.                 $slotsList->setOrder("asc");
  1316.                 $slotsList->load();
  1317.                 $data = [];
  1318.                 if(count($slotsList) > 0){
  1319.                     foreach ($slotsList as $key => $blog) {
  1320.                         $location_codes $blog->getlocation_code();
  1321.                         $loc_name ''$loc_id 0$loc_names = []; $loc_codes = [];
  1322.             
  1323.                         foreach($location_codes as $location_code){
  1324.                             $loc_name $location_code->getlocation_name();
  1325.                             $loc_code $location_code->getlocation_code();
  1326.                             $loc_id $location_code->getId();
  1327.                             array_push($loc_names,$loc_name);
  1328.                             array_push($loc_codes,$loc_code);
  1329.                         }
  1330.             
  1331.                         // if($loc_name != 0 && $loc_name == $id){
  1332.                         // if(!empty($loc_codes) && in_array($id, $loc_codes)){//&& $id!= '' 
  1333.                             // if(!empty($blog->getloc_id()) && $blog->getloc_id()->getlocation_code() == $id){//&& $id!= '' 
  1334.                             $data[] = array(
  1335.                                 "slotId" => $blog->getId(),
  1336.                                 "prior_time" => $blog->getprior_time(),
  1337.                                 "picking_time" => $blog->getpicking_time(),
  1338.                                 "location_code" => $blog->getloc_id()->getlocation_code(),
  1339.                                 "loc_name" => $blog->getloc_id()->getlocation_name(),//$loc_name,
  1340.                                 "charge" => $blog->getcharge(),
  1341.                                 "slotdate" => $blog->getslotdate(),
  1342.                                 "fromtime" => $blog->getfromtime(),
  1343.                                 "totime" => $blog->gettotime(),
  1344.                                 "maxorder" => $blog->getmaxorder(),
  1345.                                 "ordercount" => $blog->getordercount(),
  1346.                                 "delivery_mode" => $blog->getdelivery_mode());
  1347.                         //}
  1348.                     }
  1349.                 } else $data "No data found";
  1350.             }
  1351.         }
  1352.         
  1353.         return $this->json(["success" => true"data" => $data]);
  1354.     }
  1355.     /**
  1356.      * @Route("personalitystatement/getperstmtlist", methods={"POST"})
  1357.      */
  1358.     public function getperstmtlistAction(Request $request)
  1359.     {
  1360.         $message SELF::verifyauthToken();
  1361.         // $data[] = ['message'=>$message];
  1362.         if($message == "No data found")
  1363.         {
  1364.             $reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
  1365.             // print_r($reqparams); die;
  1366.             // print_r($request->get->all());
  1367.             $title = (isset($reqparams['title']))?$reqparams['title']:'';
  1368.             $gender = (isset($reqparams['gender']))?$reqparams['gender']:'';
  1369.             $standout_fitin = (isset($reqparams['standout_fitin']))?$reqparams['standout_fitin']:'';
  1370.             $describe_yourself = (isset($reqparams['describe_yourself']))?$reqparams['describe_yourself']:'';
  1371.             $occasion = (isset($reqparams['occasion']))?$reqparams['occasion']:'';
  1372.             $priceband = (isset($reqparams['priceband']))?$reqparams['priceband']:'';
  1373.             $blank1 = (isset($reqparams['blank1']))?$reqparams['blank1']:'';
  1374.             $blank2 = (isset($reqparams['blank2']))?$reqparams['blank2']:'';
  1375.             $perstmtList DataObject\Personalitystatements::getList();
  1376.             if($title)
  1377.             $perstmtList->setCondition("personality_statement = ?",[$title]);
  1378.             if($blank1)
  1379.             $perstmtList->setCondition("blank1 = ?",[$blank1]);
  1380.             if($blank2)
  1381.             $perstmtList->setCondition("blank2 = ?",[$blank2]);
  1382.             if($priceband)
  1383.             $perstmtList->setCondition("priceband = ?",[$priceband]);
  1384.             $perstmtList->load();
  1385.             foreach ($perstmtList as $key => $perstmtObj) {
  1386.                 $data_disp 0$gender_chk 0$standout_fitin_chk =0$describe_yourself_chk 0$occasion_chk 0;
  1387.                 if(($gender && !empty($perstmtObj->getstandout_fitin()) && in_array($gender$perstmtObj->getstandout_fitin())) || $gender == ''){
  1388.                     $gender_chk 1;
  1389.                 }
  1390.                 if(($standout_fitin && !empty($perstmtObj->getstandout_fitin()) && in_array($standout_fitin$perstmtObj->getstandout_fitin())) || $standout_fitin == ''){
  1391.                     $standout_fitin_chk 1;
  1392.                 }
  1393.                 if(($describe_yourself && !empty($perstmtObj->getdescribe_yourself()) && in_array($describe_yourself$perstmtObj->getdescribe_yourself())) || $describe_yourself == ''){
  1394.                     $describe_yourself_chk 1;
  1395.                 }
  1396.                 if(($occasion && !empty($perstmtObj->getoccasion()) && in_array($occasion$perstmtObj->getoccasion())) || $occasion == ''){
  1397.                     $occasion_chk 1;
  1398.                 }
  1399.                 if($gender_chk == && $standout_fitin_chk == && $describe_yourself_chk == && $occasion_chk == 1){
  1400.                     $data[] = array(
  1401.                         "id" => $perstmtObj->getId(),
  1402.                         "personality_statement" => $perstmtObj->getpersonality_statement(),
  1403.                         "standout_fitin" => $perstmtObj->getstandout_fitin(),
  1404.                         "describe_yourself" => $perstmtObj->getdescribe_yourself(),
  1405.                         "occasion" => $perstmtObj->getoccasion(),
  1406.                         "priceband" => $perstmtObj->getpriceband(),
  1407.                         "blank2" => $perstmtObj->getblank2(),
  1408.                         "blank1" => $perstmtObj->getblank1());
  1409.                 } else $data[] = ['message'=>$message];
  1410.             }
  1411.         } else $data[] = ['message'=>$message];
  1412.         // return $slotsList;
  1413.         return $this->json(["success" => true"data" => $data]);
  1414.     }
  1415.     /**
  1416.      * @Route("/factory/getfactories")
  1417.      */
  1418.     public function getfactories()
  1419.     {
  1420.         $message SELF::verifyauthToken();
  1421.         if($message == "No data found")
  1422.         {
  1423.             $factoriesList DataObject\Factories::getList();
  1424.             $factoriesList->load();
  1425.             if(count($factoriesList) > 0){
  1426.                 foreach ($factoriesList as $key => $blog) {
  1427.                     $bestbefore_date '';
  1428.                     if($blog->getbestbefore()){
  1429.                         $bestbefore_dt date("m/d/y"strtotime($blog->getbestbefore()));
  1430.                         $bestbefore_date Carbon::createFromFormat('m/d/y'$bestbefore_dt);
  1431.                     }
  1432.                     $data[] = array(
  1433.                         "code" => $blog->getcode(),
  1434.                         "name" => $blog->getname(),
  1435.                         "address" => $blog->getaddress(),
  1436.                         "street" => $blog->getstreet(),
  1437.                         "landmark" => $blog->getlandmark(),
  1438.                         "city" => $blog->getcity(),
  1439.                         "state" => $blog->getstate(),
  1440.                         "country" => $blog->getcountry(),
  1441.                         "pincode" => $blog->getpincode(),
  1442.                         "bestbefore" => $bestbefore_date);
  1443.                 }
  1444.             } else $data[] = ['message'=>$message];
  1445.         } else $data[] = ['message'=>$message];
  1446.         
  1447.         return $this->json(["success" => true"data" => $data]);
  1448.     }
  1449.     /**
  1450.      * @Route("/deliveryslottime/getslottimes")
  1451.      */
  1452.     public function getslottimesAction()
  1453.     {
  1454.         $delSlotTimesList DataObject\Deliveryslottimes::getList();
  1455.         $delSlotTimesList->load();
  1456.         if(count($delSlotTimesList) > 0){
  1457.             foreach($delSlotTimesList as $delSlotTimes)
  1458.             {
  1459.                 $prepare_days $delSlotTimes->getprepare_days();
  1460.                 $delSlot_date date('Y-m-d H:i:s'strtotime(' +'.$prepare_days.' day'));
  1461.                 $data[] = array(
  1462.                     "title" => $delSlotTimes->gettitle(),
  1463.                     "deliverytype_id" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  1464.                     "prepare_days" => $delSlotTimes->getprepare_days(),
  1465.                     "delSlot_date" => $delSlot_date);
  1466.             }
  1467.         } else $data "No data found";
  1468.         return $this->json(["success" => true"data" => $data]);
  1469.     }
  1470.     /**
  1471.      * @Route("/deliveryslottime/getslottimeslist")
  1472.      */
  1473.     public function getslottimeslistAction()
  1474.     {
  1475.         $delSlotTimesList DataObject\Deliveryslottimes::getList();
  1476.         $delSlotTimesList->load();
  1477.         // $delivery_modes = ['courier','standard','express'];
  1478.         // $slotsList = DataObject\Slots::getList();
  1479.         // $slotsList->setCondition("delivery_mode = 'courier'");
  1480.         // // if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  1481.         // //     $slotsList->filterBydelivery_mode($courier_mode, '=');
  1482.         // // }
  1483.         // $slotsList->load();
  1484.         // echo '<pre>kk'; print_r($slotsList); die;
  1485.         if(count($delSlotTimesList) > 0){
  1486.             foreach($delSlotTimesList as $delSlotTimes)
  1487.             {
  1488.                 $prepare_days $delSlotTimes->getprepare_days();
  1489.                 $delSlot_date date('Y-m-d H:i:s'strtotime(' +'.$prepare_days.' day'));
  1490.                 $delSlot_date1 date("Y-m-d"strtotime($delSlot_date));
  1491.                 $cur_time date("H:i");
  1492.                 // $delSlotTimes->delSlot_date = $delSlot_date;
  1493.                 $delivery_modes = ['courier','standard','express'];
  1494.                 $delivery_mode_slots_all = [];
  1495.                 foreach($delivery_modes as $delivery_mode)
  1496.                 {
  1497.                     $slotsList DataObject\Slots::getList();
  1498.                     // $slotsList->setCondition("delivery_mode = '".$delivery_mode."'");
  1499.                     if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  1500.                         $slotsList->filterBySlotdate($delSlot_date1'=');
  1501.                     }
  1502.                     if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  1503.                         $slotsList->filterByprior_time($cur_time'>=');
  1504.                     }
  1505.                     if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  1506.                         $slotsList->filterBydelivery_mode($delivery_mode'>=');
  1507.                     }
  1508.                     $slotsList->setLimit(100);
  1509.                     $slotsList->setOrderKey("slotdate");
  1510.                     $slotsList->setOrder("asc");
  1511.                     $slotsList->load();
  1512.                     /*---------- Slots Loop Starts ----------*/
  1513.                     $delivery_mode_slots = [];
  1514.                     if(count($slotsList) > 0){
  1515.                         foreach($slotsList as $slot)
  1516.                         {
  1517.                             // $loc_name = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_name():'';
  1518.                             // $loc_code = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_code():'';
  1519.                             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  1520.                             $loc_name $slotLocationData->getlocation_name();
  1521.                             $loc_code $slotLocationData->getlocation_code();
  1522.                             $delivery_mode_slot1 = array(
  1523.                                 "slotId" => $slot->getId(),
  1524.                                 "prior_time" => $slot->getprior_time(),
  1525.                                 // "picking_time" => $slot->getpicking_time(),
  1526.                                 // "charge" => $slot->getcharge(),
  1527.                                 "slotdate" => $slot->getslotdate(),
  1528.                                 "loc_name" => $loc_name,
  1529.                                 "loc_code" => $loc_code,
  1530.                                 "fromtime" => $slot->getfromtime(),
  1531.                                 "totime" => $slot->gettotime(),
  1532.                                 "maxorder" => $slot->getmaxorder(),
  1533.                                 "ordercount" => $slot->getordercount(),
  1534.                                 "delivery_mode" => $slot->getdelivery_mode()
  1535.                             );
  1536.                             array_push($delivery_mode_slots$delivery_mode_slot1);
  1537.                         }
  1538.                     }
  1539.                     /*---------- Slots Loop Starts ----------*/
  1540.                     $delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
  1541.                     // array_push($delivery_mode_slots_all, $delivery_mode_slot2);
  1542.                     $delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
  1543.                 }
  1544.                 $data[] = array(
  1545.                     "deliverytype_id" => $delSlotTimes->gettitle(),
  1546.                     "label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  1547.                     "prepare_days" => $delSlotTimes->getprepare_days(),
  1548.                     "delSlot_date" => $delSlot_date,
  1549.                     "slots"=>$delivery_mode_slots_all);
  1550.             }
  1551.         } else $data[] = [];
  1552.         return $this->json(["success" => true"data" => $data]);
  1553.     }
  1554.     public function getSlotTimeDates($slot_generate_days$todaydate){
  1555.         $jj=0$weekdates = [];
  1556.         for($ii=1$ii<15$ii++)
  1557.         {
  1558.             if($jj >= 7) break;
  1559.             if(empty($holidaysList) || !in_array($todaydate$holidaysList)){
  1560.                 $weekdates[] = $todaydate;
  1561.                 $jj=$jj+1;
  1562.             }
  1563.             $todaydate date('Y-m-d'strtotime($todaydate ' +1 day'));
  1564.         }
  1565.         // echo '<pre>'; print_r($weekdates); die;
  1566.         return $weekdates;
  1567.     }
  1568.     public function getWorkingDate($slot_generate_days$todaydate){
  1569.         $jj=0$weekdates = [];
  1570.         for($ii=1$ii<$slot_generate_days$ii++)
  1571.         {
  1572.             if(empty($holidaysList) || !in_array($todaydate$holidaysList)){
  1573.                 $weekdates[] = $todaydate;
  1574.                 $jj=$jj+1;
  1575.             }
  1576.             $todaydate date('Y-m-d'strtotime($todaydate ' +1 day'));
  1577.         }
  1578.         // echo '<pre>'; print_r($weekdates); die;
  1579.         return $weekdates;
  1580.     }
  1581.     /**
  1582.      * @Route("/deliveryslottime/gelocslottimes1/{locCode}")
  1583.      */
  1584.     public function gelocslottimes1Action($locCode)
  1585.     {
  1586.         $message SELF::verifyauthToken();
  1587.         if($message == "No data found")
  1588.         {
  1589.             $today_date date("Y-m-d");
  1590.             $tomorrow_date date('Y-m-d'strtotime($today_date ' +1 day'));
  1591.             $dates_list = array($today_date$tomorrow_date);
  1592.             /*---- Check Location by Location Code ---------*/
  1593.             $locationData DataObject\Locations::getBylocation_code($locCode1);
  1594.             /*--------- Getting Delivery Modes settings ----------*/
  1595.             $settingsList DataObject\Settings::getList();
  1596.             $settingsList->setLimit(1);
  1597.             $settingsList->load();
  1598.             $setting_deliveryModes = [];
  1599.             $setting_slot_time_flag "18:00";
  1600.             if(count($settingsList) > 0){
  1601.                 foreach($settingsList as $settingsData)
  1602.                 {
  1603.                     $settingDataId $settingsData->getId();
  1604.                     $setting_deliveryModes $settingsData->getdelivery_modes();
  1605.                     $setting_slot_time_flag = (!empty($settingsData->getslottime()))?$settingsData->getslottime():$setting_slot_time_flag;
  1606.                 }
  1607.             }
  1608.             if(!empty($locationData) && !empty($locationData->getId()))
  1609.             {
  1610.                 $parentLoc_id $locationData->getId();
  1611.                 //------ get holidays list ------------//
  1612.                 $holidaysList DataObject\Holidays::getList();
  1613.                 $holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
  1614.                 $holidaysList->load();
  1615.                 
  1616.                 $holidayDates = [];
  1617.                 foreach($holidaysList as $holiday)
  1618.                 {
  1619.                     $holiday_locations_list $holiday->getLocation_code();
  1620.                     $holidaydate $holiday->getHolidaydate();
  1621.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  1622.                     array_push($holidayDates,$holidayDate);
  1623.                 }
  1624.                 
  1625.                 $delSlotTimesList DataObject\Deliveryslottimes::getList();
  1626.                 $delSlotTimesList->setOrderKey("o_id");
  1627.                 $delSlotTimesList->setOrder("desc");
  1628.                 $delSlotTimesList->load();
  1629.                 
  1630.                 // foreach($dates_list as $cur_date){
  1631.                     
  1632.                     if(count($delSlotTimesList) > 0){
  1633.                         foreach($delSlotTimesList as $delSlotTimes)
  1634.                         {
  1635.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  1636.                             $slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
  1637.                             $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
  1638.                             $saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
  1639.                             $sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
  1640.                             $cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  1641.                             $cur_time date("H:i");//"09:00";//
  1642.                             $slot_generate_days = ($cur_time $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
  1643.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  1644.                             
  1645.                             $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  1646.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  1647.                             $prepare_days $delSlotTimes->getprepare_days();
  1648.                             $delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d'strtotime($today_date ' +'.$prepare_days.' day'));
  1649.                             $delSlot_date1 date("Y-m-d"strtotime($delSlot_date));
  1650.                             
  1651.                             $cur_time_data explode(" ",$cur_time);
  1652.                             $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  1653.                             $slot_generate_days_limit = ($slot_generate_days 0)?$slot_generate_days:1;
  1654.                             // echo $tomorrow_date.":".$weekdates[0];
  1655.                             if($cur_time $setting_slot_time_flag)//if($cur_time > '18:00')
  1656.                             {
  1657.                                 if($tomorrow_date >= $weekdates[0])
  1658.                                 {
  1659.                                     $weekdates = ($slot_generate_days 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  1660.                                 } else {
  1661.                                     $no_of_weekdates count($weekdates);
  1662.                                     $weekdates = ($slot_generate_days 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
  1663.                                 }
  1664.                                 
  1665.                                 // $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  1666.                             } else {
  1667.                                 $weekdates = ($slot_generate_days 0)?$weekdates:[$weekdates[0]];
  1668.                             }
  1669.                             // echo 'weekdates:<pre>:'; print_r($weekdates);
  1670.                             
  1671.                             $slot_generate_days_date  date('Y-m-d'strtotime($today_date ' +'.$slot_generate_days.' day'));
  1672.                             $delivery_modes $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
  1673.                             $delivery_mode_slots_all = [];
  1674.                             foreach($delivery_modes as $delivery_mode)
  1675.                             {
  1676.                                 if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
  1677.                                 {
  1678.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  1679.                                 } else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
  1680.                                 {
  1681.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  1682.                                 } else {
  1683.                                     $slotsList DataObject\Slots::getList();
  1684.                                     if($cur_time $setting_slot_time_flag)//if($cur_time > '18:00')
  1685.                                     {
  1686.                                         $slotsList->setCondition("slotdate >= :tomdate AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1687.                                     } else {
  1688.                                         if($delivery_mode == 'standard')
  1689.                                         {
  1690.                                             $slotsList->setCondition("((slotdate = :slotdate AND fromtime <= :prior_time AND totime >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1691.                                         } else
  1692.                                         {
  1693.                                             $slotsList->setCondition("((slotdate = :slotdate AND prior_time >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1694.                                         }
  1695.                                     }
  1696.                                     $slotsList->setOrderKey("slotdate");
  1697.                                     $slotsList->setOrder("asc");
  1698.                                     $slotsList->load();
  1699.                                     // if($slot_generate_days == 3)
  1700.                                     // {
  1701.                                     //     echo '<pre>';
  1702.                                     //     print_r($slotsList); die;
  1703.                                     // }
  1704.                                     /*---------- Slots Loop Starts ----------*/
  1705.                                     $delivery_mode_slots = [];
  1706.                                     if(count($slotsList) > && $cur_slot_generate_days>0){
  1707.                                         foreach($slotsList as $slot)
  1708.                                         {
  1709.                                             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  1710.                                             $loc_name $slotLocationData->getlocation_name();
  1711.                                             $delivery_mode_slot1 = array(
  1712.                                                 "slotId" => $slot->getId(),
  1713.                                                 "prior_time" => $slot->getprior_time(),
  1714.                                                 "slotdate" => date("Y-m-d"strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
  1715.                                                 "loc_name" => $loc_name,
  1716.                                                 "fromtime" => $slot->getfromtime(),
  1717.                                                 "totime" => $slot->gettotime(),
  1718.                                                 "maxorder" => $slot->getmaxorder(),
  1719.                                                 "ordercount" => $slot->getordercount(),
  1720.                                                 "delivery_mode" => $slot->getdelivery_mode(),
  1721.                                             );
  1722.                                             array_push($delivery_mode_slots$delivery_mode_slot1);
  1723.                                         }
  1724.                                     }
  1725.                                     /*---------- Slots Loop Starts ----------*/
  1726.                                     $delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
  1727.                                     // array_push($delivery_mode_slots_all, $delivery_mode_slot2);
  1728.                                     $delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
  1729.                                 }
  1730.                             }
  1731.                             $data[] = array(
  1732.                                 "deliverytype_id" => $delSlotTimes->gettitle(),
  1733.                                 "label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  1734.                                 "prepare_days" => $delSlotTimes->getprepare_days(),
  1735.                                 "slot_generate_days" => $slot_generate_days,
  1736.                                 "delSlot_date" => $delSlot_date1,
  1737.                                 "slots"=>$delivery_mode_slots_all);
  1738.                         }
  1739.                     } else $data[] = ['message'=>$message];
  1740.                 // }
  1741.             } else $data[] = ['message'=>$message];
  1742.             
  1743.         } else $data[] = ['message'=>$message];
  1744.         return $this->json(["success" => true"data" => $data]);
  1745.     }
  1746.     /**
  1747.      * @Route("/deliveryslottime/gelocslottimes2/{locCode}")
  1748.      */
  1749.     public function gelocslottimes2Action($locCode)
  1750.     {
  1751.         $message SELF::verifyauthToken();
  1752.         $Is_location_up_country $is_upcountry_configuration_applicable '';
  1753.         if($message == "No data found")
  1754.         {
  1755.             $today_date date("Y-m-d");
  1756.             $tomorrow_date date('Y-m-d'strtotime($today_date ' +1 day'));
  1757.             $dates_list = array($today_date$tomorrow_date);
  1758.             /*---- Check Location by Location Code ---------*/
  1759.             $locationData DataObject\Locations::getBylocation_code($locCode1);
  1760.             /*--------- Getting Delivery Modes settings ----------*/
  1761.             $settingsList DataObject\Settings::getList();
  1762.             $settingsList->setLimit(1);
  1763.             $settingsList->load();
  1764.             $setting_deliveryModes = [];
  1765.             $setting_slot_time_flag "18:00";
  1766.             if(count($settingsList) > 0){
  1767.                 foreach($settingsList as $settingsData)
  1768.                 {
  1769.                     $settingDataId $settingsData->getId();
  1770.                     $setting_deliveryModes $settingsData->getdelivery_modes();
  1771.                     $setting_slot_time_flag = (!empty($settingsData->getslottime()))?$settingsData->getslottime():$setting_slot_time_flag;
  1772.                 }
  1773.             }
  1774.             if(!empty($locationData) && !empty($locationData->getId()))
  1775.             {
  1776.                 $parentLoc_id $locationData->getId();
  1777.                 $parentLocationName $locationData->getLocation_name();
  1778.                 $parentLocationCode $locationData->getLocation_code();
  1779.     
  1780.                 /*------ Check Location is Up Country or not --------*/
  1781.                 $Is_location_up_country = (strpos(strtolower($parentLocationName),"up country") || strpos(strtoupper($parentLocationCode),"UPCTR"))?1:0;
  1782.                 //------ get holidays list ------------//
  1783.                 $holidaysList DataObject\Holidays::getList();
  1784.                 $holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
  1785.                 $holidaysList->load();
  1786.                 
  1787.                 $holidayDates = [];
  1788.                 foreach($holidaysList as $holiday)
  1789.                 {
  1790.                     $holiday_locations_list $holiday->getLocation_code();
  1791.                     $holidaydate $holiday->getHolidaydate();
  1792.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  1793.                     array_push($holidayDates,$holidayDate);
  1794.                 }
  1795.                 
  1796.                 $delSlotTimesList DataObject\Deliveryslottimes::getList();
  1797.                 $delSlotTimesList->setOrderKey("o_id");
  1798.                 $delSlotTimesList->setOrder("desc");
  1799.                 $delSlotTimesList->load();
  1800.                 
  1801.                 // foreach($dates_list as $cur_date){
  1802.                     
  1803.                     if(count($delSlotTimesList) > 0){
  1804.                         $cur_time date("H:i");//"09:00";//
  1805.                         foreach($delSlotTimesList as $delSlotTimes)
  1806.                         {
  1807.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  1808.                             $slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
  1809.                             $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
  1810.                             $saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
  1811.                             $sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
  1812.                             /*--------------------- Up Country Configuration ------------------------*/
  1813.                             $is_upcountry_configuration_applicable = ($delSlotTimes->getis_upcountry_configuration_applicable())?$delSlotTimes->getis_upcountry_configuration_applicable():'No';
  1814.                             $slot_upcountry_prepare_days = ($delSlotTimes->getupcountry_prepare_days())?$delSlotTimes->getupcountry_prepare_days():0;
  1815.                             $upcountry_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():7;
  1816.                             $upcountry_saturday_slot_availability = ($delSlotTimes->getupcountry_saturday_slot_availability())?$delSlotTimes->getupcountry_saturday_slot_availability():'No';
  1817.                             $upcountry_sunday_slot_availability = ($delSlotTimes->getupcountry_sunday_slot_availability())?$delSlotTimes->getupcountry_sunday_slot_availability():'No';
  1818.                             if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
  1819.                             {
  1820.                                 $slot_prepare_days $slot_upcountry_prepare_days;
  1821.                                 $slot_generate_days $upcountry_slot_generate_days;
  1822.                                 $saturday_slot_availability $upcountry_saturday_slot_availability;
  1823.                                 $sunday_slot_availability $upcountry_sunday_slot_availability;
  1824.                                 
  1825.                                 $cur_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():0;
  1826.                                 // $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_upcountry_prepare_days,'slot_generate_days'=>$upcountry_slot_generate_days,'saturday_slot_availability'=>$upcountry_saturday_slot_availability,'sunday_slot_availability'=>$upcountry_sunday_slot_availability];
  1827.                             }
  1828.                             else
  1829.                             {
  1830.                                 $cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  1831.                             }
  1832.                             $slot_generate_days = ($cur_time $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
  1833.                             
  1834.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  1835.                             
  1836.                             $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  1837.                             // echo $cur_time." | ".$setting_slot_time_flag;
  1838.                             // echo 'delSlotTimesAvailibility<pre>:';
  1839.                             // print_r($delSlotTimesAvailibility);
  1840.                             // echo 'weekdates<pre>:';
  1841.                             // print_r($weekdates);die;
  1842.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  1843.                             // $prepare_days = $delSlotTimes->getprepare_days();
  1844.                             // $delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$prepare_days.' day'));
  1845.                             $delSlot_date = ($slot_prepare_days == 0)?$tomorrow_date:date('Y-m-d'strtotime($today_date ' +'.$slot_prepare_days.' day'));
  1846.                             $delSlot_date1 date("Y-m-d"strtotime($delSlot_date));
  1847.                             
  1848.                             $cur_time_data explode(" ",$cur_time);
  1849.                             // $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  1850.                             // $slot_generate_days_limit = ($slot_generate_days > 0)?$slot_generate_days:1;
  1851.                             $slot_generate_days_limit = ($cur_slot_generate_days 0)?$cur_slot_generate_days:1;
  1852.                             // echo $tomorrow_date.":".$weekdates[0];
  1853.                             if($cur_time $setting_slot_time_flag)//if($cur_time > '18:00')
  1854.                             {
  1855.                                 // if($tomorrow_date >= $weekdates[0])
  1856.                                 // {
  1857.                                 //     $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  1858.                                 // } else {
  1859.                                 //     $no_of_weekdates = count($weekdates);
  1860.                                 //     $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
  1861.                                 // }
  1862.                                 
  1863.                                 $no_of_weekdates count($weekdates);
  1864.                                 // $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
  1865.                                 $weekdates = ($slot_generate_days 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  1866.                             } else {
  1867.                                 $weekdates = ($slot_generate_days 0)?$weekdates:[$weekdates[0]];
  1868.                             }
  1869.                             // echo 'weekdates:<pre>:'; print_r($weekdates);
  1870.                             
  1871.                             $slot_generate_days_date  date('Y-m-d'strtotime($today_date ' +'.$slot_generate_days.' day'));
  1872.                             $delivery_modes $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
  1873.                             $delivery_mode_slots_all = [];
  1874.                             foreach($delivery_modes as $delivery_mode)
  1875.                             {
  1876.                                 if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
  1877.                                 {
  1878.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  1879.                                 } else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
  1880.                                 {
  1881.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  1882.                                 } else {
  1883.                                     $slotsList DataObject\Slots::getList();
  1884.                                     if($cur_time $setting_slot_time_flag)//if($cur_time > '18:00')
  1885.                                     {
  1886.                                         $slotsList->setCondition("slotdate >= :tomdate AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1887.                                     } else {
  1888.                                         if($delivery_mode == 'standard')
  1889.                                         {
  1890.                                             $slotsList->setCondition("((slotdate = :slotdate AND fromtime <= :prior_time AND totime >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1891.                                         } else
  1892.                                         {
  1893.                                             $slotsList->setCondition("((slotdate = :slotdate AND prior_time >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  1894.                                         }
  1895.                                     }
  1896.                                     $slotsList->setOrderKey("slotdate");
  1897.                                     $slotsList->setOrder("asc");
  1898.                                     $slotsList->load();
  1899.                                     // if($slot_generate_days == 3)
  1900.                                     // {
  1901.                                     //     echo '<pre>';
  1902.                                     //     print_r($slotsList); die;
  1903.                                     // }
  1904.                                     /*---------- Slots Loop Starts ----------*/
  1905.                                     $delivery_mode_slots = [];
  1906.                                     if(count($slotsList) > && $cur_slot_generate_days>0){
  1907.                                         foreach($slotsList as $slot)
  1908.                                         {
  1909.                                             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  1910.                                             $loc_name $slotLocationData->getlocation_name();
  1911.                                             $delivery_mode_slot1 = array(
  1912.                                                 "slotId" => $slot->getId(),
  1913.                                                 "prior_time" => $slot->getprior_time(),
  1914.                                                 "slotdate" => date("Y-m-d"strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
  1915.                                                 "loc_name" => $loc_name,
  1916.                                                 "fromtime" => $slot->getfromtime(),
  1917.                                                 "totime" => $slot->gettotime(),
  1918.                                                 "maxorder" => $slot->getmaxorder(),
  1919.                                                 "ordercount" => $slot->getordercount(),
  1920.                                                 "delivery_mode" => $slot->getdelivery_mode(),
  1921.                                             );
  1922.                                             array_push($delivery_mode_slots$delivery_mode_slot1);
  1923.                                         }
  1924.                                     }
  1925.                                     /*---------- Slots Loop Starts ----------*/
  1926.                                     $delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
  1927.                                     // array_push($delivery_mode_slots_all, $delivery_mode_slot2);
  1928.                                     $delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
  1929.                                 }
  1930.                             }
  1931.                             $data[] = array(
  1932.                                 // "LocationName" => $parentLocationName,
  1933.                                 // "LocationCode" => $parentLocationCode,
  1934.                                 // "Is_location_up_country" => $Is_location_up_country,
  1935.                                 "is_upcountry_configuration_applicable" => $is_upcountry_configuration_applicable,
  1936.                                 "deliverytype_id" => $delSlotTimes->gettitle(),
  1937.                                 "label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  1938.                                 "prepare_days" => $slot_prepare_days,//$delSlotTimes->getprepare_days(),
  1939.                                 "slot_generate_days" => $cur_slot_generate_days,//$slot_generate_days,
  1940.                                 "delSlot_date" => $delSlot_date1,
  1941.                                 "slots"=>$delivery_mode_slots_all);
  1942.                         }
  1943.                     } else $data[] = ['message'=>$message];
  1944.                 // }
  1945.             } else $data[] = ['message'=>$message];
  1946.             
  1947.         } else $data[] = ['message'=>$message];
  1948.         return $this->json(["success" => true"Is_location_up_country" => $Is_location_up_country"data" => $data]);
  1949.     }
  1950.     /**
  1951.      * @Route("/deliveryslottime/gelocslottimes/{locCode}")
  1952.      */
  1953.     public function gelocslottimesAction($locCode)
  1954.     {
  1955.         $message SELF::verifyauthToken();
  1956.         $Is_location_up_country $is_upcountry_configuration_applicable '';
  1957.         if($message == "No data found")
  1958.         {
  1959.             $today_date date("Y-m-d");
  1960.             $tomorrow_date date('Y-m-d'strtotime($today_date ' +1 day'));
  1961.             $dates_list = array($today_date$tomorrow_date);
  1962.             /*---- Check Location by Location Code ---------*/
  1963.             $locationData DataObject\Locations::getBylocation_code($locCode1);
  1964.             /*--------------- Settings info ----------------*/
  1965.             $settingsInfo SELF::getSettingInfo();
  1966.             /*----------- End of Settings Info -------------*/
  1967.              /*--------- Getting Delivery Modes settings ----------*/
  1968.             $setting_slot_time_flag $settingsInfo['setting_slot_time_flag'];
  1969.             $setting_deliveryModes $settingsInfo['setting_deliveryModes'];
  1970.             $settingDataId $settingsInfo['settingDataId'];
  1971.             // echo 'settingsInfo:<pre>';
  1972.             // print_r($settingsInfo); die;
  1973.             
  1974.             if(!empty($locationData) && !empty($locationData->getId()))
  1975.             {
  1976.                 $parentLoc_id $locationData->getId();
  1977.                 $parentLocationName $locationData->getLocation_name();
  1978.                 $parentLocationCode $locationData->getLocation_code();
  1979.                 $fastDelivery $locationData->getfastDeliveryAvailable();
  1980.                 /*------ Check Location is Up Country or not --------*/
  1981.                 $Is_location_up_country = (strpos(strtolower($parentLocationName),"up country") || strpos(strtoupper($parentLocationCode),"UPCTR"))?1:0;
  1982.                 //------ get holidays list ------------//
  1983.                 $holidaysList DataObject\Holidays::getList();
  1984.                 $holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
  1985.                 $holidaysList->load();
  1986.                 
  1987.                 $holidayDates = [];
  1988.                 foreach($holidaysList as $holiday)
  1989.                 {
  1990.                     $holiday_locations_list $holiday->getLocation_code();
  1991.                     $holidaydate $holiday->getHolidaydate();
  1992.                     $holidayDate date("Y-m-d"strtotime($holidaydate));
  1993.                     array_push($holidayDates,$holidayDate);
  1994.                 }
  1995.                 
  1996.                 $delSlotTimesList DataObject\Deliveryslottimes::getList();
  1997.                 $delSlotTimesList->setOrderKey("o_id");
  1998.                 $delSlotTimesList->setOrder("desc");
  1999.                 $delSlotTimesList->load();
  2000.                 
  2001.                 // foreach($dates_list as $cur_date){
  2002.                     
  2003.                     if(count($delSlotTimesList) > 0){
  2004.                         $cur_time date("H:i");//"09:00";//
  2005.                         foreach($delSlotTimesList as $delSlotTimes)
  2006.                         {
  2007.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  2008.                             $slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
  2009.                             $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
  2010.                             $saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
  2011.                             $sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
  2012.                             /*--------------------- Up Country Configuration ------------------------*/
  2013.                             $is_upcountry_configuration_applicable = ($delSlotTimes->getis_upcountry_configuration_applicable())?$delSlotTimes->getis_upcountry_configuration_applicable():'No';
  2014.                             $slot_upcountry_prepare_days = ($delSlotTimes->getupcountry_prepare_days())?$delSlotTimes->getupcountry_prepare_days():0;
  2015.                             $upcountry_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():7;
  2016.                             $upcountry_saturday_slot_availability = ($delSlotTimes->getupcountry_saturday_slot_availability())?$delSlotTimes->getupcountry_saturday_slot_availability():'No';
  2017.                             $upcountry_sunday_slot_availability = ($delSlotTimes->getupcountry_sunday_slot_availability())?$delSlotTimes->getupcountry_sunday_slot_availability():'No';
  2018.                             if($settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'] == 'Yes' && $Is_location_up_country == 1)//if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
  2019.                             {
  2020.                                 $slot_prepare_days $slot_upcountry_prepare_days;
  2021.                                 $slot_generate_days $upcountry_slot_generate_days;
  2022.                                 $saturday_slot_availability $upcountry_saturday_slot_availability;
  2023.                                 $sunday_slot_availability $upcountry_sunday_slot_availability;
  2024.                                 
  2025.                                 $cur_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():0;
  2026.                                 
  2027.                                 // $slot_generate_days = ($cur_time > $settingsInfo['stg_delslot_upcountryloc_morethan_fromtime'] && $cur_time < $settingsInfo['stg_delslot_upcountryloc_lessthaneq_totime'])?$slot_generate_days+$settingsInfo['stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays']:$slot_generate_days+$settingsInfo['stg_delslot_normalloc_after_totime_extra_generate_slotdays'];
  2028.                                 
  2029.                                 $stg_normalloc_upcounry_slot_generate_days = ($cur_time $settingsInfo['stg_delslot_upcountryloc_morethan_fromtime'] && $cur_time $settingsInfo['stg_delslot_upcountryloc_lessthaneq_totime'])?$settingsInfo['stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays']:$settingsInfo['stg_delslot_upcountryloc_after_totime_extra_generate_slotdays'];
  2030.                                 $slot_generate_days $slot_generate_days+$stg_normalloc_upcounry_slot_generate_days;
  2031.                             }
  2032.                             else
  2033.                             {
  2034.                                 $cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  2035.                                 // $slot_generate_days = ($cur_time > $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
  2036.                                 $stg_normalloc_upcounry_slot_generate_days = ($cur_time $settingsInfo['stg_delslot_normalloc_morethan_fromtime'] && $cur_time $settingsInfo['stg_delslot_normalloc_lessthaneq_totime'])?$settingsInfo['stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays']:$settingsInfo['stg_delslot_normalloc_after_totime_extra_generate_slotdays'];
  2037.                                 $slot_generate_days $slot_generate_days+$stg_normalloc_upcounry_slot_generate_days;
  2038.                             }
  2039.                             $cur_slot_prepare_days = ($slot_prepare_days == 0)?$slot_prepare_days+$stg_normalloc_upcounry_slot_generate_days:$slot_prepare_days+$stg_normalloc_upcounry_slot_generate_days-1;
  2040.                             $cur_slot_prepare_days = (!empty($fastDelivery)) ? $cur_slot_prepare_days;
  2041.                             $delSlotTimesAvailibility = ['slot_prepare_days'=>$cur_slot_prepare_days,'slot_generate_days'=>$slot_generate_days,'saturday_slot_availability'=>$saturday_slot_availability,'sunday_slot_availability'=>$sunday_slot_availability];
  2042.                             
  2043.                             $weekdates self::getWeekDates($holidayDatesdate("Y-m-d"), $delSlotTimesAvailibility);
  2044.                             // echo $cur_time." | ".$setting_slot_time_flag;
  2045.                             // echo 'delSlotTimesAvailibility<pre>:';
  2046.                             // print_r($delSlotTimesAvailibility);
  2047.                             // echo 'weekdates<pre>:';
  2048.                             // print_r($weekdates);die;
  2049.                             //------- Get Week Dates based on Holidays and Slot Time data ---------//
  2050.                             // $prepare_days = $delSlotTimes->getprepare_days();
  2051.                             // $delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$prepare_days.' day'));
  2052.                             $delSlot_date = ($slot_prepare_days == 0)?$tomorrow_date:date('Y-m-d'strtotime($today_date ' +'.$slot_prepare_days.' day'));
  2053.                             if(!empty($fastDelivery)){
  2054.                                 date_default_timezone_set('Asia/Kolkata');
  2055.                                 $delSlot_date date('Y-m-d');
  2056.                                 
  2057.                                 // Get the current hour
  2058.                                 $currentHour = (int)date('H');
  2059.                                 // Check if the current time is greater than 6 PM
  2060.                                 if ($currentHour >= 18) {
  2061.                                     // Add one day to the current date
  2062.                                     $delSlot_date date('Y-m-d'strtotime($delSlot_date ' +1 day'));
  2063.                                 }
  2064.                             }
  2065.                             $delSlot_date1 date("Y-m-d"strtotime($delSlot_date));
  2066.                             
  2067.                             $cur_time_data explode(" ",$cur_time);
  2068.                             // $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
  2069.                             // $slot_generate_days_limit = ($slot_generate_days > 0)?$slot_generate_days:1;
  2070.                             $slot_generate_days_limit = ($cur_slot_generate_days 0)?$cur_slot_generate_days:1;
  2071.                             // echo $tomorrow_date.":".$weekdates[0];
  2072.                             /* if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
  2073.                             {
  2074.                                 // if($tomorrow_date >= $weekdates[0])
  2075.                                 // {
  2076.                                 //     $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  2077.                                 // } else {
  2078.                                 //     $no_of_weekdates = count($weekdates);
  2079.                                 //     $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
  2080.                                 // }
  2081.                                 
  2082.                                 $no_of_weekdates = count($weekdates);
  2083.                                 // $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
  2084.                                 $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  2085.                             } else {
  2086.                                 $weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
  2087.                             } */
  2088.                             /* if($settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'] == 'Yes' && $Is_location_up_country == 1)
  2089.                             {
  2090.                                 if($cur_time > $settingsInfo['stg_delslot_upcountryloc_morethan_fromtime'] && $cur_time < $settingsInfo['stg_delslot_upcountryloc_lessthaneq_totime'])
  2091.                                 {
  2092.                                     $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
  2093.                                 } else {
  2094.                                     $weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
  2095.                                 }
  2096.                                 if(($slot_generate_days > 0)){
  2097.                                     for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days; $ii++)
  2098.                                     {
  2099.                                         $weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
  2100.                                     }
  2101.                                 } else 
  2102.                                 $weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
  2103.                                 
  2104.                             } else {
  2105.                                 $stg_normalloc_upcounry_slot_generate_days = ($cur_time > $settingsInfo['stg_delslot_upcountryloc_morethan_fromtime'] && $cur_time < $settingsInfo['stg_delslot_upcountryloc_lessthaneq_totime'])?$settingsInfo['stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays']:$settingsInfo['stg_delslot_upcountryloc_after_totime_extra_generate_slotdays'];
  2106.                             } */
  2107.                             /* if(($slot_generate_days > 0)){
  2108.                                 for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days; $ii++)
  2109.                                 {
  2110.                                     $weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
  2111.                                 }
  2112.                             } else 
  2113.                             $weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]]; */
  2114.                             /*
  2115.                             if(($slot_generate_days > 0)){
  2116.                                 if($stg_normalloc_upcounry_slot_generate_days>1)
  2117.                                 {
  2118.                                     for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days-1; $ii++)
  2119.                                     {
  2120.                                         $weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
  2121.                                     }
  2122.                                 }
  2123.                                 $cur_weekdates = [];
  2124.                                 if($cur_slot_generate_days > 0){
  2125.                                     for($jj=0; $jj < $cur_slot_generate_days; $jj++)
  2126.                                     {
  2127.                                         array_push($cur_weekdates,$weekdates[$jj]);
  2128.                                     }
  2129.                                 }
  2130.                                 $weekdates = $cur_weekdates;
  2131.                             } else 
  2132.                             $weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
  2133.                             */
  2134.                             if(($slot_generate_days 0)){
  2135.                                 $cur_weekdates = [];
  2136.                                 if($cur_slot_generate_days 0){
  2137.                                     for($jj=0$jj $cur_slot_generate_days$jj++)
  2138.                                     {
  2139.                                         array_push($cur_weekdates,$weekdates[$jj]);
  2140.                                     }
  2141.                                 }
  2142.                                 $weekdates $cur_weekdates;
  2143.                             } else 
  2144.                             $weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
  2145.                             // $weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
  2146.                             // echo 'weekdates:<pre>:'; print_r($weekdates);
  2147.                             
  2148.                             $slot_generate_days_date  date('Y-m-d'strtotime($today_date ' +'.$slot_generate_days.' day'));
  2149.                             $delivery_modes $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
  2150.                             $locationSlotRule = new DataObject\Deliveryslotrules\Listing();
  2151.                             $locationSlotRule->setCondition(" FIND_IN_SET('".$parentLoc_id."',location_ids) ");
  2152.                             $locationSlotRule $locationSlotRule->getData();
  2153.                             if (count($locationSlotRule)) {
  2154.                                 $delivery_modes = array();
  2155.                                 foreach ($locationSlotRule as $slv) {
  2156.                                     $delivery_modes[] = $slv->getdelivery_mode();
  2157.                                 }
  2158.                             }
  2159.                             $delivery_mode_slots_all = [];
  2160.                             foreach($delivery_modes as $delivery_mode)
  2161.                             {
  2162.                                 if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
  2163.                                 {
  2164.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  2165.                                 } else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
  2166.                                 {
  2167.                                     $delivery_mode_slots_all[$delivery_mode] = [];
  2168.                                 } else {
  2169.                                     $slotsList DataObject\Slots::getList();
  2170.                                     if($cur_time $setting_slot_time_flag)//if($cur_time > '18:00')
  2171.                                     {
  2172.                                         $slotsList->setCondition("slotdate >= :tomdate AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  2173.                                     } else {
  2174.                                         if($delivery_mode == 'standard')
  2175.                                         {
  2176.                                             $slotsList->setCondition("((slotdate = :slotdate AND fromtime <= :prior_time AND totime >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  2177.                                         } else
  2178.                                         {
  2179.                                             $slotsList->setCondition("((slotdate = :slotdate AND prior_time >= :prior_time) || slotdate >= :tomdate) AND delivery_mode = :delivery_mode AND loc_id = :parentLoc_id AND slotdate IN (:slotdates)", ["slotdate" => $today_date"prior_time" => $cur_time"delivery_mode" => $delivery_mode"parentLoc_id" => $parentLoc_id"tomdate" => $delSlot_date1"slotdates" => $weekdates]);
  2180.                                         }
  2181.                                     }
  2182.                                     $slotsList->setOrderKey("slotdate");
  2183.                                     $slotsList->setOrder("asc");
  2184.                                     $slotsList->load();
  2185.                                     // if($slot_generate_days == 3)
  2186.                                     // {
  2187.                                     //     echo '<pre>';
  2188.                                     //     print_r($slotsList); die;
  2189.                                     // }
  2190.                                     /*---------- Slots Loop Starts ----------*/
  2191.                                     $delivery_mode_slots = [];
  2192.                                     if(count($slotsList) > && $cur_slot_generate_days>0){
  2193.                                         foreach($slotsList as $slot)
  2194.                                         {
  2195.                                             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  2196.                                             $loc_name $slotLocationData->getlocation_name();
  2197.                                             $delivery_mode_slot1 = array(
  2198.                                                 "slotId" => $slot->getId(),
  2199.                                                 "prior_time" => $slot->getprior_time(),
  2200.                                                 "slotdate" => date("Y-m-d"strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
  2201.                                                 "loc_name" => $loc_name,
  2202.                                                 "fromtime" => $slot->getfromtime(),
  2203.                                                 "totime" => $slot->gettotime(),
  2204.                                                 "maxorder" => $slot->getmaxorder(),
  2205.                                                 "ordercount" => $slot->getordercount(),
  2206.                                                 "delivery_mode" => $slot->getdelivery_mode(),
  2207.                                             );
  2208.                                             array_push($delivery_mode_slots$delivery_mode_slot1);
  2209.                                         }
  2210.                                     }
  2211.                                     /*---------- Slots Loop Starts ----------*/
  2212.                                     $delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
  2213.                                     // array_push($delivery_mode_slots_all, $delivery_mode_slot2);
  2214.                                     if ($fastDelivery) {
  2215.                                         $delivery_mode_slots_all[$delivery_mode] = (!empty($delivery_mode_slots[0]) ? array($delivery_mode_slots[0]) : array());
  2216.                                     } else {
  2217.                                         $delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
  2218.                                     }
  2219.                                 }
  2220.                             }
  2221.                             $data[] = array(
  2222.                                 // "LocationName" => $parentLocationName,
  2223.                                 // "LocationCode" => $parentLocationCode,
  2224.                                 // "Is_location_up_country" => $Is_location_up_country,
  2225.                                 "is_upcountry_configuration_applicable" => $is_upcountry_configuration_applicable,
  2226.                                 "stg_normalloc_upcounry_slot_generate_days" => $stg_normalloc_upcounry_slot_generate_days,
  2227.                                 "deliverytype_id" => $delSlotTimes->gettitle(),
  2228.                                 "label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  2229.                                 "prepare_days" => $slot_prepare_days,//$delSlotTimes->getprepare_days(),
  2230.                                 "slot_generate_days" => $cur_slot_generate_days,//$slot_generate_days,
  2231.                                 "delSlot_date" => $delSlot_date1,
  2232.                                 "slots"=>$delivery_mode_slots_all);
  2233.                         }
  2234.                     } else $data[] = ['message'=>$message];
  2235.                 // }
  2236.             } else $data[] = ['message'=>$message];
  2237.             
  2238.         } else $data[] = ['message'=>$message];
  2239.         return $this->json(["success" => true"Is_location_up_country" => $Is_location_up_country"data" => $data]);
  2240.     }
  2241.     /**
  2242.      * @Route("/awss3bucket/gets3bucketlist")
  2243.      */
  2244.     public function gets3bucketlistAction()
  2245.     {
  2246.         putenv('AWS_DEFAULT_REGION=us-east-2');
  2247.         putenv('AWS_ACCESS_KEY_ID=AKIAUY45FDQLWT32YTPJ');
  2248.         putenv('AWS_SECRET_ACCESS_KEY=IyaHsvQqIdeyDvUrpmlm4T/xizd5999KCpuBP8vg');
  2249.         // $output = shell_exec('aws s3 ls');
  2250.         try
  2251.         {
  2252.             $output shell_exec('aws s3api create-bucket --bucket snap2web-13 --region us-east-2 --create-bucket-configuration LocationConstraint=us-east-2');
  2253.         } catch(Exception $e)
  2254.         {
  2255.             echo $e->getMessage(); die;
  2256.         }
  2257.         // echo "<pre>$output</pre>";
  2258.         echo '<pre>'print_r($output); die;
  2259.         return $this->json(["success" => true"data" => $data]);
  2260.     }
  2261.     /**
  2262.      * @Route("/awss3bucket/uploadFileToS3")
  2263.      */
  2264.     public function uploadFileToS3()
  2265.     {
  2266.         $curl curl_init();
  2267.         curl_setopt_array($curl, array(
  2268.         CURLOPT_URL => 'https://itc-test.s3.ap-south-1.amazonaws.com/public/test.txt?X-Amz-Expires=86400&X-Amz-Date=20230320T054345Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAUY45FDQLWT32YTPJ%252F20230320%252Fap-south-1%252Fs3%252Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=8911af2498f4c48c8b0192a17fa4b8261946d1a7bb482f901091fb96760b2181',
  2269.         CURLOPT_RETURNTRANSFER => true,
  2270.         CURLOPT_ENCODING => '',
  2271.         CURLOPT_MAXREDIRS => 10,
  2272.         CURLOPT_TIMEOUT => 0,
  2273.         CURLOPT_FOLLOWLOCATION => true,
  2274.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2275.         CURLOPT_CUSTOMREQUEST => 'PUT',
  2276.         CURLOPT_POSTFIELDS => "<file contents here>",
  2277.         CURLOPT_HTTPHEADER => array(
  2278.             'Content-Type: text/plain'
  2279.         ),
  2280.         ));
  2281.         $response curl_exec($curl);
  2282.         curl_close($curl);
  2283.         echo $response;
  2284.     }
  2285.     /**
  2286.      * @Route("/user/login", methods={"POST"})
  2287.      */
  2288.     public function userLogin(Request $request)
  2289.     {
  2290.         $reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
  2291.         $userName = (isset($reqparams['username']))?$reqparams['username']:'';
  2292.         $password = (isset($reqparams['password']))?$reqparams['password']:'';
  2293.         if($userName == '' || $password == '')
  2294.         {
  2295.             $data "Username and Password are mandatory!";
  2296.         } else {
  2297.             $user User::getByName($userName);
  2298.             if($user) {
  2299.                 $validateUser \Pimcore\Tool\Authentication::authenticatePlaintext($userName,$password);
  2300.                 if($validateUser) {
  2301.                     $userInfo = ['id'=>$validateUser->getId(),
  2302.                                 'firstname'=>$validateUser->getfirstname(),
  2303.                                 'lastname'=>$validateUser->getlastname(),
  2304.                                 'email'=>$validateUser->getemail(),
  2305.                                 ];
  2306.                     $generateAuthTokenInfo SELF::generateAuthToken($userInfo);
  2307.                     $generateAuthToken $generateAuthTokenInfo['generateAuthToken'];
  2308.                     $jwtToken = (!empty($generateAuthTokenInfo['jwt']))?$generateAuthTokenInfo['jwt']:'';
  2309.                     $userId $validateUser->getId(); 
  2310.                     $dbConnection \Pimcore\Db::get();
  2311.                     $dbConnection->query("UPDATE users SET `authToken` = ? WHERE id = ?", [$generateAuthToken$userId]);
  2312.                     $userData User::getById($userId);
  2313.                     $authTokenVal $dbConnection->fetchOne("SELECT authToken FROM users WHERE id = ".$userId);
  2314.                     $data = ["message"=>'Login successfull'"authToken"=>$authTokenVal];
  2315.                     if($jwtToken!='')
  2316.                         $data = ["message"=>'Login successfull'"authToken"=>$authTokenVal"jwtToken"=>$jwtToken];
  2317.                     
  2318.                 } else {
  2319.                     $data 'Wrong password';
  2320.                 }
  2321.             } else {
  2322.                 $data 'User not found';
  2323.             }
  2324.         }
  2325.         return $this->json(["success" => true"data" => $data]);
  2326.     }
  2327.     public function generateAuthToken($userInfo=[])
  2328.     {
  2329.         /*------------- Generate MDF encode --------------*/
  2330.         $generateAuthToken md5(time());
  2331.         $jwtdata = array(
  2332.             "generateAuthToken" => $generateAuthToken
  2333.         );
  2334.         /*------------- Generate JWT Token ---------------*/
  2335.         $jwt_check 0;
  2336.         if(!empty($userInfo)){
  2337.             $id $userInfo['id'];//1024;
  2338.             $firstname $userInfo['firstname'];//'Tex';
  2339.             $lastname $userInfo['lastname'];//'Hardrock';
  2340.             $email $userInfo['email'];//'dino@stone.age';
  2341.             $secret_key "951e345a17ab26f80ec0e16b1d2a0c2a";
  2342.             $issuer_claim "pimcore6.local"// this can be the servername
  2343.             $audience_claim "Babu";
  2344.             $issuedat_claim time(); // issued at
  2345.             $notbefore_claim $issuedat_claim 10//not before in seconds
  2346.             $expire_claim $issuedat_claim 60*5// expire time in seconds
  2347.             $token = array(
  2348.                 "iss" => $issuer_claim,
  2349.                 "aud" => $audience_claim,
  2350.                 "iat" => $issuedat_claim,
  2351.                 "nbf" => $notbefore_claim,
  2352.                 "exp" => $expire_claim,
  2353.                 "data" => array(
  2354.                     "id" => $id,
  2355.                     "firstname" => $firstname,
  2356.                     "lastname" => $lastname,
  2357.                     "email" => $email
  2358.             ));
  2359.             $jwt JWT::encode($token$secret_key'HS256');
  2360.             
  2361.             $jwtdata = array(
  2362.                 "generateAuthToken" => $generateAuthToken,
  2363.                 "jwt" => $jwt,
  2364.                 "email" => $email,
  2365.                 "expireAt" => $expire_claim
  2366.             );
  2367.         }
  2368.         return $jwtdata;
  2369.     }
  2370.     public function verifyauthToken1()
  2371.     {
  2372.         $message "No data found"$tokenCheck 0;
  2373.         $headers=array();
  2374.         foreach (getallheaders() as $name => $value) {
  2375.             $headers[$name] = $value;
  2376.             if($name == 'Authtoken'$tokenCheck 1;
  2377.         }
  2378.         if($tokenCheck == 0){
  2379.             $message "Authentication Token is missing";;
  2380.         } else {
  2381.             $Authtoken $headers['Authtoken'];
  2382.         
  2383.             $dbConnection \Pimcore\Db::get();
  2384.             $authTokencheck $dbConnection->fetchOne("SELECT id FROM users WHERE authToken = '".$Authtoken."' ");
  2385.             if(empty($authTokencheck)){
  2386.                 $message "Authentication Token is mismatch";
  2387.             } else {
  2388.             }
  2389.         }
  2390.         return $message;
  2391.     }
  2392.     public function verifyauthToken2()
  2393.     {
  2394.         $api_key 'api-key';
  2395.         $api_key_value 'cGltY29yZWFwaWtleXZhbHVl';//base64encode('pimcoreapikeyvalue);
  2396.         $message "No data found"$tokenCheck 0$apikeyCheck 0$jwtCheck 0;$tokenMsg ''$apikeyMsg ''$jwtMsg '';
  2397.         $headers=array();
  2398.         foreach (getallheaders() as $name => $value) {
  2399.             $headers[$name] = $value;
  2400.             if($name == 'Authtoken'$tokenCheck 1;
  2401.             if($name == 'Api-Key'$apikeyCheck 1;
  2402.             if($name == 'Authorization'$jwtCheck 1;
  2403.         }
  2404.         // echo 'arr:<pre>';
  2405.         // print_r($headers); 
  2406.         // die;
  2407.         if($tokenCheck == && $apikeyCheck == && $jwtCheck == 0){
  2408.             $message "Fill any one of the Authentication Token, Api-Key Or JWT token!";;
  2409.         } else {
  2410.             $tokenCheck_valid 0$apikeyCheck_valid 0$jwtTokenCheck_valid 0;
  2411.             /*--------------------- Validating Auth Token -----------------*/
  2412.             if($tokenCheck == 1)
  2413.             {
  2414.                 $Authtoken $headers['Authtoken'];
  2415.         
  2416.                 $dbConnection \Pimcore\Db::get();
  2417.                 $authTokencheck $dbConnection->fetchOne("SELECT id FROM users WHERE authToken = '".$Authtoken."' ");
  2418.                 if(empty($authTokencheck)){
  2419.                     $tokenMsg "Authentication Token is mismatch";
  2420.                 } else {
  2421.                     $tokenCheck_valid 1;
  2422.                 }
  2423.             }
  2424.             /*--------------------- Validating Api Key -----------------*/
  2425.             if($apikeyCheck == 1)
  2426.             {
  2427.                 $AuthApikey $headers['Api-Key'];
  2428.                 if(empty($AuthApikey)){
  2429.                     $apikeyMsg "Key is mismatch";
  2430.                 } else if($AuthApikey != $api_key_value){
  2431.                     $apikeyMsg "key is mismatch";
  2432.                 } else {
  2433.                     $apikeyCheck_valid 1;
  2434.                 }
  2435.             }
  2436.             /*--------------------- Validating JWT Token -----------------*/
  2437.             if($jwtCheck == 1)
  2438.             {
  2439.                 $secret_key "951e345a17ab26f80ec0e16b1d2a0c2a";
  2440.                 $jwt null;
  2441.                 $authHeader $_SERVER['HTTP_AUTHORIZATION'];
  2442.                 $arr explode(" "$authHeader);
  2443.                 $jwt $arr[1];
  2444.                 if($jwt){
  2445.                     try {
  2446.                         $decoded JWT::decode($jwt, new Key($secret_key'HS256'));
  2447.                         $jwtTokenCheck_valid 1;
  2448.                     }catch (ExpiredException $e){
  2449.                         $jwtMsg "Expired JWT Token!";//$e->getMessage();
  2450.                     }catch (Exception $e){
  2451.                         $jwtTokenCheck_valid 0;
  2452.                         $jwtMsg "Expired JWT Token!";//$e->getMessage();
  2453.                     }
  2454.                 } else {
  2455.                     $jwtMsg "JWT Token is missing";
  2456.                 }
  2457.             }
  2458.             $message '';
  2459.             if($tokenMsg != '' || $apikeyMsg != '' || $jwtMsg != '')
  2460.             {
  2461.                 $message = ($tokenMsg != '')?"Token Message:".$message.$tokenMsg:$message;
  2462.                 $message = ($apikeyMsg != '')?"".$message." | Api-Key Message:".$apikeyMsg:$message;
  2463.                 $message = ($jwtMsg != '')?"".$message." | JWT Message:".$jwtMsg:$message;
  2464.             }
  2465.             $message = ($tokenCheck_valid == || $apikeyCheck_valid == || $jwtTokenCheck_valid == 1)?"No data found":$message;
  2466.         }
  2467.         return $message;
  2468.     }
  2469.     public function verifyauthToken()
  2470.     {
  2471.         $api_key 'api-key';
  2472.         $api_key_value 'cGltY29yZWFwaWtleXZhbHVl';//base64encode('pimcoreapikeyvalue);
  2473.         $message "No data found"$apikeyCheck 0$apikeyMsg '';
  2474.         $headers=array();
  2475.         foreach (getallheaders() as $name => $value) {
  2476.             $headers[$name] = $value;
  2477.             if($name == 'Api-Key'$apikeyCheck 1;
  2478.         }
  2479.         
  2480.         if($apikeyCheck == 0){
  2481.             $message "Api-Key is mandatory!";;
  2482.         } else {
  2483.             $apikeyCheck_valid 0;
  2484.             /*--------------------- Validating Api Key -----------------*/
  2485.             if($apikeyCheck == 1)
  2486.             {
  2487.                 $AuthApikey $headers['Api-Key'];
  2488.                 if(empty($AuthApikey)){
  2489.                     $message "Key is empty, Api-Key is mandatory";
  2490.                 } else if($AuthApikey != $api_key_value){
  2491.                     $message "key is mismatch";
  2492.                 } else {
  2493.                     $apikeyCheck_valid 1;
  2494.                 }
  2495.             }
  2496.         }
  2497.         return $message;
  2498.     }
  2499.     /**
  2500.      * @Route("/location/locationslist")
  2501.      */
  2502.     public function locationslist()
  2503.     {
  2504.         $message SELF::verifyauthToken();
  2505.         if($message == "No data found")
  2506.         {
  2507.             $locationsList DataObject\Locations::getList();
  2508.             $locationsList->load();
  2509.             if(count($locationsList) > 0){
  2510.                 foreach ($locationsList as $key => $location) {
  2511.                     $data[] = array(
  2512.                         "Id" => $location->getId(),
  2513.                         "location_name" => $location->getLocation_name(),
  2514.                         "location_code" => $location->getLocation_code());
  2515.                 }
  2516.             } else $data[] = ['message'=>$message];
  2517.         } else $data[] = ['message'=>$message];
  2518.         
  2519.         return $this->json(["success" => true"data" => $data]);
  2520.     }
  2521.     /**
  2522.      * @Route("personalitystatement/perstmtlist")
  2523.      */
  2524.     public function perstmtlistAction()
  2525.     {
  2526.         $message SELF::verifyauthToken();
  2527.         if($message == "No data found")
  2528.         {
  2529.             $perstmtList DataObject\Personalitystatements::getList();
  2530.             $perstmtList->load();
  2531.             if(count($perstmtList)>0){
  2532.                 foreach ($perstmtList as $key => $perstmtObj) {
  2533.                     $data[] = array(
  2534.                         "id" => $perstmtObj->getId(),
  2535.                         "personality_statement" => $perstmtObj->getpersonality_statement(),
  2536.                         "standout_fitin" => $perstmtObj->getstandout_fitin(),
  2537.                         "describe_yourself" => $perstmtObj->getdescribe_yourself(),
  2538.                         "occasion" => $perstmtObj->getoccasion(),
  2539.                         "priceband" => $perstmtObj->getpriceband(),
  2540.                         "blank2" => $perstmtObj->getblank2(),
  2541.                         "blank1" => $perstmtObj->getblank1());
  2542.                 }
  2543.             } else $data[] = ['message'=>$message];
  2544.         } else $data[] = ['message'=>$message];
  2545.         return $this->json(["success" => true"data" => $data]);
  2546.     }
  2547.     /**
  2548.      * @Route("personalitystatement/perstmtinfo/{id}")
  2549.      */
  2550.     public function perstmtinfoAction($id)
  2551.     {
  2552.         $message SELF::verifyauthToken();
  2553.         if($message == "No data found")
  2554.         {
  2555.             $perstmtObject DataObject\Personalitystatements::getById($id);
  2556.             if(!empty($perstmtObject) && $perstmtObject->getpersonality_statement()){
  2557.                 $data[] = array(
  2558.                     "id" => $perstmtObject->getId(),
  2559.                     "personality_statement" => $perstmtObject->getpersonality_statement(),
  2560.                     "standout_fitin" => $perstmtObject->getstandout_fitin(),
  2561.                     "describe_yourself" => $perstmtObject->getdescribe_yourself(),
  2562.                     "occasion" => $perstmtObject->getoccasion(),
  2563.                     "priceband" => $perstmtObject->getpriceband(),
  2564.                     "blank2" => $perstmtObject->getblank2(),
  2565.                     "blank1" => $perstmtObject->getblank1());
  2566.             } else $data[] = ['message'=>$message];
  2567.         } else $data[] = ['message'=>$message];
  2568.         return $this->json(["success" => true"data" => $data]);
  2569.     }
  2570.      /**
  2571.      * @Route("/api/gernerateJwtToken")
  2572.      */
  2573.     public function gernerateJwtTokenAction()
  2574.     {
  2575.         $id 1024;
  2576.         $firstname 'Tex';
  2577.         $lastname 'Hardrock';
  2578.         $email 'dino@stone.age';
  2579.         $secret_key "951e345a17ab26f80ec0e16b1d2a0c2a";
  2580.         $issuer_claim "pimcore6.local"// this can be the servername
  2581.         $audience_claim "Babu";
  2582.         $issuedat_claim time(); // issued at
  2583.         $notbefore_claim $issuedat_claim 10//not before in seconds
  2584.         $expire_claim $issuedat_claim 60// expire time in seconds
  2585.         $token = array(
  2586.             "iss" => $issuer_claim,
  2587.             "aud" => $audience_claim,
  2588.             "iat" => $issuedat_claim,
  2589.             "nbf" => $notbefore_claim,
  2590.             "exp" => $expire_claim,
  2591.             "data" => array(
  2592.                 "id" => $id,
  2593.                 "firstname" => $firstname,
  2594.                 "lastname" => $lastname,
  2595.                 "email" => $email
  2596.         ));
  2597.         $jwt JWT::encode($token$secret_key'HS256');
  2598.         // echo json_encode(
  2599.         //     array(
  2600.         //         "message" => "Successful login.",
  2601.         //         "jwt" => $jwt,
  2602.         //         "email" => $email,
  2603.         //         "expireAt" => $expire_claim
  2604.         //     )); die;
  2605.         $data = array(
  2606.             "message" => "Successful login.",
  2607.             "jwt" => $jwt,
  2608.             "email" => $email,
  2609.             "expireAt" => $expire_claim
  2610.         );
  2611.         return $this->json(["success" => true"data" => $data]);
  2612.     }
  2613.     /**
  2614.      * @Route("/api/verifyJwtToken")
  2615.      */
  2616.     public function verifyJwtTokenAction()
  2617.     {
  2618.         $secret_key "951e345a17ab26f80ec0e16b1d2a0c2a";
  2619.         $jwt null;
  2620.         
  2621.         $data json_decode(file_get_contents("php://input"));
  2622.         $authHeader $_SERVER['HTTP_AUTHORIZATION'];
  2623.         $arr explode(" "$authHeader);
  2624.         $jwt $arr[1];
  2625.         if($jwt){
  2626.             try {
  2627.                 $decoded JWT::decode($jwt, new Key($secret_key'HS256'));
  2628.                 // Access is granted. Add code of the operation here 
  2629.                 $data = array(
  2630.                     "message" => "Access granted"
  2631.                 );
  2632.                 return $this->json(["success" => true"data" => $data]);
  2633.             }catch (Exception $e){
  2634.                 $data = array(
  2635.                     "message" => "Access denied"
  2636.                 );
  2637.                 return $this->json(["success" => true"data" => $data]);
  2638.             }
  2639.         }
  2640.     }
  2641.     /**
  2642.      * @Route("api/shippingchargeslist")
  2643.      */
  2644.     public function shippingchargeslistAction()
  2645.     {
  2646.         $message SELF::verifyauthToken();
  2647.         if($message == "No data found")
  2648.         {
  2649.             $shippingchargesList DataObject\Shippingcharges::getList();
  2650.             $shippingchargesList->load();
  2651.             if(count($shippingchargesList)>0){
  2652.                 foreach ($shippingchargesList as $key => $shippingchargeObj) {
  2653.                     $data[] = array(
  2654.                         "id" => $shippingchargeObj->getId(),
  2655.                         "minimum_order" => $shippingchargeObj->getminimum_order(),
  2656.                         "maximum_order" => $shippingchargeObj->getmaximum_order(),
  2657.                         "discount_percentage" => $shippingchargeObj->getdiscount_percentage(),
  2658.                         "location" => $shippingchargeObj->getlocationId()->getLocation_name());
  2659.                 }
  2660.             } else $data[] = ['message'=>$message];
  2661.         } else $data[] = ['message'=>$message];
  2662.         return $this->json(["success" => true"data" => $data]);
  2663.     }
  2664.     /**
  2665.      * @Route("api/shippingrateslist1", methods={"POST"})
  2666.      */
  2667.     public function shippingrateslist1Action()
  2668.     {
  2669.         $reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
  2670.         $noofkgs = (isset($reqparams['noofkgs']))?$reqparams['noofkgs']:'';
  2671.         $shippingaddress = (isset($reqparams['shippingaddress']))?$reqparams['shippingaddress']:'';
  2672.         if($noofkgs == '' || $shippingaddress == '')
  2673.         {
  2674.             $data "No of Kgs and Shipping Address are mandatory!";
  2675.         } else {
  2676.             if(empty($shippingaddress['locationCode']) || empty($shippingaddress['location_zone']))//empty($shippingaddress['order_in_kgs']) || 
  2677.             {
  2678.                 $data "Shipping Address should have locationCode and location_zone !";// and order_in_kgs
  2679.             } else {
  2680.                 // echo 'shippingaddress<pre>:';
  2681.                 // print_r($shippingaddress);
  2682.                 $message SELF::verifyauthToken();
  2683.                 if($message == "No data found")
  2684.                 {
  2685.                     //----------- Shipping Address Params Data ------------//
  2686.                     $locationCode $shippingaddress['locationCode'];
  2687.                     // $order_in_kgs = $shippingaddress['order_in_kgs'];
  2688.                     $location_zone $shippingaddress['location_zone'];
  2689.                     //--------- Get Location data from location code ------------//
  2690.                     $LocationInfo DataObject\Locations::getList();
  2691.                     if ($LocationInfo->getClass()->getFieldDefinition('location_code')->isFilterable()) {
  2692.                         $LocationInfo->filterBylocation_code($locationCode'=');
  2693.                     }
  2694.                     $LocationInfo->load();
  2695.                     if(count($LocationInfo)>0)
  2696.                     {
  2697.                         foreach($LocationInfo as $Location)
  2698.                         {
  2699.                             $locationName $Location->getLocation_name();
  2700.                             $locationId $Location->getId();
  2701.                         }
  2702.                         // echo 'locationId:'.$locationId;
  2703.                         //------- Get Shipping Charge from Location and order ---------//
  2704.                         $shippingchargesList DataObject\Shippingcharges::getList();
  2705.                         $shippingchargesList->setCondition("locationId__Id = ?",[$locationId]);
  2706.                         $shippingchargesList->load();
  2707.                         // echo 'shippingchargesList<pre>:';
  2708.                         // print_r($shippingchargesList);
  2709.                         $locationName='';$minimum_order $maximum_order $discount_percentage 0;
  2710.                         if(count($shippingchargesList)>0)
  2711.                         {
  2712.                             foreach($shippingchargesList as $shippingchargeObj)
  2713.                             {
  2714.                                 $locationName $shippingchargeObj->getlocationId()->getLocation_name();
  2715.                                 $minimum_order $shippingchargeObj->getminimum_order();
  2716.                                 $maximum_order $shippingchargeObj->getmaximum_order();
  2717.                                 $discount_percentage $shippingchargeObj->getdiscount_percentage();
  2718.                             }
  2719.                         }
  2720.                         // echo 'minimum_order:'.$minimum_order.'|maximum_order:'.$maximum_order.'|discount_percentage:'.$discount_percentage;
  2721.                         //----------- Get Discount Percentage from Shipping Charge data and Order -----------//
  2722.                         $rate_discount_perc = ($minimum_order <= $noofkgs && $maximum_order >= $noofkgs)?$discount_percentage:0;
  2723.                         $cur_noofkgs = ($noofkgs<=2)?3:$noofkgs;
  2724.                         $shippingratesList DataObject\Shippingratecards::getList();
  2725.                         if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
  2726.                             $shippingratesList->filterByno_of_kgs($cur_noofkgs'=');
  2727.                         }
  2728.                         $shippingratesList->setOrderKey("no_of_kgs");
  2729.                         $shippingratesList->setOrder("desc");
  2730.                         $shippingratesList->load();
  2731.                         if(count($shippingratesList)>0){
  2732.                             $ii=0;
  2733.                             foreach ($shippingratesList as $key => $shippingrateObj) {
  2734.                                 // $data[] = array(
  2735.                                 //     "id" => $shippingrateObj->getId(),
  2736.                                 //     "no_of_kgs" => $shippingrateObj->getno_of_kgs(),
  2737.                                 //     "intera_region_cost" => $shippingrateObj->getintera_region_cost(),
  2738.                                 //     "j_and_k_cost" => $shippingrateObj->getj_and_k_cost(),
  2739.                                 //     "ne_and_andaman" => $shippingrateObj->getne_and_andaman());
  2740.                                 $data_key $data_val $data_key2 $data_val2 '';
  2741.                                 $data[] = array(
  2742.                                     "id" => $shippingrateObj->getId(),
  2743.                                     "no_of_kgs" => $shippingrateObj->getno_of_kgs());
  2744.                                 if($location_zone == 'Intera Region')
  2745.                                 {
  2746.                                     $data_key 'intera_region_final_cost'
  2747.                                     $data_val $shippingrateObj->getintera_region_cost()-(($shippingrateObj->getintera_region_cost()*$rate_discount_perc)/100);
  2748.                                     $data_key2 'intera_region_cost'
  2749.                                     $data_val2 $shippingrateObj->getintera_region_cost();
  2750.                                 }
  2751.                                 if($location_zone == 'J and K')
  2752.                                 {
  2753.                                     $data_key 'j_and_k_final_cost'
  2754.                                     $data_val $shippingrateObj->getj_and_k_cost()-(($shippingrateObj->getj_and_k_cost()*$rate_discount_perc)/100);
  2755.                                     $data_key2 'j_and_k_cost'
  2756.                                     $data_val2 $shippingrateObj->getj_and_k_cost();
  2757.                                 }
  2758.                                 if($location_zone == 'NE and Andaman')
  2759.                                 {
  2760.                                     $data_key 'ne_and_andaman_final_cost'
  2761.                                     $data_val $shippingrateObj->getne_and_andaman()-(($shippingrateObj->getne_and_andaman()*$rate_discount_perc)/100);  
  2762.                                     $data_key2 'ne_and_andaman_cost'
  2763.                                     $data_val2 $shippingrateObj->getne_and_andaman();  
  2764.                                 }
  2765.                                 $data[$ii]['locationName'] = $locationName;
  2766.                                 $data[$ii]['discount_percentage'] = $rate_discount_perc."%";
  2767.                                 if($location_zone == 'All')
  2768.                                 {
  2769.                                     $data_key $data_val '';
  2770.                                     $data[$ii]['intera_region_cost'] = $shippingrateObj->getintera_region_cost();
  2771.                                     $data[$ii]['intera_region_final_cost'] = $shippingrateObj->getintera_region_cost()-(($shippingrateObj->getintera_region_cost()*$rate_discount_perc)/100);
  2772.                                     $data[$ii]['j_and_k_cost'] = $shippingrateObj->getj_and_k_cost();
  2773.                                     $data[$ii]['j_and_k_final_cost'] = $shippingrateObj->getj_and_k_cost()-(($shippingrateObj->getj_and_k_cost()*$rate_discount_perc)/100);
  2774.                                     $data[$ii]['ne_and_andaman_cost'] = $shippingrateObj->getne_and_andaman();
  2775.                                     $data[$ii]['ne_and_andaman_final_cost'] = $shippingrateObj->getne_and_andaman()-(($shippingrateObj->getne_and_andaman()*$rate_discount_perc)/100);
  2776.                                 }
  2777.                                 if($data_key != '' && $data_val != '')
  2778.                                 {
  2779.                                     $data[$ii][$data_key2] = $data_val2;
  2780.                                     $data[$ii][$data_key] = $data_val;
  2781.                                 }
  2782.                             }
  2783.                         } else $data[] = ['message'=>$message];
  2784.                     } else {
  2785.                         $data "Location Code should be valid!";
  2786.                     }
  2787.                 } else $data[] = ['message'=>$message];
  2788.             }
  2789.         }
  2790.         return $this->json(["success" => true"data" => $data]);
  2791.     }
  2792.     /**
  2793.      * @Route("api/shippingrateslist2", methods={"POST"})
  2794.      */
  2795.     public function shippingrateslist2Action()
  2796.     {
  2797.         $reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
  2798.         $weight_cart = (isset($reqparams['weight_cart']))?$reqparams['weight_cart']:'';
  2799.         $req_weight_cart $weight_cart;
  2800.         $locationCode = (isset($reqparams['locationCode']))?$reqparams['locationCode']:'';
  2801.         $shipping_state_code = (isset($reqparams['shipping_state_code']))?$reqparams['shipping_state_code']:'';
  2802.         $pincode = (isset($reqparams['pincode']))?$reqparams['pincode']:'';
  2803.         $order_amount = (isset($reqparams['order_amount']))?$reqparams['order_amount']:'';
  2804.         if($weight_cart == '' || $locationCode == '' || $shipping_state_code == '' || $pincode == '' || $order_amount == '')
  2805.         {
  2806.             $data "weight_cart, locationCode, shipping_state_code, pincode and order_amount are mandatory!";
  2807.         } else {
  2808.             // $weight_cart = ceil($weight_cart);
  2809.             /*------ Get Shipping Rate Card Class data --------*/
  2810.             // $dbConnection = \Pimcore\Db::get();
  2811.             $dbConnection \Pimcore\Db::get();
  2812.             $shippingRatecardClassId $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Shippingratecards' ");
  2813.             $shippingRatecardClassId;
  2814.             $shippingRatecardObject "object_".$shippingRatecardClassId;
  2815.             // $shippingRatecardId = $dbConnection->fetchOne(" select * from object_12 order by abs(no_of_kgs - ".$weight_cart.")");
  2816.             $shippingRatecardId $dbConnection->fetchOne(" select * from ".$shippingRatecardObject." order by abs(no_of_kgs - ".$weight_cart.")");
  2817.             /*----- End of ---------*/
  2818.             /*---- Check Location by Location Code ---------*/
  2819.             $locData DataObject\Locations::getBylocation_code($locationCode1);
  2820.             $pincodeInfo DataObject\ItcAddPincode::getBypincode($pincode1);
  2821.             $stateInfo DataObject\States::getBystate_code($shipping_state_code1);
  2822.             $shipChargeInfo DataObject\Shippingratecards::getById($shippingRatecardId); //DataObject\Shippingratecards::getByno_of_kgs($weight_cart, 1);
  2823.             // echo "shippingRatecardId<pre>:".$shippingRatecardId;
  2824.             // echo "<br>shipChargeInfo<pre>:";
  2825.             // print_r($shipChargeInfo->getId()); //die;
  2826.             if(empty($locData) || empty($locData->getId()) || empty($pincodeInfo) || empty($pincodeInfo->getId()) || empty($shipChargeInfo) || empty($shipChargeInfo->getId()))// || empty($stateInfo) || empty($stateInfo->getId()) 
  2827.             {
  2828.                 if(empty($locData) || empty($locData->getId()))
  2829.                     $message "Location is not exited, please try with valid location code!";
  2830.                 
  2831.                 if(empty($pincodeInfo) || empty($pincodeInfo->getId()))
  2832.                     $message "Pincode is not exited, please try with valid pincode!";
  2833.             
  2834.                 // if(empty($stateInfo) || empty($stateInfo->getId()))
  2835.                 //     $message = "Shipping State Code is not exited, please try with valid Shipping State Code!";
  2836.             
  2837.                 if(empty($shipChargeInfo) || empty($shipChargeInfo->getId()))
  2838.                     $message "Shipping Charge is not exited for ".$weight_cart." Kgs, please try with valid No of Kgs!";
  2839.                 $data[] = ['message'=>$message];
  2840.             } else {
  2841.                 $locationId $locData->getId();
  2842.                 $locationName $locData->getLocation_name();
  2843.                 $message SELF::verifyauthToken();
  2844.                 if($message == "No data found")
  2845.                 {
  2846.                     /*------------- Check Is Shipping Applicable or Not based on Pincode from Pincode Table------------*/
  2847.                     // $pincode_error = ''; $is_shippingapplicable=''; $pincode_data = [];
  2848.                     
  2849.                     // $pincodeList = DataObject\ItcAddPincode::getList();
  2850.                     // if ($pincodeList->getClass()->getFieldDefinition('pincode')->isFilterable()) {
  2851.                     //     $pincodeList->filterBypincode($pincode, '=');
  2852.                     // }
  2853.                     // $pincodeList->load();
  2854.                     // if(count($pincodeList)>0)
  2855.                     // {
  2856.                     //     foreach($pincodeList as $pincodeInfo)
  2857.                     //     {
  2858.                     //         // echo 'pincodeInfo<pre>';
  2859.                     //         // print_r($pincodeInfo); die;
  2860.                     //         $is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
  2861.                     //         $pincode_data['pincode'] = $pincodeInfo->getpincode();
  2862.                     //         $pincode_data['state'] = $pincodeInfo->getstate();
  2863.                     //         $pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
  2864.                     //         $pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
  2865.                     //         $pincodeInfo->getData();
  2866.                     //     }
  2867.                     // } else 
  2868.                     // {
  2869.                     //     $pincode_error = 'pincode is not valid';
  2870.                     // }
  2871.                     $is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
  2872.                     $pincode_data['pincode'] = $pincodeInfo->getpincode();
  2873.                     $pincode_data['state'] = $pincodeInfo->getstate();
  2874.                     $pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
  2875.                     $pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
  2876.                     /*----------- End of Check Is Shipping Applicable or Not based on Pincode from Pincode Table ----------*/
  2877.                     /*------------- Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table------------*/
  2878.                     $final_cost=0$rate_discount_perc=0$cur_noofkgs $shipChargeInfo->getno_of_kgs();//$weight_cart;//($weight_cart<=2)?3:$weight_cart;
  2879.                     /*----------- End of Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table ----------*/
  2880.                     /*------------- Get Zone based on State Code from States Table ------------*/
  2881.                     // $zone_name='';
  2882.                     // $stateList = DataObject\States::getList();
  2883.                     // if ($stateList->getClass()->getFieldDefinition('state_code')->isFilterable()) {
  2884.                     //     $stateList->filterBystate_code($shipping_state_code, '=');
  2885.                     // }
  2886.                     // $stateList->load();
  2887.                     // if(count($stateList)>0)
  2888.                     // {
  2889.                     //     foreach($stateList as $stateInfo)
  2890.                     //     {
  2891.                     //         $zone_name=$stateInfo->getZoneId()->getzone_name();
  2892.                     //     }
  2893.                     // }
  2894.                     $zone_name=(!empty($stateInfo) && $stateInfo->getZoneId())?$stateInfo->getZoneId()->getzone_name():'';
  2895.                     /*----------- End of Get Zone based on State Code from States Table ----------*/
  2896.                     /*------------- Get Shipping rate data based on state code and weight cart ------------*/
  2897.                     $shippingratesList DataObject\Shippingratecards::getList();
  2898.                     if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
  2899.                         $shippingratesList->filterByno_of_kgs($cur_noofkgs'=');
  2900.                     }
  2901.                     $shippingratesList->setOrderKey("no_of_kgs");
  2902.                     $shippingratesList->setOrder("desc");
  2903.                     $shippingratesList->load();
  2904.                     if(count($shippingratesList)>0){
  2905.                         $ii=0;
  2906.                         foreach ($shippingratesList as $key => $shippingrateObj) {
  2907.                             $data_key $data_val $data_key2 $data_val2 '';
  2908.                             $data[] = array(
  2909.                                 "id" => $shippingrateObj->getId(),
  2910.                                 "no_of_kgs" => $req_weight_cart,//$shippingrateObj->getno_of_kgs(),
  2911.                                 "inter_region_cost" => $shippingrateObj->getintera_region_cost(),
  2912.                                 "j_k_cost" => $shippingrateObj->getj_and_k_cost(),
  2913.                                 "ne_and_andaman_cost" => $shippingrateObj->getne_and_andaman()
  2914.                             );
  2915.                             
  2916.                             if($is_shippingapplicable == 'Yes')
  2917.                             {
  2918.                                 if($zone_name == 'J and K')
  2919.                                 {
  2920.                                     $final_cost $shippingrateObj->getj_and_k_cost();
  2921.                                 }
  2922.                                 else if($zone_name == 'NE and Andaman')
  2923.                                 {
  2924.                                     $final_cost $shippingrateObj->getne_and_andaman();  
  2925.                                 }
  2926.                                 else 
  2927.                                 {
  2928.                                     $final_cost $shippingrateObj->getintera_region_cost();
  2929.                                 }
  2930.                             }
  2931.                             $data[$ii]['locationCode'] = $locationCode;
  2932.                             // $data[$ii]['is_shipping_applicable'] = $is_shippingapplicable;
  2933.                             $data[$ii]['pincode'] = $pincode_data;//$pincodeInfo->getData();//
  2934.                             // $data[$ii]['discount_percentage'] = $rate_discount_perc."%";
  2935.                             
  2936.                         }
  2937.                         $minimum_order $maximum_order $discount_percentage 0$shippingRules = [];
  2938.                         if($is_shippingapplicable == 'Yes')//&& $loc_code_error == ''
  2939.                         {
  2940.                             $shippingchargesList DataObject\Shippingcharges::getList();
  2941.                             // $shippingchargesList = new DataObject\Shippingcharges\Listing();
  2942.                             $shippingchargesList->setCondition("locationId__Id = ? AND (minimum_order <= ? AND maximum_order >= ?)",[$locationId$order_amount$order_amount]);
  2943.                             // $shippingchargesList->setCondition("locationId__Id = ?",[$locationId]);
  2944.                             // $shippingchargesList->setCondition("minimum_order >= ?",[$order_amount]);
  2945.                             // $shippingchargesList->setCondition("maximum_order <= ?",[$order_amount]);
  2946.                             $shippingchargesList->load();
  2947.                             // echo $shippingchargesList->getQuery()->__toString(); die;
  2948.                             // echo $shippingchargesList->getSQL(); die;
  2949.                             
  2950.                             // echo 'shippingchargesList:';
  2951.                             // print_r($shippingchargesList->getSqlQuery()); die;
  2952.                             // $dbConnection = \Pimcore\Db::get();
  2953.                             // $sql = "SELECT * from object_15 where `locationId__Id` = $locationId AND (minimum_order <= $order_amount AND maximum_order >= $order_amount)";
  2954.                             // // echo $sql = "SELECT * from object_15 where `locationId__Id` = $locationId AND minimum_order <=4 ";
  2955.                             // $stmt = \Pimcore\Db::get()->prepare($sql);
  2956.                             // // $stmt->bindParam(1, 101, \PDO::PARAM_INT);
  2957.                             // $stmt->execute();
  2958.                             // $result = $stmt->fetchAll();
  2959.                             // echo 'shippingcharges result:';
  2960.                             // print_r($result); die;
  2961.                             if(count($shippingchargesList)>0)
  2962.                             {
  2963.                                 foreach($shippingchargesList as $shippingchargeObj)
  2964.                                 {
  2965.                                     $minimum_order $shippingchargeObj->getminimum_order();
  2966.                                     $maximum_order $shippingchargeObj->getmaximum_order();
  2967.                                     $discount_percentage $shippingchargeObj->getdiscount_percentage();
  2968.                                     $shippingRules['shippingRuleId'] = $shippingchargeObj->getId();
  2969.                                     $shippingRules['minimum_order_amount'] = $minimum_order;
  2970.                                     $shippingRules['maximum_order_amount'] = $maximum_order;
  2971.                                     $shippingRules['discount_percentage'] = $discount_percentage;
  2972.                                 }
  2973.                                 $data[$ii]['shippingRules'] = $shippingRules;
  2974.                                 $rate_discount_perc = ($minimum_order <= $order_amount && $maximum_order >= $order_amount)?$discount_percentage:0;
  2975.                                 $final_cost $final_cost - (($final_cost*$rate_discount_perc)/100);
  2976.                             }
  2977.                             
  2978.                         }
  2979.                         $data[$ii]['final_cost'] = $final_cost;
  2980.                     } else $data[] = ['message'=>$message];
  2981.                     /*----------- End of Get Shipping rate data based on state code and weight cart ----------*/
  2982.                 } else $data[] = ['message'=>$message];
  2983.             }
  2984.         }
  2985.         return $this->json(["success" => true"data" => $data]);
  2986.     }
  2987.     /**
  2988.      * @Route("api/shippingrateslist", methods={"POST"})
  2989.      */
  2990.     public function shippingrateslistAction()
  2991.     {
  2992.         $reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
  2993.         $weight_cart = (isset($reqparams['weight_cart']))?$reqparams['weight_cart']:'';
  2994.         $req_weight_cart $weight_cart;
  2995.         $locationCode = (isset($reqparams['locationCode']))?$reqparams['locationCode']:'';
  2996.         $shipping_state_code = (isset($reqparams['shipping_state_code']))?$reqparams['shipping_state_code']:'';
  2997.         $pincode = (isset($reqparams['pincode']))?$reqparams['pincode']:'';
  2998.         $order_amount = (isset($reqparams['order_amount']))?$reqparams['order_amount']:'';
  2999.         if($weight_cart == '' || $locationCode == '' || $shipping_state_code == '' || $pincode == '' || $order_amount == '')
  3000.         {
  3001.             $data "weight_cart, locationCode, shipping_state_code, pincode and order_amount are mandatory!";
  3002.         } else {
  3003.             /*------ Get Shipping Rate Card Class data --------*/
  3004.             $dbConnection \Pimcore\Db::get();
  3005.             $shippingRatecardClassId $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Shippingratecards' ");
  3006.             $shippingRatecardObject "object_".$shippingRatecardClassId;
  3007.             // $shippingRatecardId = $dbConnection->fetchOne(" select * from object_12 order by abs(no_of_kgs - ".$weight_cart.")");
  3008.             $shippingRatecardId $dbConnection->fetchOne(" select * from ".$shippingRatecardObject." order by abs(no_of_kgs - ".$weight_cart.")");
  3009.             /*----- End of ---------*/
  3010.             /*---- Check Location by Location Code ---------*/
  3011.             $locData DataObject\Locations::getBylocation_code($locationCode1);
  3012.             $pincodeInfo DataObject\ItcAddPincode::getBypincode($pincode1);
  3013.             $stateInfo DataObject\States::getBystate_code($shipping_state_code1);
  3014.             $shipChargeInfo DataObject\Shippingratecards::getById($shippingRatecardId); //DataObject\Shippingratecards::getByno_of_kgs($weight_cart, 1);
  3015.             if(empty($locData) || empty($locData->getId()) || empty($pincodeInfo) || empty($pincodeInfo->getId()) || empty($shipChargeInfo) || empty($shipChargeInfo->getId()))// || empty($stateInfo) || empty($stateInfo->getId()) 
  3016.             {
  3017.                 if(empty($locData) || empty($locData->getId()))
  3018.                     $message "Location is not exited, please try with valid location code!";
  3019.                 
  3020.                 if(empty($pincodeInfo) || empty($pincodeInfo->getId()))
  3021.                     $message "Pincode is not exited, please try with valid pincode!";
  3022.             
  3023.                 if(empty($shipChargeInfo) || empty($shipChargeInfo->getId()))
  3024.                     $message "Shipping Charge is not exited for ".$weight_cart." Kgs, please try with valid No of Kgs!";
  3025.                 $data[] = ['message'=>$message];
  3026.             } else {
  3027.                 $locationId $locData->getId();
  3028.                 $locationName $locData->getLocation_name();
  3029.                 $message SELF::verifyauthToken();
  3030.                 if($message == "No data found")
  3031.                 {
  3032.                     /*------ Check Location is Up Country or not --------*/
  3033.                     $Is_location_up_country = (strpos(strtolower($locationName),"up country"))?1:0;
  3034.                     /*------ Get Settings Class, Object and ID data --------*/
  3035.                     $dbConnection \Pimcore\Db::get();
  3036.                     $settingsClassId $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Settings' ");
  3037.                     $settingsObject "object_".$settingsClassId;
  3038.                     $settingsObjectId $dbConnection->fetchOne("select * from ".$settingsObject." order by oo_id asc");
  3039.                     /*---- Get Settings Data ---------*/
  3040.                     $settingsData DataObject\Settings::getById($settingsObjectId);
  3041.                     // echo '<pre>settingsObjectId:'.$settingsObjectId;
  3042.                     // echo '<pre>settingsData:';
  3043.                     // print_r($settingsData->getis_deliveryfee_config_applicable());
  3044.                     $is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
  3045.                     $pincode_data['pincode'] = $pincodeInfo->getpincode();
  3046.                     $pincode_data['state'] = $pincodeInfo->getstate();
  3047.                     $pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
  3048.                     $pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
  3049.                     /*----------- End of Check Is Shipping Applicable or Not based on Pincode from Pincode Table ----------*/
  3050.                     /*------------- Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table------------*/
  3051.                     $final_cost=0$rate_discount_perc=0$cur_noofkgs $shipChargeInfo->getno_of_kgs();
  3052.                     $zone_name=(!empty($stateInfo) && $stateInfo->getZoneId())?$stateInfo->getZoneId()->getzone_name():'';
  3053.                     /*----------- End of Get Zone based on State Code from States Table ----------*/
  3054.                     /*------------- Get Shipping rate data based on state code and weight cart ------------*/
  3055.                     $shippingratesList DataObject\Shippingratecards::getList();
  3056.                     if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
  3057.                         $shippingratesList->filterByno_of_kgs($cur_noofkgs'=');
  3058.                     }
  3059.                     $shippingratesList->setOrderKey("no_of_kgs");
  3060.                     $shippingratesList->setOrder("desc");
  3061.                     $shippingratesList->load();
  3062.                     if(count($shippingratesList)>0){
  3063.                         $ii=0;
  3064.                         foreach ($shippingratesList as $key => $shippingrateObj) {
  3065.                             $data_key $data_val $data_key2 $data_val2 '';
  3066.                             $data[] = array(
  3067.                                 "id" => $shippingrateObj->getId(),
  3068.                                 "no_of_kgs" => $req_weight_cart,
  3069.                                 "inter_region_cost" => $shippingrateObj->getintera_region_cost(),
  3070.                                 "j_k_cost" => $shippingrateObj->getj_and_k_cost(),
  3071.                                 "ne_and_andaman_cost" => $shippingrateObj->getne_and_andaman()
  3072.                             );
  3073.                             
  3074.                             if($is_shippingapplicable == 'Yes')
  3075.                             {
  3076.                                 if($zone_name == 'J and K')
  3077.                                 {
  3078.                                     $final_cost $shippingrateObj->getj_and_k_cost();
  3079.                                 }
  3080.                                 else if($zone_name == 'NE and Andaman')
  3081.                                 {
  3082.                                     $final_cost $shippingrateObj->getne_and_andaman();  
  3083.                                 }
  3084.                                 else 
  3085.                                 {
  3086.                                     $final_cost $shippingrateObj->getintera_region_cost();
  3087.                                 }
  3088.                             }
  3089.                             $data[$ii]['locationCode'] = $locationCode;
  3090.                             $data[$ii]['pincode'] = $pincode_data;
  3091.                             
  3092.                         }
  3093.                         $minimum_order $maximum_order $discount_percentage 0$shippingRules = [];
  3094.                         
  3095.                         if($is_shippingapplicable == 'Yes')//&& $loc_code_error == ''
  3096.                         {
  3097.                             $shippingchargesList DataObject\Shippingcharges::getList();
  3098.                             $shippingchargesList->setCondition("locationId__Id = ? AND (minimum_order <= ? AND maximum_order >= ?)",[$locationId$order_amount$order_amount]);
  3099.                             $shippingchargesList->load();
  3100.                             if(count($shippingchargesList)>0)
  3101.                             {
  3102.                                 foreach($shippingchargesList as $shippingchargeObj)
  3103.                                 {
  3104.                                     $minimum_order $shippingchargeObj->getminimum_order();
  3105.                                     $maximum_order $shippingchargeObj->getmaximum_order();
  3106.                                     $discount_percentage $shippingchargeObj->getdiscount_percentage();
  3107.                                     $shippingRules['shippingRuleId'] = $shippingchargeObj->getId();
  3108.                                     $shippingRules['minimum_order_amount'] = $minimum_order;
  3109.                                     $shippingRules['maximum_order_amount'] = $maximum_order;
  3110.                                     $shippingRules['discount_percentage'] = $discount_percentage;
  3111.                                 }
  3112.                                 $data[$ii]['shippingRules'] = $shippingRules;
  3113.                                 $rate_discount_perc = ($minimum_order <= $order_amount && $maximum_order >= $order_amount)?$discount_percentage:0;
  3114.                                 $final_cost $final_cost - (($final_cost*$rate_discount_perc)/100);
  3115.                             }
  3116.                             
  3117.                         }
  3118.                         /*----------- Delivery Fee Configuration Condition --------------*/
  3119.                         if($settingsData->getis_deliveryfee_config_applicable() == 'Yes')
  3120.                         {
  3121.                             $stg_deliveryfee_config $settingsData->getdeliveryfee_config();
  3122.                             $stg_deliveryfee_config_location_lessthan_charge $settingsData->getdeliveryfee_config_location_lessthan_charge();
  3123.                             $stg_deliveryfee_config_location_greaterthanequal_charge $settingsData->getdeliveryfee_config_location_greaterthanequal_charge();
  3124.                             $stg_deliveryfee_config_upcountry_lessthan_charge $settingsData->getdeliveryfee_config_upcountry_lessthan_charge();
  3125.                             $stg_deliveryfee_config_upcountry_greaterthanequal_charge $settingsData->getdeliveryfee_config_upcountry_greaterthanequal_charge();
  3126.                             if($Is_location_up_country == && $order_amount $stg_deliveryfee_config && $stg_deliveryfee_config_location_lessthan_charge != -1$final_cost $stg_deliveryfee_config_location_lessthan_charge;
  3127.                             else if($Is_location_up_country == && $order_amount >= $stg_deliveryfee_config && $stg_deliveryfee_config_location_greaterthanequal_charge != -1$final_cost $stg_deliveryfee_config_location_greaterthanequal_charge;
  3128.                             else if($Is_location_up_country == && $order_amount $stg_deliveryfee_config && $stg_deliveryfee_config_upcountry_lessthan_charge != -1$final_cost $stg_deliveryfee_config_upcountry_lessthan_charge;
  3129.                             else if($Is_location_up_country == && $order_amount >= $stg_deliveryfee_config && $stg_deliveryfee_config_upcountry_greaterthanequal_charge != -1$final_cost $stg_deliveryfee_config_upcountry_greaterthanequal_charge;
  3130.                             else $final_cost $final_cost;
  3131.                         }
  3132.                         
  3133.                         $data[$ii]['final_cost'] = $final_cost;
  3134.                         // 2 hours fast delivery code
  3135.                         if($is_shippingapplicable == 'Yes')
  3136.                         {
  3137.                             $fdsett DataObject\FastDeliverySetting::getList();
  3138.                             $fdsett->setCondition("locationId__Id = ?",[$locationId]);
  3139.                             $fdsett->load();
  3140.                             $data[$ii]['platform_fee'] = 0;
  3141.                             $data[$ii]['low_order_fee'] = 0;
  3142.                             if(count($fdsett->getData()) > 0) {
  3143.                                 $fdsett $fdsett->getData()[0];
  3144.                                 $data[$ii]['platform_fee'] = $fdsett->getplatFormFee();
  3145.                                 $cartValue $fdsett->getcartValue();
  3146.                                 if($cartValue $order_amount) {
  3147.                                     $data[$ii]['low_order_fee'] = $fdsett->getminLowOrderFee();
  3148.                                 } else {
  3149.                                     $data[$ii]['low_order_fee'] = $fdsett->getlowOrderFee();
  3150.                                 }
  3151.                             }
  3152.                         }
  3153.                     } else $data[] = ['message'=>$message];
  3154.                     /*----------- End of Get Shipping rate data based on state code and weight cart ----------*/
  3155.                 } else $data[] = ['message'=>$message];
  3156.             }
  3157.         }
  3158.         return $this->json(["success" => true"data" => $data]);
  3159.     }
  3160.     /**
  3161.      * @Route("api/getfactorydata", methods={"POST"})
  3162.      */
  3163.     public function getfactorydataAction(Request $request)
  3164.     {
  3165.         $factorycode $request->get('factorycode');
  3166.         if($factorycode == "")
  3167.         {
  3168.             $data "Factory Code is mandatory!";
  3169.         } else 
  3170.         {
  3171.             $data SELF::verifyauthToken();
  3172.             if($data == "No data found")
  3173.             {
  3174.                 /*---- Check Factory by Code ---------*/
  3175.                 $factoryData DataObject\Factories::getBycode($factorycode1);
  3176.                 if(!empty($factoryData) && $factoryData->getId()){
  3177.                     $data = array(
  3178.                         "id" => $factoryData->getId(),
  3179.                         "code" => $factoryData->getCode(),
  3180.                         "name" => $factoryData->getname(),
  3181.                         "address" => $factoryData->getaddress(),
  3182.                         "street" => $factoryData->getstreet(),
  3183.                         "landmark" => $factoryData->getlandmark(),
  3184.                         "city" => $factoryData->getcity(),
  3185.                         "state" => $factoryData->getstate(),
  3186.                         "country" => $factoryData->getcountry(),
  3187.                         "pincode" => $factoryData->getpincode(),
  3188.                         "bestbefore" => $factoryData->getbestbefore());
  3189.                 } else {
  3190.                     $data "No data found!";
  3191.                 }
  3192.             }
  3193.         }
  3194.         return $this->json(["success" => true"data" => $data]);
  3195.     }
  3196.     /**
  3197.      * @Route("/api/allslots")
  3198.      */
  3199.     public function allslotsAction()
  3200.     {
  3201.         $delSlotTimesList DataObject\Deliveryslottimes::getList();
  3202.         $delSlotTimesList->load();
  3203.         // $delivery_modes = ['courier','standard','express'];
  3204.         // $slotsList = DataObject\Slots::getList();
  3205.         // $slotsList->setCondition("delivery_mode = 'courier'");
  3206.         // // if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  3207.         // //     $slotsList->filterBydelivery_mode($courier_mode, '=');
  3208.         // // }
  3209.         // $slotsList->load();
  3210.         // echo '<pre>kk'; print_r($slotsList); die;
  3211.         if(count($delSlotTimesList) > 0){
  3212.             foreach($delSlotTimesList as $delSlotTimes)
  3213.             {
  3214.                 $prepare_days $delSlotTimes->getprepare_days();
  3215.                 $delSlot_date date('Y-m-d H:i:s'strtotime(' +'.$prepare_days.' day'));
  3216.                 $delSlot_date1 date("Y-m-d");//date("Y-m-d", strtotime($delSlot_date));
  3217.                 $cur_time date("H:i");
  3218.                 // $delSlotTimes->delSlot_date = $delSlot_date;
  3219.                 $delivery_modes = ['courier','standard','express'];
  3220.                 $delivery_mode_slots_all = [];
  3221.                 foreach($delivery_modes as $delivery_mode)
  3222.                 {
  3223.                     $slotsList DataObject\Slots::getList();
  3224.                     // $slotsList->setCondition("delivery_mode = '".$delivery_mode."'");
  3225.                     if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
  3226.                         $slotsList->filterBySlotdate($delSlot_date1'>=');
  3227.                     }
  3228.                     // if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
  3229.                     //     $slotsList->filterByprior_time($cur_time, '>=');
  3230.                     // }
  3231.                     if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
  3232.                         $slotsList->filterBydelivery_mode($delivery_mode'>=');
  3233.                     }
  3234.                     $slotsList->setLimit(100);
  3235.                     $slotsList->setOrderKey("slotdate");
  3236.                     $slotsList->setOrder("asc");
  3237.                     $slotsList->load();
  3238.                     /*---------- Slots Loop Starts ----------*/
  3239.                     $delivery_mode_slots = [];
  3240.                     if(count($slotsList) > 0){
  3241.                         foreach($slotsList as $slot)
  3242.                         {
  3243.                             // $loc_name = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_name():'';
  3244.                             // $loc_code = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_code():'';
  3245.                             $slotLocationData DataObject\Locations::getById($slot->getLoc_id());
  3246.                             $loc_name $slotLocationData->getlocation_name();
  3247.                             $loc_code $slotLocationData->getlocation_code();
  3248.                             $delivery_mode_slot1 = array(
  3249.                                 "slotId" => $slot->getId(),
  3250.                                 "prior_time" => $slot->getprior_time(),
  3251.                                 // "picking_time" => $slot->getpicking_time(),
  3252.                                 // "charge" => $slot->getcharge(),
  3253.                                 "slotdate" => $slot->getslotdate(),
  3254.                                 "loc_name" => $loc_name,
  3255.                                 "loc_code" => $loc_code,
  3256.                                 "fromtime" => $slot->getfromtime(),
  3257.                                 "totime" => $slot->gettotime(),
  3258.                                 "maxorder" => $slot->getmaxorder(),
  3259.                                 "ordercount" => $slot->getordercount(),
  3260.                                 "delivery_mode" => $slot->getdelivery_mode()
  3261.                             );
  3262.                             array_push($delivery_mode_slots$delivery_mode_slot1);
  3263.                         }
  3264.                     }
  3265.                     /*---------- Slots Loop Starts ----------*/
  3266.                     $delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
  3267.                     // array_push($delivery_mode_slots_all, $delivery_mode_slot2);
  3268.                     $delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
  3269.                 }
  3270.                 $data[] = array(
  3271.                     "deliverytype_id" => $delSlotTimes->gettitle(),
  3272.                     "label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
  3273.                     "prepare_days" => $delSlotTimes->getprepare_days(),
  3274.                     "delSlot_date" => $delSlot_date,
  3275.                     "slots"=>$delivery_mode_slots_all);
  3276.             }
  3277.         } else $data[] = [];
  3278.         return $this->json(["success" => true"data" => $data]);
  3279.     }
  3280.     
  3281. }