/*
 * 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.ejb.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import sikd.ikonsol.model.TrialBalance;

/**
 *
 * @author riyan
 */
public class TrialBalanceDao implements IDAO<TrialBalance>, Serializable {

    private SqlSessionFactory sqlSessionFactory = null;
    private SqlSession session = null;

    public TrialBalanceDao(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public TrialBalance createNew() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<TrialBalance> findAll() {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

        List<TrialBalance> list = new ArrayList<TrialBalance>();

        session = sqlSessionFactory.openSession();
        try {
            list = session.selectList("TrialBalanceMapper.selectAll");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }

        return list;
    }

    @Override
    public List<TrialBalance> findByCriteria(String sql) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TrialBalance findByID(int id) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        session = sqlSessionFactory.openSession();
        TrialBalance obj = null;
        try {
            obj = session.selectOne("TrialBalanceMapper.selectId", id);

        } finally {
            session.close();
        }
        return obj;
    }

    @Override
    public TrialBalance findByKode(String kode) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TrialBalance save(TrialBalance obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TrialBalance update(TrialBalance obj) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteByID(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteByPK(String pk) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public List<TrialBalance> findAllByTahunKode(int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKode", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<TrialBalance> findAllByTahunKodeDetail(String kdrek1, 
            String kdrek2, String kdrek3,int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("kdrek1", kdrek1);
        map.put("kdrek2", kdrek2);
        map.put("kdrek3", kdrek3);
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKodeDetail", map);

        } finally {
            session.close();
        }
        return list;
    }

    public List<TrialBalance> findAllByTahunKodeSum(int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKodeSum", map);

        } finally {
            session.close();
        }
        return list;
    }

      public List<TrialBalance> findAllByTahunKode2(String kdrek1,int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
       map.put("kdrek1", kdrek1);
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKode2", map);

        } finally {
            session.close();
        }
        return list;
    }
      
         public List<TrialBalance> findAllByTahunKode3(String kdrek1,String kdrek2,int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
       map.put("kdrek1", kdrek1);
        map.put("kdrek2", kdrek2);
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKode3", map);

        } finally {
            session.close();
        }
        return list;
    }
         
             public List<TrialBalance> findAllByTahunKode4(String kdrek1,String kdrek2,
                     String kdrek3,int tahun, String kodePemda, int idbas, String kodePeriode) {
        Map<String, Object> map = new HashMap<>();
       map.put("kdrek1", kdrek1);
        map.put("kdrek2", kdrek2);
        map.put("kdrek3", kdrek3);
        map.put("tahun", tahun);
        map.put("kdpemda", kodePemda);
        map.put("idbas", idbas);
        map.put("kdperiode", kodePeriode);
        List<TrialBalance> list = null;
        session = sqlSessionFactory.openSession();
        try {

            list = session.selectList("TrialBalanceMapper.selectByTahunKode4", map);

        } finally {
            session.close();
        }
        return list;
    }
         
    
  
}
