using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using XYY.Core.Standard.Mvc;
using XYY.Model.Standard.Finance;
using XYY.Service.Standard.Finance;
using static XYY.Api.Finance.Controllers.FinanceController;

namespace XYY.Api.Finance.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SMPReportsController : ApiControllerBase
    {
        private readonly ISMPReportsService _reportsService;
        public SMPReportsController(ISMPReportsService reportsService) { 
            _reportsService = reportsService;
        }
        [AllowAnonymous]
        [HttpPost]
        public async Task<List<EFFinanceBill>> GetEFFinanceBillGroup(BillSerach serach)
        {
            var result = await _reportsService.GetEFFinanceBillGroup(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId,serach.SalesmanUserId,serach.BranchCompanyId);
            return result;
        }
        [AllowAnonymous]
        [HttpPost]
        public async Task<List<EFFinanceGroupBill>> GetEFFinanceBillGroupAsCustomer(BillSerach serach)
        {
            return await _reportsService.CacheGetEFFinanceBillGroupAsCustomer(serach.StartDate, serach.EndDate);
        }
        [AllowAnonymous]
        [HttpPost]
        public async Task<List<EFFinanceGroupBill>> GetEFFinanceBillGroupAsChannel(BillSerach serach)
        {
            return await _reportsService.CacheGetEFFinanceBillGroupAsChannel(serach.StartDate, serach.EndDate);
        }
        [AllowAnonymous]
        [HttpPost]
        public async Task<IActionResult> ExportEFFinanceBillGroup(BillSerach serach)
        {
            var list = await _reportsService.ExportEFFinanceBillGroup(serach.StartDate, serach.EndDate, serach.ChannelId, serach.CustomerId, serach.SalesmanUserId, serach.BranchCompanyId);
            return CSVFile("数据透视表.xls", list);
        }

    }
}
