Browse Source

更新销售金额单价

guq 7 years ago
parent
commit
dacedd490d

+ 4 - 0
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/mapper/SaleMapper.java

@@ -33,4 +33,8 @@ public interface SaleMapper {
     Integer validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("companyId") Long companyId);
 
     void updateTotal(Long id);
+
+    void updateTotalAndNetPrice(Long id);
+
+    void updateNetTotal(Long id);
 }

+ 37 - 4
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/impl/SaleServiceImpl.java

@@ -137,7 +137,11 @@ public class SaleServiceImpl implements SaleService{
             }
             baseDTO = getBaseDTOById(sa_id);
             //更新销售金额
-            getTotal(sa_id);
+            updateTotal(sa_id);
+            //更新从表总额
+            updateTotalAndNetPrice(sa_id);
+            //更新从表不含税金额
+            updateNetTotal(sa_id);
             //日志记录
             messageLogService.save(baseDTO);
             return baseDTO;
@@ -165,7 +169,11 @@ public class SaleServiceImpl implements SaleService{
         }
         baseDTO = getBaseDTOById(sa_id);
         //更新销售金额
-        getTotal(sa_id);
+        updateTotal(sa_id);
+        //更新从表总额
+        updateTotalAndNetPrice(sa_id);
+        //更新从表不含税金额
+        updateNetTotal(sa_id);
         //日志
         messageLogService.update(baseDTO);
         return baseDTO;
@@ -252,7 +260,12 @@ public class SaleServiceImpl implements SaleService{
         sale.setUpdaterId(BaseContextHolder.getUserId());
         //更新存在字段
         saleMapper.updateByPrimaryKeySelective(sale);
-
+        //更新销售金额
+        updateTotal(id);
+        //更新从表总额
+        updateTotalAndNetPrice(id);
+        //更新从表不含税金额
+        updateNetTotal(id);
         DocBaseDTO docBaseDTO = getBaseDTOById(id);
         //日志
         messageLogService.audit(docBaseDTO);
@@ -489,11 +502,31 @@ public class SaleServiceImpl implements SaleService{
     }
 
     //更新最新销售总额
-    private void getTotal(Long id) {
+    private void updateTotal(Long id) {
         if (null == id) {
             return;
         }
         saleMapper.updateTotal(id);
     }
 
+    /**
+    * @Description: 更新从表总额与不含税单价
+    * @Param: [id]
+    * @return: void
+    * @Author: guq
+    * @Date: 2018/10/27
+    */
+    private void updateTotalAndNetPrice(Long id) {
+        if (null == id) {
+            return;
+        }
+        saleMapper.updateTotalAndNetPrice(id);
+    }
+
+    private void updateNetTotal(Long id) {
+        if (null == id) {
+            return;
+        }
+        saleMapper.updateNetTotal(id);
+    }
 }

+ 11 - 0
applications/sale/sale-server/src/main/resources/mapper/SaleMapper.xml

@@ -364,4 +364,15 @@
   <update id="updateTotal" parameterType="long">
     	update sale a set sa_total=(select sum(sd_price*sd_qty) from saledetail b where b.sd_said=a.sa_id ) where sa_id=#{id};
   </update>
+
+  <update id="updateTotalAndNetPrice" parameterType="long">
+    update saledetail a set sd_total=sd_qty*sd_price,
+    sd_netprice=round(ifnull(sd_price,0)/(1+ifnull(sd_taxrate,0)/100),6)
+     where sd_said=#{id}
+  </update>
+
+  <update id="updateNetTotal" parameterType="long">
+    update saledetail a set sd_nettotal=round(ifnull(sd_netprice,0)*nvl(sd_qty,0),2)
+    where sd_said=#{id}
+  </update>
 </mapper>