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_EDIT
@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
,@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_production_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_production_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header' ;
goto f
end
declare @check_ms_part_list_out_header_id bigint
,@check_prod_no varchar(255)
,@check_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_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_ms_car_line_no int
SELECT top (1)
@ms_part_list_production_header_id= ms_part_list_production_id
, @check_old_ms_item_id= dt_ms_part_list_production_detail.ms_item_id
, @check_old_ms_item_custom_no= dt_ms_item.ms_item_custom_no
FROM dt_ms_part_list_production_detail
INNER JOIN dt_ms_item ON dt_ms_part_list_production_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (dt_ms_part_list_production_detail.ms_part_list_production_detail_id = @ms_part_list_production_detail_id)
SELECT top (1)
@check_ms_part_list_out_header_id=ms_part_list_production_id
,@check_prod_no= ms_part_list_production_no
,@check_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
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 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
if @quantity =0
begin
set @xStsno='02';
set @xStsdes='Gagal, Jumlah Item harus lebih besar dari 0' ;
goto f
end
declare @new_ms_item_id bigint
, @new_part_no varchar(255)
, @new_part_name varchar(255)
, @new_ms_item_custom_no varchar(255)
, @new_ms_item_h_status_id int
, @new_allow_to_production bit
, @new_mandatory_car_line bit
, @new_allow_to_scrap bit
, @new_allow_to_repair bit
, @new_allow_to_selling bit
SELECT top(1)
@new_ms_item_id= ms_item_id
, @new_part_no= part_no
, @new_part_name=part_name
, @new_ms_item_custom_no=ms_item_custom_no
, @new_ms_item_h_status_id=ms_item_h_status_id
, @new_allow_to_production=allow_to_production
, @new_mandatory_car_line=mandatory_car_line
, @new_allow_to_scrap=allow_to_scrap
, @new_allow_to_repair=allow_to_repair
, @new_allow_to_selling=allow_to_selling
FROM vw_ms_item
WHERE (ms_item_id = @ms_item_id) AND (part_no = @part_no)
if @new_ms_item_id is null
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' tidak terdaftar' ;
goto f
end
if @new_allow_to_production=0
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' tidak di izinkan di keluarkan ke produksi' ;
goto f
end
if @check_ms_car_line_no=-1 and @new_mandatory_car_line=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' hanya bisa di keluarkan ke produksi yang mempunyai CAR LINE (Mandatory CAR LINE)' ;
goto f
end
declare @quantity_jb decimal(38,4)
select @quantity_jb = quantity from dt_ms_part_list_production_header
where ms_part_list_production_id = @ms_part_list_production_header_id
BEGIN TRANSACTION;
UPDATE dt_ms_part_list_production_detail
SET ms_part_list_production_id = @ms_part_list_production_header_id
, ms_item_id = @ms_item_id
, quantity = isnull(@quantity * @quantity_jb,0)
, modify_date = @now
, modify_by = @data_by
WHERE (ms_part_list_production_detail_id= @ms_part_list_production_detail_id)
--- JIKA NEW ITEM ID TIDAK SAMA DENGAN OLD ITEM ID
if not(@new_ms_item_id=@check_old_ms_item_id)
begin
--delete from dt_ms_item_out_detail
--where mode_source =0
--and id_source =@ms_part_list_out_detail_id
delete from dt_ms_item_out_detail_used where ms_item_out_detail_id = @ms_part_list_production_detail_id
end
-- delete data_suplay dari stock
--check data suplay dari stock awal apakah sama part custom nya
COMMIT TRANSACTION;
declare @detail xml
--set @detail=(
-- SELECT
-- ms_part_list_production_detail_id AS rID
-- , ms_item_id AS r1
-- , part_no AS r2
-- , part_name AS r3
-- , ms_item_base_no as r3i
-- , uom AS r4
-- , cast(quantity_production AS decimal(18,4)) AS r5
-- --, cast(total_supply AS decimal(18,4)) AS r5s
-- --, info AS r6
-- , dbo.date_to_str(create_date ) AS r7
-- , create_by AS r8
-- , dbo.date_to_str(modify_date ) AS r9
-- , modify_by AS r10
-- , ms_part_list_production_id AS r11
-- --, r_s
-- FROM vw_part_list_production_detail
-- where ms_part_list_production_detail_id=@ms_part_list_production_detail_id
-- for xml path('detail') )
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_EDIT
@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
,@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_production_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_production_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data header' ;
goto f
end
declare @check_ms_part_list_out_header_id bigint
,@check_prod_no varchar(255)
,@check_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_old_ms_item_id bigint
,@check_old_ms_item_custom_no varchar(255)
,@check_ms_car_line_no int
SELECT top (1)
@ms_part_list_production_header_id= ms_part_list_production_id
, @check_old_ms_item_id= dt_ms_part_list_production_detail.ms_item_id
, @check_old_ms_item_custom_no= dt_ms_item.ms_item_custom_no
FROM dt_ms_part_list_production_detail
INNER JOIN dt_ms_item ON dt_ms_part_list_production_detail.ms_item_id = dt_ms_item.ms_item_id
WHERE (dt_ms_part_list_production_detail.ms_part_list_production_detail_id = @ms_part_list_production_detail_id)
SELECT top (1)
@check_ms_part_list_out_header_id=ms_part_list_production_id
,@check_prod_no= ms_part_list_production_no
,@check_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
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 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
if @quantity =0
begin
set @xStsno='02';
set @xStsdes='Gagal, Jumlah Item harus lebih besar dari 0' ;
goto f
end
declare @new_ms_item_id bigint
, @new_part_no varchar(255)
, @new_part_name varchar(255)
, @new_ms_item_custom_no varchar(255)
, @new_ms_item_h_status_id int
, @new_allow_to_production bit
, @new_mandatory_car_line bit
, @new_allow_to_scrap bit
, @new_allow_to_repair bit
, @new_allow_to_selling bit
SELECT top(1)
@new_ms_item_id= ms_item_id
, @new_part_no= part_no
, @new_part_name=part_name
, @new_ms_item_custom_no=ms_item_custom_no
, @new_ms_item_h_status_id=ms_item_h_status_id
, @new_allow_to_production=allow_to_production
, @new_mandatory_car_line=mandatory_car_line
, @new_allow_to_scrap=allow_to_scrap
, @new_allow_to_repair=allow_to_repair
, @new_allow_to_selling=allow_to_selling
FROM vw_ms_item
WHERE (ms_item_id = @ms_item_id) AND (part_no = @part_no)
if @new_ms_item_id is null
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' tidak terdaftar' ;
goto f
end
if @new_allow_to_production=0
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' tidak di izinkan di keluarkan ke produksi' ;
goto f
end
if @check_ms_car_line_no=-1 and @new_mandatory_car_line=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Part no ' + @part_no +' hanya bisa di keluarkan ke produksi yang mempunyai CAR LINE (Mandatory CAR LINE)' ;
goto f
end
declare @quantity_jb decimal(38,4)
select @quantity_jb = quantity from dt_ms_part_list_production_header
where ms_part_list_production_id = @ms_part_list_production_header_id
BEGIN TRANSACTION;
UPDATE dt_ms_part_list_production_detail
SET ms_part_list_production_id = @ms_part_list_production_header_id
, ms_item_id = @ms_item_id
, quantity = isnull(@quantity * @quantity_jb,0)
, modify_date = @now
, modify_by = @data_by
WHERE (ms_part_list_production_detail_id= @ms_part_list_production_detail_id)
--- JIKA NEW ITEM ID TIDAK SAMA DENGAN OLD ITEM ID
if not(@new_ms_item_id=@check_old_ms_item_id)
begin
--delete from dt_ms_item_out_detail
--where mode_source =0
--and id_source =@ms_part_list_out_detail_id
delete from dt_ms_item_out_detail_used where ms_item_out_detail_id = @ms_part_list_production_detail_id
end
-- delete data_suplay dari stock
--check data suplay dari stock awal apakah sama part custom nya
COMMIT TRANSACTION;
declare @detail xml
--set @detail=(
-- SELECT
-- ms_part_list_production_detail_id AS rID
-- , ms_item_id AS r1
-- , part_no AS r2
-- , part_name AS r3
-- , ms_item_base_no as r3i
-- , uom AS r4
-- , cast(quantity_production AS decimal(18,4)) AS r5
-- --, cast(total_supply AS decimal(18,4)) AS r5s
-- --, info AS r6
-- , dbo.date_to_str(create_date ) AS r7
-- , create_by AS r8
-- , dbo.date_to_str(modify_date ) AS r9
-- , modify_by AS r10
-- , ms_part_list_production_id AS r11
-- --, r_s
-- FROM vw_part_list_production_detail
-- where ms_part_list_production_detail_id=@ms_part_list_production_detail_id
-- for xml path('detail') )
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