<?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("/holidays/getlist")
*/
public function getlistAction()
{
$api_log_info = "API:Get All Holidays - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$holidaysList = DataObject\Holidays::getList();
$holidaysList->load();
$log_data = $api_log_info." | holidaysList Count:".json_encode(count($holidaysList));
SELF::createApiLog($log_data);
if(count($holidaysList) > 0){
foreach ($holidaysList as $key => $holidayInfo) {
$log_data = $api_log_info." | holidayInfo:".json_encode($holidayInfo);
SELF::createApiLog($log_data);
$location_codes = $holidayInfo->getlocation_code();
$loc_name = '';
$log_data = $api_log_info." | location_codes:".json_encode($location_codes);
SELF::createApiLog($log_data);
foreach($location_codes as $location_code){
$loc_name .= $location_code->getlocation_name().' ';
}
$log_data = $api_log_info." | loc_name:".json_encode($loc_name);
SELF::createApiLog($log_data);
$data[] = array(
"name" => $holidayInfo->getname(),
"loc_name" => $loc_name,
"holidaydate" => $holidayInfo->getHolidaydate());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = [];
// return $slotsList;
$returndata = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returndata:".json_encode($returndata);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*-------------------------------- Slots Related APIs ----------------------------*/
/**
* @Route("/deliveryslots/list")
*/
public function listAction()
{
$api_log_info = "API:Get Delivery Slots based on Today and Current Time - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$today_date = strtotime("Y-m-d");
$cur_time = date("H:i");
$log_data = $api_log_info." | today_date:".json_encode($today_date)." | cur_time:".json_encode($cur_time);
SELF::createApiLog($log_data);
$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();
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList));
SELF::createApiLog($log_data);
// if(count($slotsList) > 0){
foreach ($slotsList as $key => $slotInfo) {
$log_data = $api_log_info." | slotInfo:".json_encode($slotInfo);
SELF::createApiLog($log_data);
// $location_code = $blog->getlocation_code()->getlocation_code();
// $location_code = (!empty($slotInfo->getloc_id()) && $slotInfo->getloc_id())?$slotInfo->getloc_id()->getlocation_code():'';
// $loc_name = (!empty($slotInfo->getloc_id()) && $slotInfo->getloc_id())?$slotInfo->getloc_id()->getlocation_name():'';
$slotLocationData = DataObject\Locations::getById($slotInfo->getLoc_id());
$loc_name = (!empty($slotLocationData) && $slotLocationData->getlocation_name())?$slotLocationData->getlocation_name():'';
$location_code = (!empty($slotLocationData) && $slotLocationData->getlocation_code())?$slotLocationData->getlocation_code():'';
// foreach($location_codes as $location_code){
// $loc_name = $location_code->getlocation_name();
// }
$log_data = $api_log_info." | location_code:".json_encode($location_code)." | loc_name:".json_encode($loc_name);
SELF::createApiLog($log_data);
$data[] = array(
"slotId" => $slotInfo->getId(),
"prior_time" => $slotInfo->getprior_time(),
// "picking_time" => $slotInfo->getpicking_time(),
"location_code" => $location_code,
"loc_name" => $loc_name,
// "charge" => $slotInfo->getcharge(),
"slotdate" => $slotInfo->getslotdate(),
"fromtime" => $slotInfo->getfromtime(),
"totime" => $slotInfo->gettotime(),
"maxorder" => $slotInfo->getmaxorder(),
"ordercount" => $slotInfo->getordercount(),
"delivery_mode" => $slotInfo->getdelivery_mode());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
// } else $data[] = [];
// return $slotsList;
$returnData = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returnData:".json_encode($returnData);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslots/saveslots")
*/
public function saveslotsAction()
{
$api_log_info = "API:Generating / Saving Delivery Slots - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
/*--------------- Settings info ----------------*/
$settingsInfo = SELF::getSettingInfo($api_log_info);
$log_data = $api_log_info." | settingsInfo:".json_encode($settingsInfo);
SELF::createApiLog($log_data);
/*----------- 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();
$log_data = $api_log_info." | locationsList count:".json_encode(count($locationsList));
SELF::createApiLog($log_data);
foreach($locationsList as $location)//Start of Locations Loop
{
$log_data = $api_log_info." | location:".json_encode($location);
SELF::createApiLog($log_data);
//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;
$log_data = $api_log_info." | location_id:".json_encode($location_id)." | locationName:".json_encode($locationName)." | locationCode:".json_encode($locationCode)." | Is_location_up_country:".json_encode($Is_location_up_country);
SELF::createApiLog($log_data);
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$location_id.",%'");
$holidaysList->load();
// if(count($holidaysList) > 0)
// {
$holidayDates = $rangeDates = [];
foreach($holidaysList as $holiday)
{
$log_data = $api_log_info." | holiday:".json_encode($holiday);
SELF::createApiLog($log_data);
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
$holidaysenddate = $holiday->getHolidaysenddate();
$log_data = $api_log_info." | holiday_locations_list:".json_encode($holiday_locations_list)." | holidaydate:".json_encode($holidaydate)." | holidaysenddate:".json_encode($holidaysenddate);
SELF::createApiLog($log_data);
if(!empty($holidaysenddate) && $holidaysenddate){
$holidaysenddate = date("Y-m-d", strtotime($holidaysenddate));
$rangeDates = self::getDatesFromRange($holidayDate, $holidaysenddate);
$log_data = $api_log_info." | rangeDates:".json_encode($rangeDates)." | holidaysenddate:".json_encode($holidaysenddate);
SELF::createApiLog($log_data);
foreach($rangeDates as $rangeDateInfo){
$log_data = $api_log_info." | rangeDateInfo:".json_encode($rangeDateInfo);
SELF::createApiLog($log_data);
array_push($holidayDates,$rangeDateInfo);
$log_data = $api_log_info." | holidayDates:".json_encode($holidayDates);
SELF::createApiLog($log_data);
}
} else {
array_push($holidayDates,$holidayDate);
$log_data = $api_log_info." | holidayDate:".json_encode($holidayDate)." | holidayDates:".json_encode($holidayDates);
SELF::createApiLog($log_data);
}
}
// if(!empty($rangeDates)){
// echo '<pre>'; print_r($holidayDates); die;
// }
/*----------- Delivery Slot Times Loop Starts --------*/
$deliveryslottimesList = DataObject\Deliveryslottimes::getList();
$deliveryslottimesList->load();
//echo '<br>deliveryslottimesList Count:'.count($deliveryslottimesList);
$log_data = $api_log_info." | deliveryslottimesList Count:".json_encode(count($deliveryslottimesList));
SELF::createApiLog($log_data);
if(count($deliveryslottimesList)>0)
{
foreach($deliveryslottimesList as $deliveryslottimes)
{
$log_data = $api_log_info." | deliveryslottimes:".json_encode($deliveryslottimes);
SELF::createApiLog($log_data);
// 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'];
$log_data = $api_log_info." | slot_prepare_days:".json_encode($slot_prepare_days)." | slot_generate_days:".json_encode($slot_generate_days)." | saturday_slot_availability:".json_encode($saturday_slot_availability)." | sunday_slot_availability:".json_encode($sunday_slot_availability)." | setting stg_normalloc_slot_generate_days:".json_encode($settingsInfo['stg_normalloc_slot_generate_days'])." | slot_generate_days:".json_encode($slot_generate_days);
SELF::createApiLog($log_data);
/*--------------------- 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'];
$log_data = $api_log_info." | is_upcountry_configuration_applicable:".json_encode($is_upcountry_configuration_applicable)." | slot_upcountry_prepare_days:".json_encode($slot_upcountry_prepare_days)." | upcountry_slot_generate_days:".json_encode($upcountry_slot_generate_days)." | upcountry_saturday_slot_availability:".json_encode($upcountry_saturday_slot_availability)." | upcountry_sunday_slot_availability:".json_encode($upcountry_sunday_slot_availability)." | setting stg_upcountryloc_slot_generate_days:".json_encode($settingsInfo['stg_upcountryloc_slot_generate_days'])." | upcountry_slot_generate_days:".json_encode($upcountry_slot_generate_days);
SELF::createApiLog($log_data);
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];
$log_data = $api_log_info." | delSlotTimesAvailibility:".json_encode($delSlotTimesAvailibility);
SELF::createApiLog($log_data);
// echo '<pre>delSlotTimesAvailibility:'; print_r($delSlotTimesAvailibility); //die;
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
// echo '<pre>weekdates:'; print_r($weekdates);
$log_data = $api_log_info." | weekdates:".json_encode($weekdates);
SELF::createApiLog($log_data);
foreach($weekdates as $weekdate)
{
$log_data = $api_log_info." | weekdate:".json_encode($weekdate);
SELF::createApiLog($log_data);
$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);
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList));
SELF::createApiLog($log_data);
if(count($slotsList) > 0)
{
foreach($slotsList as $slot)
{
$log_data = $api_log_info." | slot:".json_encode($slot);
SELF::createApiLog($log_data);
$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);
$log_data = $api_log_info." | location_codes:".json_encode($location_codes);
SELF::createApiLog($log_data);
if(!empty($location_codes))
{
foreach($location_codes as $location_id_info){//foreach($location_codes as $location_code){//Location Code loop Starts
$log_data = $api_log_info." | location_id_info:".json_encode($location_id_info);
SELF::createApiLog($log_data);
if($location_id == $location_id_info)//if($location_id == $location_code->getId())
{
$log_data = $api_log_info." | location_id:".json_encode($location_id)." | location_id_info:".json_encode($location_id_info);
SELF::createApiLog($log_data);
// $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);
$log_data = $api_log_info." | location_code_id:".json_encode($location_code_id);
SELF::createApiLog($log_data);
$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 = [];
$log_data = $api_log_info." | checkDataList count:".json_encode(count($checkDataList));
SELF::createApiLog($log_data);
if(count($checkDataList) > 0)
{
foreach($checkDataList as $checkData)
{
$log_data = $api_log_info." | checkData:".json_encode($checkData);
SELF::createApiLog($log_data);
// $checkData_locData = $checkData->getloc_id();
// $checkData_locId = $checkData_locData->getId();
$checkData_locId = $checkData->getloc_id();
array_push($checkData_locs, $checkData_locId);
$log_data = $api_log_info." | checkData_locId:".json_encode($checkData_locId)." | checkData_locs:".json_encode($checkData_locs);
SELF::createApiLog($log_data);
}
}
$checkData_loc_valid = (empty($checkData_locs) || (!empty($checkData_locs) && !in_array($loc_id, $checkData_locs)) || count($checkDataList) <= 0)?1:0;
$log_data = $api_log_info." | checkData_loc_valid:".json_encode($checkData_loc_valid);
SELF::createApiLog($log_data);
// 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();
$log_data = $api_log_info." | objParentId :".json_encode($objParentId)." | slotObjectName :".json_encode($slotObjectName)." | save slot : success";
SELF::createApiLog($log_data);
}
// }
// }
}
/*---------- Delivery Slot Time loop ends ------------*/
}//Location Code loop ends
}
}
}
}
}
}
// }
}//End of Locations Loop
$log_data = "Ended - ".$api_log_info." | data : Slot Created for one week Successfully'";
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => 'Slot Created for one week Successfully']);
}
/**
* @Route("deliveryslots/updateslotordercount", methods={"POST"})
*/
public function updateslotordercountAction(Request $request)
{
$api_log_info = "API:Update Delivery Slot Order Count based on slotId - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
$data = [];
if($message == "No data found")
{
$slotId = $request->get('slotId');
$ordercount = $request->get('ordercount');
$log_data = $api_log_info." | slotId:".json_encode($slotId)." | ordercount:".json_encode($ordercount);
SELF::createApiLog($log_data);
if($slotId == "" || $ordercount == "")
{
$data = "slotId and ordercount are mandatory!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else
{
$slotruleObject = DataObject\Slots::getById($slotId);
$log_data = $api_log_info." | slotruleObject:".json_encode($slotruleObject);
SELF::createApiLog($log_data);
if(!empty($slotruleObject) && $slotruleObject->getId()){
$slotruleObject->setordercount($ordercount);
$slotruleObject->save();
$data = "Slot Updated Successfully!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else {
$data = "This Slot Id ".$slotId." is not existed, Please try with valid Slot Id";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
}
}else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
$returnData = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returnData:".json_encode($returnData);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $message]);
}
/**
* @Route("/deliveryslots/getSlot/{id}")
*/
public function getSlot($id)
{
$api_log_info = "API:Slot Info by Slot ID | ID:".$id." - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
$data = [];
if($message == "No data found")
{
$slot = DataObject\Slots::getById($id);
$log_data = $api_log_info." | slot:".json_encode($slot);
SELF::createApiLog($log_data);
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():'';
$log_data = $api_log_info." | slotLocationData:".json_encode($slotLocationData)." | loc_name:".json_encode($loc_name)." | loc_code:".json_encode($loc_code);
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else {
$data = "No data found";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
}else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
$returnData = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returnData:".json_encode($returnData);
SELF::createApiLog($log_data);
// return $slotsList;
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslots/getStoreslot/{id}")
*/
public function getStoreslot($id)
{
$api_log_info = "API:Get Delivery Slots based on Location Code for Today and Time only | ID:".$id." - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$data ="No data found";
if($id == "")
{
$data ="Location Code is mandatory!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else
{
/*---- Check Location by Location Code ---------*/
$locData = DataObject\Locations::getBylocation_code($id, 1);
$log_data = $api_log_info." | locData:".json_encode($locData);
SELF::createApiLog($log_data);
if(empty($locData) || empty($locData->getId()))
{
$data = "Location is not exited, please try with valid location code!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else {
$loc_id = $locData->getId();
$today_date = date("Y-m-d");//"2024-01-03";//
$cur_time = date("H:i");
$log_data = $api_log_info." | loc_id:".json_encode($loc_id)." | today_date:".json_encode($today_date)." | cur_time:".json_encode($cur_time);
SELF::createApiLog($log_data);
$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 = ".$loc_id);
$slotsList->setLimit(100);
$slotsList->setOrderKey("slotdate");
$slotsList->setOrder("asc");
$slotsList->load();
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList));
SELF::createApiLog($log_data);
$data = [];
if(count($slotsList) > 0){
foreach ($slotsList as $key => $slotInfo) {
$log_data = $api_log_info." | slotInfo:".json_encode($slotInfo);
SELF::createApiLog($log_data);
$slotLocationData = DataObject\Locations::getById($slotInfo->getLoc_id());
$log_data = $api_log_info." | slotLocationData:".json_encode($slotLocationData);
SELF::createApiLog($log_data);
$loc_name = $slotLocationData->getlocation_name();
$loc_code = $slotLocationData->getlocation_code();
$log_data = $api_log_info." | loc_name:".json_encode($loc_name)." | loc_code:".json_encode($loc_code);
SELF::createApiLog($log_data);
// 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" => $slotInfo->getId(),
"prior_time" => $slotInfo->getprior_time(),
// "picking_time" => $slotInfo->getpicking_time(),
"location_code" => $loc_code,
"loc_name" => $loc_name,
// "charge" => $slotInfo->getcharge(),
"slotdate" => $slotInfo->getslotdate(),
"fromtime" => $slotInfo->getfromtime(),
"totime" => $slotInfo->gettotime(),
"maxorder" => $slotInfo->getmaxorder(),
"ordercount" => $slotInfo->getordercount(),
"delivery_mode" => $slotInfo->getdelivery_mode());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
//}
}
} else $data = "No data found";
}
}
$return_data = ["success" => true, "data" => $data];
$log_data = $api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslottime/gelocslottimes/{locCode}")
*/
public function gelocslottimesAction($locCode)
{
$api_log_info = "API:Retriving Delivery Slots by Location Code | locCode:".$locCode." - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
$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);
$log_data = $api_log_info." | dates_list:".json_encode($dates_list);
SELF::createApiLog($log_data);
/*---- Check Location by Location Code ---------*/
$locationData = DataObject\Locations::getBylocation_code($locCode, 1);
$log_data = $api_log_info." | locationData:".json_encode($locationData);
SELF::createApiLog($log_data);
/*--------------- Settings info ----------------*/
$settingsInfo = SELF::getSettingInfo($api_log_info);
$log_data = $api_log_info." | settingsInfo:".json_encode($settingsInfo);
SELF::createApiLog($log_data);
/*----------- 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;
$log_data = $api_log_info." | setting_slot_time_flag:".json_encode($setting_slot_time_flag)."| setting_deliveryModes:".json_encode($setting_deliveryModes)."| settingDataId:".json_encode($settingDataId);
SELF::createApiLog($log_data);
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;
$log_data = $api_log_info." | parentLoc_id:".json_encode($parentLoc_id)."| parentLocationName:".json_encode($parentLocationName)."| parentLocationCode:".json_encode($parentLocationCode);
SELF::createApiLog($log_data);
//------ get holidays list ------------//
$holidaysList = DataObject\Holidays::getList();
$holidaysList->setCondition("location_code like '%,".$parentLoc_id.",%'");
$holidaysList->load();
$holidayDates = [];
foreach($holidaysList as $holiday)
{
$log_data = $api_log_info." | holiday:".json_encode($holiday);
SELF::createApiLog($log_data);
$holiday_locations_list = $holiday->getLocation_code();
$holidaydate = $holiday->getHolidaydate();
$holidayDate = date("Y-m-d", strtotime($holidaydate));
$log_data = $api_log_info." | holiday_locations_list:".json_encode($holiday_locations_list)."| holidaydate:".json_encode($holidaydate);
SELF::createApiLog($log_data);
$holidaysenddate = $holiday->getHolidaysenddate();
if(!empty($holidaysenddate) && $holidaysenddate){
$holidaysenddate = date("Y-m-d", strtotime($holidaysenddate));
$rangeDates = self::getDatesFromRange($holidayDate, $holidaysenddate);
$log_data = $api_log_info." | holidaysenddate:".json_encode($holidaysenddate)."| rangeDates:".json_encode($rangeDates);
SELF::createApiLog($log_data);
foreach($rangeDates as $rangeDateInfo){
array_push($holidayDates,$rangeDateInfo);
}
} else {
array_push($holidayDates,$holidayDate);
}
}
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->setOrderKey("o_id");
$delSlotTimesList->setOrder("desc");
$delSlotTimesList->load();
// foreach($dates_list as $cur_date){
$log_data = $api_log_info." | delSlotTimesList count:".count($delSlotTimesList);
SELF::createApiLog($log_data);
if(count($delSlotTimesList) > 0){
$cur_time = date("H:i");//"09:00";//
$log_data = $api_log_info." | cur_time:".$cur_time;
SELF::createApiLog($log_data);
foreach($delSlotTimesList as $delSlotTimes)
{
$log_data = $api_log_info." | delSlotTimes:".json_encode($delSlotTimes);
SELF::createApiLog($log_data);
//------- 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';
$log_data = $api_log_info." | slot_prepare_days:".json_encode($slot_prepare_days)."| slot_generate_days:".json_encode($slot_generate_days)."| saturday_slot_availability:".json_encode($saturday_slot_availability)."| sunday_slot_availability:".json_encode($sunday_slot_availability);
SELF::createApiLog($log_data);
/*--------------------- 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';
$log_data = $api_log_info." | is_upcountry_configuration_applicable:".json_encode($is_upcountry_configuration_applicable)."| slot_upcountry_prepare_days:".json_encode($slot_upcountry_prepare_days)."| upcountry_slot_generate_days:".json_encode($upcountry_slot_generate_days)."| upcountry_saturday_slot_availability:".json_encode($upcountry_saturday_slot_availability)."| upcountry_sunday_slot_availability:".json_encode($upcountry_sunday_slot_availability);
SELF::createApiLog($log_data);
$log_data = $api_log_info." | settings stg_deliveryslot_config_is_upcountry_configuration_applicable:".json_encode($settingsInfo['stg_deliveryslot_config_is_upcountry_configuration_applicable'])."| Is_location_up_country:".json_encode($Is_location_up_country);
SELF::createApiLog($log_data);
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;
$log_data = $api_log_info." | slot_prepare_days:".json_encode($slot_prepare_days)."| slot_generate_days:".json_encode($slot_generate_days)."| saturday_slot_availability:".json_encode($saturday_slot_availability)."| sunday_slot_availability:".json_encode($sunday_slot_availability)."| cur_slot_generate_days:".json_encode($cur_slot_generate_days)."| stg_normalloc_upcounry_slot_generate_days:".json_encode($stg_normalloc_upcounry_slot_generate_days)."| slot_generate_days:".json_encode($slot_generate_days);
SELF::createApiLog($log_data);
}
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;
$log_data = $api_log_info." | cur_slot_generate_days:".json_encode($cur_slot_generate_days)."| stg_normalloc_upcounry_slot_generate_days:".json_encode($stg_normalloc_upcounry_slot_generate_days);
SELF::createApiLog($log_data);
}
$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;
$log_data = $api_log_info." | cur_slot_prepare_days:".json_encode($cur_slot_prepare_days);
SELF::createApiLog($log_data);
$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];
$log_data = $api_log_info." | delSlotTimesAvailibility:".json_encode($delSlotTimesAvailibility);
SELF::createApiLog($log_data);
$weekdates = self::getWeekDates($holidayDates, date("Y-m-d"), $delSlotTimesAvailibility);
$log_data = $api_log_info." | weekdates:".json_encode($weekdates);
SELF::createApiLog($log_data);
// 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;
$log_data = $api_log_info." | delSlot_date:".json_encode($delSlot_date)."| delSlot_date1:".json_encode($delSlot_date1)."| cur_time_data:".json_encode($cur_time_data)."| slot_generate_days_limit:".json_encode($slot_generate_days_limit);
SELF::createApiLog($log_data);
// 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]];
*/
$log_data = $api_log_info." | slot_generate_days:".json_encode($slot_generate_days)."| cur_slot_generate_days:".json_encode($cur_slot_generate_days);
SELF::createApiLog($log_data);
if(($slot_generate_days > 0)){
$cur_weekdates = [];
if($cur_slot_generate_days > 0){
for($jj=0; $jj < $cur_slot_generate_days; $jj++)
{
$log_data = $api_log_info." | jj:".json_encode($jj)."| cur_weekdates:".json_encode($cur_weekdates)."| weekdates:".json_encode($weekdates);
SELF::createApiLog($log_data);
array_push($cur_weekdates,$weekdates[$jj]);
}
}
$weekdates = $cur_weekdates;
} else
$weekdates = [$weekdates[$stg_normalloc_upcounry_slot_generate_days]];
$log_data = $api_log_info." | stg_normalloc_upcounry_slot_generate_days:".json_encode($stg_normalloc_upcounry_slot_generate_days)."| weekdates:".json_encode($weekdates);
SELF::createApiLog($log_data);
// $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();
}
}
$log_data = $api_log_info." | slot_generate_days_date:".json_encode($slot_generate_days_date)."| delivery_modes:".json_encode($delivery_modes);
SELF::createApiLog($log_data);
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode)."| delSlotTimes Title:".json_encode($delSlotTimes->gettitle());
SELF::createApiLog($log_data);
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 ----------*/
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList))."| cur_slot_generate_days:".json_encode($cur_slot_generate_days);
SELF::createApiLog($log_data);
$delivery_mode_slots = [];
if(count($slotsList) > 0 && $cur_slot_generate_days>0){
foreach($slotsList as $slot)
{
$log_data = $api_log_info." | slot:".json_encode($slot);
SELF::createApiLog($log_data);
$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);
$log_data = $api_log_info." | delivery_mode_slot1:".json_encode($delivery_mode_slot1)."| delivery_mode_slots:".json_encode($delivery_mode_slots);
SELF::createApiLog($log_data);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
$log_data = $api_log_info." | delivery_mode_slot2:".json_encode($delivery_mode_slot2);
SELF::createApiLog($log_data);
// 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;
}
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode)."| delivery_mode_slots:".json_encode($delivery_mode_slots);
SELF::createApiLog($log_data);
}
}
$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);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
// }
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$return_data = ["success" => true, "Is_location_up_country" => $Is_location_up_country, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "Is_location_up_country" => $Is_location_up_country, "data" => $data]);
}
/**
* @Route("/api/allslots")
*/
public function allslotsAction()
{
$api_log_info = "API:All Available Slots - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$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;
$log_data = $api_log_info." | delSlotTimesList count:".json_encode(count($delSlotTimesList));
SELF::createApiLog($log_data);
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$log_data = $api_log_info." | delSlotTimes:".json_encode($delSlotTimes);
SELF::createApiLog($log_data);
$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'];
$log_data = $api_log_info." | prepare_days:".json_encode($prepare_days)." | delSlot_date:".json_encode($delSlot_date)." | delSlot_date1:".json_encode($delSlot_date1)." | cur_time:".json_encode($cur_time)." | delivery_modes:".json_encode($delivery_modes);
SELF::createApiLog($log_data);
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode);
SELF::createApiLog($log_data);
$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 ----------*/
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList));
SELF::createApiLog($log_data);
$delivery_mode_slots = [];
if(count($slotsList) > 0){
foreach($slotsList as $slot)
{
$log_data = $api_log_info." | slot:".json_encode($slot);
SELF::createApiLog($log_data);
// $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();
$log_data = $api_log_info." | slotLocationData:".json_encode($slotLocationData)." | loc_name:".json_encode($loc_name)." | loc_code:".json_encode($loc_code);
SELF::createApiLog($log_data);
$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()
);
$log_data = $api_log_info." | delivery_mode_slot1:".json_encode($delivery_mode_slot1);
SELF::createApiLog($log_data);
array_push($delivery_mode_slots, $delivery_mode_slot1);
$log_data = $api_log_info." | delivery_mode_slots:".json_encode($delivery_mode_slots);
SELF::createApiLog($log_data);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
$log_data = $api_log_info." | delivery_mode_slot2:".json_encode($delivery_mode_slot2);
SELF::createApiLog($log_data);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode)." | delivery_mode_slots_all:".json_encode($delivery_mode_slots_all);
SELF::createApiLog($log_data);
}
$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);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = [];
} else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
$log_data = "Ended - ".$api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Slots Related APIs -------------------------*/
/*---------------------------------- Delivery Slot Time Related APIs ----------------------------*/
/**
* @Route("/deliveryslottime/getslottimes")
*/
public function getslottimesAction()
{
$api_log_info = "API:Retriving all Delivery Slot times / Confencery Days - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$delSlotTimesList = DataObject\Deliveryslottimes::getList();
$delSlotTimesList->load();
$log_data = $api_log_info." | delSlotTimesList Count ; ".count($delSlotTimesList);
SELF::createApiLog($log_data);
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$log_data = $api_log_info." | delSlotTimes ; ".json_encode($delSlotTimes);
SELF::createApiLog($log_data);
$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);
$log_data = $api_log_info." | data ; ".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data = "No data found";
}else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
$log_data = "Ended - ".$api_log_info." | data ; ".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("/deliveryslottime/getslottimeslist")
*/
public function getslottimeslistAction()
{
$api_log_info = "API:Retriving all Delivery Slots - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$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;
$log_data = $api_log_info." | delSlotTimesList:".json_encode(count($delSlotTimesList));
SELF::createApiLog($log_data);
if(count($delSlotTimesList) > 0){
foreach($delSlotTimesList as $delSlotTimes)
{
$log_data = $api_log_info." | delSlotTimes:".json_encode($delSlotTimes);
SELF::createApiLog($log_data);
$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'];
$log_data = $api_log_info." | prepare_days:".json_encode($prepare_days)." | delSlot_date:".json_encode($delSlot_date)." | delSlot_date1:".json_encode($delSlot_date1)." | cur_time:".json_encode($cur_time)." | delivery_modes:".json_encode($delivery_modes);
SELF::createApiLog($log_data);
$delivery_mode_slots_all = [];
foreach($delivery_modes as $delivery_mode)
{
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode);
SELF::createApiLog($log_data);
$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 ----------*/
$log_data = $api_log_info." | slotsList count:".json_encode(count($slotsList));
SELF::createApiLog($log_data);
$delivery_mode_slots = [];
if(count($slotsList) > 0){
foreach($slotsList as $slot)
{
$log_data = $api_log_info." | slot:".json_encode($slot);
SELF::createApiLog($log_data);
// $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);
$log_data = $api_log_info." | delivery_mode_slot1:".json_encode($delivery_mode_slot1)." | delivery_mode_slots:".json_encode($delivery_mode_slots);
SELF::createApiLog($log_data);
}
}
/*---------- Slots Loop Starts ----------*/
$delivery_mode_slot2 = array($delivery_mode=>$delivery_mode_slots);
$log_data = $api_log_info." | delivery_mode_slot2:".json_encode($delivery_mode_slot2);
SELF::createApiLog($log_data);
// array_push($delivery_mode_slots_all, $delivery_mode_slot2);
$delivery_mode_slots_all[$delivery_mode] = $delivery_mode_slots;
$log_data = $api_log_info." | delivery_mode:".json_encode($delivery_mode)." | delivery_mode_slots_all:".json_encode($delivery_mode_slots_all);
SELF::createApiLog($log_data);
}
$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);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = [];
}else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
$log_data = "Ended - ".$api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Delivery Slot Time Related APIs -------------------------*/
/*----------------------------------- AWS S3 Bucket Related APIs ---------------------------*/
/**
* @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;
}
/*------------------------------ End of AWS S3 Bucket Related APIs -------------------------*/
/**
* @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]);
}
/*---------------------------------- JWT Related APIs ----------------------------*/
/**
* @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]);
}
}
}
/*------------------------------ End of JWT Related APIs -------------------------*/
/*---------------------------------- Personal Statement Related APIs ----------------------------*/
/**
* @Route("personalitystatement/getperstmtlist", methods={"POST"})
*/
public function getperstmtlistAction(Request $request)
{
$api_log_info = "API:Get Personality Statements list with or without params - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
// $data[] = ['message'=>$message];
$data = [];
if($message == "No data found")
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
// print_r($reqparams); die;
// print_r($request->get->all());
$log_data = $api_log_info." | reqparams:".json_encode($reqparams);
SELF::createApiLog($log_data);
$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']:'';
$log_data = $api_log_info." | title:".json_encode($title)." | gender:".json_encode($gender)." | standout_fitin:".json_encode($standout_fitin)." | describe_yourself:".json_encode($describe_yourself)." | occasion:".json_encode($occasion)." | priceband:".json_encode($priceband)." | blank1:".json_encode($blank1)." | blank2:".json_encode($blank2);
SELF::createApiLog($log_data);
$perstmtList = DataObject\Personalitystatements::getList();
if($title || $blank1 || $blank2 || $priceband || $gender || $standout_fitin || $describe_yourself || $occasion)
{
$whr_condition = " personality_statement != '' "; $whr_condition_array = [];
if($title){
$whr_condition .= " AND personality_statement = '".$title."'";
}
if($priceband){
$whr_condition .= " AND priceband = '".$priceband."'";
}
if($blank1){
$whr_condition .= " AND blank1 = '".$blank1."'";
}
if($blank2){
$whr_condition .= " AND blank2 = '".$blank2."'";
}
if($gender){
$whr_condition .= " AND gender LIKE '%,".$gender.",%'";
}
if($standout_fitin){
$whr_condition .= " AND standout_fitin LIKE '%,".$standout_fitin.",%'";
}
if($describe_yourself){
$whr_condition .= " AND describe_yourself LIKE '%,".$describe_yourself.",%'";
}
if($occasion){
$whr_condition .= " AND occasion LIKE '%,".$occasion.",%'";
}
// echo "whr_condition:".$whr_condition;
// echo "whr_condition_array:";
// print_r($whr_condition_array); die;
$log_data = $api_log_info." | whr_condition:".json_encode($whr_condition);
SELF::createApiLog($log_data);
$perstmtList->setCondition($whr_condition);
}
$perstmtList->load();
$log_data = $api_log_info." | perstmtList count:".json_encode(count($perstmtList));
SELF::createApiLog($log_data);
foreach ($perstmtList as $key => $perstmtObj) {
$log_data = $api_log_info." | perstmtObj:".json_encode($perstmtObj);
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
$data = (empty($data))?$message:$data;
// return $slotsList;
$return_data = ["success" => true, "data" => $data];
$log_data = $api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("personalitystatement/perstmtlist")
*/
public function perstmtlistAction()
{
$api_log_info = "API:Get All Personality Statements - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$perstmtList = DataObject\Personalitystatements::getList();
$perstmtList->load();
$log_data = $api_log_info." | perstmtList count:".json_encode(count($perstmtList));
SELF::createApiLog($log_data);
if(count($perstmtList)>0){
foreach ($perstmtList as $key => $perstmtObj) {
$log_data = $api_log_info." | perstmtObj:".json_encode($perstmtObj);
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("personalitystatement/perstmtinfo/{id}")
*/
public function perstmtinfoAction($id)
{
$api_log_info = "API:Get Personality Statement Info by ID - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$log_data = $api_log_info." | ID:".$id;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$perstmtObject = DataObject\Personalitystatements::getById($id);
$log_data = $api_log_info." | perstmtObject:".json_encode($perstmtObject);
SELF::createApiLog($log_data);
if(!empty($perstmtObject) && $perstmtObject->getpersonality_statement()){
$log_data = $api_log_info." | perstmtObject getpersonality_statement:".json_encode($perstmtObject->getpersonality_statement());
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$returnData = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returnData:".json_encode($returnData);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Personal Statement Related APIs -------------------------*/
/*---------------------------------- Shipping Rate / Delivery Fee Related APIs ----------------------------*/
/**
* @Route("api/shippingchargeslist")
*/
public function shippingchargeslistAction()
{
$api_log_info = "API:Get Shipping Charges List - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$shippingchargesList = DataObject\Shippingcharges::getList();
$shippingchargesList->load();
$log_data = $api_log_info." | shippingchargesList count:".json_encode(count($shippingchargesList));
SELF::createApiLog($log_data);
if(count($shippingchargesList)>0){
foreach ($shippingchargesList as $key => $shippingchargeObj) {
$log_data = $api_log_info." | shippingchargeObj:".json_encode($shippingchargeObj);
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$returnData = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | returnData:".json_encode($returnData);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/shippingrateslist", methods={"POST"})
*/
public function shippingrateslistAction()
{
$api_log_info = "API:Shipping Rate / Delivery Fee List - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$log_data = $api_log_info." | reqparams:".json_encode($reqparams);
SELF::createApiLog($log_data);
$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']:'';
$log_data = $api_log_info." | weight_cart:".json_encode($weight_cart)." | req_weight_cart:".json_encode($req_weight_cart)." | locationCode:".json_encode($locationCode)." | shipping_state_code:".json_encode($shipping_state_code)." | pincode:".json_encode($pincode)." | order_amount:".json_encode($order_amount);
SELF::createApiLog($log_data);
if($weight_cart == '' || $locationCode == '' || $shipping_state_code == '' || $pincode == '' || $order_amount == '')
{
$data = "weight_cart, locationCode, shipping_state_code, pincode and order_amount are mandatory!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} 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;
$log_data = $api_log_info." | shippingRatecardObject:".json_encode($shippingRatecardObject);
SELF::createApiLog($log_data);
// $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.")");
$log_data = $api_log_info." | shippingRatecardId:".json_encode($shippingRatecardId);
SELF::createApiLog($log_data);
/*----- 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);
$log_data = $api_log_info." | locData:".json_encode($locData)." | pincodeInfo:".json_encode($pincodeInfo)." | stateInfo:".json_encode($stateInfo)." | shipChargeInfo:".json_encode($shipChargeInfo);
SELF::createApiLog($log_data);
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];
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else {
$locationId = $locData->getId();
$locationName = $locData->getLocation_name();
$message = SELF::verifyauthToken();
$log_data = $api_log_info." | locationId:".json_encode($locationId)." | locationName:".json_encode($locationName)." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
/*------ Check Location is Up Country or not --------*/
$Is_location_up_country = (strpos(strtolower($locationName),"up country"))?1:0;
$log_data = $api_log_info." | Is_location_up_country:".json_encode($Is_location_up_country);
SELF::createApiLog($log_data);
/*------ 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;
$log_data = $api_log_info." | settingsObject:".json_encode($settingsObject);
SELF::createApiLog($log_data);
$settingsObjectId = $dbConnection->fetchOne("select * from ".$settingsObject." order by oo_id asc");
$log_data = $api_log_info." | settingsObjectId:".json_encode($settingsObjectId);
SELF::createApiLog($log_data);
/*---- Get Settings Data ---------*/
$settingsData = DataObject\Settings::getById($settingsObjectId);
$log_data = $api_log_info." | settingsData:".json_encode($settingsData);
SELF::createApiLog($log_data);
// echo '<pre>settingsObjectId:'.$settingsObjectId;
// echo '<pre>settingsData:';
// print_r($settingsData->getis_deliveryfee_config_applicable());
$is_shippingapplicable=$pincodeInfo->getis_shipping_applicable();
$log_data = $api_log_info." | is_shippingapplicable:".json_encode($is_shippingapplicable);
SELF::createApiLog($log_data);
$pincode_data['pincode'] = $pincodeInfo->getpincode();
$pincode_data['state'] = $pincodeInfo->getstate();
$pincode_data['is_shipping_applicable'] = $pincodeInfo->getis_shipping_applicable();
$pincode_data['deliverytype'] = $pincodeInfo->getdeliverytype();
$log_data = $api_log_info." | pincode_data:".json_encode($pincode_data);
SELF::createApiLog($log_data);
/*----------- 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():'';
$log_data = $api_log_info." | final_cost:".json_encode($final_cost)." | rate_discount_perc:".json_encode($rate_discount_perc)." | cur_noofkgs:".json_encode($cur_noofkgs)." | zone_name:".json_encode($zone_name);
SELF::createApiLog($log_data);
/*----------- 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();
$log_data = $api_log_info." | shippingratesList count:".json_encode(count($shippingratesList));
SELF::createApiLog($log_data);
if(count($shippingratesList)>0){
$ii=0;
foreach ($shippingratesList as $key => $shippingrateObj) {
$log_data = $api_log_info." | key:".json_encode($key)." | shippingrateObj:".json_encode($shippingrateObj);
SELF::createApiLog($log_data);
$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()
);
$log_data = $api_log_info." | Initialise data_key, data_val, data_key2 and data_val2 values as null | data:".json_encode($data);
SELF::createApiLog($log_data);
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();
}
}
$log_data = $api_log_info." | zone_name:".json_encode($zone_name)." | final_cost:".json_encode($final_cost);
SELF::createApiLog($log_data);
$data[$ii]['locationCode'] = $locationCode;
$data[$ii]['pincode'] = $pincode_data;
$log_data = $api_log_info." | ii:".json_encode($ii)." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
$minimum_order = $maximum_order = $discount_percentage = 0; $shippingRules = [];
$log_data = $api_log_info." | Initialise minimum_order, maximum_order, discount_percentage and shippingRules values as null | is_shippingapplicable:".json_encode($is_shippingapplicable);
SELF::createApiLog($log_data);
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();
$log_data = $api_log_info." | shippingchargesList count:".json_encode(count($shippingchargesList));
SELF::createApiLog($log_data);
if(count($shippingchargesList)>0)
{
foreach($shippingchargesList as $shippingchargeObj)
{
$log_data = $api_log_info." | shippingchargeObj:".json_encode($shippingchargeObj);
SELF::createApiLog($log_data);
$minimum_order = $shippingchargeObj->getminimum_order();
$maximum_order = $shippingchargeObj->getmaximum_order();
$discount_percentage = $shippingchargeObj->getdiscount_percentage();
$log_data = $api_log_info." | minimum_order:".json_encode($minimum_order)." | maximum_order:".json_encode($maximum_order)." | discount_percentage:".json_encode($discount_percentage);
SELF::createApiLog($log_data);
$shippingRules['shippingRuleId'] = $shippingchargeObj->getId();
$shippingRules['minimum_order_amount'] = $minimum_order;
$shippingRules['maximum_order_amount'] = $maximum_order;
$shippingRules['discount_percentage'] = $discount_percentage;
$log_data = $api_log_info." | shippingRules:".json_encode($shippingRules);
SELF::createApiLog($log_data);
}
$data[$ii]['shippingRules'] = $shippingRules;
$log_data = $api_log_info." | ii:".json_encode($ii)." | data:".json_encode($data);
SELF::createApiLog($log_data);
$rate_discount_perc = ($minimum_order <= $order_amount && $maximum_order >= $order_amount)?$discount_percentage:0;
$final_cost = $final_cost - (($final_cost*$rate_discount_perc)/100);
$log_data = $api_log_info." | rate_discount_perc:".json_encode($rate_discount_perc)." | final_cost:".json_encode($final_cost);
SELF::createApiLog($log_data);
}
}
/*----------- Delivery Fee Configuration Condition --------------*/
$log_data = $api_log_info." | settingsData getis_deliveryfee_config_applicable:".json_encode($settingsData->getis_deliveryfee_config_applicable());
SELF::createApiLog($log_data);
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();
$log_data = $api_log_info." | stg_deliveryfee_config:".json_encode($stg_deliveryfee_config)." | stg_deliveryfee_config_location_lessthan_charge:".json_encode($stg_deliveryfee_config_location_lessthan_charge)." | stg_deliveryfee_config_location_greaterthanequal_charge:".json_encode($stg_deliveryfee_config_location_greaterthanequal_charge)." | stg_deliveryfee_config_upcountry_lessthan_charge:".json_encode($stg_deliveryfee_config_upcountry_lessthan_charge)." | stg_deliveryfee_config_upcountry_greaterthanequal_charge:".json_encode($stg_deliveryfee_config_upcountry_greaterthanequal_charge);
SELF::createApiLog($log_data);
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;
$log_data = $api_log_info." | final_cost:".json_encode($final_cost);
SELF::createApiLog($log_data);
}
$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();
}
}
}
$log_data = $api_log_info." | final_cost:".json_encode($final_cost)." | ii:".json_encode($ii)." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else $data[] = ['message'=>$message];
/*----------- End of Get Shipping rate data based on state code and weight cart ----------*/
} else $data[] = ['message'=>$message];
}
}
} else $data[] = ['message'=>$message];
$log_data = "Ended - ".$api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Shipping Rate / Delivery Fee Related APIs -------------------------*/
/*---------------------------------- Factory Related APIs ----------------------------*/
/**
* @Route("/factory/getfactories")
*/
public function getfactories()
{
$api_log_info = "API:Get All Factories - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$factoriesList = DataObject\Factories::getList();
$factoriesList->load();
$log_data = $api_log_info." | factoriesList count:".json_encode(count($factoriesList));
SELF::createApiLog($log_data);
if(count($factoriesList) > 0){
foreach ($factoriesList as $key => $blog) {
$log_data = $api_log_info." | key:".json_encode($key)." | blog:".json_encode($blog);
SELF::createApiLog($log_data);
$bestbefore_date = '';
if($blog->getbestbefore()){
$bestbefore_dt = date("m/d/y", strtotime($blog->getbestbefore()));
$bestbefore_date = Carbon::createFromFormat('m/d/y', $bestbefore_dt);
$log_data = $api_log_info." | bestbefore_dt:".json_encode($bestbefore_dt)." | bestbefore_date:".json_encode($bestbefore_date);
SELF::createApiLog($log_data);
}
$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);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$log_data = "Ended - ".$api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/getfactorydata", methods={"POST"})
*/
public function getfactorydataAction(Request $request)
{
$api_log_info = "API:Get factory Info by Code - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$factorycode = $request->get('factorycode');
$log_data = $api_log_info." | factorycode:".json_encode($factorycode);
SELF::createApiLog($log_data);
if($factorycode == "")
{
$data = "Factory Code is mandatory!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else
{
$data = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
if($data == "No data found")
{
/*---- Check Factory by Code ---------*/
$factoryData = DataObject\Factories::getBycode($factorycode, 1);
$log_data = $api_log_info." | factoryData:".json_encode($factoryData);
SELF::createApiLog($log_data);
if(!empty($factoryData) && $factoryData->getId()){
$log_data = $api_log_info." | factoryData getId:".json_encode($factoryData->getId());
SELF::createApiLog($log_data);
$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());
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else {
$data = "No data found!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
}
}
$log_data = "Ended - ".$api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @Route("api/getfactoriesdata", methods={"POST"})
*/
public function getfactoriesdataAction(Request $request)
{
$api_log_info = "API:Get Factories list by multiple Factory codes - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$log_data = $api_log_info." | reqparams:".json_encode($reqparams);
SELF::createApiLog($log_data);
$factorycodes = (isset($reqparams['factorycodes']))?$reqparams['factorycodes']:'';
$log_data = $api_log_info." | factorycodes:".json_encode($factorycodes);
SELF::createApiLog($log_data);
// $factorycode = $request->get('factorycode');
if($factorycodes == "")
{
$data = "Factory Code(s) is(are) mandatory!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else
{
$data = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
if($data == "No data found")
{
/*---- Check Factory by Code ---------*/
$factoriesData = new DataObject\Factories\Listing();
$factoriesData->setCondition("code IN (?)", [$factorycodes]);
$factoriesData->load();
$log_data = $api_log_info." | factoriesData count:".json_encode(count($factoriesData));
SELF::createApiLog($log_data);
if(!empty($factoriesData) && count($factoriesData)>0){
$data = [];
foreach($factoriesData as $factoryData){
$log_data = $api_log_info." | factoryData:".json_encode($factoryData);
SELF::createApiLog($log_data);
$curdata = 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());
$log_data = $api_log_info." | curdata:".json_encode($curdata);
SELF::createApiLog($log_data);
array_push($data, $curdata);
}
} else {
$data = "No data found!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
}
}
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Factory Related APIs -------------------------*/
/*---------------------------------- Faq Related APIs ----------------------------*/
/**
* @param Request $request
*
* @Route("/faqApi1",methods={"POST"})
*
* @return Response
*
*/
public function faqApi1Action(Request $request)
{
$api_log_info = "API:Get Faq List by locationcode with or without type - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$data = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
if($data == "No data found")
{
$locationcode = (!empty($request->get('location_code')))?$request->get('location_code'):'';
if($locationcode == "")
{
$data = "Location Code is mandatory";
} else {
$getlocationInfo = DataObject\Locations::getBylocation_code($locationcode, 1);
$log_data = $api_log_info." | getlocationInfo :".json_encode($getlocationInfo);
SELF::createApiLog($log_data);
if((!empty($getlocationInfo))){
$loc_name = (!empty($getlocationInfo->getlocation_name()))?$getlocationInfo->getlocation_name():'';
$loc_code = (!empty($getlocationInfo->getlocation_code()))?$getlocationInfo->getlocation_code():'';
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
$faqType = (!empty($request->get('type')) && $request->get('type') == 'All')?'':((!empty($request->get('type')) && $request->get('type') != 'All')?$request->get('type'):'General');
$log_data = $api_log_info." | locationcode:".json_encode($locationcode)." | faqType:".json_encode($faqType);
SELF::createApiLog($log_data);
$faqTypes_list = ['','All','General', 'Loyalty'];
if(!in_array($faqType, $faqTypes_list)){
$data = "You are entered Type is Invalid, Please try again";
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
$entries = new DataObject\ItcAddFaq\Listing();
$whr_condition = " faqQuestion!= '' ";
if($locationcode != '')
$whr_condition .= " AND location_code= '".$loc_name."' ";
if($faqType != '')
$whr_condition .= " AND faqType= '".$faqType."' ";
// if($locationcode != '')
// $entries->setCondition("location_name = :location_name", ["location_name" => $locationcode]);
// if($faqType != '')
// $entries->setCondition("faqType = :faqType", ["faqType" => $faqType]);
$entries->setCondition($whr_condition);
$entries->load();
$log_data = $api_log_info." | faq entries count :".json_encode(count($entries));
SELF::createApiLog($log_data);
$data = (count($entries)>0)?array():"No data found";
foreach($entries as $key => $entrie){
$log_data = $api_log_info." | faq key :".json_encode($key)." | faq entrie :".json_encode($entrie);
SELF::createApiLog($log_data);
if($entrie->getlocation_code()){
$locationInfo = DataObject\Locations::getBylocation_name($entrie->getlocation_code(), 1);
$log_data = $api_log_info." | locationInfo :".json_encode($locationInfo);
SELF::createApiLog($log_data);
$loc_name = (!empty($locationInfo->getlocation_name()))?$locationInfo->getlocation_name():'';
$loc_code = (!empty($locationInfo->getlocation_code()))?$locationInfo->getlocation_code():'';
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
}
$data[] = array("faqId" => $entrie->getfaqId(),
"location_code" => $loc_code,
"location_name" => $loc_name,
"faqQuestion" => $entrie->getfaqQuestion(),
"faqAnswer" => $entrie->getfaqAnswer(),
"Type" => $entrie->getfaqType(),
);
$log_data = $api_log_info." | data :".json_encode($data);
SELF::createApiLog($log_data);
}
} else {
$data = "Invalid Location Code, Please enter valid Location Code";
$log_data = $api_log_info." | data :".json_encode($data);
SELF::createApiLog($log_data);
}
}
}
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/**
* @param Request $request
*
* @Route("/faqApi",methods={"POST"})
*
* @return Response
*
*/
public function faqApiAction(Request $request)
{
$api_log_info = "API:Get Faq List by locationcode with or without type - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$data = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
if($data == "No data found")
{
$locationcode = (!empty($request->get('location_code')))?$request->get('location_code'):'';
// if($locationcode == "")
// {
// $data = "Location Code is mandatory";
// } else {
$getlocationInfo = (isset($locationcode) && $locationcode!='')?DataObject\Locations::getBylocation_code($locationcode, 1):[];
$log_data = $api_log_info." | getlocationInfo :".json_encode($getlocationInfo);
SELF::createApiLog($log_data);
// if((!empty($getlocationInfo))){
$loc_name = (!empty($getlocationInfo) && !empty($getlocationInfo->getlocation_name()))?$getlocationInfo->getlocation_name():'';
$loc_code = (!empty($getlocationInfo) && !empty($getlocationInfo->getlocation_code()))?$getlocationInfo->getlocation_code():'';
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
$faqType = (!empty($request->get('type')) && $request->get('type') == 'All')?'':((!empty($request->get('type')) && $request->get('type') != 'All')?$request->get('type'):'General');
$log_data = $api_log_info." | locationcode:".json_encode($locationcode)." | faqType:".json_encode($faqType);
SELF::createApiLog($log_data);
$faqTypes_list = ['','All','General', 'Loyalty'];
if(!in_array($faqType, $faqTypes_list)){
$data = "You are entered Type is Invalid, Please try again";
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
$entries = new DataObject\ItcAddFaq\Listing();
$whr_condition = " faqQuestion!= '' ";
if($locationcode != '')
$whr_condition .= " AND location_code= '".$loc_name."' ";
if($faqType != '')
$whr_condition .= " AND faqType= '".$faqType."' ";
// if($locationcode != '')
// $entries->setCondition("location_name = :location_name", ["location_name" => $locationcode]);
// if($faqType != '')
// $entries->setCondition("faqType = :faqType", ["faqType" => $faqType]);
$entries->setCondition($whr_condition);
$entries->load();
$log_data = $api_log_info." | faq entries count :".json_encode(count($entries));
SELF::createApiLog($log_data);
$data = (count($entries)>0)?array():"No data found";
foreach($entries as $key => $entrie){
$log_data = $api_log_info." | faq key :".json_encode($key)." | faq entrie :".json_encode($entrie);
SELF::createApiLog($log_data);
if($entrie->getlocation_code()){
$locationInfo = DataObject\Locations::getBylocation_name($entrie->getlocation_code(), 1);
$log_data = $api_log_info." | locationInfo :".json_encode($locationInfo);
SELF::createApiLog($log_data);
$loc_name = (!empty($locationInfo->getlocation_name()))?$locationInfo->getlocation_name():'';
$loc_code = (!empty($locationInfo->getlocation_code()))?$locationInfo->getlocation_code():'';
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
}
$data[] = array("faqId" => $entrie->getfaqId(),
"location_code" => $loc_code,
"location_name" => $loc_name,
"faqQuestion" => $entrie->getfaqQuestion(),
"faqAnswer" => $entrie->getfaqAnswer(),
"Type" => $entrie->getfaqType(),
);
$log_data = $api_log_info." | data :".json_encode($data);
SELF::createApiLog($log_data);
}
// } else {
// $data = "Invalid Location Code, Please enter valid Location Code";
// $log_data = $api_log_info." | data :".json_encode($data);
// SELF::createApiLog($log_data);
// }
// }
}
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Faq Related APIs -------------------------*/
/*--------------------------------- Pincode Related APIs -----------------------------*/
/**
* @param Request $request
*
* @Route("/wearhouseDetectionApi",methods={"POST"})
*
* @return Response
*
*/
public function wearhouseDetectionApiAction(Request $request)
{
$api_log_info = "API:Get Wearhouse data by Pincode - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken();
$log_data = $api_log_info." | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
if($request->get('pincode')){
$pincode = $request->get('pincode');
$log_data = $api_log_info." | pincode:".json_encode($pincode);
SELF::createApiLog($log_data);
// $entries = new DataObject\ItcAddPincode\Listing();
// $entries->setCondition("pincode = :name", ["name" => $pincode]);
// $entries->load();
$getpincodeInfo = DataObject\ItcAddPincode::getBypincode($pincode, 1);
$log_data = $api_log_info." | getpincodeInfo :".json_encode($getpincodeInfo);
SELF::createApiLog($log_data);
if((!empty($getpincodeInfo))){
$loc_name = $loc_code = '';
$location_name = (!empty($getpincodeInfo->getlocation_code()))?$getpincodeInfo->getlocation_code():"";
$log_data = $api_log_info." | location_name:".json_encode($location_name);
SELF::createApiLog($log_data);
if(!empty($location_name)){
$getlocationInfo = DataObject\Locations::getBylocation_name($location_name, 1);
$log_data = $api_log_info." | getlocationInfo :".json_encode($getlocationInfo);
SELF::createApiLog($log_data);
if((!empty($getlocationInfo))){
$loc_name = (!empty($getlocationInfo->getlocation_name()))?$getlocationInfo->getlocation_name():'';
$loc_code = (!empty($getlocationInfo->getlocation_code()))?$getlocationInfo->getlocation_code():'';
}
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
}
$data = array("pincode" => $getpincodeInfo->getpincode(),
"store_code" => $loc_code,
"location_name" => $loc_name,
"city_name" => $getpincodeInfo->getcity(),
"state" => $getpincodeInfo->getstate(),
"delivery_type" => $getpincodeInfo->getdeliverytype(),
"is_shipping_applicable" => $getpincodeInfo->getis_shipping_applicable(),
"merichakki_available" => $getpincodeInfo->getmerichakki_available(),
"nammachakki_available" => $getpincodeInfo->getnammachakki_available(),
"vin_instance" => $getpincodeInfo->getvin_instance(),
);
} else {
$data = "You are entered Pincode is Invalid, Please try again";
}
$log_data = $api_log_info." | data :".json_encode($data);
SELF::createApiLog($log_data);
}elseif($request->get('city_name')){
$city = $request->get('city_name');
$log_data = $api_log_info." | city :".json_encode($city);
SELF::createApiLog($log_data);
$entries = new DataObject\ItcAddPincode\Listing();
$entries->setCondition("city = :name OR location_code = :name", ["name" => $city,"location_code" => $city]);
$entries->setLimit(1);
$entries->load();
$log_data = $api_log_info." | entries count :".json_encode(count($entries));
SELF::createApiLog($log_data);
foreach($entries as $key => $entrie){
$log_data = $api_log_info." | entrie :".json_encode($entrie);
SELF::createApiLog($log_data);
$loc_name = $loc_code = '';
$location_name = (!empty($entrie->getlocation_code()))?$entrie->getlocation_code():"";
$log_data = $api_log_info." | location_name:".json_encode($location_name);
SELF::createApiLog($log_data);
if(!empty($location_name)){
$getlocationInfo = DataObject\Locations::getBylocation_name($location_name, 1);
$log_data = $api_log_info." | getlocationInfo :".json_encode($getlocationInfo);
SELF::createApiLog($log_data);
if((!empty($getlocationInfo))){
$loc_name = (!empty($getlocationInfo->getlocation_name()))?$getlocationInfo->getlocation_name():'';
$loc_code = (!empty($getlocationInfo->getlocation_code()))?$getlocationInfo->getlocation_code():'';
}
$log_data = $api_log_info." | loc_name :".json_encode($loc_name)." | loc_code :".json_encode($loc_code);
SELF::createApiLog($log_data);
}
$data = array("pincode" => $entrie->getpincode(),
"store_code" => $loc_code,
"location_name" => $loc_name,
"city_name" => $entrie->getcity(),
"state" => $entrie->getstate(),
"delivery_type" => $entrie->getdeliverytype(),
"is_shipping_applicable" => $entrie->getis_shipping_applicable(),
"merichakki_available" => $entrie->getmerichakki_available(),
"nammachakki_available" => $entrie->getnammachakki_available(),
"vin_instance" => $entrie->getvin_instance(),
);
}
} else {
$data = "Pincode is mandatory";
}
}
else
$data[] = ['message'=>$message];
if(!empty($data)){
$success = (empty($data['pincode'])) ? false : true;
if ($success) {
return $this->json(["success" => $success, "data" => $data]);
} else {
return $this->json(["success" => $success, 'message' => $data]);
}
}else{
return $this->json(["success" => false, "message" => "Service not available"]);
}
}
/*------------------------------ End of Pincode Related APIs -------------------------*/
/*---------------------------------- Voucher Related APIs ----------------------------*/
/**
* @Route("api/getvouchersdata", methods={"POST"})
*/
public function getvouchersdataAction(Request $request)
{
$api_log_info = "API:Get Vouchers list by multiple voucher codes - ".date("YmdHis")." ".time();
$log_data = "Started - ".$api_log_info;
SELF::createApiLog($log_data);
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$log_data = $api_log_info." | reqparams:".json_encode($reqparams);
SELF::createApiLog($log_data);
$vouchercodes = (isset($reqparams['vouchercodes']))?$reqparams['vouchercodes']:'';
$vouchertype = (isset($reqparams['vouchertype']))?$reqparams['vouchertype']:'';
$log_data = $api_log_info." | vouchercodes:".json_encode($vouchercodes)." | vouchertype:".json_encode($vouchertype);
SELF::createApiLog($log_data);
// $factorycode = $request->get('factorycode');
if(($vouchercodes == "" || !is_array($vouchercodes)) && ($vouchertype == '' || ($vouchertype && !in_array($vouchertype, ["Master", "all"]))))
{
$data = "Voucher Code(s) OR Voucher Type is(are) mandatory, Voucher Type must be like Master OR all!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
} else
{
// die;
$data = SELF::verifyauthToken($api_log_info);
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
if($data == "No data found")
{
$vouchertype = ($vouchertype == 'all')?'Voucher':$vouchertype;
/*---- Get Master Voucher data by Master Voucher Code ---------*/
$master_voucher = "Master_Voucher";
$masterVoucherData = DataObject\Vouchers::getByvoucher_code($master_voucher, 1);
$projectUrl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://';
$projectUrl .= $_SERVER['SERVER_NAME'];
$log_data = $api_log_info." | projectUrl:".json_encode($projectUrl);
SELF::createApiLog($log_data);
/*---- Check Factory by Code ---------*/
$vouchersData = new DataObject\Vouchers\Listing();
if($vouchercodes)
$vouchersData->setCondition("voucher_code IN (?)", [$vouchercodes]);
else if($vouchertype)
$vouchersData->setCondition("voucher_type IN (?)", [$vouchertype]);
$vouchersData->load();
$log_data = $api_log_info." | vouchersData count:".json_encode(count($vouchersData));
SELF::createApiLog($log_data);
if(!empty($vouchersData) && count($vouchersData)>0){
$data = [];
foreach($vouchersData as $voucherData){
$log_data = $api_log_info." | voucherData:".json_encode($voucherData);
SELF::createApiLog($log_data);
$voucher_logo_path = ($voucherData->getvoucher_type() == "Master")?$masterVoucherData->getvoucher_logo():$voucherData->getvoucher_logo();
$voucher_logo_path = $projectUrl."/uploads/".$voucher_logo_path;
$voucher_background_image_path = $projectUrl."/uploads/".($voucherData->getvoucher_type() == "Master")?$masterVoucherData->getvoucher_background_image():$voucherData->getvoucher_background_image();
$voucher_background_image_path = $projectUrl."/uploads/".$voucher_background_image_path;
$curdata = array(
"id" => $voucherData->getId(),
"voucher_code" => $voucherData->getvoucher_code(),
"about_offer" => ($voucherData->getvoucher_type() == "Master")?$masterVoucherData->getabout_offer():$voucherData->getabout_offer(),
"avail_offer" => ($voucherData->getvoucher_type() == "Master")?$masterVoucherData->getavail_offer():$voucherData->getavail_offer(),
"voucher_logo_path" => $voucher_logo_path,
"voucher_background_image_path" => $voucher_background_image_path);
$log_data = $api_log_info." | curdata:".json_encode($curdata);
SELF::createApiLog($log_data);
array_push($data, $curdata);
}
} else {
$data = "No data found!";
$log_data = $api_log_info." | data:".json_encode($data);
SELF::createApiLog($log_data);
}
}
}
$return_data = ["success" => true, "data" => $data];
$log_data = "Ended - ".$api_log_info." | return_data:".json_encode($return_data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*------------------------------ End of Voucher Related APIs -------------------------*/
/*---------------------------------- Log Related APIs ----------------------------*/
/**
* @Route("/api/log_info/{date?}")
*/
public function log_infoAction($date)
{
// $date = ($date == '')?date("Y-m-d", strtotime("-1 day")):$date;
$date = ($date == '')?date("Y-m-d"):$date;
if($date == '')
{
$data = "Date is mandatory!";
} else {
$file = '../var/log/slot-api-log_'.$date.'.txt';
if(file_exists($file)){
$myfile = fopen($file, "r") or die("Unable to open file!");
$data = fread($myfile,filesize($file));
fclose($myfile);
} else {
$data = "The file is not exited!";
}
}
return $this->json(["success" => true, "date" => $date, "data" => $data]);
}
/**
* @Route("/api/log_info_data")
*/
public function log_info_dataAction(Request $requet)
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$date = (isset($reqparams['date']))?$reqparams['date']:'';
$from_line = (isset($reqparams['from_line']))?$reqparams['from_line']:'';
$to_line = (isset($reqparams['to_line']))?$reqparams['to_line']:'';
$date = ($date == '')?date("Y-m-d"):$date;
if($date == '' || $from_line == '' || $to_line == '')
{
$data = "Date, from_line and to_line are mandatory!";
} else {
$file = '../var/log/slot-api-log_'.$date.'.txt';
if(file_exists($file)){
$splitdata = array_slice(file($file), $from_line, $to_line);
echo $data = implode('', $splitdata); die;
} else {
$data = "The file is not exited!";
}
}
return $this->json(["success" => true, "date" => $date, "data" => $data]);
}
/**
* @Route("/api/delete_log_file/{date}")
*/
public function delete_log_fileAction($date)
{
if($date == '')
{
$data = "Date is mandatory!";
} else {
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$file = '../var/log/slot-api-log_'.$date.'.txt';
if(file_exists($file)){
unlink($file);
$data = "Deleted the file successfully!";
} else {
$data = "The file is not exited!";
}
}else $data[] = ['message'=>$message];
}
return $this->json(["success" => true, "date" => $date, "data" => $data]);
}
/**
* @Route("/api/delete_log_files")
*/
public function delete_log_filesAction(Request $request)
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$fromdate = (isset($reqparams['fromdate']))?$reqparams['fromdate']:'';
$todate = (isset($reqparams['todate']))?$reqparams['todate']:'';
if($fromdate == '' || $todate == '')
{
$data = "From Date and To Date are mandatory!";
} else {
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$rangeDates = SELF::getDatesFromRange($fromdate, $todate);
// echo 'rangeDates:<pre>';
// print_r($rangeDates); die;
foreach($rangeDates as $rangeDateInfo){
$file = '../var/log/slot-api-log_'.$rangeDateInfo.'.txt';
if(file_exists($file)){
unlink($file);
$data = "Deleted the file successfully!";
} else {
$data = (isset($data) && $data == "Deleted the file successfully!")?$data:"The file is not exited!";
}
}
}else $data[] = ['message'=>$message];
}
return $this->json(["success" => true, "fromdate" => $fromdate, "todate" => $todate, "data" => $data]);
}
/**
* @Route("/api/get_log_files")
*/
public function get_log_filesAction(Request $request)
{
$reqparams = (array) json_decode(file_get_contents('php://input'), TRUE);
$fromdate = (isset($reqparams['fromdate']))?$reqparams['fromdate']:'';
$todate = (isset($reqparams['todate']))?$reqparams['todate']:'';
$filenames = [];
if($fromdate == '' || $todate == '')
{
$data = "From Date and To Date are mandatory!";
} else {
$message = SELF::verifyauthToken();
if($message == "No data found")
{
$rangeDates = SELF::getDatesFromRange($fromdate, $todate);
// echo 'rangeDates:<pre>';
// print_r($rangeDates); die;
foreach($rangeDates as $rangeDateInfo){
$file = '../var/log/slot-api-log_'.$rangeDateInfo.'.txt';
if(file_exists($file)){
array_push($filenames, 'slot-api-log_'.$rangeDateInfo.'.txt');
} else {
$msg = (!empty($filenames))?'':"The file is not exited!";
}
}
$data = (!empty($filenames))?$filenames:$msg;
}else $data[] = ['message'=>$message];
}
return $this->json(["success" => true, "fromdate" => $fromdate, "todate" => $todate, "data" => $data]);
}
/*------------------------------ End of Log Related APIs -------------------------*/
/**
* @Route("/location/locationslist")
*/
public function locationslist()
{
$log_data = "Started - API:Get All Locations";
SELF::createApiLog($log_data);
$message = SELF::verifyauthToken();
$log_data = "API:Get All Locations | message:".json_encode($message);
SELF::createApiLog($log_data);
if($message == "No data found")
{
$locationsList = DataObject\Locations::getList();
$locationsList->load();
$log_data = "API:Get All Locations | locationsList count :".json_encode(count($locationsList));
SELF::createApiLog($log_data);
if(count($locationsList) > 0){
foreach ($locationsList as $key => $location) {
$log_data = "API:Get All Locations | location :".json_encode($location);
SELF::createApiLog($log_data);
$data[] = array(
"Id" => $location->getId(),
"location_name" => $location->getLocation_name(),
"location_code" => $location->getLocation_code());
$log_data = "API:Get All Locations | data :".json_encode($data);
SELF::createApiLog($log_data);
}
} else $data[] = ['message'=>$message];
} else $data[] = ['message'=>$message];
$log_data = "Ended - API:Get All Locations | data :".json_encode($data);
SELF::createApiLog($log_data);
return $this->json(["success" => true, "data" => $data]);
}
/*--------------- Authentication related methods ----------------*/
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_log_info='')
{
$start_method_log_info = "Verify Auth Token Method";
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | Started - ".$start_method_log_info:"Started - ".$start_method_log_info;
$log_data = $api_log_method_info;
SELF::createApiLog($log_data);
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | ".$start_method_log_info:$start_method_log_info;
$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;
}
}
}
$apikeyCheck_valid = 1;
$message = "No data found";
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | Ended - ".$start_method_log_info:"Ended - ".$start_method_log_info;
$log_data = $api_log_method_info." | message:".$message;
SELF::createApiLog($log_data);
return $message;
}
/*--------------- End of Authentication related methods ------------*/
/*-------------------------- Sub methods ---------------------------*/
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;
}
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;
}
public function getSettingInfo($api_log_info='')
{
$start_method_log_info = "Setting info Method";
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | Started - ".$start_method_log_info:"Started - ".$start_method_log_info;
$log_data = $api_log_method_info;
SELF::createApiLog($log_data);
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | ".$start_method_log_info:$start_method_log_info;
/*------ Get Settings Class data --------*/
$dbConnection = \Pimcore\Db::get();
$settingsClassId = $dbConnection->fetchOne(" SELECT id FROM classes WHERE LOWER(name) = 'Settings' ");
$settingsObject = "object_".$settingsClassId;
$log_data = $api_log_method_info." | settingsObject:".json_encode($settingsObject);
SELF::createApiLog($log_data);
$settingsId = $dbConnection->fetchOne(" select * from ".$settingsObject." WHERE setting_flag = 1");
$log_data = $api_log_method_info." | settingsId:".json_encode($settingsId);
SELF::createApiLog($log_data);
/*----- End of Get Settings Class data ---------*/
/*--------------- Settings info ----------------*/
$settingsInfo = DataObject\Settings::getById($settingsId);
$log_data = $api_log_method_info." | settingsInfo:".json_encode($settingsInfo);
SELF::createApiLog($log_data);
$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,
];
$api_log_method_info = (!empty($api_log_info))?$api_log_info." | Ended - ".$start_method_log_info:"Ended - ".$start_method_log_info;
$log_data = $api_log_method_info." | settingsdata:".json_encode($settingsdata);
SELF::createApiLog($log_data);
return $settingsdata;
}
function getDatesFromRange($start, $end, $dateformat="Y-m-d"){
$dates = array($start);
while(end($dates) < $end){
$dates[] = date($dateformat, strtotime(end($dates).' +1 day'));
}
return $dates;
}
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;
}
public function createApiLog($content)
{
$file = '../var/log/slot-api-log_'.date("Y-m-d").'.txt';
// chmod($file, 0755);
// if(!is_file($file)){
// $contents = 'This is a test!'; // Some simple example content.
// file_put_contents($file, $content); // Save our content to the file.
file_put_contents($file, date("Y-m-d H:i:s")." | ".$content."\n", FILE_APPEND);
chmod($file, 0755);
// }
}
/*----------------------- End of Sub methods -----------------------*/
}