医药网订单对接ERP软件订单接口

来源:互联网 发布:腾讯网络电影 编辑:程序博客网 时间:2024/05/17 07:03

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Orderinterface]
as
create table #a --创建临时表#a储存查询的结果集
(
ID   int IDENTITY (0,1),--自增列从0开始每次增加1
o_id int,--医药网订单ID
o_buyer_internal_code varchar(256),--采购客户ERP内码
o_add_time datetime, --订单创建时间
o_note varchar(512),--订单备注
);
 --将查询结果集插入到临时表中
INSERT INTO #a select o_id,o_buyer_internal_code,o_add_time ,o_note from mph_order
where is_fetch = '否'
--创建临时变量
declare
@ii int,--循环更新变量
@i int,
@jj int,--循环更新变量
@j int,
@Ordermaxid int,--千方OrderIndex表最大id
@oo_id int--医药网订单id   
set @ii=0   --从0开始
set @jj=0   --从0开始
--查询临时表a的ID总数赋值给i控制循环次数
select @i = count(ID) from #a;


--创建临时变量
declare
@BRec int,--采购客户ERP内码
@ERec int,
@CheckEID int,
@BillEID int,
@KRec int,
@BillDate smalldatetime,--订单创建时间
@ReachDate smalldatetime,
@Billcode varchar(50),
@billtype smallint,
@totalmoney  money,
@totalqty numeric(18, 6),
@period tinyint,
@checked tinyint,
@BillOver tinyint,
@Comment varchar(256), --订单备注
@explain char(256),
@plan_id int,
@gspid int,
@Tax smallmoney,
@ChangeID int,
@YS_Weway varchar(200),
@YS_ADDR varchar(200),
@YS_DW varchar(200)
set @ERec=120
set @CheckEID=107
set @BillEID=107
set @KRec=5
set @ReachDate=GETDATE()
set @billtype=300
set @totalmoney=10
set @totalqty=10
set @period=1
set @checked=1
set @BillOver=0 
set @explain=''
set @plan_id=0 
set @gspid=0
set @Tax=-10
set @ChangeID=1983 
set @YS_Weway=''
set @YS_ADDR='' 
set @YS_DW=''


create table #c --创建临时表#c储存千方订单表最大id
(
ID   int IDENTITY (0,1),--自增列从0开始每次增加1
maxid int,

);
create table #d --创建临时表#c储存千方订单表最大id
(
ID   int IDENTITY (0,1),--自增列从0开始每次增加1
o_id int,--医药网订单ID

);
--循环判断
WHILE @ii<@i     
BEGIN
select @Billcode= o_id from #a where ID=@ii 
create table #b --创建临时表#b储存查询的结果集
(
ID   int IDENTITY (0,1),--自增列从0开始每次增加1
od_id int,
od_g_in_sn varchar(128),
maxid int,
od_buy_number int,
od_price decimal(14, 6),

);
select @BRec = o_buyer_internal_code from #a where ID=@ii 
select @BillDate = o_add_time from #a where ID=@ii
select @Comment = o_note from #a where ID=@ii
--千方订单插入数据
insert into [OrderIndex](BRec,ERec,CheckEID,BillEID,KRec,BillDate,ReachDate, 
Billcode,billtype, totalmoney,  totalqty, period, checked, BillOver, 
Comment, explain, plan_id, gspid, Tax,ChangeID, YS_Weway, YS_ADDR, YS_DW )
values(@BRec,@ERec,@CheckEID,@BillEID,@KRec,@BillDate,@ReachDate, 
@Billcode,@billtype, @totalmoney,@totalqty,@period,@checked,@BillOver, 
@Comment,@explain,@plan_id,@gspid,@Tax,@ChangeID,@YS_Weway,@YS_ADDR,@YS_DW)


--千方订单表最大id
select @Ordermaxid = max(BillID) from OrderIndex


--医药网订单详情对应的订单id
select @oo_id = o_id from #a where ID=@ii
--修改中间表中ERP提取状态
UPDATE mph_order SET is_fetch = '是' WHERE o_id = @oo_id


--医药网订单明细对应订单id插入到临时表#b中
INSERT INTO #b (od_id,od_g_in_sn,maxid,od_buy_number,od_price)
select od_id,od_g_in_sn,0,od_buy_number,od_price from mph_order_detail where o_id=@oo_id
 select * from #b
select @j = count(ID) from #b;
select  count(ID) from #b;
--
if @j = 1 
    begin
        INSERT INTO #c select max(BillID) from OrderIndex
        
    end
    UPDATE #b SET maxid = @Ordermaxid where maxid=0
    select * from #b
--
INSERT INTO OrderBill(BillID,PRec,KRec,qty,AssQty,price,AssPrice
,total,Tax,TaxPrice,TaxTotal,comment,mxord) 
Select maxid,od_g_in_sn,1,od_buy_number,od_buy_number,
od_price,od_price,(od_buy_number*od_price),17,
((od_price*0.17)+od_price),(((od_price*0.17)+od_price)*od_buy_number),
od_id,1
from #b
 drop table  #b
SET @ii=@ii+1 --更新循环变量
END
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 漠河北极村驴友之家 齐齐哈尔 漠河 漠河腾冲是什么分界线 漠河在哪个省 去漠河怎么去 莫河 漠河北极光 漠漠 漠漠什么起 漠漠秋云起 浣溪沙 漠漠 漠漠轻寒上小楼 秋天漠漠向昏黑 山村漠漠作品 相思意 漠漠无雨 改嫁记 漠漠无雨 婉妃传 安漠漠 漠漠水田飞白鹭全诗 秋天漠漠向昏黑上一句 漠漠momo作品 红楼之贤妻难为 山村漠漠 漠然置之 漠然 漠然淡然 漠然的意思 重来漠然无语 快穿之漠然一世 漠然是什么意思 总裁的漠然逃妻 重来 漠然无语 漠然的反义词 漠然置之的意思 恶作剧同人漠然一笑 总裁的漠然逃妻全文免费阅读 漠然回首那人却在灯火阑珊处 漫游仙途 水漠然 星河主宰 萧声漠然 妖孽美男十二宫 丿冷漠然0000 漩涡鸣人 漩涡