Эх сурвалжийг харах

1.跟单开票处新增开票方式:保司开票/掌柜开票

  如果是保司开票,需要填写税点,后续在结算时,税收成本算做支出项,进账金额=开票金额*(1-税点),但统计应收金额,开票金额,已收金额,开票未进账金额均按照不扣税点的金额核算。

  如果是掌柜开票,需要填写税点,但后续结算时,进账金额=开票金额。
wuhp 2 жил өмнө
parent
commit
57c81d4605

+ 13 - 0
src/main/java/com/ydtech/modules/fnc/entity/SettlementDocumentaryFeesEntity.java

@@ -96,4 +96,17 @@ public class SettlementDocumentaryFeesEntity implements Serializable {
     @ApiModelProperty("合作公司id")
     @TableField("partner_companies_id")
     private String partnerCompaniesId;
+
+    @ApiModelProperty("开票方式")
+    @TableField("invoicing_method")
+    private String invoicingMethod;
+
+    @ApiModelProperty("税点")
+    @TableField("tax_points")
+    private BigDecimal taxPoints;
+
+    @ApiModelProperty("税点金额")
+    @TableField("expend_amount")
+    private BigDecimal expendAmount;
+
 }

+ 2 - 1
src/main/java/com/ydtech/modules/fnc/service/SettlementDocumentaryFeesService.java

@@ -8,6 +8,7 @@ import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
 import com.ydtech.modules.order.entity.BasePageResult;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 
@@ -21,7 +22,7 @@ public interface SettlementDocumentaryFeesService extends IService<SettlementDoc
 
     List<HashMap<String, Object>> getOtherSettldetail(HashMap<String,Object> params);
 
-    void batchByInvoice(String ids);
+    void batchByInvoice(String ids , String invoicingMethod, BigDecimal taxPoints ,BigDecimal invoicCommissionFeevalue);
 
     List<HashMap<String, Object>> getInvoicIds(HashMap<String, Object> params);
 

+ 44 - 7
src/main/java/com/ydtech/modules/fnc/service/impl/InsPlyIncomeServiceImpl.java

@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.sun.javafx.fxml.LoadListener;
 import com.ydtech.constants.enums.dict.agreement.ProductsType;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
@@ -44,6 +45,7 @@ import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
 import com.ydtech.modules.protocol.service.PtlAgreementService;
 import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
 import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
+import com.ydtech.utils.BigDecimalUtils;
 import com.ydtech.utils.SnowFlakeUtil;
 import com.ydtech.utils.excel.ExcelEasypoiUtils;
 import com.ydtech.utils.excel.ExcelStyleUtil;
@@ -1178,15 +1180,41 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
      * @param insPlyIncomeVo  ids   ins_ply_income  这个表的ids        incomeIds     settlement_documentary_fees  这个表的ids
      * @return
      */
-
+    /**
+     *    跟单费结算  有分批结算的情况
+     * @param insPlyIncomeVo
+     * @return
+     */
     @Override
     @Transactional
     public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
 //  通过ids 查出跟单非结算单
-        if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
-           settlementDocumentaryFeesService.batchByInvoice(insPlyIncomeVo.getIds());
-        }
-        return  HttpResult.ok();
+        BigDecimal allAmount = BigDecimal.ZERO;
+//            分批结算
+        SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
+
+        if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
+            allAmount =insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100))));
+            settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
+            settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());   //进账金额
+
+        } else {
+            settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());   //进账金额
+        }
+        settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId());   //开票号
+        settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime());   //结算时间
+        settlementDocumentaryFeesVo.setSettlementStatus("2");   //2为结算状态
+        settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());  // 保险公司id
+        settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());  //合作公司id
+        settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount()));  //未结算金额
+        settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
+        settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod());  //开票方式
+        settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints());  //税点
+        settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getExpendAmount()); //税点支出
+        settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
+        settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
+        settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
+        return HttpResult.ok();
     }
 
     /**
@@ -1382,7 +1410,7 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
             settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
         }
         settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
-        settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
+        settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());  //合作公司id
         settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue());  //其他费用金额
         settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
         settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
@@ -1390,7 +1418,16 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
         settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
         settlementDocumentaryFeesVo.setSettlementStatus("1");
         settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
-        settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId());  //开票号
+        if(StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())){
+            settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId());  //开票号
+        }
+        settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
+        settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
+        //  税点支出
+        if(BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) !=null   && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) !=null){
+            BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
+            settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
+        }
         return  settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
     }
 

+ 23 - 4
src/main/java/com/ydtech/modules/fnc/service/impl/SettlementDocumentaryFeesServiceImpl.java

@@ -118,11 +118,30 @@ public class SettlementDocumentaryFeesServiceImpl extends ServiceImpl<Settlement
         return baseMapper.getOtherSettldetail(params);
     }
 
+    /**
+     *
+     * @param ids  开票ids
+     * @param invoicingMethod  开票方式 0 保司开票  1 掌柜开票
+     * @param taxPoints  税点
+     */
     @Override
-    public void batchByInvoice(String ids) {
-        HashMap<String, Object> params = new HashMap<>();
-        params.put("ids",ids.split(","));
-        baseMapper.batchByInvoice(params);
+    public void batchByInvoice(String ids , String invoicingMethod, BigDecimal taxPoints ,BigDecimal invoicCommissionFeevalue) {
+        /**
+         * 跟单开票处新增开票方式:保司开票/掌柜开票
+         *
+         * 如果是保司开票,需要填写税点,后续在结算时,税收成本算做支出项,进账金额=开票金额*(1-税点),但统计应收金额
+         * ,开票金额,已收金额,开票未进账金额均按照不扣税点的金额核算。
+         *
+         * 如果是掌柜开票,需要填写税点,但后续结算时,进账金额=开票金额。
+         *
+         * */
+//        结算金额    收款金额=开票金额*(1-税点)
+
+
+            HashMap<String, Object> params = new HashMap<>();
+            params.put("ids",ids.split(","));
+
+            baseMapper.batchByInvoice(params);
     }
 
     @Override

+ 9 - 0
src/main/java/com/ydtech/modules/fnc/vo/InsPlyIncomeVo.java

@@ -267,4 +267,13 @@ public class InsPlyIncomeVo implements Serializable {
     @ApiModelProperty("选择ids")
     private List<String> selectIds;
 
+    @ApiModelProperty("开票方式")
+    private String invoicingMethod;
+
+    @ApiModelProperty("税点")
+    private BigDecimal taxPoints;
+
+    @ApiModelProperty("税点金额")
+    private BigDecimal expendAmount;
+
 }

+ 12 - 0
src/main/java/com/ydtech/modules/fnc/vo/SettlementDocumentaryFeesVo.java

@@ -85,4 +85,16 @@ public class SettlementDocumentaryFeesVo implements Serializable {
 
     @ApiModelProperty("合作公司id")
     private String partnerCompaniesId;
+
+    @ApiModelProperty("开票方式")
+    private String invoicingMethod;
+
+    @ApiModelProperty("税点")
+    private BigDecimal taxPoints;
+
+    @ApiModelProperty("税点金额")
+    private BigDecimal expendAmount;
+
+    @ApiModelProperty("结算时间")
+    private LocalDate settlementTime;
 }

+ 3 - 0
src/main/resources/mapper/modules/fnc/InsPlyIncomeMapper.xml

@@ -68,6 +68,7 @@
         <result column="partner_companies_name" property="partnerCompaniesName"/>
         <result column="receivable_amount" property="receivableAmount"/>
         <result column="insured_name" property="insuredName"/>
+        <result column="invoicing_method" property="invoicingMethod"/>
     </resultMap>
     <sql id="income_com">
                 a.id      as  "id",
@@ -133,6 +134,7 @@
                 a.invoic_time  as  "invoicTime",
                 a.insured_name  as  "insuredName",
                 a.user_id  as  "userId",
+                a.invoicing_method  as  "invoicingMethod",
                 a.create_time  as  "createTime"
     </sql>
 
@@ -800,6 +802,7 @@
         SELECT
         a.partner_companies_id AS "partnerCompaniesId",
         MAX( a.company_name ) AS "companyName",
+        MAX( a.company_id ) AS "companyId",
         MAX( a.partner_companies_name ) AS "partnerCompaniesName",
         IFNULL ( max(c.settleMentAmount),0.00) as  "allInvoicCommissionFeevalue",
         IFNULL(max(f.settleMentAmount) , 0.00)  as  "readyCommissionFeevalue",

+ 37 - 9
src/main/resources/mapper/modules/fnc/SettlementDocumentaryFeesMapper.xml

@@ -21,6 +21,9 @@
         <result column="invoice_id" property="invoiceId"/>
         <result column="is_not_car" property="isNotCar"/>
         <result column="partner_companies_id" property="partnerCompaniesId"/>
+        <result column="invoicing_method" property="invoicingMethod"/>
+        <result column="tax_points" property="taxPoints"/>
+        <result column="expend_amount" property="expendAmount"/>
     </resultMap>
 
 
@@ -37,17 +40,35 @@
             a.settlement_amount as "settlementAmount",
             a.agree_ment_id as "agreeMentId",
             a.partner_companies_id as "partnerCompaniesId",
+            a.invoicing_method as "invoicingMethod",
+            a.tax_points as "taxPoints",
+            a.expend_amount as "expendAmount",
             a.unsettled_amount as "unsettledAmount"
             from  settlement_documentary_fees  a
     </select>
 
     <select id="getOtherSettldetail" resultType="java.util.HashMap">
-        select
-        sum(a.settlement_amount) as "invoicCommissionFeevalue",
-        max(create_time) as "invoicTime",
-        max(invoice_id) as "invoicId",
-        GROUP_CONCAT(a.id) as "ids"
-        from settlement_documentary_fees a
+        SELECT
+        CASE
+        WHEN t.total_settlement_amount_1 = 0 THEN 0
+        ELSE t.total_settlement_amount_1 - t.total_settlement_amount_2
+        END AS "invoicCommissionFeevalue",
+        t.max_create_time AS "invoicTime",
+        t.max_invoice_id AS "invoicId",
+        t.max_tax_points AS "taxPoints",
+        t.max_invoicing_method AS "invoicingMethod",
+        t.ids AS "ids"
+        FROM (
+        SELECT
+        SUM(CASE WHEN a.settlement_status = '1' THEN a.settlement_amount ELSE 0 END) AS total_settlement_amount_1,
+        SUM(CASE WHEN a.settlement_status = '2' THEN a.settlement_amount ELSE 0 END) AS total_settlement_amount_2,
+        MAX(a.create_time) AS max_create_time,
+        MAX(a.invoice_id) AS max_invoice_id,
+        MAX(a.tax_points) AS max_tax_points,
+        MAX(a.invoicing_method) AS max_invoicing_method,
+        GROUP_CONCAT(a.id) AS ids
+        FROM
+        settlement_documentary_fees a
         <where>
             1=1
             <if test="settlementStatus !=null and  settlementStatus !=''">
@@ -67,15 +88,22 @@
                 </foreach>
             </if>
         </where>
-
-        GROUP BY a.invoice_id
+        GROUP BY
+        a.invoice_id
+        HAVING
+        SUM(CASE WHEN a.settlement_status = '1' THEN a.settlement_amount ELSE 0 END)  &lt;&gt; 0
+        AND SUM(CASE WHEN a.settlement_status = '1' THEN a.settlement_amount ELSE 0 END) &lt;&gt; SUM(CASE WHEN a.settlement_status = '2' THEN a.settlement_amount ELSE 0 END)
+        ) t;
     </select>
 
     <update id="batchByInvoice" parameterType="java.util.HashMap">
         update settlement_documentary_fees
         <set>
             settlement_status = '2',
-            settlement_time = NOW()
+            settlement_time = NOW(),
+            <if test="settlementAmount !=null and settlementAmount !=''">
+                settlement_amount =#{settlementAmount}
+            </if>
         </set>
         <where>
             <if test="ids !=null  and  ids!=''  and  ids.length>0">