Subversion Repositories SmartDukaan

Rev

Rev 23405 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.service.indent;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.spice.profitmandi.common.enumuration.IndentStatus;
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.dao.entity.fofo.Indent;
import com.spice.profitmandi.dao.entity.fofo.IndentItem;
import com.spice.profitmandi.dao.repository.GenericRepository;
import com.spice.profitmandi.dao.repository.dtr.IndentItemRepository;
import com.spice.profitmandi.dao.repository.dtr.IndentRepository;

@Component
public class IndentServiceImpl implements IndentService{
        
        @Autowired 
        IndentRepository indentRepository;
        
        @Autowired 
        IndentItemRepository indentItemRepository;

        @Autowired 
        GenericRepository genericRepository;
        

        @Override
        public boolean updateOpenIndentItem(int fofoId, int itemId, int quantity) throws ProfitMandiBusinessException {
                Indent openIndent;
                List<Indent> openIndents = indentRepository.selectIndentByStatus(fofoId, IndentStatus.OPEN);
                if(openIndents.size()==0) {
                        openIndent = new Indent();
                        openIndent.setFofoId(fofoId);
                        openIndent.setStatus(IndentStatus.OPEN);
                        indentRepository.persist(openIndent);
                } else {
                        openIndent = openIndents.get(0);
                }
                
                IndentItem indentItem = indentItemRepository.selectIndentItemByItemId(openIndent.getId(), itemId);
                if(indentItem==null) {
                        indentItem = new IndentItem();
                        indentItem.setIndentId(openIndent.getId());
                        indentItem.setItemId(itemId);
                }
                if(quantity==0){
                        indentItemRepository.remove(indentItem.getIndentId(), itemId);
                } else {
                        indentItem.setRequestedQuantity(quantity);
                        indentItemRepository.persist(indentItem);
                }
                return true;
        }

}