|
|
@@ -26,6 +26,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
@@ -80,37 +83,46 @@ public class EntryRecordService {
|
|
|
return entryRecordRepo.save(entryRecord);
|
|
|
}
|
|
|
|
|
|
- public List<EntryRecordDTO> showRecords(Long customerId, Long contractId, EntryType type, Long billId) {
|
|
|
- List<EntryRecord> entryRecords = entryRecordRepo.findAll((Specification<EntryRecord>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
- List<Predicate> and = new ArrayList<>();
|
|
|
- if (customerId != null) {
|
|
|
- and.add(criteriaBuilder.equal(root.get("customerId"), customerId));
|
|
|
- }
|
|
|
- if (contractId != null) {
|
|
|
- List<Long> billIds = contractBillRepo.findByContractId(contractId)
|
|
|
- .stream()
|
|
|
- .map(ContractBill::getId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- and.add(root.get("billId").in(billIds));
|
|
|
- }
|
|
|
- if (type != null) {
|
|
|
- and.add(criteriaBuilder.equal(root.get("type"), type));
|
|
|
- } else {
|
|
|
- and.add(criteriaBuilder.or(
|
|
|
- criteriaBuilder.equal(root.get("type"), EntryType.DEPOSIT),
|
|
|
- criteriaBuilder.equal(root.get("type"), EntryType.RECHARGE)
|
|
|
- ));
|
|
|
- }
|
|
|
- if (billId != null) {
|
|
|
- and.add(criteriaBuilder.equal(root.get("billId"), billId));
|
|
|
- }
|
|
|
- if (SecurityUtils.getAuthenticatedUser()
|
|
|
- .getAuthorities()
|
|
|
- .contains(Authority.getInstance(Authority.NAME.ROLE_SALE))) {
|
|
|
- and.add(criteriaBuilder.equal(root.get("userId"), SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
- }
|
|
|
- return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- });
|
|
|
+ public List<EntryRecordDTO> showRecords(Long customerId, Long contractId, EntryType type, Long billId, LocalDate start, LocalDate end, Long saleId) {
|
|
|
+ List<EntryRecord> entryRecords = entryRecordRepo
|
|
|
+ .findAll((Specification<EntryRecord>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = new ArrayList<>();
|
|
|
+ if (customerId != null) {
|
|
|
+ and.add(criteriaBuilder.equal(root.get("customerId"), customerId));
|
|
|
+ }
|
|
|
+ if (contractId != null) {
|
|
|
+ List<Long> billIds = contractBillRepo.findByContractId(contractId)
|
|
|
+ .stream()
|
|
|
+ .map(ContractBill::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ and.add(root.get("billId").in(billIds));
|
|
|
+ }
|
|
|
+ if (start != null & end != null) {
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .between(root.get("createdAt"), start.atStartOfDay(), end.atTime(LocalTime.MAX)));
|
|
|
+ }
|
|
|
+ if (saleId != null) {
|
|
|
+ and.add(criteriaBuilder.equal(root.get("userId"), saleId));
|
|
|
+ }
|
|
|
+ if (type != null) {
|
|
|
+ and.add(criteriaBuilder.equal(root.get("type"), type));
|
|
|
+ } else {
|
|
|
+ and.add(criteriaBuilder.or(
|
|
|
+ criteriaBuilder.equal(root.get("type"), EntryType.DEPOSIT),
|
|
|
+ criteriaBuilder.equal(root.get("type"), EntryType.RECHARGE)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ if (billId != null) {
|
|
|
+ and.add(criteriaBuilder.equal(root.get("billId"), billId));
|
|
|
+ }
|
|
|
+ if (SecurityUtils.getAuthenticatedUser()
|
|
|
+ .getAuthorities()
|
|
|
+ .contains(Authority.getInstance(Authority.NAME.ROLE_SALE))) {
|
|
|
+ and.add(criteriaBuilder
|
|
|
+ .equal(root.get("userId"), SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
+ }
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ });
|
|
|
List<EntryRecordDTO> dtos = new ArrayList<>();
|
|
|
entryRecords.removeIf(entryRecord -> entryRecord.getBillId() == null);
|
|
|
entryRecords.forEach(entryRecord -> {
|
|
|
@@ -127,7 +139,8 @@ public class EntryRecordService {
|
|
|
List<ReceiptStatus> receiptStatuses = new ArrayList<>();
|
|
|
receiptStatuses.add(ReceiptStatus.APPLY);
|
|
|
receiptStatuses.add(ReceiptStatus.COMPLETED);
|
|
|
- BillReceipt billReceipt = billReceiptRepo.findByBillIdAndStatusInAndBillTypeNot(billId, receiptStatuses, ReceiptType.DEPOSIT);
|
|
|
+ BillReceipt billReceipt = billReceiptRepo
|
|
|
+ .findByBillIdAndStatusInAndBillTypeNot(billId, receiptStatuses, ReceiptType.DEPOSIT);
|
|
|
EntryRecordDTO dto = EntryRecordDTO.builder()
|
|
|
.date(entryRecord.getCreatedAt().toLocalDate())
|
|
|
.source(contract.getContractSource().getDescription())
|