src/Controller/DeliveryslotapiController.php line 3447

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