浏览代码

销售出货&退货

rainco 7 年之前
父节点
当前提交
16798a0c5e

+ 4 - 1
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/mapper/ProdIODetailMapper.java

@@ -31,6 +31,9 @@ public interface ProdIODetailMapper extends CommonBaseMapper<ProdIODetail> {
     void updateSaleOutYqty(Long id);
 
     List<ProdIODetail> selectByFK(Long id);
-
+    //销售入库更新计算明细其它字段
+    void updatePDSaleIN(Long id);
+    //销售出库更新计算明细其它字段
+    void updatePDSaleOut(Long id);
 
 }

+ 23 - 21
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/impl/ProdInOutServiceImpl.java

@@ -36,8 +36,8 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
 
 //    @Autowired
 //    private SaledetailMapper saledetailMapper;
-//    @Autowired
-//    private MaxnumberService maxnumberService;
+    @Autowired
+    private MaxnumberService maxnumberService;
     @Autowired
     private SaleMapper saleMapper;
     @Autowired
@@ -158,11 +158,11 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
     }
     private void singleDelete(Long id) {
         if (null != id) {
+            ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
             //从表删除
             prodIODetailMapper.deleteByForeignKey(id);
             //主表删除
             prodInOutMapper.deleteByPrimaryKey(id);
-            ProdInOut prodInOut = getMapper().selectByPrimaryKey(id);
             //更新已转数
             updateYqty(prodInOut);
         }
@@ -215,9 +215,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
 
     @Override
     public Integer deleteItem(Long id) {
-        Integer num = prodIODetailMapper.deleteByPrimaryKey(id);
         ProdIODetail prodIODetail = prodIODetailMapper.selectByPrimaryKey(id);
         ProdInOut prodInOut = getMapper().selectByPrimaryKey(prodIODetail.getPd_piid());
+        Integer num = prodIODetailMapper.deleteByPrimaryKey(id);
         //更新已转数
         updateYqty(prodInOut);
         return num;
@@ -271,8 +271,8 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         List<ProdIODetail> sourcePids =prodIODetailMapper.selectByFK(id);
         //检查从表
         for (ProdIODetail prodIODetail : sourcePids) {
-            pdOutqty = prodIODetail.getPd_outqty();
-            pdYqty = prodIODetail.getPd_yqty();
+            pdOutqty = prodIODetail.getPd_outqty()==null?0.0:prodIODetail.getPd_outqty();
+            pdYqty = prodIODetail.getPd_yqty()==null?0.0:prodIODetail.getPd_yqty();
             if (pdOutqty-pdYqty>0){
                 count++;
             }
@@ -284,8 +284,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         //插入销售退货单主表
         ProdInOut targetPi = new ProdInOut();
         //生成单号
-        String piInoutno = "ProdInOut!SaleReturn"+Math.abs(Math.random()*10);
-                //maxnumberService.getMaxnumber("ProdInOut!Sale",true).getData();
+        String piInoutno =  maxnumberService.getMaxnumber("ProdInOut!Sale",true).getData();
         targetPi.setPi_inoutno(piInoutno);
         targetPi.setPi_class("销售退货单");
         targetPi.setPi_date(new Date());
@@ -294,7 +293,8 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         targetPi.setPi_custid(sourcePi.getPi_custid());
         targetPi.setPi_custcode(sourcePi.getPi_custcode());
         targetPi.setPi_custname(sourcePi.getPi_custname());
-
+        targetPi.setPi_status("未审核");
+        targetPi.setPi_statuscode("UNAUDITED");
         targetPi.setPi_sacode(sourcePi.getPi_sacode());
         targetPi.setPi_said(sourcePi.getPi_said());
         //设置公司id
@@ -306,7 +306,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         for (int i = 0;i<sourcePids.size();i++){
             ProdIODetail sourcePid = sourcePids.get(i);
             ProdIODetail targetPid = new ProdIODetail();
-            if(sourcePid.getPd_inqty()-sourcePid.getPd_yqty()>0){
+            pdOutqty = sourcePid.getPd_outqty()==null?0.0:sourcePid.getPd_outqty();
+            pdYqty = sourcePid.getPd_yqty()==null?0.0:sourcePid.getPd_yqty();
+            if(pdOutqty-pdYqty>0){
                 targetPid.setPd_piid(pi_id);
                 targetPid.setPd_inoutno(piInoutno);
                 targetPid.setPd_piclass("销售退货单");
@@ -314,18 +316,23 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
                 targetPid.setPd_orderid(sourcePid.getPd_orderid());
                 targetPid.setPd_ordercode(sourcePid.getPd_ordercode());
                 targetPid.setPd_orderdetno(sourcePid.getPd_orderdetno());
+
                 targetPid.setPd_sendprice(sourcePid.getPd_sendprice());
+
                 targetPid.setPd_sdid(sourcePid.getPd_sdid());
+
                 targetPid.setPd_prodid(sourcePid.getPd_prodid());
                 targetPid.setPd_prodcode(sourcePid.getPd_prodcode());
+                targetPid.setPd_unit(sourcePid.getPd_unit());
                 targetPid.setPd_ioid(sourcePid.getId());
+                targetPid.setPd_status(0);
                 //公司id
                 targetPid.setCompanyId(sourcePid.getCompanyId());
                 //本次转单数
-                targetPid.setPd_inqty(sourcePid.getPd_outqty()-sourcePid.getPd_yqty());
+                targetPid.setPd_inqty(pdOutqty-pdYqty);
                 prodIODetailMapper.insertSelective(targetPid);
                 //更新已转数
-                sourcePid.setPd_yqty(sourcePid.getPd_outqty());
+                sourcePid.setPd_yqty(pdOutqty);
                 prodIODetailMapper.updateByPrimaryKeySelective(sourcePid);
             }
         }
@@ -340,9 +347,9 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
      * @Date: 2018/10/19
      */
     private String pushMaxnubmer(String code, Long id,String pi_class) {
-//        if (null == code) {
-//            throw new BizException(BizExceptionCode.NULL_CODE);
-//        }
+        if (null == code) {
+            throw new BizException(BizExceptionCode.NULL_CODE);
+        }
         Integer count = "0".equals(String.valueOf(id)) ? saleMapper.validateCodeWhenInsert(code) :
                 saleMapper.validateCodeWhenUpdate(code, id);
         String caller = "";
@@ -351,12 +358,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         }else {//销售退货单
             caller = "ProdInOut!SaleReturn";
         }
-        if (null == code) {
-            return caller+Math.random()*10;
-        }else{
-            return code;
-        }
-        //return maxnumberService.pushMaxnubmer(count, code, caller).getData();
+        return maxnumberService.pushMaxnubmer(count, code, caller).getData();
     }
     /**
      * @Description: 更新已转数

+ 16 - 2
applications/sale/sale-server/src/main/resources/mapper/ProdIODetailMapper.xml

@@ -41,7 +41,7 @@
     <result column="pd_ym" jdbcType="INTEGER" property="pd_ym" />
     <result column="pd_yqty" jdbcType="INTEGER" property="pd_yqty" />
     <result column="pd_ioid" jdbcType="INTEGER" property="pd_ioid" />
-    <association property="product" javaType="com.usoftchina.saas.document.po.Product">
+    <association property="product" javaType="com.usoftchina.saas.document.entities.Product">
       <id column="pr_id" property="id"/>
       <result column="pr_code" property="pr_code"/>
       <result column="pr_detail" property="pr_detail"/>
@@ -1284,7 +1284,7 @@
     </foreach>
   </update>
 
-  <update id="updateSaleOutYqty" parameterType="long">
+  <update id="updateSaleOutYqty" parameterType="long">3
   set a.pd_yqty =ifnull((select  b.pd_inqty  from  (select pd_ioid,sum(pd_inqty) pd_inqty from  prodiodetail left join prodinout on pd_piid = pi_id where pd_piclass='销售退货单'
 and pi_said=#{id}  GROUP BY pd_ioid) b where ifnull(b.pd_ioid ,0)= a.pd_id ),0)
 where a.pd_piid = (select pi_id from prodinout where pi_said=#{id} and pi_class='销售出货单')
@@ -1296,4 +1296,18 @@ where a.pd_piid = (select pi_id from prodinout where pi_said=#{id} and pi_class=
     where pd_piid=#{id} order by pd_pdno
   </select>
 
+  <update id="updatePDSaleIN" parameterType="long">
+   update prodiodetail set
+   pd_total=ifnull(pd_inqty,0)*ifnull(pd_orderprice,0),
+   pd_netprice = ifnull(pd_sendprice,0)/(1+ifnull(pd_taxrate,0)/100),
+   pd_nettotal = (ifnull(pd_sendprice,0)/(1+ifnull(pd_taxrate,0)/100))*ifnull(pd_inqty)
+   where pd_piid=#{id}
+  </update>
+  <update id="updatePDSaleOut" parameterType="long">
+    update prodiodetail set
+    pd_total=ifnull(pd_outqty,0)*ifnull(pd_orderprice,0),
+    pd_netprice = ifnull(pd_sendprice,0)/(1+ifnull(pd_taxrate,0)/100),
+    pd_nettotal = (ifnull(pd_sendprice,0)/(1+ifnull(pd_taxrate,0)/100))*ifnull(pd_outqty)
+    where pd_piid=#{id}
+  </update>
 </mapper>