<?php

namespace OfficeBrain\Bundle\QuoteBundle\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\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use OfficeBrain\Bundle\QuoteBundle\Form\AddCustomerType;
use OfficeBrain\Bundle\QuoteBundle\Form\AddCustomerContactType;
use OfficeBrain\Bundle\QuoteBundle\Form\QuoteNegotiationType;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Form\FormError;


/**
 *
 *
 * @Route("", defaults={"rule_service"="rule_charges"})
 */
class QuoteController extends Controller {
	/**
	 *
	 * @author Employee Id: 4203
	 *         To set member variables default value
	 * @return NULL
	 */
	public function __construct() {
		$this->request = null;
		$this->user = null;
		$this->userId = null;
		$this->locale = null;
		$this->cultureId = null;
		$this->session = null;
		$this->totalProduct = 0;
		$this->refererUrl = null;
		$this->productIdArray = null;
		$this->sessionManager = null;
		$this->responseArray = array ();
		$this->projectSetting = null;
		$this->productCultureIdArray = null;
		$this->productId = null;
		$this->productSlug = null;
		$this->productCultureId = null;
		$this->searchParameterArray = array ();
		$this->searchKeyWordsArray = array ();
		$this->sortingParameterArray = array ();
		$this->formManager = null;
		$this->validationManager = null;
		$this->coreManager = null;
		$this->filePath = null;
		$this->erpConfigrationField = null;
		$this->queueApiManager = 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->productId );
		unset ( $this->productSlug );
		unset ( $this->productCultureId );
		unset ( $this->searchParameterArray );
		unset ( $this->searchKeyWordsArray );
		unset ( $this->sortingParameterArray );
		unset ( $this->formManager );
		unset ( $this->validationManager );
		unset ( $this->coreManager );
		unset ( $this->filePath );
		unset ( $this->erpConfigrationField );
		unset ( $this->queueApiManager );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Create various objects required action in this class
	 * @return NULL
	 */
	public function initAction() {
		$this->request = $this->getRequest ();
		$this->projectSetting = $this->request->get ( 'project_setting' );
		$this->projectUserSetting = $this->request->get ( 'project_user_setting' );
		$this->userId = $this->projectSetting ['user_id'];
		$this->user = $this->projectUserSetting ['user_data'];
		$this->instanceType = $this->projectSetting ['instance_type'];
		$this->productId = $this->request->get ( 'product_id', null );
		$this->productSlug = $this->request->get ( 'product_slug', null );
		$this->requestQuoteMasterId = $this->request->get ( 'requestQuoteMasterId', null );
		$this->cultureId = $this->projectSetting ['culture_id'];
		$this->locale = $this->projectSetting ['culture_code'];
		$this->configurationRule = $this->projectSetting ['configuration_rule'] ['transaction'] ['quote'];
		$this->userConfigrations = $this->projectSetting ['configuration_rule'] ['user'] ['user'];
		$this->parameter = $this->userConfigrations ['user_photo_upload_parameter'];
		$this->replaceImagePath = $this->configurationRule ['replace_product_image'] ['path'];
		// $this->replaceImageUrl = $this->configurationRule ['replace_product_image_url'];
		$this->requestStatus = $this->request->get ( 'status', 'draft' );
		$this->quoteManager = $this->get ( 'office_brain_quote_manager' );
		$this->commonLibraryManager = $this->get ( 'office_brain_common_library' );
		$this->coreManager = $this->get ( 'office_brain_core_manager' );
		$this->location = $this->get ( 'kernel' )->getRootDir () . '/../web/images/uploads/';
		$this->userManager = $this->get ( 'office_brain_user_manager' );
		$this->contactBookManager = $this->get ( 'office_brain_user_contact_book_manager' );
		$this->page = $this->request->get ( 'page', '1' );
		$this->sessionManager = $this->get ( 'office_brain_session_manager' );
		// $this->quoteManager = $this->get('office_brain_quote_manager');
		$this->responseArray ['product_id'] = $this->productId;
		$this->responseArray ['status'] = 'error';
		$this->recordsPerPage = $this->request->get ( 'records_per_page', $this->configurationRule ['list'] ['option'] ['no_of_product'] );
		$this->validationManager = $this->get ( 'office_brain_validation_manager' );
		$this->responseArray = array ();
		$this->filePath = $this->get ( 'kernel' )->getRootDir () . '/../web/';
		$this->erpConfigrationField = $this->projectSetting ['configuration_rule'] ['erp_integration'];
		if ($this->has ( 'office_brain_queue_api_manager' )) {
			$this->request->attributes->set ( 'object', 'Quote' );
			$this->queueApiManager = $this->get ( 'office_brain_queue_api_manager' );
		}
		$this->requestInfoManager = $this->get ( 'office_brain_request_info_manager' );
		$this->requestQuoteManager = $this->get ( 'office_brain_request_quote_manager' );
		$this->productDetailconfigurationRule = $this->projectSetting ['configuration_rule'] ['transaction'] ['quote'] ['product_detail_popup'];
		$this->shippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_fedex');
		$this->colorImageUrl = $this->container->getParameter ( 'api.color_image_base_url' );
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         OB eCommerce Product - preapre search parameter
	 */
	private function prepareSearchParameterArray() {
		$this->searchParameterArray ['start_date'] = $this->request->get ( 'start_date', null );
		$this->searchParameterArray ['end_date'] = $this->request->get ( 'end_date', null );
		$jsDateFormat = $this->coreManager->getDateJsFormat();
		if ($this->searchParameterArray ['start_date'] != null) {
			$startDate = \DateTime::createFromFormat ( $jsDateFormat, $this->searchParameterArray ['start_date'] );
			
			$this->searchParameterArray ['start_date'] = $startDate->format ( 'Y-m-d' );
		}
		if ($this->searchParameterArray ['end_date'] != null) {
			$endDate = \DateTime::createFromFormat ( $jsDateFormat, $this->searchParameterArray ['end_date'] );
			$this->searchParameterArray ['end_date'] = $endDate->format ( 'Y-m-d' );
		}
		$this->option = $this->request->get ( 'option', null );
		$this->keywords = $this->request->get ( 'keyword', null );
		$this->searchKeyWordsArray [$this->option] = trim ( $this->keywords );
	}
	
	private function prepareSortingParameterArray() {
		$this->sortingParameterArray ['sort_type'] = $this->request->get ( 'sort_type', null );
		$this->sortingParameterArray ['sort_field'] = $this->request->get ( 'sort_field', null );
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to display quote list.
	 * @param
	 *        	1 : No paramater
	 * @return type : Form view and data.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/quote-list",
	 *         name="office_brain_quotebundle_quote_quotelist",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *        
	 */
	public function quoteListAction() {
		$this->initAction ();
		if ($this->userId == 0) {
			$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->prepareSearchParameterArray ();
		$this->prepareSortingParameterArray ();
		$this->responseArray ['tab_status'] = $this->requestStatus;
		$this->responseArray ['data'] = $this->quoteManager->getQuoteList ( $this->page, $this->recordsPerPage, $this->requestStatus, $this->searchParameterArray, $this->sortingParameterArray, $this->searchKeyWordsArray );
		$this->responseArray ['tab_count'] = $this->quoteManager->getAllTabCount ();
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use for Create new quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : NUll.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/create-quote",
	 *         name="office_brain_quotebundle_quote_createquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function createQuoteAction() {
		$this->initAction ();
		if ($this->userId == 0) {
			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
			return $this->redirect ( $this->generateUrl ( 'office_brain_userbundle_login_login' ) );
		}
		$result = $this->quoteManager->addCreateQuoteAdmin ();
		if ($result ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['quote_id'] = $result ['data']->getId ();
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.success_message' );
			$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
					'quote_id' => $result ['data']->getId () 
			) );
		} elseif ($result ['status'] == "NOTALLOWED") {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.not_allow_error_message' );
		} else {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.error_message' );
		}
		
		unset ( $result );
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use for Create new quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : NUll.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/create-quote-from-quote",
	 *         name="office_brain_quotebundle_quote_createquotefromqueue",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function createQuoteFromQueueAction() {
		$this->initAction ();
		$result = $this->quoteManager->addCreateQuote ();
		if ($result ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['quote_id'] = $result ['data']->getId ();
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.success_message' );
			$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
					'quote_id' => $result ['data']->getId () 
			) );
		} elseif ($result ['status'] == "NOTALLOWED") {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.not_allow_error_message' );
		} else {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'quote.empty_queue_error_message' );
		}
		
		unset ( $result );
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to configure this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/quote/{quote_id}/{mode}",
	 *         name="office_brain_quotebundle_quote_quote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function quoteAction($mode = "create") {
		$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'),array('quote_id'=>$this->request->get('quote_id')),array('mode'=>$this->request->get('mode'))));
				return $this->redirect ( $this->generateUrl ( 'office_brain_userbundle_login_login' ) );
			}
		}
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		if ($mode == "edit") {
			$this->responseArray ['mode'] = 'edit';
		} else {
			$this->responseArray ['mode'] = 'create';
		}
		$this->quoteManager->updateQuoteStatus ( $quoteDetail );
		$userObj = $this->getCustomerDetailFromQuote ( $quoteDetail->getId () );
		
		if ($quoteDetail != NULL) {
			$this->responseArray ['data'] = $quoteDetail;
			$this->responseArray ['userData'] = $userObj;
			unset ( $quoteDetail );
			return $this->responseArray;
		} else {
			return $this->redirect ( $this->generateUrl ( 'office_brain_quotebundle_quote_quotelist' ) );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to add product in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/add-multiple-product-to-quote",
	 *         name="office_brain_quotebundle_quote_addmultipleproductquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function addMultipleProductQuoteAction() {
		$this->initAction ();
		$result = $this->quoteManager->addMultipleProductToQuote ();
		if ($result ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['quote_id'] = $result ['quote_id'];
			$quoteItemLineObj = $result ['data'];
			/*
			 * if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && !empty($this->queueApiManager)) { $this->request->attributes->set('object', 'QuoteItemLine'); if ($quoteItemLineObj->getQuoteMasterId()->getQuoteStatus() == 'sent') { if($quoteItemLineObj->getErpId() > 0){ $this->queueApiManager->mapQueue('update', $quoteItemLineObj); }else{ $this->queueApiManager->mapQueue('create', $quoteItemLineObj); } } }
			 */
			// $this->responseArray['success_message'] = $this->get('translator')->trans('admin.product_success_message');
		} else {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'quote.empty_queue_error_message' );
		}
		unset ( $result );
		return new JsonResponse ( $this->responseArray );
	}
	public function getCustomerDetailFromQuote($quoteId) {
		$this->initAction ();
		return $this->userDetail = $this->quoteManager->getCustomerDetailFromQuote ( $quoteId );
	}
	public function getCustomerBillingDetailFromQuote($customerId) {
		$this->initAction ();
		return $this->userDetail = $this->quoteManager->getCustomerBillingDetailFromQuote ( $customerId );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to hide show funcationality
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/hide-show",
	 *         name="office_brain_quote_bundle_hide_show",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function hideShowAction() {
		$this->initAction ();
		$fldName = $this->request->get ( 'fld_name' );
		$fldValue = $this->request->get ( 'fld_value' );
		$status = $this->quoteManager->getHideShowFieldStatus ();
		if ($status ['status'] == "SUCCESS") {
			if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				$this->quoteManager->integrateWithErp ( $fldName, $fldValue, $status ['data'], $this->queueApiManager );
			}
			$this->responseArray ['status'] = 'success';
			if ($fldName == "discount" || $fldName == "additionalCharges") {
				$this->responseArray ['quote_id'] = $status ['data']->getId ();
			}
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_update_success_message' );
		} else {
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_not_found' );
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to delete a record
	 * @param
	 *        	1 : No paramater
	 * @return type : Form view and data.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/delete-quote",
	 *         name="office_brain_quotebundle_quote_deletequote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function deleteQuoteAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->deleteQuoteDetailById ();
		switch ($quoteDetail ['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 ['quote_list'] = 'inquiry';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );
				$quoteObj = $quoteDetail ['data'];
				
				if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
					$this->request->attributes->set ( 'object', 'Quote' );
					if ($quoteObj->getQuoteStatus () == 'sent') {
						if ($quoteObj->getErpId () > 0) {
							$this->queueApiManager->mapQueue ( 'remove', array (
									'id' => $this->request->get ( 'quote_id' ),
									'deleted_at' => $quoteObj->getDeletedAt ()->format ( 'Y-m-d H:i:s' ) 
							) );
						} else {
							$this->queueApiManager->mapQueue ( 'create', $quoteObj );
						}
					}
				}
				break;
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to save quote information in to quoate master table.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/save-quote-information",
	 *         name="office_brain_quotebundle_quote_savequoteinformation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function saveQuoteInformationAction() {
		$this->initAction ();
		$this->responseArray ['quoteTitle'] = $this->request->get ( 'quote_title', null );
		$this->responseArray ['quoteExpire'] = $this->request->get ( 'quote_expire', null );
		$this->responseArray ['quoteHeader'] = $this->request->get ( 'quote_header', null );
		$this->responseArray ['quoteFooter'] = $this->request->get ( 'quote_footer', null );
		$this->responseArray ['quoteId'] = $this->request->get ( 'quote_id', null );
		$this->responseArray = $this->quoteManager->saveQuoteInfo ( $this->responseArray );
		$quoteObj = $this->responseArray ['data'];
		if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
			$this->request->attributes->set ( 'object', 'Quote' );
			if ($quoteObj->getQuoteStatus () == 'sent') {
				if ($quoteObj->getErpId () > 0) {
					$this->queueApiManager->mapQueue ( 'update', $quoteObj );
				} else {
					$this->queueApiManager->mapQueue ( 'create', $quoteObj );
				}
			}
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render customer info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/add-new-customer-to-quote/{quote_id}",
	 *         name="office_brain_quotebundle_quote_addnewcustomertoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:addNewCustomer.html.twig")
	 */
	public function addNewCustomerAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new AddCustomerContactType ( $this->coreManager ) );
		$this->form->handleRequest ( $this->request );
		$this->responseArray ['quote_customer'] = $this->form->createView ();
		$this->responseArray ['quote_id'] = $this->request->get ( 'quote_id', null );
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4493
	 *         Description : Use to render customer info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/edit-customer-to-quote/{user_id}/{quote_id}",
	 *         name="office_brain_quotebundle_quote_editcustomertoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editCustomerToQuote.html.twig")
	 */
	public function editCustomerToQuoteAction() {
		$this->initAction ();
		
		$quoteId = $this->request->get ( 'quote_id', null );
		$userId = $this->request->get ( 'user_id', null );
		$userObj = $this->getCustomerDetailFromQuote ( $quoteId );
		$this->form = $this->createForm ( new AddCustomerType ( $this->coreManager, 'edit' ), $userObj );
		$this->form->handleRequest ( $this->request );
		$this->responseArray ['edit_quote_customer'] = $this->form->createView ();
		$this->responseArray ['quote_id'] = $quoteId;
		$this->responseArray ['contact_id'] = $userObj->getId ();
		$this->responseArray ['user_id'] = $userId;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render customer billing info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/edit-customer-billing-to-quote",
	 *         name="office_brain_quotebundle_quote_editcustomerbillingtoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editCustomerbillingToQuote.html.twig")
	 */
	public function editCustomerbillingToQuoteAction() {
		$this->initAction ();
		$userId = $this->request->get ( 'user_id', null );
		$userObj = $this->getCustomerBillingDetailFromQuote ( $userId );
		$photo = $userObj->getPhoto ();
		$this->form = $this->createForm ( new AddCustomerContactType ( $this->coreManager, 'edit' ), $userObj );
		$this->form->handleRequest ( $this->request );
		$this->responseArray ['edit_quote_billing_customer'] = $this->form->createView ();
		$this->responseArray ['user_id'] = $userId;
		$this->responseArray ['photo'] = $photo;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render customer info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/save-new-customer-to-quote/{quote_id}",
	 *         name="office_brain_quotebundle_quote_savenewcustomer",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 *         @Template("OfficeBrainQuoteBundle:Quote:addNewCustomer.html.twig")
	 */
	public function saveNewCustomerAction() {
		$this->initAction ();
		$this->form = $this->createForm ( new AddCustomerContactType ( $this->coreManager ) );
		$this->form->handleRequest ( $this->request );
		
		$this->responseArray ['quote_customer'] = $this->form->createView ();
		$this->responseArray ['quote_id'] = $this->request->get ( 'quote_id', null );
		
		if ($this->form->isValid ()) {
			$billingAddressArray = $this->form->getData ();
			if (is_object ( $billingAddressArray ['photo'] )) {
				$this->coreManager->setLocationPath ( $this->location );
				$code = $this->coreManager->uploadImage ( $this->parameter, $billingAddressArray ['photo'], 'user_photo' );
				switch ($code) {
					case 'SUCCESS' :
						$this->responseArray ['success'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.success' );
						break;
					case 'FAIL' :
						$this->responseArray ['error'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.fail' );
						break;
					case 'TYPE' :
						$this->responseArray ['error'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.type' );
						break;
					case 'SIZE' :
						$this->responseArray ['error'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.size', array (
								'%img_size%' => $this->parameter ['size'] 
						) );
						break;
					case 'HEIGHT' :
						$this->responseArray ['error'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
					case 'WIDTH' :
						$this->responseArray ['error'] = $this->get ( 'translator' )->trans ( 'quote.quote_my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
				}
				if ($code != "SUCCESS") {
					$this->form->get ( "photo" )->addError ( new FormError ( $this->responseArray ['error'] ) );
					$this->responseArray = array (
							'form_name' => $this->form->getName (),
							'form_status' => 'error',
							'form_errors' => $this->getErrorsAsArray ( $this->form ) 
					);
					return new JsonResponse ( $this->responseArray );
				}
			}
			
			$this->quoteUserContact = $this->quoteManager->addQuoteUserBillingAddressInContactBook ( $billingAddressArray, $this->responseArray ['quote_id'], $billingAddressArray ['photo'] );
			if ($this->quoteUserContact ['status'] == 'SUCCESS') {
				$data ['status'] = 'success';
				$data ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.address_success_message' );
				$data ['quote_id'] = $this->responseArray ['quote_id'];
				if ($this->erpConfigrationField && $this->erpConfigrationField ['userManagement'] == 1 && ! empty ( $this->queueApiManager )) {
					$this->request->attributes->set ( 'object', 'ContactBook' );
					if ($this->quoteUserContact ['data']->getErpId () > 0) {
						$this->queueApiManager->mapQueue ( 'update', $this->quoteUserContact ['data'] );
					} else {
						$this->queueApiManager->mapQueue ( 'create', $this->quoteUserContact ['data'] );
					}
				}
				return new JsonResponse ( $data );
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		} else if ($this->request->isXmlHttpRequest ()) {
			if ($this->request->get ( 'call_type' ) == 'country_code' || $this->request->get ( 'call_type' ) == 'state_code') {
				return $this->responseArray;
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render customer info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-customer-to-quote/{quote_id}",
	 *         name="office_brain_quotebundle_quote_updatecustomertoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 *         @Template("OfficeBrainQuoteBundle:Quote:editCustomerToQuote.html.twig")
	 */
	public function updateCustomerToQuoteAction() {
		$this->initAction ();
		$quoteId = $this->request->get ( 'quote_id', null );
		$contactUserObj = $this->getCustomerDetailFromQuote ( $quoteId );
		$orignalPhoto = $contactUserObj->getPhoto ();
		$this->form = $this->createForm ( new AddCustomerType ( $this->coreManager, 'edit' ), $contactUserObj );
		$this->form->handleRequest ( $this->request );
		$this->responseArray ['edit_quote_customer'] = $this->form->createView ();
		$this->responseArray ['quote_id'] = $quoteId;
		if ($this->form->isValid ()) {
			$customerData = $this->form->getData ();
			if (is_object ( $customerData->getPhoto () )) {
				$this->coreManager->setLocationPath ( $this->location );
				$code = $this->coreManager->uploadImage ( $this->parameter, $customerData->getPhoto (), 'user_photo' );
				if ($code == 'SUCCESS') {
					$photo = $customerData->getPhoto ()->getClientOriginalName ();
				} else {
					$photo = $orignalPhoto;
				}
			} else {
				$photo = $orignalPhoto;
				$code = 'SUCCESS';
			}
			$this->quoteUser = $this->quoteManager->editQuoteUser ( $customerData, $photo );
			if ($this->quoteUser ['status'] == 'SUCCESS') {
				switch ($code) {
					case 'SUCCESS' :
						$data ['status'] = 'success';
						$data ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.customer_edit_success_message' );
						$data ['quote_id'] = $quoteId;
						break;
					case 'FAIL' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.fail' );
						break;
					case 'TYPE' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.type' );
						break;
					case 'SIZE' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.size', array (
								'%img_size%' => $this->parameter ['size'] 
						) );
						break;
					case 'HEIGHT' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
					case 'WIDTH' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
				}
				return new JsonResponse ( $data );
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		} else if ($this->request->isXmlHttpRequest ()) {
			if ($this->request->get ( 'call_type' ) == 'country_code' || $this->request->get ( 'call_type' ) == 'state_code') {
				return $this->responseArray;
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render customer billing info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-customer-billing-to-quote/{user_id}",
	 *         name="office_brain_quotebundle_quote_updatecustomerbillingtoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 *         @Template("OfficeBrainQuoteBundle:Quote:editCustomerbillingToQuote.html.twig")
	 */
	public function updateCustomerBillingToQuoteAction() {
		$this->initAction ();
		$userId = $this->request->get ( 'user_id', null );
		$userObj = $this->getCustomerBillingDetailFromQuote ( $userId );
		$orignalPhoto = $userObj->getPhoto ();
		$this->form = $this->createForm ( new AddCustomerContactType ( $this->coreManager, 'edit' ), $userObj );
		$this->form->handleRequest ( $this->request );
		$this->responseArray ['edit_quote_billing_customer'] = $this->form->createView ();
		$this->responseArray ['user_id'] = $userId;
		if ($this->form->isValid ()) {
			$customerData = $this->form->getData ();
			if (is_object ( $customerData->getPhoto () )) {
				$this->coreManager->setLocationPath ( $this->location );
				$code = $this->coreManager->uploadImage ( $this->parameter, $customerData->getPhoto (), 'user_photo' );
				if ($code == 'SUCCESS') {
					$photo = $customerData->getPhoto ()->getClientOriginalName ();
				} else {
					$photo = $orignalPhoto;
				}
			} else {
				$photo = $orignalPhoto;
				$code = 'SUCCESS';
			}
			$this->quoteUser = $this->quoteManager->editQuoteUserBilling ( $customerData, $photo );
			if ($this->quoteUser ['status'] == 'SUCCESS') {
				switch ($code) {
					case 'SUCCESS' :
						$data ['status'] = 'success';
						$data ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.customer_edit_success_message' );
						$data ['quote_id'] = $userObj->getQuoteMasterId ()->getId ();
						break;
					case 'FAIL' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.fail' );
						break;
					case 'TYPE' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.type' );
						break;
					case 'SIZE' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.size', array (
								'%img_size%' => $this->parameter ['size'] 
						) );
						break;
					case 'HEIGHT' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
					case 'WIDTH' :
						$data ['form_status'] = 'error';
						$data ['error_message'] = $this->get ( 'translator' )->trans ( 'user.my_account_edit.upload_error.widthheight', array (
								'%img_width%' => $this->parameter ['width'],
								'%img_height%' => $this->parameter ['height'] 
						) );
						break;
				}
				return new JsonResponse ( $data );
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		} 		// ###############################################
		/*
		 * if ($this->form->isValid()) { $customerData = $this->form->getData(); if (is_object($customerData->getPhoto())) { $photo = $customerData->getPhoto()->getClientOriginalName(); $this->coreManager->setLocationPath($this->location); $code=$this->coreManager->uploadImage($this->parameter, $customerData->getPhoto(), 'user_photo'); switch ($code) { case 'SUCCESS': $this->responseArray['success'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.success'); break; case 'FAIL': $this->responseArray['error'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.fail'); break; case 'TYPE': $this->responseArray['error'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.type'); break; case 'SIZE': $this->responseArray['error'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.size', array('%img_size%' => $this->parameter['size'] )); break; case 'HEIGHT': $this->responseArray['error'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] )); break; case 'WIDTH': $this->responseArray['error'] = $this->get('translator')->trans('admin.quote_my_account_edit.upload_error.widthheight', array('%img_width%' => $this->parameter['width'],'%img_height%' => $this->parameter['height'] )); break; } }else{ $photo = $userObj->getPhoto(); } $this->quoteUser = $this->quoteManager->editQuoteUserBilling($customerData,$photo); if($this->quoteUser['status'] == 'SUCCESS'){ $data['status']='success'; $data['success_message'] = $this->get('translator')->trans('admin.customer_edit_success_message'); $data['quote_id'] = $userObj->getQuoteMasterId()->getId(); return new JsonResponse($data); }else{ return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form)); } }
		 */
		else if ($this->request->isXmlHttpRequest ()) {
			if ($this->request->get ( 'call_type' ) == 'country_code' || $this->request->get ( 'call_type' ) == 'state_code') {
				return $this->responseArray;
			} else {
				return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError ( $this->form ) );
			}
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render Billing Address from Contact book/My Address book
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response in view.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-billing-address",
	 *         name="office_brain_quotebundle_quote_getBillingAddress",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"GET"})
	 */
	public function getBillingAddressAction() {
		$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->quoteManager->getUserBillingAddresByEmailOrName ();
			$addressRes = array ();
			foreach ( $Address as $key => $aa ) {
				$addressRes [$aa ['id']] = array (
						'id' => $aa ['id'],
						'label' => $aa ['label'] 
				);
			}
			return new JsonResponse ( $addressRes );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to render Billing Address By Id
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/get-billing-address-by-id/{quote_id}",
	 *         name="office_brain_quotebundle_quote_getbillingaddressbyid",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getBillingAddressById.html.twig")
	 *         @Method({"GET"})
	 */
	public function getBillingAddressByIdAction() {
		$this->initAction ();
		$quote_id = $this->request->get ( 'quote_id', null );
		$this->responseArray ['billing_address'] = $this->quoteManager->getUserBillingAddresById ( $quote_id );
		$this->responseArray ['quote_id'] = $quote_id;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4493
	 *         Description : Use to render Billing Address By Id
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/get-all-address-by-quote/{quote_id}",
	 *         name="office_brain_quotebundle_quote_getalladdressbyquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getBillingAddressById.html.twig")
	 *         @Method({"GET"})
	 */
	public function getAllAddressByQuoteAction() {
		$this->initAction ();
		$quote_id = $this->request->get ( 'quote_id', null );
		$this->responseArray ['billing_address'] = $this->quoteManager->getUserBillingAddresById ( $quote_id );
		$this->responseArray ['quote_id'] = $quote_id;
		return $this->responseArray;
	}
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to delete a user from quote
	 * @param
	 *        	1 : No paramater
	 * @return type : Form view and data.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/delete-quote-user-contact",
	 *         name="office_brain_quotebundle_quote_deletequoteusercontact",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function deleteQuoteUserContactAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->deleteQuoteUserContactAdmin ();
		switch ($quoteDetail) {
			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 ['quote_id'] = $this->request->get ( 'quote_master_id' );
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'request_quote.remove_success_message' );
				break;
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         Description : Use to search product from solr.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/search-product-for-quote",
	 *         name="office_brain_quotebundle_quote_searchproductforquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function searchProductForQuoteAction() {
		$this->initAction ();
		return array (
				'ob_id' => substr ( $this->user->getObCustomerId (), 2 ) 
		);
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 *         Description : Use to get all product list added in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-all-quote-product/{quote_id}",
	 *         name="office_brain_quotebundle_quote_getproductlist",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getProductList.html.twig")
	 */
	public function getProductListAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$this->responseArray ['quote'] = $quoteDetail;
		$this->responseArray ['data'] = $this->quoteManager->prepareQuoteProductList ();
		$this->responseArray ['instance_type'] = $this->instanceType;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to hide show funcationality
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/hide-show-itemline",
	 *         name="office_brain_quotebundle_quote_hideshowitemline",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function hideShowItemLineAction() {
		$this->initAction ();
		$fldName = $this->request->get ( 'fld_name' );
		$fldValue = $this->request->get ( 'fld_value' );
		$fldValue = trim ( $fldValue );
		$quoteItemlineId = $this->request->get ( 'quote_itemline_id' );
		$itemLineObjBeforeSaving = $this->quoteManager->getQuoteItemLineById ( $quoteItemlineId );
		// $itemLineTotal IS WHAT WAS BEFORE RECORD IS SAVED.
		$itemLineTotal = $itemLineObjBeforeSaving->getItemLineTotal ();
		unset ( $itemLineObjBeforeSaving );
		$status = $this->quoteManager->getHideShowFieldItemlineStatus ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			if ($fldName == "itemLineTotal") {
				$this->responseArray ['quote_id'] = $status ['itemLineObj']->getQuoteMasterId ()->getId ();
				$this->responseArray ['quote_item_line_id'] = $status ['itemLineObj']->getId ();
			}
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_update_success_message' );
			if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				$this->quoteManager->integrateWithErp ( $fldName, $fldValue, $status ['data'], $this->queueApiManager, $itemLineTotal );
				unset ( $itemLineTotal );
			}
		} else {
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_not_found' );
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : quote negotiation via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/quote-negotiation/{quote_id}/{secret}",
	 *         name="office_brain_quotebundle_quote_negotiation",
	 *         options={"expose"=true})
	 *         @Template("OfficeBrainQuoteBundle:Quote:negotiation.html.twig")
	 *         @Method({"GET"})
	 */
	public function negotiationAction() {
		$this->initAction ();
		
		$quoteDetail = $this->quoteManager->isNegotiationPossible ();
		if ($quoteDetail != NULL) {
			// $userObj = $this->getCustomerDetailFromQuote($quoteDetail->getId());
			$userObj = $this->quoteManager->getCustomerDetailFromQuoteNagociation ( $quoteDetail->getId () );
			$this->responseArray ['data'] = $quoteDetail;
			$this->responseArray ['userData'] = $userObj;
			$this->responseArray ['isQuotePreviewPage'] = '0';
			unset ( $quoteDetail );
			return $this->responseArray;
		} else {
			return $this->redirect ( $this->generateUrl ( "office_brain_quotebundle_quote_negotiationexpire" ) );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : quote negotiation via ajax.
	 *        
	 *         @Route("/{_locale}/quote-negotiation-process/{quote_id}",
	 *         name="office_brain_quotebundle_quote_quotenegotiationprocess",
	 *         options={"expose"=true})
	 *         @Template("OfficeBrainQuoteBundle:Quote:negotiationProcess.html.twig")
	 *         @Method({"POST"})
	 */
	public function negotiationProcessAction() {
		$this->initAction ();
		$status = $this->quoteManager->negotiationProcess ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'quote_negotiation.updated' );
			$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_thankupage' );
			unset ( $status );
			return new JsonResponse ( $this->responseArray );
		} else if ($status ['status'] == "STATUS_ERROR") {
			$this->responseArray ['status'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'quote_negotiation.status_error' );
			unset ( $status );
			return new JsonResponse ( $this->responseArray );
		 }/* else if ($status ['status'] == "COMMENT_ERROR") {
			$this->responseArray ['status'] = 'error';
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'quote_negotiation.comment_error' );
			unset ( $status );
			return new JsonResponse ( $this->responseArray );
		} */ // 4488 set optinal so dont required to check
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Desciption: product thank you page
	 * @param
	 *        	NULL
	 * @return Html Response
	 * @throws NULL @Route("/{_locale}/quote-negotiation-thank-you",
	 *         name="office_brain_quotebundle_quote_thankupage"
	 *         )
	 *        
	 *         @Method({"GET"})
	 *        
	 *         @Template("OfficeBrainQuoteBundle:Quote:thankYouNegotiation.html.twig")
	 *        
	 */
	public function thankYouNegotiationAction() {
		return array ();
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Desciption: product thank you page
	 * @param
	 *        	NULL
	 * @return Html Response
	 * @throws NULL @Route("/{_locale}/quote-negotiation-expire",
	 *         name="office_brain_quotebundle_quote_negotiationexpire"
	 *         )
	 *        
	 *         @Method({"GET"})
	 *        
	 *         @Template("OfficeBrainQuoteBundle:Quote:negotiationExpire.html.twig")
	 *        
	 */
	public function negotiationExpireAction() {
		return array ();
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to render Billing Address By Id
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *         @Route("/{_locale}/get-all-address-by-quote-preview/{quote_id}",
	 *         name="office_brain_quotebundle_quote_getalladdressbyquotepreview",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getBillingAddressByIdPreview.html.twig")
	 *         @Method({"GET"})
	 */
	public function getAllAddressByQuotePreviewAction() {
		$this->initAction ();
		$quote_id = $this->request->get ( 'quote_id', null );
		$this->responseArray ['billing_address'] = $this->quoteManager->getUserBillingAddresById ( $quote_id );
		$this->responseArray ['quote_id'] = $quote_id;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to get all product list added in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-all-quote-product-preview/{quote_id}/{is_quote_preview_page}",
	 *         name="office_brain_quotebundle_quote_getproductlistpreview",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getProductListPreview.html.twig")
	 */
	public function getProductListPreviewAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$this->responseArray ['quote'] = $quoteDetail;
		$this->responseArray ['data'] = $this->quoteManager->prepareQuoteProductList ();
		$this->responseArray ['is_quote_preview_page'] = $this->request->get ( 'is_quote_preview_page', 0 );
		foreach($this->responseArray ['data'] as $dataIndex => $dataValues)
		{
			if(isset($this->responseArray ['data'][$dataIndex]['price_type']) && $this->responseArray ['data'][$dataIndex]['price_type']== 'variations')
			{
				if(isset($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country']))
				{
					foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'] as $countryIndex=> $countryCode)
					{
						$firstVariationDataWithSpecial = array();
						$firstVariationDataWithoutSpecial= array();
						$count = 0;
						foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
						{
							if($count == 0)
							{
								$firstVariationDataWithSpecial = $variationData['pricing']['decorative'];
								$firstVariationDataWithoutSpecial= $variationData['pricing']['decorative'];
							}
							$count = $count + 1;
						}
						// Now update the rate and other things if provided
						if(!(empty($firstVariationDataWithSpecial)))
						{
							foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
							{
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code'] = '';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code'] = '';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig'] = '';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code_orig'] = '';
								}
								
								// Remove special data from without special array
								unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig']);
								unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['expired_at']);
							}
						}
						if(!(empty($firstVariationDataWithSpecial)))
						{
							foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
							{
								//echo "<br/><br/><br/><br/>Variation Changed";
								$originalData = $variationData['pricing']['decorative'];
								
								if(isset($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][0]['rate_orig']))
								{
									$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithSpecial;
								}
								else
								{
									$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithoutSpecial;
								}
								foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
								{
									//echo "<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variation Range Changed";
									foreach($originalData as $originalDataRangeIndex => $originalDataRange)
									{
										//echo "<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;originalDataRange: ".$originalDataRange['from_qty'];
										//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstVariationRange: ".$firstVariationRange['from_qty'];
										if($originalDataRange['from_qty'] == $firstVariationRange['from_qty'])
										{
											//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We are updating original data";
											$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][$firstVariationRangeIndex] = $originalDataRange;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id:
	 *         Description : Use to get all product list added in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-all-quote-product-preview/{quote_id}",
	 *         name="office_brain_quotebundle_quote_getpreviewquoteproductList",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getPreviewQuoteProductList.html.twig")
	 */
	public function getPreviewQuoteProductListAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$this->responseArray ['quote'] = $quoteDetail;
		$this->responseArray ['data'] = $this->quoteManager->prepareQuoteProductList ();
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id:
	 *         Description : Use to get all product list added in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-all-quote-product-preview-for-pdf/{quote_id}",
	 *         name="office_brain_quotebundle_quote_",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getPreviewQuoteProductListForPdf.html.twig")
	 */
	public function getPreviewQuoteProductListForPdfAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$this->responseArray ['quote'] = $quoteDetail;
		$this->responseArray ['data'] = $this->quoteManager->prepareQuoteProductList ();
		foreach($this->responseArray ['data'] as $dataIndex => $dataValues)
		{
			if(isset($this->responseArray ['data'][$dataIndex]['price_type']) && $this->responseArray ['data'][$dataIndex]['price_type']== 'variations')
			{
				if(isset($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country']))
				{
					foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'] as $countryIndex=> $countryCode)
					{
						$firstVariationDataWithSpecial = array();
						$firstVariationDataWithoutSpecial= array();
						$count = 0;
						foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
						{
							if($count == 0)
							{
								$firstVariationDataWithSpecial = $variationData['pricing']['decorative'];
								$firstVariationDataWithoutSpecial= $variationData['pricing']['decorative'];
							}
							$count = $count + 1;
						}
						// Now update the rate and other things if provided
						if(!(empty($firstVariationDataWithSpecial)))
						{
							foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
							{
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate'] = 'N/A';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig'] = 'N/A';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code'] = '';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code'] = '';
								}
								if(isset($firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig']))
								{
									$firstVariationDataWithSpecial[$firstVariationRangeIndex]['code_orig'] = '';
									$firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['code_orig'] = '';
								}
								
								// Remove special data from without special array
								unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['rate_orig']);
								unset($firstVariationDataWithoutSpecial[$firstVariationRangeIndex]['expired_at']);
							}
						}
						if(!(empty($firstVariationDataWithSpecial)))
						{
							foreach($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex] as $variationId => $variationData)
							{
								//echo "<br/><br/><br/><br/>Variation Changed";
								$originalData = $variationData['pricing']['decorative'];
								
								if(isset($this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][0]['rate_orig']))
								{
									$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithSpecial;
								}
								else
								{
									$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'] = $firstVariationDataWithoutSpecial;
								}
								foreach($firstVariationDataWithSpecial as $firstVariationRangeIndex => $firstVariationRange)
								{
									//echo "<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variation Range Changed";
									foreach($originalData as $originalDataRangeIndex => $originalDataRange)
									{
										//echo "<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;originalDataRange: ".$originalDataRange['from_qty'];
										//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;firstVariationRange: ".$firstVariationRange['from_qty'];
										if($originalDataRange['from_qty'] == $firstVariationRange['from_qty'])
										{
											//echo "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We are updating original data";
											$this->responseArray ['data'][$dataIndex]['variation_pricing_for_other_country'][$countryIndex][$variationId]['pricing']['decorative'][$firstVariationRangeIndex] = $originalDataRange;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		return $this->responseArray;
	}
	/**
	 *
	 * @author Employee Id:4217
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/preview-quote/{quote_id}/",
	 *         name="office_brain_quotebundle_quote_previewquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:previewQuote.html.twig")
	 */
	public function previewQuoteAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$userObj = $this->getCustomerDetailFromQuote ( $quoteDetail->getId () );
		if ($quoteDetail != NULL) {
			$this->responseArray ['data'] = $quoteDetail;
			$this->responseArray ['userData'] = $userObj;
			$this->responseArray ['is_quote_preview_page'] = $this->request->get ( 'is_quote_preview_page', 1 );
			return $this->responseArray;
		} else {
			return $this->redirect ( $this->generateUrl ( 'office_brain_quotebundle_quote_quotelist' ) );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to send quote in email and generate duplicate quote for all customer added
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/send-quote",
	 *         name="office_brain_quotebundle_quote_send_quote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function sendQuoteAction() {
		$this->initAction ();
		$status = $this->quoteManager->sendQuote ();
		switch ($status ['status']) {
			case 'QUOTE_NOT_FOUND' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_not_found' );
				break;
			case 'PRODUCT_NOT_ADDED' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.add_atleast_one_product' );
				break;
			case 'SELECT_CUSTOMER' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.select_atleast_one_contact' );
				break;
			case 'SUCCESS' :
				// $status['quoteId']; here you get duplicate quote created object for ERP.
				if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
					$this->request->attributes->set ( 'object', 'Quote' );
					$quoteObj = $this->quoteManager->isQuoteExists ();
					if ($quoteObj->getQuoteStatus () == 'sent') {
						if ($quoteObj->getErpId () > 0) {
							$this->queueApiManager->mapQueue ( 'update', $quoteObj );
						} else {
							$this->queueApiManager->mapQueue ( 'create', $quoteObj );
						}
						if (isset ( $status ['new_quote_id'] )) {
							foreach ( $status ['new_quote_id'] as $newQuoteId ) {
								$newQuoteObj = $this->quoteManager->isQuoteExists ( $newQuoteId );
								$this->queueApiManager->mapQueue ( 'create', $newQuoteObj );
							}
						}
					}
				}
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_sent_successfully' );
				$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quotelist' );
				break;
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to generate duplicate quote with same values.
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/duplicate-quote",
	 *         name="office_brain_quotebundle_quote_duplicatequote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function duplicateQuoteAction() {
		$this->initAction ();
		$status = $this->quoteManager->duplicateQuote ();
		switch ($status ['status']) {
			case 'QUOTE_NOT_FOUND' :
				$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_not_found' );
				break;
			case 'SUCCESS' :
				// $status['quoteObj']; here you get duplicate quote created object for ERP.
				$this->responseArray ['status'] = 'success';
				$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.duplicate_success_message' );
				$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quotelist' );
				if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
					$this->request->attributes->set ( 'object', 'Quote' );
					if ($status ['data']->getQuoteStatus () == 'sent') {
						if ($status ['data']->getErpId () > 0) {
							$this->queueApiManager->mapQueue ( 'update', $status ['data'] );
						} else {
							$this->queueApiManager->mapQueue ( 'create', $status ['data'] );
						}
					}
				}
				break;
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         Desciption: This function allow user to download quote preview.
	 * @param
	 *        	integer quoteId
	 * @return download file on requested formate
	 * @throws NULL @Route("/{_locale}/quote-product-download/{quote_id}",
	 *         name="office_brain_quotebundle_quote_downloadquoteproduct"
	 *         )
	 *        
	 *         @Method({"GET"})
	 *        
	 *         @Template()
	 *        
	 */
	public function downloadQuoteProductAction() {
		$this->initAction ();
		
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		$downloadType = $this->request->get ( 'downloadType' );
		$downloadExt = ($downloadType == 'image') ? 'jpg' : $downloadType;
		$userObj = $this->getCustomerDetailFromQuote ( $quoteDetail->getId () );
		if ($quoteDetail != NULL) {
			$this->responseArray ['data'] = $quoteDetail;
			$this->responseArray ['userData'] = $userObj;
			$response = $this->render ( 'OfficeBrainQuoteBundle:Quote:downloadQuoteProduct.html.twig', $this->responseArray );
			// echo $response->getContent(); exit;
			if ($quoteDetail->getQuoteTitle () != '') {
				$quoteName = str_replace ( ' ', '_', $quoteDetail->getQuoteTitle () );
			} else {
				$quoteName = $quoteDetail->getId ();
			}
			
			// emp_id: 5460
			// remove the following comment and run quote pdf url in following format for debugging
			// http://172.16.120.75/5460/ob-product-web-client/web/app_dev.php/en_no/quote-product-download/42
			// return new Response ( $response->getContent ());
			$quoteFile = $quoteName . '.' . $downloadExt;
			if ($downloadType == 'html') {
				return new Response ( $response->getContent (), 200, array (
						'Content-Type' => 'application/' . $downloadType,
						'Content-Disposition' => 'attachment; filename="' . $quoteFile . '"',
						'Pragma' => '0',
						'Expires' => '0' 
				) );
			} else {
				return new Response ( $this->get ( 'knp_snappy.' . $downloadType )->getOutputFromHtml ( $response->getContent ()), 200, array (
						'Content-Type' => 'application/' . $downloadType,
						'Content-Disposition' => 'attachment; filename="' . $quoteFile . '"'
				) );
			}
		} else {
			$quoteId = $this->request->get ( 'quote_id' );
			return $this->redirect ( $this->generateUrl ( 'office_brain_quotebundle_quote_createquote', array (
					'quote_id' => $quoteId 
			) ) );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Load quote tab content via ajax.
	 * @param
	 *        	1 : No paramater
	 * @return type : view html.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/quote/{product_slug}",
	 *         name="office_brain_quotebundle_quote_loadquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:loadQuote.html.twig")
	 *         @Method({"GET"})
	 */
	public function loadQuoteAction() {
		$this->initAction ();
		return $this->quoteManager->getProductDetailBySlug ( $this->productSlug );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         Description : Use to edit product in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/edit-product-to-quote",
	 *         name="office_brain_quotebundle_quote_editquoteproduct",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editQuoteProduct.html.twig")
	 */
	public function editQuoteProductAction() {
		$this->initAction ();
		$itemLineId = $this->request->get ( 'item_line_id', null );
		$this->responseArray ['product_detail'] = $this->quoteManager->getProductDetailByItemLine ( $itemLineId );
		$this->responseArray ['item_line_obj'] = $this->quoteManager->getQuoteInfo ( $itemLineId );
		$this->responseArray ['item_line_id'] = $itemLineId;
		$this->responseArray ['size_allow'] =($this->responseArray ['product_detail']['is_size']) ? 1 : 0 ;
		$this->responseArray ['request_quote_session'] = $this->quoteManager->getInputDataForEdit ( $itemLineId );
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         Description : Use to get product info in this quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-product-info-to-quote",
	 *         name="office_brain_quotebundle_quote_getproductinfotoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getProductInfotoQuote.html.twig")
	 */
	public function getProductInfotoQuoteAction() {
		$this->initAction ();
		$itemLineId = $this->request->get ( 'item_line_id', null );
		$this->responseArray ['product_detail'] = $this->quoteManager->getProductDetailByItemLine ( $itemLineId );
		$this->responseArray ['item_line_id'] = $itemLineId;
		return $this->responseArray;
	}
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to render Shipping Address By Id
	 *         @Route("/{_locale}/quote-get-shipping-address-by-id-summary",
	 *         name="office_brain_quotebundle_quote_getshippingaddressbyidsummary"
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getShippingAddressByIdSummary.html.twig")
	 */
	public function getShippingAddressByIdSummaryAction() {
		$this->initAction ();
		$this->response ['result'] = $this->quoteManager->getUserShippingAddresById ();
		$this->response ['addressId'] = $this->request->get ( 'contact_id', null );
		$this->response ['ob_project_setting'] = $this->projectSetting;
		return $this->response;
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *        
	 *         Description : Use to set session data for Quote
	 *        
	 * @param
	 *        	1 : No paramater
	 *        	
	 * @return type : json
	 *        
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/set-product",
	 *         name="office_brain_quotebundle_quote_setproduct",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 */
	public function setProductAction() {
		$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');
		if ($this->validationManager->isValid ()) {
			$status = $this->quoteManager->setProductToQuote ();
			switch ($status ['success']) {
				case 'SUCCESS' :
					if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
						$this->request->attributes->set ( 'object', 'QuoteItemLine' );
						if ($status ['data']->getQuoteMasterId ()->getQuoteStatus () == 'sent') {
							/*
							 * if($status['data']->getErpId() > 0) { $this->queueApiManager->mapQueue('update', $status['data']); }else{
							 */
							$this->queueApiManager->mapQueue ( 'create', $status ['data'] );
							// }
						}
					}
					$this->responseArray ['status'] = 'success';
					$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
							'quote_id' => $status ['quote_id'] 
					) );
					break;
			}
		} 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: 4532
	 *        
	 *         Description : Use to update quote product
	 *        
	 * @param
	 *        	1 : No paramater
	 *        	
	 * @return type : json
	 *        
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-quote-product",
	 *         name="office_brain_quotebundle_quote_updatequoteproduct",
	 *         options={"expose"=true}
	 *         )
	 *         @Method({"POST"})
	 */
	public function updateQuoteProductAction() {
		$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');
		if ($this->validationManager->isValid ()) {
			$status = $this->quoteManager->editProductToQuote ();
			switch ($status ['success']) {
				case 'SUCCESS' :
					if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
						$this->request->attributes->set ( 'object', 'QuoteItemLine' );
						if ($status ['data']->getQuoteMasterId ()->getQuoteStatus () == 'sent') {
							/*
							 * if($status['data']->getErpId() > 0){ $this->queueApiManager->mapQueue('update', $status['data']); }else{
							 */
							$this->queueApiManager->mapQueue ( 'create', $status ['data'] );
							// }
						}
					}
					$this->responseArray ['status'] = 'success';
					$this->responseArray ['page_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
							'quote_id' => $status ['quote_id'] 
					) );
					break;
			}
		} 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: 4532
	 *         Description : Use to remove itemline product.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/remove-item-line-product",
	 *         name="office_brain_quotebundle_quote_removeitemline",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function removeItemLineAction() {
		$this->initAction ();
		$status = $this->quoteManager->removeItemLineProduct ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['quote_id'] = $status ['data']->getId ();
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.remove_item_line_success_message' );
			if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				if ($status ['data']->getQuoteStatus () == 'sent') {
					$this->request->attributes->set ( 'object', 'QuoteItemLine' );
					// if($status['erp_id'] > 0){
					$this->queueApiManager->mapQueue ( 'remove', array (
							'id' => $this->request->get ( 'item_line_id' ) 
					) );
					// }
				}
			}
			unset ( $result );
			return new JsonResponse ( $this->responseArray );
		}
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to add addtional charges
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/add-addtional-charges",
	 *         name="office_brain_quotebundle_quote_addadditionalcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:addAdditionalCharges.html.twig")
	 */
	public function addAdditionalChargesAction() {
		$this->initAction ();
		$status = $this->quoteManager->addAdditionalCharges ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['data'] = $status ['data'];
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to remove addtional charges
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/remove-addtional-charges",
	 *         name="office_brain_quotebundle_quote_removeadditionalcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function removeAdditionalChargesAction() {
		$this->initAction ();
		$status = $this->quoteManager->removeAdditionalCharges ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_info.quote_additional_charges_remove' );
			$this->responseArray ['item_line_id'] = $status ['data']->getId ();
			$this->responseArray ['item_line_total'] = $status ['data']->getItemLineAmount ();
			if (count ( $status ['data']->getQuoteProductAdditionalCharges () ) == 0) {
				$this->responseArray ['no_charge_found_message'] = $this->get ( 'translator' )->trans ( 'admin.quote_info.quote_additional_charges_not_found' );
			}
			if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				if ($status ['data']->getQuoteMasterId ()->getQuoteStatus () == 'sent') {
					$this->request->attributes->set ( 'object', 'QuoteProductAdditionalCharges' );
					if ($status ['erp_id'] > 0) {
						$this->queueApiManager->mapQueue ( "remove", array (
								'id' => $this->request->get ( 'additional_charges_id' ) 
						) );
					}
				}
			}
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to update charges
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-all-charges",
	 *         name="office_brain_quotebundle_quote_updateallcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function updateAllChargesAction() {
		$this->initAction ();
		$status = $this->quoteManager->updateAllCharges ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['charge_id'] = $status ['data']->getId ();
			$this->responseArray ['item_line_id'] = $status ['data']->getQuoteItemLineId ()->getId ();
			$this->responseArray ['item_line_total'] = $status ['data']->getQuoteItemLineId ()->getItemLineTotal ();
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to update additional charges
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-additional-charges",
	 *         name="office_brain_quotebundle_quote_updateaddtionalcharges",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function updateAdditionalChargesAction() {
		$this->initAction ();
		$status = $this->quoteManager->updateAdditionalCharges ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['additional_charge_id'] = $status ['data']->getId ();
			$this->responseArray ['item_line_id'] = $status ['data']->getQuoteItemLineId ()->getId ();
			$this->responseArray ['item_line_total'] = $status ['data']->getQuoteItemLineId ()->getItemLineAmount ();
			$this->responseArray ['additional_charge_total'] = $status ['data']->getChargesAmount ();
			if (! empty ( $status ['data']->getChargesType () ) && ($status ['data']->getChargesAmount () > 0)) {
				if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
					$this->request->attributes->set ( 'object', 'QuoteProductAdditionalCharges' );
					if ($status ['data']->getQuoteItemLineId ()->getQuoteMasterId ()->getQuoteStatus () == 'sent') {
						if ($status ['data']->getErpId () > 0) {
							$this->queueApiManager->mapQueue ( "update", $status ['data'] );
						} else {
							$this->queueApiManager->mapQueue ( "create", $status ['data'] );
						}
					}
				}
			}
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to update discount
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/update-itemline-discount",
	 *         name="office_brain_quotebundle_quote_itemlineupdatediscount",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 */
	public function itemLineUpdateDiscountAction() {
		$this->initAction ();
		$status = $this->quoteManager->updateDiscount ();
		if ($status ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['item_line_id'] = $status ['data']->getId ();
			$this->responseArray ['item_line_total'] = $status ['data']->getItemLineAmount ();
			if ($this->erpConfigrationField && $this->erpConfigrationField ['orderManagement'] == 1 && ! empty ( $this->queueApiManager )) {
				$this->request->attributes->set ( 'object', 'QuoteItemLine' );
				if ($status ['data']->getQuoteMasterId ()->getQuoteStatus () == 'sent') {
					/*
					 * if($status['data']->getErpId() > 0) { $this->queueApiManager->mapQueue('update', $status['data']); } else{
					 */
					$this->queueApiManager->mapQueue ( 'create', $status ['data'] );
					// }
				}
			}
		}
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to update discount
	 * @param
	 *        	1 : No paramater
	 * @return type : Ajax response.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/display-message-box",
	 *         name="office_brain_quotebundle_quote_displaymessagebox",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:displayMessageBox.html.twig")
	 */
	public function displayMessageBoxAction() {
		$this->initAction ();
		$quoteDetail = $this->quoteManager->isQuoteExists ();
		if ($quoteDetail != NULL) {
			$this->responseArray ['fld_name'] = $this->request->get ( 'fld_name' );
			$this->responseArray ['quote'] = $quoteDetail;
		}
		return $this->responseArray;
	}
	
	/**
	 *
	 * @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",
	 *         name="officebrain_quote_bundle_quote_editimprintlocation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editImprintLocation.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editImprintLocationAction() {
		$this->initAction ();
		$data = array ();
		$data ['imprintLocation'] = $this->quoteManager->addImprintLocation ();
		$data ['imprint_info'] = $this->request->get ( 'imprint_info', null );
		$data ['confiSetting'] = $this->productDetailconfigurationRule;
		
		$standardImprintColor = $this->quoteManager->getStandardImprintColorInformation($this->request->get('product_id', null));
		$data['standard_imprint_color'] = $standardImprintColor;
		
		return $data;
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *        
	 *         Description : Select Method for edit imprint information
	 *        
	 * @param
	 *        	1 : No paramater
	 *        	
	 * @return type : Form view and data.
	 *        
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/quote-select-method-edit",
	 *         name="officebrain_quote_bundle_quote_editselectMethod",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editSelectMethod.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editSelectMethodAction() {
		$this->initAction ();
		$data = array ();
		$data ['selectImprintMethod'] = $this->quoteManager->editSelectImprintMethod ();
		$data ['imprint_info'] = $this->request->get ( 'imprint_info', null );
		// echo '<pre>'; print_r($data); die;
		return $data;
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         Description : Use to 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}/edit-shipping-method",
	 *         name="office_brain_quotebundle_quote_editShippingTypeForQuote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST","GET"})
	 */
	public function editShippingTypeForQuoteAction() {
		$this->initAction ();
		$data = $this->quoteManager->getShippingType ();
		$productId = ($data ['config'] ['product_id']);
		$colorQuantity = array ();
		$quoteShippingDetail = $this->request->get ( 'quote_shipping_detail' );
		$quoteProduct = $quoteShippingDetail->getQuoteProductId ();
		$quoteVariationMaster = $quoteProduct->getQuoteVariationMaster ();
		
		foreach ( $quoteVariationMaster as $qvm ) {
			if ($productId == $quoteProduct->getProductId ()) {
				$quoteVariationMapping = $qvm->getQuoteVariationMapping ();
				$quoteQuantity = $quoteVariationMapping->getQuoteVariationQuantity ();
				foreach ( $quoteQuantity as $qvQuanity ) {
					$productQuantity = $qvQuanity->getProductQuantity ();
					$colorQuantity ['color'] ['id:' . $qvm->getAttributeValueId ()] ['quantity'] [] = $productQuantity;
				}
			}
		}
		$data ['color_qty'] = $colorQuantity;
		$data ['quote_shipping_detail'] = $quoteShippingDetail;
		$data ['shipping_estimator'] = '';
		$shipdetail = $this->shippingEstimatorManager->checkShippingDetailAvailable($productId);
		if ($shipdetail == true) {
			$data ['shipping_estimator'] = 'yes';
		}
		
		return $this->render ( "OfficeBrainQuoteBundle:Quote:editShippingInfoForQuote.html.twig", $data );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *        
	 *         Description : Use to show the list of product in this quote for edit part.
	 *        
	 * @param
	 *        	1 : No paramater
	 *        	
	 * @return type : json
	 *        
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/edit-select-color-request-quote",
	 *         name="office_brain_quotebundle_quote_editselectColor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:editSelectColor.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function editSelectColorAction() {
		$this->initAction ();
		$standardImprintColor = $this->quoteManager->getStandardImprintColorInformation ();
		$pmsColor = $this->container->getParameter ( 'pms_color' );
		return 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' )
		);
	}
	
	/**
	 *
	 * @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}/quote-pms-colors",
	 *         name="office_brain_quotebundle_quote_pmscolor"
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:quotePmsColors.html.twig")
	 */
	public function quotePmsColorsAction() {
		$this->initAction ();
		$pmsColorValue = $this->quoteManager->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: 4532
	 *         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}/quote-add-imprint-location",
	 *         name="office_brain_quotebundle_quote_addimprintlocation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:addImprintLocation.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function addImprintLocationAction() {
		$this->initAction ();
		$data = array ();
		$data ['imprintLocation'] = $this->quoteManager->addImprintLocation ();
		$data ['confiSetting'] = $this->productDetailconfigurationRule;
		return $data;
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         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-quote",
	 *         name="office_brain_quotebundle_quote_getProductAttribute",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function getProductAttributeAction() {
		$this->initAction ();
		$productAttributes = $this->quoteManager->getSizeAttributeByColor ( $this->colorImageUrl );
		
		$shiType = $this->request->get ( 'shipping_type', null );
		if ($shiType != '') {
			$ShippingQtyBox = $this->quoteManager->getBlankColorQuantityValue ( $productAttributes );
			$html = $this->get ( 'twig' )->render ( "OfficeBrainQuoteBundle:Quote: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: 4532
	 *         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",
	 *         name="office_brain_quotebundle_quote_addimprintlocationsummary",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function addImprintLocationSummaryAction() {
		$this->initAction ();
		$addImprintLocation = $this->quoteManager->addImprintLocation ();
		$this->responseArray ['status'] = 'success';
		$this->responseArray ['data'] = $addImprintLocation;
		
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *        
	 *         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-quote-front",
	 *         name="office_brain_quotebundle_quote_selectMethod",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:selectMethod.html.twig")
	 *         @Method({"POST","GET"})
	 */
	public function selectMethodAction() {
		$this->initAction ();
		return $selectImprintMethod = $this->quoteManager->selectImprintMethod ();
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *        
	 *         Description : Use to show the list of product in this request quote.
	 *        
	 * @param
	 *        	1 : No paramater
	 *        	
	 * @return type : json
	 *        
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/select-color-quote",
	 *         name="office_brain_quotebundle_quote_selectColor",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST","GET"})
	 */
	public function selectColorAction() {
		$this->initAction ();
		$standardImprintColor = $this->quoteManager->getStandardImprintColorInformation ();
		$pmsColor = $this->container->getParameter ( 'pms_color' );
		return 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 
		);
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         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",
	 *         name="office_brain_quotebundle_quote_selectShippingType",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function selectShippingTypeAction() {
		$this->initAction ();
		$data = $this->quoteManager->getShippingType ();
		$data ['shipping_estimator'] = 'no';
		$productId = $this->request->get ( 'product_id' );
		$productDetail = $this->quoteManager->getProductDetailById ( $productId );
		if (array_key_exists ( 'shipping_information', $productDetail )) {
			if (array_key_exists ( 'free_on_board', $productDetail ['shipping_information'] )) {
				$data ['shipping_estimator'] = 'yes';
			}
		}
		$data ['userId'] = $this->userId;
		
		return $this->render ( "OfficeBrainQuoteBundle:Quote:standardShipping.html.twig", $data );
	}
	
	/**
	 *
	 * @author Employee Id: 4532
	 *         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",
	 *         name="office_brain_quotebundle_quote_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->quoteManager->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: 4532
	 *         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",
	 *         name="office_brain_quotebundle_quote_getshippingaddressbyid",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getShippingAddressById.html.twig")
	 *         @Method({"GET"})
	 */
	public function getShippingAddressByIdAction() {
		$this->initAction ();
		$this->response ['result'] = $this->quoteManager->getUserShippingAddresById ();
		$this->response ['addressId'] = $this->request->get ( 'contact_id', null );
		return $this->response;
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to convert inquiry to quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : NUll.
	 * @throws Exception: Null
	 *        
	 *         @Route("{_locale}/convert-request-info-quote",
	 *         name="office_brain_quotebundle_quote_convertreqinfotoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function convertReqInfoToQuoteAction() {
		$this->initAction ();
		$result = $this->quoteManager->convertToQuote ( $this->requestInfoManager );
		if ($result ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.success_message' );
			$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
					'quote_id' => $result ['data']->getId () 
			) );
		} else {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.error_message' );
		}
		
		unset ( $result );
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description : Use to convert inquiry to quote.
	 * @param
	 *        	1 : No paramater
	 * @return type : NUll.
	 * @throws Exception: Null
	 *        
	 *         @Route("{_locale}/convert-request-quote-quote",
	 *         name="office_brain_quotebundle_quote_convertreqquotetoquote",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function convertReqQuoteToQuoteAction() {
		$this->initAction ();
		$result = $this->quoteManager->convertToQuote ( $this->requestQuoteManager );
		if ($result ['status'] == "SUCCESS") {
			$this->responseArray ['status'] = 'success';
			$this->responseArray ['success_message'] = $this->get ( 'translator' )->trans ( 'admin.success_message' );
			$this->responseArray ['goto_url'] = $this->generateUrl ( 'office_brain_quotebundle_quote_quote', array (
					'quote_id' => $result ['data']->getId () 
			) );
		} else {
			$this->responseArray ['error'] = 'error';
			$this->responseArray ['error_message'] = $this->get ( 'translator' )->trans ( 'admin.error_message' );
		}
		unset ( $result );
		return new JsonResponse ( $this->responseArray );
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *         Description :Replace product image
	 *        
	 *        
	 *         @Route("/{_locale}/replace-product-image",
	 *         name="office_brain_quotebundle_quote_replaceproductimage",
	 *         options={"expose"=true}
	 *         )
	 *         @Template()
	 *         @Method({"POST"})
	 */
	public function replaceProductImageAction() {
		$this->initAction ();
		$replaceImage = $this->quoteManager->replaceProductImage ( $this->filePath, $this->replaceImagePath );
		echo $replaceImage;
		die ();
	}
	
	/**
	 *
	 * @author Employee Id: 4248
	 *         Description : Use to render distributor info form.
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("/{_locale}/get-quote-distributor-info",
	 *         name="office_brain_quotebundle_quote_getquotedistributorinfo",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:getQuoteDistributorInfo.html.twig")
	 *         @Method({"GET"})
	 */
	public function getQuoteDistributorInfoAction() {
		$this->initAction ();
		$quoteId = $this->request->get ( 'quote_id', null );
		$userObj = $this->getCustomerDetailFromQuote ( $quoteId );
		$this->responseArray ['userData'] = $userObj;
		return $this->responseArray;
	}
	
	/**
	 *
	 * @author Employee Id:
	 * @param
	 *        	1 : No paramater
	 * @return type : Null.
	 * @throws Exception: Null
	 *        
	 *         @Route("{_locale}/view-supplier-information-front",
	 *         name="office_brain_quotebundle_quote_viewsupplierinformation",
	 *         options={"expose"=true}
	 *         )
	 *         @Template("OfficeBrainQuoteBundle:Quote:viewSupplier.html.twig")
	 */
	public function viewSupplierInformationAction() {
		$this->initAction ();
		$this->responseArray ['supplierInformation'] = $this->quoteManager->getProductSupplierInformation ( $this->request->get ( 'product_id' ) );
		return $this->responseArray;
	}
}
