'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,Total as PRICE,Total as SKTAK,0 as SKTBT,round(Total-Total/(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(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,'+
'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,'+
'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'+
'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,'+
'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-<2D>ֽ𣬸<D6BD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BOSϵͳֱ<CDB3><D6B1><EFBFBD>·<EFBFBD>
' and pay.ITEM_ID like ''20%'''+-- ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
' and pay.BUSINESS_DATE > ''2023-09-15'''+
' and pay.BUSINESS_DATE = '''+@psaccdate+''''+@where+
' group by pay.BUSINESS_DATE,shop.FinaCode,pay.WERKS'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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,''JB'' 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'+
'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,''JB'' 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'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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'+
'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,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'+
'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'+
'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'+