<?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: ShippingController.php, v 1.0 2012/06/19 20:52:11
//
class ShippingController extends Controller {
    //MANAGE NOT SHIPPED PRODUCT ORDERS
    public function indexAction() {
        $this->setRedirect('shipping/shipped/');
    }
    //END OF FUNCTION
    //MANAGE SHIPPED PRODUCT ORDERS
    public function shippedAction() {
        $ObjOrder           = new OrderModel();
        $ObjCountry         = new CountryModel();
        $ObjShipment        = new ShipmentModel();
        $ObjShippingMethod  = new ShippingmethodModel();
        $languageIDs        = $this->ObjView->languageIDs;
        $businessID         = $this->ObjSession->getSession("BUSINESS_USER_ID");
        $settingsDateFormat = $this->getSettingValue("site_settings", "date_format");
        $timeFormat         = $this->getSettingValue('site_settings', 'time_format');
        $normallink         = '';
        if (!$businessID) {
            $this->setRedirect('/login/');
        }
         //Bulk Status change
        if (isset($_POST['bulkShippingStatus']) && $_POST['bulkShippingStatus'] != '') {
            $postData   = $_POST;
            $successIDs = '';
            if ($postData['bulkShippingStatus'] == 'Dispatched') {
                $postData['dispatchDate']    = $this->convertDateForSQL($postData['dispatchDate'], $settingsDateFormat);
                $postData['dispatchExpDate'] = $this->convertDateForSQL($postData['dispatchExpDate'], $settingsDateFormat);
                $postData['dispatchNotify']  = (isset($postData['dispatchNotify'])) ? $postData['dispatchNotify'] : 'No';
                $successIDs		= $ObjShipment->updateBulkShipmentStatus($postData);
                $this->shipmentNotificationMail($postData);
            } else if ($postData['bulkShippingStatus'] == 'Delivered') {
                $postData['deliveredDate']   = $this->convertDateForSQL($postData['deliveredDate'], $settingsDateFormat);
                $postData['deliveredNotify'] = (isset($postData['deliveredNotify'])) ? $postData['deliveredNotify'] : 'No';
                $successIDs                  = $ObjShipment->updateBulkShipmentStatus($postData);
                $this->shipmentNotificationMail($postData);
            } else if ($postData['bulkShippingStatus'] == 'Pickup') {
                foreach ($postData['checkOrderIDs'] as $shipmentID) {
                    $resNeedPickup = $ObjShippingMethod->checkNeedPickup($shipmentID);
                    if (!empty($resNeedPickup) && $resNeedPickup['drop_off_type'] == 'REQUEST_COURIER') {
                        $ObjCountry     = new CountryModel();
                        $ObjState       = new StateModel();
                        $shipmentOrigin = $ObjShipment->getShipmentOriginAddress($shipmentID);
                        $originAddress  = unserialize($shipmentOrigin);
                        if ($originAddress['businessProvince'] == '')
                            $originAddress['businessStateShortName'] = $ObjState->getStateShortNameByID($originAddress['businessState']);
                        else
                            $originAddress['businessStateShortName'] = $ObjState->getProvinceShortCode($originAddress['businessProvince']);
                        $originAddress['businessCountryShortName'] = $ObjCountry->getCountryCode($originAddress['businessCountry']);
                        $originAddress['grossWeight']              = $resNeedPickup['gross_weight'];
                        $originAddress['pickupDate']               = $postData['pickupDate'];
                        $postData['pickup_created_time']           = 'NOW()';
                        $postData['pickupDate']                    = $this->convertDateForSQL($postData['pickupDate'], $settingsDateFormat);
                        $postData['pickup_closing_time']           = $this->convertDateForSQL($postData['pickupClosingTime'], $timeFormat);
                        //Shipping Library 
                        $paramsArray                               = array(
                            'tableName' => 'shipping_methods',
                            'fieldName' => 'settingsGroupKey',
                            'conditionField' => 'settingsGroupID',
                            'condition' => '=',
                            'conditionValue' => $resNeedPickup['carrier'],
                            'conditionFieldType' => 'int'
                        );
                        $ObjCart                                   = new CartModel();
                        $resShippingGateWayKey                     = $ObjCart->getFieldValue($paramsArray);
                        $shippingGateWayKey                        = $resShippingGateWayKey['settingsGroupKey'];
                        $ObjShippingLib                            = new Shipping($shippingGateWayKey);
                        $ObjShipping                               = $ObjShippingLib->getShippingObject();
                        if (!is_object($ObjShipping)) {
                            continue;
                        } else {
                            $pickupResponseArray    = $ObjShipping->createPickup($originAddress);
                            $postData['pickupData'] = $pickupResponseArray;
                            $postData['shipmentID'] = $shipmentID;
                            if ($pickupResponseArray['successCode'] == 'FAILURE' || $pickupResponseArray['successCode'] == 'ERROR') {
                                //$this->setMessage($pickupResponseArray['message'], "error");
                                //$this->setRedirect();
                            } else {
                                $successShipmentID = $ObjShipment->updateBulkShipmentStatus($postData);
                                $successIDs .= $successShipmentID . ',';
                            }
                        }
                    }
                }
                //exit;
            }
            $this->setMessage($this->getLanguageValue("lblSuccessShipmentBulkStatus") . ' ' . rtrim($successIDs, ','), "success");
            $this->setRedirect();
        }
        
        //search
        if (isset($_POST['submitSearch'])) {
            $shippingSetting = $_POST['shippingSetting'];
            $orderNumber     = trim($this->encodeUrlString($_POST['orderNumber']));
            $orderStatusDate = $_POST['orderStatusDate'];
            if ($orderStatusDate) {
                if (strpos($orderStatusDate, ' - '))
                    list($fromDate, $toDate) = explode(' - ', $orderStatusDate);
                else
                    $fromDate = $orderStatusDate;
            }
            $productKey      = trim($this->encodeUrlString($_POST['productKey']));
            $certificateName = trim($this->encodeUrlString($_POST['certificateName']));
            $shippingStatus  = isset($_POST['shippingStatus']) ? $_POST['shippingStatus'] : '';
            $link            = "/shipping/shipped/";
            $link .= (($orderNumber != "") ? "orderid/" . $orderNumber . "/" : "");
            $link .= ((isset($fromDate) && $fromDate != "") ? "from/" . $this->urlDate($fromDate, 'set', $settingsDateFormat) . "/" : "");
            $link .= ((isset($toDate) && $toDate != "") ? "to/" . $this->urlDate($toDate, 'set', $settingsDateFormat) . "/" : "");
            $link .= (($productKey != "") ? "titleSku/" . $productKey . "/" : "");
            $link .= (($shippingSetting != "") ? "shippingby/" . $shippingSetting . "/" : "");
            $link .= (($certificateName != "") ? "cername/" . $certificateName . "/" : "");
            $link .= (($shippingStatus != "") ? "shippingStatus/" . $shippingStatus . "/" : "");
            $this->setRedirect($link);
        }
        //search parameters
        $shippingSetting = $this->getRequestValue('shippingby');
        $orderNumber     = $this->decodeUrlString($this->getRequestValue('orderid'));
        $fromDate        = $this->urlDate($this->getRequestValue('from'), 'get', $settingsDateFormat);
        $toDate          = $this->urlDate($this->getRequestValue('to'), 'get', $settingsDateFormat);
        $productKey      = $this->decodeUrlString($this->getRequestValue('titleSku'));
        $certificateName = $this->decodeUrlString($this->getRequestValue('cername'));
        $shippingStatus  = $this->getRequestValue('shippingStatus');
        $sortByOption    = $this->getRequestValue("sortby");
        $sortByOrder     = $this->getRequestValue("orderby");
        // sort by
        if ($sortByOption == 'sorderid' && $sortByOrder == "asc") {
            $sortByOrderID = "desc";
        } else {
            $sortByOrderID = "asc";
        }
        if ($sortByOption == 'scustomer' && $sortByOrder == "asc") {
            $sortByOrderCustomer = "desc";
        } else {
            $sortByOrderCustomer = "asc";
        }
        if ($sortByOption == 'squantity' && $sortByOrder == "asc") {
            $sortByOrderQuantity = "desc";
        } else {
            $sortByOrderQuantity = "asc";
        }
        if ($sortByOption == 'stotal' && $sortByOrder == "asc") {
            $sortByOrderTotal = "desc";
        } else {
            $sortByOrderTotal = "asc";
        }
        if ($sortByOption == 'shipdate' && $sortByOrder == "asc") {
            $sortByOrderStatusDate = "desc";
        } else {
            $sortByOrderStatusDate = "asc";
        }
        if ($sortByOption == 'sshipmentid' && $sortByOrder == "asc") {
            $sortByShipmentID = "desc";
        } else {
            $sortByShipmentID = "asc";
        }
        if ($sortByOption == '') {
            $sortByOption = 'sshipmentid';
        }
        if ($fromDate != "")
            $normallink .= "from/" . $this->urlDate($fromDate, 'set', $settingsDateFormat) . "/";
        if ($toDate != "")
            $normallink .= "to/" . $this->urlDate($toDate, 'set', $settingsDateFormat) . "/";
        if ($productKey != "")
            $normallink .= "titleSku/" . $productKey . "/";
        if ($orderNumber != "")
            $normallink .= "orderid/" . $orderNumber . "/";
        if ($certificateName != "")
            $normallink .= "cername/" . $certificateName . "/";
        if ($shippingSetting != "")
            $normallink .= "shippingby/" . $shippingSetting . "/";
        $normallink .= "list";
        if ($fromDate && $toDate == '') {
            $this->ObjView->assign('orderStatusDate', $fromDate. ' - ' . $fromDate);
        } else if ($fromDate && $toDate) {
            $this->ObjView->assign('orderStatusDate', $fromDate . ' - ' . $toDate);
        } else {
            $this->ObjView->assign('orderStatusDate', '');
        }
        $this->ObjView->assign("sortByOrderID", $sortByOrderID);
        $this->ObjView->assign("sortByOrderCustomer", $sortByOrderCustomer);
        $this->ObjView->assign("sortByOrderQuantity", $sortByOrderQuantity);
        $this->ObjView->assign("sortByOrderTotal", $sortByOrderTotal);
        $this->ObjView->assign("sortByOrderStatusDate", $sortByOrderStatusDate);
        $this->ObjView->assign('sortByOrder', $sortByOrder);
        $this->ObjView->assign('sortByOption', $sortByOption);
        $this->ObjView->assign("orderNumber", $orderNumber);
        $this->ObjView->assign("normallink", $normallink);
        $this->ObjView->assign("fromDate", $fromDate);
        $this->ObjView->assign('sortByShipmentID', $sortByShipmentID);
        $this->ObjView->assign("toDate", $toDate);
        $this->ObjView->assign("settingsDateFormat", $settingsDateFormat);
        $this->ObjView->assign("settingsTimeFormat", $timeFormat);
        $this->ObjView->assign("certificateName", $certificateName);
        $this->ObjView->assign("shippingStatus", $shippingStatus);
        $this->ObjView->assign("productKey", $productKey);
        if ($shippingStatus == '') {
            $searchShippingStatus = 'Shipped';
        } else {
            $searchShippingStatus = $shippingStatus;
        }
        // pagination settings
        list($limitFrom, $limitTo) = $this->getPageSettings($key = 'page');
        $params['languageIDs']        = $this->ObjView->languageIDs;
        $params['limitFrom']          = $limitFrom;
        $params['limitTo']            = $limitTo;
        $params['orderNumber']        = $orderNumber;
        $params['fromDate']           = $this->convertDateForSQL($fromDate, $settingsDateFormat);
        $params['toDate']             = $this->convertDateForSQL($toDate, $settingsDateFormat);
        $params['searchBusiness']     = isset($searchBusiness) ? $searchBusiness : '';
        $params['orderStatus']        = 'Any';
        $params['productKey']         = $productKey;
        $params['searchProductTypes'] = isset($searchProductTypes) ? $searchProductTypes : '';
        $params['certificateName']    = $certificateName;
        $params['paymentStatus']      = isset($paymentStatus) ? $paymentStatus : '';
        $params['userID']             = isset($userID) ? $userID : '';
        $params['orderAs']            = $sortByOrder;
        $params['sortBy']             = $sortByOption;
        $params['shipmentStatus']     = $searchShippingStatus;
        $params['productTypeKey']     = isset($productTypeKey) ? $productTypeKey : '';
        $params['groupBy']            = isset($groupBy) ? $groupBy : '';
        $params['orderItemID']        = isset($orderItemID) ? $orderItemID : '';
        $params['masterOrderID']      = isset($masterOrderID) ? $masterOrderID : '';
        $params['shippingSetting']    = $shippingSetting;
        $params['searchBusiness']     = $businessID;
        $resShippedOrders             = $ObjOrder->listShipments($params);
        $resPagesCount                = $this->setPagesCount($key = 'page');
        //Export
        if (isset($_POST['exportAll'])) {
            unset($params['limitTo']);
            $resOrdersCsv      = $ObjOrder->listShipments($params);
            //$defaultCurrency   = $this->getSettingValue("site_settings", "default_currency");
            $defaultCurrency   = $this->ObjView->_defaultCurrency;
            $resCurrency       = $this->ObjView->_currencies[$this->ObjView->_defaultCurrency];
            $currencySymbol    = ($resCurrency['currencySymbolLeft'] != '') ? $resCurrency['currencySymbolLeft'] : $resCurrency['currencySymbolRight'];
            $ObjCsv            = new Csv();
            $csvOutputHeader   = array(
                $this->getLanguageValue("lblShipmentId"),
                $this->getLanguageValue("lblOrderID"),
                $this->getLanguageValue("lblCustomer") . " " . $this->getLanguageValue("lblName"),
                $this->getLanguageValue("lblShippinginfo"),
                $this->getLanguageValue("lblQuantity"),
                $this->getLanguageValue("lblOrderTotalAmount") . "(" . $currencySymbol . ")",
                $this->getLanguageValue("lblShippedDate")
            );
            $csvOutputFileName = "order_list_" . date('d_m_Y_h_i_s_A');
            foreach ($resOrdersCsv as $key => $orders) {
                $orders['shippedAddress']                  = implode("~*", unserialize($orders['shippedAddress']));
                $resOrdersCsvOut[$key]['shippingID']       = $orders['shippingID'];
                $resOrdersCsvOut[$key]['orderNumber']      = $orders['orderNumber'];
                $resOrdersCsvOut[$key]['userFirstName']    = $orders['fullName'];
                $resOrdersCsvOut[$key]['shippedAddress']   = $ObjCountry->getFormattedAddress($orders['shippedAddress'], $languageIDs, ', ', '', $languageIDs['Current']);
                $resOrdersCsvOut[$key]['ItemQuantity']     = $orders['quantity'] . " \ " . $orders['ItemQuantity'];
                $resOrdersCsvOut[$key]['orderTotalAmount'] = $orders['orderTotalAmount'];
                $resOrdersCsvOut[$key]['orderStatusDate']  = $orders['orderStatusDate'];
            }
            $csvOutputData = $ObjCsv->output($csvOutputFileName . '.csv', $resOrdersCsvOut, $csvOutputHeader);
        }
        if (!$sortByOption) {
            $this->ObjView->assign('sortByOption', 'sorderid');
            $this->ObjView->assign('sortByOrder', 'desc');
        }
        $this->ObjView->assign("shippingSetting", $shippingSetting);
        $this->ObjView->assign("resShippedOrders", $resShippedOrders); //echo '<pre>';print_r($resShippedOrders);exit;
        $this->ObjView->display('ShippedList.tpl');
    }
    //END OF FUNCTION
    public function labelAction() {
        $ObjOrder         = new OrderModel();
        $languageIDs      = $this->ObjView->languageIDs;
        $ObjStatus = new OrderstatusModel();
        $this->_allorderstatus = $dynamicOrderStatuses = $ObjStatus->listOrderstatusInOptions(array("list" => 'hash','languageIDs'=>$this->ObjView->languageIDs));
        $jk=0;
        foreach($dynamicOrderStatuses as $key=>$value){
            $dynamicOrdersStatus[$jk][0] = $key;
            $dynamicOrdersStatus[$jk][1] = ($value);
            $jk++;
        }
        $this->ObjView->assign("getDynOrderStatusByKey", $dynamicOrderStatuses);
        $this->ObjView->assign("dynamicOrdersStatus", $dynamicOrdersStatus);
        //search parameters
        $shipmentID       = explode(":", substr($this->decodeUrlString($this->getRequestValue('shipmentIDs')), 0, -1));
        $shipmentID       = implode(",", $shipmentID);
        $resShippedOrders = $ObjOrder->getShipmentDetails($shipmentID, $languageIDs, 'list');
        $orderLangIDs     = $ObjOrder->getOrderLanguageIDs('', $resShippedOrders[0]['masterOrderId']); 
        //echo '<pre>';print_r($resShippedOrders);exit;
        foreach ($resShippedOrders as $key => $array) {
            $shipAddress = unserialize($array['shippingAddress']);
            if ($shipAddress != '') {
                $resShippedOrders[$key]['shippingAddress'] = array_values($shipAddress);
            }
            $billingAddress = unserialize($array['billingAddress']);
            if ($billingAddress != '') {
                $resShippedOrders[$key]['billingAddress'] = array_values(array_slice($billingAddress, 0, -2));
            }
        }
         if($resShippedOrders[0]['items'][0]['shippingMethod']!=''){
            $shippingmethod=$resShippedOrders[0]['items'][0]['shippingMethod'];
        }
        else{
            $shippingmethod='';
        } 
        $adminInfo      = $this->getSettingValue("company_information", "address_1");             
        if($this->getSettingValue("company_information", "address_2")!='') {
            $adminInfo  .=    ",<br>".$this->getSettingValue("company_information", "address_2");
        }            
        if($this->getSettingValue("company_information", "company_city")!='') {
            $adminInfo  .=    ",<br>".$this->getSettingValue("company_information", "company_city");
        }
        if($this->getSettingValue("company_information", "company_zip")!='') {
            $adminInfo  .=    ",<br>".$this->getSettingValue("company_information", "company_zip");
        }
        if($this->getSettingValue("company_information", "company_state")!='' && $this->getSettingValue("company_information", "company_city")!='' && $this->getSettingValue("company_information", "company_state")!=$this->getSettingValue("company_information", "company_city")) {
            $adminInfo  .=    ",<br>".$this->getSettingValue("company_information", "company_state");
        }
        if($this->getSettingValue("company_information", "company_country")!='') {
            $adminInfo  .=    ",<br>".$this->getSettingValue("company_information", "company_country");
        }
        $companyEmail       =   $this->getSettingValue("company_information", "company_email");
        $companyPhone       =   $this->getSettingValue("company_information", "company_phone");
        
        $companyWebsite     =   $this->getSettingValue("company_information", "company_website");
        $companyFax         =   $this->getSettingValue("company_information", "company_fax");
                 
        $this->ObjView->assign("adminInfo", $adminInfo);
        $this->ObjView->assign("companyName", $this->getSettingValue("company_information", "company_name"));
        $this->ObjView->assign("companyEmail", $companyEmail);
        $this->ObjView->assign("companyWebsite", $companyWebsite);
        $this->ObjView->assign("companyFax", $companyFax);
        $this->ObjView->assign("companyPhone", $companyPhone);
        $this->ObjView->assign("shippingMethod", $shippingmethod);
        $this->ObjView->assign("resShippedOrders", $resShippedOrders);
        $vatNumber = ($languageIDs['Current']==$orderLangIDs['Current'])?$this->getLanguageValue('lblVatValue'):$this->getVatNumber($orderLangIDs['Current']);        
        $this->ObjView->assign('vatNumber', $vatNumber);
        $this->ObjView->display('ProductLabelsList.tpl');
    }
    //END OF FUNCTION
    public function getVatNumber($languageID) {        
        $ObjLanguage        = new languageModel();
        $langXML            = $ObjLanguage->loadLanguageXMLtoArray(__CORE_PUBLIC_COMMON_FRONTEND_PATH . '/' . __DIR_LANGUAGE . '/' . $this->ObjCommon->langArray[$languageID]['LanguageLCIDstring'] . '.xml');
        return $langXML['lblVatValue'];
    }
    public function shipmentNotificationMail($postData = array()) {
        if (isset($postData['deliveredNotify']) && $postData['deliveredNotify'] == 'Yes' || isset($postData['dispatchNotify']) && $postData['dispatchNotify'] == 'Yes') {
            $languageIDs        = $this->ObjView->languageIDs;
            $currentLang        = $languageIDs['Current'];
            $ObjLanguage        = new languageModel();
            foreach ($postData['checkOrderIDs'] as $shipmentID) {
                $ObjShipment            = new ShipmentModel();
                $ObjEmailtemplate       = new EmailtemplateModel();
                $ObjOrder               = new OrderModel();
                $ObjUsers               = new UserModel();
                /* Mail for user*/
                $productTitle           = '';
                $masterOrderID          = $ObjShipment->getMasterOrderIdOfShipments($shipmentID);
                $orderLangIDs           = $ObjOrder->getOrderLanguageIDs('', $masterOrderID);
                $resProductOrderDetails = $ObjOrder->getProductOrderDetails($orderLangIDs, '', '', $masterOrderID);
                $billingAddress         = unserialize($resProductOrderDetails[0]['billingAddress']);
                
                $userLangID             = $ObjUsers->getUserDefaultLanguage($resProductOrderDetails[0]['userID']);
                if ($userLangID > 0) {
                    $languageIDs['Current'] = $userLangID;
                }
                //if($currentLang!=$languageIDs['Current']) {                       
                    $langXML                = $ObjLanguage->loadLanguageXMLtoArray(__CORE_PUBLIC_COMMON_FRONTEND_PATH . '/' . __DIR_LANGUAGE . '/' . $this->ObjCommon->langArray[$languageIDs['Current']]['LanguageLCIDstring'] . '.xml');
                    $lblComment             = $langXML['lblComment'];
                    $lblTrackingnumber      = $langXML['lblTrackingnumber'];
                    $lblCarrier             = $langXML['lblCarrier'];
                    $lblDelivered           = $langXML['lblDelivered'];
                    $lblShipmentcreated     = $langXML['lblShipmentcreated'];
                    $lblPickupCreated       = $langXML['lblPickupCreated'];
                    $lblDispatched          = $langXML['lblDispatched'];
                /*} else {
                    $lblComment             = $this->getLanguageValue("lblComment");
                    $lblTrackingnumber      = $this->getLanguageValue("lblTrackingnumber");
                    $lblCarrier             = $this->getLanguageValue("lblCarrier");
                    $lblDelivered           = $this->getLanguageValue("lblDelivered");
                    $lblShipmentcreated     = $this->getLanguageValue("lblShipmentcreated");
                    $lblPickupCreated       = $this->getLanguageValue("lblPickupCreated");
                    $lblDispatched          = $this->getLanguageValue("lblDispatched");

                }*/
                $emailbody   = $ObjEmailtemplate->getEmailTemlateDetails($languageIDs, '', 'product-order-notify');
                $from        = array(
                    $emailbody['emailFromEmail'],
                    $emailbody['emailFromName']
                );
                $siteName    = $this->getSettingValue('site_settings', 'site_name');
                $siteUrl     = $this->getSettingValue('site_settings', 'global_http_url');
                $companyLogo = $this->getSettingValue('company_information', 'company_logo');
                $companyName = $this->getSettingValue('company_information', 'company_name');
                $subject     = $emailbody['emailSubject'];
                foreach ($resProductOrderDetails as $key => $productOrderDetails) {
                    ($key > 0) ? $sep = ',' : $sep = '';
                    $nxtline = "<br />";
                    $productTitle .= $sep . $nxtline . $productOrderDetails['productTitle'];
                }
                $postData['shipmentCarrier'] = '';
                $comment                     = '';
                if ($postData['comment'] != '' || $postData['trackingNumber'] != '' || $postData['shipmentCarrier'] != '') {
                    $comment .= "<table>";
                    if ($postData['comment'] != '') {
                        $comment .= "<tr><td>" . $lblComment . "</td><td>: " . $postData['comment'] . "</td></tr>";
                    }
                    if ($postData['trackingNumber'] != '') {
                        $comment .= "<tr><td>" . $lblTrackingnumber . "</td><td>: " . $postData['trackingNumber'] . "</td></tr>";
                    }
                    if ($postData['shipmentCarrier'] != '') {
                        $comment .= "<tr><td>" . $lblCarrier . "</td><td>: " . $postData['shipmentCarrier'] . "</td></tr>";
                    }
                    $comment .= "</table>";
                }
                $name = $billingAddress['billingFirstName'] . $billingAddress['billingLastName'];
                if ($postData['bulkShippingStatus'] == 'Delivered') {
                    $shipmentCurrentStatus = $lblDelivered;
                } else if ($postData['bulkShippingStatus'] == 'Shipment') {
                    $shipmentCurrentStatus = $lblShipmentcreated;
                } else if ($postData['bulkShippingStatus'] == 'PickUp') {
                    $shipmentCurrentStatus = $lblPickupCreated;
                } else if ($postData['bulkShippingStatus'] == 'Dispatched') {
                    $shipmentCurrentStatus = $lblDispatched;
                }
                $bodytag = str_replace('{$siteName}', $siteName, $emailbody['emailHtml']);
                $bodytag = str_replace('{$productTitle}', $productTitle, $bodytag);
                $bodytag = str_replace('{$comment}', $comment, $bodytag);
                $bodytag = str_replace('{$userName}', $name, $bodytag);
                $bodytag = str_replace('{$status}', $shipmentCurrentStatus, $bodytag);
                $bodytag = str_replace('{$companyLogo}', $companyLogo, $bodytag);
                $this->ObjView->assign('emailbody', $bodytag);
                $this->ObjView->assign('siteUrl', $siteUrl);
                $this->ObjView->assign('siteName', $siteName);
                $this->ObjView->assign('companyLogo', $companyLogo);
                $body                          = $this->ObjCommon->fetch($this->ObjView,"email_templates/Layout.tpl", $languageIDs);
                $mailSettings                  = $this->getSettingValue('mail_settings');
                $mailSettings['smtp_password'] = $this->encryptDecrypt("decrypt", $mailSettings['smtp_password']);
                $emailID                       = $billingAddress['billingEmail'];
                $ObjMail                       = new Mail(isset($mailSettings) ? $mailSettings : '');
                $ObjMail->IsHTML();
                $ObjMail->sendMail($from, $emailID, $subject, $body);
                if ($ObjMail->Send()) {
                }
            }
        }
    }
}