src/Controller/DeliveryslotapiController.php line 17

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