package com.jwipc.finance.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.finance.entity.ReceiveVoucher;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jwipc.finance.model.po.*;
import com.jwipc.finance.model.query.ReceiveVoucherQuery;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 对账模块-物料凭证 服务类
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-03-04
 */
public interface IReceiveVoucherService extends IService<ReceiveVoucher> {

    List<ReceiveVoucherPO> findPageByQuery(Page<ReceiveVoucher> dbPage, ReceiveVoucherQuery query);

    /**
     * 获取开票申请中凭证数量及金额
     *
     * @param asId 需要排除的对账单ID
     * @param rvIdList 入库凭证ID
     * @return 结果
     */
    List<StatisticVoucherPO> findInvoicedApply(Long asId, List<Long> rvIdList);

    /**
     * 获取对账单明细中凭证数量及金额
     *
     * @param asId 需要排除的对账单ID
     * @param asdIdList 需要排除的对账单明细ID
     * @param rvIdList 入库凭证ID
     * @return 结果
     */
    List<StatisticVoucherPO> findStatementDetail(Long asId, List<Long> asdIdList, List<Long> rvIdList);

    /**
     * 提供创建对账单时获取入库凭证数据
     *
     * @param query 查询条件
     * @return 结果
     */
    List<StatementItemPO> provideCreateStatement(ReceiveVoucherQuery query);
    List<StatementItemPO> provideCreatePaymentMatching(ReceiveVoucherQuery query);
    List<StatementItemPO> provideCreateCostMatching(ReceiveVoucherQuery query);
    List<StatementItemPO> provideDetailByPaymentMatchingId(Long paymentMatchingId);
    List<StatementItemPO> provideDetailByCostMatchingId(Long costMatchingId);

    /**
     *
     * @param query
     * @return
     */
    List<StatementItemPO>  queryMaterialDocReconciliationInfo(String factoryCode,List<String> cvKeyList);
    List<StatementItemPO> provideCreateStatementPage(Page<ReceiveVoucher> dbPage,ReceiveVoucherQuery query);

    /**
     * 处理凭证重冲销情况
     *
     * @param list 待检查数据
     * @return 结果
     */
    Map<Long, WriteOffVoucherCheckPO> handleWriteOffVoucherData(List<ReceiveVoucher> list);

    /**
     * 根据参考凭证获取入库凭证数据
     *
     * @param cvKeyList 参考凭证数据组合(参考凭证年度#参考凭证号#参考凭证行号)
     * @return 结果
     */
    List<ReceiveVoucher> findByConsultVoucher(String supplierCode, List<String> cvKeyList, Integer voucherType);

    ReceiveVoucher findByMvCode(String mvYear, String mvCode, String mvItemNo);
    ReceiveVoucher findByMvCodeAndFactoryCode(String mvYear, String mvCode, String mvItemNo, String factoryCode);

    ReceiveVoucherPO findByErpSyncNo(String erpSyncNo);

    List<ReceiveVoucherPO> findByPoAndAsNoNotNull(String poCode, String poItemNo,String factoryCode);
    List<ReceiveVoucherPO> findByPoAndItemNo(String poCode, String poItemNo,String factoryCode);

    List<ReceiveVoucherPO> getReturnVoucherData(String supplierCode, String factoryCode);
    BigDecimal getPoReturnVoucherData(String supplierCode, String factoryCode,String companyCode);
}
