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_DETAIL_AUTO_SUPPLY
@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
,@ms_part_list_production_detail_id bigint
,@mode_supply int
,@renew_supply bit
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_part_list_production_detail_id=isnull(tempTable.item.value('detail_id[1]', 'bigint'),-1)
,@mode_supply=isnull(tempTable.item.value('mode_supply[1]', 'int'),0)
,@renew_supply=isnull(tempTable.item.value('renew_supply[1]', 'bit'),0)
FROM @PARAMETER.nodes('param/field') tempTable(item)
declare
@check_ms_part_list_production_id bigint
,@check_ms_part_list_production_no varchar(255)
,@check_ms_part_list_production_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_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_kurang decimal(38,4)
SELECT top (1)
@ms_part_list_production_header_id = ms_part_list_production_id
, @check_old_ms_item_id = vw_part_list_production_detail.ms_item_id
, @check_old_ms_item_custom_no = dt_ms_item.ms_item_custom_no
, @check_kurang = vw_part_list_production_detail.quantity-vw_part_list_production_detail.total_supply
FROM vw_part_list_production_detail
INNER JOIN dt_ms_item ON vw_part_list_production_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (vw_part_list_production_detail.ms_part_list_production_detail_id = @ms_part_list_production_detail_id)
SELECT top (1)
@check_ms_part_list_production_id=ms_part_list_production_id
,@check_ms_part_list_production_no= ms_part_list_production_no
,@check_ms_part_list_production_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
FROM vw_part_list_production_header
WHERE (ms_part_list_production_id = @ms_part_list_production_header_id)
if @check_ms_part_list_production_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header(2)' ;
goto f
end
if not(@check_ms_part_list_production_status_id=0)
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di rubah ' ;
goto f
end
BEGIN TRANSACTION;
--if @renew_supply=1
--begin
--delete from dt_ms_item_out_detail
--where mode_source=0
--and id_source_header= @ms_car_line_out_header_id
--and id_source= @ms_car_line_out_detail_id
--end
DECLARE @ms_production_in_detail_id bigint
, @doc_date date
, @quantity decimal(18,4)
, @quantity_total decimal(18,4)
, @is_sumber int
DECLARE production_cursor CURSOR FOR
SELECT
ms_production_in_detail_id
, doc_date
, quantity
, sum_qty
, is_sumber
FROM dbo.fn_ms_auto_supply_production_part_list(@check_old_ms_item_id, @mode_supply, @check_ms_part_list_production_date, @check_kurang)
OPEN production_cursor
FETCH NEXT FROM production_cursor INTO @ms_production_in_detail_id
, @doc_date
, @quantity
, @quantity_total
, @is_sumber
WHILE @@FETCH_STATUS = 0
BEGIN
--IF @quantity_total < @check_kurang
-- begin
-- set @xStsno='02';
-- set @xStsdes='Gagal, Supply kurang' ;
-- rollback tran;
-- goto g
-- end
IF @is_sumber = 0
begin
INSERT INTO dt_ms_part_list_out (ms_item_out_detail_id, ms_trans_type_id, ms_part_list_process_detail_id, ms_process_id, quantity, quantity_new_part, quantity_recycle, create_date, create_by, modify_date, modify_by)
VALUES (@ms_production_in_detail_id,1,@ms_part_list_production_detail_id,1,@quantity,@quantity,0,@NOW,@data_by,@NOW,@data_by)
end
ELSE
begin
INSERT INTO dt_ms_part_list_out (ms_item_out_detail_id, ms_trans_type_id, ms_part_list_process_detail_id, ms_process_id, quantity, quantity_new_part, quantity_recycle, create_date, create_by, modify_date, modify_by)
VALUES (@ms_production_in_detail_id,2,@ms_part_list_production_detail_id,1,@quantity,0,@quantity,@NOW,@data_by,@NOW,@data_by)
end
FETCH NEXT FROM production_cursor INTO @ms_production_in_detail_id
, @doc_date
, @quantity
, @quantity_total
, @is_sumber
END
CLOSE production_cursor
DEALLOCATE production_cursor
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_DETAIL_AUTO_SUPPLY
@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
,@ms_part_list_production_detail_id bigint
,@mode_supply int
,@renew_supply bit
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_part_list_production_detail_id=isnull(tempTable.item.value('detail_id[1]', 'bigint'),-1)
,@mode_supply=isnull(tempTable.item.value('mode_supply[1]', 'int'),0)
,@renew_supply=isnull(tempTable.item.value('renew_supply[1]', 'bit'),0)
FROM @PARAMETER.nodes('param/field') tempTable(item)
declare
@check_ms_part_list_production_id bigint
,@check_ms_part_list_production_no varchar(255)
,@check_ms_part_list_production_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_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_kurang decimal(38,4)
SELECT top (1)
@ms_part_list_production_header_id = ms_part_list_production_id
, @check_old_ms_item_id = vw_part_list_production_detail.ms_item_id
, @check_old_ms_item_custom_no = dt_ms_item.ms_item_custom_no
, @check_kurang = vw_part_list_production_detail.quantity-vw_part_list_production_detail.total_supply
FROM vw_part_list_production_detail
INNER JOIN dt_ms_item ON vw_part_list_production_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (vw_part_list_production_detail.ms_part_list_production_detail_id = @ms_part_list_production_detail_id)
SELECT top (1)
@check_ms_part_list_production_id=ms_part_list_production_id
,@check_ms_part_list_production_no= ms_part_list_production_no
,@check_ms_part_list_production_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
FROM vw_part_list_production_header
WHERE (ms_part_list_production_id = @ms_part_list_production_header_id)
if @check_ms_part_list_production_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header(2)' ;
goto f
end
if not(@check_ms_part_list_production_status_id=0)
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_part_list_production_status_name + ' tidak bisa di rubah ' ;
goto f
end
BEGIN TRANSACTION;
--if @renew_supply=1
--begin
--delete from dt_ms_item_out_detail
--where mode_source=0
--and id_source_header= @ms_car_line_out_header_id
--and id_source= @ms_car_line_out_detail_id
--end
DECLARE @ms_production_in_detail_id bigint
, @doc_date date
, @quantity decimal(18,4)
, @quantity_total decimal(18,4)
, @is_sumber int
DECLARE production_cursor CURSOR FOR
SELECT
ms_production_in_detail_id
, doc_date
, quantity
, sum_qty
, is_sumber
FROM dbo.fn_ms_auto_supply_production_part_list(@check_old_ms_item_id, @mode_supply, @check_ms_part_list_production_date, @check_kurang)
OPEN production_cursor
FETCH NEXT FROM production_cursor INTO @ms_production_in_detail_id
, @doc_date
, @quantity
, @quantity_total
, @is_sumber
WHILE @@FETCH_STATUS = 0
BEGIN
--IF @quantity_total < @check_kurang
-- begin
-- set @xStsno='02';
-- set @xStsdes='Gagal, Supply kurang' ;
-- rollback tran;
-- goto g
-- end
IF @is_sumber = 0
begin
INSERT INTO dt_ms_part_list_out (ms_item_out_detail_id, ms_trans_type_id, ms_part_list_process_detail_id, ms_process_id, quantity, quantity_new_part, quantity_recycle, create_date, create_by, modify_date, modify_by)
VALUES (@ms_production_in_detail_id,1,@ms_part_list_production_detail_id,1,@quantity,@quantity,0,@NOW,@data_by,@NOW,@data_by)
end
ELSE
begin
INSERT INTO dt_ms_part_list_out (ms_item_out_detail_id, ms_trans_type_id, ms_part_list_process_detail_id, ms_process_id, quantity, quantity_new_part, quantity_recycle, create_date, create_by, modify_date, modify_by)
VALUES (@ms_production_in_detail_id,2,@ms_part_list_production_detail_id,1,@quantity,0,@quantity,@NOW,@data_by,@NOW,@data_by)
end
FETCH NEXT FROM production_cursor INTO @ms_production_in_detail_id
, @doc_date
, @quantity
, @quantity_total
, @is_sumber
END
CLOSE production_cursor
DEALLOCATE production_cursor
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
4Used By
No items found