<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fjhx.wms.mapper.monthly.MonthlyInventoryReportMapper">
    <select id="getPage" resultType="com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo">
        select mir.id,
               mir.warehouse_id,
               mir.product_id,
               mir.initial_quantity,
               mir.receipt_quantity,
               mir.outbound_quantity,
               mir.balance_quantity,
               mir.balance_unit_price,
               mir.balance_amount,
               mir.create_user,
               mir.create_time,
               mir.update_user,
               mir.update_time,
               mir.daily_report_date
        from monthly_inventory_report mir
            ${ew.customSqlSegment}
    </select>
    <select id="getLastMonthStockJournal" resultType="com.fjhx.wms.entity.stock.vo.StockJournalDetailsVo">
        SELECT sj.warehouse_id toWarehouseId,
               sjd.product_id,
               sjd.quantity,
               sj.op_type
        FROM stock_journal_details sjd
                 LEFT JOIN stock_journal sj ON sjd.stock_journal_id = sj.id
        WHERE DATE_FORMAT(sjd.create_time, '%Y-%m') = DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y-%m')
    </select>
    <select id="getLastMonthMonthlyInventoryReport"
            resultType="com.fjhx.wms.entity.monthly.vo.MonthlyInventoryReportVo">
        select mir.id,
               mir.warehouse_id,
               mir.product_id,
               mir.initial_quantity,
               mir.receipt_quantity,
               mir.outbound_quantity,
               mir.balance_quantity,
               mir.balance_unit_price,
               mir.balance_amount,
               mir.create_user,
               mir.create_time,
               mir.update_user,
               mir.update_time
        from monthly_inventory_report mir
        where DATE_FORMAT(mir.daily_report_date, '%Y-%m') = DATE_FORMAT(CURRENT_DATE - INTERVAL 2 MONTH, '%Y-%m')
    </select>
    <select id="getYearList" resultType="java.lang.String">
        SELECT DISTINCT date_format(daily_report_date, '%Y')
        FROM monthly_inventory_report
    </select>

</mapper>
