0% found this document useful (0 votes)
30 views7 pages

XML SP (Hareshsir)

Uploaded by

deven1642004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views7 pages

XML SP (Hareshsir)

Uploaded by

deven1642004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

/****** Object: STORED PROCEDURE [sp_erp_delivery_order_mst_insup] Script Date:

10-06-2024 01:12:24 PM ******/


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- Description: <Insert data for erp_delivery_order_mst>
-- =============================================
exec dbo.sys_sp_cu_schema @schema_name='scm'
GO

IF([custom_sys].[sys_check_store_procedure_exists]
('scm','sp_erp_delivery_order_mst_insup')=0)
BEGIN
DECLARE @proc_name VARCHAR(500)=''
SELECT
@proc_name=custom_sys.sys_dummy_func_return_store_procedure('scm','sp_erp_delivery_
order_mst_insup')
EXECUTE(@proc_name)
END
GO

ALTER PROCEDURE [sp_erp_delivery_order_mst_insup]


@delivery_order_id bigint=0,
@delivery_order_no varchar(30)='',
@delivery_order_date date=NULL,
@ref_sales_order_id bigint=0,
@ref_customer_id smallint=0,
@ref_customer_person_id smallint=0,
@ref_loading_location_id smallint=0,
@do_refference_no nvarchar(30)='',
@ref_currency_id smallint=0,
@do_total_amount bigint=0,
@current_authorised_level tinyint=0,
@final_authorised_level tinyint=0,
@is_delivery_order_authorised tinyint=0,
@delivery_order_authorised_by smallint=0,
@delivery_order_authorised_date datetime2=NULL,
@department_id smallint=0,
@company_id tinyint=0,
@year_id smallint=0,
@sub_year_id smallint=0,
@ref_user_id smallint,

--sub item
@delivery_order_sub_items_xml xml,

@output_status BIT OUTPUT,


@output_msg_key VARCHAR(100) OUTPUT,
@output_execution_msg VARCHAR(250) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

DECLARE @datetime DATETIME2(0)


SET @datetime= TRY_CONVERT(DATETIME2(0), com.sys_func_get_datetime(0,0)) --
Using TRY_CONVERT

--variable we use for the opertion

DECLARE @code_exists BIT = 1;


DECLARE @can_insert BIT = 0;

DECLARE @exists_details_id smallint = 0;

--output variables
SET @output_status = 0;
SET @output_msg_key = 'error';
SET @output_execution_msg = '';

SELECT @exists_details_id = delivery_order_id


FROM [erp_delivery_order_mst]
WHERE delivery_order_id = @delivery_order_id AND
delivery_order_no=@delivery_order_no AND is_deleted = 0;

BEGIN TRAN;
BEGIN TRY

--checking whether we can able to insert/update/error


SELECT TOP 1
@can_insert = is_can_insert,
@code_exists = is_code_exist
FROM
com.cu_func_details_exists_flag(@exists_details_id,@delivery_order_id);

IF (@code_exists = 1)
BEGIN

--checking the code is already exist throught system


SET @output_status = 0;
SET @output_msg_key = 'unique_key_exists';
END;

else IF (@can_insert = 0 AND @delivery_order_id > 0 )


BEGIN
--going to update
UPDATE [erp_delivery_order_mst]
SET
--delivery_order_id=@delivery_order_id,
delivery_order_no=@delivery_order_no,
delivery_order_date=@delivery_order_date,
ref_sales_order_id=@ref_sales_order_id,
ref_customer_id=@ref_customer_id,
ref_customer_person_id=@ref_customer_person_id,
ref_loading_location_id=@ref_loading_location_id,
do_refference_no=@do_refference_no,
ref_currency_id=@ref_currency_id,
do_total_amount=@do_total_amount,
current_authorised_level=@current_authorised_level,
final_authorised_level=@final_authorised_level,
is_delivery_order_authorised=@is_delivery_order_authorised,
delivery_order_authorised_by=@delivery_order_authorised_by,
delivery_order_authorised_date=@delivery_order_authorised_date,
department_id=@department_id,
company_id=@company_id,
year_id=@year_id,
sub_year_id=@sub_year_id,
created_by=@ref_user_id,
created_date=@datetime,
modify_by=@ref_user_id,
modify_date=@datetime

WHERE delivery_order_id=@delivery_order_id;

SET @output_status = 1;
SET @output_msg_key = 'updated';
END
ELSE IF (@can_insert=1 AND @delivery_order_id=0 )
BEGIN
--going to insert
INSERT INTO [erp_delivery_order_mst]
(
delivery_order_no
,delivery_order_date
,ref_sales_order_id
,ref_customer_id
,ref_customer_person_id
,ref_loading_location_id
,do_refference_no
,ref_currency_id
,do_total_amount
,current_authorised_level
,final_authorised_level
,is_delivery_order_authorised
,delivery_order_authorised_by
,delivery_order_authorised_date
,department_id
,company_id
,year_id
,sub_year_id
,created_by
,created_date

)
VALUES
(
@delivery_order_no
,@delivery_order_date
,@ref_sales_order_id
,@ref_customer_id
,@ref_customer_person_id
,@ref_loading_location_id
,@do_refference_no
,@ref_currency_id
,@do_total_amount
,@current_authorised_level
,@final_authorised_level
,@is_delivery_order_authorised
,@delivery_order_authorised_by
,@delivery_order_authorised_date
,@department_id
,@company_id
,@year_id
,@sub_year_id
,@ref_user_id
,@datetime

);
SET @delivery_order_id = @@IDENTITY;
SELECT @delivery_order_id AS output_pk_id;
SET @output_status = 1;
SET @output_msg_key = 'success';
END;
ELSE
BEGIN

SET @output_status = 0;
SET @output_msg_key = 'error';
END;
--sub item
IF(@output_status = 1)
BEGIN
IF OBJECT_ID('tempdb..#tmp_delivery_order_sub_items') IS
NOT NULL DROP TABLE #tmp_delivery_order_sub_items;

SELECT * INTO #tmp_delivery_order_sub_items FROM


(
SELECT
dtltbl.dtlclmn.value('delivery_order_item_id[1]',
'bigint') AS delivery_order_item_id
--,dtltbl.dtlclmn.value('ref_delivery_order_id[1]',
'bigint') as ref_delivery_order_id
,dtltbl.dtlclmn.value('ref_sales_order_item_id[1]',
'bigint') as ref_sales_order_item_id
,dtltbl.dtlclmn.value('ref_item_id[1]', 'smallint')
as ref_item_id
,dtltbl.dtlclmn.value('po_item_uom_id[1]',
'smallint') as po_item_uom_id
,dtltbl.dtlclmn.value('do_item_remarks[1]',
'nvarchar(250)') as do_item_remarks
,dtltbl.dtlclmn.value('do_item_qty[1]', 'bigint')
as do_item_qty
,dtltbl.dtlclmn.value('do_item_unit_cost_actual[1]'
, 'bigint') as do_item_unit_cost_actual
,dtltbl.dtlclmn.value('do_item_unit_cost[1]',
'bigint') as do_item_unit_cost
,dtltbl.dtlclmn.value('do_item_total_cost_before_di
sc[1]', 'bigint') as do_item_total_cost_before_disc
,dtltbl.dtlclmn.value('do_item_header_disc_perc[1]'
, 'bigint') as do_item_header_disc_perc
,dtltbl.dtlclmn.value('do_item_header_disc_cost[1]'
, 'bigint') as do_item_header_disc_cost
,dtltbl.dtlclmn.value('do_item_total_cost_after_dis
c[1]', 'bigint') as do_item_total_cost_after_disc
,dtltbl.dtlclmn.value('do_item_sales_tax_id[1]',
'smallint') as do_item_sales_tax_id
,dtltbl.dtlclmn.value('do_item_tax_perc[1]', 'int')
as do_item_tax_perc
,dtltbl.dtlclmn.value('do_item_tax_cost[1]',
'bigint') as do_item_tax_cost
,dtltbl.dtlclmn.value('do_item_total_cost_after_tax
[1]', 'bigint') as do_item_total_cost_after_tax
,dtltbl.dtlclmn.value('ref_account_id[1]',
'smallint') as ref_account_id
,dtltbl.dtlclmn.value('is_billing_completed[1]',
'bit') as is_billing_completed
,dtltbl.dtlclmn.value('is_deleted[1]', 'bit') as
is_deleted
,dtltbl.dtlclmn.value('modify_by[1]', 'smallint')
as modify_by
,dtltbl.dtlclmn.value('modify_date[1]', 'DateTime')
as modify_date

FROM
@delivery_order_sub_items_xml.nodes('//Main/Sub') AS dtltbl (dtlclmn)
)t1

--SELECT * FROM #tmp_goods_receipt_sub_items

UPDATE sub Set


sub.is_deleted = 1
,sub.modify_by = reftbl.modify_by
,sub.modify_date = reftbl.modify_date
FROM [erp_delivery_order_sub_items] sub
INNER JOIN #tmp_delivery_order_sub_items reftbl
ON sub.delivery_order_item_id =
reftbl.delivery_order_item_id AND reftbl.is_deleted=1
WHERE sub.ref_delivery_order_id = @delivery_order_id;

UPDATE sub Set


--
sub.ref_delivery_order_id=reftbl.ref_delivery_order_id,

sub.ref_sales_order_item_id=reftbl.ref_sales_order_item_id,
sub.ref_item_id=reftbl.ref_item_id,
sub.po_item_uom_id=reftbl.po_item_uom_id,
sub.do_item_remarks=reftbl.do_item_remarks,
sub.do_item_qty=reftbl.do_item_qty,

sub.do_item_unit_cost_actual=reftbl.do_item_unit_cost_actual,
sub.do_item_unit_cost=reftbl.do_item_unit_cost,

sub.do_item_total_cost_before_disc=reftbl.do_item_total_cost_before_disc,

sub.do_item_header_disc_perc=reftbl.do_item_header_disc_perc,

sub.do_item_header_disc_cost=reftbl.do_item_header_disc_cost,

sub.do_item_total_cost_after_disc=reftbl.do_item_total_cost_after_disc,

sub.do_item_sales_tax_id=reftbl.do_item_sales_tax_id,
sub.do_item_tax_perc=reftbl.do_item_tax_perc,
sub.do_item_tax_cost=reftbl.do_item_tax_cost,
sub.do_item_total_cost_after_tax=reftbl.do_item_total_cost_after_tax,
sub.ref_account_id=reftbl.ref_account_id,

sub.is_billing_completed=reftbl.is_billing_completed,
sub.modify_by=reftbl.modify_by,
sub.modify_date=reftbl.modify_date

FROM [erp_delivery_order_sub_items] sub


INNER JOIN #tmp_delivery_order_sub_items reftbl
ON sub.goods_receipt_item_id = reftbl.goods_receipt_item_id
AND reftbl.is_deleted=0
WHERE sub.ref_delivery_order_id = @delivery_order_id;

INSERT INTO [erp_delivery_order_sub_items]


(
-- delivery_order_item_id
ref_delivery_order_id
,ref_sales_order_item_id
,ref_item_id
,po_item_uom_id
,do_item_remarks
,do_item_qty
,do_item_unit_cost_actual
,do_item_unit_cost
,do_item_total_cost_before_disc
,do_item_header_disc_perc
,do_item_header_disc_cost
,do_item_total_cost_after_disc
,do_item_sales_tax_id
,do_item_tax_perc
,do_item_tax_cost
,do_item_total_cost_after_tax
,ref_account_id
,is_billing_completed
,modify_by
,modify_date
)
SELECT
@delivery_order_id,
reftbl.ref_sales_order_item_id,
reftbl.ref_item_id,
reftbl.po_item_uom_id,
reftbl.do_item_remarks,
reftbl.do_item_qty,
reftbl.do_item_unit_cost_actual,
reftbl.do_item_unit_cost,
reftbl.do_item_total_cost_before_disc,
reftbl.do_item_header_disc_perc,
reftbl.do_item_header_disc_cost,
reftbl.do_item_total_cost_after_disc ,
reftbl.do_item_sales_tax_id,
reftbl.do_item_tax_perc,
reftbl.do_item_tax_cost,
reftbl.do_item_total_cost_after_tax,
reftbl.ref_account_id,
reftbl.is_billing_completed,
reftbl.modify_by,
reftbl.modify_date

FROM #tmp_delivery_order_sub_items reftbl


WHERE IsNull(reftbl.delivery_order_item_id,0)=0
AND ISNULL(reftbl.is_deleted,0)=0 ;

SET @output_status = 1;
SET @output_msg_key = 'updated';
END
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
-- Catching any error and providing output
SET @output_status = 0;
SET @output_msg_key = 'exception';
SET @output_execution_msg = ERROR_MESSAGE();
END CATCH;

SET NOCOUNT OFF;


END

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy