NJC__Documentation::DB

dbo.MG_MS_PRODUCTION_RETUR_DETAIL_DELETE

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_PRODUCTION_RETUR_DETAIL_DELETE
@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_production_retur_id bigint 
,@ms_production_retur_detail_id bigint   


SELECT 
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
,@ms_production_retur_id=isnull(tempTable.item.value('ms_production_retur_id[1]', 'bigint'),-1)
,@ms_production_retur_detail_id=isnull(tempTable.item.value('ms_production_retur_detail_id[1]', 'bigint'),-1)
 FROM @PARAMETER.nodes('param/field')  tempTable(item) 


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

declare @check_ms_production_retur_id bigint
, @check_retur_no varchar(255)
, @check_retur_date date
, @check_status_production_retur_id  int  
, @check_status_production_retur_name varchar(255) 
, @check_quantity_sisa decimal(24,4) 

SELECT   top(1)     
  @check_ms_production_retur_id=vw_ms_production_retur_header.ms_production_retur_id
, @check_retur_no=vw_ms_production_retur_header.retur_no
, @check_retur_date=vw_ms_production_retur_header.retur_date
, @check_status_production_retur_id=vw_ms_production_retur_header.status_production_retur_id
, @check_status_production_retur_name=vw_ms_production_retur_header.status_production_retur_name 
, @check_quantity_sisa=vw_ms_production_retur_detail.qty_source_sisa + vw_ms_production_retur_detail.qty_retur
FROM            vw_ms_production_retur_header INNER JOIN
                         vw_ms_production_retur_detail ON vw_ms_production_retur_header.ms_production_retur_id = vw_ms_production_retur_detail.ms_production_retur_id
WHERE        (vw_ms_production_retur_detail.ms_production_retur_detail_id = @ms_production_retur_detail_id) AND (vw_ms_production_retur_header.ms_production_retur_id = @ms_production_retur_id)


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

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

BEGIN TRANSACTION;    

 delete from        dt_ms_production_retur_detail
WHERE        (ms_production_retur_detail_id = @ms_production_retur_detail_id)


COMMIT TRANSACTION; 
declare @detail xml
set  @detail=(
 SELECT        
  ms_production_retur_id AS rID 
, status_production_retur_name AS r1 
, retur_no AS r2 
, dbo.date_to_str(retur_date ) AS r3 
, receive_no AS r4 
, dbo.date_to_str(receive_date ) AS r5 
, count_item AS r6 
, count_adjusment_avg AS r6a 
, max_doc_date  AS r6m 
, status_info AS r7 
, status_production_retur_id AS r8 
, ms_production_retur_h_status_id AS r9 
, dbo.date_to_str(status_date ) AS r10 
, status_by AS r11 
, dbo.date_to_str(create_date ) AS r12 
, create_by AS r13 
, dbo.date_to_str(modify_date ) AS r14 
, modify_by AS r15 
 FROM            vw_ms_production_retur_header
 where ms_production_retur_id=@ms_production_retur_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

--EXEC MG_MS_PRODUCTION_RETUR_DETAIL_DELETE
--'12json2::1ABA0127810007'
GO

Used By

No items found