📄 fixedassetsserviceimpl.java
字号:
/**
* =============================================
* Copyright 2006 szmx
*
* Change Revision
* --------------------------------
* Date Author Remarks
* 2006-4-17 hliu Create com.szmx.tlms.finance.service.impl.FixedAssetsServiceImpl
* =============================================
*/
package com.szmx.tlms.finance.service.impl;
import com.szmx.tlms.TlmsServiceException;
import com.szmx.tlms.TlmsServiceErrorCodes;
import com.szmx.tlms.finance.dao.FixedAssetsDao;
import com.szmx.tlms.finance.model.FixedAssets;
import com.szmx.tlms.finance.model.VoucherHeader;
import com.szmx.tlms.finance.model.VoucherLine;
import com.szmx.tlms.finance.service.FixedAssetsService;
import com.szmx.tlms.finance.service.VoucherHeaderService;
import com.szmx.tlms.finance.service.VoucherNumService;
import com.szmx.framework.base.service.impl.BaseServiceImpl;
import org.apache.commons.beanutils.BeanUtils;
import java.util.*;
import java.math.BigDecimal;
/**
* This class is the implement of the FixedAssetsService
* @see FixedAssetsService
*
* @author hliu
* @since 2006-4-17
*/
public class FixedAssetsServiceImpl extends BaseServiceImpl implements FixedAssetsService {
private static final Integer STATUS_NEW=new Integer(1);
private static final Integer STATUS_IN_USE=new Integer(2);
private static final Integer STATUS_RETIREMENT=new Integer(3);
private VoucherHeaderService voucherHeaderService;
private VoucherNumService voucherNumService;
public void setVoucherHeaderService(VoucherHeaderService voucherHeaderService) {
this.voucherHeaderService = voucherHeaderService;
}
public void setVoucherNumService(VoucherNumService voucherNumService) {
this.voucherNumService = voucherNumService;
}
/**
* @see FixedAssetsService#getAndGenerateFixedAssets();
*/
public void getAndGenerateFixedAssets() throws TlmsServiceException {
Long fixedAssetsAccount = new Long(15501000);//todo bryan:the fixed assets's account will be set at system option set function.
// List voucherLines = voucherLineService.getVoucherLines(new VoucherLine());
//initial a VoucherHeader Object.This Object is used to search the un dealed Voucher from SAP
VoucherHeader unDealVoucherHeader = new VoucherHeader();
unDealVoucherHeader.setStatus(Boolean.FALSE);
List unDealVoucherHeaderList=new ArrayList();
//unDealVoucherHeaderList= voucherHeaderService.searchVoucherHeader("1",unDealVoucherHeader,null);
for (Iterator iterator = unDealVoucherHeaderList.iterator(); iterator.hasNext();) {
VoucherHeader tempVoucherHeader = (VoucherHeader) iterator.next();
Set voucherLines = tempVoucherHeader.getVoucherLines();
//If the voucher is about fixed assets,the isNewFlag will change to 1
int isNewFlag = 0;
//Iterator the voucherlines if the Record is fixed assets
for (Iterator iteratorVoucherLines = voucherLines.iterator(); iterator.hasNext();) {
VoucherLine tempVoucherLine = (VoucherLine) iteratorVoucherLines.next();
//If the account is Fixed Assets Account
if (tempVoucherLine.getAccount() != null
&& tempVoucherLine.getAccount().getSapAccountCode() != null
&& tempVoucherLine.getAccount().getSapAccountCode().equals(fixedAssetsAccount.toString())) {
isNewFlag = 1;
FixedAssets fixedAssets = new FixedAssets();
if (tempVoucherLine.getAssignment() != null) {
fixedAssets.setAssetsNumber(tempVoucherLine.getAssignment());
}
try {
initialFixedAsset(tempVoucherLine, fixedAssets);
saveFixedAssets(fixedAssets);
} catch (Exception e) {
throw new TlmsServiceException(e.getMessage());
}
//If text column start with "FA* is also the Fixed Assets
} else if (tempVoucherLine.getVoucherText() != null) {
//check if text column start with "FA*"
String voucherText = tempVoucherLine.getVoucherText().toLowerCase();
char textArray[] = new char[100];
voucherText.getChars(0, voucherText.length(), textArray, 0);
if (textArray.length >= 2 && textArray[0] == 'p' && textArray[1] == 'a') {
FixedAssets fixedAssets = new FixedAssets();
isNewFlag = 1;
try {
//save the fixed assets
initialFixedAsset(tempVoucherLine, fixedAssets);
saveFixedAssets(fixedAssets);
//This number is the number of the sequenceString
String sequenceNumber = fixedAssets.getId().toString();
//This String wiil be set to the fixed number
//It's format is several "0"+sequenceNumber
String sequenceString = "E";
//The length's length will be 8 characters.If the sequenceNumber's length is less then 8,
//The character '0' will be insert before the sequenceNumber in the sequenceString
//For example: 00000012
for (int i = sequenceNumber.length(); i < 8; i++) {
sequenceString += "0";
}
sequenceString += sequenceNumber;
//Set the assets number with sequenceString
fixedAssets.setAssetsNumber(sequenceString);
//Update the fixedAssets with new AssetsNumber
fixedAssets.populateUpdateBean(new Long(1));//todo bryan: get user id form session.
saveFixedAssets(fixedAssets);
} catch (Exception e) {
throw new TlmsServiceException(e.getMessage());
}
}
}
}
//Generate the Reverse Voucher
if (isNewFlag == 1) {
try {
VoucherHeader reverseVoucher = generateReverseVoucher(tempVoucherHeader);
voucherHeaderService.saveVoucherHeader("1",reverseVoucher.getCalendarPeriod(),reverseVoucher);//todo bryan:get company id from session
voucherNumService.updateFlowNo("1", reverseVoucher.getCalendarPeriod(), reverseVoucher.getVoucherType(), new Long(1));//todo bryan: get company id the user id form session
} catch (Exception e) {
e.printStackTrace();//todo bryan: only test
}
}
//todo bryan:Change the Voucher Header's status
}
}
/**
* @see FixedAssetsService#getFixedAssetses(FixedAssets fixedAssets);
*/
public List getFixedAssetses(FixedAssets fixedAssets) throws TlmsServiceException {
return ((FixedAssetsDao) baseDao).getFixedAssetses(fixedAssets);
}
/**
* @see FixedAssetsService#saveFixedAssets(FixedAssets fixedAssets);
*/
public void saveFixedAssets(FixedAssets fixedAssets) throws TlmsServiceException{
((FixedAssetsDao) baseDao).saveFixedAssets(fixedAssets);
}
/**
* @see FixedAssetsService#getAndGenerateFixedAssets();
*/
public void removeFixedAssetses(String[] id) throws TlmsServiceException {
for (int i = 0; i < id.length; i++) {
((FixedAssetsDao) baseDao).removeFixedAssets(new Long(Long.parseLong(id[i])));
}
}
/**
* @see FixedAssetsService#generateFixedAssetsVoucher(Long id)
*/
public void generateFixedAssetsVoucher(Long id) throws TlmsServiceException {
//Todo bryan: generate the Fixed Assets Voucher
FixedAssets fixedAssets = ((FixedAssetsDao) baseDao).getFixedAssets(id);
fixedAssets.getVoucherSysId();
}
/**
* Set some variable about the Fixed Assets
* @param voucherLine
* @param fixedAssets
*/
private void initialFixedAsset(VoucherLine voucherLine,FixedAssets fixedAssets){
if (voucherLine.getVoucherHeader() != null) {
//Set Date in Service
fixedAssets.setDateInService(voucherLine.getVoucherHeader().getPostingDate());
//Set VoucherNumber from VoucherHead Table
fixedAssets.setVoucherSysId(voucherLine.getVoucherHeader().getId());
//Set Company Code
fixedAssets.setCompanyId(voucherLine.getVoucherHeader().getCompany().getId());
}
fixedAssets.setOriginalCost(voucherLine.getAmount());
fixedAssets.setSalvageValuePercent(new Integer(10));
fixedAssets.setStatus(STATUS_NEW);
fixedAssets.populateCreateBean(new Long(1));//todo bryan: get the user id form session
}
private VoucherHeader generateReverseVoucher(VoucherHeader voucherHeader) throws Exception{
//todo bryan:this method have not finished yet
VoucherHeader reverseVoucher = new VoucherHeader();
BeanUtils.copyProperties(reverseVoucher, voucherHeader);
reverseVoucher.setId(null);
reverseVoucher.setVoucherLines(null);
Set reverseVoucherLineList = new HashSet();
Set voucherLines = reverseVoucher.getVoucherLines();
for (Iterator iterator = voucherLines.iterator(); iterator.hasNext();) {
VoucherLine tempVoucherline = (VoucherLine) iterator.next();
VoucherLine reverseVoucherLine = new VoucherLine();
BeanUtils.copyProperties(reverseVoucherLine, tempVoucherline);
reverseVoucherLine.setId(null);
reverseVoucherLine.setAmount(reverseVoucherLine.getAmount().negate());
reverseVoucherLine.setAmountInLc(reverseVoucherLine.getAmountInLc().negate());
reverseVoucherLine.setLc2Amount(reverseVoucherLine.getLc2Amount().negate());
reverseVoucherLineList.add(reverseVoucherLine);
}
reverseVoucher.setVoucherLines(reverseVoucherLineList);
String VoucherNumber=voucherNumService.generateVoucherNum("1",reverseVoucher.getCalendarPeriod(),reverseVoucher.getVoucherType(),new Long(1));//todo bryan:get compay id , get the user id form session
reverseVoucher.setVoucherNo(VoucherNumber);
return reverseVoucher;
}
/**
* @see FixedAssetsService#depricationFixedAssets()
* @throws TlmsServiceException
*/
public void depricationFixedAssets() throws TlmsServiceException {
FixedAssets searchCondition=new FixedAssets();
searchCondition.setStatus(STATUS_IN_USE);
List inUsedFixedAsset=getFixedAssetses(searchCondition);
for (Iterator iterator = inUsedFixedAsset.iterator(); iterator.hasNext();) {
FixedAssets tempFixedAssets = (FixedAssets) iterator.next();
//if these imformation is null ,System will not handle the function.
//it will give user some message to show the error
if (tempFixedAssets == null
|| tempFixedAssets.getOriginalCost() == null
|| tempFixedAssets.getLifeMonth() == null
|| tempFixedAssets.getSalvageValuePercent()==null) {
throw new TlmsServiceException(TlmsServiceErrorCodes.SERVICE_ERROR_FI007);
} else {
//initialize variable
BigDecimal originalCost = tempFixedAssets.getOriginalCost();
BigDecimal accumulatedValue = tempFixedAssets.getAccumulatedDepreciation();
BigDecimal salvageValue= tempFixedAssets.getSalvageValue();
Integer liftMonth = tempFixedAssets.getLifeMonth();
Integer salvageValuePercent= tempFixedAssets.getSalvageValuePercent();
//If the accumulatedValue is null ,It's the first time the Fixed Assets depricate.
if (accumulatedValue == null) {
accumulatedValue = new BigDecimal(0);
}
//If the salvageValue is null,than calculate it and set it to the FixedAssets.salvageValue
if (salvageValue == null) {
salvageValue = originalCost
.multiply(new BigDecimal(salvageValuePercent.longValue()))
.divide(new BigDecimal(100),3,BigDecimal.ROUND_HALF_UP);
tempFixedAssets.setSalvageValue(salvageValue);
}
// Calculate the value that every month depreciate
BigDecimal valueEveryMonth = originalCost
.subtract(salvageValue)
.divide(new BigDecimal(liftMonth.longValue()), BigDecimal.ROUND_HALF_UP);
//accumulatedValue less than (originalCost - salvageValue),depreciate the fixed assets
if (accumulatedValue.compareTo(originalCost.subtract(salvageValue)) == -1) {
if (accumulatedValue.add(salvageValue).add(salvageValue).compareTo(originalCost.subtract(salvageValue)) != 1) {
//Increase the accumulated value for deprecation and set it to the FixedAssets.accumulatedDepreciation
tempFixedAssets.setAccumulatedDepreciation(accumulatedValue.add(valueEveryMonth));
} else {
tempFixedAssets.setAccumulatedDepreciation(originalCost.subtract(salvageValue));
}
}
}
saveFixedAssets(tempFixedAssets);
//todo bryan:Generate the depreciation Voucher
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -