NJC__Documentation::DB

dbo.MG_MS_OUT_PRODUCTION_PART_LIST_DETAIL_SUPPLY_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_DETAIL_SUPPLY_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_detail_id bigint 
,@ms_part_list_out_detail_id bigint 
,@ms_item_in_detail_id bigint 
,@quantity decimal(38,4) 
,@is_sumber int


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('ms_part_list_production_detail_id[1]', 'bigint'),-1)
,@ms_part_list_out_detail_id=isnull(tempTable.item.value('ms_part_list_out_detail_id[1]', 'bigint'),-1)
,@ms_item_in_detail_id=isnull(tempTable.item.value('ms_item_in_detail_id[1]', 'bigint'),-1)
,@quantity=dbo.StrToDec4(isnull( tempTable.item.value('quantity[1]', 'varchar(255)'),'0'))
,@is_sumber=isnull(tempTable.item.value('is_sumber[1]', 'int'),-1)
FROM @PARAMETER.nodes('param/field')  tempTable(item)


if @ms_item_in_detail_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data supply' ;
goto f
end
 

if @ms_part_list_production_detail_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data item' ;
goto f
end

declare @check_ms_part_list_production_detail_id bigint
,@check_ms_part_list_production_header_id bigint
,@check_ms_part_list_production_no varchar(255)
,@check_ms_part_list_production_date date
,@check_doc_info  varchar(1000)
,@check_ms_part_list_production_status_id int
,@check_ms_part_list_production_status_name  varchar(255)
 
SELECT top(1)       
 @check_ms_part_list_production_detail_id=dt_ms_part_list_production_detail.ms_part_list_production_detail_id
,@check_ms_part_list_production_status_id=dt_ms_part_list_production_h_status.ms_part_list_production_status_id
,@check_ms_part_list_production_no= dt_ms_part_list_production_header.ms_part_list_production_no
,@check_ms_part_list_production_date= dt_ms_part_list_production_header.ms_part_list_production_date
,@check_ms_part_list_production_status_name= enum_ms_part_list_production_status.ms_part_list_production_status_name
,@check_ms_part_list_production_header_id=        dt_ms_part_list_production_header.ms_part_list_production_id
FROM            dt_ms_part_list_production_detail 
INNER JOIN dt_ms_part_list_production_header ON dt_ms_part_list_production_detail.ms_part_list_production_id = dt_ms_part_list_production_header.ms_part_list_production_id 
INNER JOIN dt_ms_part_list_production_h_status ON dt_ms_part_list_production_header.ms_part_list_production_h_status_id = dt_ms_part_list_production_h_status.ms_part_list_production_h_status_id 
INNER JOIN enum_ms_part_list_production_status ON dt_ms_part_list_production_h_status.ms_part_list_production_status_id = enum_ms_part_list_production_status.ms_part_list_production_status_id
WHERE        (dt_ms_part_list_production_detail.ms_part_list_production_detail_id = @ms_part_list_production_detail_id)


if @check_ms_part_list_production_detail_id =-1
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Pilih data detail(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 @sisa decimal(38,4)
declare @source_status_id  int 
declare @source_status_name as varchar(255)

SELECT     top (1) @sisa =  quantity + quantity_sisa
 FROM            vw_part_list_supply_available
 WHERE        (ms_production_in_detail_id = @ms_item_in_detail_id)

if @sisa is null
 begin
  set @xStsno='02';
  set @xStsdes='Gagal, data tidak di temukan'
 goto f
 end 

if @quantity >@sisa
begin
 set @xStsno='02';
 set @xStsdes='Gagal, Jumlah melebihi sisa stock dokumen ' + 
    @pemisah + ' SISA : ' + cast(@sisa  as varchar(255))  + 
    @pemisah + ' QTY : ' + cast(@quantity  as varchar(255)) 
    ;
goto f
end 

BEGIN TRANSACTION;    

 if @is_sumber = 0
  begin
   UPDATE dt_ms_part_list_out SET 
    quantity = @quantity
    , quantity_new_part = @quantity
   WHERE ms_item_out_detail_id = @ms_item_in_detail_id
  end
 else
  begin
   UPDATE dt_ms_part_list_out set 
    quantity = @quantity
    , quantity_recycle = @quantity
   WHERE ms_item_out_detail_id = @ms_item_in_detail_id
  end
 
COMMIT TRANSACTION; 
declare @detail xml

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