package com.dayou.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IFinanceInvoiceService;
import com.dayou.entity.FinanceInvoice;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 财务开票
 *
 * @author wucl
 * @since 2023-12-08
 */
@RestController
@RequestMapping("financeInvoice")
@Slf4j
public class FinanceInvoiceController extends BaseController {
    @Autowired
    private IFinanceInvoiceService financeInvoiceService;

    /**
    * 财务开票列表
    */
    @GetMapping("")
    public RestResponse<Page<FinanceInvoice>> page(FinanceInvoice financeInvoice, Page page,String keyword){
        Page<FinanceInvoice> pages=financeInvoiceService.selectPage(page,financeInvoice,keyword);
        return RestResponse.data(pages);
    }

    /**
     * 财务开票详情
     */
    @GetMapping("/{id}")
    public RestResponse<FinanceInvoice> detail(@PathVariable Long id){
        FinanceInvoice xFinanceInvoice =financeInvoiceService.detail(id);
        return RestResponse.data(xFinanceInvoice);
     }

    /**
     * 财务开票新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody FinanceInvoice financeInvoice) {
        Boolean ret = financeInvoiceService.add(financeInvoice);
        return RestResponse.data(ret);
    }

    /**
     * 财务开票更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody FinanceInvoice financeInvoice) {
        Boolean ret = financeInvoiceService.update(financeInvoice);
        return RestResponse.data(ret);
    }

    /**
     * 财务开票删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = financeInvoiceService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 单个项目开票列表
     * @param id
     * @return
     */
    @GetMapping("/fund/{id}")
    public RestResponse<List<FinanceInvoice>> getList(@PathVariable("id") Long id){
        List<FinanceInvoice> result = financeInvoiceService.getList(id);
        return RestResponse.data(result);
    }

    /**
     * 开票作废
     * @param id
     * @return
     */
    @GetMapping("/cancellation/{id}")
    public RestResponse<Boolean> cancellation(@PathVariable("id") Long id){
        Boolean ret = financeInvoiceService.cancellation(id);
        return RestResponse.data(ret);
    }

}

