<?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 {
    public function indexAction() {
    }
    //MANAGE SHIPPED PRODUCT ORDERS
    public function shippedAction() {
        $ObjBusiness        = new BusinessModel();
        $ObjOrder           = new OrderModel();
        $ObjCountry         = new CountryModel();
        $ObjShippingMethod  = new ShippingmethodModel();
        $ObjShipment        = new ShipmentModel();
        $languageIDs        = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $resBusiness        = $ObjBusiness->listBusinessInOptions($languageIDs);
        $settingsDateFormat = $this->getSettingValue("site_settings", "date_format");
        $timeFormat         = $this->getSettingValue('site_settings', 'time_format');
        $resProductTypes    = $ObjOrder->getProductTypeOfProducts('product_product');
        $productTypeKey     = 'product_product';
        $productType        = $resProductTypes[0]['productTypeID'];
        $orderLink          = '';
        $fromDate           = '';
        $toDate             = '';
        $link               = '';
        //search
        if (isset($_POST['submitSearch'])) {
            $orderNumber     = trim($this->encodeUrlString($_POST['orderNumber']));
            $shippingSetting = ($_POST['shippingSetting'] == 'business') ? 'merchant' : $_POST['shippingSetting'];
            $date            = $_POST['date'];
            if ($date) {
                $searchDates = explode(' - ', $date);
                $fromDate    = $searchDates[0];
                if (isset($searchDates[1])) {
                    $toDate = $searchDates[1];
                }
            }
            $fromDate       = trim($fromDate);
            $toDate         = trim($toDate);
            $searchBusiness = isset($_POST['searchBusiness']) ? $_POST['searchBusiness'] : '';
            if ($searchBusiness != '') {
                $searchBusiness = implode(":", $searchBusiness);
            }
            $orderStatus     = $_POST['orderStatus'];
            $productKey      = isset($_POST['productKey']) ? trim($this->encodeUrlString($_POST['productKey'])) : '';
            $certificateName = trim($this->encodeUrlString($_POST['certificateName']));
            $paymentStatus   = $_POST['paymentStatus'];
            $shippingStatus  = isset($_POST['shippingStatus']) ? $_POST['shippingStatus'] : '';
            $link .= (($orderNumber != "") ? "orderid/" . $orderNumber . "/" : "");
            $link .= (($fromDate != "") ? "from/" . $this->urlDate($fromDate, 'set', $settingsDateFormat) . "/" : "");
            $link .= (($toDate != "") ? "to/" . $this->urlDate($toDate, 'set', $settingsDateFormat) . "/" : "");
            $link .= (($searchBusiness != "") ? "business/" . $searchBusiness . "/" : "");
            $link .= (($orderStatus != "") ? "status/" . $orderStatus . "/" : "");
            $link .= (($productKey != "") ? "productid/" . $productKey . "/" : "");
            $link .= (($certificateName != "") ? "cname/" . $certificateName . "/" : "");
            $link .= (($paymentStatus != "") ? "pymntstatus/" . $paymentStatus . "/" : "");
            $link .= (($shippingStatus != "" && $shippingStatus != "Any") ? "shippingStatus/" . $shippingStatus . "/" : "");
            $link .= (($shippingSetting != "") ? "shippingby/" . $shippingSetting . "/" : "");
            $link .= (($_POST['sm_main'] != "") ? "sm/" . $_POST['sm_main'] . "/" : "");
            $link .= (($_POST['realtime_sm_services'] != "") ? "stype/" . $_POST['realtime_sm_services'] . "/" : "");
            $link .= (($_POST['trackingNumber'] != "") ? "track/" . $_POST['trackingNumber'] . "/" : "");
            $this->setRedirect('/shipping/shipped/' . $link);
        }
        //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 parameters
        $shippingSetting     = ($this->getRequestValue('shippingby') == 'merchant') ? 'business' : $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);
        $searchBusiness      = $this->getRequestValue('business');
        $orderStatus         = $this->getRequestValue('status');
        $productKey          = $this->decodeUrlString($this->getRequestValue('productid'));
        $certificateName     = $this->decodeUrlString($this->getRequestValue('cname'));
        $paymentStatus       = $this->getRequestValue('pymntstatus');
        $shippingStatus      = $this->getRequestValue('shippingStatus');
        $shippingMethod      = $this->getRequestValue('sm');
        $shippingServiceType = $this->getRequestValue('stype');
        $trackingNumber      = $this->getRequestValue('track');
        $sortByOption        = $this->getRequestValue("sortby");
        $sortByOrder         = $this->getRequestValue("orderby");
        // sort by
        if ($sortByOption == 'sorderid' && $sortByOrder == "asc") {
            $sortByOrderID = "desc";
        } else {
            $sortByOrderID = "asc";
        }
        if ($sortByOption == 'sproductid' && $sortByOrder == "asc") {
            $sortByProductKey = "desc";
        } else {
            $sortByProductKey = "asc";
        }
        if ($sortByOption == 'ssdate' && $sortByOrder == "asc") {
            $sortByDate = "desc";
        } else {
            $sortByDate = "asc";
        }
        if ($sortByOption == 'sshipmentid' && $sortByOrder == "asc") {
            $sortByShipmentID = "desc";
        } else {
            $sortByShipmentID = "asc";
        }
        if ($sortByOption == '') {
            $sortByOption = 'sshipmentid';
        }
        $normallink = "";
        if ($fromDate != "")
            $normallink .= "from/" . $this->urlDate($fromDate, 'set', $settingsDateFormat) . "/";
        if ($toDate != "")
            $normallink .= "to/" . $this->urlDate($toDate, 'set', $settingsDateFormat) . "/";
        if ($searchBusiness != "")
            $normallink .= "business/" . $searchBusiness . "/";
        if ($orderStatus != "")
            $normallink .= "status/" . $orderStatus . "/";
        if ($productKey != "")
            $normallink .= "productid/" . $this->encodeUrlString($productKey) . "/";
        if ($certificateName != "")
            $normallink .= "cname/" . $this->encodeUrlString($certificateName) . "/";
        if ($paymentStatus != "")
            $normallink .= "pymntstatus/" . $paymentStatus . "/";
        if ($productType != "")
            $normallink .= "producttype/" . $productType . "/";
        if ($orderNumber != "")
            $normallink .= "orderid/" . $this->encodeUrlString($orderNumber) . "/";
        if ($orderNumber != "")
            $orderLink .= "orderid/" . $orderNumber . "/";
        if ($shippingStatus != "")
            $normallink .= "shippingStatus/" . $shippingStatus . "/";
        if ($shippingMethod != "")
            $normallink .= "sm/" . $shippingMethod . "/";
        if ($shippingServiceType != "")
            $normallink .= "stype/" . $shippingServiceType . "/";
        if ($trackingNumber != "")
            $normallink .= "track/" . $trackingNumber . "/";
        $normallink .= "list";
        $date = $fromDate;
        if ($toDate) {
            $date .= " - " . $toDate;
        }
        if ($fromDate && $toDate == '') {
            $toDate = $fromDate;
        }
        $this->ObjView->assign("date", $date);
        $this->ObjView->assign("orderNumber", $orderNumber);
        $this->ObjView->assign("normallink", $normallink);
        $this->ObjView->assign("fromDate", $fromDate);
        $this->ObjView->assign("toDate", $toDate);
        $this->ObjView->assign("orderStatus", $orderStatus);
        $this->ObjView->assign("productKey", $productKey);
        $this->ObjView->assign("productType", $productType);
        $this->ObjView->assign("orderLink", $orderLink);
        $this->ObjView->assign("certificateName", $certificateName);
        $this->ObjView->assign("paymentStatus", $paymentStatus);
        $this->ObjView->assign("shippingStatus", $shippingStatus);
        $this->ObjView->assign("selectedBusiness", explode(":", $searchBusiness));
        $this->ObjView->assign("business", $searchBusiness);
        $this->ObjView->assign("date_format", $settingsDateFormat);
        $this->ObjView->assign("time_format", $timeFormat);
        $this->ObjView->assign('sortByOrder', $sortByOrder);
        $this->ObjView->assign('sortByOption', $sortByOption);
        $this->ObjView->assign('sortByOrderID', $sortByOrderID);
        $this->ObjView->assign('sortByProductKey', $sortByProductKey);
        $this->ObjView->assign('smGroupID', $shippingMethod);
        $this->ObjView->assign('selectedServiceType', $shippingServiceType);
        $this->ObjView->assign('trackingNumber', $trackingNumber);
        $this->ObjView->assign('sortByDate', $sortByDate);
        $this->ObjView->assign('sortByShipmentID', $sortByShipmentID);
        $this->ObjView->assign('shippingSetting', $shippingSetting);
        if (!$sortByOption) {
            $this->ObjView->assign('sortByOption', 'sshipmentid');
            $this->ObjView->assign('sortByOrder', 'desc');
        }
        // pagination settings
        if ($shippingStatus == '') {
            $searchShippingStatus = 'Shipped';
        } else {
            $searchShippingStatus = $shippingStatus;
        }
        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 : '';
        $searchBusiness;
        $params['orderStatus'] = isset($orderStatus) ? $orderStatus : '';
        $orderStatus;
        $params['productKey'] = isset($productKey) ? $productKey : '';
        $productKey;
        $params['searchProductTypes'] = isset($searchProductTypes) ? $searchProductTypes : '';
        $params['certificateName']    = isset($certificateName) ? $certificateName : '';
        $certificateName;
        $params['paymentStatus'] = isset($paymentStatus) ? $paymentStatus : '';
        $paymentStatus;
        $params['userID']  = isset($userID) ? $userID : '';
        $params['orderAs'] = isset($sortByOrder) ? $sortByOrder : '';
        $sortByOrder;
        $params['sortBy'] = isset($sortByOption) ? $sortByOption : '';
        $sortByOption;
        $params['shipmentStatus'] = isset($searchShippingStatus) ? $searchShippingStatus : '';
        $searchShippingStatus;
        $params['productTypeKey'] = isset($productTypeKey) ? $productTypeKey : '';
        $productTypeKey;
        $params['groupBy']     = isset($groupBy) ? $groupBy : '';
        $params['orderItemID'] = isset($orderItemID) ? $orderItemID : '';
        $orderItemID;
        $params['masterOrderID'] = isset($masterOrderID) ? $masterOrderID : '';
        $masterOrderID;
        $params['shippingSetting'] = isset($shippingSetting) ? $shippingSetting : '';
        $shippingSetting;
        $params['shippingMethod']      = isset($shippingMethod) ? $shippingMethod : '';
        $params['shippingServiceType'] = isset($shippingServiceType) ? $shippingServiceType : '';
        $params['trackingNumber']      = isset($trackingNumber) ? $trackingNumber : '';
        $resNotShippedOrders           = $ObjOrder->listShipments($params);
        $resPagesCount                 = $this->setPagesCount($key = 'page');
        $this->ObjView->assign("resNotShippedOrders", $resNotShippedOrders);
        if (isset($_POST['export'])) {
            unset($params['limitTo']);
            $resOrdersCsv      = $ObjOrder->listShipments($params);
            $ObjCsv            = new Csv();
            $csvOutputHeader   = array(
                $this->getLanguageValue("lblShipmentId"),
                $this->getLanguageValue("lblOrderID"),
                $this->getLanguageValue("lblCustomer") . " " . $this->getLanguageValue("lblName"),
                $this->getLanguageValue("lblBillinginfo"),
                $this->getLanguageValue("lblShippinginfo"),
                $this->getLanguageValue("lblQuantity"),
                $this->getLanguageValue("lblOrderTotal"),
                $this->getLanguageValue("lblOrderStatus"),
                $this->getLanguageValue("lblPaymentStatus"),
                $this->getLanguageValue("lblShippedDate")
            );
            $csvOutputFileName = "order_list_" . date('d_m_Y_h_i_s_A');
            foreach ($resOrdersCsv as $key => $orders) {
                $orders['billingAddress']                  = array_values(array_slice(unserialize($orders['billingAddress']), 0, -2));
                $orders['shippedAddress']                  = array_values(unserialize($orders['shippedAddress']));
                $resOrdersCsvOut[$key]['shippingID']       = $orders['shippingID'];
                $resOrdersCsvOut[$key]['orderNumber']      = $orders['orderNumber'];
                $resOrdersCsvOut[$key]['userFirstName']    = $orders['fullName'];
                $resOrdersCsvOut[$key]['billingAddress']   = $ObjCountry->getFormattedAddress($orders['billingAddress'], $languageIDs, ', ', ', ', $languageIDs['Current']);
                $resOrdersCsvOut[$key]['shippedAddress']   = $ObjCountry->getFormattedAddress($orders['shippedAddress'], $languageIDs, ', ', ', ', $languageIDs['Current']);
                $resOrdersCsvOut[$key]['ItemQuantity']     = $orders['quantity'] . " \ " . $orders['ItemQuantity'];
                $resOrdersCsvOut[$key]['orderTotalAmount'] = $orders['orderTotalAmount'];
                $resOrdersCsvOut[$key]['orderStatus']      = $ObjOrder->getOrderStatusTitle($orders['dynamicOrderStatus'],$languageIDs);
                $resOrdersCsvOut[$key]['paymentStatus']    = $orders['paymentStatus'];
                $resOrdersCsvOut[$key]['orderStatusDate']  = $orders['orderStatusDate'];
            }
            $csvOutputData = $ObjCsv->output($csvOutputFileName . '.csv', $resOrdersCsvOut, $csvOutputHeader);
        }
        $resLogisticPartners = $ObjShippingMethod->listLogisticPartners();
        $selectAnyArray      = array(
            0 => '',
            'settingsGroupID' => '',
            1 => 'Select',
            'settingsGroupXmlLabel' => 'Select'
        );
        array_unshift($resLogisticPartners, $selectAnyArray);
        //echo '<pre>';print_r($resLogisticPartners);exit;
        $this->ObjView->assign('resSmServices', $resLogisticPartners);
        $this->ObjView->assign("resBusiness", $resBusiness);
        $this->ObjView->assign("labelPrivilege", $this->ObjCommon->hasPrivilege('shipment/label/'));
        $this->ObjView->assign("orderShowprivilage", $this->ObjCommon->hasPrivilege('order/show/'));
        $this->ObjView->assign("shipmentShowPrivilege", $this->ObjCommon->hasPrivilege('shipment/show/'));
        $this->ObjView->assign("shipmentEditPrivilege", $this->ObjCommon->hasPrivilege('shipment/edit/'));
        $this->ObjView->assign("showUserPrivilege", $this->ObjCommon->hasPrivilege('user/show/'));
        $this->ObjView->display('ShippedList.tpl');
    }
    //END OF FUNCTION
    //LIST PRODUCT ORDERS IN THE PAGE
    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
        $orderID          = explode(":", substr($this->decodeUrlString($this->getRequestValue('ordernumbers')), 0, -1));
        $orderID          = implode(",", $orderID);
        $orderLangIDs     = $ObjOrder->getOrderLanguageIDs('', $orderID);
        $resShippedOrders = $ObjOrder->getProductOrderDetails($languageIDs, '', '', $orderID);
        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));
            }
        }
        $vatNumber = ($languageIDs['Current']==$orderLangIDs['Current'])?$this->getLanguageValue('lblVatValue'):$this->getVatNumber($orderLangIDs['Current']);        
        $this->ObjView->assign('vatNumber', $vatNumber);        
        $this->ObjView->assign("resShippedOrders", $resShippedOrders);
        $this->ObjView->display('ProductLabelsList.tpl');
    }
    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'];
    }    
    //END OF FUNCTION
    //FUCNTION TO DLETE SHIPMENT HISTORY
    public function destroyAction() {
        $shippingID        = $this->getRequestValue('id');
        $ObjOrder          = new OrderModel();
        $ObjShippingMethod = new ShippingmethodModel();
        $resTrackDetails   = $ObjShippingMethod->getTrackingIDWithShippingMethod($shippingID);
        if ($resTrackDetails['isRealTimeCalculation'] == 'Yes') {
            $paramsArray           = array(
                'tableName' => 'shipping_methods',
                'fieldName' => 'settingsGroupKey',
                'conditionField' => 'settingsGroupID',
                'condition' => '=',
                'conditionValue' => $resTrackDetails['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 {
                $responseArray = $ObjShipping->cancelShipment($resTrackDetails);
            }*/
            if (is_object($ObjShipping)) {
                $responseArray = $ObjShipping->cancelShipment($resTrackDetails);
            }
        }
        $changestatus = $ObjOrder->destroyShippingHistory($shippingID);
        if ($changestatus) {
            $this->setMessage("language.msgShipmentDeleted", "success");
        }
        $this->setRedirect('/shipping/shipped/');
    }
    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("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()) {
                }
            }
        }
    }
}