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