/*
 * 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.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import sikd.ikonsol.ejb.session.JenisBasEjbHome;
import sikd.ikonsol.ejb.session.RefPemdaEjbHome;
import sikd.ikonsol.ejb.session.WorksheetViewEjbHome;
import sikd.ikonsol.model.JenisBas;
import sikd.ikonsol.model.ReferensiPemda;
import sikd.ikonsol.model.WorksheetView;

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

    WorksheetView wv;

    private List<WorksheetView> list;

    private List<JenisBas> listjbas;

    private List<ReferensiPemda> listprovinsi;

    @EJB
    WorksheetViewEjbHome worksheetViewEjbHome;

    @EJB
    RefPemdaEjbHome pemdaEjbHome;

    @EJB
    JenisBasEjbHome jenisBasEjbHome;

    private int idbas = 0;
    private int tahun;
    private String kdPemda;

    private List<ReferensiPemda> listPemda;

    @PostConstruct
    public void init() {
        try {
            list = worksheetViewEjbHome.findAllByTahunBasProvinsi(tahun, idbas, kdPemda);

            // listDetail = tbEjbHome.findAllByTahunKodeDetail(tahun, kdPemda);
        } catch (Exception e) {
            e.printStackTrace();
        }
        listjbas = jenisBasEjbHome.findAllAktif();
        listprovinsi = pemdaEjbHome.findAllProvinsi("__.00");
    }

    public void reload() {
        
        System.out.println(" Tahun : " + tahun);
        System.out.println(" BAS : " + idbas);
        System.out.println(" kdpemda : " + kdPemda);
        list = worksheetViewEjbHome.findAllByTahunBasProvinsi(tahun, idbas, kdPemda);

    }
    
    public boolean debit(String db){
        if(db.equalsIgnoreCase("D")){
            return true;
        } else {
            return false;
        }
    }
    
     public boolean kredit(String kd){
        if(kd.equalsIgnoreCase("K")){
            return true;
        } else {
            return false;
        }
    }
     
     public boolean laporanLRADebit(String db,int jnslap){
        if(db.equalsIgnoreCase("D") && jnslap==1){
            return true;
        } else {
            return false;
        }
    }
     
      public boolean laporanLRAKredit(String dk,int jnslap){
        if(dk.equalsIgnoreCase("K") && jnslap==1){
            return true;
        } else {
            return false;
        }
    }
      
       public boolean laporanLODebit(String db,int jnslap){
        if(db.equalsIgnoreCase("D") && jnslap==3){
            return true;
        } else {
            return false;
        }
    }
     
      public boolean laporanLOKredit(String dk,int jnslap){
        if(dk.equalsIgnoreCase("K") && jnslap==3){
            return true;
        } else {
            return false;
        }
    }
      
         public boolean laporanNeracaDebit(String db,int jnslap){
        if(db.equalsIgnoreCase("D") && jnslap==2){
            return true;
        } else {
            return false;
        }
    }
     
      public boolean laporanNeracaKredit(String dk,int jnslap){
        if(dk.equalsIgnoreCase("K") && jnslap==2){
            return true;
        } else {
            return false;
        }
    }


    public ArrayList<Integer> listTahun() {

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

    public WorksheetView getWv() {
        return wv;
    }

    public void setWv(WorksheetView wv) {
        this.wv = wv;
    }

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

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

    public WorksheetViewEjbHome getWorksheetViewEjbHome() {
        return worksheetViewEjbHome;
    }

    public void setWorksheetViewEjbHome(WorksheetViewEjbHome worksheetViewEjbHome) {
        this.worksheetViewEjbHome = worksheetViewEjbHome;
    }

    public RefPemdaEjbHome getPemdaEjbHome() {
        return pemdaEjbHome;
    }

    public void setPemdaEjbHome(RefPemdaEjbHome pemdaEjbHome) {
        this.pemdaEjbHome = pemdaEjbHome;
    }

    public int getIdbas() {
        return idbas;
    }

    public void setIdbas(int idbas) {
        this.idbas = idbas;
    }

    public int getTahun() {
        return tahun;
    }

    public void setTahun(int tahun) {
        this.tahun = tahun;
    }

    public String getKdPemda() {
        return kdPemda;
    }

    public void setKdPemda(String kdPemda) {
        this.kdPemda = kdPemda;
    }

    public List<ReferensiPemda> getListPemda() {
        return listPemda;
    }

    public void setListPemda(List<ReferensiPemda> listPemda) {
        this.listPemda = listPemda;
    }

    public List<JenisBas> getListjbas() {
        return listjbas;
    }

    public void setListjbas(List<JenisBas> listjbas) {
        this.listjbas = listjbas;
    }

    public List<ReferensiPemda> getListprovinsi() {
        return listprovinsi;
    }

    public void setListprovinsi(List<ReferensiPemda> listprovinsi) {
        this.listprovinsi = listprovinsi;
    }

}
