Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
| Name | Data Type | Length | Description |
|---|---|---|---|
| @id_hdr | bigint | 8 | |
| @doc_in_from_id | int | 4 | |
| @date_incoming | datetime | 8 |
SQL Script
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.spi_incoming_fg (@id_hdr as bigint, @doc_in_from_id as int, @date_incoming as datetime )
AS
BEGIN
declare @count int
declare @idx_hdr bigint
declare @doc_in_no varchar(50)
declare @hasil varchar(50)
exec [dbo].[spu_seq] @nomor_untuk = N'receiving_number', @hasil = @hasil OUTPUT
set @doc_in_no = @hasil
set @count = (select COUNT(*) from dbo.tbl_incoming_fg where [id_incoming_fg_hdr] = @id_hdr)
if @count = 0
begin
select '01' as status, ' DATA HDR NOT FOUND' as description
return
end
set @count = (select COUNT(*) from dbo.tbl_incoming_fg_dtl where [id_incoming_fg] = @id_hdr)
if @count = 0
begin
select '01' as status, ' DATA PART NOT FOUND' as description
return
end
set @count = (select COUNT(*) from dbo.tbl_data_in_hdr where id_terkait = @id_hdr and doc_in_from_id=1)
if @count <> 0
begin
select '01' as status, ' DATA ALREADY EXIST ' as description
return
end
BEGIN TRY
BEGIN TRANSACTION
insert into dbo.tbl_data_in_hdr (doc_in_no, doc_in_from_id, id_terkait, doc_in_date, status) values(@doc_in_no, 1, @id_hdr, @date_incoming, 'DATA PROCESSED')
set @idx_hdr = scope_identity()
--set @idx_hdr = (select top 1 id_data_in_hdr from dbo.tbl_data_in_hdr where id_terkait = @id_hdr )
insert into dbo.tbl_data_in_dtl (
id_data_in_hdr
,doc_in_from_id
,part_name_customs
,part_number
,part_no
,qty_in
,unit_in
,box
,pack
,id_part_number
,harga
,kdval
,type_brg
,part_name
) select
@idx_hdr
,@doc_in_from_id
,(isnull((select top 1 dbo.tbl_assy_list.DESC_ASSY from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE),tbl_incoming_fg_dtl.ASSY_NO))
,ASSY_NO
,ASSY_CODE
,(isnull(atot_pcs_sf,0)+isnull(atot_pcs_af,0)+isnull(btot_pcs_sf,0)+isnull(btot_pcs_af,0)+isnull(ctot_pcs_sf+ctot_pcs_af,0))
,'PC'
,(isnull(ATOT_BOX_SF,0) + isnull(ATOT_BOX_AF,0)+isnull(BTOT_BOX_SF,0)+isnull(BTOT_BOX_AF,0)+isnull(CTOT_BOX_SF+CTOT_BOX_AF,0))
,(isnull(atot_pcs_sf,0)+isnull(atot_pcs_af,0)+isnull(btot_pcs_sf,0)+isnull(btot_pcs_af,0)+isnull(ctot_pcs_sf,0)+isnull(ctot_pcs_af,0))
,(isnull((select top 1 dbo.tbl_assy_list.id_assy_list from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE),0))
,(select top 1 dbo.tbl_assy_list.PRICE from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE)
,'USD' -- karena tidak tau
,2 -- part finishgood lihat di tbl_typebarang
,ASSY_NO
from dbo.tbl_incoming_fg_dtl
where dbo.tbl_incoming_fg_dtl.[id_incoming_fg] = @id_hdr
update dbo.tbl_incoming_fg set status = 'DATA PROCESSED INVENTORY' where dbo.tbl_incoming_fg.id_incoming_fg_hdr = @id_hdr
INSERT INTO tbl_bc_in_hdr_h_status (id_bc_in_hdr, statusdok, status_date) values (@id_hdr, 'DATA PROCESSED INVENTORY', GETDATE())
INSERT INTO tbl_data_in_hdr_h_status
(id_data_in_hdr, status, status_date)
VALUES (@idx_hdr, 'DATA PROCESSED', GETDATE())
declare @assy_codex varchar(50)
DECLARE db_cursor CURSOR FOR
SELECT part_no FROM tbl_data_in_dtl where id_data_in_hdr = @idx_hdr and doc_in_from_id = 1 AND tbl_data_in_dtl.type_brg = 2
group by part_no
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @assy_codex
WHILE @@FETCH_STATUS = 0
BEGIN
if (select COUNT(*) from tbl_bom_hdr where ASSY_CODE = @assy_codex)=0
exec [spi_update_bom_ora] @assy_codex
FETCH NEXT FROM db_cursor INTO @assy_codex
END
CLOSE db_cursor
DEALLOCATE db_cursor
select '00' as status, ' DATA PROCESSED' as description
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
Set @ErrMsg = ERROR_MESSAGE()
set @ErrSeverity = ERROR_SEVERITY()
select @ErrMsg as description,@ErrSeverity as status
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
END
GO
GO
CREATE PROCEDURE dbo.spi_incoming_fg (@id_hdr as bigint, @doc_in_from_id as int, @date_incoming as datetime )
AS
BEGIN
declare @count int
declare @idx_hdr bigint
declare @doc_in_no varchar(50)
declare @hasil varchar(50)
exec [dbo].[spu_seq] @nomor_untuk = N'receiving_number', @hasil = @hasil OUTPUT
set @doc_in_no = @hasil
set @count = (select COUNT(*) from dbo.tbl_incoming_fg where [id_incoming_fg_hdr] = @id_hdr)
if @count = 0
begin
select '01' as status, ' DATA HDR NOT FOUND' as description
return
end
set @count = (select COUNT(*) from dbo.tbl_incoming_fg_dtl where [id_incoming_fg] = @id_hdr)
if @count = 0
begin
select '01' as status, ' DATA PART NOT FOUND' as description
return
end
set @count = (select COUNT(*) from dbo.tbl_data_in_hdr where id_terkait = @id_hdr and doc_in_from_id=1)
if @count <> 0
begin
select '01' as status, ' DATA ALREADY EXIST ' as description
return
end
BEGIN TRY
BEGIN TRANSACTION
insert into dbo.tbl_data_in_hdr (doc_in_no, doc_in_from_id, id_terkait, doc_in_date, status) values(@doc_in_no, 1, @id_hdr, @date_incoming, 'DATA PROCESSED')
set @idx_hdr = scope_identity()
--set @idx_hdr = (select top 1 id_data_in_hdr from dbo.tbl_data_in_hdr where id_terkait = @id_hdr )
insert into dbo.tbl_data_in_dtl (
id_data_in_hdr
,doc_in_from_id
,part_name_customs
,part_number
,part_no
,qty_in
,unit_in
,box
,pack
,id_part_number
,harga
,kdval
,type_brg
,part_name
) select
@idx_hdr
,@doc_in_from_id
,(isnull((select top 1 dbo.tbl_assy_list.DESC_ASSY from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE),tbl_incoming_fg_dtl.ASSY_NO))
,ASSY_NO
,ASSY_CODE
,(isnull(atot_pcs_sf,0)+isnull(atot_pcs_af,0)+isnull(btot_pcs_sf,0)+isnull(btot_pcs_af,0)+isnull(ctot_pcs_sf+ctot_pcs_af,0))
,'PC'
,(isnull(ATOT_BOX_SF,0) + isnull(ATOT_BOX_AF,0)+isnull(BTOT_BOX_SF,0)+isnull(BTOT_BOX_AF,0)+isnull(CTOT_BOX_SF+CTOT_BOX_AF,0))
,(isnull(atot_pcs_sf,0)+isnull(atot_pcs_af,0)+isnull(btot_pcs_sf,0)+isnull(btot_pcs_af,0)+isnull(ctot_pcs_sf,0)+isnull(ctot_pcs_af,0))
,(isnull((select top 1 dbo.tbl_assy_list.id_assy_list from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE),0))
,(select top 1 dbo.tbl_assy_list.PRICE from dbo.tbl_assy_list where tbl_assy_list.ASSY_CODE = tbl_incoming_fg_dtl.ASSY_CODE)
,'USD' -- karena tidak tau
,2 -- part finishgood lihat di tbl_typebarang
,ASSY_NO
from dbo.tbl_incoming_fg_dtl
where dbo.tbl_incoming_fg_dtl.[id_incoming_fg] = @id_hdr
update dbo.tbl_incoming_fg set status = 'DATA PROCESSED INVENTORY' where dbo.tbl_incoming_fg.id_incoming_fg_hdr = @id_hdr
INSERT INTO tbl_bc_in_hdr_h_status (id_bc_in_hdr, statusdok, status_date) values (@id_hdr, 'DATA PROCESSED INVENTORY', GETDATE())
INSERT INTO tbl_data_in_hdr_h_status
(id_data_in_hdr, status, status_date)
VALUES (@idx_hdr, 'DATA PROCESSED', GETDATE())
declare @assy_codex varchar(50)
DECLARE db_cursor CURSOR FOR
SELECT part_no FROM tbl_data_in_dtl where id_data_in_hdr = @idx_hdr and doc_in_from_id = 1 AND tbl_data_in_dtl.type_brg = 2
group by part_no
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @assy_codex
WHILE @@FETCH_STATUS = 0
BEGIN
if (select COUNT(*) from tbl_bom_hdr where ASSY_CODE = @assy_codex)=0
exec [spi_update_bom_ora] @assy_codex
FETCH NEXT FROM db_cursor INTO @assy_codex
END
CLOSE db_cursor
DEALLOCATE db_cursor
select '00' as status, ' DATA PROCESSED' as description
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
Set @ErrMsg = ERROR_MESSAGE()
set @ErrSeverity = ERROR_SEVERITY()
select @ErrMsg as description,@ErrSeverity as status
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
END
GO
Depends On
10Used By
No items found