| Line 9... |
Line 9... |
| 9 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
9 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 11 |
import com.spice.profitmandi.dao.entity.fofo.StoreClosure;
|
11 |
import com.spice.profitmandi.dao.entity.fofo.StoreClosure;
|
| 12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 13 |
import com.spice.profitmandi.dao.enumuration.fofo.StoreClosureReason;
|
13 |
import com.spice.profitmandi.dao.enumuration.fofo.StoreClosureReason;
|
| - |
|
14 |
import com.spice.profitmandi.dao.enumuration.fofo.StoreStatusSource;
|
| 14 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
15 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 15 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
16 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 16 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
17 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 17 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
18 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 18 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
19 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| Line 29... |
Line 30... |
| 29 |
import java.time.format.DateTimeFormatter;
|
30 |
import java.time.format.DateTimeFormatter;
|
| 30 |
import java.util.*;
|
31 |
import java.util.*;
|
| 31 |
import java.util.stream.Collectors;
|
32 |
import java.util.stream.Collectors;
|
| 32 |
|
33 |
|
| 33 |
/**
|
34 |
/**
|
| 34 |
* Permanent partner store closure. A closure needs a reason, a remark and the approval mail
|
35 |
* Permanent partner store closure. A closure needs a SUSPENDED store with a ₹0 wallet and no open loan, a closer
|
| 35 |
* (uploaded via /document-upload), and queues a closure report with the approval attached to the partner's
|
36 |
* allowed by StoreStatusService, a reason, a remark and the approval mail (uploaded via /document-upload), and queues
|
| 36 |
* Sales L2, the top three Sales levels, the top Accounts level and the closer.
|
37 |
* a closure report with the approval attached to the partner's Sales L2, the top three Sales levels, the top Accounts
|
| - |
|
38 |
* level and the closer.
|
| 37 |
*/
|
39 |
*/
|
| 38 |
@Service
|
40 |
@Service
|
| 39 |
public class StoreClosureService {
|
41 |
public class StoreClosureService {
|
| 40 |
|
42 |
|
| 41 |
private static final Logger LOGGER = LogManager.getLogger(StoreClosureService.class);
|
43 |
private static final Logger LOGGER = LogManager.getLogger(StoreClosureService.class);
|
| Line 65... |
Line 67... |
| 65 |
private RetailerService retailerService;
|
67 |
private RetailerService retailerService;
|
| 66 |
|
68 |
|
| 67 |
@Autowired
|
69 |
@Autowired
|
| 68 |
private MailOutboxService mailOutboxService;
|
70 |
private MailOutboxService mailOutboxService;
|
| 69 |
|
71 |
|
| - |
|
72 |
@Autowired
|
| - |
|
73 |
private StoreStatusService storeStatusService;
|
| - |
|
74 |
|
| 70 |
public void closeStore(int fofoId, String storeCode, StoreClosureReason reason, String remark,
|
75 |
public void closeStore(int fofoId, String storeCode, StoreClosureReason reason, String remark,
|
| 71 |
int approvalDocumentId, String closedBy) throws ProfitMandiBusinessException {
|
76 |
int approvalDocumentId, String closedBy, StoreStatusSource source) throws ProfitMandiBusinessException {
|
| 72 |
StoreAccess.check(StoreAccess.CLOSE, closedBy, "close store");
|
- |
|
| 73 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
77 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 74 |
if (fofoStore.isClosed()) {
|
- |
|
| 75 |
throw new ProfitMandiBusinessException("Store Closed", "Store Already Closed",
|
78 |
String allowedAs = storeStatusService.assertCanClose(fofoStore, closedBy);
|
| 76 |
"This store is already permanently closed");
|
- |
|
| 77 |
}
|
- |
|
| 78 |
if (storeCode == null || !storeCode.equals(fofoStore.getCode())) {
|
79 |
if (storeCode == null || !storeCode.equals(fofoStore.getCode())) {
|
| 79 |
throw new ProfitMandiBusinessException("Invalid Store Code", "Store Code Mismatch",
|
80 |
throw new ProfitMandiBusinessException("Invalid Store Code", "Store Code Mismatch",
|
| 80 |
"Please type the correct store code to confirm closure");
|
81 |
"Please type the correct store code to confirm closure");
|
| 81 |
}
|
82 |
}
|
| 82 |
if (reason == null) {
|
83 |
if (reason == null) {
|
| Line 101... |
Line 102... |
| 101 |
throw new ProfitMandiBusinessException("Approval Mail", "Approval File Missing",
|
102 |
throw new ProfitMandiBusinessException("Approval Mail", "Approval File Missing",
|
| 102 |
"The uploaded approval mail could not be found, please upload it again");
|
103 |
"The uploaded approval mail could not be found, please upload it again");
|
| 103 |
}
|
104 |
}
|
| 104 |
|
105 |
|
| 105 |
LocalDateTime now = LocalDateTime.now();
|
106 |
LocalDateTime now = LocalDateTime.now();
|
| 106 |
fofoStore.setActive(false);
|
- |
|
| 107 |
fofoStore.setClosed(true);
|
- |
|
| 108 |
fofoStore.setClosedTimestamp(now);
|
- |
|
| 109 |
|
- |
|
| 110 |
StoreClosure storeClosure = new StoreClosure();
|
107 |
StoreClosure storeClosure = new StoreClosure();
|
| 111 |
storeClosure.setFofoId(fofoId);
|
108 |
storeClosure.setFofoId(fofoId);
|
| 112 |
storeClosure.setReason(reason);
|
109 |
storeClosure.setReason(reason);
|
| 113 |
storeClosure.setRemark(remark.trim());
|
110 |
storeClosure.setRemark(remark.trim());
|
| 114 |
storeClosure.setApprovalDocumentId(approvalDocumentId);
|
111 |
storeClosure.setApprovalDocumentId(approvalDocumentId);
|
| 115 |
storeClosure.setClosedBy(closedBy);
|
112 |
storeClosure.setClosedBy(closedBy);
|
| 116 |
storeClosure.setCreateTimestamp(now);
|
113 |
storeClosure.setCreateTimestamp(now);
|
| 117 |
storeClosureRepository.persist(storeClosure);
|
114 |
storeClosureRepository.persist(storeClosure);
|
| - |
|
115 |
storeStatusService.markClosed(fofoStore, storeClosure.getRemark(), closedBy, allowedAs, source, storeClosure.getId());
|
| 118 |
LOGGER.info("Store {} closed permanently by {} - {}", fofoStore.getCode(), closedBy, storeClosure);
|
116 |
LOGGER.info("Store {} closed permanently by {} - {}", fofoStore.getCode(), closedBy, storeClosure);
|
| 119 |
|
117 |
|
| 120 |
sendClosureReport(fofoStore, storeClosure, approvalDocument, approvalFile);
|
118 |
sendClosureReport(fofoStore, storeClosure, approvalDocument, approvalFile);
|
| 121 |
}
|
119 |
}
|
| 122 |
|
120 |
|