NJC__Documentation::DB

dbo.MG_MS_OUT_PRODUCTION_PART_LIST_HEADER_EDIT

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_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 @ms_part_list_production_id bigint
DECLARE @ms_item_id bigint

DECLARE 
@data_by varchar(50)
,@prod_no varchar(255)
,@prod_date date
,@prod_part_id bigint
,@prod_part_no varchar(100)
,@prod_car_line_no bigint
,@prod_qty decimal(18,4)

SELECT 

@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_part_list_production_id=isnull(tempTable.item.value('ms_part_list_production_id[1]', 'bigint'),-1)
,@prod_no=left(ltrim(rtrim(isnull(tempTable.item.value('prod_no[1]', 'varchar(305)'),''))),255)
,@prod_date=dbo.str_to_date(isnull(tempTable.item.value('prod_date[1]', 'varchar(255)'),''))
,@prod_part_id=isnull(tempTable.item.value('prod_ms_item_id[1]', 'bigint'),-1)
,@prod_part_no=left(ltrim(rtrim(isnull(tempTable.item.value('prod_ms_item_id[1]', 'varchar(100)'),''))),1000)
,@prod_car_line_no=isnull(tempTable.item.value('prod_car_line_no[1]', 'bigint'),-1)
,@prod_qty=isnull(nullif(tempTable.item.value('prod_qty[1]', 'decimal(18,4)'),0),-1)
FROM @PARAMETER.nodes('param/field')  tempTable(item)
 

if @ms_part_list_production_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data yang akan di edit' ;
 goto f
end

declare @check_ms_part_list_production_id bigint
,@check_prod_no varchar(255)
,@check_prod_date date
,@check_prod_info  varchar(1000)
,@check_prod_part_no varchar(255)
,@check_ms_part_list_prduction_header_status_id int
,@check_ms_part_list_prduction_header_status_name  varchar(255)

SELECT  top (1)     
  @check_ms_part_list_production_id= ms_part_list_production_id
 ,@check_prod_no= ms_part_list_production_no
 ,@check_prod_date= ms_part_list_production_date
 ,@check_prod_info= status_info
 ,@check_ms_part_list_prduction_header_status_id= ms_part_list_production_status_id
 ,@check_ms_part_list_prduction_header_status_name= ms_part_list_production_status_name
FROM            vw_part_list_production_header
WHERE        (ms_part_list_production_id = @ms_part_list_production_id)

DECLARE @prod_ms_item_id bigint 

SELECT  top(1) @prod_ms_item_id = ms_item_id
FROM            dt_ms_item
WHERE        (part_no = @prod_part_no) 


if @check_ms_part_list_production_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end

if not(@check_ms_part_list_prduction_header_status_id=0)
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Production dengan status ' + @check_ms_part_list_prduction_header_status_name + ' tidak bisa di rubah ' ;
goto f 
end

if @prod_no =''
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Nomor Production tidak boleh kosong' ;
goto f
end

if @prod_date is null
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Tanggal Production tidak boleh kosong' ;
goto f
end 
 
if exists(select * from vw_part_list_production_header where  ms_part_list_production_no=@prod_no and not(ms_part_list_production_id=-1) and not(    (ms_part_list_production_id = @ms_part_list_production_id)))
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Nomor Dokumen Sudah Ada' ;
goto f
end

set @ms_item_id=-1
if len(@prod_part_no)>0
begin 
 SELECT  top(1) @ms_item_id =     ms_item_id
 FROM            dt_ms_item
 WHERE        (part_no = @prod_part_no) 
  
 if @ms_item_id is null
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, Part List ' + @prod_part_no +' tidak terdaftar' ;
  goto f
 end
end
 
if not(@xStsno='00')
begin
 goto f
end

BEGIN TRANSACTION;    

 UPDATE       dt_ms_part_list_production_header
 SET                ms_part_list_production_no = @prod_no
 , ms_part_list_production_date = @prod_date
 , quantity = @prod_qty
 , ms_car_line_no = @prod_car_line_no
 , ms_item_id = @prod_part_id
 , modify_date = @now, modify_by = @data_by              
 WHERE        (ms_part_list_production_id = @ms_part_list_production_id)

 DELETE FROM dt_ms_part_list_production_detail 
 WHERE ms_part_list_production_id = @ms_part_list_production_id

 INSERT INTO dt_ms_part_list_production_detail(
  ms_part_list_production_id
  , ms_item_id
  , quantity
  , create_date
  , create_by
  , modify_date
  , modify_by
 )
 select 
    @ms_part_list_production_id
  , ms_item_part_id
  , isnull(@prod_qty * qty_jb,0) as quantity_production
  , @NOW
  , @data_by
  , @NOW
  , @data_by

 from dt_ms_part_list_detail where ms_item_id = @prod_part_id

COMMIT TRANSACTION; 
DECLARE @detail xml
SET  @detail=(
 SELECT        
  ms_part_list_production_id AS rID 
  , ms_part_list_production_status_name AS r1 
  , @prod_no AS r2 
  , dbo.date_to_str(@prod_date ) AS r3 
  , status_info AS r4 
 FROM            vw_part_list_production_header
 where ms_part_list_production_id=@ms_part_list_production_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