/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.ikonsol.ctrl;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.postgresql.copy.CopyManager;
import org.postgresql.core.BaseConnection;
import org.primefaces.PrimeFaces;
import org.primefaces.event.FileUploadEvent;
import sikd.ikonsol.ejb.session.HeaderDataKonsolidasiEjbHome;
import sikd.ikonsol.ejb.session.JenisBasEjbHome;
import sikd.ikonsol.ejb.session.JenisLaporanEjbHome;
import sikd.ikonsol.ejb.session.LingkupDataEjbHome;
import sikd.ikonsol.ejb.session.PeriodeEjbHome;
import sikd.ikonsol.ejb.session.SusunKonsolidasiEjbHome;
import sikd.ikonsol.model.HeaderDataKonsolidasi;
import sikd.ikonsol.model.JenisBas;
import sikd.ikonsol.model.JenisLaporan;
import sikd.ikonsol.model.LingkupData;
import sikd.ikonsol.model.Periode;
import sikd.ikonsol.model.RawData;
import sikd.ikonsol.model.RawDataLak;
import sikd.ikonsol.model.RawDataLpe;
import sikd.ikonsol.model.RawDataLpsal;
import sikd.ikonsol.model.SusunKonsolidasi;
import sikd.sikd5.sikd5ejb.session.util.MyBatisConnectionFactory;

/**
 *
 * @author Imam Bhoim
 */
@ViewScoped
@Named(value = "headerDataKonsolidasiBeanCtrl")
public class HeaderDataKonsolidasiBeanCtrl implements Serializable {

    HeaderDataKonsolidasi hddatakons, hd;
    HeaderDataKonsolidasi obj;

    SusunKonsolidasi skons;
    SusunKonsolidasi obj2;

    int record = 0;

    private List<HeaderDataKonsolidasi> list, list2;
    private List<JenisLaporan> listjlapor;
    private List<LingkupData> listldata;
    private List<Periode> listperiode;
    private List<JenisBas> listjenisbas;

    RawData rwdata, rawdatatmp;

    RawDataLak rwdatalak;
    RawDataLpe rwdatalpe;
    RawDataLpsal rwdatalpsal;

    @EJB
    HeaderDataKonsolidasiEjbHome headerDataKonsEjbHome;

    @EJB
    JenisLaporanEjbHome jLaporEjbHome;

    @EJB
    LingkupDataEjbHome ldataEjbHome;

    @EJB
    PeriodeEjbHome periodeEjbHome;

    @EJB
    JenisBasEjbHome jenisbasEjbHome;

    @EJB
    SusunKonsolidasiEjbHome susunkonsolidasiEjbHome;

    @PostConstruct
    public void init() {

        list = headerDataKonsEjbHome.findAll();

        rwdata = new RawData();
        rwdatalak = new RawDataLak();
        rwdatalpe = new RawDataLpe();
        rwdatalpsal = new RawDataLpsal();
        //obj = periodeEjbHome.findByKode("22");
        //periode = periodeEjbHome.createNew();
        listjlapor = jLaporEjbHome.findAll();
        listldata = ldataEjbHome.findAll();

        listperiode = periodeEjbHome.findAllAktif();

        listjenisbas = jenisbasEjbHome.findAll();

    }

    public void add() {

        hddatakons = headerDataKonsEjbHome.createNew();

        skons = susunkonsolidasiEjbHome.createNew();

    }

    public String save() {

        // simpan
        hd = headerDataKonsEjbHome.save(hddatakons);

//        
//        System.out.println("AA " + hd.getId());
//        System.out.println("BB " + hd.getTahun());
//        System.out.println("BB " + hd.getIdjnslaporan());
        skons.setHeader_data_id(hd.getId());
        skons.setTahun(hd.getTahun());
        skons.setJenis_laporan_id(hd.getIdjnslaporan());
        skons.setLingkup_id(hd.getLingkup_id());
        skons.setLevel(hd.getLevel());
        skons.setIdbas(hd.getIdbas());

        susunkonsolidasiEjbHome.save(skons);
        //susunkonsolidasiEjbHome.save(skons);

        PrimeFaces.current().executeScript("PF('wg_entryform').hide()");
        PrimeFaces.current().ajax().update(":master:dthddatakons");

        list = headerDataKonsEjbHome.findAll();
        //this.list = service.findAll();
        return "index?faces-redirect=true";
    }

    public String update() {

        headerDataKonsEjbHome.update(obj);

        obj2.setHeader_data_id(obj.getId());
        obj2.setTahun(obj.getTahun());
        obj2.setJenis_laporan_id(obj.getIdjnslaporan());
        obj2.setLingkup_id(obj.getLingkup_id());
        obj2.setLevel(obj.getLevel());
        obj2.setIdbas(obj.getIdbas());

        susunkonsolidasiEjbHome.update(obj2);

        PrimeFaces.current().executeScript("PF('wg_entryform_ubah').hide()");
        PrimeFaces.current().ajax().update(":master:dthddatakons");

        list = headerDataKonsEjbHome.findAll();
        // this.list = service.findAll();
        return "index?faces-redirect=true";
    }

    public void edit(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        obj = headerDataKonsEjbHome.findByID(id);

        obj2 = new SusunKonsolidasi();

        listjlapor = jLaporEjbHome.findAll();
        listldata = ldataEjbHome.findAll();
        listjenisbas = jenisbasEjbHome.findAll();
        listperiode = periodeEjbHome.findAll();
    }

    public void upload(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        obj = headerDataKonsEjbHome.findByID(id);

    }

    public void delete(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        //obj = periodeEjbHome.findByKode(kode);
        headerDataKonsEjbHome.delete(id);

        susunkonsolidasiEjbHome.delete(id);
        PrimeFaces.current().ajax().update(":master:dthddatakons");
        list = headerDataKonsEjbHome.findAll();
    }

    public ArrayList<Integer> myNumbers() {

        ArrayList<Integer> numbers = new ArrayList<Integer>();
        for (int years = 2015; years <= Calendar.getInstance().get(Calendar.YEAR); years++) {
            numbers.add(years);
        }
        return (numbers);
    }

    public ArrayList<Integer> levelData() {

        ArrayList<Integer> numbers = new ArrayList<Integer>();

        numbers.add(1);
        numbers.add(2);
        numbers.add(3);
        numbers.add(4);
        numbers.add(5);
        return (numbers);
    }

    public void handleFileUpload(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {
            System.out.println("XXPath2 " + event.getFile().getFileName());
            String a = event.getFile().getFileName();
            System.out.println("XXPath " + a.toString());
            //workbook = new XSSFWorkbook(file);
            Path pathToFile = Paths.get(a).toAbsolutePath();

            InputStream file;
            file = event.getFile().getInputstream();

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "perubahan_id", "kd_rek_1", "kd_rek_2",
                            "kd_rek_3", "kd_rek_4", "kd_rek_5", "nm_rek_4", "nm_rek_5",
                            "realisasi", "anggaran", "d_k", "jenis_transaksi_id")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index

                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");

                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String perubahanid = csvRecord.get("perubahan_id");
                    String kdrek1 = csvRecord.get("kd_rek_1");
                    String kdrek2 = csvRecord.get("kd_rek_2");
                    String kdrek3 = csvRecord.get("kd_rek_3");
                    String kdrek4 = csvRecord.get("kd_rek_4");
                    String kdrek5 = csvRecord.get("kd_rek_5");

                    if (kdrek1.equalsIgnoreCase("")) {
                        kdrek1 = "0";
                    }

                    if (kdrek2.equalsIgnoreCase("")) {
                        kdrek2 = "0";
                    }

                    if (kdrek3.equalsIgnoreCase("")) {
                        kdrek3 = "0";
                    }

                    if (kdrek4.equalsIgnoreCase("")) {
                        kdrek4 = "0";
                    } else if (kdrek4.equalsIgnoreCase("1")) {
                        kdrek4 = "01";
                    } else if (kdrek4.equalsIgnoreCase("2")) {
                        kdrek4 = "02";
                    } else if (kdrek4.equalsIgnoreCase("3")) {
                        kdrek4 = "03";
                    } else if (kdrek4.equalsIgnoreCase("4")) {
                        kdrek4 = "04";
                    } else if (kdrek4.equalsIgnoreCase("5")) {
                        kdrek4 = "05";
                    } else if (kdrek4.equalsIgnoreCase("6")) {
                        kdrek4 = "06";
                    } else if (kdrek4.equalsIgnoreCase("7")) {
                        kdrek4 = "07";
                    } else if (kdrek4.equalsIgnoreCase("8")) {
                        kdrek4 = "08";
                    } else if (kdrek4.equalsIgnoreCase("9")) {
                        kdrek4 = "09";
                    } else {

                    }

                    if (kdrek5.equalsIgnoreCase("")) {
                        kdrek5 = "0";
                    } else if (kdrek5.equalsIgnoreCase("1")) {
                        kdrek5 = "01";
                    } else if (kdrek5.equalsIgnoreCase("2")) {
                        kdrek5 = "02";
                    } else if (kdrek5.equalsIgnoreCase("3")) {
                        kdrek5 = "03";
                    } else if (kdrek5.equalsIgnoreCase("4")) {
                        kdrek5 = "04";
                    } else if (kdrek5.equalsIgnoreCase("5")) {
                        kdrek5 = "05";
                    } else if (kdrek5.equalsIgnoreCase("6")) {
                        kdrek5 = "06";
                    } else if (kdrek5.equalsIgnoreCase("7")) {
                        kdrek5 = "07";
                    } else if (kdrek5.equalsIgnoreCase("8")) {
                        kdrek5 = "08";
                    } else if (kdrek5.equalsIgnoreCase("9")) {
                        kdrek5 = "09";
                    } else {

                    }

                    if (kdprov.equalsIgnoreCase("01")) {
                        kdprov = "1";
                    } else if (kdprov.equalsIgnoreCase("02")) {
                        kdprov = "2";
                    } else if (kdprov.equalsIgnoreCase("03")) {
                        kdprov = "3";
                    } else if (kdprov.equalsIgnoreCase("04")) {
                        kdprov = "4";
                    } else if (kdprov.equalsIgnoreCase("05")) {
                        kdprov = "5";
                    } else if (kdprov.equalsIgnoreCase("06")) {
                        kdprov = "6";
                    } else if (kdprov.equalsIgnoreCase("07")) {
                        kdprov = "7";
                    } else if (kdprov.equalsIgnoreCase("08")) {
                        kdprov = "8";
                    } else if (kdprov.equalsIgnoreCase("09")) {
                        kdprov = "9";
                    } else {

                    }

                    String nmrek4 = csvRecord.get("nm_rek_4");
                    String nmrek5 = csvRecord.get("nm_rek_5");
                    String realisasi = csvRecord.get("realisasi");
                    if (realisasi.equalsIgnoreCase("")) {
                        realisasi = "0";
                    }
                    String anggaran = csvRecord.get("anggaran");
                    if (anggaran.equalsIgnoreCase("")) {
                        anggaran = "0";
                    }
                    String dk = csvRecord.get("d_k");
                    String jenistransaksiid = csvRecord.get("jenis_transaksi_id");

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdata.setTahun(Integer.valueOf(tahun));
                        rwdata.setKdprov(kdprov);
                        rwdata.setKdpemda(kdpemda);
                        rwdata.setKdsatker(kdsatker);
                        rwdata.setPeriodeid(Integer.valueOf(periodeid));
                        rwdata.setPerubahanid(Integer.valueOf(perubahanid));
                        rwdata.setKdrek1(Integer.valueOf(kdrek1));
                        rwdata.setKdrek2(Integer.valueOf(kdrek2));
                        rwdata.setKdrek3(Integer.valueOf(kdrek3));
                        rwdata.setKdrek4(kdrek4.trim());
                        rwdata.setKdrek5(kdrek5.trim());
                        rwdata.setNmrek4(nmrek4);
                        rwdata.setNmrek5(nmrek5);
                        rwdata.setRealisasi(Double.valueOf(realisasi));
                        rwdata.setAnggaran(Double.valueOf(anggaran));
                        rwdata.setDk(dk);
                        rwdata.setHeader_data_id(obj.getId());
                        rwdata.setJenis_transaksi_id(Integer.valueOf(jenistransaksiid));

                        headerDataKonsEjbHome.saveImportRawdata(rwdata);
                    }
                }

                List<HeaderDataKonsolidasi> hd = headerDataKonsEjbHome.findByPemdaCount(obj.getId());

                SusunKonsolidasi objSusun = new SusunKonsolidasi();
                objSusun.setJml_pemda(hd.size());
                objSusun.setHeader_data_id(obj.getId());
                try {
                    susunkonsolidasiEjbHome.updatePemda(objSusun);
                } catch (Exception e) {
                    System.out.println(e);
                }

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Import Sukses", null));
                list = headerDataKonsEjbHome.findAll();
            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

        //list = headerDataKonsEjbHome.findAll();
        this.init();
        // this.list = service.findAll();
        //return "index?faces-redirect=true";
    }

    public boolean statusFileCSV(int id) {

        HeaderDataKonsolidasi ab = headerDataKonsEjbHome.findByID(id);
        HeaderDataKonsolidasi ac = headerDataKonsEjbHome.findCountRawData(id);

        if (ab.getSumber_id() == 2) {
            if (ac.getId() == 0) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }

    }

    public void handleFileUploadUpdate(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));

        }

        try {

            String a = event.getFile().getFileName();
            InputStream file;
            file = event.getFile().getInputstream();

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "perubahan_id", "kd_rek_1", "kd_rek_2",
                            "kd_rek_3", "kd_rek_4", "kd_rek_5", "nm_rek_4", "nm_rek_5",
                            "realisasi", "anggaran", "d_k")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");

                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String perubahanid = csvRecord.get("perubahan_id");
                    String kdrek1 = csvRecord.get("kd_rek_1");
                    String kdrek2 = csvRecord.get("kd_rek_2");
                    String kdrek3 = csvRecord.get("kd_rek_3");
                    String kdrek4 = csvRecord.get("kd_rek_4");
                    String kdrek5 = csvRecord.get("kd_rek_5");

                    String nmrek4 = csvRecord.get("nm_rek_4");
                    String nmrek5 = csvRecord.get("nm_rek_5");
                    String realisasi = csvRecord.get("realisasi");
                    if (realisasi.equalsIgnoreCase("")) {
                        realisasi = "0";
                    }
                    String anggaran = csvRecord.get("anggaran");
                    if (anggaran.equalsIgnoreCase("")) {
                        anggaran = "0";
                    }
                    String dk = csvRecord.get("d_k");

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdata.setTahun(Integer.valueOf(tahun));
                        rwdata.setKdprov(kdprov);
                        rwdata.setKdpemda(kdpemda);
                        rwdata.setKdsatker(kdsatker);
                        rwdata.setPeriodeid(Integer.valueOf(periodeid));
                        rwdata.setPerubahanid(Integer.valueOf(perubahanid));
                        rwdata.setKdrek1(Integer.valueOf(kdrek1));
                        rwdata.setKdrek2(Integer.valueOf(kdrek2));
                        rwdata.setKdrek3(Integer.valueOf(kdrek3));
                        rwdata.setKdrek4(kdrek4.trim());
                        rwdata.setKdrek5(kdrek5.trim());
                        rwdata.setNmrek4(nmrek4);
                        rwdata.setNmrek5(nmrek5);
                        rwdata.setRealisasi(Double.valueOf(realisasi));
                        rwdata.setAnggaran(Double.valueOf(anggaran));
                        rwdata.setDk(dk);

                        headerDataKonsEjbHome.saveImportRawdataUpdate(rwdata);
                    }
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

        list2 = headerDataKonsEjbHome.findKdpemda();

        for (HeaderDataKonsolidasi rrw : list2) {

            headerDataKonsEjbHome.deleteData(rrw.getNamaperiode(), obj.getId());
        }

        headerDataKonsEjbHome.deleteRawTemp();

        this.handleFileUpload(event);

    }

    public void handleFileUploadCopy(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }
        InputStream inputStream = null;

        try {
            Map<String, String> map = MyBatisConnectionFactory.urlConnection();
            Connection connection = DriverManager.getConnection(
                    map.get("dbUrl"), map.get("username"), map.get("password"));
            String sql = "COPY ikon.raw_data_temp FROM stdin CSV HEADER DELIMITER ';'";

            BaseConnection pgcon = (BaseConnection) connection;
            CopyManager mgr = new CopyManager(pgcon);

            try {
                inputStream = event.getFile().getInputstream();
                Reader in = new BufferedReader(new InputStreamReader(inputStream));
                long rowsaffected = mgr.copyIn(sql, in);

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Import Sukses", null));

            } catch (SQLException ex) {
                System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
                System.exit(0);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex, null));

            }
        } catch (IOException ex) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex, null));

        } catch (SQLException ex) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex, null));

        }

    }

    public static void exeData(String inputDataFile)
            throws FileNotFoundException, IOException, SQLException {
        Map<String, String> map = MyBatisConnectionFactory.urlConnection();
        Connection connection = DriverManager.getConnection(
                map.get("dbUrl"), map.get("username"), map.get("password"));
        String sql = "COPY ikon.raw_data_temp FROM stdin CSV HEADER DELIMITER ';'";
//        Connection conn = null;
//        try {
//            conn = MyBatisConnectionFactory.getSqlSessionFactoryIkonsol().openSession().getConnection();
//       
//        
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }

        // Connection ct =         sqlSessionFactory.openSession().getConnection();
        BaseConnection pgcon = (BaseConnection) connection;
        CopyManager mgr = new CopyManager(pgcon);
        try {
            Reader in = new BufferedReader(new FileReader(new File(inputDataFile)));
            long rowsaffected = mgr.copyIn(sql, in);
        } catch (SQLException ex) {
            System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
            System.exit(0);
        }
    }

    public void handleFileUploadLak(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {
            System.out.println("XXPath2 " + event.getFile().getFileName());
            String a = event.getFile().getFileName();
            System.out.println("XXPath " + a.toString());
            //workbook = new XSSFWorkbook(file);
            Path pathToFile = Paths.get(a).toAbsolutePath();

            InputStream file;
            file = event.getFile().getInputstream();

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "perubahan_id", "kd_rek_1", "kd_rek_2",
                            "kd_rek_3", "nm_rek_1", "nm_rek_2", "nm_rek_3",
                            "nilai", "d_k")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            System.out.println("importDapetfile " + a);
            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index
                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");

                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String perubahanid = csvRecord.get("perubahan_id");
                    String kdrek1 = csvRecord.get("kd_rek_1");
                    String kdrek2 = csvRecord.get("kd_rek_2");
                    String kdrek3 = csvRecord.get("kd_rek_3");
                    String nmrek1 = csvRecord.get("nm_rek_1");
                    String nmrek2 = csvRecord.get("nm_rek_2");
                    String nmrek3 = csvRecord.get("nm_rek_3");
                    String nilai = csvRecord.get("nilai");
                    String dk = csvRecord.get("d_k");
                    // String header_data_id = csvRecord.get(16);
                    // String jenis_transaksi_id = csvRecord.get(17);
                    System.out.println("Name : " + tahun);
                    System.out.println("Email : " + kdpemda);
                    System.out.println("Phone : " + kdrek1);
                    System.out.println("---------------\n\n");

                    if (kdprov.equalsIgnoreCase("01")) {
                        kdprov = "1";
                    } else if (kdprov.equalsIgnoreCase("02")) {
                        kdprov = "2";
                    } else if (kdprov.equalsIgnoreCase("03")) {
                        kdprov = "3";
                    } else if (kdprov.equalsIgnoreCase("04")) {
                        kdprov = "4";
                    } else if (kdprov.equalsIgnoreCase("05")) {
                        kdprov = "5";
                    } else if (kdprov.equalsIgnoreCase("06")) {
                        kdprov = "6";
                    } else if (kdprov.equalsIgnoreCase("07")) {
                        kdprov = "7";
                    } else if (kdprov.equalsIgnoreCase("08")) {
                        kdprov = "8";
                    } else if (kdprov.equalsIgnoreCase("09")) {
                        kdprov = "9";
                    } else {

                    }

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalak.setTahun(Integer.valueOf(tahun));
                        rwdatalak.setKdprov(kdprov);
                        rwdatalak.setKdpemda(kdpemda);
                        rwdatalak.setKdsatker(kdsatker);
                        rwdatalak.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalak.setPerubahanid(Integer.valueOf(perubahanid));
                        rwdatalak.setKdrek1(Integer.valueOf(kdrek1));
                        rwdatalak.setKdrek2(Integer.valueOf(kdrek2));
                        rwdatalak.setKdrek3(Integer.valueOf(kdrek3));
                        rwdatalak.setNmrek1(nmrek1);
                        rwdatalak.setNmrek2(nmrek2);
                        rwdatalak.setNmrek3(nmrek3);
                        rwdatalak.setNilai(Double.valueOf(nilai));
                        rwdatalak.setDk(dk);
                        rwdatalak.setHeader_data_id(obj.getId());
                        rwdatalak.setJenis_transaksi_id(0);

                        headerDataKonsEjbHome.saveImportRawdataLak(rwdatalak);
                    }
                    //  System.out.print("xxxn "+obj.getId());

// rwdata.setHeader_data_id(Integer.parseInt(header_data_id));
                    // rwdata.setJenis_transaksi_id(Integer.parseInt(jenis_transaksi_id));
                }

                List<HeaderDataKonsolidasi> hd = headerDataKonsEjbHome.findByPemdaCountLak(obj.getId());

                SusunKonsolidasi objSusun = new SusunKonsolidasi();
                objSusun.setJml_pemda(hd.size());
                objSusun.setHeader_data_id(obj.getId());
                try {
                    susunkonsolidasiEjbHome.updatePemda(objSusun);
                } catch (Exception e) {
                    System.out.println(e);
                }

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Import Sukses", null));

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            System.out.print("xxxn ERROR");
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

    }

    public void handleFileUploadLakUpdate(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {
            System.out.println("XXPath2 " + event.getFile().getFileName());
            String a = event.getFile().getFileName();
            System.out.println("XXPath " + a.toString());
            //workbook = new XSSFWorkbook(file);
            Path pathToFile = Paths.get(a).toAbsolutePath();

            InputStream file;
            file = event.getFile().getInputstream();

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "perubahan_id", "kd_rek_1", "kd_rek_2",
                            "kd_rek_3", "nm_rek_1", "nm_rek_2", "nm_rek_3",
                            "nilai", "d_k")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            System.out.println("importDapetfile " + a);
            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index
                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");

                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String perubahanid = csvRecord.get("perubahan_id");
                    String kdrek1 = csvRecord.get("kd_rek_1");
                    String kdrek2 = csvRecord.get("kd_rek_2");
                    String kdrek3 = csvRecord.get("kd_rek_3");
                    String nmrek1 = csvRecord.get("nm_rek_1");
                    String nmrek2 = csvRecord.get("nm_rek_2");
                    String nmrek3 = csvRecord.get("nm_rek_3");
                    String nilai = csvRecord.get("nilai");
                    String dk = csvRecord.get("d_k");

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalak.setTahun(Integer.valueOf(tahun));
                        rwdatalak.setKdprov(kdprov);
                        rwdatalak.setKdpemda(kdpemda);
                        rwdatalak.setKdsatker(kdsatker);
                        rwdatalak.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalak.setPerubahanid(Integer.valueOf(perubahanid));
                        rwdatalak.setKdrek1(Integer.valueOf(kdrek1));
                        rwdatalak.setKdrek2(Integer.valueOf(kdrek2));
                        rwdatalak.setKdrek3(Integer.valueOf(kdrek3));
                        rwdatalak.setNmrek1(nmrek1);
                        rwdatalak.setNmrek2(nmrek2);
                        rwdatalak.setNmrek3(nmrek3);
                        rwdatalak.setNilai(Double.valueOf(nilai));
                        rwdatalak.setDk(dk);

                        headerDataKonsEjbHome.saveImportRawdataLakUpdate(rwdatalak);
                    }

                }

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            System.out.print("xxxn ERROR");
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

        list2 = headerDataKonsEjbHome.findKdpemdaLak();

        for (HeaderDataKonsolidasi rrw : list2) {

            headerDataKonsEjbHome.deleteDataLak(rrw.getNamaperiode(), obj.getId());
        }

        headerDataKonsEjbHome.deleteRawLakTemp();

        this.handleFileUploadLak(event);
    }

    public void handleFileUploadLpe(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {
            String a = event.getFile().getFileName();
            //workbook = new XSSFWorkbook(file);
            Path pathToFile = Paths.get(a).toAbsolutePath();

            InputStream file;
            file = event.getFile().getInputstream();

            System.out.println("XXPath3 " + file.toString());

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "ekuitasAwal", "surplusDefisit", "koreksiPersediaan",
                            "selisihRevaluasiAset", "lainlain")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            System.out.println("importDapetfile " + a);
            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index
                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");
                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String ekuitasawal = csvRecord.get("ekuitasAwal");
                    String surplusdefisit = csvRecord.get("surplusDefisit");
                    String koreksipersediaan = csvRecord.get("koreksiPersediaan");
                    String selisihrevaluasiaset = csvRecord.get("selisihRevaluasiAset");
                    String lainlain = csvRecord.get("lainlain");

                    if (kdprov.equalsIgnoreCase("01")) {
                        kdprov = "1";
                    } else if (kdprov.equalsIgnoreCase("02")) {
                        kdprov = "2";
                    } else if (kdprov.equalsIgnoreCase("03")) {
                        kdprov = "3";
                    } else if (kdprov.equalsIgnoreCase("04")) {
                        kdprov = "4";
                    } else if (kdprov.equalsIgnoreCase("05")) {
                        kdprov = "5";
                    } else if (kdprov.equalsIgnoreCase("06")) {
                        kdprov = "6";
                    } else if (kdprov.equalsIgnoreCase("07")) {
                        kdprov = "7";
                    } else if (kdprov.equalsIgnoreCase("08")) {
                        kdprov = "8";
                    } else if (kdprov.equalsIgnoreCase("09")) {
                        kdprov = "9";
                    } else {

                    }

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalpe.setTahun(Integer.valueOf(tahun));
                        rwdatalpe.setKdprov(kdprov);
                        rwdatalpe.setKdpemda(kdpemda);
                        rwdatalpe.setKdsatker(kdsatker);
                        rwdatalpe.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalpe.setEkuitasAwal(Double.valueOf(ekuitasawal));
                        rwdatalpe.setSurplusDefisit(Double.valueOf(surplusdefisit));
                        rwdatalpe.setKoreksiPersediaan(Double.valueOf(koreksipersediaan));
                        rwdatalpe.setSelisihRevaluasiAsset(Double.valueOf(selisihrevaluasiaset));
                        rwdatalpe.setLainLain(Double.valueOf(lainlain));
                        rwdatalpe.setHeader_data_id(obj.getId());
                        rwdatalpe.setJenis_transaksi_id(0);

                        headerDataKonsEjbHome.saveImportRawdataLpe(rwdatalpe);
                    }

                }

                List<HeaderDataKonsolidasi> hd = headerDataKonsEjbHome.findByPemdaCountLpe(obj.getId());
                System.out.println("D----------D" + hd.size());

                SusunKonsolidasi objSusun = new SusunKonsolidasi();
                objSusun.setJml_pemda(hd.size());
                objSusun.setHeader_data_id(obj.getId());
                try {
                    susunkonsolidasiEjbHome.updatePemda(objSusun);
                } catch (Exception e) {
                    System.out.println(e);
                }

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Import Sukses", null));

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

    }

    public void handleFileUploadLpeUpdate(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {

            String a = event.getFile().getFileName();

            InputStream file;
            file = event.getFile().getInputstream();

            System.out.println("XXPath3 " + file.toString());

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "ekuitasAwal", "surplusDefisit", "koreksiPersediaan",
                            "selisihRevaluasiAset", "lainlain")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index

                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");
                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String ekuitasawal = csvRecord.get("ekuitasAwal");
                    String surplusdefisit = csvRecord.get("surplusDefisit");
                    String koreksipersediaan = csvRecord.get("koreksiPersediaan");
                    String selisihrevaluasiaset = csvRecord.get("selisihRevaluasiAset");
                    String lainlain = csvRecord.get("lainlain");

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalpe.setTahun(Integer.valueOf(tahun));
                        rwdatalpe.setKdprov(kdprov);
                        rwdatalpe.setKdpemda(kdpemda);
                        rwdatalpe.setKdsatker(kdsatker);
                        rwdatalpe.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalpe.setEkuitasAwal(Double.valueOf(ekuitasawal));
                        rwdatalpe.setSurplusDefisit(Double.valueOf(surplusdefisit));
                        rwdatalpe.setKoreksiPersediaan(Double.valueOf(koreksipersediaan));
                        rwdatalpe.setSelisihRevaluasiAsset(Double.valueOf(selisihrevaluasiaset));
                        rwdatalpe.setLainLain(Double.valueOf(lainlain));

                        headerDataKonsEjbHome.saveImportRawdataLpeUpdate(rwdatalpe);
                    }

                }

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

        list2 = headerDataKonsEjbHome.findKdpemdaLpe();

        for (HeaderDataKonsolidasi rrw : list2) {

            headerDataKonsEjbHome.deleteDataLpe(rrw.getNamaperiode(), obj.getId());
        }

        headerDataKonsEjbHome.deleteRawLpeTemp();

        this.handleFileUploadLpe(event);

    }

    public void handleFileUploadLpsal(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {
            System.out.println("XXPath2 " + event.getFile().getFileName());
            String a = event.getFile().getFileName();
            System.out.println("XXPath " + a.toString());
            //workbook = new XSSFWorkbook(file);
            Path pathToFile = Paths.get(a).toAbsolutePath();

            InputStream file;
            file = event.getFile().getInputstream();

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "salAwal", "penggunaanSal", "silpa",
                            "koreksi", "lainnya")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            System.out.println("importDapetfile " + a);
            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index

                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");
                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String salawal = csvRecord.get("salAwal");
                    String penggunaansal = csvRecord.get("penggunaanSal");
                    String silpa = csvRecord.get("silpa");
                    String koreksi = csvRecord.get("koreksi");
                    String lainnya = csvRecord.get("lainnya");

                    if (kdprov.equalsIgnoreCase("01")) {
                        kdprov = "1";
                    } else if (kdprov.equalsIgnoreCase("02")) {
                        kdprov = "2";
                    } else if (kdprov.equalsIgnoreCase("03")) {
                        kdprov = "3";
                    } else if (kdprov.equalsIgnoreCase("04")) {
                        kdprov = "4";
                    } else if (kdprov.equalsIgnoreCase("05")) {
                        kdprov = "5";
                    } else if (kdprov.equalsIgnoreCase("06")) {
                        kdprov = "6";
                    } else if (kdprov.equalsIgnoreCase("07")) {
                        kdprov = "7";
                    } else if (kdprov.equalsIgnoreCase("08")) {
                        kdprov = "8";
                    } else if (kdprov.equalsIgnoreCase("09")) {
                        kdprov = "9";
                    } else {

                    }

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalpsal.setTahun(Integer.valueOf(tahun));
                        rwdatalpsal.setKdprov(kdprov);
                        rwdatalpsal.setKdpemda(kdpemda);
                        rwdatalpsal.setKdsatker(kdsatker);
                        rwdatalpsal.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalpsal.setSaldoAwal(Double.valueOf(salawal));
                        rwdatalpsal.setPenggunaanSal(Double.valueOf(penggunaansal));
                        rwdatalpsal.setSilpa(Double.valueOf(silpa));
                        rwdatalpsal.setKoreksi(Double.valueOf(koreksi));
                        rwdatalpsal.setLainnya(Double.valueOf(lainnya));
                        rwdatalpsal.setHeader_data_id(obj.getId());
                        rwdatalpsal.setJenis_transaksi_id(0);

                        headerDataKonsEjbHome.saveImportRawdataLpsal(rwdatalpsal);
                    }

                }

                List<HeaderDataKonsolidasi> hd = headerDataKonsEjbHome.findByPemdaCountLpsal(obj.getId());

                SusunKonsolidasi objSusun = new SusunKonsolidasi();
                objSusun.setJml_pemda(hd.size());
                objSusun.setHeader_data_id(obj.getId());
                try {
                    susunkonsolidasiEjbHome.updatePemda(objSusun);
                } catch (Exception e) {
                    System.out.println(e);
                }

                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Import Sukses", null));

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

    }

    public void handleFileUploadLpsalUpdate(FileUploadEvent event) {
        if (event.getFile().equals(null)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is null", null));
            System.out.println("importKosong");
        }

        try {

            InputStream file;
            file = event.getFile().getInputstream();

            System.out.println("XXPath3 " + file.toString());

            Reader reader = new InputStreamReader(file);//Files.newBufferedReader((Path) file);

            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
                    .withHeader("tahun", "kd_provinsi", "kd_pemda", "kd_satker",
                            "periode_id", "salAwal", "penggunaanSal", "silpa",
                            "koreksi", "lainnya")
                    .withFirstRecordAsHeader()
                    .withIgnoreHeaderCase()
                    .withDelimiter(';').withTrim()
            );

            try {
                for (CSVRecord csvRecord : csvParser) {
                    // Accessing Values by Column Index

                    record = (int) csvRecord.getRecordNumber();

                    String tahun = csvRecord.get("tahun");
                    String kdprov = csvRecord.get("kd_provinsi");
                    String kdpemda = csvRecord.get("kd_pemda");
                    String kdsatker = csvRecord.get("kd_satker");
                    String periodeid = csvRecord.get("periode_id");
                    String salawal = csvRecord.get("salAwal");
                    String penggunaansal = csvRecord.get("penggunaanSal");
                    String silpa = csvRecord.get("silpa");
                    String koreksi = csvRecord.get("koreksi");
                    String lainnya = csvRecord.get("lainnya");

                    if (csvRecord.getRecordNumber() > 0) {
                        rwdatalpsal.setTahun(Integer.valueOf(tahun));
                        rwdatalpsal.setKdprov(kdprov);
                        rwdatalpsal.setKdpemda(kdpemda);
                        rwdatalpsal.setKdsatker(kdsatker);
                        rwdatalpsal.setPeriodeid(Integer.valueOf(periodeid));
                        rwdatalpsal.setSaldoAwal(Double.valueOf(salawal));
                        rwdatalpsal.setPenggunaanSal(Double.valueOf(penggunaansal));
                        rwdatalpsal.setSilpa(Double.valueOf(silpa));
                        rwdatalpsal.setKoreksi(Double.valueOf(koreksi));
                        rwdatalpsal.setLainnya(Double.valueOf(lainnya));

                        headerDataKonsEjbHome.saveImportRawdataLpsalUpdate(rwdatalpsal);
                    }

                }

            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.print("xxxn ERROR" + ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + ex
                        + ", baris data " + record, null));

            }
        } catch (IOException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error reading file" + e, null));
        }

        list2 = headerDataKonsEjbHome.findKdpemdaLpsal();

        for (HeaderDataKonsolidasi rrw : list2) {

            headerDataKonsEjbHome.deleteDataLpsal(rrw.getNamaperiode(), obj.getId());
        }

        headerDataKonsEjbHome.deleteRawLpsalTemp();

        this.handleFileUploadLpsal(event);

    }

    // function rawa data
    public String saveImportRawdata() {

        // simpan
        headerDataKonsEjbHome.save(hddatakons);

        PrimeFaces.current().executeScript("PF('wg_entryform').hide()");
        PrimeFaces.current().ajax().update(":master:dthddatakons");

        list = headerDataKonsEjbHome.findAll();
        //this.list = service.findAll();
        return "index?faces-redirect=true";
    }

    public void deleteAll(int id, int idjenislaporan) {
        //obj = service.findByID(Integer.parseInt(id));
        //obj = periodeEjbHome.findByKode(kode);
        if (idjenislaporan == 1 || idjenislaporan == 2 || idjenislaporan == 3) {
            //delete akun eliminasi,rawdata,susun dan header konsolidasi
            headerDataKonsEjbHome.deleteRawDataLRANeracaLO(id);

        } else if (idjenislaporan == 4) {
            headerDataKonsEjbHome.deleteRawDataLak(id);
        } else if (idjenislaporan == 5) {
            headerDataKonsEjbHome.deleteRawDataLpe(id);
        } else if (idjenislaporan == 6) {
            headerDataKonsEjbHome.deleteRawDataLpsal(id);
        } else {
            headerDataKonsEjbHome.deleteRawDataLRANeracaLO(id);

        }

        PrimeFaces.current().ajax().update(":master:dthddatakons");
        list = headerDataKonsEjbHome.findAll();
    }

    public HeaderDataKonsolidasi getHddatakons() {
        return hddatakons;
    }

    public void setHddatakons(HeaderDataKonsolidasi hddatakons) {
        this.hddatakons = hddatakons;
    }

    public HeaderDataKonsolidasi getObj() {
        return obj;
    }

    public void setObj(HeaderDataKonsolidasi obj) {
        this.obj = obj;
    }

    public List<HeaderDataKonsolidasi> getList() {
        return list;
    }

    public void setList(List<HeaderDataKonsolidasi> list) {
        this.list = list;
    }

    public HeaderDataKonsolidasiEjbHome getHeaderDataKonsEjbHome() {
        return headerDataKonsEjbHome;
    }

    public void setHeaderDataKonsEjbHome(HeaderDataKonsolidasiEjbHome headerDataKonsEjbHome) {
        this.headerDataKonsEjbHome = headerDataKonsEjbHome;
    }

    public List<JenisLaporan> getListjlapor() {
        return listjlapor;
    }

    public void setListjlapor(List<JenisLaporan> listjlapor) {
        this.listjlapor = listjlapor;
    }

    public List<LingkupData> getListldata() {
        return listldata;
    }

    public void setListldata(List<LingkupData> listldata) {
        this.listldata = listldata;
    }

    public JenisLaporanEjbHome getjLaporEjbHome() {
        return jLaporEjbHome;
    }

    public void setjLaporEjbHome(JenisLaporanEjbHome jLaporEjbHome) {
        this.jLaporEjbHome = jLaporEjbHome;
    }

    public LingkupDataEjbHome getLdataEjbHome() {
        return ldataEjbHome;
    }

    public void setLdataEjbHome(LingkupDataEjbHome ldataEjbHome) {
        this.ldataEjbHome = ldataEjbHome;
    }

    public List<Periode> getListperiode() {
        return listperiode;
    }

    public void setListperiode(List<Periode> listperiode) {
        this.listperiode = listperiode;
    }

    public List<JenisBas> getListjenisbas() {
        return listjenisbas;
    }

    public void setListjenisbas(List<JenisBas> listjenisbas) {
        this.listjenisbas = listjenisbas;
    }

    public HeaderDataKonsolidasi getHd() {
        return hd;
    }

    public void setHd(HeaderDataKonsolidasi hd) {
        this.hd = hd;
    }

    public SusunKonsolidasi getSkons() {
        return skons;
    }

    public void setSkons(SusunKonsolidasi skons) {
        this.skons = skons;
    }

    public SusunKonsolidasi getObj2() {
        return obj2;
    }

    public void setObj2(SusunKonsolidasi obj2) {
        this.obj2 = obj2;
    }

    public List<HeaderDataKonsolidasi> getList2() {
        return list2;
    }

    public void setList2(List<HeaderDataKonsolidasi> list2) {
        this.list2 = list2;
    }

}
