|
@@ -1,11 +1,28 @@
|
|
|
package cn.ezhizao.project.business.invoice.controller;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import cn.ezhizao.project.business.collection.domain.BizCollection;
|
|
|
+import cn.ezhizao.project.business.collection.domain.BizCollectionDetail;
|
|
|
+import cn.ezhizao.project.business.collection.service.IBizCollectionDetailService;
|
|
|
+import cn.ezhizao.project.business.collection.service.IBizCollectionService;
|
|
|
+import cn.ezhizao.project.business.invoice.domain.BizCopyInfo;
|
|
|
import cn.ezhizao.project.business.invoice.domain.BizInvoice;
|
|
|
+import cn.ezhizao.project.business.invoice.service.IBizCopyInfoService;
|
|
|
import cn.ezhizao.project.business.invoice.service.IBizInvoiceService;
|
|
|
+import cn.ezhizao.project.business.order.service.IBizArchiveInputService;
|
|
|
+import cn.ezhizao.project.system.domain.SysFileStorage;
|
|
|
+import cn.ezhizao.project.system.service.ISysFileStorageService;
|
|
|
+import cn.ezhizao.project.system.service.ISysUserService;
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -30,18 +47,34 @@ import cn.ezhizao.framework.web.page.TableDataInfo;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/business/invoice")
|
|
|
-public class BizInvoiceController extends BaseController
|
|
|
-{
|
|
|
+public class BizInvoiceController extends BaseController {
|
|
|
@Resource
|
|
|
private IBizInvoiceService bizInvoiceService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IBizCollectionService collectionService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IBizCollectionDetailService collectionDetailService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IBizCopyInfoService bizCopyInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IBizArchiveInputService bizArchiveInputService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ISysFileStorageService fileStorageService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询开票管理列表
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:list')")
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException
|
|
|
- {
|
|
|
+ public TableDataInfo list(BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException {
|
|
|
startPage();
|
|
|
List<BizInvoice> list = bizInvoiceService.getList(bizInvoice);
|
|
|
return getDataTable(list);
|
|
@@ -51,10 +84,9 @@ public class BizInvoiceController extends BaseController
|
|
|
* 导出开票管理列表
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:export')")
|
|
|
- @Log(title = "开票管理", businessType = BusinessType.EXPORT)
|
|
|
+ @Log(title = "开票管理导出", businessType = BusinessType.EXPORT)
|
|
|
@PostMapping("/export")
|
|
|
- public void export(HttpServletResponse response, BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException
|
|
|
- {
|
|
|
+ public void export(HttpServletResponse response, BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException {
|
|
|
List<BizInvoice> list = bizInvoiceService.getList(bizInvoice);
|
|
|
ExcelUtil<BizInvoice> util = new ExcelUtil<BizInvoice>(BizInvoice.class);
|
|
|
util.exportExcel(response, list, "开票管理数据");
|
|
@@ -65,9 +97,33 @@ public class BizInvoiceController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:query')")
|
|
|
@GetMapping(value = "/{id}")
|
|
|
- public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
- {
|
|
|
- return success(bizInvoiceService.getById(id));
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
+ BizInvoice bizInvoice = bizInvoiceService.getById(id);
|
|
|
+
|
|
|
+ SysFileStorage one = fileStorageService.getOne(new LambdaQueryWrapper<SysFileStorage>().eq(SysFileStorage::getMasterId, bizInvoice.getId()));
|
|
|
+ if (one != null) {
|
|
|
+ bizInvoice.setEvidenceFile(one.getFileUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ String contractNo = bizArchiveInputService.getById(bizInvoice.getContractId()).getContractNo();
|
|
|
+ bizInvoice.setContractNo(contractNo);
|
|
|
+ if (bizInvoice.getInvoiceId() != null) {
|
|
|
+ String userName2 = userService.selectUserById(bizInvoice.getInvoiceId()).getUserName();
|
|
|
+ bizInvoice.setInvoiceName(userName2);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bizInvoice.getApplierId() != null) {
|
|
|
+ String userName1 = userService.selectUserById(bizInvoice.getApplierId()).getUserName();
|
|
|
+ bizInvoice.setApplierName(userName1);
|
|
|
+ }
|
|
|
+ return success(bizInvoice);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/getInfoByName/{name}")
|
|
|
+ public AjaxResult getInfoByName(@PathVariable String name) {
|
|
|
+ BizCopyInfo one = bizCopyInfoService.getOne(new LambdaQueryWrapper<BizCopyInfo>().eq(BizCopyInfo::getName, name));
|
|
|
+ return success(one);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -76,8 +132,34 @@ public class BizInvoiceController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:add')")
|
|
|
@Log(title = "开票管理", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@RequestBody BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException
|
|
|
- {
|
|
|
+ public AjaxResult add(@RequestBody BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ BizCopyInfo info1 = new BizCopyInfo();
|
|
|
+ BizCopyInfo info2 = new BizCopyInfo();
|
|
|
+ //开票户
|
|
|
+ Long tenantId = getTenantId();
|
|
|
+ BizCopyInfo one = bizCopyInfoService.getOne(new LambdaQueryWrapper<BizCopyInfo>().eq(BizCopyInfo::getTenantId, tenantId));
|
|
|
+ if (one != null) {
|
|
|
+ info1.setId(one.getId());
|
|
|
+ }
|
|
|
+ info1.setName(one.getName());
|
|
|
+ info1.setAddress(one.getAddress());
|
|
|
+ info1.setAccount(one.getAccount());
|
|
|
+ info1.setCode(one.getCode());
|
|
|
+ info1.setTenantId(tenantId);
|
|
|
+ bizCopyInfoService.saveOrUpdate(info1);
|
|
|
+ //收票户
|
|
|
+ String invoiceOther = bizInvoice.getInvoiceOther();
|
|
|
+ BizCopyInfo one1 = bizCopyInfoService.getOne(new LambdaQueryWrapper<BizCopyInfo>().eq(BizCopyInfo::getName, invoiceOther));
|
|
|
+ if (one1 != null) {
|
|
|
+ info2.setId(one1.getId());
|
|
|
+ }
|
|
|
+ info2.setName(invoiceOther);
|
|
|
+ info2.setAddress(bizInvoice.getOtherAddress());
|
|
|
+ info2.setAccount(bizInvoice.getOtherAccount());
|
|
|
+ info2.setCode(bizInvoice.getOtherCreditSocietyCode());
|
|
|
+ bizCopyInfoService.saveOrUpdate(info2);
|
|
|
+ bizInvoice.setApplierId(getUserId());
|
|
|
+ bizInvoice.setApplierTime(new Date());
|
|
|
return toAjax(bizInvoiceService.save(bizInvoice));
|
|
|
}
|
|
|
|
|
@@ -87,8 +169,21 @@ public class BizInvoiceController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:edit')")
|
|
|
@Log(title = "开票管理", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@RequestBody BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException
|
|
|
- {
|
|
|
+ public AjaxResult edit(@RequestBody BizInvoice bizInvoice) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ if (bizInvoice.getStatus().equals(3)) {
|
|
|
+ Long userId = getUserId();
|
|
|
+ bizInvoice.setInvoiceId(userId);
|
|
|
+ SysFileStorage sysFileStorage = new SysFileStorage();
|
|
|
+ sysFileStorage.setMasterId(bizInvoice.getId());
|
|
|
+ sysFileStorage.setMasterTableName("biz_invoice");
|
|
|
+ sysFileStorage.setFileUrl(bizInvoice.getEvidenceFile());
|
|
|
+ sysFileStorage.setFileName(bizInvoice.getFileName());
|
|
|
+ sysFileStorage.setOriginalFileName(bizInvoice.getOriginalFileName());
|
|
|
+ SysFileStorage one = fileStorageService.getOne(new LambdaQueryWrapper<SysFileStorage>().eq(SysFileStorage::getMasterId, bizInvoice.getId()));
|
|
|
+ fileStorageService.physicalDelete(one);
|
|
|
+ fileStorageService.save(sysFileStorage);
|
|
|
+ }
|
|
|
+
|
|
|
return toAjax(bizInvoiceService.updateById(bizInvoice));
|
|
|
}
|
|
|
|
|
@@ -97,9 +192,45 @@ public class BizInvoiceController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('business:invoice:remove')")
|
|
|
@Log(title = "开票管理", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable List<Long> ids)
|
|
|
- {
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable List<Long> ids) {
|
|
|
return toAjax(bizInvoiceService.removeBatchByIds(ids));
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping(value = "/getCollectionToAmount/{id}")
|
|
|
+ public AjaxResult getCollectionToAmount(@PathVariable String id) {
|
|
|
+ List<BizCollection> list = collectionService.list(new LambdaQueryWrapper<BizCollection>()
|
|
|
+ .eq(BizCollection::getContractId, id)
|
|
|
+ .eq(BizCollection::getStatus, 1)
|
|
|
+ .eq(BizCollection::getArriveStatus, 1)
|
|
|
+ .eq(BizCollection::getDeleted, 0));
|
|
|
+ List<Long> ids = list.stream().map(v -> v.getId()).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(ids)) {
|
|
|
+ return success(0);
|
|
|
+ }
|
|
|
+ List<BizCollectionDetail> details = collectionDetailService.list(
|
|
|
+ new LambdaQueryWrapper<BizCollectionDetail>()
|
|
|
+ .in(BizCollectionDetail::getCollectionId, ids)
|
|
|
+ .eq(BizCollectionDetail::getDeleted, 0)
|
|
|
+ );
|
|
|
+ //所有审核通过的合同
|
|
|
+ BigDecimal amount = details.stream().map(BizCollectionDetail::getArriveAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ //已开票 或待审核的开票
|
|
|
+ LambdaQueryWrapper<BizInvoice> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(BizInvoice::getContractId, id);
|
|
|
+ wrapper.eq(BizInvoice::getDeleted, 0);
|
|
|
+ wrapper.and(item -> item.eq(BizInvoice::getStatus, 3).or().eq(BizInvoice::getStatus, 1));
|
|
|
+ List<BizInvoice> invoices = bizInvoiceService.list(wrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(invoices)) {
|
|
|
+ BigDecimal haveAmount = invoices.stream().map(v -> v.getAllowInvoiceAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ amount = amount.subtract(haveAmount);
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO)<0){
|
|
|
+ amount = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return success(amount);
|
|
|
+
|
|
|
+ }
|
|
|
}
|