/*
 * 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.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.PrimeFaces;
import sikd.ikonsol.ejb.session.JenisLaporanEjbHome;
import sikd.ikonsol.model.JenisLaporan;

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

    JenisLaporan jlaporan;
    JenisLaporan obj;
    private List<JenisLaporan> list;

    private int id;
    private String nama;
    private String deskripsi;

    @EJB
    JenisLaporanEjbHome jlaporanEjbHome;

    @PostConstruct
    public void init() {
        
            list = jlaporanEjbHome.findAll();
       
        //obj = periodeEjbHome.findByKode("22");
        //periode = periodeEjbHome.createNew();
    }

    public void add() {

        jlaporan = jlaporanEjbHome.createNew();

    }

    public String save() {

        // simpan
        jlaporanEjbHome.save(jlaporan);

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

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

    public String update() {

        jlaporanEjbHome.update(obj);

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

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

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

    }

    public void delete(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        //obj = periodeEjbHome.findByKode(kode);
        jlaporanEjbHome.delete(id);
        PrimeFaces.current().ajax().update(":master:dtjlaporan");
        list = jlaporanEjbHome.findAll();
    }

    public JenisLaporan getJlaporan() {
        return jlaporan;
    }

    public void setJlaporan(JenisLaporan jlaporan) {
        this.jlaporan = jlaporan;
    }

    public JenisLaporan getObj() {
        return obj;
    }

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

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

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

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getDeskripsi() {
        return deskripsi;
    }

    public void setDeskripsi(String deskripsi) {
        this.deskripsi = deskripsi;
    }

    public JenisLaporanEjbHome getJlaporanEjbHome() {
        return jlaporanEjbHome;
    }

    public void setJlaporanEjbHome(JenisLaporanEjbHome jlaporanEjbHome) {
        this.jlaporanEjbHome = jlaporanEjbHome;
    }

}
