package com.ruoyi.web.controller.warehouse.reportManagement;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.finance.domain.TWareHouseFees;
import com.ruoyi.finance.domain.dto.FeeDTO;
import com.ruoyi.finance.domain.excel.GeneralLedgerDetailExcel;
import com.ruoyi.finance.domain.excel.GeneralLedgerExcel;
import com.ruoyi.finance.domain.vo.FeeVO;
import com.ruoyi.finance.service.ITFeeService;
import com.ruoyi.reportManagement.excel.Payable;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 应付总账Controller
 *
 * @author ruoyi
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/warehouseBusiness/payable")
public class PayableController extends BaseController {

    @Autowired
    private ITFeeService tFeeService;

    /**
     * 查询应付总账列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:payable:list')")
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo chargeList(TWareHouseFees tWareHouseFees) {
        startPage();
        tWareHouseFees.setfDc("C");
        List<FeeVO> list = tFeeService.warehouseBillsFeesList(tWareHouseFees);
        return getDataTable(list);
    }

    /**
     * 根据结算单位、费用状态、审核日期查询应付总帐明细
     */
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/generalLedgerList")
    public AjaxResult financialLedgerDetails(FeeDTO feeDTO) {
        feeDTO.setFDc("C");
        return tFeeService.financialLedgerDetails(feeDTO);
    }

    /**
     * 应付总账列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:payable:export')")
    @Log(title = "库存总账", businessType = BusinessType.EXPORT)
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/export")
    public AjaxResult export(TWareHouseFees tWareHouseFees) throws Exception {
        tWareHouseFees.setfDc("C");
        List<GeneralLedgerExcel> list = tFeeService.payableExport(tWareHouseFees);
        ExcelUtil<GeneralLedgerExcel> util = new ExcelUtil<GeneralLedgerExcel>(GeneralLedgerExcel.class);
        return util.exportExcel(list, "应付总账");
    }

    /**
     * 应付总账列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:payable:export')")
    @Log(title = "库存总账明细", businessType = BusinessType.EXPORT)
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/export/detail")
    public AjaxResult exportDetail(FeeDTO feeDTO) throws Exception {
        feeDTO.setFDc("C");
        List<GeneralLedgerDetailExcel> list = tFeeService.financialLedgerDetailsExport(feeDTO);
        ExcelUtil<GeneralLedgerDetailExcel> util = new ExcelUtil<GeneralLedgerDetailExcel>(GeneralLedgerDetailExcel.class);
        return util.exportExcel(list, "应付总账明细");
    }

}
