/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kr.co.kihyun.spring;

import java.util.Date;
import kr.co.kihyun.beans.entity.Recog;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author bhs
 */
public class MoumiReportServiceImpl implements MoumiReportService {

    private MoumiDao<TotReport> reportDao;

    public MoumiDao<TotReport> getReportDao() {
        return reportDao;
    }

    public void setReportDao(MoumiDao<TotReport> reportDao) {
        this.reportDao = reportDao;
    }

    public void beginApprove(TotReport report) {
        report.setRecog(Recog.NEIS_ONGOING);
		reportDao.addDirtyField("recog");
        report.setProcess(TotReportProcess.APPROVE);
		reportDao.addDirtyField("process");
    }

    public void turnDown(TotReport report) {
        report.setRecog(Recog.NEIS_RETURN);
		reportDao.addDirtyField("recog");
		if (report.getSlaveTotDoc() == null)		// NEIS-61
			report.setProcess(TotReportProcess.RETURN);
		else
			report.setProcess(TotReportProcess.TEMP);
		reportDao.addDirtyField("process");
    }

    public void completeApprove(TotReport report) {
        report.setRecog(Recog.NEIS_COMP);
		reportDao.addDirtyField("recog");
        report.setProcess(TotReportProcess.COMP);
		reportDao.addDirtyField("process");
        report.setSubmitDate(new Date());
		reportDao.addDirtyField("submitDate");
    }

    public TotReport loadReport(Long id) {
        return reportDao.load(TotReport.class, id);
    }

    public void storeReport(TotReport report) {
        reportDao.store(TotReport.class, report);
    }
}
