Skip to content

Commit

Permalink
Merge pull request #225 from Jzow/master
Browse files Browse the repository at this point in the history
Add collection view and modal
  • Loading branch information
wansenai-bot authored Nov 23, 2023
2 parents 746e665 + c2ffab6 commit d4be7b6
Show file tree
Hide file tree
Showing 14 changed files with 1,027 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ public Response<String> updateRefundStatus(@PathVariable("ids") List<Long> ids,
public Response<String> deleteRefund(@PathVariable("ids") List<Long> ids) {
return receiptSaleService.deleteSaleRefund(ids);
}

@PostMapping("/arrears/pageList")
public Response<Page<SaleArrearsVO>> arrearsPageList(@RequestBody QuerySaleArrearsDTO arrearsDTO) {
return receiptSaleService.getSaleArrearsPage(arrearsDTO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansenai.dto.receipt.sale;

import lombok.Data;

@Data
public class QuerySaleArrearsDTO {

private Long customerId;

private String receiptNumber;

private String productInfo;

private String startDate;

private String endDate;

private Long page;

private Long pageSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
@AllArgsConstructor
public class CollectionDetailVO {

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long customerId;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansenai.vo.receipt.sale;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wansenai.bo.BigDecimalSerializerBO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SaleArrearsVO {

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;

private String customerName;

private String receiptNumber;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime receiptDate;

private String productInfo;

private String operatorName;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal thisReceiptArrears;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal receivedArrears;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal receivableArrears;
}
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ public Response<String> generateSnowflakeId(String type) {
case "收入单" -> "SRD";
case "支出单" -> "ZCD";
case "转账单" -> "ZZD";
case "收款单" -> "SKD";
case "付款单" -> "FKD";
case "采购单" -> "CGD";
case "销售单" -> "XSD";
case "退货单" -> "THD";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -112,6 +113,7 @@ public Response<Page<CollectionVO>> getCollectionReceiptPageList(QueryCollection
.ge(StringUtils.hasLength(queryCollectionDTO.getStartDate()), FinancialMain::getReceiptDate, queryCollectionDTO.getStartDate())
.le(StringUtils.hasLength(queryCollectionDTO.getEndDate()), FinancialMain::getReceiptDate, queryCollectionDTO.getEndDate())
.eq(FinancialMain::getType, "收款")
.eq(FinancialMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.page(page);

var collectionVOList = new ArrayList<CollectionVO>(financialMainPage.getRecords().size() + 1);
Expand Down Expand Up @@ -146,6 +148,9 @@ public Response<CollectionDetailVO> getCollectionReceiptDetail(Long id) {
var financialMain = getById(id);
if(financialMain != null) {
var collectionDetailVO = CollectionDetailVO.builder()
.id(financialMain.getId())
.customerId(financialMain.getRelatedPersonId())
.customerName(commonService.getCustomerName(financialMain.getRelatedPersonId()))
.receiptDate(financialMain.getReceiptDate())
.receiptNumber(financialMain.getReceiptNumber())
.financialPersonId(financialMain.getOperatorId())
Expand Down Expand Up @@ -209,7 +214,7 @@ public Response<String> addOrUpdateCollectionReceipt(AddOrUpdateCollectionDTO ad
.accountId(addOrUpdateCollectionDTO.getCollectionAccountId())
.otherReceipt(item.getSaleReceiptNumber())
.ReceivablePaymentArrears(item.getReceivableArrears())
.ReceivedPrepaidArrears(item.getReceivedArrears())
.ReceivedPrepaidArrears(Optional.ofNullable(item.getReceivedArrears()).orElse(BigDecimal.ZERO).add(item.getThisCollectionAmount()))
.singleAmount(item.getThisCollectionAmount())
.remark(item.getRemark())
.createBy(userId)
Expand Down Expand Up @@ -283,7 +288,7 @@ public Response<String> addOrUpdateCollectionReceipt(AddOrUpdateCollectionDTO ad
.accountId(addOrUpdateCollectionDTO.getCollectionAccountId())
.otherReceipt(item.getSaleReceiptNumber())
.ReceivablePaymentArrears(item.getReceivableArrears())
.ReceivedPrepaidArrears(item.getReceivedArrears())
.ReceivedPrepaidArrears(Optional.ofNullable(item.getReceivedArrears()).orElse(BigDecimal.ZERO).add(item.getThisCollectionAmount()))
.singleAmount(item.getThisCollectionAmount())
.remark(item.getRemark())
.createBy(userId)
Expand Down Expand Up @@ -321,6 +326,12 @@ public Response<String> deleteBatchCollectionReceipt(List<Long> ids) {
.set(FinancialMain::getDeleteFlag, CommonConstants.DELETED)
.in(FinancialMain::getId, ids)
.update();

financialSubService.lambdaUpdate()
.set(FinancialSub::getDeleteFlag, CommonConstants.DELETED)
.in(FinancialSub::getFinancialMainId, ids)
.update();

if(!deleteResult) {
return Response.responseMsg(CollectionPaymentCodeEnum.DELETE_COLLECTION_RECEIPT_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,15 @@ public interface ReceiptSaleService extends IService<ReceiptSaleMain> {
* 返回修改结果
*/
Response<String> updateSaleRefundStatus(List<Long> ids, Integer status);

/**
* Query sales debt documents
* 查询销售欠款单据
*
* @param arrearsDTO Query common conditions
* 查询公共条件
* @return Returns paginated data
* 返回分页数据
*/
Response<Page<SaleArrearsVO>> getSaleArrearsPage(QuerySaleArrearsDTO arrearsDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
import com.wansenai.bo.FileDataBO;
import com.wansenai.bo.SalesDataBO;
import com.wansenai.dto.receipt.sale.*;
import com.wansenai.entities.financial.FinancialMain;
import com.wansenai.entities.financial.FinancialSub;
import com.wansenai.entities.product.ProductStock;
import com.wansenai.entities.receipt.ReceiptSaleMain;
import com.wansenai.entities.receipt.ReceiptSaleSub;
import com.wansenai.entities.system.SysFile;
import com.wansenai.mappers.product.ProductStockKeepUnitMapper;
import com.wansenai.mappers.product.ProductStockMapper;
import com.wansenai.mappers.receipt.ReceiptSaleMainMapper;
import com.wansenai.mappers.system.SysFileMapper;
import com.wansenai.service.basic.CustomerService;
import com.wansenai.service.common.CommonService;
import com.wansenai.service.financial.CollectionReceiptService;
import com.wansenai.service.financial.FinancialSubService;
import com.wansenai.service.financial.IFinancialAccountService;
import com.wansenai.service.receipt.ReceiptSaleService;
import com.wansenai.service.receipt.ReceiptSaleSubService;
Expand Down Expand Up @@ -61,21 +64,23 @@ public class ReceiptSaleServiceImpl extends ServiceImpl<ReceiptSaleMainMapper, R
private final ISysUserService userService;
private final ReceiptSaleSubService receiptSaleSubService;
private final SysFileMapper fileMapper;
private final ProductStockKeepUnitMapper productStockKeepUnitMapper;
private final CommonService commonService;
private final ProductStockMapper productStockMapper;
private final IFinancialAccountService accountService;
private final CollectionReceiptService collectionReceiptService;
private final FinancialSubService financialSubService;

public ReceiptSaleServiceImpl(ReceiptSaleMainMapper receiptSaleMainMapper, CustomerService customerService, ISysUserService userService, ReceiptSaleSubService receiptSaleSubService, SysFileMapper fileMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper, CommonService commonService, ProductStockMapper productStockMapper, IFinancialAccountService accountService) {
public ReceiptSaleServiceImpl(ReceiptSaleMainMapper receiptSaleMainMapper, CustomerService customerService, ISysUserService userService, ReceiptSaleSubService receiptSaleSubService, SysFileMapper fileMapper, CommonService commonService, ProductStockMapper productStockMapper, IFinancialAccountService accountService, CollectionReceiptService collectionReceiptService, FinancialSubService financialSubService) {
this.receiptSaleMainMapper = receiptSaleMainMapper;
this.customerService = customerService;
this.userService = userService;
this.receiptSaleSubService = receiptSaleSubService;
this.fileMapper = fileMapper;
this.productStockKeepUnitMapper = productStockKeepUnitMapper;
this.commonService = commonService;
this.productStockMapper = productStockMapper;
this.accountService = accountService;
this.collectionReceiptService = collectionReceiptService;
this.financialSubService = financialSubService;
}

private final Map<Long, List<ReceiptSaleSub>> receiptSubListCache = new ConcurrentHashMap<>();
Expand All @@ -95,6 +100,13 @@ private BigDecimal calculateTotalAmount(List<ReceiptSaleSub> subList, Function<R
.setScale(2, RoundingMode.HALF_UP);
}

private BigDecimal calculateArrearsAmount(List<FinancialSub> subList, Function<FinancialSub, BigDecimal> mapper) {
return subList.stream()
.map(mapper.andThen(bd -> bd != null ? bd : BigDecimal.ZERO)) // 在这里添加空值检查
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

private int calculateProductNumber(List<ReceiptSaleSub> subList) {
return subList.stream()
.mapToInt(ReceiptSaleSub::getProductNumber)
Expand Down Expand Up @@ -1120,4 +1132,59 @@ public Response<String> deleteSaleRefund(List<Long> ids) {
public Response<String> updateSaleRefundStatus(List<Long> ids, Integer status) {
return updateSaleStatus(ids, status, SaleCodeEnum.UPDATE_SALE_REFUND_SUCCESS, SaleCodeEnum.UPDATE_SALE_REFUND_ERROR);
}

@Override
public Response<Page<SaleArrearsVO>> getSaleArrearsPage(QuerySaleArrearsDTO arrearsDTO) {
var result = new Page<SaleArrearsVO>();
var saleArrearsVOList = new ArrayList<SaleArrearsVO>();
var page = new Page<ReceiptSaleMain>(arrearsDTO.getPage(), arrearsDTO.getPageSize());
var queryWrapper = new LambdaQueryWrapper<ReceiptSaleMain>()
.eq(StringUtils.hasText(arrearsDTO.getReceiptNumber()), ReceiptSaleMain::getReceiptNumber, arrearsDTO.getReceiptNumber())
.eq(arrearsDTO.getCustomerId() != null, ReceiptSaleMain::getCustomerId, arrearsDTO.getCustomerId())
.eq(ReceiptSaleMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.gt(ReceiptSaleMain::getArrearsAmount, BigDecimal.ZERO)
.ge(StringUtils.hasText(arrearsDTO.getStartDate()), ReceiptSaleMain::getCreateTime, arrearsDTO.getStartDate())
.le(StringUtils.hasText(arrearsDTO.getEndDate()), ReceiptSaleMain::getCreateTime, arrearsDTO.getEndDate());

var queryResult = receiptSaleMainMapper.selectPage(page, queryWrapper);

queryResult.getRecords().forEach(item -> {
var customerName = getCustomerName(item.getCustomerId());
var operatorName = getUserName(item.getCreateBy());
var financeMainList = collectionReceiptService.lambdaQuery()
.eq(FinancialMain::getRelatedPersonId, item.getCustomerId())
.eq(FinancialMain::getStatus, CommonConstants.NOT_DELETED)
.list();
var saleArrearsVO = SaleArrearsVO.builder()
.id(item.getId())
.customerName(customerName)
.receiptDate(item.getReceiptDate())
.receiptNumber(item.getReceiptNumber())
.productInfo(item.getRemark())
.operatorName(operatorName)
.thisReceiptArrears(item.getArrearsAmount())
.build();
if(!financeMainList.isEmpty()) {

for (FinancialMain financialMain : financeMainList) {
var financeSubList = financialSubService.lambdaQuery()
.eq(FinancialSub::getFinancialMainId, financialMain.getId())
.eq(FinancialSub::getOtherReceipt, item.getReceiptNumber())
.eq(FinancialSub::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();
var receivableArrears = calculateArrearsAmount(financeSubList, FinancialSub::getReceivablePaymentArrears);
var receivedArrears = calculateArrearsAmount(financeSubList, FinancialSub::getReceivedPrepaidArrears);
saleArrearsVO.setReceivedArrears(receivedArrears);
saleArrearsVO.setReceivableArrears(item.getArrearsAmount().subtract(receivedArrears));
}
}
saleArrearsVOList.add(saleArrearsVO);
});
result.setRecords(saleArrearsVOList);
result.setTotal(queryResult.getTotal());
result.setCurrent(queryResult.getCurrent());
result.setSize(queryResult.getSize());

return Response.responseData(result);
}
}
12 changes: 11 additions & 1 deletion web/src/api/financial/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AddOrUpdateCollectionReq,
QueryCollectionReq,
CollectionResp,
CollectionDetailResp,
CollectionDetailResp, QuerySaleArrearsReq, SaleArrearsResp,
} from "@/api/financial/model/collectionModel";

enum API {
Expand All @@ -14,6 +14,7 @@ enum API {
DeleteBatch = '/financial/collection/deleteByIds',
UpdateStatus = '/financial/collection/updateStatusByIds',
GetDetail = '/financial/collection/getDetailById',
GetArrearsPage = '/sale/arrears/pageList',
}

export function getCollectionPageList(params: QueryCollectionReq, mode: ErrorMessageMode = 'notice') {
Expand Down Expand Up @@ -60,4 +61,13 @@ export function getCollectionDetailById(id: number) {
url: `${API.GetDetail}/${id}`
},
);
}

export function getArrearsPageList(params: QuerySaleArrearsReq) {
return defHttp.post<BaseDataResp<SaleArrearsResp>>(
{
url: API.GetArrearsPage,
params,
}
);
}
18 changes: 18 additions & 0 deletions web/src/api/financial/model/collectionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface CollectionResp {
}

export interface CollectionDetailResp {
id: string;
customerId: number;
customerName: string;
receiptDate: string;
Expand All @@ -65,4 +66,21 @@ export interface CollectionDetailResp {
status: number;
files: FileData[];
tableData: CollectionData[];
}

export interface QuerySaleArrearsReq {
customerId: number;
receiptNumber: string;
productInfo: string;
}

export interface SaleArrearsResp {
customerName: string;
receiptNumber: string;
receiptDate: string;
productInfo: string;
operatorName: string;
thisReceiptArrears: number;
receivedArrears: number;
receivableArrears: number;
}
Loading

0 comments on commit d4be7b6

Please sign in to comment.