SalesContractMapper.xml 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fjhx.jxst.mapper.sales.SalesContractMapper">
  4. <select id="getPage" resultType="com.fjhx.jxst.entity.sales.vo.SalesContractVo">
  5. select
  6. sc.id,
  7. sc.code,
  8. sc.customer_id,
  9. sc.delivery_date,
  10. sc.pay_method,
  11. sc.freight_payer,
  12. sc.remark,
  13. sc.create_user,
  14. sc.create_time,
  15. sc.update_user,
  16. sc.update_time,
  17. sc.contract_amount,
  18. sc.flow_id,
  19. sc.is_settled,
  20. ( SELECT IFNULL( SUM( cc.contract_money ), 0 ) FROM bytesailing_sale.claim_contract cc WHERE cc.contract_id = sc.id ) AS claimAmount
  21. from sales_contract sc
  22. ${ew.customSqlSegment}
  23. </select>
  24. <select id="getProfitClearingPage" resultType="com.fjhx.jxst.entity.statement.bo.SettlementBo">
  25. <include refid="getProfitClearing"/>
  26. </select>
  27. <select id="getProfitSettlementHead" resultType="com.fjhx.jxst.entity.statement.bo.SettlementBo">
  28. SELECT
  29. IFNULL( sum( contractClaimAmount ), 0 ) AS contractClaimAmount,
  30. IFNULL( sum( materialFee ), 0 ) AS materialFee,
  31. IFNULL( sum( afterSalesFee ), 0 ) AS afterSalesFee,
  32. IFNULL( sum( trailerFee ), 0 ) AS trailerFee,
  33. IFNULL( sum( inspectionRedPackFee ), 0 ) AS inspectionRedPackFee,
  34. IFNULL( sum( commissionFee ), 0 ) AS commissionFee,
  35. IFNULL( sum( otherFee ), 0 ) AS otherFee,
  36. IFNULL( sum( contractAmount ), 0 ) AS contractAmount
  37. FROM
  38. (
  39. <include refid="getProfitClearing"/>
  40. ) t1
  41. </select>
  42. <sql id="getProfitClearing">
  43. SELECT
  44. sc.id,
  45. sc.`code` AS salesContractCode,
  46. sc.customer_id,
  47. cu.`name` AS customerName,
  48. ( SELECT IFNULL( sum( cc.contract_money ), 0 ) FROM bytesailing_sale.claim_contract cc WHERE cc.contract_id = sc.id ) AS contractClaimAmount,
  49. sc.contract_amount AS contractAmount,
  50. (
  51. SELECT
  52. IFNULL(sum( IF ( sj.op_type = 2,( sjd.price * sjd.quantity ),-(sjd.price * sjd.quantity )) ),0)
  53. FROM
  54. bytesailing_wms.stock_journal_details sjd
  55. LEFT JOIN bytesailing_wms.stock_journal sj ON sjd.stock_journal_id = sj.id
  56. JOIN bytesailing_mes.work_order wo ON sj.work_order_id = wo.id
  57. JOIN sales_contract_details scd ON wo.contract_details_id = scd.id
  58. WHERE
  59. scd.sales_contract_id = sc.id
  60. ) AS materialFee,
  61. (
  62. SELECT
  63. IFNULL( sum( asr.amount ), 0 )
  64. FROM
  65. after_sales_record asr
  66. JOIN bytesailing_mes.production_task_detail ptd ON asr.product_sn = ptd.product_sn
  67. JOIN bytesailing_mes.production_task pt ON ptd.production_task_id = pt.id
  68. JOIN bytesailing_mes.production_plan pp ON pt.production_plan_id = pp.id
  69. JOIN bytesailing_mes.work_order wo ON pp.work_order_id = wo.id
  70. JOIN sales_contract_details scd ON wo.contract_details_id = scd.id
  71. WHERE
  72. scd.sales_contract_id = sc.id
  73. ) AS afterSalesFee,
  74. sc.trailer_fee AS trailerFee,
  75. sc.inspection_red_pack_fee AS inspectionRedPackFee,
  76. sc.commission_fee AS commissionFee,
  77. sc.other_fee AS otherFee,
  78. sc.is_settled
  79. FROM
  80. sales_contract sc
  81. LEFT JOIN bytesailing_customer.customer cu ON sc.customer_id = cu.id
  82. ${ew.customSqlSegment}
  83. </sql>
  84. </mapper>