<?php defined('BASEPATH') OR exit('No direct script access allowed'); 
        
    /**
     * Ajax
     */
    class Ajax extends CI_Controller { 
        var $perPage;
        var $ajax_pagination;
        function __construct() { 
            parent::__construct(); 
            // $this->db->query("SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));");
            cek_session_login(); 
            $this->perPage = 10; 
        } 
                
        /**
         * ajaxPengeluaran
         *
         * @return void
         */
        function ajaxPengeluaran(){
            // cek_session_login(); 
            $page = $this->input->post('page',true); 
            if(!$page){ 
                $offset = 0; 
                }else{ 
                $offset = $page; 
            } 
            
            $limits = $this->input->post('limits'); 
            if(!empty($limits)){ 
                $limit = $limits; 
                }else{ 
                $limit = $this->perPage; 
            } 
            // $conditions['where'] = array('pos' => 'Y');
            $sortBy = $this->input->post('sortBy'); 
            $user = $this->input->post('user'); 
            
            if(!empty($_POST['dari'])){
                $dari = date_slash($_POST['dari']);
                $conditions['search']['dari'] = $dari; 
            }
            if(!empty($_POST['sampai'])){ 
                $sampai = date_slash($_POST['sampai']);
                $conditions['search']['sampai'] = $sampai; 
            }
            
            if(!empty($sortBy)){ 
                $conditions['search']['sortBy'] = $sortBy; 
            } 
            
            if(!empty($user)){ 
                $conditions['where'] = array(
                'pengeluaran.id_user' =>$user
                );	
            } 
            
            // Get record count 
            $conditions['returnType'] = 'count'; 
            $totalRec = $this->model_data->getPengeluaran($conditions); 
            
            // Pagination configuration 
            $config['target']      = '#dataListPengeluaran'; 
            $config['base_url']    = base_url('ajax/ajaxPengeluaran'); 
            $config['total_rows']  = $totalRec; 
            $config['per_page']    = $limit; 
            $config['link_func']   = 'FilterPengeluaran'; 
            
            // Initialize pagination library 
            $this->ajax_pagination->initialize($config); 
            
            // Get records 
            $conditions['start'] = $offset; 
            $conditions['limit'] = $limit;
            
            if(!empty($_POST['dari'])){
                $dari = date_slash($_POST['dari']);
                $conditions['search']['dari'] = $dari; 
            }
            if(!empty($_POST['sampai'])){ 
                $sampai = date_slash($_POST['sampai']);
                $conditions['search']['sampai'] = $sampai; 
            }
            
            if(!empty($user)){ 
                $conditions['where'] = array(
                'pengeluaran.id_user' =>$user
                );	
            } 
            unset($conditions['returnType']); 
            $data['result'] = $this->model_data->getPengeluaran($conditions); 
            
            // Load the data list view 
            $this->load->view('pengeluaran/ajax-pengeluaran', $data); 
        }
                
           
        /**
         * ajaxPengeluaranProduk
         *
         * @return void
         */
        function ajaxPengeluaranProduk(){
            // cek_session_login(); 
            $page = $this->input->post('page'); 
            if(!$page){ 
                $offset = 0; 
                }else{ 
                $offset = $page; 
            } 
            
            $limits = $this->input->post('limits'); 
            if(!empty($limits)){ 
                $limit = $limits; 
                }else{ 
                $limit = $this->perPage; 
            } 
            $sortBy = $this->input->post('sortBy'); 
            $user = $this->input->post('user'); 
            $jenis = $this->input->post('jenis'); 
            
            if(!empty($_POST['dari'])){
                $dari = date_slash($_POST['dari']);
                $conditions['search']['dari'] = $dari; 
            }
            if(!empty($_POST['sampai'])){ 
                $sampai = date_slash($_POST['sampai']);
                $conditions['search']['sampai'] = $sampai; 
            }
            
            if(!empty($sortBy)){ 
                $conditions['search']['sortBy'] = $sortBy; 
            } 
            if(!empty($jenis)){ 
                $conditions['search']['jenis'] = $jenis; 
            } 
            if(!empty($user)){ 
                $conditions['where'] = array(
                'pengeluaran.id_user' =>$user
                );	
            } 
            // Get record count 
            $conditions['returnType'] = 'count'; 
            $totalRec = $this->model_data->getPengeluaranPerproduk($conditions); 
            
            // Pagination configuration 
            $config['target']      = '#dataListPengeluaran'; 
            $config['base_url']    = base_url('ajax/ajaxPengeluaranProduk'); 
            $config['total_rows']  = $totalRec; 
            $config['per_page']    = $limit; 
            $config['link_func']   = 'FilterPengeluaran'; 
            
            // Initialize pagination library 
            $this->ajax_pagination->initialize($config); 
            // Get records 
            $conditions['start'] = $offset; 
            $conditions['limit'] = $limit;
            if(!empty($user)){ 
                $conditions['where'] = array(
                'pengeluaran.id_user' =>$user
                );	
            } 
            
            unset($conditions['returnType']); 
            $data['jenis']  = $this->model_app->view_where('jenis_pengeluaran',['id_jenis'=>$this->input->post('jenis')])->row();
            $data['result'] = $this->model_data->getPengeluaranPerproduk($conditions); 
            
            // Load the data list view 
            $this->load->view('pengeluaran/ajax-pengeluaran-jenis', $data); 
        }        
        /**
         * 2023-07-23 01:03:56
         * ajaxRekap
         *
         * @return void
         */
        function ajaxRekap(){
            
            $page = $this->input->post('page'); 
            if(!$page){ 
                $offset = 0; 
                }else{ 
                $offset = $page; 
            } 
            
            $limits = $this->input->post('limits'); 
            if(!empty($limits)){ 
                $limit = $limits; 
                }else{ 
                $limit = $this->perPage; 
            } 
            
            //$conditions['search']['dari'] = date('Y-m-d'); 
            $sortBy = $this->input->post('sortBy'); 
            $user = $this->input->post('id_kasir'); 
            if(!empty($user)){ 
                $conditions['search']['id_kasir'] = $user; 
            } 
            if(!empty($_POST['dari'])){
                $dari = date_slash($_POST['dari']);
                $conditions['search']['dari'] = $dari; 
            }
            if(!empty($_POST['sampai'])){ 
                $sampai = date_slash($_POST['sampai']);
                $conditions['search']['sampai'] = $sampai; 
            }
            
            if(!empty($sortBy)){ 
                $conditions['search']['sortBy'] = $sortBy; 
            } 
            
            
            // Get record count 
            $conditions['returnType'] = 'count'; 
            $totalRec = $this->model_data->getRekap($conditions); 
            
            // Pagination configuration 
            $config['target']      = '#dataList'; 
            $config['base_url']    = base_url('ajax/ajaxRekap'); 
            $config['total_rows']  = $totalRec; 
            $config['per_page']    = $limit; 
            $config['link_func']   = 'searchRekap'; 
            
            // Initialize pagination library 
            $this->ajax_pagination->initialize($config); 
            
            // Get records 
            $conditions['start'] = $offset; 
            $conditions['limit'] = $limit;
            unset($conditions['returnType']); 
            $data['result'] = $this->model_data->getRekap($conditions); 
            
            // Load the data list view 
            $this->load->view('pembukuan/ajax-rekapan', $data, false); 
        }
    }            