NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
* Copyright 2006-2021 HighRadius Corporation
*/
package com.highradius.g4.service.redline.manager;

import static com.highradius.g4.service.redline.config.REDLINEDB.REDLINE_TXN;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.highradius.g4.core.common.G4Log;
import com.highradius.g4.core.common.G4LogManager;
import com.highradius.g4.redline.dto.FiscalCalendarDTO;
import com.highradius.g4.redline.entity.FiscalCalendar;
import com.highradius.g4.redline.entity.FiscalCalendarYear;
import com.highradius.g4.redline.entity.MapClosingUnitFiscalCalendar;
import com.highradius.g4.service.redline.dao.FiscalCalendarDAO;
import com.highradius.g4.service.redline.dao.FiscalCalendarYearDAO;
import com.highradius.g4.service.redline.dao.MapClosingUnitFiscalCalendarDAO;

/**
* The Class FiscalCalendarManager.
*
* @author sourav.m.
*/
@Component
public class FiscalCalendarManager {

/** The Constant LOGGER. */
private static final G4Log LOGGER = G4LogManager.getLog(FiscalCalendarManager.class);

/** The Constant ALREADY_MAPPED. */
private static final String ALREADY_MAPPED = "already mapped";

/** The Constant CONFIRMATION_YES. */
private static final String CONFIRMATION_YES = "yes";

/** The Constant CONFIRMATION_NO. */
private static final String CONFIRMATION_NO = "no";

/** The fiscal calendar DAO. */
@Autowired
private FiscalCalendarDAO fiscalCalendarDAO;

/** The fiscal calendar year DAO. */
@Autowired
private FiscalCalendarYearDAO fiscalCalendarYearDAO;

/** The map closing unit fiscal calendar DAO. */
@Autowired
private MapClosingUnitFiscalCalendarDAO mapClosingUnitFiscalCalendarDAO;

/**
* Gets the fiscal calendars.
*
* @param limit the limit
* @param offset the offset
* @param accountId the account id
* @return the fiscal calendars
*/
@Transactional(REDLINE_TXN)
public List<FiscalCalendar> getFiscalCalendars(Integer limit, Integer offset, Long accountId) {
LOGGER.debug("Getting all FiscalCalendars");
return fiscalCalendarDAO.getFiscalCalendars(limit, offset, accountId);
}

/**
* Gets the fiscal calendar.
*
* @param fiscalCalendarId the fiscal calendar id
* @param accountId the account id
* @return the fiscal calendar
*/
@Transactional(REDLINE_TXN)
public FiscalCalendar getFiscalCalendar(Long fiscalCalendarId, Long accountId) {
LOGGER.debug("Getting FiscalCalendar from id");
return fiscalCalendarDAO.getFiscalCalendar(fiscalCalendarId, accountId);
}

/**
* Gets the mapped closing unit id.
*
* @param holidayCalendarId the holiday calendar id
* @return the mapped closing unit id
*/
@Transactional(REDLINE_TXN)
public List<MapClosingUnitFiscalCalendar> getMappedClosingUnitId(Long holidayCalendarId) {
return fiscalCalendarDAO.getClosingUnitIds(holidayCalendarId);
}

/**
* Save fiscal calendar.
*
* @param userName the user name
* @param accountId the account id
* @param fiscalCalendarDTO the fiscal calendar DTO
* @return the fiscal calendar DTO
*/
@Transactional(REDLINE_TXN)
public FiscalCalendarDTO saveFiscalCalendar(String userName, Long accountId, FiscalCalendarDTO fiscalCalendarDTO) {
LOGGER.debug("Saving FiscalCalendar");
Timestamp createTime = new Timestamp(System.currentTimeMillis());
FiscalCalendar fiscalCalendar = new FiscalCalendar();
BeanUtils.copyProperties(fiscalCalendarDTO, fiscalCalendar);

fiscalCalendar.setCreateUser(userName);
fiscalCalendar.setUpdateUser(userName);
fiscalCalendar.setCreateDate(createTime);
fiscalCalendar.setUpdateDate(createTime);
fiscalCalendar.setAccountId(accountId);
fiscalCalendar.setIsDefault(fiscalCalendarDTO.getIsDefault());
fiscalCalendar.setIsCurrentYear(fiscalCalendarDTO.getIsCurrentYear());
FiscalCalendar savedFiscalCalendar = fiscalCalendarDAO.saveFiscalCalendar(fiscalCalendar, userName, accountId);

FiscalCalendarYear fiscalCalendarYear = new FiscalCalendarYear();
fiscalCalendarYear.setAccountId(accountId);
fiscalCalendarYear.setCreateDate(createTime);
fiscalCalendarYear.setCreateUser(userName);
fiscalCalendarYear.setUpdateDate(createTime);
fiscalCalendarYear.setUpdateUser(userName);
fiscalCalendarYear.setFiscalCalendar(savedFiscalCalendar);
fiscalCalendarYear.setYearStartDate(fiscalCalendarDTO.getYearStartDate());
fiscalCalendarYear.setYearEndDate(fiscalCalendarDTO.getYearEndDate());
fiscalCalendarYear.setQuarterOneEndDate(fiscalCalendarDTO.getQuarterOneEndDate());
fiscalCalendarYear.setQuarterTwoEndDate(fiscalCalendarDTO.getQuarterTwoEndDate());
fiscalCalendarYear.setQuarterThreeEndDate(fiscalCalendarDTO.getQuarterThreeEndDate());
fiscalCalendarYear.setQuarterFourEndDate(fiscalCalendarDTO.getQuarterFourEndDate());
fiscalCalendarYear.setHalfYearEndDate(fiscalCalendarYear.getHalfYearEndDate());
fiscalCalendarDAO.saveFiscalCalendarYear(fiscalCalendarYear);
BeanUtils.copyProperties(savedFiscalCalendar, fiscalCalendarDTO);

/**
* Here we check whether the is default is true not. If yes then we check
* whether the closing unit that are to be mapped are mapped to some other
* calendar or not. If yes then we send a status as "already mapped". If no then
* we can directly map these closing units. On sending the status as already
* mapped the user will get an alert. If the user confirms to over write then we
* make the necessary changes.
*/
if (fiscalCalendarDTO.getIsDefault()) {
List<Long> alreadyMappedclosingUnit = fiscalCalendarDAO.getAllMappedClosingUnitId();
if (!alreadyMappedclosingUnit.isEmpty()) {
fiscalCalendarDTO.setStatus(ALREADY_MAPPED);
return fiscalCalendarDTO;
} else {
fiscalCalendarDTO.setClosingUnitIds(fiscalCalendarDAO.getAllClosingUnits());
}
}
/**
* Here we check if any closing Unit ids exist or not. If those closing units
* are mapped to some other fiscal calendar then we set status as "already
* mapped", and user gets the alert. If the user confirms to over write then we
* make the necessary changes using another api call. If no closing are mapped
* they get mapped without any alert or confirmation.
*/
if (!fiscalCalendarDTO.getClosingUnitIds().isEmpty()) {
List<MapClosingUnitFiscalCalendar> alreadyMapped = fiscalCalendarDAO
.fetchMappedByUsers(fiscalCalendarDTO.getClosingUnitIds());
if (!alreadyMapped.isEmpty()) {
fiscalCalendarDTO.setStatus(ALREADY_MAPPED);
return fiscalCalendarDTO;
} else {
for (Long closingUnitId : fiscalCalendarDTO.getClosingUnitIds()) {
MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar = new MapClosingUnitFiscalCalendar();
mapClosingUnitFiscalCalendar.setAccountId(accountId);
mapClosingUnitFiscalCalendar.setClosingUnit(fiscalCalendarDAO.getClosingUnit(closingUnitId));
mapClosingUnitFiscalCalendar.setFiscalCalendar(savedFiscalCalendar);
mapClosingUnitFiscalCalendar.setCreateDate(createTime);
mapClosingUnitFiscalCalendar.setCreateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateDate(createTime);
fiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
}
}
return fiscalCalendarDTO;
}

/**
* Update fiscal calendar.
*
* @param userName the user name
* @param accountId the account id
* @param fiscalCalendarDTO the fiscal calendar DTO
* @return the fiscal calendar DTO
*/
@Transactional(REDLINE_TXN)
public FiscalCalendarDTO updateFiscalCalendar(String userName, Long accountId,
FiscalCalendarDTO fiscalCalendarDTO) {
LOGGER.debug("Updating FiscalCalendar");
Timestamp updateTime = new Timestamp(System.currentTimeMillis());
FiscalCalendar fiscalCalendar = fiscalCalendarDAO.findFiscalCalendar(fiscalCalendarDTO.getPkFiscalCalendar());
FiscalCalendarYear fiscalCalendarYear = fiscalCalendarYearDAO
.findFiscalCalendarYear(fiscalCalendarDTO.getPkFiscalCalendar());
BeanUtils.copyProperties(fiscalCalendarDTO, fiscalCalendar);
fiscalCalendar.setAccountId(accountId);
fiscalCalendar.setUpdateDate(updateTime);
fiscalCalendar.setUpdateUser(userName);
fiscalCalendar.setIsDefault(fiscalCalendarDTO.getIsDefault());
fiscalCalendar.setIsCurrentYear(fiscalCalendarDTO.getIsCurrentYear());

fiscalCalendarYear.setAccountId(accountId);
fiscalCalendarYear.setUpdateDate(updateTime);
fiscalCalendarYear.setUpdateUser(userName);
fiscalCalendarYear.setYearEndDate(fiscalCalendarDTO.getYearEndDate());
fiscalCalendarYear.setQuarterOneEndDate(fiscalCalendarDTO.getQuarterOneEndDate());
fiscalCalendarYear.setQuarterTwoEndDate(fiscalCalendarDTO.getQuarterTwoEndDate());
fiscalCalendarYear.setQuarterThreeEndDate(fiscalCalendarDTO.getQuarterThreeEndDate());
fiscalCalendarYear.setQuarterFourEndDate(fiscalCalendarDTO.getQuarterFourEndDate());
FiscalCalendar updatedFiscalCalendar = fiscalCalendarDAO.updateFiscalCalendar(fiscalCalendar);
fiscalCalendarYearDAO.updateFiscalCalendarYear(fiscalCalendarYear);

/**
* Here we are checking whether the is_default is true or not. If the user
* confirms to change we override the the previous mapping.
**/
if (fiscalCalendarDTO.getIsDefault() && CONFIRMATION_YES.equals(fiscalCalendarDTO.getConfirmation())) {
fiscalCalendarDTO.setStatus("");
fiscalCalendarDAO.handleIsDefault(updatedFiscalCalendar.getPkFiscalCalendar());
List<Long> allClosingUnits = fiscalCalendarDAO.getAllClosingUnits();
List<Long> alreadyMappedclosingUnit = fiscalCalendarDAO.getAllMappedClosingUnitId();
for (Long closingUnitId : allClosingUnits) {
List<MapClosingUnitFiscalCalendar> mapClosingUnitFiscalCalendars = fiscalCalendarDAO
.fetchMappedByUsers(alreadyMappedclosingUnit);
if (alreadyMappedclosingUnit.contains(closingUnitId)) {
for (MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar : mapClosingUnitFiscalCalendars) {
mapClosingUnitFiscalCalendar.setFiscalCalendar(updatedFiscalCalendar);
mapClosingUnitFiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
} else {
MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar = new MapClosingUnitFiscalCalendar();
mapClosingUnitFiscalCalendar.setCreateDate(updateTime);
mapClosingUnitFiscalCalendar.setCreateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateDate(updateTime);
mapClosingUnitFiscalCalendar.setUpdateUser(userName);
mapClosingUnitFiscalCalendar.setAccountId(accountId);
mapClosingUnitFiscalCalendar.setFiscalCalendar(updatedFiscalCalendar);
mapClosingUnitFiscalCalendar.setClosingUnit(fiscalCalendarDAO.getClosingUnit(closingUnitId));
mapClosingUnitFiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
}
return fiscalCalendarDTO;
} else if (CONFIRMATION_NO.equals(fiscalCalendarDTO.getConfirmation()) && !fiscalCalendarDTO.getIsDefault()
&& fiscalCalendarDTO.getClosingUnitIds().isEmpty()) {
fiscalCalendarDTO.setStatus("");
return fiscalCalendarDTO;
}
/**
* Here the user sends certain closing unit manually without setting it as
* default. If the closing unit is mapped to some other fiscal calendars then we
* send the status as "already mapped". If the user confirms to change we
* override the the previous mapping(s).
*/
else if (!fiscalCalendarDTO.getClosingUnitIds().isEmpty()
&& CONFIRMATION_YES.equals(fiscalCalendarDTO.getConfirmation())) {
fiscalCalendarDTO.setStatus("");
List<MapClosingUnitFiscalCalendar> mapClosingUnitFiscalCalendars = fiscalCalendarDAO
.fetchMappedByUsers(fiscalCalendarDTO.getClosingUnitIds());

for (MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar : mapClosingUnitFiscalCalendars) {
fiscalCalendarDTO.getClosingUnitIds()
.remove(mapClosingUnitFiscalCalendar.getClosingUnit().getPkClosingUnitId());
mapClosingUnitFiscalCalendar.setFiscalCalendar(updatedFiscalCalendar);
mapClosingUnitFiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
for (Long closingUnitId : fiscalCalendarDTO.getClosingUnitIds()) {
MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar = new MapClosingUnitFiscalCalendar();
mapClosingUnitFiscalCalendar.setCreateDate(updateTime);
mapClosingUnitFiscalCalendar.setCreateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateDate(updateTime);
mapClosingUnitFiscalCalendar.setUpdateUser(userName);
mapClosingUnitFiscalCalendar.setAccountId(accountId);
mapClosingUnitFiscalCalendar.setFiscalCalendar(updatedFiscalCalendar);
mapClosingUnitFiscalCalendar.setClosingUnit(fiscalCalendarDAO.getClosingUnit(closingUnitId));
mapClosingUnitFiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
return fiscalCalendarDTO;
}
/**
* Here we are checking whether the is default is true or not. If is_default is
* true and the closing unit is mapped to some other fiscal calendars then we
* send the status as "already mapped" and we make any previous existing default
* fiscal calendar as false. If the user confirms to change we over write the
* the previous mapping.
**/
else if (fiscalCalendarDTO.getIsDefault() && CONFIRMATION_NO.equals(fiscalCalendarDTO.getConfirmation())) {
List<Long> alreadyMappedclosingUnit = fiscalCalendarDAO.getAllMappedClosingUnitId();
if (!alreadyMappedclosingUnit.isEmpty()) {
fiscalCalendarDTO.setStatus(ALREADY_MAPPED);
return fiscalCalendarDTO;
} else {
fiscalCalendarDTO.setClosingUnitIds(fiscalCalendarDAO.getAllClosingUnits());
fiscalCalendarDTO.setStatus("");
}
}

/**
* If is default is false and the closing unit mapped to some other fiscal
* calendars the we send the status as "already mapped" and we make any previous
* existing default fiscal calendar as false. If the user confirms to change we
* over write the the previous mapping.
**/
if (!fiscalCalendarDTO.getClosingUnitIds().isEmpty()
&& CONFIRMATION_NO.equals(fiscalCalendarDTO.getConfirmation())) {
List<MapClosingUnitFiscalCalendar> alreadyMapped = fiscalCalendarDAO
.fetchMappedByUsers(fiscalCalendarDTO.getClosingUnitIds());
if (!alreadyMapped.isEmpty()) {
fiscalCalendarDTO.setStatus(ALREADY_MAPPED);
return fiscalCalendarDTO;
} else {
for (Long closingUnitId : fiscalCalendarDTO.getClosingUnitIds()) {
MapClosingUnitFiscalCalendar mapClosingUnitFiscalCalendar = new MapClosingUnitFiscalCalendar();
if (mapClosingUnitFiscalCalendar.getClosingUnit() == null) {
mapClosingUnitFiscalCalendar.setAccountId(accountId);
mapClosingUnitFiscalCalendar.setClosingUnit(fiscalCalendarDAO.getClosingUnit(closingUnitId));
mapClosingUnitFiscalCalendar.setFiscalCalendar(updatedFiscalCalendar);
mapClosingUnitFiscalCalendar.setCreateDate(updateTime);
mapClosingUnitFiscalCalendar.setCreateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateUser(userName);
mapClosingUnitFiscalCalendar.setUpdateDate(updateTime);
} else {
mapClosingUnitFiscalCalendar.setDeleted(false);
}

fiscalCalendarDAO.saveMapClosingUnitFiscalCalendar(mapClosingUnitFiscalCalendar);
}
}
}

BeanUtils.copyProperties(updatedFiscalCalendar, fiscalCalendarDTO);
return fiscalCalendarDTO;
}

/**
* Gets the map closing unit fiscal calendars.
*
* @param fiscalCalendarIds the fiscal calendar ids
* @param accountId the account id
* @return the map closing unit fiscal calendars
*/
@Transactional(REDLINE_TXN)

public List<MapClosingUnitFiscalCalendar> getMapClosingUnitFiscalCalendars(List<Long> fiscalCalendarIds,
Integer accountId) {
return fiscalCalendarDAO.getMapClosingUnitFiscalCalendars(fiscalCalendarIds, accountId);
}

/**
* Gets the fiscal calendar year.
*
* @param fiscalCalendar the fiscal calendar
* @param accountId the account id
* @return the fiscal calendar year
*/
@Transactional(REDLINE_TXN)
public FiscalCalendarYear getFiscalCalendarYear(Long fiscalCalendar, Long accountId) {
LOGGER.debug("Inside getFiscalCalendarYear");
return fiscalCalendarDAO.getFiscalCalendarYear(fiscalCalendar, accountId);
}

/**
* Gets the total fiscal calendar count.
*
* @return the total fiscal calendar count
*/
@Transactional(REDLINE_TXN)
public Long getTotalFiscalCalendarCount() {
LOGGER.debug("Inside getTotalFiscalCalendarCount");
return fiscalCalendarDAO.getTotalFiscalCalendarCount();
}

/**
* Gets the total fiscal calendar is active count.
*
* @return the total fiscal calendar is active count
*/
@Transactional(REDLINE_TXN)
public Long getTotalFiscalCalendarIsActiveCount() {
LOGGER.debug("Inside getTotalFiscalCalendarIsActiveCount");
return fiscalCalendarDAO.getTotalFiscalCalendarIsActiveCount();
}

/**
* Search fiscal calendar.
*
* @param searchKeyword the searchKeyword
* @return the list
*/
@Transactional(REDLINE_TXN)
public List<FiscalCalendar> searchFiscalCalendars(String searchKeyword) {
LOGGER.debug("Entered into searchFiscalCalendars in FiscalCalendarManager");
return fiscalCalendarDAO.searchFiscalCalendars(searchKeyword);
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.