<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use symfony\Component\Routing\Annotation\Route;
use Pimcore\Model\DataObject;
use Pimcore\Model\Asset\Service;
use Pimcore\Model\DataObject\Service as DoService;
use Carbon\Carbon;
use Pimcore\Model\User;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class DeliveryslotapiController extends FrontendController
{
/**
* @Route("/deliveryslots/list")
*/
public function listAction()
{
$today_date = strtotime("Y-m-d");
$cur_time = date("H:i");
$slotsList = DataObject\Slots::getList();
$slotsList->setCondition("slotdate >= ? AND prior_time >= ?",[$today_date, $cur_time]);
// $slotsList->setOffset(0);
$slotsList->setLimit(100);
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("desc");
$slotsList->load();
// $slotsList = DataObject\Slots::getList();
// $slotsList->setOffset(0);
// $slotsList->setLimit(10);
// $slotsList->load();
// if(count($slotsList) > 0){
foreach ($slotsList as $key => $blog) {
// $location_code = $blog->getlocation_code()->getlocation_code();
$location_code = (!empty($blog->getloc_id()) && $blog->getloc_id())?$blog->getloc_id()->getlocation_code():'';
$loc_name = (!empty($blog->getloc_id()) && $blog->getloc_id())?$blog->getloc_id()->getlocation_name():'';
// foreach($location_codes as $location_code){
// $loc_name = $location_code->getlocation_name();
// }
$data[] = array(
"slotId" => $blog->getId(),
"prior_time" => $blog->getprior_time(),
"picking_time" => $blog->getpicking_time(),
"location_code" => $location_code,
"loc_name" => $loc_name,
"charge" => $blog->getcharge(),
"slotdate" => $blog->getslotdate(),
"fromtime" => $blog->getfromtime(),
"totime" => $blog->gettotime(),
"maxorder" => $blog->getmaxorder(),
"ordercount" => $blog->getordercount(),
"delivery_mode" => $blog->getdelivery_mode());
}
// } else $data[] = [];
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/holidays/getlist")
*/
public function getlistAction()
{
$slotsList = DataObject\Holidays::getList();
$slotsList->load();
if(count($slotsList) > 0){
foreach ($slotsList as $key => $blog) {
$location_codes = $blog->getlocation_code();
$loc_name = '';
foreach($location_codes as $location_code){
$loc_name .= $location_code->getlocation_name().' ';
}
$data[] = array(
"name" => $blog->getname(),
"loc_name" => $loc_name,
"holidaydate" => $blog->getHolidaydate());
}
} else $data[] = [];
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
public function generateObjFolder($folderName,$location_code){
$yr = date("Y");
$mt = date("M");
$dy = date("d");
$path = "/".$folderName."/".$yr."/".$mt."/".$dy;
$path = "/".$folderName."/".$location_code;
$object = DataObject::getByPath($path);
if(!$object){
$path1 = "/".$folderName."/".$yr."/".$mt;
$object1 = DataObject::getByPath($path1);
if(!$object1){
$path2 = "/".$folderName."/".$yr;
$object2 = DataObject::getByPath($path2);
if(!$object2){
$path3 = "/".$folderName;
$object3 = DataObject::getByPath($path3);
if(!$object3){
$createAssetFolder = DoService::createFolderByPath($path3);
$createAssetFolder = DoService::createFolderByPath($path2);
$createAssetFolder = DoService::createFolderByPath($path1);
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}else {
$createAssetFolder = DoService::createFolderByPath($path2);
$createAssetFolder = DoService::createFolderByPath($path1);
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}
}else {
$createAssetFolder = DoService::createFolderByPath($path1);
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}
} else {
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}
} else
$objParentId = $object->getId();
return $objParentId;
}
public function generateSlotObjFolder($folderName,$delivery_mode,$location_code){
$yr = date("Y");
$mt = date("M");
$dy = date("d");
$path = "/".$folderName."/".$delivery_mode."/".$location_code;//."/".$date.'-'.$location_code;
$object = DataObject::getByPath($path);
if(!$object){
$path1 = "/".$folderName."/".$delivery_mode;//."/".$location_code."/".$date;
$object1 = DataObject::getByPath($path1);
if(!$object1){
$path2 = "/".$folderName;//."/".$delivery_mode."/".$location_code;
$object2 = DataObject::getByPath($path2);
if(!$object2){
$createAssetFolder = DoService::createFolderByPath($path2);
$createAssetFolder = DoService::createFolderByPath($path1);
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}else {
$createAssetFolder = DoService::createFolderByPath($path1);
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}
} else {
$createAssetFolder = DoService::createFolderByPath($path);
$objParentId = $createAssetFolder->getId();
}
} else
$objParentId = $object->getId();
return $objParentId;
}
/**
* @Route("/deliveryslots/save", methods={"POST"})
*/
public function saveAction(Request $request)
{
$prior_time = $request->get('prior_time');
$location_code = $request->get('location_code');
// $location_codes[] = $location_code;
$picking_time = $request->get('picking_time');
$delivery_mode = $request->get('delivery_mode');
$charge = $request->get('charge');
$date = $request->get('slotdate');
$message = "No data found";
if($prior_time == "" || $location_code == "" || $picking_time == "" || $delivery_mode == "" || $charge == "" || $date == "")
{
$message = "Prior Time, Location Code, Picking Time, Delivery Mode, Charge and Date are mandatory!";
} else {
/*---- Check Location by Location Code ---------*/
$locData = DataObject\Locations::getBylocation_code($location_code, 1);
// echo $locData->getId(); die;
if(empty($locData) || empty($locData->getId()))
{
$message = "Location is not exited, please try with valid location code!";
} else {
$loc_id = $locData->getId();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
$slotObjectName = $date.'-'.$loc_id.'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
$slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
$slotObject->setSlotdate($dates);
$slotObject->setloc_id(DataObject\Locations::getById($loc_id));
$slotObject->setCharge($charge);
$slotObject->setPublished(true);
$slotObject->save();
$message = 'Slot Created Successfully';
}
}
return $this->json(["success" => true, "data" => $message]);
}
public function getWeekDates1($holidaysList, $todaydate){
$jj=0; $weekdates = [];
for($ii=1; $ii<15; $ii++)
{
if($jj >= 7) break;
if(empty($holidaysList) || !in_array($todaydate, $holidaysList)){
$weekdates[] = $todaydate;
$jj=$jj+1;
}
$todaydate = date('Y-m-d', strtotime($todaydate . ' +1 day'));
}
// echo '<pre>'; print_r($weekdates); die;
return $weekdates;
}
public function getWeekDates2($holidaysList, $todaydate, $delSlotTimesAvailibility){
$jj=0; $weekdates = [];
$slot_generate_days = $delSlotTimesAvailibility['slot_generate_days'];
$saturday_slot_availability = $delSlotTimesAvailibility['saturday_slot_availability'];
$sunday_slot_availability = $delSlotTimesAvailibility['sunday_slot_availability'];
$totDays = $slot_generate_days+7;
for($ii=1; $ii<$totDays; $ii++)
{
if($jj >= $slot_generate_days) break;
if(empty($holidaysList) || !in_array($todaydate, $holidaysList)){
$weekDay = date('w', strtotime($todaydate));
if(($weekDay == 0 && $sunday_slot_availability == 'Yes') || ($weekDay == 6 && $saturday_slot_availability == 'Yes') || !in_array($weekDay, [0,6]))
{
$weekdates[] = $todaydate;
$jj=$jj+1;
}
}
$todaydate = date('Y-m-d', strtotime($todaydate . ' +1 day'));
}
// echo '<pre>'; print_r($weekdates); die;
return $weekdates;
}
public function getWeekDates($holidaysList, $todaydate, $delSlotTimesAvailibility){
$jj=0; $weekdates = [];
$slot_prepare_days = $delSlotTimesAvailibility['slot_prepare_days'];
$slot_generate_days = $delSlotTimesAvailibility['slot_generate_days'];
$saturday_slot_availability = $delSlotTimesAvailibility['saturday_slot_availability'];
$sunday_slot_availability = $delSlotTimesAvailibility['sunday_slot_availability'];
$todaydate = date('Y-m-d', strtotime($todaydate . ' +'.$slot_prepare_days.' day'));
$totDays = $slot_generate_days+7;
for($ii=1; $ii<$totDays; $ii++)
{
if($jj >= $slot_generate_days) break;
if(empty($holidaysList) || !in_array($todaydate, $holidaysList)){
$weekDay = date('w', strtotime($todaydate));
if(($weekDay == 0 && $sunday_slot_availability == 'Yes') || ($weekDay == 6 && $saturday_slot_availability == 'Yes') || !in_array($weekDay, [0,6]))
{
$weekdates[] = $todaydate;
$jj=$jj+1;
}
}
$todaydate = date('Y-m-d', strtotime($todaydate . ' +1 day'));
}
// echo '<pre>'; print_r($weekdates); die;
return $weekdates;
}
/**
* @Route("/deliveryslots/saveslots1")
*/
public function saveslots1Action()
{
// echo 'kk'; die;
$locationsList = DataObject\Locations::getList();
$locationsList->load();
foreach($locationsList as $location)//Start of Locations Loop
{
//echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
$location_id = $location->getId();
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
// echo '<pre>'; print_r($holidayDates);
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"));
//echo '<pre>weekdates:'; print_r($weekdates);
foreach($weekdates as $weekdate)
{
$slotsList = DataObject\Deliveryslotrules::getList();
$slotsList->setCondition("location_code like '%,".$location_id.",%'");
$slotsList->load();
//echo '<br>slotsList Count:'.count($slotsList);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$prior_time = $slot->getprior_time();
$location_codes = $slot->getlocation_code();
$picking_time = $slot->getpicking_time();
$delivery_mode = $slot->getdelivery_mode();
$charge = $slot->getcharge();
$fromtime = $slot->getfromtime();
$totime = $slot->gettotime();
$maxorder = $slot->getmaxorder();
// $ordercount = $slot->getordercount();
$date = $weekdate;//$slot->getslotdate();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$location_code_array = [];
//echo '<pre>location_codes Count:'.count($location_codes);
foreach($location_codes as $location_code){//Location Code loop Starts
if($location_id == $location_code->getId())
{
$location_code_array[] = DataObject\Locations::getById($location_code->getId());
$location_code_id = DataObject\Locations::getById($location_code->getId());
$loc_id = $location_code->getId();
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
/*------------ Checking the slot data -------------*/
$slotCheck = 1;
$today_date = date("Y-m-d", strtotime($weekdate));
$cur_time = $prior_time;
$checkDataList = DataObject\Slots::getList();
if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$checkDataList->filterBySlotdate($today_date, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$checkDataList->filterByprior_time($cur_time, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$checkDataList->filterBydelivery_mode($delivery_mode, '=');
}
// $checkDataList->setCondition("loc_id__id = ".$loc_id);
// $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
$checkDataList->setLimit(100);
$checkDataList->setOrderKey("slotdate");
$checkDataList->setOrder("asc");
$checkDataList->load();
//echo '<br>checkDataList Count:'.count($checkDataList);
$checkData_loc_valid = 0; $checkData_locs = [];
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
$checkData_locData = $checkData->getloc_id();
$checkData_locId = $checkData_locData->getId();
array_push($checkData_locs, $checkData_locId);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
// echo '<br>checkData_locId:'.$checkData_locId;
// echo '<pre>checkData_locs:';
// print_r($checkData_locs);
// echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
/*------------ End of Checking the slot data -------------*/
if($checkData_loc_valid == 1){
// $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
// $holidayObjectName = $location_code.'-'.$name;
$slotObjectName = $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
$slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
// $slotObject->setSlotdate($date2);
$slotObject->setSlotdate($dates);
$slotObject->setfromtime($fromtime);
$slotObject->settotime($totime);
$slotObject->setmaxorder($maxorder);
// $slotObject->setLocation_code($location_code_array);
$slotObject->setCharge($charge);
$slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
$slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
$slotObject->setPublished(true);
$slotObject->save();
}
}
}
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
// }
}//End of Locations Loop
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
/**
* @Route("/deliveryslots/saveslots2")
*/
public function saveslots2Action()
{
// echo 'kk'; die;
$locationsList = DataObject\Locations::getList();
$locationsList->load();
foreach($locationsList as $location)//Start of Locations Loop
{
//echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
$location_id = $location->getId();
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
// echo '<pre>'; print_r($holidayDates);
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
$slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
$slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
$saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
$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];
// echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility);
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo '<pre>weekdates:'; print_r($weekdates);
foreach($weekdates as $weekdate)
{
$slotsList = DataObject\Deliveryslotrules::getList();
$slotsList->setCondition("location_code like '%,".$location_id.",%'");
$slotsList->load();
//echo '<br>slotsList Count:'.count($slotsList);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$prior_time = $slot->getprior_time();
$location_codes = $slot->getlocation_code();
$picking_time = $slot->getpicking_time();
$delivery_mode = $slot->getdelivery_mode();
$charge = $slot->getcharge();
$fromtime = $slot->getfromtime();
$totime = $slot->gettotime();
$maxorder = $slot->getmaxorder();
// $ordercount = $slot->getordercount();
$date = $weekdate;//$slot->getslotdate();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$location_code_array = [];
//echo '<pre>location_codes Count:'.count($location_codes);
foreach($location_codes as $location_code){//Location Code loop Starts
if($location_id == $location_code->getId())
{
$location_code_array[] = DataObject\Locations::getById($location_code->getId());
$location_code_id = DataObject\Locations::getById($location_code->getId());
$loc_id = $location_code->getId();
/*----------- Delivery Slot Times Loop Starts --------*/
// $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
// $deliveryslottimesList->load();
// //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
// if(count($deliveryslottimesList)>0)
// {
// foreach($deliveryslottimesList as $deliveryslottimes)
// {
/*------------ Checking the slot data -------------*/
$slotCheck = 1;
$today_date = date("Y-m-d", strtotime($weekdate));
$cur_time = $prior_time;
$checkDataList = DataObject\Slots::getList();
if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$checkDataList->filterBySlotdate($today_date, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$checkDataList->filterByprior_time($cur_time, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$checkDataList->filterBydelivery_mode($delivery_mode, '=');
}
// $checkDataList->setCondition("loc_id__id = ".$loc_id);
// $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
$checkDataList->setLimit(100);
$checkDataList->setOrderKey("slotdate");
$checkDataList->setOrder("asc");
$checkDataList->load();
//echo '<br>checkDataList Count:'.count($checkDataList);
$checkData_loc_valid = 0; $checkData_locs = [];
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
$checkData_locData = $checkData->getloc_id();
$checkData_locId = $checkData_locData->getId();
array_push($checkData_locs, $checkData_locId);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
// echo '<br>checkData_locId:'.$checkData_locId;
// echo '<pre>checkData_locs:';
// print_r($checkData_locs);
// echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
/*------------ End of Checking the slot data -------------*/
if($checkData_loc_valid == 1){
// $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
// $holidayObjectName = $location_code.'-'.$name;
$slotObjectName = $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
$slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
// $slotObject->setSlotdate($date2);
$slotObject->setSlotdate($dates);
$slotObject->setfromtime($fromtime);
$slotObject->settotime($totime);
$slotObject->setmaxorder($maxorder);
// $slotObject->setLocation_code($location_code_array);
$slotObject->setCharge($charge);
$slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
$slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
$slotObject->setPublished(true);
$slotObject->save();
}
// }
// }
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
}
}
// }
}//End of Locations Loop
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
/**
* @Route("/deliveryslots/saveslots3")
*/
public function saveslots3Action()
{
// echo 'kk'; die;
$locationsList = DataObject\Locations::getList();
$locationsList->load();
foreach($locationsList as $location)//Start of Locations Loop
{
//echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
$location_id = $location->getId();
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
// echo '<pre>'; print_r($holidayDates);
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
// echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
$slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
$slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
$saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
$slot_generate_days = $slot_generate_days+1;
$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];
// echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo '<pre>weekdates:'; print_r($weekdates);
foreach($weekdates as $weekdate)
{
$slotsList = DataObject\Deliveryslotrules::getList();
// $slotsList->setCondition("location_code like '%,".$location_id.",%'");
$slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
$slotsList->load();
//echo '<br>slotsList Count:'.count($slotsList);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$prior_time = $slot->getprior_time();
$location_codes = $slot->getlocation_ids();//$slot->getlocation_code();
// $picking_time = $slot->getpicking_time();
$delivery_mode = $slot->getdelivery_mode();
// $charge = $slot->getcharge();
$fromtime = $slot->getfromtime();
$totime = $slot->gettotime();
$maxorder = $slot->getmaxorder();
// $ordercount = $slot->getordercount();
$date = $weekdate;//$slot->getslotdate();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$location_code_array = [];
// echo '<pre>location_codes Count:'.count($location_codes);
if(!empty($location_codes))
{
foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
if($location_id == $location_id_info)//if($location_id == $location_code->getId())
{
// $location_code_array[] = DataObject\Locations::getById($location_code->getId());
// $location_code_id = DataObject\Locations::getById($location_code->getId());
// $loc_id = $location_code->getId();
$location_code_array[] = DataObject\Locations::getById($location_id_info);
$location_code_id = DataObject\Locations::getById($location_id_info);
$loc_id = $location_id_info;
/*----------- Delivery Slot Times Loop Starts --------*/
// $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
// $deliveryslottimesList->load();
// //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
// if(count($deliveryslottimesList)>0)
// {
// foreach($deliveryslottimesList as $deliveryslottimes)
// {
/*------------ Checking the slot data -------------*/
$slotCheck = 1;
$today_date = date("Y-m-d", strtotime($weekdate));
$cur_time = $prior_time;
$checkDataList = DataObject\Slots::getList();
if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$checkDataList->filterBySlotdate($today_date, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$checkDataList->filterByprior_time($cur_time, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$checkDataList->filterBydelivery_mode($delivery_mode, '=');
}
// $checkDataList->setCondition("loc_id__id = ".$loc_id);
// $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
$checkDataList->setLimit(100);
$checkDataList->setOrderKey("slotdate");
$checkDataList->setOrder("asc");
$checkDataList->load();
//echo '<br>checkDataList Count:'.count($checkDataList);
$checkData_loc_valid = 0; $checkData_locs = [];
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
// $checkData_locData = $checkData->getloc_id();
// $checkData_locId = $checkData_locData->getId();
$checkData_locId = $checkData->getloc_id();
array_push($checkData_locs, $checkData_locId);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
// echo '<br>checkData_locId:'.$checkData_locId;
// echo '<pre>checkData_locs:';
// print_r($checkData_locs);
// echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
/*------------ End of Checking the slot data -------------*/
if($checkData_loc_valid == 1){
// $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
// $holidayObjectName = $location_code.'-'.$name;
$slotObjectName = $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
// $slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
// $slotObject->setSlotdate($date2);
$slotObject->setSlotdate($dates);
$slotObject->setfromtime($fromtime);
$slotObject->settotime($totime);
$slotObject->setmaxorder($maxorder);
// $slotObject->setLocation_code($location_code_array);
// $slotObject->setCharge($charge);
$slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
$slotObject->setloc_id($location_id_info);
$slotObject->setPublished(true);
$slotObject->save();
}
// }
// }
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
}
}
}
// }
}//End of Locations Loop
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
/**
* @Route("/deliveryslots/saveslots4")
*/
public function saveslots4Action()
{
$locationsList = DataObject\Locations::getList();
$locationsList->load();
foreach($locationsList as $location)//Start of Locations Loop
{
//echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
$location_id = $location->getId();
$locationName = $location->getLocation_name();
$locationCode = $location->getLocation_code();
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($locationName),"up country") || strpos(strtoupper($locationCode),"UPCTR"))?1:0;
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
// echo '<pre>'; print_r($holidayDates);
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
// echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
$slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
$slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
$saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
$slot_generate_days = $slot_generate_days+1;
/*--------------------- Up Country Configuration ------------------------*/
$is_upcountry_configuration_applicable = ($deliveryslottimes->getis_upcountry_configuration_applicable())?$deliveryslottimes->getis_upcountry_configuration_applicable():'No';
$slot_upcountry_prepare_days = ($deliveryslottimes->getupcountry_prepare_days())?$deliveryslottimes->getupcountry_prepare_days():0;
$upcountry_slot_generate_days = ($deliveryslottimes->getupcountry_slot_generate_days())?$deliveryslottimes->getupcountry_slot_generate_days():7;
$upcountry_saturday_slot_availability = ($deliveryslottimes->getupcountry_saturday_slot_availability())?$deliveryslottimes->getupcountry_saturday_slot_availability():'No';
$upcountry_sunday_slot_availability = ($deliveryslottimes->getupcountry_sunday_slot_availability())?$deliveryslottimes->getupcountry_sunday_slot_availability():'No';
$upcountry_slot_generate_days = $upcountry_slot_generate_days+1;
if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
$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];
else
$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];
// echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo '<pre>weekdates:'; print_r($weekdates);
foreach($weekdates as $weekdate)
{
$slotsList = DataObject\Deliveryslotrules::getList();
// $slotsList->setCondition("location_code like '%,".$location_id.",%'");
$slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
$slotsList->load();
//echo '<br>slotsList Count:'.count($slotsList);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$prior_time = $slot->getprior_time();
$location_codes = $slot->getlocation_ids();//$slot->getlocation_code();
// $picking_time = $slot->getpicking_time();
$delivery_mode = $slot->getdelivery_mode();
// $charge = $slot->getcharge();
$fromtime = $slot->getfromtime();
$totime = $slot->gettotime();
$maxorder = $slot->getmaxorder();
// $ordercount = $slot->getordercount();
$date = $weekdate;//$slot->getslotdate();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$location_code_array = [];
// echo '<pre>location_codes Count:'.count($location_codes);
if(!empty($location_codes))
{
foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
if($location_id == $location_id_info)//if($location_id == $location_code->getId())
{
// $location_code_array[] = DataObject\Locations::getById($location_code->getId());
// $location_code_id = DataObject\Locations::getById($location_code->getId());
// $loc_id = $location_code->getId();
$location_code_array[] = DataObject\Locations::getById($location_id_info);
$location_code_id = DataObject\Locations::getById($location_id_info);
$loc_id = $location_id_info;
/*----------- Delivery Slot Times Loop Starts --------*/
// $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
// $deliveryslottimesList->load();
// //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
// if(count($deliveryslottimesList)>0)
// {
// foreach($deliveryslottimesList as $deliveryslottimes)
// {
/*------------ Checking the slot data -------------*/
$slotCheck = 1;
$today_date = date("Y-m-d", strtotime($weekdate));
$cur_time = $prior_time;
$checkDataList = DataObject\Slots::getList();
if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$checkDataList->filterBySlotdate($today_date, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$checkDataList->filterByprior_time($cur_time, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$checkDataList->filterBydelivery_mode($delivery_mode, '=');
}
// $checkDataList->setCondition("loc_id__id = ".$loc_id);
// $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
$checkDataList->setLimit(100);
$checkDataList->setOrderKey("slotdate");
$checkDataList->setOrder("asc");
$checkDataList->load();
//echo '<br>checkDataList Count:'.count($checkDataList);
$checkData_loc_valid = 0; $checkData_locs = [];
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
// $checkData_locData = $checkData->getloc_id();
// $checkData_locId = $checkData_locData->getId();
$checkData_locId = $checkData->getloc_id();
array_push($checkData_locs, $checkData_locId);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
// echo '<br>checkData_locId:'.$checkData_locId;
// echo '<pre>checkData_locs:';
// print_r($checkData_locs);
// echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
/*------------ End of Checking the slot data -------------*/
if($checkData_loc_valid == 1){
// $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
// $holidayObjectName = $location_code.'-'.$name;
$slotObjectName = $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
// $slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
// $slotObject->setSlotdate($date2);
$slotObject->setSlotdate($dates);
$slotObject->setfromtime($fromtime);
$slotObject->settotime($totime);
$slotObject->setmaxorder($maxorder);
// $slotObject->setLocation_code($location_code_array);
// $slotObject->setCharge($charge);
$slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
$slotObject->setloc_id($location_id_info);
$slotObject->setPublished(true);
$slotObject->save();
}
// }
// }
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
}
}
}
// }
}//End of Locations Loop
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
public function getSettingInfo()
{
/*------ Get Settings Class data --------*/
$dbConnection = \Pimcore\Db::get();
$settingsClassId = $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Settings' ");
$settingsObject = "object_".$settingsClassId;
$settingsId = $dbConnection->fetchOne(" select * from ".$settingsObject." WHERE setting_flag = 1");
/*----- End of Get Settings Class data ---------*/
/*--------------- Settings info ----------------*/
$settingsInfo = DataObject\Settings::getById($settingsId);
$settingDataId = $settingsInfo->getId();
$setting_deliveryModes = $settingsInfo->getdelivery_modes();
$setting_slot_time_flag = (!empty($settingsInfo->getslottime()))?$settingsInfo->getslottime():"18:00";
$stg_deliveryslot_config_is_upcountry_configuration_applicable = ($settingsInfo->getdeliveryslot_config_is_upcountry_configuration_applicable())?$settingsInfo->getdeliveryslot_config_is_upcountry_configuration_applicable():'No';
$stg_delslot_normalloc_morethan_fromtime = ($settingsInfo->getdelslot_normalloc_morethan_fromtime())?$settingsInfo->getdelslot_normalloc_morethan_fromtime():"00:00";
$stg_delslot_normalloc_lessthaneq_totime = ($settingsInfo->getdelslot_normalloc_lessthaneq_totime())?$settingsInfo->getdelslot_normalloc_lessthaneq_totime():"18:00";
$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;
$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;
$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;
$stg_delslot_upcountryloc_morethan_fromtime = ($settingsInfo->getdelslot_upcountryloc_morethan_fromtime())?$settingsInfo->getdelslot_upcountryloc_morethan_fromtime():"00:00";
$stg_delslot_upcountryloc_lessthaneq_totime = ($settingsInfo->getdelslot_upcountryloc_lessthaneq_totime())?$settingsInfo->getdelslot_upcountryloc_lessthaneq_totime():"11:00";
$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;
$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;
$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;
$stg_is_deliveryfee_config_applicable = $settingsInfo->getis_deliveryfee_config_applicable();
$stg_deliveryfee_config = $settingsInfo->getdeliveryfee_config();
$stg_deliveryfee_config = $settingsInfo->getdeliveryfee_config();
$stg_deliveryfee_config_location_lessthan_charge = $settingsInfo->getdeliveryfee_config_location_lessthan_charge();
$stg_deliveryfee_config_location_greaterthanequal_charge = $settingsInfo->getdeliveryfee_config_location_greaterthanequal_charge();
$stg_deliveryfee_config_upcountry_lessthan_charge = $settingsInfo->getdeliveryfee_config_upcountry_lessthan_charge();
$stg_deliveryfee_config_upcountry_greaterthanequal_charge = $settingsInfo->getdeliveryfee_config_upcountry_greaterthanequal_charge();
/*----------- End of Settings Info -------------*/
$settingsdata = ['settingDataId'=>$settingDataId,
'setting_deliveryModes'=>$setting_deliveryModes,
'setting_slot_time_flag'=>$setting_slot_time_flag,
'stg_deliveryslot_config_is_upcountry_configuration_applicable'=>$stg_deliveryslot_config_is_upcountry_configuration_applicable,
'stg_delslot_normalloc_morethan_fromtime'=>$stg_delslot_normalloc_morethan_fromtime,
'stg_delslot_normalloc_lessthaneq_totime'=>$stg_delslot_normalloc_lessthaneq_totime,
'stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays'=>$stg_delslot_normalloc_bw_from_to_time_extra_generate_slotdays,
'stg_delslot_normalloc_after_totime_extra_generate_slotdays'=>$stg_delslot_normalloc_after_totime_extra_generate_slotdays,
'stg_normalloc_slot_generate_days'=>$stg_normalloc_slot_generate_days,
'stg_delslot_upcountryloc_morethan_fromtime'=>$stg_delslot_upcountryloc_morethan_fromtime,
'stg_delslot_upcountryloc_lessthaneq_totime'=>$stg_delslot_upcountryloc_lessthaneq_totime,
'stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays'=>$stg_delslot_upcountryloc_bw_from_to_time_extra_generate_slotdays,
'stg_delslot_upcountryloc_after_totime_extra_generate_slotdays'=>$stg_delslot_upcountryloc_after_totime_extra_generate_slotdays,
'stg_upcountryloc_slot_generate_days'=>$stg_upcountryloc_slot_generate_days,
'stg_is_deliveryfee_config_applicable'=>$stg_is_deliveryfee_config_applicable,
'stg_deliveryfee_config'=>$stg_deliveryfee_config,
'stg_deliveryfee_config_location_lessthan_charge'=>$stg_deliveryfee_config_location_lessthan_charge,
'stg_deliveryfee_config_location_greaterthanequal_charge'=>$stg_deliveryfee_config_location_greaterthanequal_charge,
'stg_deliveryfee_config_upcountry_lessthan_charge'=>$stg_deliveryfee_config_upcountry_lessthan_charge,
'stg_deliveryfee_config_upcountry_greaterthanequal_charge'=>$stg_deliveryfee_config_upcountry_greaterthanequal_charge,
];
return $settingsdata;
}
/**
* @Route("/deliveryslots/saveslots")
*/
public function saveslotsAction()
{
/*--------------- Settings info ----------------*/
$settingsInfo = SELF::getSettingInfo();
/*----------- End of Settings Info -------------*/
// echo 'settingsInfo:<pre>';
// echo $settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'];
// print_r($settingsInfo); die;
$locationsList = DataObject\Locations::getList();
$locationsList->load();
foreach($locationsList as $location)//Start of Locations Loop
{
//echo "<br>Id:".$location->getId()."|Location Name:".$location->getLocation_name()."|Location Code:".$location->getLocation_code();
$location_id = $location->getId();
$locationName = $location->getLocation_name();
$locationCode = $location->getLocation_code();
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($locationName),"up country") || strpos(strtoupper($locationCode),"UPCTR"))?1:0;
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
// echo '<pre>'; print_r($holidayDates);
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
// echo '<pre>deliveryslottimes:'; print_r($deliveryslottimes); //die;
$slot_prepare_days = ($deliveryslottimes->getprepare_days())?$deliveryslottimes->getprepare_days():0;
$slot_generate_days = ($deliveryslottimes->getslot_generate_days())?$deliveryslottimes->getslot_generate_days():7;
$saturday_slot_availability = ($deliveryslottimes->getsaturday_slot_availability())?$deliveryslottimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($deliveryslottimes->getsunday_slot_availability())?$deliveryslottimes->getsunday_slot_availability():'No';
$slot_generate_days = $slot_generate_days+$settingsInfo['stg_normalloc_slot_generate_days'];
/*--------------------- Up Country Configuration ------------------------*/
$is_upcountry_configuration_applicable = ($deliveryslottimes->getis_upcountry_configuration_applicable())?$deliveryslottimes->getis_upcountry_configuration_applicable():'No';
$slot_upcountry_prepare_days = ($deliveryslottimes->getupcountry_prepare_days())?$deliveryslottimes->getupcountry_prepare_days():0;
$upcountry_slot_generate_days = ($deliveryslottimes->getupcountry_slot_generate_days())?$deliveryslottimes->getupcountry_slot_generate_days():7;
$upcountry_saturday_slot_availability = ($deliveryslottimes->getupcountry_saturday_slot_availability())?$deliveryslottimes->getupcountry_saturday_slot_availability():'No';
$upcountry_sunday_slot_availability = ($deliveryslottimes->getupcountry_sunday_slot_availability())?$deliveryslottimes->getupcountry_sunday_slot_availability():'No';
$upcountry_slot_generate_days = $upcountry_slot_generate_days+$settingsInfo['stg_upcountryloc_slot_generate_days'];
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)
$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];
else
$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];
// echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo '<pre>weekdates:'; print_r($weekdates);
foreach($weekdates as $weekdate)
{
$slotsList = DataObject\Deliveryslotrules::getList();
// $slotsList->setCondition("location_code like '%,".$location_id.",%'");
$slotsList->setCondition("location_ids IS NOT NULL AND location_ids like '%,".$location_id.",%'");
$slotsList->load();
//echo '<br>slotsList Count:'.count($slotsList);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$prior_time = $slot->getprior_time();
$location_codes = $slot->getlocation_ids();//$slot->getlocation_code();
// $picking_time = $slot->getpicking_time();
$delivery_mode = $slot->getdelivery_mode();
// $charge = $slot->getcharge();
$fromtime = $slot->getfromtime();
$totime = $slot->gettotime();
$maxorder = $slot->getmaxorder();
// $ordercount = $slot->getordercount();
$date = $weekdate;//$slot->getslotdate();
$date2 = date("m/d/y", strtotime($date));
$dates = Carbon::createFromFormat('m/d/y', $date2);
$location_code_array = [];
// echo '<pre>location_codes Count:'.count($location_codes);
if(!empty($location_codes))
{
foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
if($location_id == $location_id_info)//if($location_id == $location_code->getId())
{
// $location_code_array[] = DataObject\Locations::getById($location_code->getId());
// $location_code_id = DataObject\Locations::getById($location_code->getId());
// $loc_id = $location_code->getId();
$location_code_array[] = DataObject\Locations::getById($location_id_info);
$location_code_id = DataObject\Locations::getById($location_id_info);
$loc_id = $location_id_info;
/*----------- Delivery Slot Times Loop Starts --------*/
// $deliveryslottimesList = DataObject\Deliveryslottimes::getList();
// $deliveryslottimesList->load();
// //echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
// if(count($deliveryslottimesList)>0)
// {
// foreach($deliveryslottimesList as $deliveryslottimes)
// {
/*------------ Checking the slot data -------------*/
$slotCheck = 1;
$today_date = date("Y-m-d", strtotime($weekdate));
$cur_time = $prior_time;
$checkDataList = DataObject\Slots::getList();
if ($checkDataList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$checkDataList->filterBySlotdate($today_date, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$checkDataList->filterByprior_time($cur_time, '=');
}
if ($checkDataList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$checkDataList->filterBydelivery_mode($delivery_mode, '=');
}
// $checkDataList->setCondition("loc_id__id = ".$loc_id);
// $checkDataList->setCondition("delivery_mode = '".$delivery_mode."' ");
$checkDataList->setLimit(100);
$checkDataList->setOrderKey("slotdate");
$checkDataList->setOrder("asc");
$checkDataList->load();
//echo '<br>checkDataList Count:'.count($checkDataList);
$checkData_loc_valid = 0; $checkData_locs = [];
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
// $checkData_locData = $checkData->getloc_id();
// $checkData_locId = $checkData_locData->getId();
$checkData_locId = $checkData->getloc_id();
array_push($checkData_locs, $checkData_locId);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
// echo '<br>checkData_locId:'.$checkData_locId;
// echo '<pre>checkData_locs:';
// print_r($checkData_locs);
// echo '<br>checkData_loc_valid:'.$checkData_loc_valid;
/*------------ End of Checking the slot data -------------*/
if($checkData_loc_valid == 1){
// $generateObjFolderId = self::generateSlotObjFolder('Slots',$delivery_mode,$loc_id);
$createAssetFolder = DoService::createFolderByPath('Slots');
$objParentId = $createAssetFolder->getId();
// $holidayObjectName = $location_code.'-'.$name;
$slotObjectName = $weekdate.'-'.$loc_id.'-'.$slot->getId().'-'.$deliveryslottimes->getId().'-'.time();
$slotObject = new DataObject\Slots();
$slotObject->setKey(\Pimcore\Model\Element\Service::getValidKey($slotObjectName, 'object'));
$slotObject->setParentId($objParentId);
$slotObject->setPrior_time($prior_time);
// $slotObject->setPicking_time($picking_time);
$slotObject->setDelivery_mode($delivery_mode);
// $slotObject->setSlotdate($date2);
$slotObject->setSlotdate($dates);
$slotObject->setfromtime($fromtime);
$slotObject->settotime($totime);
$slotObject->setmaxorder($maxorder);
// $slotObject->setLocation_code($location_code_array);
// $slotObject->setCharge($charge);
$slotObject->setdeliveryslottime_id(DataObject\Deliveryslottimes::getById($deliveryslottimes->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_code->getId()));
// $slotObject->setloc_id(DataObject\Locations::getById($location_id_info));
$slotObject->setloc_id($location_id_info);
$slotObject->setPublished(true);
$slotObject->save();
}
// }
// }
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
}
}
}
// }
}//End of Locations Loop
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
/**
* @Route("deliveryslots/updateslotordercount", methods={"POST"})
*/
public function updateslotordercountAction(Request $request)
{
$slotId = $request->get('slotId');
$ordercount = $request->get('ordercount');
if($slotId == "" || $ordercount == "")
{
$message = "slotId and ordercount are mandatory!";
} else
{
$slotruleObject = DataObject\Slots::getById($slotId);
if(!empty($slotruleObject) && $slotruleObject->getId()){
$slotruleObject->setordercount($ordercount);
$slotruleObject->save();
$message = "Slot Updated Successfully!";
} else {
$message = "This Slot Id ".$slotId." is not existed, Please try with valid Slot Id";
}
}
return $this->json(["success" => true, "data" => $message]);
}
/**
* @Route("/deliveryslots/getSlot1/{id}")
*/
public function getSlot1($id)
{
$slot = DataObject\Slots::getById($id);
if(isset($slot) && $slot->getId() != ''){
// $location_codes = $slot->getlocation_code();
$loc_code = (!empty($slot->getloc_id()) && $slot->getloc_id())?$slot->getloc_id()->getlocation_code():'';
$loc_name = (!empty($slot->getloc_id()) && $slot->getloc_id())?$slot->getloc_id()->getlocation_name():'';
// foreach($location_codes as $location_code){
// $loc_name = $location_code->getlocation_name();
// }
$data = array(
"prior_time" => $slot->getprior_time(),
"picking_time" => $slot->getpicking_time(),
"charge" => $slot->getcharge(),
"slotdate" => $slot->getslotdate(),
"loc_code" => $loc_code,
"loc_name" => $loc_name,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode());
} else {
$data = "No data found";
}
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslots/getSlot/{id}")
*/
public function getSlot($id)
{
$slot = DataObject\Slots::getById($id);
if(isset($slot) && $slot->getId() != ''){
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = (!empty($slotLocationData) && $slotLocationData->getlocation_name())?$slotLocationData->getlocation_name():'';
$loc_code = (!empty($slotLocationData) && $slotLocationData->getlocation_code())?$slotLocationData->getlocation_code():'';
$data = array(
"prior_time" => $slot->getprior_time(),
// "picking_time" => $slot->getpicking_time(),
// "charge" => $slot->getcharge(),
"slotdate" => date("Y-m-d", strtotime($slot->getslotdate())),//$slot->getslotdate(),
"loc_code" => $loc_code,
"loc_name" => $loc_name,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode());
} else {
$data = "No data found";
}
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslots/getStoreslot/{id}")
*/
public function getStoreslot($id)
{
$data ="No data found";
if($id == "")
{
$data ="Location Code is mandatory!";
} else
{
/*---- Check Location by Location Code ---------*/
$locData = DataObject\Locations::getBylocation_code($id, 1);
if(empty($locData) || empty($locData->getId()))
{
$data = "Location is not exited, please try with valid location code!";
} else {
$loc_id = $locData->getId();
$today_date = date("Y-m-d");
$cur_time = date("H:i");
$slotsList = DataObject\Slots::getList();
if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$slotsList->filterBySlotdate($today_date, '=');
}
if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$slotsList->filterByprior_time($cur_time, '>=');
}
$slotsList->setCondition("loc_id__id = ".$loc_id);
$slotsList->setLimit(100);
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
$data = [];
if(count($slotsList) > 0){
foreach ($slotsList as $key => $blog) {
$location_codes = $blog->getlocation_code();
$loc_name = ''; $loc_id = 0; $loc_names = []; $loc_codes = [];
foreach($location_codes as $location_code){
$loc_name = $location_code->getlocation_name();
$loc_code = $location_code->getlocation_code();
$loc_id = $location_code->getId();
array_push($loc_names,$loc_name);
array_push($loc_codes,$loc_code);
}
// if($loc_name != 0 && $loc_name == $id){
// if(!empty($loc_codes) && in_array($id, $loc_codes)){//&& $id!= ''
// if(!empty($blog->getloc_id()) && $blog->getloc_id()->getlocation_code() == $id){//&& $id!= ''
$data[] = array(
"slotId" => $blog->getId(),
"prior_time" => $blog->getprior_time(),
"picking_time" => $blog->getpicking_time(),
"location_code" => $blog->getloc_id()->getlocation_code(),
"loc_name" => $blog->getloc_id()->getlocation_name(),//$loc_name,
"charge" => $blog->getcharge(),
"slotdate" => $blog->getslotdate(),
"fromtime" => $blog->getfromtime(),
"totime" => $blog->gettotime(),
"maxorder" => $blog->getmaxorder(),
"ordercount" => $blog->getordercount(),
"delivery_mode" => $blog->getdelivery_mode());
//}
}
} else $data = "No data found";
}
}
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("personalitystatement/getperstmtlist", methods={"POST"})
*/
public function getperstmtlistAction(Request $request)
{
$message = SELF::verifyauthToken();
// $data[] = ['message'=>$message];
if($message == "No data found")
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
// print_r($reqparams); die;
// print_r($request->get->all());
$title = (isset($reqparams['title']))?$reqparams['title']:'';
$gender = (isset($reqparams['gender']))?$reqparams['gender']:'';
$standout_fitin = (isset($reqparams['standout_fitin']))?$reqparams['standout_fitin']:'';
$describe_yourself = (isset($reqparams['describe_yourself']))?$reqparams['describe_yourself']:'';
$occasion = (isset($reqparams['occasion']))?$reqparams['occasion']:'';
$priceband = (isset($reqparams['priceband']))?$reqparams['priceband']:'';
$blank1 = (isset($reqparams['blank1']))?$reqparams['blank1']:'';
$blank2 = (isset($reqparams['blank2']))?$reqparams['blank2']:'';
$perstmtList = DataObject\Personalitystatements::getList();
if($title)
$perstmtList->setCondition("personality_statement = ?",[$title]);
if($blank1)
$perstmtList->setCondition("blank1 = ?",[$blank1]);
if($blank2)
$perstmtList->setCondition("blank2 = ?",[$blank2]);
if($priceband)
$perstmtList->setCondition("priceband = ?",[$priceband]);
$perstmtList->load();
foreach ($perstmtList as $key => $perstmtObj) {
$data_disp = 0; $gender_chk = 0; $standout_fitin_chk =0; $describe_yourself_chk = 0; $occasion_chk = 0;
if(($gender && !empty($perstmtObj->getstandout_fitin()) && in_array($gender, $perstmtObj->getstandout_fitin())) || $gender == ''){
$gender_chk = 1;
}
if(($standout_fitin && !empty($perstmtObj->getstandout_fitin()) && in_array($standout_fitin, $perstmtObj->getstandout_fitin())) || $standout_fitin == ''){
$standout_fitin_chk = 1;
}
if(($describe_yourself && !empty($perstmtObj->getdescribe_yourself()) && in_array($describe_yourself, $perstmtObj->getdescribe_yourself())) || $describe_yourself == ''){
$describe_yourself_chk = 1;
}
if(($occasion && !empty($perstmtObj->getoccasion()) && in_array($occasion, $perstmtObj->getoccasion())) || $occasion == ''){
$occasion_chk = 1;
}
if($gender_chk == 1 && $standout_fitin_chk == 1 && $describe_yourself_chk == 1 && $occasion_chk == 1){
$data[] = array(
"id" => $perstmtObj->getId(),
"personality_statement" => $perstmtObj->getpersonality_statement(),
"standout_fitin" => $perstmtObj->getstandout_fitin(),
"describe_yourself" => $perstmtObj->getdescribe_yourself(),
"occasion" => $perstmtObj->getoccasion(),
"priceband" => $perstmtObj->getpriceband(),
"blank2" => $perstmtObj->getblank2(),
"blank1" => $perstmtObj->getblank1());
} else $data[] = ['message'=>$message];
}
} else $data[] = ['message'=>$message];
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/factory/getfactories")
*/
public function getfactories()
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$factoriesList = DataObject\Factories::getList();
$factoriesList->load();
if(count($factoriesList) > 0){
foreach ($factoriesList as $key => $blog) {
$bestbefore_date = '';
if($blog->getbestbefore()){
$bestbefore_dt = date("m/d/y", strtotime($blog->getbestbefore()));
$bestbefore_date = Carbon::createFromFormat('m/d/y', $bestbefore_dt);
}
$data[] = array(
"code" => $blog->getcode(),
"name" => $blog->getname(),
"address" => $blog->getaddress(),
"street" => $blog->getstreet(),
"landmark" => $blog->getlandmark(),
"city" => $blog->getcity(),
"state" => $blog->getstate(),
"country" => $blog->getcountry(),
"pincode" => $blog->getpincode(),
"bestbefore" => $bestbefore_date);
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslottime/getslottimes")
*/
public function getslottimesAction()
{
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->load();
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$prepare_days = $delSlotTimes->getprepare_days();
$delSlot_date = date('Y-m-d H:i:s', strtotime(' +'.$prepare_days.' day'));
$data[] = array(
"title" => $delSlotTimes->gettitle(),
"deliverytype_id" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $delSlotTimes->getprepare_days(),
"delSlot_date" => $delSlot_date);
}
} else $data = "No data found";
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslottime/getslottimeslist")
*/
public function getslottimeslistAction()
{
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->load();
// $delivery_modes = ['courier','standard','express'];
// $slotsList = DataObject\Slots::getList();
// $slotsList->setCondition("delivery_mode = 'courier'");
// // if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
// // $slotsList->filterBydelivery_mode($courier_mode, '=');
// // }
// $slotsList->load();
// echo '<pre>kk'; print_r($slotsList); die;
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$prepare_days = $delSlotTimes->getprepare_days();
$delSlot_date = date('Y-m-d H:i:s', strtotime(' +'.$prepare_days.' day'));
$delSlot_date1 = date("Y-m-d", strtotime($delSlot_date));
$cur_time = date("H:i");
// $delSlotTimes->delSlot_date = $delSlot_date;
$delivery_modes = ['courier','standard','express'];
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
$slotsList = DataObject\Slots::getList();
// $slotsList->setCondition("delivery_mode = '".$delivery_mode."'");
if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$slotsList->filterBySlotdate($delSlot_date1, '=');
}
if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
$slotsList->filterByprior_time($cur_time, '>=');
}
if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$slotsList->filterBydelivery_mode($delivery_mode, '>=');
}
$slotsList->setLimit(100);
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slots = [];
if(count($slotsList) > 0){
foreach($slotsList as $slot)
{
// $loc_name = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_name():'';
// $loc_code = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_code():'';
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = $slotLocationData->getlocation_name();
$loc_code = $slotLocationData->getlocation_code();
$delivery_mode_slot1 = array(
"slotId" => $slot->getId(),
"prior_time" => $slot->getprior_time(),
// "picking_time" => $slot->getpicking_time(),
// "charge" => $slot->getcharge(),
"slotdate" => $slot->getslotdate(),
"loc_name" => $loc_name,
"loc_code" => $loc_code,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode()
);
array_push($delivery_mode_slots, $delivery_mode_slot1);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
}
$data[] = array(
"deliverytype_id" => $delSlotTimes->gettitle(),
"label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $delSlotTimes->getprepare_days(),
"delSlot_date" => $delSlot_date,
"slots"=>$delivery_mode_slots_all);
}
} else $data[] = [];
return $this->json(["success" => true, "data" => $data]);
}
public function getSlotTimeDates($slot_generate_days, $todaydate){
$jj=0; $weekdates = [];
for($ii=1; $ii<15; $ii++)
{
if($jj >= 7) break;
if(empty($holidaysList) || !in_array($todaydate, $holidaysList)){
$weekdates[] = $todaydate;
$jj=$jj+1;
}
$todaydate = date('Y-m-d', strtotime($todaydate . ' +1 day'));
}
// echo '<pre>'; print_r($weekdates); die;
return $weekdates;
}
public function getWorkingDate($slot_generate_days, $todaydate){
$jj=0; $weekdates = [];
for($ii=1; $ii<$slot_generate_days; $ii++)
{
if(empty($holidaysList) || !in_array($todaydate, $holidaysList)){
$weekdates[] = $todaydate;
$jj=$jj+1;
}
$todaydate = date('Y-m-d', strtotime($todaydate . ' +1 day'));
}
// echo '<pre>'; print_r($weekdates); die;
return $weekdates;
}
/**
* @Route("/deliveryslottime/gelocslottimes1/{locCode}")
*/
public function gelocslottimes1Action($locCode)
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$today_date = date("Y-m-d");
$tomorrow_date = date('Y-m-d', strtotime($today_date . ' +1 day'));
$dates_list = array($today_date, $tomorrow_date);
/*---- Check Location by Location Code ---------*/
$locationData = DataObject\Locations::getBylocation_code($locCode, 1);
/*--------- Getting Delivery Modes settings ----------*/
$settingsList = DataObject\Settings::getList();
$settingsList->setLimit(1);
$settingsList->load();
$setting_deliveryModes = [];
$setting_slot_time_flag = "18:00";
if(count($settingsList) > 0){
foreach($settingsList as $settingsData)
{
$settingDataId = $settingsData->getId();
$setting_deliveryModes = $settingsData->getdelivery_modes();
$setting_slot_time_flag = (!empty($settingsData->getslottime()))?$settingsData->getslottime():$setting_slot_time_flag;
}
}
if(!empty($locationData) && !empty($locationData->getId()))
{
$parentLoc_id = $locationData->getId();
//------ get holidays list ------------//
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
$holidaysList->load();
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->setOrderKey("o_id");
$delSlotTimesList->setOrder("desc");
$delSlotTimesList->load();
// foreach($dates_list as $cur_date){
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
//------- Get Week Dates based on Holidays and Slot Time data ---------//
$slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
$slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
$saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
$cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
$cur_time = date("H:i");//"09:00";//
$slot_generate_days = ($cur_time > $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
$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];
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
//------- Get Week Dates based on Holidays and Slot Time data ---------//
$prepare_days = $delSlotTimes->getprepare_days();
$delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$prepare_days.' day'));
$delSlot_date1 = date("Y-m-d", strtotime($delSlot_date));
$cur_time_data = explode(" ",$cur_time);
$slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
$slot_generate_days_limit = ($slot_generate_days > 0)?$slot_generate_days:1;
// echo $tomorrow_date.":".$weekdates[0];
if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
if($tomorrow_date >= $weekdates[0])
{
$weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
} else {
$no_of_weekdates = count($weekdates);
$weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
}
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
} else {
$weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
}
// echo 'weekdates:<pre>:'; print_r($weekdates);
$slot_generate_days_date = date('Y-m-d', strtotime($today_date . ' +'.$slot_generate_days.' day'));
$delivery_modes = $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else {
$slotsList = DataObject\Slots::getList();
if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
$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]);
} else {
if($delivery_mode == 'standard')
{
$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]);
} else
{
$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]);
}
}
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
// if($slot_generate_days == 3)
// {
// echo '<pre>';
// print_r($slotsList); die;
// }
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slots = [];
if(count($slotsList) > 0 && $cur_slot_generate_days>0){
foreach($slotsList as $slot)
{
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = $slotLocationData->getlocation_name();
$delivery_mode_slot1 = array(
"slotId" => $slot->getId(),
"prior_time" => $slot->getprior_time(),
"slotdate" => date("Y-m-d", strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
"loc_name" => $loc_name,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode(),
);
array_push($delivery_mode_slots, $delivery_mode_slot1);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
}
}
$data[] = array(
"deliverytype_id" => $delSlotTimes->gettitle(),
"label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $delSlotTimes->getprepare_days(),
"slot_generate_days" => $slot_generate_days,
"delSlot_date" => $delSlot_date1,
"slots"=>$delivery_mode_slots_all);
}
} else $data[] = ['message'=>$message];
// }
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslottime/gelocslottimes2/{locCode}")
*/
public function gelocslottimes2Action($locCode)
{
$message = SELF::verifyauthToken();
$Is_location_up_country = $is_upcountry_configuration_applicable = '';
if($message == "No data found")
{
$today_date = date("Y-m-d");
$tomorrow_date = date('Y-m-d', strtotime($today_date . ' +1 day'));
$dates_list = array($today_date, $tomorrow_date);
/*---- Check Location by Location Code ---------*/
$locationData = DataObject\Locations::getBylocation_code($locCode, 1);
/*--------- Getting Delivery Modes settings ----------*/
$settingsList = DataObject\Settings::getList();
$settingsList->setLimit(1);
$settingsList->load();
$setting_deliveryModes = [];
$setting_slot_time_flag = "18:00";
if(count($settingsList) > 0){
foreach($settingsList as $settingsData)
{
$settingDataId = $settingsData->getId();
$setting_deliveryModes = $settingsData->getdelivery_modes();
$setting_slot_time_flag = (!empty($settingsData->getslottime()))?$settingsData->getslottime():$setting_slot_time_flag;
}
}
if(!empty($locationData) && !empty($locationData->getId()))
{
$parentLoc_id = $locationData->getId();
$parentLocationName = $locationData->getLocation_name();
$parentLocationCode = $locationData->getLocation_code();
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($parentLocationName),"up country") || strpos(strtoupper($parentLocationCode),"UPCTR"))?1:0;
//------ get holidays list ------------//
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
$holidaysList->load();
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->setOrderKey("o_id");
$delSlotTimesList->setOrder("desc");
$delSlotTimesList->load();
// foreach($dates_list as $cur_date){
if(count($delSlotTimesList) > 0){
$cur_time = date("H:i");//"09:00";//
foreach($delSlotTimesList as $delSlotTimes)
{
//------- Get Week Dates based on Holidays and Slot Time data ---------//
$slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
$slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
$saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
/*--------------------- Up Country Configuration ------------------------*/
$is_upcountry_configuration_applicable = ($delSlotTimes->getis_upcountry_configuration_applicable())?$delSlotTimes->getis_upcountry_configuration_applicable():'No';
$slot_upcountry_prepare_days = ($delSlotTimes->getupcountry_prepare_days())?$delSlotTimes->getupcountry_prepare_days():0;
$upcountry_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():7;
$upcountry_saturday_slot_availability = ($delSlotTimes->getupcountry_saturday_slot_availability())?$delSlotTimes->getupcountry_saturday_slot_availability():'No';
$upcountry_sunday_slot_availability = ($delSlotTimes->getupcountry_sunday_slot_availability())?$delSlotTimes->getupcountry_sunday_slot_availability():'No';
if($is_upcountry_configuration_applicable == 'Yes' && $Is_location_up_country == 1)
{
$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;
$cur_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():0;
// $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];
}
else
{
$cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
}
$slot_generate_days = ($cur_time > $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
$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];
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo $cur_time." | ".$setting_slot_time_flag;
// echo 'delSlotTimesAvailibility<pre>:';
// print_r($delSlotTimesAvailibility);
// echo 'weekdates<pre>:';
// print_r($weekdates);die;
//------- Get Week Dates based on Holidays and Slot Time data ---------//
// $prepare_days = $delSlotTimes->getprepare_days();
// $delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$prepare_days.' day'));
$delSlot_date = ($slot_prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$slot_prepare_days.' day'));
$delSlot_date1 = date("Y-m-d", strtotime($delSlot_date));
$cur_time_data = explode(" ",$cur_time);
// $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
// $slot_generate_days_limit = ($slot_generate_days > 0)?$slot_generate_days:1;
$slot_generate_days_limit = ($cur_slot_generate_days > 0)?$cur_slot_generate_days:1;
// echo $tomorrow_date.":".$weekdates[0];
if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
// if($tomorrow_date >= $weekdates[0])
// {
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
// } else {
// $no_of_weekdates = count($weekdates);
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
// }
$no_of_weekdates = count($weekdates);
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
$weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
} else {
$weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
}
// echo 'weekdates:<pre>:'; print_r($weekdates);
$slot_generate_days_date = date('Y-m-d', strtotime($today_date . ' +'.$slot_generate_days.' day'));
$delivery_modes = $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else {
$slotsList = DataObject\Slots::getList();
if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
$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]);
} else {
if($delivery_mode == 'standard')
{
$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]);
} else
{
$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]);
}
}
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
// if($slot_generate_days == 3)
// {
// echo '<pre>';
// print_r($slotsList); die;
// }
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slots = [];
if(count($slotsList) > 0 && $cur_slot_generate_days>0){
foreach($slotsList as $slot)
{
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = $slotLocationData->getlocation_name();
$delivery_mode_slot1 = array(
"slotId" => $slot->getId(),
"prior_time" => $slot->getprior_time(),
"slotdate" => date("Y-m-d", strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
"loc_name" => $loc_name,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode(),
);
array_push($delivery_mode_slots, $delivery_mode_slot1);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
}
}
$data[] = array(
// "LocationName" => $parentLocationName,
// "LocationCode" => $parentLocationCode,
// "Is_location_up_country" => $Is_location_up_country,
"is_upcountry_configuration_applicable" => $is_upcountry_configuration_applicable,
"deliverytype_id" => $delSlotTimes->gettitle(),
"label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $slot_prepare_days,//$delSlotTimes->getprepare_days(),
"slot_generate_days" => $cur_slot_generate_days,//$slot_generate_days,
"delSlot_date" => $delSlot_date1,
"slots"=>$delivery_mode_slots_all);
}
} else $data[] = ['message'=>$message];
// }
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "Is_location_up_country" => $Is_location_up_country, "data" => $data]);
}
/**
* @Route("/deliveryslottime/gelocslottimes/{locCode}")
*/
public function gelocslottimesAction($locCode)
{
$message = SELF::verifyauthToken();
$Is_location_up_country = $is_upcountry_configuration_applicable = '';
if($message == "No data found")
{
$today_date = date("Y-m-d");
$tomorrow_date = date('Y-m-d', strtotime($today_date . ' +1 day'));
$dates_list = array($today_date, $tomorrow_date);
/*---- Check Location by Location Code ---------*/
$locationData = DataObject\Locations::getBylocation_code($locCode, 1);
/*--------------- Settings info ----------------*/
$settingsInfo = SELF::getSettingInfo();
/*----------- End of Settings Info -------------*/
/*--------- Getting Delivery Modes settings ----------*/
$setting_slot_time_flag = $settingsInfo['setting_slot_time_flag'];
$setting_deliveryModes = $settingsInfo['setting_deliveryModes'];
$settingDataId = $settingsInfo['settingDataId'];
// echo 'settingsInfo:<pre>';
// print_r($settingsInfo); die;
if(!empty($locationData) && !empty($locationData->getId()))
{
$parentLoc_id = $locationData->getId();
$parentLocationName = $locationData->getLocation_name();
$parentLocationCode = $locationData->getLocation_code();
$fastDelivery = $locationData->getfastDeliveryAvailable();
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($parentLocationName),"up country") || strpos(strtoupper($parentLocationCode),"UPCTR"))?1:0;
//------ get holidays list ------------//
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
$holidaysList->load();
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
array_push($holidayDates,$holidayDate);
}
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->setOrderKey("o_id");
$delSlotTimesList->setOrder("desc");
$delSlotTimesList->load();
// foreach($dates_list as $cur_date){
if(count($delSlotTimesList) > 0){
$cur_time = date("H:i");//"09:00";//
foreach($delSlotTimesList as $delSlotTimes)
{
//------- Get Week Dates based on Holidays and Slot Time data ---------//
$slot_prepare_days = ($delSlotTimes->getprepare_days())?$delSlotTimes->getprepare_days():0;
$slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():7;
$saturday_slot_availability = ($delSlotTimes->getsaturday_slot_availability())?$delSlotTimes->getsaturday_slot_availability():'No';
$sunday_slot_availability = ($delSlotTimes->getsunday_slot_availability())?$delSlotTimes->getsunday_slot_availability():'No';
/*--------------------- Up Country Configuration ------------------------*/
$is_upcountry_configuration_applicable = ($delSlotTimes->getis_upcountry_configuration_applicable())?$delSlotTimes->getis_upcountry_configuration_applicable():'No';
$slot_upcountry_prepare_days = ($delSlotTimes->getupcountry_prepare_days())?$delSlotTimes->getupcountry_prepare_days():0;
$upcountry_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():7;
$upcountry_saturday_slot_availability = ($delSlotTimes->getupcountry_saturday_slot_availability())?$delSlotTimes->getupcountry_saturday_slot_availability():'No';
$upcountry_sunday_slot_availability = ($delSlotTimes->getupcountry_sunday_slot_availability())?$delSlotTimes->getupcountry_sunday_slot_availability():'No';
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)
{
$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;
$cur_slot_generate_days = ($delSlotTimes->getupcountry_slot_generate_days())?$delSlotTimes->getupcountry_slot_generate_days():0;
// $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'];
$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'];
$slot_generate_days = $slot_generate_days+$stg_normalloc_upcounry_slot_generate_days;
}
else
{
$cur_slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
// $slot_generate_days = ($cur_time > $setting_slot_time_flag)?$slot_generate_days+1:$slot_generate_days;
$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'];
$slot_generate_days = $slot_generate_days+$stg_normalloc_upcounry_slot_generate_days;
}
$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;
$cur_slot_prepare_days = (!empty($fastDelivery)) ? 0 : $cur_slot_prepare_days;
$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];
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo $cur_time." | ".$setting_slot_time_flag;
// echo 'delSlotTimesAvailibility<pre>:';
// print_r($delSlotTimesAvailibility);
// echo 'weekdates<pre>:';
// print_r($weekdates);die;
//------- Get Week Dates based on Holidays and Slot Time data ---------//
// $prepare_days = $delSlotTimes->getprepare_days();
// $delSlot_date = ($prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$prepare_days.' day'));
$delSlot_date = ($slot_prepare_days == 0)?$tomorrow_date:date('Y-m-d', strtotime($today_date . ' +'.$slot_prepare_days.' day'));
if(!empty($fastDelivery)){
date_default_timezone_set('Asia/Kolkata');
$delSlot_date = date('Y-m-d');
// Get the current hour
$currentHour = (int)date('H');
// Check if the current time is greater than 6 PM
if ($currentHour >= 18) {
// Add one day to the current date
$delSlot_date = date('Y-m-d', strtotime($delSlot_date . ' +1 day'));
}
}
$delSlot_date1 = date("Y-m-d", strtotime($delSlot_date));
$cur_time_data = explode(" ",$cur_time);
// $slot_generate_days = ($delSlotTimes->getslot_generate_days())?$delSlotTimes->getslot_generate_days():0;
// $slot_generate_days_limit = ($slot_generate_days > 0)?$slot_generate_days:1;
$slot_generate_days_limit = ($cur_slot_generate_days > 0)?$cur_slot_generate_days:1;
// echo $tomorrow_date.":".$weekdates[0];
/* if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
// if($tomorrow_date >= $weekdates[0])
// {
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
// } else {
// $no_of_weekdates = count($weekdates);
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
// }
$no_of_weekdates = count($weekdates);
// $weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[$no_of_weekdates-1]])):[$weekdates[0]];
$weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
} else {
$weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
} */
/* if($settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'] == 'Yes' && $Is_location_up_country == 1)
{
if($cur_time > $settingsInfo['stg_delslot_upcountryloc_morethan_fromtime'] && $cur_time < $settingsInfo['stg_delslot_upcountryloc_lessthaneq_totime'])
{
$weekdates = ($slot_generate_days > 0)?array_values(array_diff($weekdates,[$weekdates[0]])):[$weekdates[1]];
} else {
$weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
}
if(($slot_generate_days > 0)){
for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days; $ii++)
{
$weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
}
} else
$weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
} else {
$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'];
} */
/* if(($slot_generate_days > 0)){
for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days; $ii++)
{
$weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
}
} else
$weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]]; */
/*
if(($slot_generate_days > 0)){
if($stg_normalloc_upcounry_slot_generate_days>1)
{
for($ii=0; $ii<$stg_normalloc_upcounry_slot_generate_days-1; $ii++)
{
$weekdates = array_values(array_diff($weekdates,[$weekdates[0]]));
}
}
$cur_weekdates = [];
if($cur_slot_generate_days > 0){
for($jj=0; $jj < $cur_slot_generate_days; $jj++)
{
array_push($cur_weekdates,$weekdates[$jj]);
}
}
$weekdates = $cur_weekdates;
} else
$weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
*/
if(($slot_generate_days > 0)){
$cur_weekdates = [];
if($cur_slot_generate_days > 0){
for($jj=0; $jj < $cur_slot_generate_days; $jj++)
{
array_push($cur_weekdates,$weekdates[$jj]);
}
}
$weekdates = $cur_weekdates;
} else
$weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
// $weekdates = ($slot_generate_days > 0)?$weekdates:[$weekdates[0]];
// echo 'weekdates:<pre>:'; print_r($weekdates);
$slot_generate_days_date = date('Y-m-d', strtotime($today_date . ' +'.$slot_generate_days.' day'));
$delivery_modes = $setting_deliveryModes;//['standard','express'];//['courier','standard','express'];
$locationSlotRule = new DataObject\Deliveryslotrules\Listing();
$locationSlotRule->setCondition(" FIND_IN_SET('".$parentLoc_id."',location_ids) ");
$locationSlotRule = $locationSlotRule->getData();
if (count($locationSlotRule)) {
$delivery_modes = array();
foreach ($locationSlotRule as $slv) {
$delivery_modes[] = $slv->getdelivery_mode();
}
}
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
if($delSlotTimes->gettitle() == 'customized' && (!in_array($delivery_mode,['standard'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else if($delSlotTimes->gettitle() == 'Confectionery' && (!in_array($delivery_mode,['standard','express'])))
{
$delivery_mode_slots_all[$delivery_mode] = [];
} else {
$slotsList = DataObject\Slots::getList();
if($cur_time > $setting_slot_time_flag)//if($cur_time > '18:00')
{
$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]);
} else {
if($delivery_mode == 'standard')
{
$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]);
} else
{
$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]);
}
}
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
// if($slot_generate_days == 3)
// {
// echo '<pre>';
// print_r($slotsList); die;
// }
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slots = [];
if(count($slotsList) > 0 && $cur_slot_generate_days>0){
foreach($slotsList as $slot)
{
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = $slotLocationData->getlocation_name();
$delivery_mode_slot1 = array(
"slotId" => $slot->getId(),
"prior_time" => $slot->getprior_time(),
"slotdate" => date("Y-m-d", strtotime($slot->getslotdate())),//$slot->getslotdate(),//$delSlot_date1,//
"loc_name" => $loc_name,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode(),
);
array_push($delivery_mode_slots, $delivery_mode_slot1);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
if ($fastDelivery) {
$delivery_mode_slots_all[$delivery_mode] = (!empty($delivery_mode_slots[0]) ? array($delivery_mode_slots[0]) : array());
} else {
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
}
}
}
$data[] = array(
// "LocationName" => $parentLocationName,
// "LocationCode" => $parentLocationCode,
// "Is_location_up_country" => $Is_location_up_country,
"is_upcountry_configuration_applicable" => $is_upcountry_configuration_applicable,
"stg_normalloc_upcounry_slot_generate_days" => $stg_normalloc_upcounry_slot_generate_days,
"deliverytype_id" => $delSlotTimes->gettitle(),
"label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $slot_prepare_days,//$delSlotTimes->getprepare_days(),
"slot_generate_days" => $cur_slot_generate_days,//$slot_generate_days,
"delSlot_date" => $delSlot_date1,
"slots"=>$delivery_mode_slots_all);
}
} else $data[] = ['message'=>$message];
// }
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "Is_location_up_country" => $Is_location_up_country, "data" => $data]);
}
/**
* @Route("/awss3bucket/gets3bucketlist")
*/
public function gets3bucketlistAction()
{
putenv('AWS_DEFAULT_REGION=us-east-2');
putenv('AWS_ACCESS_KEY_ID=AKIAUY45FDQLWT32YTPJ');
putenv('AWS_SECRET_ACCESS_KEY=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');
// $output = shell_exec('aws s3 ls');
try
{
$output = shell_exec('aws s3api create-bucket --bucket snap2web-13 --region us-east-2 --create-bucket-configuration LocationConstraint=us-east-2');
} catch(Exception $e)
{
echo $e->getMessage(); die;
}
// echo "<pre>$output</pre>";
echo '<pre>'; print_r($output); die;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/awss3bucket/uploadFileToS3")
*/
public function uploadFileToS3()
{
$curl = curl_init();
curl_setopt_array($curl, array(
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',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => "<file contents here>",
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
/**
* @Route("/user/login", methods={"POST"})
*/
public function userLogin(Request $request)
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$userName = (isset($reqparams['username']))?$reqparams['username']:'';
$password = (isset($reqparams['password']))?$reqparams['password']:'';
if($userName == '' || $password == '')
{
$data = "Username and Password are mandatory!";
} else {
$user = User::getByName($userName);
if($user) {
$validateUser = \Pimcore\Tool\Authentication::authenticatePlaintext($userName,$password);
if($validateUser) {
$userInfo = ['id'=>$validateUser->getId(),
'firstname'=>$validateUser->getfirstname(),
'lastname'=>$validateUser->getlastname(),
'email'=>$validateUser->getemail(),
];
$generateAuthTokenInfo = SELF::generateAuthToken($userInfo);
$generateAuthToken = $generateAuthTokenInfo['generateAuthToken'];
$jwtToken = (!empty($generateAuthTokenInfo['jwt']))?$generateAuthTokenInfo['jwt']:'';
$userId = $validateUser->getId();
$dbConnection = \Pimcore\Db::get();
$dbConnection->query("UPDATE users SET `authToken` = ? WHERE id = ?", [$generateAuthToken, $userId]);
$userData = User::getById($userId);
$authTokenVal = $dbConnection->fetchOne("SELECT authToken FROM users WHERE id = ".$userId);
$data = ["message"=>'Login successfull', "authToken"=>$authTokenVal];
if($jwtToken!='')
$data = ["message"=>'Login successfull', "authToken"=>$authTokenVal, "jwtToken"=>$jwtToken];
} else {
$data = 'Wrong password';
}
} else {
$data = 'User not found';
}
}
return $this->json(["success" => true, "data" => $data]);
}
public function generateAuthToken($userInfo=[])
{
/*------------- Generate MDF encode --------------*/
$generateAuthToken = md5(time());
$jwtdata = array(
"generateAuthToken" => $generateAuthToken
);
/*------------- Generate JWT Token ---------------*/
$jwt_check = 0;
if(!empty($userInfo)){
$id = $userInfo['id'];//1024;
$firstname = $userInfo['firstname'];//'Tex';
$lastname = $userInfo['lastname'];//'Hardrock';
$email = $userInfo['email'];//'dino@stone.age';
$secret_key = "951e345a17ab26f80ec0e16b1d2a0c2a";
$issuer_claim = "pimcore6.local"; // this can be the servername
$audience_claim = "Babu";
$issuedat_claim = time(); // issued at
$notbefore_claim = $issuedat_claim + 10; //not before in seconds
$expire_claim = $issuedat_claim + 60*5; // expire time in seconds
$token = array(
"iss" => $issuer_claim,
"aud" => $audience_claim,
"iat" => $issuedat_claim,
"nbf" => $notbefore_claim,
"exp" => $expire_claim,
"data" => array(
"id" => $id,
"firstname" => $firstname,
"lastname" => $lastname,
"email" => $email
));
$jwt = JWT::encode($token, $secret_key, 'HS256');
$jwtdata = array(
"generateAuthToken" => $generateAuthToken,
"jwt" => $jwt,
"email" => $email,
"expireAt" => $expire_claim
);
}
return $jwtdata;
}
public function verifyauthToken1()
{
$message = "No data found"; $tokenCheck = 0;
$headers=array();
foreach (getallheaders() as $name => $value) {
$headers[$name] = $value;
if($name == 'Authtoken') $tokenCheck = 1;
}
if($tokenCheck == 0){
$message = "Authentication Token is missing";;
} else {
$Authtoken = $headers['Authtoken'];
$dbConnection = \Pimcore\Db::get();
$authTokencheck = $dbConnection->fetchOne("SELECT id FROM users WHERE authToken = '".$Authtoken."' ");
if(empty($authTokencheck)){
$message = "Authentication Token is mismatch";
} else {
}
}
return $message;
}
public function verifyauthToken2()
{
$api_key = 'api-key';
$api_key_value = 'cGltY29yZWFwaWtleXZhbHVl';//base64encode('pimcoreapikeyvalue);
$message = "No data found"; $tokenCheck = 0; $apikeyCheck = 0; $jwtCheck = 0;$tokenMsg = ''; $apikeyMsg = ''; $jwtMsg = '';
$headers=array();
foreach (getallheaders() as $name => $value) {
$headers[$name] = $value;
if($name == 'Authtoken') $tokenCheck = 1;
if($name == 'Api-Key') $apikeyCheck = 1;
if($name == 'Authorization') $jwtCheck = 1;
}
// echo 'arr:<pre>';
// print_r($headers);
// die;
if($tokenCheck == 0 && $apikeyCheck == 0 && $jwtCheck == 0){
$message = "Fill any one of the Authentication Token, Api-Key Or JWT token!";;
} else {
$tokenCheck_valid = 0; $apikeyCheck_valid = 0; $jwtTokenCheck_valid = 0;
/*--------------------- Validating Auth Token -----------------*/
if($tokenCheck == 1)
{
$Authtoken = $headers['Authtoken'];
$dbConnection = \Pimcore\Db::get();
$authTokencheck = $dbConnection->fetchOne("SELECT id FROM users WHERE authToken = '".$Authtoken."' ");
if(empty($authTokencheck)){
$tokenMsg = "Authentication Token is mismatch";
} else {
$tokenCheck_valid = 1;
}
}
/*--------------------- Validating Api Key -----------------*/
if($apikeyCheck == 1)
{
$AuthApikey = $headers['Api-Key'];
if(empty($AuthApikey)){
$apikeyMsg = "Key is mismatch";
} else if($AuthApikey != $api_key_value){
$apikeyMsg = "key is mismatch";
} else {
$apikeyCheck_valid = 1;
}
}
/*--------------------- Validating JWT Token -----------------*/
if($jwtCheck == 1)
{
$secret_key = "951e345a17ab26f80ec0e16b1d2a0c2a";
$jwt = null;
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
$arr = explode(" ", $authHeader);
$jwt = $arr[1];
if($jwt){
try {
$decoded = JWT::decode($jwt, new Key($secret_key, 'HS256'));
$jwtTokenCheck_valid = 1;
}catch (ExpiredException $e){
$jwtMsg = "Expired JWT Token!";//$e->getMessage();
}catch (Exception $e){
$jwtTokenCheck_valid = 0;
$jwtMsg = "Expired JWT Token!";//$e->getMessage();
}
} else {
$jwtMsg = "JWT Token is missing";
}
}
$message = '';
if($tokenMsg != '' || $apikeyMsg != '' || $jwtMsg != '')
{
$message = ($tokenMsg != '')?"Token Message:".$message.$tokenMsg:$message;
$message = ($apikeyMsg != '')?"".$message." | Api-Key Message:".$apikeyMsg:$message;
$message = ($jwtMsg != '')?"".$message." | JWT Message:".$jwtMsg:$message;
}
$message = ($tokenCheck_valid == 1 || $apikeyCheck_valid == 1 || $jwtTokenCheck_valid == 1)?"No data found":$message;
}
return $message;
}
public function verifyauthToken()
{
$api_key = 'api-key';
$api_key_value = 'cGltY29yZWFwaWtleXZhbHVl';//base64encode('pimcoreapikeyvalue);
$message = "No data found"; $apikeyCheck = 0; $apikeyMsg = '';
$headers=array();
foreach (getallheaders() as $name => $value) {
$headers[$name] = $value;
if($name == 'Api-Key') $apikeyCheck = 1;
}
if($apikeyCheck == 0){
$message = "Api-Key is mandatory!";;
} else {
$apikeyCheck_valid = 0;
/*--------------------- Validating Api Key -----------------*/
if($apikeyCheck == 1)
{
$AuthApikey = $headers['Api-Key'];
if(empty($AuthApikey)){
$message = "Key is empty, Api-Key is mandatory";
} else if($AuthApikey != $api_key_value){
$message = "key is mismatch";
} else {
$apikeyCheck_valid = 1;
}
}
}
return $message;
}
/**
* @Route("/location/locationslist")
*/
public function locationslist()
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$locationsList = DataObject\Locations::getList();
$locationsList->load();
if(count($locationsList) > 0){
foreach ($locationsList as $key => $location) {
$data[] = array(
"Id" => $location->getId(),
"location_name" => $location->getLocation_name(),
"location_code" => $location->getLocation_code());
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("personalitystatement/perstmtlist")
*/
public function perstmtlistAction()
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$perstmtList = DataObject\Personalitystatements::getList();
$perstmtList->load();
if(count($perstmtList)>0){
foreach ($perstmtList as $key => $perstmtObj) {
$data[] = array(
"id" => $perstmtObj->getId(),
"personality_statement" => $perstmtObj->getpersonality_statement(),
"standout_fitin" => $perstmtObj->getstandout_fitin(),
"describe_yourself" => $perstmtObj->getdescribe_yourself(),
"occasion" => $perstmtObj->getoccasion(),
"priceband" => $perstmtObj->getpriceband(),
"blank2" => $perstmtObj->getblank2(),
"blank1" => $perstmtObj->getblank1());
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("personalitystatement/perstmtinfo/{id}")
*/
public function perstmtinfoAction($id)
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$perstmtObject = DataObject\Personalitystatements::getById($id);
if(!empty($perstmtObject) && $perstmtObject->getpersonality_statement()){
$data[] = array(
"id" => $perstmtObject->getId(),
"personality_statement" => $perstmtObject->getpersonality_statement(),
"standout_fitin" => $perstmtObject->getstandout_fitin(),
"describe_yourself" => $perstmtObject->getdescribe_yourself(),
"occasion" => $perstmtObject->getoccasion(),
"priceband" => $perstmtObject->getpriceband(),
"blank2" => $perstmtObject->getblank2(),
"blank1" => $perstmtObject->getblank1());
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/api/gernerateJwtToken")
*/
public function gernerateJwtTokenAction()
{
$id = 1024;
$firstname = 'Tex';
$lastname = 'Hardrock';
$email = 'dino@stone.age';
$secret_key = "951e345a17ab26f80ec0e16b1d2a0c2a";
$issuer_claim = "pimcore6.local"; // this can be the servername
$audience_claim = "Babu";
$issuedat_claim = time(); // issued at
$notbefore_claim = $issuedat_claim + 10; //not before in seconds
$expire_claim = $issuedat_claim + 60; // expire time in seconds
$token = array(
"iss" => $issuer_claim,
"aud" => $audience_claim,
"iat" => $issuedat_claim,
"nbf" => $notbefore_claim,
"exp" => $expire_claim,
"data" => array(
"id" => $id,
"firstname" => $firstname,
"lastname" => $lastname,
"email" => $email
));
$jwt = JWT::encode($token, $secret_key, 'HS256');
// echo json_encode(
// array(
// "message" => "Successful login.",
// "jwt" => $jwt,
// "email" => $email,
// "expireAt" => $expire_claim
// )); die;
$data = array(
"message" => "Successful login.",
"jwt" => $jwt,
"email" => $email,
"expireAt" => $expire_claim
);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/api/verifyJwtToken")
*/
public function verifyJwtTokenAction()
{
$secret_key = "951e345a17ab26f80ec0e16b1d2a0c2a";
$jwt = null;
$data = json_decode(file_get_contents("php://input"));
$authHeader = $_SERVER['HTTP_AUTHORIZATION'];
$arr = explode(" ", $authHeader);
$jwt = $arr[1];
if($jwt){
try {
$decoded = JWT::decode($jwt, new Key($secret_key, 'HS256'));
// Access is granted. Add code of the operation here
$data = array(
"message" => "Access granted"
);
return $this->json(["success" => true, "data" => $data]);
}catch (Exception $e){
$data = array(
"message" => "Access denied"
);
return $this->json(["success" => true, "data" => $data]);
}
}
}
/**
* @Route("api/shippingchargeslist")
*/
public function shippingchargeslistAction()
{
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$shippingchargesList = DataObject\Shippingcharges::getList();
$shippingchargesList->load();
if(count($shippingchargesList)>0){
foreach ($shippingchargesList as $key => $shippingchargeObj) {
$data[] = array(
"id" => $shippingchargeObj->getId(),
"minimum_order" => $shippingchargeObj->getminimum_order(),
"maximum_order" => $shippingchargeObj->getmaximum_order(),
"discount_percentage" => $shippingchargeObj->getdiscount_percentage(),
"location" => $shippingchargeObj->getlocationId()->getLocation_name());
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/shippingrateslist1", methods={"POST"})
*/
public function shippingrateslist1Action()
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$noofkgs = (isset($reqparams['noofkgs']))?$reqparams['noofkgs']:'';
$shippingaddress = (isset($reqparams['shippingaddress']))?$reqparams['shippingaddress']:'';
if($noofkgs == '' || $shippingaddress == '')
{
$data = "No of Kgs and Shipping Address are mandatory!";
} else {
if(empty($shippingaddress['locationCode']) || empty($shippingaddress['location_zone']))//empty($shippingaddress['order_in_kgs']) ||
{
$data = "Shipping Address should have locationCode and location_zone !";// and order_in_kgs
} else {
// echo 'shippingaddress<pre>:';
// print_r($shippingaddress);
$message = SELF::verifyauthToken();
if($message == "No data found")
{
//----------- Shipping Address Params Data ------------//
$locationCode = $shippingaddress['locationCode'];
// $order_in_kgs = $shippingaddress['order_in_kgs'];
$location_zone = $shippingaddress['location_zone'];
//--------- Get Location data from location code ------------//
$LocationInfo = DataObject\Locations::getList();
if ($LocationInfo->getClass()->getFieldDefinition('location_code')->isFilterable()) {
$LocationInfo->filterBylocation_code($locationCode, '=');
}
$LocationInfo->load();
if(count($LocationInfo)>0)
{
foreach($LocationInfo as $Location)
{
$locationName = $Location->getLocation_name();
$locationId = $Location->getId();
}
// echo 'locationId:'.$locationId;
//------- Get Shipping Charge from Location and order ---------//
$shippingchargesList = DataObject\Shippingcharges::getList();
$shippingchargesList->setCondition("locationId__Id = ?",[$locationId]);
$shippingchargesList->load();
// echo 'shippingchargesList<pre>:';
// print_r($shippingchargesList);
$locationName='';$minimum_order = $maximum_order = $discount_percentage = 0;
if(count($shippingchargesList)>0)
{
foreach($shippingchargesList as $shippingchargeObj)
{
$locationName = $shippingchargeObj->getlocationId()->getLocation_name();
$minimum_order = $shippingchargeObj->getminimum_order();
$maximum_order = $shippingchargeObj->getmaximum_order();
$discount_percentage = $shippingchargeObj->getdiscount_percentage();
}
}
// echo 'minimum_order:'.$minimum_order.'|maximum_order:'.$maximum_order.'|discount_percentage:'.$discount_percentage;
//----------- Get Discount Percentage from Shipping Charge data and Order -----------//
$rate_discount_perc = ($minimum_order <= $noofkgs && $maximum_order >= $noofkgs)?$discount_percentage:0;
$cur_noofkgs = ($noofkgs<=2)?3:$noofkgs;
$shippingratesList = DataObject\Shippingratecards::getList();
if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
$shippingratesList->filterByno_of_kgs($cur_noofkgs, '=');
}
$shippingratesList->setOrderKey("no_of_kgs");
$shippingratesList->setOrder("desc");
$shippingratesList->load();
if(count($shippingratesList)>0){
$ii=0;
foreach ($shippingratesList as $key => $shippingrateObj) {
// $data[] = array(
// "id" => $shippingrateObj->getId(),
// "no_of_kgs" => $shippingrateObj->getno_of_kgs(),
// "intera_region_cost" => $shippingrateObj->getintera_region_cost(),
// "j_and_k_cost" => $shippingrateObj->getj_and_k_cost(),
// "ne_and_andaman" => $shippingrateObj->getne_and_andaman());
$data_key = $data_val = $data_key2 = $data_val2 = '';
$data[] = array(
"id" => $shippingrateObj->getId(),
"no_of_kgs" => $shippingrateObj->getno_of_kgs());
if($location_zone == 'Intera Region')
{
$data_key = 'intera_region_final_cost';
$data_val = $shippingrateObj->getintera_region_cost()-(($shippingrateObj->getintera_region_cost()*$rate_discount_perc)/100);
$data_key2 = 'intera_region_cost';
$data_val2 = $shippingrateObj->getintera_region_cost();
}
if($location_zone == 'J and K')
{
$data_key = 'j_and_k_final_cost';
$data_val = $shippingrateObj->getj_and_k_cost()-(($shippingrateObj->getj_and_k_cost()*$rate_discount_perc)/100);
$data_key2 = 'j_and_k_cost';
$data_val2 = $shippingrateObj->getj_and_k_cost();
}
if($location_zone == 'NE and Andaman')
{
$data_key = 'ne_and_andaman_final_cost';
$data_val = $shippingrateObj->getne_and_andaman()-(($shippingrateObj->getne_and_andaman()*$rate_discount_perc)/100);
$data_key2 = 'ne_and_andaman_cost';
$data_val2 = $shippingrateObj->getne_and_andaman();
}
$data[$ii]['locationName'] = $locationName;
$data[$ii]['discount_percentage'] = $rate_discount_perc."%";
if($location_zone == 'All')
{
$data_key = $data_val = '';
$data[$ii]['intera_region_cost'] = $shippingrateObj->getintera_region_cost();
$data[$ii]['intera_region_final_cost'] = $shippingrateObj->getintera_region_cost()-(($shippingrateObj->getintera_region_cost()*$rate_discount_perc)/100);
$data[$ii]['j_and_k_cost'] = $shippingrateObj->getj_and_k_cost();
$data[$ii]['j_and_k_final_cost'] = $shippingrateObj->getj_and_k_cost()-(($shippingrateObj->getj_and_k_cost()*$rate_discount_perc)/100);
$data[$ii]['ne_and_andaman_cost'] = $shippingrateObj->getne_and_andaman();
$data[$ii]['ne_and_andaman_final_cost'] = $shippingrateObj->getne_and_andaman()-(($shippingrateObj->getne_and_andaman()*$rate_discount_perc)/100);
}
if($data_key != '' && $data_val != '')
{
$data[$ii][$data_key2] = $data_val2;
$data[$ii][$data_key] = $data_val;
}
}
} else $data[] = ['message'=>$message];
} else {
$data = "Location Code should be valid!";
}
} else $data[] = ['message'=>$message];
}
}
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/shippingrateslist2", methods={"POST"})
*/
public function shippingrateslist2Action()
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$weight_cart = (isset($reqparams['weight_cart']))?$reqparams['weight_cart']:'';
$req_weight_cart = $weight_cart;
$locationCode = (isset($reqparams['locationCode']))?$reqparams['locationCode']:'';
$shipping_state_code = (isset($reqparams['shipping_state_code']))?$reqparams['shipping_state_code']:'';
$pincode = (isset($reqparams['pincode']))?$reqparams['pincode']:'';
$order_amount = (isset($reqparams['order_amount']))?$reqparams['order_amount']:'';
if($weight_cart == '' || $locationCode == '' || $shipping_state_code == '' || $pincode == '' || $order_amount == '')
{
$data = "weight_cart, locationCode, shipping_state_code, pincode and order_amount are mandatory!";
} else {
// $weight_cart = ceil($weight_cart);
/*------ Get Shipping Rate Card Class data --------*/
// $dbConnection = \Pimcore\Db::get();
$dbConnection = \Pimcore\Db::get();
$shippingRatecardClassId = $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Shippingratecards' ");
$shippingRatecardClassId;
$shippingRatecardObject = "object_".$shippingRatecardClassId;
// $shippingRatecardId = $dbConnection->fetchOne(" select * from object_12 order by abs(no_of_kgs - ".$weight_cart.")");
$shippingRatecardId = $dbConnection->fetchOne(" select * from ".$shippingRatecardObject." order by abs(no_of_kgs - ".$weight_cart.")");
/*----- End of ---------*/
/*---- Check Location by Location Code ---------*/
$locData = DataObject\Locations::getBylocation_code($locationCode, 1);
$pincodeInfo = DataObject\ItcAddPincode::getBypincode($pincode, 1);
$stateInfo = DataObject\States::getBystate_code($shipping_state_code, 1);
$shipChargeInfo = DataObject\Shippingratecards::getById($shippingRatecardId); //DataObject\Shippingratecards::getByno_of_kgs($weight_cart, 1);
// echo "shippingRatecardId<pre>:".$shippingRatecardId;
// echo "<br>shipChargeInfo<pre>:";
// print_r($shipChargeInfo->getId()); //die;
if(empty($locData) || empty($locData->getId()) || empty($pincodeInfo) || empty($pincodeInfo->getId()) || empty($shipChargeInfo) || empty($shipChargeInfo->getId()))// || empty($stateInfo) || empty($stateInfo->getId())
{
if(empty($locData) || empty($locData->getId()))
$message = "Location is not exited, please try with valid location code!";
if(empty($pincodeInfo) || empty($pincodeInfo->getId()))
$message = "Pincode is not exited, please try with valid pincode!";
// if(empty($stateInfo) || empty($stateInfo->getId()))
// $message = "Shipping State Code is not exited, please try with valid Shipping State Code!";
if(empty($shipChargeInfo) || empty($shipChargeInfo->getId()))
$message = "Shipping Charge is not exited for ".$weight_cart." Kgs, please try with valid No of Kgs!";
$data[] = ['message'=>$message];
} else {
$locationId = $locData->getId();
$locationName = $locData->getLocation_name();
$message = SELF::verifyauthToken();
if($message == "No data found")
{
/*------------- Check Is Shipping Applicable or Not based on Pincode from Pincode Table------------*/
// $pincode_error = ''; $is_shippingapplicable=''; $pincode_data = [];
// $pincodeList = DataObject\ItcAddPincode::getList();
// if ($pincodeList->getClass()->getFieldDefinition('pincode')->isFilterable()) {
// $pincodeList->filterBypincode($pincode, '=');
// }
// $pincodeList->load();
// if(count($pincodeList)>0)
// {
// foreach($pincodeList as $pincodeInfo)
// {
// // echo 'pincodeInfo<pre>';
// // print_r($pincodeInfo); die;
// $is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
// $pincode_data['pincode'] = $pincodeInfo->getpincode();
// $pincode_data['state'] = $pincodeInfo->getstate();
// $pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
// $pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
// $pincodeInfo->getData();
// }
// } else
// {
// $pincode_error = 'pincode is not valid';
// }
$is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
$pincode_data['pincode'] = $pincodeInfo->getpincode();
$pincode_data['state'] = $pincodeInfo->getstate();
$pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
$pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
/*----------- End of Check Is Shipping Applicable or Not based on Pincode from Pincode Table ----------*/
/*------------- Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table------------*/
$final_cost=0; $rate_discount_perc=0; $cur_noofkgs = $shipChargeInfo->getno_of_kgs();//$weight_cart;//($weight_cart<=2)?3:$weight_cart;
/*----------- End of Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table ----------*/
/*------------- Get Zone based on State Code from States Table ------------*/
// $zone_name='';
// $stateList = DataObject\States::getList();
// if ($stateList->getClass()->getFieldDefinition('state_code')->isFilterable()) {
// $stateList->filterBystate_code($shipping_state_code, '=');
// }
// $stateList->load();
// if(count($stateList)>0)
// {
// foreach($stateList as $stateInfo)
// {
// $zone_name=$stateInfo->getZoneId()->getzone_name();
// }
// }
$zone_name=(!empty($stateInfo) && $stateInfo->getZoneId())?$stateInfo->getZoneId()->getzone_name():'';
/*----------- End of Get Zone based on State Code from States Table ----------*/
/*------------- Get Shipping rate data based on state code and weight cart ------------*/
$shippingratesList = DataObject\Shippingratecards::getList();
if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
$shippingratesList->filterByno_of_kgs($cur_noofkgs, '=');
}
$shippingratesList->setOrderKey("no_of_kgs");
$shippingratesList->setOrder("desc");
$shippingratesList->load();
if(count($shippingratesList)>0){
$ii=0;
foreach ($shippingratesList as $key => $shippingrateObj) {
$data_key = $data_val = $data_key2 = $data_val2 = '';
$data[] = array(
"id" => $shippingrateObj->getId(),
"no_of_kgs" => $req_weight_cart,//$shippingrateObj->getno_of_kgs(),
"inter_region_cost" => $shippingrateObj->getintera_region_cost(),
"j_k_cost" => $shippingrateObj->getj_and_k_cost(),
"ne_and_andaman_cost" => $shippingrateObj->getne_and_andaman()
);
if($is_shippingapplicable == 'Yes')
{
if($zone_name == 'J and K')
{
$final_cost = $shippingrateObj->getj_and_k_cost();
}
else if($zone_name == 'NE and Andaman')
{
$final_cost = $shippingrateObj->getne_and_andaman();
}
else
{
$final_cost = $shippingrateObj->getintera_region_cost();
}
}
$data[$ii]['locationCode'] = $locationCode;
// $data[$ii]['is_shipping_applicable'] = $is_shippingapplicable;
$data[$ii]['pincode'] = $pincode_data;//$pincodeInfo->getData();//
// $data[$ii]['discount_percentage'] = $rate_discount_perc."%";
}
$minimum_order = $maximum_order = $discount_percentage = 0; $shippingRules = [];
if($is_shippingapplicable == 'Yes')//&& $loc_code_error == ''
{
$shippingchargesList = DataObject\Shippingcharges::getList();
// $shippingchargesList = new DataObject\Shippingcharges\Listing();
$shippingchargesList->setCondition("locationId__Id = ? AND (minimum_order <= ? AND maximum_order >= ?)",[$locationId, $order_amount, $order_amount]);
// $shippingchargesList->setCondition("locationId__Id = ?",[$locationId]);
// $shippingchargesList->setCondition("minimum_order >= ?",[$order_amount]);
// $shippingchargesList->setCondition("maximum_order <= ?",[$order_amount]);
$shippingchargesList->load();
// echo $shippingchargesList->getQuery()->__toString(); die;
// echo $shippingchargesList->getSQL(); die;
// echo 'shippingchargesList:';
// print_r($shippingchargesList->getSqlQuery()); die;
// $dbConnection = \Pimcore\Db::get();
// $sql = "SELECT * from object_15 where `locationId__Id` = $locationId AND (minimum_order <= $order_amount AND maximum_order >= $order_amount)";
// // echo $sql = "SELECT * from object_15 where `locationId__Id` = $locationId AND minimum_order <=4 ";
// $stmt = \Pimcore\Db::get()->prepare($sql);
// // $stmt->bindParam(1, 101, \PDO::PARAM_INT);
// $stmt->execute();
// $result = $stmt->fetchAll();
// echo 'shippingcharges result:';
// print_r($result); die;
if(count($shippingchargesList)>0)
{
foreach($shippingchargesList as $shippingchargeObj)
{
$minimum_order = $shippingchargeObj->getminimum_order();
$maximum_order = $shippingchargeObj->getmaximum_order();
$discount_percentage = $shippingchargeObj->getdiscount_percentage();
$shippingRules['shippingRuleId'] = $shippingchargeObj->getId();
$shippingRules['minimum_order_amount'] = $minimum_order;
$shippingRules['maximum_order_amount'] = $maximum_order;
$shippingRules['discount_percentage'] = $discount_percentage;
}
$data[$ii]['shippingRules'] = $shippingRules;
$rate_discount_perc = ($minimum_order <= $order_amount && $maximum_order >= $order_amount)?$discount_percentage:0;
$final_cost = $final_cost - (($final_cost*$rate_discount_perc)/100);
}
}
$data[$ii]['final_cost'] = $final_cost;
} else $data[] = ['message'=>$message];
/*----------- End of Get Shipping rate data based on state code and weight cart ----------*/
} else $data[] = ['message'=>$message];
}
}
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/shippingrateslist", methods={"POST"})
*/
public function shippingrateslistAction()
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$weight_cart = (isset($reqparams['weight_cart']))?$reqparams['weight_cart']:'';
$req_weight_cart = $weight_cart;
$locationCode = (isset($reqparams['locationCode']))?$reqparams['locationCode']:'';
$shipping_state_code = (isset($reqparams['shipping_state_code']))?$reqparams['shipping_state_code']:'';
$pincode = (isset($reqparams['pincode']))?$reqparams['pincode']:'';
$order_amount = (isset($reqparams['order_amount']))?$reqparams['order_amount']:'';
if($weight_cart == '' || $locationCode == '' || $shipping_state_code == '' || $pincode == '' || $order_amount == '')
{
$data = "weight_cart, locationCode, shipping_state_code, pincode and order_amount are mandatory!";
} else {
/*------ Get Shipping Rate Card Class data --------*/
$dbConnection = \Pimcore\Db::get();
$shippingRatecardClassId = $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Shippingratecards' ");
$shippingRatecardObject = "object_".$shippingRatecardClassId;
// $shippingRatecardId = $dbConnection->fetchOne(" select * from object_12 order by abs(no_of_kgs - ".$weight_cart.")");
$shippingRatecardId = $dbConnection->fetchOne(" select * from ".$shippingRatecardObject." order by abs(no_of_kgs - ".$weight_cart.")");
/*----- End of ---------*/
/*---- Check Location by Location Code ---------*/
$locData = DataObject\Locations::getBylocation_code($locationCode, 1);
$pincodeInfo = DataObject\ItcAddPincode::getBypincode($pincode, 1);
$stateInfo = DataObject\States::getBystate_code($shipping_state_code, 1);
$shipChargeInfo = DataObject\Shippingratecards::getById($shippingRatecardId); //DataObject\Shippingratecards::getByno_of_kgs($weight_cart, 1);
if(empty($locData) || empty($locData->getId()) || empty($pincodeInfo) || empty($pincodeInfo->getId()) || empty($shipChargeInfo) || empty($shipChargeInfo->getId()))// || empty($stateInfo) || empty($stateInfo->getId())
{
if(empty($locData) || empty($locData->getId()))
$message = "Location is not exited, please try with valid location code!";
if(empty($pincodeInfo) || empty($pincodeInfo->getId()))
$message = "Pincode is not exited, please try with valid pincode!";
if(empty($shipChargeInfo) || empty($shipChargeInfo->getId()))
$message = "Shipping Charge is not exited for ".$weight_cart." Kgs, please try with valid No of Kgs!";
$data[] = ['message'=>$message];
} else {
$locationId = $locData->getId();
$locationName = $locData->getLocation_name();
$message = SELF::verifyauthToken();
if($message == "No data found")
{
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($locationName),"up country"))?1:0;
/*------ Get Settings Class, Object and ID data --------*/
$dbConnection = \Pimcore\Db::get();
$settingsClassId = $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Settings' ");
$settingsObject = "object_".$settingsClassId;
$settingsObjectId = $dbConnection->fetchOne("select * from ".$settingsObject." order by oo_id asc");
/*---- Get Settings Data ---------*/
$settingsData = DataObject\Settings::getById($settingsObjectId);
// echo '<pre>settingsObjectId:'.$settingsObjectId;
// echo '<pre>settingsData:';
// print_r($settingsData->getis_deliveryfee_config_applicable());
$is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
$pincode_data['pincode'] = $pincodeInfo->getpincode();
$pincode_data['state'] = $pincodeInfo->getstate();
$pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
$pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
/*----------- End of Check Is Shipping Applicable or Not based on Pincode from Pincode Table ----------*/
/*------------- Get Shipping Discount Based on Is Shipping Applicable Fee Shipping Rule(Shipping Charges) Table------------*/
$final_cost=0; $rate_discount_perc=0; $cur_noofkgs = $shipChargeInfo->getno_of_kgs();
$zone_name=(!empty($stateInfo) && $stateInfo->getZoneId())?$stateInfo->getZoneId()->getzone_name():'';
/*----------- End of Get Zone based on State Code from States Table ----------*/
/*------------- Get Shipping rate data based on state code and weight cart ------------*/
$shippingratesList = DataObject\Shippingratecards::getList();
if ($shippingratesList->getClass()->getFieldDefinition('no_of_kgs')->isFilterable()) {
$shippingratesList->filterByno_of_kgs($cur_noofkgs, '=');
}
$shippingratesList->setOrderKey("no_of_kgs");
$shippingratesList->setOrder("desc");
$shippingratesList->load();
if(count($shippingratesList)>0){
$ii=0;
foreach ($shippingratesList as $key => $shippingrateObj) {
$data_key = $data_val = $data_key2 = $data_val2 = '';
$data[] = array(
"id" => $shippingrateObj->getId(),
"no_of_kgs" => $req_weight_cart,
"inter_region_cost" => $shippingrateObj->getintera_region_cost(),
"j_k_cost" => $shippingrateObj->getj_and_k_cost(),
"ne_and_andaman_cost" => $shippingrateObj->getne_and_andaman()
);
if($is_shippingapplicable == 'Yes')
{
if($zone_name == 'J and K')
{
$final_cost = $shippingrateObj->getj_and_k_cost();
}
else if($zone_name == 'NE and Andaman')
{
$final_cost = $shippingrateObj->getne_and_andaman();
}
else
{
$final_cost = $shippingrateObj->getintera_region_cost();
}
}
$data[$ii]['locationCode'] = $locationCode;
$data[$ii]['pincode'] = $pincode_data;
}
$minimum_order = $maximum_order = $discount_percentage = 0; $shippingRules = [];
if($is_shippingapplicable == 'Yes')//&& $loc_code_error == ''
{
$shippingchargesList = DataObject\Shippingcharges::getList();
$shippingchargesList->setCondition("locationId__Id = ? AND (minimum_order <= ? AND maximum_order >= ?)",[$locationId, $order_amount, $order_amount]);
$shippingchargesList->load();
if(count($shippingchargesList)>0)
{
foreach($shippingchargesList as $shippingchargeObj)
{
$minimum_order = $shippingchargeObj->getminimum_order();
$maximum_order = $shippingchargeObj->getmaximum_order();
$discount_percentage = $shippingchargeObj->getdiscount_percentage();
$shippingRules['shippingRuleId'] = $shippingchargeObj->getId();
$shippingRules['minimum_order_amount'] = $minimum_order;
$shippingRules['maximum_order_amount'] = $maximum_order;
$shippingRules['discount_percentage'] = $discount_percentage;
}
$data[$ii]['shippingRules'] = $shippingRules;
$rate_discount_perc = ($minimum_order <= $order_amount && $maximum_order >= $order_amount)?$discount_percentage:0;
$final_cost = $final_cost - (($final_cost*$rate_discount_perc)/100);
}
}
/*----------- Delivery Fee Configuration Condition --------------*/
if($settingsData->getis_deliveryfee_config_applicable() == 'Yes')
{
$stg_deliveryfee_config = $settingsData->getdeliveryfee_config();
$stg_deliveryfee_config_location_lessthan_charge = $settingsData->getdeliveryfee_config_location_lessthan_charge();
$stg_deliveryfee_config_location_greaterthanequal_charge = $settingsData->getdeliveryfee_config_location_greaterthanequal_charge();
$stg_deliveryfee_config_upcountry_lessthan_charge = $settingsData->getdeliveryfee_config_upcountry_lessthan_charge();
$stg_deliveryfee_config_upcountry_greaterthanequal_charge = $settingsData->getdeliveryfee_config_upcountry_greaterthanequal_charge();
if($Is_location_up_country == 0 && $order_amount < $stg_deliveryfee_config && $stg_deliveryfee_config_location_lessthan_charge != -1) $final_cost = $stg_deliveryfee_config_location_lessthan_charge;
else if($Is_location_up_country == 0 && $order_amount >= $stg_deliveryfee_config && $stg_deliveryfee_config_location_greaterthanequal_charge != -1) $final_cost = $stg_deliveryfee_config_location_greaterthanequal_charge;
else if($Is_location_up_country == 1 && $order_amount < $stg_deliveryfee_config && $stg_deliveryfee_config_upcountry_lessthan_charge != -1) $final_cost = $stg_deliveryfee_config_upcountry_lessthan_charge;
else if($Is_location_up_country == 1 && $order_amount >= $stg_deliveryfee_config && $stg_deliveryfee_config_upcountry_greaterthanequal_charge != -1) $final_cost = $stg_deliveryfee_config_upcountry_greaterthanequal_charge;
else $final_cost = $final_cost;
}
$data[$ii]['final_cost'] = $final_cost;
// 2 hours fast delivery code
if($is_shippingapplicable == 'Yes')
{
$fdsett = DataObject\FastDeliverySetting::getList();
$fdsett->setCondition("locationId__Id = ?",[$locationId]);
$fdsett->load();
$data[$ii]['platform_fee'] = 0;
$data[$ii]['low_order_fee'] = 0;
if(count($fdsett->getData()) > 0) {
$fdsett = $fdsett->getData()[0];
$data[$ii]['platform_fee'] = $fdsett->getplatFormFee();
$cartValue = $fdsett->getcartValue();
if($cartValue > $order_amount) {
$data[$ii]['low_order_fee'] = $fdsett->getminLowOrderFee();
} else {
$data[$ii]['low_order_fee'] = $fdsett->getlowOrderFee();
}
}
}
} else $data[] = ['message'=>$message];
/*----------- End of Get Shipping rate data based on state code and weight cart ----------*/
} else $data[] = ['message'=>$message];
}
}
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/getfactorydata", methods={"POST"})
*/
public function getfactorydataAction(Request $request)
{
$factorycode = $request->get('factorycode');
if($factorycode == "")
{
$data = "Factory Code is mandatory!";
} else
{
$data = SELF::verifyauthToken();
if($data == "No data found")
{
/*---- Check Factory by Code ---------*/
$factoryData = DataObject\Factories::getBycode($factorycode, 1);
if(!empty($factoryData) && $factoryData->getId()){
$data = array(
"id" => $factoryData->getId(),
"code" => $factoryData->getCode(),
"name" => $factoryData->getname(),
"address" => $factoryData->getaddress(),
"street" => $factoryData->getstreet(),
"landmark" => $factoryData->getlandmark(),
"city" => $factoryData->getcity(),
"state" => $factoryData->getstate(),
"country" => $factoryData->getcountry(),
"pincode" => $factoryData->getpincode(),
"bestbefore" => $factoryData->getbestbefore());
} else {
$data = "No data found!";
}
}
}
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/api/allslots")
*/
public function allslotsAction()
{
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->load();
// $delivery_modes = ['courier','standard','express'];
// $slotsList = DataObject\Slots::getList();
// $slotsList->setCondition("delivery_mode = 'courier'");
// // if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
// // $slotsList->filterBydelivery_mode($courier_mode, '=');
// // }
// $slotsList->load();
// echo '<pre>kk'; print_r($slotsList); die;
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$prepare_days = $delSlotTimes->getprepare_days();
$delSlot_date = date('Y-m-d H:i:s', strtotime(' +'.$prepare_days.' day'));
$delSlot_date1 = date("Y-m-d");//date("Y-m-d", strtotime($delSlot_date));
$cur_time = date("H:i");
// $delSlotTimes->delSlot_date = $delSlot_date;
$delivery_modes = ['courier','standard','express'];
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
$slotsList = DataObject\Slots::getList();
// $slotsList->setCondition("delivery_mode = '".$delivery_mode."'");
if ($slotsList->getClass()->getFieldDefinition('slotdate')->isFilterable()) {
$slotsList->filterBySlotdate($delSlot_date1, '>=');
}
// if ($slotsList->getClass()->getFieldDefinition('prior_time')->isFilterable()) {
// $slotsList->filterByprior_time($cur_time, '>=');
// }
if ($slotsList->getClass()->getFieldDefinition('delivery_mode')->isFilterable()) {
$slotsList->filterBydelivery_mode($delivery_mode, '>=');
}
$slotsList->setLimit(100);
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slots = [];
if(count($slotsList) > 0){
foreach($slotsList as $slot)
{
// $loc_name = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_name():'';
// $loc_code = (!empty($slot->getLoc_id()))?$slot->getLoc_id()->getlocation_code():'';
$slotLocationData = DataObject\Locations::getById($slot->getLoc_id());
$loc_name = $slotLocationData->getlocation_name();
$loc_code = $slotLocationData->getlocation_code();
$delivery_mode_slot1 = array(
"slotId" => $slot->getId(),
"prior_time" => $slot->getprior_time(),
// "picking_time" => $slot->getpicking_time(),
// "charge" => $slot->getcharge(),
"slotdate" => $slot->getslotdate(),
"loc_name" => $loc_name,
"loc_code" => $loc_code,
"fromtime" => $slot->getfromtime(),
"totime" => $slot->gettotime(),
"maxorder" => $slot->getmaxorder(),
"ordercount" => $slot->getordercount(),
"delivery_mode" => $slot->getdelivery_mode()
);
array_push($delivery_mode_slots, $delivery_mode_slot1);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
}
$data[] = array(
"deliverytype_id" => $delSlotTimes->gettitle(),
"label" => $delSlotTimes->getdeliverytype_id()->getdeliverytype(),
"prepare_days" => $delSlotTimes->getprepare_days(),
"delSlot_date" => $delSlot_date,
"slots"=>$delivery_mode_slots_all);
}
} else $data[] = [];
return $this->json(["success" => true, "data" => $data]);
}
}