<?php

namespace OfficeBrain\Bundle\TaxBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


/**
 *
 * @author Employee Id: 4471
 *         OB eCommerce Product - tax management
 *         - shipping tax calculation
 *
 * @Route("", defaults={"rule_service"="rule_charges"})
 */
class ShippingTaxController extends Controller
{

	/**
	 *
	 * @author Employee Id: 4471
	 * 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->cultureProductId = null;
		$this->refererUrl = null;
		$this->productIdArray = null;
		$this->responseArray = array();
		$this->projectSetting = null;
		$this->productCultureIdArray = null;
		$this->productId = null;
		$this->productSlug = null;
		$this->productCultureId = null;
		$this->commonLibraryManager = null;
		$this->config = null;
		$this->productDetailconfigurationRule = null;
		$this->erpIntegration = null;
		$this->coreManager = null;
	}
	
	/**
	 *
	 * @author Employee Id: 4471
	 * To unset member variables
	 * @return NULL
	 */
	public function __destruct()
	{
		unset($this->user);
		unset($this->userId);
		unset($this->locale);
		unset($this->request);
		unset($this->refererUrl);
		unset($this->cultureId);
		unset($this->cultureProductId);
		unset($this->responseArray);
		unset($this->projectSetting);
		unset($this->productCultureIdArray);
		unset($this->productId);
		unset($this->productSlug);
		unset($this->productCultureId);
		unset($this->commonLibraryManager);
		unset($this->config);
		unset($this->productDetailconfigurationRule);
		unset($this->erpIntegration);
		unset($this->coreManager);
	}
	
	
	/**
	 *
	 * @author Employee Id: 4471
	 * Create various objects required action in this class
	 * @return NULL
	 */
	public function initAction()
	{
		$this->request = $this->getRequest();
		$this->productId = $this->request->get('product_id', null);
		$this->productSlug = $this->request->get('product_slug', null);
		$this->productCultureId = $this->request->get('culture_product_id', null);
		$this->projectSetting = $this->request->get('project_setting');
		$this->siteOwnerId = $this->projectSetting['site_owner_id'];
		$this->projectUserSetting = $this->request->get('project_user_setting');
		$this->user = $this->projectUserSetting['user_data'];
		$this->locale = $this->projectSetting['culture_code'];
		$this->userId = $this->projectSetting['user_id'];
		$this->instanceType = $this->projectSetting['instance_type'];
		$this->responseArray['product_id'] = $this->productId;
		$this->responseArray['status'] = 'error';
		$this->configurationRule = $this->projectSetting['configuration_rule']['transaction']['tax_management'];
		$this->taxManager = $this->get('office_brain_shipping_tax_manager');
		$this->commonLibraryManager = $this->get('office_brain_common_library');
		$this->sessionManager = $this->get('office_brain_session_manager');
		$this->productDetailManager = $this->get('office_brain_product_detail_manager');
		$this->coreManager = $this->get('office_brain_core_manager');
		$this->productDetailconfigurationRule = $this->projectSetting['configuration_rule']['transaction']['shopping_cart']['product_detail_popup'];
		$this->validationManager = $this->get('office_brain_validation_manager');
		$this->userContactBookManager = $this->get('office_brain_user_contact_book_manager');
		$this->userManager = $this->get('office_brain_user_manager');
		$this->erpIntegration = $this->projectSetting['configuration_rule']['erp_integration'];
		$this->page = $this->request->get('page', '1');
		//$this->recordsPerPage = $this->request->get('records_per_page', $this->configRule['list_front']['option']['no_of_product']);
	}
	
	
	/**
	 * @author Employee Id: 4471
	 * Description : get shipping tax according shipping address
	 * @param 1 : No paramater
	 * @return type : json
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/calculate-tax-shipping-wise",
	 * name="office_brain_taxbundle_tax_calculatetaxshippingwise",
	 * options={"expose"=true}
	 * )
	 * @Method({"POST"})
	 */
	public function calculateTaxShippingWiseAction()
	{
		$this->initAction();
		$this->requestQuoteManager=$this->get ( 'office_brain_request_quote_manager' );
		$dataCharges=array();
		
		$dataCharges=$this->requestQuoteManager->getAllChargesForDetailPage ();
		$product_total_prices=$this->requestQuoteManager->getTotalPriceChargesForDetailPage ($dataCharges);
		$result = $this->taxManager->calculateTaxShippingWise($dataCharges);
		$result['product_total_prices']=$product_total_prices;
		return new JsonResponse($result);
	}
	
}
