Browse Source

收款单审核反审核按客户+币别更新余额,更新客户资料客户余额本位币

dingyl 6 years ago
parent
commit
4cb16f7b42

+ 8 - 0
applications/money/money-server/src/main/java/com/usoftchina/saas/money/mapper/RecbalanceMapper.java

@@ -59,4 +59,12 @@ public interface RecbalanceMapper extends CommonBaseMapper<Recbalance> {
     String validateAudit(List<DocBaseDTO> baseDTOs);
 
     void updateByAmount(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    CustAramount selectCustArByCondition(@Param("con") String con, @Param("companyId") Long companyId);
+
+    int updateCustAramountByPrimaryKeySelective(CustAramount record);
+
+    int updateCustleftamountByPrimaryKey(Integer cu_id);
+
+    int insertCustAramount(CustAramount record);
 }

+ 101 - 0
applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/CustAramount.java

@@ -0,0 +1,101 @@
+package com.usoftchina.saas.money.po;
+
+import com.usoftchina.saas.base.entity.CommonBaseEntity;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class CustAramount extends CommonBaseEntity implements Serializable {
+    private  Integer ca_custid;
+    private  String ca_custcode;
+    private  String ca_custname;
+    private  String ca_currency;
+    private  Date ca_begindate;
+    private  Double ca_beginaramount;
+    private  Double ca_beginprerecamount;
+    private  Double ca_preamount;
+    private  Double ca_recamount;
+    private  Double ca_leftamount;
+
+    public Integer getCa_custid() {
+        return ca_custid;
+    }
+
+    public void setCa_custid(Integer ca_custid) {
+        this.ca_custid = ca_custid;
+    }
+
+    public String getCa_custcode() {
+        return ca_custcode;
+    }
+
+    public void setCa_custcode(String ca_custcode) {
+        this.ca_custcode = ca_custcode;
+    }
+
+    public String getCa_custname() {
+        return ca_custname;
+    }
+
+    public void setCa_custname(String ca_custname) {
+        this.ca_custname = ca_custname;
+    }
+
+    public String getCa_currency() {
+        return ca_currency;
+    }
+
+    public void setCa_currency(String ca_currency) {
+        this.ca_currency = ca_currency;
+    }
+
+    public Date getCa_begindate() {
+        return ca_begindate;
+    }
+
+    public void setCa_begindate(Date ca_begindate) {
+        this.ca_begindate = ca_begindate;
+    }
+
+    public Double getCa_beginaramount() {
+        return ca_beginaramount;
+    }
+
+    public void setCa_beginaramount(Double ca_beginaramount) {
+        this.ca_beginaramount = ca_beginaramount;
+    }
+
+    public Double getCa_beginprerecamount() {
+        return ca_beginprerecamount;
+    }
+
+    public void setCa_beginprerecamount(Double ca_beginprerecamount) {
+        this.ca_beginprerecamount = ca_beginprerecamount;
+    }
+
+    public Double getCa_preamount() {
+        return ca_preamount;
+    }
+
+    public void setCa_preamount(Double ca_preamount) {
+        this.ca_preamount = ca_preamount;
+    }
+
+    public Double getCa_recamount() {
+        return ca_recamount;
+    }
+
+    public void setCa_recamount(Double ca_recamount) {
+        this.ca_recamount = ca_recamount;
+    }
+
+    public Double getCa_leftamount() {
+        return ca_leftamount;
+    }
+
+    public void setCa_leftamount(Double ca_leftamount) {
+        this.ca_leftamount = ca_leftamount;
+    }
+}

+ 56 - 37
applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/RecbalanceServiceImpl.java

@@ -273,25 +273,35 @@ public class RecbalanceServiceImpl extends CommonBaseServiceImpl<RecbalanceMappe
         updateRay.setRb_auditman(BaseContextHolder.getUserName());
         recbalanceMapper.updateByPrimaryKeySelective(updateRay);
         /**
-         * 更新客户资料
-         * cu_preamount=nvl(cu_preamount,0)+rb_preamount,
-         * cu_recamount=nvl(cu_recamount,0)-rb_rbdamount,
-         * cu_leftamount=cu_beginaramount-cu_beginprerecamount+cu_recamount-cu_preamount;
+         * 更新客户应收
          */
-        Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(recbalance.getRb_custid());
-        Double preamount = customerData.getCu_preamount()==null?new Double(0):customerData.getCu_preamount();
-        Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
-        Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
-        Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
-
-        Customer customer = new Customer();
+        String con="ca_custid="+recbalance.getRb_custid()+" and ca_currency='"+recbalance.getRb_currency()+"'";
+        CustAramount custar=recbalanceMapper.selectCustArByCondition(con,companyId);
         Double paybalancePreamount = recbalance.getRb_preamount();
-        customer.setId(Long.valueOf(String.valueOf(recbalance.getRb_custid())));
-        customer.setId(Long.valueOf(String.valueOf(recbalance.getRb_custid())));
-        customer.setCu_preamount(preamount+paybalancePreamount);
-        customer.setCu_recamount(recamount-amountTotal2);
-        customer.setCu_leftamount(beginapamount-beginprepayamount+recamount-amountTotal2-preamount-paybalancePreamount);
-        recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
+        if (custar == null){
+            custar=new CustAramount();
+            custar.setCa_custid(recbalance.getRb_custid());
+            custar.setCa_custcode(recbalance.getRb_custcode());
+            custar.setCa_custname(recbalance.getRb_custname());
+            custar.setCa_currency(recbalance.getRb_currency());
+            custar.setCa_begindate(null);
+            custar.setCa_beginprerecamount(new Double(0));
+            custar.setCa_beginaramount(new Double(0));
+            custar.setCa_preamount(paybalancePreamount);
+            custar.setCa_recamount(new Double(0));
+            custar.setCa_leftamount(new Double(0)-paybalancePreamount);
+            custar.setCompanyId(companyId);
+            recbalanceMapper.insertCustAramount(custar);
+        }else {
+            Double capreamount = custar.getCa_preamount()==null?new Double(0):custar.getCa_preamount();
+            Double carecamount = custar.getCa_recamount()==null?new Double(0):custar.getCa_recamount();
+            Double caleftamount = custar.getCa_leftamount()==null?new Double(0):custar.getCa_leftamount();
+            custar.setCa_preamount(capreamount+paybalancePreamount);
+            custar.setCa_recamount(carecamount-amountTotal2);
+            custar.setCa_leftamount(caleftamount-amountTotal2-paybalancePreamount);
+            recbalanceMapper.updateCustAramountByPrimaryKeySelective(custar);
+        }
+        recbalanceMapper.updateCustleftamountByPrimaryKey(recbalance.getRb_custid());
 
         //更新本次核销金额
         for (Recbalancedetail detail: recbalancedetail) {
@@ -308,7 +318,6 @@ public class RecbalanceServiceImpl extends CommonBaseServiceImpl<RecbalanceMappe
             subledger1.setSl_namount(namount-nowBalance);//未核销
             subledgerMapper.updateByPrimaryKeySelective(subledger1);
         }
-
         //计算期间金额
         Statsinfo statsinfo = new Statsinfo();
         List<Integer> ymList = recbalancedetMapper.selectYm(Math.toIntExact(id));
@@ -326,9 +335,6 @@ public class RecbalanceServiceImpl extends CommonBaseServiceImpl<RecbalanceMappe
         this.updateProdInoutStatus(id);
 
         DocBaseDTO baseDTO = getBaseDTOById(id);
-//        commonService.commonAudit(BillCodeSeq.RECBALANCE.getCaller(),
-//                "rb_id="+baseDTO.getId(),"rb_status","rb_statuscode",
-//                "rb_auditdate","rb_auditman");
         //日志记录
         messageLogService.audit(baseDTO);
         return baseDTO;
@@ -371,27 +377,40 @@ public class RecbalanceServiceImpl extends CommonBaseServiceImpl<RecbalanceMappe
 
     @Override
     public void unAudit(Long id) {
-        //更新供应商资料
-        /**
-         * ve_preamount=nvl(ve_preamount,0)-pb_preamount,
-         * ve_payamount=nvl(ve_payamount,0)+pb_pbdamount,
-         * ve_leftamount=ve_beginapamount-ve_beginprepayamount+ve_payamount-ve_preamount;
+        Long companyId = BaseContextHolder.getCompanyId();
+        /**客户应收
          */
         Recbalance rec = recbalanceMapper.selectByPrimaryKey(Math.toIntExact(id));
         Double pay_preamount = rec.getRb_preamount()==null?new Double(0):rec.getRb_preamount();
         Double pay_pbdamount = rec.getRb_rbdamount()==null?new Double(0):rec.getRb_rbdamount();
-        Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(rec.getRb_custid());
-        Double preamount = customerData.getCu_preamount()==null?(new Double(0)):customerData.getCu_preamount();
-        Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
-        Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
-        Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
-        Customer customer = new Customer();
-        customer.setId(Long.valueOf(String.valueOf(rec.getRb_custid())));
-        customer.setCu_preamount(preamount-pay_preamount);
-        customer.setCu_recamount(recamount+pay_pbdamount);
-        customer.setCu_leftamount(beginapamount-beginprepayamount+recamount+pay_pbdamount-preamount+pay_preamount);
-        recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
 
+        String con="ca_custid="+rec.getRb_custid()+" and ca_currency='"+rec.getRb_currency()+"'";
+        CustAramount custar=recbalanceMapper.selectCustArByCondition(con,companyId);
+        Double paybalancePreamount = rec.getRb_preamount();
+        if (custar == null){
+            custar=new CustAramount();
+            custar.setCa_custid(rec.getRb_custid());
+            custar.setCa_custcode(rec.getRb_custcode());
+            custar.setCa_custname(rec.getRb_custname());
+            custar.setCa_currency(rec.getRb_currency());
+            custar.setCa_begindate(null);
+            custar.setCa_beginprerecamount(new Double(0));
+            custar.setCa_beginaramount(new Double(0));
+            custar.setCa_preamount(new Double(0)-pay_preamount);
+            custar.setCa_recamount(pay_pbdamount);
+            custar.setCa_leftamount(new Double(0)- pay_pbdamount + pay_preamount);
+            custar.setCompanyId(companyId);
+            recbalanceMapper.insertCustAramount(custar);
+        }else {
+            Double capreamount = custar.getCa_preamount()==null?new Double(0):custar.getCa_preamount();
+            Double carecamount = custar.getCa_recamount()==null?new Double(0):custar.getCa_recamount();
+            Double caleftamount = custar.getCa_leftamount()==null?new Double(0):custar.getCa_leftamount();
+            custar.setCa_preamount(capreamount-pay_preamount);
+            custar.setCa_recamount(carecamount+pay_pbdamount);
+            custar.setCa_leftamount(caleftamount+pay_pbdamount+pay_preamount);
+            recbalanceMapper.updateCustAramountByPrimaryKeySelective(custar);
+        }
+        recbalanceMapper.updateCustleftamountByPrimaryKey(rec.getRb_custid());
         //更新账户资料金额
         List<Recbalancedet> recbalancedet = recbalancedetMapper.selectByPrimaryKey(Math.toIntExact(id));
         for (Recbalancedet det:recbalancedet) {

+ 156 - 0
applications/money/money-server/src/main/resources/mapper/RecbalanceMapper.xml

@@ -879,4 +879,160 @@
   <select id="checkStatus" resultType="int">
     select count(1) from recbalance where ifnull(rb_statuscode,0)='AUDITED' and rb_id= #{id,jdbcType=INTEGER}
   </select>
+  <!--客户应收-->
+  <resultMap id="CustArResultMap" type="com.usoftchina.saas.money.po.CustAramount">
+    <id column="ca_id" jdbcType="INTEGER" property="id" />
+    <result column="ca_custid" jdbcType="INTEGER" property="ca_custid" />
+    <result column="ca_custcode" jdbcType="VARCHAR" property="ca_custcode" />
+    <result column="ca_custname" jdbcType="VARCHAR" property="ca_custname" />
+    <result column="ca_currency" jdbcType="VARCHAR" property="ca_currency" />
+    <result column="ca_begindate" jdbcType="TIMESTAMP" property="ca_begindate" />
+    <result column="ca_beginaramount" jdbcType="DOUBLE" property="ca_beginaramount" />
+    <result column="ca_beginprerecamount" jdbcType="DOUBLE" property="ca_beginprerecamount" />
+    <result column="ca_preamount" jdbcType="DOUBLE" property="ca_preamount" />
+    <result column="ca_recamount" jdbcType="DOUBLE" property="ca_recamount" />
+    <result column="ca_leftamount" jdbcType="DOUBLE" property="ca_leftamount" />
+    <result column="companyid" jdbcType="INTEGER" property="companyId" />
+  </resultMap>
+  <sql id="CustAramount_Column_List">
+    ca_id, ca_custid,ca_custcode, ca_custname, ca_currency,ca_begindate, ca_beginaramount, ca_beginprerecamount,
+    ca_recamount,ca_preamount,ca_leftamount,companyid
+  </sql>
+  <select id="selectCustArByCondition" resultMap="CustArResultMap">
+    select
+    <include refid="CustAramount_Column_List" />
+    from custaramount
+    <where>
+      <if test="con != null">
+        ${con}
+      </if>
+      <if test="companyId != null">
+        and   custaramount.companyId = #{companyId}
+      </if>
+    </where>
+  </select>
+  <update id="updateCustAramountByPrimaryKeySelective" parameterType="com.usoftchina.saas.money.po.CustAramount">
+    update CustAramount
+    <set>
+      <if test="ca_custid != null">
+        ca_custid = #{ca_custid,jdbcType=INTEGER},
+      </if>
+      <if test="ca_custcode != null">
+        ca_custcode = #{ca_custcode,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_custname != null">
+        ca_custname = #{ca_custname,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_currency != null">
+        ca_currency = #{ca_currency,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_begindate != null">
+        ca_begindate = #{ca_begindate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="ca_beginaramount != null">
+        ca_beginaramount = #{ca_beginaramount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_beginprerecamount != null">
+        ca_beginprerecamount = #{ca_beginprerecamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_recamount != null">
+        ca_recamount = #{ca_recamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_preamount != null">
+        ca_preamount = #{ca_preamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_leftamount != null">
+        ca_leftamount = #{ca_leftamount,jdbcType=DOUBLE},
+      </if>
+      <if test="companyId != null">
+        companyid = #{companyId,jdbcType=INTEGER},
+      </if>
+    </set>
+    where ca_id = #{id}
+  </update>
+  <update id="updateCustleftamountByPrimaryKey" parameterType="java.lang.Integer">
+        update customer
+    <set>
+      cu_leftamount=ifnull((select sum(ca_leftamount*(case when ifnull(cr_rate,0)=0 then 1 else ifnull(cr_rate,0) end ))
+      from custaramount left join currencys on cr_name=ca_currency and custaramount.companyid=currencys.companyid
+      where custaramount.companyid=customer.companyid and ca_custid=#{cu_id,jdbcType=INTEGER}),0)
+    </set>
+    where cu_id = #{cu_id,jdbcType=INTEGER}
+  </update>
+  <insert id="insertCustAramount" parameterType="com.usoftchina.saas.money.po.CustAramount">
+    <selectKey resultType="java.lang.Long" keyProperty="id">
+      SELECT LAST_INSERT_ID() AS ID
+    </selectKey>
+    insert into CustAramount
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="companyId != null">
+        companyId,
+      </if>
+      <if test="ca_custid != null">
+        ca_custid,
+      </if>
+      <if test="ca_custcode != null">
+        ca_custcode,
+      </if>
+      <if test="ca_custname != null">
+        ca_custname,
+      </if>
+      <if test="ca_currency != null">
+        ca_currency,
+      </if>
+      <if test="ca_begindate != null">
+        ca_begindate,
+      </if>
+      <if test="ca_beginaramount != null">
+        ca_beginaramount,
+      </if>
+      <if test="ca_beginprerecamount != null">
+        ca_beginprerecamount,
+      </if>
+      <if test="ca_recamount != null">
+        ca_recamount,
+      </if>
+      <if test="ca_preamount != null" >
+        ca_preamount,
+      </if>
+      <if test="ca_leftamount != null" >
+        ca_leftamount,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="companyId != null">
+        #{companyId,jdbcType=INTEGER},
+      </if>
+      <if test="ca_custid != null">
+        #{ca_custid,jdbcType=INTEGER},
+      </if>
+      <if test="ca_custcode != null">
+        #{ca_custcode,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_custname != null">
+        #{ca_custname,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_currency != null">
+        #{ca_currency,jdbcType=VARCHAR},
+      </if>
+      <if test="ca_begindate != null">
+        #{ca_begindate,jdbcType=TIMESTAMP},
+      </if>
+      <if test="ca_beginaramount != null">
+        #{ca_beginaramount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_beginprerecamount != null">
+        #{ca_beginprerecamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_recamount != null">
+        #{ca_recamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_preamount != null" >
+        #{ca_preamount,jdbcType=DOUBLE},
+      </if>
+      <if test="ca_leftamount != null" >
+        #{ca_leftamount,jdbcType=DOUBLE},
+      </if>
+    </trim>
+  </insert>
 </mapper>