Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account flow views and api #201

Merged
merged 8 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.wansenai.service.receipt.ReceiptService;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
Expand Down Expand Up @@ -54,4 +55,13 @@ public Response<Page<StockFlowVO>> getStockFlow(@RequestBody QueryStockFlowDTO s
public Response<Page<AccountStatisticsVO>> getAccountStatistics(@RequestBody QueryAccountStatisticsDTO accountStatisticsDTO) {
return receiptService.getAccountStatistics(accountStatisticsDTO);
}

@GetMapping("accountFlow")
public Response<Page<AccountFlowVO>> getAccountFlow(
@RequestParam("accountId") Long accountId,
@RequestParam(value = "page", defaultValue = "1") Long page,
@RequestParam(value = "size", defaultValue = "10") Long pageSize
) {
return receiptService.getAccountFlow(accountId, page, pageSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.report;

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

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

@Data
@Builder
public class AccountFlowVO {

private String receiptNumber;

private String subType;

// 供应商 客户 会员
private String useType;

private String name;

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

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

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime receiptDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ public interface CommonService {
List<FileDataBO> getFileList(String fileId);

String getWarehouseName(Long warehouseId);

String getMemberName(Long memberId);

String getSupplierName(Long supplierId);

String getCustomerName(Long customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.wansenai.bo.FileDataBO;
import com.wansenai.entities.warehouse.Warehouse;
import com.wansenai.mappers.system.SysFileMapper;
import com.wansenai.service.BaseService;
import com.wansenai.service.product.ProductStockKeepUnitService;
Expand Down Expand Up @@ -102,6 +103,8 @@ public class CommonServiceImpl implements CommonService{

private final SysFileMapper fileMapper;

private final String NullString = "";

public CommonServiceImpl(RedisUtil redisUtil, Producer producer, SupplierService supplierService, CustomerService customerService, MemberService memberService, ISysPlatformConfigService platformConfigService, ProductService productService, ProductStockKeepUnitService productStockKeepUnitService, ProductStockService productStockService, ProductCategoryService productCategoryService, WarehouseService warehouseService, BaseService baseService, SysFileMapper fileMapper) {
this.redisUtil = redisUtil;
this.producer = producer;
Expand Down Expand Up @@ -720,7 +723,30 @@ public List<FileDataBO> getFileList(String fileId) {

@Override
public String getWarehouseName(Long warehouseId) {
return warehouseService.getById(warehouseId).getWarehouseName();
return Optional.ofNullable(warehouseService.getById(warehouseId))
.map(Warehouse::getWarehouseName)
.orElse(NullString);
}

@Override
public String getMemberName(Long memberId) {
return Optional.ofNullable(memberService.getById(memberId))
.map(Member::getMemberName)
.orElse(NullString);
}

@Override
public String getSupplierName(Long supplierId) {
return Optional.ofNullable(supplierService.getById(supplierId))
.map(Supplier::getSupplierName)
.orElse(NullString);
}

@Override
public String getCustomerName(Long customerId) {
return Optional.ofNullable(customerService.getById(customerId))
.map(Customer::getCustomerName)
.orElse(NullString);
}

private String getCellValue(Cell cell, DataFormatter dataFormatter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.wansenai.vo.receipt.ReceiptDetailVO;
import com.wansenai.vo.receipt.ReceiptVO;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
Expand All @@ -47,4 +48,6 @@ public interface ReceiptService {
Response<Page<StockFlowVO>> getStockFlow(QueryStockFlowDTO queryStockFlowDTO);

Response<Page<AccountStatisticsVO>> getAccountStatistics(QueryAccountStatisticsDTO accountStatisticsDTO);

Response<Page<AccountFlowVO>> getAccountFlow(Long accountId, Long page, Long pageSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.wansenai.dto.receipt.retail.QueryShipmentsDTO;
import com.wansenai.dto.receipt.retail.RetailRefundDTO;
import com.wansenai.dto.receipt.retail.RetailShipmentsDTO;
import com.wansenai.entities.financial.FinancialAccount;
import com.wansenai.entities.product.ProductStock;
import com.wansenai.entities.product.ProductStockKeepUnit;
import com.wansenai.entities.receipt.ReceiptRetailMain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.wansenai.service.basic.CustomerService;
import com.wansenai.service.basic.MemberService;
import com.wansenai.service.basic.SupplierService;
import com.wansenai.service.common.CommonService;
import com.wansenai.service.financial.IFinancialAccountService;
import com.wansenai.service.product.ProductService;
import com.wansenai.service.receipt.*;
Expand All @@ -41,6 +42,7 @@
import com.wansenai.vo.receipt.ReceiptDetailVO;
import com.wansenai.vo.receipt.ReceiptVO;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
Expand All @@ -52,6 +54,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

@Service
public class ReceiptServiceImpl implements ReceiptService {
Expand Down Expand Up @@ -84,7 +87,9 @@ public class ReceiptServiceImpl implements ReceiptService {

private final IFinancialAccountService accountService;

public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptRetailSubService receiptRetailSubService, ReceiptSaleService receiptSaleService, ReceiptSaleSubService receiptSaleSubService, ReceiptPurchaseService receiptPurchaseService, ReceiptPurchaseSubService receiptPurchaseSubService, MemberService memberService, CustomerService customerService, SupplierService supplierService, ISysUserService userService, ProductService productService, ProductStockMapper productStockMapper, WarehouseService warehouseService, IFinancialAccountService accountService) {
private final CommonService commonService;

public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptRetailSubService receiptRetailSubService, ReceiptSaleService receiptSaleService, ReceiptSaleSubService receiptSaleSubService, ReceiptPurchaseService receiptPurchaseService, ReceiptPurchaseSubService receiptPurchaseSubService, MemberService memberService, CustomerService customerService, SupplierService supplierService, ISysUserService userService, ProductService productService, ProductStockMapper productStockMapper, WarehouseService warehouseService, IFinancialAccountService accountService, CommonService commonService) {
this.receiptRetailService = receiptRetailService;
this.receiptRetailSubService = receiptRetailSubService;
this.receiptSaleService = receiptSaleService;
Expand All @@ -99,6 +104,7 @@ public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptReta
this.productStockMapper = productStockMapper;
this.warehouseService = warehouseService;
this.accountService = accountService;
this.commonService = commonService;
}

private String getProductName(Long id) {
Expand Down Expand Up @@ -669,13 +675,10 @@ public Response<Page<StockFlowVO>> getStockFlow(QueryStockFlowDTO queryStockFlow

int startIndex = (int) ((page.getCurrent() - 1) * page.getSize());
int endIndex = (int) Math.min(startIndex + page.getSize(), stockFlowVos.size());

startIndex = Math.min(startIndex, endIndex);
List<StockFlowVO> pagedStockFlowVos = new ArrayList<>(stockFlowVos.subList(startIndex, endIndex));

page.setRecords(pagedStockFlowVos);
page.setTotal(stockFlowVos.size());

return Response.responseData(page);

}
Expand Down Expand Up @@ -799,4 +802,84 @@ public Response<Page<AccountStatisticsVO>> getAccountStatistics(QueryAccountStat

return Response.responseData(result);
}

@Override
public Response<Page<AccountFlowVO>> getAccountFlow(Long accountId, Long page, Long pageSize) {
if (accountId == null) {
return Response.responseMsg(BaseCodeEnum.PARAMETER_NULL);
}
var account = accountService.getById(accountId);
var retailData = receiptRetailService.lambdaQuery()
.eq(ReceiptRetailMain::getAccountId, accountId)
.eq(ReceiptRetailMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();

var accountAmount = new AtomicReference<>(account.getInitialAmount());
var accountFlowVos = new ArrayList<AccountFlowVO>();
if (!retailData.isEmpty()) {
retailData.forEach(retail -> {
accountAmount.accumulateAndGet(Optional.ofNullable(retail.getChangeAmount()).orElse(BigDecimal.ZERO), BigDecimal::add);
var accountFlowVO = AccountFlowVO.builder()
.receiptNumber(retail.getReceiptNumber())
.receiptDate(retail.getReceiptDate())
.subType(retail.getSubType())
.useType("会员")
.name(commonService.getMemberName(retail.getMemberId()))
.amount(retail.getChangeAmount() == null ? BigDecimal.ZERO : retail.getChangeAmount())
.balance(accountAmount.get())
.build();
accountFlowVos.add(accountFlowVO);
});
}
var salesData = receiptSaleService.lambdaQuery()
.eq(ReceiptSaleMain::getAccountId, accountId)
.eq(ReceiptSaleMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();
if (!salesData.isEmpty()) {
salesData.forEach(sale -> {
accountAmount.accumulateAndGet(Optional.ofNullable(sale.getChangeAmount()).orElse(BigDecimal.ZERO), BigDecimal::add);
var accountFlowVO = AccountFlowVO.builder()
.receiptNumber(sale.getReceiptNumber())
.receiptDate(sale.getReceiptDate())
.subType(sale.getSubType())
.useType("客户")
.name(commonService.getCustomerName(sale.getCustomerId()))
.amount(sale.getChangeAmount() == null ? BigDecimal.ZERO : sale.getChangeAmount())
.balance(accountAmount.get())
.build();
accountFlowVos.add(accountFlowVO);
});
}

var purchaseData = receiptPurchaseService.lambdaQuery()
.eq(ReceiptPurchaseMain::getAccountId, accountId)
.eq(ReceiptPurchaseMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();
if (!purchaseData.isEmpty()) {
purchaseData.forEach(purchase -> {
accountAmount.accumulateAndGet(Optional.ofNullable(purchase.getChangeAmount()).orElse(BigDecimal.ZERO), BigDecimal::add);
var accountFlowVO = AccountFlowVO.builder()
.receiptNumber(purchase.getReceiptNumber())
.receiptDate(purchase.getReceiptDate())
.subType(purchase.getSubType())
.useType("供应商")
.name(commonService.getSupplierName(purchase.getSupplierId()))
.amount(purchase.getChangeAmount() == null ? BigDecimal.ZERO : purchase.getChangeAmount())
.balance(accountAmount.get())
.build();
accountFlowVos.add(accountFlowVO);
});
}
accountFlowVos.sort(Comparator.comparing(AccountFlowVO::getReceiptDate).reversed());

var result = new Page<AccountFlowVO>(page, pageSize);
int startIndex = (int) ((result.getCurrent() - 1) * result.getSize());
int endIndex = (int) Math.min(startIndex + result.getSize(), accountFlowVos.size());
startIndex = Math.min(startIndex, endIndex);
List<AccountFlowVO> pageAccountFlowVos = new ArrayList<>(accountFlowVos.subList(startIndex, endIndex));
result.setRecords(pageAccountFlowVos);
result.setTotal(accountFlowVos.size());

return Response.responseData(result);
}
}
14 changes: 12 additions & 2 deletions web/src/api/report/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
ProductStockFlowResp,
QueryProductStockFlowReq,
QueryAccountStatisticsReq,
AccountStatisticsResp
AccountStatisticsResp, AccountFlowResp
} from "@/api/report/reportModel";

enum API {
getStatisticalData = '/report/homePage/statistics',
getProductStockData = '/report/productStock',
getProductStockFlowData = '/report/productStockFlow',
getAccountStatistics = '/report/accountStatistics'
getAccountStatistics = '/report/accountStatistics',
getAccountFlow = '/report/accountFlow'
}


Expand Down Expand Up @@ -51,4 +52,13 @@ export function getAccountStatistics(params: QueryAccountStatisticsReq) {
params
}
);
}

export function getAccountFlow(accountId: number) {
return defHttp.get<BaseDataResp<AccountFlowResp>>(
{
url: API.getAccountFlow,
params: accountId
}
);
}
10 changes: 10 additions & 0 deletions web/src/api/report/reportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ export interface AccountStatisticsResp {
initialAmount: number;
thisMonthChangeAmount: number;
currentAmount: number;
}

export interface AccountFlowResp {
receiptNumber: string;
subType: string;
useType: string;
name: string;
amount: number;
balance: number;
receiptDate: string;
}
2 changes: 1 addition & 1 deletion web/src/views/receipt/LinkReceiptModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default defineComponent({
showIndexColumn: false,
bordered: true,
showTableSetting: true,
canResize: true,
canResize: false,
tableSetting: { fullScreen: true },
useSearchForm: true,
clickToRowSelect: true,
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/receipt/ReceiptDetailModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineComponent({
},
bordered: true,
showTableSetting: false,
canResize: true,
canResize: false,
tableSetting: { fullScreen: true },
useSearchForm: false,
clickToRowSelect: true,
Expand Down
Loading