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_CAR_LINE_HEADER_APPROVE
@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_car_line_out_header_id bigint
,@allow_move_ms_date_business bit
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
, @ms_car_line_out_header_id=isnull(tempTable.item.value('ms_car_line_out_header_id[1]', 'bigint'),-1)
, @allow_move_ms_date_business =isnull(tempTable.item.value('move_business_date[1]', 'bit'),0)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_car_line_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit' ;
goto f
end
declare @check_ms_car_line_out_header_id bigint
,@check_doc_no varchar(255)
,@check_doc_date date
,@check_doc_info varchar(1000)
,@check_ms_car_line_out_header_status_id int
,@check_ms_car_line_out_header_status_name varchar(255)
SELECT top (1)
@check_ms_car_line_out_header_id=ms_car_line_out_header_id
,@check_doc_no= doc_no
,@check_doc_date= doc_date
,@check_doc_info= doc_info
,@check_ms_car_line_out_header_status_id= ms_car_line_out_header_status_id
,@check_ms_car_line_out_header_status_name= ms_car_line_out_header_status_name
FROM vw_ms_out_car_line_header
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id)
if @check_ms_car_line_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end
if @check_ms_car_line_out_header_status_id=-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_car_line_out_header_status_name + ' tidak bisa di Approve ' ;
goto f
end
if @check_ms_car_line_out_header_status_id=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_car_line_out_header_status_name + ' tidak bisa di Approve Lagi' ;
goto f
end
if (SELECT COUNT(*) AS Expr1
FROM dt_ms_car_line_out_detail
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id))=0
begin
set @xStsno='02';
set @xStsdes='Gagal, Tidak ada detail , masukan detail item ' ;
goto f
end
declare @new_daily_out_item table (
ms_item_out_move_avg_id bigint
,ms_date_business_id int
,ms_item_id bigint
)
declare @result_date_business_id bigint,
@result_date_business date,
@result_date_business_id_from bigint,
@result_date_business_from date,
@is_move_date_business bit,
@business_date date=@check_doc_date
EXEC [dbo].[MG_MS_CHECK_BUSINESS_DATE_AND_AVG]
@business_date = @business_date,
@allow_move_ms_date_business = @allow_move_ms_date_business,
@result_date_business_id = @result_date_business_id OUTPUT,
@result_date_business = @result_date_business OUTPUT,
@result_date_business_id_from = @result_date_business_id_from OUTPUT,
@result_date_business_from = @result_date_business_from OUTPUT,
@is_move_date_business = @is_move_date_business OUTPUT,
@xStsno = @xStsno OUTPUT,
@xStsdes = @xStsdes OUTPUT
if not(@xStsno='00')
begin
goto f
end
declare @ms_car_line_out_header_h_status_id bigint
BEGIN TRANSACTION;
INSERT INTO dt_ms_car_line_out_header_h_status
(ms_car_line_out_header_id, ms_car_line_out_header_status_id, status_info, create_date, create_by)
VALUES (@ms_car_line_out_header_id, 1, N'',@now,@data_by)
set @ms_car_line_out_header_h_status_id=SCOPE_IDENTITY();
update dt_ms_car_line_out_header
set ms_car_line_out_header_h_status_id=@ms_car_line_out_header_h_status_id
where ms_car_line_out_header_id=@ms_car_line_out_header_id
---- CARI AVG MOVE OUT BERDASARKAN TANGGAL YANG SAMA
UPDATE dt_ms_car_line_out_detail
SET ms_item_out_move_avg_id = dt_ms_item_daily_out_move_avg.ms_item_out_move_avg_id
, is_move_business_date = @is_move_date_business
, ms_date_business_id_from =@result_date_business_id_from
, ms_date_business_id =@result_date_business_id
FROM dt_ms_car_line_out_detail INNER JOIN
dt_ms_item_daily_out_move_avg ON dt_ms_car_line_out_detail.ms_item_id = dt_ms_item_daily_out_move_avg.ms_item_id
WHERE (dt_ms_car_line_out_detail.ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (dt_ms_item_daily_out_move_avg.ms_date_business_id = @result_date_business_id)
INSERT INTO dt_ms_item_daily_out_move_avg
(ms_date_business_id, ms_item_in_move_avg_id, ms_item_id, ms_item_h_price_id,ms_cost_final_avg_id)
output inserted.ms_item_out_move_avg_id,inserted.ms_date_business_id,inserted.ms_item_id into @new_daily_out_item
SELECT
@result_date_business_id
, ( SELECT TOP (1) dt_ms_item_daily_in_move_avg.ms_item_in_move_avg_id
FROM dt_ms_item_daily_in_move_avg INNER JOIN
dt_ms_date_business ON dt_ms_item_daily_in_move_avg.ms_date_business_id = dt_ms_date_business.ms_date_business_id
WHERE (dt_ms_item_daily_in_move_avg.ms_item_id = dt_ms_car_line_out_detail.ms_item_id ) AND (dt_ms_date_business.ms_date_business <= @check_doc_date)
ORDER BY dt_ms_date_business.ms_date_business DESC
)
,ms_item_id
,-1
,-1
FROM dt_ms_car_line_out_detail
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (ms_item_out_move_avg_id = - 1 OR
ms_item_out_move_avg_id IS NULL)
group by ms_item_id
if (select count(*) from @new_daily_out_item )>0
begin
UPDATE dt_ms_car_line_out_detail
SET ms_item_out_move_avg_id = new_avg.ms_item_out_move_avg_id
, is_move_business_date = @is_move_date_business
, ms_date_business_id_from =@result_date_business_id_from
, ms_date_business_id =@result_date_business_id
FROM dt_ms_car_line_out_detail INNER JOIN
@new_daily_out_item AS new_avg ON dt_ms_car_line_out_detail.ms_item_id = new_avg.ms_item_id
WHERE (dt_ms_car_line_out_detail.ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (dt_ms_car_line_out_detail.ms_item_out_move_avg_id = - 1 OR
dt_ms_car_line_out_detail.ms_item_out_move_avg_id IS NULL)
end
COMMIT TRANSACTION;
declare @detail xml
set @detail=(
SELECT
ms_car_line_out_header_id AS rID
, ms_car_line_out_header_status_name AS r1
, doc_no AS r2
, dbo.date_to_str(doc_date ) AS r3
, doc_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_ms_out_car_line_header
where ms_car_line_out_header_id=@ms_car_line_out_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
--EXEC MG_MS_OUT_CAR_LINE_HEADER_APPROVE
--'1 2 json 2 ::1 ABA01 27 8 10007 '
GO
GO
create procedure dbo.MG_MS_OUT_CAR_LINE_HEADER_APPROVE
@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_car_line_out_header_id bigint
,@allow_move_ms_date_business bit
SELECT
@data_by=left(ltrim(rtrim(isnull(tempTable.item.value('data_by[1]', 'varchar(100)'),''))),50)
, @ms_car_line_out_header_id=isnull(tempTable.item.value('ms_car_line_out_header_id[1]', 'bigint'),-1)
, @allow_move_ms_date_business =isnull(tempTable.item.value('move_business_date[1]', 'bit'),0)
FROM @PARAMETER.nodes('param/field') tempTable(item)
if @ms_car_line_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit' ;
goto f
end
declare @check_ms_car_line_out_header_id bigint
,@check_doc_no varchar(255)
,@check_doc_date date
,@check_doc_info varchar(1000)
,@check_ms_car_line_out_header_status_id int
,@check_ms_car_line_out_header_status_name varchar(255)
SELECT top (1)
@check_ms_car_line_out_header_id=ms_car_line_out_header_id
,@check_doc_no= doc_no
,@check_doc_date= doc_date
,@check_doc_info= doc_info
,@check_ms_car_line_out_header_status_id= ms_car_line_out_header_status_id
,@check_ms_car_line_out_header_status_name= ms_car_line_out_header_status_name
FROM vw_ms_out_car_line_header
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id)
if @check_ms_car_line_out_header_id =-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Pilih data yang akan di edit(2)' ;
goto f
end
if @check_ms_car_line_out_header_status_id=-1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_car_line_out_header_status_name + ' tidak bisa di Approve ' ;
goto f
end
if @check_ms_car_line_out_header_status_id=1
begin
set @xStsno='02';
set @xStsdes='Gagal, Dokumen dengan status ' + @check_ms_car_line_out_header_status_name + ' tidak bisa di Approve Lagi' ;
goto f
end
if (SELECT COUNT(*) AS Expr1
FROM dt_ms_car_line_out_detail
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id))=0
begin
set @xStsno='02';
set @xStsdes='Gagal, Tidak ada detail , masukan detail item ' ;
goto f
end
declare @new_daily_out_item table (
ms_item_out_move_avg_id bigint
,ms_date_business_id int
,ms_item_id bigint
)
declare @result_date_business_id bigint,
@result_date_business date,
@result_date_business_id_from bigint,
@result_date_business_from date,
@is_move_date_business bit,
@business_date date=@check_doc_date
EXEC [dbo].[MG_MS_CHECK_BUSINESS_DATE_AND_AVG]
@business_date = @business_date,
@allow_move_ms_date_business = @allow_move_ms_date_business,
@result_date_business_id = @result_date_business_id OUTPUT,
@result_date_business = @result_date_business OUTPUT,
@result_date_business_id_from = @result_date_business_id_from OUTPUT,
@result_date_business_from = @result_date_business_from OUTPUT,
@is_move_date_business = @is_move_date_business OUTPUT,
@xStsno = @xStsno OUTPUT,
@xStsdes = @xStsdes OUTPUT
if not(@xStsno='00')
begin
goto f
end
declare @ms_car_line_out_header_h_status_id bigint
BEGIN TRANSACTION;
INSERT INTO dt_ms_car_line_out_header_h_status
(ms_car_line_out_header_id, ms_car_line_out_header_status_id, status_info, create_date, create_by)
VALUES (@ms_car_line_out_header_id, 1, N'',@now,@data_by)
set @ms_car_line_out_header_h_status_id=SCOPE_IDENTITY();
update dt_ms_car_line_out_header
set ms_car_line_out_header_h_status_id=@ms_car_line_out_header_h_status_id
where ms_car_line_out_header_id=@ms_car_line_out_header_id
---- CARI AVG MOVE OUT BERDASARKAN TANGGAL YANG SAMA
UPDATE dt_ms_car_line_out_detail
SET ms_item_out_move_avg_id = dt_ms_item_daily_out_move_avg.ms_item_out_move_avg_id
, is_move_business_date = @is_move_date_business
, ms_date_business_id_from =@result_date_business_id_from
, ms_date_business_id =@result_date_business_id
FROM dt_ms_car_line_out_detail INNER JOIN
dt_ms_item_daily_out_move_avg ON dt_ms_car_line_out_detail.ms_item_id = dt_ms_item_daily_out_move_avg.ms_item_id
WHERE (dt_ms_car_line_out_detail.ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (dt_ms_item_daily_out_move_avg.ms_date_business_id = @result_date_business_id)
INSERT INTO dt_ms_item_daily_out_move_avg
(ms_date_business_id, ms_item_in_move_avg_id, ms_item_id, ms_item_h_price_id,ms_cost_final_avg_id)
output inserted.ms_item_out_move_avg_id,inserted.ms_date_business_id,inserted.ms_item_id into @new_daily_out_item
SELECT
@result_date_business_id
, ( SELECT TOP (1) dt_ms_item_daily_in_move_avg.ms_item_in_move_avg_id
FROM dt_ms_item_daily_in_move_avg INNER JOIN
dt_ms_date_business ON dt_ms_item_daily_in_move_avg.ms_date_business_id = dt_ms_date_business.ms_date_business_id
WHERE (dt_ms_item_daily_in_move_avg.ms_item_id = dt_ms_car_line_out_detail.ms_item_id ) AND (dt_ms_date_business.ms_date_business <= @check_doc_date)
ORDER BY dt_ms_date_business.ms_date_business DESC
)
,ms_item_id
,-1
,-1
FROM dt_ms_car_line_out_detail
WHERE (ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (ms_item_out_move_avg_id = - 1 OR
ms_item_out_move_avg_id IS NULL)
group by ms_item_id
if (select count(*) from @new_daily_out_item )>0
begin
UPDATE dt_ms_car_line_out_detail
SET ms_item_out_move_avg_id = new_avg.ms_item_out_move_avg_id
, is_move_business_date = @is_move_date_business
, ms_date_business_id_from =@result_date_business_id_from
, ms_date_business_id =@result_date_business_id
FROM dt_ms_car_line_out_detail INNER JOIN
@new_daily_out_item AS new_avg ON dt_ms_car_line_out_detail.ms_item_id = new_avg.ms_item_id
WHERE (dt_ms_car_line_out_detail.ms_car_line_out_header_id = @ms_car_line_out_header_id) AND (dt_ms_car_line_out_detail.ms_item_out_move_avg_id = - 1 OR
dt_ms_car_line_out_detail.ms_item_out_move_avg_id IS NULL)
end
COMMIT TRANSACTION;
declare @detail xml
set @detail=(
SELECT
ms_car_line_out_header_id AS rID
, ms_car_line_out_header_status_name AS r1
, doc_no AS r2
, dbo.date_to_str(doc_date ) AS r3
, doc_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_ms_out_car_line_header
where ms_car_line_out_header_id=@ms_car_line_out_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
--EXEC MG_MS_OUT_CAR_LINE_HEADER_APPROVE
--'
GO
Depends On
10Used By
No items found