<?php

namespace OfficeBrain\Bundle\OrderBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
 *
 * @author 4488
 * @Route("{_locale}/", defaults={"rule_service"="rule_charges"})
 */
class CustomOrderController extends Controller
{
	/**
	 * @author Employee Id: 4488
	 * set Default Value
	 */
	protected $user;
	protected $projectUserSetting;
	
	public function __construct()
	{
		$this->request = null;
		$this->user = null;
		$this->userId = null;
		$this->locale = null;
		$this->cultureId = null;
		$this->session = null;
		$this->totalProduct = 0;
		$this->refererUrl = null;
		$this->productIdArray = null;
		$this->sessionManager = null;
		$this->responseArray = array();
		$this->projectSetting = null;
		$this->productCultureIdArray = null;
		$this->inlineViewProductMaxLimit = null;
		$this->productId = null;
		$this->productSlug = null;
		$this->productCultureId = null;
		$this->commonLibraryManager = null;
		$this->config = null;
		$this->productDetailconfigurationRule = null;
		$this->searchParameterArray = array();
		$this->searchKeyWordsArray = array();
	}
	/**
	 *
	 * @author Employee Id: 4488
	 * To unset member variables
	 * @return NULL
	 */
	public function __destruct()
	{
		unset($this->user);
		unset($this->userId);
		unset($this->locale);
		unset($this->session);
		unset($this->request);
		unset($this->refererUrl);
		unset($this->cultureId);
		unset($this->cultureProductId);
		unset($this->responseArray);
		unset($this->totalProduct);
		unset($this->entityManager);
		unset($this->productIdArray);
		unset($this->sessionManager);
		unset($this->projectSetting);
		unset($this->productCultureIdArray);
		unset($this->productId);
		unset($this->productSlug);
		unset($this->productCultureId);
		unset($this->inlineViewProductMaxLimit);
		unset($this->commonLibraryManager);
		unset($this->config);
		unset($this->searchParameterArray);
		unset($this->searchKeyWordsArray);
	}
	/**
	 *
	 * @author Employee Id: 4488
	 * 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->locale = $this->projectSetting['culture_code'];
		$this->userId = $this->projectSetting['user_id'];
		$this->instanceType = $this->projectSetting['instance_type'];
		$this->orderManager = $this->get('office_brain_order_manager');
		$this->commonLibraryManager = $this->get('office_brain_common_library');
		$this->sessionManager = $this->get('office_brain_session_manager');
		$this->validationManager = $this->get('office_brain_validation_manager');
		$this->userManager = $this->get('office_brain_user_manager');
		$this->projectUserSetting = $this->request->get('project_user_setting');
		
		$this->user = $this->projectUserSetting['user_data'];
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Order Status
	 * @Route("order-status",
	 * name="office_brain_orderbundle_customorder_order_status",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:orderStatus.html.twig")
	 */
	public function orderStatusAction()
	{
		$this->initAction();
		if(!is_object($this->user))
		{
			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
		}
		
		
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Order Status Detail ajax
	 * @Route("order-status-detail",
	 * name="office_brain_orderbundle_customorder_order_status_detail",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:orderStatusDetail.html.twig")
	 */
	public function orderStatusDetailAction()
	{
		$this->initAction();
		$this->responseArray['aakronCustomer']=$this->request->get('aakronCustomer',null);
		$this->responseArray['aakronOrder']=$this->request->get('aakronOrder',null);
		$this->responseArray['aakronCustomerPO']=$this->request->get('aakronCustomerPO',null);
		
		if($this->responseArray['aakronCustomer'] !='' && ($this->responseArray['aakronOrder']!='' || $this->responseArray['aakronCustomerPO']!='' ))
			$this->responseArray['recordSet'][]=$this->orderManager->getOrderStatusDetails($this->responseArray['aakronCustomer'],$this->responseArray['aakronOrder'],$this->responseArray['aakronCustomerPO']);
		else
			$this->responseArray['fail']=1;
		return $this->responseArray;
		
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Order Invoice
	 * @Route("order-invoice",
	 * name="office_brain_orderbundle_customorder_order_invoice",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:orderInvoice.html.twig")
	 */
	public function orderInvoiceAction()
	{
		$this->initAction();
		if(!is_object($this->user))
		{
			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
		}
	
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Order invoice list ajax
	 * @Route("order-invocie-list",
	 * name="office_brain_orderbundle_customorder_order_invoice_detail",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:orderInvoiceDetail.html.twig")
	 */
	public function orderInvoiceDetailAction()
	{
		$this->initAction();
		$this->responseArray['aakronCustomer']=$this->request->get('aakronCustomer',null);
		$this->responseArray['aakronOrder']=$this->request->get('aakronOrder',null);
		$this->responseArray['aakronCustomerPO']=$this->request->get('aakronCustomerPO',null);
		$this->responseArray['aakronInvoiceNo']=$this->request->get('aakronInvoiceNo',null);
		if($this->responseArray['aakronCustomer'] !='' && ($this->responseArray['aakronOrder']!='' || $this->responseArray['aakronCustomerPO']!='' || $this->responseArray['aakronInvoiceNo']!='' ))
			$this->responseArray['recordSet'][]=$this->orderManager->getOrderInvoiceDetails($this->responseArray['aakronCustomer'],$this->responseArray['aakronOrder'],$this->responseArray['aakronCustomerPO'],$this->responseArray['aakronInvoiceNo']);
		else 
			$this->responseArray['fail']=1;
		return $this->responseArray;
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Order invoice Detail Report ajax
	 * @Route("order-invocie-detail",
	 * name="office_brain_orderbundle_customorder_order_invoice_report",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainOrderBundle:Order:orderInvoiceDetailReport.html.twig")
	 */
	public function orderInvoiceReportAction()
	{
		$this->initAction();
		$this->responseArray['OrderNo']=$this->request->get('invoiceno',null);
		$this->responseArray['recordSet']=$this->orderManager->getOrderInvoiceReport($this->responseArray['OrderNo']);
		
		return $this->responseArray;
	}
}
