<?php

namespace OfficeBrain\Bundle\OrderBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use OfficeBrain\Bundle\UserBundle\Form\ContactBookType;
use OfficeBrain\Bundle\UserBundle\Entity\ContactBook;
use OfficeBrain\Bundle\OrderBundle\Form\OrderAddGuestShippingType;
use OfficeBrain\Bundle\OrderBundle\Form\GuestBillingAddressType;
use OfficeBrain\Bundle\OrderBundle\Form\GuestUserType;
use OfficeBrain\Bundle\OrderBundle\Form\GuestInfoType;


/**
 *
 *
 * @Route("", defaults={"rule_service"="rule_charges"})
 */
class OrderController extends Controller
{
	/**
	 *
	 * @author Employee Id: 4203
	 * To set member variables default value
	 * @return NULL
	 */
	public function __construct()
	{
		$this->request = null;
		$this->user = null;
		$this->userId = null;
		$this->locale = null;
		$this->cultureId = null;
		$this->session = null;
		$this->totalProduct = 0;
		$this->refererUrl = null;
		$this->productIdArray = null;
		$this->sessionManager = null;
		$this->responseArray = array();
		$this->projectSetting = null;
		$this->productCultureIdArray = null;
		$this->inlineViewProductMaxLimit = null;
		$this->productId = null;
		$this->productSlug = null;
		$this->productCultureId = null;
		$this->commonLibraryManager = null;
		$this->config = null;
		$this->productDetailconfigurationRule = null;
		$this->transactionconfigurationRule = null;
		$this->searchParameterArray = array();
		$this->searchKeyWordsArray = array();
		$this->erpIntegration = null;
		$this->queueApiManager = null;
		$this->coreManager = null;
		$this->twigManager = null;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 * To unset member variables
	 * @return NULL
	 */
	public function __destruct()
	{
		unset($this->user);
		unset($this->userId);
		unset($this->locale);
		unset($this->session);
		unset($this->request);
		unset($this->refererUrl);
		unset($this->cultureId);
		unset($this->cultureProductId);
		unset($this->responseArray);
		unset($this->totalProduct);
		unset($this->entityManager);
		unset($this->productIdArray);
		unset($this->sessionManager);
		unset($this->projectSetting);
		unset($this->productCultureIdArray);
		unset($this->productId);
		unset($this->productSlug);
		unset($this->productCultureId);
		unset($this->inlineViewProductMaxLimit);
		unset($this->commonLibraryManager);
		unset($this->config);
		unset($this->productDetailconfigurationRule);
		unset($this->transactionconfigurationRule);
		unset($this->searchParameterArray);
		unset($this->searchKeyWordsArray);
		unset($this->erpIntegration);
		unset($this->queueApiManager);
		unset($this->coreManager);
		unset($this->twigManager);
	}

	/**
	 *
	 * @author Employee Id: 4203
	 * Create various objects required action in this class
	 * @return NULL
	 */
	public function initAction()
	{
		$this->request = $this->getRequest();
		$this->productId = $this->request->get('product_id', null);
		$this->productSlug = $this->request->get('product_slug', null);
		$this->productCultureId = $this->request->get('culture_product_id', null);
		$this->projectSetting = $this->request->get('project_setting');
		$this->siteOwnerId = $this->projectSetting['site_owner_id'];
		$this->projectUserSetting = $this->request->get('project_user_setting');
		$this->user = $this->projectUserSetting['user_data'];

		$this->locale = $this->projectSetting['culture_code'];
		$this->userId = $this->projectSetting['user_id'];
		$this->instanceType = $this->projectSetting['instance_type'];
		$this->responseArray['product_id'] = $this->productId;
		$this->responseArray['status'] = 'error';
		$this->configurationRule = $this->projectSetting['configuration_rule']['transaction']['shopping_cart'];
		$this->configRule = $this->projectSetting['configuration_rule']['transaction']['manage_order'];
		$this->orderManager = $this->get('office_brain_order_manager');
		$this->commonLibraryManager = $this->get('office_brain_common_library');
		$this->sessionManager = $this->get('office_brain_session_manager');
		$this->productDetailManager = $this->get('office_brain_product_detail_manager');
		$this->imageLibraryManager = $this->get('office_brain_cms_media_library_manager');
		$this->colorImageUrl = $this->container->getParameter('api.color_image_base_url');
		$this->artworkFileURL = $this->container->getParameter('artwork.file_url');
		$this->artworkFilePath = $this->container->getParameter('artwork.file_path');
		$this->coreManager = $this->get('office_brain_core_manager');
		$this->fedexShippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_fedex');
		$this->upsShippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_ups');
		//print_riner->getParameter('artwork.temp_file_path');
		//$this->mediaFileURL = $this->container->getParameter('cms.media_file_url');
		$this->categoryApiManager = $this->get("officebrain_category_api_manager");
		$this->mediaFilePath = $this->container->getParameter('cms.media_file_path');
		$this->thirdPartyManager = $this->get('office_brain_cms_third_party_service_manager');

		$this->inlineViewProductMaxLimit = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['inline_view']['option']['no_of_product'];
		$this->config['size_attribute_id'] = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['size_attribute_id'];
		$this->config['color_attribute_id'] = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['color_attribute_id'];
		$this->productDetailconfigurationRule = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['product_detail_popup'];
		$this->transactionconfigurationRule = $this->projectSetting['configuration_rule']['transaction'];

		$this->validationManager = $this->get('office_brain_validation_manager');
		$this->userContactBookManager = $this->get('office_brain_user_contact_book_manager');
		$this->userManager = $this->get('office_brain_user_manager');
        $this->erpIntegration = $this->projectSetting['configuration_rule']['erp_integration'];
        $this->page = $this->request->get('page', '1');
        $this->recordsPerPage = $this->request->get('records_per_page', $this->configRule['list_front']['option']['no_of_product']);
        if ($this->has('office_brain_queue_api_manager')) {
            $this->request->attributes->set('object', 'Order');
            $this->queueApiManager = $this->get('office_brain_queue_api_manager');
        }
        $this->shippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_fedex');
        $this->freeFreightAllowCategoryList = $this->getParameter('free_freight_allow_category_list');
        $this->twigManager = $this->get('twig');
        $this->wishListManager = $this->get('office_brain_wish_list_manager');
        $this->compareProductManager = $this->get('office_brain_compare_product_manager');
   	}

	/**
	 * @author Employee Id: 4217
	 * OB eCommerce Product - preapre  search parameter
	 */
	private function prepareSearchParameterArray()
	{
		$this->option = $this->request->get('option', null);
		$this->keywords = $this->request->get('keyword', null);
		$this->searchKeyWordsArray[$this->option]=trim($this->keywords);

	}


	/**
	 * @author Employee Id: 4203
	 * Description : Load order tab content via ajax.
	 * @param 1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-tab/{product_slug}",
	 * name="office_brain_orderbundle_order_loadorder",
	 * options={"expose"=true}
	 * ) 
	 * @Template("OfficeBrainOrderBundle:Order:loadOrderTab.html.twig")
	 * @Method({"GET"})
	 */
	public function loadOrderTabAction()
	{
		$this->initAction();
		$colourAttr = $this->request->get('clr',null);
		$data = $this->orderManager->getProductDetailBySlug();
		$data['default_color_id'] = $colourAttr;
		return $data;
	}

	/**
	 * @author Employee Id: 4203
	 * Description : Load order decoration tab content via ajax.
	 * @param 1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-decoration/{product_slug}",
	 * name="office_brain_orderbundle_order_decoration",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig")
	 * @Method({"GET"})
	 */
	public function decorationAction()
	{
		$this->initAction();
		$colourAttr = $this->request->get('clr',null);
		$data ['product_detail']=$this->orderManager->getProductDetailBySlug($this->productSlug);
		$data['default_color_id'] = $colourAttr;
		$imageArray = array();
		if($colourAttr==null){
			if(count($data['product_detail']['images'])>0){
				foreach($data['product_detail']['images'] as $key => $imgs){

					if($imgs['is_default']==1){
						
						$imageArray[] = $imgs;
						//$data['default_color_id'] = $imgs['actual_color_id'];
						unset($data['product_detail']['images'][$key]);
					}
				}
			}
			if(array_key_exists('mapped_color_products',$data ['product_detail'])){
				foreach($data['product_detail']['mapped_color_products'] as $key => $colorSlug){
					if($colorSlug==$this->productSlug){
						$data['default_color_id'] = $key;
						break;
					}
				}
			}
		}
		//echo "<pre>";
		//print_r($data); die;
		$data['product_detail']['images'] = array_merge($imageArray,$data['product_detail']['images']);
		//print_r(array_column($data ['product_detail']['images'],'actual_color_id','is_default'));die;
		$data['color_info'] = $this->orderManager->checkForAttribute($data ['product_detail']['attributes']);
		if($data['color_info']['is_trim_color'] == 1 or $data['color_info']['is_ink_color'] == 1 or $data['color_info']['is_barrel_color'] == 1){
			$data['color_info_val'] = $this->orderManager->mergeAttributeArray($data['color_info'],$data ['product_detail']['attributes']);
		}
		$data['is_shipping_allow'] = 'no';
		$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($data ['product_detail']['product_id']);
		if ($shipdetail == true) {
			$data['is_shipping_allow'] = 'yes';
		}
        $data['wishlist_status']= $this->wishListManager->checkProductExist($data ['product_detail']['product_id'], $data ['product_detail']['product_id']);
        $data['compare_status']=$this->compareProductManager->checkProductExistInCompare($data ['product_detail']['product_id'], $data ['product_detail']['product_id']);
		//$data['all_states']=$this->coreManager->getLocateDistributorStateDataAPI();
		$data['type'] = 'decoration';
		$data['order_type'] = 'decorative';
		// $data ['allowed_section'] = array('quantity_price','color','color_quantity','print_position',"shipping_method",'speacial_instruction');
		$data ['allowed_section'] = array('quantity_price','color','color_quantity','print_position');
		$data['config'] = $this->config;

		$firstImprintLocationId = $this->getFirstImprintLocationId($data);
		$firstImprintMethodId = $this->getFirstImprintMethodId($data,$firstImprintLocationId);
		$firstImprintMethodName = $this->getFirstImprintMethodName($data,$firstImprintLocationId);
		$firstMaximumSelectableColor = ($data ['product_detail']['imprint_information']['imprint_method_information'][$firstImprintMethodId]['maximum_selectable_color'] >= 1)?1:0;
		
		$data['first_maximum_selectable_color'] = $firstMaximumSelectableColor;
				
		$data['decoration']['zero_controller']['html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig', $data);
		
		// on clicking the location we are calling two ajax functions, so here we have to render two controllers
		// render the controller of first ajax
		$data['first_controller']['html']['data'] = array(
				'imprint_methods' => $data ['product_detail']['imprint_methods'],
				'imprint_information' => $data ['product_detail']['imprint_information'],
				'imprint_position_and_methods' => $data ['product_detail']['imprint_position_and_methods'],
				'product_id' => $data ['product_detail']['product_id'],
				'imprint_location_id' => $firstImprintLocationId,
		);	
		$data['first_controller']['html']['status'] = 'success';
		
		// render the controller of second ajax		
		$data['second_controller']['imprintLocation'] = array(
				'imprint_methods' => $data ['product_detail']['imprint_methods'],
				'imprint_information' => $data ['product_detail']['imprint_information'],
				'imprint_position_and_methods' => $data ['product_detail']['imprint_position_and_methods'],
				'product_id' => $data ['product_detail']['product_id'],
				'imprint_location_id' => $firstImprintLocationId,
		);		
		$data['second_controller']['confiSetting'] = $this->productDetailconfigurationRule;
		$data['second_controller']['first_imprint_method_id'] = $firstImprintMethodId;
		$data['second_controller']['first_imprint_method_name'] = $firstImprintMethodName;
		// $data['second_controller']['html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:addImprintLocation.html.twig', $data['second_controller']);
		

		// render the controller of third ajax
		$standardImprintColor = $this->orderManager->getStandardImprintColorInformation($data ['product_detail']['product_id']);
		$pmsColor = $this->container->getParameter('pms_color');
		$data['third_controller']['maximum_selectable_color'] = $data ['product_detail']['imprint_information']['imprint_method_information'][$firstImprintMethodId]['maximum_selectable_color'];
		$data['third_controller']['method_name'] = $firstImprintMethodName;
		$data['third_controller']['product_id'] = $data ['product_detail']['product_id'];
		$data['third_controller']['imprint_location_id'] = $firstImprintLocationId;
		$data['third_controller']['first_maximum_selectable_color'] = $firstMaximumSelectableColor;
		$data['third_controller']['standard_imprint_color'] = $standardImprintColor;
		if($data ['product_detail']['imprint_information']['imprint_method_information'][$firstImprintMethodId]['is_pms_color_allow'] == 1) {
			$data['third_controller']['pms_color'] = $pmsColor;
		}
		$data['third_controller']['html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:selectMethod.html.twig', $data['third_controller']);		

		// render the controller of fourth ajax

		$data['fourth_controller'] = array('color_no'=>$firstMaximumSelectableColor
				,'imprint_id'=>$firstImprintLocationId
				,'product_id'=>$data ['product_detail']['product_id']
				,'standard_imprint_color'=> $standardImprintColor
// 				,'pms_color'=> $pmsColor
		);
		if($data ['product_detail']['imprint_information']['imprint_method_information'][$firstImprintMethodId]['is_pms_color_allow'] == 1) {
			$data['fourth_controller']['pms_color'] = $pmsColor;
		}
		$data['fourth_controller']['html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:selectColor.html.twig', $data['fourth_controller']);
		
		return new JsonResponse($data);
		//return $this->render("OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig" , $data );
	}
	
	public function getFirstImprintLocationId($data)
	{
		$firstImprintLocationId = 0;
		if(isset($data ['product_detail']['imprint_position_and_methods']) && (!(empty($data ['product_detail']['imprint_position_and_methods']))))
		{
			foreach($data ['product_detail']['imprint_position_and_methods'] as $key => $imprint_method)
			{
				//{%  if imprint_method.position_area is defined and imprint_method.position_area|length>0 and ob_project_transaction_configuration_rule.shopping_cart.start_from_imprint_method.status==1 %}
				if(isset($imprint_method['position_area']) && strlen($imprint_method['position_area']) > 0
						&& isset($this->transactionconfigurationRule['shopping_cart']['start_from_imprint_method']['status'])
						&& $this->transactionconfigurationRule['shopping_cart']['start_from_imprint_method']['status'] == 1)
				{
					if($firstImprintLocationId == 0)
					{
						$firstImprintLocationId = $key;
						break;
					}
				}
				else
				{
					if($firstImprintLocationId == 0)
					{
						$firstImprintLocationId = $imprint_method['id'];
						break;
					}
				}
			}
		}
		return $firstImprintLocationId;
	}
	public function getFirstImprintMethodId($data,$firstImprintLocationId)
	{
		$firstImprintMethodId = 0;
		if(isset($data ['product_detail']['imprint_position_and_methods']) && (!(empty($data ['product_detail']['imprint_position_and_methods']))))
		{
			foreach($data ['product_detail']['imprint_position_and_methods'] as $location_id => $imprint_position)
			{
				if($location_id == $firstImprintLocationId)
				{
					if(isset($imprint_position['imprint_method']))
					{
						foreach($imprint_position['imprint_method'] as $id => $method)
						{
							if($firstImprintMethodId == 0)
							{
								$firstImprintMethodId = $id;
								break;
							}
						}
					}
				}
			}
		}
		
		return $firstImprintMethodId;
	}
	public function getFirstImprintMethodName($data,$firstImprintLocationId)
	{
		$firstImprintMethodName = '';
		if(isset($data ['product_detail']['imprint_position_and_methods']) && (!(empty($data ['product_detail']['imprint_position_and_methods']))))
		{
			foreach($data ['product_detail']['imprint_position_and_methods'] as $location_id => $imprint_position)
			{
				if($location_id == $firstImprintLocationId)
				{
					if(isset($imprint_position['imprint_method']))
					{
						foreach($imprint_position['imprint_method'] as $id => $method)
						{
							if($firstImprintMethodName == '')
							{
								$firstImprintMethodName = $method;
								break;
							}
						}
					}
				}
			}
		}
		
		return $firstImprintMethodName;
	}

	/**
	 * @author Employee Id: 4203
	 * Description : Load order blank tab content via ajax.
	 * @param 1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-blank/{product_slug}",
	 * name="office_brain_orderbundle_order_blank",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig")
	 * @Method({"GET"})
	 */
	public function blankAction()
	{
		$this->initAction();

		$data ['product_detail']=$this->orderManager->getProductDetailBySlug($this->productSlug);
// comment for the Distributor Display Without select State
// 		$data['all_distributor']=$this->userManager->getDistributors();
		$data['all_states']=$this->coreManager->getLocateDistributorStateDataAPI();
		$data['type'] = 'blank';
		$data['order_type'] = 'blank';
		$data ['allowed_section'] = array('quantity_price','color','color_quantity','shipping_method','speacial_instruction');
		$data['config'] = $this->config;
		return $data;
		//return $this->render("OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig" , $data );
	}

	/**
	 * @author Employee Id: 4203
	 * Description : Load order sample tab content via ajax.
	 * @param 1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-sample/{product_slug}",
	 * name="office_brain_orderbundle_order_sample",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:loadOrderDetail.html.twig")
	 * @Method({"GET"})
	 */
	public function sampleAction()
	{
		$this->initAction();
		
		$data ['product_detail'] = $this->orderManager->getProductDetailBySlug($this->productSlug);
		$data['color_info'] = $this->orderManager->checkForAttribute($data ['product_detail']['attributes']);
		if($data['color_info']['is_trim_color'] == 1 or $data['color_info']['is_ink_color'] == 1 or $data['color_info']['is_barrel_color'] == 1){
			$data['color_info_val'] = $this->orderManager->mergeAttributeArray($data['color_info'],$data ['product_detail']['attributes']);
		}
		// comment for the Distributor Display Without select State
		$data['all_states'] = $this->coreManager->getLocateDistributorStateDataAPI();
		$data['type'] = 'sample';
		$data['order_type'] = 'sample';
		$data ['allowed_section'] = array('sample','quantity_price','color','color_quantity','shipping_method','speacial_instruction');
		$data['config'] = $this->config;
		//$data['all_distributor'] = $distributor=$this->userManager->getDistributors();
		
		return $data;
		//return new JsonResponse($data);
		//return array('product_detail'=>$productDetail,'order_type'=>'sample','type'=>'sample','allowed_section'=>$allowedSection, 'config'=>$this->config, 'all_distributor'=>$distributor,'all_states'=> $states );
	}

	/**
	 * @author Employee Id: 410175
	 * Description : Use to render Color Wise Qty
	 * @param 1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-get-color-wise-quantity",
	 * name="office_brain_orderbundle_order_getProductAttribute",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:getProductAttribute.html.twig")
	 * @Method({"POST","GET"})
	 */
	public function getProductAttributeAction()
	{ 
		//$this->initAction();
		$orderManager = $this->get('office_brain_order_manager');
		$colorImageUrl = $this->container->getParameter('api.color_image_base_url');
		$productAttributes = $orderManager->getSizeAttributeByColor($colorImageUrl);
		$productId = $this->getRequest()->get('product_id',null);
		$productId = '1336484';
		$shiType = $this->getRequest()->get('shipping_type',null);
		//$extraCharge = $this->productDetailManager->getExtraChargeByProductId($productId);
		//$product = $this->productDetailManager->getProductDetailById($productId, $this->locale);
		$productData = $productAttributes['products'];
		$minPrice = $productData['min_price'];
		$exchargeData = null;
		$fdetailvalue = null;
		$sizeArray = array();
		$indexKey = 0;
		$orderSize = array();
		if(count($productAttributes['attributes'])>0){
			foreach($productAttributes['attributes'] as $ind=>$attr){
				if($attr['id']==11){
					$sizeArray = $attr['values'];
					$indexKey = $ind;
					break;
				}
			}
		}
		if(count($sizeArray)>0){
			$sizeflipArray = array_flip($sizeArray);
			if(isset($productData['feature_details'])){
				foreach($productData['feature_details'] as $feature){
					if($feature['label']=="Additional Size Charge"){
						$fdetailvalue =$feature['value'];
					}
				}
			}

			if($fdetailvalue!=null){
				$value = array();
				$sizedata = explode('#',$fdetailvalue);
				foreach($sizedata as $val){
					$valData = explode(':',$val);
					$value[$valData[0]] = $valData[1]; 
					$orderSize[$valData[0]] = $sizeflipArray[$valData[0]];
				}
				$exchargeData = $value;
				
			}else{
				$orderSize = $sizeflipArray;
			}
			$productAttributes['attributes'][$indexKey]['values'] = $orderSize;
		}
		
		if($shiType !=''){
			$ShippingQtyBox = $orderManager->getBlankColorQuantityValue($productAttributes);
			$html = $this->get('twig')->render("OfficeBrainOrderBundle:Order:loadShippingQuantityBox.html.twig" , $ShippingQtyBox);
			return new JsonResponse(array('data'=>$productAttributes,'status'=>'success','shipping_qty_box'=>$html));
		}
		return new JsonResponse(array('data'=>$productAttributes,'exchargeData'=>$exchargeData,'status'=>'success'));
	}

	/**
	 * @author Employee Id: 4203
	 * Description : Use to render Size attribute header for quantity
	 * @param 1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-size-header/{product_id}/{edit}",
	 * name="office_brain_orderbundle_order_getproductheadingattribute"
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:getProductHeadingAttribute.html.twig")
	 */
	public function getProductHeadingAttributeAction()
	{
		$this->initAction();
		$this->responseArray['productCatgory']=$this->projectSetting['configuration_rule']['transaction']['shopping_cart']['product_detail_popup']['option']['product_category'];
		$this->responseArray['size'] = $this->orderManager->getSizeAttributeHeader();
		$this->responseArray['edit']= $this->request->get('edit');
		return $this->responseArray;
	}


	/**
	 * @author Employee Id: 410175
	 * Description : Use to render imprint location in summary box.
	 * @param 1 : No paramater
	 * @return type : Ajax response in json.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/order-add-imprint-location-summary",
	 * name="office_brain_orderbundle_order_addimprintlocationsummary",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:addImprintLocationSummary.html.twig")
	 * @Method({"POST"})
	 */
	public function addImprintLocationSummaryAction()
	{
		//$this->initAction();
		$orderManager = $this->get('office_brain_order_manager');
		$productId = $this->getRequest()->get('product_id', null);
		$addImprintLocation=$orderManager->addImprintLocation();
		$responseArray['product_id'] = $productId;
		$responseArray['status'] = 'success';
		$responseArray['data'] = $addImprintLocation;
		return new JsonResponse($responseArray);
	}

	/**
     * @author Employee Id: 410175
     * Description : Use to render view to add imprint location box.
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-add-imprint-location",
     * name="office_brain_orderbundle_order_addimprintlocation",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:addImprintLocation.html.twig")
     * @Method({"POST"})
     */
    public function addImprintLocationAction()
    {
    	//$this->initAction();
    	$projectSetting = $this->getRequest()->get('project_setting');
    	$orderManager = $this->get('office_brain_order_manager');
    	$productDetailconfigurationRule= $projectSetting['configuration_rule']['transaction']['shopping_cart']['product_detail_popup'];;
		$data = array();
		$data['imprintLocation'] = $orderManager->addImprintLocation();
		$data['confiSetting'] = $productDetailconfigurationRule;
    	return $data;
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to render view to add imprint location box when color are automatic displayed if we select the position ex. (Top, Bottom etc..).
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-pre-color-add-imprint-location",
     * name="office_brain_orderbundle_order_precoloraddimprintlocation",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:preColorAddImprintLocation.html.twig")
     * @Method({"POST"})
     */
    public function preColorAddImprintLocationAction()
    {
    	/**  HERE_WE_CHANGE_CODE  **/
    	$this->initAction();
    	$data = array();
    	$data['imprintLocation'] = $this->orderManager->addPreImprintLocation();
    	$data['confiSetting'] = $this->productDetailconfigurationRule;
    	$data['selectImprintMethod'] = $this->orderManager->selectPreImprintMethod();
    	return $data;
    	/** END  HERE_WE_CHANGE_CODE ***/
    }

    /**
     * @author Employee Id: 410175
     * Description : Use to render Shipping by Type (Statndard/Split)
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-select-shipping-type",
     * name="office_brain_orderbundle_order_selectShippingType",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:selectShippingType.html.twig")
     * 
     */
 	public function selectShippingTypeAction()
    {   
    	$this->initAction();
    	$data = $this->orderManager->getShippingType();
    	$data['shipping_estimator'] = 'no';
    	$productId = $this->request->get('product_id');
    	$data ['color_info'] = $this->orderManager->checkForAttribute($data['product_attributes']);
    	$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
		if ($shipdetail == true) {
			$data ['shipping_estimator'] = 'yes';
		}
    	$data['userId'] = $this->userId;
    	$data['edit'] = $this->request->get('edit');
    	$data['order_type'] = $this->request->get('order_type');
    	//echo '<pre/>';print_r($data);exit;
    	return $data;
    }

    /**
     * @author Employee Id: 410175
     * Description : Use to render Shipping Address from Contact book/My Address book
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-get-shipping-address",
     * name="office_brain_orderbundle_order_getShippingAddress",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getShippingAddress.html.twig")
     * @Method({"GET"})
     */
    public function getShippingAddressAction()
    {
    	$this->initAction();

    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	else
    	{
    		$Address = $this->orderManager->getUserShippingAddresByEmailOrName();
    		$addressRes = array();
    		foreach ($Address as $key=>$aa){
    			$addressRes[$aa['id']] = array('id'=>$aa['id'],'label'=>$aa['label']);
    		}
    		return new JsonResponse($addressRes);
    	}

    }

    /**
     * @author Employee Id: 410175
     * Description : Use to render Shipping Address By Id
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-get-shipping-address-by-id",
     * name="office_brain_orderbundle_order_getshippingaddressbyid",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getShippingAddressById.html.twig")
     * @Method({"GET"})
     */
    public function getShippingAddressByIdAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->orderManager->getUserShippingAddresById();
    	$this->response['addressId'] = $this->request->get('contact_id',null);
    	return $this->response;
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to render Shipping Address By Id
     * @Route("/{_locale}/order-get-shipping-address-by-id-summary",
     * name="office_brain_orderbundle_order_getshippingaddressbyidsummary"
     * )
     * @Template()
     */
    public function getShippingAddressByIdSummaryAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->orderManager->getUserShippingAddresById();
    	$this->response['addressId'] = $this->request->get('contact_id',null);
    	$this->response ['ob_project_setting'] = $this->projectSetting;
    	return $this->response;
    }

    /**
     * @author Employee Id: 410175
     *
     * Description : Use to submit guest user quote form.
     *
     * @param 1 : No paramater
     *
     * @return type : Form view and data.
     *
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-select-method",
     * name="office_brain_orderbundle_order_selectMethod",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:selectMethod.html.twig")
     * @Method({"POST"})
     */
    public function selectMethodAction()
    {
    	//$this->initAction();
    	$chargeList = $this->container->getParameter('run_charge_list');
    	$orderManager = $this->get('office_brain_order_manager');
		$selectImprintMethod = $orderManager->selectImprintMethod($chargeList);
    	return $selectImprintMethod;
    }

    //HERE_WE_CHANGE_CODE
    /**
     * @author Employee Id: 4532
     *
     * Description : For get quantity price as per select imprint method.
     *
     * @param 1 : No paramater
     *
     * @return type : Form view and data.
     *
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-get-quantity-price-as-imprint-method",
     * name="office_brain_orderbundle_order_quantityprice_as_imprintmethod",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getQuantityPriceAsImprintMethod.html.twig")
     * @Method({"POST"})
     */
    public function getQuantityPriceAsImprintMethodAction()
    {
    	$this->initAction();
    	$productId = $this->request->get('product_id');
    	$imprintMethodId = $this->request->get('imprint_method_id');
    	return $this->orderManager->getProductPriceInfo($productId,$imprintMethodId);
    }

    /**
     * @author Employee Id: 4532
     * Description : For get quantity price as per select imprint method.
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-get-imprint-location-by-imprint-method-id",
     * name="office_brain_orderbundle_order_imprintlocationbyimprintmethodid",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getImprintLocationByImprintMethodId.html.twig")
     * @Method({"POST"})
     */
    public function getImprintLocationByImprintMethodIdAction()
    {
    	$this->initAction();
    	return $this->orderManager->getImprintLocationByImprintMethodId();
    }

    //END HERE_WE_CHANGE_CODE

    /**
     * @author Employee Id: 410175
     * Description : Use to show the list of product in this request quote.
     * @param 1 : No paramater
     * @return type : json
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-select-color-request-quote",
     * name="office_brain_orderbundle_order_selectColor",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:selectColor.html.twig")
     * @Method({"POST"})
     */
    public function selectColorAction()
    {

    	$this->initAction();
    	$standardImprintColor = $this->orderManager->getStandardImprintColorInformation();
    	$pmsColor = $this->container->getParameter('pms_color');
    	
    	$selectColorArray = array(
    			'color_no'=>$this->request->get('color_no'),
    			'imprint_id'=>$this->request->get('imprint_id'),
    			'product_id'=>$this->request->get('product_id'),
    			'standard_imprint_color'=> $standardImprintColor,
//     			'pms_color'=>$pmsColor
    	);
    	
    	$data ['product_detail']=$this->orderManager->getProductDetailById($this->request->get('product_id'));
    	if(isset($data ['product_detail']) && !empty($data ['product_detail'])) {
    		$imprintMethodId = $this->getFirstImprintMethodId($data,$this->request->get('imprint_id'));
    		if(isset($imprintMethodId) && $imprintMethodId!='') {
    			if($data ['product_detail']['imprint_information']['imprint_method_information'][$imprintMethodId]['is_pms_color_allow'] == 1) {
    				$selectColorArray['pms_color'] = $pmsColor;
    			}
    		}
    	}
    	
    	return $selectColorArray;
    }

    /**
     * @author Employee Id: 410175
     * Description : use to render Select Logo Block
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-select-logo-block",
     * name="office_brain_orderbundle_order_selectlogoblock",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:selectLogoBlock.html.twig")
     * @Method({"GET"})
     */
    public function selectLogoBlockAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	else
    	{
    		$page=$this->request->get('page',1);
    		$recordPerPage = $this->request->get('recordperpage',12);
	    	$this->response ['logo_id'] = $this->request->get ( 'productsku' );
			$this->response ['callFrom'] = $this->request->get ( 'productName' );
	    	//$this->response['record_set']=$this->imageLibraryManager->getMediaLibraryRecords();
	    	$this->response['record_set']=$this->imageLibraryManager->getMediaLibraryRecordsWithPagination(null,$page,$recordPerPage=9);

	    	return $this->response;
    	}
    }

    /**
     * @author Employee Id: 4471
     * Description : use to copy image for art work
     * @param 1 : No paramater
     * @return type : Ajax response in image successfully uploaded
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-upload-artwork-from-gallery",
     * name="office_brain_orderbundle_order_uploadartworkfromgallery",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:uploadArtWorkFromGallery.html.twig")
     * @Method({"POST"})
     */
    public function uploadArtWorkFromGalleryAction()
    {
    	$this->initAction();
    	$logoId= $this->request->get('logoId');
    	$originalImageName= $this->request->get('imageName');
    	$imageUpload=$this->imageLibraryManager->copyMedia($this->mediaFilePath, $this->artworkFilePath ,$originalImageName,$originalImageName);
    	if($imageUpload != '')
    	{
    		$this->response['logoId']=$logoId;
    		$this->response['uploadedImageName']= $this->artworkFileURL.'/'.$imageUpload;
    		$this->response['status']='success';
    		$this->response['success_message']= $this->get('translator')->trans('order.print_position.artwork.upload_image_sucess');
    	}
    	else
    	{
    		$this->response['logoId']=$logoId;
    		$this->response['sucess']='error';
    	}
    	return new JsonResponse($this->response);
    }

    /**
     * @author Employee Id: 4471
     * Description : use to upload image
     * @param 1 : No paramater
     * @return type : Ajax response in image uploaded from system
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-upload-new-artwork",
     * name="office_brain_orderbundle_order_uploadnewartwork",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:uploadNewArtWork.html.twig")
     * @Method({"POST"})
     */
    public function uploadNewArtWorkAction()
    {
    	$this->initAction();
    	$addtoDb = 'no';
    	$this->name=$this->imageLibraryManager->uploadMediaFileToFolder($_FILES,$this->artworkFilePath,$addtoDb);
    	$this->responseArray = $this->artworkFileURL.'/'.$this->name[0];
    	return new JsonResponse($this->responseArray);
    }

	/**
	 * @author Employee Id: 4217
	 * Description : Use add to cart
	 * @param 1 : product_id
	 * @return type : Form view.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/add-to-cart",
	 * name="office_brain_orderbundle_order_addtocart",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:addToCart.html.twig")
	 * @Method({"POST"})
	 */
	public function addToCartAction()
	{
		$this->initAction();
		$status = $this->orderManager->setPreAddToCart();
		switch ($status)
		{
			case 'ERROR_MAX_LIMIT_REACHED':
				$this->responseArray['error_message'] = $this->get('translator')->trans('cart_list.max_product_cart', array('%count%'=>$this->inlineViewProductMaxLimit));
				break;
			case 'ERROR_PRODUCT_ALREADY_EXISTS':
				$this->responseArray['error_message'] = $this->get('translator')->trans('cart_list.product_already_exists');
				break;
			case 'SUCCESS':
				$this->responseArray['status'] = 'success';
				$this->responseArray['success_message'] = $this->get('translator')->trans('cart_list.add_success_message');
				$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
				break;
		}
		if ($this->refererUrl=='office_brain_orderbundle_order_cartlist') {
			$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
		} else {
			$this->responseArray['total_product'] = $this->orderManager->getTotalCount();
		}

		return new JsonResponse($this->responseArray);
	}

	/**
	 * @author Employee Id: 4217
	 * Description : Use edit to cart
	 * @param 1 : product_id
	 * @return type : Form view.
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/edit-to-cart/{cart_id}",
	 * name="office_brain_orderbundle_order_edittocart",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:editToCart.html.twig")
	 *
	 */
	public function editToCartAction() {
		$this->initAction ();
		list($defaultCulture,$defaultCountry) = explode("_",$this->request->get("_locale"));
		$culture = $this->request->get('language',$defaultCulture);
		$activeCulture = $culture;
		$cultureCategory =  $activeCulture . "_" . $country;
		$categoryAndSubCategoryData = $this->categoryApiManager->getList(array($cultureCategory),array(),true);
		if($this->userId==0 && $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1){
			if ($this->request->isXmlHttpRequest()) {
				$this->responseArray['status'] = 'error';
				$this->responseArray['error_type'] ='loginError';
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
				return new JsonResponse($this->responseArray);
			}else{
				$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route'),array('cart_id'=>$this->request->get('cart_id'))));
				return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
			}
		}else{
		$startFromImprintMethod = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['start_from_imprint_method']['status'];
		$productDetail = $this->orderManager->getProductDataForEdit();
		$this->request->request->set('culture_product_id', $productDetail['culture_product_id']);
		$this->responseArray ['request_quote_session'] =  $this->orderManager->getInputDataForEdit();

		$exchargeData = null;
		$fdetailvalue = null;
		if(isset($productDetail['feature_details'])){
			foreach($productDetail['feature_details'] as $feature){
				if($feature['label']=="Additional Size Charge"){
					$fdetailvalue =$feature['value'];
					break;
				}
			}
		}
		if($fdetailvalue!=null){
			//$orderSize = array();
			$sizeArray = array();
			$indexKey = 0;
			if(count($productDetail['attributes'])>0){
				foreach($productDetail['attributes'] as $ind=>$attr){
					if($attr['id']==11){
						$sizeArray = $attr['values'];
						$indexKey = $ind;
						break;
					}
				}
			}
			$sizeflipArray = array_flip($sizeArray);
			$sizeQtyMapping = array();
			$sizeQtyMappingIndex = 0;
			foreach($this->responseArray ['request_quote_session']['color'] as $sizeindx=>$reqData){
				if(isset($reqData['size'])){
					foreach($reqData['size'] as $key=>$sizes){
						$sizeQtyMapping[$sizes]=$reqData['quantity'][$key];
					}
					$sizeQtyMappingIndex = $sizeindx;
					break;
				}
			}
			
			$sizeReqArray = array();
			$sizedata = explode('#',$fdetailvalue);
			$cnt = 0;
			foreach($sizedata as $val){
				$valData = explode(':',$val);
				$exchargeData[$valData[0]] = $valData[1];
				$sizeReqArray['size'][$cnt] = $sizeflipArray[$valData[0]];
				$sizeReqArray['quantity'][$cnt] = $sizeQtyMapping[$sizeflipArray[$valData[0]]];
				//$orderSize[$sizeflipArray[$valData[0]]] = $valData[0];
				$cnt++;
			}
			$this->responseArray ['request_quote_session']['color'][$sizeQtyMappingIndex]=$sizeReqArray;
		}

		//$this->responseArray ['product_detail'] = $productDetail;

		$imprintMethodPosition = array();
		$chargeList = $this->container->getParameter('run_charge_list');
		if($chargeList!=NULL){
			$chargeList = array_keys($chargeList);
		}
		if($startFromImprintMethod == 1){
			$imprint = $this->responseArray ['request_quote_session']['imprint'];
			foreach($imprint as $key=>$imp){
				$impPosition = explode(':',$key);
				$imprintMethodPosition[$imp['imprint_method_id']] = $impPosition[1];

				$no_of_colors=0;
				if(isset($productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['charges']))
				{
					foreach($productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['charges'] as $charge=>$chargeData){
						if(in_array($charge,$chargeList)){
							
							$no_of_colors++;
						}
					}	
				}else{
					$no_of_colors=1;
				}

				$productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['maximum_selectable_color'] =$no_of_colors;

				//echo $no_of_colors."===============s".$imp['imprint_method_id'];
			}
		}else{
			$imprint = $this->responseArray ['request_quote_session']['imprint'];
			foreach($imprint as $key=>$imp){
				$no_of_colors=0;
				if(isset($productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['charges']))
				{
					foreach($productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['charges'] as $charge=>$chargeData){
						if(in_array($charge,$chargeList)){
							
							$no_of_colors++;
						}
					}	
				}else{
					$no_of_colors=1;
				}

				$productDetail['imprint_information']['imprint_method_information'][$imp['imprint_method_id']]['maximum_selectable_color'] =$no_of_colors;
			}
		}

		$this->responseArray ['product_detail'] = $productDetail;
		$this->responseArray ['imprint_method_position'] = $imprintMethodPosition;
		if($productDetail['is_size']==1){
			$this->responseArray ['size_allow'] = true;
		}else{
			$this->responseArray ['size_allow'] = false;
		}
		$categoryAndSubCategoryList = array();
		$categoryAndSubCategoryList = $this->categoryApiManager->getParentChildCategoryList($categoryAndSubCategoryData,$productDetail['category'],$activeCulture);
		$existValue = 0;
		
		$this->responseArray['color_info'] = $this->orderManager->checkForAttribute($productDetail['attributes']);
		if($this->responseArray['color_info']['is_trim_color'] == 1 or $this->responseArray['color_info']['is_ink_color'] == 1 or $this->responseArray['color_info']['is_barrel_color'] == 1){
			$this->responseArray['color_info_val'] = $this->orderManager->mergeAttributeArray($this->responseArray['color_info'],$productDetail['attributes']);
		}
		$this->responseArray['dispalyText'] = $existValue;
		$this->responseArray['all_distributor']=$this->userManager->getDistributors();
		$this->responseArray['all_states']=$this->coreManager->getLocateDistributorStateDataAPI();
		$this->responseArray['cart_id']=$this->request->get('cart_id');
		$this->responseArray['allowed_section'] = array('quantity_price','color','color_quantity','print_position');
		$this->responseArray['type'] = 'decoration';
		$this->responseArray['order_type'] = 'decorative';
		$this->responseArray['exchargeData'] = $exchargeData;
		
		//echo "<pre>";
		//print_r($this->responseArray); die;
		return $this->responseArray;
		}
		
	}
    
    /**
     * @author Employee Id: 4203
     * Description : use to display guest shipping data
     * @param 1 : productid
     * @param 2 : method
     * @param 3 : counter
     * @return type : Ajax response in view.
     * @throws Exception: Null
     * @Route("/{_locale}/order-guest-ship-address-cart-item/{product_id}/{method}/{counter}",
     * name="office_brain_orderbundle_order_guestshippingaddress_cartitem"
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderGuestShipping.html.twig")
     */
    public function orderGuestShippingCartItemAction()
    {
    	$this->initAction();
    	$this->responseArray = $this->orderManager->getGuestAddressInfoForCartItem();
    	$this->responseArray['edit']=0;
    	$this->responseArray['is_summary'] = $this->request->get('is_summary', 0);
    	return $this->responseArray;
    }

	/**
	 * @author Employee Id: 4203
	 * Description : Use to unset session data for order
	 * @return type : json
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/unset-cart-session",
	 * name="office_brain_orderbundle_order_unsetcartsession",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:unsetCartSession.html.twig")
	 * @Method({"POST"})
	 */
	public function unsetCartSessionAction()
	{
		$this->initAction();
		$status = $this->requestQuoteManager->unsetAddToRequestQuote();
		switch ($status)
		{
			case 'SUCCESS':
				$this->responseArray['status'] = 'success';
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_requestquotebundle_requestquote_requestquotelist');
				return new JsonResponse($this->responseArray);
		}
		return new JsonResponse($this->responseArray);
	}

	/**
	 * To get recent cart product  list
	 *
	 * @Route("/{_locale}/recent-cart-list",
	 * 	name="office_brain_orderbundle_order_recentcartlist",
	 *  options={"expose"=true}
	 * )
	 *
	 * @Method({"GET"})
	 * @Template("OfficeBrainOrderBundle:Order:recentCartList.html.twig")
	 */
	public function recentCartListAction()
	{
		$this->initAction();
		$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
		$this->responseArray['record_set'] = $this->orderManager->getMaxNoOfCart($this->inlineViewProductMaxLimit);
		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 * Desciption: This function allow user to delete product from his/her cart list.
	 *
	 * @param integer productId
	 * @param integer cultureProductId
	 *
	 * @return Json Response
	 *
	 * @throws NULL
	 *
	 * @Route("/{_locale}/cart-list-delete",
	 * 	name="office_brain_orderbundle_order_deletecart",
	 *  options={"expose"=true}
	 * )
	 *
	 * @Method({"POST"})
	 *
	 * @Template("OfficeBrainOrderBundle:Order:deleteCart.html.twig")
	 *
	 */
	public function deleteCartAction()
	{
		$this->initAction();
		if($this->userId==0 && $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1){
			if ($this->request->isXmlHttpRequest()) {
				$this->responseArray['status'] = 'error';
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
				return new JsonResponse($this->responseArray);
			}else{
				$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
				return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
			}
		}else{
			$status = $this->orderManager->deleteCartList();
			switch ($status) {
				case 'ERROR_NOT_FOUND':
					$this->responseArray['error_message'] = $this->get('translator')->trans('cart_list.product_not_found');
					break;
				case 'SUCCESS':
					$this->responseArray['status'] = 'success';
					$this->responseArray['success_message'] = $this->get('translator')->trans('cart_list.remove_success_message');
					$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
					break;
			}

			if ($this->refererUrl=='office_brain_orderbundle_order_cartlist') {
				$this->sessionManager->set('cart_success_deleted',$this->get('translator')->trans('cart_list.remove_success_message'));
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
			} elseif ($this->refererUrl=='office_brain_orderbundle_order_checkoutdetail') {
				$this->sessionManager->set('cart_success_deleted',$this->get('translator')->trans('cart_list.remove_success_message'));
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_checkoutdetail');
			} else {
				$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
			}
		}

		return new JsonResponse($this->responseArray);
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *
	 * Desciption: This function allow user to delete all product from his/her cart list.
	 *
	 * @param integer productId
	 * @param integer cultureProductId
	 *
	 * @return Html Response
	 *
	 * @throws NULL
	 *
	 * @Route("/{_locale}/cart-list-delete-all",
	 * 	name="office_brain_orderbundle_order_deleteallcart", options={"expose"=true}
	 * )
	 *
	 * @Method({"POST"})
	 *
	 * @Template("OfficeBrainOrderBundle:Order:deleteAllCart.html.twig")
	 *
	 */
	public function deleteAllCartAction()
	{
		$this->initAction();
		$status = $this->orderManager->deleteAllCartList();
		switch ($status)
		{
			case 'ERROR_NOT_FOUND':
				$this->responseArray['error_message'] = $this->get('translator')->trans('cart_list.product_not_found');
				break;
			case 'SUCCESS':
				$this->responseArray['status'] = 'success';
				$this->responseArray['success_message'] = $this->get('translator')->trans('cart_list.remove_success_message');
				$this->refererUrl = $this->commonLibraryManager->getRefererRouteName();
				break;
		}

		if ($this->refererUrl=='office_brain_orderbundle_order_cartlist') {
			$this->sessionManager->set('cart_success_deleted',$this->get('translator')->trans('cart_list.remove_success_message'));
			$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
			$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
		} else {
			$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
		}

		return new JsonResponse($this->responseArray);

	}
	
	/**
	 * To get cart product list
	 *
	 * @Route("/{_locale}/cart-list",
	 * 	name="office_brain_orderbundle_order_cartlist", options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:cartList.html.twig")
	 */
	public function cartListAction()
	{
		$this->initAction();
		if($this->userId==0 && $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1){
			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
		}
		
		$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
		$this->deliveryStatus= $this->orderManager->checkProductDeliveryDate();
		$this->responseArray['shopping_cart_list'] = $this->orderManager->getCartList();
		//echo "<pre>";print_r($this->responseArray['shopping_cart_list']);exit;
		$this->orderManager->setContinueShoppingUrl($this->commonLibraryManager->getRefererRouteName(), $this->commonLibraryManager->getRefererUrl());
		return $this->responseArray;
	}


	/**
     * @author Employee Id: 410175
     * Description : Use to set session data for order
     * @param 1 : No paramater
     * @return type : json
     * @throws Exception: Null
     *
     * @Route("/{_locale}/set-product-to-cart",
     * name="office_brain_orderbundle_order_setproducttocart",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainOrderBundle:Order:setProductToCart.html.twig")
     */
    public function setProductToCartAction()
    {
    	$this->initAction();
    	//echo '<pre/>';print_r($_POST);exit;
    	if( $this->userId==0 && $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'success';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	else
    	{   
	    	$this->validationManager->setMaxNoOfColor($this->request->get('max_selectable_color'));
	    	$this->validationManager->setProjectConfiguration($this->productDetailconfigurationRule);
	    	$this->validationManager->setRules('color', 'color','color');
	    	$this->validationManager->setRules ( 'extra_color', 'extraColor', 'extraColor' );
	    	//$this->validationManager->setRules('imprint', 'printPosition','printPosition');
	    	// $this->validationManager->setRules('fax_proof', 'faxProof','printPositionProof');
	    	// $this->validationManager->setRules('paper_proof', 'paperProof','printPositionProof');
	    	$this->validationManager->setRules('shipping_method', 'shippingMethod','shippingMethod');
	    	//$this->validationManager->setRules('special_instruction', 'required','specialInstruction');
	    	// $this->validationManager->setRules('pref_dist', 'prefDist','prefDist');
	    	
			if($this->validationManager->isValid()){
		    	$status = $this->orderManager->setAddToCart();
		    	switch ($status)
		    	{
		    		case 'ERROR_MAX_LIMIT_REACHED':
		    			$this->responseArray['error_message'] = $this->get('translator')->trans('order.max_product_order', array('%count%'=>$this->inlineViewProductMaxLimit));
		    			break;
		    		case 'ERROR_PRODUCT_ALREADY_EXISTS':
		    			$this->responseArray['error_message'] = $this->get('translator')->trans('order.product_already_exists');
		    			break;
		    		case 'SUCCESS':
		    			$this->responseArray['status'] = 'success';
		    			$this->responseArray['success_message'] = $this->get('translator')->trans('order.add_success_message');
		    			$byPass = $this->request->get('by_pass');
		    			$orderType = $this->request->get('order_type');
		    			if($orderType == 'sample') {
		    				$this->responseArray['order_type'] = 'sample';
		    				$this->responseArray['success_message'] = $this->get('translator')->trans('order.sample_order_success_message');
		    				$this->responseArray['page_url'] = $this->generateUrl('officebrain_product_bundle_product_detail',array('productSlug' => $this->request->get('product_slug')));
		    			}
		    			elseif($byPass==0){
		    				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
		    			}
		    			else{
		    				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_checkoutdetail');
		    			}
		    			break;
		    		default:
		    			$this->generateUrl('office_brain_orderbundle_order_cartlist');
		    	}
	    		$this->responseArray['total_product'] = $this->orderManager->getTotalCount();
	    	}
	    	else
	    	{
	    		$this->responseArray['status'] = 'error';
	    		$this->responseArray['error_data'] = $this->validationManager->isError();
	    		return new JsonResponse($this->responseArray); /// return validation error array
	    	}
	    	return new JsonResponse($this->responseArray);
    	}
    }


    /**
     * @author Employee Id: 4203
     * Description : Use to edit session data for order
     * @param 1 : No paramater
     * @return type : json
     * @throws Exception: Null
     *
     * @Route("/{_locale}/set-edit-product-to-cart",
     * name="office_brain_orderbundle_order_seteditproducttocart",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainOrderBundle:Order:setEditProductToCart.html.twig")
     */
    public function setEditProductToCartAction()
    {

    	$this->initAction();

    	$this->validationManager->setMaxNoOfColor($this->request->get('max_selectable_color'));
    	$this->validationManager->setProjectConfiguration($this->productDetailconfigurationRule);
    	$this->validationManager->setRules('color', 'color','color');
    	$this->validationManager->setRules ( 'extra_color', 'extraColor', 'extraColor' );
    	$this->validationManager->setRules('imprint', 'printPosition','printPosition');
    	$this->validationManager->setRules('fax_proof', 'faxProof','printPositionProof');
    	//$this->validationManager->setRules('paper_proof', 'paperProof','printPositionProof');
    	$this->validationManager->setRules('shipping_method', 'shippingMethod','shippingMethod');
    	//$this->validationManager->setRules('special_instruction', 'required','specialInstruction');
    	//$this->validationManager->setRules('pref_dist', 'prefDist','prefDist');

    	if($this->validationManager->isValid()){ //echo '<pre/>'; print_r($_POST);exit;
    		$status = $this->orderManager->setEditToCart();
    		if($status)
    		{
    				$this->responseArray['status'] = 'success';
    				$this->responseArray['success_message'] = $this->get('translator')->trans('cart_list.update_success_message');
    				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
    				$this->responseArray['total_product'] = $this->orderManager ->getTotalCount();
    		}
    	}
    	else
    	{
    		$this->responseArray['status'] = 'error';
    		$this->responseArray['error_data'] = $this->validationManager->isError();
    		return new JsonResponse($this->responseArray); /// return validation error array
    	}
    	return new JsonResponse($this->responseArray);
    }
    /**
     * @author Employee Id: 4248
     * Description : Use to render the Shipping address for Session Quote List
     * @return type : json
     * @throws Exception: Null
     *
     * @Route("/{_locale}/get-total-quantatity-by-product-id-order/{product_id}",
     * name="office_brain_requestquotebundle_requestquote_gettotalquantatiybyproductid",
     * options={"expose"=true}
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:getTotalQuantatiyByProductId.html.twig")
     */
    public function getTotalQuantatiyByProductIdAction()
    {
    	$this->initAction();
    	$productId = $this->request->get ( 'product_id' );
    	$aryRequestQuote = $this->orderManager->getCartList()[$productId]['color'];
    	$quantity = 0;
    	foreach($aryRequestQuote as $imprintDetail)
    	{
    		foreach ($imprintDetail['quantity'] as $quantityVal)
    		{
    			$quantity = $quantity + $quantityVal;
    		}
    	}
    	return array (
    			'total_quantity' => $quantity
    	);
    }

    /**
     * @author Employee Id: 4471
     * Description : use to remove file form art work
     * @param 1 : No paramater
     * @return type : Ajax response in image successfully deleted
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-remove-file-from-artwork",
     * name="office_brain_orderbundle_order_removefilefromartwork",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:removeFileFromArtWork.html.twig")
     * @Method({"POST"})
     */
    public function removeFileFromArtWorkAction()
    {
    	$this->initAction();
    	$logoId= $this->request->get('logoId');
    	$filePath= $this->request->get('filePath');
    	$fileName = substr(strrchr(rtrim($filePath, '/'), '/'), 1);
    	$removeFile=$this->imageLibraryManager->deleteFile($this->artworkFilePath ,$fileName);
    	if($removeFile == 1)
    	{
    		$this->response['status']='success';
    	}
    	else
    	{
    		$this->response['status']='error';
    	}
    	return new JsonResponse($this->response);
    }

    /**
     * @return 302 Redirection Response
     * @throws NULL
     * @Route("/{_locale}/continue-shopping-from-cart-list",
     * 	name="office_brain_orderbundle_order_continueshopping"
     * )
     *
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:continueShopping.html.twig")
     */
    public function continueShoppingAction()
    {
    	return $this->redirect($this->generateUrl('office_brain_searchbundle_search_continueshopping'));
    }

    /**
     * To get cart product list
     *
     * @Route("/{_locale}/checkout-detail",
     * 	name="office_brain_orderbundle_order_checkoutdetail"
     * )
     * @Template("OfficeBrainOrderBundle:Order:checkoutDetail.html.twig")
     */
    public function checkoutDetailAction()
    {
    	$this->initAction();
    	$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
    	if($this->responseArray['total_record']>0){
    		$this->deliveryStatus= $this->orderManager->checkProductDeliveryDate();
    		if($this->deliveryStatus['status'] == 'delay' || $this->deliveryStatus['status'] == 'is_deleted')
    		{
    			$this->responseArray['checkout_product_list'] = $this->orderManager->getCartList();
    			return $this->responseArray;
    			return $this->redirect($this->generateUrl('office_brain_orderbundle_order_cartlist'));
    		}
    		else
    		{
    			$this->responseArray['checkout_product_list'] = $this->orderManager->getCartList();
    			return $this->responseArray;
    		}
    	}else{
    		return $this->redirect($this->generateUrl('office_brain_orderbundle_order_cartlist'));
    	}
    }

    /**
     * To get cart product list
     *
     * @Route("/{_locale}/get-all-billing-address",
     * name="office_brain_orderbundle_order_getallbillingaddress",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getAllBillingAddress.html.twig")
     */
    public function getAllBillingAddressAction()
    {
    	$this->initAction();
    	$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
    	if($this->responseArray['total_record']>0){
    	$this->responseArray['billing_address'] = $this->orderManager->getAllBillingAddressBook();
	    	if ($this->request->isXmlHttpRequest()) {
	    		return $this->responseArray;
	    	}else{
	    		return $this->responseArray;
	    	}
    	}else{
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray = 'logout';
    			return new JsonResponse($this->responseArray);
    		}else{
    			return $this->redirect($this->generateUrl('office_brain_orderbundle_order_cartlist'));
    		}

    	}
    }


    /**
     * To get cart product list
     *
     * @Route("/{_locale}/get-billing-address-suggestion-form",
     * 	name="office_brain_orderbundle_order_getbillingaddresssuggestionform", options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getBillingAddressSuggestionForm.html.twig")
     */
    public function getBillingAddressSuggestionFormAction()
    {
    	$this->initAction();
    	$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
    	if($this->responseArray['total_record']>0){
    		return array();
    	}else{
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray = 'logout';
    			return new JsonResponse($this->responseArray);
    		}else{
    			return $this->redirect($this->generateUrl('office_brain_orderbundle_order_cartlist'));
    		}
    	}
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to render Billing Address from Contact book/My Address book
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/get-billing-address-order",
     * name="office_brain_orderbundle_order_getbillingaddress",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"GET"})
     */
    public function getBillingAddressAction()
    {
    	$this->initAction();
    	$this->responseArray['total_record'] = $this->orderManager->getTotalCount();
    	if($this->responseArray['total_record']>0){
    		$address = $this->orderManager->getUserBillingAddresByEmailOrName();
    		$addressRes = array();
    		foreach ($address as $key=>$aa){
    			$addressRes[$aa['id']] = array('id'=>$aa['id'],'label'=>$aa['label']);
    		}
    		return new JsonResponse($addressRes);
    	}
    	else
    	{
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
    			return new JsonResponse($this->responseArray);
    		}else{
    			return $this->redirect($this->generateUrl('office_brain_orderbundle_order_cartlist'));
    		}
    	}

    }

    /**
     * @author Employee Id: 410175
     * Description : Use to render Shipping Address By Id
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/get-order-billing-address-by-id",
     * name="office_brain_orderbundle_order_getorderbillingaddressbyid",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getOrderBillingAddressById.html.twig")
     * @Method({"GET"})
     */
    public function getOrderBillingAddressByIdAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->orderManager->getUserBillingAddresById();
    	$this->response['addressId'] = $this->request->get('contact_id',null);
    	return $this->response;
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to edit the existing shipping address
     *
     * @Route("/{_locale}/checkout-shipping-edit-address/{contactBookId}",
     * name="office_brain_orderbundle_order_editcheckoutshippingaddress",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:editCheckoutShippingAddress.html.twig")
     */
    public function editCheckoutShippingAddressAction()
    {
    	$this->initAction();
    	$contactBookId 		= $this->request->get('contactBookId');
    	$contactBookArray 	= $this->userContactBookManager->getSingleContactBook($contactBookId);
    	$contactBookForm 	= $this->createForm(new ContactBookType($this->container), $contactBookArray);

    	return array('contactBookForm'=> $contactBookForm->createView(),'contactBookId'=>$contactBookId);
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to edit the existing shipping address
     *
     * @Route("/{_locale}/checkout-billing-edit-address/{contactBookId}",
     * name="office_brain_orderbundle_order_editcheckoutbillingaddress",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:editCheckoutShippingAddress.html.twig")
     */
    public function editCheckoutBillingAddressAction()
    {
    	$this->initAction();
    	$editShippingAddress = $this->orderManager->getBillingAddressSession();
    	$this->form = $this->createForm(new GuestBillingAddressType($this->coreManager, 'edit',$editShippingAddress['address_data']));
    		$this->form->handleRequest($this->request);
    		return $this->render('OfficeBrainOrderBundle:Order:addCheckoutBillingAddressGuest.html.twig', array('contactBookForm' => $this->form->createView()));
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to add the new billing address
     *
     * @Route("/{_locale}/checkout-add-billing-address-guest",
     * name="office_brain_orderbundle_order_addcheckoutshippingaddressguest",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * 
     */
    public function addCheckoutBillingAddressGuestAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new GuestBillingAddressType($this->coreManager, 'add'));
    	$this->form->handleRequest($this->request);
    	if($this->form->isValid()) {
    		$status = $this->orderManager->setRequestOrderAddGuestBillingInSession();
    		if($status['status']=="success"){
    			unset($this->responseArray['product_id']);
    			$this->responseArray['status'] = 'success';
    			$this->responseArray['call_ajax_url_checkout_guest'] = $this->generateUrl('office_brain_orderbundle_order_guestbillingaddress',array('billing'=>'guest','counter'=>$status['counter']));

    			$this->responseArray['contact_book_id'] = $status['counter'];
    			$this->responseArray['success_message'] = $this->get('translator')->trans('order.shipping_type.address_added_successfully');
    			$this->responseArray['counter'] = $status['counter'];
    			return new JsonResponse($this->responseArray);
    		}
    	} else{
    		return new JsonResponse (  $this->commonLibraryManager->prepareFormJsonError($this->form) );
    	}
    }

    /**
     * @author Employee Id: 410175
     * Description : Use to render Shipping Address By Id
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/get-order-guest-billing",
     * name="office_brain_orderbundle_order_guestbillingaddress",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getOrderBillingAddressguest.html.twig")
     * @Method({"GET"})
     */
    public function getOrderBillingGuestAddressAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->orderManager->getBillingAddressSession();
    	$this->response['addressId'] = 0;
    	//print_r($this->response); die;
    	return $this->response;
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to add the new billing address
     *
     * @Route("/{_locale}/cheakout-add-billing-address",
     * name="office_brain_orderbundle_order_addcheckoutshippingaddress",
     * options={"expose"=true}
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:addCheckoutBillingAddress.html.twig")
     */
    public function addCheckoutBillingAddressAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		/*if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}*/

    		if($this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1)
    		{
	    		if ($this->request->isXmlHttpRequest()) {
	    			$this->responseArray['status'] = 'error';
	    			$this->responseArray['error_type'] = 'loginError';
	    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
	    			return new JsonResponse($this->responseArray);
	    		}else{
	    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
	    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
	    		}
    		}
    		$this->form = $this->createForm(new GuestBillingAddressType($this->coreManager, 'add'));
    		$this->form->handleRequest($this->request);
    		return $this->render('OfficeBrainOrderBundle:Order:addCheckoutBillingAddressGuest.html.twig', array('contactBookForm' => $this->form->createView()));

    	}
    	else
    	{
    		$contactBookObj = new ContactBook();
    		$addressObj = $this->container->get('office_brain_core_manager')->getAddressTypeObj(1);
    		
    		$contactBookObj->setAdressType($addressObj);

    		$this->form = $this->createForm(new ContactBookType($this->container), $contactBookObj);
    		$this->form->handleRequest($this->request);
    		$this->responseArray['contactBookForm'] = $this->form->createView();
    		return  $this->responseArray;
    	}
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to add the new order detail into the table
     *
     * @Route("/{_locale}/add-order-detail",
     * name="office_brain_orderbundle_order_addorderdetail",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:addOrderDetail.html.twig")
     */
    public function addOrderDetailAction()
    {
    	$this->initAction();
    	$status = $this->orderManager->addOrderDetail();
    	if( $status['status']== "success"){
    		$this->responseArray['success'] = 'success';
    		//$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_thankyou');
    		return new JsonResponse($this->responseArray);
    	}
    	else
    	{
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}

    	}
    }

 /**
     * @author Employee Id: 4203
     * @Route("/{_locale}/order-payment-list",
     * name="office_brain_orderbundle_order_paymentlist"
     * )
     * @Template("OfficeBrainOrderBundle:Order:paymentList.html.twig")
     */
    public function paymentListAction()
    {
    	$this->initAction();
    	$countryCode=explode('_',$this->locale);
    	$this->responseArray['payment'] = array();
     	if($this->userId>0){
     		if($this->user->getUserType()=="end_user" && $this->instanceType=="distributor"){ // end_user
     			//echo "here i have to add code for subshop owner id"; die;
     				$prefDistId= $this->siteOwnerId;//$this->user->getLocatedDistributorId();
     			$this->responseArray['payment']=$this->thirdPartyManager->getPaymentCountryWise($countryCode[1], $prefDistId);
     		}else{
     			if($this->user->getUserType()=="end_user"){
	     			$prefDistId= $this->user->getLocatedDistributorId();
	     			$this->responseArray['payment']=$this->thirdPartyManager->getPaymentCountryWise($countryCode[1], $prefDistId);
     			}
     		}
     	}
    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 4203
     * @Route("/{_locale}/payment-success",
     * name="office_brain_orderbundle_payment_paymentsuccess"
     * )
     * @Template("OfficeBrainOrderBundle:Order:paymentSuccess.html.twig")
     */

    public function paymentSuccessAction(){
    	$this->initAction();
    	$result = $this->orderManager->addOrderDetail();
    	/*if ($this->erpIntegration && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
    		$this->queueApiManager->mapQueue("create", $result['data']);
    	}*/
    	if(isset($_COOKIE['virtualLogofyCartSequenceId'])){
    		$response = new Response();
    		$response->headers->setCookie(new Cookie('virtualLogofyCartSequenceId', "" , time() - (10 * 365 * 24 * 60 * 60), '/', null, false, false));
    	}
    	if(array_key_exists('error',$result)){
    		return array('id'=>$result['data']->getId(),'instance_id' => $this->instanceId);
    	}else{
    		return array('id'=>$result['data']->getId(),'order_no'=>$result['data']->getOrderNo());
    	}
    	 
    }
//     public function paymentSuccessAction(){
//     	$this->initAction();
//     	$result = $this->orderManager->addOrderDetail();
//     	if ($this->erpIntegration && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
//     		$this->queueApiManager->mapQueue("create", $result['data']);
//     	}
//     	if(is_array($result)) {
// 	    	if(array_key_exists('error',$result)){
// 	    		$this->sessionManager->set($this->userId.'_order_id', $result['data']->getId());
// 	    		return array('id'=>$result['data']->getId());
// 	    	}else{
// 	    		$this->sessionManager->set($this->userId.'_order_id', $result['data']->getId());
// 	    		return array('id'=>$result['data']->getId());
// 	    	}
//     	}
//     	else if($this->sessionManager->has($this->userId.'_order_id')){
//     		return array('id'=>$this->sessionManager->get($this->userId.'_order_id'));
//     	}
//     }

    /**
     * @author Employee Id: 4203
     * @Route("/{_locale}/payment-failed",
     * name="office_brain_orderbundle_payment_paymentfailed"
     * )
     * @Template("OfficeBrainOrderBundle:Order:paymentFailed.html.twig")
     */

    public function paymentFailedAction(){
    	$this->initAction();
    	return array();
    }

    /**
     * @author Employee Id: 4532
     * Description : Use to get pms colors as per given hashkey
     * @param 1 : hashkey color code
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-pms-colors",
     * name="office_brain_orderbundle_order_pmscolor",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderPmsColors.html.twig")
     */
    public function orderPmsColorsAction()
    {
    	$this->initAction();
    	$pmsColorValue = $this->orderManager->getPMSColorInfo ();
    	$this->responseArray['counter'] = $this->request->get('counter',0);
    	$this->responseArray['count'] = $pmsColorValue['data']['count'];
    	$this->responseArray['pms_colors_value'] = $pmsColorValue['data']['pmshexcolor'];
    	$this->responseArray['status'] = $pmsColorValue['status'];

    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 4217
     * Description : Use to display order list
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-list",
     * name="office_brain_orderbundle_order_orderlist",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderList.html.twig")
     *
     */
    public function orderListAction()
    {
    	$this->initAction();
    	$this->prepareSearchParameterArray();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->prepareSearchParameterArray();
    	//$this->page = 1;
    	//$this->recordsPerPage = 1;
    	$this->responseArray['records_per_page'] = $this->recordsPerPage;
    	$this->responseArray['page'] = $this->page;
    	$this->responseArray['status'] = 'success';
    	$this->responseArray['data'] = $this->orderManager->getOrderList($this->searchParameterArray, $this->searchKeyWordsArray, $this->page, $this->recordsPerPage);

    	return $this->responseArray;
    }


    /**
     * @author Employee Id: 4217
     * Description : Use to submit guest user info form.
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/order-details/{order_id}",
     * name="office_brain_orderbundle_order_orderdetails",
     * defaults={"order_id"=null},
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderDetails.html.twig")
     *
     */
    public function orderDetailsAction()
    {	
    	$this->initAction();
    	$orderDetail = $this->orderManager->isOrderExists();
    	$this->responseArray['order'] = $orderDetail;
    	$this->responseArray['data'] = $this->orderManager->getProductList();
    	$this->responseArray['instance_type']= $this->instanceType;
    	//$data ['color_info'] = $this->orderManager->checkForAttribute($this->responseArray['data']['product_attributes']);
    	//print_r($this->responseArray); die;
    	return $this->responseArray;

    }

    /**
     * @author Employee Id: 4217
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/customer/{user_id}/{user_type}",
     * name="office_brain_orderbundle_order_customerinfo",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:customerInfo.html.twig")
     * @Method({"GET"})
     */
    public function customerInfoAction()
    {
    	$this->initAction();
    	$this->responseArray['userDetail'] = $this->orderManager->getUserDetail($this->request->get('user_id'),$this->request->get('user_type'));
    	return $this->responseArray;
    }


    /**
     * @author Employee Id: 4217
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/guest-customer/{user_id}/{user_type}",
     * name="office_brain_orderbundle_order_guestcustomerinfo",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:guestCustomerInfo.html.twig")
     * @Method({"GET"})
     */
    public function guestCustomerInfoAction()
    {
    	$this->initAction();
    	$this->responseArray['userDetail'] = $this->orderManager->getUserDetail($this->request->get('user_id'),$this->request->get('user_type'));
    	return $this->responseArray;
    }


    /**
     * @author Employee Id: 4248
     *
     * Redirect to thank-you payment page
     * @Route("/{_locale}/order/thank-you",
     * 	name="office_brain_orderbundle_order_thankyouofflinepayment",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:thankYouOfflinePayment.html.twig")
     */
    public function thankYouOfflinePaymentAction()
    {
    	return array();
    }

    /**
     * @author Employee Id: 4248
     * Description : Use to add the new shipping address
     *
     * @Route("/{_locale}/order-add-address",
     * name="office_brain_orderbundle_order_saveorderaddress",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:addContactBook.html.twig")
     */
    public function addContactBookAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		
    		if($this->projectSetting['configuration_rule']['transaction']['shopping_cart']['guest_user']['status'] != 1)
    		{
	    		if ($this->request->isXmlHttpRequest()) {
	    			$this->responseArray['status'] = 'error';
	    			$this->responseArray['error_type'] = 'loginError';
	    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
	    			return new JsonResponse($this->responseArray);
	    		}else{
	    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
	    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
	    		}
    		}
    		$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'add'));
    		$this->form->handleRequest($this->request);
    		return $this->render('OfficeBrainOrderBundle:Order:addGuestContactBook.html.twig', array('contactBookForm' => $this->form->createView()));
    	}
    	else
    	{
    		$contactBookObj = new ContactBook();
    		$addressObj = $this->container->get('office_brain_core_manager')->getAddressTypeObj(2);
    		
    		$contactBookObj->setAdressType($addressObj);
    		$this->form = $this->createForm(new ContactBookType($this->container), $contactBookObj);
    		$this->form->handleRequest($this->request);
    		$this->responseArray['contactBookForm'] = $this->form->createView();
    		return  $this->responseArray;
    	}
    }

    /**
     *
     * @author Employee Id: 4248
     * Desciption: Use to get Request Quote Product Detail
     * @Route("/{_locale}/order-add-contact-session",
     * name="office_brain_orderbundle_order_addcontactinsession",
     * options={"expose"=true}
     * )
     *
     * @Method({"POST"})
     * @Template("OfficeBrainOrderBundle:Order:orderAddGuestContactInSession.html.twig")
     *
     */
    public function orderAddGuestContactInSessionAction() {
    	$this->initAction();
    	$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'add'));
    	$this->form->handleRequest($this->request);
    	if($this->form->isValid()) {
    		$status = $this->orderManager->setRequestOrderAddGuestContactInSession();

    		if($status['status']=="success"){
    			$this->responseArray['status'] = 'success';
    			$this->responseArray['call_ajax_url'] = $this->generateUrl('office_brain_orderbundle_order_guestshippingaddress',array('product_id'=>$status['product_id'],'method'=>$status['method'],'counter'=>$status['counter']));
    			$this->responseArray['contact_book_id'] = $status['counter'];
    			$this->responseArray['success_message'] = $this->get('translator')->trans('order.shipping_type.address_added_successfully');
    			$this->responseArray['counter'] = $status['counter'];
    			return new JsonResponse($this->responseArray);
    		}
    	} else{
    		return new JsonResponse (  $this->commonLibraryManager->prepareFormJsonError($this->form) );
    	}
    }

    /**
     * @author Employee Id: 4203
     * Description : Use to edit the existing shipping address
     *
     * @Route("/{_locale}/request-order-edit-guest-address/{productId}/{counter}/{method}",
     * name="office_brain_orderbundle_editguestaddress",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:editGuestContact.html.twig")
     */
    public function editGuestContactAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		$requestData = array();
    		$productId=$requestData['productId']=$this->request->get('productId');
    		$method=$requestData['method']=$this->request->get('method');
    		$counter=$requestData['counter']=$this->request->get('counter');
    		$sessionData = $this->sessionManager->get('order_guest_shipping_address');
    		$data=$sessionData[$productId][$method][$counter];
    		$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'edit',$data));
    		$this->form->handleRequest($this->request);
    		return $this->render('OfficeBrainOrderBundle:Order:editGuestContactBook.html.twig', array('contactBookForm' => $this->form->createView(),'formData'=>$data,'requestData'=>$requestData));
    	}
    }

    /**
     * @author Employee Id: 4203
     * Description : use to display guest shipping data
     * @param 1 : productid
     * @param 2 : method
     * @param 3 : counter
     * @return type : Ajax response in view.
     * @throws Exception: Null
     * @Route("/{_locale}/order-guest-ship-address/{product_id}/{method}/{counter}",
     * name="office_brain_orderbundle_order_guestshippingaddress"
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderGuestShipping.html.twig")
     */
    public function orderGuestShippingAction()
    {
    	$this->initAction();
    	$this->responseArray = $this->orderManager->getRequestOrderGuestContactInSession();
    	$this->responseArray['edit']=0;
    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 4203
     * Description : use to edit guest shipping address
     * @param 1 : productid
     * @param 2 : method
     * @param 3 : counter
     * @return type : Ajax response in view.
     * @throws Exception: Null
     * @Route("/{_locale}/request-order-edit-guest-ship-address",
     * name="office_brain_orderbundle_editguestrequestorderaddress"
     * )
     * @Template("OfficeBrainOrderBundle:Order:requestOrderEditGuestShipping.html.twig")
     */
    public function requestOrderEditGuestShippingAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'add'));
    	$this->form->handleRequest($this->request);
    	if ($this->form->isValid()) {
    		$status = $this->requestQuoteManager->setRequestOrderAddGuestContactInSession();
    		if($status['status']=="success"){
    			$this->responseArray['status'] = 'success';
    			$this->responseArray['call_ajax_url'] = $this->generateUrl('office_brain_orderbundle_order_guestshippingaddress',array('product_id'=>$status['product_id'],'method'=>$status['method'],'counter'=>$status['counter']));
    			$this->responseArray['contact_book_id'] = $status['counter'];
    			$this->responseArray['success_message'] = $this->get('translator')->trans('order.shipping_type.address_added_successfully');
    			$this->responseArray['counter'] = $status['counter'];
    			return new JsonResponse($this->responseArray);
    		}
    	}else{
    		return new JsonResponse (  $this->commonLibraryManager->prepareFormJsonError($this->form) );
    	}
    }

    /**
     * @author Employee Id: 4532
     * Description : Use to render view to edit imprint location box.
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/edit-imprint-location-order",
     * name="office_brain_orderbundle_order_editimprintlocation",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:editImprintLocation.html.twig")
     * @Method({"POST","GET"})
     */
    public function editImprintLocationAction()
    {
    	$this->initAction();
    	$data = array();
    	$data['imprintLocation'] = $this->orderManager->addImprintLocation();
    	$data['confiSetting'] = $this->productDetailconfigurationRule;
    	$data['imprint_info'] = $this->request->get('imprint_info', null);
    	//$data['request_quote_session'] = $this->requestQuoteManager->getInputDataForEdit();
    	
    	$standardImprintColor = $this->orderManager->getStandardImprintColorInformation($this->request->get('product_id', null));

    	$data['standard_imprint_color'] = $standardImprintColor;
    	$chargeList = $this->container->getParameter('run_charge_list');
		if($chargeList!=NULL){
			$chargeList = array_keys($chargeList);
		}
		
		if(count($data['imprintLocation']['imprint_information']['imprint_method_information']))
		{

			foreach($data['imprintLocation']['imprint_information']['imprint_method_information'] as $imprint=>$imprintData){
				$no_of_colors=0;
				if(count($imprintData['charges'])>0){
					foreach($imprintData['charges'] as $charge=>$chargeData){
						if(in_array($charge,$chargeList)){
							$no_of_colors++;
						}
					}
				}else{
						$no_of_colors=1;
				}
				$data['imprintLocation']['imprint_information']['imprint_method_information'][$imprint]['maximum_selectable_color'] =$no_of_colors;	
			}	
		}
    	//print_r($data); die;
    	return $data;
    }

    /**
     * @author Employee Id: 4532
     * Description : Use to render view to edit imprint location box.
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/edit-imprint-location-start-imprint-method",
     * name="office_brain_orderbundle_order_editimprintlocation_start_imprint_method",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:editImprintLocationStartImprintMethod.html.twig")
     * @Method({"POST","GET"})
     */
    public function editImprintLocationStartImprintMethodAction()
    {
    	$this->initAction();
    	$data = array();
    	$data['imprintLocation'] = $this->orderManager->addPreImprintLocation();
    	$data['confiSetting'] = $this->productDetailconfigurationRule;
    	$data['imprint_info'] = $this->request->get('imprint_info', null);
    	//$data['request_quote_session'] = $this->requestQuoteManager->getInputDataForEdit();
    	
    	$standardImprintColor = $this->orderManager->getStandardImprintColorInformation($this->request->get('product_id', null));
    	$data['standard_imprint_color'] = $standardImprintColor;
    	
    	return $data;
    }


    /**
     * @author Employee Id: 4532
     *
     * Description : Select Method for edit imprint information
     *
     * @param 1 : No paramater
     *
     * @return type : Form view and data.
     *
     * @throws Exception: Null
     *
     * @Route("/{_locale}/select-method-edit-order",
     * name="office_brain_orderbundle_order_editselectMethod",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:editSelectMethod.html.twig")
     * @Method({"POST","GET"})
     */
    public function editSelectMethodAction()
    {
    	$this->initAction();
    	$data = array();
    	$data['selectImprintMethod'] = $this->orderManager->editSelectImprintMethod();
    	$data['imprint_info'] = $this->request->get('imprint_info',null);
    	//echo '<pre>'; print_r($data); die;
    	return $data;
    }

    /**
     * @author Employee Id: 4532
     *
     * Description : Use to show the list of product in this request quote for edit part.
     *
     * @param 1 : No paramater
     *
     * @return type : json
     *
     * @throws Exception: Null
     *
     * @Route("/{_locale}/edit-select-color-order",
     * name="office_brain_orderbundle_order_editselectColor",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:editSelectColor.html.twig")
     * @Method({"POST","GET"})
     */
    public function editSelectColorAction()
    {
    	$this->initAction();
    	$standardImprintColor = $this->orderManager->getStandardImprintColorInformation();
    	$pmsColor = $this->container->getParameter('pms_color');
    	$selectColorArray = array(
    			'color_no'=>$this->request->get('color_no'),
    			'imprint_id'=>$this->request->get('imprint_id'),
    			'product_id'=>$this->request->get('product_id'),
    			'standard_imprint_color'=> $standardImprintColor,
//     			'pms_color'=>$pmsColor,
    			'imprint_info'=>$this->request->get('imprint_info'),
    			'is_pms_color_allow' => $this->request->get ( 'is_pms_color_allow' )
    	);
    	
    	$data ['product_detail']=$this->orderManager->getProductDetailById($this->request->get('product_id'));
    	if(isset($data ['product_detail']) && !empty($data ['product_detail'])) {
    		$imprintMethodId = $this->getFirstImprintMethodId($data,$this->request->get('imprint_id'));
    		if(isset($imprintMethodId) && $imprintMethodId!='') {
    			if($data ['product_detail']['imprint_information']['imprint_method_information'][$imprintMethodId]['is_pms_color_allow'] == 1) {
    				$selectColorArray['pms_color'] = $pmsColor;
    			}
    		}
    	}
    	
    	return $selectColorArray;
    }

    /**
     * @author Employee Id: 4532
     * Description : Use to render Shipping by Type (Statndard/Split), for Edit shipping method
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/select-shipping-type-order",
     * name="office_brain_orderbundle_order_editSelectShippingType",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:editStandardShipping.html.twig")
     * @Method({"POST","GET"})
     */
	public function editSelectShippingTypeAction()
	{
	
		$this->initAction();
	
		$data = $this->orderManager->getShippingType();
		$data['shipping_detail_info'] = $this->request->get('shipping_detail_info');
		$data['shipping_estimator'] = 'no';
		$productId = $this->request->get('product_id');
		$data['product_id']=$productId;
		$productDetail= $this->orderManager->getProductDetailById($productId);
		/*if(array_key_exists('shipping_information', $productDetail))
		{
			if(array_key_exists('free_on_board', $productDetail['shipping_information']))
			{
				$data['shipping_estimator'] = 'yes';
			}
		}*/
		$data ['color_info'] = $this->orderManager->checkForAttribute($data['product_attributes']);
		$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
		if ($shipdetail == true) {
			$data ['shipping_estimator'] = 'yes';
		}
		
		if(!$this->getUser())
		{
			$data['cart_item_address_guest'] = $this->request->get('cart_item_adress');
		}
		//$data ['request_quote_session'] = $this->requestQuoteManager->getInputDataForEdit();
	
		//return $this->render("OfficeBrainOrderBundle:Order:editStandardShipping.html.twig" , $data);
		return $data;
	}


    /**
     * @author Employee Id: 4248
     * Description : Use to render Shipping Address By Id
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/get-checkout-shipping-address-by-id",
     * name="office_brain_orderbundle_order_getcheckoutshippingaddressbyid",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:getCheckoutShippingAddressById.html.twig")
     * @Method({"GET"})
     */
    public function getCheckoutShippingAddressByIdAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->orderManager->getUserShippingAddresById();
    	$this->response['addressId'] = $this->request->get('contact_id',null);
    	return $this->response;
    }
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    /**
     * @author Employee Id: 4203
     * Description : Use to edit the existing shipping address
     *
     * @Route("/{_locale}/order-quote-edit-mode-guest-address/{productId}/{counter}/{method}",
     * name="office_brain_orderbundle_editmodeguestaddress",
     * )
     * @Method({"GET"})
     * @Template("OfficeBrainOrderBundle:Order:editModeGuestContactBook.html.twig")
     */
    public function editModeGuestContactAction()
    {
    	$this->initAction();
    	$requestData = array();
    	$productId=$requestData['productId']=$this->request->get('productId');
    	$method=$requestData['method']=$this->request->get('method');
    	$counter=$requestData['counter']=$this->request->get('counter');
    	$inputData = $this->sessionManager->get('request_quotes');
    	$sessionData = $inputData[$productId]['guest_shipping_detail'];
    	$data=$sessionData[$productId][$method][$counter];
    	$this->form = $this->createForm(new OrderAddGuestShippingType($this->coreManager, 'edit',$data));
    	$this->form->handleRequest($this->request);
    	return array('contactBookForm' => $this->form->createView(),'formData'=>$data,'requestData'=>$requestData);
    }

    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit order form.
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-guest-user-order",
     *  name="office_brain_orderbundle_order_addgguestuser"
     * )
     *
     * @Template("OfficeBrainOrderBundle:Order:addGuestUser.html.twig")
     *
     * @Method({"GET"})
     *
     */
    public function addGuestUserAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new GuestUserType());
    	return array('form'=>$this->form->createView());
    }

    /**
     *
     * @author Employee Id: 4203
     * Desciption: Use to submit guest user info form.
     * @param NULL
     * @return Html Response
     * @throws NULL
     * @Route("/{_locale}/add-guest-user-order",
     *  name="office_brain_orderbundle_order_processaddgguestusersubmit"
     * )
     * @Template("OfficeBrainOrderBundle:Order:processAddGuestUser.html.twig")
     * @Method({"POST"})
     *
     */
    public function processAddGuestUserAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new GuestUserType());
    	$this->form->handleRequest($this->request);
    	if ($this->form->isValid()){
    		$user = $this->userManager->addGuestUser($this->form);
    		$this->orderManager->addShippingBillingForGuest($user['data']);
    		$result = $this->requestQuoteManager->addRequestQuoteSession($user['data']->getId());
    	}
    	else if ($this->request->isXmlHttpRequest ()) {
    		return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
    	}
    }

    /**
     * To get cart product list
     *
     * @Route("/{_locale}/checkout-detail-guest",
     * 	name="office_brain_orderbundle_order_checkoutdetailguest"
     * )
     * @Template("OfficeBrainOrderBundle:Order:checkoutDetailGuest.html.twig")
     */
    public function checkoutDetailGuestAction()
    {   
    	$this->initAction();
    	if ($this->request->isXmlHttpRequest()) {
    		$this->responseArray['status'] = 'success';
    		$this->responseArray['popup_url'] = $this->generateUrl('office_brain_userbundle_login_login_popup',array('refer_url'=>'office_brain_orderbundle_order_addgguestuser'));
    		return new JsonResponse($this->responseArray);
    	}
    }



    /**
     * @author Employee Id: 4471
     * Description : display order inline status.
     * @param 1 : No paramater
     * @return type : Form view and edit data.
     * @throws Exception: Null
     *
     * @Route("{_locale}/order-email/{order_id}",
     * name="office_brain_orderbundle_order_orderemail",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderEmail.html.twig")
     * @Method({"GET"})
     */
    public function orderEmailAction()
    {
    	$this->initAction();
    	$xmlFilePath = $this->request->getScheme().'://'.$this->request->getHost().$this->request->getBasePath();
    	$orderDetail = $this->orderManager->isOrderExists();
    	$xmlFileName = $this->orderManager->generateXMLOfOrder();
    	$this->responseArray['order'] = $orderDetail;
    	$this->responseArray['data'] = $this->orderManager->getProductList();
    	$this->responseArray['instance_type']= $this->instanceType;
    	$this->responseArray['xml_file_path'] = $xmlFilePath.'/order_xml/'.$xmlFileName;
    	$this->responseArray['sizeAllowed']= 1;
    	$data['confi'] = $this->configurationRule['order_tax'];
    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 4471
     * Description : display order inline status.
     * @param 1 : No paramater
     * @return type : Form view and edit data.
     * @throws Exception: Null
     *
     * @Route("{_locale}/track-order",
     * name="office_brain_orderbundle_order_ordertrack",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderTrackShipping.html.twig")
     * @Method({"GET"})
     */
    public function orderTrackShippingAction()
    {
    	$this->initAction();
    	$orderId=$this->request->get('orderId', null);
    	$this->responseArray['orderId'] = $orderId;
    	$this->responseArray['data'] = $this->orderManager->getOrderDetailById();
    	$this->responseArray['orderInlineProductDetail'] = $this->orderManager->getProductList();
       	return $this->responseArray;
    }

    /**
     * @author Employee Id: 4471
     * Description : display order inline tracking in detail.
     * @param 1 : No paramater
     * @return type : Form view and edit data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/track-order-detail",
     * name="office_brain_orderbundle_order_ordertrackingdetail",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:orderTrackingShippingDetail.html.twig")
     * @Method({"POST"})
     */

    public function orderTrackingShippingDetailAction()
    {
    	$this->initAction();
    	$this->shippingId =$this->request->get('shippingId', null);
    	$inLineShippingDetail = $this->orderManager->getOrderLineShippingDetailAdmin($this->shippingId);
    	$this->responseArray['data']=$inLineShippingDetail;
    	$this->responseArray['shippingDetail'] = Null;
    	$this->status = $inLineShippingDetail->getStatusCode();
    	$this->shippingType= $inLineShippingDetail->getShippingTypeAdmin();
    	//echo $inLineShippingDetail->getTrackingId();
    	if($this->status=='shipping' || $this->status=='delivery')
    	{

    		if($this->shippingType == 'fedex')
    		{
    			$this->shippinEstiConfi = $this->projectSetting['configuration_rule']['transaction']['shipping_estimator']['option']['registered_user']['option']['fedex']['option']['fedex_shipment']['option'];
    			$shippingDetail =  $this->fedexShippingEstimatorManager->callRequest($inLineShippingDetail->getTrackingId(),$this->shippinEstiConfi,'shippingDetail');
    			if($shippingDetail->TrackDetails->Notification->Severity=='SUCCESS')
    			{
    				$this->responseArray['trackingResult']= 'SUCCESS';
    				$this->responseArray['shippingDetail']=$shippingDetail;
    				if($shippingDetail->TrackDetails->Events[0]->EventType=='DL' && $this->status!='delivery')
    				{
    					$statuschange=$this->orderManager->changeOrderLineStatusAdmin($this->shippingId,'3','delivery','','');
    				}
    			}
    			//echo "<pre>";print_r($this->responseArray['shippingDetail']);exit();
    		}
    		else if ($this->shippingType == 'ups')
    		{
    			$this->shippinEstiConfi = $this->projectSetting['configuration_rule']['transaction']['shipping_estimator']['option']['registered_user']['option']['ups']['option']['ups_track']['option'];
    			$this->responseArray['trackingResult']= 'SUCCESS';
    			$this->responseArray['shippingDetail'] = $this->upsShippingEstimatorManager->callRequest($inLineShippingDetail->getTrackingId(),$this->shippinEstiConfi,'shippingDetail');
    			//echo "<pre>";print_r($this->responseArray['shippingDetail']);exit();
    		}
    	}
    	//exit();
    	return $this->responseArray;
    }


    /**
     * @author Employee Id: 4203
     * Description : update the preferred distributor via ajax.
     * @param 1 : No paramater
     * @return type : view html.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/pref-dist",
     * name="office_brain_orderbundle_order_updateselectpreferreddistributor",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:updateSelectPreferredDistributor.html.twig")
     * @Method({"POST"})
     */
    public function updateSelectPreferredDistributorAction()
    {
    	$this->initAction();
    	$this->responseArray=array();
    	if($this->userId>0){
    	$this->responseArray['success']=$this->userManager->updateLocateDistributor($this->userManager->getUserById($this->userId), $this->request->get('dist_id'));
    	}
    	return new JsonResponse($this->responseArray);
    }
    
    /**
     *
     * @author Employee Id: 4248
     *         Description : Use to edit the existing shipping address
     *
     *         @Route("/{_locale}/order-edit-address/{contactBookId}",
     *         name="office_brain_orderbundle_editorderaddress",
     *         )
     *         @Method({"GET"})
     *         @Template("OfficeBrainOrderBundle:Order:editContactBook.html.twig")
     */
    public function editContactBookAction() {
    	$this->initAction ();
    	$contactBookId = $this->request->get ( 'contactBookId' );
    	$contactBookArray = $this->userContactBookManager->getSingleContactBook ( $contactBookId );
    	$this->form = $this->createForm ( new ContactBookType ( $this->container ), $contactBookArray );
    	$this->form->handleRequest ( $this->request );
    	return array (
    			'contactBookForm' => $this->form->createView (),
    			'contactBookId' => $contactBookId
    	);
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to remove shipping and render twig
     * @param 1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/remove-shipping-by-counter-order",
     * name="office_brain_orderbundle_order_removeShippingByCounter",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:removeShippingByCounter.html.twig")
     * @Method({"POST","GET"})
     */
    public function removeShippingByCounterAction()
    {    
    	$this->initAction();
    	
    	$data = $this->orderManager->removeShippingCounterById();
    	$data['shipping_estimator'] = 'no';
    	
    	$productId     = $data['data'][0]['product_id'];
    	$productDetail = $this->orderManager->getProductDetailById($productId);
    	
    	/*
    	 if(array_key_exists('shipping_information', $productDetail))
    	 {
	    	 if(array_key_exists('free_on_board', $productDetail['shipping_information']))
	    	 {
	    	 	$data['shipping_estimator'] = 'yes';
	    	 }
    	 } */
    	
    	$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
    	
    	if ($shipdetail == true) 
    	{
    		$data ['shipping_estimator'] = 'yes';
    	}
    	$data['userId'] = $this->userId;
    	
    	return $data;    	
    }

    /**
     * @author Employee Id: 5083
     * Description : Use to display search address list
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/popaddress-search",
     * name="office_brain_orderbundle_order_popupaddresssrearch",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:popupaddresslist.html.twig")
     *
     */
    public function popupAddressSearchListAction()
    {
    	$this->initAction();
    	$this->option=trim($_POST['option']);
    	$this->keywords=trim($_POST['keywords']);
    	$this->addressType=trim($_POST['shipping_type']);
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->responseArray['records_per_page'] = $this->recordsPerPage;
    	$this->responseArray['page'] = $this->page;
    	$this->responseArray['status'] = 'success';
    	$this->responseArray['data'] = $this->userContactBookManager->getPopAddressList($this->userId,$this->option, $this->keywords, $this->page, $this->recordsPerPage,$this->addressType);
    	$this->responseArray['ob_project_setting'] = $this->projectSetting;
    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 5083
     * Description : Use to display company search address list
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/popaddress-company-search",
     * name="office_brain_orderbundle_order_popupaddresscompanylist",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainOrderBundle:Order:popupaddresslist.html.twig")
     *
     */
    public function popupAddressCompanyListAction()
    {
    	$this->initAction();
    	$this->keywords=trim($_POST['keywords']); 
    	$this->addressType=trim($_POST['shipping_type']);
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->responseArray['records_per_page'] = $this->recordsPerPage;
    	$this->responseArray['page'] = $this->page;
    	$this->responseArray['status'] = 'success';
    	$this->responseArray['company']='yes';
    	$this->responseArray['data'] = $this->userContactBookManager->getPopCompanyAddressList($this->userId,$this->keywords, $this->page, $this->recordsPerPage,$this->addressType);
    	$this->responseArray['ob_project_setting'] = $this->projectSetting;
    	return $this->responseArray;
    }

    /**
     * @author Employee Id: 5265
     * Description : Use to order list
     * @param 1 : No paramater
     * @return type : json data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/reorder",
     * name="office_brain_orderbundle_order_reorder",
     * options={"expose"=true}
     * )
     * @Template()
     *
     */

    public function reOrderAction(){
    	
    	$this->initAction();

    	$orderId = $this->request->get('order_id', null);
		$orderDetail = $this->orderManager->isOrderExists($orderId);
		$orderitemLine = $orderDetail->getOrderItemLine();
		$this->responseArray = $this->orderManager->reOrderCheck($orderitemLine,$this->get('translator'));

		if($this->responseArray['status'] == 'SUCCESS'){
			$this->responseArray['status'] = 'success';
			$this->responseArray['success_message'] = $this->get('translator')->trans('order.add_success_message');
	    	$byPass = $this->configurationRule['checkout_bypass']['status'];//$this->request->get('by_pass');
			if($byPass==0){
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
			}else{
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_checkoutdetail');
			}
		}else if($this->responseArray['status'] == 'error'){
			$this->responseArray['status'] = 'error';
			$this->responseArray['order_id'] = $orderId;
			if(array_key_exists('inputProductArray', $this->responseArray))
				$this->responseArray['inputProductArray'] = base64_encode(serialize($this->responseArray['inputProductArray']));
		}
		return new JsonResponse($this->responseArray);
    }

    /**
     * @author Employee Id: 5265
     * Description : Use to order list
     * @param 1 : No paramater
     * @return type : json data.
     * @throws Exception: Null
     *
     * @Route("/{_locale}/placereorder",
     * name="office_brain_orderbundle_order_placereorder",
     * options={"expose"=true}
     * )
     * @Template()
     *
     */

    public function placereOrderAction(){
    	$this->initAction();
    	$orderId = $this->request->get('order_id', null);
    	$inputProductArray = $this->request->get('inputProductArray', null);
    	$this->responseArray = $this->orderManager->processReOrder(unserialize(base64_decode($inputProductArray)),$orderId);

		if($this->responseArray['status'] == 'SUCCESS'){
			$this->responseArray['status'] = 'success';
			$this->responseArray['success_message'] = $this->get('translator')->trans('order.add_success_message');
	    	$byPass = $this->configurationRule['checkout_bypass']['status'];//$this->request->get('by_pass');
			if($byPass==0){
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_cartlist');
			}else{
				$this->responseArray['page_url'] = $this->generateUrl('office_brain_orderbundle_order_checkoutdetail');
			}
		}
		return new JsonResponse($this->responseArray);
    }
    
    /**
     * @author Employee Id: 4248
     * Description : Use to add the new billing address
     *
     * @Route("/{_locale}/cheakout-add-guest-info",
     * name="office_brain_orderbundle_order_addguestinfo",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainOrderBundle:Order:addGuestInfo.html.twig")
     */
    public function addGuestInfoAction()
    {
    	$this->initAction();
    	
    	$this->form = $this->createForm(new GuestInfoType());
    	$this->form->handleRequest($this->request);
    	
    	$sessGuestInfo = array();
    	if($this->sessionManager->has('cart-list'))
    	{
    		$arrCartListData = $this->sessionManager->get('cart-list');
    		$sessGuestInfo = $arrCartListData['guest_user_info'];
    	}
    	
    	if($this->form->isValid()) 
    	{
    		$status = $this->orderManager->setGuestInfoInSession($this->form->getData());
    		
    		$responseArray['status'] = 'success';
    		$responseArray['guest_form_save'] = 1;
    		$responseArray['success_message'] = $this->get('translator')->trans('order.shipping_type.address_added_successfully');
    		
    		return new JsonResponse($responseArray);
    	} 
    	else 
    	{
    		if($this->request->isXmlHttpRequest()) 
    		{
    			return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
    		}
    	}
    	
    	return $this->render('OfficeBrainOrderBundle:Order:addGuestInfo.html.twig', array('guestInfoForm' => $this->form->createView(), 'sessGuestInfo' => $sessGuestInfo));
    }
    


    /**
     *
     * @author Employee Id: 4532
     *         Description : use to render Select Logo Block if user is not login
     * @param
     *        	1 : No paramater
     * @return type : Ajax response in view.
     * @throws Exception: Null
     *
     *         @Route("/{_locale}/order-select-logo-block-guestuser",
     *         name="office_brain_orderbundle_order_selectlogoblock_guestuser",
     *         options={"expose"=true}
     *         )
     *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:selectLogoBlockGuestUser.html.twig")
     *         @Method({"GET","POST"})
     */
    public function selectLogoBlockGuestUserAction() {
    	$this->initAction ();
    	if ($this->request->isXmlHttpRequest ()) {
    		// Commented code is to redirect the guest user at login page, when guest user upload a logo from request quote page
    		/*
    		* if( $this->userId==0){ $this->responseArray['status'] = 'error'; $this->responseArray['error_type'] = 'loginError'; $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login'); return new JsonResponse($this->responseArray); }
    		*/
    		$this->response ['logo_id'] = $this->request->get ( 'productsku' );
			$this->response ['callFrom'] = $this->request->get ( 'productName' );
    		$requestQuoteUploadLogo = $this->get ( 'session' )->get ( 'request_quotes_upload_logo' );
    		return $this->response;
    	}
    }
}
