zoukankan      html  css  js  c++  java
  • 即时库存查询分析报表

    GO
    
    /****** Object:  StoredProcedure [dbo].[Cargill_inventroyandPrice]    Script Date: 7/2/2019 9:02:07 AM ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER proc [dbo].[Cargill_inventroyandPrice]
    @fbegstock  varchar(20),
    @fendstock  varchar(20),
    @fbegnumber varchar(20),
    @fendnumber varchar(20)
    
    
    as
    
    
    Set Nocount on
    Create Table #TempInventory( 
                                [FBrNo] [varchar] (10)  NOT NULL ,
                                [FItemID] [int] NOT NULL ,
                                [FBatchNo] [varchar] (200)  NOT NULL ,
                                [FMTONo] [varchar] (200)  NOT NULL ,
                                [FSupplyID] [int] NOT NULL ,
                                [FStockID] [int] NOT NULL ,
                                [FQty] [decimal](28, 10) NOT NULL ,
                                [FBal] [decimal](20, 2) NOT NULL ,
                                [FStockPlaceID] [int] NULL ,
                                [FKFPeriod] [int] NOT NULL Default(0),
                                [FKFDate] [varchar] (255)  NOT NULL ,
                                [FMyKFDate] [varchar] (255), 
                                [FStockTypeID] [Int] NOT NULL,
                                [FQtyLock] [decimal](28, 10) NOT NULL,
                                [FAuxPropID] [int] NOT NULL,
                                [FSecQty] [decimal](28, 10) NOT NULL,
                                [FHelpCode] [varchar](200) NOT NULL,
                                [FProperty] [int] NOT NULL Default(0),
                                [FChartNumber] [varchar](255) NOT NULL,
                                [FBatchNo2] [VarChar] (200) NOT NULL Default(''),
                                [FStockID2] [int]  NOT NULL Default(0),
    							fcaigoudate datetime,
    							fcurrency   varchar(20)
                                 )
    Insert Into #TempInventory Select u1.FBrNo,u1.FItemID,u1.FBatchNo,u1.FMTONo,u1.FSupplyID,u1.FStockID,u1.FQty,u1.FBal,u1.FStockPlaceID,
    u1.FKFPeriod,ISNULL(u1.FKFDate,''),ISNULL(u1.FKFDate,''),500,u1.FQtyLock,u1.FAuxPropID,u1.FSecQty,'',s.FProperty ,'','',0,'','' From ICInventory u1 left join t_stock s on u1.FStockID=s.FItemID  where u1.FQty<>0 
    
    Insert Into #TempInventory Select u1.FBrNo,u1.FItemID,u1.FBatchNo,u1.FMTONo,u1.FSupplyID,u1.FStockID,u1.FQty,u1.FBal,u1.FStockPlaceID,
    u1.FKFPeriod,ISNULL(u1.FKFDate,''),ISNULL(u1.FKFDate,''),u1.FStockTypeID,0,u1.FAuxPropID,u1.FSecQty,'',s.FProperty,'' ,'',0,'','' From POInventory u1 left join t_stock s on u1.FStockID=s.FItemID  where u1.FQty<>0 
    
    DECLARE @CalculateType AS INT 
    SELECT @CalculateType=FValue FROM t_SystemProfile WHERE FCategory='IC' AND FKey='CalculateType'
    
    
    UPDATE t1 SET FBatchNo2=(SELECT CASE t2.FTrack WHEN 80 THEN t1.FBatchNo WHEN 20309 THEN t1.FBatchNo ELSE '' END ), 
    FStockID2=(SELECT CASE @CalculateType 
    WHEN 0 THEN 0 WHEN 1 THEN t1.FStockID ELSE t3.FGroupID END)
    FROM  #TempInventory t1 
    INNER JOIN t_ICItem t2 ON t1.FItemID=t2.FItemID 
    INNER JOIN t_Stock  t3 ON t1.FStockID=t3.FItemID 
    
    
    Select distinct 
    t1.FName as FMaterialName,t1.FModel as FMaterialModel,
    u1.FBatchNo,t2.FName as FStockName,u1.FKFPeriod,
    case when isdate(u1.FKFDate)=1 then Convert(datetime,u1.FKFDate) else null end as FKFDate,
     t3.FName as FBUUnitName,
    t3.FNumber as FBUUnitNumber,ROUND(u1.FQty,t1.FQtydecimal) as FBUQty,
    Case when isdate(u1.FKFDate)=0 then NULL else Convert(datetime,u1.FKFDate) + u1.FKFPeriod END AS FMaturityDate,
     t2.FNumber AS FStockNumber ,t1.FNumber AS FMaterialNumber
     ,CASE WHEN  t2.FIncludeAccounting=1 THEN ISNULL(t20.FPrice,0) ELSE 0 END as FPrice,
     CASE WHEN t2.FIncludeAccounting=1 THEN ISNULL(t20.FPrice * t4.FCoefficient,0) ELSE 0 END as FCUPrice,
     CASE WHEN t2.FIncludeAccounting=1 THEN ISNULL(ROUND(t20.FPrice * u1.FQty,2),0) ELSE 0 END as FAmount  ,
     t1.FItemID ,isnull(u1.fcaigoudate ,'')fcaigoudate,isnull(fcurrency,'') fcurrency
    
     into #TempInventory1
    
    From #TempInventory u1 left join t_ICItem t1 on u1.FItemID = t1.FItemID
    left join t_Stock t2 on u1.FStockID=t2.FItemID
    left join t_Supplier t_8 on u1.FSupplyID=t_8.FItemID
    left join t_MeasureUnit t3 on t1.FUnitID=t3.FMeasureUnitID
    left join t_MeasureUnit t4 on t1.FStoreUnitID=t4.FMeasureUnitID
    left join t_StockPlace t5 on u1.FStockPlaceID=t5.FSPID
    left join t_AuxItem t9 on u1.FAuxPropID=t9.FItemID left join t_Measureunit t19 on t1.FSecUnitID=t19.FMeasureunitID   
    Left Join ICRealtimeCost t20 ON u1.FItemID=t20.FItemID AND u1.FBatchNo2=t20.FBatchNo AND u1.FStockID2=t20.FStockID  
    where (Round(u1.FQty,t1.FQtyDecimal)<>0 OR Round(u1.FQty/t4.FCoefficient,t1.FQtyDecimal)<>0) 
     and t1.FDeleted=0 
    
     AND t2.FTypeID in (500,20291,20293,504,505,501)
     Order By t2.fnumber,t1.FNumber,u1.FBatchNo 
    
    
     declare  @FcurrentYear varchar(10)
    
     declare  @Fcurrentperiod varchar(10)
    
     SELECT @FcurrentYear=  FValue   FROM t_SystemProfile WHERE FCategory='IC' AND   FKey='CurrentYear'
     
     SELECT @Fcurrentperiod=  FValue  FROM t_SystemProfile WHERE FCategory='IC' AND   FKey='CurrentPeriod'
    
    
      select FItemID  ,sum(FBegQty)FBegQty,sum(FBegBal)FBegBal  into #TempInventory2  
     from  ICBal 
     where  FPeriod =@Fcurrentperiod and  FYear =@FcurrentYear  and fitemid in 
     (select FItemID from #TempInventory1)
     group by FItemID 
    
      select FItemID  ,case when FBegQty  <>0 then  round( FBegBal /FBegQty ,6) else 0 end aaa into #TempInventory3  
     from  #TempInventory2 
    
    
     update a set a.FPrice =b.aaa from #TempInventory1 a inner join #TempInventory3 b on a.FItemID =b.FItemID 
    
    
      update c set c.FcuPrice =b.fprice  from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
      where a.FTranType =1
    
      update c set c.fcaigoudate  =a.FDate   from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
    
      where a.FTranType =1
    
      update c set c.FcuPrice =b.fprice   from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
      where a.FTranType =10
    
      update c set c.fcaigoudate  =a.FDate  from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
      where a.FTranType =10
    
      update c set c.fcaigoudate  =a.FDate from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
      where a.FTranType =2
    
       update c set c.FPrice =b.fprice  from ICStockBill  a 
      inner join ICStockBillentry b on a.FInterID =b.FInterID 
      inner join  #TempInventory1 c on c.FItemID =b.FItemID  and c.FBatchNo =b.FBatchNo 
      where a.FTranType =1 and c.FPrice =0 
     
     select FStockNumber  [CODE OF STORAGE WAREHOUSE] ,FStockName [DESCRIPTION OF STORAGE WAREHOUSE] ,
     FMaterialNumber [MATERIAL NUMBER] ,FMaterialName [PRODUCT CATEGORY] ,b.FModel [DESCRIPTION OF PRODUCT],	
        c.fname   [PRODUCT LINE],
    	F_103 [GIS PACKAGING CODE],
    	F_104 [GIS CODE],
    	F_105 [GIS NAME],
    	F_107 [PLANT FROM] ,FBatchNo [BATCH NUMBER] ,FBUUnitName [UNIT OF MATERIAL] ,FBUQty QTY ,
     FKFDate [DATE OF MANUFACTURE] ,a.FKFPeriod [SHELF LIFE] ,FMaturityDate [EXPIRATION DATE],fcaigoudate as [DATE OF GOODS RECEIPT] ,
     FPrice [LAST MONTH END PRICE] ,FCUPrice [PURCHASE PRICE],'RMB' CURRENCY  from #TempInventory1 a 
     left  join t_ICItem b on a.FItemID =b.FItemID 
     left  join  t_item c on c.fitemid =b.F_102 
       where FStockNumber >=@fbegstock 
     and FStockNumber <=@fendstock  and FMaterialNumber >=@fbegnumber and FMaterialNumber <=@fendnumber 
     
    
     
    
    
    Drop Table #TempInventory
    
    Drop Table #TempInventory1
    
    Drop Table #TempInventory2
    
    Drop Table #TempInventory3
    
    
    GO
    

      

  • 相关阅读:
    window.open打开新窗体并用post方式传参
    开发环境搭建问题及解决
    JavaScript高级程序设计(二)
    JavaScript高级程序设计(一)
    JS 小技巧整理
    Windows7版本了解
    安装mysql8.0.17时候报错1251-Client does not support authentication protocol requested by server; consider upgrading MySQL client
    idea中gradle的springboot的项目热部署
    idea多行注释缩进
    idea的类头注释和方法注释的编辑
  • 原文地址:https://www.cnblogs.com/zhugq02/p/11149098.html
Copyright © 2011-2022 走看看