<?php
namespace App\OfficeBrain\Bundle\OrderBundle\Controller;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\OrderBundle\Manager\Service\OrderService;
use App\OfficeBrain\Bundle\CoreBundle\Service\OBCommon;
use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
use App\OfficeBrain\Bundle\CoreBundle\Helper\Validation;
use App\OfficeBrain\Bundle\UserBundle\Manager\Service\UserService;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
*
* @author 4488
* @Route("{_locale}/")
*/
class CustomOrderController extends AbstractController
{
/**
* @author Employee Id: 4488
* set Default Value
*/
protected $user;
protected $projectUserSetting;
protected $tioryApiURL;
public function __construct(ContainerInterface $container, UserService $userService, SessionManager $sessionManager, Validation $validation, OrderService $orderService, RequestStack $requestStack, RouterInterface $router, ValidatorInterface $validatorInterface)
{
$commonLibraryManager = new OBCommon($router, $validatorInterface, $requestStack);
$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->orderManager = $orderService->getOrderManagerExtended();
$this->validationManager = $validation;
$this->userManager = $userService->getUserExtended();
$this->sessionManager = $sessionManager;
$this->commonLibraryManager = $commonLibraryManager;
$this->responseArray = array();
$this->projectSetting = null;
$this->productCultureIdArray = null;
$this->inlineViewProductMaxLimit = null;
$this->productId = null;
$this->productSlug = null;
$this->productCultureId = null;
$this->config = null;
$this->productDetailconfigurationRule = null;
$this->searchParameterArray = array();
$this->searchKeyWordsArray = array();
$this->tioryApiURL = null;
$this->serviceContainer = $container;
}
/**
*
* @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);
unset($this->tioryApiURL);
}
/**
*
* @author Employee Id: 4488
* Create various objects required action in this class
* @return NULL
*/
public function initAction(Request $request)
{
$this->request = $request;
$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->serviceContainer->get('office_brain_order_manager');
$this->orderManager = $this->orderManager;
// $this->commonLibraryManager = $this->serviceContainer->get('office_brain_common_library');
$this->commonLibraryManager = $this->commonLibraryManager;
// $this->sessionManager = $this->serviceContainer->get('office_brain_session_manager');
$this->sessionManager = $this->sessionManager;
// $this->validationManager = $this->serviceContainer->get('office_brain_validation_manager');
$this->validationManager = $this->validationManager;
// $this->userManager = $this->serviceContainer->get('office_brain_user_manager');
$this->userManager = $this->userManager;
$this->projectUserSetting = $this->request->get('project_user_setting');
$this->page = $this->request->get('page', '1');
$this->recordsPerPage = $this->request->get('records_per_page', 100);
$this->user = $this->projectUserSetting['user_data'];
$this->tioryApiURL = $this->serviceContainer->getParameter('tiory_url');
}
/**
* @author Employee Id: 4488
* Description : Order Status
* @Route("order-status",
* name="office_brain_orderbundle_customorder_order_status",
* options={"expose"=true}
* )
* @Template("OfficeBrain/Bundle/OrderBundle/Order/orderStatus.html.twig")
*/
public function orderStatusAction(Request $request)
{
$this->initAction($request);
if(!is_object($this->user))
{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
$this->responseArray['userObj']=$this->user;
return $this->responseArray;
}
/**
* @author Employee Id: 4488
* Description : Order Status
* @Route("cc-payment-status",
* name="office_brain_orderbundle_customorder_order_ccpayments",
* options={"expose"=true}
* )
* @Template("OfficeBrain/Bundle/OrderBundle/Order/ccpayment.html.twig")
*/
public function ccpaymentsAction(Request $request)
{
$this->initAction($request);
if(!is_object($this->user))
{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
// $userId = $this->user->getId();
$userAccountId = $this->user->getUserCompany()->getTioryCustomerAccountId();
//$userAccountId = 234;
$this->responseArray['records_per_page'] = $this->recordsPerPage;
$this->responseArray['page'] = $this->page;
$this->prepareSearchParameterArray();
$this->responseArray['data'] = $this->orderManager->getccPaymentList($userAccountId, $this->page,$this->recordsPerPage,$this->searchParameterArray,$this->searchKeyWordsArray);
$this->responseArray['total'] = $this->orderManager->getccTotalCountUserWise($userAccountId);
//print_r($this->responseArray);
//$this->responseArray['payment']=$this->orderManager->getCcpayments($userId,$userAccountId);
//die("Here");
$this->responseArray['userObj']=$this->user;
return $this->responseArray;
}
private function prepareSearchParameterArray()
{
$this->option = $this->request->get('option', null);
$this->keywords = $this->request->get('keyword', null);
$this->searchKeyWordsArray[$this->option]=trim($this->keywords);
}
/**
* @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("OfficeBrain/Bundle/OrderBundle/Order/orderStatusDetail.html.twig")
*/
public function orderStatusDetailAction(Request $request)
{
$this->initAction($request);
$data = $this->request->request->all();
$data['url'] = $this->tioryApiURL;
/*if(empty($data['aakronCustomer'])){
//$this->responseArray['recordSet'][]['errorMessage'] = "Customer Account is required";
$this->responseArray['fail']=1;
}*/
//print_r($this->container->getParameter('order_status_setting'));exit;
$this->responseArray['recordSet'][] = $this->orderManager->getOrderStatusDetails($data);
$this->responseArray['recordSet'][count($this->responseArray['recordSet'])]['order_status_setting']=$this->serviceContainer->getParameter('order_status_setting');
/*echo "<pre>";
print_r($this->responseArray); die;*/
//$this->responseArray['recordSet'][]=$this->orderManager->getOrderStatusDetails($this->responseArray['aakronCustomer'],$this->responseArray['aakronOrder'],$this->responseArray['aakronCustomerPO']);
/*$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("OfficeBrain/Bundle/OrderBundle/Order/orderInvoice.html.twig")
*/
public function orderInvoiceAction(Request $request)
{
$this->initAction($request);
if(!is_object($this->user))
{
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
$this->responseArray['userObj']=$this->user;
return $this->responseArray;
}
/**
* @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("OfficeBrain/Bundle/OrderBundle/Order/orderInvoiceDetail.html.twig")
*/
public function orderInvoiceDetailAction(Request $request)
{
$this->initAction($request);
$userAccountId = null;
if(is_object($this->user))
{
if($this->user->getUserCompany()!=null){
if($this->user->getUserCompany()->getTioryCustomerAccountId()!=null){
$userAccountId = $this->user->getUserCompany()->getTioryCustomerAccountId();
}
}
}
//$userAccountId = 194171;
$this->responseArray['aakronCustomer']=$this->request->get('aakronCustomer',$userAccountId);
$this->responseArray['aakronOrder']=$this->request->get('aakronOrder',null);
$this->responseArray['aakronCustomerPO']=$this->request->get('aakronCustomerPO',null);
$this->responseArray['aakronInvoiceNo']=$this->request->get('aakronCustomerPO',null);
$this->responseArray['aakronInvoiceType']=$this->request->get('aakronInvoceType',null);
$this->responseArray['aakronInvoiceReqDate']=$this->request->get('aakronInvoiceReqDate',null);
$this->responseArray['aakronInvoiceAvalDate']=$this->request->get('aakronInvoiceAvalDate',null);
$this->responseArray['aakronInvoiceStartDate']=$this->request->get('aakronInvoiceStartDate',null);
$this->responseArray['aakronInvoiceEndDate']=$this->request->get('aakronInvoiceEndDate',null);
if($this->responseArray['aakronCustomer'] !='' && $this->responseArray['aakronInvoiceType'] !='' && ($this->responseArray['aakronOrder']!='' || $this->responseArray['aakronCustomerPO']!='' || $this->responseArray['aakronInvoiceNo']!='' || $this->responseArray['aakronInvoiceReqDate']!='' || $this->responseArray['aakronInvoiceAvalDate']!='' || $this->responseArray['aakronInvoiceStartDate']!='' || $this->responseArray['aakronInvoiceEndDate'])){
$this->responseArray['recordSet'][]=$this->orderManager->getOrderInvoiceDetails($this->responseArray['aakronCustomer'],$this->responseArray['aakronOrder'],$this->responseArray['aakronCustomerPO'],$this->responseArray['aakronInvoiceNo'],$this->responseArray['aakronInvoiceType'],$this->responseArray['aakronInvoiceReqDate'],$this->responseArray['aakronInvoiceAvalDate'],$this->responseArray['aakronInvoiceStartDate'],$this->responseArray['aakronInvoiceEndDate'],'',$this->tioryApiURL);
}else{
//$this->responseArray['fail']=1;
if($this->responseArray['aakronCustomer'] !=''){
$this->responseArray['recordSet'][]=$this->orderManager->getOrderInvoiceDetails($this->responseArray['aakronCustomer'],$this->responseArray['aakronOrder'],$this->responseArray['aakronCustomerPO'],$this->responseArray['aakronInvoiceNo'],$this->responseArray['aakronInvoiceType'],$this->responseArray['aakronInvoiceReqDate'],$this->responseArray['aakronInvoiceAvalDate'],$this->responseArray['aakronInvoiceStartDate'],$this->responseArray['aakronInvoiceEndDate'],'no',$this->tioryApiURL);
}else{
$this->responseArray['fail']=1;
}
}
//print_r($this->responseArray); die;
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("OfficeBrain/Bundle/OrderBundle/Order/orderInvoiceDetailReport.html.twig")
*/
public function orderInvoiceReportAction(Request $request)
{
$this->initAction($request);
$this->responseArray['OrderNo']=$this->request->get('invoiceno',null);
$this->responseArray['recordSet']=$this->orderManager->getOrderInvoiceReport($this->responseArray['OrderNo']);
return $this->responseArray;
}
/**
* @author Vendor
* Description : Review Proof
* @Route("proof-review/{orderId}",
* name="office_brain_orderbundle_customorder_review_proof",
* options={"expose"=true}
* )
* @Template("OfficeBrain/Bundle/OrderBundle/Order/orderReviewProof.html.twig")
*/
public function orderProofReviewAction(Request $request, $orderId=0)
{
$this->initAction($request);
/* if(!is_object($this->user)){
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
}
*/
$this->responseArray['userObj']=$this->user;
$this->responseArray['orderId']=$orderId;
$this->responseArray['APIUrl']= "https://arc1967.tiory.com/api/";
$this->responseArray['attachmentBasePath']= "https://aakronline-erp.s3.amazonaws.com/";
return $this->responseArray;
}
/**
*
* @author Vendor
*
* Desciption: download pdf of proof
* @return Response
*
* @Route("download-order-review-proof/{orderId}",
* name="officebrain_custombundle_orderbundle_download_order_review_proof"
* )
*/
public function downloadOrderReviewProofAction(Request $request, $orderId)
{
$this->initAction($request);
$this->responseArray['userObj']=$this->user;
$this->responseArray['orderId']=$orderId;
$this->responseArray['APIUrl']= "https://arc1967.tiory.com/api/";
$this->responseArray['attachmentBasePath']= "https://aakronline-erp.s3.amazonaws.com/";
try{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://arc1967.tiory.com/api/en_us/proof-view/'.$orderId,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
$this->responseArray['privewDataPdf'] = json_decode($response,true);
$twigResponse = $this->render('project/OfficeBrain/CustomBundle/OrderBundle/Order/downloadOrderReviewProof.html.twig', $this->responseArray);
//echo $twigResponse->getContent();
return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($twigResponse->getContent()), 200, array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="E-proof.pdf"'
));
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
}
}