--日结插件入口 if exists (select name from sysobjects where name='p_sys_day_over_plugin' and xtype='p') drop procedure p_sys_day_over_plugin go create procedure p_sys_day_over_plugin ( @orgcode varchar(10), @accdate varchar(10), @acctimes int, @usercode varchar(10), @overdaytype varchar(20), @message varchar(200) out ) as declare @psmsg varchar(200) begin if @overdaytype = 'ODT_BLUESALE' exec p_sys_day_over_plugin_bluesale @orgcode, @accdate else exec p_sys_day_over_plugin_acc @orgcode, @accdate set @message = '' return (1) end go --正常日结 if exists (select name from sysobjects where name='p_sys_day_over_plugin_acc' and xtype='p') drop procedure p_sys_day_over_plugin_acc go create procedure p_sys_day_over_plugin_acc ( @orgcode varchar(10), @accdate varchar(10) ) as begin declare @irtnresult int declare @srtnmsg varchar(200) --销售明细 exec @irtnresult = p_int_gen_flow_item @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --销售成本 exec @irtnresult = p_int_gen_flow_chg @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --支付方式 exec @irtnresult = p_int_gen_flow_pay @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --现金缴存 /* exec @irtnresult = p_int_gen_flow_pay_cash @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end */ --非油采购验收 exec @irtnresult = p_int_gen_accept @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --非油采购退货 exec @irtnresult = p_int_gen_return @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --历史进价调整 exec @irtnresult = p_int_gen_buy_price_his @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --现存进价调整 exec @irtnresult = p_int_gen_buy_price_now @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --领用 exec @irtnresult = p_int_gen_draw @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --自然报损 exec @irtnresult = p_int_gen_scrap @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --非自然报损 exec @irtnresult = p_int_gen_damage @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --盘点 exec @irtnresult = p_int_gen_differ @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --配送 exec @irtnresult = p_int_gen_dist @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --配退 exec @irtnresult = p_int_gen_dist_return @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --配送销售 exec @irtnresult = p_int_gen_dist_sale @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --配送成本 exec @irtnresult = p_int_gen_dist_chg @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --调拨 exec @irtnresult = p_int_gen_out_trans @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --批发销售 exec @irtnresult = p_int_gen_wh_sale @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --批发成本 exec @irtnresult = p_int_gen_wh_chg @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end return (1) end go --补录日结 if exists (select name from sysobjects where name='p_sys_day_over_plugin_bluesale' and xtype='p') drop procedure p_sys_day_over_plugin_bluesale go create procedure p_sys_day_over_plugin_bluesale ( @orgcode varchar(10), @accdate varchar(10) ) as begin declare @irtnresult int declare @srtnmsg varchar(200) declare @pluqty numeric(19,4) declare @amount numeric(19,4) select @pluqty = isnull(sum(pluqty),0) from t_saleblue_head a, t_saleblue_body b where a.rzdate <> '' and a.rzdate is not null and a.orgcode = @orgcode and a.tradedate = @accdate select @amount = isnull(sum(amount),0) from t_saleblue_head a, t_saleblue_body2 b where a.rzdate <> '' and a.rzdate is not null and a.orgcode = @orgcode and a.tradedate = @accdate --销售明细 exec @irtnresult = p_int_gen_flow_item @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end --销售成本 if @pluqty <> 0 begin exec @irtnresult = p_int_gen_flow_chg @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end end --支付方式 if @amount <> 0 begin exec @irtnresult = p_int_gen_flow_pay @orgcode, @accdate, @srtnmsg out if @irtnresult <> 1 begin insert into t_over_error (orgcode, overdate, overtime, errreason) values (@orgcode, @accdate, convert(varchar(10), getdate(), 24), @srtnmsg) end end return (1) end go --非油销售收入 if exists (select name from sysobjects where name='p_int_gen_flow_item' and xtype='p') drop procedure p_int_gen_flow_item go create procedure p_int_gen_flow_item ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @tablename varchar(40) declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @tablename = 't_plusale_'+substring(@psaccdate,1,4)+substring(@psaccdate,6,2) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if not exists(select * from sysobjects where name=@tablename) begin set @psmsg = '不存在表'+@tablename return(-1) end if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and sale.OrgCode = ''' + @psorgcode + '''' end set @sql = 'insert into t_int_sap_drysalesinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,ZYWDAT,ZTYPE,ZCXLX,ZJYFS,' + ' VVTYP,MATNR,MENGE,MEINS,PRICE,SKTAK,SKTBT,TMWSTS,GTTAX,WAERS,ZTOLAMT,' + ' ZTSDAT,ZGZDAT,ZFNAME,ZUNFLG,ZYZLX,MWSKZ)' + 'select ''' + @createdate + ''' as CREATEDATE,''F01'' as IFTYPE,FinaCode as BUKRS,OrgCode as WERKS,''1'' as ZSIGN,''P''+FinaCode+''1''+OrgCode as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F01'' as ZTYPE,''Z30'' as ZCXLX,''Z01'' as ZJYFS,' + ' '''' as VVTYP,ClsCode as MATNR,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,Amount as PRICE,Total as SKTAK,0 as SKTBT,TaxAmount as TMWSTS,0 as GTTAX,''CNY'' as WAERS,0 as ZTOLAMT,' + ' ''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,'''' as ZFNAME,case when Amount < 0 then ''Y'' else '''' end as ZUNFLG,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,' + ' case STaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end as MWSKZ' + ' from (' + ' select AccDate,FinaCode,OrgCode,ClsCode,STaxRate,OrgType,sum(Total) as Total,sum(Amount) as Amount,sum(Amount-NetAmount) as TaxAmount,sum(Counts) as Counts' + ' from (' + ' select sale.AccDate,shop.FinaCode,sale.OrgCode,class.UpperCode1 as ClsCode,sale.STaxRate,' + ' isnull((select JyMode from t_supplier where SupCode = sale.SupCode),''0'') as JyMode,' + ' sale.Counts,sale.Total,sale.Amount,sale.NetAmount,shop.OrgType' + ' from ' + @tablename + ' sale, t_shop shop, t_plu plu, t_gclass class' + ' where sale.OrgCode = shop.OrgCode' + ' and sale.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and sale.AccDate = ''' + @psaccdate + '''' + @where + ' ) b' + ' where JyMode = ''0''' + ' group by AccDate,FinaCode,OrgCode,ClsCode,STaxRate,OrgType' + ' ) a' + ' where Amount <> 0 or Counts <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总经销销售明细失败' return(-1) end set @sql = 'insert into t_int_sap_drysalesinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,ZYWDAT,ZTYPE,ZCXLX,ZJYFS,' + ' VVTYP,MATNR,MENGE,MEINS,PRICE,SKTAK,SKTBT,TMWSTS,GTTAX,WAERS,ZTOLAMT,' + ' ZTSDAT,ZGZDAT,ZFNAME,ZUNFLG,ZYZLX,MWSKZ)' + 'select ''' + @createdate + ''' as CREATEDATE,''F01'' as IFTYPE,FinaCode as BUKRS,OrgCode as WERKS,''1'' as ZSIGN,''P''+FinaCode+''1''+OrgCode as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F01'' as ZTYPE,''Z30'' as ZCXLX,''Z03'' as ZJYFS,' + ' '''' as VVTYP,ClsCode as MATNR,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,Amount as PRICE,Total as SKTAK,DkTotal as SKTBT,round(DkTotal-DkTotal/(1+STaxRate/100.00),2) as TMWSTS,0 as GTTAX,''CNY'' as WAERS,0 as ZTOLAMT,' + ' ''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,'''' as ZFNAME,case when Counts < 0 then ''Y'' else '''' end as ZUNFLG,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,' + ' case STaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end as MWSKZ' + ' from (' + ' select AccDate,FinaCode,OrgCode,ClsCode,STaxRate,OrgType,sum(Total) as Total,sum(Amount) as Amount,sum(Total-Cost) as DkTotal,sum(Counts) as Counts' + ' from (' + ' select sale.AccDate,shop.FinaCode,sale.OrgCode,class.UpperCode1 as ClsCode,sale.STaxRate,' + ' isnull((select JyMode from t_supplier where SupCode = sale.SupCode),''0'') as JyMode,' + ' sale.Counts,sale.Cost,sale.Total,sale.Amount,shop.OrgType' + ' from ' + @tablename + ' sale, t_shop shop, t_plu plu, t_gclass class' + ' where sale.OrgCode = shop.OrgCode' + ' and sale.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and sale.AccDate = ''' + @psaccdate + '''' + @where + ' ) b' + ' where JyMode = ''2''' + ' group by AccDate,FinaCode,OrgCode,ClsCode,STaxRate,OrgType' + ' ) a' + ' where Amount <> 0 or Counts <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总联销销售明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drysalesinfo set DOCNO = 'XSD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F01' and ZJYFS in ('Z01','Z03') and DOCNO is null set @psmsg = '' return (1) end go --非油库存成本 if exists (select name from sysobjects where name='p_int_gen_flow_chg' and xtype='p') drop procedure p_int_gen_flow_chg go create procedure p_int_gen_flow_chg ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @tablename varchar(40) declare @where varchar(2000) declare @sql varchar(2000) declare @createdate varchar(20) declare @tsdat varchar(10) set @tablename = 't_plusale_'+substring(@psaccdate,1,4)+substring(@psaccdate,6,2) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if not exists(select * from sysobjects where name=@tablename) begin set @psmsg = '不存在表'+@tablename return(-1) end if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and sale.OrgCode = ''' + @psorgcode + '''' end set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,' + ' SLTWR,WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG)' + 'select ''' + @createdate + ''' as CREATEDATE,''F11'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,OrgCode as WERKS,''P''+FinaCode+''1''+OrgCode as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F11'' as ZTYPE,ClsCode as MATNR,case JyMode when ''0'' then ''Z01'' else ''Z03'' end as ZJYFS,' + ' NetCost as SLTWR,''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,case when Counts < 0 then ''Y'' else '''' end as UNFLG' + ' from (' + ' select AccDate,FinaCode,OrgCode,ClsCode,JyMode,OrgType,sum(NetCost+NetAdjustProfit) as NetCost,sum(Counts) as Counts' + ' from (' + ' select sale.AccDate,shop.FinaCode,sale.OrgCode,class.UpperCode1 as ClsCode,' + ' isnull((select JyMode from t_supplier where SupCode = sale.SupCode),''0'') as JyMode,' + ' sale.NetCost,sale.NetAdjustProfit,sale.Counts,shop.OrgType' + ' from ' + @tablename + ' sale, t_shop shop, t_plu plu, t_gclass class' + ' where sale.OrgCode = shop.OrgCode' + ' and sale.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and sale.AccDate = ''' + @psaccdate + '''' + @where + ' ) b' + ' where JyMode = ''0''' + ' group by AccDate,FinaCode,OrgCode,ClsCode,OrgType,JyMode' + ' ) a' + ' where NetCost <> 0 or Counts <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总销售成本失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'XSC' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F11' and ZJYFS in ('Z01','Z03') and DOCNO is null set @psmsg = '' return (1) end go --非油支付 if exists (select name from sysobjects where name='p_int_gen_flow_pay' and xtype='p') drop procedure p_int_gen_flow_pay go create procedure p_int_gen_flow_pay ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @tablename varchar(40) declare @where varchar(2000) declare @sql varchar(2000) declare @createdate varchar(20) declare @tsdat varchar(10) set @tablename = 't_int_flow_pay_deily_'+substring(@psaccdate,1,4)+substring(@psaccdate,6,2) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if not exists(select * from sysobjects where name=@tablename) begin set @psmsg = '不存在表'+@tablename return(-1) end if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and shop.OrgCode = ''' + @psorgcode + '''' end set @sql = 'insert into t_int_sap_paymentreportinfo' + ' (CREATEDATE,IFTYPE,ZSIGN,ZTSDAT,BUKRS,PRCTR,KUNNR,' + ' SKART,ZYYDAT,WRBTR,WEARS,ZCXBS)' + 'select ''' + @createdate + ''' as CREATEDATE,''Z01'' as IFTYPE,''1'' as ZSIGN,''' + @tsdat + ''' as ZTSDAT,FinaCode as BUKRS,''P''+FinaCode+''1''+OrgCode as PRCTR,OrgCode as KUNNR,' + ' PayCode,replace(AccDate,''-'','''') as ZYYDAT,Amount as WRBTR,''CNY'' as WEARS,case when Amount < 0 then ''Y'' else '''' end as ZCXBS' + ' from (' + ' select pay.BUSINESS_DATE as AccDate,shop.FinaCode,pay.WERKS as OrgCode,pay.MOP_ID as PayCode,sum(pay.AMOUNT) as Amount' + ' from ' + @tablename + ' pay, t_shop shop' + ' where pay.WERKS = shop.OrgCode' + ' and pay.ITEM_ID like ''20%''' + -- 只传非油品 ' and pay.BUSINESS_DATE > ''2023-09-15''' + ' and pay.BUSINESS_DATE = ''' + @psaccdate + '''' + @where + ' group by pay.BUSINESS_DATE,shop.FinaCode,pay.WERKS,pay.MOP_ID' + ' ) a' + ' where Amount <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总销售支付方式失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_paymentreportinfo set DOCNO = 'ZFD' + ZTSDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'Z01' and DOCNO is null set @psmsg = '' return (1) end go --非油现金 if exists (select name from sysobjects where name='p_int_gen_flow_pay_cash' and xtype='p') drop procedure p_int_gen_flow_pay_cash go create procedure p_int_gen_flow_pay_cash ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @tablename varchar(40) declare @where varchar(2000) declare @sql varchar(2000) declare @createdate varchar(20) declare @tsdat varchar(10) set @tablename = 't_int_flow_pay_deily_'+substring(@psaccdate,1,4)+substring(@psaccdate,6,2) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if not exists(select * from sysobjects where name=@tablename) begin set @psmsg = '不存在表'+@tablename return(-1) end if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and shop.OrgCode = ''' + @psorgcode + '''' end set @sql = 'insert into t_int_sap_cashpaymentinfo' + ' (CREATEDATE,IFTYPE,ZSIGN,ZTSDAT,BUKRS,PRCTR,KUNNR,SKART,' + ' ZYRDAT,JCRQ,WRBTR,JCYYK,SYBTR,CDYSK,JKDOC,ZGZDAT,WAERS,ZCXBS)' + 'select ''' + @createdate + ''' as CREATEDATE,''Z02'' as IFTYPE,''1'' as ZSIGN,''' + @tsdat + ''' as ZTSDAT,FinaCode as BUKRS,''P''+FinaCode+''1''+OrgCode as PRCTR,OrgCode as KUNNR,''1000001'' as SKART,' + ' replace(AccDate,''-'','''') as ZYRDAT,replace(AccDate,''-'','''') as JCRQ,Amount as WRBTR,Amount as JCYYK,0 as SYBTR,0 as CDYSK,'''' as JKDOC,replace(AccDate,''-'','''') as ZGZDAT,''CNY'' as WAERS,case when Amount < 0 then ''Y'' else '''' end as ZCXBS' + ' from (' + ' select pay.BUSINESS_DATE as AccDate,shop.FinaCode,pay.WERKS as OrgCode,sum(pay.AMOUNT) as Amount' + ' from ' + @tablename + ' pay, t_shop shop' + ' where pay.WERKS = shop.OrgCode' + ' and pay.MOP_ID = ''40''' + -- 40-现金,该支付方式编码由BOS系统直接下发 ' and pay.ITEM_ID like ''20%''' + -- 只传非油品 ' and pay.BUSINESS_DATE > ''2023-09-15''' + ' and pay.BUSINESS_DATE = ''' + @psaccdate + '''' + @where + ' group by pay.BUSINESS_DATE,shop.FinaCode,pay.WERKS' + ' ) a' + ' where Amount <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总现金支付失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_cashpaymentinfo set DOCNO = 'ZFX' + ZTSDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'Z02' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_accept' and xtype='p') drop procedure p_int_gen_accept go create procedure p_int_gen_accept ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --采购单汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo ' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CREATEDATE,''F02'' as IFTYPE,FinaCode as BUKRS,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,ClsCode as MATNR,SupCode as LIFNR,case JyMode when ''0'' then ''Z01'' else ''Z03'' end as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F02'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode,head.SupCode,sup.JyMode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts' + ' from t_accept_head head, t_accept_body body, t_shop shop, t_plu plu, t_gclass class, t_supplier sup, t_financial_body fina' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and head.SupCode = sup.SupCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and shop.FinaCode = fina.FinaCode' + ' and head.BillType in (''1'',''2'')' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and fina.FinaType = ''0''' + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,head.SupCode,sup.JyMode,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总验收明细失败' return(-1) end --子公司配送单汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo ' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CREATEDATE,''F02'' as IFTYPE,FinaCode as BUKRS,ShopCode as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+ShopCode as PRCTR,ClsCode as MATNR,SupCode as LIFNR,''Z02'' as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F02'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.ZpCount) as Counts,shop.OrgType,fina.SupCode' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class, t_financial_body fina' + ' where head.BillNo = body.BillNo' + ' and head.ShopCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and shop.FinaCode = fina.FinaCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount > 0' + ' and fina.FinaType = ''1''' + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType,fina.SupCode' + ' ) a'; exec(@sql) if @@error <>0 begin set @psmsg = '汇总子公司验收明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drypurchaseinfo set DOCNO = 'JHD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F02' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_return' and xtype='p') drop procedure p_int_gen_return go create procedure p_int_gen_return ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --退货单汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CREATEDATE,''F03'' as IFTYPE,FinaCode as BUKRS,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,ClsCode as MATNR,SupCode as LIFNR,case JyMode when ''0'' then ''Z01'' else ''Z03'' end as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F03'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode,head.SupCode,sup.JyMode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts' + ' from t_return_head head, t_return_body body, t_shop shop, t_plu plu, t_gclass class, t_supplier sup, t_financial_body fina' + ' where head.BillNo = body.BillNo ' + ' and head.OrgCode = shop.OrgCode ' + ' and head.SupCode = sup.SupCode' + ' and body.PluCode = plu.PluCode ' + ' and plu.ClsCode = class.ClsCode ' + ' and shop.FinaCode = fina.FinaCode ' + ' and head.BillType in (''0'',''2'') ' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and fina.FinaType = ''0''' + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,head.SupCode,sup.JyMode,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总退货明细失败' return(-1) end --子公司配送退货单汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo ' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CREATEDATE,''F03'' as IFTYPE,FinaCode as BUKRS,ShopCode as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+ShopCode as PRCTR,ClsCode as MATNR,SupCode as LIFNR,''Z02'' as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F03'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,' + ' sum(-body.NetCost) as NetCost,sum(-body.ZpCount) as Counts,shop.OrgType,fina.SupCode' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class, t_financial_body fina' + ' where head.BillNo = body.BillNo' + ' and head.ShopCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and shop.FinaCode = fina.FinaCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount < 0' + ' and fina.FinaType = ''1''' + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType,fina.SupCode' + ' ) a'; exec(@sql) if @@error <>0 begin set @psmsg = '汇总子公司退货明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drypurchaseinfo set DOCNO = 'THD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F03' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_buy_price_his' and xtype='p') drop procedure p_int_gen_buy_price_his go create procedure p_int_gen_buy_price_his ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --历史进价调整汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZUNFLG,ZYZLX)' + 'select ''' + @createdate + ''' as CreateDate,''F14'' as IFTYPE,FinaCode as BUKRS,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,ClsCode as MATNR,SupCode as LIFNR,case JyMode when ''0'' then ''Z01'' else ''Z03'' end as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F14'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case when NetCost < 0 then ''Y'' else '''' end as ZUNFLG,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode, head.SupCode,sup.JyMode,' + ' sum(body.NetCjCost) as NetCost,sum(body.TzCount) as Counts' + ' from t_adjbuyprice_head head, t_adjbuyprice_body body, t_shop shop, t_plu plu, t_gclass class, t_supplier sup' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and head.SupCode = sup.SupCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.TzType = ''0''' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,head.SupCode,sup.JyMode,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总历史进价调整失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drypurchaseinfo set DOCNO = 'TJS' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F14' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_buy_price_now' and xtype='p') drop procedure p_int_gen_buy_price_now go create procedure p_int_gen_buy_price_now ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --现存进价调整汇总 set @sql = 'insert into t_int_sap_drypurchaseinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,MATNR,LIFNR,ZJYFS,' + ' ZYWDAT,ZTYPE,WAERS,SLTWR,DWERT,MENGE,MEINS,ZTSDAT,ZGZDAT,ZUNFLG,ZYZLX)' + 'select ''' + @createdate + ''' as CreateDate,''F15'' as IFTYPE,FinaCode as BUKRS,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS, ''1'' as ZSIGN,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,ClsCode as MATNR,SupCode as LIFNR,case JyMode when ''0'' then ''Z01'' else ''Z03'' end as ZJYFS,' + ' replace(AccDate,''-'','''') as ZYWDAT,''F15'' as ZTYPE,''CNY'' as WAERS,NetCost as SLTWR,0 as DWERT,Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case when NetCost < 0 then ''Y'' else '''' end as ZUNFLG,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode, head.SupCode,sup.JyMode,' + ' sum(body.NetCjCost) as NetCost,sum(body.TzCount) as Counts' + ' from t_adjbuyprice_head head, t_adjbuyprice_body body, t_shop shop, t_plu plu, t_gclass class, t_supplier sup' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and head.SupCode = sup.SupCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.TzType = ''1''' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,head.SupCode,sup.JyMode,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总现存进价调整失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drypurchaseinfo set DOCNO = 'TJC' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F15' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_draw' and xtype='p') drop procedure p_int_gen_draw go create procedure p_int_gen_draw ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --领用单汇总 set @sql = 'insert into t_int_sap_stockconsumer' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZHQBS,KOSTL,PRCTR,ZLYLB,' + ' ZTYPE,BLDAT,MATNR,SLTWR,ZXSZJ,MENGE,WAERS,MEINS,' + ' MWSKZ,TSDAT,BUDAT,UNFLG,SGTXT,ZPLXH)' + 'select ''' + @createdate + ''' as CreateDate,''F13'' as IFTYPE,FinaCode as BUKRS,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS, ''1'' as ZHQBS,CostCenter as KOSTL,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,LyType as ZLYLB,' + ' ''F13'' as ZTYPE,replace(AccDate,''-'','''') as BLDAT,ClsCode as MATNR,NetCost as SLTWR,Total as ZXSZJ,Counts as MENGE,''CNY'' as WAERS,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,' + ' case left(LyType,2) when ''A1'' then case JTaxRate when 0 then ''J0'' when 17 then ''J1'' when 13 then ''J2'' when 11 then ''J3'' when 6 then ''J4'' when 4 then ''J5'' when 3 then ''J6'' when 5 then ''J7'' when 16 then ''J8'' when ''10'' then ''J9'' when 9 then ''JA'' when 1 then ''JB'' end' + ' when ''A2'' then case STaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end' + ' else ''X0'' end as MWSKZ,''' + @tsdat + ''' as TSDAT,replace(AccDate,''-'','''') as BUDAT,'''' as UNFLG,PurPose as SGTXT,'''' as ZPLXH' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,head.LyType,head.CostCenter,head.PurPose,class.UpperCode1 as ClsCode,body.JTaxRate,plu.STaxRate,' + ' sum(body.NetCost) as NetCost,sum(body.Total) as Total,sum(body.Counts) as Counts' + ' from t_draw_head head, t_draw_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.billno = body.billno ' + ' and head.OrgCode = shop.OrgCode ' + ' and body.PluCode = plu.PluCode ' + ' and plu.ClsCode = class.ClsCode ' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.AccDate,shop.FinaCode,head.OrgCode,head.LyType,head.CostCenter,head.PurPose,class.UpperCode1,shop.OrgType,body.JTaxRate,plu.STaxRate' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总领用明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_stockconsumer set DOCNO = 'LYD' + BLDAT + convert(varchar(10),SERIALNO), DOCNO1 = 'LYD'+BLDAT+convert(varchar(10),SERIALNO) where IFTYPE = 'F13' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_scrap' and xtype='p') drop procedure p_int_gen_scrap go create procedure p_int_gen_scrap ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --报损单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,SLTWR,' + ' WEARS,MENGE,DWERT,MEINS,MWSKZ,TMWSTS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG)' + 'select ''' + @createdate + ''' as CreateDate,''F08'' as IFTYPE,FinaCode as BUKRS, ''1'' as ZSIGN,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F08'' as ZTYPE,ClsCode as MATNR,''Z01'' as ZJYFS,NetCost as SLTWR,' + ' ''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,'''' as MWSKZ,0 as TMWSTS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,'''' as UNFLG' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts,sum(body.Cost-body.NetCost) as TaxTotal' + ' from t_scrap_head head, t_scrap_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.BsType = ''01''' + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总自然报损失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'BSZ' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F08' and ZJYFS = 'Z01' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_damage' and xtype='p') drop procedure p_int_gen_damage go create procedure p_int_gen_damage ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --报损单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,SLTWR,' + ' WEARS,MENGE,DWERT,MEINS,MWSKZ,TMWSTS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG)' + 'select ''' + @createdate + ''' as CreateDate,''F09'' as IFTYPE,FinaCode as BUKRS, ''1'' as ZSIGN,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F09'' as ZTYPE,ClsCode as MATNR,''Z01'' as ZJYFS,NetCost as SLTWR,' + ' ''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''JC'' as MWSKZ,TaxTotal as TMWSTS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,'''' as UNFLG' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts,sum(body.Cost-body.NetCost) as TaxTotal' + ' from t_scrap_head head, t_scrap_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.BsType = ''02''' + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总非自然报损失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'BSF' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F09' and ZJYFS = 'Z01' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_differ' and xtype='p') drop procedure p_int_gen_differ go create procedure p_int_gen_differ ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --盈亏单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,' + ' ZJYFS,SLTWR,WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG)' + 'select ''' + @createdate + ''' as CreateDate,''F10'' as IFTYPE,FinaCode as BUKRS, ''1'' as ZSIGN,case OrgType when ''2'' then ''2Y00'' else OrgCode end as WERKS,''P''+FinaCode+''1''+case OrgType when ''2'' then ''2Y00'' else OrgCode end as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F10'' as ZTYPE,ClsCode as MATNR,' + ' ''Z01'' as ZJYFS,NetCost as SLTWR,''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,case when Counts < 0 then ''Y'' else '''' end as UNFLG' + ' from (' + ' select head.AccDate,shop.FinaCode,shop.OrgType,head.OrgCode,class.UpperCode1 as ClsCode,' + ' sum(body.YkNetCost) as NetCost,sum(body.YkCount) as Counts' + ' from t_differ_head head, t_differ_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.BillType in (''0'',''1'',''3'')' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.AccDate,shop.FinaCode,head.OrgCode,class.UpperCode1,shop.OrgType' + ' ) a' + ' where NetCost <> 0 or Counts <> 0' exec(@sql) if @@error <>0 begin set @psmsg = '汇总盈亏明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'PKD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F10' and ZJYFS = 'Z01' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_dist' and xtype='p') drop procedure p_int_gen_dist go create procedure p_int_gen_dist ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --配送单汇总 set @sql = 'insert into t_int_sap_drydeliveryinfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,SDWRK,SPRCTR,WERKS,PRCTR,ZYWDAT,ZTYPE,' + ' MATNR,ZJYFS,DMBTR,WAERS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CreateDate,''F04'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,ShopCode as SDWRK,''P''+FinaCode+''1''+ShopCode as SPRCTR,''2Y00'' as WERKS,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F04'' as ZTYPE,' + ' ClsCode as MATNR,''Z01'' as ZJYFS,NetCost as DMBTR,''CNY'' as WAERS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.ZpCount) as Counts,shop.OrgType' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class, t_financial_body fina' + ' where head.BillNo = body.BillNo' + ' and head.ShopCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and shop.FinaCode = fina.FinaCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount > 0' + ' and fina.FinaType = ''0''' + ' group by head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总配送明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drydeliveryinfo set DOCNO = 'PSD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F04' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_dist_return' and xtype='p') drop procedure p_int_gen_dist_return go create procedure p_int_gen_dist_return ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --配送退货单汇总 set @sql = 'insert into t_int_sap_drydeliveryinfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,SDWRK,SPRCTR,WERKS,PRCTR,ZYWDAT,ZTYPE,' + ' MATNR,ZJYFS,DMBTR,WAERS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZYZLX)' + 'select ''' + @createdate + ''' as CreateDate,''F05'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,ShopCode as SDWRK,''P''+FinaCode+''1''+ShopCode as SPRCTR,''2Y00'' as WERKS,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F05'' as ZTYPE,' + ' ClsCode as MATNR,''Z01'' as ZJYFS,NetCost as DMBTR,''CNY'' as WAERS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX' + ' from (' + ' select head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,' + ' sum(-body.NetCost) as NetCost,sum(-body.ZpCount) as Counts,shop.OrgType' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class, t_financial_body fina' + ' where head.BillNo = body.BillNo' + ' and head.ShopCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and shop.FinaCode = fina.FinaCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount < 0' + ' and fina.FinaType = ''0''' + ' group by head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总配送退货明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drydeliveryinfo set DOCNO = 'PST' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F05' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_dist_sale' and xtype='p') drop procedure p_int_gen_dist_sale go create procedure p_int_gen_dist_sale ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --配送单汇总 set @sql = 'insert into t_int_sap_drysalesinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,ZYWDAT,ZTYPE,ZCXLX,ZJYFS,VVTYP,MATNR,' + ' MENGE,MEINS,PRICE,SKTAK,SKTBT,TMWSTS,GTTAX,WAERS,ZTOLAMT,ZTSDAT,ZGZDAT,ZYZLX,' + ' ZFNAME,ZUNFLG,VBELN,KUNNR,KUNWE,MWSKZ)' + 'select ''' + @createdate + ''' as CreateDate,''F01'' as IFTYPE,FinaCode as BUKRS,''2Y00'' as WERKS,''1'' as ZSIGN,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F01'' as ZTYPE,''Z30'' as ZCXLX,''Z20'' as ZJYFS,'''' as VVTYP,ClsCode as MATNR,' + ' Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,ZpAmount as PRICE,ZpAmount as SKTAK,0 as SKTBT,TaxAmount as TMWSTS,0 as GTTAX,''CNY'' as WAERS,0 as ZTOLAMT,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,' + ' '''' as ZFNAME,case when Counts < 0 then ''Y'' else '''' end as ZUNFLG,BillNo as VBELN,ShopCode as KUNNR,ShopCode as KUNWE,case JTaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end as MWSKZ' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,body.JTaxRate,' + ' sum(body.ZpAmount) as ZpAmount,sum(body.ZpAmount-body.ZpNetAmount) as TaxAmount,sum(body.ZpCount) as Counts,shop.OrgType' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate is not null and head.AccDate <> ''''' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount <> 0' + ' and exists (select OrgCode from t_shop a, t_financial_body b where a.FinaCode = b.FinaCode and a.OrgCode = head.ShopCode and b.FinaType = ''1'')' + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType,body.JTaxRate' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总配送销售失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drysalesinfo set DOCNO = 'PSX' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F01' and ZJYFS = 'Z20' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_dist_chg' and xtype='p') drop procedure p_int_gen_dist_chg go create procedure p_int_gen_dist_chg ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --配送单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,SLTWR,' + ' WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,VBELN,KUNNR,KUNWE,UNFLG)' + 'select ''' + @createdate + ''' as CreateDate,''F11'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,''2Y00'' as WERKS,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F11'' as ZTYPE,ClsCode as MATNR,''Z20'' as ZJYFS,NetCost as SLTWR,' + ' ''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,' + ' case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,BillNo as VBELN,ShopCode as KUNNR,ShopCode as KUNWE,case when Counts < 0 then ''Y'' else '''' end as UNFLG' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.ZpCount) as Counts,shop.OrgType' + ' from t_dist_head head, t_dist_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' and body.ZpCount <> 0' + ' and exists (select OrgCode from t_shop a, t_financial_body b where a.FinaCode = b.FinaCode and a.OrgCode = head.ShopCode and b.FinaType = ''1'')' + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.ShopCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总配送成本失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'PSC' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F11' and ZJYFS = 'Z20' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_out_trans' and xtype='p') drop procedure p_int_gen_out_trans go create procedure p_int_gen_out_trans ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --调拨单汇总 set @sql = 'insert into t_int_sap_drytransferinfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,SDWRK,SPRCTR,WERKS,PRCTR,ZYWDAT,' + ' ZTYPE,MATNR,ZJYFS,SLTWR,WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZYZLX,UNFLG)' + 'select ''' + @createdate + ''' as CreateDate,''F06'' as IFTYPE,FinaCode as BUKRS, ''1'' as ZSIGN,OutOrgCode as SDWRK,''P''+FinaCode+''1''+OutOrgCode as SPRCTR,InOrgCode as WERKS,''P''+FinaCode+''1''+InOrgCode as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,' + ' ''F06'' as ZTYPE,ClsCode as MATNR,''Z01'' as ZJYFS,NetCost as SLTWR,''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,'''' as UNFLG' + ' from (' + ' select head.AccDate,shop.FinaCode,head.OutOrgCode,head.InOrgCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts,shop.OrgType' + ' from t_outtrans_head head, t_outtrans_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OutOrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.BillType = ''1''' + ' and head.IsOut = ''1''' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.AccDate,shop.FinaCode,head.OutOrgCode,head.InOrgCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总调拨明细失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drytransferinfo set DOCNO = 'DBD' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F06' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_wh_sale' and xtype='p') drop procedure p_int_gen_wh_sale go create procedure p_int_gen_wh_sale ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --批发销售单汇总 set @sql = 'insert into t_int_sap_drysalesinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,ZYWDAT,ZTYPE,ZCXLX,ZJYFS,VVTYP,MATNR,' + ' MENGE,MEINS,PRICE,SKTAK,SKTBT,TMWSTS,GTTAX,WAERS,ZTOLAMT,ZTSDAT,ZGZDAT,ZYZLX,' + ' ZFNAME,ZUNFLG,VBELN,KUNNR,KUNWE,MWSKZ)' + 'select ''' + @createdate + ''' as CreateDate,''F01'' as IFTYPE,FinaCode as BUKRS,''2Y00'' as WERKS,''1'' as ZSIGN,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F01'' as ZTYPE,''Z30'' as ZCXLX,''Z21'' as ZJYFS,'''' as VVTYP,ClsCode as MATNR,' + ' Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,PfTotal as PRICE,PfTotal as SKTAK,0 as SKTBT,TaxAmount as TMWSTS,0 as GTTAX,''CNY'' as WAERS,0 as ZTOLAMT,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,' + ' '''' as ZFNAME,'''' as ZUNFLG,BillNo as VBELN,CustCode as KUNNR,CustCode as KUNWE,case STaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end as MWSKZ' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1 as ClsCode,plu.STaxRate,' + ' sum(body.PfTotal) as PfTotal,sum(body.PfTotal - body.NetPfTotal) as TaxAmount,sum(body.Counts) as Counts,shop.OrgType' + ' from t_whsale_head head, t_whsale_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1,shop.OrgType,plu.STaxRate' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总批发销售失败' return(-1) end --批发退货单汇总 set @sql = 'insert into t_int_sap_drysalesinfo' + ' (CREATEDATE,IFTYPE,BUKRS,WERKS,ZSIGN,PRCTR,ZYWDAT,ZTYPE,ZCXLX,ZJYFS,VVTYP,MATNR,' + ' MENGE,MEINS,PRICE,SKTAK,SKTBT,TMWSTS,GTTAX,WAERS,ZTOLAMT,ZTSDAT,ZGZDAT,ZYZLX,' + ' ZFNAME,ZUNFLG,VBELN,KUNNR,KUNWE,MWSKZ)' + 'select ''' + @createdate + ''' as CreateDate,''F01'' as IFTYPE,FinaCode as BUKRS,''2Y00'' as WERKS,''1'' as ZSIGN,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F01'' as ZTYPE,''Z30'' as ZCXLX,''Z21'' as ZJYFS,'''' as VVTYP,ClsCode as MATNR,' + ' Counts as MENGE,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,PfTotal as PRICE,PfTotal as SKTAK,0 as SKTBT,TaxAmount as TMWSTS,0 as GTTAX,''CNY'' as WAERS,0 as ZTOLAMT,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,' + ' '''' as ZFNAME,''Y'' as ZUNFLG,BillNo as VBELN,CustCode as KUNNR,CustCode as KUNWE,case STaxRate when 0 then ''X0'' when 17 then ''X1'' when 13 then ''X2'' when 2 then ''X3'' when 6 then ''X4'' when 11 then ''X5'' when 16 then ''X7'' when 10 then ''X8'' when 9 then ''X9'' end as MWSKZ' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1 as ClsCode,plu.STaxRate,' + ' sum(-body.PfTotal) as PfTotal,sum(body.NetPfTotal - body.PfTotal) as TaxAmount,sum(body.ZrTotal-body.PfTotal) as SsTotal,sum(-body.Counts) as Counts,shop.OrgType' + ' from t_whreturn_head head, t_whreturn_body body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate is not null and head.AccDate <> ''''' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1,shop.OrgType,plu.STaxRate' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总批发退货失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_drysalesinfo set DOCNO = 'PFX' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F01' and ZJYFS = 'Z21' and DOCNO is null set @psmsg = '' return (1) end go if exists (select name from sysobjects where name='p_int_gen_wh_chg' and xtype='p') drop procedure p_int_gen_wh_chg go create procedure p_int_gen_wh_chg ( @psorgcode varchar(10), @psaccdate varchar(10), @psmsg varchar(2000) out ) as begin declare @where varchar(2000) declare @sql varchar(5000) declare @createdate varchar(20) declare @tsdat varchar(10) set @where = '' set @createdate = convert(varchar(20),getdate(),120) set @tsdat = convert(varchar(8),getdate(),112) if @psorgcode <> '' and @psorgcode is not null and @psorgcode <> '*' begin set @where = ' and head.OrgCode = ''' + @psorgcode + '''' end --批发销售单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,SLTWR,' + ' WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG,VBELN,KUNNR,KUNWE)' + 'select ''' + @createdate + ''' as CreateDate,''F11'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,''2Y00'' as WERKS,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F11'' as ZTYPE,ClsCode as MATNR,''Z21'' as ZJYFS,NetCost as SLTWR,' + ' ''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,'''' as UNFLG,BillNo as VBELN,CustCode as KUNNR,CustCode as KUNWE' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1 as ClsCode,' + ' sum(body.NetCost) as NetCost,sum(body.Counts) as Counts,shop.OrgType' + ' from t_whsale_head head, t_whsale_body2 body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总批发销售成本失败' return(-1) end --批发退货单汇总 set @sql = 'insert into t_int_sap_inventorychginfo' + ' (CREATEDATE,IFTYPE,BUKRS,ZSIGN,WERKS,PRCTR,ZYWDAT,ZTYPE,MATNR,ZJYFS,SLTWR,' + ' WEARS,MENGE,DWERT,MEINS,ZTSDAT,ZGZDAT,ZCSBS,ZYZLX,UNFLG,VBELN,KUNNR,KUNWE)' + 'select ''' + @createdate + ''' as CreateDate,''F11'' as IFTYPE,FinaCode as BUKRS,''1'' as ZSIGN,''2Y00'' as WERKS,''P''+FinaCode+''1''+''2Y00'' as PRCTR,replace(AccDate,''-'','''') as ZYWDAT,''F11'' as ZTYPE,ClsCode as MATNR,''Z21'' as ZJYFS,NetCost as SLTWR,' + ' ''CNY'' as WEARS,Counts as MENGE,0 as DWERT,case ClsCode when ''2018'' then ''L'' else ''EA'' end as MEINS,''' + @tsdat + ''' as ZTSDAT,replace(AccDate,''-'','''') as ZGZDAT,''X'' as ZCSBS,case OrgType when ''1'' then ''DO'' else ''COCO'' end as ZYZLX,'''' as UNFLG,BillNo as VBELN,CustCode as KUNNR,CustCode as KUNWE' + ' from (' + ' select head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1 as ClsCode,' + ' sum(-body.NetCost) as NetCost,sum(-body.Counts) as Counts,shop.OrgType' + ' from t_whreturn_head head, t_whreturn_body2 body, t_shop shop, t_plu plu, t_gclass class' + ' where head.BillNo = body.BillNo' + ' and head.OrgCode = shop.OrgCode' + ' and body.PluCode = plu.PluCode' + ' and plu.ClsCode = class.ClsCode' + ' and head.AccDate = ''' + @psaccdate + '''' + @where + ' group by head.BillNo,head.AccDate,shop.FinaCode,head.OrgCode,head.CustCode,class.UpperCode1,shop.OrgType' + ' ) a' exec(@sql) if @@error <>0 begin set @psmsg = '汇总批发退货成本失败' return(-1) end --更新零管单号(3位业务前缀+6位日期+6流水号,物理记录) update t_int_sap_inventorychginfo set DOCNO = 'PFC' + ZYWDAT + convert(varchar(10),SERIALNO) where IFTYPE = 'F11' and ZJYFS = 'Z21' and DOCNO is null set @psmsg = '' return (1) end go