Subversion Repositories SmartDukaan

Rev

Rev 18969 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Exceptionalnlcs Controller
 *
 * @property Exceptionalnlc $Exceptionalnlc
 * @property PaginatorComponent $Paginator
 */
class TinsController extends AppController {

/**
 * Components
 *
 * @var array
 */
        public $components = array('Paginator');

        public function beforeFilter() {
                parent::beforeFilter();
                $this->Auth->allow(array('tin_search'));
                $this->apihost = Configure::read('pythonapihost');
                $this->mobileapihost = Configure::read('saholicapihost');
        }
        public function tin_search($tin_num = null) {
                $this->layout = 'ajax';
                $user_email = $this->Auth->user('email');
                $phone_number = $this->Auth->user('mobile_number');
                $this->loadModel("UserAccount");
                $opt = array('conditions'=>array('user_id'=>$this->Auth->user('id'),'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
                $usId = $this->UserAccount->find('first',$opt);
                $cuid = $usId['UserAccount']['account_key'];
                
                $url = $this->mobileapihost."counter?userId=".$cuid."&isLoggedIn=true&privateDealUser=true&tin=".$tin_num;
                $tinres = $this->make_request($url, null);
                if($tinres["response"]["counterExists"] == true)
                {       $tinres = $tinres["response"];
                        $this->set(compact('tinres'));
                        $this->render('existtin');
                }
                else{
                        //              $tinres = json_decode('{"pin_required" : "false" , "tin" : "07976957280" , "cst" : "07976957280","counter_name" : "E-RETAIL SHOP","counter_address" : "SHOP IN H. NO. 61 BLOCK B MOLAR BAND EXTN.,-110044" ,"state" : "North Delhi","pan" : "AEEPV9740C","registered_on" :"16/03/15 ","cst_status" : "Active","valid_since" :"06/07/15", "isError": false, "errorMsg": "Error message"}',true);
                        $url = $this->apihost."tinsearch?tin=".$tin_num;
                        $tinres = $this->make_request($url,null);
                        $pincheck = "nothing";
                        if($tinres['pin_required'] == false){
                                $pincheck = $tinres['pin'];
                        }
                        $this->set(compact('tinres' ,'tin_num','user_email','phone_number','pincheck'));
                        $this->render('/Elements/gettindetail');
                }
        }
        
        public function index() {
                $this->layout = "innerpages";
                $res = false;
                $this->loadModel("UserAccount");
//              $tinres = json_decode('{"pin_required" : "false" , "tin" : "07976957280" , "cst" : "07976957280","counter_name" : "E-RETAIL SHOP","counter_address" : "SHOP IN H. NO. 61 BLOCK B MOLAR BAND EXTN.,-110044" ,"state" : "North Delhi","pan" : "AEEPV9740C","registered_on" :"16/03/15 ","cst_status" : "Active","valid_since" :"06/07/15", "isError": false, "errorMsg": "Error message"}',true);
                $opt = array('conditions'=>array('user_id'=>$this->Auth->user('id'),'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
                $usId = $this->UserAccount->find('first',$opt);
                $cuid = $usId['UserAccount']['account_key'];
                $url = $this->mobileapihost."counter?userId=".$cuid."&isLoggedIn=true&privateDealUser=true";
                $tinres = $this->make_request( $url, null );
//              debug($tinres);
                $res = $tinres["response"]["counterExists"];
                $tinres= $tinres["response"];
                if($res == true){
//                      $this->redirect(array(
//                                      'controller' => 'tins', 'action' => 'showtin', 'tinres' => $tinres
//                      ));
                        $this->set(compact('tinres'));
                        $this->render('showtin');
                }
                
                
        }
        
        public function confirm(){
                $this->autoRender = false;
                $this->request->onlyAllow ( 'ajax' );
                $arr=array();
                $data = $this->request->data;
                
                $arr['tinMap'] = json_encode($data);
//              $senddata = $this->request->query('aParam');
                $this->loadModel('UserAccount');
                $opt = array('conditions'=>array('user_id'=>$this->Auth->user('id'),'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
                $usId = $this->UserAccount->find('first',$opt);
                $cuid = $usId['UserAccount']['account_key'];
                $url = $this->mobileapihost."register!registerTin?userId=".$cuid."&isLoggedIn=true&privateDealUser=true";
//              $url = "http://45.79.106.95:8080/mobileapi/register!registerTin?isLoggedIn=true&privateDealUser=true&userId=483649";
                $res = $this->post_request( $url, $arr, 'nojson' );
//              $this->redirect('/category/3');
                return  $res;
        }
        
        public function showtin(){
                $this->layout = "innerpages";
        }
        public function existtin(){
                $this->layout = "innerpages";
        }

}