SBO库位实现方案

简单的动态库位管理解决方案

   第一步:在仓库主数据上添加自定义字段:CH_WhSh,描述:“需要库位管理”。

SBO库位实现方案_第1张图片

 

第二步:在营销凭证-行里面,添加两个自定义字段:CH_FrShCH_ToSh,如下图:

[转帖]SBO库位实现方案 - Mr.Яi�困�t - Up得就Up

 

[转帖]SBO库位实现方案 - Mr.Яi�困�t - Up得就Up

  

第三步:打开公司数据库,新建一个查询,复制入下列代码并运行

create table [@CHSH]

(TransNum int PRIMARY KEY, WhShelf nvarchar(20))

 

第四步:打开公司数据库,新建一个查询,复制入下列代码并运行:

 

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

CREATE PROCEDURE CH_AddShInfo

   @object_type nvarchar(25),             

   @list_of_cols_val_tab_del nvarchar(255)

 

AS

 

BEGIN

  declare @sql_str nvarchar(2000)

  declare @str     nvarchar(20)

  if @object_type=20 set @str='PDN1'

  if @object_type=18 set @str='PCH1'

  if @object_type=59 set @str='IGN1'

  if @object_type=16 set @str='RDN1'

  if @object_type=14 set @str='RIN1'

  if @object_type=15 set @str='DLN1'

  if @object_type=13 set @str='INV1'

  if @object_type=60 set @str='IGE1'

  if @object_type=21 set @str='RPD1'

  if @object_type=19 set @str='RPC1'

  if @object_type=67 set @str='WTR1'

 

 set @sql_str='INSERT INTO [@CHSH] (TransNum, WhShelf) SELECT OINM.TransNum, CASE WHEN oinm.inqty > 0

                THEN t1.U_CH_tosh ELSE t1.u_ch_frsh END AS sh FROM OINM LEFT OUTER JOIN

                ' + @str + ' AS t1 ON OINM.DocLineNum = t1.LineNum AND OINM.CreatedBy = t1.DocEntry

                WHERE (OINM.TransType = ' + @object_type + ') AND (OINM.InQty > 0) AND (OINM.CreatedBy =

                ' + @list_of_cols_val_tab_del + ') AND (OINM.Warehouse IN (SELECT WhsCode FROM OWHS

                WHERE (U_CH_WhSh = 1))) OR (OINM.TransType = ' + @object_type + ') AND (OINM.CreatedBy =

                ' + @list_of_cols_val_tab_del + ') AND (OINM.OutQty > 0) AND (OINM.Warehouse IN

                (SELECT WhsCode FROM OWHS AS OWHS_1 WHERE (U_CH_WhSh = 1)))'

  exec (@sql_str)

END

GO

 

第五步:打开公司数据库,新建一个查询,复制入下列代码,并运行:

 

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

CREATE FUNCTION CH_InquireQty

(

    @ItemCode nvarchar(20),

    @DocDate  datetime,

    @WhsCode  nvarchar(8),

    @WhShelf  nvarchar(20)

)

RETURNS numeric(19, 6)

AS

BEGIN

   

    DECLARE @qty numeric(19, 6)

 

    select @qty=SUM(OINM.InQty - OINM.OutQty) FROM [@CHSH] RIGHT OUTER JOIN

         OINM ON [@CHSH].TransNum = OINM.TransNum WHERE (OINM.ItemCode = @ItemCode) AND (OINM.DocDate <=

         @DocDate) AND (OINM.Warehouse = @WhsCode) AND ([@CHSH].WhShelf = @WhShelf)

 

    if @qty is null set @qty=0

    RETURN @qty

 

END

GO

 

第六步:打开公司数据库,新建一个查询,复制入如下代码,并运行:

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

 

 

 

Create FUNCTION [dbo].[CH_CheckError]

(

    @object_type nvarchar(25), 

    @list_of_cols_val_tab_del nvarchar(255)

)

RETURNS int

AS

BEGIN

    declare @ch_getvalue int

    declare @WhsCode     nvarchar(8)

    declare @ItemCode    nvarchar(20)

    declare @DocDate     datetime

    declare @Sh          nvarchar(20)

    declare @qty         numeric(19, 6)

    declare @LineNum     int

 

    set @ch_getvalue=0

 

    if @object_type<>67   --不是库存转储时,代码基本相同

    begin

      if @object_type=20

         begin

         SELECT top(1) @ch_getvalue= LineNum +1 FROM PDN1 WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del) AND (U_CH_ToSh IS NULL)

         goto endlabel

         end

 

      if @object_type=18

         begin

         SELECT top(1) @ch_getvalue= LineNum +1 FROM PCH1 WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del) AND (U_CH_ToSh IS NULL)

         goto endlabel

         end

 

      if @object_type=59

         begin

         SELECT top(1) @ch_getvalue= LineNum +1 FROM IGN1 WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del) AND (U_CH_ToSh IS NULL)

         goto endlabel

         end

 

      if @object_type=16

         begin

         SELECT top(1) @ch_getvalue= LineNum +1 FROM RDN1 WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del) AND (U_CH_ToSh IS NULL)

         goto endlabel

         end

 

      if @object_type=14

         begin

         SELECT top(1) @ch_getvalue= LineNum +1 FROM RIN1 WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del) AND (U_CH_ToSh IS NULL)

         goto endlabel

         end

 

      if @object_type=15

       begin

         declare new_Doc cursor for

         select linenum,whscode,ItemCode,docdate,U_CH_FrSh,quantity from DLN1

         WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del)

       end

 

      if @object_type=13

       begin

         declare new_Doc cursor for

         select linenum,whscode,ItemCode,docdate,U_CH_FrSh,quantity from INV1

         WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del)

       end

 

      if @object_type=60

       begin

         declare new_Doc cursor for

         select linenum,whscode,ItemCode,docdate,U_CH_FrSh,quantity from IGE1

         WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del)

       end

 

      if @object_type=21

       begin

         declare new_Doc cursor for

         select linenum,whscode,ItemCode,docdate,U_CH_FrSh,quantity from RPD1

         WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del)

       end

 

      if @object_type=19

       begin

         declare new_Doc cursor for

         select linenum,whscode,ItemCode,docdate,U_CH_FrSh,quantity from RPC1

         WHERE (WhsCode IN (SELECT WhsCode FROM OWHS WHERE (U_CH_WhSh = 1))) AND (DocEntry = @list_of_cols_val_tab_del)

       end

     

      open new_doc

      fetch next from new_doc

      into @LineNum,@WhsCode,@ItemCode,@DocDate,@Sh,@qty

     

      WHILE @@FETCH_STATUS = 0

      begin

        if len(@sh)>0

        begin

          if @qty>dbo.CH_InquireQty(@ItemCode,@DocDate,@WhsCode,@sh)

            begin

             set @ch_getvalue=@LineNum+1

             goto endlabel

            end

        end

        else

        begin

          set @ch_getvalue=@LineNum+1

          goto endlabel

        end

  

        fetch next from new_doc

        into @LineNum,@WhsCode,@ItemCode,@DocDate,@Sh,@qty

      end

      close new_doc

      DEALLOCATE new_doc

     end

    else   --库存转储的情形

    begin

      declare @filler nvarchar(8)

      declare @wh1    int

      declare @wh2    int

      declare @sh2    nvarchar(20)

 

      declare new_doc cursor for

      SELECT WTR1.LineNum, OWTR.DocDate, OWTR.Filler, WTR1.Quantity, WTR1.WhsCode, WTR1.ItemCode, OWHS.U_CH_WhSh,

      OWHS_1.U_CH_WhSh AS FrWh, WTR1.U_CH_FrSh, WTR1.U_CH_ToSh FROM  OWHS AS OWHS_1 RIGHT OUTER JOIN

      OWTR ON OWHS_1.WhsCode = OWTR.Filler RIGHT OUTER JOIN WTR1 INNER JOIN

      OWHS ON WTR1.WhsCode = OWHS.WhsCode ON OWTR.DocEntry = WTR1.DocEntry WHERE (WTR1.DocEntry = @list_of_cols_val_tab_del)

     

      open new_doc

      fetch next from new_doc

      into @LineNum,@DocDate,@filler,@qty,@WhsCode,@ItemCode,@wh1,@wh2,@Sh,@sh2

 

      WHILE @@FETCH_STATUS = 0

      begin

        if @wh2=1

          begin

          if  len(@sh)>0

          begin

            if @qty>dbo.CH_InquireQty(@ItemCode,@DocDate,@filler,@sh)

            begin

             set @ch_getvalue=@LineNum+1

             goto endlabel

            end

          end

          else

          begin

            set @ch_getvalue=@LineNum+1

            goto endlabel

          end

          end

        if @wh1=1 and ((@sh2 is null) or len(@sh2)=0)

          begin

            set @ch_getvalue=@LineNum+1

            goto endlabel

          end

      fetch next from new_doc

      into @LineNum,@DocDate,@filler,@qty,@WhsCode,@ItemCode,@wh1,@wh2,@Sh,@sh2

      end

      close new_doc

      DEALLOCATE new_doc

    end

 

endlabel:

    return @ch_getvalue

END

 

 

第七步:打开系统的存储过程:SBO_SP_TransactionNotification,把下面蓝色字体的部分插入存储过程中,并运行:

---以下为库位管理所需代码,如果有其它限定条件,则把此段代码放在其它限定条件之后!----

declare @ch_getvalue int

 

if (@object_type=20 or @object_type=18 or @object_type=59 or @object_type=16 or @object_type=14 or @object_type=67

    or @object_type=15 or @object_type=13 or @object_type=60 or @object_type=21 or @object_type=19)

    and @transaction_type='A'

begin

  set @ch_getvalue=dbo.CH_CheckError(@object_type,@list_of_cols_val_tab_del)

  if @ch_getvalue >0

  begin

     set @error=1

     set @error_message=N'' + cast(@ch_getvalue as nvarchar(20)) +N'行必需填写有效的库位信息,该仓库需要库位管理,或该库位已经无余额!'

  end   

  if @error=0

    exec CH_AddShInfo @object_type,@list_of_cols_val_tab_del

end

---以上为库位管理所需代码-------------------------------------------------------------

 

第八步:准备一些报表,供客户查询有关的库位信息。(把蓝色字体部分复制到查询管理器中)

1、  查询物料存放库位实时信息:

declare @int as int

declare @item as nvarchar(20)

declare @wh   as nvarchar(8)

select @int=count(*) from pdn1 t2 where t2.itemcode='[%0]' and t2.whscode='[%1]'

set @item ='[%0]'

set @wh='[%1]'

 

SELECT     OWHS.WhsCode as 仓库代码, OWHS.WhsName as 仓库名称, derivedtbl_1.ItemCode as 物料号, OITM.ItemName as 物料名称, derivedtbl_1.WhShelf AS 库位, derivedtbl_1.qty AS 结存数量

FROM         (SELECT     t0.Warehouse, t0.ItemCode, t1.WhShelf, SUM(t0.InQty - t0.OutQty) AS qty

                       FROM          [@CHSH] AS t1 RIGHT OUTER JOIN

                                              OINM AS t0 ON t1.TransNum = t0.TransNum

                       WHERE     (t0.TransNum IN

                                                  (SELECT DISTINCT TransNum

                                                    FROM          [@CHSH]))

                       GROUP BY t0.Warehouse, t0.ItemCode, t1.WhShelf

                       HAVING      (t0.ItemCode = @item OR @item='') AND (t0.Warehouse = @wh or @wh='') AND (SUM(t0.InQty - t0.OutQty) > 0)) AS derivedtbl_1 LEFT OUTER JOIN

                      OWHS ON derivedtbl_1.Warehouse = OWHS.WhsCode LEFT OUTER JOIN

                      OITM ON derivedtbl_1.ItemCode = OITM.ItemCode

 

 

2、  物料库位过账明细清单

declare @int as int

declare @item as nvarchar(20)

declare @wh   as nvarchar(8)

declare @dte1 as datetime

declare @dte2 as datetime

declare @sh   as nvarchar(20)

 

 

select @int=count(*) from pdn1 t4 where t4.itemcode='[%0]' and t4.whscode='[%1]' and t4.docdate>='[%2]' and t4.docdate<='[%3]' and t4.u_ch_frsh='[%4]'

set @item ='[%0]'

set @wh='[%1]'

set @dte1='[%2]'

set @dte2='[%3]'

set @sh='[%4]'

 

 

SELECT     t0.TransNum as 序号, case t0.TransType  when 20 then N'收货采购订单' when 18 then N'应付发票'

     when 59 then N'库存生产收货' when 16 then N'销售退货' when 14 then N'应收贷项凭证' when 15 then N'销售交货'

     when 13 then N'应收发票' when 60 then N'库存生产发货' when 21 then N'采购退货' when 19 then N'应付贷项凭证'

     when 67 then N'库存转储' end as 交易种类, t0.BASE_REF as 单据号码, t1.WhsCode as 仓库代码, t1.WhsName as 仓库名称, t3.WhShelf AS 库位, t0.InQty as 收货数量, t0.OutQty as 发出数量, t0.ItemCode as 物料代码, t0.Dscription as 物料名称

FROM         OWHS AS t1 RIGHT OUTER JOIN

                      OINM AS t0 ON t1.WhsCode = t0.Warehouse LEFT OUTER JOIN

                      [@CHSH] AS t3 ON t0.TransNum = t3.TransNum

WHERE     (t0.TransNum IN

                          (SELECT     TransNum

                            FROM          [@CHSH] AS [@CHSH_1])) AND (t0.ItemCode = @item or @item='') AND (t0.DocDate >= @dte1 or @dte1='') AND

                      (t0.DocDate <= @dte2 or @dte2='') AND (t0.Warehouse = @wh or @wh='') and (t3.WhShelf = @sh or @sh='')

 

 

3、  物料库位过账汇总表

 

declare @int as int

declare @item as nvarchar(20)

declare @wh   as nvarchar(8)

declare @dte1 as datetime

declare @dte2 as datetime

declare @sh   as nvarchar(20)

 

 

select @int=count(*) from pdn1 t4 where t4.itemcode='[%0]' and t4.whscode='[%1]' and t4.docdate>='[%2]' and t4.docdate<='[%3]' and t4.u_ch_tosh='[%4]'

set @item ='[%0]'

set @wh='[%1]'

set @dte1='[%2]'

set @dte2='[%3]'

set @sh='[%4]'

 

 

 

SELECT     t5.ItemCode AS 物料代码, OITM.ItemName AS 物料名, t5.Warehouse AS 仓库代码, OWHS.WhsName AS 仓库名, t5.WhShelf AS 库位, t5.期初数,

                      t5.本期收到数, t5.本期发出数, t5.期末结存数

FROM         (SELECT     ItemCode, Warehouse, WhShelf, SUM(CASE WHEN t4.docdate < @dte1 THEN t4.inqty - t4.outqty ELSE 0 END) AS 期初数,

                                              SUM(CASE WHEN t4.docdate >= @dte1 THEN t4.inqty ELSE 0 END) AS 本期收到数,

                                              SUM(CASE WHEN t4.docdate >= @dte1 THEN t4.outqty ELSE 0 END) AS 本期发出数, SUM(InQty - OutQty) AS 期末结存数

                       FROM          (SELECT     t0.ItemCode, t0.Warehouse, t3.WhShelf, t0.DocDate, t0.InQty, t0.OutQty

                                               FROM          OINM AS t0 LEFT OUTER JOIN

                                                                      [@CHSH] AS t3 ON t0.TransNum = t3.TransNum

                                               WHERE      (t0.TransNum IN

                                                                          (SELECT     TransNum

                                                                            FROM          [@CHSH] AS [@CHSH_1])) AND (t0.ItemCode = @item or @item='') AND (t0.DocDate <= @dte2) AND (t0.Warehouse = @wh or @wh='') AND

                                                                      (t3.WhShelf = @sh or @sh='')) AS t4

                       GROUP BY ItemCode, Warehouse, WhShelf) AS t5 LEFT OUTER JOIN

                      OITM ON t5.ItemCode = OITM.ItemCode LEFT OUTER JOIN

                      OWHS ON t5.Warehouse = OWHS.WhsCode

ORDER BY 仓库代码, 库位, 物料代码

 

第九步:可以添加一个格式化搜索,以供用户在输入发货库位和收货库位的时候,从已经发生的业务中选择库位。(注意:参数取值根据单据需要改为不同的值)

SELECT     t1.WhShelf AS 库位, SUM(t0.InQty - t0.OutQty) AS 结存数量

FROM         [@CHSH] AS t1 RIGHT OUTER JOIN

                      OINM AS t0 ON t1.TransNum = t0.TransNum

WHERE     (t0.Warehouse = $[$13.15.0]) AND (t0.ItemCode =$[$13.1.0] )

GROUP BY t1.WhShelf

 

HAVING      (NOT (t1.WhShelf IS NULL))

for browse

你可能感兴趣的:(职场,休闲,Sbo,SBO;库位,sbo知识)