refactor(so): 同步更新应收单和销售发票信息
- 修改销售订单时,同步更新相关的应收单和销售发票信息 - 更新应收单的部门、业务员、客户等信息 - 更新销售发票的物料、单位等信息- 优化了查询和更新逻辑,提高了系统性能
This commit is contained in:
		
							parent
							
								
									a88411238e
								
							
						
					
					
						commit
						b10459f27a
					
				|  | @ -22,6 +22,8 @@ import nc.pubimpl.so.m30.pub.SaleOrderSaveUtil; | |||
| import nc.pubitf.so.m30.api.ISaleOrderQueryAPI; | ||||
| import nc.vo.arap.gathering.GatheringBillItemVO; | ||||
| import nc.vo.arap.gathering.GatheringBillVO; | ||||
| import nc.vo.arap.receivable.ReceivableBillItemVO; | ||||
| import nc.vo.arap.receivable.ReceivableBillVO; | ||||
| import nc.vo.bd.defdoc.DefdocVO; | ||||
| import nc.vo.ml.NCLangRes4VoTransl; | ||||
| import nc.vo.pub.BusinessException; | ||||
|  | @ -1867,20 +1869,27 @@ public class APISaleOrderMaitainImpl implements IAPISaleOrderMaitain { | |||
|             if (null != invoiceBVOS) { | ||||
|                 Set<String> billIds = new HashSet<>(); | ||||
|                 for (SaleInvoiceBVO invoiceBVO : invoiceBVOS) { | ||||
|                     // ²éѯӦÊÕµ¥ÊÇ·ñÉúЧ | ||||
|                     String countSql = "SELECT count(1) FROM ar_recitem b " | ||||
|                             + " left join ar_recbill a on a.pk_recbill = b.pk_recbill " | ||||
|                             + " WHERE b.dr = 0 and a.effectstatus = 10 and b.src_billid = '[billId]' "; | ||||
|                     countSql = countSql.replace("[billId]", csaleorderid); | ||||
|                     Integer num = (Integer) getDao().executeQuery(countSql, new ColumnProcessor()); | ||||
|                     if (num > 0) { | ||||
|                         continue; | ||||
|                     } | ||||
|                     // 来源单据子表 | ||||
|                     String csrcbid = invoiceBVO.getCsrcbid() != null ? invoiceBVO.getCsrcbid() : "~"; | ||||
|                     // 匹配销售订单子表的vo | ||||
|                     SaleOrderBVO soBvo = Arrays.stream(bvos) | ||||
|                             .filter(bvo -> csrcbid.equals(bvo.getCsaleorderbid())) | ||||
|                             .findFirst() | ||||
|                             .orElse(null); | ||||
|                     invoiceBVO.setCordercustid(ccustomerid); | ||||
|                     invoiceBVO.setCordercustvid(ccustomervid); | ||||
|                     invoiceBVO.setCdeptid(cdeptid); | ||||
|                     invoiceBVO.setCdeptvid(cdeptvid); | ||||
|                     invoiceBVO.setCemployeeid(cemployeeid); | ||||
|                     if (soBvo != null) { | ||||
|                         invoiceBVO.setCmaterialid(soBvo.getCmaterialid()); | ||||
|                         invoiceBVO.setCmaterialvid(soBvo.getCmaterialvid()); | ||||
|                         invoiceBVO.setCastunitid(soBvo.getCastunitid()); | ||||
|                         invoiceBVO.setCunitid(soBvo.getCunitid()); | ||||
|                         invoiceBVO.setVchangerate(soBvo.getVchangerate()); | ||||
|                         invoiceBVO.setCqtunitid(soBvo.getCqtunitid()); | ||||
|                         invoiceBVO.setVqtunitrate(soBvo.getVqtunitrate()); | ||||
|                     } | ||||
|                     invoiceBVO.setStatus(VOStatus.UPDATED); | ||||
|                     hypub.update(invoiceBVO); | ||||
|                     billIds.add(invoiceBVO.getCsaleinvoiceid()); | ||||
|  | @ -1897,6 +1906,41 @@ public class APISaleOrderMaitainImpl implements IAPISaleOrderMaitain { | |||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             // 同步修改应收单的部门、业务员、客户、开票客户 | ||||
|             for (SaleOrderBVO saleOrderBVO : bvos) { | ||||
|                 SqlBuilder recWhere = new SqlBuilder(); | ||||
|                 recWhere.append("src_itemid", saleOrderBVO.getCsaleorderbid()); | ||||
|                 ReceivableBillItemVO[] receivableBillItemVOS = (ReceivableBillItemVO[]) hypub.queryByCondition(ReceivableBillItemVO.class, recWhere.toString()); | ||||
|                 if (null != receivableBillItemVOS) { | ||||
|                     for (ReceivableBillItemVO itemVO : receivableBillItemVOS) { | ||||
|                         String pkRecbill = itemVO.getPk_recbill();// 应收单id | ||||
|                         ReceivableBillVO billVO = (ReceivableBillVO) hypub.queryByPrimaryKey(ReceivableBillVO.class, pkRecbill); | ||||
|                         if (billVO != null) { | ||||
|                             // 应收单未生效则同步修改 | ||||
|                             if (billVO.getEffectstatus() != 10) { | ||||
|                                 itemVO.setPk_deptid(cdeptid); | ||||
|                                 itemVO.setPk_deptid_v(cdeptvid); | ||||
|                                 itemVO.setPk_psndoc(cemployeeid); | ||||
|                                 itemVO.setCustomer(ccustomerid); | ||||
|                                 itemVO.setCustomer_v(ccustomervid); | ||||
|                                 itemVO.setMaterial(saleOrderBVO.getCmaterialid()); | ||||
|                                 itemVO.setMaterial_src(saleOrderBVO.getCmaterialid()); | ||||
|                                 itemVO.setStatus(VOStatus.UPDATED); | ||||
|                                 hypub.update(itemVO); | ||||
|                                 // 修改应收单 | ||||
|                                 billVO.setPk_deptid(cdeptid); | ||||
|                                 billVO.setPk_deptid_v(cdeptvid); | ||||
|                                 billVO.setPk_psndoc(cemployeeid); | ||||
|                                 billVO.setCustomer(ccustomerid); | ||||
|                                 billVO.setCustomer_v(ccustomervid); | ||||
|                                 billVO.setStatus(VOStatus.UPDATED); | ||||
|                                 hypub.update(billVO); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue