<?php
/**
 * @filename        MSHShippingCalculator.php
 * @description     This class is the interface of this library and calculates shipping with help of different shipping carrier classes
 * @version         1.0
 * @package         MSHShippingLibrary
 * @author          Mohammad Sajjad Hossain - info@sajjadhossain.com
 *
 * @link            http://sajjadhossain.com
 * @created on      December 07, 2010
 * @dependacies
 * @license
 ***/

define('MSHSL_BASE', dirname(__FILE__) . '/');
define('MSHSL_CLASS_PATH', MSHSL_BASE . 'shippingClasses/');
define('MSHSL_LOG_FILE_PATH', MSHSL_BASE . 'log/shipping/');
define('SC_FEDEX', 1);
define('SC_UPS', 2);
define('SC_USPS', 3);
define('SC_CANADA_POST', 4);
define('SC_AUSTRALIA_POST', 5);
define('SC_ENDICIA_POST', 6);

/**
*@desc Configuration for DB, if you want to use caching
*/
//LOCAL
define('MSHSL_DB_HOST', 'localhost');
define('MSHSL_DB_NAME', 'db_pwc');
define('MSHSL_DB_USER', 'root');
define('MSHSL_DB_PASS', '');

//LIVE
//define('MSHSL_DB_HOST', '192.168.100.230');
//define('MSHSL_DB_NAME', 'db_pwc');
//define('MSHSL_DB_USER', 'secureinfousr');
//define('MSHSL_DB_PASS', '!PWCBangladesh2015');

//DEMO
//define('MSHSL_DB_HOST', '192.168.100.228');
//define('MSHSL_DB_NAME', 'db_pwc_demo');
//define('MSHSL_DB_USER', 'pwc_demo_user');
//define('MSHSL_DB_PASS', 'Pwcuser321');

include_once(MSHSL_CLASS_PATH . 'Carrier.php');
include_once(MSHSL_BASE . 'classes/ISOCountry.php');
include_once(MSHSL_CLASS_PATH . 'ShippingResponse.php');
include_once(MSHSL_CLASS_PATH . 'ShippingItem.php');

class MSHShippingCalculator
{
    private $carrier = null;

    public function MSHShippingCalculator($carrierConst = 4)
    {
        switch($carrierConst)
        {
            case SC_FEDEX:
                include_once(MSHSL_CLASS_PATH . 'FedEx.php');
                $this->carrier = new FedEx();
                break;
            case SC_CANADA_POST:
                include_once(MSHSL_CLASS_PATH . 'CanadaPost.php');
                $this->carrier = new CanadaPost();
                break;
            case SC_USPS:
                include_once(MSHSL_CLASS_PATH . 'USPS.php');
                $this->carrier = new USPS();
                break;
            case SC_UPS:
                include_once(MSHSL_CLASS_PATH . 'UPS.php');
                $this->carrier = new UPS();
                break;
            case SC_AUSTRALIA_POST:
                include_once(MSHSL_CLASS_PATH . 'AustraliaPost.php');
                $this->carrier = new AustraliaPost();
                break;
            case SC_ENDICIA_POST://6
                include_once(MSHSL_CLASS_PATH . 'Endicia.php');
                $this->carrier = new Endicia();
                break;
        }
    }

    /**
    *@desc Sets account number or user ID for the shipping carrier account
    */
    public function setUserId($id)
    {
        $this->carrier->setUserId($id);
    }

    /**
    *@desc Sets additional account information
    */
    public function setCredentialOne($cred)
    {
        $this->carrier->setCredentialOne($cred);
    }

    /**
    *@desc Sets additional account information
    */
    public function setCredentialTwo($cred)
    {
        $this->carrier->setCredentialTwo($cred);
    }

    /**
    *@desc Sets additional account information
    */
    public function setCredentialThree($cred)
    {
        $this->carrier->setCredentialThree($cred);
    }

    /**
    *@desc Calculates shipping rate
    */
    public function calculate()
    {
        return $this->carrier->calculate();
    }

    public function setFromCity($city)
    {
        $this->carrier->setFromCity($city);
    }

    public function setFromState($state)
    {
        $this->carrier->setFromState($state);
    }

    public function setFromZip($zip)
    {
        $this->carrier->setFromZip($zip);
    }

    public function setFromCountryCode($code)
    {
        $this->carrier->setFromCountryCode($code);
        $isoCon = new ISOCountry();
        $this->carrier->setFromCountry($isoCon->getCountryFullName($code));
    }

    public function setFromCountry($country)
    {
        $this->carrier->setFromCountry($country);
        $isoCon = new ISOCountry();
        $this->carrier->setFromCountryCode($isoCon->getCountryCode($country));
    }

    public function setToCity($city)
    {
        $this->carrier->setToCity($city);
    }

    public function setToState($state)
    {
        $this->carrier->setToState($state);
    }

    public function setToZip($zip)
    {
        $this->carrier->setToZip($zip);
    }

    public function setToCountryCode($code)
    {
        $this->carrier->setToCountryCode($code);
        $isoCon = new ISOCountry();
        $this->carrier->setToCountry($isoCon->getCountryFullName($code));
    }

    public function setToCountry($country)
    {
        $this->carrier->setToCountry($country);
        $isoCon = new ISOCountry();
        $this->carrier->setToCountryCode($isoCon->getCountryCode($country));
    }

    public function setItem($item)
    {
        $this->carrier->setItem($item);
    }

    public function enableDebugging()
    {
        $this->carrier->enableDebugging();
    }

    public function showCurlError()
    {
        $this->carrier->showCurlError();
    }

    public function setWeightUnit($unit)
    {
        $this->carrier->setWeightUnit($unit);
    }

    public function setLengthUnit($unit)
    {
        $this->carrier->setLengthUnit($unit);
    }

    public function setCurrencyCode($code)
    {
        $this->carrier->setCurrencyCode($code);
    }

    public function deleteInvalidData()
    {
        $this->carrier->deleteInvalidData();
    }

    public function setServices($services)
    {
        $this->carrier->setServices($services);
    }
    public function loadRealTimeCarrierObj()
    {
    	if (is_object($this->carrier))
        return $this->carrier;
        else
        return;
    }
    
    //Anjuman | D: 04242012 (mmddyyyy)  --  for residential or commercial shipping address
    public function setShippingDestinationType($shipping_destination_type)
    {
        $this->carrier->setShippingDestinationType($shipping_destination_type);
    }
    //End of Anjuman 
}
//End of file MSHShippingCalculator.php