<?php defined('BASEPATH') or exit('No direct script access allowed');
class Importvouchers extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        checkLogin();
    }
    function index()
    {
        $data['pageTitle'] = "Import Vouchers";
        $importedData = array();
        if (isset($_FILES['voucher_list'])) {
            $filename = $_FILES["voucher_list"]["tmp_name"];
            if ($_FILES["voucher_list"]["size"] > 0) {
                $file = fopen($filename, "r");
                while (($getData = fgetcsv($file, 100000, ",")) !== FALSE) {
                    $importedData[] = $getData;
                }
                fclose($file);
            }
            $data['importedData'] = $importedData;
            switch ($_POST['import_type']) {
                case 'Groups':
                    loadView("accounts/importgroups", $data);
                    break;
                case 'Categories':
                    loadView("accounts/importcategories", $data);
                    break;
                case 'Accounts':
                    loadView("accounts/importaccounts", $data);
                    break;
                case 'Vouchers':
                    loadView("accounts/importvouchers", $data);
                    break;
                case 'VoucherDetails':
                    loadView("accounts/importvoucherdetails", $data);
                    break;
                default:
                    //loadView("accounts/importvouchers", $data);
                    break;
            }
        } else {
            loadView("accounts/importvouchers", $data);
        }
    }
}