Subversion Repositories SmartDukaan

Rev

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

<?php
App::uses('AppController', 'Controller');
/**
 * Skuschemes Controller
 *
 * @property Skuscheme $Skuscheme
 * @property PaginatorComponent $Paginator
 */
class SkuschemesController extends AppController {

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

        public $apihost;

        public function beforeFilter() {
                parent::beforeFilter();
//              Configure::load('live');
                $this->apihost = Configure::read('pythonapihost');
        }
/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $page = $this->request->query('page');
                if(!isset($page)){
                        $page = 1;
                }
                $limit = Configure::read('admindashboardlimit');
                $offset = ($page - 1)*$limit;
                $url = $this->apihost."discountInfo/getAllSkuSchemeDetails/?limit=$limit&offset=$offset";
                $response = $this->make_request($url,null);
                $this->set('skuschemes',$response);
                $this->set('page',$page);
                // $this->Skuscheme->recursive = 0;
                // $this->set('skuschemes', $this->Paginator->paginate());
        }

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_search() {
                $type = $this->request->query('type');
                $search = $this->request->query('search');                              
                $url = $this->apihost."Catalog/searchProducts/?class=SkuSchemeDetails&$type=$search";
                $response = $this->make_request($url,null);
                $this->set('skuschemes', $response);
                $this->set('page',1);
                $this->render('admin_index');
        }

        public function admin_searchdp() {
                $type = $this->request->query('type');
                $search = $this->request->query('search');                              
                $url = $this->apihost."Catalog/searchProducts/?class=SkuDealerPrices&$type=$search";
                $response = $this->make_request($url,null);
                $this->set('dealerprices', $response);
                $this->set('page',1);
                $this->render('admin_dp');
        }

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $data = $this->request->data['Skuscheme'];
                        $url = $this->apihost."discountInfo/addSkuSchemeDetails";
                        $url = $this->generateMultiUrl($url,$data);
                        $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
                        $response = $this->make_request($url,$jsonVar);
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }                       
                }
        }

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

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
        public function admin_delete($id = null) {              
                if ($this->remove($id,'SkuSchemeDetails')) {
                        $this->Session->setFlash(__('The sku scheme deal has been deleted.'));
                } else {
                        $this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }

        public function admin_deletedp($id = null) {            
                if ($this->remove($id,'SkuDealerPrices')) {
                        $this->Session->setFlash(__('The sku scheme deal has been deleted.'));
                } else {
                        // $this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
                }
                return $this->redirect(array('action' => 'index'));
        }
        
        public function admin_dp(){             
                $page = $this->request->query('page');
                if(!isset($page)){
                        $page = 1;
                }
                $limit = Configure::read('admindashboardlimit');
                $offset = ($page - 1)*$limit;
                $url = $this->apihost."dealerPrices/getAllDealerPrice/?limit=$limit&offset=$offset";
                $response = $this->make_request($url,null);
                $this->set('dealerprices',$response);
                $this->set('page',$page);
        }

        public function admin_adddp() {
                if ($this->request->is('post')) {
                        $data = $this->request->data['Skuscheme'];
                        $url = $this->apihost."dealerPrices/addDealerPrice";
                        $url = $this->generateMultiUrl($url,$data);
                        $jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
                        $response = $this->make_request($url,$jsonVar);
                        if (key($response)) {
                                $this->Session->setFlash(current($response));
                                return $this->redirect(array('action' => 'admin_dp'));
                        } else {
                                $this->Session->setFlash(current($response));
                        }                       
                }
        }
}