<?php

namespace OfficeBrain\Bundle\RequestQuoteBundle\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 OfficeBrain\Bundle\RequestQuoteBundle\Form\RequestQuoteCommentType;
use OfficeBrain\Bundle\RequestQuoteBundle\Entity\RequestQuoteComment;
use OfficeBrain\Bundle\UserBundle\Form\ContactBookType;
use OfficeBrain\Bundle\UserBundle\Entity\ContactBook;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use OfficeBrain\Bundle\RequestQuoteBundle\Form\UploadArtWorkDetailType as UploadArtWorkDetailType;
use OfficeBrain\Bundle\RequestQuoteBundle\Form\RequestQuoteAddGuestShippingType;
use OfficeBrain\Bundle\RequestQuoteBundle\Form\RequestQuoteGuestUserType;

/**
 *
 * @author Employee Id: 4203
 *         OB eCommerce Product -Request Quote
 *         - List All the Request Quote Inquiry
 *         - Add New Request Quote Inquiry
 *
 * @Route("", defaults={"rule_service"="rule_charges"})
 */
class RequestQuoteController 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->userManager = null;
		$this->responseArray = array ();
		$this->projectSetting = null;
		$this->productCultureIdArray = null;
		$this->productSlug = null;
		$this->productDetailManager = null;
		$this->form = null;
		$this->commonLibraryManager = null;
		$this->erpIntegration = null;
		$this->queueApiManager = null;
		$this->paginationManager = null;
		$this->arrayToPaginationManager = null;
		$this->emailManager = null;
		$this->splitAddressArr = array ();
		$this->page = null;
		$this->recordsPerPage = 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->responseArray );
		unset ( $this->totalProduct );
		unset ( $this->entityManager );
		unset ( $this->productIdArray );
		unset ( $this->sessionManager );
		unset ( $this->projectSetting );
		unset ( $this->productCultureIdArray );
		unset ( $this->productSlug );
		unset ( $this->productDetailManager );
		unset ( $this->form );
		unset ( $this->commonLibraryManager );
		unset ( $this->erpIntegration );
		unset ( $this->queueApiManager );
		unset ( $this->paginationManager );
		unset ( $this->arrayToPaginationManager );
		unset ( $this->emailManager );
		unset ( $this->userManager );
		unset($this->page);
		unset($this->recordsPerPage);
		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->userId = $this->projectSetting ['user_id'];
		$this->responseArray ['product_id'] = $this->productId;
		$this->responseArray ['status'] = 'error';
		$this->configurationRule = $this->projectSetting ['configuration_rule'] ['transaction'] ['request_quote'];
		// $this->shippingSectionconfigurationRule = $this->projectSetting['configuration_rule']['transaction']['request_quote']['shipping_section'];
		// $this->imprintSectionconfigurationRule = $this->projectSetting['configuration_rule']['transaction']['request_quote']['imprint_section'];
		$this->productDetailconfigurationRule = $this->projectSetting ['configuration_rule'] ['transaction'] ['request_quote'] ['product_detail_popup'];
		$this->inlineViewProductMaxLimit = $this->configurationRule ['inline_view'] ['option'] ['no_of_product'];
		$this->requestQuoteManager = $this->get ( 'office_brain_request_quote_manager' );
		$this->coreManager = $this->get ( 'office_brain_core_manager' );
		$this->validationManager = $this->get ( 'office_brain_validation_manager' );
		$this->categoryApiManager = $this->get("officebrain_category_api_manager");
		$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->artworkFileURL = $this->container->getParameter ( 'artwork.file_url' );
		$this->artworkFilePath = $this->container->getParameter ( 'artwork.file_path' );
		$this->artworkTempFileURL = $this->container->getParameter ( 'artwork.temp_file_url' );
		$this->artworkTempFilePath = $this->container->getParameter ( 'artwork.temp_file_path' );
		$this->mediaFileURL = $this->container->getParameter ( 'cms.media_file_url' );
		$this->mediaFilePath = $this->container->getParameter ( 'cms.media_file_path' );
		$this->colorImageUrl = $this->container->getParameter ( 'api.color_image_base_url' );
		$this->userContactBookManager = $this->get ( 'office_brain_user_contact_book_manager' );
		$this->userManager = $this->get ( 'office_brain_user_manager' );
		$this->commonLibraryManager = $this->get ( 'office_brain_common_library' );
		$this->erpIntegration = $this->projectSetting ['configuration_rule'] ['erp_integration'];
		if ($this->has ( 'office_brain_queue_api_manager' )) {
			$this->request->attributes->set ( 'object', 'RequestQuote' );
			$this->queueApiManager = $this->get ( 'office_brain_queue_api_manager' );
		}
		$this->paginationManager = $this->get ( 'knp_paginator' );
		$this->arrayToPaginationManager = $this->get ( 'office_brain_array_to_pagination_manager' );
		$this->emailManager = $this->get ( 'office_brain_email_service' );
		$this->userManager = $this->get ( 'office_brain_user_manager' );
		$this->shippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_fedex');
		$this->page = $this->request->get('page', '1');
		$this->recordsPerPage = $this->request->get('records_per_page', $this->configurationRule['list_front']['option']['no_of_product']);
		$this->locale=$this->request->get('_locale');
		$this->freeFreightAllowCategoryList = $this->getParameter('free_freight_allow_category_list');
        $this->twigManager = $this->get('twig');
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load quote tab content via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/load-request-quote/{product_slug}",
	 *         name="office_brain_requestquotebundle_requestquote_loadquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:loadQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function loadQuoteAction() {
		$this->initAction ();
		return $this->requestQuoteManager->getProductDetailBySlug ( $this->productSlug, $this->locale );
	}
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load quote sizzing modal via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/size-chart-mode",
	 *         name="office_brain_requestquotebundle_requestquote_sizechartmode",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:sizeChartMode.html.twig")
	 *         @Method({"GET"})
	 */
	public function sizeChartModeAction() {
		$this->initAction ();
		return array ();
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load quote sizzing modal via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/imprint-chart",
	 *         name="office_brain_requestquotebundle_requestquote_imprintchart",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:imprintChart.html.twig")
	 *         @Method({"GET"})
	 */
	public function imprintChartAction() {
		$this->initAction ();
		return array ();
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load quote sizzing modal via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/embrodidery-chart",
	 *         name="office_brain_requestquotebundle_requestquote_embrodiderychart",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:embrodideryChart.html.twig")
	 *         @Method({"GET"})
	 */
	public function embrodideryChartAction() {
		$this->initAction ();
		return array ();
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load request quote tab content via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/load-quote/{product_slug}",
	 *         name="office_brain_requestquotebundle_requestquote_loadrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:loadRequestQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function loadRequestQuoteAction() {
		$this->initAction ();
		$data = $this->requestQuoteManager->getProductDetailBySlug ( $this->productSlug, $this->locale );
		$data ['product_detail'] = $data; 
		$data['color_info'] = $this->requestQuoteManager->checkForAttribute($data['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->requestQuoteManager->mergeAttributeArray($data['color_info'],$data['attributes']);
		}
		// this is Comment for a Distributor is display without any  selected State
		//$data ['all_distributor'] = $distributor = $this->userManager->getDistributors ();
		$data ['all_states'] = $distributor = $this->coreManager->getLocateDistributorStateDataAPI ();
		
		$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_imprint_location_id'] = $firstImprintLocationId;
		$data['first_imprint_method_id'] = $firstImprintMethodId;
		$data['first_imprint_method_name'] = $firstImprintMethodName;
		$data['first_maximum_selectable_color'] = $firstMaximumSelectableColor;
		
		$data['load_request_quote']['zero_controller']['html'] = $this->twigManager->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:loadRequestQuote.html.twig', $data);
		
		// 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 ( 'OfficeBrainRequestQuoteBundle:RequestQuote:addImprintLocation.html.twig', $data['second_controller']);
		

		// render the controller of third ajax
		$standardImprintColor = $this->requestQuoteManager->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 ( 'OfficeBrainRequestQuoteBundle:RequestQuote: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 ( 'OfficeBrainRequestQuoteBundle:RequestQuote:selectColor.html.twig', $data['fourth_controller']);
		/*echo "<pre>";
		print_r($data);exit;*/
		
		return new JsonResponse($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: 410175
	 *         Description : Use to render Color Wise Qty
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/get-color-wise-quantity-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_getProductAttribute",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function getProductAttributeAction() {
		$this->initAction ();
		$productAttributes = $this->requestQuoteManager->getSizeAttributeByColor ( $this->colorImageUrl );
		$shiType = $this->request->get ( 'shipping_type', null );
		if ($shiType != '') {
			$ShippingQtyBox = $this->requestQuoteManager->getBlankColorQuantityValue ( $productAttributes );
			$html = $this->get ( 'twig' )->render ( "OfficeBrainRequestQuoteBundle:RequestQuote:loadShippingQuantityBox.html.twig", $ShippingQtyBox );
			return new JsonResponse ( array (
					'data' => $productAttributes,
					'status' => 'success',
					'shipping_qty_box' => $html
			) );
		}
		return new JsonResponse ( array (
				'data' => $productAttributes,
				'status' => 'success'
		) );
	}

	/**
	 *
	 * @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}/select-shipping-type-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_selectShippingType",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function selectShippingTypeAction() {
		$this->initAction ();
		$data = $this->requestQuoteManager->getShippingType ();
		$data ['shipping_estimator'] = 'no';
		$productId = $this->request->get ( 'product_id' );
		$data ['edit'] = $this->request->get ( 'edit' );
// 		$productDetail = $this->requestQuoteManager->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->requestQuoteManager->checkForAttribute($data['product_attributes']);
		$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
		if ($shipdetail == true) {
			$data ['shipping_estimator'] = 'yes';
		}
		$data ['userId'] = $this->userId;
		
		return $this->render ( "OfficeBrainRequestQuoteBundle:RequestQuote:standardShipping.html.twig", $data );
	}

	/**
	 *
	 * @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-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_editSelectShippingType",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST","GET"})
	 */
	public function editSelectShippingTypeAction() {
		$this->initAction ();
		$data = $this->requestQuoteManager->getShippingType ();
		$data ['shipping_detail_info'] = $this->request->get ( 'shipping_detail_info' );
		$data ['shipping_estimator'] = 'no';
		$productId = $this->request->get ( 'product_id' );
// 		$productDetail = $this->requestQuoteManager->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->requestQuoteManager->checkForAttribute($data['product_attributes']);
		$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
		if ($shipdetail == true) {
			$data ['shipping_estimator'] = 'yes';
		}
		// $data ['request_quote_session'] = $this->requestQuoteManager->getInputDataForEdit();
		return $this->render ( "OfficeBrainRequestQuoteBundle:RequestQuote:editStandardShipping.html.twig", $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}/get-billing-address-by-user-id",
	 *         name="office_brain_requestquotebundle_requestquote_getBillingAddressByUserId",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"GET"})
	 */
	public function getBillingAddressByUserIdAction() {
		$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 {
			$addressRes = $this->requestQuoteManager->getUserBillingAddresByUserId($this->userId);
			if($addressRes!=NULL){
				$this->responseArray ['success'] = 'success';

				$contactBookId = $addressRes['id'];
		    	$contactBookArray = $this->userContactBookManager->getSingleContactBook ( $contactBookId );
		    	$this->form = $this->createForm ( new ContactBookType ( $this->container ), $contactBookArray );
		    	$this->form->handleRequest ( $this->request );

				$this->responseArray ['data']['billing_html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:editContactBookBillingCheckout.html.twig', array (
		    			'contactBookForm' => $this->form->createView (),
		    			'contactBookId' => $contactBookId
		    	));

				$this->responseArray ['data']['email'] = $addressRes['email'];
			}else{
				$this->responseArray ['error_type'] = 'Notfound';
				$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_userbundle_contactbook_viewcontactbook' );
				
			}
			return new JsonResponse ( $this->responseArray );
		}
	}


	/**
	 *
	 * @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}/get-shipping-address-by-email",
	 *         name="office_brain_requestquotebundle_requestquote_getShippingAddressByemail",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"GET"})
	 */
	public function getShippingAddressByEmailAction() {
		$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 {
			$addressRes = $this->requestQuoteManager->getUserShippingAddresByEmail($this->userId);
			if($addressRes!=NULL){
				$this->responseArray ['success'] = 'success';

				$contactBookId = $addressRes['id'];
		    	$contactBookArray = $this->userContactBookManager->getSingleContactBook ( $contactBookId );
		    	$this->form = $this->createForm ( new ContactBookType ( $this->container ), $contactBookArray );
		    	$this->form->handleRequest ( $this->request );

				$this->responseArray ['data']['shipping_html'] = $this->twigManager->render ( 'OfficeBrainOrderBundle:Order:editContactBookCheckout.html.twig', array (
		    			'contactBookForm' => $this->form->createView (),
		    			'contactBookId' => $contactBookId
		    	));

				$this->responseArray ['data']['email'] = $addressRes['email'];
			}else{
				$this->responseArray ['error_type'] = 'Notfound';
				$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_userbundle_contactbook_viewcontactbook' );
				
			}
			return new JsonResponse ( $this->responseArray );
		}
	}


	/**
	 *
	 * @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}/get-shipping-address-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_getShippingAddress",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @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->requestQuoteManager->getUserShippingAddresByEmailOrName ();
			$addressRes = array ();
			foreach ( $Address as $key => $aa ) {
				// $addressRes[$aa['id']] = $aa['id'].'##'.$aa['label'];
				$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}/get-shipping-address-by-id-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_getshippingaddressbyid",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getShippingAddressById.html.twig")
	 *         @Method({"GET"})
	 */
	public function getShippingAddressByIdAction() {
		$this->initAction ();
		$this->response ['result'] = $this->requestQuoteManager->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}/request-quote-get-shipping-address-by-id-summary",
	 * name="office_brain_requestquotebundle_requestquote_getshippingaddressbyidsummary"
	 * )
	 * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getShippingAddressByIdSummary.html.twig")
	 */
	public function getShippingAddressByIdSummaryAction()
	{
		$this->initAction();
		$this->response['result'] = $this->requestQuoteManager->getUserShippingAddresById();
		$this->response['addressId'] = $this->request->get('contact_id',null);
		$this->response ['ob_project_setting'] = $this->projectSetting;
		return $this->response;
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render view to add attribute quantity box.
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/add-product-attribute",
	 *         name="office_brain_requestquotebundle_requestquote_addProductAttribute",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addProductAttribute.html.twig")
	 *         @Method({"POST"})
	 */
	public function addProductAttributeAction() {
		$this->initAction ();
		return $addProductAttributes = $this->requestQuoteManager->addAttributes ();
	}

	/**
	 * Need to remove below action *
	 */
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render view to add attribute quantity box.
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/edit-product-attribute",
	 *         name="office_brain_requestquotebundle_requestquote_editProductAttribute",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:editProductAttribute.html.twig")
	 *         @Method({"POST"})
	 */
	public function editProductAttributeAction() {
		$this->initAction ();
		return $addProductAttributes = $this->requestQuoteManager->addAttributes ();
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         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}/add-imprint-location-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_addimprintlocation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addImprintLocation.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function addImprintLocationAction() {
		$this->initAction ();
		$data = array ();
		$data ['imprintLocation'] = $this->requestQuoteManager->addImprintLocation ();
		$data ['confiSetting'] = $this->productDetailconfigurationRule;
		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-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_editimprintlocation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:editImprintLocation.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editImprintLocationAction() {
		$this->initAction ();
		$data = array ();
		$data ['imprintLocation'] = $this->requestQuoteManager->addImprintLocation ();
		$data ['confiSetting'] = $this->productDetailconfigurationRule;
		$data ['imprint_info'] = $this->request->get ( 'imprint_info', null );

		// $data['request_quote_session'] = $this->requestQuoteManager->getInputDataForEdit();
		
		$standardImprintColor = $this->requestQuoteManager->getStandardImprintColorInformation($this->request->get('product_id', null));
		$data['standard_imprint_color'] = $standardImprintColor;
		
		return $data;
	}

	/**
	 *
	 * @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}/select-logo-block",
	 *         name="office_brain_requestquotebundle_requestquote_selectlogoblock",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:selectLogoBlock.html.twig")
	 *         @Method({"GET","POST"})
	 */
	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',9 );
			$this->response ['logo_id'] = $this->request->get ( 'productsku' );
			$this->response ['callFrom'] = $this->request->get ( 'productName' );
			$this->response ['record_set'] = $this->imageLibraryManager->getMediaLibraryRecordsWithPagination ( null, $page, $recordPerPage );
			return $this->response;
		}
	}

	/**
	 *
	 * @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}/select-logo-block-guestuser",
	 *         name="office_brain_requestquotebundle_requestquote_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;
		}
	}

	/**
	 *
	 * @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}/upload-artwork-from-gallery",
	 *         name="office_brain_requestquotebundle_requestquote_uploadartworkfromgallery",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @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 ( 'request_quote.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}/upload-new-artwork",
	 *         name="office_brain_requestquotebundle_requestquote_uploadnewartwork",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function uploadNewArtWorkAction() {
		$this->initAction ();
		$addtoDb = 'no';
		// $this->responseArray = $_FILES['uploadNewImage'];
		$this->name = $this->imageLibraryManager->uploadMediaFileToFolder ( $_FILES, $this->artworkFilePath, $addtoDb );
		$this->responseArray = $this->artworkFileURL . '/' . $this->name [0];
		return new JsonResponse ( $this->responseArray );
	}

	/**
	 *
	 * @author Employee Id: 4532
	 *         Description : use to upload image for without login
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in image uploaded from system
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/upload-new-artwork-guest-user",
	 *         name="office_brain_requestquotebundle_requestquote_uploadnewartwork_guestuser",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function uploadNewArtWorkGuestUserAction() {
		$this->initAction ();
		$addtoDb = 'no';
		// $this->responseArray = $_FILES['uploadNewImage'];
		$this->name = $this->imageLibraryManager->uploadMediaFileToFolder ( $_FILES, $this->artworkFilePath, $addtoDb );
		$this->responseArray = $this->artworkFileURL . '/' . $this->name [0];
		// $sessionLogoName = $this->requestQuoteManager->setUploadLogoToSession($this->name[0]);
		return new JsonResponse ( $this->responseArray );
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *         Description : add image name and cutomer name to image
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/upload-artwork-detail",
	 *         name="office_brain_requestquotebundle_requestquote_uploadartworkdetail",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:uploadArtWorkDetail.html.twig")
	 *         @Method({"POST"})
	 */
	public function uploadArtWorkDetailAction() {
		$this->initAction ();
		
		foreach($_FILES as $findex => $file)
		{
			if(isset($_FILES[$findex]['name']))
			{
				$_FILES[$findex]['name'] = str_replace(' ','-',$_FILES[$findex]['name']);
			}
		}
		$file = $_FILES ['uploadNewImage'];
		$addtoDb = 'no';
		$this->filename = $this->imageLibraryManager->uploadMediaFileToFolder ( $_FILES, $this->artworkTempFilePath, $addtoDb );
		$this->fileType = $this->imageLibraryManager->checkUploadedMediaType ( $file );
		$this->form = $this->createForm ( new UploadArtWorkDetailType ( $this->filename [0], $this->fileType ) );
		$this->responseArray ['form'] = $this->form->createView ();
		$this->responseArray ['logoId'] = $this->request->get ( 'logoId' );
		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *         Description : add image name and cutomer name to image submit
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/upload-artwork-detail-submit",
	 *         name="office_brain_requestquotebundle_requestquote_uploadartworkdetail_submit",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function submitUploadArtWorkDetailAction() {
		$this->initAction ();
		$this->formDetail = $this->request->get ( 'uploadartworkdetail' );
		$this->filename = $this->formDetail ['file_name'];
		$this->filename = str_replace(' ','-',$this->filename);
		$this->fileType = $this->formDetail ['file_type'];
		$this->logoId = $this->request->get ( 'logoId' );
		$this->form = $this->createForm ( new UploadArtWorkDetailType ( $this->filename, $this->fileType ) );
		$this->form->handleRequest ( $this->request );

		if ($this->form->isValid ()) {
			$this->imageName = $this->form ['image_name']->getData ();
			$this->customerName = $this->form ['customer_name']->getData ();

			$uploadedMediaInfo = array (
					'name' => $this->filename,
					'type' => $this->fileType,
					'image_name' => $this->imageName,
					'customer_name' => $this->customerName
			);
			$this->imageLibraryManager->setMedia ( $uploadedMediaInfo ); // add file to image library (add to database)
			$response = $this->imageLibraryManager->copyMedia ( $this->artworkTempFilePath, $this->mediaFilePath, $this->filename, $this->filename ); // copy image to media library
			$this->name = $this->imageLibraryManager->copyMedia ( $this->artworkTempFilePath, $this->artworkFilePath, $this->filename, $this->filename ); // copy image to artwork library
			$this->imageLibraryManager->deleteFile ( $this->artworkTempFilePath, $this->filename ); // delete file from tmp folder
			$this->responseArray ['artwork'] = 'done';
			$this->responseArray ['logoId'] = $this->logoId;
			$this->responseArray ['fileDetail'] = $this->artworkFileURL . '/' . $this->filename; // get image path from artwork
			$this->responseArray ['status'] = 'success';
		} else {
			$this->responseArray = $this->commonLibraryManager->prepareFormJsonError ( $this->form );
		}

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

	/**
	 *
	 * @author Employee Id: 4471
	 *         Description : use to remove file form art work
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in image succ essfully deleted
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/remove-file-from-artwork",
	 *         name="office_brain_requestquotebundle_requestquote_removefilefromartwork",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @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 );
		// $this->requestQuoteManager->imageRemovedFromSession($fileName);
		if ($removeFile == 1) {
			$this->response ['status'] = 'success';
		} else {
			$this->response ['status'] = 'error';
		}
		return new JsonResponse ( $this->response );
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render imprint location in summary box.
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in json.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/add-imprint-location-summary-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_addimprintlocationsummary",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function addImprintLocationSummaryAction() {
		$this->initAction ();
		$addImprintLocation = $this->requestQuoteManager->addImprintLocation ();
		$this->responseArray ['status'] = 'success';
		$this->responseArray ['data'] = $addImprintLocation;
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 5069
	 *
	 * Desciption: Use to submit guest user info form.
	 *
	 * @param NULL
	 *
	 * @return Html Response
	 *
	 * @throws NULL
	 *
	 * @Route("/{_locale}/my-inquiries-list-request-quote",
	 *  name="office_brain_requestinfobundle_requestquote_myinquiryrequestquotelist",
	 *  options={"expose"=true}
	 * )
	 *
	 * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:myInquiryRequestQuoteList.html.twig")
	 *
	 * @Method({"GET"})
	 *
	 */
	public function myInquiryRequestQuoteListAction()
	{
		$this->initAction();
		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['page'] = $this->page;
		$this->responseArray['records_per_page'] = $this->recordsPerPage;
		$this->responseArray['data'] = $this->requestQuoteManager->getRequestQuoteList($this->page,$this->recordsPerPage);
		$this->responseArray['total'] = $this->requestQuoteManager->getTotalCountUserWiseAdmin();
	
		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 *         Description : Use to submit guest user quote form.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/select-method",
	 *         name="office_brain_requestquotebundle_requestquote_selectMethod",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:selectMethod.html.twig")
	 *         @Method({"POST"})
	 */
	public function selectMethodAction() {
		$this->initAction ();
		return $selectImprintMethod = $this->requestQuoteManager->selectImprintMethod ();
	}

	/**
	 *
	 * @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",
	 *         name="office_brain_requestquotebundle_requestquote_editselectMethod",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:editSelectMethod.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editSelectMethodAction() {
		$this->initAction ();
		$data = array ();
		$data ['selectImprintMethod'] = $this->requestQuoteManager->editSelectImprintMethod ();
		$data ['imprint_info'] = $this->request->get ( 'imprint_info', null );
		// echo '<pre>'; print_r($data); die;
		return $data;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 *         Description : Use to submit guest user quote form.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/list-quote-quote",
	 *         name="office_brain_requestquotebundle_requestquote_listrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:listRequestQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function listRequestQuoteAction() {
		$this->initAction ();
		$response = array ();
		$this->responseArray['page'] = $this->page;
		$this->responseArray['records_per_page'] = $this->recordsPerPage;
		$requestQuote = $this->requestQuoteManager->getRequestQuoteList($this->page,$this->recordsPerPage);
		$total = $this->requestQuoteManager->getTotalCountUserWiseAdmin();
		return $response = array (
				'data' => $requestQuote,
				'total' => $requestQuote->getTotalItemCount()
		);
	}

	
	/**
	 *
	 * @author Employee Id: 4471
	 *
	 *         Description : Use to dalete a record
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/delete-request-quote/{request_quote_id}",
	 *         name="office_brain_requestquotebundle_requestquote_deleterequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"GET"})
	 */
	public function deleteRequestQuoteAction() {
		$this->initAction ();
		$this->request = $this->getRequest ();
		$requestQuoteDetail = $this->requestQuoteManager->deleteRequestQuoteDetailById ();
		switch ($requestQuoteDetail ['status']) {
			case 'ERROR_NOT_FOUND' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.no_record' );
				break;
			case 'SUCCESS' :
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['inquiry_list'] = 'inquiry_quote';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );
				break;
		}
		return new JsonResponse ( $this->responseArray );
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *
	 *         Description : Use to submit guest user info form.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/detail-request-quote/{request_quote_id}",
	 *         name="office_brain_requestquotebundle_requestquote_detailrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:detailRequestQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function detailRequestQuoteAction() {
		$this->initAction ();
		$requestQuoteDetail = $this->requestQuoteManager->getRequestQuoteDetailById ();
		return array (
				'data' => $requestQuoteDetail
		);
	}

	/**
	 *
	 * @author Employee Id: 410175
	 *
	 *         Desciption: Use to get Product Detail By id
	 *
	 * @param
	 *        	product_id
	 *
	 * @return Html Response
	 *
	 * @throws NULL @Route("/{_locale}/product-detail-byid/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_productdetailbyid"
	 *         )
	 *
	 *         @Method({"GET"})
	 *
	 */
	public function productDetailByIdAction() {
		$this->initAction ();
		$productId = $this->request->get ( 'product_id' );
		$this->responseArray['product_detail'] = $this->requestQuoteManager->getProductDetailById ($productId);
		return new JsonResponse ( $this->responseArray ['product_detail'] );
	}

	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render Commemt Request quote form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Form view.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/add-comment-request-quote/{request_id}/{user_id}",
	 *         name="office_brain_requestquotebundle_requestquote_addcommentrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addCommentRequestQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function addCommentRequestQuoteAction() {
		$this->initAction ();

		$userDetail = $this->get ( 'office_brain_request_info_manager' )->getUserDetail ( $this->request->get ( 'user_id' ), 'user' );
		$this->form = $this->createForm ( new RequestQuoteCommentType (), new RequestQuoteComment () );
		return array (
				'form' => $this->form->createView (),
				'request_id' => $this->request->get ( 'request_id' ),
				'user_name' => $userDetail->getFirstName () . ' ' . $userDetail->getLastName ()
		);
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *
	 *         Description : Use to submit Commemt Request quote form.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/add-comment-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_processcommnentrequestquotesubmit",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addCommentRequestQuote.html.twig")
	 *         @Method({"POST"})
	 */
	public function addCommentRequestQuoteSubmitAction() {
		$this->initAction ();
		$data = array ();
		$this->request = $this->getRequest ();
		$this->form = $this->createForm ( new RequestQuoteCommentType (), new RequestQuoteComment () );
		$this->form->handleRequest ( $this->request );

		if ('POST' === $this->request->getMethod ()) {
			$requestId = $this->form->getData ()->requestQuoteId;

			if ($this->form->isValid ()) {
				$result = $this->requestQuoteManager->setCommentRequestQuote ( $this->form->getData () );

				switch ($result ['status']) {
					case 'COMMENT_ADDED_SUCESSFULLY' :
						$this->responseArray ['url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_listcommentrequestquote', array (
								'request_quote_id' => $requestId
						) );
						$this->responseArray ['status'] = 'success';
						$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.comment_added_successfully' );
						return new JsonResponse ( $this->responseArray );
						break;
				}
			} else if ($this->request->isXmlHttpRequest ()) {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError($this->form) );
			}
		}
		return array (
				'form' => $this->form->createView (),
				'request_id' => $requestId
		);
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *
	 *         Description : Use to submit Commemt Request quote form.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : Form view and data.
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/list-comment-request-quote/{request_quote_id}",
	 *         name="office_brain_requestquotebundle_requestquote_listcommentrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:listCommentRequestQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function listCommentRequestQuoteAction() {
		$this->initAction ();
		$requestQuoteDetail = $this->requestQuoteManager->getCommentRequestQuoteList ();
		return array (
				'data' => $requestQuoteDetail
		);
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 *         Description : Use to show the list of product in this request quote.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : json
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/request-quote-select-color",
	 *         name="office_brain_requestquotebundle_requestquote_selectColor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:selectColor.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function selectColorAction() {
		$this->initAction ();
		$standardImprintColor = $this->requestQuoteManager->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->requestQuoteManager->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 show the list of product in this request quote for edit part.
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : json
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/request-quote-edit-select-color",
	 *         name="office_brain_requestquotebundle_requestquote_editselectColor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:editSelectColor.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editSelectColorAction() {
		$this->initAction ();
		$standardImprintColor = $this->requestQuoteManager->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->requestQuoteManager->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 set session data for Request Quote
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : json
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/set-request-quote-session",
	 *         name="office_brain_requestquotebundle_requestquote_setrequestquotesession",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST","GET"})
	 */
	public function setRequestQuoteSessionAction() {
		$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 ()) {
			if ($this->userId == 0 && $this->request->get ( 'by_pass' ) == 1) {
				$this->responseArray ['guest_user'] = 1;
			} 
			$status = $this->requestQuoteManager->setAddToRequestQuote ();

			switch ($status) {
				case 'ERROR_MAX_LIMIT_REACHED' :
					$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.max_product_request_quote', array (
							'%count%' => $this->inlineViewProductMaxLimit
					) );
					break;
				case 'ERROR_PRODUCT_ALREADY_EXISTS' :
					$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.product_already_exists' );
					break;
				case 'SUCCESS' :
					$this->responseArray ['status'] = 'success';
					$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.add_success_message' );
					$byPass = $this->request->get ( 'by_pass' );
					if ($byPass == 0) {
						$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_requestquotelist' );
					} else {
						// Temp Change - Need to discuss with yogesh bhai, How to open popup
						$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_saverequestquotesession' );
					}
					break;
			}

			$this->responseArray ['total_product'] = $this->requestQuoteManager->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 the session data for Request Quote
	 *
	 * @param
	 *        	1 : No paramater
	 *
	 * @return type : json
	 *
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/edit-request-quote-session",
	 *         name="office_brain_requestquotebundle_requestquote_editrequestquotesession",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 */
	public function editRequestQuoteSessionAction() {
		$this->initAction ();
		$color = $this->request->get ( 'color' );

		$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->requestQuoteManager->setEditToRequestQuote ();
			if ($status) {
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.add_success_message' );
				$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_requestquotelist' );
				$this->responseArray ['total_product'] = $this->requestQuoteManager->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 );
	}

	/**
	 * To get recent request quote product list
	 *
	 * @Route("/{_locale}/recent-request-quote-list",
	 * name="office_brain_requestquotebundle_requestquote_recentrequestquotelist",
	 * options={"expose"=true}
	 * )
	 *
	 * @Method({"GET"})
	 * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:recentRequestQuoteList.html.twig")
	 */
	public function recentRequestQuoteListAction() {
		$this->initAction ();
		$this->responseArray ['total_record'] = $this->requestQuoteManager->getTotalCount ();
		$this->responseArray ['record_set'] = $this->requestQuoteManager->getMaxNoOfQuote ( $this->inlineViewProductMaxLimit );
		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 *         Desciption: This function allow user to delete product from his/her request quote list.
	 *
	 * @param
	 *        	integer productId
	 * @param
	 *        	integer cultureProductId
	 *
	 * @return Json Response
	 *
	 * @throws NULL @Route("/{_locale}/request-quote-list-delete",
	 *         name="office_brain_requestquotebundle_requestquote_deleteajaxrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *
	 *         @Method({"POST"})
	 *
	 *         @Template()
	 *
	 */
	public function deleteAjaxRequestQuoteAction() {
		$this->initAction ();
		if ($this->productId && $this->productCultureId) {
			$status = $this->requestQuoteManager->deleteQuoteList ( $this->productId, $this->productCultureId );
			switch ($status) {
				case 'ERROR_NOT_FOUND' :
					$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.product_not_found' );
					break;
				case 'SUCCESS' :
					$this->responseArray ['status'] = 'success';
					$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );

					$this->refererUrl = $this->commonLibraryManager->getRefererRouteName ();
					break;
			}
		}
		if ($this->refererUrl == 'office_brain_requestquotebundle_requestquote_requestquotelist') {
			$this->sessionManager->set ( 'request_quote_success_deleted', $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' ) );
			$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_requestquotelist' );
		} else {
			$this->responseArray ['total_record'] = $this->requestQuoteManager->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}/request-quote-list-delete-all",
	 *         name="office_brain_requestquotebundle_requestquote_deleteallrequestquote",
	 *         options={"expose"=true}
	 *         )
	 *
	 *         @Method({"POST"})
	 *
	 *         @Template()
	 *
	 */
	public function deleteAllRequestQuoteAction() {
		$this->initAction ();
		$status = $this->requestQuoteManager->deleteAllQuoteList ();
		switch ($status) {
			case 'ERROR_NOT_FOUND' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.product_not_found' );
				break;
			case 'SUCCESS' :
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );
				$this->refererUrl = $this->commonLibraryManager->getRefererRouteName ();
				break;
		}

		if ($this->refererUrl == 'office_brain_requestquotebundle_requestquote_requestquotelist') {
			$this->sessionManager->set ( 'request_quote_success_deleted', $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' ) );
			$this->responseArray ['total_record'] = $this->requestQuoteManager->getTotalCount ();
			$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_requestquotelist' );
		} else {
			$this->responseArray ['total_record'] = $this->requestQuoteManager->getTotalCount ();
		}

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

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to get session data for Request Quote
	 *
	 *         @Route("/{_locale}/list-request-quote-list",
	 *         name="office_brain_requestquotebundle_requestquote_requestquotelist",
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:listRequestQuoteSession.html.twig")
	 */
	public function listRequestQuoteSessionAction() {
		$this->initAction ();
		$this->responseArray ['total_record'] = $this->requestQuoteManager->getTotalCount ();
		$this->responseArray ['shopping_cart_list'] = $this->requestQuoteManager->getRequestQuoteListData ();
		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to save session data of Request Quote
	 *
	 *         @Route("/{_locale}/add-request-quote-session",
	 *         name="office_brain_requestquotebundle_saverequestquotesession",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET","POST"})
	 */
	public function saveRequestQuoteSessionAction() {
		$this->initAction ();
		$result = $this->requestQuoteManager->addRequestQuoteSession ( $this->userId );
		if ($result ['status'] == 'success') {
			$requestQuoteObj = $result ['data'];
			if (is_array ( $this->erpIntegration ) && $this->erpIntegration ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				if ($requestQuoteObj->getGuestId () == 0) {
					$this->queueApiManager->mapQueue ( "create", $requestQuoteObj );
				}
			}
			// if($status=='SUCCESS')
			// {
			$this->responseArray ['status'] = 'success';
			if ($this->request->isXmlHttpRequest ()) {
				$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' );
				return new JsonResponse ( $this->responseArray );
			} else {
				return $this->redirect ( $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' ) );
			}
			// }
		} else if ($result ['status'] == 'error' && $result ['error'] == 'billing_address_missing') {
			$this->responseArray ['status'] = 'error';
			$this->responseArray ['msg'] = $this->get ( 'translator' )->trans ( 'request_quote.billing_address_error' );
			return new JsonResponse ( $this->responseArray );
		} else if ($result ['status'] == 'loginError') {
			// Temp Change - Need to discuss with yogesh bhai, How to open popup in this case
			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_requestquotebundle_requestquote_addgguestuser'));
				$this->responseArray ['popup_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_addgguestuser' );
				return new JsonResponse ( $this->responseArray );
			}
		}
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *         Desciption: request quote thank you page
	 * @param
	 *        	NULL
	 * @return Html Response
	 * @throws NULL @Route("/{_locale}/request-quote-thank-you",
	 *         name="office_brain_requestquotebundle_requestquote_thankyoupage"
	 *         )
	 *
	 *         @Method({"GET"})
	 *
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:thankYouRequestQuote.html.twig")
	 *
	 */
	public function thankYouRequestQuoteAction() {
		$this->initAction ();
		$this->requestQuoteManager->setContinueProdDetailURL ( $this->commonLibraryManager->getRefererRouteName (), $this->commonLibraryManager->getRefererUrl () );
		return array ();
	}

	/**
	 *
	 * @author Employee Id: 4471
	 *
	 *         Desciption: This function allow user go back to page from where he/she came to Request quote.
	 *
	 * @param
	 *        	NULL
	 *
	 * @return Html Response
	 *
	 * @throws NULL @Route("/{_locale}/continue-request-quote-from-product-detail",
	 *         name="office_brain_requestquotebundle_requestquote_continue_request_quote"
	 *         )
	 *
	 *         @Method({"GET"})
	 *
	 */
	public function continueRequestQuoteAction() {
		$this->initAction ();
		return $this->redirect ( $this->requestQuoteManager->getContinueProdDetailURL () );
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to add the new shipping address
	 *
	 *         @Route("/{_locale}/request-quote-add-address",
	 *         name="office_brain_requestquotebundle_saverequestquoteaddress",
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addContactBook.html.twig")
	 */
	public function addContactBookAction() {
		$this->initAction ();
		if ($this->userId == 0) {
			// Commented code is to redirect the guest user at login page, when guest user click on add new user link from request quote page
			/*
			 * 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{ return $this->redirect($this->generateUrl('office_brain_userbundle_login_login')); }
			 */
			$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'add' ) );
			$this->form->handleRequest ( $this->request );
			return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:addGuestContactBook.html.twig', array (
					'contactBookForm' => $this->form->createView ()
			) );
		} else {
			$this->form = $this->createForm ( new ContactBookType ( $this->container ), new ContactBook () );
			$this->form->handleRequest ( $this->request );
			$this->responseArray ['contactBookForm'] = $this->form->createView ();
			return $this->responseArray;
		}
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to edit the existing shipping address
	 *
	 *         @Route("/{_locale}/request-quote-edit-address/{contactBookId}",
	 *         name="office_brain_requestquotebundle_editrequestquoteaddress",
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote: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: 4248
	 *         Desciption: Use to get Request Quote Product Detail
	 *
	 *         @Route("/{_locale}/request-quote-product-view-byid/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_requestquoteproductdetailview"
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:requestQuoteProductDetailViews.html.twig")
	 *
	 */
	public function requestQuoteProductDetailViewsAction() {
		$this->initAction ();
		$productId = $this->request->get ( 'product_id' );
		$this->responseArray ['product_detail'] = $this->requestQuoteManager->getProductDetailById ( $productId );
		$this->responseArray ['request_quote'] = $this->requestQuoteManager->getSessionRequestQuoteList ();
		return array (
				'productDetail' => $this->responseArray ['product_detail'],
				'requestQuote' => $this->responseArray ['request_quote'] [$productId]
		);
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Desciption: Use to get Request Quote Product Detail
	 *         @Route("/{_locale}/request-quote-product-edit-byid/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_requestquoteproductedit"
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:requestQuoteProductEdit.html.twig")
	 *
	 */
	public function requestQuoteProductEditAction() {
		$this->initAction ();
		if ($this->requestQuoteManager->getTotalCount () == 0) {
			return $this->redirect ( $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_requestquotelist' ) );
		}
		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);
		$productDetail = $this->requestQuoteManager->getProductDataForEdit ();
		$editSession = $this->requestQuoteManager->getInputDataForEdit ();
		$this->responseArray ['product_detail'] = $productDetail;
		$this->responseArray ['edit'] = 1;
		$this->responseArray ['request_quote_session'] = $editSession [$productDetail ['product_id']];
		$categoryAndSubCategoryList = array();
		$categoryAndSubCategoryList = $this->categoryApiManager->getParentChildCategoryList($categoryAndSubCategoryData,$productDetail['category'],$activeCulture);
		 $existValue = 0;
		 
		 $this->responseArray['color_info'] = $this->requestQuoteManager->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->requestQuoteManager->mergeAttributeArray($this->responseArray['color_info'],$productDetail['attributes']);
		} 
		 
		 
        /*foreach($this->freeFreightAllowCategoryList as $key => $value){ 
         	if(array_key_exists($value,$categoryAndSubCategoryList['parent_id'])){ 
         		$existValue = 1;
         		break;
         	}else{
         		if(count($categoryAndSubCategoryList['parent_id'][$value]['child'])>0){
         			if(array_key_exists($value,$categoryAndSubCategoryList[$value]['child'])){
		   				$existValue = 1;
		   				break;
		    		}
         		}
         	}	
         }*/	
         $this->responseArray['dispalyText'] = $existValue;
		
		//$this->responseArray ['size_allow'] = $this->requestQuoteManager->checkSizeAllow ( $productDetail ['category'] );
		
		if($productDetail['is_size']==1){
			$this->responseArray ['size_allow'] = true;
		}else{
			$this->responseArray ['size_allow'] = false;
		}
		
		$this->responseArray ['all_distributor'] = $distributor = $this->userManager->getDistributors ();
		$this->responseArray ['all_states'] = $distributor = $this->coreManager->getLocateDistributorStateDataAPI ();

		return $this->responseArray;
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to unset session data for Request Quote
	 * @return type : json
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/unset-request-quote-session",
	 *         name="office_brain_requestquotebundle_unsetrequestquotesession",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 */
	public function unsetRequestQuoteSessionAction() {
		$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' );
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );
				return new JsonResponse ( $this->responseArray );
		}
		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-shipping-ddress-detail-by-id/{address_id}",
	 *         name="office_brain_requestquotebundle_getshippingaddressdetailbyid",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getShippingAddressDetailById.html.twig")
	 *
	 */
	public function getShippingAddressDetailByIdAction() {
		$this->initAction ();
		$address = $this->requestQuoteManager->getShippingAddressDetailById ();
		return array (
				'address' => $address
		);
	}

	/**
	 *
	 * @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/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_gettotalquantatiybyproductid",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getTotalQuantatiyByProductId.html.twig")
	 */
	public function getTotalQuantatiyByProductIdAction($productId = "") {
		$this->initAction ();
		$quantity = $this->requestQuoteManager->getTotalQuantatiyByProductId ();
		return array (
				'total_quantity' => $quantity
		);
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to render the All Charges Detail
	 * @return type : json
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/get-all-charges/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_getallcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getAllChargesById.html.twig")
	 */
	public function getAllChargesByIdAction() {
		$this->initAction ();
		$this->responseArray ['product_detail'] = $this->requestQuoteManager->getProductDetailById ( $this->request->get ( 'product_id' ) );
		return array (
				'chargesArr' => $this->requestQuoteManager->getAllChargesById (),
				'productDetail' => $this->responseArray ['product_detail']
		);
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to render the Total Charges
	 * @return type : json
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/get-total-charges/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_gettotalcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getTotalChargesById.html.twig")
	 */
	public function getTotalChargesByIdAction() {
		return $this->getAllChargesByIdAction ();
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to render the Shipping address wise price box
	 * @return type : json
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/get-product-box-by-address/{product_id}",
	 *         name="office_brain_requestquotebundle_requestquote_getproductboxbyaddress",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getProductBoxByAddress.html.twig")
	 */
	public function getProductBoxByAddressAction() {
		$this->initAction ();
		$productId = $this->request->get ( 'product_id' );
		$productInfo = $this->requestQuoteProductDetailViewsAction ();
		$productInfo ['attributeArray'] = $this->getColorAndSizeArrayAction ( $productId );
		return $productInfo;
	}
	public function getColorAndSizeArrayAction($productId) {
		$colorSizeArr = array ();
		$productDetail = $this->requestQuoteManager->getProductDetailById ( $productId )['attributes'];
		foreach ( $productDetail as $productInfo ) {
			$colorSizeArr [$productInfo ['label']] = $productInfo ['values'];
		}
		return $colorSizeArr;
	}

	/**
	 *
	 * @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}/request-quote-size-header/{product_id}/{edit}",
	 *         name="office_brain_requestquotebundle_getproductheadingattribute"
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:getProductHeadingAttribute.html.twig")
	 */
	public function getProductHeadingAttributeAction() {
		$this->initAction ();
		$this->responseArray ['productCatgory'] = $this->projectSetting ['configuration_rule'] ['transaction'] ['request_quote'] ['product_detail_popup'] ['option'] ['product_category'];
		$this->responseArray ['size'] = $this->requestQuoteManager->getSizeAttributeHeader();
		$this->responseArray ['edit'] = $this->request->get ( 'edit' );
		return $this->responseArray;
	}

	/**
	 *
	 * @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}/request-quote-pms-colors",
	 *         name="office_brain_requestquotebundle_requestquote_pmscolor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:requestQuotePmsColors.html.twig")
	 */
	public function requestQuotePmsColorsAction() {
		$this->initAction ();
		$pmsColorValue = $this->requestQuoteManager->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: 4273
	 *         Description : Reflact charges based on selection of attribute on product detail page
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in json.
	 * @throws Exception: Null
	 *
	 *         @Route("/{_locale}/get-applied-charges-for-product",
	 *         name="office_brain_requestquotebundle_requestquote_getappliedchargesforproduct",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST","GET"})
	 */
	public function getAppliedChargesForProductAction() {
		//$this->initAction ();
		$requestQuoteManager = $this->get('office_brain_request_quote_manager');
		$productId = $this->getRequest()->get('product_id', null );
		$responseArray ['product_id'] = $productId;
		$responseArray ['status'] = 'success';
		$responseArray ['data_charges'] = $requestQuoteManager->getAllChargesForDetailPage ();
		$responseArray ['product_total_prices'] = $requestQuoteManager->getTotalPriceChargesForDetailPage ( $responseArray ['data_charges'] );
		return new JsonResponse ( $responseArray ); 
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Desciption: Use to get Request Quote Product Detail
	 *         @Route("/{_locale}/request-quote-add-contact-session",
	 *         name="office_brain_requestquotebundle_requestquote_addcontactinsession",
	 *         options={"expose"=true}
	 *         )
	 *
	 *         @Method({"POST"})
	 *         @Template()
	 *
	 */
	public function requestQuoteAddGuestContactInSessionAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'add' ) );
		$this->form->handleRequest ( $this->request );
		if ($this->form->isValid ()) {
			$status = $this->requestQuoteManager->setRequestQuoteAddGuestContactInSession ();
			if ($status ['status'] == "success") {
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['call_ajax_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_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 ( 'request_quote.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 display guest shipping data
	 * @param
	 *        	1 : productid
	 * @param
	 *        	2 : method
	 * @param
	 *        	3 : counter
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/request-quote-guest-ship-address/{product_id}/{method}/{counter}",
	 *         name="office_brain_requestquotebundle_requestquote_guestshippingaddress"
	 *         )
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:requestQuoteGuestShipping.html.twig")
	 */
	public function requestQuoteGuestShippingAction() {
		$this->initAction ();
		$this->responseArray = $this->requestQuoteManager->getRequestQuoteGuestContactInSession ();
		$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-quote-edit-guest-ship-address",
	 *         name="office_brain_requestquotebundle_editguestrequestquoteaddress"
	 *         )
	 *         @Template()
	 */
	public function requestQuoteEditGuestShippingAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'add' ) );
		$this->form->handleRequest ( $this->request );
		if ($this->form->isValid ()) {
			$status = $this->requestQuoteManager->setRequestQuoteAddGuestContactInSession ();
			if ($status ['status'] == "success") {
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['call_ajax_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_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 ( 'request_quote.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-quote-edit-guest-address/{productId}/{counter}/{method}",
	 *         name="office_brain_requestquotebundle_editguestaddress",
	 *         )
	 *         @Method({"GET"})
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:editGuestContactBook.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 ( 'guest_shipping_address' );
			$data = $sessionData [$productId] [$method] [$counter];

			$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'edit', $data ) );
			$this->form->handleRequest ( $this->request );
			return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:editGuestContactBook.html.twig', array (
					'contactBookForm' => $this->form->createView (),
					'formData' => $data,
					'requestData' => $requestData
			) );
		}
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 *         Desciption: Use to submit request info form.
	 *
	 * @param
	 *        	NULL
	 *
	 * @return Html Response
	 *
	 * @throws NULL @Route("/{_locale}/add-guest-user-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_addgguestuser"
	 *         )
	 *
	 *         @Template("OfficeBrainRequestQuoteBundle:RequestQuote:addGuestUser.html.twig")
	 *
	 *         @Method({"GET"})
	 *
	 */
	public function addGuestUserAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteGuestUserType () );
		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-request-quote",
	 *         name="office_brain_requestquotebundle_requestquote_processaddgguestusersubmit"
	 *         )
	 *
	 *         @Template()
	 *
	 *         @Method({"POST"})
	 *
	 */
	public function processAddGuestUserAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteGuestUserType () );
		$this->form->handleRequest ( $this->request );		
		if ($this->form->isValid ()) {
			// based on this condition we decied either we have to make an entry into the user table or not
			if ($this->form->getData ()['isRegisterWithSameDetail'] == 1) {
				$chkGuestUser = $this->userManager->checkGuestUserExists ( $this->form );
				if (is_object ( $chkGuestUser )) {
					$this->responseArray ['form_status'] = 'error';
					$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'request_quote.email_already_present' );
					return new JsonResponse ( $this->responseArray );
				} else {
					$guest = $this->requestQuoteManager->setRequestQuoteGuestInfo ( $this->form->getData () );
					$result = $this->requestQuoteManager->addRequestQuoteSession ( $guest->getId (), 'guest_user' );
					$user = $this->userManager->addGuestUser ( $this->form );
					if ($result ['status'] == 'success') {
						$requestQuoteObj = $result ['data'];
						if ($this->request->isXmlHttpRequest ()) {
							$this->responseArray ['status'] = 'success';
							$this->responseArray ['success_message'] = 'success';
							$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' );
							return new JsonResponse ( $this->responseArray );
						} else {
							return $this->redirect ( $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' ) );
						}
					} else if ($result ['status'] == 'error' && $result ['error'] == 'billing_address_missing') {
						$this->responseArray ['status'] = 'error';
						$this->responseArray ['msg'] = $this->get ( 'translator' )->trans ( 'request_quote.billing_address_error' );
						return new JsonResponse ( $this->responseArray );
					}
				}
			} else {				
				// Save User Detail in Guest Table If User not want to register into the Site
				$guest = $this->requestQuoteManager->setRequestQuoteGuestInfo ( $this->form->getData () );				
				$result = $this->requestQuoteManager->addRequestQuoteSession ( $guest->getId (), 'guest_user' );
				
				if ($this->request->isXmlHttpRequest ()) {					
					$this->responseArray ['status'] = 'success';
					$this->responseArray ['success_message'] = 'success';
					$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' );
					return new JsonResponse ( $this->responseArray );
				} else {
					return $this->redirect ( $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_thankyoupage' ) );
				}
			}
		} else if ($this->request->isXmlHttpRequest ()) {
			return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
		}
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render guest user shipping address.
	 * @param
	 *        	NULL
	 * @return Html Response
	 * @throws NULL @Route("/{_locale}/select-shipping-type-guest",
	 *         name="office_brain_requestquotebundle_requestquote_editselectshippingtypeguest",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST","GET"})
	 */
	public function editSelectShippingTypeGuestAction() {
		$this->initAction ();
		$data = $this->requestQuoteManager->getShippingTypeGuest ();
		$data ['shipping_detail_info'] = $this->request->get ( 'shipping_detail_info' );
		$data ['shipping_detail_guest'] = $this->request->get ( 'shipping_detail_guest' );
		$data ['shipping_estimator'] = 'no';
		$productId = $this->request->get ( 'product_id' );
// 		$productDetail = $this->requestQuoteManager->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';
		}
		return $this->render ( "OfficeBrainRequestQuoteBundle:RequestQuote:editStandardShippingGuest.html.twig", $data );
	}

	/**
	 *
	 * @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}/request-quote-guest-ship-address-edit/{product_id}/{method}/{counter}",
	 *         name="office_brain_requestquotebundle_requestquote_guestshippingaddressedit"
	 *         )
	 *         @Template()
	 */
	public function requestQuoteGuestShippingEditAction() {
		$this->initAction ();
		$this->responseArray = $this->requestQuoteManager->getRequestQuoteGuestContactEdit ();
		$this->responseArray ['edit'] = 1;
		return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:requestQuoteGuestShipping.html.twig', $this->responseArray );
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to edit the existing shipping address
	 *
	 *         @Route("/{_locale}/request-quote-edit-mode-guest-address/{productId}/{counter}/{method}",
	 *         name="office_brain_requestquotebundle_editmodeguestaddress",
	 *         )
	 *         @Method({"GET"})
	 *         @Template()
	 */
	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 RequestQuoteAddGuestShippingType ( $this->coreManager, 'edit', $data ) );
		$this->form->handleRequest ( $this->request );
		return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:editModeGuestContactBook.html.twig', array (
				'contactBookForm' => $this->form->createView (),
				'formData' => $data,
				'requestData' => $requestData
		) );
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Desciption: Use to get Request Quote Product Detail
	 *         @Route("/{_locale}/request-quote-edit-contact-session",
	 *         name="office_brain_requestquotebundle_requestquote_editcontactinsession",
	 *         options={"expose"=true}
	 *         )
	 *
	 *         @Method({"POST"})
	 *         @Template()
	 *
	 */
	public function editGuestContactInSessionAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'add' ) );
		$this->form->handleRequest ( $this->request );
		if ($this->form->isValid ()) {
			$status = $this->requestQuoteManager->getRequestQuoteGuestContactEditInProductConfig ();
			if ($status ['status'] == "success") {
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['call_ajax_url'] = $this->generateUrl ( 'office_brain_requestquotebundle_requestquote_guestshippingaddresseditmode', 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 ( 'request_quote.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 display guest shipping data
	 * @param
	 *        	1 : productid
	 * @param
	 *        	2 : method
	 * @param
	 *        	3 : counter
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/request-quote-guest-ship-address-edit-mode/{product_id}/{method}/{counter}",
	 *         name="office_brain_requestquotebundle_requestquote_guestshippingaddresseditmode"
	 *         )
	 *         @Template()
	 */
	public function requestQuoteGuestShippingEditModeAction() {
		$this->initAction ();
		$this->responseArray = $this->requestQuoteManager->getRequestQuoteGuestContactEditMode ();
		$this->responseArray ['edit'] = 1;
		return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:requestQuoteGuestShipping.html.twig', $this->responseArray );
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to add the new shipping address
	 *
	 *         @Route("/{_locale}/request-quote-edit-mode-address",
	 *         name="office_brain_requestquotebundle_editmodecontactbook",
	 *         )
	 *         @Method({"GET"})
	 *         @Template()
	 */
	public function editModeContactBookAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new RequestQuoteAddGuestShippingType ( $this->coreManager, 'add' ) );
		$this->form->handleRequest ( $this->request );
		return $this->render ( 'OfficeBrainRequestQuoteBundle:RequestQuote:editViewModeGuestContactBook.html.twig', array (
				'contactBookForm' => $this->form->createView ()
		) );
	}

	/**
	 *
	 * @author Employee Id: 4248
	 *         Desciption: Use to send Request Quote Email
	 *         @Route("/{_locale}/request-quote-send-email",
	 *         name="office_brain_requestquotebundle_requestquote_sendrequestquoteemail",
	 *         options={"expose"=true}
	 *         )
	 *
	 *         @Method({"GET","POST"})
	 *         @Template()
	 *
	 */
	public function sendRequestQuoteEmailAction() {
		/*
		 * $this->initAction(); $response = array(); $this->responseArray['requestQuote'] = $this->requestQuoteManager->getRequestQuoteDetailById('722'); $this->responseArray['data'] = $this->requestQuoteManager->getProductList($this->responseArray['requestQuote']->getId()); $this->responseArray['user_type'] = $this->responseArray['requestQuote']->getUserType(); if($this->responseArray['requestQuote']->getUserType()=="guest"){ $this->responseArray['userDetail'] = $this->requestQuoteManager->getGuestUserDetailById($this->responseArray['requestQuote']->getGuestId()); }else{ $this->responseArray['userDetail'] = $this->requestQuoteManager->getUserDetail($this->responseArray['requestQuote']->getUserId(), $this->responseArray['user_type']); } 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}/request-quote-pref-dist",
	 *         name="office_brain_requestquotebundle_requestquote_updateselectpreferreddistributor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @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: 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-request-quote",
	 * name="office_brain_requestquotebundle_requestquote_removeShippingByCounter",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:removeShippingByCounter.html.twig")
	 * @Method({"POST","GET"})
	 */
	public function removeShippingByCounterAction()
	{
		$this->initAction();
		
		$data = $this->requestQuoteManager->removeShippingCounterById();
		$data['shipping_estimator'] = 'no';
		
		$productId     = $data['data'][0]['product_id'];
		$productDetail = $this->requestQuoteManager->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;
		/* $data = $this->requestQuoteManager->getShippingType();
		 $data['shipping_detail_info'] = $this->request->get('shipping_method');
		 $data['shipping_estimator'] = 'no';
		 $productId = $this->request->get('product_id');
		 $productDetail= $this->requestQuoteManager->getProductDetailById($productId);
		 if(array_key_exists('shipping_information', $productDetail))
		 {datadata
		 if(array_key_exists('free_on_board', $productDetail['shipping_information']))
		 {
		 $data['shipping_estimator'] = 'yes';
		 }
		 }
		 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}/quote-popaddress-search",
     * name="office_brain_requestquotebundle_requestquote_quotepopupaddresssrearch",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:popupaddresslist.html.twig")
     *
     */
    public function quotePopupAddressSearchListAction()
    {
    	$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}/quote-popaddress-company-search",
     * name="office_brain_requestquotebundle_requestquote_quotepopupaddresscompanylist",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainRequestQuoteBundle:RequestQuote:popupaddresslist.html.twig")
     *
     */
    public function quotePopupAddressCompanyListAction()
    {
    	$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['data'] = $this->userContactBookManager->getPopCompanyAddressList($this->userId,$this->keywords, $this->page, $this->recordsPerPage,$this->addressType);
    	$this->responseArray['ob_project_setting'] = $this->projectSetting;
    	return $this->responseArray;
    }
}
