NJC__Documentation::DB

dbo.MG_MS_OUT_PRODUCTION_PART_LIST_HEADER_CANCEL

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_CANCEL
@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
,@move_business_date bit
,@info varchar(255)

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)
, @info=left(ltrim(rtrim(isnull(tempTable.item.value('info[1]', 'varchar(300)'),''))),255)
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 cancel' ;
goto f
end

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_header_status_id int
,@check_ms_part_list_production_header_status_name  varchar(255) 

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_header_status_id= ms_part_list_production_status_id
 ,@check_ms_part_list_production_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_header_id)
 

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

if @check_ms_part_list_production_header_status_id=-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Production sudah dalam status ' + @check_ms_part_list_production_header_status_name ;
goto f 
end
  
--if @check_ms_part_list_production_header_status_id =1
--begin
-- declare @check_avg_final_avg_name varchar(255)
-- ,@check_avg_start_date varchar(255)
-- ,@check_avg_end_date varchar(255)

-- SELECT top 1
-- @check_avg_final_avg_name=dt_ms_cost_final_avg.final_avg_name
-- , @check_avg_start_date=dt_ms_cost_final_avg.start_date
-- , @check_avg_end_date=dt_ms_cost_final_avg.end_date
-- FROM dt_ms_date_business INNER JOIN
-- dt_ms_cost_final_avg ON dt_ms_date_business.ms_cost_final_avg_id = dt_ms_cost_final_avg.ms_cost_final_avg_id INNER JOIN
-- dt_ms_cost_final_avg_h_status ON dt_ms_cost_final_avg.ms_cost_final_avg_h_status_id = dt_ms_cost_final_avg_h_status.ms_cost_final_avg_h_status_id
-- WHERE (dt_ms_cost_final_avg_h_status.ms_cost_final_avg_status_id = 1)
-- AND (dt_ms_date_business.ms_date_business_id =@check_ms_date_business_id)

-- if @check_avg_final_avg_name is not null
-- begin
-- set @xStsno='02';
-- set @xStsdes='Gagal, Dokumen sudah terkait FINAL AVG ' + @check_avg_final_avg_name ;
-- goto f
-- end

--end

--- CHECK APAKAH TERPAKAI SEBAGAI SUPPLY

if @check_ms_part_list_production_header_status_id=1
begin

 declare @result varchar(max)
 SET @resultX= ( 
 SELECT       
   'type : '+ ms_process_name + 
  +' ,Doc no: ' +  doc_no
  +' ,Doc Date: ' +  isnull(dbo.date_to_str(doc_date),'')
  +' ,Status : ' +  status_name
  + @pemisah 
 AS [text()] 
 FROM  
 ( 
  SELECT  assets_list_id, ms_process_name, quantity, doc_no, doc_date, ms_item_id, status_id, status_name
  FROM  vw_ms_part_list_in_out_to_change_part_detail 
  where not(status_id =-1) and (ms_part_list_production_id=@ms_part_list_production_header_id)
  UNION ALL
  SELECT  assets_list_id, ms_process_name, quantity, doc_no, doc_date, ms_item_id, status_id, status_name
  FROM            vw_ms_part_list_in_out_to_disamble_detail
  where not(status_id =-1) and (ms_part_list_production_id=@ms_part_list_production_header_id) 
 )data
  
 For XML PATH (''))     
 SET @resultX= REPLACE(@resultX,@pemisah_replace,@pemisah);
 IF @resultX is not null
 BEGIN 
    SET @xStsno='17';
    SET @xStsdes=' Gagal , Data Terpakai di sebagai supply dokumen : ' + @pemisah+  @pemisah+ @resultX + @pemisah+  @pemisah+ ', Cancel Terlebih dahulu dokumen terkait supply' ;
   GOto f
 end    
end  

declare @ms_part_list_production_header_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,@info ,@now,@data_by)

SET @ms_part_list_production_header_h_status_id=SCOPE_IDENTITY();
 
UPDATE dt_ms_part_list_production_header
set ms_part_list_production_h_status_id=@ms_part_list_production_header_h_status_id 
where  ms_part_list_production_id=@ms_part_list_production_header_id 
 
COMMIT TRANSACTION; 
declare @detail xml
--set @detail=(
-- SELECT
-- ms_part_list_production_id AS rID
-- , ms_part_list_production_status_name AS r1
-- , ms_part_list_production_no AS r2
-- , dbo.date_to_str(ms_part_list_production_date ) AS r3
-- , status_info AS r4
-- --, ms_type_prosses_name AS r5
-- --, ms_car_line_no AS r6
-- --, ms_car_line_name AS r7
-- --, status_info AS r8
-- --, dbo.date_to_str2(status_date ) AS r9
-- --, status_by AS r10
-- --, dbo.date_to_str2(create_date ) AS r11
-- --, create_by AS r12
-- --, dbo.date_to_str2(modify_date ) AS r13
-- --, modify_by AS r14
-- --, ms_type_prosses_id AS r15
-- --, ms_car_line_out_header_status_id AS r16
-- --, ms_car_line_out_header_h_status_id AS r17
-- FROM vw_part_list_production_header
-- where ms_part_list_production_id=@ms_part_list_production_header_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