找回密码
 立即注册
搜索
查看: 358|回复: 6

海典H2 导出数据(入库明细、配送明细、退仓明细)

[复制链接]

255

主题

144

回帖

1461

积分

版主

积分
1461

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

发表于 2025-5-24 14:25:05 | 显示全部楼层 |阅读模式
本帖最后由 wbv123 于 2025-5-27 09:32 编辑


海典H1


---111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') as 有效期至,
tvb.vencusname as  供应商
from  t_accept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_accept_d b left join t_ware w on  b.wareid = w.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';

  ----222表二:门店退库入库表_公司总库
select
f_get_busnoname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.srcbusno 退库门店编号,
f_get_busnoname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MEDICALNO    退库门店定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.srcbusno=g.busno  ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



----333333表三:派送出库表_公司总库
select
f_get_busnoname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.objbusno  派送门店编号,
f_get_busnoname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MEDICALNO  定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---444表四:退货出库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 退库时间,
b.returnqty 退库数量,
b.purprice 退库单价,
b.returnqty*b.purprice   退库金额,
tvb.vencusname as  供应商
from  t_reaccept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_reaccept_d b left join t_ware w on  b.wareid = w.wareid
where a.reacceptno=b.reacceptno  and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



---5555表五:入库表_门店药库
select  
f_get_busnoname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
f_get_busnoname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd')派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
CASE WHEN w.scan_flag = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno ,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';




----88 表八:期末库存表_公司总库_2024年末
select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(w.warename)   商品名称,
max(i.makeno )批号,
CASE WHEN max(w.scan_flag) = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
sum(a.wareqty) 数量,
max(nvl(ad.purpriceo,i.purprice))单价,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) 金额,
max(w.warespec) 规格,
max(to_char(i.invalidate, 'yyyy-mm-dd'))  有效期至,
max(tvb.vencusname) as  供应商
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( '202412312359','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
  left join t_vencus_base tvb on tvb.vencusno = i.vencusno
  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( '202412312359','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( '202412312359','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( '202412312359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
group  by  a.compid,a.busno,a.wareid ;








255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-26 09:30:41 | 显示全部楼层
本帖最后由 wbv123 于 2025-5-26 09:32 编辑

CASE WHEN e.isinsurance = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,      集采品种全部改成  否




---111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
dbo.f_get_orgname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
b.invalidate as 有效期至,
tvb.vendorname as  供应商
from  u_accept_m a
left join u_vendor tvb on tvb.vendorno = a.vendorno
, u_accept_c b left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'

  ----222表二:门店退库入库表_公司总库
select
dbo.f_get_orgname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
b.invalidate 有效期至,
a.srcbusno 退库门店编号,
dbo.f_get_orgname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MedicalNo    退库门店定点机构编号
from u_dist_m  a
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.srcbusno=g.busno
,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'



----333333表三:派送出库表_公司总库
select
dbo.f_get_orgname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
b.invalidate 有效期至,
a.objbusno  派送门店编号,
dbo.f_get_orgname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MedicalNo  定点机构编号
from u_dist_m  a LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.objbusno=g.busno ,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'


---444表四:退货出库表_公司总库
select
dbo.f_get_orgname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 退库时间,
b.wareqty 退库数量,
b.purprice 退库单价,
b.wareqty*b.purprice   退库金额,
tvb.vendorname as  供应商
from  u_accept_m a
left join u_vendor tvb on tvb.vendorno = a.vendorno
, u_accept_c b left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.acceptno=b.acceptno  and a.status=1 and  a.billcode='REJ'
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31';



---5555表五:入库表_门店药库
select  
dbo.f_get_orgname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
dbo.f_get_orgname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
b.invalidate 有效期至
from u_dist_m  a LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.objbusno=g.busno,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
dbo.f_get_orgname(a.busno)  门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
a.accdate  销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
c.invalidate 有效期至
from u_sale_m a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.busno=g.busno,u_sale_c c,u_ware_q w,u_ware_ext   e
where    a.saleno=c.saleno and c.wareid=w.wareid  and c.wareid=e.wareid  
and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND a.accdate >='2021-01-01'
AND a.accdate <='2024-12-31'


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
dbo.f_get_orgname(a.busno)  门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
a.accdate  退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
c.invalidate 有效期至
from u_sale_m a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.busno=g.busno ,u_sale_c c,u_ware_q w,u_ware_ext  e
where    a.saleno=c.saleno and c.wareid=w.wareid and c.wareid=e.wareid
and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND a.accdate >='2021-01-01'
AND a.accdate <='2024-12-31'


----777 表七:期初库存表_公司总库_2021年期初
--库存
if object_id('tempdb..#store_his') is not null drop table #store_his                                 select  a.busno,a.wareid,a.stallno,c.buyer,b.warename,b.warespec,b.producer,b.wareunit,c.makeno,                                c.batchno,c.idno,c.purprice,c.distprice,a.wareqty,c.bioavailability,(a.wareqty  *   c.bioavailability  / 1000) as sy ,                                b.saletax,b.saleprice,c.invalidate,b.maxunit,c.vendorno,d.vendorname, dbo.f_get_class('03',a.wareid) as classcode1                                
INTO #store_his from u_store_c a,u_ware_q b,u_store_i c,u_vendor d                                
WHERE a.wareid = b.wareid and a.batchno = c.batchno and a.idno = c.idno and wareqty <> 0  and a.wareid = c.wareid and c.vendorno=d.vendorno

insert into #store_his select a.busno,a.wareid,a.stallno,max(c.buyer),max(b.warename),max(b.warespec),                max(b.producer),max(b.wareunit),max(c.makeno),a.batchno,a.idno,max(c.purprice),max(c.distprice),sum(a.outqty - a.inqty),                max(c.bioavailability),sum((a.outqty - a.inqty)  *   c.bioavailability  / 1000) as sy ,                max(b.saletax),max(b.saleprice),max(c.invalidate) ,max(b.maxunit),max(c.vendorno),max(d.vendorname),dbo.f_get_class('03',a.wareid) as classcode1                
FROM v_item_in_out a,u_ware_q b,u_store_i c,u_vendor d  where a.wareid = c.wareid and a.wareid = b.wareid and a.wareid = c.wareid and c.vendorno=d.vendorno          and a.batchno = c.batchno and a.idno = c.idno and a.execdate >= dateadd(dd,0,'2021-01-01 00:00')                  group by a.busno,a.wareid,a.batchno,a.idno,a.stallno



select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(q.warename)   商品名称,
max(i.makeno )批号,
CASE WHEN max(e.isinsurance) = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
sum(a.wareqty) 数量,
max(a.purprice)单价,
sum(round(a.wareqty * a.purprice,2)) 金额,
max(q.warespec) 规格,
max(i.invalidate)  有效期至,
dbo.f_get_vendorname(a.vendorno) as  供应商
from #store_his a,u_ware_q q,c_org_busi b,u_store_i i,u_ware_ext  e
where a.wareid=q.wareid and a.busno=b.busno
and a.wareid=i.wareid and   a.wareid=e.wareid and a.batchno=i.batchno and a.makeno=i.makeno and a.idno=i.idno
and dbo.f_get_class('02',q.wareid)<>'10'
group by a.busno,a.wareid,a.vendorno










  

255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-26 09:34:33 | 显示全部楼层
---111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') as 有效期至,
tvb.vencusname as  供应商
from  t_accept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_accept_d b left join t_ware w on  b.wareid = w.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';

  ----222表二:门店退库入库表_公司总库
select
f_get_busnoname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.srcbusno 退库门店编号,
f_get_busnoname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MEDICALNO    退库门店定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.srcbusno=g.busno  ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



----333333表三:派送出库表_公司总库
select
f_get_busnoname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.objbusno  派送门店编号,
f_get_busnoname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MEDICALNO  定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---444表四:退货出库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 退库时间,
b.returnqty 退库数量,
b.purprice 退库单价,
b.returnqty*b.purprice   退库金额,
tvb.vencusname as  供应商
from  t_reaccept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_reaccept_d b left join t_ware w on  b.wareid = w.wareid
where a.reacceptno=b.reacceptno  and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



---5555表五:入库表_门店药库
select  
f_get_busnoname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
f_get_busnoname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd')派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno ,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';




----88 表八:期末库存表_公司总库_2024年末
select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(w.warename)   商品名称,
max(i.makeno )批号,
'否'   AS  是否集采商品,
sum(a.wareqty) 数量,
max(nvl(ad.purpriceo,i.purprice))单价,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) 金额,
max(w.warespec) 规格,
max(to_char(i.invalidate, 'yyyy-mm-dd'))  有效期至,
max(tvb.vencusname) as  供应商
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( '202412312359','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
  left join t_vencus_base tvb on tvb.vencusno = i.vencusno
  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( '202412312359','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( '202412312359','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( '202412312359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
group  by  a.compid,a.busno,a.wareid ;






  

255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-27 09:32:03 | 显示全部楼层
---111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') as 有效期至,
tvb.vencusname as  供应商
from  t_accept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_accept_d b left join t_ware w on  b.wareid = w.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';

  ----222表二:门店退库入库表_公司总库
select
f_get_busnoname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.srcbusno 退库门店编号,
f_get_busnoname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MEDICALNO    退库门店定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.srcbusno=g.busno  ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



----333333表三:派送出库表_公司总库
select
f_get_busnoname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.objbusno  派送门店编号,
f_get_busnoname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MEDICALNO  定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---444表四:退货出库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 退库时间,
b.returnqty 退库数量,
b.purprice 退库单价,
b.returnqty*b.purprice   退库金额,
tvb.vencusname as  供应商
from  t_reaccept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_reaccept_d b left join t_ware w on  b.wareid = w.wareid
where a.reacceptno=b.reacceptno  and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



---5555表五:入库表_门店药库
select  
f_get_busnoname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
f_get_busnoname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd')派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno ,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';




----88 表八:期末库存表_公司总库_2024年末
select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(w.warename)   商品名称,
max(i.makeno )批号,
'否'   AS  是否集采商品,
sum(a.wareqty) 数量,
max(nvl(ad.purpriceo,i.purprice))单价,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) 金额,
max(w.warespec) 规格,
max(to_char(i.invalidate, 'yyyy-mm-dd'))  有效期至,
max(tvb.vencusname) as  供应商
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( '202412312359','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
  left join t_vencus_base tvb on tvb.vencusno = i.vencusno
  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( '202412312359','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( '202412312359','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( '202412312359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
group  by  a.compid,a.busno,a.wareid ;






  

255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-28 15:17:28 | 显示全部楼层

----88 表八:期除库存表_公司总库_2021年初
select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(w.warename)   商品名称,
max(i.makeno )批号,
CASE WHEN max(w.scan_flag) = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
sum(a.wareqty) 数量,
max(nvl(ad.purpriceo,i.purprice))单价,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) 金额,
max(w.warespec) 规格,
max(to_char(i.invalidate, 'yyyy-mm-dd'))  有效期至,
max(tvb.vencusname) as  供应商
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
  left join t_vencus_base tvb on tvb.vencusno = i.vencusno
  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( '202309012359','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'
group  by  a.compid,a.busno,a.wareid ;

255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-28 15:18:17 | 显示全部楼层
-H1

--111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
dbo.f_get_orgname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
b.invalidate as 有效期至,
tvb.vendorname as  供应商
from  u_accept_m a
left join u_vendor tvb on tvb.vendorno = a.vendorno
, u_accept_c b left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'

  ----222表二:门店退库入库表_公司总库
select
dbo.f_get_orgname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
b.invalidate 有效期至,
a.srcbusno 退库门店编号,
dbo.f_get_orgname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MedicalNo    退库门店定点机构编号
from u_dist_m  a
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.srcbusno=g.busno
,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'



----333333表三:派送出库表_公司总库
select
dbo.f_get_orgname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
b.invalidate 有效期至,
a.objbusno  派送门店编号,
dbo.f_get_orgname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MedicalNo  定点机构编号
from u_dist_m  a LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.objbusno=g.busno ,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'


---444表四:退货出库表_公司总库
select
dbo.f_get_orgname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 退库时间,
b.wareqty 退库数量,
b.purprice 退库单价,
b.wareqty*b.purprice   退库金额,
tvb.vendorname as  供应商
from  u_accept_m a
left join u_vendor tvb on tvb.vendorno = a.vendorno
, u_accept_c b left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.acceptno=b.acceptno  and a.status=1 and  a.billcode='REJ'
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31';



---5555表五:入库表_门店药库
select  
dbo.f_get_orgname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
dbo.f_get_orgname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
a.execdate 派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
b.invalidate 有效期至
from u_dist_m  a LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.objbusno=g.busno,u_dist_c  b
left join u_ware_q w on  b.wareid = w.wareid
left join u_ware_ext e on  b.wareid = e.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and a.execdate>='2021-01-01'
AND a.execdate<='2024-12-31'


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
dbo.f_get_orgname(a.busno)  门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
a.accdate  销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
c.invalidate 有效期至
from u_sale_m a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.busno=g.busno,u_sale_c c,u_ware_q w,u_ware_ext   e
where    a.saleno=c.saleno and c.wareid=w.wareid  and c.wareid=e.wareid  
and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND a.accdate >='2021-01-01'
AND a.accdate <='2024-12-31'


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
dbo.f_get_orgname(a.busno)  门店名称,
'是' 是否定点机构,
g.MedicalNo 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
a.accdate  退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
c.invalidate 有效期至
from u_sale_m a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
LEFT JOIN hydee_ybpt..MEDICARE_ORGAN_CONFIG g ON a.busno=g.busno ,u_sale_c c,u_ware_q w,u_ware_ext  e
where    a.saleno=c.saleno and c.wareid=w.wareid and c.wareid=e.wareid
and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND a.accdate >='2021-01-01'
AND a.accdate <='2024-12-31'


----777 表七:期初库存表_公司总库_2021年期初
--库存
if object_id('tempdb..#store_his') is not null drop table #store_his                                 select  a.busno,a.wareid,a.stallno,c.buyer,b.warename,b.warespec,b.producer,b.wareunit,c.makeno,                                c.batchno,c.idno,c.purprice,c.distprice,a.wareqty,c.bioavailability,(a.wareqty  *   c.bioavailability  / 1000) as sy ,                                b.saletax,b.saleprice,c.invalidate,b.maxunit,c.vendorno,d.vendorname, dbo.f_get_class('03',a.wareid) as classcode1                                
INTO #store_his from u_store_c a,u_ware_q b,u_store_i c,u_vendor d                                
WHERE a.wareid = b.wareid and a.batchno = c.batchno and a.idno = c.idno and wareqty <> 0  and a.wareid = c.wareid and c.vendorno=d.vendorno

insert into #store_his select a.busno,a.wareid,a.stallno,max(c.buyer),max(b.warename),max(b.warespec),                max(b.producer),max(b.wareunit),max(c.makeno),a.batchno,a.idno,max(c.purprice),max(c.distprice),sum(a.outqty - a.inqty),                max(c.bioavailability),sum((a.outqty - a.inqty)  *   c.bioavailability  / 1000) as sy ,                max(b.saletax),max(b.saleprice),max(c.invalidate) ,max(b.maxunit),max(c.vendorno),max(d.vendorname),dbo.f_get_class('03',a.wareid) as classcode1                
FROM v_item_in_out a,u_ware_q b,u_store_i c,u_vendor d  where a.wareid = c.wareid and a.wareid = b.wareid and a.wareid = c.wareid and c.vendorno=d.vendorno          and a.batchno = c.batchno and a.idno = c.idno and a.execdate >= dateadd(dd,0,'2021-01-01 00:00')                  group by a.busno,a.wareid,a.batchno,a.idno,a.stallno



select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(q.warename)   商品名称,
max(i.makeno )批号,
CASE WHEN max(e.isinsurance) = '1' THEN '是' ELSE '否 ' END AS  是否集采商品,
sum(a.wareqty) 数量,
max(a.purprice)单价,
sum(round(a.wareqty * a.purprice,2)) 金额,
max(q.warespec) 规格,
max(i.invalidate)  有效期至,
dbo.f_get_vendorname(a.vendorno) as  供应商
from #store_his a,u_ware_q q,c_org_busi b,u_store_i i,u_ware_ext  e
where a.wareid=q.wareid and a.busno=b.busno
and a.wareid=i.wareid and   a.wareid=e.wareid and a.batchno=i.batchno and a.makeno=i.makeno and a.idno=i.idno
and dbo.f_get_class('02',q.wareid)<>'10'
group by a.busno,a.wareid,a.vendorno










  

255

主题

144

回帖

1461

积分

版主

积分
1461

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

 楼主| 发表于 2025-5-28 15:18:29 | 显示全部楼层
---111表一:采购入库表_公司总库
---表一:采购入库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.purprice 入库单价,
b.wareqty*b.purprice   入库金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') as 有效期至,
tvb.vencusname as  供应商
from  t_accept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_accept_d b left join t_ware w on  b.wareid = w.wareid
where a.acceptno=b.acceptno  and a.billcode='ACC' and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';

  ----222表二:门店退库入库表_公司总库
select
f_get_busnoname(a.objbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 入库时间,
b.wareqty 入库数量,
b.distprice 入库单价,
b.wareqty*b.distprice   入库金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.srcbusno 退库门店编号,
f_get_busnoname(a.srcbusno) 退库门店名称,
'是' 退库门店是否定点机构,
g.MEDICALNO    退库门店定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.srcbusno=g.busno  ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIR','ADR') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



----333333表三:派送出库表_公司总库
select
f_get_busnoname(a.srcbusno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 派送时间,
b.wareqty 派送数量,
b.distprice  派送单价,
b.wareqty * b.distprice   派送金额,
w.warespec 规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至,
a.objbusno  派送门店编号,
f_get_busnoname(a.objbusno) 派送门店名称,
'是' 是否定点机构,
g.MEDICALNO  定点机构编号
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno ,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---444表四:退货出库表_公司总库
select
f_get_busnoname(a.busno)  单位名称,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd') 退库时间,
b.returnqty 退库数量,
b.purprice 退库单价,
b.returnqty*b.purprice   退库金额,
tvb.vencusname as  供应商
from  t_reaccept_h a
left join t_vencus_base tvb on tvb.vencusno = a.vencusno
, t_reaccept_d b left join t_ware w on  b.wareid = w.wareid
where a.reacceptno=b.reacceptno  and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';



---5555表五:入库表_门店药库
select  
f_get_busnoname(a.srcbusno)  单位名称,
a.objbusno 门店编号,
f_get_busnoname(a.objbusno) 门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
b.wareid  商品ID,
w.warename 商品名称,
b.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.execdate, 'yyyy-mm-dd')派送时间,
b.wareqty 派送数量,
b.distprice 派送单价,
b.wareqty * b.distprice 派送金额,
w.warespec  规格,
to_char(b.invalidate, 'yyyy-mm-dd') 有效期至
from t_dist_h  a left  join  YBCloud.med_store  g on a.objbusno=g.busno,t_dist_d  b
left join t_ware w on  b.wareid = w.wareid
where a.distno=b.distno  and a.billcode in ('DIS','ADD') and a.status=1
and to_char(a.execdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.execdate,'yyyy-mm-dd')<='2024-12-31';


---6666表六:销售出库表_门店药库
select   
'定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 销售时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 销售数量,
c.netprice 销售单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 销售金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) >0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';


---666表六:门店退库表_门店药库
select  '定西众济堂医药连锁有限责任公司' 单位名称,
a.busno 门店编号,
f_get_busnoname(a.busno)  门店名称,
'是' 是否定点机构,
g.MEDICALNO 定点机构编号,
c.wareid 商品ID,
w.warename 商品名称,
c.makeno 批号,
'否'   AS  是否集采商品,
to_char(a.accdate,'yyyy-mm-dd') 退库时间,
round((c.wareqty + c.minqty / stdtomin) * times ,2) 退库数量,
c.netprice 退库单价,
round((c.wareqty + c.minqty ) * times * c.netprice,2) 退库金额,
w.warespec  规格,
to_char(c.invalidate, 'yyyy-mm-dd') 有效期至
from t_sale_h a  left  join  T_YBY_ORDER_H  h  on  a.saleno=h.erpsaleno
left  join  YBCloud.med_store  g on a.busno=g.busno ,t_sale_d c,t_ware w
where  w.compid=a.compid and a.saleno=c.saleno and c.wareid=w.wareid  and round((c.wareqty + c.minqty / stdtomin) * times ,2) <0
AND to_char(a.accdate,'yyyy-mm-dd')>='2021-01-01'
AND to_char(a.accdate,'yyyy-mm-dd')<='2024-12-31';




----88 表八:期末库存表_公司总库_2024年末
select  
'定西众济堂医药连锁有限责任公司'  单位名称,
a.wareid  商品ID,
max(w.warename)   商品名称,
max(i.makeno )批号,
'否'   AS  是否集采商品,
sum(a.wareqty) 数量,
max(nvl(ad.purpriceo,i.purprice))单价,
sum(round(a.wareqty * nvl(ad.purpriceo,i.purprice),2)) 金额,
max(w.warespec) 规格,
max(to_char(i.invalidate, 'yyyy-mm-dd'))  有效期至,
max(tvb.vencusname) as  供应商
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( '202412312359','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
  left join t_vencus_base tvb on tvb.vencusno = i.vencusno
  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( '202412312359','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( '202412312359','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( '202412312359','yyyy-mm-dd hh24:mi' ) and i.compid = 2 AND w.compid=2     and    nvl(w.insuranceno,'1')<>'1'
group  by  a.compid,a.busno,a.wareid ;






  
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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