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_DETAIL_PROCESS
@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_out_part_list_disamble_header_id bigint
, @ms_out_part_list_disamble_detail_id varchar(max)
, @ms_item_id bigint
, @quantity_recycle decimal(18,4)
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_out_part_list_disamble_header_id=tempTable.item.value('header_id[1]', 'bigint')
,@ms_out_part_list_disamble_detail_id=tempTable.item.value('detail_id[1]', 'varchar(max)')
,@ms_item_id=tempTable.item.value('ms_item_id[1]', 'bigint')
,@quantity_recycle=dbo.StrToDec4(isnull( tempTable.item.value('quantity[1]', 'decimal(18,4)'),'0'))
FROM @PARAMETER.nodes('param/field') tempTable(item)
DECLARE @check_ms_part_list_disamble_header_id bigint
,@check_ms_part_list_disamble_no varchar(255)
,@check_ms_part_list_disamble_date date
,@check_ms_part_list_disamble_status_id int
,@check_ms_part_list_disamble_status_name varchar(255)
,@check_assets_list_id bigint
SELECT top(1)
@check_ms_part_list_disamble_header_id = a.ms_part_list_disamble_id
,@check_ms_part_list_disamble_no = a.ms_part_list_disamble_no
,@check_ms_part_list_disamble_date = a.ms_part_list_disamble_date
,@check_assets_list_id = a.assets_list_id
,@check_ms_part_list_disamble_status_id = a.ms_part_list_disamble_status_id
,@check_ms_part_list_disamble_status_name = a.ms_part_list_disamble_status_name
FROM vw_part_list_disamble_header a
WHERE (a.ms_part_list_disamble_id = @ms_out_part_list_disamble_header_id)
if not(@check_ms_part_list_disamble_status_id=0)
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_disamble_status_name + ' tidak bisa di process ' ;
goto f
end
DECLARE @check_ms_part_list_production_id bigint
SELECT TOP (1) @check_ms_part_list_production_id = ms_part_list_production_id
FROM dt_ms_assets_list WHERE assets_list_id = @check_assets_list_id
DECLARE @sisa decimal(38,4)
SELECT top (1) @sisa = isnull(quantity,0)
FROM dt_ms_part_list_disamble_detail
WHERE (ms_part_list_disamble_detail_id= @ms_out_part_list_disamble_detail_id)
if @quantity_recycle > @sisa
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Jumlah melebihi quantity ' +
@pemisah + ' SISA : ' + cast(@sisa as varchar(255)) +
@pemisah + ' QTY : ' + cast(@quantity_recycle as varchar(255))
;
goto f
end
DECLARE @ms_part_list_out_detail_id bigint
BEGIN TRANSACTION;
DECLARE @cur_ms_part_list_production_detail_id bigint
,@cur_ms_part_list_out_id bigint
,@cur_quantity_available decimal(38,4)
,@cur_quantity_recycle decimal(38,4)
,@cur_quantity_needed decimal(18,4)
,@cur_quantity_good decimal(38,4)
SET @cur_quantity_needed = @quantity_recycle
DECLARE loopchecking1 CURSOR FOR
SELECT ms_part_list_out_id, (ISNULL(quantity,0) - ISNULL(quantity_used,0)) as quantity_available, ISNULL(quantity_recycle,0) as quantity_recycle
FROM dt_ms_part_list_out a
WHERE ms_part_list_process_detail_id = @ms_out_part_list_disamble_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = -1
OPEN loopchecking1
FETCH NEXT FROM loopchecking1 INTO @cur_ms_part_list_out_id, @cur_quantity_available, @cur_quantity_recycle
WHILE @@FETCH_STATUS = 0
BEGIN
IF @cur_quantity_needed > 0
BEGIN
if @cur_quantity_available - @cur_quantity_needed >= 0
begin
update dt_ms_part_list_out
set quantity_used = isnull(@cur_quantity_needed,0) + isnull(quantity_used,0),
quantity_new_part = 0,
quantity_recycle = 0
where ms_part_list_out_id = @cur_ms_part_list_out_id
if @cur_quantity_recycle > 0
begin
set @cur_quantity_good = @cur_quantity_needed
end
else
begin
set @cur_quantity_good = @cur_quantity_needed
end
update dt_ms_part_list_out
set quantity_scrap = quantity - isnull(quantity_used,0),
--set quantity_scrap = isnull(@cur_quantity_needed,0) - isnull(quantity_used,0),
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @cur_ms_part_list_out_id
set @cur_quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(@cur_quantity_available,0) + isnull(quantity_used,0),
quantity_new_part = 0,
quantity_recycle = 0
where ms_part_list_out_id = @cur_ms_part_list_out_id
if @cur_quantity_recycle > 0
begin
set @cur_quantity_good = @cur_quantity_available
end
else
begin
set @cur_quantity_good = @cur_quantity_available
end
update dt_ms_part_list_out
set quantity_scrap = isnull(@cur_quantity_available,0) - isnull(quantity_used,0),
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @cur_ms_part_list_out_id
set @cur_quantity_needed = @cur_quantity_needed - @cur_quantity_good
end
END
ELSE
BEGIN
BREAK
END
FETCH NEXT FROM loopchecking1 INTO @cur_ms_part_list_out_id, @cur_quantity_available, @cur_quantity_recycle
END
CLOSE loopchecking1
DEALLOCATE loopchecking1
--select * from dt_ms_part_list_out
--select * from vw_part_list_disamble_detail
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
GO
CREATE PROCEDURE dbo.MG_MS_OUT_DISAMBLE_PART_LIST_DETAIL_PROCESS
@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_out_part_list_disamble_header_id bigint
, @ms_out_part_list_disamble_detail_id varchar(max)
, @ms_item_id bigint
, @quantity_recycle decimal(18,4)
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_out_part_list_disamble_header_id=tempTable.item.value('header_id[1]', 'bigint')
,@ms_out_part_list_disamble_detail_id=tempTable.item.value('detail_id[1]', 'varchar(max)')
,@ms_item_id=tempTable.item.value('ms_item_id[1]', 'bigint')
,@quantity_recycle=dbo.StrToDec4(isnull( tempTable.item.value('quantity[1]', 'decimal(18,4)'),'0'))
FROM @PARAMETER.nodes('param/field') tempTable(item)
DECLARE @check_ms_part_list_disamble_header_id bigint
,@check_ms_part_list_disamble_no varchar(255)
,@check_ms_part_list_disamble_date date
,@check_ms_part_list_disamble_status_id int
,@check_ms_part_list_disamble_status_name varchar(255)
,@check_assets_list_id bigint
SELECT top(1)
@check_ms_part_list_disamble_header_id = a.ms_part_list_disamble_id
,@check_ms_part_list_disamble_no = a.ms_part_list_disamble_no
,@check_ms_part_list_disamble_date = a.ms_part_list_disamble_date
,@check_assets_list_id = a.assets_list_id
,@check_ms_part_list_disamble_status_id = a.ms_part_list_disamble_status_id
,@check_ms_part_list_disamble_status_name = a.ms_part_list_disamble_status_name
FROM vw_part_list_disamble_header a
WHERE (a.ms_part_list_disamble_id = @ms_out_part_list_disamble_header_id)
if not(@check_ms_part_list_disamble_status_id=0)
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_disamble_status_name + ' tidak bisa di process ' ;
goto f
end
DECLARE @check_ms_part_list_production_id bigint
SELECT TOP (1) @check_ms_part_list_production_id = ms_part_list_production_id
FROM dt_ms_assets_list WHERE assets_list_id = @check_assets_list_id
DECLARE @sisa decimal(38,4)
SELECT top (1) @sisa = isnull(quantity,0)
FROM dt_ms_part_list_disamble_detail
WHERE (ms_part_list_disamble_detail_id= @ms_out_part_list_disamble_detail_id)
if @quantity_recycle > @sisa
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Jumlah melebihi quantity ' +
@pemisah + ' SISA : ' + cast(@sisa as varchar(255)) +
@pemisah + ' QTY : ' + cast(@quantity_recycle as varchar(255))
;
goto f
end
DECLARE @ms_part_list_out_detail_id bigint
BEGIN TRANSACTION;
DECLARE @cur_ms_part_list_production_detail_id bigint
,@cur_ms_part_list_out_id bigint
,@cur_quantity_available decimal(38,4)
,@cur_quantity_recycle decimal(38,4)
,@cur_quantity_needed decimal(18,4)
,@cur_quantity_good decimal(38,4)
SET @cur_quantity_needed = @quantity_recycle
DECLARE loopchecking1 CURSOR FOR
SELECT ms_part_list_out_id, (ISNULL(quantity,0) - ISNULL(quantity_used,0)) as quantity_available, ISNULL(quantity_recycle,0) as quantity_recycle
FROM dt_ms_part_list_out a
WHERE ms_part_list_process_detail_id = @ms_out_part_list_disamble_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = -1
OPEN loopchecking1
FETCH NEXT FROM loopchecking1 INTO @cur_ms_part_list_out_id, @cur_quantity_available, @cur_quantity_recycle
WHILE @@FETCH_STATUS = 0
BEGIN
IF @cur_quantity_needed > 0
BEGIN
if @cur_quantity_available - @cur_quantity_needed >= 0
begin
update dt_ms_part_list_out
set quantity_used = isnull(@cur_quantity_needed,0) + isnull(quantity_used,0),
quantity_new_part = 0,
quantity_recycle = 0
where ms_part_list_out_id = @cur_ms_part_list_out_id
if @cur_quantity_recycle > 0
begin
set @cur_quantity_good = @cur_quantity_needed
end
else
begin
set @cur_quantity_good = @cur_quantity_needed
end
update dt_ms_part_list_out
set quantity_scrap = quantity - isnull(quantity_used,0),
--set quantity_scrap = isnull(@cur_quantity_needed,0) - isnull(quantity_used,0),
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @cur_ms_part_list_out_id
set @cur_quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(@cur_quantity_available,0) + isnull(quantity_used,0),
quantity_new_part = 0,
quantity_recycle = 0
where ms_part_list_out_id = @cur_ms_part_list_out_id
if @cur_quantity_recycle > 0
begin
set @cur_quantity_good = @cur_quantity_available
end
else
begin
set @cur_quantity_good = @cur_quantity_available
end
update dt_ms_part_list_out
set quantity_scrap = isnull(@cur_quantity_available,0) - isnull(quantity_used,0),
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @cur_ms_part_list_out_id
set @cur_quantity_needed = @cur_quantity_needed - @cur_quantity_good
end
END
ELSE
BEGIN
BREAK
END
FETCH NEXT FROM loopchecking1 INTO @cur_ms_part_list_out_id, @cur_quantity_available, @cur_quantity_recycle
END
CLOSE loopchecking1
DEALLOCATE loopchecking1
--select * from dt_ms_part_list_out
--select * from vw_part_list_disamble_detail
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
Depends On
5Used By
No items found