NJC__Documentation::DB

dbo.MG_MS_OUT_DISAMBLE_PART_LIST_HEADER_APPROVE

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

Name Data Type Length Description
@PARAMETER xml -1

SQL Script

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO

CREATE procedure dbo.MG_MS_OUT_DISAMBLE_PART_LIST_HEADER_APPROVE
@PARAMETER xml='' 
---XencX---with encryption
as

SET TRANSACTION ISOLATION LEVEL  READ UNCOMMITTED

declare @pemisah varchar(255)
declare @pemisah_replace varchar(255)
set @pemisah_replace='<br />'
--set @pemisah=CHAR(13) + CHAR(10) + '
'

set @pemisah = '
'


declare @resultX varchar(max)
declare @resultX2 varchar(max)

declare @XmlSts xml
declare @raw xml
declare @xStsnoheader varchar(2),
  @xStsno varchar(2),
  @xStsdes varchar(max)
   
set @xStsnoheader='07'
set @xStsno='00';
set @xStsdes='sukses'
 
BEGIN TRY
SET NOCOUNT ON
DECLARE @NOW datetime
set @NOW =GETDATE()

DECLARE 
@data_by varchar(50)
,@ms_part_list_disamble_header_id bigint

SELECT 
   @data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,  @ms_part_list_disamble_header_id=isnull(tempTable.item.value('ms_part_list_disamble_header_id[1]', 'bigint'),-1)
FROM @PARAMETER.nodes('param/field')  tempTable(item) 


if @ms_part_list_disamble_header_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data yang akan di edit' ;
goto f
end

DECLARE @check_ms_part_list_disamble_id bigint
  ,@check_ms_part_list_disamble_no varchar(255)
  ,@check_ms_part_list_disamble_date date
  ,@check_status_info  varchar(1000)
  ,@check_ms_part_list_disamble_status_id int
  ,@check_ms_part_list_disamble_status_name  varchar(255)
  ,@check_ms_item_id bigint
  ,@check_assets_list_id bigint

SELECT  Top (1)     
  @check_ms_part_list_disamble_id = ms_part_list_disamble_id
 ,@check_ms_part_list_disamble_no = ms_part_list_disamble_no
 ,@check_ms_part_list_disamble_date = ms_part_list_disamble_date
 ,@check_status_info= status_info
 ,@check_ms_part_list_disamble_status_id = ms_part_list_disamble_status_id
 ,@check_ms_part_list_disamble_status_name = ms_part_list_disamble_status_name
 ,@check_ms_item_id = ms_item_id
 ,@check_assets_list_id = assets_list_id
FROM            vw_part_list_disamble_header
WHERE        (ms_part_list_disamble_id = @ms_part_list_disamble_header_id)



if @check_ms_part_list_disamble_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end

if @check_ms_part_list_disamble_status_id=-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_disamble_status_name + ' tidak bisa di Approve ' ;
goto f 
end
 
if @check_ms_part_list_disamble_status_id=1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_disamble_status_name + ' tidak bisa di Approve Lagi' ;
goto f 
end


if (SELECT        COUNT(*) AS Expr1
FROM            dt_ms_part_list_disamble_detail
WHERE        (ms_part_list_disamble_id = @ms_part_list_disamble_header_id))=0
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Tidak ada detail , masukan detail item ' ;
goto f 
end 
   
if not(@xStsno='00')
begin
 goto f
end

declare @ms_part_list_disamble_h_status_id bigint

BEGIN TRANSACTION;     

 INSERT INTO dt_ms_part_list_disamble_h_status
   (ms_part_list_disamble_id, ms_part_list_disamble_status_id, status_info, create_date, create_by)
 VALUES  (@ms_part_list_disamble_header_id, 1, N'', @NOW, @data_by)

 SET @ms_part_list_disamble_h_status_id=SCOPE_IDENTITY();

 UPDATE dt_ms_part_list_disamble_header
 SET ms_part_list_disamble_h_status_id=@ms_part_list_disamble_h_status_id 
 WHERE  ms_part_list_disamble_id=@ms_part_list_disamble_header_id 

 DECLARE @cur_ms_part_list_process_detail_id bigint
 , @cur_ms_item_id bigint
 , @cur_quantity_recycle decimal(38,4)
 , @cur_quantity_scrap decimal(38,4)
 , @cur_ms_part_list_out_id bigint

 IF CURSOR_STATUS('global','loopchecking')>=-1
 BEGIN
  DEALLOCATE loopchecking
 END

 DECLARE loopchecking CURSOR FOR
  SELECT
     a.ms_part_list_process_detail_id 
   , b.ms_item_id
   , sum(isnull(a.quantity_used,0)) as qty_recycle
   , sum(isnull(a.quantity_scrap,0)) as qty_scrap
   --, a.ms_part_list_out_id
  FROM dt_ms_part_list_out a 
  INNER JOIN dt_ms_part_list_disamble_detail b ON a.ms_part_list_process_detail_id = b.ms_part_list_disamble_detail_id
  INNER JOIN dt_ms_part_list_disamble_header c ON b.ms_part_list_disamble_id = c.ms_part_list_disamble_id
  WHERE a.ms_process_id = -1 and b.ms_part_list_disamble_detail_id = @ms_part_list_disamble_header_id
  GROUP BY a.ms_part_list_process_detail_id, b.ms_item_id
 OPEN loopchecking
 FETCH NEXT FROM loopchecking INTO @cur_ms_part_list_process_detail_id ,@cur_ms_item_id ,@cur_quantity_recycle, @cur_quantity_scrap
 WHILE @@FETCH_STATUS = 0 
 BEGIN

  IF @cur_quantity_recycle > 0
  BEGIN
   insert into dt_ms_part_list_recycle(ms_item_id,ms_part_list_disamble_detail_id,ms_part_list_out_id,quantity,quantity_used, trans_type_id, create_date, create_by, modify_date, modify_by) 
   VALUES (@cur_ms_item_id, @cur_ms_part_list_process_detail_id, @cur_ms_part_list_out_id, @cur_quantity_recycle, 0, -1, @NOW, @data_by, @NOW, @data_by)   
  END

  IF @cur_quantity_scrap > 0
  BEGIN 
   insert into dt_ms_part_list_scrap (ms_item_id,ms_part_list_disamble_detail_id,ms_part_list_out_id,quantity,quantity_used, trans_type_id, create_date, create_by, modify_date, modify_by) 
   VALUES (@cur_ms_item_id, @cur_ms_part_list_process_detail_id, @cur_ms_part_list_out_id, @cur_quantity_scrap, 0, -1, @NOW, @data_by, @NOW, @data_by)   
  END
   
  FETCH NEXT FROM loopchecking INTO @cur_ms_part_list_process_detail_id ,@cur_ms_item_id ,@cur_quantity_recycle, @cur_quantity_scrap
 END
 CLOSE loopchecking    
 DEALLOCATE loopchecking

 --select * from dt_ms_part_list_recycle
 --select * from dt_ms_part_list_scrap

 UPDATE dt_ms_assets_list
 SET used = 1
 WHERE assets_list_id = @check_assets_list_id

commit TRANSACTION; 
declare @detail xml

f:

set nocount off

END TRY  
BEGIN CATCH
 IF (@@TRANCOUNT > 0)  ROLLBACK TRAN;
 
 set @xStsno='88'
 set @xStsdes= ERROR_MESSAGE() 
END CATCH

g:
set @XmlSts=(select @xStsnoheader + @xStsno as 'no', @xStsdes as 'des' for xml path('sts'))
 select  CAST( (select @XmlSts,isnull(@detail ,'') ,isnull(@raw ,'')   for xml path ('result')
)  as XML)  as dt

GO

Used By

No items found