| 32907 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled.purchaseorder;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.dao.entity.inventory.Vendor;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.warehouse.WarehousePurchaseOrder;
|
|
|
6 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
|
|
7 |
import com.spice.profitmandi.dao.repository.warehouse.WarehousePurchaseOrderRepository;
|
|
|
8 |
import in.shop2020.purchase.POStatus;
|
|
|
9 |
import in.shop2020.purchase.PurchaseOrder;
|
|
|
10 |
import org.apache.logging.log4j.core.config.Scheduled;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.stereotype.Component;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
|
|
|
15 |
import java.time.LocalDate;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
import java.util.Set;
|
|
|
18 |
import java.util.stream.Collectors;
|
|
|
19 |
|
|
|
20 |
@Component
|
|
|
21 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
22 |
public class POScheduler {
|
|
|
23 |
//Auto close non-internal vendor POs greater than seven days
|
|
|
24 |
@Autowired
|
|
|
25 |
WarehousePurchaseOrderRepository warehousePurchaseOrderRepository;
|
|
|
26 |
@Autowired
|
|
|
27 |
SupplierRepository supplierRepository;
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
public void autoClosePurchaseOrders() {
|
|
|
31 |
System.out.println("At autoclose pos");
|
|
|
32 |
List<WarehousePurchaseOrder> warehousePurchaseOrderList = warehousePurchaseOrderRepository.selectAllByStatus(POStatus.READY);
|
|
|
33 |
warehousePurchaseOrderList.addAll(warehousePurchaseOrderRepository.selectAllByStatus(POStatus.PARTIALLY_FULFILLED));
|
|
|
34 |
//Also ignore internal pos
|
|
|
35 |
Set<Integer> internalSupplierIds = supplierRepository.selectAll().stream().filter(x->x.isInternal()).map(x->x.getId()).collect(Collectors.toSet());
|
|
|
36 |
|
|
|
37 |
List<WarehousePurchaseOrder> posToClose = warehousePurchaseOrderList.stream()
|
|
|
38 |
.filter(x->!internalSupplierIds.contains(x.getSupplierId()))
|
|
|
39 |
.filter(x -> x.getCreatedAt().isBefore(LocalDate.now().minusDays(6).atStartOfDay()))
|
|
|
40 |
.collect(Collectors.toList());
|
|
|
41 |
for (WarehousePurchaseOrder warehousePurchaseOrder : posToClose) {
|
|
|
42 |
//System.out.println(warehousePurchaseOrder);
|
|
|
43 |
warehousePurchaseOrder.setStatus(POStatus.CLOSED);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
}
|
|
|
48 |
}
|