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_PRODUCTION_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_production_header_id bigint
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
, @ms_part_list_production_header_id=isnull(tempTable.item.value('ms_part_list_production_header_id[1]', 'bigint'),-1)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_part_list_production_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit' ;
goto f
end
declare @check_ms_part_list_out_header_id bigint
,@check_ms_part_list_prod_no varchar(255)
,@check_ms_part_list_prod_date date
,@check_status_info varchar(1000)
,@check_ms_part_list_production_status_id int
,@check_ms_part_list_production_status_name varchar(255)
,@check_ms_item_id bigint
,@check_quantity int
SELECT top (1)
@check_ms_part_list_out_header_id=ms_part_list_production_id
,@check_ms_part_list_prod_no= ms_part_list_production_no
,@check_ms_part_list_prod_date= ms_part_list_production_date
,@check_status_info= status_info
,@check_ms_part_list_production_status_id= ms_part_list_production_status_id
,@check_ms_part_list_production_status_name= ms_part_list_production_status_name
,@check_ms_item_id = ms_item_id
,@check_quantity = quantity
FROM vw_part_list_production_header
WHERE (ms_part_list_production_id = @ms_part_list_production_header_id)
if @check_ms_part_list_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end
if @check_ms_part_list_production_status_id=-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di Approve ' ;
goto f
end
if @check_ms_part_list_production_status_id=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di Approve Lagi' ;
goto f
end
if (SELECT COUNT(*) AS Expr1
FROM dt_ms_part_list_production_detail
WHERE (ms_part_list_production_id = @ms_part_list_production_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_production_h_status_id bigint
BEGIN TRANSACTION;
INSERT INTO dt_ms_part_list_production_h_status
(ms_part_list_production_id, ms_part_list_production_status_id, status_info, create_date, create_by)
VALUES (@ms_part_list_production_header_id, 1, N'', @NOW, @data_by)
SET @ms_part_list_production_h_status_id=SCOPE_IDENTITY();
UPDATE dt_ms_part_list_production_header
SET ms_part_list_production_h_status_id=@ms_part_list_production_h_status_id
WHERE ms_part_list_production_id=@ms_part_list_production_header_id
--SELECT
-- ms_part_list_production_detail_id
-- , ms_item_id
-- , quantity / @check_quantity as quantity_material
-- FROM dt_ms_part_list_production_detail a
-- WHERE a.ms_part_list_production_id = @check_ms_part_list_out_header_id
--select * from dt_ms_part_list_out where ms_part_list_process_detail_id = @check_ms_part_list_out_header_id
DECLARE @qty_loop int = 0,
@part_list_no varchar(50)
WHILE @qty_loop < @check_quantity
BEGIN
declare @ms_part_list_production_detail_id bigint
,@ms_item_id bigint
,@quantity_material decimal(38,4)
,@quantity_supply decimal(38,4)
,@quantity_needed decimal(38,4)
,@quantity_available decimal(38,4)
,@quantity_recycle decimal(38,4)
,@quantity_good decimal(38,4)
,@ms_part_list_out_id bigint
,@assets_list_id bigint
SET @qty_loop = @qty_loop + 1
SET @part_list_no = @check_ms_part_list_prod_no + '-' + convert(varchar(100), @qty_loop)
INSERT INTO dt_ms_assets_list
(ms_item_id, assets_number, ms_part_list_production_id, used, create_by, create_date, modify_by, modify_date)
VALUES (@check_ms_item_id, @part_list_no, @check_ms_part_list_out_header_id, 0, @data_by, @now, @data_by, @now)
SET @assets_list_id = SCOPE_IDENTITY()
IF CURSOR_STATUS('global','loopchecking')>=-1
BEGIN
DEALLOCATE loopchecking
END
DECLARE loopchecking CURSOR FOR
SELECT
ms_part_list_production_detail_id
, ms_item_id
, quantity / @check_quantity as quantity_material
FROM dt_ms_part_list_production_detail a
WHERE a.ms_part_list_production_id = @check_ms_part_list_out_header_id
OPEN loopchecking
FETCH NEXT FROM loopchecking INTO @ms_part_list_production_detail_id ,@ms_item_id ,@quantity_material
WHILE @@FETCH_STATUS = 0
BEGIN
SET @quantity_needed = @quantity_material
IF CURSOR_STATUS('global','loopchecking2')>=-1
BEGIN
DEALLOCATE loopchecking2
END
DECLARE loopchecking2 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_production_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = 1
OPEN loopchecking2
FETCH NEXT FROM loopchecking2 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
insert into dt_ms_assets_list_detail (assets_list_id, ms_part_list_out_id, quantity, quantity_recycle, quantity_total)
VALUES (@assets_list_id, @ms_part_list_out_id, @quantity_good, @quantity_recycle, @quantity_needed)
set @quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(quantity_used,0) + isnull(@quantity_available,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
insert into dt_ms_assets_list_detail (assets_list_id, ms_part_list_out_id, quantity, quantity_recycle, quantity_total)
VALUES (@assets_list_id, @ms_part_list_out_id, @quantity_good, @quantity_recycle, @quantity_available)
set @quantity_needed = @quantity_needed - @quantity_available
end
end
else
begin
BREAK
end
FETCH NEXT FROM loopchecking2 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
END
CLOSE loopchecking2
DEALLOCATE loopchecking2
FETCH NEXT FROM loopchecking INTO @ms_part_list_production_detail_id ,@ms_item_id ,@quantity_material
END
CLOSE loopchecking
DEALLOCATE loopchecking
END;
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_PRODUCTION_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_production_header_id bigint
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
, @ms_part_list_production_header_id=isnull(tempTable.item.value('ms_part_list_production_header_id[1]', 'bigint'),-1)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_part_list_production_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit' ;
goto f
end
declare @check_ms_part_list_out_header_id bigint
,@check_ms_part_list_prod_no varchar(255)
,@check_ms_part_list_prod_date date
,@check_status_info varchar(1000)
,@check_ms_part_list_production_status_id int
,@check_ms_part_list_production_status_name varchar(255)
,@check_ms_item_id bigint
,@check_quantity int
SELECT top (1)
@check_ms_part_list_out_header_id=ms_part_list_production_id
,@check_ms_part_list_prod_no= ms_part_list_production_no
,@check_ms_part_list_prod_date= ms_part_list_production_date
,@check_status_info= status_info
,@check_ms_part_list_production_status_id= ms_part_list_production_status_id
,@check_ms_part_list_production_status_name= ms_part_list_production_status_name
,@check_ms_item_id = ms_item_id
,@check_quantity = quantity
FROM vw_part_list_production_header
WHERE (ms_part_list_production_id = @ms_part_list_production_header_id)
if @check_ms_part_list_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end
if @check_ms_part_list_production_status_id=-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di Approve ' ;
goto f
end
if @check_ms_part_list_production_status_id=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di Approve Lagi' ;
goto f
end
if (SELECT COUNT(*) AS Expr1
FROM dt_ms_part_list_production_detail
WHERE (ms_part_list_production_id = @ms_part_list_production_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_production_h_status_id bigint
BEGIN TRANSACTION;
INSERT INTO dt_ms_part_list_production_h_status
(ms_part_list_production_id, ms_part_list_production_status_id, status_info, create_date, create_by)
VALUES (@ms_part_list_production_header_id, 1, N'', @NOW, @data_by)
SET @ms_part_list_production_h_status_id=SCOPE_IDENTITY();
UPDATE dt_ms_part_list_production_header
SET ms_part_list_production_h_status_id=@ms_part_list_production_h_status_id
WHERE ms_part_list_production_id=@ms_part_list_production_header_id
--SELECT
-- ms_part_list_production_detail_id
-- , ms_item_id
-- , quantity / @check_quantity as quantity_material
-- FROM dt_ms_part_list_production_detail a
-- WHERE a.ms_part_list_production_id = @check_ms_part_list_out_header_id
--select * from dt_ms_part_list_out where ms_part_list_process_detail_id = @check_ms_part_list_out_header_id
DECLARE @qty_loop int = 0,
@part_list_no varchar(50)
WHILE @qty_loop < @check_quantity
BEGIN
declare @ms_part_list_production_detail_id bigint
,@ms_item_id bigint
,@quantity_material decimal(38,4)
,@quantity_supply decimal(38,4)
,@quantity_needed decimal(38,4)
,@quantity_available decimal(38,4)
,@quantity_recycle decimal(38,4)
,@quantity_good decimal(38,4)
,@ms_part_list_out_id bigint
,@assets_list_id bigint
SET @qty_loop = @qty_loop + 1
SET @part_list_no = @check_ms_part_list_prod_no + '-' + convert(varchar(100), @qty_loop)
INSERT INTO dt_ms_assets_list
(ms_item_id, assets_number, ms_part_list_production_id, used, create_by, create_date, modify_by, modify_date)
VALUES (@check_ms_item_id, @part_list_no, @check_ms_part_list_out_header_id, 0, @data_by, @now, @data_by, @now)
SET @assets_list_id = SCOPE_IDENTITY()
IF CURSOR_STATUS('global','loopchecking')>=-1
BEGIN
DEALLOCATE loopchecking
END
DECLARE loopchecking CURSOR FOR
SELECT
ms_part_list_production_detail_id
, ms_item_id
, quantity / @check_quantity as quantity_material
FROM dt_ms_part_list_production_detail a
WHERE a.ms_part_list_production_id = @check_ms_part_list_out_header_id
OPEN loopchecking
FETCH NEXT FROM loopchecking INTO @ms_part_list_production_detail_id ,@ms_item_id ,@quantity_material
WHILE @@FETCH_STATUS = 0
BEGIN
SET @quantity_needed = @quantity_material
IF CURSOR_STATUS('global','loopchecking2')>=-1
BEGIN
DEALLOCATE loopchecking2
END
DECLARE loopchecking2 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_production_detail_id
AND (ISNULL(quantity,0) - ISNULL(quantity_used,0)) > 0
AND ms_process_id = 1
OPEN loopchecking2
FETCH NEXT FROM loopchecking2 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
insert into dt_ms_assets_list_detail (assets_list_id, ms_part_list_out_id, quantity, quantity_recycle, quantity_total)
VALUES (@assets_list_id, @ms_part_list_out_id, @quantity_good, @quantity_recycle, @quantity_needed)
set @quantity_needed = 0
end
else
begin
update dt_ms_part_list_out
set quantity_used = isnull(quantity_used,0) + isnull(@quantity_available,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
insert into dt_ms_assets_list_detail (assets_list_id, ms_part_list_out_id, quantity, quantity_recycle, quantity_total)
VALUES (@assets_list_id, @ms_part_list_out_id, @quantity_good, @quantity_recycle, @quantity_available)
set @quantity_needed = @quantity_needed - @quantity_available
end
end
else
begin
BREAK
end
FETCH NEXT FROM loopchecking2 INTO @ms_part_list_out_id, @quantity_available, @quantity_recycle
END
CLOSE loopchecking2
DEALLOCATE loopchecking2
FETCH NEXT FROM loopchecking INTO @ms_part_list_production_detail_id ,@ms_item_id ,@quantity_material
END
CLOSE loopchecking
DEALLOCATE loopchecking
END;
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
7Used By
No items found