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_CHANGE_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_part_list_change_part_header_id bigint
,@ms_part_list_change_part_detail_id bigint
,@ms_item_id bigint
,@quantity decimal(38,4)
,@info varchar(1000)
,@part_no varchar(50)
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_part_list_change_part_detail_id=isnull(tempTable.item.value('detail_id[1]', 'bigint'),-1)
,@ms_item_id=isnull(tempTable.item.value('ms_item_id[1]', 'bigint'),-1)
,@quantity=dbo.StrToDec4(isnull( tempTable.item.value('quantity[1]', 'varchar(255)'),'0'))
,@info=left(ltrim(rtrim(isnull(tempTable.item.value('info[1]', 'varchar(1050)'),''))),1000)
,@part_no=left(ltrim(rtrim(isnull(tempTable.item.value('part_no[1]', 'varchar(1050)'),''))),50)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_part_list_change_part_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header' ;
goto f
end
declare @check_ms_part_list_change_part_id bigint
,@check_ms_part_list_change_part_no varchar(255)
,@check_ms_part_list_change_part_date date
,@check_status_info varchar(1000)
,@check_ms_part_list_change_part_status_id int
,@check_ms_part_list_change_part_status_name varchar(255)
,@check_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_ms_car_line_no int
,@chcek_assets_list_id bigint
SELECT top (1)
@ms_part_list_change_part_header_id= ms_part_list_change_part_id
, @check_old_ms_item_id= dt_ms_part_list_change_part_detail.ms_item_id
, @check_old_ms_item_custom_no= dt_ms_item.ms_item_custom_no
FROM dt_ms_part_list_change_part_detail
INNER JOIN dt_ms_item ON dt_ms_part_list_change_part_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (dt_ms_part_list_change_part_detail.ms_part_list_change_part_detail_id = @ms_part_list_change_part_detail_id)
SELECT top (1)
@check_ms_part_list_change_part_id=ms_part_list_change_part_id
,@check_ms_part_list_change_part_no= ms_part_list_change_part_no
,@check_ms_part_list_change_part_date= ms_part_list_change_part_date
,@check_status_info= status_info
,@check_ms_part_list_change_part_status_id= ms_part_list_change_part_status_id
,@check_ms_part_list_change_part_status_name= ms_part_list_change_part_status_name
,@chcek_assets_list_id = assets_list_id
FROM vw_part_list_change_part_header
WHERE (ms_part_list_change_part_id = @ms_part_list_change_part_header_id)
if @check_ms_part_list_change_part_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header(2)' ;
goto f
end
if not(@check_ms_part_list_change_part_status_id=0)
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_change_part_status_name + ' tidak bisa di rubah ' ;
goto f
end
if @quantity =0
begin
set @xStsno='02';
set @xStsdes='Gagal, Jumlah Item harus lebih besar dari 0' ;
goto f
end
DECLARE @quantity_change_part decimal(38,4), @total_quantity_change_part decimal(38,4)
SELECT top (1) @quantity_change_part = isnull(quantity,0) ,
@total_quantity_change_part = isnull(quantity_supply,0)
FROM dt_ms_part_list_change_part_detail
WHERE (ms_part_list_change_part_detail_id= @ms_part_list_change_part_detail_id)
if @total_quantity_change_part = 0
begin
set @xStsno='02';
set @xStsdes='Gagal, Item belum ada supply' ;
goto f
end
if @quantity > @quantity_change_part
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Jumlah melebihi quantity ' +
@pemisah + ' SISA : ' + cast(@quantity_change_part as varchar(255)) +
@pemisah + ' QTY : ' + cast(@quantity as varchar(255))
;
goto f
end
BEGIN TRANSACTION;
DECLARE @ms_part_list_production_detail_id bigint
,@ms_part_list_out_id bigint
,@quantity_available decimal(38,4)
,@quantity_recycle decimal(38,4)
,@quantity_needed decimal(18,4)
,@quantity_good decimal(38,4)
SET @quantity_needed = @quantity
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_part_list_change_part_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = -2
OPEN loopchecking1
FETCH NEXT FROM loopchecking1 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
WHILE @@FETCH_STATUS = 0
BEGIN
IF @quantity_needed > 0
BEGIN
if @quantity_available - @quantity_needed >= 0
begin
update dt_ms_part_list_out
set quantity_used = isnull(@quantity_needed,0) + isnull(quantity_used,0)
where ms_part_list_out_id = @ms_part_list_out_id
if @quantity_recycle > 0
begin
set @quantity_good = 0
end
else
begin
set @quantity_good = @quantity_needed
end
update dt_ms_part_list_out
set quantity_scrap = @quantity_needed,
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @ms_part_list_out_id
set @quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(@quantity_available,0) + isnull(quantity_used,0)
where ms_part_list_out_id = @ms_part_list_out_id
if @quantity_recycle > 0
begin
set @quantity_good = 0
end
else
begin
set @quantity_good = @quantity_available
end
update dt_ms_part_list_out
set quantity_scrap = @quantity_available,
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @ms_part_list_out_id
set @quantity_needed = @quantity_needed - @quantity_good
end
END
ELSE
BEGIN
BREAK
END
FETCH NEXT FROM loopchecking1 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
END
CLOSE loopchecking1
DEALLOCATE loopchecking1
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_CHANGE_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_part_list_change_part_header_id bigint
,@ms_part_list_change_part_detail_id bigint
,@ms_item_id bigint
,@quantity decimal(38,4)
,@info varchar(1000)
,@part_no varchar(50)
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_part_list_change_part_detail_id=isnull(tempTable.item.value('detail_id[1]', 'bigint'),-1)
,@ms_item_id=isnull(tempTable.item.value('ms_item_id[1]', 'bigint'),-1)
,@quantity=dbo.StrToDec4(isnull( tempTable.item.value('quantity[1]', 'varchar(255)'),'0'))
,@info=left(ltrim(rtrim(isnull(tempTable.item.value('info[1]', 'varchar(1050)'),''))),1000)
,@part_no=left(ltrim(rtrim(isnull(tempTable.item.value('part_no[1]', 'varchar(1050)'),''))),50)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_part_list_change_part_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header' ;
goto f
end
declare @check_ms_part_list_change_part_id bigint
,@check_ms_part_list_change_part_no varchar(255)
,@check_ms_part_list_change_part_date date
,@check_status_info varchar(1000)
,@check_ms_part_list_change_part_status_id int
,@check_ms_part_list_change_part_status_name varchar(255)
,@check_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_ms_car_line_no int
,@chcek_assets_list_id bigint
SELECT top (1)
@ms_part_list_change_part_header_id= ms_part_list_change_part_id
, @check_old_ms_item_id= dt_ms_part_list_change_part_detail.ms_item_id
, @check_old_ms_item_custom_no= dt_ms_item.ms_item_custom_no
FROM dt_ms_part_list_change_part_detail
INNER JOIN dt_ms_item ON dt_ms_part_list_change_part_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (dt_ms_part_list_change_part_detail.ms_part_list_change_part_detail_id = @ms_part_list_change_part_detail_id)
SELECT top (1)
@check_ms_part_list_change_part_id=ms_part_list_change_part_id
,@check_ms_part_list_change_part_no= ms_part_list_change_part_no
,@check_ms_part_list_change_part_date= ms_part_list_change_part_date
,@check_status_info= status_info
,@check_ms_part_list_change_part_status_id= ms_part_list_change_part_status_id
,@check_ms_part_list_change_part_status_name= ms_part_list_change_part_status_name
,@chcek_assets_list_id = assets_list_id
FROM vw_part_list_change_part_header
WHERE (ms_part_list_change_part_id = @ms_part_list_change_part_header_id)
if @check_ms_part_list_change_part_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header(2)' ;
goto f
end
if not(@check_ms_part_list_change_part_status_id=0)
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_change_part_status_name + ' tidak bisa di rubah ' ;
goto f
end
if @quantity =0
begin
set @xStsno='02';
set @xStsdes='Gagal, Jumlah Item harus lebih besar dari 0' ;
goto f
end
DECLARE @quantity_change_part decimal(38,4), @total_quantity_change_part decimal(38,4)
SELECT top (1) @quantity_change_part = isnull(quantity,0) ,
@total_quantity_change_part = isnull(quantity_supply,0)
FROM dt_ms_part_list_change_part_detail
WHERE (ms_part_list_change_part_detail_id= @ms_part_list_change_part_detail_id)
if @total_quantity_change_part = 0
begin
set @xStsno='02';
set @xStsdes='Gagal, Item belum ada supply' ;
goto f
end
if @quantity > @quantity_change_part
begin
set @xStsno='02 ';
set @xStsdes='Gagal, Jumlah melebihi quantity ' +
@pemisah + ' SISA : ' + cast(@quantity_change_part as varchar(255)) +
@pemisah + ' QTY : ' + cast(@quantity as varchar(255))
;
goto f
end
BEGIN TRANSACTION;
DECLARE @ms_part_list_production_detail_id bigint
,@ms_part_list_out_id bigint
,@quantity_available decimal(38,4)
,@quantity_recycle decimal(38,4)
,@quantity_needed decimal(18,4)
,@quantity_good decimal(38,4)
SET @quantity_needed = @quantity
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_part_list_change_part_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = -2
OPEN loopchecking1
FETCH NEXT FROM loopchecking1 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
WHILE @@FETCH_STATUS = 0
BEGIN
IF @quantity_needed > 0
BEGIN
if @quantity_available - @quantity_needed >= 0
begin
update dt_ms_part_list_out
set quantity_used = isnull(@quantity_needed,0) + isnull(quantity_used,0)
where ms_part_list_out_id = @ms_part_list_out_id
if @quantity_recycle > 0
begin
set @quantity_good = 0
end
else
begin
set @quantity_good = @quantity_needed
end
update dt_ms_part_list_out
set quantity_scrap = @quantity_needed,
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @ms_part_list_out_id
set @quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(@quantity_available,0) + isnull(quantity_used,0)
where ms_part_list_out_id = @ms_part_list_out_id
if @quantity_recycle > 0
begin
set @quantity_good = 0
end
else
begin
set @quantity_good = @quantity_available
end
update dt_ms_part_list_out
set quantity_scrap = @quantity_available,
modify_date = @NOW,
modify_by = @data_by
where ms_part_list_out_id = @ms_part_list_out_id
set @quantity_needed = @quantity_needed - @quantity_good
end
END
ELSE
BEGIN
BREAK
END
FETCH NEXT FROM loopchecking1 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
END
CLOSE loopchecking1
DEALLOCATE loopchecking1
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