| | |
| | | |
| | | /** |
| | | * 处理当月开票台账删除 |
| | | * |
| | | * @param invoiceRegistrationProductId |
| | | * @param invoiceRegistrationProduct |
| | | */ |
| | | private void dealCurrentMonthDel(Integer invoiceRegistrationProductId,InvoiceRegistrationProduct invoiceRegistrationProduct){ |
| | | |
| | | private void dealCurrentMonthDel(Integer invoiceRegistrationProductId, InvoiceRegistrationProduct invoiceRegistrationProduct) { |
| | | |
| | | // 删除开票台账 |
| | | QueryWrapper<InvoiceLedger> delMapper = new QueryWrapper<>(); |
| | | delMapper.eq("invoice_registration_product_id", invoiceRegistrationProductId); |
| | | invoiceLedgerMapper.delete(delMapper); |
| | | // 删除开票登记并回滚 |
| | | QueryWrapper<InvoiceLedger> delLedgerWrapper = new QueryWrapper<>(); |
| | | delLedgerWrapper.eq("invoice_registration_product_id", invoiceRegistrationProductId); |
| | | invoiceLedgerMapper.delete(delLedgerWrapper); |
| | | |
| | | // 查询当前产品下的所有开票登记 |
| | | QueryWrapper<InvoiceRegistrationProduct> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("sales_ledger_id", invoiceRegistrationProduct.getSalesLedgerId()); |
| | | queryWrapper.eq("sales_ledger_product_id", invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | queryWrapper.orderByAsc("create_time"); |
| | | List<InvoiceRegistrationProduct> invoiceRegistrationProductList = invoiceRegistrationProductMapper.selectList(queryWrapper); |
| | | // InvoiceRegistrationProduct invoiceRegistrationProduct = invoiceRegistrationProductMapper.selectById(invoiceRegistrationProductId); |
| | | int index = -1; |
| | | for (int i = 0; i < invoiceRegistrationProductList.size(); i++) { |
| | | InvoiceRegistrationProduct currentInvoiceRegProduct = invoiceRegistrationProductList.get(i); |
| | | if(invoiceRegistrationProduct.getId().equals(currentInvoiceRegProduct.getId())){ |
| | | List<InvoiceRegistrationProduct> allList = invoiceRegistrationProductMapper.selectList(queryWrapper); |
| | | |
| | | int index = -1; |
| | | for (int i = 0; i < allList.size(); i++) { |
| | | if (invoiceRegistrationProductId.equals(allList.get(i).getId())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | if(index == -1){ |
| | | if (index == -1) { |
| | | return; |
| | | } |
| | | for (int i = index + 1; i < invoiceRegistrationProductList.size(); i++) { |
| | | InvoiceRegistrationProduct currentInvoiceRegProduct = invoiceRegistrationProductList.get(i); |
| | | // 回滚未开票数/未开票金额 |
| | | BigDecimal noInvoiceAmount = currentInvoiceRegProduct.getNoInvoiceAmount().add(invoiceRegistrationProduct.getInvoiceAmount()); |
| | | BigDecimal noInvoiceNum = currentInvoiceRegProduct.getNoInvoiceNum().add(invoiceRegistrationProduct.getInvoiceNum()); |
| | | currentInvoiceRegProduct.setNoInvoiceAmount(noInvoiceAmount); |
| | | currentInvoiceRegProduct.setNoInvoiceNum(noInvoiceNum); |
| | | invoiceRegistrationProductMapper.updateById(currentInvoiceRegProduct); |
| | | |
| | | for (int i = index + 1; i < allList.size(); i++) { |
| | | InvoiceRegistrationProduct current = allList.get(i); |
| | | |
| | | current.setNoInvoiceNum(current.getNoInvoiceNum().add(invoiceRegistrationProduct.getInvoiceNum())); |
| | | current.setNoInvoiceAmount(current.getNoInvoiceAmount().add(invoiceRegistrationProduct.getInvoiceAmount())); |
| | | |
| | | invoiceRegistrationProductMapper.updateById(current); |
| | | } |
| | | |
| | | // 删除当前开票登记 |
| | | invoiceRegistrationProductMapper.deleteById(invoiceRegistrationProductId); |
| | | // 修改sale_product数据 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | |
| | | // 查询删除后的剩余开票登记 |
| | | QueryWrapper<InvoiceRegistrationProduct> newQueryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("sales_ledger_id", invoiceRegistrationProduct.getSalesLedgerId()); |
| | | queryWrapper.eq("sales_ledger_product_id", invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | queryWrapper.orderByAsc("create_time"); |
| | | List<InvoiceRegistrationProduct> newInvoiceRegistrationProductList = invoiceRegistrationProductMapper.selectList(newQueryWrapper); |
| | | if(CollectionUtils.isEmpty(newInvoiceRegistrationProductList)){ |
| | | newQueryWrapper.eq("sales_ledger_id", invoiceRegistrationProduct.getSalesLedgerId()); |
| | | newQueryWrapper.eq("sales_ledger_product_id", invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | newQueryWrapper.orderByAsc("create_time"); |
| | | List<InvoiceRegistrationProduct> remainList = invoiceRegistrationProductMapper.selectList(newQueryWrapper); |
| | | |
| | | // 查询销售台账产品 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | |
| | | if (CollectionUtils.isEmpty(remainList)) { |
| | | // 没有任何开票记录,恢复初始状态 |
| | | salesLedgerProduct.setInvoiceNum(BigDecimal.ZERO); |
| | | salesLedgerProduct.setInvoiceAmount(BigDecimal.ZERO); |
| | | salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity()); |
| | | salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | }else { |
| | | } else { |
| | | salesLedgerProduct.setInvoiceNum(salesLedgerProduct.getInvoiceNum().subtract(invoiceRegistrationProduct.getInvoiceNum())); |
| | | salesLedgerProduct.setInvoiceAmount(salesLedgerProduct.getInvoiceAmount().subtract(invoiceRegistrationProduct.getInvoiceAmount())); |
| | | salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getNoInvoiceNum().add(invoiceRegistrationProduct.getInvoiceNum())); |
| | | salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getNoInvoiceAmount().add(invoiceRegistrationProduct.getInvoiceAmount())); |
| | | } |
| | | |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | |
| | |
| | | * @param invoiceRegistrationProduct |
| | | * @param invoiceLedger |
| | | */ |
| | | private void dealOtherMonthDel(InvoiceRegistrationProduct invoiceRegistrationProduct,InvoiceLedger invoiceLedger ){ |
| | | InvoiceRegistrationProduct copyRegProduct = new InvoiceRegistrationProduct(); |
| | | BeanUtils.copyProperties(invoiceRegistrationProduct, copyRegProduct); |
| | | BigDecimal invoiceNum = copyRegProduct.getInvoiceNum().negate(); |
| | | BigDecimal invoiceAmount = copyRegProduct.getInvoiceAmount().negate(); |
| | | // invoice_registration_product |
| | | // 删除开票登记并回滚 |
| | | private void dealOtherMonthDel(InvoiceRegistrationProduct invoiceRegistrationProduct, InvoiceLedger invoiceLedger) { |
| | | //查询历史开票登记 |
| | | QueryWrapper<InvoiceRegistrationProduct> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("sales_ledger_id", invoiceRegistrationProduct.getSalesLedgerId()); |
| | | queryWrapper.eq("sales_ledger_product_id", invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | queryWrapper.orderByAsc("create_time"); |
| | | List<InvoiceRegistrationProduct> invoiceRegistrationProductList = invoiceRegistrationProductMapper.selectList(queryWrapper); |
| | | InvoiceRegistrationProduct lastInvoiceRegistrationProduct = invoiceRegistrationProductList.get(invoiceRegistrationProductList.size() - 1); |
| | | BigDecimal noInvoiceNum = lastInvoiceRegistrationProduct.getNoInvoiceNum().subtract(invoiceNum); |
| | | BigDecimal noInvoiceAmount = lastInvoiceRegistrationProduct.getNoInvoiceAmount().subtract(invoiceAmount); |
| | | copyRegProduct.setInvoiceNum(invoiceNum); |
| | | copyRegProduct.setInvoiceAmount(invoiceAmount); |
| | | copyRegProduct.setNoInvoiceNum(noInvoiceNum); |
| | | copyRegProduct.setNoInvoiceAmount(noInvoiceAmount); |
| | | copyRegProduct.setId(null); |
| | | invoiceRegistrationProductMapper.insert(copyRegProduct); |
| | | List<InvoiceRegistrationProduct> list = invoiceRegistrationProductMapper.selectList(queryWrapper); |
| | | |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return; |
| | | } |
| | | |
| | | InvoiceRegistrationProduct last = list.get(list.size() - 1); |
| | | |
| | | BigDecimal negateInvoiceNum = invoiceRegistrationProduct.getInvoiceNum().negate(); |
| | | BigDecimal negateInvoiceAmount = invoiceRegistrationProduct.getInvoiceAmount().negate(); |
| | | |
| | | InvoiceRegistrationProduct copy = new InvoiceRegistrationProduct(); |
| | | BeanUtils.copyProperties(invoiceRegistrationProduct, copy); |
| | | |
| | | copy.setId(null); |
| | | copy.setInvoiceNum(negateInvoiceNum); |
| | | copy.setInvoiceAmount(negateInvoiceAmount); |
| | | |
| | | // 未开票 = 上一条 + 本次冲回的数量 |
| | | copy.setNoInvoiceNum(last.getNoInvoiceNum().add(invoiceRegistrationProduct.getInvoiceNum())); |
| | | copy.setNoInvoiceAmount(last.getNoInvoiceAmount().add(invoiceRegistrationProduct.getInvoiceAmount())); |
| | | |
| | | invoiceRegistrationProductMapper.insert(copy); |
| | | |
| | | // 复制开票台账 |
| | | InvoiceLedger invoiceLedgerCopy = new InvoiceLedger(); |
| | | BeanUtils.copyProperties(invoiceLedger, invoiceLedgerCopy); |
| | | invoiceLedgerCopy.setInvoiceRegistrationProductId(copyRegProduct.getId()); |
| | | BigDecimal invoiceTotal = invoiceLedgerCopy.getInvoiceTotal().negate(); |
| | | invoiceLedgerCopy.setInvoiceTotal(invoiceTotal); |
| | | invoiceLedgerCopy.setId(null); |
| | | invoiceLedgerCopy.setInvoiceDate(LocalDate.now()); |
| | | invoiceLedgerMapper.insert(invoiceLedgerCopy); |
| | | // 更新sales_leger_product |
| | | QueryWrapper<SalesLedgerProduct> salesLedgerProductQueryWrapper = new QueryWrapper<>(); |
| | | salesLedgerProductQueryWrapper.eq("id", invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectOne(salesLedgerProductQueryWrapper); |
| | | salesLedgerProduct.setNoInvoiceNum(noInvoiceNum); |
| | | salesLedgerProduct.setNoInvoiceAmount(noInvoiceAmount); |
| | | BigDecimal newInvoiceNum = salesLedgerProduct.getInvoiceNum().add(invoiceNum); |
| | | BigDecimal newInvocieAmount = salesLedgerProduct.getInvoiceAmount().add(invoiceAmount); |
| | | salesLedgerProduct.setInvoiceNum(newInvoiceNum); |
| | | salesLedgerProduct.setInvoiceAmount(newInvocieAmount); |
| | | InvoiceLedger ledgerCopy = new InvoiceLedger(); |
| | | BeanUtils.copyProperties(invoiceLedger, ledgerCopy); |
| | | |
| | | ledgerCopy.setId(null); |
| | | ledgerCopy.setInvoiceRegistrationProductId(copy.getId()); |
| | | ledgerCopy.setInvoiceTotal(invoiceLedger.getInvoiceTotal().negate()); |
| | | ledgerCopy.setInvoiceDate(LocalDate.now()); |
| | | |
| | | invoiceLedgerMapper.insert(ledgerCopy); |
| | | |
| | | // 回滚 sales_ledger_product |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(invoiceRegistrationProduct.getSalesLedgerProductId()); |
| | | |
| | | // 已开票 |
| | | salesLedgerProduct.setInvoiceNum(salesLedgerProduct.getInvoiceNum().add(negateInvoiceNum)); |
| | | salesLedgerProduct.setInvoiceAmount(salesLedgerProduct.getInvoiceAmount().add(negateInvoiceAmount)); |
| | | |
| | | // 未开票 |
| | | salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getNoInvoiceNum().add(invoiceRegistrationProduct.getInvoiceNum())); |
| | | salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getNoInvoiceAmount().add(invoiceRegistrationProduct.getInvoiceAmount())); |
| | | |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | |
| | | } |