zoukankan      html  css  js  c++  java
  • hcjk_SQL 退费干掉,组套全展开,但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
  • 相关阅读:
    物理机连接虚拟机中的sqlserver
    Vue.js
    拆分时间段
    System.Threading.Timer
    浏览器被恶心页面占用
    sqlserver超时时间已到
    几年没写CSS
    C#生成高清缩略图
    抽奖概率算法
    html 页面实现指定位置的跳转
  • 原文地址:https://www.cnblogs.com/guchunchao/p/11807055.html
Copyright © 2011-2022 走看看