com.nec.harvest.controller.SuisController.java Source code

Java tutorial

Introduction

Here is the source code for com.nec.harvest.controller.SuisController.java

Source

/*
 * Copyright(C) 2014
 * NEC Corporation All rights reserved.
 * 
 * No permission to use, copy, modify and distribute this software
 * and its documentation for any purpose is granted.
 * This software is provided under applicable license agreement only.
 */
package com.nec.harvest.controller;

import java.net.URI;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.inject.Inject;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import com.nec.core.exception.ObjectNotFoundException;
import com.nec.core.exception.TooManyObjectsException;
import com.nec.harvest.bean.mapping.SuisMonthBean;
import com.nec.harvest.bean.mapping.SuisTotalBean;
import com.nec.harvest.constant.Constants;
import com.nec.harvest.exception.ServiceException;
import com.nec.harvest.menu.group.ProfitAndLossManagementProGroup;
import com.nec.harvest.model.BudgetPerformance;
import com.nec.harvest.model.Tighten;
import com.nec.harvest.model.VJiseki;
import com.nec.harvest.service.ActualViewService;
import com.nec.harvest.service.BudgetPerformanceService;
import com.nec.harvest.service.ConsumptionTaxRateService;
import com.nec.harvest.service.InventoryService;
import com.nec.harvest.service.TightenService;
import com.nec.harvest.stereotype.SessionAttribute;
import com.nec.harvest.util.DateFormatUtil;
import com.nec.harvest.util.DateFormatUtil.DateFormat;
import com.nec.harvest.util.DateUtil;
import com.nec.harvest.util.RoundNumericUtil;

/**
 * A controller that listen every request after process logic for (SonekiSuii)
 * After response to page html
 * 
 * @author hungpd
 * 
 */
@Controller
@RequestMapping(value = Constants.SUIS_PATH)
public class SuisController extends ProfitAndLossManagementProGroup implements AbstractRenderer, TitleRenderer {

    private static final Logger logger = LoggerFactory.getLogger(SuisController.class);

    private final ActualViewService actualViewService;

    private final TightenService tightenService;

    private final InventoryService inventoryService;

    private final BudgetPerformanceService budgetPerformanceService;

    private final ConsumptionTaxRateService consumptionTaxRateService;

    @Inject
    public SuisController(ActualViewService actualViewService, TightenService tightenService,
            InventoryService inventoryService, BudgetPerformanceService budgetPerformanceService,
            ConsumptionTaxRateService consumptionTaxRateService) {
        this.actualViewService = actualViewService;
        this.tightenService = tightenService;
        this.inventoryService = inventoryService;
        this.budgetPerformanceService = budgetPerformanceService;
        this.consumptionTaxRateService = consumptionTaxRateService;
    }

    /** {@inheritDoc} */
    @Override
    @RequestMapping(value = "", method = RequestMethod.GET)
    public String render(@SessionAttribute(Constants.SESS_ORGANIZATION_CODE) String orgCode,
            @SessionAttribute(Constants.SESS_BUSINESS_DAY) Date businessDay, @PathVariable String proGNo) {
        if (logger.isDebugEnabled()) {
            logger.debug("Redering suis report...");
        }

        // ?
        UriComponents uriComponents = UriComponentsBuilder
                .fromUriString(Constants.SUIS_PATH + "/{orgCode}/{currentQuarter}").build();
        String yearQuater = DateUtil.getCurrentQuarter(businessDay);
        URI uri = uriComponents.expand(proGNo, orgCode, yearQuater).encode().toUri();

        logger.info("Redirect to suis screen with params in session...");
        return "redirect:" + uri.toString();
    }

    /**
     * Render page with path variables mapping
     * 
     * @param businessDay
     *            Actual business day
     * @param orgCode
     *            A path variable user's orgCode
     * @param year
     *            A path variable year
     * @param quarter
     *            A path variable quarter
     * @param model
     *            Spring's model that can be used to render a view
     * @return A redirect URL
     */
    @RequestMapping(value = "/{orgCode:[a-z0-9]+}/{year:\\d{4}}/{quarter:[1-4]}", method = RequestMethod.GET)
    public String render(@SessionAttribute(Constants.SESS_BUSINESS_DAY) Date businessDay,
            @PathVariable String orgCode, @PathVariable @DateTimeFormat(pattern = "yyyy") Date year,
            @PathVariable int quarter, final Model model) {

        // get three month of current quarter business
        final String CURRENT_MONTHLIES = "monthlies";
        String[] monthiesCurrentQuarter = DateUtil.getMonthliesOfQuarter(year, quarter);
        model.addAttribute(CURRENT_MONTHLIES, monthiesCurrentQuarter);

        // get final tighten
        Date finalTighten = null;
        try {
            finalTighten = getMonthlyTighten(businessDay, model);
        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return getViewName();
        }

        // ???[?]?????
        if (!availableNext(orgCode, quarter, year, model, finalTighten, businessDay)) {
            return getViewName();
        }

        // ??????????
        if (!availablePrevious(orgCode, quarter, year, model, finalTighten)) {
            return getViewName();
        }
        // get startMonth
        String currentYear = DateFormatUtil.format(year, DateFormat.DATE_YEAR);
        String startMonth = currentYear + "04";

        // get endMonth
        String nextYear = DateFormatUtil.format(DateUtils.addYears(year, 1), DateFormat.DATE_YEAR);
        String endMonth = nextYear + "03";

        int countMonth = 12;
        try {
            Date endDate = DateFormatUtil.parse(endMonth, DateFormat.DATE_WITHOUT_DAY);
            if (endDate.after(businessDay)) {
                countMonth = countMonth - DateUtil.monthsBetween(businessDay, endDate);
                endMonth = DateFormatUtil.format(businessDay, DateFormat.DATE_WITHOUT_DAY);
            }
        } catch (NullPointerException | IllegalArgumentException | ParseException ex) {
            logger.warn(ex.getMessage());
        }

        // ???jiseki??
        Map<String, VJiseki> mapSuis = null;
        List<VJiseki> listSuisYear = null;
        try {
            listSuisYear = actualViewService.findByOrgCodeAndPeriodMonthly(orgCode, startMonth, endMonth);
        } catch (IllegalArgumentException | ObjectNotFoundException | NullPointerException ex) {
            logger.warn(ex.getMessage());

        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return getViewName();
        }

        // ????
        try {
            mapSuis = getSuiiList(listSuisYear, DateFormatUtil.parse(startMonth, DateFormat.DATE_WITHOUT_DAY),
                    countMonth);
        } catch (NullPointerException | IllegalArgumentException | ParseException ex) {
            logger.warn(ex.getMessage());
        }

        // find data budget performance
        Map<String, BudgetPerformance> mapAT023 = null;
        try {
            mapAT023 = budgetPerformanceService.findByOrgCodeAndStartMonthEndMonthAndKmkCodeJs(orgCode, startMonth,
                    endMonth, Constants.DEFAULT_KMKCODEJ_K7111, Constants.DEFAULT_KMKCODEJ_K7521,
                    Constants.DEFAULT_KMKCODEJ_K8110, Constants.DEFAULT_KMKCODEJ_K8210,
                    Constants.DEFAULT_KMKCODEJ_K8310);
        } catch (IllegalArgumentException | ObjectNotFoundException ex) {
            logger.warn(ex.getMessage());

        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return getViewName();
        }

        // ???
        Map<String, Double> mapAT015 = null;
        try {
            mapAT015 = inventoryService.findByOrgCodeAndPeriodMonthly(orgCode, startMonth, endMonth);
        } catch (IllegalArgumentException | ObjectNotFoundException ex) {
            logger.warn(ex.getMessage());

        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return getViewName();
        }

        // ??
        calculateSuii(mapSuis, finalTighten, businessDay, mapAT023, mapAT015, quarter, model);
        return getViewName();
    }

    private void setDataMonthly(int month, SuisMonthBean suisMonthly, Model model) {
        switch (month) {
        case 0:
            // ?????
            model.addAttribute("firstMonth", suisMonthly);
            break;
        case 1:
            // ??
            model.addAttribute("secondMonth", suisMonthly);
            break;
        case 2:
            // ???
            model.addAttribute("thirdMonth", suisMonthly);
            break;
        default:
            break;
        }
    }

    private boolean availableNext(String orgCode, int currentQuater, Date currentYear, Model model,
            Date finalTighten, Date businessDay) {
        final String URL_NEXT = "nextUrl";
        try {
            // if quarter equal 4 then set quarter equal 1
            int intNextQuater = currentQuater + 1;
            if (currentQuater == 5) {
                intNextQuater = 1;
            }
            // get three month of next quarter
            String[] monthiesNext = DateUtil.getMonthliesOfQuarter(currentYear, intNextQuater);
            String nextQuarter = null;
            Date firstDate = DateFormatUtil.parse(monthiesNext[0], DateFormat.DATE_WITHOUT_DAY);
            if (firstDate.after(businessDay)) {
                // next url set null <=> disabled button next 
                model.addAttribute(URL_NEXT, nextQuarter);
                return true;
            }
            // greater than tighten date
            if (firstDate.after(finalTighten)) {
                // count data in v_jiseki view if count greater > 0 then return true otherwise return false
                if (actualViewService.checkAvailableByOrgCodeAndMonthly(orgCode, monthiesNext)) {
                    nextQuarter = DateUtil.nextQuarter(firstDate);
                }
            } else {
                // count data in budget performance if count greater > 0 then return true otherwise return false
                boolean isNextAvailable = budgetPerformanceService.checkAvailableByOrgCodeAndMonthlyAndKmkCodeJs(
                        orgCode, monthiesNext[0], Constants.DEFAULT_KMKCODEJ_K7111,
                        Constants.DEFAULT_KMKCODEJ_K7521, Constants.DEFAULT_KMKCODEJ_K8110,
                        Constants.DEFAULT_KMKCODEJ_K8210, Constants.DEFAULT_KMKCODEJ_K8310);
                if (isNextAvailable) {
                    nextQuarter = DateUtil.nextQuarter(firstDate);
                }
            }
            model.addAttribute(URL_NEXT, nextQuarter);
        } catch (IllegalArgumentException | NullPointerException | ParseException ex) {
            logger.warn(ex.getMessage());

            // 
            model.addAttribute(URL_NEXT, null);
        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return false;
        }
        return true;
    }

    private boolean availablePrevious(String orgCode, int currentQuater, Date currentYear, Model model,
            Date finalTighten) {
        final String URL_PREVIOUS = "previousUrl";
        try {
            // if quarter equal 1 then set quarter equal 4
            int preQuater = currentQuater - 1;
            if (currentQuater == 0) {
                preQuater = 4;
            }
            // get three month of previous quarter
            String[] monthiesPrevious = DateUtil.getMonthliesOfQuarter(currentYear, preQuater);
            String previousQuarter = null;
            Date date = DateFormatUtil.parse(monthiesPrevious[2], DateFormat.DATE_WITHOUT_DAY);
            // greater than tighten date
            if (date.after(finalTighten)) {
                if (actualViewService.checkAvailableByOrgCodeAndMonthly(orgCode, monthiesPrevious)) {
                    previousQuarter = DateUtil.previousQuarter(date);
                }
            } else {
                boolean isPreviousAvailable = budgetPerformanceService
                        .checkAvailableByOrgCodeAndMonthlyAndKmkCodeJs(orgCode, monthiesPrevious[2],
                                Constants.DEFAULT_KMKCODEJ_K7111, Constants.DEFAULT_KMKCODEJ_K7521,
                                Constants.DEFAULT_KMKCODEJ_K8110, Constants.DEFAULT_KMKCODEJ_K8210,
                                Constants.DEFAULT_KMKCODEJ_K8310);
                if (isPreviousAvailable) {
                    previousQuarter = DateUtil.nextQuarter(date);
                }
            }
            model.addAttribute(URL_PREVIOUS, previousQuarter);
        } catch (IllegalArgumentException | NullPointerException | ParseException | ObjectNotFoundException ex) {
            logger.warn(ex.getMessage());

            // set value url previous and disable previous button
            model.addAttribute(URL_PREVIOUS, null);
        } catch (ServiceException ex) {
            logger.error(ex.getMessage(), ex);

            // ???????????
            model.addAttribute(ERROR_MESSAGE, getSystemError());
            model.addAttribute(ERROR, true);
            return false;
        }
        return true;
    }

    /**
     * Calculator total data 12 month and fill 3 month of quarter
     * 
     * @param listSuisYear
     *            Data profit and loss
     * @param monthly
     *            month
     * @param businessDay
     *            a day business
     * @param mapAT023
     *            Map at023
     * @param mapAT015
     *            Map at015
     * @param quarter
     *            a current quarter
     * @param model
     */
    private void calculateSuii(Map<String, VJiseki> mapSuisYear, Date monthly, Date businessDay,
            Map<String, BudgetPerformance> mapAT023, Map<String, Double> mapAT015, int quarter, Model model) {
        logger.info("Begin calculator suii for 3 month and total of year");

        final String TOTAL_QUARTER = "totalQuarter";
        Integer no08 = null; //_??__??
        Integer no10 = null; //_?__??)
        Integer no12 = null; //___??
        Integer no14 = null; //_??__??
        Integer no16 = null; //___??
        Integer no18 = null; //_?__??
        Integer no21 = null; //___??
        Double no22 = null; //___
        Integer no25 = null; //__??
        Double no26 = null; //__
        Integer no29 = null; //__??
        Double no30 = null; //__
        Integer no33 = null; //__??
        Double no34 = null; //__
        int index = 0;
        SuisMonthBean suisMonthly = null;
        String valueBlank = "1";

        // Loop data soneki suis
        if (mapSuisYear != null && mapSuisYear.size() > 0) {
            for (Map.Entry<String, VJiseki> entry : mapSuisYear.entrySet()) {
                String key = entry.getKey();
                VJiseki jiseki = entry.getValue();
                String strValueBlank = "";
                try {
                    String getsudo = key;
                    Date yearmonth = DateFormatUtil.parse(getsudo, DateFormat.DATE_WITHOUT_DAY);
                    double taxRate = 0d;
                    try {
                        taxRate = consumptionTaxRateService.findActualTaxRateByDate(yearmonth);
                    } catch (IllegalArgumentException | ObjectNotFoundException ex) {
                        logger.warn(ex.getMessage());

                    } catch (ServiceException ex) {
                        logger.error(ex.getMessage(), ex);

                        // ???????????
                        model.addAttribute(ERROR_MESSAGE, getSystemError());
                        model.addAttribute(ERROR, true);
                    }
                    Integer no07 = null; //_??_n1n3_?
                    Integer no11 = null; //__n1n3_????
                    Integer no09 = null; //_?_n1n3_?
                    Integer no13 = null; //_??_n1n3_??
                    Integer no15 = null; //__n1n3_??
                    Integer no17 = null; //_?_n1n3_??
                    Integer no19 = null; //__n1n3_??
                    Double no20 = null; //__n1n3_
                    Integer no23 = null; //_n1n3_??
                    Double no24 = null; //_n1n3_
                    Integer no27 = null; //_n1n3_??
                    Double no28 = null; //_n1n3_
                    Integer no31 = null; //_n1n3_??
                    Double no32 = null; //_n1n3_
                    Double no15Percent = null;
                    if (yearmonth.after(monthly) && jiseki != null) {
                        int daysInMonth = DateUtil.getActualMaximumOfMonth(businessDay);
                        logger.info("Total days of month {} ", daysInMonth);

                        //                  // NO07 ???????? ? ????? ??1,000??????                  
                        //                  if (jiseki.getUriSkKG() != null) {
                        //                     double uriSkKG = jiseki.getUriSkKG().doubleValue();
                        //                     no07 = (int) ((uriSkKG - Math.floor(uriSkKG / (100 + taxRate) * taxRate)) / 1000);
                        //                     
                        //                     // NO08 ??????_??_??? ??1,000??????
                        //                     no08 = (no08 == null) ? 0 : no08.intValue();
                        //                     no08 += no07;
                        //                  }

                        // Modified by SONDN 2014/12/22: Update SPEC 20141222
                        // NO07 ???????? ? ????? ??1,000??????                  
                        if (jiseki.getUriSkKG() != null || jiseki.getKtSkKG() != null
                                || jiseki.getIdoSkKGU() != null || jiseki.getIdoSkKGH() != null) {
                            Double uriSkKG = jiseki.getUriSkKG();
                            Double ktSkKG = jiseki.getKtSkKG();
                            Double idoSkKGU = jiseki.getIdoSkKGU();
                            Double idoSkKGH = jiseki.getIdoSkKGH();
                            double step1 = uriSkKG == null ? 0
                                    : uriSkKG - Math.floor((uriSkKG / (100 + taxRate)) * taxRate);
                            double step2 = ktSkKG == null ? 0 : ktSkKG;
                            int days = DateUtil.getNumberOfDays(yearmonth, businessDay);
                            if (days > 0) {
                                step2 = (step2 / daysInMonth) * days;
                            }
                            double step3 = idoSkKGU == null ? 0 : idoSkKGU;
                            double step4 = idoSkKGH == null ? 0 : idoSkKGH;
                            no07 = (int) Math.floor((step1 + step2 + step3 - step4) / 1000);

                            // NO08 ??????_??_??? ??1,000??????
                            no08 = (no08 == null) ? 0 : no08.intValue();
                            no08 += no07;
                        }

                        // (1) ? ????
                        double temp1 = 0d;
                        if (jiseki.getUriKrKG() != null) {
                            double uriKrKG = jiseki.getUriKrKG().doubleValue();
                            temp1 = uriKrKG - Math.floor(uriKrKG / (100 + taxRate) * taxRate);
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1
                        }

                        // (2) ? ???
                        double temp2 = 0d;
                        if (jiseki.getKtKrKG() != null) {
                            temp2 = jiseki.getKtKrKG().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 11
                        }

                        int days = DateUtil.getNumberOfDays(yearmonth, businessDay);
                        if (days > 0) {
                            temp1 = (temp1 / daysInMonth) * days;
                            temp2 = (temp2 / daysInMonth) * days;
                        } else if (days == 0) {
                            strValueBlank = "11";
                        }

                        // NO09 ????????(1) + (2)
                        if (!strValueBlank.equals("11")) {
                            no09 = (no09 == null) ? 0 : no09.intValue();
                            no09 = (int) ((temp1 + temp2) / 1000);

                            // NO10 ??????_?_???   ??1,000??????
                            no10 = (no10 == null) ? 0 : no10.intValue();
                            no10 += no09;
                        }

                        // NO11 ????????   _??__???  _?__??? ??1,000??????2
                        if (no07 != null || no09 != null) {
                            int temp07 = (no07 == null) ? 0 : no07.intValue();
                            int temp09 = (no09 == null) ? 0 : no09.intValue();
                            no11 = (no11 == null) ? 0 : no11.intValue();
                            no11 = temp07 + temp09;
                        }

                        // NO17 ?????????   ????????  ??1,000??????
                        Double amount = (mapAT015 != null) ? mapAT015.get(getsudo) : null;
                        if (amount != null && amount.doubleValue() != -1d) {
                            no17 = (int) (amount.doubleValue() / 1000);
                        }

                        // NO13 ?????????????????? ??1,000??????
                        if (no17 != null) {
                            Date preMonth = DateUtil.monthsToSubtract(yearmonth, 1);
                            int previousGetSudo = Integer
                                    .parseInt(DateFormatUtil.format(preMonth, DateFormat.DATE_WITHOUT_DAY));
                            Double temp = (mapAT015 != null)
                                    ? (Double) mapAT015.get(String.valueOf(previousGetSudo))
                                    : null;
                            if (temp != null && temp.doubleValue() != -1) {
                                // Change SPEC 01/09/2014 
                                if (days != -1 && no17 == 0) {
                                    no13 = null;
                                    no17 = null;
                                } else {
                                    no13 = (int) (temp.doubleValue() / 1000);
                                } // End change SPEC 01/09/2014 
                            }
                        }
                        // ????????
                        strValueBlank = "";
                        double ktsrkg = 0d;

                        // (1) ? ?
                        if (jiseki.getKtSrKG() != null) {
                            ktsrkg = jiseki.getKtSrKG().doubleValue();
                            if (days >= 0) {
                                ktsrkg = (ktsrkg / daysInMonth) * days;
                            }
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1
                        }
                        // (2) ? ??
                        double kgcSrKG = 0d;
                        if (jiseki.getKgcSrKG() != null) {
                            kgcSrKG = jiseki.getKgcSrKG().doubleValue();
                            kgcSrKG = kgcSrKG - Math.floor(kgcSrKG / (100 + taxRate) * taxRate);
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 11
                        }

                        // (3) ? ??????
                        double idoSrkGU = 0d;
                        if (jiseki.getIdoSrKGU() != null) {
                            idoSrkGU = jiseki.getIdoSrKGU().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 111
                        }

                        // (4) ? ??
                        double idoSrkGH = 0d;
                        if (jiseki.getIdoSrKGH() != null) {
                            idoSrkGH = jiseki.getIdoSrKGH().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 1111
                        }

                        // (5) ? ?
                        double knSrKG = 0d;
                        if (jiseki.getKnSrKG() != null) {
                            knSrKG = jiseki.getKnSrKG().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 11111
                        }

                        // (1) + (2) + (3) + (4) - (5)
                        if (!strValueBlank.equals("11111")) {
                            no15 = (int) ((knSrKG + ktsrkg + kgcSrKG + idoSrkGU - idoSrkGH) / 1000);
                        }

                        // NO23 ????????
                        strValueBlank = "";

                        // (1) ? ??
                        double ktJkKG = 0d;
                        if (jiseki.getKtJkKG() != null) {
                            ktJkKG = jiseki.getKtJkKG().doubleValue();
                            if (days >= 0) {
                                ktJkKG = (ktJkKG / daysInMonth) * days;
                            }
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1
                        }

                        // (2) ? ?            
                        double jkJkKG = 0d;
                        if (jiseki.getJkJkKG() != null) {
                            jkJkKG = jiseki.getJkJkKG().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 11
                        }
                        // (3) ? ??????         
                        double kgcJkKG = 0d;
                        if (jiseki.getKgcJkKG() != null) {
                            kgcJkKG = jiseki.getKgcJkKG().doubleValue();
                            kgcJkKG = kgcJkKG - Math.floor(kgcJkKG / (100 + taxRate) * taxRate);
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 111
                        }
                        // (4) ? ??
                        double idoJkKGU = 0d;
                        if (jiseki.getIdoJkKGU() != null) {
                            idoJkKGU = jiseki.getIdoJkKGU().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1111
                        }

                        // (5) ? ?
                        double idoJkKGH = 0d;
                        if (jiseki.getIdoJkKGH() != null) {
                            idoJkKGH = jiseki.getIdoJkKGH().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 11111
                        }

                        // (6) ? ??
                        double helpJkKGU = 0d;
                        if (jiseki.getHelpJkKGU() != null) {
                            helpJkKGU = jiseki.getHelpJkKGU().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 111111
                        }

                        // (7) ? ?
                        double helpJkKGH = 0d;
                        if (jiseki.getHelpJkKGH() != null) {
                            helpJkKGH = jiseki.getHelpJkKGH().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1111111
                        }

                        // (1) + (2) + (3) + (4) - (5) + (6) - (7)
                        if (!strValueBlank.equals("1111111")) {
                            no23 = (int) ((ktJkKG + jkJkKG + kgcJkKG + idoJkKGU - idoJkKGH + helpJkKGU - helpJkKGH)
                                    / 1000);
                        }

                        // NO27 ????????

                        // (1) ? ??
                        strValueBlank = "";
                        double ktKhKG = 0d;
                        if (jiseki.getKtKhKG() != null) {
                            ktKhKG = jiseki.getKtKhKG().doubleValue();
                            if (days >= 0) {
                                ktKhKG = ktKhKG / daysInMonth * days;
                            }
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank); // 1
                        }

                        // (2) ? ?
                        double knKhKG = 0d;
                        if (jiseki.getKnKhKG() != null) {
                            knKhKG = jiseki.getKnKhKG().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 11
                        }

                        // (3) ? ??????
                        double kgcKhKG = 0d;
                        if (jiseki.getKgcKhKG() != null) {
                            kgcKhKG = jiseki.getKgcKhKG().doubleValue();
                            kgcKhKG = kgcKhKG - Math.floor(kgcKhKG / (100 + taxRate) * taxRate);
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 111
                        }

                        // (4) ? ??
                        double idoKhKGU = 0d;
                        if (jiseki.getIdoKhKGU() != null) {
                            idoKhKGU = jiseki.getIdoKhKGU().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 1111
                        }

                        // (5) ? ?
                        double idoKhKGH = 0d;
                        if (jiseki.getIdoKhKGH() != null) {
                            idoKhKGH = jiseki.getIdoKhKGH().doubleValue();
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 11111
                        }

                        // (6) ? ??
                        double uriKhKG = 0d;
                        if (jiseki.getUriKhKG() != null) {
                            uriKhKG = jiseki.getUriKhKG().doubleValue();
                            uriKhKG = uriKhKG - Math.floor(uriKhKG / (100 + taxRate) * taxRate);
                            if (days >= 0) {
                                uriKhKG = uriKhKG / daysInMonth * days;
                            }
                        } else {
                            strValueBlank = strValueBlank.concat(valueBlank);// 111111
                        }

                        // (1) + (2) + (3) + (4) - (5) + (6)
                        if (!strValueBlank.equals("111111")) {
                            no27 = (int) ((ktKhKG + knKhKG + kgcKhKG + idoKhKGU - idoKhKGH + uriKhKG) / 1000);
                        }

                        // (NO19) _??_n_??__n_??-_?_n_??
                        if (no13 != null || no15 != null || no17 != null) {
                            int temp13 = (no13 == null) ? 0 : no13.intValue();
                            int temp15 = (no15 == null) ? 0 : no15.intValue();
                            int temp17 = (no17 == null) ? 0 : no17.intValue();
                            no19 = temp13 + temp15 - temp17;
                        }

                        // NO 31 ???????? ___???___???__???__??
                        if (no11 != null || no19 != null || no23 != null || no27 != null) {
                            int temp11 = (no11 == null) ? 0 : no11.intValue();
                            int temp19 = (no19 == null) ? 0 : no19.intValue();
                            int temp23 = (no23 == null) ? 0 : no23.intValue();
                            int temp27 = (no27 == null) ? 0 : no27.intValue();
                            no31 = temp11 - temp19 - temp23 - temp27;
                        }

                        //no15Percent

                    } else {
                        if (mapAT023 != null) {
                            // (N011) ??????????? ? =???
                            BudgetPerformance kingaku = (BudgetPerformance) mapAT023
                                    .get(getsudo + Constants.DEFAULT_KMKCODEJ_K7111);
                            if (kingaku != null && kingaku.getJisekiKingaku() != null) {
                                no11 = (int) (kingaku.getJisekiKingaku().doubleValue() / 1000);
                            }

                            // (NO15) ??????????? ? =???
                            kingaku = (BudgetPerformance) mapAT023.get(getsudo + Constants.DEFAULT_KMKCODEJ_K7521);
                            if (kingaku != null && kingaku.getJisekiKingaku() != null) {
                                no15 = (int) (kingaku.getJisekiKingaku().doubleValue() / 1000);
                            }

                            // (NO23) ???????????? =???
                            kingaku = (BudgetPerformance) mapAT023.get(getsudo + Constants.DEFAULT_KMKCODEJ_K8110);
                            if (kingaku != null && kingaku.getJisekiKingaku() != null) {
                                no23 = (int) (kingaku.getJisekiKingaku().doubleValue() / 1000);
                            }

                            // (NO27) ??????????? ? =???
                            kingaku = (BudgetPerformance) mapAT023.get(getsudo + Constants.DEFAULT_KMKCODEJ_K8210);
                            if (kingaku != null && kingaku.getJisekiKingaku() != null) {
                                no27 = (int) (kingaku.getJisekiKingaku().doubleValue() / 1000);
                            }

                            // NO 31 ???????????? =???
                            kingaku = (BudgetPerformance) mapAT023.get(getsudo + Constants.DEFAULT_KMKCODEJ_K8310);
                            if (kingaku != null && kingaku.getJisekiKingaku() != null) {
                                no31 = (int) (kingaku.getJisekiKingaku().doubleValue() / 1000);
                            }
                        }
                        // (NO19) _??_n_??__n_??-_?_n_??
                        if (no13 != null || no15 != null || no17 != null) {
                            int temp13 = (no13 == null) ? 0 : no13.intValue();
                            int temp15 = (no15 == null) ? 0 : no15.intValue();
                            int temp17 = (no17 == null) ? 0 : no17.intValue();
                            no19 = temp13 + temp15 - temp17;
                        }
                    }

                    if (no11 != null && no11.intValue() > 0) {

                        //(NO20) __n_???__n_??   ???
                        if (no19 != null) {
                            no20 = RoundNumericUtil.roundSonekiSuii(no19, no11);
                        }

                        // (NO24) _n_???__n_??   ???
                        if (no23 != null) {
                            no24 = RoundNumericUtil.roundSonekiSuii(no23, no11);
                        }

                        // (NO28) _n_???__n_?? ???
                        if (no27 != null) {
                            no28 = RoundNumericUtil.roundSonekiSuii(no27, no11);
                        }

                        // (NO32) _n_???__n_?? ???
                        if (no31 != null) {
                            no32 = RoundNumericUtil.roundSonekiSuii(no31, no11);
                        }

                        // NO15/NO07
                        if (no15 != null && (no07 != null && no07.intValue() > 0)) {
                            no15Percent = RoundNumericUtil.roundSonekiSuii(no15, no07);
                        }
                    }

                    int currentQuarter = Integer.parseInt(DateUtil.getQuarter(yearmonth)) - 1;
                    if (currentQuarter == 0) {
                        currentQuarter = 4;
                    }

                    // ??
                    if (quarter == currentQuarter) {
                        suisMonthly = new SuisMonthBean(no07, no09, no11, no13, no15, no17, no19, no20, no23, no24,
                                no27, no28, no31, no32, no15Percent);
                        setDataMonthly(index, suisMonthly, model);

                        logger.info("??");
                        index++;
                    }

                    // ?? (NO12, NO14, NO16, NO18, NO25, NO29, NO33)
                    if (no11 != null) {
                        no12 = (no12 == null) ? 0 : no12.intValue();
                        no12 += no11;
                    }
                    if (no13 != null) {
                        no14 = (no14 == null) ? 0 : no14.intValue();
                        no14 += no13;
                    }
                    if (no15 != null) {
                        no16 = (no16 == null) ? 0 : no16.intValue();
                        no16 += no15;
                    }
                    if (no17 != null) {
                        no18 = (no18 == null) ? 0 : no18.intValue();
                        no18 += no17;
                    }
                    if (no23 != null) {
                        no25 = (no25 == null) ? 0 : no25.intValue();
                        no25 += no23;
                    }
                    if (no27 != null) {
                        no29 = (no29 == null) ? 0 : no29.intValue();
                        no29 += no27;
                    }
                    if (no31 != null) {
                        no33 = (no33 == null) ? 0 : no33.intValue();
                        no33 += no31;
                    }
                } catch (NullPointerException | IllegalArgumentException | ParseException ex) {
                    logger.warn(ex.getMessage());
                }

                // (NO21) _??_n_??__n_??-_?_n_??
                if (no14 != null || no16 != null || no18 != null) {
                    int temp14 = (no14 == null) ? 0 : no14.intValue();
                    int temp16 = (no16 == null) ? 0 : no16.intValue();
                    int temp18 = (no18 == null) ? 0 : no18.intValue();
                    no21 = temp14 + temp16 - temp18;
                }

                if (no12 != null && no12.intValue() > 0) {

                    // (NO22) ___???___?? ???
                    if (no21 != null) {
                        no22 = RoundNumericUtil.roundSonekiSuii(no21, no12);
                    }

                    // (NO26) __???___?? ???
                    if (no25 != null) {
                        no26 = RoundNumericUtil.roundSonekiSuii(no25, no12);
                    }

                    // (NO30) __???___?? ???
                    if (no29 != null) {
                        no30 = RoundNumericUtil.roundSonekiSuii(no29, no12);
                    }

                    // (NO34) __???___?? ???
                    if (no33 != null) {
                        no34 = RoundNumericUtil.roundSonekiSuii(no33, no12);
                    }
                }
            }
        }
        // ?? 
        SuisTotalBean suisTotal = new SuisTotalBean(no08, no10, no12, no14, no16, no18, no21, no22, no25, no26,
                no29, no30, no33, no34);
        model.addAttribute(TOTAL_QUARTER, suisTotal);

        // 
        logger.info("End calculator suii for 3 month and total of year");
    }

    private Map<String, VJiseki> getSoduYear(Date startMonth, int countMonth) {
        Calendar bCalendar = Calendar.getInstance();
        Map<String, VJiseki> mapSuis = new TreeMap<String, VJiseki>();
        for (int i = 0; i < countMonth; i++) {
            bCalendar.setTime(startMonth);
            bCalendar.add(Calendar.MONTH, i);
            int month = bCalendar.get(Calendar.MONTH) + 1;
            mapSuis.put(
                    String.valueOf(bCalendar.get(Calendar.YEAR)) + String.valueOf(month < 10 ? "0" + month : month),
                    null);
        }
        return mapSuis;
    }

    private Map<String, VJiseki> getSuiiList(List<VJiseki> listSuis, Date startMonth, int countMonth) {
        Map<String, VJiseki> mapSuis = getSoduYear(startMonth, countMonth);
        if (CollectionUtils.isNotEmpty(listSuis)) {
            for (VJiseki VJiseki : listSuis) {
                mapSuis.put(VJiseki.getGetSudo(), VJiseki);
            }
        }
        return mapSuis;
    }

    private Date getMonthlyTighten(Date businessDay, Model model) {
        Date getSudoDate = null;
        try {
            Tighten tighten = tightenService.findByClassifyAndMonth("1");

            // 
            getSudoDate = DateFormatUtil.parse(tighten.getGetSudo(), DateFormat.DATE_WITHOUT_DAY);
        } catch (IllegalArgumentException | NullPointerException | ParseException | ObjectNotFoundException ex) {
            logger.warn(ex.getMessage());

            getSudoDate = DateUtil.monthsToSubtract(businessDay, 3);
        } catch (TooManyObjectsException | ServiceException ex) {
            throw new ServiceException(ex.getMessage());
        }
        return getSudoDate;
    }

    @Override
    public String getViewName() {
        return "suis/suis";
    }

    @Override
    public String getTitleName() {
        return "??";
    }
}