<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/
//$Id: ShippingmethodModel.php, v 1.0 2012/12/18 14:00:00
class ShippingmethodModel extends Model {
    public function listShippingMethods($limitFrom = 0, $limitTo = "", $status = '') {
        $sqlShippingMethods = "SELECT ";
        if ($limitTo) {
            $sqlShippingMethods .= " SQL_CALC_FOUND_ROWS ";
        }
        $sqlShippingMethods .= " settingsGroupID,settingsGroupXmlLabel,settingsGroupStatus FROM " . DB_PREFIX . "shipping_methods 
									WHERE settingsGroupParent=0 ";
        if ($status != '') {
            $sqlShippingMethods .= " AND settingsGroupStatus='" . $status . "' ";
        }
        $sqlShippingMethods .= " ORDER BY settingsGroupPriority ";
        if ($limitTo) {
            $sqlShippingMethods .= " LIMIT " . $limitFrom . "," . $limitTo . "";
        }
        $resShippingMethods = $this->ObjDatabase->readValues($sqlShippingMethods);
        return $resShippingMethods;
    }
    //FETCH ALL SETTINGS BY GROUP ID
    public function listSmSettingsByGroupId($smGroupID, $order = NULL, $settingsKey = '') {
        if ($order)
            $append = $order;
        else
            $append = "ASC";
        $sqlSelectSmSettings = "SELECT * FROM `" . DB_PREFIX . "shipping_methods_settings` 
											WHERE `settingsGroupID`='" . $smGroupID . "' AND settingFieldVisibility IN ('Global','All') ";
        if ($settingsKey != '') {
            $sqlSelectSmSettings .= " AND settingKey='" . $settingsKey . "' ";
        }
        $sqlSelectSmSettings .= " ORDER BY `settingPriority` " . $append;
        $resSelectSmSettings = $this->ObjDatabase->readValues($sqlSelectSmSettings);
        return $resSelectSmSettings;
    }
    //Edit shipping method settings details
    public function saveSmSettingsDetails($POST, $smGroupID = '') {
        $resSmSettings = $this->listSmSettingsByGroupId($smGroupID);
        for ($i = 0; $i < count($resSmSettings); $i++) {
            $resSmSettings[$i]['settingKey'] = isset($resSmSettings[$i]['settingKey']) ? $resSmSettings[$i]['settingKey'] : '';
            $POST['delivery_zones']          = (isset($POST['delivery_zones'])) ? $POST['delivery_zones'] : '';
            $sqlUpdateSmSettings             = "UPDATE " . DB_PREFIX . "shipping_methods_settings SET settingValue='" . $this->decodeSplChar($this->escape($POST[$resSmSettings[$i]['settingKey']], TRUE, FALSE)) . "' 
									WHERE settingKey LIKE '" . $resSmSettings[$i]['settingKey'] . "' AND settingsGroupID=" . $smGroupID;
            $resUpdateSmSettings             = $this->ObjDatabase->setQuery($sqlUpdateSmSettings);
            if ($resSmSettings[$i]['settingKey'] == 'sm_status' && $smGroupID != '') {
                $this->changeShippingMethodStatus('', $POST[$resSmSettings[$i]['settingKey']], $smGroupID);
            }
            if ($resSmSettings[$i]['settingKey'] == 'shipping_method_name' && $smGroupID != '') {
                $this->changeSmGroupLabel($POST, $smGroupID);
            }
        }
        return true;
    }
    //CHANGE SHIPPING METHOD STATUS
    public function changeShippingMethodStatus($POST, $status = '', $checkSmgIDs = '') {
        if ($status == '') {
            $status      = $POST['changeStatus'];
            $checkSmgIDs = $POST['checkSmgIDs'];
        }
        if ($status != '') {
            $sqlUpdateSmgStatus = "UPDATE `" . DB_PREFIX . "shipping_methods` SET settingsGroupStatus='" . $status . "' ";
            if (isset($POST['checkSmgIDs']) && $POST['checkSmgIDs'] != '') {
                $sqlUpdateSmgStatus .= " WHERE settingsGroupID IN (" . implode(",", $checkSmgIDs) . ") ";
            } else {
                $sqlUpdateSmgStatus .= " ,settingsGroupLastUpdated='" . date("Y-m-d H:i:s") . "' WHERE settingsGroupID IN (" . $checkSmgIDs . ") ";
            }
            $resUpdateSmgStatus = $this->ObjDatabase->setQuery($sqlUpdateSmgStatus);
            if (isset($POST['checkSmgIDs']) && $POST['checkSmgIDs'] != '') {
                $sqlUpdateSmSettings = "UPDATE " . DB_PREFIX . "shipping_methods_settings SET settingValue='" . $status . "' 
												WHERE settingKey='sm_status' AND settingsGroupID IN (" . implode(",", $checkSmgIDs) . ")";
                $resUpdateSmSettings = $this->ObjDatabase->setQuery($sqlUpdateSmSettings);
            }
            return true;
        } else {
            return false;
        }
    }
    public function changeShippingMethodDefault($smGroupID, $isDefault) {
        $sqlUpdateSmgStatus  = "UPDATE `" . DB_PREFIX . "shipping_methods` SET isDefault='" . $isDefault . "',settingsGroupLastUpdated='" . date("Y-m-d H:i:s") . "' WHERE settingsGroupID='" . $smGroupID . "'";
        $resUpdateSmSettings = $this->ObjDatabase->setQuery($sqlUpdateSmgStatus);
        return true;
    }
    //CHANGE SHIPPING METHODS PRIORITY	
    public function updateShippingMethodPriority($smGroupID, $priority = '') {
        $priority          = $priority + 1;
        $sqlUpdatePriority = "UPDATE `" . DB_PREFIX . "shipping_methods` SET settingsGroupPriority=" . $priority . " 
								WHERE settingsGroupID=" . $smGroupID; // settingsGroupParent=0 AND
        $resUpdatePriority = $this->ObjDatabase->setQuery($sqlUpdatePriority);
        return true;
    }
    //GET SHIPPING METHOD GROUP DETAILS		
    public function getShippingMethodGroupDetails($smGroupID = '', $smGroupKey = '') {
        $sqlSelectSmgDetails = "SELECT * FROM `" . DB_PREFIX . "shipping_methods` WHERE ";
        if ($smGroupID != '') {
            $sqlSelectSmgDetails .= "`settingsGroupID`=" . $smGroupID;
        } else {
            $sqlSelectSmgDetails .= "`settingsGroupKey`='" . $smGroupKey . "'";
        }
        $resSelectSmgDetails = $this->ObjDatabase->readValue($sqlSelectSmgDetails);
        return $resSelectSmgDetails;
    }
    //GET SHIPPING METHOD GROUP DETAILS		
    public function getShippingMethodDefault($smGroupID) {
        $sqlSelectSmgDetails = "SELECT isDefault FROM `" . DB_PREFIX . "shipping_methods` WHERE			
		
			`settingsGroupID`=" . $smGroupID;
        $resSelectSmgDetails = $this->ObjDatabase->readValue($sqlSelectSmgDetails);
        return $resSelectSmgDetails['isDefault'];
    }
    //CHANGE SHIPPING METHOD NAME
    public function changeSmGroupLabel($POST, $smGroupID) {
        $sqlUpdateSmgLabel = "UPDATE " . DB_PREFIX . "shipping_methods SET settingsGroupXmlLabel='" . $this->escape($POST['shipping_method_name']) . "',settingsGroupLastUpdated='" . date("Y-m-d H:i:s") . "'
								WHERE settingsGroupID=" . $smGroupID;
        $resUpdateSmgLabel = $this->ObjDatabase->setQuery($sqlUpdateSmgLabel);
        return true;
    }
    //CHANGE SHIPPING METHOD NAME
    public function changeSmGroupDefault($isDefault, $smGroupID) {
        $sqlUpdateSmgLabel = "UPDATE " . DB_PREFIX . "shipping_methods SET isDefault='" . $this->escape($isDefault) . "'
								WHERE settingsGroupID=" . $smGroupID;
        $resUpdateSmgLabel = $this->ObjDatabase->setQuery($sqlUpdateSmgLabel);
        return true;
    }
    public function listShippingMethodServices($smServiceID = '') {
        $sqlMainMethods = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent=0 AND optionsAvailable='Yes' AND settingsGroupStatus='Active' 
								ORDER BY settingsGroupPriority ";
        $resMainMethods = $this->ObjDatabase->readValues($sqlMainMethods);
        return $resMainMethods;
        /*
        $listServices 		= '';
        
        foreach($resMainMethods as $mainMethod) {
        $listServices	.= '<optgroup label="'.$mainMethod['settingsGroupXmlLabel'].'">';
        
        $sqlSmServices	= "SELECT settingsGroupID, settingsGroupXmlLabel
        FROM ".DB_PREFIX."shipping_methods 
        WHERE settingsGroupParent='".$mainMethod['settingsGroupID']."' 
        AND isRealTimeCalculation='Yes' AND settingsGroupStatus='Active' 
        ORDER BY settingsGroupPriority ";
        $resSmServices	= $this->ObjDatabase->readValues($sqlSmServices);
        
        foreach($resSmServices as $smService) {
        
        $optSelStatus= ($smServiceID == $smService['settingsGroupID']) ? 'selected="selected"' : '';
        $listServices.= '<option '.$optSelStatus.' value="'.$smService['settingsGroupID'].'">'.$smService['settingsGroupXmlLabel'].'</option>';
        }
        $listServices	.= "</optgroup>";
        }
        
        return $listServices;
        */
    }
    public function listSmServices($smGroupID, $smServiceID, $smGroupKey = "", $smServiceTypeID = '') {
        $sqlSmServices = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent='" . $smGroupID . "' AND settingsGroupStatus='Active' AND isServiceType='Yes'";
        $sqlSmServices .= " ORDER BY settingsGroupPriority ";
        $resSmServices = $this->ObjDatabase->readValues($sqlSmServices);
        $listServices  = '';
        foreach ($resSmServices as $smService) {
            $optSelStatus = ($smServiceTypeID == $smService['settingsGroupID']) ? 'selected="selected"' : '';
            $listServices .= '<option ' . $optSelStatus . ' value="' . $smService['settingsGroupID'] . '">' . $smService['settingsGroupXmlLabel'] . '</option>';
        }
        if ($smGroupKey) {
            $type         = ($smGroupKey == 'free_shipping') ? 'free_custom' : 'flat_custom';
            $listServices = '<option selected="selected" value=' . $type . '>Custom</option>';
        }
        return $listServices;
    }
    public function updateSmServiceAvailability($smGroupID = '') {
        $sqlUpdateAvailability = "UPDATE `" . DB_PREFIX . "shipping_methods` SET isAvailable='Yes', settingsGroupLastUpdated='" . date("Y-m-d H:i:s") . "'
									WHERE settingsGroupID='" . $smGroupID . "'";
        $resUpdateAvailability = $this->ObjDatabase->setQuery($sqlUpdateAvailability);
        return true;
    }
    public function listAvailableSmServices($limitFrom = '', $limitTo = '') {
        $sqlSelServices = "SELECT ";
        if ($limitTo) {
            $sqlSelServices .= "	SQL_CALC_FOUND_ROWS	";
        }
        $sqlSelServices .= " settingsGroupID,settingsServiceTypeID,settingsGroupXmlLabel,isDefault,settingsGroupParent,(SELECT settingsGroupXmlLabel 
								FROM " . DB_PREFIX . "shipping_methods WHERE settingsGroupID=sm.settingsGroupParent) AS shippingMethodMain, 
								(SELECT GROUP_CONCAT(settingValue SEPARATOR ' - ') FROM " . DB_PREFIX . "shipping_methods_settings 
									WHERE settingsGroupID=sm.settingsGroupID AND settingKey IN ('cp_min_weight','cp_max_weight')
									GROUP BY settingsGroupID) AS serviceWeightLimit,
								isRealTimeCalculation, settingsGroupStatus
								FROM " . DB_PREFIX . "shipping_methods sm
								WHERE sm.settingsGroupParent>0 AND sm.isAvailable='Yes' AND sm.isServiceType='No' AND sm.settingsGroupStatus<>'Delete' 
								ORDER BY sm.settingsGroupPriority ASC,sm.settingsGroupLastUpdated ASC ";
        if ($limitTo) {
            $sqlSelServices .= "LIMIT	" . $limitFrom . "," . $limitTo . "";
        }
        $resSelServices = $this->ObjDatabase->readValues($sqlSelServices);
        return $resSelServices;
    }
    public function unassignSmService($smServiceID) {
        $sqlUpdateSmService  = "UPDATE `" . DB_PREFIX . "shipping_methods` SET `isAvailable` = 'No',
		`settingsGroupStatus` = 'Inactive' WHERE `settingsGroupID`='" . $smServiceID . "'";
        $resUpdateSmService  = $this->ObjDatabase->setQuery($sqlUpdateSmService);
        $sqlUpdateSmsSetting = "UPDATE `" . DB_PREFIX . "shipping_methods_settings` SET settingValue='' 
									WHERE settingsGroupID='" . $smServiceID . "'";
        $resUpdateSmsSetting = $this->ObjDatabase->setQuery($sqlUpdateSmsSetting);
        return true;
    }
    public function assignSmServiceZone($smServiceID, $zone) {
        $sqlUpdateSmsSetting = "UPDATE `" . DB_PREFIX . "shipping_methods_settings` SET settingValue='" . $zone . "' 
									WHERE settingsGroupID='" . $smServiceID . "' AND settingKey='delivery_zones'";
        $resUpdateSmsSetting = $this->ObjDatabase->setQuery($sqlUpdateSmsSetting);
    }
    public function groupSmServices() {
        $serviceArray   = array();
        $sqlMainMethods = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent=0 AND optionsAvailable='Yes' AND settingsGroupStatus='Active' 
								ORDER BY settingsGroupPriority ";
        $resMainMethods = $this->ObjDatabase->readValues($sqlMainMethods);
        foreach ($resMainMethods as $mainMethod) {
            $sqlSmServices = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent='" . $mainMethod['settingsGroupID'] . "' 
									 AND settingsGroupStatus='Active' 
								AND isAvailable='Yes' ORDER BY settingsGroupPriority ";
            $resSmServices = $this->ObjDatabase->readValues($sqlSmServices);
            $i             = 0;
            foreach ($resSmServices as $smService) {
                $serviceArray[$mainMethod['settingsGroupXmlLabel']][$i][0] = $smService['settingsGroupID'];
                $serviceArray[$mainMethod['settingsGroupXmlLabel']][$i][1] = $smService['settingsGroupXmlLabel'];
                $i++;
            }
        }
        return $serviceArray;
    }
    public function cloneCustomShippingService() {
        $sql                 = "SELECT
						COUNT(settingsGroupID) AS optionsCount
					FROM
						" . DB_PREFIX . "shipping_methods
					WHERE
						settingsGroupParent='" . $_POST['sm_main'] . "'
					LIMIT 0,1";
        $result              = $this->ObjDatabase->readValue($sql);
        $settingsGroupKeyNew = $_POST['settingsGroupKey'] . '' . $result['optionsCount']++;
        $isDefault           = isset($_POST['isDefault']) ? $_POST['isDefault'] : '';
        if ($_POST['action'] == 1)
            $apndID = $_POST['realtime_sm_services'];
        else
            $apndID = '';
        $sql                = " INSERT INTO " . DB_PREFIX . "shipping_methods
					(
						settingsGroupParent,
						settingsServiceTypeID,
						settingsGroupKey,
						settingsGroupXmlLabel,
						isRealTimeCalculation,
						optionsAvailable,
						isAvailable,
						settingsGroupStatus,
						settingsGroupPriority,
						settingsGroupLastUpdated,
						isDefault
					) 
					VALUES 
					(
						'" . $_POST['sm_main'] . "',
						'" . $_POST['realtime_sm_services'] . "',
						'" . $settingsGroupKeyNew . "',
						'" . $this->escape($_POST['shipping_method_name' . $apndID]) . "',
						'" . $this->escape($_POST['isRealTimeCalculation']) . "',
						'No',
						'Yes',
						'Active',
						'999',
						NOW(),'" . $isDefault . "'
					)";
        $resp               = $this->ObjDatabase->setQuery($sql);
        $settingsGroupIDNew = $this->ObjDatabase->getInsertId();
        $resSmSettings      = $this->listSmSettingsByGroupId($_POST['realtime_sm_services']);
        for ($i = 0; $i < count($resSmSettings); $i++) {
            if ($resSmSettings[$i]['settingKey'] == 'shipping_method_name')
                $settingValue = $_POST[$resSmSettings[$i]['settingKey'] . $apndID];
            else
                $settingValue = isset($_POST[$resSmSettings[$i]['settingKey']]) ? $_POST[$resSmSettings[$i]['settingKey']] : '';
            $sql  = " INSERT INTO " . DB_PREFIX . "shipping_methods_settings
						(
							settingsGroupID,
							settingsGroupKey,
							settingKey,
							settingXmlLabel,
							settingOptions,
							settingValue,
							settingInputType,
							settingValidate,
							settingValidateError,
							settingDescription,
							settingPriority,
							settingFieldVisibility
						) 
						VALUES
						(
							'" . $settingsGroupIDNew . "',
							'" . $settingsGroupKeyNew . "',
							'" . $resSmSettings[$i]['settingKey'] . "',
							'" . $this->escape($resSmSettings[$i]['settingXmlLabel']) . "',
							'" . $resSmSettings[$i]['settingOptions'] . "',
							'" . $this->escape($settingValue) . "',
							'" . $resSmSettings[$i]['settingInputType'] . "',
							'" . $resSmSettings[$i]['settingValidate'] . "',
							'" . $resSmSettings[$i]['settingValidateError'] . "',
							'" . $resSmSettings[$i]['settingDescription'] . "',
							'999',
							'" . $resSmSettings[$i]['settingFieldVisibility'] . "'
						)";
            $resp = $this->ObjDatabase->setQuery($sql);
        }
        return $settingsGroupIDNew;
    }
    public function getSmsZoneByID($smGroupID) {
        $sql = "SELECT settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
						WHERE `settingsGroupID`='" . $smGroupID . "' 
							AND settingKey='delivery_zones'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getGroupKeyByID($smGroupID) {
        $sql = "SELECT settingsGroupKey FROM `" . DB_PREFIX . "shipping_methods` 
						WHERE `settingsGroupID`='" . $smGroupID . "'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getGroupIDByKey($smGroupKey) {
        $sql = "SELECT settingsGroupID FROM `" . DB_PREFIX . "shipping_methods` 
						WHERE `settingsGroupKey`='" . $smGroupKey . "'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getTaxcalassByID($smGroupID) {
        $sql = "SELECT settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
						WHERE `settingsGroupID`='" . $smGroupID . "' 
							AND settingKey='flat_tax_class'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getSmsBaseChargeByID($smGroupID) {
        $sql = "SELECT settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
						WHERE `settingsGroupID`='" . $smGroupID . "' 
							AND settingKey='flat_fixed_charge'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getSmsValueByID($smGroupID, $key) {
        $sql = "SELECT settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
						WHERE `settingsGroupID`='" . $smGroupID . "' 
							AND settingKey='" . $key . "'";
        return $result = $this->ObjDatabase->getField($sql);
    }
    public function getProductShippingServices() {
        $sql    = "SELECT shippingServiceID
			FROM `" . DB_PREFIX . "shipping_to_product` WHERE status!='D'";
        $result = $this->ObjDatabase->readValues($sql);
        foreach ($result as $val) {
            $services[] = $val['shippingServiceID'];
        }
        return $services;
    }
    public function listLogisticPartners() {
        $sqlMainMethods = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent=0 AND optionsAvailable='Yes' AND settingsGroupStatus='Active' 
								AND isCarrier='Yes' ORDER BY settingsGroupPriority ";
        $partnerArray   = $this->ObjDatabase->readValues($sqlMainMethods);
        $OtherArray[]   = array(
            0 => 'other',
            'settingsGroupID' => 'other',
            1 => 'Other',
            'settingsGroupXmlLabel' => 'Other'
        );
        $resultArray    = array_merge($partnerArray, $OtherArray);
        return $resultArray;
    }
    public function getShippingServiceAndKey($shippingtoproductID = 0) {
        $sqlMainMethods = "SELECT shipToPro.shippingServiceID,
										shipMeth.settingsGroupKey,
										shipMeth.settingsServiceTypeID,
										( SELECT
											mth.settingsGroupKey
											FROM 
											dp_shipping_methods mth 
											WHERE mth.settingsGroupID = shipMeth.settingsServiceTypeID
										)
										shippingTypeKey
								FROM " . DB_PREFIX . "shipping_to_product shipToPro
								LEFT JOIN " . DB_PREFIX . "shipping_methods shipMeth 
								ON shipToPro.shippingServiceID=shipMeth.settingsGroupID
								WHERE shipToPro.shippingtoproductID=" . $shippingtoproductID . "  ";
        return $this->ObjDatabase->readValue($sqlMainMethods);
    }
    public function listShippingSettings($smGroupID, $settingsGroupKey = '') {
        $sqlSelectSmSettings = "SELECT settingKey,settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
											WHERE `settingsGroupID`='" . $smGroupID . "' ";
        if ($settingsGroupKey != '') {
            $sqlSelectSmSettings .= " AND settingsGroupKey='" . $settingsGroupKey . "' ";
        }
        return $this->ObjDatabase->readValues($sqlSelectSmSettings);
    }
    public function checkIsRealtimeCarrier($shippingMethodID) {
        $sql = "SELECT isRealTimeCalculation FROM `" . DB_PREFIX . "shipping_methods`
					WHERE settingsGroupID = '" . $shippingMethodID . "' LIMIT 1";
        return $this->ObjDatabase->getField($sql);
    }
    public function getTrackingIDWithShippingMethod($shippingID) {
        $sql = "SELECT ship.trackingNumber,
						ship.carrier,
						shipMeth.isRealTimeCalculation
				FROM `" . DB_PREFIX . "shipments` ship
				LEFT JOIN " . DB_PREFIX . "shipping_methods shipMeth
				ON ship.carrier = shipMeth.settingsGroupID
					WHERE shippingID = '" . $shippingID . "' LIMIT 1";
        return $this->ObjDatabase->readValue($sql);
    }
    public function getShippingSettingsByKey($settingsGroupKey, $settingsKey) {
        $sqlSelectSmSettings = "SELECT settingValue FROM `" . DB_PREFIX . "shipping_methods_settings` 
											WHERE `settingKey`='" . $settingsKey . "' ";
        if ($settingsGroupKey != '') {
            $sqlSelectSmSettings .= " AND settingsGroupKey='" . $settingsGroupKey . "' ";
        }
        return $this->ObjDatabase->getField($sqlSelectSmSettings);
    }
    public function checkNeedPickup($shippingID) {
        $sql = "SELECT ship.drop_off_type,ship.carrier,ship.gross_weight 
				FROM `" . DB_PREFIX . "shipments` ship
				LEFT JOIN " . DB_PREFIX . "shipping_methods shipMeth
				ON ship.carrier = shipMeth.settingsGroupID
					WHERE ship.shippingID = '" . $shippingID . "' AND shipMeth.isRealTimeCalculation = 'Yes' LIMIT 1";
        return $this->ObjDatabase->readValue($sql);
    }
    public function getAllProducts() {
        $sqlSelect = "SELECT productID FROM " . DB_PREFIX . "products where productStatus!='Deleted' ORDER BY productID ASC";           
        return $this->ObjDatabase->readValues($sqlSelect);
    }
    public function listLogisticPartnersnew() {
        $sqlMainMethods = "SELECT settingsGroupID, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent=0 AND optionsAvailable='Yes' AND settingsGroupStatus='Active' 
								AND isCarrier='Yes' ORDER BY settingsGroupPriority ";
        $partnerArray   = $this->ObjDatabase->readValues($sqlMainMethods);
        $OtherArray[]   = array(
            0 => 'other',
            'settingsGroupID' => 'other',
            1 => 'Other',
            'settingsGroupXmlLabel' => 'Other'
        );
        $resultArray    = array_merge($partnerArray, $OtherArray);
        return $resultArray;
    }
    public function listLogisticPartnersWithKey() {
        $sqlMainMethods = "SELECT settingsGroupKey, settingsGroupXmlLabel
								FROM " . DB_PREFIX . "shipping_methods 
								WHERE settingsGroupParent=0 AND optionsAvailable='Yes' AND settingsGroupStatus='Active' 
								AND isCarrier='Yes' ORDER BY settingsGroupPriority ";
        $partnerArray   = $this->ObjDatabase->readValues($sqlMainMethods);
        $OtherArray[]   = array(
            0 => 'other',
            'settingsGroupID' => 'other',
            1 => 'Other',
            'settingsGroupXmlLabel' => 'Other'
        );
        $resultArray    = array_merge($partnerArray, $OtherArray);
        return $resultArray;
    }
}