using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.UserModule; using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Entity; using DS.WMS.Core.Application.Interface; using DS.WMS.Core.Fee.Dtos; using Microsoft.AspNetCore.Mvc; namespace DS.WMS.FeeApi.Controllers { /// /// 发票申请API /// public class InvoiceApplicationController : ApiController { readonly IInvoiceApplicationService _service; /// /// 初始化 /// /// public InvoiceApplicationController(IInvoiceApplicationService service) { _service = service; } /// /// 根据业务编号及类型获取该票业务的币别 /// /// 业务ID与业务类型 /// [HttpPost, Route("GetCurrencies")] public async Task>> GetCurrenciesAsync([FromBody] params FeeClient[] items) { return await _service.GetCurrenciesAsync(items); } /// /// 获取列表 /// /// /// [HttpPost, Route("GetList")] public async Task>> ListAsync([FromBody] PageRequest request) { return await _service.GetListAsync(request); } /// /// 获取待开票的业务列表 /// /// /// /// 注意!!【费用范围】一栏需通过 OtherQueryCondition 字段传入枚举值 [HttpPost, Route("GetBizList")] public async Task>> BizListAsync([FromBody] PageRequest request) { return await _service.GetBizListAsync(request); } /// /// 获取申请单详情 /// /// 申请单ID /// [HttpGet, Route("Get")] public async Task> GetAsync([FromQuery] long id) { return await _service.GetAsync(id); } /// /// 根据业务编号及类型获取关联费用记录 /// /// 业务ID和类型 /// [HttpPost, Route("GetFees")] public async Task> GetFeesAsync([FromBody] params FeeClient[] items) { if (items == null || items.Length == 0) return DataResult.Failed("缺少请求参数"); return await _service.GetFeesAsync(items); } /// /// 提交申请单 /// /// 申请单 /// [HttpPost, Route("Save")] public async Task> SaveAsync([FromBody] InvoiceApplication application) { return await _service.SaveAsync(application); } /// /// 按业务提交申请单 /// /// /// [HttpPost, Route("BizSave")] public async Task> SaveAsync([FromBody] ApplicationRequest request) { if (request.Items == null || request.Items.Count == 0) return DataResult.Failed("缺少请求参数"); return await _service.SaveAsync(request); } /// /// 删除发票明细 /// /// 发票明细ID /// [HttpPost, Route("DeleteInvoiceDetail")] public async Task DeleteInvoiceDetailAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _service.DeleteInvoiceDetailAsync(model.Ids); } /// /// 删除申请单明细 /// /// 申请单明细ID /// [HttpPost, Route("DeleteDetail")] public async Task DeleteDetailAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _service.DeleteDetailAsync(model.Ids); } /// /// 删除申请单 /// /// 申请单ID /// [HttpPost, Route("Delete")] public async Task DeleteAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _service.DeleteAsync(model.Ids); } /// /// 发起审批 /// /// 申请单ID /// [HttpPost, Route("ApplyAudit")] public async Task ApplyAuditAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _service.SubmitApprovalAsync(TaskBaseTypeEnum.APPLICATION_INVOICE_AUDIT, model.Remark, model.Ids); } /// /// 撤销审批 /// /// 申请单ID /// [HttpPost, Route("Withdraw")] public async Task WithdrawAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _service.WithdrawAsync(model.Ids); } /// /// 获取发票模板字段 /// /// /// /// [HttpGet, Route("GetTemplateFields")] public DataResult> GetTemplateFields( [FromServices] IInvoiceTemplateService templateService, [FromServices] IHostEnvironment host) { return templateService.GetFields(host); } /// /// 获取发票模板列表 /// /// /// 如果为空,则创建默认模板 /// [HttpGet, Route("GetTemplateList")] public DataResult> GetTemplateList( [FromServices] IInvoiceTemplateService templateService, [FromQuery] bool createIfEmpty = true) { var user = HttpContext.RequestServices.GetRequiredService(); long userId = long.Parse(user.UserId); return templateService.GetList(userId, createIfEmpty); } /// /// 保存发票模板 /// /// /// 发票模板 /// [HttpPost, Route("SaveTemplate")] public DataResult> SaveTemplate( [FromServices] IInvoiceTemplateService templateService, [FromBody] params InvoiceTemplate[] templates) { return templateService.Save(templates); } /// /// 以申请单的数据渲染发票模板 /// /// 发票申请ID /// 模板文本 /// /// /// [HttpGet, Route("RenderTemplate")] public async Task> RenderTemplate([FromQuery] long id, [FromQuery] string template, [FromServices] IInvoiceTemplateService templateService, [FromServices] IHostEnvironment host) { return await templateService.RenderTemplateAsync(id, template, host); } } }