CREATE PROCEDURE [dbo].[sp_Create_Parvande_From_TmpDrugH] @New_Par_No varchar(9) OutPut ,@Note_Code varchar(20), @Id_Havaleh Numeric(9) , @Family Nvarchar(30) , @Name NVarchar(15), @Cur_Date Varchar(4),@Sazman_Code AS Varchar(3), @UserId Smallint
AS

DECLARE @Par_Id NUMERIC(9)
Exec @New_Par_No  = dbo.Make_new_Par_No  @Cur_Date , @Sazman_Code 

INSERT INTO tbl_HParvande 
( Par_No, PT_Code, Sazman_Code, Note_Code, Name, Family, Nezam_No , Par_Status, User_Id)
SELECT @New_Par_No ,ISNULL(PT_Code ,'0') , @Sazman_Code , @Note_Code, @Name , @Family  ,Nezam_No , '0', @UserId
FROM     TmpDrugH
WHERE Id_Havaleh = @Id_Havaleh

SELECT  @Par_Id = @@IDENTITY

INSERT INTO tbl_DParvande
(Par_Id, Row_No, K_Code, K_Qty, Price_Forosh ,Refer_Step ,User_Id)
SELECT @Par_Id , Radif, K_Code, K_Qty1, Price_Forosh , 1, @UserId
FROM         TmpDrugHavaleh
WHERE Id_Havaleh = @Id_Havaleh

RETURN @New_Par_No
