Subversion Repositories SmartDukaan

Rev

Rev 15051 | Rev 19768 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');
/**
 * Retailers Controller
 *
 * @property Retailer $Retailer
 * @property PaginatorComponent $Paginator
 */
class RetailersController extends AppController {

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

/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->layout = 'ajax';
                $this->Retailer->recursive = 0;
                $options = array('conditions'=>array('status' =>'new'));        
                $result = $this->Retailer->find('first',$options);
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }
public function notificationactive(){
                $retailerId = $this->request->query('retailerid');
                $options = array('conditions' => array('id'=> $retailerId,'status'=>'new','expiresAt >'=>date('Y-m-d H:i:s',time())));
                $count = $this->NotificationCampaign->find('count',$options);
                
                if(!$count){
                        $result = array('success'=>false);
                }else{
                        $result = array('success'=>true);
                }
                
                $this->response->type('json');
                $this->layout = 'ajax';
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }

        /*public function index() {     
                $this->layout = 'ajax';
                $t = $this->request->query('t');
                $retailer = $this->Mobileappsetting->find('one',$options);
                $options = array('fields'=>array("unix_timestamp(modified) t"),'order'=>array('modified'=>'desc'));
                $lasttimestamp = $this->Mobileappsetting->find('first',$options);               
                $result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t']);
                $this->set(array(
                    'result' => $result,
                    '_serialize' => array('result')
                ));
                $this->render('/Elements/json');
        }*/
/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function view($id = null) {
                if (!$this->Retailer->exists($id)) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                $options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
                $this->set('retailer', $this->Retailer->find('first', $options));
        }

/**
 * add method
 *
 * @return void
 */
        public function add() {
                if ($this->request->is('post')) {
                        $this->Retailer->create();
                        if ($this->Retailer->save($this->request->data)) {
                                $this->Session->setFlash(__('The retailer has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
                        }
                }
        }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function edit($id = null) {
                if (!$this->Retailer->exists($id)) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Retailer->save($this->request->data)) {
                                $this->Session->setFlash(__('The retailer has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
                        $this->request->data = $this->Retailer->find('first', $options);
                }
        }

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function delete($id = null) {
                $this->Retailer->id = $id;
                if (!$this->Retailer->exists()) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->Retailer->delete()) {
                        $this->Session->setFlash(__('The retailer has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The retailer could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }

/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $this->Retailer->recursive = 0;
                $this->set('retailers', $this->Paginator->paginate());
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_view($id = null) {
                if (!$this->Retailer->exists($id)) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                $options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
                $this->set('retailer', $this->Retailer->find('first', $options));
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->Retailer->create();
                        if ($this->Retailer->save($this->request->data)) {
                                $this->Session->setFlash(__('The retailer has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
                        }
                }
        }

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_edit($id = null) {
                if (!$this->Retailer->exists($id)) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->Retailer->save($this->request->data)) {
                                $this->Session->setFlash(__('The retailer has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
                        $this->request->data = $this->Retailer->find('first', $options);
                }
        }

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_delete($id = null) {
                $this->Retailer->id = $id;
                if (!$this->Retailer->exists()) {
                        throw new NotFoundException(__('Invalid retailer'));
                }
                $this->request->onlyAllow('post', 'delete');
                if ($this->Retailer->delete()) {
                        $this->Session->setFlash(__('The retailer has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The retailer could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }

        public function admin_pendingretailer(){
//              $options['conditions'] = array('status LIKE '=>"%$search%");
                $opt = array('conditions' => array('status'=> 'pending_verification'));
                $pending = $this->Retailer->find('all',$opt);
                $this->set(compact('pending'));
        }
        
        public function admin_retailerverify($id,$tin){
                $options['conditions'] = array('id'=> $id);
                $pending = $this->Retailer->find('first',$options);
                $result = $pending['Retailer'];
                $tinresult = "";
                if($tin != null){
                        $url = Configure::read('pythonapihost')."tinsearch?tin=".$tin;
                        $tinres = $this->make_request($url, null);
                        if(!$tinres['isError']){
                                $tinresult = $tinres;
                                $this->set(compact('tinresult'));
                        }
                }
                $this->set(compact('result'));
        }
        public function admin_verifycancel($id,$type){
                if($type == "verify"){
                        $retquery ="update retailers set status = 'retailer_verified' and isvalidated = 1  where id = ".$id."";
                        $this->Retailer->query($retquery);
                }else if($type == "cancel"){
                        $retquery ="update retailers set status = 'not_verified' where id = ".$id."";
                        $this->Retailer->query($retquery);
                }
                $this->redirect("pendingretailer");
        }
}