|
|
|
@ -24,6 +24,7 @@ import jnpf.poundlist.service.PoundlistService;
|
|
|
|
|
import jnpf.purchaseback.entity.PurchaseorderEntity;
|
|
|
|
|
import jnpf.purchaseback.service.PurchaseorderService;
|
|
|
|
|
import jnpf.purchaseorder.entity.Purchaseorder_item0Entity;
|
|
|
|
|
import jnpf.purchaseorder.service.Purchaseorder_item0Service;
|
|
|
|
|
import jnpf.purchaseorder.service.PurchaseorderitemService;
|
|
|
|
|
import jnpf.supplier.entity.SupplierEntity;
|
|
|
|
|
import jnpf.supplier.service.SupplierService;
|
|
|
|
@ -57,6 +58,7 @@ import jnpf.util.GeneraterSwapUtil;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import jnpf.util.file.UploadUtil;
|
|
|
|
|
import jnpf.util.enums.FileTypeEnum;
|
|
|
|
@ -103,6 +105,8 @@ public class InvoicesController {
|
|
|
|
|
private ContractFileService contractFileService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SupplierService supplierService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private Purchaseorder_item0Service purchaseorder_item0Service;
|
|
|
|
|
/**
|
|
|
|
|
* 列表
|
|
|
|
|
*
|
|
|
|
@ -143,20 +147,20 @@ public class InvoicesController {
|
|
|
|
|
@PostMapping
|
|
|
|
|
@Transactional
|
|
|
|
|
public ActionResult create(@RequestBody @Valid InvoicesCrForm invoicesCrForm) throws DataException {
|
|
|
|
|
String mainId =RandomUtil.uuId();
|
|
|
|
|
UserInfo userInfo=userProvider.get();
|
|
|
|
|
String mainId = RandomUtil.uuId();
|
|
|
|
|
UserInfo userInfo = userProvider.get();
|
|
|
|
|
//invoicesCrForm.setDocumentNo(generaterSwapUtil.getBillNumber("yffp", false));
|
|
|
|
|
InvoicesEntity entity = JsonUtil.getJsonToBean(invoicesCrForm, InvoicesEntity.class);
|
|
|
|
|
entity.setId(mainId);
|
|
|
|
|
invoicesService.save(entity);
|
|
|
|
|
List<InvoicesItem1Entity> InvoicesItem1List = JsonUtil.getJsonToList(invoicesCrForm.getInvoicesitem1List(),InvoicesItem1Entity.class);
|
|
|
|
|
for(InvoicesItem1Entity entitys : InvoicesItem1List){
|
|
|
|
|
List<InvoicesItem1Entity> InvoicesItem1List = JsonUtil.getJsonToList(invoicesCrForm.getInvoicesitem1List(), InvoicesItem1Entity.class);
|
|
|
|
|
for (InvoicesItem1Entity entitys : InvoicesItem1List) {
|
|
|
|
|
entitys.setId(RandomUtil.uuId());
|
|
|
|
|
entitys.setInvoicesId(entity.getId());
|
|
|
|
|
invoicesItem1Service.save(entitys);
|
|
|
|
|
}
|
|
|
|
|
List<InvoicesItem0Entity> InvoicesItem0List = JsonUtil.getJsonToList(invoicesCrForm.getInvoicesitem0List(),InvoicesItem0Entity.class);
|
|
|
|
|
for(InvoicesItem0Entity entitys : InvoicesItem0List){
|
|
|
|
|
List<InvoicesItem0Entity> InvoicesItem0List = JsonUtil.getJsonToList(invoicesCrForm.getInvoicesitem0List(), InvoicesItem0Entity.class);
|
|
|
|
|
for (InvoicesItem0Entity entitys : InvoicesItem0List) {
|
|
|
|
|
entitys.setId(RandomUtil.uuId());
|
|
|
|
|
entitys.setInvoicesId(entity.getId());
|
|
|
|
|
invoicesItem0Service.save(entitys);
|
|
|
|
@ -167,28 +171,37 @@ public class InvoicesController {
|
|
|
|
|
purchaseorderEntity.setInvoiceAmount(entity.getInvoiceAmount());
|
|
|
|
|
purchaseorderEntity.setInvoiceNum(entity.getInvoiceQuantity());
|
|
|
|
|
purchaseorderService.updateById(purchaseorderEntity);
|
|
|
|
|
|
|
|
|
|
List<Purchaseorder_item0Entity> Purchaseorder_item0List = purchaseorderitemService.GetPurchaseorder_item0List(entity.getPurchaseorderId());
|
|
|
|
|
List<PoundlistEntity> poundlistEntityList = purchaseorderitemService.getPoundList(entity.getPurchaseorderId());
|
|
|
|
|
Purchaseorder_item0Entity orderItem = Purchaseorder_item0List.stream().filter(item0 -> ObjectUtil.equals(item0.getPoundlistId(), poundlistEntityList.get(0).getId())).findAny().get();
|
|
|
|
|
BigDecimal total = orderItem.getAmount();
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (entity.getInvoiceAmount().compareTo(total) >= 0){
|
|
|
|
|
i++;
|
|
|
|
|
if(i < poundlistEntityList.size()){
|
|
|
|
|
String poundlistId = poundlistEntityList.get(i).getId();
|
|
|
|
|
orderItem = Purchaseorder_item0List.stream().filter(item0 -> ObjectUtil.equals(item0.getPoundlistId(), poundlistId)).findAny().get();
|
|
|
|
|
total = total.add(orderItem.getAmount());
|
|
|
|
|
}else{
|
|
|
|
|
break;
|
|
|
|
|
if (purchaseorderEntity.getAmount().compareTo(entity.getInvoiceAmount()) == 0) {
|
|
|
|
|
for (PoundlistEntity poundlistEntity: poundlistEntityList) {
|
|
|
|
|
poundlistEntity.setIsInvoicing("1");
|
|
|
|
|
poundlistEntity.setInputDate(new Date());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0;j<poundlistEntityList.size();j++) {
|
|
|
|
|
if(j < i){
|
|
|
|
|
poundlistEntityList.get(j).setIsInvoicing("1");
|
|
|
|
|
poundlistEntityList.get(j).setInputDate(new Date());
|
|
|
|
|
poundlistService.updateBatchById(poundlistEntityList);
|
|
|
|
|
}else {
|
|
|
|
|
Purchaseorder_item0Entity orderItem = Purchaseorder_item0List.stream().filter(item0 -> ObjectUtil.equals(item0.getPoundlistId(), poundlistEntityList.get(0).getId())).findAny().get();
|
|
|
|
|
BigDecimal total = orderItem.getAmount();
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (entity.getInvoiceAmount().compareTo(total) >= 0) {
|
|
|
|
|
i++;
|
|
|
|
|
if (i < poundlistEntityList.size()) {
|
|
|
|
|
String poundlistId = poundlistEntityList.get(i).getId();
|
|
|
|
|
orderItem = Purchaseorder_item0List.stream().filter(item0 -> ObjectUtil.equals(item0.getPoundlistId(), poundlistId)).findAny().get();
|
|
|
|
|
total = total.add(orderItem.getAmount());
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int j = 0; j < poundlistEntityList.size(); j++) {
|
|
|
|
|
if (j < i) {
|
|
|
|
|
poundlistEntityList.get(j).setIsInvoicing("1");
|
|
|
|
|
poundlistEntityList.get(j).setInputDate(new Date());
|
|
|
|
|
}
|
|
|
|
|
poundlistEntityList.get(j).setPurchaseStatus("1");
|
|
|
|
|
poundlistService.updateById(poundlistEntityList.get(j));
|
|
|
|
|
}
|
|
|
|
|
poundlistEntityList.get(j).setPurchaseStatus("1");
|
|
|
|
|
poundlistService.updateById(poundlistEntityList.get(j));
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.success("创建成功");
|
|
|
|
|
}
|
|
|
|
|