找回密码
 立即注册
搜索
查看: 887|回复: 10

海典H2 医保对账导出 销售导出 入库导出

[复制链接]

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

发表于 2024-12-11 16:12:22 | 显示全部楼层 |阅读模式

---333入库信息
select   
a.billno 入库单号,
a.rowno  入库单内流水号,
a.wareid 商品自编码,
q.warename 商品名称,
q.insuranceno 商品国家医保编码,
q.fileno 批准文号,
q.warespec  规格,
f_get_classname('03',a.wareid,q.compid) 剂型,
q.barcode 本位码,
1 最小包装数量,
q.wareunit 最小包装单位,
q.wareunit 最小制剂单位,
'' 包装材质,
q.factoryname  生产厂家,
a.batid  生产批次号,
i.vencusno 供货商代码,
f_get_vencusname(i.compid,i.vencusno) 供货商名称,
to_char(a.execdate,'yyyy-mm-dd hh24:mi:ss') 经办时间,
f_get_username(a.createuser)   经办人,
a.purprice  成本价,
q.lastsaleprice 零售价,
CASE WHEN a.billcode IN ('DIS','DET') THEN
          a.inqty
         ELSE
          a.outqty
       end  数量,
f_get_classname('01',a.wareid,2) 商品属性
  FROM t_item_in_out_remain  a,
       t_ware      q,
       t_store_i      i
WHERE a.billcode IN ('DIS', 'DIR','DET','DER')
   AND a.wareid = q.wareid
   and  a.compid=q.compid
   AND a.wareid = i.wareid
   AND a.batid = i.batid
   AND a.compid = i.compid
   AND a.busno = '190'  and  nvl(q.insuranceno,'1')<>'1'
   AND to_char(a.execdate,'yyyy-mm-dd')>='2023-09-01'
   AND to_char(a.execdate,'yyyy-mm-dd')<='2024-11-30';


-------4444销售信息表

SELECT
a.saleno 销售单号,
a.rowno 销售单内流水号,
a.wareid 商品自编码,
q.warename 商品名称,
q.insuranceno  商品国家医保编码,
q.fileno  批准文号,
q.warespec  规格,
f_get_classname('03',a.wareid,b.compid) 剂型,
q.barcode 本位码,
1 最小包装数量,
q.wareunit 最小包装单位,
q.wareunit 最小制剂单位,
'' 包装材质,
q.factoryname 生产厂家,
a.batid 生产批次号,
i.vencusno  供货商代码,
  f_get_vencusname(i.compid,i.vencusno) 供货商名称,
to_char(b.finaltime,'yyyy-mm-dd hh24:mi:ss') 经办时间,
  f_get_username(a.saler)  经办人,
a.purprice  成本价,
a.netprice  零售价,
     a.netprice 实售价,
     round((a.wareqty + a.minqty / a.stdtomin) * a.times, 4)  数量,
'省医保' 结算方式,
ord.Name 客户姓名,
   ord.IdentityNo  客户医保卡号,
'' 类型,
case  when  round((a.wareqty + a.minqty / a.stdtomin) * a.times, 4)<0 then '退货'  else  '销售'  end  销售类型,
b.saleno  业务单据号,
f_get_classname('02',a.wareid,2) 医保类型
FROM t_sale_h b,t_sale_d a, ybcloud.med_ORDER ord
LEFT JOIN ybcloud.med_ORDER_REC_LIST ordl
on ord.ORDERNO = ordl.orderno  and ord.PaymentId=ordl.PaymentId,
    t_ware q, t_store_i i
WHERE  a.saleno=b.saleno
and a.wareid = q.wareid
and q.compid=b.compid
AND a.wareid = i.wareid
AND a.batid = i.batid
AND b.compid = i.compid
AND a.busno = '190'
and ord.OutSaleNo = a.saleno
AND to_char(a.accdate,'yyyy-mm-dd')>='2023-09-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-11-30';





-----555医保对账表
select  c.PsnName as 人员姓名,
        c.CERTNO  as  身份证,
        ord.OutSaleNo  as 系统流水号,
        c.psnno   as  人员信息编号,
        c.SETTELID  as   结算ID,
        c.MDTRTID  as  就医ID,
        to_char(ord.settletime,'yyyy-mm-dd hh24:mi:ss')    as  结算时间,
        'P62112311193'   as  医保机构编号,
        ord.AREACODE   as   区医保编号,
        case when c.clrtype=41   then  '药店购药'  
              when  c.clrtype=11   then  '普通门诊'  
              when  c.clrtype='99972'   then   '省内异地药店购药'
              when  c.clrtype='9903'   then   '跨省异地药店购药'
              when  c.clrtype='99970'   then   '省内异地门诊'
              when  c.clrtype='9901'   then   '跨省异地门诊'
        else  ''  end   as   清算类别,
        c.totalamount   as    总金额,
        c.CASHPAY  as   现金支付,
        c.HIFPPAY  as  统筹基金支付,
        c.ACCOUNTPAY  as  个人账户支付,
        c.HIFOBPAY  as   大病保险基金,
        c.FUNDPAY   as  基本医疗保险基金,
        c.MAFPAY     as   医疗救助基金,
        c.BALANCE    as    账户余额,
        case  when  ord.orderstatus=5  then '退费成功'
              when  ord.orderstatus=6  then '已退费'
         else  ''  end         退费标志,  
         '社保卡'    as  卡类别,
        case  when  c.insutype='390' then '职工医保'  else  '居民医保'  end  险种类型,
        m.label            人员类型      
from YBCloud.med_ORDER ord  
left  join YBCloud.MED_ORDER_REC_LIST c  on  ord.OrderNo=c.OrderNo
left join  YBCLOUD.CODE_DIC  m  on  m.TYPE ='PSN_TYPE' AND  m.VALUE =c.PSNTYPE
where  ord.OrderStatus in (2,3,5,6)
and ord.IsDeleted=0
and  to_char( ord.settletime,'yyyy-mm-dd')>='2023-09-01'  
and   to_char(ord.settletime,'yyyy-mm-dd')<='2024-11-30'   
and  ord.ORDERMEDICALNO='P6111100493'
order by ord.OrderNo;


251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2024-12-11 17:19:19 | 显示全部楼层
加盟店的导出 :
---333入库信息
select   
a.billno 入库单号,
a.rowno  入库单内流水号,
a.wareid 商品自编码,
q.warename 商品名称,
q.insuranceno 商品国家医保编码,
q.fileno 批准文号,
q.warespec  规格,
f_get_classname('03',a.wareid,q.compid) 剂型,
q.barcode 本位码,
1 最小包装数量,
q.wareunit 最小包装单位,
q.wareunit 最小制剂单位,
'' 包装材质,
q.factoryname  生产厂家,
a.batid  生产批次号,
i.vencusno 供货商代码,
f_get_vencusname(i.compid,i.vencusno) 供货商名称,
to_char(a.execdate,'yyyy-mm-dd hh24:mi:ss') 经办时间,
f_get_username(a.createuser)   经办人,
a.purprice  成本价,
q.lastsaleprice 零售价,
CASE WHEN a.billcode IN ('DIS','DET') THEN
          a.inqty
         ELSE
          a.outqty
       end  数量,
f_get_classname('01',a.wareid,2) 商品属性
  FROM t_item_in_out_remain  a,
       t_ware      q,
       t_store_i      i
WHERE a.billcode IN ('DIS', 'DIR','DET','DER','ADD','ADR')
   AND a.wareid = q.wareid
   and  a.compid=q.compid
   AND a.wareid = i.wareid
   AND a.batid = i.batid
   AND a.compid = i.compid
   AND a.busno = '325'  and  nvl(q.insuranceno,'1')<>'1'
   AND to_char(a.execdate,'yyyy-mm-dd')>='2024-01-01'
   AND to_char(a.execdate,'yyyy-mm-dd')<='2024-11-30';

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2024-12-11 18:25:19 | 显示全部楼层
----1111  期初库存
SELECT    max(i.ownerid)     保管账ID, a.compid 关联 , '默认货主' 保管账,
        a.wareid   AS  货品ID,
       max(w.warename)      AS 通用名,
       max(w.warename)      AS 商品名,
       max(w.warespec)      AS 规格,
       max(w.wareunit)      AS 基本单位,
       max(f.factoryname)   AS 生产厂商,
       max(t_area.areafullname)  AS 产地,
       max(w.fileno) 批准文号,
       max(wb.regno)  as 注册证号,
       max(i.buyer)         AS 采购员ID,f_get_username(max(i.buyer))  as 采购员,
       sum(a.wareqty)   as 库存数量,            
       sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
    sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
               busno AS busno,
               wareid AS wareid,
               stallno AS stallno,
               batid AS batid,
               SUM(wareqty) AS wareqty
          FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
                  FROM t_store_d
                 WHERE  compid = 2
                UNION ALL
                SELECT l.compid,
                       l.busno,
                       l.wareid,
                       l.stallno,
                       l.batid,
                       SUM(-l.inqty) AS wareqty
                  FROM t_store_inout_list l
                 WHERE  l.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
                 GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
         GROUP BY compid, busno, wareid, stallno, batid) a
  JOIN t_store_i i
    ON a.wareid = i.wareid
   AND a.batid = i.batid
  JOIN t_ware w
    ON a.compid = w.compid
   AND a.wareid = w.wareid
  JOIN t_ware_ext wb
    ON wb.wareid = a.wareid
  LEFT JOIN t_factory f
    ON f.factoryid = w.factoryid
  LEFT JOIN t_area
    ON t_area.areacode = i.areacode   
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
                             from t_adjust_purprice_d d1,
                                  t_adjust_purprice_h h1
                            where d1.adjustno = h1.adjustno
                              and  h1.compid = 2
                              and h1.status = 1
                              and (d1.adjustype = 2 or d1.adjustype = 3)
                              and  h1.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' )
                              and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and  h2.compid = 2
                    and h2.status = 1
                              and (d2.adjustype = 2 or d2.adjustype = 3)
                              and  h2.execdate > to_date( '202312312359','yyyy-mm-dd hh24:mi' )
                               and h2.compid = h1.compid and d2.wareid = d1.wareid
                               and d2.batid = d1.batid and h2.execdate < h1.execdate)         
                            order by execdate asc
                            ) ad
                            on
                               ad.compid = a.compid
                              and ad.wareid = a.wareid
                              and ad.batid = a.batid
WHERE  i.createtime <= to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2    and    nvl(w.insuranceno,'1')<>'1'
and   a.busno ='266'
group  by  a.compid,a.busno,a.wareid ;


-----2222期末库存

--2222期末库存
SELECT    max(i.ownerid)     保管账ID, a.compid 关联 , '默认货主' 保管账,
        a.wareid   AS  货品ID,
       max(w.warename)      AS 通用名,
       max(w.warename)      AS 商品名,
       max(w.warespec)      AS 规格,
       max(w.wareunit)      AS 基本单位,
       max(f.factoryname)   AS 生产厂商,
       max(t_area.areafullname)  AS 产地,
       max(w.fileno) 批准文号,
       max(wb.regno)  as 注册证号,
       max(i.buyer)         AS 采购员ID,f_get_username(max(i.buyer))  as 采购员,
       sum(a.wareqty)   as 库存数量,            
       sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
    sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
               busno AS busno,
               wareid AS wareid,
               stallno AS stallno,
               batid AS batid,
               SUM(wareqty) AS wareqty
          FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
                  FROM t_store_d
                 WHERE  compid = 2
                UNION ALL
                SELECT l.compid,
                       l.busno,
                       l.wareid,
                       l.stallno,
                       l.batid,
                       SUM(-l.inqty) AS wareqty
                  FROM t_store_inout_list l
                 WHERE  l.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
                 GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
         GROUP BY compid, busno, wareid, stallno, batid) a
  JOIN t_store_i i
    ON a.wareid = i.wareid
   AND a.batid = i.batid
  JOIN t_ware w
    ON a.compid = w.compid
   AND a.wareid = w.wareid
  JOIN t_ware_ext wb
    ON wb.wareid = a.wareid
  LEFT JOIN t_factory f
    ON f.factoryid = w.factoryid
  LEFT JOIN t_area
    ON t_area.areacode = i.areacode   
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
                             from t_adjust_purprice_d d1,
                                  t_adjust_purprice_h h1
                            where d1.adjustno = h1.adjustno
                              and  h1.compid = 2
                              and h1.status = 1
                              and (d1.adjustype = 2 or d1.adjustype = 3)
                              and  h1.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
                              and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and  h2.compid = 2
                    and h2.status = 1
                              and (d2.adjustype = 2 or d2.adjustype = 3)
                              and  h2.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
                               and h2.compid = h1.compid and d2.wareid = d1.wareid
                               and d2.batid = d1.batid and h2.execdate < h1.execdate)         
                            order by execdate asc
                            ) ad
                            on
                               ad.compid = a.compid
                              and ad.wareid = a.wareid
                              and ad.batid = a.batid
WHERE  i.createtime <= to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
and   a.busno ='266'
group  by  a.compid,a.busno,a.wareid ;

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2024-12-11 18:40:36 | 显示全部楼层
----1111  期初库存
SELECT    max(i.ownerid)     保管账ID, a.compid 关联 , '默认货主' 保管账,
        a.wareid   AS  货品ID,
       max(w.warename)      AS 通用名,
       max(w.warename)      AS 商品名,
       max(w.warespec)      AS 规格,
       max(w.wareunit)      AS 基本单位,
       max(f.factoryname)   AS 生产厂商,
       max(t_area.areafullname)  AS 产地,
       max(w.fileno) 批准文号,
       max(wb.regno)  as 注册证号,
       max(i.buyer)         AS 采购员ID,f_get_username(max(i.buyer))  as 采购员,
       sum(a.wareqty)   as 库存数量,            
       sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
    sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
               busno AS busno,
               wareid AS wareid,
               stallno AS stallno,
               batid AS batid,
               SUM(wareqty) AS wareqty
          FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
                  FROM t_store_d
                 WHERE  compid = 2
                UNION ALL
                SELECT l.compid,
                       l.busno,
                       l.wareid,
                       l.stallno,
                       l.batid,
                       SUM(-l.inqty) AS wareqty
                  FROM t_store_inout_list l
                 WHERE  l.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
                 GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
         GROUP BY compid, busno, wareid, stallno, batid) a
  JOIN t_store_i i
    ON a.wareid = i.wareid
   AND a.batid = i.batid
  JOIN t_ware w
    ON a.compid = w.compid
   AND a.wareid = w.wareid
  JOIN t_ware_ext wb
    ON wb.wareid = a.wareid
  LEFT JOIN t_factory f
    ON f.factoryid = w.factoryid
  LEFT JOIN t_area
    ON t_area.areacode = i.areacode   
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
                             from t_adjust_purprice_d d1,
                                  t_adjust_purprice_h h1
                            where d1.adjustno = h1.adjustno
                              and  h1.compid = 2
                              and h1.status = 1
                              and (d1.adjustype = 2 or d1.adjustype = 3)
                              and  h1.execdate > to_date( '202309012359','yyyy-mm-dd hh24:mi' )
                              and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and  h2.compid = 2
                    and h2.status = 1
                              and (d2.adjustype = 2 or d2.adjustype = 3)
                              and  h2.execdate > to_date( '202312312359','yyyy-mm-dd hh24:mi' )
                               and h2.compid = h1.compid and d2.wareid = d1.wareid
                               and d2.batid = d1.batid and h2.execdate < h1.execdate)         
                            order by execdate asc
                            ) ad
                            on
                               ad.compid = a.compid
                              and ad.wareid = a.wareid
                              and ad.batid = a.batid
WHERE  i.createtime <= to_date( '202309012359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2    and    nvl(w.insuranceno,'1')<>'1'
and   a.busno ='160'
group  by  a.compid,a.busno,a.wareid ;


251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2024-12-11 18:40:50 | 显示全部楼层
-----2222期末库存

--2222期末库存
SELECT    max(i.ownerid)     保管账ID, a.compid 关联 , '默认货主' 保管账,
        a.wareid   AS  货品ID,
       max(w.warename)      AS 通用名,
       max(w.warename)      AS 商品名,
       max(w.warespec)      AS 规格,
       max(w.wareunit)      AS 基本单位,
       max(f.factoryname)   AS 生产厂商,
       max(t_area.areafullname)  AS 产地,
       max(w.fileno) 批准文号,
       max(wb.regno)  as 注册证号,
       max(i.buyer)         AS 采购员ID,f_get_username(max(i.buyer))  as 采购员,
       sum(a.wareqty)   as 库存数量,            
       sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) as 批次金额,
    sum(round(a.wareqty * (nvl(ad.purpriceo,i.purprice)/(1+i.PURTAX/100)),2)) 批次无税金额
FROM (SELECT compid AS compid,
               busno AS busno,
               wareid AS wareid,
               stallno AS stallno,
               batid AS batid,
               SUM(wareqty) AS wareqty
          FROM (SELECT compid, busno, wareid, stallno, batid, wareqty
                  FROM t_store_d
                 WHERE  compid = 2
                UNION ALL
                SELECT l.compid,
                       l.busno,
                       l.wareid,
                       l.stallno,
                       l.batid,
                       SUM(-l.inqty) AS wareqty
                  FROM t_store_inout_list l
                 WHERE  l.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and l.compid = 2
                 GROUP BY l.compid, l.busno, l.wareid, l.batid, l.stallno)
         GROUP BY compid, busno, wareid, stallno, batid) a
  JOIN t_store_i i
    ON a.wareid = i.wareid
   AND a.batid = i.batid
  JOIN t_ware w
    ON a.compid = w.compid
   AND a.wareid = w.wareid
  JOIN t_ware_ext wb
    ON wb.wareid = a.wareid
  LEFT JOIN t_factory f
    ON f.factoryid = w.factoryid
  LEFT JOIN t_area
    ON t_area.areacode = i.areacode   
left join (select h1.compid,d1.wareid,d1.batid,d1.purpriceo,h1.execdate
                             from t_adjust_purprice_d d1,
                                  t_adjust_purprice_h h1
                            where d1.adjustno = h1.adjustno
                              and  h1.compid = 2
                              and h1.status = 1
                              and (d1.adjustype = 2 or d1.adjustype = 3)
                              and  h1.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
                              and not exists(
select 1 from t_adjust_purprice_d d2,t_adjust_purprice_h h2
where d2.adjustno = h2.adjustno and  h2.compid = 2
                    and h2.status = 1
                              and (d2.adjustype = 2 or d2.adjustype = 3)
                              and  h2.execdate > to_date( '202411302359','yyyy-mm-dd hh24:mi' )
                               and h2.compid = h1.compid and d2.wareid = d1.wareid
                               and d2.batid = d1.batid and h2.execdate < h1.execdate)         
                            order by execdate asc
                            ) ad
                            on
                               ad.compid = a.compid
                              and ad.wareid = a.wareid
                              and ad.batid = a.batid
WHERE  i.createtime <= to_date( '202411302359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
and   a.busno ='160'
group  by  a.compid,a.busno,a.wareid ;

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2024-12-11 19:19:16 | 显示全部楼层
加盟店的  入库 导出  

---333入库信息
select   
a.billno 入库单号,
a.rowno  入库单内流水号,
a.wareid 商品自编码,
q.warename 商品名称,
q.insuranceno 商品国家医保编码,
q.fileno 批准文号,
q.warespec  规格,
f_get_classname('03',a.wareid,q.compid) 剂型,
q.barcode 本位码,
1 最小包装数量,
q.wareunit 最小包装单位,
q.wareunit 最小制剂单位,
'' 包装材质,
q.factoryname  生产厂家,
a.batid  生产批次号,
i.vencusno 供货商代码,
f_get_vencusname(i.compid,i.vencusno) 供货商名称,
to_char(a.execdate,'yyyy-mm-dd hh24:mi:ss') 经办时间,
f_get_username(a.createuser)   经办人,
a.purprice  成本价,
q.lastsaleprice 零售价,
CASE WHEN a.billcode IN ('DIS','DET','ADD') THEN
          a.inqty
         ELSE
          a.outqty
       end  数量,
f_get_classname('01',a.wareid,2) 商品属性
  FROM t_item_in_out_remain  a,
       t_ware      q,
       t_store_i      i
WHERE a.billcode IN ('DIS', 'DIR','DET','DER','ADD','ADR')
   AND a.wareid = q.wareid
   and  a.compid=q.compid
   AND a.wareid = i.wareid
   AND a.batid = i.batid
   AND a.compid = i.compid
   AND a.busno = '325'  and  nvl(q.insuranceno,'1')<>'1'
   AND to_char(a.execdate,'yyyy-mm-dd')>='2023-09-01'
   AND to_char(a.execdate,'yyyy-mm-dd')<='2024-11-30';

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2025-2-26 17:31:49 | 显示全部楼层
-----进销存  
select   'P62110200017'  as    医保机构编号,
         '定西众济堂医药连锁有限责任公司自由街店'    as   门店名称,
          w.warecode   as  货号,
          max(w.warename)   as  商品名及通用名,
          max(w.warespec)   as  商品规格,
          max(w.wareunit)  as   单位,
          max(w.INSURANCENO)   as   药品国家医保编码,
          nvl(max(qc.qckc),0)    as  期初库存,
          sum(r.inqty)   as   入库数量,
          sum(r.outqty)  as   出库数量,
          nvl(max(qm.qmkc),0)   as   期末库存
from  t_item_in_out_remain   r
   left  join  t_ware   w  on    r.wareid=w.wareid   and  r.compid=w.compid
   left  join  (select  wareid,sum(wareqty) as qckc  from  t_store_d_bak
                where  busno=101  and   period='202312'
                group  by   wareid)  qc
           on   r.wareid=qc.wareid  
   left  join  (select  wareid,sum(wareqty) as qmkc from  t_store_d_bak
                where  busno=101  and   period='202412'
                group  by   wareid)  qm
           on   r.wareid=qm.wareid            
where   r.busno='101'   and   w.isinsurance=1  and  
to_char( r.execdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char(r.execdate,'yyyy-mm-dd')<='2024-09-30'
and  r.compid=2
and  r.billcode  not  in  ('MDACC')
group  by   w.warecode;

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2025-2-26 17:32:05 | 显示全部楼层
----销售明细表2024
select distinct  a.INSTITUTIONCODE  as   门店编号,
         a.INSTITUTIONNAME  as  门店名称,
         a.erpsaleno   as    零售流水号,
         h.accdate   as  开单日期,
         h.finaltime   as   开单时间,
         f_get_username(d.saler)  as   营业员,
         f_get_username(h.payee)  as   收银员,
         b.warecode   as  货号,
         b.CENTERITEMCODE   as   药品国家医保编码,
         b.warename   as    商品名及通用名,
         b.specs   as    规格,
         b.MANUFACTURER   as   生产单位,
         b.CHARGEUNIT   as  单位,
         d.wareqty   as    数量,
         round(d.wareqty*d.netprice,2)   as   金额,
         d.makeno   as   批号,
         d.invalidate  as    效期,
         i.makedate   as    生产日期,
         d.netprice   as  零售价,
         f_get_classname('03',d.wareid,h.compid)   as  剂型
from   t_yby_order_h  a  
     left  join   t_yby_order_d  b  on   a.orderno=b.orderno
     left  join   t_sale_h   h  on   a.erpsaleno=h.saleno    and  h.compid=2
     left  join   t_ware  t  on   b.warecode=t.warecode   and  t.compid=2
     left  join   t_sale_d  d  on  h.saleno=d.saleno  and a.erpsaleno=d.saleno   
     and  t.wareid=d.wareid
     left  join  t_store_i  i  on   d.wareid=i.wareid   and  d.batid=i.batid   
                                   and   h.compid=i.compid
where   a.INSTITUTIONCODE='P62110200017'     and
to_char( h.accdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char( h.accdate,'yyyy-mm-dd')<='2024-09-30'
order  by   h.accdate,a.erpsaleno;

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2025-2-26 17:32:21 | 显示全部楼层
----销售明细表2024
select distinct  a.INSTITUTIONCODE  as   门店编号,
         a.INSTITUTIONNAME  as  门店名称,
         a.erpsaleno   as    零售流水号,
         h.accdate   as  开单日期,
         h.finaltime   as   开单时间,
         f_get_username(d.saler)  as   营业员,
         f_get_username(h.payee)  as   收银员,
         b.warecode   as  货号,
         b.CENTERITEMCODE   as   药品国家医保编码,
         b.warename   as    商品名及通用名,
         b.specs   as    规格,
         b.MANUFACTURER   as   生产单位,
         b.CHARGEUNIT   as  单位,
         d.wareqty   as    数量,
         round(d.wareqty*d.netprice,2)   as   金额,
         d.makeno   as   批号,
         d.invalidate  as    效期,
         i.makedate   as    生产日期,
         d.netprice   as  零售价,
         f_get_classname('03',d.wareid,h.compid)   as  剂型
from   t_yby_order_h  a  
     left  join   t_yby_order_d  b  on   a.orderno=b.orderno
     left  join   t_sale_h   h  on   a.erpsaleno=h.saleno    and  h.compid=2
     left  join   t_ware  t  on   b.warecode=t.warecode   and  t.compid=2
     left  join   t_sale_d  d  on  h.saleno=d.saleno  and a.erpsaleno=d.saleno   
     and  t.wareid=d.wareid
     left  join  t_store_i  i  on   d.wareid=i.wareid   and  d.batid=i.batid   
                                   and   h.compid=i.compid
where   a.INSTITUTIONCODE='P62110200029'     and
to_char( h.accdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char( h.accdate,'yyyy-mm-dd')<='2024-09-30'
order  by   h.accdate,a.erpsaleno;

-----进销存  
select   'P62110200029'  as    医保机构编号,
         '定西众济堂医药连锁有限责任公司解放桥店'    as   门店名称,
          w.warecode   as  货号,
          max(w.warename)   as  商品名及通用名,
          max(w.warespec)   as  商品规格,
          max(w.wareunit)  as   单位,
          max(w.INSURANCENO)   as   药品国家医保编码,
          nvl(max(qc.qckc),0)    as  期初库存,
          sum(r.inqty)   as   入库数量,
          sum(r.outqty)  as   出库数量,
          nvl(max(qm.qmkc),0)   as   期末库存
from  t_item_in_out_remain   r
   left  join  t_ware   w  on    r.wareid=w.wareid   and  r.compid=w.compid
   left  join  (select  wareid,sum(wareqty) as qckc  from  t_store_d_bak
                where  busno=104  and   period='202312'
                group  by   wareid)  qc
           on   r.wareid=qc.wareid  
   left  join  (select  wareid,sum(wareqty) as qmkc from  t_store_d_bak
                where  busno=104  and   period='202412'
                group  by   wareid)  qm
           on   r.wareid=qm.wareid            
where   r.busno='104'   and   w.isinsurance=1  and  
to_char( r.execdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char(r.execdate,'yyyy-mm-dd')<='2024-09-30'
and  r.compid=2
and  r.billcode  not  in  ('MDACC')
group  by   w.warecode;

-----医保对账表
select  c.PsnName as 人员姓名,
        c.CERTNO  as  身份证,
        ord.OutSaleNo  as 系统流水号,
        c.psnno   as  人员信息编号,
        c.SETTELID  as   结算ID,
        c.MDTRTID  as  就医ID,
        ord.settletime   as  结算时间,
        'P62110200029'   as  医保机构编号,
        ord.AREACODE   as   区医保编号,
        case when c.clrtype=41   then  '药店购药'  
              when  c.clrtype=11   then  '普通门诊'  
              when  c.clrtype='99972'   then   '省内异地药店购药'
              when  c.clrtype='9903'   then   '跨省异地药店购药'
              when  c.clrtype='99970'   then   '省内异地门诊'
              when  c.clrtype='9901'   then   '跨省异地门诊'
        else  ''  end   as   清算类别,
        c.totalamount   as    总金额,
        c.CASHPAY  as   现金支付,
        c.HIFPPAY  as  统筹基金支付,
        c.ACCOUNTPAY  as  个人账户支付,
        c.HIFOBPAY  as   大病保险基金,
        c.FUNDPAY   as  基本医疗保险基金,
        c.MAFPAY     as   医疗救助基金,
        c.BALANCE    as    账户余额,
        case  when  ord.orderstatus=5  then '退费成功'
              when  ord.orderstatus=6  then '已退费'
         else  ''  end         退费标志,  
         '社保卡'    as  卡类别,
        case  when  c.insutype='390' then '职工医保'  else  '居民医保'  end  险种类型,
        m.label            人员类型      
from YBCloud.med_ORDER ord  
left  join YBCloud.MED_ORDER_REC_LIST c  on  ord.OrderNo=c.OrderNo
left join  YBCLOUD.CODE_DIC  m  on  m.TYPE ='PSN_TYPE' AND  m.VALUE =c.PSNTYPE
where  ord.OrderStatus in (2,3,5,6)
and ord.IsDeleted=0
and  to_char( ord.settletime,'yyyy-mm-dd')>='2024-01-01'  
and   to_char(ord.settletime,'yyyy-mm-dd')<='2024-09-30'   
and  ord.ORDERMEDICALNO='P62110200029'
order by ord.OrderNo;

251

主题

134

回帖

1404

积分

版主

积分
1404

活跃会员宣传达人突出贡献优秀版主

 楼主| 发表于 2025-2-26 17:32:37 | 显示全部楼层
-----进销存  
select   'P62110200017'  as    医保机构编号,
         '定西众济堂医药连锁有限责任公司自由街店'    as   门店名称,
          w.warecode   as  货号,
          max(w.warename)   as  商品名及通用名,
          max(w.warespec)   as  商品规格,
          max(w.wareunit)  as   单位,
          max(w.INSURANCENO)   as   药品国家医保编码,
          nvl(max(qc.qckc),0)    as  期初库存,
          sum(r.inqty)   as   入库数量,
          sum(r.outqty)  as   出库数量,
          nvl(max(qm.qmkc),0)   as   期末库存
from  t_item_in_out_remain   r
   left  join  t_ware   w  on    r.wareid=w.wareid   and  r.compid=w.compid
   left  join  (select  wareid,sum(wareqty) as qckc  from  t_store_d_bak
                where  busno=101  and   period='202312'
                group  by   wareid)  qc
           on   r.wareid=qc.wareid  
   left  join  (select  wareid,sum(wareqty) as qmkc from  t_store_d_bak
                where  busno=101  and   period='202412'
                group  by   wareid)  qm
           on   r.wareid=qm.wareid            
where   r.busno='101'   and   w.isinsurance=1  and  
to_char( r.execdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char(r.execdate,'yyyy-mm-dd')<='2024-09-30'
and  r.compid=2
and  r.billcode  not  in  ('MDACC')
group  by   w.warecode;


-----进销存  
select   'P62110200019'  as    医保机构编号,
         '定西众济堂医药连锁有限责任公司锦屏路店'    as   门店名称,
          w.warecode   as  货号,
          max(w.warename)   as  商品名及通用名,
          max(w.warespec)   as  商品规格,
          max(w.wareunit)  as   单位,
          max(w.INSURANCENO)   as   药品国家医保编码,
          nvl(max(qc.qckc),0)    as  期初库存,
          sum(r.inqty)   as   入库数量,
          sum(r.outqty)  as   出库数量,
          nvl(max(qm.qmkc),0)   as   期末库存
from  t_item_in_out_remain   r
   left  join  t_ware   w  on    r.wareid=w.wareid   and  r.compid=w.compid
   left  join  (select  wareid,sum(wareqty) as qckc  from  t_store_d_bak
                where  busno=103  and   period='202312'
                group  by   wareid)  qc
           on   r.wareid=qc.wareid  
   left  join  (select  wareid,sum(wareqty) as qmkc from  t_store_d_bak
                where  busno=103  and   period='202412'
                group  by   wareid)  qm
           on   r.wareid=qm.wareid            
where   r.busno='103'   and   w.isinsurance=1  and  
to_char( r.execdate,'yyyy-mm-dd')>='2024-01-01'  
and   to_char(r.execdate,'yyyy-mm-dd')<='2024-09-30'
and  r.compid=2
and  r.billcode  not  in  ('MDACC')
group  by   w.warecode;


-----进销存  
select   'P62110200019'  as    医保机构编号,
         '定西众济堂医药连锁有限责任公司锦屏路'    as   门店名称,
          w.warecode   as  货号,
          max(w.warename)   as  商品名及通用名,
          max(w.warespec)   as  商品规格,
          max(w.wareunit)  as   单位,
          max(w.INSURANCENO)   as   药品国家医保编码,
          nvl(max(qc.qckc),0)    as  期初库存,
          sum(r.inqty)   as   入库数量,
          sum(r.outqty)  as   出库数量,
          nvl(max(qm.qmkc),0)   as   期末库存
from  t_item_in_out_remain   r
   left  join  t_ware   w  on    r.wareid=w.wareid   and  r.compid=w.compid
   left  join  (select  wareid,sum(wareqty) as qckc  from  t_store_d_bak
                where  busno=103  and   period='202212'
                group  by   wareid)  qc
           on   r.wareid=qc.wareid  
   left  join  (select  wareid,sum(wareqty) as qmkc from  t_store_d_bak
                where  busno=103  and   period='202312'
                group  by   wareid)  qm
           on   r.wareid=qm.wareid            
where   r.busno='103'   and   w.isinsurance=1  and  
to_char( r.execdate,'yyyy-mm-dd')>='2023-01-01'  
and   to_char(r.execdate,'yyyy-mm-dd')<='2023-12-31'
and  r.compid=2
and  r.billcode  not  in  ('MDACC')
group  by   w.warecode
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表