Subversion Repositories SmartDukaan

Rev

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

<?php
App::uses('AppController', 'Controller');
/**
 * AppTransactions Controller
 *
 * @property AppTransaction $AppTransaction
 * @property PaginatorComponent $Paginator
 */
class AppTransactionsController extends AppController {

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

        public function beforeFilter()
    {
       parent::beforeFilter();
       $this->Paginator->settings=array(
              'limit'=>100
       );
    } 
/**
 * index method
 *
 * @return void
 */
        public function index() {
                $this->AppTransaction->recursive = 0;
                $this->set('appTransactions', $this->Paginator->paginate());
        }

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

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

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

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

/**
 * admin_index method
 *
 * @return void
 */
        public function admin_index() {
                $this->AppTransaction->recursive = 0;
                $this->set('appTransactions', $this->Paginator->paginate(array('AppTransaction.' . $this->AppTransaction.'payout_description'=>'Approved')));
        }

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

/**
 * admin_add method
 *
 * @return void
 */
        public function admin_add() {
                if ($this->request->is('post')) {
                        $this->AppTransaction->create();
                        if ($this->AppTransaction->save($this->request->data)) {
                                $this->Session->setFlash(__('The app transaction has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The app transaction 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->AppTransaction->exists($id)) {
                        throw new NotFoundException(__('Invalid app transaction'));
                }
                if ($this->request->is(array('post', 'put'))) {
                        if ($this->AppTransaction->save($this->request->data)) {
                                $this->Session->setFlash(__('The app transaction has been saved.'));
                                return $this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
                        }
                } else {
                        $options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
                        $this->request->data = $this->AppTransaction->find('first', $options);
                }
        }

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

        public function admin_retailer(){

                $this->AppTransaction->recursive = -1;
                #$data = $this->request->data;
                #$date = date('Y-m-d',time()-86400);            
                $this->Paginator->settings = array(
                'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
                'conditions' => array('Date(AppTransaction.transaction_time)'=>'2015-08-28'),
                'group' => 'app_id'
                );
                $approvedCounts =  $this->Paginator->paginate();
                $sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='2015-08-28' and payout_description='Approved' group by app_id";
                $approved = $this->AppTransaction->query($sql);
                #debug($approved);
                foreach ($approved as $key => $value1) {
                        $app_id=$value1['app_transactions']['app_id'];
                        $value22=$value1['0']['count(1)'];
                        foreach ($approvedCounts as $key2 => $value) {
                                 debug($value);
                                 if($app_id==$value['AppTransaction']['app_id']){
                                        $approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
                                        $approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value['AppTransaction']['count'])*100);
                                 }else{
                                        $approvedCounts[$key2]['AppTransaction']['approved'] = 0;
                                        $approvedCounts[$key2]['AppTransaction']['conversion_percentage']=0;
                                 }
                        }
                        #debug($value['AppTransaction']['app_name']);
                }
                // $this->Paginator->settings = array(
         //     'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
         //     'conditions' => array('AppTransaction.payout_description'=>'Approved','Date(AppTransaction.transaction_time)'=>$date),
         //     'group' => 'app_id'
         //     );

                // debug($approvedCounts);
            #$this->set('items', $this->Paginator->paginate('Item'));
        #       $this->Paginator->paginate(array('AppTransaction.' . $this->AppTransaction.'payout_description'=>'Approved'))
                $this->set('appTransactions', $approvedCounts);
        }
}