<?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 Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Form\FormError;


/**
 *
 *
 * @Route("", defaults={"rule_service"="rule_charges"})
 */
class QuoteAdminController extends Controller
{
	protected $user;
	protected $form;
	protected $request;
	protected $formData;
	protected $responseArray;
	
	/**
	 *
	 * @author Employee Id: 4203
	 *
	 * Desciption: Define member variables with thier default value
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function __construct(ContainerInterface $container=null)
	{
		$this->user = null;
		$this->form = null;
		$this->request = null;
		$this->formData = null;
		$this->commonLibraryManager = null;
		$this->responseArray = array();
		$this->locale = null;
		$this->productId = null;
		$this->productSlug = null;
		$this->searchParameterArray = array();
		$this->searchKeyWordsArray = array();
		$this->sortingParameterArray = array();
		$this->validationManager =null;
		$this->erpConfigrationField = null;		
		$this->queueApiManager = null;
	}
	
	/**
	 *
	 * @author Employee Id: 4217
	 * Desciption: Unset member variables
	 * @param NULL
	 * @return NULL
	 * @throws NULL
	 *
	 */
	public function __destruct()
	{
		unset($this->user);
		unset($this->form);
		unset($this->request);
		unset($this->formData);
		unset($this->commonLibraryManager);
		unset($this->productId);
		unset($this->productSlug);
		unset($this->locale);
		unset($this->productId);
		unset($this->productSlug);
		unset($this->locale);
		unset($this->searchParameterArray);
		unset($this->searchKeyWordsArray);
		unset($this->sortingParameterArray);
		unset($this->validationManager);
		unset($this->erpConfigrationField);
		unset($this->queueApiManager);
	}
	
	public function initAction()
	{
		$this->request = $this->getRequest();
		$this->projectSetting = $this->request->get('project_setting');
		$this->projectUserSetting = $this->request->get('project_user_setting');
		$this->erpConfigrationField = $this->projectSetting['configuration_rule']['erp_integration'];		
		$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->responseArray = array();
		$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->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->recordsPerPage = $this->request->get('records_per_page', $this->configurationRule['inline_view']['option']['no_of_product']);
		$this->recordsPerPage = $this->request->get('records_per_page', $this->configurationRule['list']['option']['no_of_product']);
		$this->validationManager = $this->get('office_brain_validation_manager');
		$this->filePath = $this->get('kernel')->getRootDir() . '/../web/';
		
		$this->requestInfoManager = $this->get('office_brain_request_info_manager');
		$this->requestQuoteManager = $this->get('office_brain_request_quote_manager');
		
        if ($this->has('office_brain_queue_api_manager')) {
            $this->request->attributes->set('object', 'Quote');
            $this->queueApiManager = $this->get('office_brain_queue_api_manager');
        }
        $this->productDetailconfigurationRule = $this->projectSetting ['configuration_rule'] ['transaction'] ['quote'] ['product_detail_popup'];
        $this->shippingEstimatorManager = $this->get('office_brain_shipping_estimator_manager_fedex');
	}
	
	/**
     * @author Employee Id: 4217
     * Description : Use to display quote list.
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/quote-list",
     * name="office_brain_quotebundle_quoteadmin_adminquotelist",
     * options={"expose"=true}
     * )
     * @Template()
     *
     */
    public function adminQuoteListAction()
    {
    	$this->initAction();
    	$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->getQuoteAdminList($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("/admin/{_locale}/create-quote",
     * name="office_brain_quotebundle_quoteadmin_createquote",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    public function createQuoteAction()
    {
    	$this->initAction();
    	/*$result = $this->quoteManager->addCreateQuoteAdmin();
    	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_quoteadmin_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');
    	}*/
    	
    	$this->responseArray['status'] = 'success';
    	$this->responseArray['success_message'] = '';
    	$this->responseArray['goto_url'] = $this->generateUrl('office_brain_page_admin_dashboard');
    	
    	unset($result);
    	return new JsonResponse($this->responseArray);
    }
    
    /**
     * @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: 4203
     * Description : Use to configure this quote.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/quote/{quote_id}/{mode}",
     * name="office_brain_quotebundle_quoteadmin_quote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    public function quoteAction($mode="create")
    {
    	return $this->redirect($this->generateUrl('office_brain_page_admin_dashboard'));
    	
    	/*$this->initAction();
    	$quoteDetail = $this->quoteManager->isQuoteExists();
    	
    	$this->quoteManager->updateQuoteStatus($quoteDetail);
    	if ($quoteDetail!=NULL) {
    		$userObj = $this->getCustomerDetailFromQuote($quoteDetail->getId());
    		$this->responseArray['data'] = $quoteDetail;
    		$this->responseArray['userData'] = $userObj;
    		if($mode=="edit"){
    			$this->responseArray['mode'] = 'edit' ;
    		}else{
    			$this->responseArray['mode'] = 'create' ;
    		}
    		unset($quoteDetail);
    		return $this->responseArray;
    	}
    	else
    	{
    		return $this->redirect($this->generateUrl('office_brain_quotebundle_quoteadmin_adminquotelist'));
    	}*/
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to add product in this quote.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/add-product-to-quote",
     * name="office_brain_quotebundle_quoteadmin_addProductquote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    public function addProductQuoteAction()
    {
    	$this->initAction();
    	$result = $this->quoteManager->addProductToQuote();
    	if($result['status']=="SUCCESS"){
    		$this->responseArray['status'] = 'success';
    		$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('admin.product_error_message');
    	}
    	unset($result);
    	return new JsonResponse($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("/admin/{_locale}/get-product-info-to-quote",
     * name="office_brain_quotebundle_quoteadmin_getproductinfotoquote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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: 4532
     * Description : Use to edit product in this quote.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/edit-product-to-quote-admin",
     * name="office_brain_quotebundle_quoteadmin_editquoteproduct",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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['size_allow'] = $this->quoteManager->checkSizeAllow($this->responseArray['product_detail']['category']);
    	$this->responseArray ['request_quote_session'] =  $this->quoteManager->getInputDataForEdit($itemLineId);
    	return $this->responseArray;
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to render Shipping Address By Id
     * @Route("/{_locale}/quote-admin-get-shipping-address-by-id-summary",
     * name="office_brain_quotebundle_quoteadmin_getshippingaddressbyidsummary"
     * )
     * @Template()
     */
    public function getShippingAddressByIdSummaryAction()
    {
    	$this->initAction();
    	$this->response['result'] = $this->quoteManager->getUserShippingAddresById();
    	$this->response['addressId'] = $this->request->get('contact_id',null);
    	return $this->response;
    }
    
    /**
     * @author Employee Id: 4532
     * Description : Use to save quote information in to quoate master table.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/save-quote-information",
     * name="office_brain_quotebundle_quoteadmin_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: 4203
     * Description : Use to get all product list added in this quote.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/get-all-quote-product/{quote_id}",
     * name="office_brain_quotebundle_quoteadmin_getProductList",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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 remove itemline product.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/remove-item-line-product",
     * name="office_brain_quotebundle_quoteadmin_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: 4532
     * Description : Use to search product from solr.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/search-product-for-quote",
     * name="office_brain_quotebundle_quoteadmin_searchproductforquote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    public function searchProductForQuoteAction()
    {	
    	$this->initAction();
    	return array('ob_id'=>substr($this->user->getObCustomerId(),2));
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to render customer info form.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/add-new-customer-to-quote/{quote_id}",
     * name="officebrain_quote_bundle_add_newcustomer_to_quote",
     * options={"expose"=true}
     * )
     * @Template()
     */
 	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("/admin/{_locale}/edit-customer-to-quote/{user_id}/{quote_id}",
     * name="officebrain_quote_bundle_edit_customer_to_quote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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: 4488
     * Description : Use to render distributor info form.
     *
     * @Route("/admin/{_locale}/get-quote-distributor-info",
     * name="office_brain_quotebundle_quote_getdistributorinfo",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin: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 ;
    	$this->responseArray['quote_id'] = $quoteId ;
    	return $this->responseArray;
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to render customer billing info form.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/edit-customer-billing-to-quote",
     * name="officebrain_quote_bundle_edit_customer_billing_to_quote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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("/admin/{_locale}/save-new-customer-to-quote/{quote_id}",
     * name="officebrain_quote_bundle_save_new_contact",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin: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('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;
	    		}
	    		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: 4203
     * Description : Use to render customer info form.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/update-customer-to-quote/{quote_id}",
     * name="officebrain_quote_bundle_update_customer_to_quote",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin:editCustomerToQuote.html.twig")
     */
    public function updateCustomerToQuoteAction()
    {
    	$this->initAction();
    	$quoteId = $this->request->get('quote_id', null);
    	$userObj = $this->getCustomerDetailFromQuote($quoteId);
    	$orignalPhoto = $userObj->getPhoto();
    	$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;
    	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['quote_id'] = $quoteId;
    					$data['success_message'] = $this->get('translator')->trans('admin.customer_edit_success_message');
    					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: 4203
     * Description : Use to render customer billing info form.
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/update-customer-billing-to-quote/{user_id}",
     * name="officebrain_quote_bundle_update_customer_billing_to_quote",
     * options={"expose"=true}
     * )
     * @Method({"POST"})
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin: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: 
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/view-supplier-information",
     * name="office_brain_quotebundle_quoteadmin_viewsupplierinformation",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin:viewSupplier.html.twig")
     */
    
    public function viewSupplierInformationAction()
    {
    	$this->initAction();
    	$this->responseArray['supplierInformation']= $this->quoteManager->getProductSupplierInformation($this->request->get('product_id'));
    	return $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: 410175
     *
     * Description : Use to set session data for Request Quote
     *
     * @param 1 : No paramater
     *
     * @return type : json
     *
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/set-product",
     * name="office_brain_quotebundle_quoteadmin_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('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_quoteadmin_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("/admin/{_locale}/update-quote-product",
     * name="office_brain_quotebundle_quoteadmin_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('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_quoteadmin_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: 4493
     * 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_quoteadmin_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: 4493
     * Description : Use to render Billing Address By Id
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     * @Route("/admin/{_locale}/get-billing-address-by-id/{quote_id}",
     * name="office_brain_quotebundle_quoteadmin_getbillingaddressbyid",
     * options={"expose"=true}
     * )
     * @Template()
     * @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("/admin/{_locale}/get-all-address-by-quote/{quote_id}",
     * name="office_brain_quotebundle_quoteadmin_getalladdressbyquote",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin: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:
     * @param 1 : No paramater
     * @return type : Null.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/preview-quote/{quote_id}",
     * name="office_brain_quotebundle_quoteadmin_previewquote",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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 ;
    		return $this->responseArray;
    	}else{
    		return $this->redirect($this->generateUrl('office_brain_quotebundle_quoteadmin_adminquotelist'));
    	}
    }
    
    /**
     * @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("/admin/{_locale}/get-all-quote-product-preview/{quote_id}",
     * name="office_brain_quotebundle_quoteadmin_getpreviewquoteproductList",
     * options={"expose"=true}
     * )
     * @Template()
     */
    public function getPreviewQuoteProductListAction()
    {
    	$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
     * Description : Use to delete a record
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *	
     * @Route("/admin/{_locale}/delete-quote",
     * name="office_brain_quotebundle_quoteadmin_admindeletequote",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    public function adminDeleteQuoteAction()
    {
    	$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 delete a user from quote
     * @param 1 : No paramater
     * @return type : Form view and data.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/admin-delete-quote-user-contact",
     * name="officebrain_quote_bundle_admin_delete_quote_user_contact",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    public function adminDeleteQuoteUserContactAction()
    {
    	$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: 4203
     * Description : Use to hide show funcationality
     * @param 1 : No paramater
     * @return type : Ajax response.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/hide-show",
     * name="officebrain_quote_bundle_admin_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: 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("/admin/{_locale}/send-quote",
     * name="officebrain_quote_bundle_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':
    			$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_quoteadmin_adminquotelist');
    			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);
	                    }
                    }
    				// LETS CHECK new_quote_id IS THERE OR NOT
    				if(isset($status['new_quote_id']))
    				{
    					foreach($status['new_quote_id'] as $newQuoteId)
    					{
    						$newQuoteObj = $this->quoteManager->isQuoteExists($newQuoteId);
    						$this->queueApiManager->mapQueue('create', $newQuoteObj);
    					}
    				}
    			}
    			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("/admin/{_locale}/duplicate-quote",
     * name="officebrain_quote_bundle_duplicate_quote",
     * 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':
    			$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_quoteadmin_adminquotelist');
    			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
     * 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("/admin/{_locale}/edit-shipping-method",
     * name="office_brain_quotebundle_quoteadmin_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:QuoteAdmin: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("/admin/{_locale}/admin-edit-select-color-request-quote",
     *         name="office_brain_quotebundle_quoteadmin_editselectColor",
     *         options={"expose"=true}
     *         )
     *         @Template()
     *         @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' )
    	);
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to hide show funcationality
     * @param 1 : No paramater
     * @return type : Ajax response.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/hide-show-itemline",
     * name="officebrain_quote_bundle_admin_hide_show_itemline",
     * 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: 4532
     *
     * Desciption: This function allow user to download quote preview.
     *
     * @param integer quoteId
     *
     * @return download file on requested formate
     *
     * @throws NULL
     *
     * @Route("/admin/{_locale}/quote-product-download/{quote_id}",
     * 	name="office_brain_quotebundle_quoteadmin_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 ;
    		$this->responseArray['file_path'] = $this->filePath;
    		$response = $this->render('OfficeBrainQuoteBundle:QuoteAdmin:downloadQuoteProduct.html.twig', $this->responseArray);
    		if ($quoteDetail->getQuoteTitle()!='') {
    			$quoteName = str_replace(' ', '_',$quoteDetail->getQuoteTitle());
    		}
    		else {
    			$quoteName = $quoteDetail->getId();
    		}
    		$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_quoteadmin_quote', array('quote_id'=>$quoteId)));
    	}
    }
    
    /**
     * @author Employee Id: 4203
     * Description : Use to add addtional charges
     * @param 1 : No paramater
     * @return type : Ajax response.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/add-addtional-charges",
     * name="officebrain_quote_bundle_admin_addadditionalcharges",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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("/admin/{_locale}/remove-addtional-charges",
     * name="officebrain_quote_bundle_admin_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') {
                    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("/admin/{_locale}/update-all-charges",
     * name="officebrain_quote_bundle_admin_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()->getItemLineAmount();
    	}
    	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("/admin/{_locale}/update-additional-charges",
     * name="officebrain_quote_bundle_admin_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("/admin/{_locale}/update-itemline-discount",
     * name="officebrain_quote_bundle_admin_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("/admin/{_locale}/display-message-box",
     * name="officebrain_quote_bundle_admin_displaymessagebox",
     * options={"expose"=true}
     * )
     * @Template()
     */
    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("/admin/{_locale}/edit-imprint-location",
     * name="officebrain_quote_bundle_admin_editimprintlocation",
     * options={"expose"=true}
     * )
     * @Template()
     * @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;
    	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("/admin/{_locale}/quote-admin-select-method-edit",
     * name="officebrain_quote_bundle_admin_editselectMethod",
     * options={"expose"=true}
     * )
     * @Template("OfficeBrainQuoteBundle:QuoteAdmin: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: 4203
     * Description : Use to convert inquiry to quote.
     * @param 1 : No paramater
     * @return type : NUll.
     * @throws Exception: Null
     *
     * @Route("/admin/{_locale}/convert-request-info-quote",
     * name="office_brain_quotebundle_quoteadmin_convertreqinfotoquote",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    public function convertReqInfoToQuoteAction()
    {
    	$this->initAction();
    	$result = $this->quoteManager->convertToQuoteAdmin($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_quoteadmin_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("/admin/{_locale}/convert-request-quote-quote",
     * name="office_brain_quotebundle_quoteadmin_convertreqquotetoquote",
     * options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    public function convertReqQuoteToQuoteAction()
    {
    	$this->initAction();
    	$result = $this->quoteManager->convertToQuoteAdmin($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_quoteadmin_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}/admin-replace-product-image",
     *  name="office_brain_quotebundle_quote_adminreplaceproductimage",
     *  options={"expose"=true}
     * )
     * @Template()
     * @Method({"POST"})
     */
    
    public function replaceProductImageAction()
    {
    	$this->initAction ();
    	$replaceImage = $this->quoteManager->replaceProductImage($this->filePath, $this->replaceImagePath);
    	echo $replaceImage;
    	die;
    }
    
    /*
     * Created By 4488
     * For Custom Error     
     */
    public function getErrorsAsArray($form)
    {
    	$errors = array();
    	foreach ($form->getErrors() as $error) {
    		$errors[] = $error->getMessage();
    	}
    
    	foreach ($form->all() as $key => $child) {
    		if ($err = $this->getErrorsAsArray($child)) {
    			$errors[$key] = $err;
    		}
    	}
    
    	return $errors;
    }	
}
