Browse Source

更新货款调账的方法

hejq 7 years ago
parent
commit
b8f79f8842

+ 15 - 25
src/main/java/com/uas/platform/b2b/erp/service/impl/PurchaseAPBillServiceImpl.java

@@ -81,37 +81,27 @@ public class PurchaseAPBillServiceImpl implements PurchaseAPBillService {
 		List<ApbillAdjustment> adjusts = new ArrayList<ApbillAdjustment>();
 		if (!CollectionUtils.isEmpty(apBills)) {
 			Long enUU = SystemSession.getUser().getEnterprise().getUu();
+			// 获取物料编号集合
+			Set<String> productCodes = CollectionUtil.getProductCodeCollection(apBills);
+            Map<String, ProductInfo> products = null;
+            if (!CollectionUtils.isEmpty(productCodes)) {
+                products = ProductUtils.findByEnUUAndCodes(enUU, productCodes);
+            }
 			for (PurchaseAPBill apBill : apBills) {
 				if (!CollectionUtils.isEmpty(apBill.getDetails())) {
 					for (PurchaseAPBillDetail detail : apBill.getDetails()) {
-						ApbillAdjustment adjust = new ApbillAdjustment(apBill);
-						Product product = new Product();
-						product.setCode(detail.getAbd_prodcode());
-						adjust.setPrid(product.getId());
-						adjust.setDetno(detail.getAbd_detno());
-						adjust.setProdcode(product.getCode());
-						adjust.setProdUnit(product.getUnit());
-						adjust.setQty(detail.getAbd_qty());
-						adjust.setThischeckqty(detail.getAbd_thisvoqty());
-						adjust.setOrderprice(detail.getAbd_price());
-						adjust.setOrdercode(detail.getAbd_ordercode());
-						adjust.setOrderdetno(detail.getAbd_orderdetno());
-						adjust.setTaxrate(detail.getAbd_taxrate());
-						if (detail.getAbd_yqty() != null) {
-							adjust.setYcheckqty(detail.getAbd_yqty());
-						} else {
-							adjust.setYcheckqty((double) 0);
-						}
+						ApbillAdjustment adjust = new ApbillAdjustment(apBill, detail);
 						Enterprise enterprise = enterpriseDao.findEnterpriseByUu(adjust.getEnuu());
 						adjust.setReceivename(enterprise.getEnName());
-						List<Product> products = ProductUtils.findByEnUUAndCode(enUU, adjust.getProdcode());
 						if (!CollectionUtils.isEmpty(products)) {
-							Product productInfo = products.get(0);
-							adjust.setPrid(productInfo.getId());
-							adjust.setProdcode(productInfo.getCode());
-							adjust.setProdtitle(productInfo.getTitle());
-							adjust.setProdspec(productInfo.getSpec());
-						}
+                            ProductInfo product = products.get(adjust.getProdcode());
+                            if (null != product) {
+                                adjust.setPrid(product.getId());
+                                adjust.setProdcode(product.getCode());
+                                adjust.setProdtitle(product.getTitle());
+                                adjust.setProdspec(product.getSpec());
+                            }
+                        }
 						adjusts.add(adjust);
 					}
 				}

+ 16 - 2
src/main/java/com/uas/platform/b2b/model/ApbillAdjustment.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2b.model;
 
 import com.uas.platform.b2b.erp.model.PurchaseAPBill;
+import com.uas.platform.b2b.erp.model.PurchaseAPBillDetail;
 import com.uas.platform.b2b.support.SystemSession;
 
 import javax.persistence.*;
@@ -462,10 +463,9 @@ public class ApbillAdjustment implements Serializable {
 		this.nonposting = nonposting;
 	}
 
-	public ApbillAdjustment(PurchaseAPBill apBill) {
+	public ApbillAdjustment(PurchaseAPBill apBill, PurchaseAPBillDetail detail) {
 		Enterprise enterprise = SystemSession.getUser().getEnterprise();
 		this.setCurrency(apBill.getAb_currency());
-		this.setDate(new Date());
 		this.setOrderdate(apBill.getAb_date());
 		this.setSourceid(apBill.getAb_id());
 		this.setEnuu(apBill.getAb_vendoruu());
@@ -473,6 +473,20 @@ public class ApbillAdjustment implements Serializable {
 		this.setCustname(enterprise.getEnName());
 		this.setInoutno(apBill.getAb_code());
 		this.setRate(apBill.getAb_rate());
+		this.setProdcode(detail.getAbd_prodcode());
+		this.setDetno(detail.getAbd_detno());
+        this.setQty(detail.getAbd_qty());
+        this.setThischeckqty(detail.getAbd_thisvoqty());
+        this.setOrderprice(detail.getAbd_price());
+        this.setOrdercode(detail.getAbd_ordercode());
+        this.setOrderdetno(detail.getAbd_orderdetno());
+        this.setTaxrate(detail.getAbd_taxrate());
+        this.setDate(new Date(System.currentTimeMillis()));
+        if (detail.getAbd_yqty() != null) {
+            this.setYcheckqty(detail.getAbd_yqty());
+        } else {
+            this.setYcheckqty((double) 0);
+        }
 	}
 
 	public ApbillAdjustment() {