NJC__Documentation::DB

dbo.MG_MS_OUT_CHANGE_PART_LIST_HEADER_ADD

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_HEADER_ADD
@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 @detail 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)
,@change_part_list_no varchar(255)
,@change_part_list_date date
,@change_part_list_assets_list_id bigint
,@change_part_list_assets_list_name varchar(100)
,@change_part_car_line_no bigint

SELECT 
 @data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@change_part_list_no=left(ltrim(rtrim(isnull(tempTable.item.value('change_part_list_no[1]', 'varchar(255)'),''))),255)
,@change_part_list_date=dbo.str_to_date(isnull(tempTable.item.value('change_part_list_date[1]', 'varchar(255)'),''))
,@change_part_list_assets_list_id=isnull(tempTable.item.value('change_part_list_assets_list_id[1]', 'bigint'),-1)
,@change_part_list_assets_list_name=left(ltrim(rtrim(isnull(tempTable.item.value('change_part_list_assets_list_name[1]', 'varchar(100)'),''))),1000)
,@change_part_car_line_no=isnull(tempTable.item.value('change_part_car_line_no[1]', 'bigint'),-1)
FROM @PARAMETER.nodes('param/field')  tempTable(item)

if @change_part_list_no =''
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Nomor Change Part tidak boleh kosong' ;
  goto f
 end

if @change_part_list_date is null
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Tanggal Change Part tidak boleh kosong' ;
  goto f
 end

if @change_part_list_assets_list_id = 0
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Assets List tidak boleh kosong' ;
  goto f
 end

if @change_part_car_line_no = 0
 begin
  set @xStsno='02';
  set @xStsdes='Gagal,Car line No wajib' ;
 goto f
 end

if exists(select * from vw_part_list_change_part_header where  ms_part_list_change_part_no = @change_part_list_no and not(ms_part_list_change_part_status_id=-1))
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Nomor Production Sudah Ada' ;
  goto f
 end

if @change_part_list_assets_list_id=-1
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Assets List No wajib di isi' ;
  goto f
 end

declare @check_ms_item_id bigint ,
  @check_ms_part_list_production_id bigint

SELECT  top(1) @check_ms_item_id = ms_item_id, @check_ms_part_list_production_id = ms_part_list_production_id
FROM            dt_ms_assets_list
WHERE        (assets_list_id = @change_part_list_assets_list_id) 
 
if not(@xStsno='00')
 begin
  goto f
 end

declare @ms_part_list_change_part_id bigint
declare @ms_part_list_change_part_h_status_id bigint

BEGIN TRANSACTION;    

 INSERT INTO dt_ms_part_list_change_part_header
  ( ms_part_list_production_id
  , ms_part_list_change_part_no
  , ms_part_list_change_part_date
  , ms_item_id
  , assets_list_id
  , ms_car_line_no
  , create_date
  , create_by
  , modify_date
  , modify_by
  )
 VALUES      
  ( @check_ms_part_list_production_id
  , @change_part_list_no
  , @change_part_list_date
  , @check_ms_item_id
  , @change_part_list_assets_list_id
  , @change_part_car_line_no
  , @NOW
  , @data_by
  , @NOW
  , @data_by
 )

 SET @ms_part_list_change_part_id=SCOPE_IDENTITY();

 INSERT INTO dt_ms_part_list_change_part_h_status(ms_part_list_change_part_id, ms_part_list_change_part_status_id, status_info, create_date, create_by)
 VALUES        (@ms_part_list_change_part_id, 0, N'',@now,@data_by)

 SET @ms_part_list_change_part_h_status_id=SCOPE_IDENTITY();
 
 UPDATE dt_ms_part_list_change_part_header
 SET ms_part_list_change_part_h_status_id=@ms_part_list_change_part_h_status_id
 WHERE  ms_part_list_change_part_id=@ms_part_list_change_part_id

 DECLARE @temp_table table(
  id bigint
  , ms_item_id bigint
 )

 INSERT INTO dt_ms_part_list_change_part_detail(
  ms_part_list_change_part_id
  , ms_item_id
  , quantity
  , quantity_new_part
  , quantity_recycle
  , quantity_supply
  , create_date
  , create_by
  , modify_date
  , modify_by
 )
 OUTPUT  INSERTED.ms_part_list_change_part_detail_id, INSERTED.ms_item_id
 INTO @temp_table

 SELECT @ms_part_list_change_part_id
  , c.ms_item_id
  , sum(ISNULL(a.quantity,0) + ISNULL(a.quantity_recycle,0))
  , sum(ISNULL(a.quantity,0))
  , sum(ISNULL(a.quantity_recycle ,0)) 
  , sum(ISNULL(a.quantity,0))
  , @NOW
  , @data_by
  , @NOW
  , @data_by
 FROM dt_ms_assets_list_detail a
 LEFT OUTER JOIN dt_ms_part_list_out b ON a.ms_part_list_out_id = b.ms_part_list_out_id
 LEFT OUTER JOIN dt_ms_part_list_production_detail c ON b.ms_part_list_process_detail_id = c.ms_part_list_production_detail_id
 WHERE a.assets_list_id = @change_part_list_assets_list_id
 GROUP BY c.ms_item_id

 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
 )
 SELECT 
  b.ms_item_out_detail_id
  , b.ms_trans_type_id
  , d.id
  , -2
  , sum(ISNULL(a.quantity,0) + ISNULL(a.quantity_recycle,0))
  , sum(ISNULL(a.quantity,0))
  , sum(ISNULL(a.quantity_recycle ,0)) 
  , @NOW
  , @data_by
  , @NOW
  , @data_by
 FROM dt_ms_assets_list_detail a
 LEFT OUTER JOIN dt_ms_part_list_out b ON a.ms_part_list_out_id = b.ms_part_list_out_id
 LEFT OUTER JOIN dt_ms_part_list_production_detail c ON b.ms_part_list_process_detail_id = c.ms_part_list_production_detail_id
 LEFT OUTER JOIN @temp_table d ON c.ms_item_id = d.ms_item_id
 WHERE a.assets_list_id = @change_part_list_assets_list_id
 GROUP BY c.ms_item_id, b.ms_item_out_detail_id, b.ms_trans_type_id, d.id, b.ms_process_id
 ORDER BY b.ms_trans_type_id

COMMIT TRANSACTION; 

set  @detail=(
SELECT        
  ms_part_list_change_part_id AS rID 
  , ms_part_list_change_part_status_name AS r1 
  , @change_part_list_no AS r2 
  , dbo.date_to_str(@change_part_list_date ) AS r3 
  , status_info AS r4  
FROM            vw_part_list_change_part_header
WHERE ms_part_list_change_part_id=@ms_part_list_change_part_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

Used By

No items found