Subversion Repositories SmartDukaan

Rev

Rev 23405 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23405 amit.gupta 1
package com.spice.profitmandi.service.indent;
2
 
3
import java.util.List;
4
 
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.stereotype.Component;
7
 
8
import com.spice.profitmandi.common.enumuration.IndentStatus;
9
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
10
import com.spice.profitmandi.dao.entity.fofo.Indent;
11
import com.spice.profitmandi.dao.entity.fofo.IndentItem;
12
import com.spice.profitmandi.dao.repository.GenericRepository;
13
import com.spice.profitmandi.dao.repository.dtr.IndentItemRepository;
14
import com.spice.profitmandi.dao.repository.dtr.IndentRepository;
15
 
16
@Component
17
public class IndentServiceImpl implements IndentService{
18
 
19
	@Autowired 
20
	IndentRepository indentRepository;
21
 
22
	@Autowired 
23
	IndentItemRepository indentItemRepository;
24
 
25
	@Autowired 
26
	GenericRepository genericRepository;
27
 
28
 
29
	@Override
30
	public boolean updateOpenIndentItem(int fofoId, int itemId, int quantity) throws ProfitMandiBusinessException {
31
		Indent openIndent;
32
		List<Indent> openIndents = indentRepository.selectIndentByStatus(fofoId, IndentStatus.OPEN);
33
		if(openIndents.size()==0) {
34
			openIndent = new Indent();
35
			openIndent.setFofoId(fofoId);
36
			openIndent.setStatus(IndentStatus.OPEN);
37
			indentRepository.persist(openIndent);
38
		} else {
39
			openIndent = openIndents.get(0);
40
		}
41
 
42
		IndentItem indentItem = indentItemRepository.selectIndentItemByItemId(openIndent.getId(), itemId);
43
		if(indentItem==null) {
44
			indentItem = new IndentItem();
45
			indentItem.setIndentId(openIndent.getId());
46
			indentItem.setItemId(itemId);
47
		}
48
		if(quantity==0){
49
			indentItemRepository.remove(indentItem.getIndentId(), itemId);
50
		} else {
51
			indentItem.setRequestedQuantity(quantity);
52
			indentItemRepository.persist(indentItem);
53
		}
54
		return true;
55
	}
56
 
57
}