package com.jwipc.finance.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.finance.entity.ReceiveVoucher;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jwipc.finance.model.po.ReceiveVoucherPO;
import com.jwipc.finance.model.po.StatementItemPO;
import com.jwipc.finance.model.po.StatisticVoucherPO;
import com.jwipc.finance.model.query.ReceiveVoucherQuery;
import org.apache.ibatis.annotations.Param;

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

/**
 * <p>
 * 对账模块-物料凭证 Mapper 接口
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-03-04
 */
public interface ReceiveVoucherMapper extends BaseMapper<ReceiveVoucher> {

    List<ReceiveVoucherPO> findPageByQuery(@Param("query") ReceiveVoucherQuery query);

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

    List<StatisticVoucherPO> findInvoicedApply(@Param("asId") Long asId, @Param("rvIdList") List<Long> rvIdList);

    List<StatisticVoucherPO> findStatementDetail(@Param("asId") Long asId, @Param("asdIdList") List<Long> asdIdList, @Param("rvIdList") List<Long> rvIdList);

    List<StatementItemPO> provideCreateStatement(@Param("query") ReceiveVoucherQuery query);
    List<StatementItemPO> provideCreatePaymentMatching(@Param("query") ReceiveVoucherQuery query);
    List<StatementItemPO> provideCreateCostMatching(@Param("query") ReceiveVoucherQuery query);
    List<StatementItemPO> provideDetailByPaymentMatchingId(@Param("paymentMatchingId") Long paymentMatchingId);
    List<StatementItemPO> provideDetailByCostMatchingId(@Param("costMatchingId") Long costMatchingId);


    List<StatementItemPO> provideCreateStatement(Page<ReceiveVoucher> dbPage, @Param("query") ReceiveVoucherQuery query);

    List<ReceiveVoucher> findByConsultVoucher(@Param("supplierCode") String supplierCode, @Param("cvKeyList") List<String> cvKeyList,
                                              @Param("orderType") Integer orderType);

    ReceiveVoucher findByMvCode(@Param("mvYear") String mvYear, @Param("mvCode") String mvCode, @Param("mvItemNo") String mvItemNo);

    ReceiveVoucher findByMvCodeAndFactoryCode(@Param("mvYear") String mvYear,  @Param("mvCode") String mvCode,  @Param("mvItemNo") String mvItemNo,  @Param("factoryCode") String factoryCode);

    ReceiveVoucherPO findByErpSyncNo(String erpSyncNo);

    List<StatementItemPO> queryMaterialDocReconciliationInfo(@Param("factoryCode")String factoryCode,@Param("cvKeyList") List<String> cvKeyList);

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

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