首页 > 数据库技术 > 详细

hcjk_SQL 退费干掉,组套全展开,但0元被删掉了,退费的打印待沟通

时间:2019-11-06 19:30:01      阅读:83      评论:0      收藏:0      [点我收藏+]

 

 

1.invoice

 select * from  
  (
  select
    t.itemName,
    t.patient_name,
    t.price,
    t.fatherItemClass,
    t.fatherItemClassName,
    t.createBy,
    t.createTime,
    sum(t.quantity)  as quantity,
sum(t.totalMoney) AS totalMoney

  --     select *
  from(
          -- 退费
          select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                b.mealFlag,
                TRUNCATE(b.preFee - b.discountFee - b.promotionBenefitFee - b.couponFee - b.itemBenefitFee - b.memberCardBenefitFee - b.itemComInvBenefitFee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id

            where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != VS00000000  AND a.returnId="${id}"
            and b.mealFlag = 0
            union
            -- 正向支付
            select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                b.mealFlag,
                TRUNCATE(b.preFee - b.discountFee - b.promotionBenefitFee - b.couponFee - b.itemBenefitFee - b.memberCardBenefitFee - b.itemComInvBenefitFee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
               where a.isDelete= 0 and a.returnFlag = 0   AND a.id="${id}"
                and b.mealFlag = 0
  ) t
  group by
    t.itemName,
    t.patient_name,
    t.fatherItemClass,
    t.fatherItemClassName
  having (totalMoney > 0 and quantity > 0)
  
  
  
  union
  
  
  
  
  select
    t.itemName,
    t.patient_name,
    t.price,
    t.fatherItemClass,
    t.fatherItemClassName,
    t.createBy,
    t.createTime,
    sum(t.quantity)  as quantity,
    0 AS totalMoney
  --     select *
  from(
          -- 退费
          select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                TRUNCATE(b.preFee - b.discountFee - b.promotionBenefitFee - b.couponFee - b.itemBenefitFee - b.memberCardBenefitFee - b.itemComInvBenefitFee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id

            where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != VS00000000  AND a.returnId="${id}"
            and b.mealFlag = 0
            union
            -- 正向支付
            select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                TRUNCATE(b.preFee - b.discountFee - b.promotionBenefitFee - b.couponFee - b.itemBenefitFee - b.memberCardBenefitFee - b.itemComInvBenefitFee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
               where a.isDelete= 0 and a.returnFlag = 0   AND a.id="${id}"
                and b.mealFlag = 1
  ) t
  group by
    t.itemName,
    t.patient_name,
    t.fatherItemClass,
    t.fatherItemClassName
  
 ) tt
limit 10 offset ${startIndex}

 

 

 

payLog

select * from `thc_rcm`.`pay_trade_log`
where settlement_id = ${id}
union
select distinct d.*
FROM  `thc_rcm`.`Cs_Settlement` a
JOIN `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.settlementID
JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
JOIN `thc_rcm`.`pay_trade_log` d
 where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != VS00000000 and d.settlement_id = a.returnId
AND a.returnId="${id}"

 

 

 

 

sub_01

select
    sum(totalMoney) as totalMoney,
    sum(quantity) as quantity,
    fatherItemClass,
    fatherItemClassName,
    CASE fatherItemClass                                                 -- 初复诊
        WHEN 8 THEN 1         -- 西药费
        WHEN 9 THEN 2         -- 中成药费
        WHEN 36 THEN 3        -- 材料费
        WHEN 43 THEN 4        -- 其它费
    END AS itemClassOrder
from (

    select * from (
         select
    t.itemName,
    t.patient_name,
    t.price,
    t.fatherItemClass,
    t.fatherItemClassName,
    t.createBy,
    t.createTime,
    sum(t.quantity)  as quantity,
sum(t.totalMoney) AS totalMoney

  --     select *
  from(
          -- 退费
          select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                b.mealFlag,
                TRUNCATE(b.fee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id

            where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != VS00000000  AND a.returnId="${id}"
            and b.mealFlag = 0
            union
            -- 正向支付
            select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                b.mealFlag,
                TRUNCATE(b.fee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
               where a.isDelete= 0 and a.returnFlag = 0   AND a.id="${id}"
                and b.mealFlag = 0
  ) t
  group by
    t.itemName,
    t.patient_name,
    t.fatherItemClass,
    t.fatherItemClassName
  having (totalMoney > 0 and quantity > 0)
  
  
  
  union
  
  
  
  
  select
    t.itemName,
    t.patient_name,
    t.price,
    t.fatherItemClass,
    t.fatherItemClassName,
    t.createBy,
    t.createTime,
    sum(t.quantity)  as quantity,
    0 AS totalMoney
  --     select *
  from(
          -- 退费
          select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                TRUNCATE(b.fee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id

            where a.isDelete = 0 and a.returnFlag = 1 and b.itemID != VS00000000  AND a.returnId="${id}"
            and b.mealFlag = 0
            union
            -- 正向支付
            select
                b.itemID,
                b.itemName,
                d.`name` AS patient_name,
                c.fatherItemClass,
                c.fatherItemClassName,
                k.docname as createBy,
                DATE_FORMAT(a.createtime,%Y-%m-%d) as createtime,
                round(b.quantity) as quantity,
                round(b.price,2) as price,
                TRUNCATE(b.fee,2) AS totalMoney,
                c.AccountBillId,
                b.settlementID
            FROM  Cs_Settlement a
            JOIN Cs_SettlementDetail b on a.id = b.settlementID
            JOIN `thc_rcm`.`Cs_AccountBillDetail` c ON b.accountBillDetailID = c.id
            JOIN (
                SELECT u.clinic_id AS clinicid, u.id AS docid,u.name AS docname
                FROM thc_warehouse.staff_record u
                LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = SXX000083 AND u.id = u1.staff_record_id
            ) k     ON a.createBy = k.docid
            JOIN `thc_c_union`.`patient` d ON a.patientID = d.id
               where a.isDelete= 0 and a.returnFlag = 0   AND a.id="${id}"
                and b.mealFlag = 1
  ) t
  group by
    t.itemName,
    t.patient_name,
    t.fatherItemClass,
    t.fatherItemClassName

    ) kk
    limit 10 offset ${startIndex}
) tt
where tt.fatherItemClass in (43,36,8,9)
group by fatherItemClass,fatherItemClassName
order by itemClassOrder asc

 

 

 

 

 

 

 

 

 

 

hcjk_SQL 退费干掉,组套全展开,但0元被删掉了,退费的打印待沟通

原文:https://www.cnblogs.com/guchunchao/p/11807055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!