当前位置: 首页 > news >正文

ERP系统各种单据流水号的产生方案

        ERP系统单据流水号是整个业务的一个重要凭证,并且都是唯一的。这些单据流水号可能包含的信息有日期信息、操作员信息等,而且每个客户都有自己的单据编码规范。本篇就介绍如何来产生这类单据流水号。主要应用的还是字符串的拼接技术。

1、简单的单据号产生办法:  
     declare @ord_id varchar(20)
       select  @ord_id=max(ord_id) from Toc_AdviseOrder
       if @ord_id is null
         set @ord_id='DJH10000001'
       else

          set @ord_id='DJH'+convert(varchar(8),right(10000000+convert(int,substring(@ord_id,5,11))+1,8))

2、具有商业价值的的解决方案:
例如:
create proc [dbo].CreateSequenceNumber
@custId   varchar(20) ,                  --客户编号
@typeFlag char(3),                        --业务类型
@outputId       varchar(30) output  --输出单据号
as

declare @l int,
        @Y char(2),
        @OutPutId varchar(20), --输出客户编号
        @CustIdFormat varchar(20)
select top 1 @l=len(custId) from customers where custUp='0'
select @Y=Y from Years

if @typeFlag='1'  --订货单
begin
     if @custId='0'
        begin
          select @OutPutId=max(ord_id) from [order] where len(cst_id)=@l and substring(ord_id,1,6)='DHDA'+@Y and len(ord_id)=15
          if @OutPutId is null
             set @OutPutId='DHDA'+@Y+'000000001'
          else
             set @OutPutId='DHDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(ord_id) from [order] inner join Customers on [order].cst_id=Customers.custId
     where
[email=[ft=,2,]custup=@custId]custup=@custId[/email] and len(ord_id)=15 and substring(ord_id,1,3) = 'DHD'
   if @OutPutId is null
      set @OutPutId='DHD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='DHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end      
end
if @typeFlag='2' --发货单
begin
     if @custId='0'
        begin
          select @OutPutId=max(sal_id) from sales where len(cust_id)=@l and substring(sal_id,1,6)='FHDA'+@Y and len(sal_id)=15
          if @OutPutId is null
             set @OutPutId='FHDA'+@Y+'000000001'
          else
             set @OutPutId='FHDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(sal_id) from sales inner join Customers on sales.cust_id=Customers.custId
     where
[email=[ft=,2,]custup=@custId]custup=@custId[/email] and len(sal_id)=15 and substring(sal_id,1,3) = 'FHD'
   if @OutPutId is null
      set @OutPutId='FHD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='FHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end
if @typeFlag='3' --退货单
begin
     if @custId='0'
        begin
          select @OutPutId=max(back_id) from Backs where len(cust_id)=@l and substring(back_id,1,6)='THDA'+@Y and len(back_id)=15
          if @OutPutId is null
             set @OutPutId='THDA'+@Y+'000000001'
          else
             set @OutPutId='THDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(back_id) from Backs inner join Customers on Backs.cust_id=Customers.custId
     where
[email=[ft=,2,]custup=@custId]custup=@custId[/email] and len(back_id)=15 and substring(back_id,1,3) = 'THD'
   if @OutPutId is null
      set @OutPutId='THD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='THD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end
if @typeFlag='4' --入库单
begin
     if @custId='0'
        begin
          select @OutPutId=max(rkd_id) from Rukudan inner join StorageType
             on Rukudan.Storagetype=StorageType.id and custId='0'
               where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and substring(rkd_id,1,6)='RKDA'+@Y and len(rkd_id)=15
          if @OutPutId is null
             set @OutPutId='RKDA'+@Y+'000000001'
          else
             set @OutPutId='RKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(rkd_id) from Rukudan
                inner join StorageType on StorageType.id=Rukudan.StorageType
        where
[email=[ft=,2,]CustId=@custId]CustId=@custId[/email] and len(rkd_id)=15 and substring(rkd_id,1,3) = 'RKD'
   if @OutPutId is null
      set @OutPutId='RKD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='RKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end


if @typeFlag='6' --移库单
begin
     if @custId='0'
        begin
          select @OutPutId=max(StockMoveID) from StockMove inner join StorageType
             on StockMove.StockOut=StorageType.id and custId='0'
               where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and substring(StockMoveID,1,6)='ZKDA'+@Y  
                and len(StockMoveID)=15
          if @OutPutId is null
             set @OutPutId='ZKDA'+@Y+'000000001'
          else
             set @OutPutId='ZKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(StockMoveID) from StockMove inner join StorageType
                  on StockMove.StockOut=StorageType.id or stockMove.StockIn=StorageType.id
     where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and len(StockMoveID)=15 and substring(StockMoveID,1,3) = 'ZKD'
   if @OutPutId is null
      set @OutPutId='ZKD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='ZKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end

if @typeFlag='7' --调货单
begin

     set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
      select @OutPutId=max(ChId) from ChProduct inner join Customers
         on ChProduct.OutCustId=Customers.custId  
           where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and substring(ChId,1,3) = 'CHD' and len(ChId)=15
      if @OutPutId is null
         set @OutPutId='CHD'+@Y+@CustIdFormat+'00001'
      else
         set @OutPutId='CHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))    

end
if @typeFlag='8' --盘点单
begin
     if @custId='0'
        begin
          select @OutPutId=max(pandianId) from  PanDian inner join StorageType
             on PanDian.StorageId=StorageType.id and custId='0'
               where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and substring(pandianId,1,6)='PDDA'+@Y and len(pandianId)=15
          if @OutPutId is null
             set @OutPutId='PDDA'+@Y+'000000001'
          else
             set @OutPutId='PDDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(pandianId) from PanDian
                inner join StorageType on StorageType.id=PanDian.StorageId
        where
[email=[ft=,2,]CustId=@custId]CustId=@custId[/email] and len(pandianId)=15 and substring(pandianId,1,3) = 'PDD'
   if @OutPutId is null
      set @OutPutId='PDD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='PDD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end

if @typeFlag='9' --盈亏单
begin
     if @custId='0'
        begin
          select @OutPutId=max(yk_id) from  YingKui inner join StorageType
             on YingKui.storageid=StorageType.id and custId='0'
               where
[email=[ft=,2,]custId=@custId]custId=@custId[/email] and substring(yk_id,1,6)='YKDA'+@Y and len(yk_id)=15
          if @OutPutId is null
             set @OutPutId='YKDA'+@Y+'000000001'
          else
             set @OutPutId='YKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9))
        end
     else  --分销
       begin
          set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId)
   select @OutPutId=max(yk_id) from YingKui
                inner join StorageType on StorageType.id=YingKui.storageid
        where
[email=[ft=,2,]CustId=@custId]CustId=@custId[/email] and len(yk_id)=15 and substring(yk_id,1,3) = 'YKD'
   if @OutPutId is null
      set @OutPutId='YKD'+@Y+@CustIdFormat+'00001'
   else
    set @OutPutId='YKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5))
       end  
end
SET @outputId= @OutPutId

转载于:https://www.cnblogs.com/silverLee/archive/2009/11/05/1596656.html

相关文章:

  • WebSocket在spring messagemapping下获取httpsession
  • 图片的动画 ease.js
  • [翻译].net 2.0(c#)下简单的FTP应用程序(转)
  • Python Unicode 转换 字符串
  • java中关于、、|、||之间的区别和运算
  • 生成静态页面的方法
  • 项目质量量化考核建议
  • Linux命令(磁盘的卸载与挂载)
  • 手势识别论文解读
  • 用于在弹出窗口中计算窗口位置的函数
  • 《领域特定语言》一2.2为何需要DSL
  • 关注数据中心NFV性能
  • 取页面内各种尽寸数据。备档
  • Kotlin和Java EE系列之—— 如何让Kotlin类对Java EE友好
  • 多个项目共享一个app.config 的解决办法
  • “大数据应用场景”之隔壁老王(连载四)
  • 【翻译】babel对TC39装饰器草案的实现
  • 〔开发系列〕一次关于小程序开发的深度总结
  • 10个最佳ES6特性 ES7与ES8的特性
  • CSS相对定位
  • happypack两次报错的问题
  • python3 使用 asyncio 代替线程
  • Sass Day-01
  • Windows Containers 大冒险: 容器网络
  • 双管齐下,VMware的容器新战略
  • MiKTeX could not find the script engine ‘perl.exe‘ which is required to execute ‘latexmk‘.
  • const的用法,特别是用在函数前面与后面的区别
  • Hibernate主键生成策略及选择
  • ​Base64转换成图片,android studio build乱码,找不到okio.ByteString接腾讯人脸识别
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • #{} 和 ${}区别
  • #HarmonyOS:Web组件的使用
  • #传输# #传输数据判断#
  • #我与Java虚拟机的故事#连载13:有这本书就够了
  • (2)STL算法之元素计数
  • (Bean工厂的后处理器入门)学习Spring的第七天
  • (solr系列:一)使用tomcat部署solr服务
  • (草履虫都可以看懂的)PyQt子窗口向主窗口传递参数,主窗口接收子窗口信号、参数。
  • (二)JAVA使用POI操作excel
  • (二)springcloud实战之config配置中心
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • .[hudsonL@cock.li].mkp勒索病毒数据怎么处理|数据解密恢复
  • .bat批处理(六):替换字符串中匹配的子串
  • .NET Framework .NET Core与 .NET 的区别
  • .net mvc actionresult 返回字符串_.NET架构师知识普及
  • .NET 中 GetHashCode 的哈希值有多大概率会相同(哈希碰撞)
  • .Net(C#)常用转换byte转uint32、byte转float等
  • .NET6使用MiniExcel根据数据源横向导出头部标题及数据
  • .NET国产化改造探索(三)、银河麒麟安装.NET 8环境
  • .NET开源快速、强大、免费的电子表格组件
  • .net连接MySQL的方法
  • .net下简单快捷的数值高低位切换
  • .Net中的集合
  • .py文件应该怎样打开?
  • .ui文件相关