package com.ruoyi.hywz.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hywz.entity.AdsMatHyxtStampTaxComputeD;
import com.ruoyi.hywz.entity.po.HomeStampTaxCountPO;
import com.ruoyi.hywz.entity.vo.stamp.tax.HomeStampTaxCountVO;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxComputeDService;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxContractDService;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxInvoiceDService;
import com.ruoyi.hywz.service.IAdsMatHyxtStampTaxZhptInvoiceDService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author: jxh
 * @description:
 * @create: 2024/9/1
 */
@RestController
@RequestMapping("home")
@AllArgsConstructor
@Api(value = "home", tags = "首页接口")
public class HomeController {

    private final IAdsMatHyxtStampTaxContractDService adsMatHyxtStampTaxContractDService;
    private final IAdsMatHyxtStampTaxInvoiceDService adsMatHyxtStampTaxInvoiceDService;
    private final IAdsMatHyxtStampTaxComputeDService adsMatHyxtStampTaxComputeDService;
    private final IAdsMatHyxtStampTaxZhptInvoiceDService adsMatHyxtStampTaxZhptInvoiceDService;


    @ApiOperation(value = "【印花税模块】统计", notes = "【印花税模块】统计")
    @PostMapping("/stampTax/count")
    public R stampTaxCount(@RequestBody HomeStampTaxCountPO param) {
        String orgNo = param.getHomeOrgNo();
        String date = param.getHomeDate();

        int contractNum = adsMatHyxtStampTaxContractDService.countNum(orgNo, date);
        int invoiceNum = adsMatHyxtStampTaxInvoiceDService.countNum(orgNo, date);
        int warningNum = adsMatHyxtStampTaxContractDService.countWarningNum(orgNo, date) + adsMatHyxtStampTaxInvoiceDService.countWarningNum(orgNo, date);
        int zhptInvoiceNum = adsMatHyxtStampTaxZhptInvoiceDService.countNum(orgNo, date);
        BigDecimal taxAmount = BigDecimal.ZERO;
        BigDecimal payTaxAmount = BigDecimal.ZERO;
        AdsMatHyxtStampTaxComputeD one = adsMatHyxtStampTaxComputeDService.getOne(orgNo, date);
        if (null != one) {
            taxAmount = new BigDecimal(one.getTaxAmount());
            payTaxAmount = new BigDecimal(one.getAmount());
        }
        HomeStampTaxCountVO vo = new HomeStampTaxCountVO(contractNum,invoiceNum,warningNum,zhptInvoiceNum,taxAmount, payTaxAmount);
        return R.ok(vo);
    }

}
