storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->orderCollectionFactory = $orderCollectionFactory; $this->_date = $date; $this->timezone = $timezone; $this->customerFactory = $customerFactory; $this->_logger = $logger; } /** * Get Logger * * @return \JR\NetSuite\Logger\Logger */ public function getLogger() { return $this->_logger; } /** * Get NetSuite API URL * * @return string */ public function getApiUrl() { return $this->getConfigValue(self::XML_PATH_NETSUITE_API_URL); } /** * Get NetSuite Enable * * @return string */ public function getNetSuiteIsEnabled() { return $this->getConfigValue(self::XML_PATH_NETSUITE_ENABLE); } /** * Get Multi Location Enable * * @return string */ public function getMultiLocationEnabled() { return $this->getConfigValue(self::XML_PATH_MULTI_LOCATION_ENABLE); } /** * Get Root Category * * @return string */ public function getDefaultCategory() { return $this->getConfigValue(self::XML_PATH_DEFAULT_CATEGORY); } /** * Get NetSuite visibility id * * @return string */ public function getDefaultVisibilityId() { return $this->getConfigValue(self::XML_PATH_DEFAULT_VISIBILITY_ID); } /** * Get NetSuite assign tax class * * @return string */ public function getDefaultTaxClass() { return $this->getConfigValue(self::XML_PATH_DEFAULT_TAX_CLASS); } /** * Get XML_PATH_NETSUITE_MAX_ATTEMPT * * @return string */ public function getNetSuiteMaxAttempt() { return $this->getConfigValue(self::XML_PATH_NETSUITE_MAX_ATTEMPT); } /** * Get XML_PATH_CRON_BATCH_SIZE * * @return string */ public function getCronBatchSize() { return $this->getConfigValue(self::XML_PATH_CRON_BATCH_SIZE); } /** * Get default_customer_group * * @return string */ public function getDefaultCustomerGroup() { return $this->getConfigValue(self::XML_PATH_DEFAULT_CUSTOMER_GROUP); } /** * Get default_store_id * * @return string */ public function getDefaultStoreId() { return $this->getConfigValue(self::XML_PATH_DEFAULT_STORE_ID); } /** * Get calculate date for order fatch * * @return \DateTime time */ public function getNetSuiteCountFromDate() { $dayes = $this->getConfigValue(self::XML_PATH_NETSUITE_COUNT_FROM); $currenctDate = $this->_date->date('Y-m-d H:i:s'); return $this->_date->date('Y-m-d H:i:s', (strtotime('-' . $dayes . ' day', strtotime($currenctDate)))); } /** * Get calculate date for order fatch * * @return \DateTime time */ public function getCurrentDate() { return $this->_date->date('Y-m-d H:i:s'); } public function convertUtcToLocalTime($utcDate, $format = 'Y-m-d H:i:s', $modify = null) { $date = new \DateTime($utcDate, new \DateTimeZone('UTC')); if (!empty($modify)) $date = $date->modify($modify); $date->setTimezone(new \DateTimeZone($this->timezone->getConfigTimezone())); return $date->format($format); } public function convertLocalTimeToUtc($localTimeString, $format = "Y-m-d H:i:s") { try { // Assum ing $localTimeString is in a specific format, e.g., "Y-m-d H:i:s" $date = new \DateTime($localTimeString, new \DateTimeZone($this->timezone->getConfigTimezone())); if (!$date) { throw new \Exception("Invalid date format"); } // Convert to UTC $date->setTimezone(new \DateTimeZone('UTC')); return $date->format($format); // Format as needed for the database } catch (\Exception $e) { // Handle the exception as needed return null; } } /** * Get NetSuite Config value * * @return string */ public function getConfigValue($path) { $store = $this->getStoreId(); $config_data = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $store); return $config_data; } /** * Get store id * @return int */ public function getStoreId() { return $this->storeManager->getStore()->getStoreId(); } public function convertStringToCode($string) { return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($string)), '-'); } public function formatBytes($bytes) { if ($bytes >= 1073741824) { $bytes = number_format($bytes / 1073741824, 2) . ' GB'; } elseif ($bytes >= 1048576) { $bytes = number_format($bytes / 1048576, 2) . ' MB'; } elseif ($bytes >= 1024) { $bytes = number_format($bytes / 1024, 2) . ' KB'; } elseif ($bytes > 1) { $bytes = $bytes . ' bytes'; } elseif ($bytes == 1) { $bytes = $bytes . ' byte'; } else { $bytes = '0 bytes'; } return $bytes; } public function nDigitRandom($digits) { return rand(pow(10, $digits - 1) - 1, pow(10, $digits) - 1); } public function secondsToTime($s) { $h = floor($s / 3600); $s -= $h * 3600; $m = floor($s / 60); $s -= $m * 60; return $h . ':' . sprintf('%02d', $m) . ':' . sprintf('%02d', $s); } //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case) public function convertPHPSizeToBytes($sSize) { if (is_numeric($sSize)) { return $sSize; } $sSuffix = substr($sSize, -1); $iValue = substr($sSize, 0, -1); switch (strtoupper($sSuffix)) { case 'P': $iValue *= 1024; break; case 'T': $iValue *= 1024; break; case 'G': $iValue *= 1024; break; case 'M': $iValue *= 1024; break; case 'K': $iValue *= 1024; break; } return $iValue; } }