dbo.spi_incoming_approved

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

Name Data Type Length Description
@id_data_in_hdr bigint 8
@doc_in_from_id bigint 8
@doc_in_no varchar 50
@doc_in_date varchar 50
@id_terkait bigint 8
@user varchar 70

SQL Script

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.spi_incoming_approved(@id_data_in_hdr as bigint, @doc_in_from_id  as bigint, @doc_in_no as varchar(50), @doc_in_date as varchar(50), @id_terkait bigint, @user varchar(70))
AS
BEGIN
 declare @count int
 set @count = (select COUNT(*) from dbo.tbl_data_in_hdr where id_data_in_hdr = @id_data_in_hdr and status = 'APPROVED')
 if @count <> 0
 begin
  select '01' as status, ' DATA HDR NOT FOUND OR DATA ALREADY APPROVED' as description
  return
 end
 set @count = (select COUNT(*) from dbo.[tbl_data_in_hdr] where [tbl_data_in_hdr].id_data_in_hdr = @id_data_in_hdr and doc_in_from_id=@doc_in_from_id and id_terkait=@id_terkait)
 if @count = 0
 begin
  select '01' as status, ' HDR DATA NOT FOUND' as description
  return
 end
 if (select COUNT(*) from dbo.[tbl_data_in_dtl] where id_data_in_hdr = (select top 1 [tbl_data_in_hdr].id_data_in_hdr from dbo.[tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr)) = 0
 begin
  select '01' as status, 'DTL DATA NOT FOUND' as description
  return
 end
BEGIN TRY  
 BEGIN TRANSACTION
 if (@doc_in_from_id = 2) or (@doc_in_from_id = 3)  or (@doc_in_from_id = 4)  or (@doc_in_from_id = 5)
 begin 
  update dbo.tbl_bc_in_hdr set statusdok = 'APPROVED INVENTORY' where id_bc_in_hdr = @id_terkait
  
  INSERT INTO tbl_bc_in_hdr_h_status
                      (id_bc_in_hdr, statusdok, status_date, create_by, create_date, update_by, update_date)
  VALUES     (@id_data_in_hdr, (select top 1 statusdok from tbl_bc_in_hdr where id_bc_in_hdr = @id_data_in_hdr), GETDATE(), @user, GETDATE(), @user, GETDATE())
  
  update dbo.tbl_data_in_hdr set status = 'APPROVED', doc_in_date=@doc_in_date where id_data_in_hdr = @id_data_in_hdr
  
  INSERT INTO tbl_data_in_hdr_h_status
                      (id_data_in_hdr, status, status_date, create_by, create_date, update_by, update_date)
  VALUES     ((select top 1 [tbl_data_in_hdr].id_data_in_hdr from dbo.[tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr), 'APPROVED', GETDATE(), @user, GETDATE(), @user, GETDATE())
 end 
 
 if  (@doc_in_from_id = 1)
 begin
  update dbo.tbl_incoming_fg set status = 'APPROVED INVENTORY' where [id_incoming_fg_hdr] = @id_terkait
  
  update dbo.tbl_data_in_hdr set status = 'APPROVED', doc_in_date=@doc_in_date where id_data_in_hdr = @id_data_in_hdr
  
  INSERT INTO tbl_data_in_hdr_h_status
                      (id_data_in_hdr, status, status_date, create_by, create_date, update_by, update_date)
  VALUES     ((select top 1 [tbl_data_in_hdr].id_data_in_hdr from dbo.[tbl_data_in_hdr] where id_data_in_hdr = @id_data_in_hdr), 'APPROVED', GETDATE(), @user, GETDATE(), @user, GETDATE())
 end
  
  select '00' as status, ' DATA SUKSES UPDATED' as description
    
    COMMIT
END TRY
 
BEGIN CATCH
  -- Whoops, there was an error
  IF @@TRANCOUNT > 0
     ROLLBACK

  -- Raise an error with the details of the exception
  DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
  Set @ErrMsg = ERROR_MESSAGE()
  set @ErrSeverity = ERROR_SEVERITY()
  select @ErrMsg as description,@ErrSeverity as status
  RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH    

END
GO