<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
ini_set('display_errors', 0);
#error_reporting(E_ALL ^ E_NOTICE);
//magazine
if ($_SERVER['HTTP_HOST'] == 'localhost') {
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/PHPExcel/Classes/PHPExcel.php";
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/PHPExcel/Classes/PHPExcel/Writer/Excel2007.php";
} elseif($_SERVER['HTTP_HOST'] == 'nurturecraftmagazines.com') {
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/PHPExcel/Classes/PHPExcel.php";
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/PHPExcel/Classes/PHPExcel/Writer/Excel2007.php";
} else {
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/smsystem/PHPExcel/Classes/PHPExcel.php";
    require_once $_SERVER['DOCUMENT_ROOT']."/magazine/smsystem/PHPExcel/Classes/PHPExcel/Writer/Excel2007.php";
}
class Financedepartment extends CI_Controller {

    /**
     * Function index
     * default functionality for the user.
     * Controllers default method.
     *
     * @author	Himanshu Charegaonkar
     * @access	public
     */
    public function index($pm_id = '')
    {
        $this->load->model('subscribers');

        # Check whether the session is set or not.
        if(! $this->session->userdata('username') ) {
            $strRedirectpath = base_url().'index.php/users/login';
            redirect($strRedirectpath);
        }

        if(!empty($pm_id)) {
            $fdrows = $this->db->get_where('finance_department', array('payment_method' => $pm_id))->result_array();
        }else {
            $fdrows = $this->db->get('finance_department')->result_array();    
        }
        
        $arrCampaign = $this->subscribers->fnGetDetails("campaigns");

        $arrData['arrCampaign']   = $arrCampaign;
        $arrData['fdrows']   = $fdrows;

        # Add the middle content to the template.
        $arrData['middle'] = 'financedepartment/listing';
        $this->load->view('admin/templates/template', $arrData);
    }


    // public function add_finance_department()
    // {
    //     $this->load->model('subscribers');

    //     $res['status'] = FALSE;
    //     $res['class'] = 'alert alert-danger';

    //     $this->form_validation->set_rules('fb_campaign_id', 'fb_campaign_id', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_payment_date', 'fb_payment_date', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_box', 'fb_box', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_owl', 'fb_owl', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_rrj', 'fb_rrj', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_think', 'fb_think', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_chinese', 'fb_chinese', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_science_adventure', 'fb_science_adventure', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_highlights', 'fb_highlights', 'trim|xss_clean');
    //     $this->form_validation->set_rules('fb_payment_method', 'fb_payment_method', 'trim|xss_clean');
    //     $this->form_validation->set_rules('edit_id', 'edit_id', 'trim|xss_clean');

    //     try {
            
    //         if ($this->form_validation->run() == FALSE) {
    //             throw new Exception('All fields are required', 1);
    //         }

    //         $edit_id = $this->input->post('edit_id');
    //         $cols = [];

    //         $cols['campaign_id'] = $this->input->post('fb_campaign_id');
    //         $cols['payment_date'] = date('Y-m-d', strtotime($this->input->post('fb_payment_date')));
    //         $cols['box'] = $this->input->post('fb_box');
    //         $cols['owl'] = $this->input->post('fb_owl');
    //         $cols['rrj'] = $this->input->post('fb_rrj');
    //         $cols['think'] = $this->input->post('fb_think');
    //         $cols['chinese'] = $this->input->post('fb_chinese');
    //         $cols['science_adventure'] = $this->input->post('fb_science_adventure');
    //         $cols['highlights'] = $this->input->post('fb_highlights');
    //         $cols['payment_method'] = $this->input->post('fb_payment_method');

    //         if(!empty($edit_id)) {
    //             $this->db->where('id', $edit_id);
    //             $update = $this->db->update('finance_department', $cols);
    //             if($update) {
    //                 $insert_id = $edit_id;    
    //             }else {
    //                 $insert_id = FALSE;
    //             }

    //         }else {
    //             $this->db->insert('finance_department', $cols);
    //             $insert_id = $this->db->insert_id();
    //         }

    //         if($insert_id) {

    //             $res['status'] = TRUE;
    //             $res['message'] = 'Successfully submitted.';
    //             $res['class']  = 'alert alert-success';

    //         }else {
    //             throw new Exception('data not inserted', 1);
    //         }
    //     } catch (Exception $e) {
    //         $res['message'] = $e->getMessage();
    //     }

    //     echo json_encode($res);
    // }
   
    // public function get_finance_department()
    // {
    //     $this->load->model('subscribers');

    //     $id = $this->input->post('edit_id');
       
    //     $fdrows = $this->db->get_where('finance_department', array('id' => $id))->result_array();

    //     echo json_encode($fdrows);
    // }
}
