USE [master]
GO
/****** Object:  Database [namedatabase]    Script Date: 02/19/2018 12:56:07 ق.ظ ******/
CREATE DATABASE [namedatabase]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'almas95', FILENAME = N'adressdatabase\namedatabase.mdf' , SIZE = 11456KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'almas95_log', FILENAME = N'adressdatabase\namedatabase.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [namedatabase] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [namedatabase].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [namedatabase] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [namedatabase] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [namedatabase] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [namedatabase] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [namedatabase] SET ARITHABORT OFF 
GO
ALTER DATABASE [namedatabase] SET AUTO_CLOSE ON 
GO
ALTER DATABASE [namedatabase] SET AUTO_SHRINK ON 
GO
ALTER DATABASE [namedatabase] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [namedatabase] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [namedatabase] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [namedatabase] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [namedatabase] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [namedatabase] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [namedatabase] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [namedatabase] SET  DISABLE_BROKER 
GO
ALTER DATABASE [namedatabase] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [namedatabase] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [namedatabase] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [namedatabase] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [namedatabase] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [namedatabase] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [namedatabase] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [namedatabase] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [namedatabase] SET  MULTI_USER 
GO
ALTER DATABASE [namedatabase] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [namedatabase] SET DB_CHAINING OFF 
GO
ALTER DATABASE [namedatabase] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [namedatabase] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
ALTER DATABASE [namedatabase] SET DELAYED_DURABILITY = DISABLED 
GO
USE [namedatabase]
GO
/****** Object:  User [dah]    Script Date: 02/19/2018 12:56:07 ق.ظ ******/
CREATE USER [dah] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[dah]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [dah]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [dah]
GO
ALTER ROLE [db_datareader] ADD MEMBER [dah]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [dah]
GO
/****** Object:  Schema [dah]    Script Date: 02/19/2018 12:56:07 ق.ظ ******/
CREATE SCHEMA [dah]
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckPass]    Script Date: 02/19/2018 12:56:07 ق.ظ ******/
CREATE TYPE [dbo].[dtCheckPass] AS TABLE(
	[ID] [bigint] NULL,
	[fldShomarePas] [bigint] NULL,
	[fldTozihat] [nvarchar](50) NULL,
	[fldSanad] [bigint] NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckPassMain]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtCheckPassMain] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldSHomareHesab] [bigint] NULL,
	[fldShomarePas] [bigint] NULL,
	[fldTozihat] [nvarchar](50) NULL,
	[fldSanad] [bigint] NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckPassMain2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtCheckPassMain2] AS TABLE(
	[ID] [int] NOT NULL,
	[fldShomarePas] [bigint] NULL,
	[fldTozihat] [nvarchar](50) NULL,
	[fldSanad] [bigint] NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckPassMain3]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtCheckPassMain3] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldSHomareHesab] [bigint] NULL,
	[fldShomarePas] [bigint] NULL,
	[fldTozihat] [nvarchar](50) NULL,
	[fldSanad] [bigint] NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckVosool]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtCheckVosool] AS TABLE(
	[fldIDVosool] [bigint] NULL,
	[fldShomareVosool] [bigint] NULL,
	[fldDateVosool] [int] NULL,
	[fldTozihateVosool] [nvarchar](50) NULL,
	[fldVaziat] [nvarchar](15) NULL,
	[fldSanadVosool] [bigint] NULL,
	[fldCodeHesabeVosool] [nvarchar](10) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtKala] AS TABLE(
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNameKala] [nvarchar](100) NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSerial] [nvarchar](20) NULL,
	[fldCodeGroup] [bigint] NOT NULL,
	[fldCodeVahed1] [bigint] NOT NULL,
	[fldCodeVahed2] [bigint] NULL,
	[fldNogheSefaresh] [decimal](18, 0) NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldTedadJoz] [decimal](18, 0) NULL,
	[fldFeeDarsadKharid] [float] NULL,
	[fldFeeBadAzTakhfif] [money] NULL,
	[fldNerkhePorsantKol] [float] NULL,
	[fldNerkhePorsantJoz] [float] NULL,
	[fldFeeForoosh] [money] NULL,
	[fldPathPic] [nvarchar](max) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 0) NULL,
	[fldIDPrinter] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtTasfie]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[dtTasfie] AS TABLE(
	[fldShomareFactor] [bigint] NULL,
	[fldShomareDaryaft] [bigint] NULL,
	[fldMablagh] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[LocationTableType]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[LocationTableType] AS TABLE(
	[LocationName] [nvarchar](50) NULL,
	[CostRate] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tbl1]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tbl1] AS TABLE(
	[fld1] [varchar](50) NULL,
	[fld2] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckDaryafti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tblCheckDaryafti] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckDaryaftiNew]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tblCheckDaryaftiNew] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [nvarchar](15) NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckPardakhti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tblCheckPardakhti] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckVagozari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tblCheckVagozari] AS TABLE(
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblDaftarCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tblDaftarCheck] AS TABLE(
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldCodeBank] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[TestEmpType]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[TestEmpType] AS TABLE(
	[ID] [int] NULL,
	[Name] [varchar](3000) NULL,
	[Address] [varchar](8000) NULL,
	[Operation] [smallint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[TestEmpType2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[TestEmpType2] AS TABLE(
	[ID] [int] NULL,
	[Name] [varchar](3000) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh_Enteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh_Enteghal] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid] AS TABLE(
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_Enteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_Enteghal] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_FactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_FactorKharid] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldHamloNaghl] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_FactorKharid_Final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_FactorKharid_Final] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldHamloNaghl] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 0) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_MojodiEbtedaDoreh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_MojodiEbtedaDoreh] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpSanadEbteda_Ashkas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[tpSanadEbteda_Ashkas] AS TABLE(
	[fldSanad] [varchar](50) NULL,
	[fldDay] [varchar](50) NULL,
	[fldMonth] [varchar](50) NULL,
	[fldYear] [varchar](50) NULL,
	[fldCodeKol] [varchar](50) NULL,
	[fldCodeMoin] [varchar](50) NULL,
	[fldCodeTafzili] [varchar](50) NULL,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldRadif] [varchar](50) NULL,
	[fldDate] [int] NULL,
	[fldSharh] [varchar](50) NULL,
	[fldMoinKamel] [varchar](50) NULL,
	[fldCodeNoeTafzili] [varchar](50) NULL,
	[fldType] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[typeKharidtest]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
CREATE TYPE [dbo].[typeKharidtest] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [smallint] NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL
)
GO
/****** Object:  Table [dbo].[DasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[DasteCheck](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeBank] [nvarchar](10) NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tbl2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl2](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblAnbar](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCode] [int] NOT NULL,
	[fldNameAnbar] [nvarchar](50) NULL,
 CONSTRAINT [PK_tblAnbar] PRIMARY KEY CLUSTERED 
(
	[fldCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblBankeMoshtari](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNameBank] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_tblBankeMoshtari] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblBargashtAzForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorForoosh] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
 CONSTRAINT [PK_tblBargashtAzForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblBargashtAzKharid](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorKharid] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblChap]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblChap](
	[fldNameMoassese] [nvarchar](150) NULL,
	[fldTozihateBala] [nvarchar](150) NULL,
	[fldAdress] [nvarchar](max) NULL,
	[fldPasafhe] [nvarchar](max) NULL,
	[fldCodeEghtesadi] [nvarchar](20) NULL,
	[fldShomareSabt] [nvarchar](20) NULL,
	[fldCodePosti] [nvarchar](20) NULL,
	[fldTell] [nvarchar](50) NULL,
	[fldLogo] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblChapeSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblChapeSanad](
	[fldCodeKol] [nvarchar](50) NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldSharh] [nvarchar](190) NULL,
	[fldMablagheJoz] [nvarchar](50) NULL,
	[fldBedehkar] [nvarchar](50) NULL,
	[fldBestankar] [nvarchar](50) NULL,
	[fldControleSharh] [nvarchar](50) NULL,
	[fldControleTekrari] [nvarchar](50) NULL,
	[fldCodeKolShow] [nvarchar](50) NULL,
	[fldCodeMoinShow] [nvarchar](50) NULL,
	[fldSanad] [nvarchar](50) NULL,
	[fldDate] [nvarchar](50) NULL,
	[fldCodeTafziliShow] [nvarchar](50) NULL,
	[fldBedOrBes] [nvarchar](50) NULL,
	[fldControl] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblCheckeDaryafti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblCheckeDaryafti](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[fldShomareCheck] [bigint] NOT NULL,
	[fldShomareHesab] [bigint] NOT NULL,
	[fldDateSarResid] [int] NOT NULL,
	[fldCodeBank] [int] NOT NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NOT NULL,
	[fldDateDaryaft] [int] NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL,
	[fldShomareDaryaft] [bigint] NULL,
	[fldVasete] [nvarchar](10) NULL,
	[fldSanad] [nvarchar](50) NULL,
	[fldShomarePardakht] [bigint] NULL,
	[fldShomareVosool] [bigint] NULL,
	[fldDateVosool] [int] NULL,
	[fldDateVagozariBeBank] [int] NULL,
	[fldTozihateVosool] [nvarchar](50) NULL,
	[fldTozihateVagozariBeBank] [nvarchar](50) NULL,
	[fldVaziat] [nvarchar](15) NULL,
	[fldSanadVosool] [bigint] NULL,
	[fldCodeHesabeVosool] [nvarchar](10) NULL,
	[fldCodeBankVagozari] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblCheckePardakhti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblCheckePardakhti](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[fldShomareCheck] [bigint] NOT NULL,
	[fldShomareHesab] [bigint] NOT NULL,
	[fldDateSarResid] [int] NOT NULL,
	[fldCodeBank] [int] NOT NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NOT NULL,
	[fldDatePardakht] [int] NULL,
	[fldCodeSahebeCheck] [nvarchar](10) NULL,
	[fldShomarePardakht] [bigint] NULL,
	[fldCodeSahebeHesab] [nvarchar](10) NULL,
	[fldVasete] [nvarchar](10) NULL,
	[fldSanad] [nvarchar](50) NULL,
	[fldShomarePass] [bigint] NULL,
	[fldDatePass] [int] NULL,
	[fldSharhePass] [nvarchar](50) NULL,
	[fldSanadPas] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblControlPanel]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblControlPanel](
	[fldNameSherkat] [nvarchar](100) NULL,
	[fldShomareEftetahie] [bigint] NULL,
	[fldShomareEkhtetamie] [bigint] NULL,
	[fldEx] [nvarchar](15) NULL,
	[fldControleTarikh] [nvarchar](5) NULL,
	[fldNumberPooste] [nvarchar](50) NULL,
	[fldVersion] [nvarchar](10) NULL,
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_tblControlPanel] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDaftarcheTell]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDaftarcheTell](
	[fldIdDaftarche] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeTafzili] [nvarchar](10) NULL,
	[fldName] [nvarchar](50) NULL,
	[fldShomare] [nvarchar](50) NULL,
	[fldSms] [nvarchar](20) NULL,
	[fldSharh] [nvarchar](100) NULL,
 CONSTRAINT [PK_tblDaftarche] PRIMARY KEY CLUSTERED 
(
	[fldIdDaftarche] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDaryaft](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareDaryaft] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldCodeTafzili] [nvarchar](10) NOT NULL,
	[fldType] [nvarchar](20) NULL,
 CONSTRAINT [PK_tblDaryaft] PRIMARY KEY CLUSTERED 
(
	[fldShomareDaryaft] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDasteCheck](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeBank] [nvarchar](10) NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDastrasi]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDastrasi](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeUser] [bigint] NULL,
	[fldCodeDastrasi] [bigint] NULL,
 CONSTRAINT [PK_tblDastrasi] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDastrasi2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDastrasi2](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeUser] [bigint] NULL,
	[fldCodeDastrasi] [bigint] NULL,
 CONSTRAINT [PK_tblDastrasi2] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDastrasi3]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDastrasi3](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeUser] [bigint] NULL,
	[fldCodeDastrasi] [bigint] NULL,
 CONSTRAINT [PK_tblDastrasi3] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDastrasi4]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDastrasi4](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeUser] [bigint] NULL,
	[fldCodeDastrasi] [bigint] NULL,
 CONSTRAINT [PK_tblDastrasi4] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblDastrasiSandoogh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblDastrasiSandoogh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeUser] [bigint] NULL,
	[fldSandoogh] [bigint] NULL,
	[fldType] [nvarchar](10) NULL,
 CONSTRAINT [PK_tblDastrasiSandoogh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblError]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblError](
	[fldSharh] [nvarchar](100) NULL,
	[fldNumber] [nvarchar](50) NULL,
	[fldDate] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblEshantionTabaghati]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblEshantionTabaghati](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeKalaForoosh] [bigint] NULL,
	[fldShomareTabaghe] [bigint] NULL,
	[fldTedadForoosh] [decimal](18, 2) NULL,
	[fldCodeKalaEshantion] [bigint] NULL,
	[fldTedadEshantion] [decimal](18, 2) NULL,
 CONSTRAINT [PK_tblEshantionTabaghati] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblEshantionTekrarShavande]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblEshantionTekrarShavande](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeKalaForoosh] [bigint] NULL,
	[fldTedadKala] [decimal](18, 2) NULL,
	[fldCodeKalaEshantion] [bigint] NULL,
	[fldTedadEshantion] [decimal](18, 2) NULL,
 CONSTRAINT [PK_tblEshantionTekrarShavande] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblFee]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblFee](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldName] [nvarchar](100) NOT NULL,
	[fldFee] [money] NOT NULL,
	[fldCodeTasvie] [bigint] NULL,
 CONSTRAINT [PK_tblFee] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblFish]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblFish](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldShomareFish] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorForoosh] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
 CONSTRAINT [PK_tblForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblGroupAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGroupAshkhas](
	[fldGroupId] [bigint] NOT NULL,
	[fldGroupName] [nvarchar](80) NOT NULL,
 CONSTRAINT [PK_tblGroupAshkhas] PRIMARY KEY CLUSTERED 
(
	[fldGroupId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblGroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGroupKala](
	[fldGroupId] [bigint] NOT NULL,
	[fldGroupName] [nvarchar](80) NOT NULL,
 CONSTRAINT [PK_tblGroupKala] PRIMARY KEY CLUSTERED 
(
	[fldGroupId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblIDChapgarKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblIDChapgarKala](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[fldIDChapgarKala] [bigint] NULL,
	[fldCodeKala] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblImageKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblImageKala](
	[ID] [bigint] NULL,
	[fldCodeKala] [bigint] NULL,
	[fldImageKoochak] [image] NULL,
	[fldImageBozorg] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKala](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNameKala] [nvarchar](100) NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSerial] [nvarchar](20) NULL,
	[fldCodeGroup] [bigint] NOT NULL,
	[fldCodeVahed1] [bigint] NOT NULL,
	[fldCodeVahed2] [bigint] NULL,
	[fldNogheSefaresh] [decimal](18, 0) NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldTedadJoz] [decimal](18, 0) NULL,
	[fldFeeDarsadKharid] [float] NULL,
	[fldFeeBadAzTakhfif] [money] NULL,
	[fldNerkhePorsantKol] [float] NULL,
	[fldNerkhePorsantJoz] [float] NULL,
	[fldFeeForoosh] [money] NULL,
	[fldPathPic] [nvarchar](max) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 0) NULL,
	[fldIDPrinter] [bigint] NULL,
 CONSTRAINT [PK_tblKala] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblKarbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKarbar](
	[fldKarKard1] [smallint] NULL,
	[fldKarKard2] [smallint] NULL,
	[fldKarKard3] [smallint] NULL,
	[fldKarKard4] [smallint] NULL,
	[fldKarKard5] [smallint] NULL,
	[Gozaresh1] [smallint] NULL,
	[Gozaresh2] [smallint] NULL,
	[Gozaresh3] [smallint] NULL,
	[Gozaresh4] [smallint] NULL,
	[Gozaresh5] [smallint] NULL,
	[Gozaresh6] [smallint] NULL,
	[Gozaresh7] [smallint] NULL,
	[Taraz1] [smallint] NULL,
	[Taraz2] [smallint] NULL,
	[Taraz3] [smallint] NULL,
	[Poshtiban1] [smallint] NULL,
	[Poshtiban2] [smallint] NULL,
	[Paye1] [smallint] NULL,
	[Paye2] [smallint] NULL,
	[Paye3] [smallint] NULL,
	[Paye4] [smallint] NULL,
	[Paye5] [smallint] NULL,
	[Paye6] [smallint] NULL,
	[fldName] [nvarchar](50) NULL,
	[fldPassword] [nvarchar](50) NULL,
	[fldKarKard6] [smallint] NULL,
	[Paye7] [smallint] NULL,
	[Paye8] [smallint] NULL,
	[Gozaresh8] [smallint] NULL,
	[Gozaresh9] [smallint] NULL,
	[Gozaresh10] [smallint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKharid](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorKharid] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKolMoin](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeHesab] [nvarchar](10) NULL,
	[fldSharheHesab] [nvarchar](50) NULL,
	[fldNoeHesab] [nvarchar](20) NULL,
	[fldCodeNoeHesab] [nvarchar](10) NULL,
	[fldMarkazFirst] [nvarchar](10) NULL,
	[fldMarkazSecond] [nvarchar](10) NULL,
	[fldNoe] [nvarchar](10) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblListeDastrasi]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblListeDastrasi](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCode] [bigint] NULL,
	[fldName] [nvarchar](150) NULL,
	[fldGroup] [bigint] NULL,
	[fldOrder] [bigint] NULL,
	[fldNameGroup] [nvarchar](20) NULL,
 CONSTRAINT [PK_tblListeDastrasi] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblListPorsantVaset]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblListPorsantVaset](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldIDVasete] [bigint] NOT NULL,
	[fldDarsad] [decimal](18, 0) NOT NULL,
 CONSTRAINT [PK_tblListPorsantVaset] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblMarkaz1]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMarkaz1](
	[fldCode] [nchar](10) NULL,
	[fldSharh] [nchar](200) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblMarkaz2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMarkaz2](
	[fldCode] [nchar](10) NULL,
	[fldSharh] [nchar](200) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblMorooreHesabha]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMorooreHesabha](
	[fldCodeHesab] [nvarchar](50) NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldBedehkar] [nvarchar](50) NULL,
	[fldBestankar] [nvarchar](50) NULL,
	[fldMande] [nvarchar](50) NULL,
	[fldMandeInt] [money] NULL,
	[fldShomareSanad] [nvarchar](50) NULL,
	[fldDate] [bigint] NULL,
	[fldSharheKol] [nvarchar](200) NULL,
	[fldSharheMoin] [nvarchar](200) NULL,
	[fldCodeKol] [nvarchar](50) NULL,
	[fldDateShow] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPardakht](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomarePardakht] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NOT NULL,
	[fldCodeTafzili] [nvarchar](10) NOT NULL,
	[fldType] [nvarchar](20) NULL,
 CONSTRAINT [PK_tblPardakht] PRIMARY KEY CLUSTERED 
(
	[fldShomarePardakht] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPas](
	[fldID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomarePas] [bigint] NULL,
	[fldShomareSanad] [bigint] NULL,
 CONSTRAINT [PK_tblPas] PRIMARY KEY CLUSTERED 
(
	[fldID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPaye]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPaye](
	[fldKol] [smallint] NOT NULL,
	[fldMoin] [smallint] NOT NULL,
	[fldTafzili] [smallint] NOT NULL,
	[fldMarkaz1] [smallint] NOT NULL,
	[fldMarkaz2] [smallint] NOT NULL,
	[fldMaheSaleMali] [nvarchar](10) NOT NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPishForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorForoosh] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
	[fldHamloNaghl] [bigint] NULL,
 CONSTRAINT [PK_tblPishForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPishPishForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactorForoosh] [bigint] NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldDate] [bigint] NULL,
	[fldSharhFactor] [nvarchar](250) NULL,
	[fldHamloNaghl] [bigint] NULL,
 CONSTRAINT [PK_tblPishPishForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblPrinters]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPrinters](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNameMahal] [nvarchar](50) NULL,
	[fldNamePrinter] [nvarchar](max) NULL,
 CONSTRAINT [PK_tblPrinters] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblReportAll]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblReportAll](
	[fldCodeKol] [nvarchar](50) NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeShow] [nvarchar](50) NULL,
	[fldSharheShow] [nvarchar](50) NULL,
	[fldSharheKol] [nvarchar](50) NULL,
	[fldMandeMoin] [decimal](18, 0) NOT NULL,
	[fldMandeTafzili] [decimal](18, 0) NULL,
	[fldOrder] [nvarchar](50) NULL,
	[fldHelp1] [nvarchar](50) NULL,
	[fldHelp2] [nvarchar](50) NULL,
	[fldHelp3] [nvarchar](50) NULL,
	[fldHelp4] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblReportAmalkardeMoinTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblReportAmalkardeMoinTafzili](
	[fldCodeKol] [nchar](50) NULL,
	[fldCodeMoin] [nchar](50) NULL,
	[fldCodeShow] [nchar](50) NULL,
	[fldSharheShow] [nchar](100) NULL,
	[fldSharheKol] [nchar](100) NULL,
	[fldMandeMoin] [decimal](18, 0) NULL,
	[fldMandeTafzili] [decimal](18, 0) NULL,
	[fldOrder] [nvarchar](50) NULL,
	[fldCodeNoeTafzili] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizeBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizeBargashtAzForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
 CONSTRAINT [PK_tblRizeBargashtAzForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizeBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizeBargashtAzKharid](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldHamloNaghl] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 0) NULL,
 CONSTRAINT [PK_tblRizeBargashtAzKharid] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizeForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizeForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldShomareBargasht] [bigint] NULL,
 CONSTRAINT [PK_tblRizeForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizeKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizeKharid](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldHamloNaghl] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 0) NULL,
 CONSTRAINT [PK_tblRizeKharid] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizePishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizePishForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 0) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldShomareBargasht] [bigint] NULL,
 CONSTRAINT [PK_tblRizePishForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizePishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizePishPishForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeTafsili] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](10) NULL,
	[fldTedadJoz] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldShomareEnteghal] [bigint] NULL,
	[fldShomareBargasht] [bigint] NULL,
	[fldShomarePishFactor] [bigint] NULL,
 CONSTRAINT [PK_tblRizePishPishForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblRizeTasfie]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblRizeTasfie](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldShomareDaryaft] [bigint] NULL,
	[fldMablagh] [bigint] NULL,
 CONSTRAINT [PK_tblRizeTasfie] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblSanadMovaghat]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSanadMovaghat](
	[fldSanad] [nvarchar](50) NULL,
	[fldDay] [nvarchar](50) NULL,
	[fldMonth] [nvarchar](50) NULL,
	[fldYear] [nvarchar](50) NULL,
	[fldCodeKol] [nvarchar](50) NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldCodeMarkaz1] [nvarchar](50) NULL,
	[fldCodeMarkaz2] [nvarchar](50) NULL,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldRadif] [nvarchar](50) NULL,
	[fldCodeSharh] [nvarchar](50) NULL,
	[fldDate] [int] NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldMoinKamel] [nvarchar](50) NULL,
	[fldCodeNoeTafzili] [nvarchar](50) NULL,
	[fldGhateiMovaghat] [nvarchar](50) NULL,
	[fldGhateiDaem] [nvarchar](50) NULL,
	[fldSanadGhadim] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblSanavat]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSanavat](
	[fldSal] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblSecurity]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSecurity](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCode] [bigint] NOT NULL,
	[fldUser] [nvarchar](25) NULL,
	[fldPassword] [nvarchar](max) NULL,
	[fldType] [int] NULL,
 CONSTRAINT [PK_tblSecurity] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblSharhhayePishSakhte]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSharhhayePishSakhte](
	[fldCode] [int] NULL,
	[fldSharh] [ntext] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblSodooreSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblSodooreSanad](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldSanad] [nvarchar](50) NULL,
	[fldDay] [nvarchar](50) NULL,
	[fldMonth] [nvarchar](50) NULL,
	[fldYear] [nvarchar](50) NULL,
	[fldCodeKol] [nvarchar](50) NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldCodeMarkaz1] [nvarchar](50) NULL,
	[fldCodeMarkaz2] [nvarchar](50) NULL,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldRadif] [varchar](50) NULL,
	[fldCodeSharh] [varchar](50) NULL,
	[fldDate] [int] NULL,
	[fldSharh] [nvarchar](150) NULL,
	[fldMoinKamel] [nvarchar](50) NULL,
	[fldCodeNoeTafzili] [nvarchar](50) NULL,
	[fldGhateiMovaghat] [nvarchar](50) NULL,
	[fldGhateiDaem] [nvarchar](50) NULL,
	[fldSanadGhadim] [nvarchar](50) NULL,
	[fldShomarePeigiri] [nvarchar](50) NULL,
	[fldMoghayerat] [nvarchar](50) NULL,
	[fldType] [nvarchar](50) NULL,
	[fldVasete] [nvarchar](50) NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tblSodooreSanad3]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblSodooreSanad3](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldSanad] [varchar](50) NULL,
	[fldDay] [varchar](50) NULL,
	[fldMonth] [varchar](50) NULL,
	[fldYear] [varchar](50) NULL,
	[fldCodeKol] [varchar](50) NULL,
	[fldCodeMoin] [varchar](50) NULL,
	[fldCodeTafzili] [varchar](50) NULL,
	[fldCodeMarkaz1] [varchar](50) NULL,
	[fldCodeMarkaz2] [varchar](50) NULL,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldRadif] [varchar](50) NULL,
	[fldCodeSharh] [varchar](50) NULL,
	[fldDate] [int] NULL,
	[fldSharh] [varchar](50) NULL,
	[fldMoinKamel] [varchar](50) NULL,
	[fldCodeNoeTafzili] [varchar](50) NULL,
	[fldGhateiMovaghat] [varchar](50) NULL,
	[fldGhateiDaem] [varchar](50) NULL,
	[fldSanadGhadim] [varchar](50) NULL,
	[fldShomarePeigiri] [varchar](50) NULL,
	[fldMoghayerat] [varchar](50) NULL,
	[fldType] [varchar](50) NULL,
	[fldAz] [nvarchar](50) NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tblSodooreSanad5]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSodooreSanad5](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldSanad] [nvarchar](50) NOT NULL,
	[fldDay] [nvarchar](50) NOT NULL,
	[fldMonth] [nvarchar](50) NOT NULL,
	[fldYear] [nvarchar](50) NOT NULL,
	[fldCodeKol] [nvarchar](50) NOT NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldCodeMarkaz1] [nvarchar](50) NULL,
	[fldCodeMarkaz2] [nvarchar](50) NULL,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldRadif] [nvarchar](50) NULL,
	[fldCodeSharh] [nvarchar](50) NULL,
	[fldDate] [int] NULL,
	[fldSharh] [nvarchar](50) NULL,
	[fldMoinKamel] [nvarchar](50) NULL,
	[fldCodeNoeTafzili] [nvarchar](50) NULL,
	[fldGhateiMovaghat] [nvarchar](50) NULL,
	[fldGhateiDaem] [nvarchar](50) NULL,
	[fldSanadGhadim] [nvarchar](50) NULL,
	[fldShomarePeigiri] [nvarchar](50) NULL,
	[fldMoghayerat] [nvarchar](50) NULL,
	[fldType] [nvarchar](50) NULL,
	[fldVasete] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblTafzili](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNoeHesab] [nvarchar](15) NOT NULL,
	[fldSharheTafzili] [nvarchar](200) NOT NULL,
	[fldCodeTafzili] [nvarchar](10) NOT NULL,
	[fldCodeNoe] [nvarchar](10) NULL,
	[fldNoe] [nvarchar](10) NULL,
	[fldCodeGroup] [varchar](100) NULL,
	[fldOstan] [nvarchar](50) NULL,
	[fldCity] [nvarchar](50) NULL,
	[fldAddress] [nvarchar](200) NULL,
	[fldShomareHesab] [nvarchar](20) NULL,
	[fldCodeMeli] [nvarchar](20) NULL,
	[fldCodeEghtesadi] [nvarchar](20) NULL,
	[fldCodePosti] [nvarchar](20) NULL,
	[fldShomareSabt] [nvarchar](20) NULL,
	[fldSaghfeEtebar] [varchar](100) NULL,
	[fldBlackList] [nvarchar](5) NULL,
	[fldSharhBlackList] [nvarchar](100) NULL,
	[fldDate1] [bigint] NULL,
	[fldDate2] [bigint] NULL,
	[fldVisitor] [bigint] NULL CONSTRAINT [DF_tblTafzili_fldVisitor]  DEFAULT ((0)),
	[fldPic] [nvarchar](300) NULL,
	[fldNoeVizitor] [int] NULL,
	[fldPoorsant] [int] NULL,
	[fldCodeSuperVisor] [nvarchar](10) NULL,
	[fldNoeMohasebePoorsant] [int] NULL,
 CONSTRAINT [PK_tblTafzili] PRIMARY KEY CLUSTERED 
(
	[fldCodeTafzili] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tblTanzimat]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTanzimat](
	[fldCodeKolBank] [nvarchar](10) NULL,
	[fldCodeKolHazine] [nvarchar](10) NULL,
	[fldCodeKolSandoogh] [nvarchar](10) NULL,
	[fldCodeMoinCheck] [nvarchar](10) NULL,
	[fldCodeMoinTakhfifateDaryaft] [nvarchar](10) NULL,
	[fldCodeMoinHesabhayeDaryaftani] [nvarchar](10) NULL,
	[fldCodeKolCheck] [nvarchar](10) NULL,
	[fldCodeMoinTakhfifatePardakht] [nvarchar](10) NULL,
	[fldCodeMoinHesabhayePardakhtani] [nvarchar](10) NULL,
	[fldCodeKolCheckPardakhti] [nvarchar](10) NULL,
	[fldCodeMoinCheckPardakhti] [nvarchar](10) NULL,
	[fldCodeKolDaramad] [nvarchar](10) NULL,
	[fldCodeMoinDaramad] [nvarchar](10) NULL,
	[fldCodeMoinForoosh] [nvarchar](10) NULL,
	[fldMoinArzesheAfzoode] [nvarchar](10) NULL,
	[fldMoinDaramadeHamlVaNaghl] [nvarchar](10) NULL,
	[fldMoinMojoodieEbteda] [nvarchar](10) NULL,
	[fldKolSarmaye] [nvarchar](10) NULL,
	[fldMoinArzesheAfzoodeKharid] [nvarchar](10) NULL,
	[fldCodeMoinKharid] [nvarchar](10) NULL,
	[fldCodeMoinHazineHamlVaNaghl] [nvarchar](10) NULL,
	[fldCodeMoinBargashtAzForoosh] [nvarchar](10) NULL,
	[fldCodeKolHesabhayeDaryaftani] [nvarchar](10) NULL,
	[fldCodeKolHesabhayePardakhtani] [nvarchar](10) NULL,
	[fldCodeHoghoogh] [nvarchar](10) NULL,
	[fldCodeMoinHesabhayePardakhtaniPoorsant] [nvarchar](10) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTanzimateKol]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTanzimateKol](
	[fldType] [nvarchar](50) NULL,
	[fldMeghdar] [nvarchar](70) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTanzimatForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTanzimatForoosh](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldKalaTekrary] [bit] NULL,
	[fldTypeInputKalaInGrid] [nvarchar](10) NULL,
	[fldAllowForooshKalaBishAzMojodi] [bit] NULL,
	[fldShowMotalebatInFactorForoosh] [bit] NULL,
	[fldForooshNaghdi] [bit] NULL,
	[fldShowSodKala] [bit] NULL,
	[fldShowSodFactor] [bit] NULL,
	[fldEshantion] [bit] NULL,
	[fldChandGheymate] [bit] NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldTedadChapInForoosh] [smallint] NULL,
	[fldSearchNumberingInKala] [bit] NULL,
	[fldBeginDateTakhfifat] [bigint] NULL,
	[fldEndDateTakhfifat] [bigint] NULL,
 CONSTRAINT [PK_tblTanzimatForoosh] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTanzimatKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTanzimatKharid](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldKalaTekrary] [bit] NULL,
	[fldTypeInputKalaInGrid] [nvarchar](10) NULL,
	[fldArzeshAfzode] [decimal](18, 0) NULL,
	[fldTedadChapInKharid] [smallint] NULL,
	[fldSearchNumberingInKala] [bit] NULL,
 CONSTRAINT [PK_tblTanzimatKharid] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTanzimatNew]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTanzimatNew](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldName] [nvarchar](30) NOT NULL,
	[fldMeghdar] [nvarchar](30) NOT NULL,
 CONSTRAINT [PK_tblTanzimatNew] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTasfie]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTasfie](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCodeTafzili] [nvarchar](10) NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldMablagheFactor] [decimal](18, 0) NULL,
	[fldMablagheDaryafti] [decimal](18, 0) NULL,
	[fldMablagheMandeFactor] [decimal](18, 0) NULL,
	[fldMablagheMande] [decimal](18, 0) NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldDateSarResid] [bigint] NULL,
 CONSTRAINT [PK_tblTasfie] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTasvie]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTasvie](
	[ID] [bigint] NULL,
	[fldCode] [bigint] NULL,
	[fldName] [nvarchar](100) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTest]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTest](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[adad] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTest2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTest2](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTest5]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTest5](
	[id] [int] NULL,
	[name1] [nvarchar](50) NULL,
	[name2] [nvarchar](50) NULL,
	[name3] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTest6]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTest6](
	[fld1] [nvarchar](50) NULL,
	[fld2] [nvarchar](50) NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTest7]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTest7](
	[fld1] [nvarchar](50) NULL,
	[fld2] [bigint] NULL,
	[fld3] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblTranslate]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTranslate](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCode] [bigint] NULL,
	[fldLang] [nvarchar](10) NULL,
	[fldMatn] [nvarchar](max) NULL,
 CONSTRAINT [PK_tblTranslate] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblVahed](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldNameVahed] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_tblVahed] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[tblVosool]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblVosool](
	[fldID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldShomareVosool] [bigint] NULL,
	[fldShomareSanad] [bigint] NULL,
 CONSTRAINT [PK_tblVosool] PRIMARY KEY CLUSTERED 
(
	[fldID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TempMojoodieAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TempMojoodieAnbar](
	[fldGroupName] [nvarchar](50) NULL,
	[fldCodeGroup] [bigint] NULL,
	[fldCodeKala] [bigint] NULL,
	[fldNameKala] [nvarchar](100) NULL,
	[fldTedadeVorood] [decimal](18, 0) NULL,
	[fldTedadeKhorooj] [decimal](18, 0) NULL,
	[fldTedadeJoz] [decimal](18, 0) NULL,
	[fldTedadeKol] [decimal](18, 0) NULL,
	[fldTedadDarKarton] [decimal](18, 0) NULL,
	[fldCodeAnbar] [int] NULL,
	[fldNameAnbar] [nvarchar](200) NULL,
	[fldNogheSefaresh] [decimal](18, 0) NULL,
	[fldFeeForoosh] [money] NULL,
	[fldLastFee] [money] NULL,
	[fldMianginFee] [money] NULL,
	[fldNameVahed] [nvarchar](100) NULL,
	[fldNameVahed2] [nvarchar](100) NULL,
	[fldKharid] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TempMojoodieAnbarForForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TempMojoodieAnbarForForoosh](
	[fldCodeKala] [bigint] NULL,
	[SumVorood] [decimal](18, 0) NULL,
	[SumKhorooj] [decimal](18, 0) NULL,
	[SumMande] [decimal](18, 0) NULL,
	[fldTedadDarKarton] [decimal](18, 0) NULL,
	[fldTedadDarKartonShow] [nvarchar](70) NULL,
	[fldTedadVoroodKarton] [decimal](18, 0) NULL,
	[fldTedadVoroodKartonShow] [nvarchar](70) NULL,
	[fldTedadKhoroojKarton] [decimal](18, 0) NULL,
	[fldTedadKhoroojKartonShow] [nvarchar](70) NULL,
	[fldGroupName] [nvarchar](50) NULL,
	[fldCodeGroup] [bigint] NULL,
	[fldNameKala] [nvarchar](100) NULL,
	[fldNogheSefaresh] [decimal](18, 0) NULL,
	[fldNameVahed] [nvarchar](100) NULL,
	[fldNameVahed2] [nvarchar](100) NULL,
	[fldKharid] [bigint] NULL
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TempRizeForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TempRizeForoosh](
	[fldShomareSanad] [nvarchar](30) NULL,
	[fldShomareFactor] [nvarchar](30) NULL,
	[fldCodeVasete] [nvarchar](30) NULL,
	[fldCodeTafsili] [nvarchar](30) NULL,
	[fldSharheTafzili] [nvarchar](200) NULL,
	[fldCodeAnbar] [nvarchar](30) NULL,
	[fldNameAnbar] [nvarchar](200) NULL,
	[fldCodeKala] [bigint] NULL,
	[fldNameKala] [nvarchar](200) NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCarton] [nvarchar](100) NULL,
	[fldTedadJoz] [nvarchar](100) NULL,
	[fldFeeJoz] [nvarchar](30) NULL,
	[fldFeeYekCarton] [nvarchar](30) NULL,
	[fldFeeKol] [nvarchar](40) NULL,
	[fldDarsadTakhfif] [nvarchar](30) NULL,
	[fldMablaghTakhfif] [nvarchar](40) NULL,
	[fldFeeVahed1BadAzTakhfif] [nvarchar](40) NULL,
	[fldFeeVahed2BadAzTakhfif] [nvarchar](40) NULL,
	[fldArzeshAfzode] [nvarchar](30) NULL,
	[fldFeeKolBadAzTakhfif] [nvarchar](40) NULL,
	[fldMablaghKhales] [nvarchar](40) NULL,
	[fldType] [nvarchar](50) NULL,
	[fldDate] [int] NULL,
	[fldGroupId] [nvarchar](30) NULL,
	[fldGroupName] [nvarchar](200) NULL,
	[fldGroupIdAshkas1] [nvarchar](30) NULL,
	[fldGroupNameAshkas2] [nvarchar](200) NULL
) ON [PRIMARY]

GO
/****** Object:  View [dah].[viewLoadVizitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dah].[viewLoadVizitor]
AS
SELECT          dbo.tblTafzili.fldCodeTafzili,dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldPoorsant, dbo.tblTafzili.fldNoeMohasebePoorsant, 
                         iif(dbo.tblTafzili.fldNoeMohasebePoorsant = 1, 'فروش', 'واریز') AS fldSharheMohasebe,  
                         dbo.tblTafzili.fldCodeSuperVisor AS CodeSuperVisor,tblTafzili_1.fldSharheTafzili AS fldNameSuperVizor,dbo.tblTafzili.ID
FROM            dbo.tblTafzili INNER JOIN
                         dbo.tblTafzili AS tblTafzili_1 ON dbo.tblTafzili.fldCodeSuperVisor = tblTafzili_1.fldCodeTafzili
WHERE        (dbo.tblTafzili.fldNoeVizitor = 2)

GO
/****** Object:  View [dbo].[Join_TblTell_TblTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Join_TblTell_TblTafzili]
AS
SELECT        TOP (100) PERCENT dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldCodeTafzili, dbo.tblDaftarcheTell.fldShomare, dbo.tblTafzili.fldCodeMeli, 
                         dbo.tblTafzili.fldAddress
FROM            dbo.tblDaftarcheTell INNER JOIN
                         dbo.tblTafzili ON dbo.tblDaftarcheTell.fldCodeTafzili = dbo.tblTafzili.fldCodeTafzili
GROUP BY dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldCodeTafzili, dbo.tblDaftarcheTell.fldShomare, dbo.tblTafzili.fldCodeMeli, dbo.tblTafzili.fldAddress

GO
/****** Object:  View [dbo].[lstlistKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[lstlistKala]
AS
SELECT        fldNameKala, fldCodeKala
FROM            dbo.tblKala

GO
/****** Object:  View [dbo].[View_2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[View_2]
AS
SELECT DISTINCT 
                         dbo.tblTafzili.fldCodeGroup, dbo.tblGroupAshkhas.fldGroupId, dbo.tblGroupAshkhas.fldGroupName, dbo.tblDaftarcheTell.fldShomare, 
                         dbo.tblTafzili.fldCodeTafzili
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup INNER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)

GO
/****** Object:  View [dbo].[View_ListAshkhas_In_ReportFactorForosh_AliJahangard]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[View_ListAshkhas_In_ReportFactorForosh_AliJahangard]
AS
SELECT        dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldCodeGroup, dbo.tblTafzili.fldOstan, dbo.tblTafzili.fldCity, dbo.tblTafzili.fldAddress, 
                         dbo.tblTafzili.fldShomareHesab, dbo.tblTafzili.fldCodeMeli, dbo.tblTafzili.fldCodeEghtesadi, dbo.tblTafzili.fldCodePosti, dbo.tblTafzili.fldShomareSabt, 
                         dbo.tblTafzili.fldSaghfeEtebar, dbo.tblTafzili.fldBlackList, dbo.tblTafzili.fldSharhBlackList, dbo.tblTafzili.fldDate1, dbo.tblTafzili.fldDate2, dbo.tblDaftarcheTell.fldSms, 
                         dbo.tblDaftarcheTell.fldShomare
FROM            dbo.tblTafzili LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON dbo.tblTafzili.fldCodeTafzili = dbo.tblDaftarcheTell.fldCodeTafzili

GO
/****** Object:  View [dbo].[View_TblChap]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[View_TblChap]
AS
SELECT        fldNameMoassese, fldTozihateBala, fldAdress, fldPasafhe, fldCodeEghtesadi, fldShomareSabt, fldCodePosti, fldTell
FROM            dbo.tblChap

GO
/****** Object:  View [dbo].[viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala]
AS
SELECT DISTINCT fldCodeTafzili, fldSharheTafzili
FROM            dbo.tblTafzili

GO
/****** Object:  View [dbo].[viewGetAnbarForComboBox]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewGetAnbarForComboBox]
AS
SELECT        fldCode, fldNameAnbar
FROM            dbo.tblAnbar

GO
/****** Object:  View [dbo].[viewGetListEshantionTabalaghti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewGetListEshantionTabalaghti]
AS
SELECT        dbo.tblEshantionTabaghati.fldShomareTabaghe, dbo.tblEshantionTabaghati.fldTedadForoosh, dbo.tblEshantionTabaghati.fldTedadEshantion, 
                         dbo.tblEshantionTabaghati.fldCodeKalaEshantion, dbo.tblKala.fldNameKala AS fldNameKalaEshantion, tblKala_1.fldCodeKala AS fldCodeKalaForoosh, 
                         tblKala_1.fldNameKala AS fldNameKalaForoosh
FROM            dbo.tblEshantionTabaghati INNER JOIN
                         dbo.tblKala ON dbo.tblEshantionTabaghati.fldCodeKalaEshantion = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblKala AS tblKala_1 ON dbo.tblEshantionTabaghati.fldCodeKalaForoosh = tblKala_1.fldCodeKala

GO
/****** Object:  View [dbo].[viewGridForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewGridForoosh]
AS
SELECT        dbo.tblRizeForoosh.fldRadif, dbo.tblRizeForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeForoosh.fldSharhKala, dbo.tblRizeForoosh.fldTedadCarton, 
                         dbo.tblRizeForoosh.fldTedadJoz, dbo.tblRizeForoosh.fldFeeJoz, dbo.tblRizeForoosh.fldFeeYekCarton, dbo.tblRizeForoosh.fldFeeKol, 
                         dbo.tblRizeForoosh.fldDarsadTakhfif, dbo.tblRizeForoosh.fldMablaghTakhfif, dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeForoosh.fldArzeshAfzode, dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldCodeAnbar, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, dbo.tblKala.fldGhymatMasrafkonande
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizeForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizeForoosh.fldShomareFactor = 30)

GO
/****** Object:  View [dbo].[viewListBarcodeKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewListBarcodeKala]
AS
SELECT        fldCodeKala, fldSerial
FROM            dbo.tblKala
WHERE        (fldSerial <> 0) AND (fldSerial <> '')

GO
/****** Object:  View [dbo].[viewListKalaInFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewListKalaInFactorForoosh]
AS
SELECT        dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2, dbo.tblKala.fldFeeForoosh
FROM            dbo.tblKala INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed1 = dbo.tblVahed.ID INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID

GO
/****** Object:  View [dbo].[viewListKalaInFactorForooshByFldCodeGroup]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewListKalaInFactorForooshByFldCodeGroup]
AS
SELECT        dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldCodeGroup
FROM            dbo.tblKala INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed1 = dbo.tblVahed.ID INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID

GO
/****** Object:  View [dbo].[viewListSmallKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewListSmallKala]
AS
SELECT        fldNameKala, fldCodeKala
FROM            dbo.tblKala

GO
/****** Object:  View [dbo].[viewReportListAshkhasByIN]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewReportListAshkhasByIN]
AS
SELECT DISTINCT 
                         TOP (100) PERCENT dbo.tblTafzili.fldCodeGroup, dbo.tblGroupAshkhas.fldGroupName, dbo.tblDaftarcheTell.fldShomare, dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldSharheTafzili
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)
GROUP BY dbo.tblTafzili.fldCodeGroup, dbo.tblGroupAshkhas.fldGroupId, dbo.tblGroupAshkhas.fldGroupName, dbo.tblDaftarcheTell.fldShomare, dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldSharheTafzili
HAVING        (dbo.tblTafzili.fldCodeGroup IN (108, 100, 105))
ORDER BY dbo.tblGroupAshkhas.fldGroupName, dbo.tblTafzili.fldSharheTafzili

GO
/****** Object:  View [dbo].[viewRizeForooshEhsan]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewRizeForooshEhsan]
AS
SELECT        dbo.tblRizeForoosh.fldShomareSanad, dbo.tblRizeForoosh.fldShomareFactor, dbo.tblRizeForoosh.fldCodeVasete, dbo.tblRizeForoosh.fldCodeTafsili, 
                         dbo.tblTafzili.fldSharheTafzili, dbo.tblRizeForoosh.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeForoosh.fldCodeKala, dbo.tblKala.fldNameKala, 
                         dbo.tblKala.fldGhymatMasrafkonande, dbo.tblRizeForoosh.fldSharhKala, dbo.tblRizeForoosh.fldTedadCarton, dbo.tblRizeForoosh.fldTedadJoz, 
                         dbo.tblRizeForoosh.fldFeeJoz, dbo.tblRizeForoosh.fldFeeYekCarton, dbo.tblRizeForoosh.fldFeeKol, dbo.tblRizeForoosh.fldDarsadTakhfif, 
                         dbo.tblRizeForoosh.fldMablaghTakhfif, dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, 
                         dbo.tblRizeForoosh.fldArzeshAfzode, dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif, dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldType, 
                         dbo.tblRizeForoosh.fldDate, dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblGroupAshkhas.fldGroupName AS fldGroupNameAshkas2
FROM            dbo.tblRizeForoosh INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeForoosh.fldCodeAnbar = dbo.tblAnbar.fldCode INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizeForoosh.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblGroupKala ON dbo.tblTafzili.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
                         dbo.tblGroupAshkhas ON dbo.tblRizeForoosh.fldCodeVasete = dbo.tblGroupAshkhas.fldGroupId

GO
/****** Object:  View [dbo].[viewShowListKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewShowListKala]
AS
SELECT        dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldCodeGroup
FROM            dbo.tblKala INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed1 = dbo.tblVahed.ID INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID

GO
/****** Object:  View [dbo].[viewShowListSmallGroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewShowListSmallGroupKala]
AS
SELECT        fldGroupId, fldGroupName
FROM            dbo.tblGroupKala

GO
/****** Object:  View [dbo].[viewtestforoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewtestforoosh]
AS
SELECT        dbo.tblRizeForoosh.fldCodeTafsili, tblTafzili_1.fldSharheTafzili, dbo.tblRizeForoosh.fldCodeVasete, dbo.tblTafzili.fldSharheTafzili AS fldNameVasete
FROM            dbo.tblRizeForoosh LEFT OUTER JOIN
                         dbo.tblTafzili ON dbo.tblRizeForoosh.fldCodeVasete = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblTafzili AS tblTafzili_1 ON dbo.tblRizeForoosh.fldCodeTafsili = tblTafzili_1.fldCodeTafzili

GO
/****** Object:  View [dbo].[viewtestShomaretel]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewtestShomaretel]
AS
SELECT        dbo.tblTafzili.fldCodeTafzili, dbo.tblDaftarcheTell.fldCodeTafzili AS Expr1, dbo.tblDaftarcheTell.fldName, dbo.tblDaftarcheTell.fldShomare, 
                         dbo.tblDaftarcheTell.fldSms, dbo.tblDaftarcheTell.fldSharh, dbo.tblTafzili.fldOstan
FROM            dbo.tblTafzili INNER JOIN
                         dbo.tblDaftarcheTell ON dbo.tblTafzili.fldCodeTafzili = dbo.tblDaftarcheTell.fldCodeTafzili

GO
/****** Object:  View [dbo].[viwListeCheckHayePasNashode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viwListeCheckHayePasNashode]
AS
SELECT        TOP (100) PERCENT ID, fldShomareCheck, fldShomareHesab, fldDateSarResid, SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 1, 4) 
                         + '/' + SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResidShow, 
                         fldCodeBank, fldShobe, fldMablagh, fldDatePardakht, SUBSTRING(CONVERT(nvarchar, fldDatePardakht), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, 
                         fldDatePardakht), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, fldDatePardakht), 7, 2) AS fldDatePardakhtShow, fldCodeSahebeCheck, fldShomarePardakht, 
                         fldCodeSahebeHesab, fldVasete, fldSanad, fldShomarePass, fldDatePass, fldSharhePass
FROM            dbo.tblCheckePardakhti
WHERE        (fldShomarePass IS NULL)
ORDER BY fldDateSarResid

GO
SET IDENTITY_INSERT [dbo].[tbl2] ON 

INSERT [dbo].[tbl2] ([id]) VALUES (1)
INSERT [dbo].[tbl2] ([id]) VALUES (2)
INSERT [dbo].[tbl2] ([id]) VALUES (3)
INSERT [dbo].[tbl2] ([id]) VALUES (4)
INSERT [dbo].[tbl2] ([id]) VALUES (5)
INSERT [dbo].[tbl2] ([id]) VALUES (6)
INSERT [dbo].[tbl2] ([id]) VALUES (7)
INSERT [dbo].[tbl2] ([id]) VALUES (8)
INSERT [dbo].[tbl2] ([id]) VALUES (9)
SET IDENTITY_INSERT [dbo].[tbl2] OFF
SET IDENTITY_INSERT [dbo].[tblAnbar] ON 

INSERT [dbo].[tblAnbar] ([ID], [fldCode], [fldNameAnbar]) VALUES (1, 1000, N'مرکزی')
SET IDENTITY_INSERT [dbo].[tblAnbar] OFF
SET IDENTITY_INSERT [dbo].[tblBankeMoshtari] ON 

INSERT [dbo].[tblBankeMoshtari] ([ID], [fldNameBank]) VALUES (5, N'ملی')
INSERT [dbo].[tblBankeMoshtari] ([ID], [fldNameBank]) VALUES (6, N'ملت')
INSERT [dbo].[tblBankeMoshtari] ([ID], [fldNameBank]) VALUES (7, N'صادرات')
INSERT [dbo].[tblBankeMoshtari] ([ID], [fldNameBank]) VALUES (8, N'تجارت')
SET IDENTITY_INSERT [dbo].[tblBankeMoshtari] OFF
INSERT [dbo].[tblChap] ([fldNameMoassese], [fldTozihateBala], [fldAdress], [fldPasafhe], [fldCodeEghtesadi], [fldShomareSabt], [fldCodePosti], [fldTell], [fldLogo]) VALUES (N'نام شرکت/فروشگاه', N'توضیحات بالا', N'آدرس', N'توضیحات پایین', N'', N'', N'', N'', NULL)
SET IDENTITY_INSERT [dbo].[tblControlPanel] ON 

INSERT [dbo].[tblControlPanel] ([fldNameSherkat], [fldShomareEftetahie], [fldShomareEkhtetamie], [fldEx], [fldControleTarikh], [fldNumberPooste], [fldVersion], [ID]) VALUES (N'نام شرکت/فروشگاه', 1, 130, N'44', N'False', N'6', N'7', 1)
SET IDENTITY_INSERT [dbo].[tblControlPanel] OFF
SET IDENTITY_INSERT [dbo].[tblDasteCheck] ON 

INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (396, N'11102', N'پاسداران', 10000, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (397, N'11102', N'پاسداران', 10001, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (398, N'11102', N'پاسداران', 10002, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (399, N'11102', N'پاسداران', 10003, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (400, N'11102', N'پاسداران', 10004, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (401, N'11102', N'پاسداران', 10005, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (402, N'11102', N'پاسداران', 10006, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (403, N'11102', N'پاسداران', 10007, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (404, N'11102', N'پاسداران', 10008, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (405, N'11102', N'پاسداران', 10009, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (406, N'11102', N'پاسداران', 10010, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (407, N'11102', N'پاسداران', 10011, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (408, N'11102', N'پاسداران', 10012, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (409, N'11102', N'پاسداران', 10013, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (410, N'11102', N'پاسداران', 10014, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (411, N'11102', N'پاسداران', 10015, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (412, N'11102', N'پاسداران', 10016, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (413, N'11102', N'پاسداران', 10017, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (414, N'11102', N'پاسداران', 10018, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (415, N'11102', N'پاسداران', 10019, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (416, N'11102', N'پاسداران', 10020, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (417, N'11102', N'پاسداران', 10021, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (418, N'11102', N'پاسداران', 10022, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (419, N'11102', N'پاسداران', 10023, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (420, N'11102', N'پاسداران', 10024, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (421, N'11102', N'پاسداران', 10025, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (422, N'11102', N'پاسداران', 10026, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (423, N'11102', N'پاسداران', 10027, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (424, N'11102', N'پاسداران', 10028, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (425, N'11102', N'پاسداران', 10029, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (426, N'11102', N'پاسداران', 10030, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (427, N'11102', N'پاسداران', 10031, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (428, N'11102', N'پاسداران', 10032, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (429, N'11102', N'پاسداران', 10033, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (430, N'11102', N'پاسداران', 10034, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (431, N'11102', N'پاسداران', 10035, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (432, N'11102', N'پاسداران', 10036, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (433, N'11102', N'پاسداران', 10037, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (434, N'11102', N'پاسداران', 10038, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (435, N'11102', N'پاسداران', 10039, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (436, N'11102', N'پاسداران', 10040, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (437, N'11102', N'پاسداران', 10041, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (438, N'11102', N'پاسداران', 10042, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (439, N'11102', N'پاسداران', 10043, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (440, N'11102', N'پاسداران', 10044, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (441, N'11102', N'پاسداران', 10045, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (442, N'11102', N'پاسداران', 10046, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (443, N'11102', N'پاسداران', 10047, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (444, N'11102', N'پاسداران', 10048, 306602743)
INSERT [dbo].[tblDasteCheck] ([ID], [fldCodeBank], [fldShobe], [fldShomareCheck], [fldShomareHesab]) VALUES (445, N'11102', N'پاسداران', 10049, 306602743)
SET IDENTITY_INSERT [dbo].[tblDasteCheck] OFF
SET IDENTITY_INSERT [dbo].[tblDastrasi] ON 

INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (236, 1000, 100)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (237, 1000, 101)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (241, 1000, 105)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (242, 1000, 106)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (243, 1000, 107)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (244, 1000, 108)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (245, 1000, 201)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (246, 1000, 202)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (262, 1001, 100)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (263, 1001, 101)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (264, 1001, 102)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (266, 1001, 104)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (267, 1001, 105)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (268, 1001, 106)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (269, 1001, 107)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (270, 1001, 108)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (271, 1001, 201)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (272, 1001, 202)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (273, 1002, 100)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (274, 1002, 101)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (276, 1002, 103)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (278, 1002, 105)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (280, 1002, 107)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (282, 1002, 201)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (283, 1002, 202)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (284, 1003, 100)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (285, 1003, 104)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (286, 1003, 106)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (287, 1003, 101)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (289, 1003, 107)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (290, 1000, 102)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (291, 1002, 102)
INSERT [dbo].[tblDastrasi] ([ID], [fldCodeUser], [fldCodeDastrasi]) VALUES (292, 1003, 102)
SET IDENTITY_INSERT [dbo].[tblDastrasi] OFF
SET IDENTITY_INSERT [dbo].[tblDastrasiSandoogh] ON 

INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (27, 1001, 1, N'sandoogh')
INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (28, 1001, 1, N'bank')
INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (35, 1000, 11002, N'sandoogh')
INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (36, 1000, 11103, N'bank')
INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (37, 1002, 11001, N'sandoogh')
INSERT [dbo].[tblDastrasiSandoogh] ([ID], [fldCodeUser], [fldSandoogh], [fldType]) VALUES (38, 1002, 11106, N'bank')
SET IDENTITY_INSERT [dbo].[tblDastrasiSandoogh] OFF
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtBedehkar_KeyDownConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-SaveInformationConversion from string "" to type  Double  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-SaveInformationConversion from string "" to type  Double  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-SaveInformationConversion from string "" to type  Double  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from type  DBNull  to type  String  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from type  DBNull  to type  String  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from string "" to type  Integer  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtShomareSanad_LostFocusConversion from type  DBNull  to type  String  is not valid.', N'13', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
GO
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/24')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/24')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/28')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\7\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\7\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\7\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\7\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\1\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\1\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\1\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\1\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\2\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\2\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\2\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\2\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\3\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\3\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\3\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\3\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\4\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\4\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\4\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\4\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\5\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\5\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\5\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\5\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\minimizedMain.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMain-LoadPicture-F:\Source\Mali 2015\bin\Debug\Picture\6\exitMainMoraba.jpg', N'53', N'96/10/23')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
GO
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblError] ([fldSharh], [fldNumber], [fldDate]) VALUES (N'frmMali-txtTafzili_TextChangedInvalid column name  fldCodeHesab .', N'5', N'//')
INSERT [dbo].[tblGroupAshkhas] ([fldGroupId], [fldGroupName]) VALUES (100, N'لیست اشخاص')
INSERT [dbo].[tblGroupAshkhas] ([fldGroupId], [fldGroupName]) VALUES (101, N'مشتری متفرقه')
INSERT [dbo].[tblGroupKala] ([fldGroupId], [fldGroupName]) VALUES (100, N'لیست کالا')
SET IDENTITY_INSERT [dbo].[tblIDChapgarKala] ON 

INSERT [dbo].[tblIDChapgarKala] ([Id], [fldIDChapgarKala], [fldCodeKala]) VALUES (23, 20010, 1001)
INSERT [dbo].[tblIDChapgarKala] ([Id], [fldIDChapgarKala], [fldCodeKala]) VALUES (24, 20010, 1002)
INSERT [dbo].[tblIDChapgarKala] ([Id], [fldIDChapgarKala], [fldCodeKala]) VALUES (25, 20010, 1003)
SET IDENTITY_INSERT [dbo].[tblIDChapgarKala] OFF
INSERT [dbo].[tblKarbar] ([fldKarKard1], [fldKarKard2], [fldKarKard3], [fldKarKard4], [fldKarKard5], [Gozaresh1], [Gozaresh2], [Gozaresh3], [Gozaresh4], [Gozaresh5], [Gozaresh6], [Gozaresh7], [Taraz1], [Taraz2], [Taraz3], [Poshtiban1], [Poshtiban2], [Paye1], [Paye2], [Paye3], [Paye4], [Paye5], [Paye6], [fldName], [fldPassword], [fldKarKard6], [Paye7], [Paye8], [Gozaresh8], [Gozaresh9], [Gozaresh10]) VALUES (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, N'حسابدار', N'1', 1, 1, 1, 1, 1, 1)
SET IDENTITY_INSERT [dbo].[tblKolMoin] ON 

INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (1, N'1', N'دارايي هاي جاري', N'تراز-دارايي', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (2, N'11001', N'صندوق', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (3, N'11002', N'صندوق2', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (4, N'110', N'صندوقها', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (5, N'11102', N'بانک ملت', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'bank')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (6, N'11103', N'صادرات', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (7, N'11104', N'تجارت', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (8, N'11105', N'ملي', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (9, N'11106', N'ملي 2', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (10, N'112', N'تنخواه', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (11, N'113', N'حسابهاي دريافتني - پرسنل شرکت', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (12, N'11301', N'حسابهاي دريافتني - اشخاص', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (13, N'11310', N'حسابهاي دريافتني - مساعده', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (14, N'11312', N'حسابهاي دريافتني - وام ضروري', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (15, N'11399', N'حسابهاي دريافتني - ساير', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (16, N'114', N'حسابهاي دريافتني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (17, N'11311', N'حسابهاي دريافتني - اشخاص وشرکتها', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (18, N'115', N'پيش پرداختها', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (19, N'11511', N'پيش پرداختها- اشخاص وشرکتها', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (20, N'117', N'اسناددريافتني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (86, N'713', N'فروش', N'معين دارد', N'0', N' ', N' ', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (22, N'2', N'داراييهاي غيرجاري', N'تراز-دارايي', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (23, N'211', N'داراييهاي ثابت', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (24, N'21111', N'داراييهاي ثابت - اثاثيه وملزومات اداري', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (25, N'21112', N'داراييهاي ثابت - لوازم فني', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (26, N'21113', N'داراييهاي ثابت - ماشين آلات', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (27, N'21114', N'داراييهاي ثابت - ساختمانها', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (28, N'21115', N'داراييهاي ثابت - زمين', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (29, N'212', N'داراييهاي نامشهود', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (30, N'21211', N'داراييهاي نامشهود- تلفن', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (31, N'21212', N'داراييهاي نامشهود- نرم افزار', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (32, N'21213', N'داراييها ي نامشهود- سرقفلي', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (33, N'214', N'ذخائر', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (34, N'3', N'بدهيهاي جاري', N'تراز- بدهي', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (35, N'313', N'حسابهاي پرداختني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (36, N'31399', N'حسابهاي پرداختني - پرسنل', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (37, N'315', N'پيش دريافتها', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (38, N'31512', N'پيش دريافتها- اشخاص وشرکتها', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (39, N'317', N'اسنادپرداختني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (87, N'71301', N'فروش کالا', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (41, N'318', N'کسورپرداختني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (42, N'31811', N'کسورپرداختني -ماليات حقوق', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (43, N'31812', N'کسورپرداختني -بيمه حقوق', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (44, N'31813', N'کسورپرداختني -ماليات هاي تکليفي', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (45, N'319', N'سودسهام پرداختني', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (46, N'31912', N'سودسهام پرداختني - سهامداران', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (47, N'4', N'بد هيهاي غيرجاري', N'تراز- بدهي', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (48, N'412', N'تسهيلات واعتبارات مالي', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (49, N'41211', N'تسهيلات واعتبارات مالي - وام', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (50, N'413', N'ذخيره استهلاک انباشته', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (51, N'41311', N'ذخيره استهلاک انباشته - اثاثيه وملزومات اداري', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (52, N'41312', N'ذخيره استهلاک انباشته - لوازم فني', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (53, N'41313', N'ذخيره استهلاک انباشته - ماشين آلات', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (54, N'41314', N'ذخيره استهلاک انباشته - ساختمانها', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (55, N'5', N'حقوق صاحبان سهام', N'تراز- بدهي', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (56, N'511', N'سرمايه', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (57, N'512', N'اندوخته قانوني', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (58, N'513', N'سودوزيان', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (59, N'51311', N'سودوزيان سال جاري', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (60, N'51312', N'سودوزيان سنواتي', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (61, N'51313', N'سودوزيان انباشته', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (62, N'6', N'هزينه ها', N'عملكرد هزينه', N'2', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (63, N'611', N'هزينه هاي عملياتي', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (64, N'61101', N'تخفيفات دريافت', N'اشخاص', N'1', N'غير فعال  ', N'غير فعال  ', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (65, N'61112     ', N'هزينه هاي عملياتي - ماشين آلات', N'تفصيلي ندارد        ', N'4         ', N'فعال      ', N'غير فعال  ', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (88, N'71102', N'درآمد حمل و نقل', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (108, N'11003', N'تنخواه زرگانی', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (66, N'61113     ', N'هزينه هاي عملياتي  - عمومي', N'مركزهزينه           ', N'2         ', N'فعال      ', N'غير فعال  ', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (67, N'7', N'درآمد', N'عملكرد درآمد', N'3', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (68, N'711', N'درآمدعملياتي', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (69, N'71111', N'درآمد ناشي ازارائه خدمات', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (70, N'712', N'درآمدهاي غيرعملياتي', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (71, N'8', N'حسابهاي آماري', N'حساب واسطه', N'4', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (72, N'811', N'حسابهاي انتظامي', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (73, N'81111', N'ضمانتنامه شرکت در مناقصه', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (74, N'81112', N'ضمانتنامه پيش پرداخت', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (75, N'81113', N'ضمانتنامه حسن اجراي تعهدات', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (76, N'81114', N'چک سفته و ضمانتنامه مانزدديگران', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (77, N'81115', N'چک سفته و ضمانتنامه مانزدديگران', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (78, N'81116', N'چک سفته وضمانتنامه ديگران نزدما', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (79, N'812', N'طرف حساب انتظامي', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (80, N'899', N'کنترل حسابها', N'معين ندارد', N'1', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (81, N'111', N'بانکها', N'معين دارد', N'0', N'', N'', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (82, N'71101', N'تخفيفات پرداخت', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (83, N'31301', N'حسابهاي پرداختني - سایر اشخاص', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (84, N'11701', N'اسناد دريافتني - اشخاص', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (85, N'31701', N'اسناد پرداختني - اشخاص', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (89, N'31302', N'حسابهاي پرداختني-ارزش افزوده', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (90, N'11201', N'تنخواه پرسنل', N'جاري كاركنان', N'0', N'فعال', N'فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (91, N'109', N'کالا', N'معين دارد', N'0', N' ', N' ', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (92, N'10901', N'موجودي ابتداي دوره', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (93, N'11401', N'حسابهاي دريافتني-ارزش افزوده', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (97, N'61102', N'هزينه حمل و نقل', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (98, N'612', N'هزينه هاي اداري', N'معين دارد', N'0', N' ', N' ', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (100, N'10902', N'خريد', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (99, N'61201', N'هزينه حقوق', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (101, N'31303', N'حسابهاي پرداختني - پورسانت پرسنل', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (102, N'61114', N'هزینه حقوق', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (103, N'61103', N'هزينه اجاره', N'اشخاص', N'1', N'غير فعال', N'غير فعال', N'')
GO
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (104, N'61111', N'هزينه حقوق پرسنل', N'جاري كاركنان', N'0', N'غير فعال', N'غير فعال', N'')
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (105, N'61115', N'هزینه متفرقه', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (106, N'61116', N'هزینه حمل و نقل', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (109, N'61118', N'هزینه پذیرایی', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (113, N'61121', N'هزینه مراسم', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (107, N'61117', N'هزینه اداری3', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (110, N'61119', N'هزینه قفل', N'اشخاص', N'1', N'غير فعال', N'غير فعال', NULL)
INSERT [dbo].[tblKolMoin] ([ID], [fldCodeHesab], [fldSharheHesab], [fldNoeHesab], [fldCodeNoeHesab], [fldMarkazFirst], [fldMarkazSecond], [fldNoe]) VALUES (111, N'61120', N'هزینه کرایه', N'تفصيلي ندارد', N'4', N'غير فعال', N'غير فعال', NULL)
SET IDENTITY_INSERT [dbo].[tblKolMoin] OFF
SET IDENTITY_INSERT [dbo].[tblListeDastrasi] ON 

INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (1, 100, N'فروش', 1, 1, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (2, 101, N'امکان حذف فاکتور فروش', 1, 2, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (3, 102, N'امکان اصلاح فاکتور فروش', 1, 3, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (4, 103, N'امکان ثبت فاکتور فروش اعتباری', 1, 4, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (5, 104, N'امکان مشاهده آرشیو فاکتور فروش', 1, 5, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (6, 105, N'امکان تغییر فی فروش', 1, 6, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (7, 106, N'امکان مشاهده انبار جاری در فاکتور فروش', 1, 7, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (8, 107, N'امکان مشاهده انبار کل در فاکتور فروش', 1, 8, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (9, 108, N'امکان اصلاح فاکتور توسط کاربر دیگر', 1, 9, N'فروش')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (10, 201, N'امکان حذف فاکتور خرید', 2, 1, N'خرید')
INSERT [dbo].[tblListeDastrasi] ([ID], [fldCode], [fldName], [fldGroup], [fldOrder], [fldNameGroup]) VALUES (11, 202, N'امکان اصلاح فاکتور خرید', 2, 2, N'خرید')
SET IDENTITY_INSERT [dbo].[tblListeDastrasi] OFF
INSERT [dbo].[tblMarkaz1] ([fldCode], [fldSharh]) VALUES (N'1         ', N'ا                                                                                                                                                                                                       ')
INSERT [dbo].[tblMarkaz1] ([fldCode], [fldSharh]) VALUES (N'1010      ', N'ال                                                                                                                                                                                                      ')
INSERT [dbo].[tblMarkaz2] ([fldCode], [fldSharh]) VALUES (N'1         ', N'يلا                                                                                                                                                                                                     ')
INSERT [dbo].[tblMarkaz2] ([fldCode], [fldSharh]) VALUES (N'1010      ', N'ذت                                                                                                                                                                                                      ')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'10902', N'', N'10000', N'0', N'10000', NULL, N'282', 960823, NULL, NULL, NULL, N'96/08/23')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'31301', N'فاکتور خريد شماره 75', N'0', N'11000', N'-11000', NULL, N'282', 960823, NULL, NULL, NULL, N'96/08/23')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'10902', N'', N'0', N'10000', N'-10000', NULL, N'284', 960823, NULL, NULL, NULL, N'96/08/23')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'31301', N'برگشت از خريد شماره 23', N'11000', N'0', N'11000', NULL, N'284', 960823, NULL, NULL, NULL, N'96/08/23')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'10902', N'', N'0', N'1000', N'-1000', NULL, N'302', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'31301', N'برگشت از خريد شماره 29', N'1100', N'0', N'1100', NULL, N'302', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'31301', N'5', N'0', N'30007', N'-30007', NULL, N'302', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'11701', N'3', N'30000', N'0', N'30000', NULL, N'302', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'11701', N'3', N'33333', N'0', N'33333', NULL, N'303', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'11301', N'55', N'0', N'33340', N'-33340', NULL, N'303', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'71301', N'برگشت از فروش به شماره 106', N'25000', N'0', N'25000', NULL, N'316', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'11301', N'برگشت از فروش به شماره 106', N'0', N'27500', N'-27500', NULL, N'316', 960824, NULL, NULL, NULL, N'96/08/24')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'10902', N'', N'10000', N'0', N'10000', NULL, N'330', 960826, NULL, NULL, NULL, N'96/08/26')
INSERT [dbo].[tblMorooreHesabha] ([fldCodeHesab], [fldSharh], [fldBedehkar], [fldBestankar], [fldMande], [fldMandeInt], [fldShomareSanad], [fldDate], [fldSharheKol], [fldSharheMoin], [fldCodeKol], [fldDateShow]) VALUES (N'31301', N'فاکتور خريد شماره 83', N'0', N'11000', N'-11000', NULL, N'330', 960826, NULL, NULL, NULL, N'96/08/26')
INSERT [dbo].[tblPaye] ([fldKol], [fldMoin], [fldTafzili], [fldMarkaz1], [fldMarkaz2], [fldMaheSaleMali]) VALUES (3, 2, 5, 4, 4, N'فروردین')
SET IDENTITY_INSERT [dbo].[tblPishForoosh] ON 

INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (4, 1, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (6, 3, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (7, 5, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (8, 7, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (9, 8, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (11, 9, NULL, 13961029, N'', NULL)
INSERT [dbo].[tblPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (13, 10, NULL, 13961029, N'', NULL)
SET IDENTITY_INSERT [dbo].[tblPishForoosh] OFF
SET IDENTITY_INSERT [dbo].[tblPishPishForoosh] ON 

INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (645, 15, NULL, 13961113, N'34', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (646, 16, NULL, 13961113, N'35', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (647, 17, NULL, 13961113, N'36', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (648, 18, NULL, 13961113, N'37', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (649, 19, NULL, 13961113, N'38', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (650, 20, NULL, 13961113, N'39', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (651, 21, NULL, 13961113, N'40', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (652, 22, NULL, 13961113, N'42', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (653, 23, NULL, 13961113, N'43', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (654, 24, NULL, 13961114, N'44', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (655, 25, NULL, 13961114, N'45', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (656, 26, NULL, 13961114, N'46', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (657, 27, NULL, 13961114, N'47', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (658, 28, NULL, 13961114, N'48', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (659, 29, NULL, 13961114, N'49', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (660, 30, NULL, 13961114, N'50', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (661, 31, NULL, 13961114, N'51', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (662, 32, NULL, 13961114, N'52', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (663, 33, NULL, 13961115, N'55', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (664, 34, NULL, 13961115, N'56', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (665, 35, NULL, 13961115, N'57', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (666, 36, NULL, 13961115, N'1', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (667, 37, NULL, 13961115, N'2', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (668, 38, NULL, 13961115, N'58', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (669, 39, NULL, 13961115, N'59', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (670, 40, NULL, 13961115, N'1', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (671, 41, NULL, 13961115, N'3', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (672, 42, NULL, 13961115, N'60', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (673, 43, NULL, 13961115, N'61', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (674, 44, NULL, 13961115, N'4', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (675, 45, NULL, 13961115, N'62', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (676, 46, NULL, 13961116, N'5', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (677, 47, NULL, 13961116, N'6', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (678, 48, NULL, 13961116, N'63', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (679, 49, NULL, 13961116, N'3', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (680, 50, NULL, 13961116, N'4', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (681, 51, NULL, 13961117, N'5', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (682, 52, NULL, 13961117, N'6', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (683, 53, NULL, 13961117, N'2', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (684, 54, NULL, 13961118, N'3', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (685, 55, NULL, 13961119, N'4', NULL)
INSERT [dbo].[tblPishPishForoosh] ([ID], [fldShomareFactorForoosh], [fldShomareSanad], [fldDate], [fldSharhFactor], [fldHamloNaghl]) VALUES (686, 56, NULL, 13961119, N'6', NULL)
SET IDENTITY_INSERT [dbo].[tblPishPishForoosh] OFF
SET IDENTITY_INSERT [dbo].[tblRizePishForoosh] ON 

INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (4, NULL, 1, 0, 10002, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(450 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(5450 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:51 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (5, NULL, 1, 0, 10002, 0, 2, 1000, 1001, N'', N'', CAST(2.00 AS Decimal(18, 2)), CAST(3000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(6000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(540 AS Decimal(18, 0)), CAST(6000 AS Decimal(18, 0)), CAST(6540 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:51 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (8, NULL, 2, 0, 10002, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(1000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(90 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), CAST(1090 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:53 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (9, NULL, 2, 0, 10002, 0, 2, 1000, 1002, N'', N'', CAST(2.00 AS Decimal(18, 2)), CAST(10000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(20000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(1800 AS Decimal(18, 0)), CAST(20000 AS Decimal(18, 0)), CAST(21800 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:53 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (10, NULL, 3, 0, 10002, 0, 3, 1000, 1001, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(3000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(3000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(270 AS Decimal(18, 0)), CAST(3000 AS Decimal(18, 0)), CAST(3270 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:53 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (12, NULL, 5, 0, 10001, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(450 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(5450 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:54 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (13, NULL, 7, 0, 10003, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(450 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(5450 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:55 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (14, NULL, 8, 10006, 10002, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(450 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(5450 AS Decimal(18, 0)), N'Foroosh', 13961029, N'06:56 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (16, NULL, 9, 10006, 10000, 0, 1, 1000, 1000, N'', N'', CAST(1.00 AS Decimal(18, 2)), CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(450 AS Decimal(18, 0)), CAST(5000 AS Decimal(18, 0)), CAST(5450 AS Decimal(18, 0)), N'Foroosh', 13961029, N'07:17 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (19, NULL, 10, 10006, 10003, 0, 1, 1000, 1000, N'', N'', CAST(2.00 AS Decimal(18, 2)), CAST(2000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(4000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(360 AS Decimal(18, 0)), CAST(4000 AS Decimal(18, 0)), CAST(4360 AS Decimal(18, 0)), N'Foroosh', 13961029, N'07:33 ب ظ', NULL, NULL)
INSERT [dbo].[tblRizePishForoosh] ([ID], [fldShomareSanad], [fldShomareFactor], [fldCodeVasete], [fldCodeTafsili], [fldCodeUser], [fldRadif], [fldCodeAnbar], [fldCodeKala], [fldSharhKala], [fldTedadCarton], [fldTedadJoz], [fldFeeJoz], [fldFeeYekCarton], [fldFeeKol], [fldDarsadTakhfif], [fldMablaghTakhfif], [fldFeeVahed1BadAzTakhfif], [fldFeeVahed2BadAzTakhfif], [fldArzeshAfzode], [fldFeeKolBadAzTakhfif], [fldMablaghKhales], [fldType], [fldDate], [fldTime], [fldShomareEnteghal], [fldShomareBargasht]) VALUES (20, NULL, 10, 10006, 10003, 0, 2, 1000, 1002, N'', N'', CAST(3.00 AS Decimal(18, 2)), CAST(30000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(90000 AS Decimal(18, 0)), CAST(0.00 AS Decimal(18, 2)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(8100 AS Decimal(18, 0)), CAST(90000 AS Decimal(18, 0)), CAST(98100 AS Decimal(18, 0)), N'Foroosh', 13961029, N'07:33 ب ظ', NULL, NULL)
SET IDENTITY_INSERT [dbo].[tblRizePishForoosh] OFF
SET IDENTITY_INSERT [dbo].[tblRizeTasfie] ON 

INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (1, 5, 1, 1000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (2, 5, 2, 500)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (3, 6, 3, 600)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (4, 6, 4, 800)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (5, 6, 5, 700)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (6, 5, 10, 8000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (7, 7, 10, 10000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (8, 8, 10, 1000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (9, 4, 10, 1000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (14, 9, 11, 200000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (15, 9, 12, 300000)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (16, 6, 13, 69900)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (17, 3, 13, 10100)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (18, 3, 14, 1900)
INSERT [dbo].[tblRizeTasfie] ([ID], [fldShomareFactor], [fldShomareDaryaft], [fldMablagh]) VALUES (19, 6, 16, 72000)
SET IDENTITY_INSERT [dbo].[tblRizeTasfie] OFF
SET IDENTITY_INSERT [dbo].[tblSecurity] ON 

INSERT [dbo].[tblSecurity] ([ID], [fldCode], [fldUser], [fldPassword], [fldType]) VALUES (1, 1000, N'سازنده', N'g/byxfZyaO+Q0vRvW5o1uA==', 0)
INSERT [dbo].[tblSecurity] ([ID], [fldCode], [fldUser], [fldPassword], [fldType]) VALUES (10012, 1001, N'مجید', N'1GvYtZNLLSaUEy5L85q4kw==', 1)
INSERT [dbo].[tblSecurity] ([ID], [fldCode], [fldUser], [fldPassword], [fldType]) VALUES (10013, 1002, N'محسن', N'g/byxfZyaO+Q0vRvW5o1uA==', 1)
INSERT [dbo].[tblSecurity] ([ID], [fldCode], [fldUser], [fldPassword], [fldType]) VALUES (10014, 1003, N'کاربر', N'g/byxfZyaO+Q0vRvW5o1uA==', 2)
INSERT [dbo].[tblSecurity] ([ID], [fldCode], [fldUser], [fldPassword], [fldType]) VALUES (10015, 1004, N'نسن', N'g/byxfZyaO+Q0vRvW5o1uA==', 2)
SET IDENTITY_INSERT [dbo].[tblSecurity] OFF
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (2, N'اصلاح حساب ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (3, N'بابت سندهزينه شماره ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (4, N'چک شماره ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (5, N'فيش واريزي')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (6, N'علي الحساب بابت پروژه ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (7, N'تراکنش')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (8, N'منظوربه حساب ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (9, N'بابت تسويه بدهي ')
INSERT [dbo].[tblSharhhayePishSakhte] ([fldCode], [fldSharh]) VALUES (10, N'بابت کارمزد بانکي ')
SET IDENTITY_INSERT [dbo].[tblSodooreSanad3] ON 

INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (10, N'1', N'1', N'1', N'95', N'111', N'02', N'', N'', N'', CAST(10000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', N'0', 950101, N'', N'11102', N'', NULL, NULL, NULL, N'', NULL, NULL, NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (11, N'1', N'1', N'1', N'95', N'111', N'02', N'', N'', N'', CAST(0 AS Decimal(18, 0)), CAST(10000 AS Decimal(18, 0)), N'2', N'0', 950101, N'', N'11102', N'', NULL, NULL, NULL, N'', NULL, NULL, NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (29, N'3', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (30, N'3', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (31, N'3', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (26, N'2', N'01', N'01', N'95', N'110', N'01', N'', N'', N'', CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', N'0', 950101, N'', N'11001', N'', NULL, NULL, NULL, N'', NULL, NULL, NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (27, N'2', N'01', N'01', N'95', N'111', N'02', N'', N'', N'', CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', N'0', 950101, N'', N'11102', N'', NULL, NULL, NULL, N'', NULL, NULL, NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (28, N'2', N'01', N'01', N'95', N'110', N'01', N'', N'', N'', CAST(0 AS Decimal(18, 0)), CAST(133000 AS Decimal(18, 0)), N'3', N'0', 950101, N'', N'11001', N'', NULL, NULL, NULL, N'', NULL, NULL, NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (32, N'4', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (33, N'4', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (34, N'4', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (35, N'4', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'0161101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (36, N'5', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (37, N'5', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (38, N'5', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (39, N'5', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'61161101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (40, N'6', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (41, N'6', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (42, N'6', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (43, N'6', N'01', N'01', N'95', N'611', N'61161101', N'', NULL, NULL, CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'61161101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (44, N'7', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (45, N'7', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (46, N'7', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (47, N'7', N'01', N'01', N'95', N'611', N'01', N'', NULL, NULL, CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'61161101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (48, N'8', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (49, N'8', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (50, N'8', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (51, N'8', N'01', N'01', N'95', N'611', N'', N'', NULL, NULL, CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'61101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (52, N'9', N'01', N'01', N'95', N'110', N'01', N'', NULL, NULL, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'1', NULL, 950101, N'', N'11001', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (53, N'9', N'01', N'01', N'95', N'111', N'02', N'', NULL, NULL, CAST(13000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'2', NULL, 950101, N'', N'11102', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (54, N'9', N'01', N'01', N'95', N'117', N'11', N'', NULL, NULL, CAST(160000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'3', NULL, 950101, N'', N'11711', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
INSERT [dbo].[tblSodooreSanad3] ([ID], [fldSanad], [fldDay], [fldMonth], [fldYear], [fldCodeKol], [fldCodeMoin], [fldCodeTafzili], [fldCodeMarkaz1], [fldCodeMarkaz2], [fldBedehkar], [fldBestankar], [fldRadif], [fldCodeSharh], [fldDate], [fldSharh], [fldMoinKamel], [fldCodeNoeTafzili], [fldGhateiMovaghat], [fldGhateiDaem], [fldSanadGhadim], [fldShomarePeigiri], [fldMoghayerat], [fldType], [fldAz]) VALUES (55, N'9', N'01', N'01', N'95', N'611', N'01', N'', NULL, NULL, CAST(5000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), N'4', NULL, 950101, N'', N'61101', N'', NULL, NULL, NULL, NULL, NULL, N'daryaft', NULL)
SET IDENTITY_INSERT [dbo].[tblSodooreSanad3] OFF
SET IDENTITY_INSERT [dbo].[tblTafzili] ON 

INSERT [dbo].[tblTafzili] ([ID], [fldNoeHesab], [fldSharheTafzili], [fldCodeTafzili], [fldCodeNoe], [fldNoe], [fldCodeGroup], [fldOstan], [fldCity], [fldAddress], [fldShomareHesab], [fldCodeMeli], [fldCodeEghtesadi], [fldCodePosti], [fldShomareSabt], [fldSaghfeEtebar], [fldBlackList], [fldSharhBlackList], [fldDate1], [fldDate2], [fldVisitor], [fldPic], [fldNoeVizitor], [fldPoorsant], [fldCodeSuperVisor], [fldNoeMohasebePoorsant]) VALUES (164, N'', N'مشتری', N'10000', N'1', N'', N'101', N'', N'', N'', N'', N'', N'', N'', N'', N'0', N'0', N'', 0, 0, 10009, N'', NULL, NULL, NULL, 0)
SET IDENTITY_INSERT [dbo].[tblTafzili] OFF
INSERT [dbo].[tblTanzimat] ([fldCodeKolBank], [fldCodeKolHazine], [fldCodeKolSandoogh], [fldCodeMoinCheck], [fldCodeMoinTakhfifateDaryaft], [fldCodeMoinHesabhayeDaryaftani], [fldCodeKolCheck], [fldCodeMoinTakhfifatePardakht], [fldCodeMoinHesabhayePardakhtani], [fldCodeKolCheckPardakhti], [fldCodeMoinCheckPardakhti], [fldCodeKolDaramad], [fldCodeMoinDaramad], [fldCodeMoinForoosh], [fldMoinArzesheAfzoode], [fldMoinDaramadeHamlVaNaghl], [fldMoinMojoodieEbteda], [fldKolSarmaye], [fldMoinArzesheAfzoodeKharid], [fldCodeMoinKharid], [fldCodeMoinHazineHamlVaNaghl], [fldCodeMoinBargashtAzForoosh], [fldCodeKolHesabhayeDaryaftani], [fldCodeKolHesabhayePardakhtani], [fldCodeHoghoogh], [fldCodeMoinHesabhayePardakhtaniPoorsant]) VALUES (N'111', N'611', N'110', N'11701', N'61101', N'11301', N'117', N'71101', N'31301', N'317', N'31701', N'711', N'71101', N'71301', N'31302', N'71102', N'10901', N'511', N'11401', N'10902', N'61102', N'71301', N'113', N'313', N'61201', N'31303')
INSERT [dbo].[tblTanzimateKol] ([fldType], [fldMeghdar]) VALUES (N'komision', N'5')
SET IDENTITY_INSERT [dbo].[tblTanzimatForoosh] ON 

INSERT [dbo].[tblTanzimatForoosh] ([ID], [fldKalaTekrary], [fldTypeInputKalaInGrid], [fldAllowForooshKalaBishAzMojodi], [fldShowMotalebatInFactorForoosh], [fldForooshNaghdi], [fldShowSodKala], [fldShowSodFactor], [fldEshantion], [fldChandGheymate], [fldArzeshAfzode], [fldTedadChapInForoosh], [fldSearchNumberingInKala], [fldBeginDateTakhfifat], [fldEndDateTakhfifat]) VALUES (10081, 0, N'Royeham', 1, 0, 0, 0, 0, 0, 0, CAST(9 AS Decimal(18, 0)), 1, 0, 13960101, 13960101)
SET IDENTITY_INSERT [dbo].[tblTanzimatForoosh] OFF
SET IDENTITY_INSERT [dbo].[tblTanzimatNew] ON 

INSERT [dbo].[tblTanzimatNew] ([ID], [fldName], [fldMeghdar]) VALUES (10034, N'barcodeforoosh', N'0')
SET IDENTITY_INSERT [dbo].[tblTanzimatNew] OFF
SET IDENTITY_INSERT [dbo].[tblTasfie] ON 

INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (2, N'10004', 5, CAST(12000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(12000 AS Decimal(18, 0)), CAST(8000 AS Decimal(18, 0)), N'تو', 13960101)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (3, N'10004', 6, CAST(144000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(144000 AS Decimal(18, 0)), CAST(72000 AS Decimal(18, 0)), N'', 13960505)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (4, N'10004', 7, CAST(10000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(10000 AS Decimal(18, 0)), CAST(10000 AS Decimal(18, 0)), N'', 13961124)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (5, N'10004', 8, CAST(1000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), N'توصیف', 13961128)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (6, N'10004', 4, CAST(1000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), CAST(1000 AS Decimal(18, 0)), N'', 13961125)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (7, N'10004', 3, CAST(12000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(12000 AS Decimal(18, 0)), CAST(12000 AS Decimal(18, 0)), N'', 13961125)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (8, N'10000', 2, CAST(120000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(120000 AS Decimal(18, 0)), CAST(120000 AS Decimal(18, 0)), N'', 13961125)
INSERT [dbo].[tblTasfie] ([ID], [fldCodeTafzili], [fldShomareFactor], [fldMablagheFactor], [fldMablagheDaryafti], [fldMablagheMandeFactor], [fldMablagheMande], [fldSharh], [fldDateSarResid]) VALUES (9, N'10005', 9, CAST(600000 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(600000 AS Decimal(18, 0)), CAST(600000 AS Decimal(18, 0)), N'', 13961125)
SET IDENTITY_INSERT [dbo].[tblTasfie] OFF
SET IDENTITY_INSERT [dbo].[tblTest] ON 

INSERT [dbo].[tblTest] ([id], [adad]) VALUES (15, 123)
INSERT [dbo].[tblTest] ([id], [adad]) VALUES (20, 0)
INSERT [dbo].[tblTest] ([id], [adad]) VALUES (16, 20)
INSERT [dbo].[tblTest] ([id], [adad]) VALUES (17, 0)
INSERT [dbo].[tblTest] ([id], [adad]) VALUES (18, 0)
INSERT [dbo].[tblTest] ([id], [adad]) VALUES (19, 0)
SET IDENTITY_INSERT [dbo].[tblTest] OFF
SET IDENTITY_INSERT [dbo].[tblTest2] ON 

INSERT [dbo].[tblTest2] ([ID], [name]) VALUES (3, N'301')
SET IDENTITY_INSERT [dbo].[tblTest2] OFF
INSERT [dbo].[tblTest5] ([id], [name1], [name2], [name3]) VALUES (NULL, N'16', N'19', NULL)
INSERT [dbo].[tblTest5] ([id], [name1], [name2], [name3]) VALUES (NULL, N'16', N'19', NULL)
INSERT [dbo].[tblTest6] ([fld1], [fld2]) VALUES (N'majid', N'25')
INSERT [dbo].[tblTest6] ([fld1], [fld2]) VALUES (N'mohsen', N'40')
INSERT [dbo].[tblTest6] ([fld1], [fld2]) VALUES (N'mehdi', N'50')
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 187, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 187, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 182, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 181, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 180, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 179, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 178, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 177, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 176, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 175, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 174, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 173, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 172, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 171, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 170, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 168, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 167, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 166, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 165, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 164, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 163, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 161, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 160, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 159, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 158, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 157, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 156, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 155, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 154, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 153, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 152, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 151, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 150, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 149, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 148, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 147, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 146, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 145, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 144, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 143, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 142, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 105, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 104, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 103, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 102, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 101, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 187, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 182, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 182, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 181, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 192, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 182, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 181, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 193, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 105, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 104, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 103, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 102, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 101, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 100, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 187, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 183, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 182, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 181, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 180, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 179, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 178, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 177, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 176, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 175, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 174, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 173, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 172, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 175, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 187, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 186, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 184, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 16, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 16, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 185, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 31, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 42, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 31, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 90, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 90, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 88, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 90, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 88, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 40, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 39, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 38, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 37, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 36, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 35, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 34, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 33, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 33, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 32, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 31, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 10, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 16, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 1, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 16, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 16, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 15, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 14, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 9, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 8, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 3, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 4, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 2, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 11, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 13, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 12, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 6, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 18, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 5, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 7, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 42, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 41, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 40, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 39, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 39, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 38, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 37, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 36, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 35, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 34, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 33, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 32, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 32, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 31, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 42, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 41, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 40, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 39, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 21, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 20, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 19, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 18, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 17, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 27, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 23, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 22, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
GO
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 26, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 28, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 25, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 24, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 30, NULL)
INSERT [dbo].[tblTest7] ([fld1], [fld2], [fld3]) VALUES (NULL, 29, NULL)
SET IDENTITY_INSERT [dbo].[tblTranslate] ON 

INSERT [dbo].[tblTranslate] ([ID], [fldCode], [fldLang], [fldMatn]) VALUES (1, 1000, N'farsi', N'سازنده')
INSERT [dbo].[tblTranslate] ([ID], [fldCode], [fldLang], [fldMatn]) VALUES (2, 1001, N'farsi', N'مدیر')
INSERT [dbo].[tblTranslate] ([ID], [fldCode], [fldLang], [fldMatn]) VALUES (3, 1002, N'farsi', N'کاربر')
SET IDENTITY_INSERT [dbo].[tblTranslate] OFF
SET IDENTITY_INSERT [dbo].[tblVahed] ON 

INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (1, N'انتخاب کنید')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (2, N'عدد')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (3, N'گرم')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (4, N'کیلوگرم')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (5, N'متر')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (6, N'کارتن')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (7, N'دستگاه')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (8, N'شاخه')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (9, N'جفت')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (10, N'بسته')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (11, N'حلقه')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (12, N'متر مربع')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (13, N'مسیر')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (14, N'مورد')
INSERT [dbo].[tblVahed] ([ID], [fldNameVahed]) VALUES (15, N'پالت')
SET IDENTITY_INSERT [dbo].[tblVahed] OFF
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1000, N'مرعشی', CAST(10 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1000, N'مرکزی', CAST(0 AS Decimal(18, 0)), -1.0000, 1000.0000, -1.0000, N'عدد', N'انتخاب کنید', 1000)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1001, N'تن ماهی', CAST(1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1000, N'مرکزی', CAST(0 AS Decimal(18, 0)), -1.0000, 10000.0000, -1.0000, N'عدد', N'انتخاب کنید', 12344)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1001, N'تن ماهی', CAST(10 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1001, N'فروشگاه', CAST(0 AS Decimal(18, 0)), -1.0000, 0.0000, -1.0000, N'عدد', N'انتخاب کنید', 12344)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1000, N'مرعشی', CAST(10 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1000, N'مرکزی', CAST(0 AS Decimal(18, 0)), -1.0000, 1000.0000, -1.0000, N'عدد', N'انتخاب کنید', 1000)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1001, N'تن ماهی', CAST(1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1000, N'مرکزی', CAST(0 AS Decimal(18, 0)), -1.0000, 10000.0000, -1.0000, N'عدد', N'انتخاب کنید', 12344)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1001, N'تن ماهی', CAST(10 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1001, N'فروشگاه', CAST(0 AS Decimal(18, 0)), -1.0000, 0.0000, -1.0000, N'عدد', N'انتخاب کنید', 12344)
INSERT [dbo].[TempMojoodieAnbar] ([fldGroupName], [fldCodeGroup], [fldCodeKala], [fldNameKala], [fldTedadeVorood], [fldTedadeKhorooj], [fldTedadeJoz], [fldTedadeKol], [fldTedadDarKarton], [fldCodeAnbar], [fldNameAnbar], [fldNogheSefaresh], [fldFeeForoosh], [fldLastFee], [fldMianginFee], [fldNameVahed], [fldNameVahed2], [fldKharid]) VALUES (N'لیست کالا', 100, 1000, N'مرعشی', CAST(0 AS Decimal(18, 0)), CAST(1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(-1 AS Decimal(18, 0)), CAST(0 AS Decimal(18, 0)), 1000, N'مرکزی', CAST(0 AS Decimal(18, 0)), 10000.0000, 0.0000, -1.0000, N'عدد', N'انتخاب کنید', 1000)
/****** Object:  StoredProcedure [dah].[DateToShow]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[DateToShow]
	-- Add the parameters for the stored procedure here
	
	@strDate nvarchar(10),
	@NewDate nvarchar(15) output
AS
BEGIN
	--declare @str1 nvarchar(15),@strTest nvarchar(15)
	--set @strTest ='960601'
	--set @str =(Select '/' + SUBSTRING('960601', 2,2))


	if len(@strDate)=6 -- بدون 13 اول
		begin
			set @NewDate = (Select Substring(@strDate,1,2) + '/')
			set @NewDate =(select @NewDate +  Substring(@strDate,3,2) + '/' )


		end

END

GO
/****** Object:  StoredProcedure [dah].[DateToShow6Va9Ragham]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[DateToShow6Va9Ragham]
	-- Add the parameters for the stored procedure here
	
	@strDate nvarchar(10),
	@NewDate nvarchar(15) output
AS
BEGIN
	--declare @str1 nvarchar(15),@strTest nvarchar(15)
	--set @strTest ='960601'
	--set @str =(Select '/' + SUBSTRING('960601', 2,2))


	if len(@strDate)=6 -- بدون 13 اول
		begin
			set @NewDate = (Select Substring(@strDate,1,2) + '/')
			set @NewDate =(select @NewDate +  Substring(@strDate,3,2) + '/' )
			set @NewDate =(select @NewDate +  Substring(@strDate,5,2) )

		end

END

GO
/****** Object:  StoredProcedure [dah].[DeleteSuperVizor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[DeleteSuperVizor]
	-- Add the parameters for the stored procedure here
	@ID bigint
AS
BEGIN
	Delete from tblTafzili Where ID=@Id
END

GO
/****** Object:  StoredProcedure [dah].[HasAmalkardSuperVizor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[HasAmalkardSuperVizor] 
	-- Add the parameters for the stored procedure here
	@CodeTafzili nvarchar(10),
	@strHasAmalkard nvarchar(20) output
AS
BEGIN
	declare @bigCount bigint
	set @bigCount=(Select count(id) from tblTafzili Where fldCodeSuperVisor=@CodeTafzili)
	
	set @strHasAmalkard='false'
	if @bigCount>0 		
		set @strHasAmalkard='true'
	else
		set @bigCount=(Select count(id) from tblSodooreSanad Where fldCodeTafzili=@CodeTafzili)
			if @bigCount>0 				
				set @strHasAmalkard='true'			
				



END

GO
/****** Object:  StoredProcedure [dah].[HasAmalkardVizitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create PROCEDURE [dah].[HasAmalkardVizitor] 
	-- Add the parameters for the stored procedure here
	@CodeTafzili nvarchar(10),
	@strHasAmalkard nvarchar(20) output
AS
BEGIN
	declare @bigCount bigint
	set @bigCount=(Select count(id) from tblRizeForoosh Where fldCodeVasete=@CodeTafzili)
	
	set @strHasAmalkard='false'
	if @bigCount>0 		
		set @strHasAmalkard='true'
	else
		set @bigCount=(Select count(id) from tblSodooreSanad Where fldCodeTafzili=@CodeTafzili)
			if @bigCount>0 				
				set @strHasAmalkard='true'			
				



END

GO
/****** Object:  StoredProcedure [dah].[InfoPoorsantVizitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[InfoPoorsantVizitor] 
	@CodeTafzili nvarchar(10),
	@fldNoeMohasebePoorsant int output,
	@fldCodeSuperVisor nvarchar(10) output,
	@fldPoorsant int output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	set @fldNoeMohasebePoorsant=(Select fldNoeMohasebePoorsant from tblTafzili Where fldCodeTafzili = @CodeTafzili)
	set @fldCodeSuperVisor=(Select iif(fldCodeSuperVisor is null,'',fldCodeSuperVisor) from tblTafzili Where fldCodeTafzili = @CodeTafzili)
	set @fldPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili = @CodeTafzili)
	
END

GO
/****** Object:  StoredProcedure [dah].[LoadSuperVisor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[LoadSuperVisor]
	-- Add the parameters for the stored procedure here
	
	
AS
BEGIN
	update tblTafzili set fldNoeMohasebePoorsant=0  where fldNoeMohasebePoorsant is null
	select fldCodeTafzili , fldSharheTafzili,fldPoorsant,ID,fldNoeMohasebePoorsant,iif(fldNoeMohasebePoorsant=1,'فروش','واریز') as fldSharheMohasebe from tblTafzili Where fldCodeNoe='0' And fldNoeVizitor=1
END

GO
/****** Object:  StoredProcedure [dah].[LoadVaseteArshiveBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dah].[LoadVaseteArshiveBargashtAzForoosh] 
	-- Add the parameters for the stored procedure here
	@ShomareSanad nvarchar(50),
	@CodeTafziliVizitor nvarchar(50) output,
	--@CodeTafziliSuperVizor nvarchar(50) output,
	@bigMablaghPoorsantVizitor bigint output,
	@bigMablaghPoorsantSuperVizor bigint output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @CodeMoinHoghoogh nvarchar(10)

	execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output									


	set @CodeTafziliVizitor =(SELECT        fldCodeVasete
									FROM            dbo.tblRizeBargashtAzForoosh
										WHERE        (fldShomareSanad = @ShomareSanad) And fldRadif=1 )
	if @CodeTafziliVizitor is null
		set @CodeTafziliVizitor=-1

	set @bigMablaghPoorsantVizitor =(SELECT        fldBestankar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 2))))

	if @bigMablaghPoorsantVizitor is null
		set @bigMablaghPoorsantVizitor=0


	
	--set @CodeTafziliSuperVizor =(SELECT        fldCodeTafzili
	--								FROM            dbo.tblSodooreSanad
	--									WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
	--										(SELECT        fldCodeTafzili
	--											FROM            dbo.tblTafzili
	--											WHERE        (fldNoeVizitor = 1))))
	--if @CodeTafziliSuperVizor is null
	--	set @CodeTafziliSuperVizor=0


	set @bigMablaghPoorsantSuperVizor =(SELECT        fldBestankar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 1))))
	if @bigMablaghPoorsantSuperVizor is null
		set @bigMablaghPoorsantSuperVizor=0
END

GO
/****** Object:  StoredProcedure [dah].[LoadVaseteArshiveForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[LoadVaseteArshiveForoosh] 
	-- Add the parameters for the stored procedure here
	@ShomareSanad nvarchar(50),
	@CodeTafziliVizitor nvarchar(50) output,
	--@CodeTafziliSuperVizor nvarchar(50) output,
	@bigMablaghPoorsantVizitor bigint output,
	@bigMablaghPoorsantSuperVizor bigint output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @CodeMoinHoghoogh nvarchar(10)

	execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output									


	set @CodeTafziliVizitor =(SELECT        fldCodeVasete
									FROM            dbo.tblRizeForoosh
										WHERE        (fldShomareSanad = @ShomareSanad) And fldRadif=1 )
	if @CodeTafziliVizitor is null
		set @CodeTafziliVizitor=-1

	set @bigMablaghPoorsantVizitor =(SELECT        fldBedehkar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 2))))

	if @bigMablaghPoorsantVizitor is null
		set @bigMablaghPoorsantVizitor=0


	
	--set @CodeTafziliSuperVizor =(SELECT        fldCodeTafzili
	--								FROM            dbo.tblSodooreSanad
	--									WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
	--										(SELECT        fldCodeTafzili
	--											FROM            dbo.tblTafzili
	--											WHERE        (fldNoeVizitor = 1))))
	--if @CodeTafziliSuperVizor is null
	--	set @CodeTafziliSuperVizor=0


	set @bigMablaghPoorsantSuperVizor =(SELECT        fldBedehkar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 1))))
	if @bigMablaghPoorsantSuperVizor is null
		set @bigMablaghPoorsantSuperVizor=0
END

GO
/****** Object:  StoredProcedure [dah].[LoadVaseteArshiveSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[LoadVaseteArshiveSanad] 
	-- Add the parameters for the stored procedure here
	@ShomareSanad nvarchar(50),
	@CodeTafziliVizitor nvarchar(50) output,
	--@CodeTafziliSuperVizor nvarchar(50) output,
	@bigMablaghPoorsantVizitor bigint output,
	@bigMablaghPoorsantSuperVizor bigint output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @CodeMoinHoghoogh nvarchar(10)

	execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output									


	set @CodeTafziliVizitor =(SELECT        fldCodeTafzili
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 2))))
	if @CodeTafziliVizitor is null  -- برای حالتی که واریزی واسطه داره ولی پورسانت نداره
		begin
			set @CodeTafziliVizitor = (Select Top(1) fldVasete from tblSodooreSanad Where fldSanad=@ShomareSanad)
			if @CodeTafziliVizitor is null
				set @CodeTafziliVizitor=-1
		end

	set @bigMablaghPoorsantVizitor =(SELECT        fldBedehkar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 2))))

	if @bigMablaghPoorsantVizitor is null
		set @bigMablaghPoorsantVizitor=0


	
	--set @CodeTafziliSuperVizor =(SELECT        fldCodeTafzili
	--								FROM            dbo.tblSodooreSanad
	--									WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
	--										(SELECT        fldCodeTafzili
	--											FROM            dbo.tblTafzili
	--											WHERE        (fldNoeVizitor = 1))))
	--if @CodeTafziliSuperVizor is null
	--	set @CodeTafziliSuperVizor=0


	set @bigMablaghPoorsantSuperVizor =(SELECT        fldBedehkar
									FROM            dbo.tblSodooreSanad
										WHERE        (fldSanad = @ShomareSanad) AND (fldMoinKamel = @CodeMoinHoghoogh) AND (fldCodeTafzili IN
											(SELECT        fldCodeTafzili
												FROM            dbo.tblTafzili
												WHERE        (fldNoeVizitor = 1))))
	if @bigMablaghPoorsantSuperVizor is null
		set @bigMablaghPoorsantSuperVizor=0
END

GO
/****** Object:  StoredProcedure [dah].[LoadVizitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dah].[LoadVizitor]
	-- Add the parameters for the stored procedure here
	
	
AS
BEGIN
	update tblTafzili set fldNoeMohasebePoorsant=0  where fldNoeMohasebePoorsant is null
	select fldCodeTafzili , fldSharheTafzili,fldPoorsant,ID,fldNoeMohasebePoorsant,iif(fldNoeMohasebePoorsant=1,'فروش','واریز') as fldSharheMohasebe from tblTafzili Where fldCodeNoe='0' And fldNoeVizitor=2
END

GO
/****** Object:  StoredProcedure [dah].[MinMaxDateAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[MinMaxDateAnbar]
	@MinDate bigint output,
	@MaxDate bigint output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @tmp bigint
    -- Insert statements for procedure here
	set @MinDate = 0
	set @MaxDate = 0

	set @tmp = (Select Min(fldDate) from tblRizeKharid)
	if @tmp is not null
		set @MinDate =@tmp

	set @tmp = (Select Min(fldDate) from tblRizeForoosh)
	if @tmp is not null
		begin
			if @tmp<@MinDate
				begin
					set @MinDate =@tmp
				end

		end

	set @tmp = (Select Min(fldDate) from tblRizeBargashtAzKharid)
	if @tmp is not null
		begin
			if @tmp<@MinDate
				begin
					set @MinDate =@tmp
				end

		end

	set @tmp = (Select Min(fldDate) from tblRizeBargashtAzForoosh)
	if @tmp is not null
		begin
			if @tmp<@MinDate
				begin
					set @MinDate =@tmp
				end

		end
		

		--######MAX

	set @tmp = (Select Max(fldDate) from tblRizeKharid)
	if @tmp is not null
		set @MaxDate =@tmp

	set @tmp = (Select Max(fldDate) from tblRizeForoosh)
	if @tmp is not null
		begin
			if @tmp>@MaxDate
				begin
					set @MaxDate =@tmp
				end

		end

	set @tmp = (Select Max(fldDate) from tblRizeBargashtAzKharid)
	if @tmp is not null
		begin
			if @tmp>@MaxDate
				begin
					set @MaxDate =@tmp
				end

		end

	set @tmp = (Select Max(fldDate) from tblRizeBargashtAzForoosh)
	if @tmp is not null
		begin
			if @tmp>@MaxDate
				begin
					set @MaxDate =@tmp
				end

		end

END

GO
/****** Object:  StoredProcedure [dah].[NameKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dah].[NameKolMoin]
	@MoinKamel nvarchar(10),
	@strName nvarchar(50) output
AS
BEGIN

	set @strName =( Select fldSharheHesab from tblKolMoin Where fldCodeHesab=@MoinKamel) 

END

GO
/****** Object:  StoredProcedure [dah].[typeSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dah].[typeSanad] 
	-- Add the parameters for the stored procedure here
	@Sanad bigint,
	@strType nvarchar(20) output,
	@Shomare bigint output
AS
BEGIN
	declare @bigCount bigint


	--فروش
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblForoosh where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='foroosh'
			set @shomare = (select  fldShomareFactorForoosh  from tblForoosh where fldShomareSanad=@Sanad )
		end

	--خرید
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblKharid where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='kharid'
			set @shomare = (select  fldShomareFactorKharid  from tblKharid where fldShomareSanad=@Sanad )
		end

	--برگشت از فروش
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblBargashtAzForoosh where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='BargashtAzForoosh'
			set @shomare = (select  fldShomareFactorForoosh  from tblBargashtAzForoosh where fldShomareSanad=@Sanad )
		end

	--برگشت از خرید
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblBargashtAzKharid where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='BargashtAzKharid'
			set @shomare = (select  fldShomareFactorKharid  from tblBargashtAzKharid where fldShomareSanad=@Sanad )
		end

	--دریافت
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblDaryaft where fldShomareSanad=@Sanad And fldType='daryaft')
	if @bigCount>0
		begin
			set @strType='daryaft'
			set @shomare = (select  fldShomareDaryaft  from tblDaryaft where fldShomareSanad=@Sanad And fldType='daryaft')
		end

	--پرداخت
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblPardakht where fldShomareSanad=@Sanad And fldType='pardakht')
	if @bigCount>0
		begin
			set @strType='pardakht'
			set @shomare = (select  fldShomarePardakht  from tblPardakht where fldShomareSanad=@Sanad And fldType='pardakht')
		end
END

GO
/****** Object:  StoredProcedure [dah].[Update_SuperVizor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dah].[Update_SuperVizor] 
	@ID bigint,
	@fldPoorsant int,
	@fldSharheTafzili nvarchar(200),
	@fldNoeMohasebePoorsant int
AS
BEGIN
	update tblTafzili set fldSharheTafzili=@fldSharheTafzili,fldPoorsant=@fldPoorsant,
			fldNoeMohasebePoorsant=@fldNoeMohasebePoorsant
		where ID=@ID
		
	
END

GO
/****** Object:  StoredProcedure [dah].[Update_Vizitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dah].[Update_Vizitor] 
	@ID bigint,
	@fldPoorsant int,
	@fldSharheTafzili nvarchar(200),
	@fldNoeMohasebePoorsant int,
	@CodeSuperVisor nvarchar(10)
AS
BEGIN
	update tblTafzili set fldSharheTafzili=@fldSharheTafzili,fldPoorsant=@fldPoorsant,
			fldNoeMohasebePoorsant=@fldNoeMohasebePoorsant,fldCodeSuperVisor=@CodeSuperVisor
		where ID=@ID
		
	
END

GO
/****** Object:  StoredProcedure [dbo].[aaaa]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[aaaa]

@NameVahed nvarChar(70),
@mmm nvarchar(30),
@IDOutPut int outPut
as 

begin

	insert into tblTanzimatDynamic 
		values(@NameVahed,@mmm)	
	set @IDOutPut=@@IDENTITY
	
end

GO
/****** Object:  StoredProcedure [dbo].[AddRecordTanzimatForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[AddRecordTanzimatForoosh]
	       @fldKalaTekrary bit
	       ,@fldTypeInputKalaInGrid nvarchar(10)
           ,@fldAllowForooshKalaBishAzMojodi bit
           ,@fldShowMotalebatInFactorForoosh bit
           ,@fldForooshNaghdi bit
           ,@fldShowSodKala bit
           ,@fldShowSodFactor bit
           ,@fldEshantion bit
           ,@fldChandGheymate bit
           ,@fldArzeshAfzode decimal(18,0)
           ,@fldTedadChapInForoosh smallint
           ,@fldSearchNumberingInKala bit
           ,@fldBeginDateTakhfifat bigint
           ,@fldEndDateTakhfifat bigint
		   ,@intResult smallint output
AS
BEGIN
	begin transaction AddRecord
		begin try
		--Delete 
		delete from tblTanzimatForoosh
		--insert
			INSERT INTO [dbo].[tblTanzimatForoosh]
           ([fldKalaTekrary]
           ,[fldTypeInputKalaInGrid]
           ,[fldAllowForooshKalaBishAzMojodi]
           ,[fldShowMotalebatInFactorForoosh]
           ,[fldForooshNaghdi]
           ,[fldShowSodKala]
           ,[fldShowSodFactor]
           ,[fldEshantion]
           ,[fldChandGheymate]
           ,[fldArzeshAfzode]
           ,[fldTedadChapInForoosh]
           ,[fldSearchNumberingInKala]
           ,[fldBeginDateTakhfifat]
           ,[fldEndDateTakhfifat])
     VALUES
           (@fldKalaTekrary
	       ,@fldTypeInputKalaInGrid
           ,@fldAllowForooshKalaBishAzMojodi
           ,@fldShowMotalebatInFactorForoosh
           ,@fldForooshNaghdi
           ,@fldShowSodKala
           ,@fldShowSodFactor
           ,@fldEshantion
           ,@fldChandGheymate
           ,@fldArzeshAfzode
           ,@fldTedadChapInForoosh
           ,@fldSearchNumberingInKala
           ,@fldBeginDateTakhfifat
           ,@fldEndDateTakhfifat)
			set @intResult=1
			commit transaction AddRecord
		end try
		begin catch
			if @@TranCount>0
			begin
				set @intResult=0
				rollback transaction AddRecord;
			end
		end catch
END


GO
/****** Object:  StoredProcedure [dbo].[AmalkardBankInTblCheckPardakhti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[AmalkardBankInTblCheckPardakhti] 
	-- Add the parameters for the stored procedure here
	@CodeBank bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @intCount bigint

	set @intCount=(Select Count(fldCodeBank) from tblCheckePardakhti Where fldCodeBank=@CodeBank)
	if @intCount>0
		set @Amalkard='true'
	else
		set @Amalkard='false'
END

GO
/****** Object:  StoredProcedure [dbo].[AmalkardCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[AmalkardCheck] 
	-- Add the parameters for the stored procedure here
	@ShomareCheck bigint,
	@ShomareHesab bigint,	
	@ShomareDaryaft bigint,
	@Amalkard nvarchar(20) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @cnt bigint
    -- Insert statements for procedure here
	set @cnt= (Select count(fldSHomareCheck) from tblCheckeDaryafti Where fldShomareCheck=@ShomareCheck and fldShomareHesab=@ShomareHesab and fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)
	
	IF @cnt>0 
		set @Amalkard ='true'
	else
		begin			
			set @cnt= (Select count(fldSHomareCheck) from tblCheckeDaryafti Where fldShomareCheck=@ShomareCheck and fldShomareHesab=@ShomareHesab and fldShomareDaryaft=@ShomareDaryaft and (fldShomareVosool  is not null or fldShomarePardakht  is not null))
			if @cnt>0 
				set @Amalkard ='true'
			else
				set @Amalkard ='false'
		end
END

GO
/****** Object:  StoredProcedure [dbo].[AmalkardCheckForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[AmalkardCheckForoosh]
	-- Add the parameters for the stored procedure here
	@ShomareDaryaft bigint,
	@Amalkard nvarchar(15) output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @cnt bigint
    -- Insert statements for procedure here
	set @cnt= (Select count(fldSHomareCheck) from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)
	
	IF @cnt>0 
		set @Amalkard ='true'
	else
		begin			
			set @cnt= (Select count(fldSHomareCheck) from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and (fldShomareVosool  is not null or fldShomarePardakht  is not null))
			if @cnt>0 
				set @Amalkard ='true'
			else
				set @Amalkard ='false'
		end
END

GO
/****** Object:  StoredProcedure [dbo].[Az]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Az]
as
begin
	declare @str1 nvarchar(20)
	set @str1='(9,2)'
	Select * FROM tblCheckeDaryafti
		WHERE        (fldSanad NOT IN (@str1))
end

GO
/****** Object:  StoredProcedure [dbo].[bbbb]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[bbbb]
--@NameHesab nvarChar(50),
@Meghdar bigint OutPut


as

begin
	--set @Meghdar=1020
	Select *
		Into   #Temp
		From   tblSodooreSanad

		Declare @Id int,@Jam bigint
		set @Jam=0

		While (Select Count(*) From #Temp) > 0
		Begin

			Select Top 1 @Id = Id From #Temp

			--Do some processing here

			--Delete #Temp Where Id = @Id
			set @jam=@Jam+( Select fldBedehkar from #Temp Where Id = @Id)
		End
		set @Meghdar=@jam

end
GO
/****** Object:  StoredProcedure [dbo].[Check_AmalKard_IDGroupAshkhas_TblAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[Check_AmalKard_IDGroupAshkhas_TblAshkhas]
@fldGroupAshkhasId bigint,

@flagCheckIdInTblAshkhas int output  --چک کردن ای دی وارد شده ایا در عمکرد کالا سابقه دارد یا خیر new

as


begin
-------------------------------------------------------------------new 95-09-03
declare @hasRowInTblAshkhas int --new

set @hasRowInTblAshkhas=0 --new 
set @flagCheckIdInTblAshkhas=0 -- new 
set @hasRowInTblAshkhas=(select count(fldCodeGroup) from tblTafzili where fldCodeGroup=@fldGroupAshkhasId)-- new 
if (@hasRowInTblAshkhas >= 1) --new 
begin
set @flagCheckIdInTblAshkhas=1
return 
end 
------------------------------------------------------ new 95-09-03


			 
end


GO
/****** Object:  StoredProcedure [dbo].[Check_AmalKard_IDGroupKalaIN_TblKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[Check_AmalKard_IDGroupKalaIN_TblKala]
@fldGroupKalaId bigint,

@flagCheckIdInTblKala int output  --چک کردن ای دی وارد شده ایا در عمکرد کالا سابقه دارد یا خیر new

as


begin
-------------------------------------------------------------------new 95-09-03
declare @hasRowInTblKala int --new

set @hasRowInTblKala=0 --new 
set @flagCheckIdInTblKala=0 -- new 
set @hasRowInTblKala=(select count(fldCodeGroup) from tblKala where fldCodeGroup=@fldGroupKalaId)-- new 
if (@hasRowInTblKala >= 1) --new 
begin
set @flagCheckIdInTblKala=1
return 
end 
------------------------------------------------------ new 95-09-03


			 
end


GO
/****** Object:  StoredProcedure [dbo].[Check_AmlKard_CodeTafzili_For_Delete_In_Tbl_Tafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Check_AmlKard_CodeTafzili_For_Delete_In_Tbl_Tafzili]

@fldCodeTafzili	nvarchar(10),
@flagDelete_Tafzili int output	 
as
begin
declare @hasrowinSanad int

set @hasrowinSanad=(select count(fldCodeTafzili) from tblSodooreSanad  where fldCodeTafzili=@fldCodeTafzili)

if (@hasrowinSanad > 0)
begin
set @flagDelete_Tafzili=1
return
end
end

GO
/****** Object:  StoredProcedure [dbo].[Check_CodeTafzili_Delete_Tbl_Tafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Check_CodeTafzili_Delete_Tbl_Tafzili]
@fldCodeTafzili	nvarchar(10),
@flagDelete_Tafzili int output	 
as
begin
declare @hasrowinSanad int

set @hasrowinSanad=(select count(fldCodeTafzili) from tblSodooreSanad  where fldCodeTafzili=@fldCodeTafzili)

if (@hasrowinSanad > 0)
begin
set @flagDelete_Tafzili=1
return
end
end

GO
/****** Object:  StoredProcedure [dbo].[checkIdNumber_GruopAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[checkIdNumber_GruopAshkhas]
@LenidNumber nvarchar(20),
@idNumber nvarchar(20)
--@ReturnID bigint output
	
AS
BEGIN
	               select Max(fldGroupId) from tblGroupAshkhas
	               where LEN(convert(nvarchar(20),fldGroupId))=@LenidNumber
				   and   convert(nvarchar(20),fldGroupId) like @idNumber + '%'
     --Return @ReturnID
END

GO
/****** Object:  StoredProcedure [dbo].[checkIdNumber_GruopKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[checkIdNumber_GruopKala]
@LenidNumber nvarchar(20),
@idNumber nvarchar(20)
--@ReturnID bigint output
	
AS
BEGIN
	               select Max(fldGroupId) from tblGroupKala
	               where LEN(convert(nvarchar(20),fldGroupId))=@LenidNumber
				   and   convert(nvarchar(20),fldGroupId) like @idNumber + '%'
     --Return @ReturnID
END

GO
/****** Object:  StoredProcedure [dbo].[CodeKolHesab]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[CodeKolHesab]
@NameHesab nvarChar(50),
@Meghdar nvarChar(100) OutPut

as

begin
	if @NameHesab='bank' 
		begin
			set @Meghdar=(Select  fldCodeKolBank from tblTanzimat )
		end
	else if @NameHesab='sandoogh' 
		begin
			set @Meghdar=(Select  fldCodeKolSandoogh from tblTanzimat )
		end
	else if @NameHesab='check' 
		begin
			set @Meghdar=(Select  fldCodeKolCheck from tblTanzimat )
		end
	else if @NameHesab='checkpardakhti' 
		begin
			set @Meghdar=(Select  fldCodeKolCheckPardakhti from tblTanzimat )
		end
	else if @NameHesab='hesabhayedaryaftani' 
		begin
			set @Meghdar=(Select  fldCodeMoinHesabhayeDaryaftani from tblTanzimat )
		end		
	else if @NameHesab='kolhesabhayedaryaftani' 
		begin
			set @Meghdar=(Select  fldCodeKolHesabhayeDaryaftani from tblTanzimat )
		end	
	else if @NameHesab='kolhesabhayepardakhtani' 
		begin
			set @Meghdar=(Select  fldCodeKolHesabhayePardakhtani from tblTanzimat )
		end		
	else if @NameHesab='daramad' 
		begin
			set @Meghdar=(Select  fldCodeKolDaramad from tblTanzimat )
		end	
	else if @NameHesab='hazine' 
		begin
			set @Meghdar=(Select  fldCodeKolHazine from tblTanzimat )
		end	
	else if @NameHesab='sarmaye'
		begin
			set @Meghdar=(Select  fldKolSarmaye from tblTanzimat )
		end	

end
GO
/****** Object:  StoredProcedure [dbo].[CodeMoinHesab]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[CodeMoinHesab]
@NameHesab nvarChar(50),
@Meghdar nvarChar(100) OutPut

as

begin
	if @NameHesab='check' 
		begin
			set @Meghdar=(Select  fldCodeMoinCheck from tblTanzimat )
		end
	else if @NameHesab='checkpardakhti' 
		begin
			set @Meghdar=(Select  fldCodeMoinCheckPardakhti from tblTanzimat )
		end
	else if @NameHesab='takhfifatedaryaft' 
		begin
			set @Meghdar=(Select  fldCodeMoinTakhfifateDaryaft from tblTanzimat )								  
		end
	else if @NameHesab='hesabhayedaryaftani' 
		begin
			set @Meghdar=(Select  fldCodeMoinHesabhayeDaryaftani from tblTanzimat )
		end
	else if @NameHesab='hesabhayepardakhtani' 
		begin
			set @Meghdar=(Select  fldCodeMoinHesabhayePardakhtani from tblTanzimat )
		end
	else if @NameHesab='hesabhayepardakhtanipoorsant' 
		begin
			set @Meghdar=(Select  fldCodeMoinHesabhayePardakhtaniPoorsant from tblTanzimat )
		end		
	else if @NameHesab='takhfifatepardakht' 
		begin
			set @Meghdar=(Select  fldCodeMoinTakhfifatePardakht from tblTanzimat )								  
		end
	else if @NameHesab='daramad' 
		begin
			set @Meghdar=(Select  fldCodeMoinDaramad from tblTanzimat )								  
		end
	else if @NameHesab='foroosh'
		begin
			set @Meghdar=(Select  fldCodeMoinForoosh from tblTanzimat )		
		end 
	else if @NameHesab='bargashtazforoosh'
		begin
			set @Meghdar=(Select  fldCodeMoinBargashtAzForoosh from tblTanzimat )		
		end 		
	else if @NameHesab='hamlvanaghl'
		begin
			set @Meghdar=(Select  fldMoinDaramadeHamlVaNaghl from tblTanzimat )		
		end 
	else if @NameHesab='arzesheafzoode'
		begin
			set @Meghdar=(Select  fldMoinArzesheAfzoode from tblTanzimat )		
		end 
	else if @NameHesab='mojoodieebteda'
		begin
			set @Meghdar=(Select  fldMoinMojoodieEbteda from tblTanzimat )
		end	
	else if @NameHesab='arzesheafzoodekharid'
		begin
			set @Meghdar=(Select  fldMoinArzesheAfzoodeKharid from tblTanzimat )		
		end 
	else if @NameHesab='kharid'
		begin
			set @Meghdar=(Select  fldCodeMoinKharid from tblTanzimat )		
		end 
	else if @NameHesab='hazinehamlvanaghlekharid'
		begin
			set @Meghdar=(Select  fldCodeMoinHazineHamlVaNaghl from tblTanzimat )		
		end 
	else if @NameHesab='hoghoogh'
		begin
			set @Meghdar=(Select  fldCodeHoghoogh from tblTanzimat )		
		end 
end
GO
/****** Object:  StoredProcedure [dbo].[dastrasiUser]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[dastrasiUser] 
	@CodeUser bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	
	create  table #TempTable2(
		fldCodeUser bigint,
		fldUserName nvarchar(25) COLLATE Persian_100_CI_AS,
		fldCodeDastrasi bigint ,
		fldName nvarchar(150) COLLATE Persian_100_CI_AS,
		fldGroup bigint,
		fldOrder bigint,
		fldNameGroup nvarchar(20) COLLATE Persian_100_CI_AS,
		fldCheck int


	)

	insert into #TempTable2
		(fldCodeUser,fldCodeDastrasi,fldName,fldGroup,fldOrder,fldUserName,fldNameGroup,fldCheck)	
	SELECT        tblDastrasi.fldCodeUser, tblDastrasi.fldCodeDastrasi, tblListeDastrasi.fldName, tblListeDastrasi.fldGroup, tblListeDastrasi.fldOrder, tblSecurity.fldUser,tblListeDastrasi.fldNameGroup,1
		FROM            tblDastrasi INNER JOIN
								 tblSecurity ON tblDastrasi.fldCodeUser = tblSecurity.fldCode INNER JOIN
								 tblListeDastrasi ON tblDastrasi.fldCodeDastrasi = tblListeDastrasi.fldCode
										where tblDastrasi.fldCodeUser=@CodeUser


	insert into #TempTable2
		(fldCodeUser,fldCodeDastrasi,fldName,fldGroup,fldOrder,fldUserName,fldNameGroup, fldCheck)
		Select @CodeUser,fldCode,fldName,fldGroup,fldOrder,'',fldNamegroup, 0
			from tblListeDastrasi 
				Where fldCode not in (Select fldCodedastrasi from tblDastrasi Where fldCodeUser =@CodeUser)
		
		
		
			--SELECT        tblDastrasi.fldCodeUser, tblDastrasi.fldCodeDastrasi, tblListeDastrasi.fldName, tblListeDastrasi.fldGroup, tblListeDastrasi.fldOrder, tblSecurity.fldUser,0
			--FROM            tblDastrasi INNER JOIN
			--					 tblSecurity ON tblDastrasi.fldCodeUser = tblSecurity.fldCode INNER JOIN
			--					 tblListeDastrasi ON tblDastrasi.fldCodeDastrasi = tblListeDastrasi.fldCode
			--							where fldCodeDastrasi Not In (Select fldCodeDastrasi from tblDastrasi Where fldCodeUser=@CodeUser)
				

	select fldCodeUser, fldCodeDastrasi, fldName, fldGroup, fldOrder,fldNameGroup, fldCheck from #TempTable2

END
	

GO
/****** Object:  StoredProcedure [dbo].[DataMokhtalef]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[DataMokhtalef] 
@namedarkhast nvarchar(50),
@data nvarchar(50),
@Meghdarstring nvarchar(50) output

as

begin
	if @namedarkhast='nametafzili'
		begin
			set @Meghdarstring	 =	(select fldSharheTafzili from tblTafzili Where fldCodeTafzili=@data)
		end
end



GO
/****** Object:  StoredProcedure [dbo].[Date9Raghami]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Date9Raghami]

@DateSmall int,
@DateKamel int Output
as

begin	
	declare @strDateSmall varchar(10),@strDateKamel varchar(10)
	set @strDateSmall=convert(varchar,@DateSmall)
	set @strDateKamel='13' + @strDateSmall
	set @DateKamel=CONVERT(int,@strDateKamel)

end


GO
/****** Object:  StoredProcedure [dbo].[Delete_Tbl_DaftarcheTell]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Delete_Tbl_DaftarcheTell]
@fldIdTell	bigint,
@flagDelete int output	
as
begin


Delete  from tblDaftarcheTell
where fldIdDaftarche=@fldIdTell
set @flagDelete=1
end

GO
/****** Object:  StoredProcedure [dbo].[Delete_Tbl_Tafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Delete_Tbl_Tafzili]
@fldCodeTafzili	nvarchar(10),
@flagDelete_Tafzili int output	 
as
begin
declare @hasrowinSanad int

set @hasrowinSanad=(select count(fldCodeTafzili) from tblSodooreSanad  where fldCodeTafzili=@fldCodeTafzili)

if (@hasrowinSanad > 0)
begin
set @flagDelete_Tafzili=1
return
end
 
if(@hasrowinSanad=0)
begin

Delete from tblTafzili 
where fldCodeTafzili=convert(bigint,@fldCodeTafzili)

Delete  from tblDaftarcheTell
where fldCodeTafzili=CONVERT(bigint,@fldCodeTafzili)
set @flagDelete_Tafzili=0
end
end



GO
/****** Object:  StoredProcedure [dbo].[DeleteAllInfo]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeleteAllInfo] 
	-- Add the parameters for the stored procedure here
	@Anbar int,
	@Kala int,
	@DaftarcheTell int,
	@Ashkhas int,	
	@BankeMoshtari int
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	Delete from tblSodooreSanad
	delete from tblForoosh
	Delete from tblRizeForoosh
	delete from tblBargashtAzForoosh
	delete from tblRizeBargashtAzForoosh
	delete from tblKharid
	delete from tblRizeKharid
	delete from tblBargashtAzKharid
	delete from tblRizeBargashtAzKharid
	delete from tblCheckeDaryafti
	delete from tblCheckePardakhti
	delete from tblDaryaft
	delete from tblPardakht
	delete from DasteCheck
	delete from tblFish
	delete from tblPas
	delete from tblPrinters
	delete from tblRizePishPishForoosh
	delete from tblVosool

	if @Anbar=1 
		Delete from tblAnbar Where fldCode<>1000

	if @Kala=1 
		begin
			delete from tblKala 
			delete from tblEshantionTabaghati
			delete from tblEshantionTekrarShavande
			delete from tblGroupKala Where fldGroupId<>100 
			delete from tblFee
			delete from tblImageKala
		end

	if @DaftarcheTell=1 
		begin
			delete tblDaftarcheTell where fldCodeTafzili=0	
		end

	if @Ashkhas=1
		begin
			delete from tblTafzili Where fldCodeTafzili<>10000
			delete from tblGroupAshkhas Where fldGroupId<>100 and fldGroupId<>101
			delete from tblListPorsantVaset
			if @DaftarcheTell=1 
				Delete  tblDaftarcheTell 
			else
				update tblDaftarcheTell set fldCodeTafzili=0
		end

	if @BankeMoshtari=1
		delete from tblBankeMoshtari

END

GO
/****** Object:  StoredProcedure [dbo].[DeleteChapgar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeleteChapgar]
	-- Add the parameters for the stored procedure here
	@IDPrinter bigint,
	@strResult nvarchar(30) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	declare @bigCount bigint
	set @bigCount = (Select Count(fldIDPrinter)  from tblKala where fldIDPrinter=@IDPrinter)
	
	if @bigCount>0 
		set @strResult ='amalkard'
	else
		begin
			Delete from tblPrinters Where id=@IDPrinter
			set @strResult ='delete'
		end

END

GO
/****** Object:  StoredProcedure [dbo].[DeleteDaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[DeleteDaryaft]

@ShomareDaryaft bigint,
@NoeKhata nvarchar(30) output

as

begin
	begin transaction transact
		begin try
			declare @ShomareSanad nvarchar(50)
			set @ShomareSanad =(Select fldShomareSanad from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
			delete from tblDaryaft Where fldShomareSanad=@shomareSanad	
			delete from tblSodooreSanad Where fldSanad=@shomareSanad
			delete from tblCheckeDaryafti Where fldSanad=@shomareSanad		
			delete from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft	

			set @NoeKhata='deleteok'
	commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[DeleteDasteCheck]
@Serial bigint,
@CodeBank bigint
as

begin
	Delete from tblDasteCheck Where fldShomareCheck=@serial and fldCodeBank=@CodeBank
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorbARGASHTaZForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[DeleteFactorbARGASHTaZForoosh]
   @fldShomareSanad bigint,
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					declare @ShomarePardakht as bigint

					delete from tblRizeBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad and fldShomareFactorForoosh=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedForoosh'
										rollback transaction DelRecord;
									end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										rollback transaction DelRecord;
									end

					--#############################
					--خودم اضافه کردم
					set @ShomarePardakht =(Select fldShomarePardakht from tblPardakht
												where fldShomareSanad=@fldShomareSanad)
					--#############################

					delete from tblPardakht
						where fldShomareSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblDaryaft'
							--		rollback transaction DelRecord;
							--	end

					--#############################
					--خودم اضافه کردم
					delete from tblCheckePardakhti
						where fldSanad=@fldShomareSanad
					
					update tblCheckeDaryafti
						set fldShomarePardakht = NULL
						where fldShomarePardakht=@ShomarePardakht
					--##############################

							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblCheckeDaryafti'
							--		rollback transaction DelRecord;
							--	end
					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorbargashtazkharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--کامل نیست  (واگذاری چک تعیین نشده)
CREATE  PROCEDURE [dbo].[DeleteFactorbargashtazkharid]
   @fldShomareSanad bigint,
   @fldShomareFactor bigint,
   @CheckeVagozari tblCheckVagozari  readonly,
   @ShomarePardakht bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizebargashtazkharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeBargashtAzKharid'
										rollback transaction DelRecord;
								end
					delete from tblbargashtazkharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactorKharid=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedBargashtAzKharid'
										rollback transaction DelRecord;
									end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										rollback transaction DelRecord;
									end
					delete from tblDaryaft
						where fldShomareSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblDaryaft'
							--		rollback transaction DelRecord;
							--	end
					delete from tblCheckeDaryafti
						where fldSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblCheckeDaryafti'
							--		rollback transaction DelRecord;
							--	end
					



					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[DeleteFactorForoosh]
   @fldShomareSanad bigint,
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizeForoosh
						where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblForoosh
						where fldShomareSanad=@fldShomareSanad and fldShomareFactorForoosh=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedForoosh'
										rollback transaction DelRecord;
									end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										rollback transaction DelRecord;
									end
					delete from tblDaryaft
						where fldShomareSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblDaryaft'
							--		rollback transaction DelRecord;
							--	end
					delete from tblCheckeDaryafti
						where fldSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblCheckeDaryafti'
							--		rollback transaction DelRecord;
							--	end
					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--کامل نیست  (واگذاری چک تعیین نشده)
CREATE  PROCEDURE [dbo].[DeleteFactorKharid]
   @fldShomareSanad bigint,
   @fldShomareFactor bigint,
   @CheckeVagozari tblCheckVagozari  readonly,
   @ShomarePardakht bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizeKharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeKharid'
										rollback transaction DelRecord;
								end
					delete from tblKharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactorKharid=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedKharid'
										rollback transaction DelRecord;
									end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										rollback transaction DelRecord;
									end
					delete from tblPardakht
						where fldShomareSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblDaryaft'
							--		rollback transaction DelRecord;
							--	end
					delete from tblCheckePardakhti
						where fldSanad=@fldShomareSanad
							--IF @@ROWCOUNT = 0  
							--	begin
							--		set @strResult='NotDeletedtblCheckeDaryafti'
							--		rollback transaction DelRecord;
							--	end

					UPDATE tblCheckeDaryafti Set fldShomarePardakht=NULL Where fldShomarePardakht=@ShomarePardakht 



					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[DeleteFactorPishForoosh]   
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizePishForoosh
						where  fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblPishForoosh
						where  fldShomareFactorForoosh=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedForoosh'
										rollback transaction DelRecord;
									end															
					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFactorPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create  PROCEDURE [dbo].[DeleteFactorPishPishForoosh]   
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizePishPishForoosh
						where  fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblPishPishForoosh
						where  fldShomareFactorForoosh=@fldShomareFactor
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedForoosh'
										rollback transaction DelRecord;
									end															
					set @strResult='deleted'
					commit transaction DelRecord;
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction DelRecord;
			end
		end catch
   
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteFullKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteFullKala]
	@IdKalaForoosh bigint,
	@fldResult int output
AS
BEGIN
	begin transaction transact
		begin try
			delete from tblKala
				where fldCodeKala=@IdKalaForoosh
			delete from tblEshantionTabaghati 
				where fldCodeKalaForoosh=@IdKalaForoosh
		    delete from tblEshantionTekrarshavande
				where fldCodeKalaForoosh=@IdKalaForoosh
		    delete from tblFee 
				where fldCodeKala=@IdKalaForoosh

			delete tblImageKala Where fldCodeKala = @IdKalaForoosh

			set @fldResult=1
	commit transaction
		end try

	begin catch
		if @@trancount>0 
			rollback transaction ;
			set @fldResult=0

	end catch


END

GO
/****** Object:  StoredProcedure [dbo].[DeleteGroupAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteGroupAshkhas]
@fldGroupAshkhasId bigint,
@res int output,
@flagCheckIdInTblAshkhas int output
	
AS
set @flagCheckIdInTblAshkhas=0
declare @hasrow int
declare @hasrowin_tblAshkhas int

BEGIN
set @hasrowin_tblAshkhas=(select count(fldCodeGroup) from tblTafzili where fldCodeGroup=@fldGroupAshkhasId)
if (@hasrowin_tblAshkhas >=1) 
begin
set @flagCheckIdInTblAshkhas=1
return 
end

set @hasrow=(select count(fldGroupId) from tblGroupAshkhas where CONVERT(nvarchar(50),fldGroupId) like CONVERT(nvarchar(50), @fldGroupAshkhasId) + '%')
if @hasrow > 1
begin

set @res=1


end
else
begin
set @res=0
delete from tblGroupAshkhas
where fldGroupId=@fldGroupAshkhasId
  end
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteGroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteGroupKala]
@fldGroupKalaId bigint,
@res int output,
@flagCheckIdInTblKala int output
	
AS
set @flagCheckIdInTblKala=0
declare @hasrow int
declare @hasrowin_tblKala int

BEGIN
set @hasrowin_tblKala=(select count(fldCodeGroup) from tblKala where fldCodeGroup=@fldGroupKalaId)
if (@hasrowin_tblKala >=1) 
begin
set @flagCheckIdInTblKala=1
return 
end

set @hasrow=(select count(fldGroupId) from tblGroupKala where CONVERT(nvarchar(50),fldGroupId) like CONVERT(nvarchar(50), @fldGroupKalaId) + '%')
if @hasrow > 1
begin

set @res=1


end
else
begin
set @res=0
delete from tblGroupKala
where fldGroupId=@fldGroupKalaId
  end
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteInfo_Ebteda_Doreh_Ashkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteInfo_Ebteda_Doreh_Ashkhas] 
@fldShomareSanad bigint,
@strResult varchar(25) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @HasRow int
	set @HasRow=0
	set @HasRow=(select count(fldSanad) from tblSodooreSanad where fldSanad=@fldShomareSanad And fldType='EbtedaAshkhas')
    -- Insert statements for procedure here
	If @HasRow > 0 
	 Begin
		Delete from tblSodooreSanad where fldSanad=@fldShomareSanad And fldType='EbtedaAshkhas'
		
		set @strResult='Delete Is OK'
     End
	Else
	 Begin
	    set @strResult='Delete Is Error'
	 End
	
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteInfo_MojodiEbteda_Doreh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteInfo_MojodiEbteda_Doreh] 
@fldShomareSanad bigint,
@strResult varchar(25) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @HasRow int
	set @HasRow=0
	set @HasRow=(select count(fldSanad) from tblSodooreSanad where fldSanad=@fldShomareSanad )
    -- Insert statements for procedure here
	If @HasRow > 0 
	 Begin
		Delete from tblSodooreSanad where fldSanad=@fldShomareSanad And fldType='mojoodieebteda'
		Delete from tblRizeKharid where fldShomareSanad=@fldShomareSanad And fldType='mojodi_ebteda_doreh'
		set @strResult='Delete Is OK'
     End
	Else
	 Begin
	    set @strResult='Delete Is Error'
	 End
	
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteInfoEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteInfoEnteghal] 
	-- Add the parameters for the stored procedure here
	@fldShomareEnteghal bigint,
	@strResult nvarchar(25) output
  
AS
BEGIN
	
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	delete from tblRizeForoosh where fldShomareEnteghal=@fldShomareEnteghal and fldType='enteghal'
    delete from tblRizeKharid where fldShomareEnteghal=@fldShomareEnteghal and fldType='enteghal'

END

GO
/****** Object:  StoredProcedure [dbo].[DeleteInfoKhabanidanCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[DeleteInfoKhabanidanCheck] 
@fldIdCheck bigint,
@Result nvarchar(50) output
    
AS
BEGIN
	
	SET NOCOUNT ON;

   UPDATE [dbo].[tblCheckeDaryafti]
   SET 
     fldDateVagozariBeBank=Null, 
     fldTozihateVagozariBeBank=Null,
     fldVaziat =Null,
     fldCodeBankVagozari=Null 
    
 WHERE ID=@fldIdCheck 
    set @Result='DeleteOK'
	
END
GO
/****** Object:  StoredProcedure [dbo].[DeleteInfoVosoolCheck_Final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteInfoVosoolCheck_Final] 
@fldShomareVosool bigint,
@strResult nvarchar(25) output
as            
BEGIN
	
	SET NOCOUNT ON;                                                                                          
declare @StrShomareSanadVosool1 nvarchar(20);
set @StrShomareSanadVosool1=(select fldShomareSanad from tblVosool where fldShomareVosool=@fldShomareVosool)
delete from tblSodooreSanad where fldSanad=@StrShomareSanadVosool1 
delete from tblVosool where fldShomareVosool=@fldShomareVosool 
						 
	-- /update tblchkDaryafti Reset For Update
	update tblCheckeDaryafti 
	set fldShomareVosool=NULL,
	fldDateVosool=NULL,
	fldTozihateVosool=NULL,
	fldVaziat=NULL,
	fldSanadVosool=NULL,
	fldCodeHesabeVosool=NULL
	where fldShomareVosool=@fldShomareVosool 

  
		----///
		--baraye halati ke check be bank vagozar shode					
		update tblCheckeDaryafti 
			set fldShomareVosool=NULL,
			fldDateVosool=NULL,
			fldTozihateVosool=NULL,
			fldVaziat='vagozari',
			fldSanadVosool=NULL,
			fldCodeHesabeVosool=NULL
			where fldShomareVosool=@fldShomareVosool and fldDateVagozariBeBank IS not NULL
		----///

END

GO
/****** Object:  StoredProcedure [dbo].[DeletePardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[DeletePardakht]

@ShomarePardakht bigint,
@NoeKhata nvarchar(30) output

as

begin
	begin transaction transact
		begin try
			declare @ShomareSanad nvarchar(50)
			set @ShomareSanad =(Select fldShomareSanad from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
			delete from tblPardakht Where fldShomareSanad=@shomareSanad	
			delete from tblSodooreSanad Where fldSanad=@shomareSanad
			delete from tblCheckePardakhti Where fldSanad=@shomareSanad			
			UPDATE tblCheckeDaryafti Set fldShomarePardakht=NULL Where fldShomarePardakht=@ShomarePardakht 
			set @NoeKhata='deleteok'
	commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
end
GO
/****** Object:  StoredProcedure [dbo].[DeletePaseCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeletePaseCheck] 
	-- Add the parameters for the stored procedure here
	@fldShomarePas bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @ShomareSanad bigint

	set @ShomareSanad =(Select top(1) fldSanadPas  from tblCheckePardakhti Where fldShomarePass=@fldShomarePas)
	UPDATE       tblCheckePardakhti
		SET         																					
			fldShomarePass=NULL,
			fldDatePass =NULL,
			fldSharhePass =NULL,
			fldSanadPas =NUll																	
			where fldShomarePass=@fldShomarePas

	
	delete from tblSodooreSanad Where fldSanad=@ShomareSanad
	delete from tblPas Where fldShomarePas=@fldShomarePas
							
END

GO
/****** Object:  StoredProcedure [dbo].[DeleteTblAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc  [dbo].[DeleteTblAnbar]
@ID as int

as
begin
Delete from tblAnbar Where ID=@ID
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteTblBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc  [dbo].[DeleteTblBankeMoshtari]
@ID as int

as
begin
Delete from tblBankeMoshtari Where ID=@ID
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteTblKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc  [dbo].[DeleteTblKolMoin]
@ID as int

as
begin
Delete from tblKolMoin Where ID=@ID
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteTblVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc  [dbo].[DeleteTblVahed]
@ID as int

as
begin
Delete from tblVahed Where ID=@ID
end
GO
/****** Object:  StoredProcedure [dbo].[DeleteUser]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[DeleteUser] 
	-- Add the parameters for the stored procedure here
	@Code bigint,
	@NoeKhata nvarchar(10) output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	
	begin transaction transact
		begin try
			declare @mmm bigint
			Delete from tblSecurity Where fldCode=@Code
			execute InsertDastrasi @Code,0,2

			delete from tblDastrasiSandoogh Where fldCodeUser=@Code

			
		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
		
END

GO
/****** Object:  StoredProcedure [dbo].[ehsan2]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ehsan2]
@idget bigint,
@r bigint output
as

insert into tbl2(name) values(convert(nvarchar,@idget))
set @r=@@identity
GO
/****** Object:  StoredProcedure [dbo].[ehsantest]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE  proc [dbo].[ehsantest]
@result bigint output

as

insert into tbl2(name) values('ehsan')
set @result=@@identity

GO
/****** Object:  StoredProcedure [dbo].[ExistCodeAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ExistCodeAnbar]
@CodeAnbar bigint

AS
BEGIN
	select fldCode from tblAnbar
	where fldCode=@CodeAnbar
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ExistFactorBargashtAzForoosh]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorForoosh  from tblBargashtAzForoosh where fldShomareFactorForoosh=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[ExistFactorBargashtAzKharid]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorKharid  from tblBargashtAzKharid where fldShomareFactorKharid=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ExistFactorForoosh]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorForoosh  from tblForoosh where fldShomareFactorForoosh=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[ExistFactorKharid]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorKharid  from tblKharid where fldShomareFactorKharid=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[ExistFactorPishForoosh]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorForoosh  from tblPishForoosh where fldShomareFactorForoosh=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistFactorPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[ExistFactorPishPishForoosh]
	@fldShomareFactor bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareFactorForoosh  from tblPishPishForoosh where fldShomareFactorForoosh=@fldShomareFactor)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[ExistShomareEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[ExistShomareEnteghal]
	@fldShomareHavale bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareEnteghal  from tblRizeForoosh where fldShomareEnteghal=@fldShomareHavale)
	if @fldMax is null
		set @fldMax=0
	
END
GO
/****** Object:  StoredProcedure [dbo].[ExistShomareVosool]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ExistShomareVosool]
	@fldShomareVosool bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareVosool  from tblVosool where fldShomareVosool=@fldShomareVosool)
	if @fldMax is null
		set @fldMax=0
	
END

GO
/****** Object:  StoredProcedure [dbo].[Fillter_tbl_DaftarcheTell_ByName_ByTell_NotHas_CodeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Fillter_tbl_DaftarcheTell_ByName_ByTell_NotHas_CodeTafzili]
@itemSearch_name_or_Tell nvarchar(45),
@flagFillter int
as
if (@flagFillter=0)
begin
select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh  from tblDaftarcheTell 
where  fldShomare Like '%' +  @itemSearch_name_or_Tell  + '%' 
end
else if (@flagFillter=1)
begin
select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh  from tblDaftarcheTell 
where fldName  Like '%' +  @itemSearch_name_or_Tell  + '%' 
end

GO
/****** Object:  StoredProcedure [dbo].[Filter_Tbl_Tafsili_in_Form_Enteghal_Kala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[Filter_Tbl_Tafsili_in_Form_Enteghal_Kala]
@codeTafzili nvarchar(20),
@flagSearch int
as
begin
if (@flagSearch=0)
   begin
            SELECT DISTINCT fldCodeTafzili, fldSharheTafzili
               
				
            FROM            dbo.tblTafzili

            where fldCodeTafzili like '%' + @codeTafzili + '%'
       end

 else if (@flagSearch=1)
 begin
            SELECT DISTINCT fldCodeTafzili,fldSharheTafzili
				
            FROM            dbo.tblTafzili

		    where fldSharheTafzili like '%' + @codeTafzili + '%'

 end
end
GO
/****** Object:  StoredProcedure [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]
@codeTafzili nvarchar(20),
@flagSearch int
as
begin
if (@flagSearch=0)
   begin
            SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldSharheTafzili,fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar 
				
            FROM            dbo.tblTafzili

            where fldCodeTafzili like '%' + @codeTafzili + '%'
       end

 else if (@flagSearch=1)
 begin
            SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldSharheTafzili,fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar 
				
            FROM            dbo.tblTafzili

		    where fldSharheTafzili like '%' + @codeTafzili + '%'

 end
end

GO
/****** Object:  StoredProcedure [dbo].[FilterByCodeAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[FilterByCodeAnbar]
@fldCodeAnbar bigint
AS
BEGIN
	select fldCode,fldNameAnbar from tblAnbar
	where convert(nvarchar(50),fldCode) like '%'+convert(nvarchar(50),@fldCodeAnbar)+'%'
END

GO
/****** Object:  StoredProcedure [dbo].[FilterByNameAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[FilterByNameAnbar]
@fldNameAnbar nvarchar(50)

AS
BEGIN
	select fldCode,fldNameAnbar from tblAnbar
	where fldNameAnbar like '%'+@fldNameAnbar+'%'
END

GO
/****** Object:  StoredProcedure [dbo].[FilterDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[FilterDasteCheck]
@ShomareCheck nvarchar(50)
--@CodeBank int
as

begin
	--SELECT        tblDasteCheck.fldCodeBank as fldCodeBank, tblDasteCheck.fldShobe as fldShobe, tblDasteCheck.fldShomareCheck as fldShomareCheck, tblDasteCheck.fldShomareHesab as fldShomareHesab, tblKolMoin.fldSharheHesab as fldNameBank
	--	FROM            tblDasteCheck INNER JOIN
	--							 tblKolMoin ON tblDasteCheck.fldCodeBank = tblKolMoin.fldCodeHesab
	--	WHERE        (Convert(nvarchar,tblDasteCheck.fldShomareCheck) LIKE '%' +@ShomareCheck + '%')
	--	order by fldNameBank,fldShomareCheck
	--if @CodeBank=0 
	--	begin
			--SELECT        fldCodeBank, fldShobe, fldShomareCheck, fldShomareHesab, fldNameBank
			--	FROM            (SELECT        tblDasteCheck.fldCodeBank, tblDasteCheck.fldShobe, tblDasteCheck.fldShomareCheck, tblDasteCheck.fldShomareHesab, 
			--														tblKolMoin.fldSharheHesab AS fldNameBank
			--							   FROM            tblDasteCheck INNER JOIN
			--														tblKolMoin ON tblDasteCheck.fldCodeBank = tblKolMoin.fldCodeHesab
			--							   WHERE        (CONVERT(nvarchar, tblDasteCheck.fldShomareCheck) LIKE '%' +  +@ShomareCheck + + '%')) AS tbl1
			--	WHERE        (NOT (fldCodeBank =@codeBank)) OR
			--							 (NOT (fldShomareCheck = @ShomareCheck))
			--	ORDER BY fldNameBank, fldShomareCheck
				SELECT        fldCodeBank, fldShobe, fldShomareCheck, fldShomareHesab, fldNameBank
				FROM            (SELECT        tblDasteCheck.fldCodeBank, tblDasteCheck.fldShobe, tblDasteCheck.fldShomareCheck, tblDasteCheck.fldShomareHesab, 
																	tblKolMoin.fldSharheHesab AS fldNameBank
										   FROM            tblDasteCheck INNER JOIN
																	tblKolMoin ON tblDasteCheck.fldCodeBank = tblKolMoin.fldCodeHesab
										   WHERE        (CONVERT(nvarchar, tblDasteCheck.fldShomareCheck) LIKE '' + @ShomareCheck + '%')) AS tbl1
				WHERE        ((CONVERT(nvarchar, fldCodeBank) + CONVERT(nvarchar, fldShomareCheck)) NOT IN
											 (SELECT        CONVERT(nvarchar, fldCodeBank) + CONVERT(nvarchar, fldShomareCheck) AS Expr1
												FROM            tblCheckePardakhti))
				ORDER BY fldNameBank, fldShomareCheck
			--end
	--else if @CodeBank>0 
	--	begin
	--		SELECT        fldCodeBank, fldShobe, fldShomareCheck, fldShomareHesab, fldNameBank
	--			FROM            (SELECT        tblDasteCheck.fldCodeBank, tblDasteCheck.fldShobe, tblDasteCheck.fldShomareCheck, tblDasteCheck.fldShomareHesab, 
	--																tblKolMoin.fldSharheHesab AS fldNameBank
	--									   FROM            tblDasteCheck INNER JOIN
	--																tblKolMoin ON tblDasteCheck.fldCodeBank = tblKolMoin.fldCodeHesab
	--									   WHERE        (CONVERT(nvarchar, tblDasteCheck.fldShomareCheck) LIKE '%' +  +@ShomareCheck + + '%')) AS tbl1
	--			WHERE        (NOT (fldCodeBank =@codeBank)) OR
	--									 (NOT (fldShomareCheck = @ShomareCheck))
	--			ORDER BY fldNameBank, fldShomareCheck
	--		end
	--	end
end
GO
/****** Object:  StoredProcedure [dbo].[FindMaxCodeGroupAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[FindMaxCodeGroupAshkhas](@id nvarchar(50))
AS
BEGIN
if(len(@id)=3)
begin
	select max(fldGroupId) from tblGroupAshkhas
	where len(fldGroupId)=3 
	
end
else if(len(@id)>=6)
begin
declare @idSub nvarchar(50)

set @idSub=SUBSTRING(@id,0,4)
	select max(fldGroupId) from tblGroupAshkhas
	where len(fldGroupId)=len(@id)
	and convert(nvarchar,fldGroupId) like @idSub +'%'
end
END

GO
/****** Object:  StoredProcedure [dbo].[FindMaxCodeGroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[FindMaxCodeGroupKala](@id nvarchar(50))
AS
BEGIN
if(len(@id)=3)
begin
	select max(fldGroupId) from tblGroupKala
	where len(fldGroupId)=3 
	--and @id like +'%'
end
else if(len(@id)>=6)
begin
declare @idSub nvarchar(50)

set @idSub=SUBSTRING(@id,0,4)
	select max(fldGroupId) from tblGroupKala
	where len(fldGroupId)=len(@id)
	and convert(nvarchar,fldGroupId) like @idSub +'%'
end
END

GO
/****** Object:  StoredProcedure [dbo].[GetCodeVahedByName]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetCodeVahedByName]
@strNameVahed nvarchar(50),
@lngCodeVahed bigint output
AS
BEGIN

	set @lngCodeVahed=( SELECT Id from tblVahed
	where fldNameVahed = N''+@strNameVahed+'')

	if @lngCodeVahed is null
		set @lngCodeVahed=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetCodeVaseteByCodeTafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetCodeVaseteByCodeTafsili]
	@strCodeTafsili nvarchar(25),
	@strCodeVasete nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	--set  @strCodeVasete=(SELECT        dbo.tblTafzili.fldVisitor
	--			FROM            dbo.tblTafzili INNER JOIN
	--									 dbo.tblGroupAshkhas ON dbo.tblTafzili.fldVisitor = dbo.tblGroupAshkhas.fldGroupId
	--			WHERE        (dbo.tblTafzili.fldCodeTafzili = @strCodeTafsili)
	--			       )

	set  @strCodeVasete  = (Select fldVisitor from tblTafzili Where fldCodeTafzili = @strCodeTafsili)
	set @strCodeVasete= ISNULL(@strCodeVasete,'0')	
END

GO
/****** Object:  StoredProcedure [dbo].[GetfldTedadInYekCarton]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetfldTedadInYekCarton]
	@fldCodeKala bigint,
	@fldValue bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldValue=(	SELECT        fldTedadJoz AS fldTedadInYekCarton
		FROM            dbo.tblKala
		where fldCodeKala=@fldCodeKala)
		if @fldValue is null or @fldValue = ''
			set @fldValue=0


END

GO
/****** Object:  StoredProcedure [dbo].[GetGhymatMasrafkonande]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE  PROCEDURE [dbo].[GetGhymatMasrafkonande]
@lngCodeKala bigint,
@decPrice decimal output
AS
BEGIN
	
		set @decPrice=(select isnull(fldGhymatMasrafkonande,0) from tblKala 
		where fldCodeKala=@lngCodeKala)
		
END

GO
/****** Object:  StoredProcedure [dbo].[GetInfoKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetInfoKala]
@CodeKala bigint
AS
BEGIN

	SELECT         ID, fldNameKala, fldCodeKala, fldSerial, fldCodeGroup, fldCodeVahed1, fldCodeVahed2, fldNogheSefaresh, fldSharh, fldTedadJoz, fldFeeDarsadKharid, 
                         fldFeeBadAzTakhfif, fldNerkhePorsantKol, fldNerkhePorsantJoz, fldFeeForoosh, fldPathPic, fldGhymatMasrafkonande
		FROM            dbo.tblKala
		Where fldCodeKala=@CodeKala

END

GO
/****** Object:  StoredProcedure [dbo].[GetListFullInfoKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[GetListFullInfoKala]
@fldCodeKala bigint
AS
SELECT        dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldSerial, dbo.tblKala.fldCodeGroup, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldSharh, dbo.tblKala.fldTedadJoz, dbo.tblKala.fldFeeBadAzTakhfif, 
                         dbo.tblKala.fldFeeDarsadKharid, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz, dbo.tblKala.fldPathPic
FROM            dbo.tblKala INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed1 = dbo.tblVahed.ID INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID
where dbo.tblKala.fldCodeKala =@fldCodeKala
GO
/****** Object:  StoredProcedure [dbo].[GetListMultiPrice]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetListMultiPrice]
	@lngCodeKala bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
		select fldName,convert(dec,fldFee) as fldFee from tblFee
			where fldCodeKala=@lngCodeKala
END

GO
/****** Object:  StoredProcedure [dbo].[GetMablaghHamloNaghl]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetMablaghHamloNaghl]

 @fldSanad bigint,
 @fldMablagh bigint output

AS
BEGIN

	SET NOCOUNT ON;
		declare  @fldCodeHamloNaghl bigint
		set @fldCodeHamloNaghl=(select dbo.tblTanzimat.fldMoinDaramadeHamlVaNaghl from tblTanzimat)
	set @fldMablagh=	(SELECT        fldBestankar
		FROM            tblSodooreSanad
		WHERE        (fldSanad = @fldSanad) AND (fldMoinKamel = CONVERT(nvarchar(10),@fldCodeHamloNaghl)))
		if (@fldMablagh is null)
			set @fldMablagh=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetMablaghHamloNaghlBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMablaghHamloNaghlBargashtAzKharid]

 @fldSanad bigint,
 @fldMablagh bigint output

AS
BEGIN

	SET NOCOUNT ON;
		declare  @fldCodeHamloNaghl bigint
		set @fldCodeHamloNaghl=(select dbo.tblTanzimat.fldCodeMoinHazineHamlVaNaghl from tblTanzimat)
	set @fldMablagh=	(SELECT        fldBestankar
		FROM            tblSodooreSanad
		WHERE        (fldSanad = @fldSanad) AND (fldMoinKamel = CONVERT(nvarchar(10),@fldCodeHamloNaghl)))
		if (@fldMablagh is null)
			set @fldMablagh=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetMablaghHamloNaghlKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetMablaghHamloNaghlKharid]

 @fldSanad bigint,
 @fldMablagh bigint output

AS
BEGIN

	SET NOCOUNT ON;
		declare  @fldCodeHamloNaghl bigint
		set @fldCodeHamloNaghl=(select dbo.tblTanzimat.fldCodeMoinHazineHamlVaNaghl from tblTanzimat)
	set @fldMablagh=	(SELECT        fldBedehkar
		FROM            tblSodooreSanad
		WHERE        (fldSanad = @fldSanad) AND (fldMoinKamel = CONVERT(nvarchar(10),@fldCodeHamloNaghl)))
		if (@fldMablagh is null)
			set @fldMablagh=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[GetMaxShomareEnteghal]
	@fldMax bigint output
AS
BEGIN
	
	set @fldMax=( SELECT isnull(max(fldShomareEnteghal),0) as fldMax from tblRizeForoosh)
END
GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMaxShomareFactorBargashtAzForoosh]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactorForoosh),0) as fldMax from tblBargashtAzForoosh)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMaxShomareFactorBargashtAzKharid]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactor),0) as fldMax from tblRizeBargashtAzKharid)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetMaxShomareFactorForoosh]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactorForoosh),0) as fldMax from tblForoosh)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMaxShomareFactorKharid]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactor),0) as fldMax from tblRizeKharid)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetMaxShomareFactorPishForoosh]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactorForoosh),0) as fldMax from tblPishForoosh)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomareFactorPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMaxShomareFactorPishPishForoosh]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactorForoosh),0) as fldMax from tblPishPishForoosh)
END

GO
/****** Object:  StoredProcedure [dbo].[GetMaxShomarePishFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetMaxShomarePishFactorForoosh]
	@fldMax bigint output
AS
BEGIN
	SET NOCOUNT ON;
	set @fldMax=( SELECT isnull(max(fldShomareFactorForoosh),0) as fldMax from tblPishForoosh)
END

GO
/****** Object:  StoredProcedure [dbo].[GetNameGroupByCodeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetNameGroupByCodeTafzili]
	@fldCodeHesab bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  SELECT        dbo.tblTafzili.fldCodeGroup, dbo.tblGroupAshkhas.fldGroupName
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup
WHERE        (dbo.tblTafzili.fldCodeTafzili = @fldCodeHesab)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoBargashtAzFactor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetOtherInfoBargashtAzFactor] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizeBargashtAzForoosh.fldCodeVasete, dbo.tblRizeBargashtAzForoosh.fldCodeUser, dbo.tblRizeBargashtAzForoosh.fldTime, dbo.tblRizeBargashtAzForoosh.fldDate, 
                         dbo.tblbargashtAzForoosh.fldSharhFactor, dbo.tblRizeBargashtAzForoosh.fldShomareFactor, dbo.tblRizeBargashtAzForoosh.fldShomareSanad, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeBargashtAzForoosh.fldCodeTafsili
FROM            dbo.tblRizeBargashtAzForoosh INNER JOIN
                         dbo.tblbargashtAzForoosh ON dbo.tblRizeBargashtAzForoosh.fldShomareSanad = dbo.tblbargashtAzForoosh.fldShomareSanad INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizeBargashtAzForoosh.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizeBargashtAzForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoFactor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetOtherInfoFactor] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizeForoosh.fldCodeVasete, dbo.tblRizeForoosh.fldCodeUser, dbo.tblRizeForoosh.fldTime, dbo.tblRizeForoosh.fldDate, 
                         dbo.tblForoosh.fldSharhFactor, dbo.tblRizeForoosh.fldShomareFactor, dbo.tblRizeForoosh.fldShomareSanad, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeForoosh.fldCodeTafsili
FROM            dbo.tblRizeForoosh INNER JOIN
                         dbo.tblForoosh ON dbo.tblRizeForoosh.fldShomareSanad = dbo.tblForoosh.fldShomareSanad INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizeForoosh.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizeForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoFactorBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Create PROCEDURE [dbo].[GetOtherInfoFactorBargashtAzKharid] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizeBargashtAzKharid.fldCodeVasete, dbo.tblRizeBargashtAzKharid.fldCodeUser, dbo.tblRizeBargashtAzKharid.fldTime, dbo.tblRizeBargashtAzKharid.fldDate, 
                         dbo.tblBargashtAzKharid.fldSharhFactor, dbo.tblRizeBargashtAzKharid.fldShomareFactor, dbo.tblRizeBargashtAzKharid.fldShomareSanad, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeBargashtAzKharid.fldCodeTafsili
FROM            dbo.tblRizeBargashtAzKharid INNER JOIN
                         dbo.tblBargashtAzKharid ON dbo.tblRizeBargashtAzKharid.fldShomareSanad = dbo.tblBargashtAzKharid.fldShomareSanad INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizeBargashtAzKharid.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizeBargashtAzKharid.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoFactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetOtherInfoFactorKharid] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizeKharid.fldCodeVasete, dbo.tblRizeKharid.fldCodeUser, dbo.tblRizeKharid.fldTime, dbo.tblRizeKharid.fldDate, 
                         dbo.tblKharid.fldSharhFactor, dbo.tblRizeKharid.fldShomareFactor, dbo.tblRizeKharid.fldShomareSanad, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeKharid.fldCodeTafsili
FROM            dbo.tblRizeKharid INNER JOIN
                         dbo.tblKharid ON dbo.tblRizeKharid.fldShomareSanad = dbo.tblKharid.fldShomareSanad INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizeKharid.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizeKharid.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetOtherInfoPishForoosh] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizePishForoosh.fldCodeVasete, dbo.tblRizePishForoosh.fldCodeUser, dbo.tblRizePishForoosh.fldTime, dbo.tblRizePishForoosh.fldDate, 
                         dbo.tblPishForoosh.fldSharhFactor, dbo.tblRizePishForoosh.fldShomareFactor,  dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizePishForoosh.fldCodeTafsili
FROM            dbo.tblRizePishForoosh INNER JOIN
                         dbo.tblPishForoosh ON dbo.tblRizePishForoosh.fldShomareFactor = dbo.tblPishForoosh.fldShomareFactorForoosh INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizePishForoosh.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizePishForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetOtherInfoPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetOtherInfoPishPishForoosh] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

		SELECT        TOP (1) dbo.tblRizePishPishForoosh.fldCodeVasete, dbo.tblRizePishPishForoosh.fldCodeUser, dbo.tblRizePishPishForoosh.fldTime, dbo.tblRizePishPishForoosh.fldDate, 
                         dbo.tblPishPishForoosh.fldSharhFactor, dbo.tblRizePishPishForoosh.fldShomareFactor,  dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizePishPishForoosh.fldCodeTafsili
FROM            dbo.tblRizePishPishForoosh INNER JOIN
                         dbo.tblPishPishForoosh ON dbo.tblRizePishPishForoosh.fldShomareFactor = dbo.tblPishPishForoosh.fldShomareFactorForoosh INNER JOIN
                         dbo.tblTafzili ON dbo.tblRizePishPishForoosh.fldCodeTafsili = dbo.tblTafzili.fldCodeTafzili
WHERE        (dbo.tblRizePishPishForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[GetPorsantSuperVisor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetPorsantSuperVisor]
	-- Add the parameters for the stored procedure here
	@fldCodeKala bigint,
	@fldPorsant float output
AS
BEGIN
	
	set @fldPorsant=(SELECT fldNerkhePorsantJoz from tblKala 
		where fldCodeKala=@fldCodeKala)

END

GO
/****** Object:  StoredProcedure [dbo].[GetPorsantVisitor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetPorsantVisitor]
	-- Add the parameters for the stored procedure here
	@fldCodeKala bigint,
	@fldPorsant float output
AS
BEGIN
	
	set @fldPorsant=(SELECT fldNerkhePorsantKol from tblKala 
		where fldCodeKala=@fldCodeKala)

END

GO
/****** Object:  StoredProcedure [dbo].[GetRowEshantionTabaghati]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetRowEshantionTabaghati]
	@lngCodeKala bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    
		SELECT 
			  [fldCodeKalaForoosh]
			  ,[fldShomareTabaghe]
			  ,[fldTedadForoosh]
			  ,[fldCodeKalaEshantion]
			  ,[fldTedadEshantion]
		  FROM tblEshantionTabaghati
			  where [fldCodeKalaForoosh]=@lngCodeKala

END

GO
/****** Object:  StoredProcedure [dbo].[GetRowEshantionTekrarShavande]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetRowEshantionTekrarShavande]
	@lngCodeKala bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    
		SELECT 
		  [fldCodeKalaForoosh]
		  ,[fldTedadKala]
		  ,[fldCodeKalaEshantion]
		  ,[fldTedadEshantion]
			  FROM tblEshantionTekrarShavande
				  where [fldCodeKalaForoosh]=@lngCodeKala

END

GO
/****** Object:  StoredProcedure [dbo].[GetShomareDaryaftByfldSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetShomareDaryaftByfldSanad]
	@fldShomareSanad bigint,
	@fldShomareDaryaft bigint output
AS
BEGIN

	SET NOCOUNT ON;
				set @fldShomareDaryaft=(	SELECT        TOP (1) dbo.tblDaryaft.fldShomareDaryaft
						FROM            dbo.tblSodooreSanad INNER JOIN
												 dbo.tblDaryaft ON dbo.tblSodooreSanad.fldSanad = dbo.tblDaryaft.fldShomareSanad
						WHERE        (dbo.tblDaryaft.fldShomareSanad = @fldShomareSanad))
				if @fldShomareDaryaft is null
					set @fldShomareDaryaft=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetShomarePardakhtByfldSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[GetShomarePardakhtByfldSanad]
	@fldShomareSanad bigint,
	@fldShomarePardakht bigint output
AS
BEGIN

	SET NOCOUNT ON;
				set @fldShomarePardakht=(	SELECT        TOP (1) dbo.tblPardakht.fldShomarePardakht
						FROM            dbo.tblSodooreSanad INNER JOIN
												 dbo.tblPardakht ON dbo.tblSodooreSanad.fldSanad = dbo.tblPardakht.fldShomareSanad
						WHERE        (dbo.tblPardakht.fldShomareSanad = @fldShomareSanad))
				if @fldShomarePardakht is null
					set @fldShomarePardakht=0
END

GO
/****** Object:  StoredProcedure [dbo].[GetTanzimatForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetTanzimatForoosh]
AS
BEGIN
	SELECT top 1 [ID]
      ,[fldKalaTekrary]
      ,[fldTypeInputKalaInGrid]
      ,[fldAllowForooshKalaBishAzMojodi]
      ,[fldShowMotalebatInFactorForoosh]
      ,[fldForooshNaghdi]
      ,[fldShowSodKala]
      ,[fldShowSodFactor]
      ,[fldEshantion]
      ,[fldChandGheymate]
      ,[fldArzeshAfzode]
      ,[fldTedadChapInForoosh]
      ,[fldSearchNumberingInKala]
      ,[fldBeginDateTakhfifat]
      ,[fldEndDateTakhfifat]
  FROM [dbo].[tblTanzimatForoosh]
  order by ID DESC
END

GO
/****** Object:  StoredProcedure [dbo].[GetTedadJozKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetTedadJozKala]
@fldCodeKala bigint,
@fldTedadJoz decimal output
AS
BEGIN
	
	set @fldTedadJoz=(SELECT fldTedadJoz from tblKala
	 where fldCodeKala=@fldCodeKala)
end

GO
/****** Object:  StoredProcedure [dbo].[HasAmalkard]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[HasAmalkard]

@Meghdar bigint,
@NameTable nvarchar(20),
@TedadTekrari int output
as

begin
	declare @RowCount int
	if @NameTable='Vahed' 
		begin
			set @RowCount =(Select Count(fldCodeVahed1) from tblKala Where fldCodeVahed1=@meghdar)
			if (@RowCount>0 )
				begin
					set @Tedadtekrari=@Rowcount
				end
			else
				begin
					set @RowCount =(Select Count(fldCodeVahed2) from tblKala Where fldCodeVahed2=@meghdar)
					set @Tedadtekrari=@Rowcount
				end
		end


end
GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[HasAmalkardAnbar]
	@CodeAnbar bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @intCount bigint

	set @Amalkard ='false'

	set @intCount =(select Count(fldCodeKala) from tblRizeForoosh Where fldCodeAnbar=@CodeAnbar)	
	if @intCount>0 
		begin
			set @Amalkard ='true'
			return
		end

	set @intCount =(select Count(fldCodeKala) from tblRizeKharid Where fldCodeAnbar=@CodeAnbar)	
	if @intCount>0 
		begin
			set @Amalkard ='true'
			return
		end

	set @intCount =(select Count(fldCodeKala) from tblRizeBargashtAzForoosh Where fldCodeAnbar=@CodeAnbar)	
	if @intCount>0 
		begin
			set @Amalkard ='true'
			return
		end

	set @intCount =(select Count(fldCodeKala) from tblRizeBargashtAzKharid Where fldCodeAnbar=@CodeAnbar)	
	if @intCount>0 
		begin
			set @Amalkard ='true'
			return
		end
END

GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardAnbarNew]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[HasAmalkardAnbarNew]
	@CodeAnbar bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @intCount bigint

	set @Amalkard ='false'

	--set @intCount =(select Count(fldCodeKala) from tblRizeForoosh Where fldCodeAnbar=@CodeAnbar)	
	--if @intCount>0 
	--	begin
	--		set @Amalkard ='true'
	--		return
	--	end

	--set @intCount =(select Count(fldCodeKala) from tblRizeKharid Where fldCodeAnbar=@CodeAnbar)	
	--if @intCount>0 
	--	begin
	--		set @Amalkard ='true'
	--		return
	--	end

	--set @intCount =(select Count(fldCodeKala) from tblRizeBargashtAzForoosh Where fldCodeAnbar=@CodeAnbar)	
	--if @intCount>0 
	--	begin
	--		set @Amalkard ='true'
	--		return
	--	end

	--set @intCount =(select Count(fldCodeKala) from tblRizeBargashtAzKharid Where fldCodeAnbar=@CodeAnbar)	
	--if @intCount>0 
	--	begin
	--		set @Amalkard ='true'
	--		return
	--	end
END

GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardBankMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[HasAmalkardBankMoshtari]
	-- Add the parameters for the stored procedure here
	@CodeBank bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @intCount bigint

	set @intCount =(Select Count(fldCodeBank) from tblCheckeDaryafti Where fldCodeBank =@CodeBank)
	if @intCount>0 
		set @Amalkard='true'
	else
		set @Amalkard='false'
END

GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardeDaryaftMain]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[HasAmalkardeDaryaftMain]
@ShomareDaryaft bigint,
@Khorooji nvarchar(50) output
as
begin
	declare @ShomareSanad nvarchar(50),@VaziatVosool nvarchar(15)

	set @ShomareSanad=(Select fldShomareSanad from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
	if isnumeric(@shomareSanad)=1
		begin
			set @Khorooji=(Select fldType from tblSodooreSanad Where fldSanad=@ShomareSanad and fldRadif='1')
		end

	set @VaziatVosool=(Select top(1) fldVaziat from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)
	
	if @VaziatVosool is not null
		set @Khorooji=	@VaziatVosool
		
		
end
GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardePardakhtMain]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[HasAmalkardePardakhtMain]
@ShomarePardakht bigint,
@Khorooji nvarchar(50) output
as
begin
	declare @ShomareSanad nvarchar(50)

	set @ShomareSanad=(Select fldShomareSanad from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
	if isnumeric(@shomareSanad)=1
		begin
			set @Khorooji=(Select fldType from tblSodooreSanad Where fldSanad=@ShomareSanad and fldRadif='1')
		end
end
GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[HasAmalkardKala] 
	@CodeKala bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	declare @lngCount bigint
	
	set @lngcount=(Select Count(fldCodeKala) from tblRizeForoosh Where fldCodeKala=@CodeKala )

	set @Amalkard='false'
	if @lngCount>0
		begin
			set @Amalkard='true'
			return
		end

	set @lngcount=(Select Count(fldCodeKala) from tblRizeKharid Where fldCodeKala=@CodeKala )
	if @lngCount>0
		begin
			set @Amalkard='true'
			return
		end

	set @lngcount=(Select Count(fldCodeKala) from tblRizeBargashtAzForoosh Where fldCodeKala=@CodeKala )
	if @lngCount>0
		begin
			set @Amalkard='true'
			return
		end

	set @lngcount=(Select Count(fldCodeKala) from tblRizeBargashtAzKharid Where fldCodeKala=@CodeKala )	
	if @lngCount>0
		begin
			set @Amalkard='true'
			return
		end
END

GO
/****** Object:  StoredProcedure [dbo].[HasAmalkardKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


Create proc [dbo].[HasAmalkardKolMoin]

@CodeKol nvarchar(50),
@CountRecord int output
as
begin
	declare @RowCountBank int
	begin
		set @RowCountBank=(Select Count(fldMoinKamel) from tblSodooreSanad  Where fldMoinKamel=@CodeKol)
		set @CountRecord=@RowCountBank
	end
end

GO
/****** Object:  StoredProcedure [dbo].[HesabeHazinePardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[HesabeHazinePardakht] 
	@ShomareSanad bigint,
	@CodeKolHazine nvarchar(10),
	@CodeKolMoinHazine nvarchar(10) output,
	@SharheHesab nvarchar(50) output

AS
BEGIN
	set @CodeKolMoinHazine=(Select fldMoinKamel from tblSodooreSanad Where fldSanad=@ShomareSanad and fldCodeKol=@CodeKolHazine)
	set @SharheHesab=(Select fldSharheHesab from tblKolMoin Where fldCodeHesab=@CodeKolMoinHazine)
END

GO
/****** Object:  StoredProcedure [dbo].[HesabeSandooghBankPardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[HesabeSandooghBankPardakht] 
	@ShomareSanad bigint,	
	@CodeKolMoinHesab nvarchar(10) output,
	@SharheHesab nvarchar(50) output

AS
BEGIN
	
	declare @CodeKolSandoogh  nvarchar(10),@CodeKolBank nvarchar(10)

	execute CodeKolHesab 'bank',@CodeKolBank output
	execute CodeKolHesab 'sandoogh',@CodeKolSandoogh output

	set @CodeKolMoinHesab=(Select fldMoinKamel from tblSodooreSanad Where fldSanad=@ShomareSanad and (fldCodeKol=@CodeKolSandoogh or fldCodeKol=@CodeKolBank) and fldBedehkar>0)
	set @SharheHesab=(Select fldSharheHesab from tblKolMoin Where fldCodeHesab=@CodeKolMoinHesab)
END

GO
/****** Object:  StoredProcedure [dbo].[IDOfPrinter]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[IDOfPrinter] 
	-- Add the parameters for the stored procedure here
	@NamePrinter nvarchar(max),
	@IDPrinter bigint output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @ID1  bigint
	
	set @id1 =(Select id from tblPrinters Where fldNamePrinter=@NamePrinter )
    if @id1 is null
		set @IDPrinter=0
	else
		set @IDPrinter =@ID1
END

GO
/****** Object:  StoredProcedure [dbo].[Insert_Tbl_DaftarcheTell]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Insert_Tbl_DaftarcheTell]
@fldCodeTafzili	nvarchar(10),
@fldName	nvarchar(50),
@fldShomare	nvarchar(50),
@fldSms	nvarchar(20),
@fldSharh	nvarchar(100),
@flagSabt int output	
as
begin

insert into tblDaftarcheTell
values(
 @fldCodeTafzili,
 @fldName,
 @fldShomare,
 @fldSms,
 @fldSharh) 
 
set @flagsabt=1
end

GO
/****** Object:  StoredProcedure [dbo].[Insert_Tbl_DaftarcheTell_has_CodeTafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Insert_Tbl_DaftarcheTell_has_CodeTafsili]
@fldCodeTafzili	nvarchar(10),
@fldName nvarchar(50),
@fldShomare	nvarchar(50),
@fldSms	nvarchar(20),
@fldSharh	nvarchar(100),
@flagSabt int output	
as
begin

insert into tblDaftarcheTell
values(
 @fldCodeTafzili,
 @fldName,
 @fldShomare,
 @fldSms,
 @fldSharh) 
 
set @flagsabt=1
end

GO
/****** Object:  StoredProcedure [dbo].[Insert_Tbl_Tafzili_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Insert_Tbl_Tafzili_final]
@fldNoeHesab	nvarchar(15),	
@fldSharheTafzili	nvarchar(200),
--@fldCodeTafzili	nvarchar(10),	
@fldCodeNoe	nvarchar(5),	--set "1"
@fldNoe	nvarchar(10),	
@fldCodeGroup	bigint,	        
@fldOstan	nvarchar(50),	
@fldCity	nvarchar(50),	
@fldAddress	nvarchar(200),	
@fldShomareHesab	nvarchar(20),	
@fldCodeMeli	nvarchar(20),	
@fldCodeEghtesadi	nvarchar(20),	
@fldCodePosti	nvarchar(20),	
@fldShomareSabt	nvarchar(20),	
@fldSaghfeEtebar	decimal,
@fldBlackList	nvarchar(5),	
@fldSharhBlackList	nvarchar(100),	
@fldDate1	bigint,	
@fldDate2	bigint,	
@fldVisitor	bigint,	
@fldPic	nvarchar(300),
@fldNoeVizitor int,
@fldPoorsant int,
@fldCodeSuperVisor nvarchar(10),
@fldNoeMohasebePoorsant int,
@flagSabtOK int output,
@iDTafsiliReturned bigint output,
@flagReturnChkCodeTafzili int output 

as
begin
set @flagSabtOK=0
declare @LenNumber int
declare @TafziliCode_Create bigint
declare @CountTafzili_in_TblTafzili int
declare @MaxCodeTafzili bigint
declare @chkCodeTafzili bigint 
Declare @Convert_TafziliCode_Create nvarchar(10)
Declare @Convert_TafziliCode_Create2 nvarchar(10)

set @fldVisitor=isnull(@fldVisitor,0)



set @LenNumber=(select fldTafzili  from tblPaye)

set @CountTafzili_in_TblTafzili=(select COUNT(CONVERT(bigint,fldCodeTafzili)) from tblTafzili)

if(@CountTafzili_in_TblTafzili =0)
 begin 
  if(@LenNumber >0)
    begin
      set @TafziliCode_Create=POWER(10,@lennumber-1)
        set @TafziliCode_Create=@TafziliCode_Create+1

		--
		  set  @Convert_TafziliCode_Create=CONVERT(nvarchar(10),@TafziliCode_Create)

		insert into tblTafzili(
				fldNoeHesab,fldSharheTafzili,fldCodeTafzili,fldCodeNoe,
				fldNoe,fldCodeGroup,fldOstan,fldCity,fldAddress,
				fldShomareHesab,fldCodeMeli,fldCodeEghtesadi,
				fldCodePosti,fldShomareSabt,fldSaghfeEtebar,
				fldBlackList,fldSharhBlackList,
				fldDate1,fldDate2,
				fldVisitor,
				fldPic,fldNoeVizitor,fldPoorsant,fldCodeSuperVisor,fldNoeMohasebePoorsant)

				values (@fldNoeHesab,@fldSharheTafzili,@Convert_TafziliCode_Create,@fldCodeNoe,
				@fldNoe,@fldCodeGroup,@fldOstan,@fldCity,@fldAddress,
				@fldShomareHesab,@fldCodeMeli,@fldCodeEghtesadi,
				@fldCodePosti,@fldShomareSabt,@fldSaghfeEtebar,
				@fldBlackList,@fldSharhBlackList,
				@fldDate1,@fldDate2,
				@fldVisitor,
				@fldPic,@fldNoeVizitor,@fldPoorsant,@fldCodeSuperVisor,@fldNoeMohasebePoorsant)
              
			  set @flagSabtOK=1
			  set @iDTafsiliReturned=@TafziliCode_Create
		--
    end
  else
    begin
      return
    end 
 end
else if @CountTafzili_in_TblTafzili > 0 ---یعنی کد قبل از  ایجاد شده و باید یه رقم به آن اضافه شود	 
begin

  set @MaxCodeTafzili=(select MAX(CONVERT(bigint,fldCodeTafzili)) from tblTafzili)

------------------------------------------------------------ باید چک شود کد تفیلی خارج از محدوده نباشد
 set @chkCodeTafzili=POWER(10,@lennumber)-1  -- orginal
                                                   
 --if  @chkCodeTafzili <=  @MaxCodeTafzili  --orginal Error
 if  @MaxCodeTafzili >=  @chkCodeTafzili -- Fixed 96-03-01 Is Worked OK!
 begin
    set @flagReturnChkCodeTafzili=1
     return
 end
------------------------------------------------------------
set @MaxCodeTafzili=@MaxCodeTafzili+1

set  @Convert_TafziliCode_Create2=CONVERT(nvarchar(10),@MaxCodeTafzili)
insert into tblTafzili
(
				fldNoeHesab,fldSharheTafzili,fldCodeTafzili,fldCodeNoe,
				fldNoe,fldCodeGroup,fldOstan,fldCity,fldAddress,
				fldShomareHesab,fldCodeMeli,fldCodeEghtesadi,
				fldCodePosti,fldShomareSabt,fldSaghfeEtebar,
				fldBlackList,fldSharhBlackList,
				fldDate1,fldDate2,
				fldVisitor,
				fldPic,fldNoeVizitor,fldPoorsant,fldCodeSuperVisor,fldNoeMohasebePoorsant)
values (@fldNoeHesab,@fldSharheTafzili,@Convert_TafziliCode_Create2,@fldCodeNoe,
@fldNoe,@fldCodeGroup,@fldOstan,@fldCity,@fldAddress,
@fldShomareHesab,@fldCodeMeli,@fldCodeEghtesadi,
@fldCodePosti,@fldShomareSabt,@fldSaghfeEtebar,
@fldBlackList,@fldSharhBlackList,
@fldDate1,@fldDate2,
@fldVisitor,
@fldPic,@fldNoeVizitor,@fldPoorsant,@fldCodeSuperVisor,@fldNoeMohasebePoorsant)

                   set @flagSabtOK=1
				     set @iDTafsiliReturned=@MaxCodeTafzili
end 

END

GO
/****** Object:  StoredProcedure [dbo].[InsertAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertAnbar]

@IDAnbar bigInt,
@NameAnbar nvarChar(70),
@flagSabt int output,
@IDOutPut int outPut
as 

begin
	set @IDAnbar= (Select Max(fldCode) from tblAnbar)
	Set @IDAnbar+=1
	insert into tblAnbar 
		values(@IDAnbar,@NameAnbar)
	set @flagSabt=@IDAnbar
	set @IDOutPut=@@IDENTITY
end

GO
/****** Object:  StoredProcedure [dbo].[InsertBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[InsertBankeMoshtari]

@NameBank nvarChar(70),
@IDOutPut int outPut
as 

begin

	insert into tblBankeMoshtari 
		values(@NameBank)	
	set @IDOutPut=@@IDENTITY
end

GO
/****** Object:  StoredProcedure [dbo].[insertDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[insertDasteCheck]
@daste tblDaftarCheck ReadOnly

as

begin
	insert into tblDasteCheck (fldCodeBank,fldShobe,fldShomareCheck,fldShomareHesab)
		Select fldCodeBank,fldShobe,fldShomareCheck,fldShomareHesab from @daste
end


GO
/****** Object:  StoredProcedure [dbo].[InsertDastrasi]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertDastrasi] 
	-- Add the parameters for the stored procedure here
	@CodeUser bigint,
	@CodeDastrasi bigint,
	@Check int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	if @check=0 --یعنی پاک بشه
		delete from tblDastrasi Where fldCodeUser=@CodeUser and fldCodeDastrasi=@CodeDastrasi
	else if @check=1
		begin
			insert into tblDastrasi
				(fldCodeUser,fldCodeDastrasi)
				values
					(@CodeUser,@CodeDastrasi)
		end
	else if @check=2 --UnCheckaLL
		begin
			DELETE from tbldastrasi	
				where fldCodeUser=@CodeUser
		end
	else if @Check=3 --CheckAll
		begin
			DELETE from tbldastrasi	
				where fldCodeUser=@CodeUser
			insert into tbldastrasi	
				(fldCodeUser,fldCodeDastrasi)
				Select @CodeUser,fldCode from  tblListeDastrasi
		end
END

GO
/****** Object:  StoredProcedure [dbo].[InsertDastrasiSandoogh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertDastrasiSandoogh] 
	@CodeUser bigint,
	@CodeSandoogh bigint,
	@CodeBank bigint,	
	@NoeKhata nvarchar(10) output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END

BEGIN
	begin transaction transact
	begin try

		Delete from tblDastrasiSandoogh Where fldCodeUser=@CodeUser
		
		insert tblDastrasiSandoogh
			(fldCodeUser,fldSandoogh,fldType)
			values
			(@CodeUser,@CodeSandoogh,'sandoogh')

		insert tblDastrasiSandoogh
			(fldCodeUser,fldSandoogh,fldType)
			values
			(@CodeUser,@CodeBank,'bank')

	commit transaction
	end try

	begin catch
		if @@trancount>0 
			rollback transaction ;
			set @NoeKhata='rolback'

	end catch
		
END

GO
/****** Object:  StoredProcedure [dbo].[InsertEbtedaDoreh_Ashkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertEbtedaDoreh_Ashkhas]
    @dtSanadEbteda_Ashkas tpSanadEbteda_Ashkas  Readonly,
	@strResult  nvarchar(25) output,
    @InsertType nvarchar(50),
	@fldBedehkar decimal,
	@fldBestankar  decimal, 
	@fldRadif varchar(50),
	@fldCodeKolSarmaye varchar(50),
	@fldMoinKamelSarmaye varchar(50),
	@fldShmareSanad varchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	   Begin Transaction InsertRow
	     declare @lngCountMojodi bigint
    -- Insert statements for procedure here
	      Begin Try
		          set @lngCountmojodi=(Select Count(fldSanad) from tblSodooreSanad Where  fldType='EbtedaAshkhas')
			 if (@lngCountMojodi = 0)
			   Begin
		        if @InsertType='insert'
					begin
						INSERT INTO [dbo].[tblSodooreSanad]
								([fldSanad]
								,[fldDay] 
								,[fldMonth]
								,[fldYear]
								,[fldCodeKol] 
								,[fldCodeMoin] 
								,[fldCodeTafzili] 
								,[fldBedehkar] 
								,[fldBestankar] 
								,[fldRadif] 
								,[fldDate]  
								,[fldSharh] 
								,[fldMoinKamel]
								,[fldCodeNoeTafzili]
								,[fldType])
								
								SELECT
								 [fldSanad]
								,[fldDay] 
								,[fldMonth]
								,[fldYear]
								,[fldCodeKol] 
								,[fldCodeMoin] 
								,[fldCodeTafzili] 
								,[fldBedehkar] 
								,[fldBestankar] 
								,[fldRadif] 
								,[fldDate]  
								,[fldSharh] 
								,[fldMoinKamel]
								,[fldCodeNoeTafzili]
								,[fldType]
								output from @dtSanadEbteda_Ashkas;

								
								
									INSERT INTO tblSodooreSanad                      --sarmaye
												(fldSanad,fldCodeKol,fldCodeMoin,
													fldBedehkar,fldBestankar,fldRadif, 
													fldType,fldCodeTafzili)
									values (@fldShmareSanad,@fldCodeKolSarmaye,@fldMoinKamelSarmaye,
											@fldBedehkar,@fldBestankar,@fldRadif,'EbtedaAshkhas','')


							     set @strResult='insertOk'
                       End
                  End
                
				 if (@lngCountMojodi > 0)
			       Begin
				   Delete from tblSodooreSanad where fldType='EbtedaAshkhas'
		              if @InsertType='insert'
					begin
						INSERT INTO [dbo].[tblSodooreSanad]
								([fldSanad]
								,[fldDay] 
								,[fldMonth]
								,[fldYear]
								,[fldCodeKol] 
								,[fldCodeMoin] 
								,[fldCodeTafzili] 
								,[fldBedehkar] 
								,[fldBestankar] 
								,[fldRadif] 
								,[fldDate]  
								,[fldSharh] 
								,[fldMoinKamel]
								,[fldCodeNoeTafzili]
								,[fldType])
								
								SELECT
								 [fldSanad]
								,[fldDay] 
								,[fldMonth]
								,[fldYear]
								,[fldCodeKol] 
								,[fldCodeMoin] 
								,[fldCodeTafzili] 
								,[fldBedehkar] 
								,[fldBestankar] 
								,[fldRadif] 
								,[fldDate]  
								,[fldSharh] 
								,[fldMoinKamel]
								,[fldCodeNoeTafzili]
								,[fldType]
								output from @dtSanadEbteda_Ashkas;

								
								
									INSERT INTO tblSodooreSanad                      --sarmaye
												(fldSanad,fldCodeKol,fldCodeMoin,
													fldBedehkar,fldBestankar,fldRadif, 
													fldType,fldCodeTafzili)
									values (@fldShmareSanad,@fldCodeKolSarmaye,@fldMoinKamelSarmaye,
											@fldBedehkar,@fldBestankar,@fldRadif,'EbtedaAshkhas','')

				
							     set @strResult='UpdateArchiveOk'
                          End
				   End

		     Commit Transaction InsertRow; 
		   End Try

			 Begin Catch
			   if @@TRANCOUNT > 0 
			     begin 
				  RollBack Transaction InsertRow;
				     set @strResult='Error'
				 end

			  End Catch

END

GO
/****** Object:  StoredProcedure [dbo].[insertGroupAshkhas_m]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery16.sql|7|0|C:\Users\ALISER~1\AppData\Local\Temp\~vsF5E.sql
CREATE proc [dbo].[insertGroupAshkhas_m]
@fldGroupAshkhasId bigint,
@fldGroupAshkhasName nvarchar(50),
@codlen int,
@flag int output,
@flagroot int  -- این فلگ مشخص میکنه که کدام دستورات باید اجرا شود

as


begin
declare @idnumber bigint
declare @idnumberconvert nvarchar(30)
declare @GroupName nvarchar(50)


set @flag=0

 

 if (@codlen=1)  --وقتی از دیتا گرید انتخاب نشود  ایجاد سرگروه سه رقمی
  begin
    set @idnumber=(select max(fldGroupId) from tblGroupAshkhas where LEN(fldGroupId)=3 )
    if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName and LEN(fldGroupId)=3)
     begin
		 set @idnumber=@idnumber+1
		 
		 insert into tblGroupAshkhas
		     values(@idnumber,@fldGroupAshkhasName)
			 
			
	  end
	   else
	     begin
		  set @flag=1
		  return
		 end
		
   end

   -- زیر گروه اول

   --if (@codlen=3)
   if ((@codlen<>1) and (@flagroot=1 ))
  begin
   
	set @idnumber=(select max(fldGroupId) from tblGroupAshkhas where LEN(convert(nvarchar(50),fldGroupId))> = 3 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupAshkhasId) + '%')
   
		if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName and LEN(fldGroupId) > =3 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupAshkhasId) + '%')-- نام تکراری نباشد در هر سطح
	     begin
	     set @idnumberconvert=convert(nvarchar(30),@idnumber)+ '001'
		 set @idnumber=CONVERT(bigint,@idnumberconvert)
		 
		 insert into tblGroupAshkhas
		     values(@idnumber,@fldGroupAshkhasName)
			 
			

	  end
	   else
	     begin
		  set @flag=1
		  return
		  end
		
   end

		   --
		  -- if (@codlen=6)
		   if ((@codlen <> 1) and (@flagroot=2)) --تولید زیر گروه جز
				begin
				 
				  set @idnumber=(select max(fldGroupId) from tblGroupAshkhas where LEN(convert(nvarchar(50),fldGroupId)) = len(@fldGroupAshkhasId)
							 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupAshkhasId) + '%' )

				 if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName)
				
					 begin
						set @idnumber=@idnumber+1
						
						
							 insert into tblGroupAshkhas
								 values(@idnumber,@fldGroupAshkhasName)
								 
					 end
				 else
					 begin
					  set @flag=1 -- نام کالا در آن سطح مشابه میباشد
					  return
					 end
		
		   end
		 

		      end


GO
/****** Object:  StoredProcedure [dbo].[insertGroupKala_m]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: SQLQuery16.sql|7|0|C:\Users\ALISER~1\AppData\Local\Temp\~vsF5E.sql
CREATE proc [dbo].[insertGroupKala_m]
@fldGroupKalaId bigint,
@fldGroupKalaName nvarchar(50),
@codlen int,
@flag int output,
@flagroot int  -- این فلگ مشخص میکنه که کدام دستورات باید اجرا شود
--@flagCheckIdInTblKala int output  --چک کردن ای دی وارد شده ایا در عمکرد کالا سابقه دارد یا خیر new

as


begin
declare @idnumber bigint
declare @idnumberconvert nvarchar(30)
declare @GroupName nvarchar(50)
--------------------------------------------------------------------new 95-09-03
--declare @hasRowInTblKala int --new

--set @hasRowInTblKala=0 --new 
--set @flagCheckIdInTblKala=0 -- new 
--set @hasRowInTblKala=(select count(fldCodeGroup) from tblKala where fldCodeGroup=@fldGroupKalaId)-- new 
--if (@hasRowInTblKala >= 1) --new 
--begin
--set @flagCheckIdInTblKala=1
--return 
--end 
------------------------------------------------------ new 95-09-03

set @flag=0

 --set @GroupName=(select fldGroupName  from tblGroupKala where fldGroupName=@fldGroupKalaName)
 --  selectیه سلکت از جدول کالا برای مشخص شدن اینکه این شماره کالا دارد یا ندارد
 if (@codlen=1)  --وقتی از دیتا گرید انتخاب نشود  ایجاد سرگروه سه رقمی
  begin
    set @idnumber=(select max(fldGroupId) from tblGroupKala where LEN(fldGroupId)=3 )
    if not Exists(select fldGroupName  from tblGroupKala where fldGroupName=@fldGroupKalaName and LEN(fldGroupId)=3)
     begin
		 set @idnumber=@idnumber+1
		 
		 insert into tblGroupKala
		     values(@idnumber,@fldGroupKalaName)
			 
			 

	  end
	   else
	     begin
		  set @flag=1
		  return
		 end
		
   end

   -- زیر گروه اول

   --if (@codlen=3)
   if ((@codlen<>1) and (@flagroot=1 ))
  begin
   
	set @idnumber=(select max(fldGroupId) from tblGroupKala where LEN(convert(nvarchar(50),fldGroupId))> = 3 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupKalaId) + '%')
   
		if not Exists(select fldGroupName  from tblGroupKala where fldGroupName=@fldGroupKalaName and LEN(fldGroupId) > =3 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupKalaId) + '%')-- نام تکراری نباشد در هر سطح
	
     begin
	     set @idnumberconvert=convert(nvarchar(30),@idnumber)+ '001'
		 set @idnumber=CONVERT(bigint,@idnumberconvert)
		 
		 insert into tblGroupKala
		     values(@idnumber,@fldGroupKalaName)
			 
			

	  end
	   else
	     begin
		  set @flag=1
		  return
		  end
		
   end

		   --
		  -- if (@codlen=6)
		   if ((@codlen <> 1) and (@flagroot=2)) --تولید زیر گروه جز
				begin
				 --set @idnumber=(select max(fldGroupId) from tblGroupKala where LEN(fldGroupId)> =3 and fldGroupId=@fldGroupKalaId)
				 --set @idnumber=(select max(fldGroupId) from tblGroupKala where LEN(convert(nvarchar(50),fldGroupId))> = 3 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupKalaId) + '%')

				  set @idnumber=(select max(fldGroupId) from tblGroupKala where LEN(convert(nvarchar(50),fldGroupId)) = len(@fldGroupKalaId)
							 and convert(nvarchar(50),fldGroupId) like  convert(nvarchar(50),@fldGroupKalaId) + '%' )

				 if not Exists(select fldGroupName  from tblGroupKala where fldGroupName=@fldGroupKalaName)
				  --and not Exists(select fldGroupId  from tblGroupKala where fldGroupId=@fldGroupKalaId)
					 begin
						set @idnumber=@idnumber+1
						
						
							 insert into tblGroupKala
								 values(@idnumber,@fldGroupKalaName)
								 
					 end
				 else
					 begin
					  set @flag=1 -- نام کالا در آن سطح مشابه میباشد
					  return
					 end
		
		   end
		   --
		   --if(LEN(@idnumber) < 15)
		   -- begin
		   --set @returnIdInsert=@idnumber
		  
		   --return @returnIdInsert
		   --end
		 


     end


GO
/****** Object:  StoredProcedure [dbo].[InsertInfoBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoBargashtAzForoosh]
	@flagForoosh nvarchar(10),

	@intHasRowCheckPardakhti int,
	@intHasRowCheckMoshtari int,
	@lngMablaghKolCheckHaPardakhti bigint,
	@lngMablaghKolCheckMoshtari bigint,



	@lngMablaghNaghdPardakht bigint,
	@lngMablaghBankPardakht bigint,
	@lngMablaghTakhfifPardakht bigint,

	@dtForoosh tpRizeForoosh  readonly,	
	@fldSharhFactor nvarchar(250),
	@fldShomareFactor bigint,
    @fldShomareSanad bigint,
    @fldDate bigint,
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,






	
	
	
	


	--پارامترهای صندوق
@CodeKolSandoogh nvarchar(10),
@CodeMoinSandoogh nvarchar(10),
--@Naghd decimal,
--@SNaghd nvarchar(200),

--'پارامترهای بانک
@CodeKolBank nvarchar(10),
@CodeMoinBank nvarchar(10),
--@Bank decimal,
--@SBank nvarchar(200),

--'پارامترهای چک
@tblCheck tblCheckPardakhti readonly,
@CodeKolCheck nvarchar(10),
@CodeMoinCheck nvarchar(10),
--@MablaghCheck decimal,
--@SCheck nvarchar(200),

--'پارامترهای چک واگذاری
@CheckeVagozari tblCheckVagozari readonly,
@CodeKolCheckVagozari nvarchar(10),
@CodeMoinCheckVagozari nvarchar(10),
--@MablaghCheckVagozari decimal,
--@SCheckVagozari nvarchar(200),

--پارامترهای تخفیفات
@CodeKoltakhfifat nvarchar(10),
@CodeMoinTakhfifatePardakht nvarchar(10),
--@Takhfif decimal,
--@STakhfif nvarchar(200),

-----پایان کد مرعشی
--شرح پرداخت
@strSharhNaghd nvarchar(50),
@strSharhBank nvarchar(50),
@strSharhCheck nvarchar(50),
@strSharhCheckMoshtari nvarchar(50),
@strSharhTakhfif nvarchar(50),
@strSharhKoli nvarchar(50),







	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
	--@ErrorLine bigint output
	
AS
BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayePardakhtani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomarePardakht bigint,@yearFull nvarchar(5),@dateSmall bigint,@strMoinKamel nvarchar(50),@lngSumPardakht bigint
			declare @CodeMoinHoghoogh nvarchar(10)
			set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @month=substring(convert(nvarchar(20),@fldDate),5,2)
			set @day=substring(convert(nvarchar(20),@fldDate),7,2)
			set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
			declare @lngSumDaryaft bigint
			set @intRadif=0
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'

			if @flagForoosh='arshive'
				begin
					--arishive
					--update(delete and insert)
					--delete
					delete from tblRizeBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad

					declare @ShomarePardakhtArshive bigint
					set @ShomarePardakhtArshive=(Select fldShomarePardakht from tblPardakht Where fldShomareSanad=@fldShomareSanad)
					if @ShomarePardakhtArshive is not null
						begin
							update tblCheckeDaryafti 
								set fldShomarePardakht= null
								where fldShomarePardakht=@ShomarePardakhtArshive
						end

					delete from tblPardakht
						where fldShomareSanad=@fldShomareSanad

					delete from tblCheckePardakhti
						where fldSanad=Convert(nvarchar(50),@fldShomareSanad)


					


						--where fldSanad=@fldShomareSanad  

					--insert

							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output

							execute codemoinhesab 'bargashtazforoosh' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad

						
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end
							
							if @lngArzeshAfzode>0
							begin 
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
							--چون در حالت ویرایش میباشد از لست استفاده کردم
							
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
	

							--بررسی شرح های پرداخت
							if (@strSharhNaghd is null or @strSharhNaghd='')
							begin
								set @strSharhNaghd='nonePardakht'
							end
							if (@strSharhBank is null or @strSharhBank='')
							begin
								set @strSharhBank='nonePardakht'
							end
							if (@strSharhCheck is null or @strSharhCheck='')
							begin
								set @strSharhCheck='nonePardakht'
							end
							if (@strSharhTakhfif is null or @strSharhTakhfif='')
							begin
								set @strSharhTakhfif='nonePardakht'
							end
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
							begin
								set @strSharhKoli='nonePardakht'
							end

							--پایان بررسی شرح های پرداخت
							set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

							if(@lngSumPardakht>0)
							begin
								set @intRadif=@intRadif+1
								execute ToolePaye 'kol',@TooleKol output
								execute ToolePaye 'moin',@Toolemoin output
								execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								--بدهکار
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end

							if @lngMablaghNaghdPardakht>0
							begin
								set @intRadif =@intRadif+1
								set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
								set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
								execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
							end
							--INSERT INTO tblTest
							--	(adad)
							--		VALUES        (@lngMablaghBankPardakht)
							--سند بانک
							if @lngMablaghBankPardakht>0
							begin
								--INSERT INTO tblTest
								--(adad)
								--	VALUES        (66)
								set @intRadif =@intRadif+1

								set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
								set @strMoinKamel=@CodeKolBank + @CodeMoinBank
								execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
							end
							--سند چک
							if @lngMablaghKolCheckHaPardakhti>0
							begin
								set @intRadif =@intRadif+1

								set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
								set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
								execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
							end
							--سند حسابداری واگذاری چک
							if @lngMablaghKolCheckMoshtari>0
							begin
								set @intRadif =@intRadif+1
								set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
								set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
								execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;

							end

							if @lngMablaghTakhfifPardakht>0
							begin
								set @intRadif =@intRadif+1
								set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
								set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
								execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
							end
							if (@lngSumPardakht>0)
							begin
								set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
								set @ShomarePardakht=@ShomarePardakht+1
								INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'bargashtazforoosh')

								--ثبت ریز اطلاعات چک
								Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
								Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@dateSmall,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

								--ثبت واگذاری چک
								UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

							end



								--ح س پرداختنی
							
							--execute  ToolePaye 'kol',@TooleKol output
							--execute  ToolePaye 'moin',@Toolemoin output
							--execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
							--set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							--set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
							----declare @lngSumDaryaft bigint
							--set @lngSumPardakht=(@lngMablaghTakhfifPardakht+@lngMablaghBankPardakht+@lngMablaghNaghdPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari)
							--if(@lngSumPardakht>0)
							--begin
							--	set @intRadif=@intRadif+1
							--	execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngSumPardakht,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad 
							--end 
							--سند پورسانت واسطه ها و ویزیتور ها
							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								--if @lngSumPardakht>0
								--begin
								--	set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
								--	set @ShomarePardakht=@ShomarePardakht+1
								--	--ثبت دریافت اصلی فروش
								--	INSERT  INTO   tblpardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
								--					VALUES        (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'5bargashtazforoosh')

								--	--ثبت ریز اطلاعات چک	
								--	--Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
								--	--		Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,ShomarePardakht,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								--end 
							INSERT INTO tblbargashtazforoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizeBargashtAzForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;






					set @strResult='update'
					set @strResult2='update'
					
					--commit transaction AddRecord;
					--return
				end
				--تا اینجا تفصیلی ها به روز  شدند
			else if @flagForoosh='insert'
				begin
				--insert
						
					declare @resultExist bigint
					execute ExistFactorBargashtazForoosh @fldShomareFactor,@resultExist output
					declare @maxFactor bigint
					execute GetMaxShomareFactorBargashtAzForoosh @maxFactor output
					set @maxFactor=@maxFactor+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					 else if(@resultExist=0 and @flagInsert='yes')
					 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
					     begin
						
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'takhfifatepardakht' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad output 
								
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end 
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'bargashtazforoosh' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='nonepardakht'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='nonepardakht'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='nonepardakht'
								end 
							if (@strSharhTakhfif is null or  @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='nonepardakht'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='none'
								end 
	
							--پایان بررسی شرح های دریافت

							set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

									if(@lngSumPardakht>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بدهکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
									execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند بانک
									if @lngMablaghBankPardakht>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolBank + @CodeMoinBank
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند چک
									if @lngMablaghKolCheckHaPardakhti>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند حسابداری واگذاری چک
									if @lngMablaghKolCheckMoshtari>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
									execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;

									end

									if @lngMablaghTakhfifPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									if (@lngSumPardakht>0)
									begin
									set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
									set @ShomarePardakht=@ShomarePardakht+1
									INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
									VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'bargashtazforoosh')

									--ثبت ریز اطلاعات چک
									Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
									Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@dateSmall,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

									--ثبت واگذاری چک
									UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

									end





							--سند پورسانت واسطه ها و ویزیتور ها
							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								if @lngSumPardakht>0
								begin
									set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
									set @ShomarePardakht=@ShomarePardakht+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'bargashtazforoosh')

									--ثبت ریز اطلاعات چک	
									--Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
									--		Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,ShomarePardakht,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblBargashtAzForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@maxFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizeBargashtAzForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='insert'
							--commit transaction AddRecord;
						end
					else if(@resultExist=0 and @flagInsert='no')
						 begin
						
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output

							set @intRadif=@intRadif+1							
							execute codemoinhesab 'bargashtazforoosh' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad output 
							--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
						   

							

							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayePardakhtani output
								set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							end 


							
							--############################################################################################
							-----------------------pardakht----------------------------------------
									--بررسی شرح های پرداخت
									if (@strSharhNaghd is null or @strSharhNaghd='')
									begin
									set @strSharhNaghd='nonePardakht'
									end
									if (@strSharhBank is null or @strSharhBank='')
									begin
									set @strSharhBank='nonePardakht'
									end
									if (@strSharhCheck is null or @strSharhCheck='')
									begin
									set @strSharhCheck='nonePardakht'
									end
									if (@strSharhTakhfif is null or @strSharhTakhfif='')
									begin
									set @strSharhTakhfif='nonePardakht'
									end
									--شرح دریافت اصلی فروش
									if (@strSharhKoli is null or @strSharhKoli='')
									begin
									set @strSharhKoli='nonePardakht'
									end

									--پایان بررسی شرح های پرداخت
									set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

									if(@lngSumPardakht>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بدهکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
									execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند بانک
									if @lngMablaghBankPardakht>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolBank + @CodeMoinBank
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند چک
									if @lngMablaghKolCheckHaPardakhti>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									--سند حسابداری واگذاری چک
									if @lngMablaghKolCheckMoshtari>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
									execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;

									end

									if @lngMablaghTakhfifPardakht>0
									begin
										set @intRadif =@intRadif+1
										set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
										set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
										execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad;
									end
									
									if (@lngSumPardakht>0)
									begin
										set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
										set @ShomarePardakht=@ShomarePardakht+1
										INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
										VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'bargashtazforoosh')

										--ثبت ریز اطلاعات چک
										Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
										Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@dateSmall,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

										--ثبت واگذاری چک
										UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

									end

									set @intRadif=@intRadif+1
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayePardakhtani output
							set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
							--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							--execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad output 
							 execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazforoosh',@fldCodeVasete,@fldShomareSanad
							--############################################################################################



							--سند پورسانت واسطه ها و ویزیتور ها
							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 



								if @lngSumPardakht>0
								begin
									set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
									set @ShomarePardakht=@ShomarePardakht+1
									--ثبت دریافت اصلی فروش

									--control
									--INSERT  INTO   tblpardakht( fldShomarepardakht, fldShomareSanad, fldCodeTafzili,fldType)
									--				VALUES        (ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'bargashtazforoosh')

									--ثبت ریز اطلاعات چک	
									--Insert into  tblCheckepardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatepardakht,fldShomarepardakht,fldVasete,fldSanad)
									--		Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,ShomarePardakht,@fldCodeVasete,@fldShomareSanad output from @dtCheckpardakhti;	
								end
							INSERT INTO tblBargashtAzForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizeBargashtAzForoosh
													   ([fldShomareSanad]
													   ,[fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime])
														select @fldShomareSanad
														--edit
													   ,@fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@fldShomareFactor)
							set @strResult2='insertByNo'
							--commit transaction AddRecord
						end
						
				end
			--set @strResult='errorx'
			--set @strResult2='errorx'
			--update sharh Ha
			--@fldShomarefactor dar khat zir bayad avaz beshe (shayad =>@fldShomarefactorNew )
			 if @flagInsert='yes'
				begin
					update  tblSodooreSanad
							--set fldSharh ='برگشت از فروش به شماره ' + convert(nvarchar(17),@maxFactor)
							set fldSharh ='' 
							where fldSanad=@fldShomareSanad and fldSharh like 'none'
					update  tblSodooreSanad
							--set fldSharh ='برگشت از فروش به شماره ' + convert(nvarchar(17),@maxFactor) + ' - شماره پرداخت ' +  convert(nvarchar(17),@ShomarePardakht) 
							set fldSharh =''  
							where fldSanad=@fldShomareSanad and fldSharh like 'nonepardakht'
				end
			else
				begin
					 update  tblSodooreSanad
							--set fldSharh ='برگشت از فروش به شماره ' + convert(nvarchar(17),@fldShomarefactor)
							set fldSharh ='' 
							where fldSanad=@fldShomareSanad and fldSharh like 'none'

					update  tblSodooreSanad
							--set fldSharh ='برگشت از فروش به شماره ' + convert(nvarchar(17),@fldShomarefactor) + ' - شماره پرداخت ' +  convert(nvarchar(17),@ShomarePardakht) 
							set fldSharh =''  
							where fldSanad=@fldShomareSanad and fldSharh like 'nonepardakht'
				end


				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult= 'error' 
				set @strResult2='error'
				 --set @ErrorLine=( Select ERROR_LINE() as errln)
				--set @ErrorLine=1
				--select  ERROR_LINE() as mm 
				--SELECT
				--	 ERROR_NUMBER() AS ErrorNumber,
				--	 ERROR_SEVERITY() AS ErrorSeverity,
				--	 ERROR_STATE() AS ErrorState,
				--	 ERROR_PROCEDURE() AS ErrorProcedure,
				--	 ERROR_LINE() AS ErrorLine,
				--	 ERROR_MESSAGE() AS ErrorMessage;

				rollback transaction AddRecord;
			end
		end catch
END
GO
/****** Object:  StoredProcedure [dbo].[InsertInfoBargashtAzForooshTest]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoBargashtAzForooshTest]
	@flagForoosh nvarchar(10),
	@fldCodeTafsili bigint,
	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,
    @fldShomareFactor bigint,
    @fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizeForoosh  readonly,
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,
	@lngMablaghKolCheckHa bigint,
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft bigint,
    @lngMablaghBankDaryaft bigint,
	@lngMablaghTakhfifDaryaft bigint,
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	--شرح دریافت
	@strSharhNaghd nvarchar(50), 
	@strSharhBank nvarchar(50),
	@strSharhCheck nvarchar(50),
	@strSharhTakhfif nvarchar(50),
	@strSharhKoli nvarchar(50),
	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10),
	@ErrorLine bigint output
AS
BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomareDaryaft bigint,@yearFull nvarchar(5),@dateSmall bigint
			set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @month=substring(convert(nvarchar(20),@fldDate),5,2)
			set @day=substring(convert(nvarchar(20),@fldDate),7,2)
			set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
			declare @lngSumDaryaft bigint
			set @intRadif=0
		
			if @flagForoosh='arshive'
				begin
					--arishive
					--update(delete and insert)
					--delete
					delete from tblRizeBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad

					delete from tblDaryaft
						where fldShomareSanad=@fldShomareSanad

					delete from tblCheckeDaryafti
						where fldSanad=@fldShomareSanad and (fldShomareVosool  is  null and fldShomarePardakht  is  null)
						--where fldSanad=@fldShomareSanad  

					--insert
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--چون در حالت ویرایش میباشد از لست استفاده کردم
							
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end
							
							if @lngArzeshAfzode>0
							begin 
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='noneDaryaft'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--declare @lngSumDaryaft bigint
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if(@lngSumDaryaft>0)
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end 
							--سند پورسانت واسطه ها و ویزیتور ها
							if @lngMablaghPorsant>0
								begin
									set @intRadif=@intRadif+1

									--execute codemoinhesab '' ,@CodeMoinHesabhayeDaryaftani output
									--set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									--set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end 
							INSERT INTO tblBargashtAzForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)

							 INSERT INTO tblRizeBargashtAzForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;






					set @strResult='update'
					set @strResult2='update'
					
					--commit transaction AddRecord;
					--return
				end
				--تا اینجا تفصیلی ها به روز  شدند
			else if @flagForoosh='insert'
				begin
				--insert
						
					declare @resultExist bigint
					execute ExistFactorBargashtAzForoosh @fldShomareFactor,@resultExist output
					declare @maxFactor bigint
					execute GetMaxShomareFactorBargashtAzForoosh @maxFactor output
					set @maxFactor=@maxFactor+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					 else if(@resultExist=0 and @flagInsert='yes')
					 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
					     begin
						
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
								
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or  @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='none'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--declare @lngSumDaryaft bigint
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end
							--سند پورسانت واسطه ها و ویزیتور ها
							if @lngMablaghPorsant>0
								begin
									set @intRadif=@intRadif+1

									--execute codemoinhesab '' ,@CodeMoinHesabhayeDaryaftani output
									--set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									--set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblBargashtAzForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)

							 INSERT INTO tblRizeBargashtAzForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='insert'
							--commit transaction AddRecord;
						end
					else if(@resultExist=0 and @flagInsert='no')
						 begin
						
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='noneDaryaft'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end 
							--سند پورسانت واسطه ها و ویزیتور ها
							if @lngMablaghPorsant>0
								begin
									set @intRadif=@intRadif+1

									--execute codemoinhesab '' ,@CodeMoinHesabhayeDaryaftani output
									--set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									--set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 
								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblBargashtAzForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)

							 INSERT INTO tblRizeBargashtAzForoosh
													   ([fldShomareSanad]
													   ,[fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime])
														select @fldShomareSanad
														--edit
													   ,@fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@fldShomareFactor)
							set @strResult2='insertByNo'
							--commit transaction AddRecord
						end
						
				end
			--set @strResult='errorx'
			--set @strResult2='errorx'
			--update sharh Ha
			--@fldShomarefactor dar khat zir bayad avaz beshe (shayad =>@fldShomarefactorNew )
			 if @flagInsert='yes'
				begin
					update  tblSodooreSanad
							set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@maxFactor)
							where fldSanad=@fldShomareSanad and fldSharh like 'none'
					update  tblSodooreSanad
							set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@maxFactor) + ' - شماره دریافت ' +  convert(nvarchar(17),@ShomareDaryaft) 
							where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end
			else
				begin
					 update  tblSodooreSanad
							set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@fldShomarefactor)
							where fldSanad=@fldShomareSanad and fldSharh like 'none'

					update  tblSodooreSanad
							set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@fldShomarefactor) + ' - شماره دریافت ' +  convert(nvarchar(17),@ShomareDaryaft) 
							where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end


				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				set @strResult2='error'
				set @ErrorLine=( Select ERROR_LINE() as errln)
				if @ErrorLine is null 
					set @errorline=0
				rollback transaction AddRecord;
			end
		end catch
END
GO
/****** Object:  StoredProcedure [dbo].[InsertInfoBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInfoBargashtAzKharid]
@flagKharid nvarchar(10),

@dtCheckDaryafti tblCheckDaryafti readonly,
@intHasRowCheckDaryafti int,
@lngMablaghKolCheckHa bigint,
@lngMablaghNaghdDaryaft bigint,
@lngMablaghBankDaryaft bigint,
@lngMablaghTakhfifDaryaft bigint,


@dtKharid tpRizeKharid_FactorKharid_Final readonly,
@fldSharhfactor nvarchar(250),
@fldShomarefactor bigint,
@fldShomaresanad bigint,
@fldDate bigint,
@fldCodeTafsili bigint,


@lngHazineHamlVaNaghl bigint,
@lngArzeshAfzode bigint,
@lngMablaghKolFactor bigint,

@lngCodeSandoghDaryaft bigint,
@lngCodeBankDaryaft bigint,

--شرح دریافت
@strSharhNaghd nvarchar(50), 
@strSharhBank nvarchar(50),
@strSharhCheck nvarchar(50),
@strSharhTakhfif nvarchar(50),
@strSharhKoli nvarchar(50),

@strResult nvarchar(25) output,
@strResult2 NVarChar (25) output,
@flagInsert nvarchar(10)
AS
BEGIN
begin transaction AddRecord
			begin try
					--set @MablaghCheckVagozari=@lngMablaghKolCheckMoshtari
					--set @MablaghCheck=@lngMablaghKolCheckHaPardakhti
					declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
					declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@yearFull nvarchar(5),@dateSmall bigint
					declare @fldCodeVasete bigint,@strMoinKamel nvarchar(50),@lngSumPardakht bigint,@lngSumDaryaft bigint,@ShomareDaryaft bigint
					--,@ShomarePardakht bigint,@lngSumPardakht bigint
					set @year=substring(convert(nvarchar(20),@fldDate),3,2)
					set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
					set @month=substring(convert(nvarchar(20),@fldDate),5,2)
					set @day=substring(convert(nvarchar(20),@fldDate),7,2)
					set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
					declare @maxFactor bigint
					set @intRadif=0
					set @fldCodeVasete=0
					----------End Declare and set Init Values----------

			if(@flagKharid='arshive')
				begin
				--delete
					delete from tblRizeBargashtAzKharid
					where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
					IF @@ROWCOUNT = 0
					begin
					set @strResult='NotDeletedRizeBargashtAzKharid'
					rollback transaction DelRecord;
					end
					delete from tblBargashtAzKharid
					where fldShomareSanad=@fldShomareSanad and fldShomareFactorKharid=@fldShomareFactor
					IF @@ROWCOUNT = 0
					begin
					set @strResult='NotDeletedBargashtAzKharid'
					rollback transaction DelRecord;
					end
					delete from tblSodooreSanad
					where fldSanad=@fldShomareSanad
					IF @@ROWCOUNT = 0
					begin
					set @strResult='NotDeletedtblSodooreSanad'
					rollback transaction DelRecord;
					end
					delete from tblDaryaft
					where fldShomareSanad=@fldShomareSanad

					delete from tblCheckeDaryafti
							where fldSanad=@fldShomareSanad and (fldShomareVosool  is  null and fldShomarePardakht  is  null) and fldVaziat is  null
					


				--insert
				----------hamlonaghl and arzeshafzode and BargashtAzKharid--------------
				set @intRadif=@intRadif+1
				execute ToolePaye 'kol',@TooleKol output
				execute ToolePaye 'moin',@Toolemoin output
				execute codemoinhesab 'kharid' ,@CodeMoinHesabhayeDaryaftani output
				set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
				set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
				set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))
				--upd
				execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad

				if @lngHazineHamlVaNaghl>0
				begin
					set @intRadif=@intRadif+1
					execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayeDaryaftani output
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
					--upd
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
				end

				if @lngArzeshAfzode>0
				begin
					set @intRadif=@intRadif+1
					execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayeDaryaftani output
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
					--upd
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
				end
				-----------------end hamlonaghl and arzeshafzode and kharid-------------
				set @intRadif=@intRadif+1
				execute ToolePaye 'kol',@TooleKol output
				execute ToolePaye 'moin',@Toolemoin output
				execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
				set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
				set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
				--بدهکار
				--upd
				execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
				-----------------------daryaft----------------------------------------
				--بررسی شرح های پرداخت
				if (@strSharhNaghd is null or @strSharhNaghd='')
				begin
					set @strSharhNaghd='noneDaryaft'
				end
				if (@strSharhBank is null or @strSharhBank='')
				begin
					set @strSharhBank='noneDaryaft'
				end
				if (@strSharhCheck is null or @strSharhCheck='')
				begin
					set @strSharhCheck='noneDaryaft'
				end
				if (@strSharhTakhfif is null or @strSharhTakhfif='')
				begin
					set @strSharhTakhfif='noneDaryaft'
				end
				--شرح دریافت اصلی فروش
				if (@strSharhKoli is null or @strSharhKoli='')
				begin
					set @strSharhKoli='noneDaryaft'
				end

				--پایان بررسی شرح های دریافت
				set @lngSumDaryaft=(@lngMablaghNaghdDaryaft+@lngMablaghBankDaryaft+@lngMablaghKolCheckHa+@lngMablaghTakhfifDaryaft)

				if(@lngSumDaryaft>0)
				begin
					set @intRadif=@intRadif+1
					execute ToolePaye 'kol',@TooleKol output
					execute ToolePaye 'moin',@Toolemoin output
					execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
					--بدهکار
					--upd
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
				end

				if @lngMablaghNaghdDaryaft>0
				begin
									--صندوق
					set @intRadif=@intRadif+1
					set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad								
					--execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@lngMablaghNaghdPardakht,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				end
				--سند بانک
				if @lngMablaghBankDaryaft>0
				--begin
				--	set @intRadif =@intRadif+1

				--	set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
				--	set @strMoinKamel=@CodeKolBank + @CodeMoinBank
				--	--upd
				--	execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@lngMablaghBankPardakht,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				--end
				begin
					set @intRadif=@intRadif+1
					set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
					--	execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@lngMablaghBankPardakht,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				end 
				--سند چک
				if @lngMablaghKolCheckHa>0
				--begin
				--	set @intRadif =@intRadif+1

				--	set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
				--	set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
				--	--upd
				--	execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',@lngMablaghKolCheckHaPardakhti,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				--end
				begin
					set @intRadif=@intRadif+1
					execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
					--	execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',@lngMablaghKolCheckHaPardakhti,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				end 
				

				if @lngMablaghTakhfifDaryaft>0
				--begin
				--	set @intRadif =@intRadif+1
				--	set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
				--	set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
				--	--upd
				--	execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,@lngMablaghTakhfifPardakht,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				--end
				begin
					set @intRadif=@intRadif+1

					execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
					--	execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,@lngMablaghTakhfifPardakht,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
				end 

				set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
				if @lngSumDaryaft>0
					begin
						set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
						set @ShomareDaryaft=@ShomareDaryaft+1
						--ثبت دریافت 
						INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
										VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'bargashtazkharid')

						--ثبت ریز اطلاعات چک	
						Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
								Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
						
						delete tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and  fldvaziat is null and fldShomareCheck in (Select fldShomareCheck from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)
					end

				-----------------------factor--------------------------------------

				set @maxFactor=@fldShomarefactor


				INSERT INTO tblBargashtAzKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
					values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
					INSERT INTO tblRizeBargashtAzKharid([fldShomareSanad],[fldShomareFactor]
					,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
					,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
					,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
					,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
					,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
					,[fldHamloNaghl],[fldGhymatMasrafkonande])
					select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
					,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
					,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
					,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
					,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
					,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
					,[fldGhymatMasrafkonande]
					output from @dtKharid;
					set @strResult=convert(nvarchar(17),@maxFactor)
					set @strResult2='update'
					set @flagInsert='yes'
				end
			else if(@flagKharid='insert')
				begin
				    declare @resultExist bigint
					execute ExistFactorBargashtAzKharid @fldShomareFactor,@resultExist output
					declare @maxFactorKharidForKarbar bigint
					execute GetMaxShomareFactorBargashtAzkharid @maxFactorKharidForKarbar output
					set @maxFactorKharidForKarbar=@maxFactorKharidForKarbar+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactorKharidForKarbar)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					else if(@resultExist=0 and @flagInsert='yes')
					    begin
						 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
						--ehsan test
							--declare @resultExist bigint
							execute ExistFactorBargashtAzKharid @fldShomareFactor,@resultExist output
							--declare @maxFactorKharidForKarbar bigint
							--execute GetMaxShomareFactorBargashtAzKharid @maxFactorKharidForKarbar output
							set @maxFactorKharidForKarbar=@fldShomarefactor
							--set @maxFactorKharidForKarbar=@maxFactorKharidForKarbar+1
						
							if(@resultExist>0)
								begin
								--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
									set @strResult=convert(nvarchar(17),@maxFactorKharidForKarbar)
									set @strResult2='New_Enter'
									rollback transaction AddRecord;
									return
									--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
									--yes
										--insert
									--no
										--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								end 
						--ehsan test end
									----------hamlonaghl and arzeshafzode and kharid--------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output									
									execute codemoinhesab 'kharid' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))									
									execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad out

									if @lngHazineHamlVaNaghl>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngArzeshAfzode>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end
									-----------------end hamlonaghl and arzeshafzode and kharid-------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--بستانکار
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									-----------------------pardakht----------------------------------------
									--بررسی شرح های پرداخت
									if (@strSharhNaghd is null or @strSharhNaghd='')
									begin
									set @strSharhNaghd='noneDaryaft'
									end
									if (@strSharhBank is null or @strSharhBank='')
									begin
									set @strSharhBank='noneDaryaft'
									end
									if (@strSharhCheck is null or @strSharhCheck='')
									begin
									set @strSharhCheck='noneDaryaft'
									end
									if (@strSharhTakhfif is null or @strSharhTakhfif='')
									begin
									set @strSharhTakhfif='noneDaryaft'
									end
									--شرح دریافت اصلی فروش
									if (@strSharhKoli is null or @strSharhKoli='')
									begin
									set @strSharhKoli='noneDaryaft'
									end

									--پایان بررسی شرح های پرداخت
									set @lngSumDaryaft=(@lngMablaghNaghdDaryaft+@lngMablaghBankDaryaft+@lngMablaghKolCheckHa+@lngMablaghTakhfifDaryaft)

									if(@lngSumDaryaft>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--بدهکار
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdDaryaft>0
									begin
									--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad								
									--execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@lngMablaghNaghdPardakht,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
								end
									--سند بانک
									if @lngMablaghBankDaryaft>0
										begin
											--set @intRadif =@intRadif+1

											--set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
											--set @strMoinKamel=@CodeKolBank + @CodeMoinBank
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
											set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											--upd
											--execute insertSanadLast @CodeKolkham,@CodeMoinKham,@strMoinKamel,NUll,NULL,@lngMablaghBankdaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									--سند چک
									if @lngMablaghKolCheckHa>0
										begin
											set @intRadif=@intRadif+1
											execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
											----upd
											--execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',@lngMablaghKolCheckHaPardakhti,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;							
											  execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									

									if @lngMablaghTakhfifDaryaft>0
									begin
										--set @intRadif =@intRadif+1
										--set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
										--set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
										----upd
										--execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,@lngMablaghTakhfifPardakht,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
										set @intRadif=@intRadif+1

										execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
										set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)												
										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end
									

									if @lngSumDaryaft>0
										begin
											set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
											set @ShomareDaryaft=@ShomareDaryaft+1
											--ثبت دریافت
											INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
															VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'bargashtazkharid')

											--ثبت ریز اطلاعات چک	
											Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
													Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
										end 

									-----------------------factor--------------------------------------

									--execute GetMaxShomareFactorKharid @maxFactor output
									set @maxFactor=@maxFactorKharidForKarbar

									INSERT INTO tblBargashtAzKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
									INSERT INTO tblRizeBargashtAzKharid([fldShomareSanad],[fldShomareFactor]
									,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
									,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
									,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
									,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
									,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
									,[fldHamloNaghl],[fldGhymatMasrafkonande])
									select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
									,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
									,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
									,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
									,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
									,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
									,[fldGhymatMasrafkonande]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byKarbar'
						end
					else if(@resultExist=0 and @flagInsert='no')
					    begin
						
									----------hamlonaghl and arzeshafzode and kharid--------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'kharid' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))
									--upd
									execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad out

									if @lngHazineHamlVaNaghl>0
									begin
										set @intRadif=@intRadif+1
										execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayeDaryaftani output
										set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
										--upd
										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngArzeshAfzode>0
										begin
											set @intRadif=@intRadif+1
											execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayeDaryaftani output
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
											--upd
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									-----------------end hamlonaghl and arzeshafzode and kharid-------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--بستانکار
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									-----------------------pardakht----------------------------------------
									--بررسی شرح های پرداخت
									if (@strSharhNaghd is null or @strSharhNaghd='')
										begin
										set @strSharhNaghd='noneDaryaft'
										end
									if (@strSharhBank is null or @strSharhBank='')
										begin
										set @strSharhBank='noneDaryaft'
										end
									if (@strSharhCheck is null or @strSharhCheck='')
										begin
										set @strSharhCheck='noneDaryaft'
										end
									if (@strSharhTakhfif is null or @strSharhTakhfif='')
										begin
										set @strSharhTakhfif='noneDaryaft'
										end
									--شرح دریافت اصلی فروش
									if (@strSharhKoli is null or @strSharhKoli='')
										begin
										set @strSharhKoli='noneDaryaft'
										end

									--پایان بررسی شرح های پرداخت
									set @lngSumDaryaft=(@lngMablaghNaghdDaryaft+@lngMablaghBankDaryaft+@lngMablaghKolCheckHa+@lngMablaghTakhfifDaryaft)

									if(@lngSumDaryaft>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
									--بدهکار
									--upd
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdDaryaft>0
										begin
											--set @intRadif =@intRadif+1
											--set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
											--set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
											----upd
											--execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@lngMablaghNaghdPardakht,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
											set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									--سند بانک
									if @lngMablaghBankDaryaft>0
										begin
											--set @intRadif =@intRadif+1

											--set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
											--set @strMoinKamel=@CodeKolBank + @CodeMoinBank
											----upd
											--execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@lngMablaghBankPardakht,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
											set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									--سند چک
									--if @lngMablaghKolCheckHaPardakhti>0
									--begin
									--set @intRadif =@intRadif+1

									--set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
									--set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
									----upd
									--execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',@lngMablaghKolCheckHaPardakhti,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
									--end
									if @intHasRowCheckDaryafti>0
										begin
											set @intRadif=@intRadif+1
											execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end 
									

									--if @lngMablaghTakhfifPardakht>0
									--begin
									--set @intRadif =@intRadif+1
									--set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
									--set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
									----upd
									--execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,@lngMablaghTakhfifPardakht,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad;
									--end
									if @lngMablaghTakhfifDaryaft>0
										begin
											set @intRadif=@intRadif+1
											
											execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
											set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end 
									if @lngSumDaryaft>0
										begin
											set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
											set @ShomareDaryaft=@ShomareDaryaft+1
											--ثبت دریافت اصلی 
											INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
															VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'bargashtazkharid')

											--ثبت ریز اطلاعات چک	
											Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
													Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
										end

									-----------------------factor--------------------------------------

									--execute GetMaxShomareFactorKharid @maxFactor output
									set @maxFactor=@fldShomareFactor

									INSERT INTO tblBargashtAzKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
									INSERT INTO tblRizeBargashtAzKharid([fldShomareSanad],[fldShomareFactor]
									,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
									,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
									,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
									,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
									,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
									,[fldHamloNaghl],[fldGhymatMasrafkonande])
									select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
									,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
									,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
									,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
									,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
									,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
									,[fldGhymatMasrafkonande]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byNo'
						end
			

			end--aaaa



			if @flagInsert='yes'
				begin
					update tblSodooreSanad
					--set fldSharh ='برگشت از خرید شماره ' + convert(nvarchar(17),@maxFactor)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'none'
					update tblSodooreSanad
					--set fldSharh ='برگشت از خرید شماره ' + convert(nvarchar(17),@maxFactor) + ' - شماره دریافت ' + convert(nvarchar(17),@ShomareDaryaft)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end
			else
				begin
					update tblSodooreSanad
					--set fldSharh ='برگشت از خرید شماره ' + convert(nvarchar(17),@fldShomarefactor)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'none'

					update tblSodooreSanad
					--set fldSharh ='برگشت از خرید شماره ' + convert(nvarchar(17),@fldShomarefactor) + ' - شماره دریافت ' + convert(nvarchar(17),@ShomareDaryaft)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end

			commit transaction AddRecord;
   end try
		begin catch
			if @@TranCount>0
				begin
					set @strResult='error'
					set @strResult2='error'
					rollback transaction AddRecord;
				end
		end catch


END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoEnteghal]
	@dtForoosh tpRizeForoosh_Enteghal readonly,
	@dtKharid tpRizeKharid_Enteghal readonly,
	@fldShomareEnteghal bigint,
	@fldCodeAnbar_out bigint,
	@fldCodeAshkhas_out bigint,
	@fldCodeAnbar_in bigint,
	@fldCodeAshkhas_in bigint,
	@strResult nvarchar(25) output,
    @InsertType nvarchar(50)
	
AS
BEGIN

	SET NOCOUNT ON;

        begin transaction AddRecord
             declare @lngCountEnteghal bigint
             begin try  --try

			                  set @lngCountEnteghal=(Select Count(fldShomareEnteghal) from tblRizeForoosh Where fldShomareEnteghal=@fldShomareEnteghal)
					          if ( @lngCountEnteghal = 0)
							    begin
									if @InsertType='insert'
									  begin
									INSERT INTO [dbo].[tblRizeForoosh]
										   ([fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareEnteghal])
											SELECT
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,@fldCodeAshkhas_out
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,@fldCodeAnbar_out
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,@fldShomareEnteghal 
										   output from @dtForoosh


																		   --ثبت انبار وارده ریز خرید
									INSERT INTO [dbo].[tblRizeKharid]
												(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareEnteghal]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareEnteghal])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareEnteghal
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,@fldCodeAshkhas_in
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,@fldCodeAnbar_in
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,@fldShomareEnteghal 

												output from @dtKharid;

										set @strResult='insertOk'

											end --flag insert
									end --count rowShomare Enteghal

							--set @lngCountEnteghal=(Select Count(fldShomareEnteghal) from tblRizeForoosh Where fldShomareEnteghal=@fldShomareEnteghal)
							if ( @lngCountEnteghal > 0)
									begin
										if @InsertType='archive'
										  begin
											delete from tblRizeForoosh where fldShomareEnteghal=@fldShomareEnteghal and fldType='enteghal'
											delete from tblRizeKharid where fldShomareEnteghal=@fldShomareEnteghal and fldType='enteghal'

										INSERT INTO [dbo].[tblRizeForoosh]
												([fldShomareSanad]
												,[fldShomareFactor]
												,[fldCodeVasete]
												,[fldCodeTafsili]
												,[fldCodeUser]
												,[fldRadif]
												,[fldCodeAnbar]
												,[fldCodeKala]
												,[fldSharhKala]
												,[fldTedadCarton]
												,[fldTedadJoz]
												,[fldFeeJoz]
												,[fldFeeYekCarton]
												,[fldFeeKol]
												,[fldDarsadTakhfif]
												,[fldMablaghTakhfif]
												,[fldFeeVahed1BadAzTakhfif]
												,[fldFeeVahed2BadAzTakhfif]
												,[fldArzeshAfzode]
												,[fldFeeKolBadAzTakhfif]
												,[fldMablaghKhales]
												,[fldType]
												,[fldDate]
												,[fldTime]
												,[fldShomareEnteghal])
												SELECT
												[fldShomareSanad]
												,[fldShomareFactor]
												,[fldCodeVasete]
												,@fldCodeAshkhas_out
												,[fldCodeUser]
												,[fldRadif]
												,@fldCodeAnbar_out
												,[fldCodeKala]
												,[fldSharhKala]
												,[fldTedadCarton]
												,[fldTedadJoz]
												,[fldFeeJoz]
												,[fldFeeYekCarton]
												,[fldFeeKol]
												,[fldDarsadTakhfif]
												,[fldMablaghTakhfif]
												,[fldFeeVahed1BadAzTakhfif]
												,[fldFeeVahed2BadAzTakhfif]
												,[fldArzeshAfzode]
												,[fldFeeKolBadAzTakhfif]
												,[fldMablaghKhales]
												,[fldType]
												,[fldDate]
												,[fldTime]
												,@fldShomareEnteghal 
												output from @dtForoosh


								--ثبت انبار وارده ریز خرید
												INSERT INTO [dbo].[tblRizeKharid]
															(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareEnteghal]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareEnteghal])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareEnteghal
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,@fldCodeAshkhas_in
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,@fldCodeAnbar_in
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,@fldShomareEnteghal 

												output from @dtKharid;


															set @strResult='insertArchiveOk'
															end

												else 
													begin
														if @InsertType='insert'
														   begin
														    set @strResult='error_tekrari_insert'
														      rollback transaction 
														       return
														   end
													 end
												end

																							

				              commit transaction AddRecord;

           end try    --try

		  begin catch
		   if @@TranCount > 0
			 begin
				set @strResult='error'
				rollback transaction AddRecord;
			  end
		   end catch
   
		END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoForoosh]
	@flagForoosh nvarchar(10),
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

    @fldShomareFactor bigint,
    @fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizeForoosh  readonly,
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,
	@lngMablaghKolCheckHa bigint,
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft bigint,
    @lngMablaghBankDaryaft bigint,
	@lngMablaghTakhfifDaryaft bigint,
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	--شرح دریافت
	@strSharhNaghd nvarchar(50), 
	@strSharhBank nvarchar(50),
	@strSharhCheck nvarchar(50),
	@strSharhTakhfif nvarchar(50),
	@strSharhKoli nvarchar(50),
	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
AS
BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomareDaryaft bigint,@yearFull nvarchar(5),@dateSmall bigint
			declare @CodeMoinHoghoogh nvarchar(10),@CodeMoinHesabhayePardakhtani nvarchar(10)

			set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @month=substring(convert(nvarchar(20),@fldDate),5,2)
			set @day=substring(convert(nvarchar(20),@fldDate),7,2)
			set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
			declare @lngSumDaryaft bigint
			set @intRadif=0
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'

			if @flagForoosh='arshive'
				begin
					--arishive
					--update(delete and insert)
					--delete
					delete from tblRizeForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblForoosh
						where fldShomareSanad=@fldShomareSanad

					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad

					delete from tblDaryaft
						where fldShomareSanad=@fldShomareSanad

					delete from tblCheckeDaryafti
						where fldSanad=@fldShomareSanad and (fldShomareVosool  is  null and fldShomarePardakht  is  null) and fldVaziat is  null
						--where fldSanad=@fldShomareSanad  

					--insert
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--چون در حالت ویرایش میباشد از لست استفاده کردم
							
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end
							
							if @lngArzeshAfzode>0
							begin 
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='noneDaryaft'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--declare @lngSumDaryaft bigint
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if(@lngSumDaryaft>0)
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end 
							--سند پورسانت واسطه ها و ویزیتور ها
							--if @lngMablaghPorsant>0
							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end 
									
								end 

							

								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	

									delete tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and  fldvaziat is null and fldShomareCheck in (Select fldShomareCheck from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)
								end 

							
							INSERT INTO tblForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))
								 
							 INSERT INTO tblRizeForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;






					set @strResult='update'
					set @strResult2='update'
					
					--commit transaction AddRecord;
					--return
				end
				--تا اینجا تفصیلی ها به روز  شدند
			else if @flagForoosh='insert'
				begin
				--insert
						
					declare @resultExist bigint
					execute ExistFactorForoosh @fldShomareFactor,@resultExist output
					declare @maxFactor bigint
					execute GetMaxShomareFactorForoosh @maxFactor output
					set @maxFactor=@maxFactor+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					 else if(@resultExist=0 and @flagInsert='yes')
					 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
					     begin
						
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
								
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or  @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='none'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							--declare @lngSumDaryaft bigint
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end

							--سند پورسانت واسطه ها و ویزیتور ها
							--if @lngMablaghPorsant>0
							--	begin									
							--		set @intRadif=@intRadif+1
									
							--		execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
							--		set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


							--		set @intRadif=@intRadif+1									
							--		execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
							--		set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
									
							--	end 

							----### سند سوپروایزر####
							--if @lngMablaghPorsantSuperVizor>0
							--	begin								
							--		set @intRadif=@intRadif+1
									
							--		execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
							--		set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


							--		set @intRadif=@intRadif+1									
							--		execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
							--		set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
							--	end 

							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end 
									
								end 

								--پایان سند پورسانت واسطه ها و ویزیتور ها 

								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@maxFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizeForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select @fldShomareSanad
						   ,@maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='insert'
							--commit transaction AddRecord;
						end
					else if(@resultExist=0 and @flagInsert='no')
						 begin
						
							set @intRadif=@intRadif+1
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
							if @lngHazineHamlVaNaghl>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'hamlvanaghl' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end
							if @lngArzeshAfzode>0
							begin
								set @intRadif=@intRadif+1
								execute codemoinhesab 'arzesheafzoode' ,@CodeMoinHesabhayeDaryaftani output
								set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
								set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,0,@lngArzeshAfzode,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							end 

							set @intRadif=@intRadif+1
							execute codemoinhesab 'foroosh' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
							set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngsum,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							--بررسی شرح های دریافت
							if (@strSharhNaghd is null or @strSharhNaghd='')
								begin
									set @strSharhNaghd='noneDaryaft'
								end 
							if (@strSharhBank is null or @strSharhBank='')
								begin
									set @strSharhBank='noneDaryaft'
								end 
							if (@strSharhCheck is null or @strSharhCheck='')
								begin
									set @strSharhCheck='noneDaryaft'
								end 
							if (@strSharhTakhfif is null or @strSharhTakhfif='')
								begin
									set @strSharhTakhfif='noneDaryaft'
								end 
							--شرح دریافت اصلی فروش
							if (@strSharhKoli is null or @strSharhKoli='')
								begin
									set @strSharhKoli='noneDaryaft'
								end 
	
							--پایان بررسی شرح های دریافت

							if @lngMablaghNaghdDaryaft>0
								begin
								--صندوق
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeSandoghDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghNaghdDaryaft,0,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghBankDaryaft,0,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @intHasRowCheckDaryafti>0
								begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'check' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
					
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolCheckHa,0,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

							if @lngMablaghTakhfifDaryaft>0
								begin
									set @intRadif=@intRadif+1

									execute codemoinhesab 'takhfifatedaryaft' ,@CodeMoinHesabhayeDaryaftani output
									set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,null,null,@lngMablaghTakhfifDaryaft,0,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								end 

								--ح س دریافتنی
							
							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output
							execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
							set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
							
							set @lngSumDaryaft=(@lngMablaghTakhfifDaryaft+@lngMablaghBankDaryaft+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
							end 



							--سند پورسانت واسطه ها و ویزیتور ها
							--if @lngMablaghPorsant>0
							--	begin									
							--		set @intRadif=@intRadif+1
									
							--		execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
							--		set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


							--		set @intRadif=@intRadif+1									
							--		execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
							--		set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
									
							--	end 

							----### سند سوپروایزر####
							--if @lngMablaghPorsantSuperVizor>0
							--	begin								
							--		set @intRadif=@intRadif+1
									
							--		execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
							--		set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


							--		set @intRadif=@intRadif+1									
							--		execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
							--		set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
							--		set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
							--		--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
							--		execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
							--	end 
							if isnumeric(@fldCodeVasete )=1  and Convert(dec,@fldCodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'foroosh','',@fldShomareSanad
										end 
									
								end 



								--پایان سند پورسانت واسطه ها و ویزیتور ها 
								if @lngSumDaryaft>0
								begin
									set @ShomareDaryaft=(select isnull(max(fldShomareDaryaft),0) as fldMax from tblDaryaft)
									set @ShomareDaryaft=@ShomareDaryaft+1
									--ثبت دریافت اصلی فروش
									INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
													VALUES        (@ShomareDaryaft,@fldShomareSanad,@fldCodeTafsili,'foroosh')

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizeForoosh
													   ([fldShomareSanad]
													   ,[fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime])
														select @fldShomareSanad
														--edit
													   ,@fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@fldShomareFactor)
							set @strResult2='insertByNo'
							--commit transaction AddRecord
						end
						
				end
			--set @strResult='errorx'
			--set @strResult2='errorx'
			--update sharh Ha
			--@fldShomarefactor dar khat zir bayad avaz beshe (shayad =>@fldShomarefactorNew )
			 if @flagInsert='yes'
				begin
					update  tblSodooreSanad
							--set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@maxFactor)
							set fldSharh ='' 
							where fldSanad=@fldShomareSanad and fldSharh like 'none'
					update  tblSodooreSanad
							--set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@maxFactor) + ' - شماره دریافت ' +  convert(nvarchar(17),@ShomareDaryaft) 
							set fldSharh ='' 
							where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end
			else
				begin
					 update  tblSodooreSanad
							--set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@fldShomarefactor)
							set fldSharh =''
							where fldSanad=@fldShomareSanad and fldSharh like 'none'

					update  tblSodooreSanad
							--set fldSharh ='فاکتور شماره ' + convert(nvarchar(17),@fldShomarefactor) + ' - شماره دریافت ' +  convert(nvarchar(17),@ShomareDaryaft) 
							set fldSharh =''
							where fldSanad=@fldShomareSanad and fldSharh like 'noneDaryaft'
				end


				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				set @strResult2='error'
				rollback transaction AddRecord;
			end
		end catch
END
GO
/****** Object:  StoredProcedure [dbo].[InsertInfoInDaramad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[InsertInfoInDaramad]
--پارامترهای کلی
@InsertType nvarchar(10),
@DateDaryaft int,
@CodeTafzili nvarchar(10),
@ShomareDaryaft bigint,
@ShomareSanadKarbar nvarchar(50),
@SharheKol nvarchar(200),
@CodeMoinDaramad nvarchar(10),
@day nvarchar(50),
@month nvarchar(50),
@year nvarchar(50),
@TypeDaryaft nvarchar(10),


--پارامترهای صندوق
@CodeKolSandoogh nvarchar(10),
@CodeMoinSandoogh nvarchar(10),
@Naghd decimal,
@SNaghd nvarchar(200),

--'پارامترهای بانک
@CodeKolBank nvarchar(10),
@CodeMoinBank nvarchar(10),
@Bank decimal,
@SBank nvarchar(200),

--'پارامترهای چک
@tblCheck tblCheckDaryafti readonly,
@CodeKolCheck nvarchar(10),
@CodeMoinCheck nvarchar(10),
@MablaghCheck decimal,
@SCheck nvarchar(200),

--پارامترهای تخفیفات
@CodeKoltakhfifat nvarchar(10),
@CodeMoinTakhfifateDaryaft nvarchar(10),
@Takhfif decimal,
@STakhfif nvarchar(200),


--پارامترهای واسطه
@CodeVasete nvarchar(10),





@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as

begin
	begin transaction transact
		begin try
			declare @MaxSanad bigint,@lngI bigint,@lngCount bigint,@strShomareSanad nvarchar(50),@lngCountDaryaft int,@IDOutPut bigint,@decJam decimal	
			declare @TooleKol bigint,@TooleMoin bigint,@ShomareSanadArchive nvarchar(50),@DateKamel int
	 
			 execute  ToolePaye 'kol',@TooleKol output
			 execute  ToolePaye 'moin',@Toolemoin output

			 execute  Date9raghami @datedaryaft,@datekamel output

			 set @lngCountDaryaft=(Select Count(fldShomareDaryaft) from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft);

			 set @decjam=@naghd+@bank +@MablaghCheck+ @Takhfif ;

			 if @lngCountDaryaft>0 
				begin
					if @InsertType='archive'  --برای حالتی که میخاد بروزرسانی کنه
						begin
							--Insert into tblTest5(name1,name2)
							--	values ('a','a')
							--declare @ShomareSanadArchive nvarchar(50)

							set @ShomareSanadArchive=(select fldShomareSanad from tblDaryaft where fldShomareDaryaft=@shomaredaryaft)
							--Insert into tblTest7(fld2)
							--	values (@ShomareSanadArchive)
							delete from tblSodooreSanad Where fldSanad=@ShomareSanadArchive
							delete from tblCheckeDaryafti where fldSanad=@ShomareSanadArchive  and fldVaziat is null
							delete from tblDaryaft where fldShomareSanad=@ShomareSanadArchive
							set @noekhata='update_archive'
							--set @noekhata=3

						end
					else
						--set @NoeKhata='error_tekrari_insert'
						--return
					--else
						begin
							if @InsertType='insert' -- برای حالتی که جدید میخاد ثبت کنه ولی یکم قبلش یک کاربر دیگه ثبت میکنه
								begin
									--Insert into tblTest7(fld1)
									--	values ('er in')
									set @NoeKhata='error_tekrari_insert'
									rollback transaction 
									return
									--set @NoeKhata=2
								end
						end
				end
			--else -- برای حالتی که شماره دریافت جدیده 
			--	begin
					declare @CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@intRadif int,@strRadif nvarchar(50),@strMoinKamel nvarchar(12)
					declare @ResultSanad nvarchar(10)
					--set @CodeKolHesabDaryaftani= substring('11301',2,2)
					--insert into tblTest7 (fld2,fld3)
					--	values(@TooleKol,@Toolemoin)
			
					set @CodeKolkham=left(@CodeMoinDaramad,@TooleKol)	
					set @CodeMoinKham=substring(@CodeMoinDaramad,@TooleKol+1,@Toolemoin)
			
					set @intRadif=0;

					--سند نقد
			
					execute IsArchiveShomareSanad @ShomareSanadKarbar,@ResultSanad output

					--Insert into tblTest7(fld1)
					--			values (@ResultSanad)

					if @naghd>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
							
							
							if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
								begin
									execute insertSanadFirst  @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@Naghd,0,@strRadif,@DateDaryaft,@SNaghd,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
								end
							else	
								begin							
								  execute insertSanadLast @CodeKolSandoogh,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Naghd,0,@strRadif,@DateDaryaft,@SNaghd,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
								  set @strShomareSanad=@ShomareSanadKarbar
								end
							--insert into tblTest7 (fld1)
								--values(@strShomareSanad)
						end
					--سند بانک
					if @Bank>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolBank + @CodeMoinBank
					
							--insert into tblTest7 (fld1)
							--	values(@CodeKolBank + @CodeMoinBank)
							--execute insertSanadFirst  @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,'daryaft',@strShomareSanad output	;
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
						end
					--سند چک
					if @MablaghCheck>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,NUll,NULL,@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daryaft',@strShomareSanad output	;
						end
					--سند تخفیفات
					if @Takhfif>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinTakhfifateDaryaft,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifateDaryaft

							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;										
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daryaft',@strShomareSanad output	;
						end
					--سند بستانکاری
					set @intRadif =@intRadif+1			
					set @strRadif=convert(nvarchar(50),@intRadif)
					set @CodeKolkham =substring(@CodeMoinDaramad, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinDaramad,@TooleKol+1,@Toolemoin)
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinDaramad,NULL,'1',0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinDaramad,NULL,'1',0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
						end
					--execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinDaramad,NUll,NUll,@decjam,0,@strRadif,@DateDaryaft,@SharheKol,'daryaft';


					if @Resultsanad='notarchive' 
						begin
							set @strShomareSanad=@ShomareSanadKarbar
						end


					--ثبت ریز اطلاعات چک					
					Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
						Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@CodeTafzili,@Datekamel,@ShomareDaryaft, @CodeVasete,@strShomareSanad output from @tblCheck;	

					delete tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and  fldvaziat is null and fldShomareCheck in (Select fldShomareCheck from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)

					--ثبت اطلاعات دریافت
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomareDaryaft,@strShomareSanad,@CodeTafzili,@TypeDaryaft)
						end
					else
						begin
							INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomareDaryaft,@ShomareSanadKarbar,@CodeTafzili,@TypeDaryaft)
						end

					set @NoeKhata='Insert_New'
		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
					--set @NoeKhata=1
				


			--set @MaxSanad=(Select Max(Convert(dec,fldSanad)) from tblSodooreSanad);	
			--set @MaxSanad+=1;
	
			--INSERT INTO tblSodooreSanad
			--                     (fldSanad)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS Expr1
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1
	


	
			--INSERT INTO tblSodooreSanad
		 --                        (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldType)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS MaxSanad,'111','01','11101',@CodeTafzili,'1',@decjam,0,'1',@DateDaryaft,@SharheKol,'daryaft'
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1

	
			--set @IDOutPut=@@IDENTITY;	

			--set @lngShomareSanad=(Select fldSanad from tblSodooreSanad   where id=@IDOutPut)



                         
	

	
	

end


GO
/****** Object:  StoredProcedure [dbo].[InsertInfoInDaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[InsertInfoInDaryaft]
--پارامترهای کلی
@InsertType nvarchar(10),
@DateDaryaft int,
@CodeTafzili nvarchar(10),
@ShomareDaryaft bigint,
@ShomareSanadKarbar nvarchar(50),
@SharheKol nvarchar(200),
@CodeMoinHesabhayeDaryaftani nvarchar(10),
@day nvarchar(50),
@month nvarchar(50),
@year nvarchar(50),
@TypeDaryaft nvarchar(10),


--پارامترهای صندوق
@CodeKolSandoogh nvarchar(10),
@CodeMoinSandoogh nvarchar(10),
@Naghd decimal,
@SNaghd nvarchar(200),

--'پارامترهای بانک
@CodeKolBank nvarchar(10),
@CodeMoinBank nvarchar(10),
@Bank decimal,
@SBank nvarchar(200),

--'پارامترهای چک
@tblCheck tblCheckDaryafti readonly,
@CodeKolCheck nvarchar(10),
@CodeMoinCheck nvarchar(10),
@MablaghCheck decimal,
@SCheck nvarchar(200),

--پارامترهای تخفیفات
@CodeKoltakhfifat nvarchar(10),
@CodeMoinTakhfifateDaryaft nvarchar(10),
@Takhfif decimal,
@STakhfif nvarchar(200),


--پارامترهای واسطه
@CodeVasete nvarchar(10),
@lngMablaghPorsant bigint,
@fldCodeSuperVizor nvarchar(10),
@lngMablaghPorsantSuperVizor bigint,

--'پارامتر تسویه
@dtTasfie dtTasfie readonly,


@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as

begin
	begin transaction transact
		begin try
			declare @MaxSanad bigint,@lngI bigint,@lngCount bigint,@strShomareSanad nvarchar(50),@lngCountDaryaft int,@IDOutPut bigint,@decJam decimal	
			declare @TooleKol bigint,@TooleMoin bigint,@ShomareSanadArchive nvarchar(50),@DateKamel int
			declare @CodeMoinHoghoogh nvarchar(10),@CodeMoinHesabhayePardakhtani nvarchar(10)

			 execute  ToolePaye 'kol',@TooleKol output
			 execute  ToolePaye 'moin',@Toolemoin output

			 execute  Date9raghami @datedaryaft,@datekamel output

			 set @lngCountDaryaft=(Select Count(fldShomareDaryaft) from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft);

			 set @decjam=@naghd+@bank +@MablaghCheck+ @Takhfif ;

			 if @lngCountDaryaft>0 
				begin
					if @InsertType='archive'  --برای حالتی که میخاد بروزرسانی کنه
						begin
							--Insert into tblTest5(name1,name2)
							--	values ('a','a')
							--declare @ShomareSanadArchive nvarchar(50)

							set @ShomareSanadArchive=(select fldShomareSanad from tblDaryaft where fldShomareDaryaft=@shomaredaryaft)
							--Insert into tblTest7(fld2)
							--	values (@ShomareSanadArchive)
							delete from tblSodooreSanad Where fldSanad=@ShomareSanadArchive
							delete from tblCheckeDaryafti where fldSanad=@ShomareSanadArchive and fldVaziat is null
							delete from tblDaryaft where fldShomareSanad=@ShomareSanadArchive
							delete from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft
							set @noekhata='update_archive'
							--set @noekhata=3

						end
					else
						--set @NoeKhata='error_tekrari_insert'
						--return
					--else
						begin
							if @InsertType='insert' -- برای حالتی که جدید میخاد ثبت کنه ولی یکم قبلش یک کاربر دیگه ثبت میکنه
								begin
									--Insert into tblTest7(fld1)
									--	values ('er in')
									set @NoeKhata='error_tekrari_insert'
									rollback transaction 
									return
									--set @NoeKhata=2
								end
						end
				end
			--else -- برای حالتی که شماره دریافت جدیده 
			--	begin
					declare @CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@intRadif int,@strRadif nvarchar(50),@strMoinKamel nvarchar(12)
					declare @ResultSanad nvarchar(10)
					--set @CodeKolHesabDaryaftani= substring('11301',2,2)
					--insert into tblTest7 (fld2,fld3)
					--	values(@TooleKol,@Toolemoin)
			
					set @CodeKolkham=left(@codemoinhesabhayedaryaftani,@TooleKol)	
					set @CodeMoinKham=substring(@codemoinhesabhayedaryaftani,@TooleKol+1,@Toolemoin)
			
					set @intRadif=0;

					--سند نقد
			
					execute IsArchiveShomareSanad @ShomareSanadKarbar,@ResultSanad output

					--Insert into tblTest7(fld1)
					--			values (@ResultSanad)

					if @naghd>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
							
							
							if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
								begin
									execute insertSanadFirst  @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@Naghd,0,@strRadif,@DateDaryaft,@SNaghd,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
								end
							else	
								begin							
								  execute insertSanadLast @CodeKolSandoogh,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Naghd,0,@strRadif,@DateDaryaft,@SNaghd,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
								  set @strShomareSanad=@ShomareSanadKarbar
								end
							--insert into tblTest7 (fld1)
								--values(@strShomareSanad)
						end
					--سند بانک
					if @Bank>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolBank + @CodeMoinBank
					
							--insert into tblTest7 (fld1)
							--	values(@CodeKolBank + @CodeMoinBank)
							--execute insertSanadFirst  @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,'daryaft',@strShomareSanad output	;
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
						end
					--سند چک
					if @MablaghCheck>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,NUll,NULL,@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daryaft',@strShomareSanad output	;
						end
					--سند تخفیفات
					if @Takhfif>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinTakhfifateDaryaft,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifateDaryaft

							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;										
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daryaft',@strShomareSanad output	;
						end
					--سند بستانکاری
					set @intRadif =@intRadif+1			
					set @strRadif=convert(nvarchar(50),@intRadif)
					set @CodeKolkham =substring(@CodeMoinHesabhayeDaryaftani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayeDaryaftani,@TooleKol+1,@Toolemoin)
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayeDaryaftani,@CodeTafzili,'1',0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayeDaryaftani,@CodeTafzili,'1',0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
						end
					--execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@codemoinhesabhayedaryaftani,NUll,NUll,@decjam,0,@strRadif,@DateDaryaft,@SharheKol,'daryaft';




					--سند پورسانت واسطه ها و ویزیتور ها
							if isnumeric(@CodeVasete )=1  and Convert(dec,@CodeVasete)>0
								begin									
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
									set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
			
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											if @ResultSanad='archive'
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@lngMablaghPorsant,0,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@ShomareSanadKarbar


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											if @ResultSanad='archive'
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'1',0,@lngMablaghPorsant,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@ShomareSanadKarbar
										end

									--### سند سوپروایزر####
									if @lngMablaghPorsantSuperVizor>0
										begin								
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
											set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
											
											if @ResultSanad='archive'
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'1',@lngMablaghPorsantSuperVizor,0,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@ShomareSanadKarbar


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
											if @ResultSanad='archive'
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'1',0,@lngMablaghPorsantSuperVizor,@intRadif,@DateDaryaft,'پورسانت واریزی',@day,@month,@year,'daryaft','',@ShomareSanadKarbar
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 




					if @Resultsanad='notarchive' 
						begin
							set @strShomareSanad=@ShomareSanadKarbar
						end


					--ثبت ریز اطلاعات چک					
					Insert into  tblCheckeDaryafti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
						Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@CodeTafzili,@Datekamel,@ShomareDaryaft,  @CodeVasete,@strShomareSanad output from @tblCheck;	

					delete tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and  fldvaziat is null and fldShomareCheck in (Select fldShomareCheck from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldVaziat is not null)

					--ثبت اطلاعات دریافت
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomareDaryaft,@strShomareSanad,@CodeTafzili,@TypeDaryaft)
						end
					else
						begin
							INSERT  INTO   tblDaryaft( fldShomareDaryaft, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomareDaryaft,@ShomareSanadKarbar,@CodeTafzili,@TypeDaryaft)
						end

					
					INSERT       INTO              tblRizeTasfie( fldShomareFactor, fldShomareDaryaft, fldMablagh)
						Select fldShomareFactor, @ShomareDaryaft, fldMablagh    from  @dtTasfie
									

					set @NoeKhata='Insert_New'
		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
					--set @NoeKhata=1
				


			--set @MaxSanad=(Select Max(Convert(dec,fldSanad)) from tblSodooreSanad);	
			--set @MaxSanad+=1;
	
			--INSERT INTO tblSodooreSanad
			--                     (fldSanad)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS Expr1
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1
	


	
			--INSERT INTO tblSodooreSanad
		 --                        (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldType)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS MaxSanad,'111','01','11101',@CodeTafzili,'1',@decjam,0,'1',@DateDaryaft,@SharheKol,'daryaft'
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1

	
			--set @IDOutPut=@@IDENTITY;	

			--set @lngShomareSanad=(Select fldSanad from tblSodooreSanad   where id=@IDOutPut)



                         
	

	
	

end


GO
/****** Object:  StoredProcedure [dbo].[InsertInfoInPardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[InsertInfoInPardakht]
--پارامترهای کلی
@InsertType nvarchar(10),
@DatePardakht int,
@CodeTafzili nvarchar(10),
@ShomarePardakht bigint,
@ShomareSanadKarbar nvarchar(50),
@SharheKol nvarchar(200),
@CodeMoinHesabhayePardakhtani nvarchar(10),
@day nvarchar(50),
@month nvarchar(50),
@year nvarchar(50),
@TypePardakht nvarchar(20),
@CodeHesabeHazine nvarchar(10),
@CodeNoeTafzili nvarchar(10),


--پارامترهای صندوق
@CodeKolSandoogh nvarchar(10),
@CodeMoinSandoogh nvarchar(10),
@Naghd decimal,
@SNaghd nvarchar(200),

--'پارامترهای بانک
@CodeKolBank nvarchar(10),
@CodeMoinBank nvarchar(10),
@Bank decimal,
@SBank nvarchar(200),

--'پارامترهای چک
@tblCheck tblCheckPardakhti readonly,
@CodeKolCheck nvarchar(10),
@CodeMoinCheck nvarchar(10),
@MablaghCheck decimal,
@SCheck nvarchar(200),

--'پارامترهای چک واگذاری
@CheckeVagozari tblCheckVagozari  readonly,
@CodeKolCheckVagozari nvarchar(10),
@CodeMoinCheckVagozari nvarchar(10),
@MablaghCheckVagozari decimal,
@SCheckVagozari nvarchar(200),

--پارامترهای تخفیفات
@CodeKoltakhfifat nvarchar(10),
@CodeMoinTakhfifatePardakht nvarchar(10),
@Takhfif decimal,
@STakhfif nvarchar(200),


--پارامترهای واسطه
@CodeVasete nvarchar(10),





@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as

begin
	begin transaction transact
		begin try
			declare @MaxSanad bigint,@lngI bigint,@lngCount bigint,@strShomareSanad nvarchar(50),@lngCountPardakht int,@IDOutPut bigint,@decJam decimal	
			declare @TooleKol bigint,@TooleMoin bigint,@ShomareSanadArchive nvarchar(50),@LngCountVagozari bigint,@lngIVagozari bigint,@DateKamel int
	 
			 execute  ToolePaye 'kol',@TooleKol output
			 execute  ToolePaye 'moin',@Toolemoin output

			 execute  Date9raghami @datePardakht,@datekamel output

			 set @lngCountPardakht=(Select Count(fldShomarePardakht) from tblPardakht Where fldShomarePardakht=@ShomarePardakht);

			 set @decjam=@naghd+@bank +@MablaghCheck+ @MablaghCheckVagozari+ @Takhfif ;

			 if @TypePardakht='hazine' and @CodeTafzili=0
				begin
					set @CodeTafzili=''
					set @CodeNoeTafzili=''
				end

			if @TypePardakht='enteghalevajh' 
				begin
					set @CodeTafzili=''
					set @CodeNoeTafzili=''
				end

			 if @lngCountPardakht>0 
				begin
					if @InsertType='archive'  --برای حالتی که میخاد بروزرسانی کنه
						begin
							--Insert into tblTest5(name1,name2)
							--	values ('a','a')
							--declare @ShomareSanadArchive nvarchar(50)

							set @ShomareSanadArchive=(select fldShomareSanad from tblPardakht where fldShomarePardakht=@shomarePardakht)
							--Insert into tblTest7(fld2)
							--	values (@ShomareSanadArchive)
							delete from tblSodooreSanad Where fldSanad=@ShomareSanadArchive
							delete from tblCheckePardakhti where fldSanad=@ShomareSanadArchive
							delete from tblPardakht where fldShomareSanad=@ShomareSanadArchive
							set @noekhata='update_archive'
							--set @noekhata=3

						end
					else
						--set @NoeKhata='error_tekrari_insert'
						--return
					--else
						begin
							if @InsertType='insert' -- برای حالتی که جدید میخاد ثبت کنه ولی یکم قبلش یک کاربر دیگه ثبت میکنه
								begin
									--Insert into tblTest7(fld1)
									--	values ('er in')
									set @NoeKhata='error_tekrari_insert'
									rollback transaction 
									return
									--set @NoeKhata=2
								end
						end
				end
			--else -- برای حالتی که شماره دریافت جدیده 
			--	begin
					declare @CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@intRadif int,@strRadif nvarchar(50),@strMoinKamel nvarchar(12)
					declare @ResultSanad nvarchar(10)
					--set @CodeKolHesabPardakhtani= substring('11301',2,2)
					--insert into tblTest7 (fld2,fld3)
					--	values(@TooleKol,@Toolemoin)
			
					set @CodeKolkham=left(@codemoinhesabhayePardakhtani,@TooleKol)	
					set @CodeMoinKham=substring(@codemoinhesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
					set @intRadif=0;

					--سند نقد
			
					execute IsArchiveShomareSanad @ShomareSanadKarbar,@ResultSanad output

					--Insert into tblTest7(fld1)
					--			values (@ResultSanad)

					if @naghd>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
							
							
							if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
								begin
									execute insertSanadFirst  @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@Naghd,@strRadif,@DatePardakht,@SNaghd,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output	;
								end
							else	
								begin							
								  execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@Naghd,@strRadif,@DatePardakht,@SNaghd,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
								  set @strShomareSanad=@ShomareSanadKarbar
								end
							--insert into tblTest7 (fld1)
								--values(@strShomareSanad)
						end
					--سند بانک
					if @Bank>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolBank + @CodeMoinBank
					
							--insert into tblTest7 (fld1)
							--	values(@CodeKolBank + @CodeMoinBank)
							--execute insertSanadFirst  @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DatePardakht,@SBank,@TypePardakht,@strShomareSanad output	;
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@Bank,@strRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@Bank,@strRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@Bank,@strRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
								end
						end
					--سند چک
					if @MablaghCheck>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,NUll,NULL,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DatePardakht,@SCheck,@TypePardakht,@strShomareSanad output	;
						end
						

					--@CheckeVagozari tblCheckVagozari  readonly,
					--@CodeKolCheckVagozari nvarchar(10),
					--@CodeMoinCheckVagozari nvarchar(10),
					--@MablaghCheckVagozari decimal,
					--@SCheckVagozari nvarchar(200),
					--سند واگذاری چک
						--While @lngIVagozari< @LngCountVagozari-1
						--	begin
								--update tblCheckeDaryafti set fldShomarePardakht=@ShomarePardakht  Where fldShomareCheck= @CheckeVagozari.fldShomarecheck And fldShomareHesab=@CheckeVagozari.fldShomareHesab 
								--UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where fldShomareCheck =@CheckeVagozari.fldShomareCheck
					--ثبت واگذاری چک
					UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)


					--سند حسابداری واگذاری چک
					if @MablaghCheckVagozari>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,NUll,NULL,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DatePardakht,@SCheck,@TypePardakht,@strShomareSanad output	;
						end
						--		--Set @lngiVagozari+=1
						--	end	
						--update tblCheckeDaryafti set fldShomarePardakht=@ShomarePardakht Where fldShomareCheck= @CheckeVagozari.fldShomarecheck And fldShomareHesab=@CheckeVagozari.fldShomareHesab 
						--insert into tblCheckePardakhti (fldShomareCheck) values 
					--سند تخفیفات
					if @Takhfif>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht

							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											execute insertSanadFirst @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@Takhfif,@strRadif,@DatePardakht,@STakhfif,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end
									else
										begin
											execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@Takhfif,@strRadif,@DatePardakht,@STakhfif,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;										
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@Takhfif,@strRadif,@DatePardakht,@STakhfif,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DatePardakht,@SCheck,@TypePardakht,@strShomareSanad output	;
						end
					--سند بدهکاری
					set @intRadif =@intRadif+1			
					set @strRadif=convert(nvarchar(50),@intRadif)

					if @TypePardakht='hazine' 
						begin
							set @CodeMoinHesabhayePardakhtani=@CodeHesabeHazine
						end

					if @TypePardakht='enteghalevajh'
						begin
							--Insert into tblTest5(name1,name2)
							--		values (@CodeMoinHesabhayePardakhtani,@CodeHesabeHazine)
							set @CodeMoinHesabhayePardakhtani=@CodeHesabeHazine
							--Insert into tblTest5(name1,name2)
							--		values (@CodeMoinHesabhayePardakhtani,@CodeHesabeHazine)
						end
					 
				

					set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayePardakhtani,@CodeTafzili,@CodeNoeTafzili,@decjam,0,@strRadif,@DatePardakht,@SharheKol,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayePardakhtani,@CodeTafzili,@CodeNoeTafzili,@decjam,0,@strRadif,@DatePardakht,@SharheKol,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
						end
					--execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@codemoinhesabhayePardakhtani,NUll,NUll,@decjam,0,@strRadif,@DatePardakht,@SharheKol,@TypePardakht;


					if @Resultsanad='notarchive' 
						begin
							set @strShomareSanad=@ShomareSanadKarbar
						end


					--ثبت ریز اطلاعات چک					
					Insert into  tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
						Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@CodeTafzili,@DateKamel,@ShomarePardakht, @CodeVasete,@strShomareSanad output from @tblCheck;	

					--update tblCheckePardakhti set fldShomareCheck=10 where @tblCheck.fld 

					

					--ثبت اطلاعات دریافت
					if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
						begin
							INSERT  INTO   tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomarePardakht,@strShomareSanad,@CodeTafzili,@TypePardakht)
						end
					else
						begin
							INSERT  INTO   tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
								VALUES        (@ShomarePardakht,@ShomareSanadKarbar,@CodeTafzili,@TypePardakht)
						end

					set @NoeKhata='Insert_New'
		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
					--set @NoeKhata=1
				


			--set @MaxSanad=(Select Max(Convert(dec,fldSanad)) from tblSodooreSanad);	
			--set @MaxSanad+=1;
	
			--INSERT INTO tblSodooreSanad
			--                     (fldSanad)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS Expr1
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1
	


	
			--INSERT INTO tblSodooreSanad
		 --                        (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldType)
			--	SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS MaxSanad,'111','01','11101',@CodeTafzili,'1',@decjam,0,'1',@DatePardakht,@SharheKol,@TypePardakht
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1

	
			--set @IDOutPut=@@IDENTITY;	

			--set @lngShomareSanad=(Select fldSanad from tblSodooreSanad   where id=@IDOutPut)



                         
	

	
	

end


GO
/****** Object:  StoredProcedure [dbo].[InsertInfoInTblTanzimatDynamic]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[InsertInfoInTblTanzimatDynamic]
	@strType nvarchar(30),
	@strMeghdar nvarchar(30)
as 

begin
	INSERT       INTO              tblTanzimatDynamic(fldType, fldMeghdar)
				VALUES        (@strtype,@strmeghdar)
end

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoIntblTanzimatKol]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInfoIntblTanzimatKol] 
	@Type nvarchar(50),
	@Meghdar nvarchar(70)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	Delete tblTanzimateKol Where fldtype=@Type

	Insert into tblTanzimateKol
		(fldType,fldMeghdar)
		values
		(@Type,@Meghdar)
END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoKhabanidanCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoKhabanidanCheck] 
@fldIdCheck bigint,
@fldDateVagozariBeBank  int,
@fldTozihateVagozariBeBank  nvarchar(50),
@fldCodeBankVagozari  nvarchar(50),
@Result nvarchar(50) output
    
AS
BEGIN
	
	SET NOCOUNT ON;

   UPDATE [dbo].[tblCheckeDaryafti]
   SET 
     fldDateVagozariBeBank=@fldDateVagozariBeBank, 
     fldTozihateVagozariBeBank=@fldTozihateVagozariBeBank,
     fldVaziat ='Vagozari',
     fldCodeBankVagozari=@fldCodeBankVagozari 
    
 WHERE ID=@fldIdCheck 
    set @Result='UpdateOk'
	
END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInfoKharid]
@flagKharid nvarchar(10),

--@dtCheckPardakhti tblCheckPardakhti readonly,
--@dtCheckMoshtari tblCheckVagozari readonly,
@intHasRowCheckPardakhti int,
@intHasRowCheckMoshtari int,
@lngMablaghKolCheckHaPardakhti bigint,
@lngMablaghKolCheckMoshtari bigint,



@lngMablaghNaghdPardakht bigint,
@lngMablaghBankPardakht bigint,
@lngMablaghTakhfifPardakht bigint,

@dtKharid tpRizeKharid_FactorKharid_Final readonly,
@fldSharhfactor nvarchar(250),
@fldShomarefactor bigint,
@fldShomaresanad bigint,
@fldDate bigint,
@fldCodeTafsili bigint,


@lngHazineHamlVaNaghl bigint,
@lngArzeshAfzode bigint,
@lngMablaghKolFactor bigint,

--@lngCodeSandoghPardakht bigint,
--@lngCodeBankPardakht bigint,


---مرعشی

--پارامترهای صندوق
@CodeKolSandoogh nvarchar(10),
@CodeMoinSandoogh nvarchar(10),
--@Naghd decimal,
--@SNaghd nvarchar(200),

--'پارامترهای بانک
@CodeKolBank nvarchar(10),
@CodeMoinBank nvarchar(10),
--@Bank decimal,
--@SBank nvarchar(200),

--'پارامترهای چک
@tblCheck tblCheckPardakhti readonly,
@CodeKolCheck nvarchar(10),
@CodeMoinCheck nvarchar(10),
--@MablaghCheck decimal,
--@SCheck nvarchar(200),

--'پارامترهای چک واگذاری
@CheckeVagozari tblCheckVagozari readonly,
@CodeKolCheckVagozari nvarchar(10),
@CodeMoinCheckVagozari nvarchar(10),
--@MablaghCheckVagozari decimal,
--@SCheckVagozari nvarchar(200),

--پارامترهای تخفیفات
@CodeKoltakhfifat nvarchar(10),
@CodeMoinTakhfifatePardakht nvarchar(10),
--@Takhfif decimal,
--@STakhfif nvarchar(200),

-----پایان کد مرعشی
--شرح پرداخت
@strSharhNaghd nvarchar(50),
@strSharhBank nvarchar(50),
@strSharhCheck nvarchar(50),
@strSharhCheckMoshtari nvarchar(50),
@strSharhTakhfif nvarchar(50),
@strSharhKoli nvarchar(50),
@strResult nvarchar(25) output,
@strResult2 NVarChar (25) output,
@flagInsert nvarchar(10)
AS
BEGIN
begin transaction AddRecord
			begin try
					--set @MablaghCheckVagozari=@lngMablaghKolCheckMoshtari
					--set @MablaghCheck=@lngMablaghKolCheckHaPardakhti
					declare @intRadif int,@CodeMoinHesabhayePardakhtani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
					declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomarePardakht bigint,@yearFull nvarchar(5),@dateSmall bigint
					declare @fldCodeVasete bigint,@strMoinKamel nvarchar(50),@lngSumPardakht bigint
					--,@ShomarePardakht bigint,@lngSumPardakht bigint
					set @year=substring(convert(nvarchar(20),@fldDate),3,2)
					set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
					set @month=substring(convert(nvarchar(20),@fldDate),5,2)
					set @day=substring(convert(nvarchar(20),@fldDate),7,2)
					set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
					declare @maxFactor bigint
					set @intRadif=0
					set @fldCodeVasete=0
					----------End Declare and set Init Values----------

			if(@flagKharid='arshive')
				begin
					--delete
						delete from tblRizeKharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactor=@fldShomareFactor
						IF @@ROWCOUNT = 0
						begin
						set @strResult='NotDeletedRizeKharid'
						rollback transaction DelRecord;
						end
						delete from tblKharid
						where fldShomareSanad=@fldShomareSanad and fldShomareFactorKharid=@fldShomareFactor
						IF @@ROWCOUNT = 0
						begin
						set @strResult='NotDeletedKharid'
						rollback transaction DelRecord;
						end
						delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
						IF @@ROWCOUNT = 0
						begin
						set @strResult='NotDeletedtblSodooreSanad'
						rollback transaction DelRecord;
						end							
						
						set @ShomarePardakht =(Select  fldShomarePardakht from tblPardakht Where fldShomareSanad = @fldShomareSanad)
						if @ShomarePardakht is not null
							begin
								UPDATE tblCheckeDaryafti Set fldShomarePardakht=NULL Where fldShomarePardakht=@ShomarePardakht 
							end
						
						delete from tblPardakht
						where fldShomareSanad=@fldShomareSanad

						delete from tblCheckePardakhti
						where fldSanad=@fldShomareSanad

						--declare @mm bigint
						--set @mm=(Select  fldShomarePardakht from tblPardakht Where fldShomareSanad = 384)
						

						--INSERT INTO dbo.tblTest5
						--				(name1, name2, name3)
						--				VALUES        (@mm,@fldShomareSanad,'aa')
						


						--INSERT INTO dbo.tblTest5
						--				(name1, name2, name3)
						--				VALUES        (@ShomarePardakht,@fldShomareSanad,'hh')

					--insert
					----------hamlonaghl and arzeshafzode and kharid--------------
					set @intRadif=@intRadif+1
					execute ToolePaye 'kol',@TooleKol output
					execute ToolePaye 'moin',@Toolemoin output
					execute codemoinhesab 'kharid' ,@CodeMoinHesabhayePardakhtani output
					set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
					set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad

					if @lngHazineHamlVaNaghl>0
					begin
						set @intRadif=@intRadif+1
						execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayePardakhtani output
						set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
						set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
						execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
					end

					if @lngArzeshAfzode>0
					begin
						set @intRadif=@intRadif+1
						execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayePardakhtani output
						set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
						set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
						execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
					end
					-----------------end hamlonaghl and arzeshafzode and kharid-------------
					set @intRadif=@intRadif+1
					execute ToolePaye 'kol',@TooleKol output
					execute ToolePaye 'moin',@Toolemoin output
					execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
					set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
					set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
					--بستانکار
					execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
					-----------------------pardakht----------------------------------------
					--بررسی شرح های پرداخت
					if (@strSharhNaghd is null or @strSharhNaghd='')
					begin
						set @strSharhNaghd='nonePardakht'
					end
					if (@strSharhBank is null or @strSharhBank='')
					begin
						set @strSharhBank='nonePardakht'
					end
					if (@strSharhCheck is null or @strSharhCheck='')
					begin
						set @strSharhCheck='nonePardakht'
					end
					if (@strSharhTakhfif is null or @strSharhTakhfif='')
					begin
						set @strSharhTakhfif='nonePardakht'
					end
					--شرح دریافت اصلی فروش
					if (@strSharhKoli is null or @strSharhKoli='')
					begin
						set @strSharhKoli='nonePardakht'
					end

					--پایان بررسی شرح های پرداخت
					set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

					if(@lngSumPardakht>0)
					begin
						set @intRadif=@intRadif+1
						execute ToolePaye 'kol',@TooleKol output
						execute ToolePaye 'moin',@Toolemoin output
						execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
						set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
						set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
						--بدهکار
						execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
					end

					if @lngMablaghNaghdPardakht>0
					begin
						set @intRadif =@intRadif+1
						set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
						set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
						execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
					end
					--سند بانک
					if @lngMablaghBankPardakht>0
					begin
						set @intRadif =@intRadif+1

						set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
						set @strMoinKamel=@CodeKolBank + @CodeMoinBank
						execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
					end
					--سند چک
					if @lngMablaghKolCheckHaPardakhti>0
					begin
						set @intRadif =@intRadif+1

						set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
						set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
						execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
					end
					--سند حسابداری واگذاری چک
					if @lngMablaghKolCheckMoshtari>0
					begin
						set @intRadif =@intRadif+1
						set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
						set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
						execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;

					end

					if @lngMablaghTakhfifPardakht>0
					begin
						set @intRadif =@intRadif+1
						set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
						set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
						execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
					end
					if (@lngSumPardakht>0)
					begin
						set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
						set @ShomarePardakht=@ShomarePardakht+1
						INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
						VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'kharid')

						--ثبت ریز اطلاعات چک
						Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
						Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

						--ثبت واگذاری چک
						UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

					end

					-----------------------factor--------------------------------------

					set @maxFactor=@fldShomarefactor


					INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
						values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
						INSERT INTO tblRizeKharid([fldShomareSanad],[fldShomareFactor]
						,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
						,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
						,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
						,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
						,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
						,[fldHamloNaghl],[fldGhymatMasrafkonande])
						select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
						,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
						,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
						,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
						,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
						,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
						,[fldGhymatMasrafkonande]
						output from @dtKharid;
						set @strResult=convert(nvarchar(17),@maxFactor)
						set @strResult2='update'
						set @flagInsert='yes'
					end


			--########

			else if(@flagKharid='insert')
			begin
				    declare @resultExist bigint
					execute ExistFactorKharid @fldShomareFactor,@resultExist output
					declare @maxFactorKharidForKarbar bigint
					execute GetMaxShomareFactorKharid @maxFactorKharidForKarbar output
					set @maxFactorKharidForKarbar=@maxFactorKharidForKarbar+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactorKharidForKarbar)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					else if(@resultExist=0 and @flagInsert='yes')
					    begin
						 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
						--ehsan test
							--declare @resultExist bigint
							execute ExistFactorKharid @fldShomareFactor,@resultExist output
							--declare @maxFactorKharidForKarbar bigint
							--execute GetMaxShomareFactorKharid @maxFactorKharidForKarbar output
							set @maxFactorKharidForKarbar=@fldShomarefactor
							--set @maxFactorKharidForKarbar=@maxFactorKharidForKarbar+1
						
							if(@resultExist>0)
								begin
								--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
									set @strResult=convert(nvarchar(17),@maxFactorKharidForKarbar)
									set @strResult2='New_Enter'
									rollback transaction AddRecord;
									return
									--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
									--yes
										--insert
									--no
										--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								end 
						--ehsan test end
									----------hamlonaghl and arzeshafzode and kharid--------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'kharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))
									execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad out

									if @lngHazineHamlVaNaghl>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngArzeshAfzode>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end
									-----------------end hamlonaghl and arzeshafzode and kharid-------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بستانکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									-----------------------pardakht----------------------------------------
									--بررسی شرح های پرداخت
									if (@strSharhNaghd is null or @strSharhNaghd='')
									begin
									set @strSharhNaghd='nonePardakht'
									end
									if (@strSharhBank is null or @strSharhBank='')
									begin
									set @strSharhBank='nonePardakht'
									end
									if (@strSharhCheck is null or @strSharhCheck='')
									begin
									set @strSharhCheck='nonePardakht'
									end
									if (@strSharhTakhfif is null or @strSharhTakhfif='')
									begin
									set @strSharhTakhfif='nonePardakht'
									end
									--شرح دریافت اصلی فروش
									if (@strSharhKoli is null or @strSharhKoli='')
									begin
									set @strSharhKoli='nonePardakht'
									end

									--پایان بررسی شرح های پرداخت
									set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

									if(@lngSumPardakht>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بدهکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
									execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند بانک
									if @lngMablaghBankPardakht>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolBank + @CodeMoinBank
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند چک
									if @lngMablaghKolCheckHaPardakhti>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند حسابداری واگذاری چک
									if @lngMablaghKolCheckMoshtari>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
									execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;

									end

									if @lngMablaghTakhfifPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									if (@lngSumPardakht>0)
									begin
									set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
									set @ShomarePardakht=@ShomarePardakht+1
									INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
									VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'kharid')

									--ثبت ریز اطلاعات چک
									Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
									Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

									--ثبت واگذاری چک
									UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

									end

									-----------------------factor--------------------------------------

									--execute GetMaxShomareFactorKharid @maxFactor output
									set @maxFactor=@maxFactorKharidForKarbar

									INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
									INSERT INTO tblRizeKharid([fldShomareSanad],[fldShomareFactor]
									,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
									,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
									,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
									,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
									,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
									,[fldHamloNaghl],[fldGhymatMasrafkonande])
									select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
									,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
									,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
									,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
									,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
									,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
									,[fldGhymatMasrafkonande]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byKarbar'
						end
					else if(@resultExist=0 and @flagInsert='no')
					    begin
						
									----------hamlonaghl and arzeshafzode and kharid--------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'kharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									set @lngsum=(@lngMablaghKolFactor-(@lngHazineHamlVaNaghl+@lngArzeshAfzode))
									execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngsum,0,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad out

									if @lngHazineHamlVaNaghl>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'hazinehamlvanaghlekharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngHazineHamlVaNaghl,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngArzeshAfzode>0
									begin
									set @intRadif=@intRadif+1
									execute codemoinhesab 'arzesheafzoodekharid' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,null,null,@lngArzeshAfzode,0,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end
									-----------------end hamlonaghl and arzeshafzode and kharid-------------
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بستانکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,'none',@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									-----------------------pardakht----------------------------------------
									--بررسی شرح های پرداخت
									if (@strSharhNaghd is null or @strSharhNaghd='')
									begin
									set @strSharhNaghd='nonePardakht'
									end
									if (@strSharhBank is null or @strSharhBank='')
									begin
									set @strSharhBank='nonePardakht'
									end
									if (@strSharhCheck is null or @strSharhCheck='')
									begin
									set @strSharhCheck='nonePardakht'
									end
									if (@strSharhTakhfif is null or @strSharhTakhfif='')
									begin
									set @strSharhTakhfif='nonePardakht'
									end
									--شرح دریافت اصلی فروش
									if (@strSharhKoli is null or @strSharhKoli='')
									begin
									set @strSharhKoli='nonePardakht'
									end

									--پایان بررسی شرح های پرداخت
									set @lngSumPardakht=(@lngMablaghNaghdPardakht+@lngMablaghBankPardakht+@lngMablaghKolCheckHaPardakhti+@lngMablaghKolCheckMoshtari+@lngMablaghTakhfifPardakht)

									if(@lngSumPardakht>0)
									begin
									set @intRadif=@intRadif+1
									execute ToolePaye 'kol',@TooleKol output
									execute ToolePaye 'moin',@Toolemoin output
									execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output
									set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
									--بدهکار
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',@lngSumPardakht,0,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
									end

									if @lngMablaghNaghdPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinSandoogh,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolSandoogh + @CodeMoinSandoogh
									execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,0,@lngMablaghNaghdPardakht,@intRadif,@dateSmall,@strSharhNaghd,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند بانک
									if @lngMablaghBankPardakht>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinBank,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolBank + @CodeMoinBank
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@lngMablaghBankPardakht,@intRadif,@dateSmall,@strSharhBank,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند چک
									if @lngMablaghKolCheckHaPardakhti>0
									begin
									set @intRadif =@intRadif+1

									set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckHaPardakhti,@intRadif,@dateSmall,@strSharhCheck,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									--سند حسابداری واگذاری چک
									if @lngMablaghKolCheckMoshtari>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinCheckVagozari,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKolCheckVagozari + @CodeMoinCheckVagozari
									execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@fldCodeTafsili,'1',0,@lngMablaghKolCheckMoshtari,@intRadif,@dateSmall,@strSharhCheckMoshtari,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;

									end

									if @lngMablaghTakhfifPardakht>0
									begin
									set @intRadif =@intRadif+1
									set @CodeMoinKham=substring(@CodeMoinTakhfifatePardakht,@TooleKol+1,@Toolemoin)
									set @strMoinKamel=@CodeKoltakhfifat + @CodeMoinTakhfifatePardakht
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifatePardakht,@strMoinKamel,NUll,NULL,0,@lngMablaghTakhfifPardakht,@intRadif,@dateSmall,@strSharhTakhfif,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad;
									end
									if (@lngSumPardakht>0)
									begin
									set @ShomarePardakht=(select isnull(max(fldShomarePardakht),0) as fldMax from tblPardakht)
									set @ShomarePardakht=@ShomarePardakht+1
									INSERT INTO tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
									VALUES (@ShomarePardakht,@fldShomareSanad,@fldCodeTafsili,'kharid')

									--ثبت ریز اطلاعات چک
									Insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,fldCodeSahebeCheck,fldDatePardakht,fldShomarePardakht,fldVasete,fldSanad)
									Select fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,@fldCodeTafsili,@fldDate,@ShomarePardakht, @fldCodeVasete,@fldShomareSanad output from @tblCheck;

									--ثبت واگذاری چک
									UPDATE tblCheckeDaryafti Set fldShomarePardakht=@ShomarePardakht Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

									end

									-----------------------factor--------------------------------------

									--execute GetMaxShomareFactorKharid @maxFactor output
									set @maxFactor=@fldShomareFactor

									INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@fldSharhFactor)
									INSERT INTO tblRizeKharid([fldShomareSanad],[fldShomareFactor]
									,[fldCodeVasete],[fldCodeTafsili],[fldCodeUser],[fldRadif],[fldCodeAnbar]
									,[fldCodeKala],[fldSharhKala],[fldTedadCarton],[fldTedadJoz],[fldFeeJoz]
									,[fldFeeYekCarton],[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif]
									,[fldFeeVahed1BadAzTakhfif],[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode]
									,[fldFeeKolBadAzTakhfif],[fldMablaghKhales],[fldType],[fldDate],[fldTime]
									,[fldHamloNaghl],[fldGhymatMasrafkonande])
									select @fldShomareSanad,@maxFactor,[fldCodeVasete],[fldCodeTafsili]
									,[fldCodeUser],[fldRadif],[fldCodeAnbar],[fldCodeKala],[fldSharhKala]
									,[fldTedadCarton],[fldTedadJoz],[fldFeeJoz],[fldFeeYekCarton]
									,[fldFeeKol],[fldDarsadTakhfif],[fldMablaghTakhfif],[fldFeeVahed1BadAzTakhfif]
									,[fldFeeVahed2BadAzTakhfif],[fldArzeshAfzode],[fldFeeKolBadAzTakhfif]
									,[fldMablaghKhales],[fldType],[fldDate],[fldTime],[fldHamloNaghl]
									,[fldGhymatMasrafkonande]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byNo'
						end
			

			end



			if @flagInsert='yes'
				begin
					update tblSodooreSanad
					--set fldSharh ='فاکتور خرید شماره ' + convert(nvarchar(17),@maxFactor)
					set fldSharh ='' 
					where fldSanad=@fldShomareSanad and fldSharh like 'none'
					update tblSodooreSanad
					--set fldSharh ='فاکتور خرید شماره ' + convert(nvarchar(17),@maxFactor) + ' - شماره پرداخت ' + convert(nvarchar(17),@ShomarePardakht)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'nonePardakht'
				end
			else
				begin
					update tblSodooreSanad
					--set fldSharh ='فاکتور خرید شماره ' + convert(nvarchar(17),@fldShomarefactor)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'none'

					update tblSodooreSanad
					--set fldSharh ='فاکتور خرید شماره ' + convert(nvarchar(17),@fldShomarefactor) + ' - شماره پرداخت ' + convert(nvarchar(17),@ShomarePardakht)
					set fldSharh =''
					where fldSanad=@fldShomareSanad and fldSharh like 'nonePardakht'
				end

			commit transaction AddRecord;
   end try
		begin catch
			if @@TranCount>0
				begin
					set @strResult='error'
					set @strResult2='error'
					rollback transaction AddRecord;
				end
		end catch


END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoMojodiEbtedaDoreh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInfoMojodiEbtedaDoreh]
    @dtRizekharid tpRizeKharid_MojodiEbtedaDoreh Readonly,
	@strResult  nvarchar(25) output,
    @InsertType nvarchar(50),

	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	--@fldCodeTafzili nvarchar(50),
	--@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal,
	@fldBestankar  decimal, 
	--@fldRadif nvarchar(50),
	@fldDate int, 
	@fldSharh nvarchar(100),
	@day nvarchar(50),
	@month nvarchar(50),
	@year nvarchar(50),
	@fldType nvarchar(20),
	@vasete nvarchar(10),
	@ShomareSanad nvarchar(50), 
	@fldCodeKolSarmaye nvarchar(50),
	@fldMoinKamelSarmaye nvarchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	   Begin Transaction InsertRow
	     declare @lngCountMojodi bigint
    -- Insert statements for procedure here
	      Begin Try
		          set @lngCountmojodi=(Select Count(fldShomareSanad) from tblRizeKharid Where  fldType='mojodi_ebteda_doreh')
			 if (@lngCountMojodi = 0)
			   Begin
		        if @InsertType='insert'
					begin
						INSERT INTO [dbo].[tblRizeKharid]
								([fldShomareSanad]
								,[fldShomareFactor]
								,[fldCodeVasete]
								,[fldCodeTafsili]
								,[fldCodeUser]
								,[fldRadif]
								,[fldCodeAnbar]
								,[fldCodeKala]
								,[fldSharhKala]
								,[fldTedadCarton]
								,[fldTedadJoz]
								,[fldFeeJoz]
								,[fldFeeYekCarton]
								,[fldFeeKol]
								,[fldDarsadTakhfif]
								,[fldMablaghTakhfif]
								,[fldFeeVahed1BadAzTakhfif]
								,[fldFeeVahed2BadAzTakhfif]
								,[fldArzeshAfzode]
								,[fldFeeKolBadAzTakhfif]
								,[fldMablaghKhales]
								,[fldType]
								,[fldDate]
								,[fldTime]
								,[fldShomareEnteghal])
								SELECT
								 [fldShomareSanad]
								,[fldShomareFactor]
								,[fldCodeVasete]
								,[fldCodeTafsili]
								,[fldCodeUser]
								,[fldRadif]
								,[fldCodeAnbar]
								,[fldCodeKala]
								,[fldSharhKala]
								,[fldTedadCarton]
								,[fldTedadJoz]
								,[fldFeeJoz]
								,[fldFeeYekCarton]
								,[fldFeeKol]
								,[fldDarsadTakhfif]
								,[fldMablaghTakhfif]
								,[fldFeeVahed1BadAzTakhfif]
								,[fldFeeVahed2BadAzTakhfif]
								,[fldArzeshAfzode]
								,[fldFeeKolBadAzTakhfif]
								,[fldMablaghKhales]
								,[fldType]
								,[fldDate]
								,[fldTime]
								,[fldShomareEnteghal]
								output from @dtRizekharid;

								INSERT INTO tblSodooreSanad
												(fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel,
													fldBedehkar, fldBestankar , fldRadif,fldDate ,
													fldSharh,fldday,fldmonth,fldyear,fldvasete,fldType,fldCodeTafzili)
						        values (@ShomareSanad,@fldCodeKol,@fldCodeMoin,@fldMoinKamel,
									    @fldBedehkar,0,'1',@fldDate,@fldSharh,@day,@month,@year,@vasete, @fldType,' ')

								
									INSERT INTO tblSodooreSanad                      --sarmaye
												(fldSanad,fldCodeKol,fldCodeMoin,fldMoinKamel,
													fldBedehkar,fldBestankar,fldRadif,fldDate, 
													fldSharh,fldday,fldmonth,fldyear,fldvasete,fldType,fldCodeTafzili)
									values (@ShomareSanad,@fldCodeKolSarmaye,'',@fldMoinKamelSarmaye,
											0,@fldBestankar,'2',@fldDate,@fldSharh,@day,@month,@year,@vasete,@fldType,' ')


							     set @strResult='insertOk'
                       End
                  End
                
				 if (@lngCountMojodi > 0)
			       Begin
				   Delete from tblSodooreSanad where fldSanad=@ShomareSanad And fldType='mojoodieebteda'
		           Delete from tblRizeKharid where fldShomareSanad=@ShomareSanad And fldType='mojodi_ebteda_doreh'
				      if @InsertType='insert'
					    begin
						INSERT INTO [dbo].[tblRizeKharid]
								([fldShomareSanad]
								,[fldShomareFactor]
								,[fldCodeVasete]
								,[fldCodeTafsili]
								,[fldCodeUser]
								,[fldRadif]
								,[fldCodeAnbar]
								,[fldCodeKala]
								,[fldSharhKala]
								,[fldTedadCarton]
								,[fldTedadJoz]
								,[fldFeeJoz]
								,[fldFeeYekCarton]
								,[fldFeeKol]
								,[fldDarsadTakhfif]
								,[fldMablaghTakhfif]
								,[fldFeeVahed1BadAzTakhfif]
								,[fldFeeVahed2BadAzTakhfif]
								,[fldArzeshAfzode]
								,[fldFeeKolBadAzTakhfif]
								,[fldMablaghKhales]
								,[fldType]
								,[fldDate]
								,[fldTime]
								,[fldShomareEnteghal])
								SELECT
								 [fldShomareSanad]
								,[fldShomareFactor]
								,[fldCodeVasete]
								,[fldCodeTafsili]
								,[fldCodeUser]
								,[fldRadif]
								,[fldCodeAnbar]
								,[fldCodeKala]
								,[fldSharhKala]
								,[fldTedadCarton]
								,[fldTedadJoz]
								,[fldFeeJoz]
								,[fldFeeYekCarton]
								,[fldFeeKol]
								,[fldDarsadTakhfif]
								,[fldMablaghTakhfif]
								,[fldFeeVahed1BadAzTakhfif]
								,[fldFeeVahed2BadAzTakhfif]
								,[fldArzeshAfzode]
								,[fldFeeKolBadAzTakhfif]
								,[fldMablaghKhales]
								,[fldType]
								,[fldDate]
								,[fldTime]
								,[fldShomareEnteghal]
								output from @dtRizekharid;

								INSERT INTO tblSodooreSanad
												(fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel,
													fldBedehkar, fldBestankar , fldRadif,fldDate ,
													fldSharh,fldday,fldmonth,fldyear,fldvasete,fldType,fldCodeTafzili)
						        values (@ShomareSanad,@fldCodeKol,@fldCodeMoin,@fldMoinKamel,
									    @fldBedehkar,0,'1',@fldDate,@fldSharh,@day,@month,@year,@vasete, @fldType,' ')

								
									INSERT INTO tblSodooreSanad                      --sarmaye
												(fldSanad,fldCodeKol,fldCodeMoin,fldMoinKamel,
													fldBedehkar,fldBestankar,fldRadif,fldDate, 
													fldSharh,fldday,fldmonth,fldyear,fldvasete,fldType,fldCodeTafzili)
									values (@ShomareSanad,@fldCodeKolSarmaye,'',@fldMoinKamelSarmaye,
											0,@fldBestankar,'2',@fldDate,@fldSharh,@day,@month,@year,@vasete,@fldType,' ')


							     set @strResult='UpdateArchiveOk'
                       End
				   End

		     Commit Transaction InsertRow; 
		   End Try

			 Begin Catch
			   if @@TRANCOUNT > 0 
			     begin 
				  RollBack Transaction InsertRow;
				     set @strResult='Error'
				 end

			  End Catch

END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoPaseCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInfoPaseCheck]
	@fldShomarePas bigint,
	@fldSanadPas bigint,
	@strResult nvarchar(25) output,
	@InsertType nvarchar(50)null,	
	@Date bigint,
	@tblCheck dtCheckPassMain readonly

AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	begin transaction AddRecord
			declare @lngCountShomarePas bigint,@EmpId bigint,@intRadif bigint,@strRadif nvarchar(50),@CodeMoinKham nvarchar(10),@TooleKol bigint,@TooleMoin bigint,@CodeMoinCheck nvarchar(10),@CodeKolCheck nvarchar(10),@strMoinKamel nvarchar(50),@MablaghCheck bigint,@smallDate nvarchar(15),@strSharheCheck nvarchar(50),@day nvarchar(50),@month nvarchar(50),@year nvarchar(50),@strCodeTafzili nvarchar(50),@CodeNoe nvarchar(10),@CodeVasete nvarchar(50)
			declare @lngCountShomareSanad bigint,@strMoinKamelBank nvarchar(50),@CodeKolBank nvarchar(50),@CodeMoinBank nvarchar(50),@ShomareCheck nvarchar(50) ,@Sharh  nvarchar(70)--,@NoeMohasebePoorsant int,@DarsadePoorsant int,@MablaghePoorsant bigint
			declare @bigShomareSanad bigint
			begin try
				 set @lngCountShomarePas=(select COUNT(fldShomarePas) from tblPas where fldShomarePas=@fldShomarePas) 
				 set @lngCountShomareSanad=(select COUNT(convert(bigint,fldSanad)) from tblSodooreSanad where convert(bigint,fldSanad)=@fldSanadPas)

				 --###############################################################################################
				  if @lngCountShomarePas > 0  --یعنی در حالت اینسرت هستیم و شماره رو زودتر یک نفر ذخیره کرد
				  	 Begin					 
						if @InsertType='insert'
							begin
							set @strResult='error_tekrari_insert'
								rollback transaction 
								return
							end --End Insert
				      end --@lngCoun

				 --###############################################################################################
				if @InsertType='arshive'
					begin
						UPDATE       tblCheckePardakhti
							SET         																					
										fldShomarePass=NULL,
										fldDatePass =NULL,
										fldSharhePass =NULL,
										fldSanadPas =NUll
																	
								where fldShomarePass=@fldShomarePas

							delete from tblSodooreSanad Where fldSanad=@fldSanadPas
							delete from tblPas Where fldShomarePas=@fldShomarePas

							set @bigShomareSanad=@fldSanadPas
							
					end

				 --حالت اینسرت و شماره آزاده
				if @InsertType='insert'
					begin
						
						IF (@lngCountShomareSanad=0) 
							set @bigShomareSanad =@fldSanadPas
						else
							begin
								declare @MaxSanad bigint
								set @MaxSanad=(select max(convert(bigint,fldSanad)) from tblSodooreSanad)
								set @MaxSanad=@MaxSanad+1
								set @bigShomareSanad =@MaxSanad
							end
					 	
							--update tblCheckePardakhti
							--set fldShomareCheck=mm.fldShomareCheck ,
							--	fldShomareHesab=mm.fldShomareHesab,
							--	@fldShomarePas=@fldShomarePas
							--	from @tblCheck as mm
							--	where fldShomareCheck=mm.fldShomareCheck and fldShomareHesab=mm.fldShomareHesab

						

								--UPDATE       tblCheckePardakhti
								--	SET                fldShomareCheck = mm.fldShomareCheck
								--	FROM            @tblCheck as mm CROSS JOIN
								--							 tblCheckePardakhti
						

								--from @dtCheckPas
								--where fldShomareCheck=@dtCheckPas.fldShomareCheck and fldShomareHesab=@dtCheckPas.fldShomareHesab
						
						--update tblCheckePardakhti
						--		set fldShomarePass=@fldShomarePas,
						--		fldSharhePass=@tblCheck.fldTozihat,
						--		fldSanad=@bigShomareSanad
						--	from @tblCheck 
						--		where fldShomareCheck=@tblCheck.fldShomareCheck and fldShomareHesab=@tblCheck.fldShomareHesab


									
							--select * from @tblCheck
									--FROM tblCheckeDaryafti  INNER JOIN @dtCheckPas as P
										--ON tblCheckePardakhti.fldShomareCheck = p.fldShomareCheck
					end


					UPDATE       tblCheckePardakhti
							SET         fldShomareCheck = mm.fldShomareCheck,										
										fldShomarePass=@fldShomarePas,
										fldSanadPas =@bigShomareSanad,
										fldDatePass=@Date,
										fldSharhePass=mm.fldTozihat

							FROM            @tblCheck AS mm INNER JOIN
													 tblCheckePardakhti ON mm.fldShomareCheck = tblCheckePardakhti.fldShomareCheck
			


			declare EmpCursor Cursor For
				SELECT ID  FROM @tblCheck
			--Select Id from tblSodooreSanad With (NoLock) where fldCodeTafzili='1000' ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
				open EmpCursor
				fetch Next From EmpCursor into @EmpId
				While @@Fetch_Status = 0
					Begin	

						--INSERT INTO dbo.tblTest5
						--	(name1, name2, name3)
						--	VALUES        ('','',Convert(varchar,@EmpId))

							execute  ToolePaye 'kol',@TooleKol output
							execute  ToolePaye 'moin',@Toolemoin output

							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)							
							set @CodeMoinKham=substring(@CodeMoinCheck,@TooleKol+1,@Toolemoin)

							execute codemoinhesab 'checkpardakhti' ,@strMoinKamel output

							set @CodeKolCheck =substring(@strMoinKamel, 1, @TooleKol)
							set @CodeMoinCheck =substring(@strMoinKamel,@TooleKol+1,@Toolemoin)

							set @strMoinKamel=@CodeKolCheck + @CodeMoinCheck
							set @MablaghCheck = (Select fldmablagh from @tblCheck  Where id=@EmpId)
							set @strSharheCheck=(Select fldTozihat from @tblCheck  Where id=@EmpId)
							set @smallDate=SUBSTRING(CONVERT(nvarchar, @Date), 3, 6)
							set @day=SUBSTRING(CONVERT(nvarchar, @Date), 7, 2)
							set @month=SUBSTRING(CONVERT(nvarchar, @Date), 5, 2)
							set @year=SUBSTRING(CONVERT(nvarchar, @Date), 3, 2)

							set @strCodeTafzili =(Select fldCodeSahebeCheck from @tblCheck Where id=@EmpId)
							set @CodeNoe =(Select fldCodeNoe from tblTafzili Where fldCodeTafzili=@strCodeTafzili)
							set @CodeVasete = (Select fldVasete from tblCheckePardakhti Where id=@EmpId)


							set @strMoinKamelBank = (Select fldCodeBank from tblCheckePardakhti Where id =@EmpId)
							set @ShomareCheck= (Select fldShomareCheck from tblCheckePardakhti Where id =@EmpId)
							set @Sharh = 'وصول چک شماره ' + @ShomareCheck

							set @CodeKolBank =substring(@strMoinKamelBank, 1, @TooleKol)
							set @CodeMoinBank =substring(@strMoinKamelBank,@TooleKol+1,@Toolemoin)
							--if @intRadif=1
							--	begin
									--if @InsertType='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
									--	begin
											--execute insertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,NUll,NULL,0,@MablaghCheck,@strRadif,strsmalDate ,@strSharheCheck,@day,@month,@year,'pardakht',@CodeVasete,@strShomareSanad;

							--INSERT INTO dbo.tblTest5
							--	(name1, name2, name3)
							--	VALUES        (@CodeKolCheck,@CodeMoinCheck,@strMoinKamel)

							--execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,NUll,NULL,0,@MablaghCheck,@strRadif,strsmalDate ,@strSharheCheck,01,01,96,'pas',0,105;
							if @InsertType='insert' and @intRadif=1
								begin
									execute InsertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@strCodeTafzili,@CodeNoe,@MablaghCheck,0,@intRadif,@smallDate,@strSharheCheck,@day,@month,@year,'pasecheck',@CodeVasete,@bigShomareSanad;
									set @intRadif=2
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamelBank,NULL,NULL,0,@MablaghCheck,@intRadif,@smallDate,@Sharh,@day,@month,@year,'pasecheck',@CodeVasete,@bigShomareSanad;
								end
							else
								begin
									set @intRadif = @intRadif +1
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@strCodeTafzili,@CodeNoe,@MablaghCheck,0,@intRadif,@smallDate,@strSharheCheck,@day,@month,@year,'pasecheck',@CodeVasete,@bigShomareSanad;
									set @intRadif = @intRadif +1
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamelBank,NULL,NULL,0,@MablaghCheck,@intRadif,@smallDate,@Sharh,@day,@month,@year,'pasecheck',@CodeVasete,@bigShomareSanad;
								end

							--set @NoeMohasebePoorsant = (Select fldNoeMohasebePoorsant from tblTafzili Where fldCodeTafzili=@strCodeTafzili)
							--if isnumeric(@NoeMohasebePoorsant )=1
							--	begin
							--		set @DarsadePoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili=@strCodeTafzili)
							--		if @DarsadePoorsant>0  and @NoeMohasebePoorsant =2  --محاسبه براساس واریز
							--			begin
							--				set @MablaghePoorsant = @MablaghCheck * @DarsadePoorsant / 100

							--			end
							--	end

							--			end
							--		else
							--			begin
							--				execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,'pardakht',@CodeVasete,@ShomareSanadKarbar;
							--				set @strShomareSanad=@ShomareSanadKarbar
							--			end
							--	end
							--else
							--	begin
							--		execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,'pardakht',@CodeVasete,@strShomareSanad;
							--	end

						
						Fetch Next from EmpCursor
						into @EmpId
					end
			Close EmpCurSor
			Deallocate EmpCursor


			insert into tblPas
				(fldshomarepas,fldShomareSanad)
				values
				(@fldShomarePas,@bigShomareSanad)
			
			commit transaction AddRecord;
           end try
		begin catch
			if @@TranCount > 0
				begin
					set @strResult='error'
					
					rollback transaction AddRecord;
				end
		end catch
END

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoPishForoosh]
	@flagForoosh nvarchar(10),
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

    @fldShomareFactor bigint,
    --@fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizeForoosh  readonly,
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,
	@lngMablaghKolCheckHa bigint,
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft bigint,
    @lngMablaghBankDaryaft bigint,
	@lngMablaghTakhfifDaryaft bigint,
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	--شرح دریافت
	@strSharhNaghd nvarchar(50), 
	@strSharhBank nvarchar(50),
	@strSharhCheck nvarchar(50),
	@strSharhTakhfif nvarchar(50),
	@strSharhKoli nvarchar(50),
	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
AS
BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomareDaryaft bigint,@yearFull nvarchar(5),@dateSmall bigint
			declare @CodeMoinHoghoogh nvarchar(10),@CodeMoinHesabhayePardakhtani nvarchar(10)

			set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @month=substring(convert(nvarchar(20),@fldDate),5,2)
			set @day=substring(convert(nvarchar(20),@fldDate),7,2)
			set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
			declare @lngSumDaryaft bigint
			set @intRadif=0
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'

			if @flagForoosh='arshive'
				begin
					--arishive
					--update(delete and insert)
					--delete
					delete from tblRizePishForoosh
						where fldShomareFactor =@fldShomareFactor

					delete from tblPishForoosh
						where fldShomareFactorForoosh =@fldShomareFactor

							INSERT INTO tblPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))
								 
							 INSERT INTO tblRizePishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select
							@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;






					set @strResult='update'
					set @strResult2='update'
					
					--commit transaction AddRecord;
					--return
				end
				--تا اینجا تفصیلی ها به روز  شدند
			else if @flagForoosh='insert'
				begin
				--insert
						
					declare @resultExist bigint
					execute ExistFactorPishForoosh @fldShomareFactor,@resultExist output
					declare @maxFactor bigint
					execute GetMaxShomareFactorPishForoosh @maxFactor output
					set @maxFactor=@maxFactor+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					 else if(@resultExist=0 and @flagInsert='yes')
					 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
					     begin
						
							
							INSERT INTO tblPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )							   
								 values(@maxFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizePishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select 
						    @maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='insert'
							commit transaction AddRecord;
						end
					else if(@resultExist=0 and @flagInsert='no')
						 begin
						
							
							INSERT INTO tblPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizePishForoosh
													   ([fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime])
														select 
														--edit
													    @fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@fldShomareFactor)
							set @strResult2='insertByNo'
							--commit transaction AddRecord
						end
						
				end
		


				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				set @strResult2='error'
				rollback transaction AddRecord;
			end
		end catch
END
GO
/****** Object:  StoredProcedure [dbo].[InsertInfoPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[InsertInfoPishPishForoosh]
	@flagForoosh nvarchar(10),
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

    @fldShomareFactor bigint,
    --@fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizeForoosh  readonly,
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,
	@lngMablaghKolCheckHa bigint,
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft bigint,
    @lngMablaghBankDaryaft bigint,
	@lngMablaghTakhfifDaryaft bigint,
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	--شرح دریافت
	@strSharhNaghd nvarchar(50), 
	@strSharhBank nvarchar(50),
	@strSharhCheck nvarchar(50),
	@strSharhTakhfif nvarchar(50),
	@strSharhKoli nvarchar(50),
	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
AS
BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum bigint
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomareDaryaft bigint,@yearFull nvarchar(5),@dateSmall bigint
			declare @CodeMoinHoghoogh nvarchar(10),@CodeMoinHesabhayePardakhtani nvarchar(10)

			set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @month=substring(convert(nvarchar(20),@fldDate),5,2)
			set @day=substring(convert(nvarchar(20),@fldDate),7,2)
			set @dateSmall=substring(convert(nvarchar(15),@fldDate),3,6)
			declare @lngSumDaryaft bigint
			set @intRadif=0
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'

			if @flagForoosh='arshive'
				begin
					--arishive
					--update(delete and insert)
					--delete
					delete from tblRizePishPishForoosh
						where fldShomareFactor =@fldShomareFactor

					delete from tblPishPishForoosh
						where fldShomareFactorForoosh =@fldShomareFactor

							INSERT INTO tblPishPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))
								 
							 INSERT INTO tblRizePishPishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select
							@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;






					set @strResult='update'
					set @strResult2='update'
					
					--commit transaction AddRecord;
					--return
				end
				--تا اینجا تفصیلی ها به روز  شدند
			else if @flagForoosh='insert'
				begin
				--insert
						
					declare @resultExist bigint
					execute ExistFactorPishPishForoosh @fldShomareFactor,@resultExist output
					declare @maxFactor bigint
					execute GetMaxShomareFactorPishPishForoosh @maxFactor output
					set @maxFactor=@maxFactor+1
						
					if(@resultExist>0)
						begin
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='New_Enter'
							rollback transaction AddRecord;
							return
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					 else if(@resultExist=0 and @flagInsert='yes')
					 --زمانی که کاربر از کادر پیام رویه دکمه بله کلیک میکنه
					     begin
						
							
							INSERT INTO tblPishPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )							   
								 values(@maxFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizePishPishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime])
							select 
						    @maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@maxFactor)
							set @strResult2='insert'
							commit transaction AddRecord;
						end
					else if(@resultExist=0 and @flagInsert='no')
						 begin
						
							
							INSERT INTO tblPishPishForoosh
							   ([fldShomareFactorForoosh]							   
							   ,[fldDate]
							   ,[fldSharhFactor]
							   )
								 values(@fldShomareFactor,@fldDate,iif (@fldSharhFactor='none','',@fldSharhFactor))

							 INSERT INTO tblRizePishPishForoosh
													   ([fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime])
														select 
														--edit
													    @fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime] output  from @dtForoosh;
							set @strResult=convert(nvarchar(17),@fldShomareFactor)
							set @strResult2='insertByNo'
							--commit transaction AddRecord
						end
						
				end
		


				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				set @strResult2='error'
				rollback transaction AddRecord;
			end
		end catch
END
GO
/****** Object:  StoredProcedure [dbo].[InsertInfoTblTanzimatDynamic]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[InsertInfoTblTanzimatDynamic]
	@strType nvarchar(30),
	@strMeghdar nvarchar(30)
as 

begin
	INSERT       INTO              tblTanzimatDynamic(fldType, fldMeghdar)
				VALUES        (@strtype,@strmeghdar)
end

GO
/****** Object:  StoredProcedure [dbo].[InsertInfoVosoolCheck_Final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[InsertInfoVosoolCheck_Final] 
@fldShomareVosool bigint,
@fldSanadVosool bigint,
@strResult nvarchar(25) output,
@InsertType nvarchar(50)null,
@dtChecksVosools [dbo].[dtCheckVosool] readonly

as            
BEGIN
	
	SET NOCOUNT ON;
   begin transaction AddRecord
            declare @lngCountShomareVosool bigint
			declare @lngCountShomareSanad bigint
			begin try
			     
				 set @lngCountShomareVosool=(select COUNT(fldShomareVosool) from tblVosool where fldShomareVosool=@fldShomareVosool) 
				 set @lngCountShomareSanad=(select COUNT(convert(bigint,fldSanad)) from tblSodooreSanad where convert(bigint,fldSanad)=@fldSanadVosool)
				  if @lngCountShomareVosool > 0
				  	 Begin
						if @InsertType='insert'
							begin
							set @strResult='error_tekrari_insert'
								rollback transaction 
								return
							end --End Insert
				      end --@lngCountShomareVosool > 0
					  
                 --*************************************
	       
					  if @InsertType='insert'
					   begin

					 IF (@lngCountShomareSanad=0) --@lngcountShomareVosool = 0 and sanad =0  Shomare Sanad Tekrari Nist
					 Begin
					   -- /update tblchkDaryafti
					  update tblCheckeDaryafti 
					  set  fldShomareVosool=P.fldShomareVosool,
						   fldDateVosool=P.fldDateVosool,
						   fldTozihateVosool=P.fldTozihateVosool,
						   fldVaziat=P.fldVaziat,
						   fldSanadVosool=@fldSanadVosool,
						   fldCodeHesabeVosool=P.fldCodeHesabeVosool
					  FROM tblCheckeDaryafti  INNER JOIN @dtChecksVosools as P
					  ON tblCheckeDaryafti.ID =P.fldIDVosool;
			   
						--/update tblchkDaryafti

					


						--*/*----------------------------------Sanad hesab dari
						        IF OBJECT_ID('tempdb..#TempCheck1') IS NOT NULL
									 begin
										delete from  #TempCheck1
									 end
									else 
									 begin
									create table #TempCheck1(
									fldIDVosool1 bigint NULL,
									fldDateVosool1 int NULL,
									fldCodeHesabeVosool1 nvarchar(10)NULL,
									fldMablagh1      decimal(18,0) NULL,
									fldTozihateVosool1 Nvarchar(50)NULL,
									[fldCodeSahebeCheck1] nvarchar(10)NULL
									)
									 end

									insert into #TempCheck1(fldIDVosool1,fldDateVosool1,fldCodeHesabeVosool1,fldMablagh1,fldTozihateVosool1,[fldCodeSahebeCheck1]
									)
									select fldIDVosool,fldDateVosool,fldCodeHesabeVosool,fldMablagh,fldTozihateVosool,fldCodeSahebeCheck from
									@dtChecksVosools output




								DECLARE @Mablagh dec(18,0);
								Declare @CodeHesab nvarchar(10);
								Declare @Tarikh int;
								Declare @Tozihate Nvarchar(50);
								Declare @IDVosool Bigint;
								Declare @CodeSahebeCheck nvarchar(10);

								
								declare @TooleKol bigint,@TooleMoin bigint,@fldCodhesabKol Nvarchar(10),@fldCodHesabMoin nvarchar(10)
								declare @intRow int=1,@day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@dateSmall bigint;
								
								declare @OutCountMoin nvarchar(100);
								declare @strTozihateVShomareCheck Nvarchar(100);
								Declare @strShomareCheckByID Nvarchar(50);
								--//cursor
								DECLARE intListCursor CURSOR LOCAL FAST_FORWARD
								FOR
								SELECT [fldIDVosool1],[fldDateVosool1],[fldCodeHesabeVosool1],[fldMablagh1],[fldTozihateVosool1],[fldCodeSahebeCheck1] 
								FROM #TempCheck1;

								
								OPEN intListCursor


								FETCH NEXT FROM intListCursor INTO @IDVosool,@Tarikh,@CodeHesab,@Mablagh,@Tozihate,@CodeSahebeCheck;

								WHILE @@FETCH_STATUS = 0
								BEGIN

								--// Get Shomare Check By ID from Tbl CheckDaryafti
								set @strShomareCheckByID=(select fldShomareCheck  from tblCheckeDaryafti where ID=@IDVosool)
								--// Get Shomare Check By ID from Tbl CheckDaryafti
	                            execute  ToolePaye 'kol',@TooleKol output
								execute  ToolePaye 'moin',@Toolemoin output
								set @fldCodhesabKol=SUBSTRING(@CodeHesab,1,@TooleKol)
								set @fldCodHesabMoin=SUBSTRING(@CodeHesab,@TooleKol +1,@TooleMoin)
								
								--//Tarikh
								set @year=substring(convert(nvarchar(20),@Tarikh),3,2)
								set @month=substring(convert(nvarchar(20),@Tarikh),5,2)
								set @day=substring(convert(nvarchar(20),@Tarikh),7,2)
								set @dateSmall=substring(convert(nvarchar(15),@Tarikh),3,6)
								--//Tarikh
								
								
							

								   	--/*insert to tblVosool
									if @intRow=1
									 begin
									    execute insertSanadlast @fldCodhesabKol,@fldCodHesabMoin,@CodeHesab,NUll,NULL,
                                       @Mablagh,0,@intRow,@dateSmall,@Tozihate,@day,@month,@year,'Vosool',NULL,@fldSanadVosool;
									  

									   --//Asanad Daryaftani
									 
										execute CodeMoinHesab 'check', @OutCountMoin output
										set @fldCodhesabKol=SUBSTRING(@OutCountMoin,1,@TooleKol)
										set @fldCodHesabMoin=SUBSTRING(@OutCountMoin,@TooleKol +1,@TooleMoin)
										
										
										set @strTozihateVShomareCheck=Convert(nvarchar(100),@strShomareCheckByID)+'بابت وصول چک به شماره'

										set @intRow =@intRow + 1

										execute insertSanadLast @fldCodhesabKol ,@fldCodHesabMoin,@OutCountMoin,@CodeSahebeCheck,'0',
										0,@Mablagh,@intRow,@dateSmall,@strTozihateVShomareCheck,@day,@month,@year,'Vosool',NULL,@fldSanadVosool; 
									   -- // Asnad Daryaftani


						              insert into tblVosool(fldShomareSanad,fldShomareVosool)values(@fldSanadVosool,@fldShomareVosool)
									  End

									else
									 begin
									      set @intRow =@intRow + 1
									      execute insertSanadLast @fldCodhesabKol ,@fldCodHesabMoin,@CodeHesab,NULL,'1',
                                          @Mablagh,0,@intRow,@dateSmall,@Tozihate,@day,@month,@year,'Vosool',NULL,@fldSanadVosool;

										  --///// Asnad Daryafti
										execute CodeMoinHesab 'check', @OutCountMoin output
										set @fldCodhesabKol=SUBSTRING(@OutCountMoin,1,@TooleKol)
										set @fldCodHesabMoin=SUBSTRING(@OutCountMoin,@TooleKol +1,@TooleMoin)
										set @strTozihateVShomareCheck=Convert(nvarchar(100),@strShomareCheckByID)+'بابت وصول چک به شماره'
										  set @intRow =@intRow + 1
										execute insertSanadLast @fldCodhesabKol ,@fldCodHesabMoin,@OutCountMoin,@CodeSahebeCheck,'0',
										0,@Mablagh,@intRow,@dateSmall,@strTozihateVShomareCheck,@day,@month,@year,'Vosool',NULL,@fldSanadVosool; 
										 --//// asnad Daryafti
									 end

						             --/* insert to tblvosool

								   -- Attempt to fetch next row from cursor
								   FETCH NEXT FROM intListCursor INTO @IDVosool,@Tarikh,@CodeHesab,@Mablagh,@Tozihate,@CodeSahebeCheck;
								END;

								CLOSE intListCursor;
								DEALLOCATE intListCursor;


							

						--*/*------------------------------------sanad hesab dari

						    set @strResult='insertOk1'
							
						
					End -- @lngCountSanadVosool = 0
				 --****************************************
				 
				else if @lngCountShomareSanad > 0 --@sanad > 0 Shomare Sanad Tekrari Bod
				    begin					
					 declare @MaxSanad bigint
					 set @MaxSanad=(select max(convert(bigint,fldSanad)) from tblSodooreSanad)
					 set @MaxSanad=@MaxSanad+1
					  
					   -- /update tblchkDaryafti
					  update tblCheckeDaryafti 
					  set  fldShomareVosool=P.fldShomareVosool,
						   fldDateVosool=P.fldDateVosool,
						   fldTozihateVosool=P.fldTozihateVosool,
						   fldVaziat=P.fldVaziat,
						   fldSanadVosool=@MaxSanad,
						   fldCodeHesabeVosool=P.fldCodeHesabeVosool
					  FROM tblCheckeDaryafti  INNER JOIN @dtChecksVosools as P
					  ON tblCheckeDaryafti.ID =P.fldIDVosool;
			   
						--/update tblchkDaryafti
						     
					    --/insert Sanad Hesabdari
						  IF OBJECT_ID('tempdb..#TempCheck3') IS NOT NULL
									 begin
										delete from  #TempCheck3
									 end
									else 
									 begin
									create table #TempCheck3(
									fldIDVosool1 bigint NULL,
									fldDateVosool1 int NULL,
									fldCodeHesabeVosool1 nvarchar(10)NULL,
									fldMablagh1      decimal(18,0) NULL,
									fldTozihateVosool1 Nvarchar(50)NULL,
									[fldCodeSahebeCheck1] nvarchar(10)NULL
									)
									 end

									insert into #TempCheck3(fldIDVosool1,fldDateVosool1,fldCodeHesabeVosool1,fldMablagh1,fldTozihateVosool1,[fldCodeSahebeCheck1])
									
									select fldIDVosool,fldDateVosool,fldCodeHesabeVosool,fldMablagh,fldTozihateVosool,fldCodeSahebeCheck from
									@dtChecksVosools output

								DECLARE @Mablagh3 dec(18,0);
								Declare @CodeHesab3 nvarchar(10);
								Declare @Tarikh3 int;
								Declare @Tozihate3 Nvarchar(50);
								
								Declare @IDVosool3 Bigint;
								
								Declare @CodeSahebeCheck3 nvarchar(10);
								declare @OutCountMoin3 nvarchar(100);
						        declare @strTozihateVShomareCheck3 Nvarchar(100);
								Declare @strShomareCheckByID3 Nvarchar(50);
								
								declare @TooleKol3 bigint,@TooleMoin3 bigint,@fldCodhesabKol3 Nvarchar(10),@fldCodHesabMoin3 nvarchar(10)
								
								declare @intRow3 int=1,@day3 nvarchar(4),@Month3 nvarchar(4),@year3 nvarchar(5),@dateSmall3 bigint;

								DECLARE intListCursor CURSOR LOCAL FAST_FORWARD
								FOR
								SELECT [fldIDVosool1],[fldDateVosool1],[fldCodeHesabeVosool1],[fldMablagh1],[fldTozihateVosool1],[fldCodeSahebeCheck1] 
								FROM #TempCheck3;

								
								OPEN intListCursor


								FETCH NEXT FROM intListCursor INTO @IDVosool3,@Tarikh3,@CodeHesab3,@Mablagh3,@Tozihate3,@CodeSahebeCheck3;

								WHILE @@FETCH_STATUS = 0
								BEGIN



								--// Get Shomare Check By ID from Tbl CheckDaryafti
								set @strShomareCheckByID3=(select fldShomareCheck  from tblCheckeDaryafti where ID=@IDVosool3)
								--// Get Shomare Check By ID from Tbl CheckDaryafti

								-- Kol v Moin
							
	                            execute  ToolePaye 'kol',@TooleKol3 output
								execute  ToolePaye 'moin',@Toolemoin3 output
								set @fldCodhesabKol3=SUBSTRING(@CodeHesab3,1,@TooleKol3)
								set @fldCodHesabMoin3=SUBSTRING(@CodeHesab3,@TooleKol3 +1,@TooleMoin3)
								-- Kol V moin
								
								--//Tarikh
								set @year3=substring(convert(nvarchar(20),@Tarikh3),3,2)
								set @month3=substring(convert(nvarchar(20),@Tarikh3),5,2)
								set @day3=substring(convert(nvarchar(20),@Tarikh3),7,2)
								set @dateSmall3=substring(convert(nvarchar(15),@Tarikh3),3,6)
								--//Tarikh
								
								
								
							
						             
									
								

								   	--/*insert to tblVosool
									if @intRow3=1
									 begin
									       --/// First Sanad
		                                execute InsertSanadLast @fldCodhesabKol3,@fldCodHesabMoin3,@CodeHesab3,NUll,NULL,
                                       @Mablagh3,0, @intRow3,@dateSmall3,@Tozihate3,@day3,@month3,@year3,'Vosool',NULL,@MaxSanad;
									 
									        -- /// First Sanad
											set @intRow3 =@intRow3 +1
											 --/Asnad Daryaftani
						  
										   execute CodeMoinHesab 'check', @OutCountMoin3 output
										   set @fldCodhesabKol3=SUBSTRING(@OutCountMoin3,1,@TooleKol3)
										   set @fldCodHesabMoin3=SUBSTRING(@OutCountMoin3,@TooleKol3 +1,@TooleMoin3)
						  
						   
										   set @strTozihateVShomareCheck3=Convert(nvarchar(100),@strShomareCheckByID3)+'بابت وصول چک به شماره '

										   execute insertSanadLast @fldCodhesabKol3 ,@fldCodHesabMoin3,@OutCountMoin3,@CodeSahebeCheck3,'0',
										   0,@Mablagh3,@intRow3,@dateSmall3,@strTozihateVShomareCheck3,@day3,@Month3,@year3,'Vosool',NULL,@MaxSanad; 

						                  --/Asanad Daryaftani
						              insert into tblVosool(fldShomareSanad,fldShomareVosool)values(@MaxSanad,@fldShomareVosool)
									  end
									 else
									    begin
										        -- ///Last Sanad Insert 
												 set @intRow3 =@intRow3 +1
										     execute insertSanadLast @fldCodhesabKol3 ,@fldCodHesabMoin3,@CodeHesab3,NULL,'1',
                                             @Mablagh3,0,@intRow3,@dateSmall3,@Tozihate3,@day3,@month3,@year3,'Vosool',NULL,@MaxSanad; 
											   -- ///Last Sanad Insert
									     
										 --/Asnad Daryaftani
						  
										   execute CodeMoinHesab 'check', @OutCountMoin3 output
										   set @fldCodhesabKol3=SUBSTRING(@OutCountMoin3,1,@TooleKol3)
										   set @fldCodHesabMoin3=SUBSTRING(@OutCountMoin3,@TooleKol3 +1,@TooleMoin3)
						  
						   
										   set @strTozihateVShomareCheck3=Convert(nvarchar(100),@strShomareCheckByID3)+'بابت وصول چک به شماره '

										   set @intRow3 =@intRow3 +1
										   execute insertSanadLast @fldCodhesabKol3 ,@fldCodHesabMoin3,@OutCountMoin3,@CodeSahebeCheck3,'0',
										   0,@Mablagh3,@intRow3,@dateSmall3,@strTozihateVShomareCheck3,@day3,@Month3,@year3,'Vosool',NULL,@MaxSanad; 

						                  --/Asanad Daryaftani

									  End
						             --/* insert to tblvosool

								   -- Attempt to fetch next row from cursor
								   FETCH NEXT FROM intListCursor INTO @IDVosool3,@Tarikh3,@CodeHesab3,@Mablagh3,@Tozihate3,@CodeSahebeCheck3;
								END;

								CLOSE intListCursor;
								DEALLOCATE intListCursor;


						--/insert Sanad Hesabdari

					
						 
						
						

						    set @strResult='insertOk2'
						
						 end ---- else @lngCountShomareVosool = 0
					End --Type Insert
			 		
					--// 
					
						if @InsertType='archive'
							begin
						   declare @MaxNewSanad1 nvarchar(10)
						   declare @StrShomareSanadVosool nvarchar(20);
						   set @StrShomareSanadVosool=(select fldShomareSanad from tblVosool where fldShomareVosool=@fldShomareVosool)
						   --insert into tbltest2 (name) values (@StrShomareSanadVosool)
						   delete from tblSodooreSanad where fldSanad=@StrShomareSanadVosool 
						   delete from tblVosool where fldShomareVosool=@fldShomareVosool 
				  	        
						   ---/// sanad az karbar check mishavad tekrari nabashad
							declare @SanadVosoolCount1 bigint;
							set @SanadVosoolCount1=(select COUNT(convert(bigint,fldSanad)) from tblSodooreSanad where convert(bigint,fldSanad)=@fldSanadVosool)
							if @SanadVosoolCount1 > 0 -- //////in yani karbar zodtar sabt kardeh
							 begin
							
							
					         set @MaxNewSanad1=(select max(convert(bigint,fldSanad)) from tblSodooreSanad)
					         set @MaxNewSanad1=@MaxNewSanad1+1

							  update tblCheckeDaryafti 
						   set fldShomareVosool=NULL,
						   fldDateVosool=NULL,
						   fldTozihateVosool=NULL,
						   fldVaziat=NULL,
						   fldSanadVosool=NULL,
						   fldCodeHesabeVosool=NULL
						   where fldShomareVosool=@fldShomareVosool 
						  
						--------///
						------baraye halati ke check be bank vagozar shode					
						update tblCheckeDaryafti 
						   set fldShomareVosool=NULL,
						   fldDateVosool=NULL,
						   fldTozihateVosool=NULL,
						   fldVaziat='vagozari',
						   fldSanadVosool=NULL,
						   fldCodeHesabeVosool=NULL
						   where fldShomareVosool=@fldShomareVosool and fldDateVagozariBeBank IS not NULL
						--------///

					 


						--*/*----------------------------------Sanad hesab dari
						        IF OBJECT_ID('tempdb..#TempCheck4') IS NOT NULL
									 begin
										delete from  #TempCheck4
									 end
									else 
									 begin
									create table #TempCheck4(
									fldIDVosool1 bigint NULL,
									fldDateVosool1 int NULL,
									fldCodeHesabeVosool1 nvarchar(10)NULL,
									fldMablagh1      decimal(18,0) NULL,
									fldTozihateVosool1 Nvarchar(50)NULL,
									[fldCodeSahebeCheck1] nvarchar(10)NULL
									)
									 end

									insert into #TempCheck4(fldIDVosool1,fldDateVosool1,fldCodeHesabeVosool1,fldMablagh1,fldTozihateVosool1,[fldCodeSahebeCheck1]
									)
									select fldIDVosool,fldDateVosool,fldCodeHesabeVosool,fldMablagh,fldTozihateVosool,fldCodeSahebeCheck from
									@dtChecksVosools output




								DECLARE @Mablagh4 dec(18,0);
								Declare @CodeHesab4 nvarchar(10);
								Declare @Tarikh4 int;
								Declare @Tozihate4 Nvarchar(50);
								
								Declare @IDVosool4 Bigint;
								
								Declare @CodeSahebeCheck4 nvarchar(10);

								
								declare @TooleKol4 bigint,@TooleMoin4 bigint,@fldCodhesabKol4 Nvarchar(10),@fldCodHesabMoin4 nvarchar(10)
								declare @intRow4 int=1,@day4 nvarchar(4),@Month4 nvarchar(4),@year4 nvarchar(5),@dateSmall4 bigint;
								
								declare @OutCountMoin4 nvarchar(100);
								declare @strTozihateVShomareCheck4 Nvarchar(100);
								Declare @strShomareCheckByID4 Nvarchar(50);
								--//cursor
								DECLARE intListCursor CURSOR LOCAL FAST_FORWARD
								FOR
								SELECT [fldIDVosool1],[fldDateVosool1],[fldCodeHesabeVosool1],[fldMablagh1],[fldTozihateVosool1],[fldCodeSahebeCheck1] 
								FROM #TempCheck4;

								
								OPEN intListCursor


								FETCH NEXT FROM intListCursor INTO @IDVosool4,@Tarikh4,@CodeHesab4,@Mablagh4,@Tozihate4,@CodeSahebeCheck4;

								WHILE @@FETCH_STATUS = 0
								BEGIN

								--// Get Shomare Check By ID from Tbl CheckDaryafti
								set @strShomareCheckByID4=(select fldShomareCheck  from tblCheckeDaryafti where ID=@IDVosool4)
								--// Get Shomare Check By ID from Tbl CheckDaryafti
	                            execute  ToolePaye 'kol',@TooleKol4 output
								execute  ToolePaye 'moin',@Toolemoin4 output
								set @fldCodhesabKol4=SUBSTRING(@CodeHesab4,1,@TooleKol4)
								set @fldCodHesabMoin4=SUBSTRING(@CodeHesab4,@TooleKol4 +1,@TooleMoin4)
								
								--//Tarikh
								set @year4=substring(convert(nvarchar(20),@Tarikh4),3,2)
								set @month4=substring(convert(nvarchar(20),@Tarikh4),5,2)
								set @day4=substring(convert(nvarchar(20),@Tarikh4),7,2)
								set @dateSmall4=substring(convert(nvarchar(15),@Tarikh4),3,6)
								--//Tarikh
								
								
								
								
							

								   	--/*insert to tblVosool
									if @intRow4=1
									 begin
									    execute insertSanadlast @fldCodhesabKol4,@fldCodHesabMoin4,@CodeHesab4,NUll,NULL,
                                       @Mablagh4,0,@intRow4,@dateSmall4,@Tozihate4,@day4,@month4,@year4,'Vosool',NULL,@MaxNewSanad1
									

									   --//Asanad Daryaftani
									     set @intRow4 =@intRow4 +1
										execute CodeMoinHesab 'check', @OutCountMoin4 output
										set @fldCodhesabKol4=SUBSTRING(@OutCountMoin4,1,@TooleKol4)
										set @fldCodHesabMoin4=SUBSTRING(@OutCountMoin4,@TooleKol4 +1,@TooleMoin4)
										
										
										set @strTozihateVShomareCheck4=Convert(nvarchar(100),@strShomareCheckByID4)+'بابت وصول چک به شماره'

										execute insertSanadLast @fldCodhesabKol4 ,@fldCodHesabMoin4,@OutCountMoin4,@CodeSahebeCheck4,'0',
										0,@Mablagh4,@intRow4,@dateSmall4,@strTozihateVShomareCheck4,@day4,@month4,@year4,'Vosool',NULL,@MaxNewSanad1; 
									   -- // Asnad Daryaftani


						              insert into tblVosool(fldShomareSanad,fldShomareVosool)values(@MaxNewSanad1,@fldShomareVosool)
									  End

									else
									 begin
									      
										  set @intRow4 =@intRow4 +1
									      execute insertSanadLast @fldCodhesabKol4 ,@fldCodHesabMoin4,@CodeHesab4,NULL,'1',
                                          @Mablagh4,0,@intRow4,@dateSmall4,@Tozihate4,@day4,@month4,@year4,'Vosool',NULL,@MaxNewSanad1;

										  --// Asnad Daryafti
										execute CodeMoinHesab 'check', @OutCountMoin4 output
										set @fldCodhesabKol4=SUBSTRING(@OutCountMoin4,1,@TooleKol4)
										set @fldCodHesabMoin4=SUBSTRING(@OutCountMoin4,@TooleKol4 +1,@TooleMoin4)
										set @strTozihateVShomareCheck4=Convert(nvarchar(100),@strShomareCheckByID4)+'بابت وصول چک به شماره'

										set @intRow4 =@intRow4 +1
										execute insertSanadLast @fldCodhesabKol4 ,@fldCodHesabMoin4,@OutCountMoin4,@CodeSahebeCheck4,'0',
										0,@Mablagh4,@intRow4,@dateSmall4,@strTozihateVShomareCheck4,@day4,@month4,@year4,'Vosool',NULL,@MaxNewSanad1; 
										  --// asnad Daryafti
									   end

						             --/* insert to tblvosool

								   -- Attempt to fetch next row from cursor
								   FETCH NEXT FROM intListCursor INTO @IDVosool4,@Tarikh4,@CodeHesab4,@Mablagh4,@Tozihate4,@CodeSahebeCheck4;
								END;

								CLOSE intListCursor;
								DEALLOCATE intListCursor;

								  -- /update tblchkDaryafti
					  update tblCheckeDaryafti 
					  set  fldShomareVosool=P.fldShomareVosool,
						   fldDateVosool=P.fldDateVosool,
						   fldTozihateVosool=P.fldTozihateVosool,
						   fldVaziat=P.fldVaziat,
						   fldSanadVosool=@MaxNewSanad1,
						   fldCodeHesabeVosool=P.fldCodeHesabeVosool
					  FROM tblCheckeDaryafti  INNER JOIN @dtChecksVosools as P
					  ON tblCheckeDaryafti.ID =P.fldIDVosool;
			   
						--/update tblchkDaryafti
							

						--*/*------------------------------------sanad hesab dari

						    set @strResult='ArchiveUpdateOK1'
							
						     End -- end count

							else   -- lngCountsanad =0
							 begin

						   declare @StrShomareSanadVosool1 nvarchar(20);
						   set @StrShomareSanadVosool1=(select fldShomareSanad from tblVosool where fldShomareVosool=@fldShomareVosool)
						   delete from tblSodooreSanad where fldSanad=@StrShomareSanadVosool1 
						   delete from tblVosool where fldShomareVosool=@fldShomareVosool 

							 set @MaxNewSanad1=@fldSanadVosool     -- // yani sanad tekrari nist

							 
						 -- /update tblchkDaryafti Reset For Update
							update tblCheckeDaryafti 
						   set fldShomareVosool=NULL,
						   fldDateVosool=NULL,
						   fldTozihateVosool=NULL,
						   fldVaziat=NULL,
						   fldSanadVosool=NULL,
						   fldCodeHesabeVosool=NULL
						   where fldShomareVosool=@fldShomareVosool 
						  
						--------///
						------baraye halati ke check be bank vagozar shode					
						 update tblCheckeDaryafti 
						   set fldShomareVosool=NULL,
						   fldDateVosool=NULL,
						   fldTozihateVosool=NULL,
						   fldVaziat='vagozari',
						   fldSanadVosool=NULL,
						   fldCodeHesabeVosool=NULL
						   where fldShomareVosool=@fldShomareVosool and fldDateVagozariBeBank IS not NULL
						--------///

					   --/update tblchkDaryafti Reset For Update

					      -- /update tblchkDaryafti
					  update tblCheckeDaryafti 
					  set  fldShomareVosool=P.fldShomareVosool,
						   fldDateVosool=P.fldDateVosool,
						   fldTozihateVosool=P.fldTozihateVosool,
						   fldVaziat=P.fldVaziat,
						   fldSanadVosool=@MaxNewSanad1,
						   fldCodeHesabeVosool=P.fldCodeHesabeVosool
					  FROM tblCheckeDaryafti  INNER JOIN @dtChecksVosools as P
					  ON tblCheckeDaryafti.ID =P.fldIDVosool;
			   
						--/update tblchkDaryafti
						
						   -- TempTable
						      --*/*----------------------------------Sanad hesab dari
						        IF OBJECT_ID('tempdb..#TempCheck5') IS NOT NULL
									 begin
										delete from  #TempCheck5
									 end
									else 
									 begin
									create table #TempCheck5(
									fldIDVosool1 bigint NULL,
									fldDateVosool1 int NULL,
									fldCodeHesabeVosool1 nvarchar(10)NULL,
									fldMablagh1      decimal(18,0) NULL,
									fldTozihateVosool1 Nvarchar(50)NULL,
									[fldCodeSahebeCheck1] nvarchar(10)NULL
									)
									 end

								   insert into #TempCheck5(fldIDVosool1,fldDateVosool1,fldCodeHesabeVosool1,fldMablagh1,fldTozihateVosool1,[fldCodeSahebeCheck1]
									)
									select fldIDVosool,fldDateVosool,fldCodeHesabeVosool,fldMablagh,fldTozihateVosool,fldCodeSahebeCheck from
									@dtChecksVosools output

								DECLARE @Mablagh5 dec(18,0);
								Declare @CodeHesab5 nvarchar(10);
								Declare @Tarikh5 int;
								Declare @Tozihate5 Nvarchar(50);
								Declare @IDVosool5 Bigint;
								Declare @CodeSahebeCheck5 nvarchar(10);

								
								declare @TooleKol5 bigint,@TooleMoin5 bigint,@fldCodhesabKol5 Nvarchar(10),@fldCodHesabMoin5 nvarchar(10)
								declare @intRow5 int=1,@day5 nvarchar(4),@Month5 nvarchar(4),@year5 nvarchar(5),@dateSmall5 bigint;
								
								declare @OutCountMoin5 nvarchar(100);
								declare @strTozihateVShomareCheck5 Nvarchar(100);
								Declare @strShomareCheckByID5 Nvarchar(50);
						   -- TempTable

						   --//cursor
								DECLARE intListCursor CURSOR LOCAL FAST_FORWARD
								FOR
								SELECT [fldIDVosool1],[fldDateVosool1],[fldCodeHesabeVosool1],[fldMablagh1],[fldTozihateVosool1],[fldCodeSahebeCheck1] 
								FROM #TempCheck5;

								
								OPEN intListCursor


								FETCH NEXT FROM intListCursor INTO @IDVosool5,@Tarikh5,@CodeHesab5,@Mablagh5,@Tozihate5,@CodeSahebeCheck5;

								WHILE @@FETCH_STATUS = 0
								BEGIN

								--// Get Shomare Check By ID from Tbl CheckDaryafti
								set @strShomareCheckByID5=(select fldShomareCheck  from tblCheckeDaryafti where ID=@IDVosool5)
								--// Get Shomare Check By ID from Tbl CheckDaryafti
	                            execute  ToolePaye 'kol',@TooleKol5 output
								execute  ToolePaye 'moin',@Toolemoin5 output
								set @fldCodhesabKol5=SUBSTRING(@CodeHesab5,1,@TooleKol5)
								set @fldCodHesabMoin5=SUBSTRING(@CodeHesab5,@TooleKol5 +1,@TooleMoin5)
								
								--//Tarikh
								set @year5=substring(convert(nvarchar(20),@Tarikh5),3,2)
								set @month5=substring(convert(nvarchar(20),@Tarikh5),5,2)
								set @day5=substring(convert(nvarchar(20),@Tarikh5),7,2)
								set @dateSmall5=substring(convert(nvarchar(15),@Tarikh5),3,6)
								--//Tarikh
								
												   	--/*insert to tblVosool
									if @intRow5=1
									 begin
									    execute InsertSanadLast @fldCodhesabKol5,@fldCodHesabMoin5,@CodeHesab5,NUll,NULL,
                                       @Mablagh5,0,@intRow5,@dateSmall5,@Tozihate5,@day5,@month5,@year5,'Vosool',NULL,@MaxNewSanad1;
									 

									   --//Asanad Daryaftani
									 
										execute CodeMoinHesab 'check', @OutCountMoin5 output
										set @fldCodhesabKol5=SUBSTRING(@OutCountMoin5,1,@TooleKol5)
										set @fldCodHesabMoin5=SUBSTRING(@OutCountMoin5,@TooleKol5 +1,@TooleMoin5)
										
										
										set @strTozihateVShomareCheck5=Convert(nvarchar(100),@strShomareCheckByID5)+'بابت وصول چک به شماره'
										set @intRow5 =@intRow5 +1
										execute insertSanadLast @fldCodhesabKol5 ,@fldCodHesabMoin5,@OutCountMoin5,@CodeSahebeCheck5,'0',
										0,@Mablagh5,@intRow5,@dateSmall5,@strTozihateVShomareCheck5,@day5,@month5,@year5,'Vosool',NULL,@MaxNewSanad1; 
									   -- // Asnad Daryaftani


						              insert into tblVosool(fldShomareSanad,fldShomareVosool)values(@MaxNewSanad1,@fldShomareVosool)
									  End

									else
									 begin
									       set @intRow5 =@intRow5 +1
									      execute insertSanadLast @fldCodhesabKol5 ,@fldCodHesabMoin5,@CodeHesab5,NULL,'1',
                                          @Mablagh5,0,@intRow5,@dateSmall5,@Tozihate5,@day5,@month5,@year5,'Vosool',NULL,@MaxNewSanad1;

										  --// Asnad Daryafti
										execute CodeMoinHesab 'check', @OutCountMoin5 output
										set @fldCodhesabKol5=SUBSTRING(@OutCountMoin5,1,@TooleKol5)
										set @fldCodHesabMoin5=SUBSTRING(@OutCountMoin5,@TooleKol5 +1,@TooleMoin5)
										set @strTozihateVShomareCheck5=Convert(nvarchar(100),@strShomareCheckByID5)+'بابت وصول چک به شماره'

										set @intRow5 =@intRow5 +1
										execute insertSanadLast @fldCodhesabKol5 ,@fldCodHesabMoin5,@OutCountMoin5,@CodeSahebeCheck5,'0',
										0,@Mablagh5,@intRow5,@dateSmall5,@strTozihateVShomareCheck5,@day5,@month5,@year5,'Vosool',NULL,@MaxNewSanad1; 
										  --// asnad Daryafti
									 end

						             --/* insert to tblvosool

								   -- Attempt to fetch next row from cursor
								   FETCH NEXT FROM intListCursor INTO @IDVosool5,@Tarikh5,@CodeHesab5,@Mablagh5,@Tozihate5,@CodeSahebeCheck5;
								END;

								CLOSE intListCursor;
								DEALLOCATE intListCursor;


							

						--*/*------------------------------------sanad hesab dari

						    set @strResult='ArchiveUpdateOK2'


                         

							 end
							 ---/// sanad az karbar check mishavad tekrari nabashad

				
				   End --/// ArchiveUpdate End
                        
				
																																												                    
   commit transaction AddRecord;
           end try
		begin catch
			if @@TranCount > 0
				begin
					set @strResult='error'
					
					rollback transaction AddRecord;
				end
		end catch
		
END


GO
/****** Object:  StoredProcedure [dbo].[InsertInTblPrinters]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertInTblPrinters] 
	-- Add the parameters for the stored procedure here
	@type nvarchar(10),
	@ID bigint,
	@NameMahal nvarchar(50),
	@NamePrinter nvarchar(MAX)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	if @type='update'
		update tblPrinters
			set fldNameMahal=@NameMahal,fldNamePrinter=@NamePrinter  
				where ID=@ID

	if @type='insert'
	INSERT        INTO              tblPrinters( fldNameMahal, fldNamePrinter)
			VALUES        (@NameMahal,@NamePrinter)


END

GO
/****** Object:  StoredProcedure [dbo].[InsertIntoTblIDChapgarKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertIntoTblIDChapgarKala] 
	-- Add the parameters for the stored procedure here
	@CodeKala bigint,
	@IDChapgar bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	delete tblIDChapgarKala Where fldCodeKala=@CodeKala

   insert into tblIDChapgarKala
		(fldCodeKala,fldIDChapgarKala)
	Values
		(@CodeKala,@IDChapgar)
END

GO
/****** Object:  StoredProcedure [dbo].[InsertKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertKolMoin]

@IDHesab bigInt,
@NameHesab nvarChar(70),
@CodeKolHesab nvarChar(8),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@flagSabt int output,
@IDOutPut int outPut


as 

begin
	set @IDHesab= (Select Max(fldCodeHesab) from tblKolMoin Where left(fldCodeHesab,len(@CodekolHesab))=@CodeKolHesab )
	Set @IDHesab+=1
	insert into tblKolMoin 
		values(@IDHesab,@NameHesab,@SharheNoeTafzili,@CodeType,'غير فعال','غير فعال',null)
	set @flagSabt=@IDHesab
	set @IDOutPut=@@IDENTITY
end

GO
/****** Object:  StoredProcedure [dbo].[InsertSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[InsertSanad]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal,
	@fldBestankar  decimal, 
	@fldRadif nvarchar(50),
	@fldDate int, 
	@fldSharh nvarchar(100),
	@fldType nvarchar(20)
as

begin
		INSERT INTO tblSodooreSanad
                         (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldType)
		SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS MaxSanad,@fldCodeKol,@fldCodeMoin,@fldMoinKamel,@fldCodeTafzili,@fldCodeNoeTafzili,@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,'daryaft'
		FROM            tblSodooreSanad AS tblSodooreSanad_1
end
GO
/****** Object:  StoredProcedure [dbo].[InsertSanadFirst]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertSanadFirst]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal,
	@fldBestankar  decimal, 
	@fldRadif nvarchar(50),
	@fldDate int, 
	@fldSharh nvarchar(100),	
	@day nvarchar(50),
	@month nvarchar(50),
	@year nvarchar(50),
	@fldType nvarchar(20),
	@fldVasete nvarchar(10),
	@ShomareSanad nvarchar(50) output
as

begin
		declare @lngShomareSanad nvarchar(50),@IDOutPut bigint,@lngCount bigint
		
		set @lngCount= (Select Count(fldSanad) from tblSodooreSanad)

		if @lngCount>0 
			begin
				INSERT INTO tblSodooreSanad
								 (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldCodeMarkaz1,fldCodeMarkaz2, fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldDay,fldMonth,fldYear,fldVasete, fldType)
				SELECT        MAX(CONVERT(dec, fldSanad)) + 1 AS MaxSanad,@fldCodeKol,@fldCodeMoin,@fldMoinKamel,ISNULL(@fldCodeTafzili,''),ISNULL(@fldCodeNoeTafzili,''),'','',@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,@day,@month,@year,@fldVasete,@fldType
				FROM            tblSodooreSanad AS tblSodooreSanad_1
			end
		else
			begin
				INSERT INTO tblSodooreSanad
								 (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldCodeMarkaz1,fldCodeMarkaz2,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldDay,fldMonth,fldYear,fldVasete, fldType)
					Values ('1',@fldCodeKol,@fldCodeMoin,@fldMoinKamel,ISNULL(@fldCodeTafzili,''),ISNULL(@fldCodeNoeTafzili,''),'','',@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,@day,@month,@year,@fldVasete,@fldType)
				--FROM            tblSodooreSanad AS tblSodooreSanad_1

				--INSERT INTO tblSodooreSanad
				--				 (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldDay,fldMonth,fldYear,fldVasete, fldType)
				--values        ('66','110','01','1101','','',10000,0,'2',950101,'ss','01','01','95','100','daryaft')
				
			end

		set @IDOutPut=@@IDENTITY;
	
		--set @lngShomareSanad=(Select fldSanad from tblSodooreSanad   where id=@IDOutPut)

		

		set @lngShomareSanad =(select fldSanad from tblSodooreSanad Where ID=@IDOutPut)

		--insert into tblTest7 (fld1)
		--values(@IDOutPut)

		set @ShomareSanad=@lngShomareSanad

		--INSERT INTO tblTest7(fld1)
		--VALUES        (@lngShomareSanad )

	 --  	set @ShomareSanad=@lngShomareSanad
		--EXECUTE [TestInsert]  @IDOutPut
end
GO
/****** Object:  StoredProcedure [dbo].[InsertSanadLast]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertSanadLast]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal,
	@fldBestankar  decimal, 
	@fldRadif nvarchar(50),
	@fldDate int, 
	@fldSharh nvarchar(100),
	@day nvarchar(50),
	@month nvarchar(50),
	@year nvarchar(50),
	@fldType nvarchar(20),
	@vasete nvarchar(10),
	@ShomareSanad nvarchar(50) 
as

begin
		declare @lngShomareSanad nvarchar(50),@IDOutPut bigint
		
		INSERT INTO tblSodooreSanad
                         (fldSanad, fldCodeKol, fldCodeMoin, fldMoinKamel, fldCodeTafzili, fldCodeNoeTafzili,fldCodeMarkaz1,fldCodeMarkaz2,fldBedehkar, fldBestankar , fldRadif,fldDate , fldSharh,fldday,fldmonth,fldyear,fldvasete,fldType)
		values (@ShomareSanad,@fldCodeKol,@fldCodeMoin,@fldMoinKamel,isnull(@fldCodeTafzili,''),isnull(@fldCodeNoeTafzili,''),'','',@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,@day,@month,@year,@vasete, @fldType)


		--set @IDOutPut=@@IDENTITY;	

		--set @lngShomareSanad =(select fldSanad from tblSodooreSanad Where ID=@IDOutPut)

		--set @ShomareSanad=@lngShomareSanad

		--INSERT INTO tblTest7(fld1)
		--VALUES        (@lngShomareSanad )

	 --  	set @ShomareSanad=@lngShomareSanad
		--EXECUTE [TestInsert]  @IDOutPut
end
GO
/****** Object:  StoredProcedure [dbo].[InsertShomareFish]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertShomareFish] 
	-- Add the parameters for the stored procedure here
	@ShomareFactor bigint,
	@ShomareFish bigint
AS
BEGIN
	
	SET NOCOUNT ON;
	declare @ShomareForSave bigint
	if @ShomareFish=-1 --یعنی شماره ماکس باید دربیادیا بعبارتی زمانی که حالت آرشیو نیست
		execute MaxShomareFish @ShomareForSave output
	else
		set @ShomareForSave =@ShomareFish
		
	Delete tblFish Where fldShomareFactor=@ShomareFactor or fldShomareFish=@ShomareForSave
    --set @ShomareForSave=1
	Insert into tblFish
		(fldShomarefactor,fldShomareFish)
		values
		(@ShomareFactor,@ShomareForSave)
END

GO
/****** Object:  StoredProcedure [dbo].[InsertTanzimatNew]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertTanzimatNew]

	@Name1 nvarChar(30),
	@Meghdar nvarChar(30),
	@NoeKhata nvarchar(30) output ,
	@IDOutPut int outPut
as 

begin
	begin transaction transact
		begin try
			delete tblTanzimatNew where fldName=@Name1
			insert into tblTanzimatNew 
				values(@Name1,@Meghdar)	
			set @IDOutPut=@@IDENTITY
			set @noekhata='insert'
		commit transaction
		end try

	begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'				
	end catch
end

GO
/****** Object:  StoredProcedure [dbo].[inserttest]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[inserttest]
as
DECLARE @LocationTVP AS LocationTableType;  
  
/* Add data to the table variable. */  
INSERT INTO @LocationTVP (LocationName, CostRate)  
    SELECT Name1, 0.00  
    FROM tblTest5;  
  
/* Pass the table variable data to a stored procedure. */  
EXEC usp_InsertProductionLocation @LocationTVP;  

GO
/****** Object:  StoredProcedure [dbo].[InsertUser]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[InsertUser]
	@Code bigint,
	@UserName nvarchar(25),
	@Password nvarchar(MAX),
	@Type int,
	@TypeInsert nvarchar(15),
	@Result nvarchar(30) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	if @TypeInsert='update'
		begin
			update tblSecurity set fldUser=@UserName ,fldPassword=@Password Where fldCode=@Code
			set @Result='true'
		end

	if @TypeInsert='insert'
		begin
			declare @MaxCode bigint

			set @MaxCode=(Select Max(fldCode) from tblSecurity)
			if @MaxCode is null 
				set @MaxCode=1000
			else
				set @MaxCode=@MaxCode+1

			Insert into tblSecurity
				(fldCode, fldUser,fldPassword,fldType)
				values
				(@MaxCode, @UserName,@Password,@Type)

				set @Result='true'
		end
END

GO
/****** Object:  StoredProcedure [dbo].[InsertVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[InsertVahed]

@NameVahed nvarChar(70),
@IDOutPut int outPut
as 

begin

	insert into tblVahed 
		values(@NameVahed)	
	set @IDOutPut=@@IDENTITY
end

GO
/****** Object:  StoredProcedure [dbo].[IsArchiveShomaredaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[IsArchiveShomaredaryaft]
@Shomaredaryaft bigint,
@Result nvarchar(20) output

as
begin
	declare @lngCount bigint,@strType nvarchar(50)

	set @lngCount=(Select count(fldShomareDaryaft) from tblDaryaft Where fldShomareDaryaft=@Shomaredaryaft)
	if @lngCount>0 
		begin
			set @Result=(Select fldType from tblDaryaft Where fldShomareDaryaft=@Shomaredaryaft)
		end
	else
		begin
			set @Result='notarchive'
		end
end
GO
/****** Object:  StoredProcedure [dbo].[IsArchiveShomarePardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[IsArchiveShomarePardakht]
@ShomarePardakht bigint,
@Result nvarchar(10) output

as
begin
	declare @lngCount bigint

	set @lngCount=(Select count(fldShomarePardakht) from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
	if @lngCount>0 
		begin
			set @Result='archive'
		end
	else
		begin
			set @Result='notarchive'
		end
end
GO
/****** Object:  StoredProcedure [dbo].[IsArchiveShomareSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[IsArchiveShomareSanad]
@ShomareSanad nvarchar(50),
@Result nvarchar(10) output

as
begin
	declare @lngCount bigint

	set @lngCount=(Select count(fldSanad) from tblSodooreSanad Where fldSanad=@ShomareSanad)							
						
	if @lngCount>0 
		begin
			set @Result='archive'
		end
	else
		begin
			set @Result='notarchive'
		end
end
GO
/****** Object:  StoredProcedure [dbo].[IsArshiveShomarePas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[IsArshiveShomarePas]
	@ShomarePas bigint,
	@Result nvarchar(30) output
AS
BEGIN
	declare @bigCount bigint

	set @bigCount =(Select Count(fldShomarePas) from tblPas Where fldShomarePas=@ShomarePas)
	if @bigCount>0 
		set @Result='arshive'
	else
		set @Result='insert'
END

GO
/****** Object:  StoredProcedure [dbo].[ISTekrariCheckeDaryafti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ISTekrariCheckeDaryafti]
@intShomareCheck bigint,
@ID Int,
@intOutPut int output 
as

begin
	declare @RowCount int
	if @ID>0 --برای حالتی که مقایسه در حالت ویرایشه یعنی مقایسه بغیر خودش  
		begin
			set @RowCount=(Select count(fldShomareCheck) from tblCheckeDaryafti Where fldShomareCheck=@intShomareCheck and ID<>@ID);			
		end
	else -- برای حالتی که مقایسه در حالت درج جدیده یعنی با کل رکوردها مقایسه انجام میشه
		begin
			set @RowCount=(Select count(fldShomareCheck) from tblCheckeDaryafti Where fldShomareCheck=@intShomareCheck );			
		end
	
	set @intOutPut=@Rowcount

end
GO
/****** Object:  StoredProcedure [dbo].[ISTekrariCheckePardakhti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[ISTekrariCheckePardakhti]
@intShomareCheck bigint,
@ID Int,
@intOutPut int output 
as

begin
	declare @RowCount int
	if @ID>0 --برای حالتی که مقایسه در حالت ویرایشه یعنی مقایسه بغیر خودش  
		begin
			set @RowCount=(Select count(fldShomareCheck) from tblCheckePardakhti Where fldShomareCheck=@intShomareCheck and ID<>@ID);			
		end
	else -- برای حالتی که مقایسه در حالت درج جدیده یعنی با کل رکوردها مقایسه انجام میشه
		begin
			set @RowCount=(Select count(fldShomareCheck) from tblCheckePardakhti Where fldShomareCheck=@intShomareCheck );			
		end
	
	set @intOutPut=@Rowcount

end

GO
/****** Object:  StoredProcedure [dbo].[isTekrariDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[isTekrariDasteCheck]
@CodeBank nvarchar(50),
@SerialStart bigint,
@SerialEnd bigint,
@NoeKhata nvarchar(20) output
as

begin
	declare @lngCount bigint
 	set @lngcount=(SELECT        Count(fldShomareCheck)
			FROM            tblDasteCheck
			WHERE        (fldCodeBank = @codebank) AND (fldShomareCheck BETWEEN @SerialStart AND @SerialEnd))

	if @lngcount>0 
		begin
			set @NoeKhata='tekrari'
		end
	else if @lngcount<=0 
		begin
			set @NoeKhata='new'
		end
end
GO
/****** Object:  StoredProcedure [dbo].[Kardeks]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[Kardeks]

--@mm nvarchar(10),
--@nn nvarchar(10)

as

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100),
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldTedadDarKarton decimal(18, 0),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200), 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldDate bigint,
fldType nvarchar(20)
)



--insert into #TempMojoodieAnbar (
--fldCodeGroup,fldCodeKala,fldNameKala,fldTedadeVorood,fldTedadeKhorooj,
--fldTedadeJoz,fldTedadeKol,fldCodeAnbar,fldNameAnbar,fldNogheSefaresh,fldFeeForoosh,
--fldLastFee,fldMianginFee,fldNameVahed,fldNameVahed2 )
--values (1,2,'3',4,5,6,7,7.1,'8',9,10,11,12,'13','14')


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeKharid



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeForoosh


UPDATE       #TempMojoodieAnbar
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar ON tblKala.fldCodeKala = #TempMojoodieAnbar.fldCodeKala


UPDATE       #TempMojoodieAnbar
SET                #TempMojoodieAnbar.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar ON #TempMojoodieAnbar.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar ON tblAnbar.fldCode = #TempMojoodieAnbar.fldCodeAnbar


update #tempMojoodieAnbar set #tempMojoodieAnbar.fldNameVahed=tbl2.fldNameVahed,#tempMojoodieAnbar.fldNameVahed2=tbl2.fldNameVahed2
from
(SELECT    fldCodeKala,    tbl1.fldCodeVahed1, tbl1.fldCodeVahed2, tbl1.fldNameVahed, tblVahed.fldNameVahed AS fldNameVahed2
FROM            tblVahed INNER JOIN
                             (SELECT       fldCodeKala, tblKala.fldCodeVahed1, tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed
                                FROM            tblKala INNER JOIN
                                                         tblVahed AS tblVahed_1 ON tblKala.fldCodeVahed1 = tblVahed_1.ID) AS tbl1 ON tblVahed.ID = tbl1.fldCodeVahed2) tbl2

where tbl2.fldCodeKala=#tempMojoodieAnbar.fldCodeKala


Select * from #TempMojoodieAnbar
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareDaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomareDaryaft]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareDaryafteJari bigint,
@NewShomareDaryaft bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 --set @NewShomareDaryaft=(	SELECT        ISNULL( max(fldShomareDaryaft),@ShomareDaryafteJari) AS Expr1
			--	FROM            tblDaryaft
			--	WHERE        (fldShomareDaryaft < @ShomareDaryafteJari and fldType=@TypeForm))
			set @NewShomareDaryaft=(	SELECT        ISNULL( max(fldShomareDaryaft),@ShomareDaryafteJari) AS Expr1
				FROM            tblDaryaft
				WHERE        (fldShomareDaryaft < @ShomareDaryafteJari ))
		
		end

	if @Type='bozorg'
		begin
		--set @NewShomareDaryaft=(	SELECT        isnull( min(fldShomareDaryaft),@ShomareDaryafteJari) AS Expr1
		--		FROM            tblDaryaft
		--		WHERE        (fldShomareDaryaft > @ShomareDaryafteJari  and fldType=@TypeForm))
		set @NewShomareDaryaft=(	SELECT        isnull( min(fldShomareDaryaft),@ShomareDaryafteJari) AS Expr1
				FROM            tblDaryaft
				WHERE        (fldShomareDaryaft > @ShomareDaryafteJari ))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomareEnteghal]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareEnteghalJari bigint,
@NewShomareEnteghal bigint output

as

begin
      
	   SET NOCOUNT ON;
	if @Type='koochak'
		begin
		 set @NewShomareEnteghal=(	SELECT        ISNULL( max(fldShomareEnteghal),@ShomareEnteghalJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareEnteghal < @ShomareEnteghalJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareEnteghal=(	SELECT        isnull( min(fldShomareEnteghal),@ShomareEnteghalJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareEnteghal > @ShomareEnteghalJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomareFactorBargashtAzForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorBargashtAzForooshJari bigint,
@NewShomareFactorBargashtAzForoosh bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorBargashtAzForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorBargashtAzForooshJari) AS Expr1
				FROM            tblRizeBargashtAzForoosh
				WHERE        (fldShomareFactor < @ShomareFactorBargashtAzForooshJari))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorBargashtAzForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorBargashtAzForooshJari) AS Expr1
				FROM            tblRizeBargashtAzForoosh
				WHERE        (fldShomareFactor > @ShomareFactorBargashtAzForooshJari ))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomareFactorBargashtAzKharid]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorKharidJari bigint,
@NewShomareFactorKharid bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorKharid=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorKharidJari) AS Expr1
				FROM            tblRizeBargashtAzKharid
				WHERE        (fldShomareFactor < @ShomareFactorKharidJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorKharid=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorKharidJari) AS Expr1
				FROM            tblRizeBargashtAzKharid
				WHERE        (fldShomareFactor > @ShomareFactorKharidJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomareFactorForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorForooshJari bigint,
@NewShomareFactorForoosh bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomareFactorKharid]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorKharidJari bigint,
@NewShomareFactorKharid bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorKharid=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorKharidJari) AS Expr1
				FROM            tblRizeKharid
				WHERE        (fldShomareFactor < @ShomareFactorKharidJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorKharid=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorKharidJari) AS Expr1
				FROM            tblRizeKharid
				WHERE        (fldShomareFactor > @ShomareFactorKharidJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomareFactorPishForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorForooshJari bigint,
@NewShomareFactorForoosh bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizePishForoosh
				WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizePishForoosh
				WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareFactorPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomareFactorPishPishForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorForooshJari bigint,
@NewShomareFactorForoosh bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizePishPishForoosh
				WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizePishPishForoosh
				WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomarePardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomarePardakht]
@Type nvarchar(50),
@ShomarePardakhteJari bigint,
@NewShomarePardakht bigint output

as

begin
	if @Type='koochak'
		begin
		 set @NewShomarePardakht=(	SELECT        ISNULL( max(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht < @ShomarePardakhteJari) and fldType<>'hazine'  and fldType<>'enteghalevajh') 
		 --insert into tbltest7	(fld2)
			--values(@ShomarePardakhteJari)
		end

	if @Type='bozorg'
		begin
		set @NewShomarePardakht=(	SELECT        isnull( min(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht > @ShomarePardakhteJari) and fldType<>'hazine'  and fldType<>'enteghalevajh') 
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomarePardakhtEnteghaleVajh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomarePardakhtEnteghaleVajh]
@Type nvarchar(50),
@ShomarePardakhteJari bigint,
@NewShomarePardakht bigint output

as

begin
	if @Type='koochak'
		begin
		 set @NewShomarePardakht=(	SELECT        ISNULL( max(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht < @ShomarePardakhteJari) and fldType='enteghalevajh') 
		 --insert into tbltest7	(fld2)
			--values(@ShomarePardakhteJari)
		end

	if @Type='bozorg'
		begin
		set @NewShomarePardakht=(	SELECT        isnull( min(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht > @ShomarePardakhteJari) and fldType='enteghalevajh') 
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomarePardakhtHazine]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomarePardakhtHazine]
@Type nvarchar(50),
@ShomarePardakhteJari bigint,
@NewShomarePardakht bigint output

as

begin
	if @Type='koochak'
		begin
		 set @NewShomarePardakht=(	SELECT        ISNULL( max(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht < @ShomarePardakhteJari) and fldType='hazine') 
		 --insert into tbltest7	(fld2)
			--values(@ShomarePardakhteJari)
		end

	if @Type='bozorg'
		begin
		set @NewShomarePardakht=(	SELECT        isnull( min(fldShomarePardakht),@ShomarePardakhteJari) AS Expr1
				FROM            tblPardakht
				WHERE        (fldShomarePardakht > @ShomarePardakhteJari) and fldType='hazine') 
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomarePasCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[KoochakBozorgShomarePasCheck]
@Type nvarchar(50),
--@TypeForm nvarchar(50),
@ShomarePasJari bigint,
@NewShomarePas bigint output

as

begin
      
	   SET NOCOUNT ON;
	if @Type='koochak'
		begin
		 set @NewShomarePas=(SELECT   ISNULL(max(fldShomarePas),@ShomarePasJari) AS Expr1
				FROM            tblPas
				WHERE        (fldShomarePas < @ShomarePasJari))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomarePas=(	SELECT   isnull(min(fldShomarePas),@ShomarePasJari) AS Expr1
				FROM            tblPas
				WHERE        (fldShomarePas > @ShomarePasJari ))
		end
end


GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareSanad_MojodiEbteda_doreh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomareSanad_MojodiEbteda_doreh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareSanadJari bigint,
@NewShomareSanad bigint output

as

begin
      
	   SET NOCOUNT ON;
	if @Type='koochak'
		begin
		 set @NewShomareSanad=(	SELECT        ISNULL( max(fldShomareSanad),@ShomareSanadJari) AS Expr1
				FROM            tblRizeKharid
				WHERE        (fldShomareSanad < @ShomareSanadJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareSanad=(	SELECT        isnull( min(fldShomareSanad),@ShomareSanadJari) AS Expr1
				FROM            tblRizeKharid
				WHERE        (fldShomareSanad > @ShomareSanadJari  and fldType=@TypeForm))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[KoochakBozorgShomareVosoolCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[KoochakBozorgShomareVosoolCheck]
@Type nvarchar(50),
--@TypeForm nvarchar(50),
@ShomareVosoolJari bigint,
@NewShomareVosool bigint output

as

begin
      
	   SET NOCOUNT ON;
	if @Type='koochak'
		begin
		 set @NewShomareVosool=(SELECT   ISNULL(max(fldShomareVosool),@ShomareVosoolJari) AS Expr1
				FROM            tblVosool
				WHERE        (fldShomareVosool < @ShomareVosoolJari))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareVosool=(	SELECT   isnull(min(fldShomareVosool),@ShomareVosoolJari) AS Expr1
				FROM            tblVosool
				WHERE        (fldShomareVosool > @ShomareVosoolJari ))
		end
end


GO
/****** Object:  StoredProcedure [dbo].[ListeAshkhasBaMande]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeAshkhasBaMande]
	-- Add the parameters for the stored procedure here
	@Filter nvarchar(15) output
AS

IF 1=0 BEGIN
 SET FMTONLY OFF
END

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	create table #TempListeAshkhas3(

		fldCodetafzili nvarchar(10),
		fldSharheTafzili nvarchar(200),
		fldBedehkar bigint,
		fldBestankar Bigint,
		fldMande bigint,
		fldAdress nvarchar(200),
		fldTell nvarchar(50),
		fldCodeGroup nvarchar(100),
		fldNameGroup nvarchar(50),
		fldVisitor bigint,
		fldNameVisitor nvarchar(200)
	)
	
    declare @CodeKolDaryaftani nvarchar(100),@CodeKolPardakhtani nvarchar(100)

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKolDaryaftani output
	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKolPardakhtani output

	
	Insert into #TempListeAshkhas3 (fldCodetafzili,fldBedehkar,fldBestankar,fldMande)	
		SELECT        fldCodeTafzili, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS SumBes, SUM(fldBedehkar - fldBestankar) AS Mande
			FROM            tblSodooreSanad
			WHERE        (fldCodeKol = @CodeKolDaryaftani) OR
									 (fldCodeKol= @CodeKolPardakhtani) and fldCodeNoeTafzili='1'
			GROUP BY fldCodeTafzili


	Insert into #TempListeAshkhas3 (fldCodetafzili,fldBedehkar,fldBestankar,fldMande)
		Select fldCodeTafzili, 0, 0, 0 from tblTafzili
			Where fldCodeNoe='1' and fldCodeTafzili Not In (Select fldCodeTafzili from #TempListeAshkhas3)


	update #TempListeAshkhas3  set fldSharheTafzili=tblTafzili.fldSharheTafzili,  fldAdress=tblTafzili.fldAddress , fldVisitor=tblTafzili.fldVisitor from tblTafzili
		where #TempListeAshkhas3.fldCodetafzili=tblTafzili.fldCodeTafzili


	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #TempListeAshkhas3  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin	
					

									
					update #TempListeAshkhas3  set  fldTell=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
							where fldCodetafzili=@EmpCodeTafzili
					Fetch Next from EmpCursor
				into @EmpCodeTafzili
			end
	Close EmpCurSor
	Deallocate EmpCursor

	--Select fldShomare from tblTafzili
	update #TempListeAshkhas3 set fldCodeGroup=tblTafzili.fldCodeGroup from tblTafzili Where #TempListeAshkhas3.fldCodetafzili=tblTafzili.fldCodeTafzili

	update #TempListeAshkhas3 set fldNameGroup=tblGroupAshkhas.fldGroupName from tblGroupAshkhas Where #TempListeAshkhas3.fldCodeGroup=tblGroupAshkhas.fldGroupId

	update #TempListeAshkhas3 set fldNameVisitor=tblTafzili.fldSharheTafzili from tblTafzili Where #TempListeAshkhas3.fldVisitor=tblTafzili.fldCodeTafzili

	if @Filter='bedehkaran' 
		delete #TempListeAshkhas3 Where fldMande<=0
	
	if @Filter='bestankaran'
		begin
			delete #TempListeAshkhas3 Where fldMande>=0
			update #TempListeAshkhas3 set fldMande=-1*fldMande
		end
	
	select fldNameGroup,fldCodetafzili,fldSharheTafzili, fldBedehkar,fldBestankar,fldMande,fldVisitor,fldTell,fldAdress,fldCodeGroup,fldNameVisitor from #TempListeAshkhas3


END

GO
/****** Object:  StoredProcedure [dbo].[ListeBedehkaran]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeBedehkaran]
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	--ناقصه باید کامل بشه
    declare @CodeKolDaryaftani nvarchar(100),@CodeKolPardakhtani nvarchar(100)

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKolDaryaftani output
	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKolPardakhtani output

	SELECT        fldCodeTafzili, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS SumBes, SUM(fldBedehkar - fldBestankar) AS Mande
		FROM            tblSodooreSanad
		WHERE        (fldMoinKamel = @CodeKolDaryaftani) OR
								 (fldMoinKamel = @CodeKolPardakhtani)
		GROUP BY fldCodeTafzili
END

GO
/****** Object:  StoredProcedure [dbo].[ListeCheckhayePasNashode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeCheckhayePasNashode]
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	--SELECT         ID, fldShomareCheck, fldShomareHesab, fldDateSarResid, SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 1, 4) 
 --                        + '/' + SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResidShow, 
 --                        fldCodeBank, fldShobe, fldMablagh, fldDatePardakht, SUBSTRING(CONVERT(nvarchar, fldDatePardakht), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, 
 --                        fldDatePardakht), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, fldDatePardakht), 7, 2) AS fldDatePardakhtShow, fldCodeSahebeCheck, fldShomarePardakht, 
 --                        fldCodeSahebeHesab, fldVasete, fldSanad, fldShomarePass, fldDatePass, fldSharhePass
	--	FROM            dbo.tblCheckePardakhti
	--		WHERE        (fldShomarePass IS NULL)
	--			ORDER BY fldDateSarResid


	SELECT        dbo.tblCheckePardakhti.ID, dbo.tblCheckePardakhti.fldShomareCheck, dbo.tblCheckePardakhti.fldShomareHesab, dbo.tblCheckePardakhti.fldDateSarResid, 
                         SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 
                         5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
						 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab,  dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,
                         dbo.tblCheckePardakhti.fldMablagh, dbo.tblCheckePardakhti.fldDatePardakht, SUBSTRING(CONVERT(nvarchar, 
                         dbo.tblCheckePardakhti.fldDatePardakht), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDatePardakht), 5, 2) 
                         + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDatePardakht), 7, 2) AS fldDatePardakhtShow, 
                         dbo.tblCheckePardakhti.fldShomarePardakht, dbo.tblCheckePardakhti.fldCodeSahebeHesab, dbo.tblCheckePardakhti.fldVasete, dbo.tblCheckePardakhti.fldSanad, 
                         dbo.tblCheckePardakhti.fldShomarePass, dbo.tblCheckePardakhti.fldDatePass, dbo.tblCheckePardakhti.fldSharhePass, 
                         dbo.tblCheckePardakhti.fldShobe
FROM            dbo.tblCheckePardakhti INNER JOIN
                         dbo.tblTafzili ON dbo.tblCheckePardakhti.fldCodeSahebeCheck = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblKolMoin ON dbo.tblCheckePardakhti.fldCodeBank = dbo.tblKolMoin.fldCodeHesab
WHERE        (dbo.tblCheckePardakhti.fldShomarePass IS NULL)
			ORDER BY fldDateSarResid
END

GO
/****** Object:  StoredProcedure [dbo].[ListeCheckhayePasShode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeCheckhayePasShode] 
	-- Add the parameters for the stored procedure here
	@ShomarePas bigint
	
AS
BEGIN

	SELECT        dbo.tblCheckePardakhti.ID, dbo.tblCheckePardakhti.fldShomareCheck, dbo.tblCheckePardakhti.fldShomareHesab, dbo.tblCheckePardakhti.fldDateSarResid, 
                         SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 
                         5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
						 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab,  dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,
                         dbo.tblCheckePardakhti.fldMablagh, dbo.tblCheckePardakhti.fldDatePardakht, SUBSTRING(CONVERT(nvarchar, 
                         dbo.tblCheckePardakhti.fldDatePardakht), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDatePardakht), 5, 2) 
                         + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckePardakhti.fldDatePardakht), 7, 2) AS fldDatePardakhtShow, 
                         dbo.tblCheckePardakhti.fldShomarePardakht, dbo.tblCheckePardakhti.fldCodeSahebeHesab, dbo.tblCheckePardakhti.fldVasete, dbo.tblCheckePardakhti.fldSanad, 
                         dbo.tblCheckePardakhti.fldShomarePass, dbo.tblCheckePardakhti.fldDatePass, dbo.tblCheckePardakhti.fldSharhePass, 
                         dbo.tblCheckePardakhti.fldShobe,fldSanadPas
FROM            dbo.tblCheckePardakhti INNER JOIN
                         dbo.tblTafzili ON dbo.tblCheckePardakhti.fldCodeSahebeCheck = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblKolMoin ON dbo.tblCheckePardakhti.fldCodeBank = dbo.tblKolMoin.fldCodeHesab
WHERE        (dbo.tblCheckePardakhti.fldShomarePass IS Not NULL) and dbo.tblCheckePardakhti.fldShomarePass=@ShomarePas
			ORDER BY fldDateSarResid

END

GO
/****** Object:  StoredProcedure [dbo].[ListeFactorhayeTasfieNashode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashode] 
	@CodeTafzili nvarchar(10),
	@ShomareDaryaft bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie2(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10),
	[fldMablagheMande][bigint],
	[fldSharh][nvarchar](100),
	[fldMablagheDaryaftiJari] [bigint],
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint]

	)

	--insert into #tmpDaryaftTasfie2
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		


	insert into #tmpDaryaftTasfie2
		(fldShomareFactor,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldSharh,fldDateSarResid)
		Select fldShomareFactor,0,fldCodeTafzili, fldMablagheMandeFactor,fldSharh,fldDateSarResid
			from tblTasfie
			where fldCodeTafzili = @CodeTafzili

	update #tmpDaryaftTasfie2
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie2.fldShomareFactor=tbl1.fldShomareFactor

--FROM            tblTasfie

--	SELECT        #tmpDaryaftTasfie2.fldShomareFactor, #tmpDaryaftTasfie2.SumDaryafti, tblTasfie.fldCodeTafzili, tblTasfie.fldMablagheMande, tblTasfie.fldSharh, 
--							 tblTasfie.fldDateSarResid
--	FROM            #tmpDaryaftTasfie2 INNER JOIN
--							 tblTasfie ON #tmpDaryaftTasfie2.fldShomareFactor = tblTasfie.fldShomareFactor
--					WHERE        (tblTasfie.fldCodeTafzili = @CodeTafzili)


	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
		(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
		where tbl2.fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor

	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null

	Select fldShomareFactor,SumDaryafti,fldMablagheMande,fldSharh,fldMablagheDaryaftiJari,
		substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid
		from #tmpDaryaftTasfie2
			where fldMablagheMande>SumDaryafti or fldMablagheDaryaftiJari>0
		order by fldDateSarResid,fldShomareFactor

END

GO
/****** Object:  StoredProcedure [dbo].[ListeFactorhayeTasfieNashodeReport]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReport] 
	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@FlagSort Varchar(15),
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie3(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10),
	[fldMablagheMande][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100),	
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200),
	[codeTafzili][nvarchar](10),
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80),
	[fldCodeVasete][bigint],
	[NameVasete][nvarchar](200),
	[Tell][nvarchar](50),
	[Adress][nvarchar](200)

	)

	--insert into #tmpDaryaftTasfie3
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
		insert into #tmpDaryaftTasfie3
			(fldShomareFactor,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldSharh,fldDateSarResid)
			Select fldShomareFactor,0,fldCodeTafzili, fldMablagheMandeFactor,fldSharh,fldDateSarResid
				from tblTasfie
	
		if @Codetafzili<>0 --یعنی همه افراد
			delete #tmpDaryaftTasfie3 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie3
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie3.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie3.fldShomareFactor=tbl1.fldShomareFactor




	--update #tmpDaryaftTasfie3 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie3.fldShomareFactor

	--update #tmpDaryaftTasfie3 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie3 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti

	--بروزرسانی کد تفصیلی
	update #tmpDaryaftTasfie3 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie3.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرسانی نام تفصیلی
	update #tmpDaryaftTasfie3 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie3.codeTafzili=tbl5.fldCodeTafzili

	--بروزرسانی کدگروه 
	update #tmpDaryaftTasfie3 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie3.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرسانی نام گروه
	update #tmpDaryaftTasfie3  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie3.fldCodeGroupAshkhas

	--بروزرسانی کد ویزیتورها
	
	update #tmpDaryaftTasfie3  set fldCodeVasete = tbl7.fldCodeVasete from
		(SELECT        tblForoosh.fldShomareFactorForoosh, tblRizeForoosh.fldCodeVasete
			FROM            tblForoosh INNER JOIN
							 tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl7
		where #tmpDaryaftTasfie3.fldShomareFactor=tbl7.fldShomareFactorForoosh

	--بروزرسانی نام ویزیتورها
	update #tmpDaryaftTasfie3  set NameVasete=tbl8.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl8
		where #tmpDaryaftTasfie3.fldCodeVasete=tbl8.fldCodeTafzili  and fldCodeVasete<>0
	
	update #tmpDaryaftTasfie3 set NameVasete='' where fldCodeVasete=0


	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie3 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie3 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeVisitor<>''
			begin
				if @ListCodeVisitor='-1' --لیست فاکتورهای بدون ویزیتور
					begin
						delete from #tmpDaryaftTasfie3 where fldCodeVasete<>0
					end
				else
					begin
					declare @StrDeleteVisitor varchar(5000)
					set  @StrDeleteVisitor='delete from #tmpDaryaftTasfie3 
						where '+ @ListCodeVisitor + ''
						execute(@StrDeleteVisitor)
					end
			end


	if @DataType='tasfienashode'
		delete from #tmpDaryaftTasfie3 where fldMablagheMande=SumDaryafti

	if @DataType='tasfieshode'
		delete from #tmpDaryaftTasfie3 where fldMablagheMande<>SumDaryafti


	--بروزرسانی تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie3  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie3  set  Tell=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
							where fldCodetafzili=@EmpCodeTafzili
					Fetch Next from EmpCursor
				into @EmpCodeTafzili
			end
	Close EmpCurSor
	Deallocate EmpCursor


	update #tmpDaryaftTasfie3  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie3.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie3)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie3)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie3			
				order by fldDateSarResid,fldShomareFactor
	
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie3			
				order by fldShomareFactor,fldDateSarResid

	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie3			
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie3			
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid
	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie3			
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) +'f' as fldDateSarResid,	
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie3			
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) + 'g' as fldDateSarResid,	
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie3			
			order by NameVasete asc,fldShomareFactor,fldDateSarResid

	--declare @strEXE nvarchar(300),@Order nvarchar(100)

	--if @FlagSort='date'
	--	set @order=' order by fldDateSarResid,fldShomareFactor'
	--set @strEXE='Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheMande,SumDaryafti,fldmandeTasfienashode, 		
	--	fldDateSarResid ,NameVasete,Tell,Adress,fldSharh from #tmpDaryaftTasfie3' + @order			


END

GO
/****** Object:  StoredProcedure [dbo].[ListeTafziliWithNoe]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ListeTafziliWithNoe] 
	@CodeNoe nvarchar(10)
AS
BEGIN
	Select fldCodeTafzili,fldSharheTafzili,fldCodeNoe from tblTafzili
		where fldCodeNoe=@CodeNoe
		order by Convert(dec,fldCodeTafzili)
END

GO
/****** Object:  StoredProcedure [dbo].[LoadPrinterOfKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[LoadPrinterOfKala] 
	-- Add the parameters for the stored procedure here
	@CodeKala bigint,
	@IdPrinter Bigint output
AS
BEGIN
	set @IdPrinter =(Select fldIDChapgarKala from tblIDChapgarKala Where fldCodeKala=@CodeKala)
	if @IdPrinter is null
		set @IdPrinter = -1
		
END

GO
/****** Object:  StoredProcedure [dbo].[LoadShomareFishBeTafkikeChapger]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[LoadShomareFishBeTafkikeChapger]
	@fldShomareFactor bigint,
	@IDChapgarKala bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	create table #tmpFactor2(
		fldRadif bigint,
		fldCodeKala bigint,
		fldNameKala nvarchar(100),
		fldSharhKala nvarchar(100),
		fldTedadCarton nvarchar(10),
		fldTedadJoz bigint,
		fldFeeJoz bigint,		
		fldFeeYekCarton bigint,
		fldFeeKol bigint ,
        fldDarsadTakhfif bigint,
		fldMablaghTakhfif bigint,
		fldFeeVahed1BadAzTakhfif bigint, 
        fldFeeVahed2BadAzTakhfif bigint,
		fldArzeshAfzode bigint,
		fldFeeKolBadAzTakhfif bigint, 
        fldMablaghKhales bigint,
		fldCodeAnbar bigint,
		fldNameVahed nvarchar(100),	
		fldNameVahed2	nvarchar(100),	
		fldNameAnbar nvarchar(50),
		fldVahed1Code bigint,
		fldVahed2Code bigint,
		fldGhymatMasrafkonande bigint,
		fldCodePrinter bigint

	)

		insert into #tmpFactor2(fldRadif,fldCodeKala ,fldNameKala ,fldSharhKala,fldTedadCarton,fldTedadJoz,
				fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif, 
				fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldCodeAnbar,
				fldNameVahed,fldNameVahed2,fldNameAnbar,fldVahed1Code,fldVahed2Code,fldGhymatMasrafkonande)
		
		SELECT        dbo.tblRizeForoosh.fldRadif, dbo.tblRizeForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeForoosh.fldSharhKala, dbo.tblRizeForoosh.fldTedadCarton, 
                         dbo.tblRizeForoosh.fldTedadJoz, dbo.tblRizeForoosh.fldFeeJoz, dbo.tblRizeForoosh.fldFeeYekCarton, dbo.tblRizeForoosh.fldFeeKol, 
                         dbo.tblRizeForoosh.fldDarsadTakhfif, dbo.tblRizeForoosh.fldMablaghTakhfif, dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeForoosh.fldArzeshAfzode, dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldCodeAnbar, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
		FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizeForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizeForoosh.fldShomareFactor = @fldShomareFactor)

	update #tmpFactor2 set fldCodePrinter = tblIDChapgarKala.fldIDChapgarKala  from tblIDChapgarKala Where #tmpFactor2.fldCodeKala=tblIDChapgarKala.fldCodeKala
	update #tmpFactor2 set fldCodePrinter =0 where fldCodePrinter is null
	select fldNameKala,fldTedadJoz,fldCodePrinter from #tmpFactor2 Where fldCodePrinter=@IDChapgarKala order by Convert(dec,fldRadif)
END

GO
/****** Object:  StoredProcedure [dbo].[MandeAnbarReport]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[MandeAnbarReport]
	@CodeGroup bigint
as

begin
	Select * from tblKala Where fldCodeGroup=@CodeGroup
end
GO
/****** Object:  StoredProcedure [dbo].[MandeKolTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[MandeKolTafzili]
@CodeTafzili nvarchar(10),
@Mande bigint output
as

begin
	--declare @CodeKolMoin nvarchar(10),@MandeTalab bigint,@MandeBedehi bigint
	--execute CodeMoinHesab 'hesabhayedaryaftani',@CodeKolMoin output

	--set @MandeTalab=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0) - ISNULL(fldBestankar, 0)),0) AS SumM
	--	FROM            tblSodooreSanad
	--	WHERE      (fldMoinKamel=@CodeKolMoin) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)

	--execute CodeMoinHesab 'hesabhayepardakhtani',@CodeKolMoin output

	--set @MandeBedehi=(SELECT       ISNULL( SUM(ISNULL(fldBestankar, 0) - ISNULL(fldBedehkar, 0)),0) AS SumM
	--	FROM            tblSodooreSanad
	--	WHERE      (fldMoinKamel=@CodeKolMoin) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)
	--set @Mande=@MandeTalab-@MandeBedehi

	declare @CodeKol nvarchar(100),@MandeTalab bigint,@MandeBedehi bigint,@Sanad bigint

	set @Sanad =(Select Max(Convert(dec,fldSanad)) from tblSodooreSanad )
	if @Sanad is null
		set @sanad=0

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKol output

	--INSERT  INTO dbo.tblTest5(name1, name2, name3)
	--	VALUES        (@CodeKol,'','')
	--execute NameKolMoin @strcodemoinkamel  ,@strNameHesab output
	set @MandeTalab=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0) - ISNULL(fldBestankar, 0)),0) AS SumM
		FROM            tblSodooreSanad
		WHERE      (fldCodeKol=@CodeKol) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)

	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKol output

	set @MandeBedehi=(SELECT       ISNULL( SUM(ISNULL(fldBestankar, 0) - ISNULL(fldBedehkar, 0)),0) AS SumM
		FROM            tblSodooreSanad
		WHERE      (fldCodeKol=@CodeKol) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)
	set @Mande=@MandeTalab-@MandeBedehi

end
GO
/****** Object:  StoredProcedure [dbo].[MandeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MandeTafzili]
@CodeTafzili nvarchar(10),
@Sanad bigint,
@Mande bigint output
as

begin
	--declare @CodeKolMoin nvarchar(10),@MandeTalab bigint,@MandeBedehi bigint
	--execute CodeMoinHesab 'hesabhayedaryaftani',@CodeKolMoin output

	--set @MandeTalab=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0) - ISNULL(fldBestankar, 0)),0) AS SumM
	--	FROM            tblSodooreSanad
	--	WHERE      (fldMoinKamel=@CodeKolMoin) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)

	--execute CodeMoinHesab 'hesabhayepardakhtani',@CodeKolMoin output

	--set @MandeBedehi=(SELECT       ISNULL( SUM(ISNULL(fldBestankar, 0) - ISNULL(fldBedehkar, 0)),0) AS SumM
	--	FROM            tblSodooreSanad
	--	WHERE      (fldMoinKamel=@CodeKolMoin) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)
	--set @Mande=@MandeTalab-@MandeBedehi

	declare @CodeKol nvarchar(100),@MandeTalab bigint,@MandeBedehi bigint

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKol output

	--INSERT  INTO dbo.tblTest5(name1, name2, name3)
	--	VALUES        (@CodeKol,'','')
	--execute NameKolMoin @strcodemoinkamel  ,@strNameHesab output
	set @MandeTalab=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0) - ISNULL(fldBestankar, 0)),0) AS SumM
		FROM            tblSodooreSanad
		WHERE      (fldCodeKol=@CodeKol) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)

	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKol output

	set @MandeBedehi=(SELECT       ISNULL( SUM(ISNULL(fldBestankar, 0) - ISNULL(fldBedehkar, 0)),0) AS SumM
		FROM            tblSodooreSanad
		WHERE      (fldCodeKol=@CodeKol) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)
	set @Mande=@MandeTalab-@MandeBedehi

end
GO
/****** Object:  StoredProcedure [dbo].[MandeTafziliBedehi]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[MandeTafziliBedehi]
@CodeTafzili nvarchar(10),
@Sanad bigint,
@Mande bigint output
as

begin
	declare @CodeKolMoin nvarchar(10)
	execute CodeMoinHesab 'hesabhayepardakhtani',@CodeKolMoin output

	set @Mande=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0) - ISNULL(fldBestankar, 0)),0) AS SumM
		FROM            tblSodooreSanad
		WHERE      (fldMoinKamel=@CodeKolMoin) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldSanad)<=@Sanad)

	
end
GO
/****** Object:  StoredProcedure [dbo].[MaxDateAndMinDate]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[MaxDateAndMinDate]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizeForoosh) 
if @MaxDate is null
	set @MaxDate=0
set @minDate=(select min(flddate) from tblRizeForoosh) 
if @minDate is null	
	set @minDate=0

Return @MaxDate
Return @minDate
END

GO
/****** Object:  StoredProcedure [dbo].[MaxDateAndMinDate_RizeKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[MaxDateAndMinDate_RizeKharid]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizeKharid) 
set @minDate=(select min(flddate) from tblRizeKharid) 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END

GO
/****** Object:  StoredProcedure [dbo].[MaxDateAndMinDateSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[MaxDateAndMinDateSanad]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(Convert(dec,flddate)) from tblSodooreSanad) 
set @minDate=(select min(Convert(dec,flddate)) from tblSodooreSanad) 
Return @MaxDate
Return @minDate
END

GO
/****** Object:  StoredProcedure [dbo].[MaxShomareDaryaft]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareDaryaft]
@lngMaxShomareDaryaft bigint output
as

begin
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomareDaryaft) from tblDaryaft)
	if @lngCount>0 
		begin
 			set @lngMaxShomareDaryaft =(Select Max(fldShomareDaryaft) from tblDaryaft)
		end
	else
		set @lngMaxShomareDaryaft =0
end
GO
/****** Object:  StoredProcedure [dbo].[MaxShomareEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareEnteghal]
@lngMaxShomareEnteghal bigint output
as

begin

            			SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomareEnteghal) from tblRizeForoosh)
	if @lngCount>0 
		begin
 			set @lngMaxShomareEnteghal =(Select Max(fldShomareEnteghal) from tblRizeForoosh)
		end
	else
		set @lngMaxShomareEnteghal =0
end



GO
/****** Object:  StoredProcedure [dbo].[MaxShomareFish]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[MaxShomareFish]
	-- Add the parameters for the stored procedure here
	@MaxShomare bigint output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @bigMax bigint
    -- Insert statements for procedure here
	set @bigMax=(Select Max(fldShomareFish) from tblFish)
	if @bigMax is  null
		set @MaxShomare=1
	else
		set @MaxShomare=@bigMax+1
END

GO
/****** Object:  StoredProcedure [dbo].[MaxShomarePardakht]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE proc [dbo].[MaxShomarePardakht]
@lngMaxShomarePardakht bigint output
as

begin
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomarePardakht) from tblPardakht)
	if @lngCount>0 
		begin
 			set @lngMaxShomarePardakht =(Select Max(fldShomarePardakht) from tblPardakht)
		end
	else
		set @lngMaxShomarePardakht =0
end

GO
/****** Object:  StoredProcedure [dbo].[MaxShomarePas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[MaxShomarePas]
@lngMaxShomarePas bigint output
as

begin

     SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomarePas) from tblPas)
	if @lngCount > 0 
		begin
 			set @lngMaxShomarePas =(Select Max(fldShomarePas) from tblPas)
		end
	else
		set @lngMaxShomarePas =0
end


GO
/****** Object:  StoredProcedure [dbo].[MaxShomareSanad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareSanad]
@lngMaxShomareSanad bigint output
as

begin
	declare @lngCount bigint
	set @lngCount=(Select Count(fldSanad) from tblSodooreSanad)
	if @lngCount>0 
		begin
 			set @lngMaxShomareSanad =(Select Max(Convert(bigint,fldSanad)) from tblSodooreSanad)
		end
	else
		set @lngMaxShomareSanad =0
end
GO
/****** Object:  StoredProcedure [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ashkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ashkhas] --ali 96-01-29
@lngMaxShomareSanad bigint output
as

begin
     SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldSanad) from tblSodooreSanad where fldSanad='1')
	if @lngCount > 0 
		begin
 			set @lngMaxShomareSanad =(Select Max(Convert(bigint,fldSanad)) from tblSodooreSanad)
			set @lngMaxShomareSanad=@lngMaxShomareSanad + 1
		end
	else
		set @lngMaxShomareSanad =1
end

GO
/****** Object:  StoredProcedure [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ebteda]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ebteda] --ali 95-12-24
@lngMaxShomareSanad bigint output
as

begin
     SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldSanad) from tblSodooreSanad where fldSanad='1')
	if @lngCount > 0 
		begin
 			set @lngMaxShomareSanad =(Select Max(Convert(bigint,fldSanad)) from tblSodooreSanad)
			set @lngMaxShomareSanad=@lngMaxShomareSanad + 1
		end
	else
		set @lngMaxShomareSanad =1
end
GO
/****** Object:  StoredProcedure [dbo].[MaxShomareVosool]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[MaxShomareVosool]
@lngMaxShomareVosool bigint output
as

begin

     SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomareVosool) from tblVosool)
	if @lngCount > 0 
		begin
 			set @lngMaxShomareVosool =(Select Max(fldShomareVosool) from tblVosool)
		end
	else
		set @lngMaxShomareVosool =0
end


GO
/****** Object:  StoredProcedure [dbo].[NameHesab]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[NameHesab]
@CodeHesab nvarchar(10),
@SharheHesab nvarchar(50) Output

as
begin
	set @SharheHesab=(Select fldSharhehesab from tblKolMoin Where fldCodeHesab=@CodeHesab)
end
GO
/****** Object:  StoredProcedure [dbo].[NamePrinter]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[NamePrinter]
	-- Add the parameters for the stored procedure here
	@IdPrinter bigint,
	@EsmePrinter nvarchar(Max) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @strName nvarchar(max)

	set @strName = (Select fldNamePrinter from tblPrinters Where id=@IdPrinter)
	if @strName is null
		set @EsmePrinter=''
	else
		set @EsmePrinter = @strName
    
END

GO
/****** Object:  StoredProcedure [dbo].[NextOrBeforFactorShakhs]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[NextOrBeforFactorShakhs] 
	-- Add the parameters for the stored procedure here
@Type nvarchar(50),
@ShomareFactorForooshJari bigint,
@CodeTafzili nvarchar(10),
@NewShomareFactorForoosh bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='before'
		begin
		 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareFactor < @ShomareFactorForooshJari and  fldCodeTafsili=@CodeTafzili ))
		
		end

	if @Type='next'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and  fldCodeTafsili=@CodeTafzili))
		end
end

GO
/****** Object:  StoredProcedure [dbo].[procGridBargashtAzForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[procGridBargashtAzForoosh]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizeBargashtAzForoosh.fldRadif, dbo.tblRizeBargashtAzForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeBargashtAzForoosh.fldSharhKala, dbo.tblRizeBargashtAzForoosh.fldTedadCarton, 
                         dbo.tblRizeBargashtAzForoosh.fldTedadJoz, dbo.tblRizeBargashtAzForoosh.fldFeeJoz, dbo.tblRizeBargashtAzForoosh.fldFeeYekCarton, dbo.tblRizeBargashtAzForoosh.fldFeeKol, 
                         dbo.tblRizeBargashtAzForoosh.fldDarsadTakhfif, dbo.tblRizeBargashtAzForoosh.fldMablaghTakhfif, dbo.tblRizeBargashtAzForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeBargashtAzForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeBargashtAzForoosh.fldArzeshAfzode, dbo.tblRizeBargashtAzForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeBargashtAzForoosh.fldMablaghKhales, dbo.tblRizeBargashtAzForoosh.fldCodeAnbar, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizeBargashtAzForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeBargashtAzForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizeBargashtAzForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizeBargashtAzForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[procGridBargashtAzKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[procGridBargashtAzKharid]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizeBargashtAzKharid.fldRadif, dbo.tblRizeBargashtAzKharid.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeBargashtAzKharid.fldSharhKala, dbo.tblRizeBargashtAzKharid.fldTedadCarton, 
                         dbo.tblRizeBargashtAzKharid.fldTedadJoz, dbo.tblRizeBargashtAzKharid.fldFeeJoz, dbo.tblRizeBargashtAzKharid.fldFeeYekCarton, dbo.tblRizeBargashtAzKharid.fldFeeKol, 
                         dbo.tblRizeBargashtAzKharid.fldDarsadTakhfif, dbo.tblRizeBargashtAzKharid.fldMablaghTakhfif, dbo.tblRizeBargashtAzKharid.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeBargashtAzKharid.fldFeeVahed2BadAzTakhfif, dbo.tblRizeBargashtAzKharid.fldArzeshAfzode, dbo.tblRizeBargashtAzKharid.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeBargashtAzKharid.fldMablaghKhales, dbo.tblRizeBargashtAzKharid.fldCodeAnbar,dbo.tblRizeBargashtAzKharid.fldHamloNaghl, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
			FROM            dbo.tblAnbar INNER JOIN
									 dbo.tblRizeBargashtAzKharid ON dbo.tblAnbar.fldCode = dbo.tblRizeBargashtAzKharid.fldCodeAnbar INNER JOIN
									 dbo.tblKala ON dbo.tblRizeBargashtAzKharid.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
									 dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
									 dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
			WHERE        (dbo.tblRizeBargashtAzKharid.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[procGridForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[procGridForoosh]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizeForoosh.fldRadif, dbo.tblRizeForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeForoosh.fldSharhKala, dbo.tblRizeForoosh.fldTedadCarton, 
                         dbo.tblRizeForoosh.fldTedadJoz, dbo.tblRizeForoosh.fldFeeJoz, dbo.tblRizeForoosh.fldFeeYekCarton, dbo.tblRizeForoosh.fldFeeKol, 
                         dbo.tblRizeForoosh.fldDarsadTakhfif, dbo.tblRizeForoosh.fldMablaghTakhfif, dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeForoosh.fldArzeshAfzode, dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldCodeAnbar, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizeForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizeForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[procGridKharid]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[procGridKharid]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizeKharid.fldRadif, dbo.tblRizeKharid.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeKharid.fldSharhKala, dbo.tblRizeKharid.fldTedadCarton, 
                         dbo.tblRizeKharid.fldTedadJoz, dbo.tblRizeKharid.fldFeeJoz, dbo.tblRizeKharid.fldFeeYekCarton, dbo.tblRizeKharid.fldFeeKol, 
                         dbo.tblRizeKharid.fldDarsadTakhfif, dbo.tblRizeKharid.fldMablaghTakhfif, dbo.tblRizeKharid.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizeKharid.fldFeeVahed2BadAzTakhfif, dbo.tblRizeKharid.fldArzeshAfzode, dbo.tblRizeKharid.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizeKharid.fldMablaghKhales, dbo.tblRizeKharid.fldCodeAnbar,dbo.tblRizeKharid.fldHamloNaghl, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
			FROM            dbo.tblAnbar INNER JOIN
									 dbo.tblRizeKharid ON dbo.tblAnbar.fldCode = dbo.tblRizeKharid.fldCodeAnbar INNER JOIN
									 dbo.tblKala ON dbo.tblRizeKharid.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
									 dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
									 dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
			WHERE        (dbo.tblRizeKharid.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[procGridPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[procGridPishForoosh]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizePishForoosh.fldRadif, dbo.tblRizePishForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizePishForoosh.fldSharhKala, dbo.tblRizePishForoosh.fldTedadCarton, 
                         dbo.tblRizePishForoosh.fldTedadJoz, dbo.tblRizePishForoosh.fldFeeJoz, dbo.tblRizePishForoosh.fldFeeYekCarton, dbo.tblRizePishForoosh.fldFeeKol, 
                         dbo.tblRizePishForoosh.fldDarsadTakhfif, dbo.tblRizePishForoosh.fldMablaghTakhfif, dbo.tblRizePishForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizePishForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizePishForoosh.fldArzeshAfzode, dbo.tblRizePishForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizePishForoosh.fldMablaghKhales, dbo.tblRizePishForoosh.fldCodeAnbar,dbo.tblRizePishForoosh.fldCodeVasete, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizePishForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizePishForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizePishForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizePishForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[procGridPishPishForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[procGridPishPishForoosh]
	@fldShomareFactor bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   SELECT        dbo.tblRizePishPishForoosh.fldRadif, dbo.tblRizePishPishForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizePishPishForoosh.fldSharhKala, dbo.tblRizePishPishForoosh.fldTedadCarton, 
                         dbo.tblRizePishPishForoosh.fldTedadJoz, dbo.tblRizePishPishForoosh.fldFeeJoz, dbo.tblRizePishPishForoosh.fldFeeYekCarton, dbo.tblRizePishPishForoosh.fldFeeKol, 
                         dbo.tblRizePishPishForoosh.fldDarsadTakhfif, dbo.tblRizePishPishForoosh.fldMablaghTakhfif, dbo.tblRizePishPishForoosh.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizePishPishForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizePishPishForoosh.fldArzeshAfzode, dbo.tblRizePishPishForoosh.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizePishPishForoosh.fldMablaghKhales, dbo.tblRizePishPishForoosh.fldCodeAnbar,dbo.tblRizePishPishForoosh.fldCodeVasete, tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2, 
                         dbo.tblAnbar.fldNameAnbar, tblVahed_2.ID AS fldVahed1Code, dbo.tblVahed.ID AS fldVahed2Code, isnull(dbo.tblKala.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizePishPishForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizePishPishForoosh.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizePishPishForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
WHERE        (dbo.tblRizePishPishForoosh.fldShomareFactor = @fldShomareFactor)
END

GO
/****** Object:  StoredProcedure [dbo].[QueryDynamic]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[QueryDynamic]
	@strQuery nvarchar(3000)
as
begin
	--declare	@strQuery nvarchar(3000)
	--set @strQuery='select * from tblForoosh'
	execute (@strQuery)
end

GO
/****** Object:  StoredProcedure [dbo].[Report_ListAshkhas_groupby_CodeGroup_order_SharhTafsili_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Report_ListAshkhas_groupby_CodeGroup_order_SharhTafsili_final]
@CodeGroupAshkhas varchar(5000)=null
as
--declare @myReport varchar(5000)
begin
     SET NOCOUNT ON;
	 -- -----------------------------------------TempTable In Below Code
IF OBJECT_ID('tempdb..#TempListAshkhas1') IS NOT NULL
 begin
	delete from  #TempListAshkhas1
 end
else 
begin
create table #TempListAshkhas1(
fldSharheTafzili Nvarchar(200),
fldCodeGroup bigint,
fldGroupName Nvarchar(200),
fldShomare Nvarchar(50),
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50),
fldAddress Nvarchar(400)

)
end
insert into #TempListAshkhas1(fldSharheTafzili,fldCodeGroup,fldGroupName,fldShomare,fldCodeTafzili,fldCodeMeli,fldAddress)
select dbo.tblTafzili.fldSharheTafzili,
dbo.tblTafzili.fldCodeGroup,
dbo.tblGroupAshkhas.fldGroupName,
isnull(dbo.tblDaftarcheTell.fldShomare,'') as fldShomare,
dbo.tblTafzili.fldCodeTafzili, 
isnull(dbo.tblTafzili.fldCodeMeli,0) as fldCodeMeli,
isnull (dbo.tblTafzili.fldAddress,'') as fldAddress
                         
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(bigint, dbo.tblTafzili.fldCodeTafzili) = CONVERT(bigint, dbo.tblDaftarcheTell.fldCodeTafzili)



if @CodeGroupAshkhas<>''
begin
declare @StrDeleteGroupAshkhas varchar(5000)
set  @StrDeleteGroupAshkhas='delete from #TempListAshkhas1
	where  '+ @CodeGroupAshkhas + ''
	execute(@StrDeleteGroupAshkhas)
end


SELECT  fldSharheTafzili,fldCodeGroup,fldGroupName,fldShomare,fldCodeTafzili,fldCodeMeli,fldAddress
                   
FROM      #TempListAshkhas1
ORDER BY  fldSharheTafzili asc

----set @myReport= 'SELECT DISTINCT 
----                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
----                         dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress
----FROM            dbo.tblGroupAshkhas INNER JOIN
----                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
----                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)
----GROUP BY  dbo.tblGroupAshkhas.fldGroupName,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupId,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
----                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress
----HAVING        (dbo.tblTafzili.fldCodeGroup IN (' + @CodeGroupAshkhas + '))
----ORDER BY  dbo.tblTafzili.fldSharheTafzili'

----exec( @myReport)
end
GO
/****** Object:  StoredProcedure [dbo].[Report_ListAshkhas_groupby_NameGroup_order_SharhTafsili_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Report_ListAshkhas_groupby_NameGroup_order_SharhTafsili_final]
@CodeGroupAshkhas varchar(5000)=null
as
--declare @myReport varchar(5000)
begin
     SET NOCOUNT ON;
	 -- -----------------------------------------TempTable In Below Code

	 IF OBJECT_ID('tempdb..#TempListAshkhas') IS NOT NULL
 begin
	delete from  #TempListAshkhas
 end
else 
begin
create table #TempListAshkhas(
fldSharheTafzili Nvarchar(200),
fldCodeGroup bigint,
fldGroupName Nvarchar(200),
fldShomare Nvarchar(50),
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50),
fldAddress Nvarchar(400)

)
end
insert into #TempListAshkhas(fldSharheTafzili,fldCodeGroup,fldGroupName,fldShomare,fldCodeTafzili,fldCodeMeli,fldAddress)
select dbo.tblTafzili.fldSharheTafzili,
dbo.tblTafzili.fldCodeGroup,
dbo.tblGroupAshkhas.fldGroupName,
isnull(dbo.tblDaftarcheTell.fldShomare,'') as fldShomare,
dbo.tblTafzili.fldCodeTafzili, 
isnull(dbo.tblTafzili.fldCodeMeli,0) as fldCodeMeli,
isnull (dbo.tblTafzili.fldAddress,'') as fldAddress
                         
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(bigint, dbo.tblTafzili.fldCodeTafzili) = CONVERT(bigint, dbo.tblDaftarcheTell.fldCodeTafzili)



if @CodeGroupAshkhas<>''
begin
declare @StrDeleteGroupAshkhas varchar(5000)
set  @StrDeleteGroupAshkhas='delete from #TempListAshkhas
	where  '+ @CodeGroupAshkhas + ''
	execute(@StrDeleteGroupAshkhas)
end


SELECT  fldSharheTafzili,fldCodeGroup,fldGroupName,fldShomare,fldCodeTafzili,fldCodeMeli,fldAddress
                   
FROM      #TempListAshkhas
ORDER BY  fldSharheTafzili asc


--set @myReport= 'SELECT DISTINCT 
--                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,isnull(dbo.tblDaftarcheTell.fldShomare,0) as fldShomare,dbo.tblTafzili.fldCodeTafzili, 
--                         isnull(dbo.tblTafzili.fldCodeMeli,0) as fldCodeMeli,dbo.tblTafzili.fldAddress
--FROM            dbo.tblGroupAshkhas INNER JOIN
--                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
--                         dbo.tblDaftarcheTell ON CONVERT(bigint, dbo.tblTafzili.fldCodeTafzili) = CONVERT(bigint, dbo.tblDaftarcheTell.fldCodeTafzili)
--GROUP BY  dbo.tblGroupAshkhas.fldGroupName,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupId,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
--                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress
--HAVING          dbo.tblTafzili.fldCodeGroup IN (' + @CodeGroupAshkhas + ')
--ORDER BY  dbo.tblTafzili.fldSharheTafzili '

--exec( @myReport)


        

 END
GO
/****** Object:  StoredProcedure [dbo].[Report_ListKala_groupby_NameGroup_order_CodeKala_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Report_ListKala_groupby_NameGroup_order_CodeKala_final]
@CodeGroupKala varchar(5000)
as
--declare @myReport varchar(5000)
begin



SET NOCOUNT ON;

	-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempListKala1') IS NOT NULL
 begin
	delete from  #TempListKala1
 end
else 
begin
create table #TempListKala1(
fldNameKala         nvarchar(300), 
fldCodeKala         bigint,
fldCodeVahed1       varchar(100),
fldCodeVahed2       varchar(100), 
fldNameVahed        nvarchar(100), 
FldNameVahed2       nvarchar(100),
fldCodeGroup        bigint,
fldGroupName        nvarchar(300),
fldFeeForoosh       varchar(100) , 
fldFeeBadAzTakhfif  varchar(100),
fldNogheSefaresh    varchar(50),
fldNerkhePorsantKol varchar(50),
fldNerkhePorsantJoz varchar(50))
end

insert into #TempListKala1(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
                          fldCodeGroup,fldGroupName,fldFeeForoosh,fldFeeBadAzTakhfif,fldNogheSefaresh,
						  fldNerkhePorsantKol,fldNerkhePorsantJoz)
select   dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeKala,  dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
FROM     dbo.tblKala LEFT OUTER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID


if @CodeGroupKala<>''
begin
	declare @StrDeleteGroupKala varchar(5000)
	set  @StrDeleteGroupKala='delete from #TempListKala1
		where '+ @CodeGroupKala + ''
		execute(@StrDeleteGroupKala)
end


select 
fldNameKala,       
fldCodeKala,       
fldCodeVahed1,      
fldCodeVahed2,      
fldNameVahed,       
FldNameVahed2,      
fldCodeGroup,      
fldGroupName,       
fldFeeForoosh,      
fldFeeBadAzTakhfif, 
fldNogheSefaresh,   
fldNerkhePorsantKol,
fldNerkhePorsantJoz
from #TempListKala1
ORDER BY fldCodeKala Asc


--set @myReport=' select   DISTINCT dbo.tblKala.fldNameKala,dbo.tblKala.fldCodeKala,dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
--                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
--                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
--FROM            dbo.tblKala LEFT OUTER JOIN
--                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
--                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
--                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
--GROUP BY        dbo.tblGroupKala.fldGroupName,dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
--                         dbo.tblKala.fldFeeForoosh, dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, 
--                         dbo.tblKala.fldNerkhePorsantJoz, dbo.tblKala.fldCodeGroup, dbo.tblVahed.fldNameVahed
--						 HAVING        (dbo.tblKala.fldCodeGroup IN ('+  @CodeGroupKala +'))
--ORDER BY dbo.tblKala.fldCodeKala'
-- exec( @myReport)
end

GO
/****** Object:  StoredProcedure [dbo].[Report_ListKala_groupby_NameGroup_order_NameKala_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Report_ListKala_groupby_NameGroup_order_NameKala_final]
@CodeGroupKala varchar(5000)=null
as
declare @myReport varchar(5000)
begin
     
	SET NOCOUNT ON;

	-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempListKala') IS NOT NULL
 begin
	delete from  #TempListKala
 end
else 
begin
create table #TempListKala(
fldNameKala         nvarchar(300), 
fldCodeKala         bigint,
fldCodeVahed1       varchar(100),
fldCodeVahed2       varchar(100), 
fldNameVahed        nvarchar(100), 
FldNameVahed2       nvarchar(100),
fldCodeGroup        bigint,
fldGroupName        nvarchar(300),
fldFeeForoosh       varchar(100) , 
fldFeeBadAzTakhfif  varchar(100),
fldNogheSefaresh    varchar(50),
fldNerkhePorsantKol varchar(50),
fldNerkhePorsantJoz varchar(50))
end

insert into #TempListKala(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
                          fldCodeGroup,fldGroupName,fldFeeForoosh,fldFeeBadAzTakhfif,fldNogheSefaresh,
						  fldNerkhePorsantKol,fldNerkhePorsantJoz)
select   dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeKala,  dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
FROM     dbo.tblKala LEFT OUTER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID


if @CodeGroupKala<>''
begin
	declare @StrDeleteGroupKala varchar(5000)
	set  @StrDeleteGroupKala='delete from #TempListKala
		where '+ @CodeGroupKala + ''
		execute(@StrDeleteGroupKala)
end


select 
fldNameKala,       
fldCodeKala,       
fldCodeVahed1,      
fldCodeVahed2,      
fldNameVahed,       
FldNameVahed2,      
fldCodeGroup,      
fldGroupName,       
fldFeeForoosh,      
fldFeeBadAzTakhfif, 
fldNogheSefaresh,   
fldNerkhePorsantKol,
fldNerkhePorsantJoz
from #TempListKala
ORDER BY fldCodeKala Asc


----set @myReport=' select   DISTINCT dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeKala,  dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
----                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
----                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
----FROM            dbo.tblKala LEFT OUTER JOIN
----                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
----                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
----                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
----GROUP BY        dbo.tblGroupKala.fldGroupName,dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
----                         dbo.tblKala.fldFeeForoosh, dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, 
----                         dbo.tblKala.fldNerkhePorsantJoz, dbo.tblKala.fldCodeGroup, dbo.tblVahed.fldNameVahed
----						 HAVING        (dbo.tblKala.fldCodeGroup IN ('+  @CodeGroupKala +'))
----ORDER BY dbo.tblKala.fldCodeKala'
---- exec( @myReport)
end

GO
/****** Object:  StoredProcedure [dbo].[ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili]
as
SELECT DISTINCT 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)
GROUP BY  dbo.tblGroupAshkhas.fldGroupId,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress

ORDER BY  dbo.tblTafzili.fldSharheTafzili

GO
/****** Object:  StoredProcedure [dbo].[ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili]
as
SELECT DISTINCT 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)
GROUP BY  dbo.tblGroupAshkhas.fldGroupId,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,dbo.tblDaftarcheTell.fldShomare,dbo.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress

ORDER BY  dbo.tblTafzili.fldSharheTafzili

GO
/****** Object:  StoredProcedure [dbo].[ReportAll_ListKala_groupby_NameGroup_order_CodeKala_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ReportAll_ListKala_groupby_NameGroup_order_CodeKala_final]

as

begin
 select   DISTINCT dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeKala,  dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
FROM            dbo.tblKala LEFT OUTER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
GROUP BY        dbo.tblGroupKala.fldGroupName,dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblKala.fldFeeForoosh, dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, 
                         dbo.tblKala.fldNerkhePorsantJoz, dbo.tblKala.fldCodeGroup, dbo.tblVahed.fldNameVahed
						 
ORDER BY dbo.tblKala.fldCodeKala

end

GO
/****** Object:  StoredProcedure [dbo].[ReportAll_ListKala_groupby_NameGroup_order_NameKala_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ReportAll_ListKala_groupby_NameGroup_order_NameKala_final]

as

begin
 select   DISTINCT dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeKala,  dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblVahed.fldNameVahed AS FldNameVahed2, dbo.tblKala.fldCodeGroup, dbo.tblGroupKala.fldGroupName, dbo.tblKala.fldFeeForoosh, 
                         dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, dbo.tblKala.fldNerkhePorsantJoz
FROM            dbo.tblKala LEFT OUTER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId LEFT OUTER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed1 = tblVahed_1.ID LEFT OUTER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
GROUP BY        dbo.tblGroupKala.fldGroupName,dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldCodeVahed1, dbo.tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed, 
                         dbo.tblKala.fldFeeForoosh, dbo.tblKala.fldFeeBadAzTakhfif, dbo.tblKala.fldNogheSefaresh, dbo.tblKala.fldNerkhePorsantKol, 
                         dbo.tblKala.fldNerkhePorsantJoz, dbo.tblKala.fldCodeGroup, dbo.tblVahed.fldNameVahed
						 
ORDER BY dbo.tblKala.fldNameKala

end

GO
/****** Object:  StoredProcedure [dbo].[ResetShomarefish]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ResetShomarefish] 
	-- Add the parameters for the stored procedure here
	@ShomareFish bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    Delete from tblFish
	insert into tblFish	
		(fldShomareFish,fldShomareFactor)
		values
		(@ShomareFish,0)

END

GO
/****** Object:  StoredProcedure [dbo].[RizeFactorTasfieNashode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[RizeFactorTasfieNashode]
	@ShomareFactor bigint

AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	
	CREATE TABLE #tmpRizeTasfie(	
	[Sharh][nvarchar](100),
	[ShomareDaryaft][bigint],	
	[fldMablagheMandeFactor]	[bigint],
	[fldMablagheDaryaft][bigint],
	[fldMande][bigint]	
	)

	declare @Mablagh bigint
	
	set @Mablagh=(Select fldMablagheMandeFactor  from tblTasfie Where fldShomareFactor=@ShomareFactor)
	if @Mablagh is not null
		begin
			insert into #tmpRizeTasfie
				(Sharh,ShomareDaryaft, fldMablagheMandeFactor,fldMablagheDaryaft,fldMande)
			values('' , 0,@Mablagh ,0,@Mablagh)

			insert into #tmpRizeTasfie
				(Sharh,ShomareDaryaft, fldMablagheMandeFactor,fldMablagheDaryaft,fldMande)
				(Select '',fldShomareDaryaft,0,fldMablagh,0 from tblRizeTasfie Where fldShomareFactor=@ShomareFactor)
		end
	Select Sharh,ShomareDaryaft,fldMablagheMandeFactor,fldMablagheDaryaft,fldMande from #tmpRizeTasfie order by ShomareDaryaft

END

GO
/****** Object:  StoredProcedure [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]
@codeTafzili nvarchar(10)
as
begin
SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldSharheTafzili, fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar 
				
FROM            dbo.tblTafzili

where fldCodeTafzili=@codeTafzili 
end
GO
/****** Object:  StoredProcedure [dbo].[SerachIntbl_GroupAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[SerachIntbl_GroupAshkhas]
@StrSearchTxt nvarchar(50)
as
select fldGroupId,fldGroupName from tblGroupAshkhas
where fldGroupName like '%' + @StrSearchTxt  + '%'

GO
/****** Object:  StoredProcedure [dbo].[SerachIntbl_GroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[SerachIntbl_GroupKala]
@StrSearchTxt nvarchar(50)
as
select fldGroupId,fldGroupName  from tblGroupKala
where fldGroupName like '%' + @StrSearchTxt  + '%'

GO
/****** Object:  StoredProcedure [dbo].[ShomareSanadDaryaftArchive]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShomareSanadDaryaftArchive]
@ShomareDaryaft bigint,
@ShomareSanad nvarchar(50) output

as

begin

	Set @ShomareSanad=(Select fldShomareSanad from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
end

GO
/****** Object:  StoredProcedure [dbo].[ShomareSanadPardakhtArchive]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ShomareSanadPardakhtArchive]
@ShomarePardakht bigint,
@ShomareSanad nvarchar(50) output

as

begin

	Set @ShomareSanad=(Select fldShomareSanad from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
end

GO
/****** Object:  StoredProcedure [dbo].[ShomareSanadVosoolArchive]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShomareSanadVosoolArchive]
@ShomareVosool bigint,
@ShomareSanadVosool nvarchar(50) output

as

begin
               SET NOCOUNT ON;
	Set @ShomareSanadVosool=(Select fldShomareSanad from tblVosool Where fldShomareVosool=@ShomareVosool)
end

GO
/****** Object:  StoredProcedure [dbo].[Show_Mojoodie_Anbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Show_Mojoodie_Anbar]

@mm nvarchar(10),
@nn nvarchar(10)

as

begin
 
 IF OBJECT_ID('tempdb..##TempMojoodieAnbar') IS NOT NULL
 begin
	delete from  #TempMojoodieAnbar
 end
else 
begin
create table #TempMojoodieAnbar(

fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100),
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldNameAnbar Nvarchar(200), 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100)
)
end


insert into #TempMojoodieAnbar (
fldCodeGroup,fldCodeKala,fldNameKala,fldTedadeVorood,fldTedadeKhorooj,
fldTedadeJoz,fldTedadeKol,fldNameAnbar,fldNogheSefaresh,fldFeeForoosh,
fldLastFee,fldMianginFee,fldNameVahed,fldNameVahed2 )
values (1,2,'3',4,5,6,7,'8',9,10,11,12,'13','14')


Select * from #TempMojoodieAnbar
end

GO
/****** Object:  StoredProcedure [dbo].[ShowAllAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ShowAllAshkhas]

as

	SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
GO
/****** Object:  StoredProcedure [dbo].[ShowAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowAnbar]

as
begin
	select [fldCode],[fldNameAnbar],[ID] from tblAnbar
		order by id
end

GO
/****** Object:  StoredProcedure [dbo].[ShowArchiveCheckVagozari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowArchiveCheckVagozari]
@ShomarePardakht bigint
as
begin
		--SELECT        tblCheckeDaryafti.ID, tblCheckeDaryafti.fldShomareCheck, tblCheckeDaryafti.fldShomareHesab,SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckeDaryafti.fldDateSarResid), 7, 2) as fldDateSarResid, tblCheckeDaryafti.fldCodeBank, 
		--							tblCheckeDaryafti.fldShobe, tblCheckeDaryafti.fldMablagh,tblBankeMoshtari.fldNameBank
		--FROM            tblCheckeDaryafti INNER JOIN
		--							tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
		--WHERE        (isnumeric(fldShomarePardakht) = 0) AND (isnumeric(fldShomareVosool) = 0)


		SELECT        tbl1.ID, tbl1.fldCodeSahebeCheck, tblTafzili.fldSharheTafzili, tbl1.fldShomareCheck, tbl1.fldShomareHesab, tbl1.fldDateSarResid, tbl1.fldCodeBank, tbl1.fldShobe, 
                         tbl1.fldMablagh, tbl1.fldNameBank
			FROM            (SELECT        tblCheckeDaryafti.ID, tblCheckeDaryafti.fldCodeSahebeCheck, tblCheckeDaryafti.fldShomareCheck, tblCheckeDaryafti.fldShomareHesab, 
																SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 
																5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 7, 2) AS fldDateSarResid, tblCheckeDaryafti.fldCodeBank, 
																tblCheckeDaryafti.fldShobe, tblCheckeDaryafti.fldMablagh, tblBankeMoshtari.fldNameBank
										FROM            tblCheckeDaryafti INNER JOIN
																tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
										WHERE    fldShomarePardakht=@ShomarePardakht)     AS tbl1 INNER JOIN
										tblTafzili ON tbl1.fldCodeSahebeCheck = tblTafzili.fldCodeTafzili
	return
end

GO
/****** Object:  StoredProcedure [dbo].[ShowAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowAshkhas]
@NameShakhs nvarchar(200),
@CodeGroup  bigint
as

	if @NameShakhs<>'' 
		if @codegroup=0 
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldSharheTafzili like '%'+@NameShakhs+'%'
			end
		else
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldSharheTafzili like '%'+@NameShakhs+'%' and fldCodeGroup=@CodeGroup
			end
	else
		if @codegroup=0 
			begin
					SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId											 
			end
		else
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldCodeGroup=@CodeGroup
			end
GO
/****** Object:  StoredProcedure [dbo].[ShowAshkhas_Filter_CodeKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[ShowAshkhas_Filter_CodeKala]
@CodeShakhs nvarchar(200),
@CodeGroup  bigint
as

	if @CodeShakhs<>'' 
		if @codegroup=0 
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldCodeTafzili like '%'+@CodeShakhs+'%'
			end
		else
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldCodeTafzili like '%'+@CodeShakhs+'%' and fldCodeGroup=@CodeGroup
			end
	else
		if @codegroup=0 
			begin
					SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId											 
			end
		else
			begin
				SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
											 where fldCodeGroup=@CodeGroup
			end
GO
/****** Object:  StoredProcedure [dbo].[ShowBankeMa]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowBankeMa]

as
begin
		declare @strCodeKoleHesab nvarchar(10)
		execute CodeKolHesab 'bank',@strcodekolehesab output

	select [fldSharheHesab] as fldNameBank,[fldCodeHesab] from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab
end

GO
/****** Object:  StoredProcedure [dbo].[ShowBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create proc [dbo].[ShowBankeMoshtari]

as
begin
	select [fldNameBank],[ID] from tblBankeMoshtari
		order by id
end

GO
/****** Object:  StoredProcedure [dbo].[ShowBankInFormKhabandanCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowBankInFormKhabandanCheck]
	
AS
BEGIN
	
	SET NOCOUNT ON;

declare @codebank nvarchar(100) 
declare @codesandoog nvarchar(50)

execute CodeKolHesab 'bank', @codebank output


SELECT         fldSharheHesab,fldCodeHesab
FROM            tblKolMoin
WHERE        (fldCodeHesab like @codebank+'%' ) And (LEN(fldCodeHesab) > LEN(@codebank))
order by fldSharheHesab

  
END

GO
/****** Object:  StoredProcedure [dbo].[ShowCheckDaryafti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowCheckDaryafti]
@ShomareSanad nvarchar(50)
as
begin
	--SELECT        ID.tblCheckeDaryafti,ID.tblBankeMoshtari, fldShomareCheck, fldShomareHesab, fldDateSarResid, fldCodeBank,fldNameBank, fldShobe, fldMablagh   
                           
	--					FROM            tblCheckeDaryafti,tblBankeMoshtari
	--					WHERE        (fldSanad = @ShomareSanad) and ID.tblBankeMoshtari=fldCodeBank



		SELECT        tblCheckeDaryafti.ID, tblCheckeDaryafti.fldShomareCheck, tblCheckeDaryafti.fldShomareHesab,SUBSTRING(CONVERT(nvarchar, 
                         tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, 
                         tblCheckeDaryafti.fldDateSarResid), 7, 2) as fldDateSarResid, tblCheckeDaryafti.fldCodeBank, 
									tblCheckeDaryafti.fldShobe, tblCheckeDaryafti.fldMablagh,tblBankeMoshtari.fldNameBank
		FROM            tblCheckeDaryafti INNER JOIN
									tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
		WHERE        (tblCheckeDaryafti.fldSanad = @ShomareSanad)
	return
end

GO
/****** Object:  StoredProcedure [dbo].[ShowCheckDaryaftiAndVagozariInFormVosoolCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowCheckDaryaftiAndVagozariInFormVosoolCheck]
	
AS
BEGIN
	
SET NOCOUNT ON;


SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,
                        SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 7, 2) AS fldDateSarResid,
						 dbo.tblCheckeDaryafti.fldCodeBank,dbo.tblBankeMoshtari.fldNameBank, dbo.tblCheckeDaryafti.fldShobe, 
                         dbo.tblCheckeDaryafti.fldMablagh, SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),1,4)+ '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),5,2)+ '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),7,2) As fldDateDaryaft ,dbo.tblCheckeDaryafti.fldShomareDaryaft,dbo.tblCheckeDaryafti.fldVaziat, dbo.tblCheckeDaryafti.fldShomarePardakht
                         
FROM            dbo.tblCheckeDaryafti INNER JOIN
                         dbo.tblTafzili ON dbo.tblCheckeDaryafti.fldCodeSahebeCheck = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblBankeMoshtari ON dbo.tblCheckeDaryafti.fldCodeBank = dbo.tblBankeMoshtari.ID
WHERE        (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat IS NULL) OR
                         (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat = 'vagozari')
END

GO
/****** Object:  StoredProcedure [dbo].[ShowCheckDaryaftiAndVagozarNashodeAndVosoolNashodeINfrmKhabandan]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowCheckDaryaftiAndVagozarNashodeAndVosoolNashodeINfrmKhabandan]
	
AS
BEGIN
	
SET NOCOUNT ON;


SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,
                        SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 7, 2) AS fldDateSarResid,
						 dbo.tblCheckeDaryafti.fldCodeBank,dbo.tblBankeMoshtari.fldNameBank, dbo.tblCheckeDaryafti.fldShobe, 
                         dbo.tblCheckeDaryafti.fldMablagh, SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),1,4)+ '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),5,2)+ '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft),7,2) As fldDateDaryaft ,dbo.tblCheckeDaryafti.fldShomareDaryaft,dbo.tblCheckeDaryafti.fldVaziat, dbo.tblCheckeDaryafti.fldShomarePardakht
                         
FROM            dbo.tblCheckeDaryafti INNER JOIN
                         dbo.tblTafzili ON dbo.tblCheckeDaryafti.fldCodeSahebeCheck = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblBankeMoshtari ON dbo.tblCheckeDaryafti.fldCodeBank = dbo.tblBankeMoshtari.ID
WHERE        (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat IS NULL) OR
                         (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat is NULL)
						 order by tblCheckeDaryafti.fldDateSarResid
END

GO
/****** Object:  StoredProcedure [dbo].[ShowCheckDaryaftiVosoolVaVagozarNashode]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowCheckDaryaftiVosoolVaVagozarNashode]
@ShomareCheck nvarchar(50)
as
begin
		--SELECT        tblCheckeDaryafti.ID, tblCheckeDaryafti.fldShomareCheck, tblCheckeDaryafti.fldShomareHesab,SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckeDaryafti.fldDateSarResid), 7, 2) as fldDateSarResid, tblCheckeDaryafti.fldCodeBank, 
		--							tblCheckeDaryafti.fldShobe, tblCheckeDaryafti.fldMablagh,tblBankeMoshtari.fldNameBank
		--FROM            tblCheckeDaryafti INNER JOIN
		--							tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
		--WHERE        (isnumeric(fldShomarePardakht) = 0) AND (isnumeric(fldShomareVosool) = 0)


		SELECT        tbl1.ID, tbl1.fldCodeSahebeCheck, tblTafzili.fldSharheTafzili, tbl1.fldShomareCheck, tbl1.fldShomareHesab, tbl1.fldDateSarResid, tbl1.fldCodeBank, tbl1.fldShobe, 
                         tbl1.fldMablagh, tbl1.fldNameBank
			FROM            (SELECT        tblCheckeDaryafti.ID, tblCheckeDaryafti.fldCodeSahebeCheck, tblCheckeDaryafti.fldShomareCheck, tblCheckeDaryafti.fldShomareHesab, 
																SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 
																5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateSarResid), 7, 2) AS fldDateSarResid, tblCheckeDaryafti.fldCodeBank, 
																tblCheckeDaryafti.fldShobe, tblCheckeDaryafti.fldMablagh, tblBankeMoshtari.fldNameBank
										FROM            tblCheckeDaryafti INNER JOIN
																tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
										WHERE        (isnumeric(tblCheckeDaryafti.fldShomarePardakht) = 0) AND (isnumeric(tblCheckeDaryafti.fldShomareVosool) = 0 and Convert(nvarchar,fldShomareCheck) like '%' + @ShomareCheck + '%')) AS tbl1 INNER JOIN
										tblTafzili ON tbl1.fldCodeSahebeCheck = tblTafzili.fldCodeTafzili
	return
end

GO
/****** Object:  StoredProcedure [dbo].[ShowCheckPardakhti]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowCheckPardakhti]
@ShomareSanad nvarchar(50)
as
begin
	--SELECT        ID.tblCheckePardakht,ID.tblBankeMoshtari, fldShomareCheck, fldShomareHesab, fldDateSarResid, fldCodeBank,fldNameBank, fldShobe, fldMablagh   
                           
	--					FROM            tblCheckePardakht,tblBankeMoshtari
	--					WHERE        (fldSanad = @ShomareSanad) and ID.tblBankeMoshtari=fldCodeBank


		declare @strCodeMoinHesab nvarchar(10)
		execute CodeMoinHesab 'bank',@strCodeMoinHesab  output
		--SELECT        tblCheckePardakht.ID, tblCheckePardakht.fldShomareCheck, tblCheckePardakht.fldShomareHesab,SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckePardakht.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckePardakht.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckePardakht.fldDateSarResid), 7, 2) as fldDateSarResid, tblCheckePardakht.fldCodeBank, 
		--							tblCheckePardakht.fldShobe, tblCheckePardakht.fldMablagh,tblBankeMoshtari.fldNameBank
		--FROM            tblCheckePardakht INNER JOIN
		--							tblBankeMoshtari ON tblCheckePardakht.fldCodeBank = tblBankeMoshtari.ID
		--WHERE        (tblCheckePardakht.fldSanad = @ShomareSanad)

		--SELECT        tblCheckePardakhti.ID, tblCheckePardakhti.fldShomareCheck, tblCheckePardakhti.fldShomareHesab, SUBSTRING(CONVERT(nvarchar, 
  --                       tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar,
  --                        tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResid, tblCheckePardakhti.fldCodeBank, tblCheckePardakhti.fldShobe, tblCheckePardakhti.fldMablagh, 
  --                       tblKolMoin.fldSharheHesab as fldNameBank
		--			FROM            tblCheckePardakhti INNER JOIN
  --                       tblKolMoin ON CONVERT(nvarchar, tblCheckePardakhti.fldCodeBank) = @strCodeKoleHesab
		--			WHERE        (tblCheckePardakhti.fldSanad = @ShomareSanad)


		

--Select * from tblCheckePardakhti,tblKolMoin
--    Where 
--    CONVERT(nvarchar, tblCheckePardakhti.fldCodeBank) = '11701'
--and  (tblCheckePardakhti.fldSanad = '1')
--and tblCheckePardakhti.fldCodeBank=tblKolMoin.fldCodeHesab

SELECT        tblCheckePardakhti.ID, tblCheckePardakhti.fldShomareCheck, tblCheckePardakhti.fldShomareHesab,SUBSTRING(CONVERT(nvarchar, 
                         tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, 
                         tblCheckePardakhti.fldDateSarResid), 7, 2) as fldDateSarResid,  
                         tblCheckePardakhti.fldCodeBank, tblCheckePardakhti.fldShobe, tblCheckePardakhti.fldMablagh, tblCheckePardakhti.fldDatePardakht, 
                         tblCheckePardakhti.fldCodeSahebeCheck, tblCheckePardakhti.fldShomarePardakht, tblCheckePardakhti.fldCodeSahebeHesab, tblCheckePardakhti.fldVasete, 
                         tblCheckePardakhti.fldSanad, tblKolMoin.fldSharheHesab as fldNameBank
FROM            tblCheckePardakhti INNER JOIN
                         tblKolMoin ON tblCheckePardakhti.fldCodeBank = tblKolMoin.fldCodeHesab
WHERE        (tblCheckePardakhti.fldSanad = @ShomareSanad)





	return
end

GO
/****** Object:  StoredProcedure [dbo].[ShowCode_Daryaft_Daramad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowCode_Daryaft_Daramad]
@Sanad nvarchar(50),
@CodeHesab nvarchar(50) output
as

begin
	set @CodeHesab=( SELECT        fldMoinKamel
		FROM            tblSodooreSanad
		WHERE        (fldSanad = @Sanad) AND (isnumeric(fldBestankar) = 1) AND (fldBestankar > 0))
end

GO
/****** Object:  StoredProcedure [dbo].[ShowDaryaftInfo]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowDaryaftInfo]
@ShomareDaryaft bigint,

@ShomareSanad nvarchar(50) output,
@DateDaryaft int output,
@CodeTafzili nvarchar(10) output,
@SharheKol nvarchar(200) output,
@TypeDaryaft nvarchar(20),

----صندوق
@Naghd decimal output,
@CodeMoinSandoogh nvarchar(10) output,
@SNaghd nvarchar(200) output,


----بانک
@Bank decimal output,
@CodeMoinBank nvarchar(10) output,

@SBank nvarchar(200) output,

----چک
@MablaghCheck decimal output,
@SCheck nvarchar(200) output,

----تخفیفات
@Takhfif decimal output,
@STakhfif nvarchar(200) output,

----واسطه
@CodeVasete nvarchar(10) output,

@NoeKhata nvarchar(30) output 

as

begin
	begin transaction transact
		begin try
		--اطلاعات کلی
		declare @KolSandoogh nvarchar(100),@strMablagh nvarchar(20),@KolBank nvarchar(100),@KolMoinCheck nvarchar(100),@KolMoinTakhfif nvarchar(100),@strType nvarchar(20)
		set @ShomareSanad=(Select fldShomareSanad from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
		set @strtype=(Select fldType from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
		set @DateDaryaft=(Select fldDate from tblSodooreSanad Where fldSanad=@ShomareSanad and fldRadif='1')
		if @strtype='daryaft' or @strtype='bargashtazkharid' or @strtype='foroosh'
			begin
				set @CodeTafzili=(Select fldCodeTafzili from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
			end
		else if @strtype='daramad' 
			begin
				set @CodeTafzili=(Select TOP (1) fldCodeSahebeCheck from tblCheckedaryafti Where fldShomareDaryaft=@ShomareDaryaft)
			end
		--رکوردهای این بخش بیشتر از کی هست باید کد معین حسابهای دریافتنی اضافه بشه
		declare @fldHesabDaryaftani bigint,@fldHesabPardakhtani bigint
		 
		
		if @strtype='bargashtazkharid'
			begin
				set @fldHesabPardakhtani=(select  fldCodeMoinHesabhayePardakhtani from tblTanzimat)
				set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldMoinKamel=@fldHesabPardakhtani and fldBestankar>0)
				--set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=302 And fldMoinKamel=31301 and fldBestankar>0)
				--set @SharheKol='55'

			end
		else
			begin
				set @fldHesabDaryaftani=(select  fldCodeMoinHesabhayeDaryaftani from tblTanzimat)
				set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldMoinKamel=@fldHesabDaryaftani and fldBestankar>0)
				--set @SharheKol='66'
			end
		set @CodeVasete=(Select Top(1)isnull(fldVasete,'') from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBestankar>0)
		--set @SharheKol=@TypeDaryaft
		

		--صندوق
		execute CodeKolHesab  'sandoogh', @KolSandoogh output
		set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad)	
		set @CodeMoinSandoogh =(Select fldMoinKamel from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad)	
		set @SNaghd=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad)	

		if @strMablagh is null
			begin			
				set @naghd=0
				set @CodeMoinSandoogh =''
				set @SNaghd=''
			end
		else
			begin			
				set @naghd=Convert(dec,@strMablagh)
			end

		--بانک
		execute CodeKolHesab  'bank', @KolBank output
		set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad)
		set @CodeMoinBank=(Select fldMoinKamel from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad)		
		set @SBank=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @bank=0
				set @CodeMoinBank=''
				set @SBank=''
			end
		else
			begin			
				set @bank=Convert(dec,@strMablagh)
			end
		--چک
		execute CodeMoinHesab  'check', @KolMoincheck output
		set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)
		--set @CodeMoin=(Select fldMoinKamel from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		set @SCheck=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @MablaghCheck=0
				--set @CodeMoincheck=''
				set @Scheck=''
			end
		else
			begin			
				set @MablaghCheck=Convert(dec,@strMablagh)
			end


		--تخفیفات
		execute CodeMoinHesab  'takhfifatedaryaft', @KolMoinTakhfif output
		set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoinTakhfif and fldSanad=@ShomareSanad)
		--set @CodeMoin=(Select fldMoinKamel from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		set @STakhfif=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldMoinKamel=@KolMoinTakhfif and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @Takhfif=0
				--set @CodeMoincheck=''
				set @STakhfif=''
			end
		else
			begin			
				set @Takhfif=Convert(dec,@strMablagh)
			end

		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
	--insert into tblTest7 (fld1,fld2)
	--values(@CodeMoinBank,@bank)

	--declare @nn decimal
	--set @nn=(Select fldBedehkar from tblSodooreSanad Where fldMoinkamel='11001' and fldSanad='47')
	--insert into tblTest7 (fld2)
	--	values(@nn)
	--Select fldBedehkar from tblSodooreSanad Where fldCodeKol='110' and fldSanad='48'
end
GO
/****** Object:  StoredProcedure [dbo].[ShowDastrasiSandoogh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowDastrasiSandoogh] 
	@CodeUser bigint,
	@CodeSanadoogh bigint output,
	@CodeBank bigint  output
AS
BEGIN
	set @CodeSanadoogh=(Select fldSandoogh from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='sandoogh')
	if @CodeSanadoogh is null
		set @CodeSanadoogh=1

	set @CodeBank=(Select fldSandoogh from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='bank')
	if @CodeBank  is null
		set @CodeBank=1

END

GO
/****** Object:  StoredProcedure [dbo].[ShowHesabKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create proc [dbo].[ShowHesabKolMoin]
@CodeKolHesab nvarChar(8)
as
begin
	select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
		Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
		order by fldCodeHesab
end

GO
/****** Object:  StoredProcedure [dbo].[ShowHesabKolMoin_Filter]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowHesabKolMoin_Filter]
@CodeKolHesab nvarChar(8),
@Sharh nvarchar(50)
as
begin
	if isnumeric(@Sharh)=0 
		begin
			select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
				Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab and fldSharheHesab like '%' + @Sharh + '%'
				order by fldCodeHesab
		end
	else if isnumeric(@Sharh)=1 
		begin
			select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
				Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab and fldCodeHesab like  @Sharh + '%'
				order by fldCodeHesab
		end
end

GO
/****** Object:  StoredProcedure [dbo].[ShowHesabKolMoinNoeTafzili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowHesabKolMoinNoeTafzili]
@CodeKolHesab nvarChar(8)
as
begin
	select [fldCodeHesab],[fldSharheHesab],[ID],[fldCodeNoeHesab] from tblKolMoin
		Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab and fldCodeNoeHesab<>'2'
		order by fldCodeHesab
end

GO
/****** Object:  StoredProcedure [dbo].[ShowHesabKolMoinSandooghBank]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create proc [dbo].[ShowHesabKolMoinSandooghBank]
--@CodeKolBank nvarChar(8)
as
begin
	declare @strCodeBank nvarchar(10),@strCodeSandoogh nvarchar(10)
    execute  CodeKolHesab 'sandoogh', @strCodeSandoogh output
	execute  CodeKolHesab 'bank', @strCodeBank output
	select [fldCodeHesab],[fldSharheHesab],[ID],[fldCodeNoeHesab] from tblKolMoin
		Where fldCodeHesab<>@strCodeSandoogh and fldCodeHesab<>@strCodeBank  and (left(fldCodeHesab,len(@strCodeSandoogh))=@strCodeSandoogh or left(fldCodeHesab,len(@strCodeBank))=@strCodeBank)
		order by fldCodeHesab
end

GO
/****** Object:  StoredProcedure [dbo].[ShowHesabKolMoinWithType]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Create proc [dbo].[ShowHesabKolMoinWithType]
@CodeKolHesab nvarChar(8)
as
begin
	select [fldCodeHesab],[fldSharheHesab],[ID],fldCodeNoeHesab from tblKolMoin
		Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
		order by fldCodeHesab
end

GO
/****** Object:  StoredProcedure [dbo].[ShowInfo]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowInfo]
@TblField nvarchar(50),
@Vorood nvarchar(100),
@Khorooj nvarchar(100) output
as
begin
	if @TblField='namevizitor'
		begin
			set @khorooj=(Select fldGroupName from tblGroupAshkhas Where fldGroupId=Convert(bigint,@Vorood))
		end

	if @TblField='codevizitoretafzili'
		begin
			set @Khorooj=(Select Convert(bigint,fldVisitor) from tblTafzili Where fldCodeTafzili=@Vorood) 
		end

end
GO
/****** Object:  StoredProcedure [dbo].[ShowInfoChecksKhabandehShodeInFormVagozri]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowInfoChecksKhabandehShodeInFormVagozri]

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  SELECT        dbo.tblCheckeDaryafti.fldShomareCheck, dbo.tblCheckeDaryafti.fldShomareHesab, dbo.tblCheckeDaryafti.fldCodeSahebeCheck, 
                         dbo.tblTafzili.fldSharheTafzili, SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateSarResid), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, 
                         dbo.tblCheckeDaryafti.fldDateSarResid), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateSarResid), 7, 2) AS fldDateSarResid, 
                         dbo.tblCheckeDaryafti.fldCodeBank, dbo.tblBankeMoshtari.fldNameBank, dbo.tblCheckeDaryafti.fldShobe, dbo.tblCheckeDaryafti.fldMablagh, 
                         SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft), 5, 2) 
                         + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateDaryaft), 7, 2) AS fldDateDaryaft, dbo.tblCheckeDaryafti.fldShomareDaryaft, 
                          SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateVagozariBeBank), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, 
                         dbo.tblCheckeDaryafti.fldDateVagozariBeBank), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateVagozariBeBank), 7, 2) 
                         AS fldDateVagozariBeBank, dbo.tblCheckeDaryafti.fldCodeBankVagozari, 
                         dbo.tblKolMoin.fldSharheHesab,dbo.tblCheckeDaryafti.fldTozihateVagozariBeBank,dbo.tblCheckeDaryafti.fldVaziat, dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomarePardakht
FROM            dbo.tblCheckeDaryafti INNER JOIN
                         dbo.tblTafzili ON dbo.tblCheckeDaryafti.fldCodeSahebeCheck = dbo.tblTafzili.fldCodeTafzili INNER JOIN
                         dbo.tblBankeMoshtari ON dbo.tblCheckeDaryafti.fldCodeBank = dbo.tblBankeMoshtari.ID INNER JOIN
                         dbo.tblKolMoin ON dbo.tblCheckeDaryafti.fldCodeBankVagozari = dbo.tblKolMoin.fldCodeHesab
WHERE  (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat = 'vagozari')
END

GO
/****** Object:  StoredProcedure [dbo].[ShowInfoEnteghal]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowInfoEnteghal]
	@ShomareEnteghal bigint,
	@fldType nvarchar(50)

AS
BEGIN
	
	SET NOCOUNT ON;

   select  fldCodeAnbar,fldCodeAnbar,fldCodeTafsili,fldSharhKala,fldTedadJoz  from tblRizeForoosh 
   where fldShomareEnteghal=@ShomareEnteghal and fldType=@fldType
END

GO
/****** Object:  StoredProcedure [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final]
	@ListCodeKala varchar(5000)=null,
	@ListGroupKala varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@ListCodeAnbar varchar(5000)=null,
	@DataType varchar(40),
	@DateFrom varchar(8),
	@DateTo varchar(8),
	@FlagSort Varchar(5)
as
   
	
BEGIN
	
	SET NOCOUNT ON;


-- ----------------------------------------
-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempRizeForoosh') IS NOT NULL
 begin
	delete from  #TempRizeForoosh
 end
else 
begin
create table #TempRizeForoosh(

fldShomareSanad Nvarchar(30),
fldShomareFactor Nvarchar(30),
fldCodeTafsili Nvarchar(30),
fldSharheTafzili Nvarchar(200), 
fldCodeAnbar Nvarchar(30), 
fldNameAnbar Nvarchar(200), 
fldCodeKala bigint,
fldNameKala Nvarchar(200),
fldGhymatMasrafkonande Nvarchar(100),
fldSharhKala Nvarchar(250),
fldTedadCarton Nvarchar(100), 
fldTedadJoz Nvarchar(100),
fldFeeJoz Nvarchar(30), 
fldFeeYekCarton Nvarchar(30),
fldFeeKol Nvarchar(40), 
fldDarsadTakhfif Nvarchar(30), 
fldMablaghTakhfif Nvarchar(40), 
fldFeeVahed1BadAzTakhfif Nvarchar(40),
fldFeeVahed2BadAzTakhfif Nvarchar(40), 
fldArzeshAfzode Nvarchar(30), 
fldFeeKolBadAzTakhfif Nvarchar(40), 
fldMablaghKhales Nvarchar(40), 
fldType Nvarchar(50), 
fldDate int, 
fldGroupId Nvarchar(30),
fldGroupName Nvarchar(200),
fldCodeVasete Nvarchar(30),
fldNameVasete Nvarchar(200),
fldCodeGroupAshkhas Nvarchar(30), 
fldGroupNameAshkhas Nvarchar(200),
fldTedadJozKarton Nvarchar(30),
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100)
)
end


INSERT INTO #TempRizeForoosh(fldShomareSanad ,
fldShomareFactor ,
fldCodeTafsili ,
fldSharheTafzili , 
fldCodeAnbar , 
fldNameAnbar , 
fldCodeKala ,
fldNameKala ,
fldGhymatMasrafkonande,
fldSharhKala ,
fldTedadCarton , 
fldTedadJoz ,
fldFeeJoz , 
fldFeeYekCarton ,
fldFeeKol , 
fldDarsadTakhfif , 
fldMablaghTakhfif , 
fldFeeVahed1BadAzTakhfif ,
fldFeeVahed2BadAzTakhfif , 
fldArzeshAfzode , 
fldFeeKolBadAzTakhfif , 
fldMablaghKhales , 
fldType, 
fldDate, 
fldGroupId,
fldGroupName, 
fldCodeVasete,
fldNameVasete,
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldTedadJozKarton,
fldNameVahed,
fldNameVahed2)




SELECT        dbo.tblRizeForoosh.fldShomareSanad, dbo.tblRizeForoosh.fldShomareFactor, dbo.tblRizeForoosh.fldCodeTafsili, tblTafzili_1.fldSharheTafzili, 
                         dbo.tblRizeForoosh.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldGhymatMasrafkonande, 
                         dbo.tblRizeForoosh.fldSharhKala, dbo.tblRizeForoosh.fldTedadCarton,ABS(dbo.tblRizeForoosh.fldTedadJoz), dbo.tblRizeForoosh.fldFeeJoz, 
                         dbo.tblRizeForoosh.fldFeeYekCarton, dbo.tblRizeForoosh.fldFeeKol, dbo.tblRizeForoosh.fldDarsadTakhfif, dbo.tblRizeForoosh.fldMablaghTakhfif, 
                         dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeForoosh.fldArzeshAfzode, 
                         dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif, dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldType, dbo.tblRizeForoosh.fldDate, 
                         dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblRizeForoosh.fldCodeVasete, dbo.tblTafzili.fldSharheTafzili AS fldNameVasete, 
                         dbo.tblGroupAshkhas.fldGroupId AS fldCodeGroupAshkhas, dbo.tblGroupAshkhas.fldGroupName AS fldGroupNameAshkhas, 
                         dbo.tblKala.fldTedadJoz AS fldTedadJozKarton, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2
FROM            dbo.tblVahed INNER JOIN
                         dbo.tblRizeForoosh INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeForoosh.fldCodeAnbar = dbo.tblAnbar.fldCode INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId ON dbo.tblVahed.ID = dbo.tblKala.fldCodeVahed1 INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID LEFT OUTER JOIN
                         dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili AS tblTafzili_1 ON dbo.tblGroupAshkhas.fldGroupId = tblTafzili_1.fldCodeGroup ON 
                         dbo.tblRizeForoosh.fldCodeTafsili = tblTafzili_1.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblTafzili ON dbo.tblRizeForoosh.fldCodeVasete = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblGroupAshkhas AS tblGroupAshkhas_1 ON dbo.tblRizeForoosh.fldCodeVasete = tblGroupAshkhas_1.fldGroupId

						 where  dbo.tblRizeForoosh.fldType=@DataType  ANd dbo.tblRizeForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo 

         if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempRizeForoosh 
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempRizeForoosh 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempRizeForoosh 
		            where fldCodeTafsili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempRizeForoosh 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempRizeForoosh 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


			if @ListCodeVisitor<>''
		     begin
		      declare @StrDeleteVisitor varchar(5000)
		       set  @StrDeleteVisitor='delete from #TempRizeForoosh 
		            where '+ @ListCodeVisitor + ''
					execute(@StrDeleteVisitor)
		     end

	
if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldDate ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldShomareSanad ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldCodeKala ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldCodeTafsili ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType
From #TempRizeForoosh	ORDER BY fldSharheTafzili  ASC
end
 
END

GO
/****** Object:  StoredProcedure [dbo].[ShowList_ReportJaameKharid_RizeKharid_final]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ShowList_ReportJaameKharid_RizeKharid_final]
	@ListCodeKala varchar(5000)=null,
	@ListGroupKala varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	--@ListCodeVisitor varchar(5000)=null,
	@ListCodeAnbar varchar(5000)=null,
	@DataType varchar(40),
	@DateFrom varchar(8),
	@DateTo varchar(8),
	@FlagSort Varchar(5)
as
   
	
BEGIN
	
	SET NOCOUNT ON;


-- ----------------------------------------
-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempRizeKharid') IS NOT NULL
 begin
	delete from  #TempRizeKharid
 end
else 
begin
create table #TempRizeKharid(

fldShomareSanad Nvarchar(30),
fldShomareFactor Nvarchar(30),
fldCodeTafsili Nvarchar(30),
fldSharheTafzili Nvarchar(200), 
fldCodeAnbar Nvarchar(30), 
fldNameAnbar Nvarchar(200), 
fldCodeKala bigint,
fldNameKala Nvarchar(200),
fldGhymatMasrafkonande Nvarchar(100),
fldSharhKala Nvarchar(250),
fldTedadCarton Nvarchar(100), 
fldTedadJoz Nvarchar(100),
fldFeeJoz Nvarchar(30), 
fldFeeYekCarton Nvarchar(30),
fldFeeKol Nvarchar(40), 
fldDarsadTakhfif Nvarchar(30), 
fldMablaghTakhfif Nvarchar(40), 
fldFeeVahed1BadAzTakhfif Nvarchar(40),
fldFeeVahed2BadAzTakhfif Nvarchar(40), 
fldArzeshAfzode Nvarchar(30), 
fldFeeKolBadAzTakhfif Nvarchar(40), 
fldMablaghKhales Nvarchar(40), 
fldType Nvarchar(50), 
fldDate int, 
fldGroupId Nvarchar(30),
fldGroupName Nvarchar(200),
fldCodeGroupAshkhas Nvarchar(30), 
fldGroupNameAshkhas Nvarchar(200),
fldTedadJozKarton Nvarchar(30),
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldHamloNaghl  Nvarchar(100)
)
end


INSERT INTO #TempRizeKharid(fldShomareSanad ,
fldShomareFactor ,
fldCodeTafsili ,
fldSharheTafzili , 
fldCodeAnbar , 
fldNameAnbar , 
fldCodeKala ,
fldNameKala ,
fldGhymatMasrafkonande,
fldSharhKala ,
fldTedadCarton , 
fldTedadJoz ,
fldFeeJoz , 
fldFeeYekCarton ,
fldFeeKol , 
fldDarsadTakhfif , 
fldMablaghTakhfif , 
fldFeeVahed1BadAzTakhfif ,
fldFeeVahed2BadAzTakhfif , 
fldArzeshAfzode , 
fldFeeKolBadAzTakhfif , 
fldMablaghKhales , 
fldType, 
fldDate, 
fldGroupId,
fldGroupName, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldTedadJozKarton,
fldNameVahed,
fldNameVahed2,
fldHamloNaghl)




SELECT        dbo.tblRizeKharid.fldShomareSanad, dbo.tblRizeKharid.fldShomareFactor, dbo.tblRizeKharid.fldCodeTafsili, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeKharid.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeKharid.fldCodeKala,
						 dbo.tblKala.fldNameKala,dbo.tblRizeKharid.fldGhymatMasrafkonande, dbo.tblRizeKharid.fldSharhKala, dbo.tblRizeKharid.fldTedadCarton, 
                         ABS(dbo.tblRizeKharid.fldTedadJoz), dbo.tblRizeKharid.fldFeeJoz, dbo.tblRizeKharid.fldFeeYekCarton, dbo.tblRizeKharid.fldFeeKol, dbo.tblRizeKharid.fldDarsadTakhfif, 
                         dbo.tblRizeKharid.fldMablaghTakhfif, dbo.tblRizeKharid.fldFeeVahed1BadAzTakhfif, dbo.tblRizeKharid.fldFeeVahed2BadAzTakhfif, 
                         dbo.tblRizeKharid.fldArzeshAfzode, dbo.tblRizeKharid.fldFeeKolBadAzTakhfif, dbo.tblRizeKharid.fldMablaghKhales, dbo.tblRizeKharid.fldType, 
                         dbo.tblRizeKharid.fldDate, dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblGroupAshkhas.fldGroupId AS fldGroupAshkhas, 
                         dbo.tblGroupAshkhas.fldGroupName AS fldGroupNameAshkhas, dbo.tblKala.fldTedadJoz AS fldTedadJozKarton, dbo.tblVahed.fldNameVahed, 
                         tblVahed_1.fldNameVahed AS fldNameVahed2, dbo.tblRizeKharid.fldHamloNaghl

FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup LEFT OUTER JOIN
                         dbo.tblKala INNER JOIN
                         dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId INNER JOIN
                         dbo.tblVahed AS tblVahed_1 ON dbo.tblKala.fldCodeVahed2 = tblVahed_1.ID INNER JOIN
                         dbo.tblVahed ON dbo.tblKala.fldCodeVahed1 = dbo.tblVahed.ID INNER JOIN
                         dbo.tblRizeKharid INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeKharid.fldCodeAnbar = dbo.tblAnbar.fldCode ON dbo.tblKala.fldCodeKala = dbo.tblRizeKharid.fldCodeKala ON 
                         dbo.tblTafzili.fldCodeTafzili = dbo.tblRizeKharid.fldCodeTafsili

						 where  dbo.tblRizeKharid.fldType=@DataType  ANd dbo.tblRizeKharid.fldDate  BETWEEN  @DateFrom  AND  @DateTo 

         if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempRizeKharid
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempRizeKharid 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempRizeKharid 
		            where fldCodeTafsili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempRizeKharid 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempRizeKharid 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end



if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldDate ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldShomareSanad ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldCodeKala ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldCodeTafsili ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
IIF(fldNameVahed=N'انتخاب کنید' ,'',fldNameVahed) as fldNameVahed,
IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate, 
fldSharhKala,
fldType,
fldHamloNaghl
From #TempRizeKharid	ORDER BY fldSharheTafzili  ASC
end
 
END


GO
/****** Object:  StoredProcedure [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas]
@fldCodeTafsili nvarchar(10)
as
begin
SELECT        fldShomare
FROM          dbo.tblDaftarcheTell
where fldCodeTafzili=@fldCodeTafsili 
end
GO
/****** Object:  StoredProcedure [dbo].[ShowList_Vasteha]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ShowList_Vasteha]
as
begin
select fldGroupId,fldGroupName   from tblGroupAshkhas
where convert(nvarchar,[fldGroupId]) like convert(nvarchar,10100)+ '%' 
and len(convert(nvarchar,[fldGroupId]))=9
end

GO
/****** Object:  StoredProcedure [dbo].[ShowListEbteda_Doreh_Ashkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowListEbteda_Doreh_Ashkhas]
	
	--@fldtype nvarchar(50),
	--@Result nvarchar(20) output
AS
BEGIN
	
	SET NOCOUNT ON;
SELECT        dbo.tblSodooreSanad.fldSanad,dbo.tblSodooreSanad.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, dbo.tblSodooreSanad.fldBedehkar,
              dbo.tblSodooreSanad.fldBestankar, dbo.tblSodooreSanad.fldRadif, 
              dbo.tblSodooreSanad.fldDate, dbo.tblSodooreSanad.fldSharh
FROM            dbo.tblTafzili INNER JOIN
                         dbo.tblSodooreSanad ON dbo.tblTafzili.fldCodeTafzili = dbo.tblSodooreSanad.fldCodeTafzili
WHERE        (dbo.tblSodooreSanad.fldType = 'EbtedaAshkhas')
END

GO
/****** Object:  StoredProcedure [dbo].[ShowListeDasteCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ShowListeDasteCheck]
@CodeBank bigint

as
begin
	SELECT        ID, fldCodeBank, fldShobe, fldShomareCheck, fldShomareHesab
		FROM            tblDasteCheck
		WHERE        (fldCodeBank = @CodeBank)
		ORDER BY fldShomareCheck
end
GO
/****** Object:  StoredProcedure [dbo].[ShowListEnteghal_Kala_Anbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowListEnteghal_Kala_Anbar]
	@fldShomareEnteghal bigint,
	@fldtype nvarchar(50),
	@Result nvarchar(20) output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

SELECT        dbo.tblKala.fldNameKala, dbo.tblRizeForoosh.fldTedadJoz, dbo.tblRizeForoosh.fldSharhKala,  
                         dbo.tblKala.fldCodeKala AS fldCodeKala
FROM            dbo.tblRizeForoosh INNER JOIN
                         dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala
WHERE        (dbo.tblRizeForoosh.fldShomareEnteghal = @fldShomareEnteghal and dbo.tblRizeForoosh.fldType=@fldtype)
END

GO
/****** Object:  StoredProcedure [dbo].[ShowListePersonel]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowListePersonel] 
AS

IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	CREATE TABLE #tmpSooratHesab2(
	[ID] [bigint]  NOT NULL,
	[fldSharheTafzili] [nvarchar](200) ,
	[fldCodeTafzili][nvarchar](200) ,
	[fldOstan] [nvarchar](50) ,
	[fldCity] [nvarchar](50),
	[fldAddress] [nvarchar](200),
	[fldTell] [nvarchar](50)
	)

	Insert into	#tmpSooratHesab2(ID,fldSharheTafzili,fldCodeTafzili,fldOstan,fldCity,fldAddress)
			SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0'

	update #tmpSooratHesab2
		set fldTell=tblDaftarcheTell.fldShomare
		from tblDaftarcheTell Where #tmpSooratHesab2.fldCodeTafzili=tblDaftarcheTell.fldCodeTafzili

		Select fldCodeTafzili, fldSharheTafzili, fldOstan, fldCity, fldTell,fldAddress,ID from #tmpSooratHesab2
END

GO
/****** Object:  StoredProcedure [dbo].[ShowListeUser]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowListeUser] 
	@CodeUser bigint
AS
BEGIN
	declare @intType integer

	set @intType = (Select fldType from tblSecurity Where fldCode=@CodeUser)
	if @intType=0 --سازنده
		Select ID, fldCode, fldUser, fldPassword, fldType from tblSecurity
	else if @intType=1 -- مدیر
		Select ID, fldCode, fldUser, fldPassword, fldType from tblSecurity where fldType<>0
	else if @intType=2 --کاربر
		Select ID, fldCode, fldUser, fldPassword, fldType from tblSecurity where fldCode=@CodeUser

END

GO
/****** Object:  StoredProcedure [dbo].[ShowListGroupAshkhas_AfterAdd]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListGroupAshkhas_AfterAdd](@ID  nvarchar(50))
as
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where convert(nvarchar,[fldGroupId]) like @ID + '%' and  len(convert(nvarchar,[fldGroupId]))=(len(@ID)+3)
order by convert(nvarchar,[fldGroupId])
end

GO
/****** Object:  StoredProcedure [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll]
as
begin
select fldGroupId,fldGroupName   from tblGroupAshkhas
where convert(nvarchar,[fldGroupId]) like convert(nvarchar,10100)+ '%' 
and len(convert(nvarchar,[fldGroupId]))=6
end
GO
/****** Object:  StoredProcedure [dbo].[ShowListGroupKala_AfterAdd]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListGroupKala_AfterAdd](@ID  nvarchar(50))
as
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupKala]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where convert(nvarchar,[fldGroupId]) like @ID + '%' and  len(convert(nvarchar,[fldGroupId]))=(len(@ID)+3)
order by convert(nvarchar,[fldGroupId])
end

GO
/****** Object:  StoredProcedure [dbo].[ShowListGruopAshkhas_All]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListGruopAshkhas_All]
as
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where len(convert(nvarchar,[fldGroupId]))=3
order by convert(nvarchar,[fldGroupId])
end

GO
/****** Object:  StoredProcedure [dbo].[showListGruopAshkhasBy_Enter]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[showListGruopAshkhasBy_Enter](@id  bigint,@len  int)
as

if(exists(select [fldGroupId],fldGroupName from tblGroupAshkhas where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3))
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3
order by convert(nvarchar,[fldGroupId])
end
GO
/****** Object:  StoredProcedure [dbo].[showListGruopAshkhasBy_Escap]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[showListGruopAshkhasBy_Escap](@id  nvarchar(30),@lenid  nvarchar(30))
as


if (@lenid >= 3)
begin
SELECT [fldGroupId]
      ,[fldGroupName]
FROM [dbo].[tblGroupAshkhas]
where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@lenid+3
order by convert(nvarchar,[fldGroupId])

end


GO
/****** Object:  StoredProcedure [dbo].[ShowListGruopKala_All]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListGruopKala_All]
as
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupKala]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where len(convert(nvarchar,[fldGroupId]))=3
order by convert(nvarchar,[fldGroupId])
end

GO
/****** Object:  StoredProcedure [dbo].[showListGruopKalaBy_Enter]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[showListGruopKalaBy_Enter](@id  bigint,@len  int)
as

if(exists(select [fldGroupId],fldGroupName from tblGroupKala where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3))
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupKala]
  where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3
order by convert(nvarchar,[fldGroupId])
end
GO
/****** Object:  StoredProcedure [dbo].[showListGruopKalaBy_Escap]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[showListGruopKalaBy_Escap](@id  nvarchar(30),@lenid  nvarchar(30))
as


if (@lenid >= 3)
begin
SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupKala]
where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@lenid+3
order by convert(nvarchar,[fldGroupId])

end


GO
/****** Object:  StoredProcedure [dbo].[ShowListMojodi_Ebteda_Doreh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ShowListMojodi_Ebteda_Doreh]
	--@fldShomareSanad bigint,
	@fldtype nvarchar(50),
	@Result nvarchar(20) output
AS
BEGIN
	
	SET NOCOUNT ON;
SELECT                   dbo.tblAnbar.fldNameAnbar, dbo.tblRizeKharid.fldShomareSanad, dbo.tblKala.fldNameKala,
                         dbo.tblRizeKharid.fldRadif, dbo.tblRizeKharid.fldCodeAnbar, 
                         dbo.tblRizeKharid.fldCodeKala, dbo.tblRizeKharid.fldSharhKala, 
						 dbo.tblRizeKharid.fldTedadJoz, dbo.tblRizeKharid.fldFeeJoz, dbo.tblRizeKharid.fldFeeKol, 
                         dbo.tblRizeKharid.fldTedadCarton, dbo.tblRizeKharid.fldType, dbo.tblRizeKharid.fldDate, dbo.tblRizeKharid.fldTime
FROM          dbo.tblAnbar INNER JOIN
                         dbo.tblRizeKharid ON dbo.tblAnbar.fldCode = dbo.tblRizeKharid.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizeKharid.fldCodeKala = dbo.tblKala.fldCodeKala
where          tblRizeKharid.fldType='mojodi_ebteda_doreh' 
--where          tblRizeKharid.fldType='mojodi_ebteda_doreh'  And fldShomareSanad=@fldShomareSanad
END

GO
/****** Object:  StoredProcedure [dbo].[ShowListMojoodieAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListMojoodieAnbar]

  @MiangineKharid  nvarchar(10) output,
  @JameTedad bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100),
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldTedadDarKarton decimal(18, 0),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200), 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldDate bigint,
fldType nvarchar(20)
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70),

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70),

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70),

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldNameKala nvarchar(100),
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldKharid bigint,
fldArzesheMojoodi bigint
)



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeKharid

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzForoosh


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeForoosh

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzKharid


Insert into #TempMojoodieAnbar
	(fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
		fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',fldCodeGroup, fldCodeKala, fldNameKala ,0,0 , - 1 , - 1 , 0, '' , fldNogheSefaresh, fldFeeForoosh, 
                         0, 0, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,0,''
FROM            tblKala
	where fldCodeKala Not In (Select fldCodeKala from #TempMojoodieAnbar)



UPDATE       #TempMojoodieAnbar
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar ON tblKala.fldCodeKala = #TempMojoodieAnbar.fldCodeKala


UPDATE       #TempMojoodieAnbar
SET                #TempMojoodieAnbar.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar ON #TempMojoodieAnbar.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar ON tblAnbar.fldCode = #TempMojoodieAnbar.fldCodeAnbar


update #tempMojoodieAnbar set #tempMojoodieAnbar.fldNameVahed=tbl2.fldNameVahed,#tempMojoodieAnbar.fldNameVahed2=tbl2.fldNameVahed2
from
(SELECT    fldCodeKala,    tbl1.fldCodeVahed1, tbl1.fldCodeVahed2, tbl1.fldNameVahed, tblVahed.fldNameVahed AS fldNameVahed2
FROM            tblVahed INNER JOIN
                             (SELECT       fldCodeKala, tblKala.fldCodeVahed1, tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed
                                FROM            tblKala INNER JOIN
                                                         tblVahed AS tblVahed_1 ON tblKala.fldCodeVahed1 = tblVahed_1.ID) AS tbl1 ON tblVahed.ID = tbl1.fldCodeVahed2) tbl2

where tbl2.fldCodeKala=#tempMojoodieAnbar.fldCodeKala


if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempMojoodieAnbar 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


--فیلتر تا قبل از تاریخ 



Insert into #TempShowMojoodi
	(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol





--update #TempShowMojoodi set fldTedadDarKarton=1
--	where fldTedadDarKarton=0

--تعداد کارتن و تعداد جز در آن
update #TempShowMojoodi set fldNameVahed2='' where fldTedadDarKarton=0

update #TempShowMojoodi Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumMande, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumVorood, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Sumkhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


set @MiangineKharid=0


update #TempShowMojoodi set fldKharid=tbl1.Miangin from
(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
FROM            tblRizeKharid
--WHERE        (fldShomareFactor > 0)
GROUP BY fldCodeKala) as tbl1
where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala

--پاک کردن گروه کالاهایی که در گزارش نیستن
if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempShowMojoodi 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
					end
--پاک کردن کالاهایی که در گزارش نیستن
if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempShowMojoodi 
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end
--نقطه سفارش
if @Filter=1 	
	begin
		delete from #TempShowMojoodi Where fldNogheSefaresh < SumMande 
		delete from #TempShowMojoodi Where fldNogheSefaresh = 0 
	end
--موجودی مثبت
if @Filter=2
		delete from #TempShowMojoodi Where  SumMande <=0
		

--موجودی منفی
if @Filter=3
		delete from #TempShowMojoodi Where  SumMande >=0

--موجودی صفر
if @Filter=4
		delete from #TempShowMojoodi Where  SumMande <>0


--محاسبه ارزش موجودی هر کالا
update #TempShowMojoodi set fldArzesheMojoodi=0
update #TempShowMojoodi set fldArzesheMojoodi=SumMande*fldKharid where SumMande>0

--محاسبه میانگین خرید هرکالا
set @MiangineKharid= (Select Sum(fldKharid*SumMande) as SumMiangin from #TempShowMojoodi Where SumMande>0)


if   @MiangineKharid is null
	set @MiangineKharid=0

	

	

Set @JameTedad=(Select Sum(SumMande)  from #TempShowMojoodi Where SumMande>0)

if   @JameTedad is null
	set @JameTedad=0

			--if @ListGroupAshkhas<>''
		 --     begin
		 --      declare @StrDeleteGroupAshkhas varchar(5000)
		 --       set  @StrDeleteGroupAshkhas='delete from #TempRizeForoosh 
		 --           where '+ @ListGroupAshkhas + ''
			--		execute(@StrDeleteGroupAshkhas)
		 --     end


 declare @StrOrder nvarchar(50)
 declare @Select nvarchar(500)



 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi from #TempShowMojoodi '

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi

if @Order=0 
	set @StrOrder=' order by fldCodeKala'
else if @order=1 	
	set @StrOrder=' order by fldNameKala'
else if @order=2 
	set @StrOrder=' order by SumMande desc'
else if @order=3 
	set @StrOrder=' order by SumMande asc'
else if @order=4 
	set @StrOrder=' order by fldKharid desc'	
else if @order=5 
	set @StrOrder=' order by fldKharid asc'
else if @Order=6
	set @StrOrder=' order by fldGroupName desc'
else if @Order=7
	set @StrOrder=' order by fldCodeGroup asc'

execute(@select + @StrOrder)

	 

end

GO
/****** Object:  StoredProcedure [dbo].[ShowListMojoodieAnbarAll]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[ShowListMojoodieAnbarAll]

  @MiangineKharid  nvarchar(10) output,
  @JameTedad bigint output,
  @Order int,
  @Filter int
--@nn nvarchar(10)

as

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100),
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldTedadDarKarton decimal(18, 0),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200), 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldDate bigint,
fldType nvarchar(20)
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70),

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70),

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70),

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldNameKala nvarchar(100),
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldKharid bigint,
fldArzesheMojoodi bigint
)



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeKharid

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzForoosh


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeForoosh

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzKharid


UPDATE       #TempMojoodieAnbar
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar ON tblKala.fldCodeKala = #TempMojoodieAnbar.fldCodeKala


UPDATE       #TempMojoodieAnbar
SET                #TempMojoodieAnbar.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar ON #TempMojoodieAnbar.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar ON tblAnbar.fldCode = #TempMojoodieAnbar.fldCodeAnbar


update #tempMojoodieAnbar set #tempMojoodieAnbar.fldNameVahed=tbl2.fldNameVahed,#tempMojoodieAnbar.fldNameVahed2=tbl2.fldNameVahed2
from
(SELECT    fldCodeKala,    tbl1.fldCodeVahed1, tbl1.fldCodeVahed2, tbl1.fldNameVahed, tblVahed.fldNameVahed AS fldNameVahed2
FROM            tblVahed INNER JOIN
                             (SELECT       fldCodeKala, tblKala.fldCodeVahed1, tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed
                                FROM            tblKala INNER JOIN
                                                         tblVahed AS tblVahed_1 ON tblKala.fldCodeVahed1 = tblVahed_1.ID) AS tbl1 ON tblVahed.ID = tbl1.fldCodeVahed2) tbl2

where tbl2.fldCodeKala=#tempMojoodieAnbar.fldCodeKala




--فیلتر تا قبل از تاریخ 



Insert into #TempShowMojoodi
	(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol


--update #TempShowMojoodi set fldTedadDarKarton=1
--	where fldTedadDarKarton=0

--تعداد کارتن و تعداد جز در آن
update #TempShowMojoodi set fldNameVahed2='' where fldTedadDarKarton=0

update #TempShowMojoodi Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumMande, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumVorood, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Sumkhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


set @MiangineKharid=0


update #TempShowMojoodi set fldKharid=tbl1.Miangin from
(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
FROM            tblRizeKharid
WHERE        (fldShomareFactor > 0)
GROUP BY fldCodeKala) as tbl1
where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala


--نقطه سفارش
if @Filter=1 	
	begin
		delete from #TempShowMojoodi Where fldNogheSefaresh < SumMande 
		delete from #TempShowMojoodi Where fldNogheSefaresh = 0 
	end
--موجودی مثبت
if @Filter=2
		delete from #TempShowMojoodi Where  SumMande <=0
		

--موجودی منفی
if @Filter=3
		delete from #TempShowMojoodi Where  SumMande >=0

--موجودی صفر
if @Filter=4
		delete from #TempShowMojoodi Where  SumMande <>0


--محاسبه ارزش موجودی هر کالا
update #TempShowMojoodi set fldArzesheMojoodi=0
update #TempShowMojoodi set fldArzesheMojoodi=SumMande*fldKharid where SumMande>0

--محاسبه میانگین خرید هرکالا
set @MiangineKharid= (Select Sum(fldKharid*SumMande) as SumMiangin from #TempShowMojoodi Where SumMande>0)


if   @MiangineKharid is null
	set @MiangineKharid=0

	

	

Set @JameTedad=(Select Sum(SumMande)  from #TempShowMojoodi Where SumMande>0)

if   @JameTedad is null
	set @JameTedad=0

			--if @ListGroupAshkhas<>''
		 --     begin
		 --      declare @StrDeleteGroupAshkhas varchar(5000)
		 --       set  @StrDeleteGroupAshkhas='delete from #TempRizeForoosh 
		 --           where '+ @ListGroupAshkhas + ''
			--		execute(@StrDeleteGroupAshkhas)
		 --     end


 declare @StrOrder nvarchar(50)
 declare @Select nvarchar(500)



 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi from #TempShowMojoodi '

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi

if @Order=0 
	set @StrOrder=' order by fldCodeKala'
else if @order=1 	
	set @StrOrder=' order by fldNameKala'
else if @order=2 
	set @StrOrder=' order by SumMande desc'
else if @order=3 
	set @StrOrder=' order by SumMande asc'
else if @order=4 
	set @StrOrder=' order by fldKharid desc'	
else if @order=5 
	set @StrOrder=' order by fldKharid asc'
else if @Order=6
	set @StrOrder=' order by fldGroupName desc'
else if @Order=7
	set @StrOrder=' order by fldCodeGroup asc'

execute(@select + @StrOrder)

	 

end

GO
/****** Object:  StoredProcedure [dbo].[ShowListMojoodieAnbarForForoosh]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListMojoodieAnbarForForoosh]        
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100),
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldTedadDarKarton decimal(18, 0),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200), 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldDate bigint,
fldType nvarchar(20)
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70),

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70),

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70),

fldGroupName nvarchar(50),
fldCodeGroup bigint,
fldNameKala nvarchar(100),
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100),
fldNameVahed2 Nvarchar(100),
fldKharid bigint,
fldFeeForoosh money,
fldArzesheMojoodi bigint
)



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeKharid

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz, 0 , - 1 , - 1 ,0, fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, 0 AS Expr8, 
                         fldFeeJoz, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzForoosh


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeForoosh

INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzKharid


Insert into #TempMojoodieAnbar
	(fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
		fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',fldCodeGroup, fldCodeKala, fldNameKala ,0,0 , - 1 , - 1 , 0, '' , fldNogheSefaresh, fldFeeForoosh, 
                         0, 0, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,0,''
FROM            tblKala
	where fldCodeKala Not In (Select fldCodeKala from #TempMojoodieAnbar)



UPDATE       #TempMojoodieAnbar
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar ON tblKala.fldCodeKala = #TempMojoodieAnbar.fldCodeKala


UPDATE       #TempMojoodieAnbar
SET                #TempMojoodieAnbar.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar ON #TempMojoodieAnbar.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar ON tblAnbar.fldCode = #TempMojoodieAnbar.fldCodeAnbar


update #tempMojoodieAnbar set #tempMojoodieAnbar.fldNameVahed=tbl2.fldNameVahed,#tempMojoodieAnbar.fldNameVahed2=tbl2.fldNameVahed2
from
(SELECT    fldCodeKala,    tbl1.fldCodeVahed1, tbl1.fldCodeVahed2, tbl1.fldNameVahed, tblVahed.fldNameVahed AS fldNameVahed2
FROM            tblVahed INNER JOIN
                             (SELECT       fldCodeKala, tblKala.fldCodeVahed1, tblKala.fldCodeVahed2, tblVahed_1.fldNameVahed
                                FROM            tblKala INNER JOIN
                                                         tblVahed AS tblVahed_1 ON tblKala.fldCodeVahed1 = tblVahed_1.ID) AS tbl1 ON tblVahed.ID = tbl1.fldCodeVahed2) tbl2

where tbl2.fldCodeKala=#tempMojoodieAnbar.fldCodeKala




--فیلتر تا قبل از تاریخ 



Insert into #TempShowMojoodi
	(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol





--update #TempShowMojoodi set fldTedadDarKarton=1
--	where fldTedadDarKarton=0

--تعداد کارتن و تعداد جز در آن
update #TempShowMojoodi set fldNameVahed2='' where fldTedadDarKarton=0

update #TempShowMojoodi Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumMande, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumVorood, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Sumkhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0





update #TempShowMojoodi set fldKharid=tbl1.Miangin from
(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
FROM            tblRizeKharid
WHERE        (fldShomareFactor > 0)
GROUP BY fldCodeKala) as tbl1
where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala





--محاسبه ارزش موجودی هر کالا
update #TempShowMojoodi set fldArzesheMojoodi=0
update #TempShowMojoodi set fldArzesheMojoodi=SumMande*fldKharid where SumMande>0



	

	

update #TempShowMojoodi set fldFeeForoosh=tblKala.fldFeeForoosh from tblkala Where #TempShowMojoodi.fldCodeKala=tblKala.fldCodeKala



 declare @StrOrder nvarchar(50)
 declare @Select nvarchar(500)



 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi from #TempShowMojoodi '

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi

--execute(@select )

--select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
--	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh from #TempShowMojoodi	 

select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumMande ,fldFeeForoosh,fldCodeGroup from #TempShowMojoodi	 

end

GO
/****** Object:  StoredProcedure [dbo].[ShowListTbl_Tafsili_in_Form_Enteghal_Kala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[ShowListTbl_Tafsili_in_Form_Enteghal_Kala]
as
begin
SELECT DISTINCT fldCodeTafzili, fldSharheTafzili
                
				
FROM            dbo.tblTafzili

end
GO
/****** Object:  StoredProcedure [dbo].[ShowListTbl_Tafsili_in_FormAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListTbl_Tafsili_in_FormAshkhas]
as
begin
SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldSharheTafzili, fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar 
				
FROM            dbo.tblTafzili
where fldcodeNoe='1'

end
GO
/****** Object:  StoredProcedure [dbo].[ShowListtblDaftarcheTell_Has_CodeTafisili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListtblDaftarcheTell_Has_CodeTafisili]
@codeTafsili nvarchar(10)
as
begin

select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh   from tblDaftarcheTell 
where fldCodeTafzili=@codeTafsili
end

GO
/****** Object:  StoredProcedure [dbo].[ShowListtblDaftarcheTell_NotHas_CodeTafisili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowListtblDaftarcheTell_NotHas_CodeTafisili]

as
begin

select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh   from tblDaftarcheTell 

end

GO
/****** Object:  StoredProcedure [dbo].[ShowMojodiAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
CREATE PROCEDURE [dbo].[ShowMojodiAnbar] 
@CodeKala bigint,
@CodeAnbar bigint,
@TypeShow nvarchar(40),
@ReturnAllAnbar  decimal(16,2) output,
@ReturnAllKhoroji decimal(16,2) output,
@ReturnAllVorodi decimal(16,2) output

AS
BEGIN
	
	SET NOCOUNT ON;

declare @SumAllForoosh decimal(16,2)
declare @SumAllKharid decimal(16,2)
declare @SumAllBargashtAzForoosh decimal(16,2)
declare @SumAllBargashtAzKharid decimal(16,2)
declare @MandehMojodi decimal(16,2)
declare @SumAllForoosh2 decimal(16,2)
declare @SumAllBargashtAzForoosh2 decimal(16,2)
declare @SumAllKharid2 decimal(16,2)
declare @SumAllBargashtAzKharid2 decimal(16,2)
declare @MandehMojodi2 decimal(16,2)
   
   if(@TypeShow='AllAnbar')
   begin
   set @SumAllForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeForoosh where fldCodeKala=@CodeKala)
   set @SumAllBargashtAzForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzForoosh where fldCodeKala=@CodeKala)
   set @SumAllKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeKharid  where fldCodeKala=@CodeKala)
   set @SumAllBargashtAzKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid  where fldCodeKala=@CodeKala)   
   set @MandehMojodi=@SumAllKharid+@SumAllBargashtAzForoosh - @SumAllForoosh-@SumAllBargashtAzKharid
   set @ReturnAllAnbar=@MandehMojodi
   Return @ReturnAllAnbar
   end

     
	 if(@TypeShow='AllKhoroji')
	 begin
	 set @SumAllForoosh2=(select Isnull(sum(fldTedadJoz),0) from tblRizeForoosh where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	 set @SumAllBargashtAzForoosh2=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzForoosh where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	 set @SumAllKharid2=(select Isnull(sum(fldTedadJoz),0) from tblRizeKharid where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	 set @SumAllBargashtAzKharid2=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	 set @SumAllForoosh2=@SumAllKharid2+@SumAllBargashtAzForoosh2 - @SumAllForoosh2-@SumAllBargashtAzKharid2
	 set @ReturnAllKhoroji= @SumAllForoosh2
	 Return @ReturnAllKhoroji
	 end


	 if(@TypeShow='AllVorodi')
	 begin
	set @SumAllKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeKharid  where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	set @SumAllBargashtAzKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid  where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	set @SumAllForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeForoosh where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	set @SumAllBargashtAzForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzForoosh where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)

	set @SumAllKharid=@SumAllKharid+@SumAllBargashtAzForoosh - @SumAllForoosh-@SumAllBargashtAzKharid
    set	@ReturnAllVorodi=@SumAllKharid
	Return @ReturnAllVorodi
	 end

	  if(@TypeShow='AnbarMakhsos')
	 begin
	   set @SumAllForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeForoosh where fldCodeKala=@CodeKala and fldCodeAnbar=@CodeAnbar)
	   set @SumAllBargashtAzForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzForoosh where fldCodeKala=@CodeKala and fldCodeAnbar=@CodeAnbar)
	   set @SumAllKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeKharid  where fldCodeKala=@CodeKala and fldCodeAnbar=@CodeAnbar)
	   set @SumAllBargashtAzKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid  where fldCodeKala=@CodeKala and fldCodeAnbar=@CodeAnbar)	   
	   set @MandehMojodi=@SumAllKharid+@SumAllBargashtAzForoosh - @SumAllForoosh-@SumAllBargashtAzKharid
	   set @ReturnAllAnbar=@MandehMojodi
	   Return @ReturnAllAnbar
	 end
	 
END

GO
/****** Object:  StoredProcedure [dbo].[ShowPardakhtInfo]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowPardakhtInfo]
@ShomarePardakht bigint,

@ShomareSanad nvarchar(50) output,
@DatePardakht int output,
@CodeTafzili nvarchar(10) output,
@SharheKol nvarchar(200) output,

----صندوق
@Naghd decimal output,
@CodeMoinSandoogh nvarchar(10) output,
@SNaghd nvarchar(200) output,


----بانک
@Bank decimal output,
@CodeMoinBank nvarchar(10) output,

@SBank nvarchar(200) output,

----چک
@MablaghCheck decimal output,
@SCheck nvarchar(200) output,

--چک واگذاری مشتریان
@MablagheCheckeVagozari decimal output,
@SCheckVagozari nvarchar(200) output,

----تخفیفات
@Takhfif decimal output,
@STakhfif nvarchar(200) output,

----واسطه
@CodeVasete nvarchar(10) output,

@NoeKhata nvarchar(30) output 

as

begin
	begin transaction transact
		begin try
		--اطلاعات کلی
		declare @KolSandoogh nvarchar(100),@strMablagh nvarchar(20),@KolBank nvarchar(100),@KolMoinCheck nvarchar(100),@KolMoinTakhfif nvarchar(100)
		set @ShomareSanad=(Select fldShomareSanad from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
		set @DatePardakht=(Select fldDate from tblSodooreSanad Where fldSanad=@ShomareSanad and fldRadif='1')
		set @CodeTafzili=(Select fldCodeTafzili from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
		declare @CodeMoinHesabhayePardakhtani nvarchar(100),@CodeMoinHesab nvarchar(10),@TooleKol bigint,@Toolemoin bigint,@strtype nvarchar(20),@fldHesabDaryaftani bigint
			
		execute  ToolePaye 'kol',@TooleKol output
		execute  ToolePaye 'moin',@Toolemoin output
		execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinHesabhayePardakhtani output


		set @strtype=(Select fldType from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
		if @strtype='bargashtazforoosh'
			begin
				set @fldHesabDaryaftani=(select  fldCodeMoinHesabhayeDaryaftani from tblTanzimat)
				set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBestankar>0 and fldMoinKamel=@fldHesabDaryaftani)				
			end
		else
			set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0 and fldMoinKamel=@CodeMoinHesabhayePardakhtani)



		set @CodeVasete='0'--(Select isnull(fldVasete,'') from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0)

		--صندوق
		execute CodeKolHesab  'sandoogh', @KolSandoogh output
		set @strMablagh=(Select isnull(fldBestankar,0) from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad and fldBestankar>0)	
		set @CodeMoinSandoogh =(Select fldMoinKamel from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad and fldBestankar>0)	
		set @SNaghd=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldCodeKol=@kolSandoogh and fldSanad=@ShomareSanad and fldBestankar>0)	

		if @strMablagh is null
			begin			
				set @naghd=0
				set @CodeMoinSandoogh =''
				set @SNaghd=''
			end
		else
			begin			
				set @naghd=Convert(dec,@strMablagh)
			end

		--بانک
		execute CodeKolHesab  'bank', @KolBank output
		set @strMablagh=(Select isnull(fldBestankar,0) from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0)
		set @CodeMoinBank=(Select fldMoinKamel from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0)		
		set @SBank=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0)		
		if @strMablagh is null
			begin			
				set @bank=0
				set @CodeMoinBank=''
				set @SBank=''
			end
		else
			begin			
				set @bank=Convert(dec,@strMablagh)
			end
		--چک پرداختی از خودمان
		execute CodeMoinHesab  'checkpardakhti', @KolMoincheck output
		set @strMablagh=(Select isnull(fldBestankar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)
		
		--set @CodeMoin=(Select fldMoinKamel from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		set @SCheck=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @MablaghCheck=0
				--set @CodeMoincheck=''
				set @Scheck=''
			end
		else
			begin			
				set @MablaghCheck=Convert(dec,@strMablagh)
			end


		--چک واگذاری مشتریان
		execute CodeMoinHesab  'check', @KolMoincheck output
		set @strMablagh=(Select isnull(fldBestankar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)
		--set @CodeMoin=(Select fldMoinKamel from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		set @SCheckVagozari=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @MablagheCheckeVagozari=0
				--set @CodeMoincheck=''
				set @Scheck=''
			end
		else
			begin			
				set @MablagheCheckeVagozari=Convert(dec,@strMablagh)
			end


		--تخفیفات
		execute CodeMoinHesab  'takhfifatePardakht', @KolMoinTakhfif output
		set @strMablagh=(Select isnull(fldBestankar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoinTakhfif and fldSanad=@ShomareSanad)
		--set @CodeMoin=(Select fldMoinKamel from tblSodooreSanad Where fldMoinKamel=@KolMoincheck and fldSanad=@ShomareSanad)		
		set @STakhfif=(Select isnull(fldSharh,'') from tblSodooreSanad Where fldMoinKamel=@KolMoinTakhfif and fldSanad=@ShomareSanad)		
		if @strMablagh is null
			begin			
				set @Takhfif=0
				--set @CodeMoincheck=''
				set @STakhfif=''
			end
		else
			begin			
				set @Takhfif=Convert(dec,@strMablagh)
			end

		commit transaction
			end try

		begin catch
			if @@trancount>0 
				rollback transaction ;
				set @NoeKhata='rolback'

		end catch
	--insert into tblTest7 (fld1,fld2)
	--values(@CodeMoinBank,@bank)

	--declare @nn decimal
	--set @nn=(Select fldBestankar from tblSodooreSanad Where fldMoinkamel='11001' and fldSanad='47')
	--insert into tblTest7 (fld2)
	--	values(@nn)
	--Select fldBestankar from tblSodooreSanad Where fldCodeKol='110' and fldSanad='48'
end
GO
/****** Object:  StoredProcedure [dbo].[ShowSandooghAndBankInFormVosoolCheck]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowSandooghAndBankInFormVosoolCheck]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

declare @codebank nvarchar(100) 
declare @codesandoog nvarchar(50)

execute CodeKolHesab 'bank', @codebank output
execute CodeKolHesab 'sandoogh',@codesandoog output

SELECT         fldSharheHesab,fldCodeHesab
FROM            tblKolMoin
WHERE        (fldCodeHesab like @codebank+'%' Or fldCodeHesab like @codesandoog+'%') And (LEN(fldCodeHesab) > LEN(@codebank))
order by fldSharheHesab
END

GO
/****** Object:  StoredProcedure [dbo].[ShowShomareFish]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowShomareFish] 
	-- Add the parameters for the stored procedure here
	@ShomareFactor bigint,
	@ShomareFish bigint output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @SFish bigint

	set @SFish = (Select fldShomareFish from tblFish Where fldShomareFactor = @ShomareFactor)
	if @SFish is null
		set @shomarefish=0
	else
		set @shomarefish=@SFish
END

GO
/****** Object:  StoredProcedure [dbo].[ShowTanzimatNew]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ShowTanzimatNew]

	@Name1 nvarChar(30),
	@Meghdar nvarChar(30) OutPut	
as 

begin
	
	Set @Meghdar=(Select fldMeghdar from tblTanzimatNew Where fldName=@Name1)
	if @meghdar is  null
		begin
			set @meghdar='NOTHING'	
		end

end

GO
/****** Object:  StoredProcedure [dbo].[ShowUsers]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ShowUsers] 
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	Select Convert(varchar,fldCode) + '-'  + fldUser as fldUserCode ,fldpassword from tblsecurity
END

GO
/****** Object:  StoredProcedure [dbo].[ShowVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE proc [dbo].[ShowVahed]

as
begin
	select [fldNameVahed],[ID] from tblVahed
		where id<>1
		order by id
end

GO
/****** Object:  StoredProcedure [dbo].[SooratHesab]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[SooratHesab]
@CodeTafzili nvarChar(10),
@bigDateMin bigint ,
@bigDateMax bigint ,
@flagMande int ,
@intOrder int,
@SumBedGhabl bigint output,
@SumBesGhabl bigint output
as

begin
	declare @EmpId bigint,@Select nvarchar(500),@Type nvarchar(50),@ShomareFactor bigint,@CodeKolMoin nvarchar(50),@CodeKolMoinTanzimat nvarchar(50),@CodeKolTanzimat nvarchar(50),@CodeKolSanad nvarchar(50)
	declare @ShomareSanad bigint,@CodekolMoinDaryaftTanzimat nvarchar(10)
	declare @ShomareDaryaft bigint,@ShomarePardakht bigint, @strAlaki nvarchar(50),@lngAlaki bigint,@SharheKol nvarchar(200) ,@lngNaghd bigint,@strMoinKamelSandoogh nvarchar(10),@strSharhenaghd nvarchar(200) ,@lngBank bigint,@strMoinKamelBank nvarchar(10),@strShareBank nvarchar(200),@lngCheck bigint,@strSharheCheck nvarchar(200),@strMoinKamelCheckDaryafti nvarchar(10),@strMoinKamelCheckPardakhti nvarchar(10),@lngMablagheCheckeVagozari bigint,@strSCheckVaghozari nvarchar(200),@strMoinKamelCheckVagozari nvarchar(10),@lngTakhfif bigint,@strSharheTakhfifat nvarchar(200)
	declare @str1 nvarchar(200),@str2 nvarchar(200),@str3 nvarchar(200),@str4 nvarchar(200),@str5 nvarchar(200),@str6 nvarchar(200),@str7 nvarchar(200),@lngAlaki2 bigint
	declare @CodekolMoinHesabhayeDaryaftaniTanzimat nvarchar(10),@CodekolMoinHesabhayePardakhtaniTanzimat nvarchar(10),@strSharheHesab nvarchar(50),@bigBed bigint,@bigBes bigint

	CREATE TABLE #tmpSooratHesab2(
	[ID] [nvarchar](20)  NOT NULL,
	[radif] [bigint]  null,
	[shomare] [nvarchar](15) null,
	[fldSanad] [nvarchar](50) NULL,
	[fldSharh] [nvarchar](150) NULL,
	[fldRiz] [nvarchar](150) NULL,
	[fldDate] [int] NULL,
	[fldTedad][bigint] null,
	[fldNameVahed] [nvarchar](100),
	[fldNameVahed2] [nvarchar](100),
	[fldFee][bigint] null,
	[fldFeeYekCarton][bigint] null,
	[fldFeeKol][bigint] null,
	[fldDarsadTakhfif][bigint] null,
	[fldMablaghTakhfif][bigint] null,
	[fldFeeVahed1BadAzTakhfif][bigint] null,
	[fldFeeVahed2BadAzTakhfif][bigint] null,
	[fldArzeshAfzode][bigint] null,
	[fldFeeKolBadAzTakhfif][bigint] null,
	[fldMablaghKhales][bigint] null,
	[fldCodeAnbar] [bigint] null,
	[fldNameAnbar][nvarchar](50) null,


	[fldMablagh][bigint] null,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldMande][bigint] null,
	[fldCodeKol] [nvarchar](50) NULL,
	[fldCodeMoin] [nvarchar](50) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldCodeMarkaz1] [nvarchar](50) NULL,
	[fldCodeMarkaz2] [nvarchar](50) NULL,
	[fldRadif] [varchar](50) NULL,
	[fldCodeSharh] [varchar](50) NULL,		
	[fldMoinKamel] [nvarchar](50) NULL,
	[fldCodeNoeTafzili] [nvarchar](50) NULL,
	[fldGhateiMovaghat] [nvarchar](50) NULL,
	[fldGhateiDaem] [nvarchar](50) NULL,
	[fldSanadGhadim] [nvarchar](50) NULL,
	[fldShomarePeigiri] [nvarchar](50) NULL,
	[fldMoghayerat] [nvarchar](50) NULL,
	[fldType] [nvarchar](50) NULL,
	[fldVaziat][nvarchar](20) NULL,
	[fldVasete] [nvarchar](50) NULL
) ON [PRIMARY]
---اسناد مربوط به کدتفصیلی یک به یک بررسی میشه و متناسب با نوع سند تحلیل و گسترش میباشد
	declare EmpCursor Cursor For
		Select Id from tblSodooreSanad With (NoLock) where fldCodeTafzili=@CodeTafzili ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
			open EmpCursor
			fetch Next From EmpCursor into @EmpId
			While @@Fetch_Status = 0
				Begin					
					--Update tblSodooreSanad With (RowLock) Set [fldGhateiMovaghat]='False'					
					--Where ID=@EmpId
					
					-- ریختن کلیه اسناد مربوط به تفصیلی در جدول موقت  #########
					INSERT INTO #tmpSooratHesab2
                         (ID, fldSanad, fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, fldRadif, 
                         fldCodeSharh, fldDate, fldSharh, fldMoinKamel, fldCodeNoeTafzili, fldGhateiMovaghat, fldGhateiDaem, fldSanadGhadim, fldShomarePeigiri, fldMoghayerat, fldType, 
                         fldVasete)
					Select ID, fldSanad,fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, fldRadif, 
                         fldCodeSharh, fldDate, fldSharh, fldMoinKamel, fldCodeNoeTafzili, fldGhateiMovaghat, fldGhateiDaem, fldSanadGhadim, fldShomarePeigiri, fldMoghayerat, fldType, 
                         fldVasete
					from tblSodooreSanad 
						Where ID=Convert(varchar,@EmpId)

					
					set @type =(Select fldType from tblSodooresanad Where ID=@EmpId)
					set @CodeKolMoin =(Select fldMoinKamel from tblSodooresanad Where ID=@EmpId)
					execute codemoinhesab 'foroosh' ,@CodekolmoinTanzimat output
					execute codemoinhesab 'hesabhayedaryaftani' ,@CodekolMoinDaryaftTanzimat output	
					execute codemoinhesab 'check' ,@strMoinKamelCheckDaryafti output	
					execute codemoinhesab 'checkpardakhti' ,@strMoinKamelCheckPardakhti output	
					set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
					execute codemoinhesab 'hesabhayepardakhtani' ,@CodekolMoinHesabhayePardakhtaniTanzimat output	
									
					set @CodekolMoinHesabhayeDaryaftaniTanzimat = @CodekolMoinDaryaftTanzimat
					

					--###### فروش ##################
					if @type='foroosh'   ---برای نمایش ریز فاکتور فروش
						begin
							if @CodekolmoinTanzimat = @CodeKolMoin --اگر سند فروش بود
								begin
									declare @bigDate bigint									
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorForoosh from tblForoosh Where fldShomareSanad = @ShomareSanad)
									

									update #tmpSooratHesab2
										set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayeDaryaftaniTanzimat 

									update #tmpSooratHesab2
										set fldSharh=' فروش' + iif( fldSharh='' or fldSharh is null,'', '-' + fldSharh ) where fldSanad=@ShomareSanad And fldMoinKamel= @CodekolMoinHesabhayeDaryaftaniTanzimat 

										--,fldSharh=' فروش' + iif( fldSharh='','', '-' + fldSharh )

									update #tmpSooratHesab2 set shomare = 'ف'+Convert(varchar, @ShomareFactor) where fldSanad= @ShomareSanad
									insert into #tmpSooratHesab2 (ID,shomare,fldSanad,fldRiz,
											fldDate,fldTedad,fldNameVahed,fldNameVahed2,fldFee,fldFeeYekCarton,
											fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
											fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,
											fldCodeAnbar,fldNameAnbar,fldType)
									Select Convert(varchar,@EmpId) + Convert(varchar,fldRadif+100),'ف'+Convert(varchar, @ShomareFactor),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeForoosh.fldSharhKala,
											@bigDate,dbo.tblRizeForoosh.fldTedadJoz,tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2,dbo.tblRizeForoosh.fldFeeJoz,dbo.tblRizeForoosh.fldFeeYekCarton,
											dbo.tblRizeForoosh.fldFeeKol,dbo.tblRizeForoosh.fldDarsadTakhfif,dbo.tblRizeForoosh.fldMablaghTakhfif,dbo.tblRizeForoosh.fldFeeVahed1BadAzTakhfif, 
											dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeForoosh.fldArzeshAfzode, dbo.tblRizeForoosh.fldFeeKolBadAzTakhfif,dbo.tblRizeForoosh.fldMablaghKhales,
											dbo.tblRizeForoosh.fldCodeAnbar,dbo.tblAnbar.fldNameAnbar,'foroosh'
									FROM            dbo.tblAnbar INNER JOIN
															 dbo.tblRizeForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeForoosh.fldCodeAnbar INNER JOIN
															 dbo.tblKala ON dbo.tblRizeForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
															 dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
															 dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
									WHERE        (dbo.tblRizeForoosh.fldShomareFactor = @ShomareFactor)

									--### حذف ردیف سندی که کد کل و معینش فروشه ، در حقیقت فقط باید حسابهای دریافتنی و پرداختنی و سندهای دستی نمایش داده بشه									
								end

							else if @CodekolMoinHesabhayeDaryaftaniTanzimat = @CodeKolMoin  -- اگر سند مربوط به دریافت در فروش بود
								begin
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
									set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorForoosh from tblForoosh Where fldShomareSanad = @ShomareSanad)
									set @ShomareDaryaft =(Select  fldShomareDaryaft from tblDaryaft Where fldShomareSanad = @ShomareSanad)
									set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
									set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)

									execute	ShowDaryaftInfo @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'daryaft', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3

									UPDATE       #tmpSooratHesab2
										SET                fldSharh = @SharheKol
											where #tmpSooratHesab2.ID = @EmpId


									
									update #tmpSooratHesab2
										set fldSharh ='دریافت' + iif( @SharheKol='','',' - ' +@SharheKol), shomare ='ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor)  where fldSanad=@ShomareSanad And fldMoinKamel =  @CodekolMoinHesabhayeDaryaftaniTanzimat  and fldBestankar>0

									update #tmpSooratHesab2
										set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayeDaryaftaniTanzimat 


									if @bigbes>0
										begin
											if @lngNaghd>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '101' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd) ,@bigDate,@lngNaghd,'foroosh')
												end

											if @lngBank>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strShareBank='','','-' +@strShareBank) ,@bigDate,@lngBank,'foroosh')
												end
									
											if @lngCheck>0 
												begin
													--set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelCheckDaryafti)
													--set @strSharheHesab ='چک شماره ' 
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

															select Convert(varchar,@EmpId) +'103' + Convert(varchar,id) ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid) +  iif(@strSharheCheck='','','-' +@strSharheCheck)  ,@bigDate,fldMablagh,'foroosh'
																from tblCheckeDaryafti Where fldSanad = @ShomareSanad

													update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad and fldMoinKamel = @strMoinKamelCheckDaryafti
												end

											if @lngTakhfif>0
												begin
													set @strSharheHesab = 'تخفیفات فروش '
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '104' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd)  ,@bigDate,@lngTakhfif,'foroosh')
												end
										end
								end
								
						end

					
					set @CodeKolMoin =(Select fldMoinKamel from tblSodooresanad Where ID=@EmpId)--11301
					set @CodeKolSanad =(Select fldCodeKol from tblSodooresanad Where ID=@EmpId)--113
					set @CodeKolTanzimat =(Select fldCodeKol from tblSodooresanad Where ID=@EmpId)--110
					execute CodeKolHesab 'hesabhayedaryaftani' ,@CodeKolTanzimat output--11301

					
				


				
				if @type='kharid'   ---برای نمایش ریز فاکتور خرید
						begin
							execute codemoinhesab 'kharid' ,@CodekolmoinTanzimat output
							execute codemoinhesab 'hesabhayepardakhtani' ,@CodekolMoinHesabhayePardakhtaniTanzimat output	

							set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckPardakhti
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckdaryafti

							if @CodekolmoinTanzimat = @CodeKolMoin --اگر سند خرید بود
								begin
									
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
						
								end

							else if @CodekolMoinHesabhayePardakhtaniTanzimat = @CodeKolMoin  -- اگر سند مربوط به پرداخت در خرید بود
								begin
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
									set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorKharid from tblKharid Where fldShomareSanad = @ShomareSanad)
									set @ShomarePardakht =(Select  fldShomarePardakht from tblPardakht Where fldShomareSanad = @ShomareSanad)
									set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
									set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)

									execute	ShowPardakhtInfo @ShomarePardakht, @str1, @lngAlaki, @str1, @SharheKol output, @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output,@lngMablagheCheckeVagozari output, @strSCheckVaghozari output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3



									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorkharid from tblKharid Where fldShomareSanad = @ShomareSanad)
									
									if @bigbes>0  or (@bigbes=0 and @bigbed=0)
										begin
											update #tmpSooratHesab2 set shomare = 'خ'+Convert(varchar, @ShomareFactor) ,fldSharh=' خرید' + iif(fldSharh='','','-' +fldSharh)   where ID=@EmpId
											update #tmpSooratHesab2 set shomare = 'خ'+Convert(varchar, @ShomareFactor) where fldSanad= @ShomareSanad
											insert into #tmpSooratHesab2 (ID,shomare,fldSanad,fldRiz,
													fldDate,fldTedad,fldNameVahed,fldNameVahed2,fldFee,fldFeeYekCarton,
													fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
													fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,
													fldCodeAnbar,fldNameAnbar,fldType)
											Select Convert(varchar,@EmpId) + Convert(varchar,fldRadif+100),'خ'+Convert(varchar, @ShomareFactor),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizekharid.fldSharhKala,
													@bigDate,dbo.tblRizekharid.fldTedadJoz,tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2,dbo.tblRizekharid.fldFeeJoz,dbo.tblRizekharid.fldFeeYekCarton,
													dbo.tblRizekharid.fldFeeKol,dbo.tblRizekharid.fldDarsadTakhfif,dbo.tblRizekharid.fldMablaghTakhfif,dbo.tblRizekharid.fldFeeVahed1BadAzTakhfif, 
													dbo.tblRizekharid.fldFeeVahed2BadAzTakhfif, dbo.tblRizekharid.fldArzeshAfzode, dbo.tblRizekharid.fldFeeKolBadAzTakhfif,dbo.tblRizekharid.fldMablaghKhales,
													dbo.tblRizekharid.fldCodeAnbar,dbo.tblAnbar.fldNameAnbar,'kharid'
											FROM            dbo.tblAnbar INNER JOIN
																		dbo.tblRizekharid ON dbo.tblAnbar.fldCode = dbo.tblRizekharid.fldCodeAnbar INNER JOIN
																		dbo.tblKala ON dbo.tblRizekharid.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
																		dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
																		dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
											WHERE        (dbo.tblRizekharid.fldShomareFactor = @ShomareFactor)
										end




									update #tmpSooratHesab2
										set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayePardakhtaniTanzimat 

									

									if @bigbed>0
										begin
											update #tmpSooratHesab2 set fldSharh='پرداخت ' +  fldSharh ,shomare ='ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor) where id=@EmpId
											if @lngNaghd>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '100' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab +  iif(@strSharhenaghd='','','-' +@strSharhenaghd)  ,@bigDate,@lngNaghd,'kharid')
												end

											if @lngBank>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '200' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(    @strShareBank='','','-' +    @strShareBank),@bigDate,@lngBank,'kharid')
												end
									
											if @lngCheck>0 
												begin													
													
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

															select Convert(varchar,@EmpId ) + '300' + + Convert(varchar,id) ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'شماره چک ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSharheCheck='','','-' +@strSharheCheck) ,@bigDate,fldMablagh,'kharid'
																from tblCheckePardakhti Where fldSanad = @ShomareSanad													
												end

							
											if @lngMablagheCheckeVagozari>0 
												begin													
													
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

															select Convert(varchar,@EmpId ) + '400' + Convert(varchar,id) ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'واگذاری چک شماره ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSCheckVaghozari='','','-' +@strSCheckVaghozari) ,@bigDate,fldMablagh,'kharid'
																from tblCheckeDaryafti Where fldShomarePardakht = @ShomarePardakht													
												end

											if @lngTakhfif>0
												begin
													set @strSharheHesab = 'تخفیفات خرید '
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId ) + '500' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(  @strSharheTakhfifat='','','-' +  @strSharheTakhfifat)  ,@bigDate,@lngTakhfif,'kharid')
												end
										end
								end
								
						end



					execute codemoinhesab 'foroosh' ,@CodekolmoinTanzimat output

					

					--###### برگشت از فروش ##################
					if @type='bargashtazforoosh'   ---برای نمایش ریز برگشت از فروش
						begin
							set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckPardakhti
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckdaryafti

						

							update #tmpSooratHesab2
											set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayeDaryaftaniTanzimat 

							begin
								if @CodekolmoinTanzimat = @CodeKolMoin --اگر سند برگشت از فروش بود
									begin
									
										set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
										set @ShomareFactor =(Select  fldShomareFactorForoosh from tblBargashtAzForoosh Where fldShomareSanad = @ShomareSanad)
									
									end

								else if @CodekolMoinHesabhayeDaryaftaniTanzimat = @CodeKolMoin  -- اگر سند مربوط به پرداخت در برگشت از فروش بود
									begin
										set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
										set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
										set @ShomareFactor =(Select  fldShomareFactorForoosh from tblBargashtAzForoosh Where fldShomareSanad = @ShomareSanad)
										set @ShomarePardakht =(Select  fldShomarePardakht from tblPardakht Where fldShomareSanad = @ShomareSanad)
										set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
										set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)
									
										execute	ShowPardakhtInfo @ShomarePardakht, @str1, @lngAlaki, @str1, @SharheKol output, @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output,@lngMablagheCheckeVagozari output, @strSCheckVaghozari output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3


										set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
										set @ShomareFactor =(Select  fldShomareFactorForoosh from tblBargashtAzForoosh Where fldShomareSanad = @ShomareSanad)

									
												
										if @bigbes>0  or (@bigbes=0 and @bigbed=0)
											begin
												update #tmpSooratHesab2 set shomare = 'ب ف'+Convert(varchar, @ShomareFactor) ,fldSharh=' برگشت از فروش' + iif(  fldSharh ='','','-' +  fldSharh ) where ID=@EmpId
												update #tmpSooratHesab2 set shomare = 'ب ف'+Convert(varchar, @ShomareFactor) where fldSanad= @ShomareSanad
												insert into #tmpSooratHesab2 (ID,shomare,fldSanad,fldRiz,
														fldDate,fldTedad,fldNameVahed,fldNameVahed2,fldFee,fldFeeYekCarton,
														fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
														fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,
														fldCodeAnbar,fldNameAnbar,fldType)
												Select Convert(varchar,@EmpId) + Convert(varchar,fldRadif+100),'ب ف'+Convert(varchar, @ShomareFactor),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeBargashtAzForoosh.fldSharhKala,
														@bigDate,dbo.tblRizeBargashtAzForoosh.fldTedadJoz,tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2,dbo.tblRizeBargashtAzForoosh.fldFeeJoz,dbo.tblRizeBargashtAzForoosh.fldFeeYekCarton,
														dbo.tblRizeBargashtAzForoosh.fldFeeKol,dbo.tblRizeBargashtAzForoosh.fldDarsadTakhfif,dbo.tblRizeBargashtAzForoosh.fldMablaghTakhfif,dbo.tblRizeBargashtAzForoosh.fldFeeVahed1BadAzTakhfif, 
														dbo.tblRizeBargashtAzForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeBargashtAzForoosh.fldArzeshAfzode, dbo.tblRizeBargashtAzForoosh.fldFeeKolBadAzTakhfif,dbo.tblRizeBargashtAzForoosh.fldMablaghKhales,
														dbo.tblRizeBargashtAzForoosh.fldCodeAnbar,dbo.tblAnbar.fldNameAnbar,'bargashtazforoosh'
												FROM            dbo.tblAnbar INNER JOIN
																			dbo.tblRizeBargashtAzForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeBargashtAzForoosh.fldCodeAnbar INNER JOIN
																			dbo.tblKala ON dbo.tblRizeBargashtAzForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
																			dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
																			dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
												WHERE        (dbo.tblRizeBargashtAzForoosh.fldShomareFactor = @ShomareFactor)
											end


											
									if @bigbed>0
										begin
											update #tmpSooratHesab2 set fldSharh='پرداخت ' +  fldSharh ,shomare = 'ش پ' + Convert(varchar,@ShomarePardakht) + ' ب ف' + Convert(varchar,@ShomareFactor) where id=@EmpId
											if @lngNaghd>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '100' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ب ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif( @strSharhenaghd='','','-' +@strSharhenaghd),@bigDate,@lngNaghd,'bargashtazforoosh')
												end

											if @lngBank>0
												begin
													set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId) + '200' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif( @strShareBank='','','-' + @strShareBank )  ,@bigDate,@lngBank,'bargashtazforoosh')
												end
									
											if @lngCheck>0 
												begin													
													
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

															select Convert(varchar,@EmpId ) + '300' + + Convert(varchar,id) ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'شماره چک ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSharheCheck='','','-' +@strSharheCheck)  ,@bigDate,fldMablagh,'bargashtazforoosh'
																from tblCheckePardakhti Where fldSanad = @ShomareSanad													
												end

								

										if @lngMablagheCheckeVagozari>0 
											begin													
													
												insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

														select Convert(varchar,@EmpId ) + '400' + Convert(varchar,id) ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'واگذاری چک شماره ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSCheckVaghozari='','','-' +@strSCheckVaghozari) ,@bigDate,fldMablagh,'bargashtazforoosh'
															from tblCheckeDaryafti Where fldShomarePardakht = @ShomarePardakht													
											end

											if @lngTakhfif>0
												begin
													set @strSharheHesab = 'تخفیفات فروش '
													insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
														values (Convert(varchar,@EmpId ) + '500' ,'ش پ' + Convert(varchar,@ShomarePardakht) + ' ش خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strSharheTakhfifat='','',' - ' +@strSharheTakhfifat),@bigDate,@lngTakhfif,'bargashtazforoosh')
												end
										end



									end		    
						   end 
								
						end

					

					if @type='bargashtazkharid'   ---برای نمایش ریز برگشت از خرید
						begin
							execute codemoinhesab 'kharid' ,@CodekolmoinTanzimat output
							execute codemoinhesab 'hesabhayepardakhtani' ,@CodekolMoinHesabhayePardakhtaniTanzimat output	

							set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckPardakhti
							update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad=@ShomareSanad and fldMoinKamel = @strMoinKamelCheckdaryafti

							
							set @ShomareFactor =(Select  fldShomareFactorKharid from tblBargashtAzKharid Where fldShomareSanad = @ShomareSanad)
												
							update #tmpSooratHesab2
								set fldSharh ='دریافت' + iif( @SharheKol='','',' - ' +@SharheKol) ,Shomare='ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar, @ShomareFactor )  where fldSanad=@ShomareSanad And fldMoinKamel =  @CodekolMoinHesabhayePardakhtaniTanzimat  and fldBestankar>0

							if @CodekolmoinTanzimat = @CodeKolMoin --اگر سند خرید بود
								begin
									
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)

								end

							else if @CodekolMoinHesabhayePardakhtaniTanzimat = @CodeKolMoin  -- اگر سند مربوط به دریافت در برگشت از خرید بود
								begin
									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
									set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorKharid from tblBargashtAzKharid Where fldShomareSanad = @ShomareSanad)
									set @ShomareDaryaft =(Select  fldShomareDaryaft from tblDaryaft Where fldShomareSanad = @ShomareSanad)
									set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
									set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)
									
									
									execute	ShowDaryaftInfo @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'bargashtazkharid', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3


									set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
									set @ShomareFactor =(Select  fldShomareFactorkharid from tblBargashtAzKharid Where fldShomareSanad = @ShomareSanad)

									
									if @bigbed>0  or (@bigbes=0 and @bigbed=0)
										begin
											update #tmpSooratHesab2 set shomare = 'ب خ'+Convert(varchar, @ShomareFactor) ,fldSharh=' برگشت از خرید' + iif(fldSharh='','','-' +fldSharh)   where ID=@EmpId
											update #tmpSooratHesab2 set shomare = 'ب خ'+Convert(varchar, @ShomareFactor) where fldSanad= @ShomareSanad

																						

											insert into #tmpSooratHesab2 (ID,shomare,fldSanad,fldRiz,
													fldDate,fldTedad,fldNameVahed,fldNameVahed2,fldFee,fldFeeYekCarton,
													fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
													fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,
													fldCodeAnbar,fldNameAnbar,fldType)
											Select Convert(varchar,@EmpId) + Convert(varchar,fldRadif+100),'ب خ'+Convert(varchar, @ShomareFactor),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeBargashtAzkharid.fldSharhKala,
													@bigDate,dbo.tblRizeBargashtAzkharid.fldTedadJoz,tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2,dbo.tblRizeBargashtAzkharid.fldFeeJoz,dbo.tblRizeBargashtAzkharid.fldFeeYekCarton,
													dbo.tblRizeBargashtAzkharid.fldFeeKol,dbo.tblRizeBargashtAzkharid.fldDarsadTakhfif,dbo.tblRizeBargashtAzkharid.fldMablaghTakhfif,dbo.tblRizeBargashtAzkharid.fldFeeVahed1BadAzTakhfif, 
													dbo.tblRizeBargashtAzkharid.fldFeeVahed2BadAzTakhfif, dbo.tblRizeBargashtAzkharid.fldArzeshAfzode, dbo.tblRizeBargashtAzkharid.fldFeeKolBadAzTakhfif,dbo.tblRizeBargashtAzkharid.fldMablaghKhales,
													dbo.tblRizeBargashtAzkharid.fldCodeAnbar,dbo.tblAnbar.fldNameAnbar,'bargashtazkharid'
											FROM            dbo.tblAnbar INNER JOIN
																		dbo.tblRizeBargashtAzkharid ON dbo.tblAnbar.fldCode = dbo.tblRizeBargashtAzkharid.fldCodeAnbar INNER JOIN
																		dbo.tblKala ON dbo.tblRizeBargashtAzkharid.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
																		dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
																		dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
											WHERE        (dbo.tblRizeBargashtAzkharid.fldShomareFactor = @ShomareFactor)
										




											update #tmpSooratHesab2
												set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayePardakhtaniTanzimat 

											

									
											begin
												--set @ShomareSanad=@ShomareSanad
													if @lngNaghd>0
														begin
															set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																values (Convert(varchar,@EmpId+1) + '101' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd) ,@bigDate,@lngNaghd,'bargashtazkharid')
														end

													if @lngBank>0
														begin
															set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																values (Convert(varchar,@EmpId+1) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strShareBank='','','-' +@strShareBank) ,@bigDate,@lngBank,'bargashtazkharid')
														end
									
													if @lngCheck>0 
														begin
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

																	select Convert(varchar,@EmpId+1) +'103'   + Convert(varchar,id) ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor) ,@ShomareSanad,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid) +  iif(@strSharheCheck='','','-' +@strSharheCheck)  ,@bigDate,fldMablagh,'bargashtazkharid'
																		from tblCheckeDaryafti Where fldSanad = @ShomareSanad

															update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad and fldMoinKamel = @strMoinKamelCheckDaryafti
														end

													if @lngTakhfif>0
														begin
															set @strSharheHesab = 'تخفیفات خرید '
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																values (Convert(varchar,@EmpId+1) + '104' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd)  ,@bigDate,@lngTakhfif,'bargashtazkharid')
														end

												
												end
										end
									
								end
								
						end

					if @type='daryaft'   ---برای نمایش ریز دریافت مستقیم
						begin
							set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
							set @ShomareDaryaft =(Select  fldShomareDaryaft from tblDaryaft Where fldShomareSanad = @ShomareSanad)

							--if @ShomareSanad=408
							--	begin
							--		INSERT INTO dbo.tblTest5
							--				 (name1, name2, name3)
							--					VALUES        (@bigDate,@ShomareDaryaft,'aa')
								--end

							set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
							set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)
							update #tmpSooratHesab2 set fldSharh='دریافت' ,Shomare='ش د' + Convert(varchar,@ShomareDaryaft) Where ID=@EmpId

							execute	ShowDaryaftInfo @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'bargashtazkharid', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3


							if @bigbes>0
								begin
									if @lngNaghd>0
									begin
										set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
										insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
											values (Convert(varchar,@EmpId) + '101' ,'ش د' + Convert(varchar,@ShomareDaryaft) ,@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd) ,@bigDate,@lngNaghd,'daryaft')
									end

									if @lngBank>0
									begin
										set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
										insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
											values (Convert(varchar,@EmpId)+ '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) ,@ShomareSanad,@strSharheHesab + iif(@strShareBank='','','-' +@strShareBank) ,@bigDate,@lngBank,'daryaft')
									end
									
									if @lngCheck>0 
									begin
										insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

										select Convert(varchar,@EmpId)+'103'  + Convert(varchar,id) ,'ش د' + Convert(varchar,@ShomareDaryaft)  ,@ShomareSanad,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid) +  iif(@strSharheCheck='','','-' +@strSharheCheck)  ,@bigDate,fldMablagh,'daryaft'
										from tblCheckeDaryafti Where fldSanad = @ShomareSanad

										update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad and fldMoinKamel = @strMoinKamelCheckDaryafti
									end

								if @lngTakhfif>0
									begin
										set @strSharheHesab = 'تخفیفات دریافت '
										insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
											values (Convert(varchar,@EmpId) + '104' ,'ش د' + Convert(varchar,@ShomareDaryaft) ,@ShomareSanad,@strSharheHesab + iif(@strSharhenaghd='','','-' +@strSharhenaghd)  ,@bigDate,@lngTakhfif,'daryaft')
									end
								
								end
						end




					if @type = 'pardakht'  -- اگر سند مربوط به پرداخت اصلی بود
						begin
								set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
								set @ShomareSanad=(Select Convert(bigint,fldSanad) from tblSodooresanad Where ID=@EmpId)								
								set @ShomarePardakht =(Select  fldShomarePardakht from tblPardakht Where fldShomareSanad = @ShomareSanad)
								set @bigbed = (Select fldBedehkar from tblSodooresanad Where ID=@EmpId)
								set @bigbes = (Select fldBestankar from tblSodooresanad Where ID=@EmpId)
									
								execute	ShowPardakhtInfo @ShomarePardakht, @str1, @lngAlaki, @str1, @SharheKol output, @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngCheck  output, @strSharheCheck  output,@lngMablagheCheckeVagozari output, @strSCheckVaghozari output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3

								set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)																	
												
								--if @bigbes>0 
								--	begin
										--update #tmpSooratHesab2 set shomare = 'ب ف'+Convert(varchar, @ShomareFactor) ,fldSharh=' برگشت از فروش' + iif(  fldSharh ='','','-' +  fldSharh ) where ID=@EmpId
										--update #tmpSooratHesab2 set shomare = 'ب ف'+Convert(varchar, @ShomareFactor) where fldSanad= @ShomareSanad
										--insert into #tmpSooratHesab2 (ID,shomare,fldSanad,fldRiz,
										--		fldDate,fldTedad,fldNameVahed,fldNameVahed2,fldFee,fldFeeYekCarton,
										--		fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
										--		fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,
										--		fldCodeAnbar,fldNameAnbar)
										--Select Convert(varchar,@EmpId) + Convert(varchar,fldRadif+100),'ب ف'+Convert(varchar, @ShomareFactor),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeBargashtAzForoosh.fldSharhKala,
										--		@bigDate,dbo.tblRizeBargashtAzForoosh.fldTedadJoz,tblVahed_2.fldNameVahed, dbo.tblVahed.fldNameVahed AS fldNameVahed2,dbo.tblRizeBargashtAzForoosh.fldFeeJoz,dbo.tblRizeBargashtAzForoosh.fldFeeYekCarton,
										--		dbo.tblRizeBargashtAzForoosh.fldFeeKol,dbo.tblRizeBargashtAzForoosh.fldDarsadTakhfif,dbo.tblRizeBargashtAzForoosh.fldMablaghTakhfif,dbo.tblRizeBargashtAzForoosh.fldFeeVahed1BadAzTakhfif, 
										--		dbo.tblRizeBargashtAzForoosh.fldFeeVahed2BadAzTakhfif, dbo.tblRizeBargashtAzForoosh.fldArzeshAfzode, dbo.tblRizeBargashtAzForoosh.fldFeeKolBadAzTakhfif,dbo.tblRizeBargashtAzForoosh.fldMablaghKhales,
										--		dbo.tblRizeBargashtAzForoosh.fldCodeAnbar,dbo.tblAnbar.fldNameAnbar
										--FROM            dbo.tblAnbar INNER JOIN
										--							dbo.tblRizeBargashtAzForoosh ON dbo.tblAnbar.fldCode = dbo.tblRizeBargashtAzForoosh.fldCodeAnbar INNER JOIN
										--							dbo.tblKala ON dbo.tblRizeBargashtAzForoosh.fldCodeKala = dbo.tblKala.fldCodeKala INNER JOIN
										--							dbo.tblVahed AS tblVahed_2 ON dbo.tblKala.fldCodeVahed1 = tblVahed_2.ID INNER JOIN
										--							dbo.tblVahed ON dbo.tblKala.fldCodeVahed2 = dbo.tblVahed.ID
										--WHERE        (dbo.tblRizeBargashtAzForoosh.fldShomareFactor = @ShomareFactor)
									--end


											
							if @bigbed>0
								begin

								--INSERT INTO dbo.tblTest5
								--		 (name1, name2, name3)
								--			VALUES        (@lngNaghd,@ShomarePardakht,@ShomareFactor)

								
									update #tmpSooratHesab2
											set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel<> @CodekolMoinHesabhayePardakhtaniTanzimat 

									update #tmpSooratHesab2 set fldSharh='پرداخت ' +  fldSharh ,Shomare='ش پ' + Convert(varchar,@ShomarePardakht) where id=@EmpId
									if @lngNaghd>0
										begin
											set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelSandoogh)											
											insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
												values (Convert(varchar,@EmpId) + '100' ,'ش پ' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,@strSharheHesab + iif( @strSharhenaghd='','','-' +@strSharhenaghd),@bigDate,@lngNaghd,'pardakht')
										end

									if @lngBank>0
										begin
											set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank)
											insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
												values (Convert(varchar,@EmpId) + '200' ,'ش پ' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,@strSharheHesab + iif( @strShareBank='','','-' + @strShareBank )  ,@bigDate,@lngBank,'pardakht')
										end
									
									if @lngCheck>0 
										begin													
													
											insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

													select Convert(varchar,@EmpId ) + '300' + + Convert(varchar,id) ,'ش پ' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,'شماره چک ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSharheCheck='','','-' +@strSharheCheck)  ,@bigDate,fldMablagh,'pardakht'
														from tblCheckePardakhti Where fldSanad = @ShomareSanad													
										end

								----INSERT INTO dbo.tblTest5
								----	 (name1, name2, name3)
								----		VALUES        (@lngMablagheCheckeVagozari,'','hh')

								if @lngMablagheCheckeVagozari>0 
									begin													
													
										insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)

												select Convert(varchar,@EmpId ) + '400' + Convert(varchar,id) ,'ش پ' ,@ShomareSanad,'واگذاری چک شماره ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + iif(@strSCheckVaghozari='','','-' +@strSCheckVaghozari) ,@bigDate,fldMablagh,'pardakht'
													from tblCheckeDaryafti Where fldShomarePardakht = @ShomarePardakht													
									end

									if @lngTakhfif>0
										begin
											set @strSharheHesab = 'تخفیفات پرداخت '
											insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
												values (Convert(varchar,@EmpId ) + '500' ,'ش پ' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,@strSharheHesab + iif(@strSharheTakhfifat='','',' - ' +@strSharheTakhfifat),@bigDate,@lngTakhfif,'pardakht')
										end
								



							end		    
								
						end

						if @type='EbtedaAshkhas'
							begin
								update #tmpSooratHesab2 set fldSharh='طلب ابتدای دوره' + iif(fldSharh<>'' and fldSharh is not null,'-' +fldSharh,''),fldType='ebtedadore' Where fldBestankar>0 and ID=@EmpId 
								update #tmpSooratHesab2 set fldSharh='بدهی ابتدای دوره' + iif(fldSharh<>'' and fldSharh is not null,'-' +fldSharh,''),fldType='ebtedadore' Where fldBedehkar>0 and ID=@EmpId 
							end

						if @type is null
							begin
								declare @strNameHesab nvarchar(50),@strCodeMoinKamel nvarchar(50)

								set @strcodemoinkamel = (Select fldMoinKamel from #tmpSooratHesab2 Where ID=@EmpId)
								execute NameKolMoin @strcodemoinkamel  ,@strNameHesab output
								update #tmpSooratHesab2 set fldSharh=@strNameHesab + iif(fldSharh<>'' and fldSharh is not null,'-' +fldSharh,''),fldType='other' Where   ID=@EmpId 
							end
					
				Fetch Next from EmpCursor
				into @EmpId
			end
	Close EmpCurSor
	Deallocate EmpCursor

	--set @select ='Select ID, fldSanad, fldDay, fldMonth, fldYear, fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, fldRadif, 
 --                        fldCodeSharh, fldDate, fldSharh, fldMoinKamel, fldCodeNoeTafzili, fldGhateiMovaghat, fldGhateiDaem, fldSanadGhadim, fldShomarePeigiri, fldMoghayerat, fldType, 
 --                        fldVasete from #tmpSooratHesab2'

	--execute (@Select)
	--Select ID, fldSanad,  fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, fldRadif, 
 --                       fldCodeSharh, fldDate, fldSharh, fldMoinKamel, fldCodeNoeTafzili, fldGhateiMovaghat, fldGhateiDaem, fldSanadGhadim, fldShomarePeigiri, fldMoghayerat, fldType, 
 --                       fldVasete from #tmpSooratHesab2

	--رکوردهایی که در پایان باید حذف بشن
	delete #tmpSooratHesab2 where fldVaziat='delete'

	--#### حذف محدوده ها ######
	


	set @SumBedGhabl=(Select Sum(fldBedehkar) as SumBed from  #tmpSooratHesab2  Where fldBestankar is not null and fldBedehkar is not null and Convert(dec,fldDate)<@bigDateMin)
	if @SumBedGhabl is null
		set @SumBedGhabl =0

	set @SumBesGhabl=(Select Sum(fldBestankar) as SumBes from  #tmpSooratHesab2  Where fldBestankar is not null and fldBedehkar is not null  and Convert(dec,fldDate)<@bigDateMin)
	if @SumBesGhabl is null
		set @SumBesGhabl=0

	delete #tmpSooratHesab2  Where Convert(dec,fldDate)<@bigDateMin

	update #tmpSooratHesab2 set fldNameVahed2='' Where fldNameVahed2=N'انتخاب کنید'

	if @flagMande =1 --با نقل مانده		
		if (@SumBedGhabl-@SumBesGhabl)<>0
			insert into #tmpSooratHesab2
				(id,shomare,fldSanad,fldSharh,fldDate,fldBedehkar,fldBestankar,fldMande)
					values
				('0','','0','مانده قبل','0',@SumBedGhabl,@SumBesGhabl,@SumBedGhabl-@SumBesGhabl)

	--select * from #tmpSooratHesab2 order by Convert(dec,fldSanad),Convert(varchar,id)
	declare @strOrder nvarchar(30)

	--if @intOrder=0  --مرتب سازی براساس تاریخ
	--	select * from #tmpSooratHesab2 order by Convert(dec,fldDate),Convert(varchar,id)
	--else --مرتب سازی براساس سند
	--	select * from #tmpSooratHesab2 order by Convert(dec,fldSanad),Convert(varchar,id)



	if @intOrder=0  --مرتب سازی براساس تاریخ
		select  ID,radif,shomare,fldSanad,fldSharh,fldRiz,fldDate,fldTedad,fldNameVahed,
			fldNameVahed2,fldFee,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,
			fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,
			fldMablaghKhales,fldCodeAnbar,fldNameAnbar,fldMablagh,fldBedehkar,fldBestankar,fldMande,
			fldType,fldVaziat,fldVasete
		from #tmpSooratHesab2  order by Convert(dec,fldDate),Convert(varchar,id)
		--select  shomare,fldSanad,fldSharh,fldRiz,fldDate,fldTedad,fldNameVahed,
		--	fldFee,fldMablaghKhales,fldBedehkar,fldBestankar,fldMande			
		--	from #tmpSooratHesab2  order by Convert(dec,fldDate),Convert(varchar,id)
	else
		if @intOrder=1  --مرتب سازی براساس سند
			select ID,radif,shomare,fldSanad,fldSharh,fldRiz,fldDate,fldTedad,fldNameVahed,
				fldNameVahed2,fldFee,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,
				fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,
				fldMablaghKhales,fldCodeAnbar,fldNameAnbar,fldMablagh,fldBedehkar,fldBestankar,fldMande,
				fldType,fldVaziat,fldVasete
			from #tmpSooratHesab2  order by Convert(dec,fldSanad),Convert(varchar,id)
end
GO
/****** Object:  StoredProcedure [dbo].[SooratHesab22]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[SooratHesab22]
@mm bigint output
as
begin
	Select *
		Into   #Temp
		From   tblSodooreSanad

		Declare @Id int,@Jam bigint
		set @Jam=0

		While (Select Count(*) From #Temp) > 0
		Begin

			Select Top 1 @Id = Id From #Temp

			--Do some processing here

			--Delete #Temp Where Id = @Id
			set @jam=@Jam+( Select fldBedehkar from #Temp Where Id = @Id)
		End
		set @mm=@jam
end

GO
/****** Object:  StoredProcedure [dbo].[spEmpDetails]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spEmpDetails]
@Type VARCHAR(15),

@Details3 TestEmpType2 Readonly
AS
BEGIN
            if @type='1'
				begin
            --For inserting the new records in the table
					INSERT INTO tblTest3(fld1, fld2) 
						SELECT ID, Name FROM @Details3 
				end
			else
				begin
					INSERT INTO tblTest3(fld1, fld2) 
						SELECT ID, Name FROM @Details3 
				end
				EXEC usp_InsertProductionLocation @Details3;
end

			
     
   


GO
/****** Object:  StoredProcedure [dbo].[spTable]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[spTable]
@tbl tbl1 Readonly

as

begin

	insert into tbltest6
		select * from @tbl
end
GO
/****** Object:  StoredProcedure [dbo].[TafzilieDaramad]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create proc [dbo].[TafzilieDaramad]
@CodeKolMoin nvarchar(10),
@Sanad bigint

as

begin
	declare @CodeKolMoin2 nvarchar(10),@strTypeOfTafzili nvarchar(50)
	execute CodeMoinHesab 'daramad',@CodeKolMoin output

	set @strTypeOfTafzili=(	Select isnull(fldCodeNoeHesab,'-1') from tblKolMoin where fldCodeHesab=  @CodeKolMoin  and fldNoeHesab<>'تفصيلي ندارد')
	if @strTypeOfTafzili<>'-1' 
		begin	
			--set @Mande=(SELECT       isnull( SUM(ISNULL(fldBedehkar, -1) - ISNULL(fldBestankar, 0)),0) AS SumM
			--	FROM            tblSodooreSanad
			--	WHERE      (fldMoinKamel=@CodeKolMoin)  and Convert(bigint,fldSanad)<=@Sanad)
			Select fldCodeTafzili,fldSharheTafzili from tblTafzili where fldCodeNoe=@strTypeOfTafzili order by fldCodeTafzili

		end
end

GO
/****** Object:  StoredProcedure [dbo].[TekrariAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[TekrariAnbar]

@NameAnbar nvarchar(70),
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountAnbar int
	if @IDType=0  --برای مقایسه برای حالت اضافه کردن رکورد
		begin
		 set @RowCountAnbar=(Select Count(fldNameAnbar) from tblAnbar  Where fldNameAnbar=@NameAnbar)
		 set @flagOUt=@rowcountanbar
		end
	else
		begin --برای مقایسه با غیرخودش در حالت ویرایش
		   set	@RowCountAnbar=(Select  Count(fldNameAnbar) from tblAnbar  Where fldNameAnbar=@NameAnbar and ID<>@ID)
		   set @flagOUt=@rowcountanbar
		end
end


GO
/****** Object:  StoredProcedure [dbo].[TekrariBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[TekrariBankeMoshtari]

@NameBank nvarchar(70),
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountBank int
	if @IDType=0  --برای مقایسه برای حالت اضافه کردن رکورد
		begin
		 set @RowCountBank=(Select Count(fldNameBank) from tblBankeMoshtari  Where fldNameBank=@NameBank)
		 set @flagOUt=@rowcountBank
		end
	else
		begin --برای مقایسه با غیرخودش در حالت ویرایش
		   set	@RowCountBank=(Select  Count(fldNameBank) from tblBankeMoshtari  Where fldNameBank=@NameBank and ID<>@ID)
		   set @flagOUt=@rowcountBank
		end
end


GO
/****** Object:  StoredProcedure [dbo].[TekrariKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[TekrariKolMoin]

@NameKolMoin nvarchar(50),
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountKolMoin int
	if @IDType=0  --برای مقایسه برای حالت اضافه کردن رکورد
		begin
		 set @RowCountKolMoin=(Select Count(fldSharheHesab) from tblKolMoin  Where fldSharheHesab=@NameKolMoin)
		 set @flagOUt=@RowCountKolMoin
		end
	else
		begin --برای مقایسه با غیرخودش در حالت ویرایش
		   set	@RowCountKolMoin=(Select  Count(fldSharheHesab) from tblKolMoin  Where fldSharheHesab=@NameKolMoin and ID<>@ID)
		   set @flagOUt=@RowCountKolMoin
		end
end


GO
/****** Object:  StoredProcedure [dbo].[TekrariVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[TekrariVahed]

@NameVahed nvarchar(70),
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountAnbar int
	if @IDType=0  --برای مقایسه برای حالت اضافه کردن رکورد
		begin
		 set @RowCountAnbar=(Select Count(fldNameVahed) from tblVahed  Where fldNameVahed=@NameVahed)
		 set @flagOUt=@rowcountanbar
		end
	else
		begin --برای مقایسه با غیرخودش در حالت ویرایش
		   set	@RowCountAnbar=(Select  Count(fldNameVahed) from tblVahed  Where fldNameVahed=@NameVahed and ID<>@ID)
		   set @flagOUt=@rowcountanbar
		end
end


GO
/****** Object:  StoredProcedure [dbo].[TestCursor]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[TestCursor]
--@NameHesab nvarChar(50),
--@Meghdar bigint OutPut


as
--این کرسر کارش اینه که یک یکه رکوردهای جدول سند رو فراخوانی میکنه و طبق حلقه بروزسانی انجام میده
begin
	declare @EmpId bigint
	declare EmpCursor Cursor For
		Select Id from tblSodooreSanad With (NoLock)
			open EmpCursor
			fetch Next From EmpCursor into @EmpId
			While @@Fetch_Status = 0
				Begin
					Update tblSodooreSanad With (RowLock) Set [fldGhateiMovaghat]='false'
					Where ID=@EmpId

				Fetch Next from EmpCursor
				into @EmpId
			end
	Close EmpCurSor
	Deallocate EmpCursor

end
GO
/****** Object:  StoredProcedure [dbo].[testehsan]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[testehsan]
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@s bigint output
	as

BEGIN
    
	set @s=(SELECT count(*) from @dtCheckDaryafti);
END

GO
/****** Object:  StoredProcedure [dbo].[TestInsert]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[TestInsert]
@adad bigint
--@inID bigint output
as

begin
	--declare @lngShomareSanad nvarchar(50)
	declare @lngShomareSanad int
	--execute insertSanadFirst '111','01','11101','1111','1',@adad,0,'1',950101,'sha','daryaft',@lngShomareSanad output	;
	execute  ToolePaye 'kol',@lngShomareSanad output;
	INSERT INTO tblTest7(fld1)
		VALUES        (@lngShomareSanad)
end


GO
/****** Object:  StoredProcedure [dbo].[TESTReport_ListAshkhas_groupby_NameGroup_order_SharhTafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[TESTReport_ListAshkhas_groupby_NameGroup_order_SharhTafsili]
@CodeGroupAshkhas varchar(1000)
as
declare @myReport varchar(1000)
begin
 set @myReport='SELECT DISTINCT 
                         dbo.tblTafzili.fldCodeGroup, dbo.tblGroupAshkhas.fldGroupId, dbo.tblGroupAshkhas.fldGroupName, dbo.tblDaftarcheTell.fldShomare, 
                         dbo.tblTafzili.fldCodeTafzili
FROM            dbo.tblGroupAshkhas INNER JOIN
                         dbo.tblTafzili ON dbo.tblGroupAshkhas.fldGroupId = dbo.tblTafzili.fldCodeGroup INNER JOIN
                         dbo.tblDaftarcheTell ON CONVERT(int, dbo.tblTafzili.fldCodeTafzili) = CONVERT(int, dbo.tblDaftarcheTell.fldCodeTafzili)
where fldCodeGroup in('+ @CodeGroupAshkhas +')
GROUP BY dbo.tblGroupAshkhas.fldGroupName, dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, dbo.tblDaftarcheTell.fldShomare, dbo.tblTafzili.fldCodeMeli, 
                         dbo.tblTafzili.fldAddress,dbo.tblGroupAshkhas.fldGroupId
ORDER BY dbo.tblTafzili.fldSharheTafzili'
exec( @myReport)
end
GO
/****** Object:  StoredProcedure [dbo].[TestTransaction]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[TestTransaction]
@intadad as bigint,
@intKhata int output
as
begin
	begin transaction transact
		begin try
			insert into tblTest2
				values('mohammad')
				
			if @intadad>0 
				begin
					insert into tblTest
						values(@intadad)
				end
			else
				begin
					insert into tblTest
						values('majid')
				end
			
	commit transaction
		end try

	begin catch
		if @@trancount>0 
			rollback transaction ;
			set @intkhata=1

	end catch
end
GO
/****** Object:  StoredProcedure [dbo].[ToolePaye]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[ToolePaye]
@type nvarchar(10),
@Tool int output
as
begin
	if @type='kol'
		begin
			set @tool=(select fldKol from   tblPaye )
		end
	else if @type='moin'
		begin
			set @tool=(select fldMoin from tblPaye)
		end
	else if @type='tafzili'
		begin
			set @tool=(select fldTafzili from tblPaye)
		end
	else if @type='markaz1'
		begin
			set @tool=(select fldMarkaz1 from tblPaye)
		end
	else if @type='markaz2'
		begin
			set @tool=(select fldMarkaz2 from tblPaye)
		end

end


GO
/****** Object:  StoredProcedure [dbo].[UpadteChap]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[UpadteChap]
	@fldNameMoassese nvarchar(150),
	@fldTozihateBala nvarchar(150),
	@fldAdress nvarchar(MAX),
	@fldPasafhe nvarchar(MAX),
	@fldCodeEghtesadi nvarchar(20),
	@fldShomareSabt nvarchar(20),
	@fldCodePosti nvarchar(20),
	@fldTell nvarchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	update tblChap 
		set fldNameMoassese= @fldNameMoassese ,
			fldTozihateBala=@fldTozihateBala ,
			fldAdress=@fldAdress ,
			fldPasafhe=@fldPasafhe ,
			fldCodeEghtesadi=@fldCodeEghtesadi ,
			fldShomareSabt=@fldShomareSabt ,
			fldCodePosti=@fldCodePosti ,
			fldTell=@fldTell 
	
	update tblControlPanel
		set fldNameSherkat=@fldNameMoassese
END

GO
/****** Object:  StoredProcedure [dbo].[Update_Tbl_DaftarcheTell_Has_CodeTafisili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Update_Tbl_DaftarcheTell_Has_CodeTafisili]
@fldIdTell bigint,
@fldcodeTafzili nvarchar(10),
@fldShomare	nvarchar(50),
@fldSms	nvarchar(20),
@fldSharh	nvarchar(100),
@flagUpdate int output	
as
begin

update tblDaftarcheTell
set
fldCodeTafzili=@fldcodeTafzili,
fldShomare= @fldShomare,
fldSms= @fldSms,
fldSharh= @fldSharh 
 where fldIdDaftarche=@fldIdTell
set @flagUpdate=1
end

GO
/****** Object:  StoredProcedure [dbo].[Update_Tbl_DaftarcheTell_NotHas_CodeTafisili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Update_Tbl_DaftarcheTell_NotHas_CodeTafisili]
@fldIdTell bigint,
@fldName	nvarchar(50),
@fldShomare	nvarchar(50),
@fldSms	nvarchar(20),
@fldSharh	nvarchar(100),
@flagUpdate int output	
as
begin


update tblDaftarcheTell
set
fldCodeTafzili='0',
fldName= @fldName,
fldShomare= @fldShomare,
fldSms= @fldSms,
fldSharh= @fldSharh 
 where fldIdDaftarche=@fldIdTell
set @flagUpdate=1
end

GO
/****** Object:  StoredProcedure [dbo].[Update_Tbl_Tafsili]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[Update_Tbl_Tafsili]
@fldNoeHesab	nvarchar(15),	
@fldSharheTafzili	nvarchar(200),
@fldCodeTafzili	nvarchar(10),	
@fldCodeNoe	nvarchar(5),	--set "1"
@fldNoe	nvarchar(10),	
@fldCodeGroup	bigint,	        
@fldOstan	nvarchar(50),	
@fldCity	nvarchar(50),	
@fldAddress	nvarchar(200),	
@fldShomareHesab	nvarchar(20),	
@fldCodeMeli	nvarchar(20),	
@fldCodeEghtesadi	nvarchar(20),	
@fldCodePosti	nvarchar(20),	
@fldShomareSabt	nvarchar(20),	
@fldSaghfeEtebar	decimal,
@fldBlackList	nvarchar(5),	
@fldSharhBlackList	nvarchar(100),	
@fldDate1	bigint,	
@fldDate2	bigint,	
@fldVisitor	bigint,	
@fldPic	nvarchar(300),
@flagUpdateOK int output

as
begin
set @fldVisitor=isnull(@fldVisitor,0)
update  tblTafzili
set fldNoeHesab='',
    fldSharheTafzili=@fldSharheTafzili,
	fldCodeNoe=@fldCodeNoe,
	fldNoe=@fldNoe,
	fldCodeGroup=@fldCodeGroup,
	fldOstan=@fldOstan,
	fldCity=@fldCity,
	fldAddress=@fldAddress,
	fldShomareHesab=@fldShomareHesab,
	fldCodeMeli=@fldCodeMeli,
	fldCodeEghtesadi=@fldCodeEghtesadi,
	fldCodePosti=@fldCodePosti,
	fldShomareSabt=@fldShomareSabt,
	fldSaghfeEtebar=@fldSaghfeEtebar,
	fldBlackList=@fldBlackList,
	fldSharhBlackList=@fldSharhBlackList,
	fldDate1=@fldDate1,
	fldDate2=@fldDate2,
	fldVisitor=@fldVisitor,
	fldPic=@fldPic
where fldCodeTafzili=@fldCodeTafzili
set @flagUpdateOK=1
END

GO
/****** Object:  StoredProcedure [dbo].[UpdateDaftarCheTelPersonel]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[UpdateDaftarCheTelPersonel] 
	@CodeTafzili nvarchar(10),
	@Name nvarchar(50),
	@ShomareOld nvarchar(50),
	@ShomareNew nvarchar(50)

AS
BEGIN
	--if ISNUMERIC(@shomarenew)=1
	delete tblDaftarcheTell Where fldShomare=@ShomareOld and fldCodeTafzili=@CodeTafzili

	INSERT        INTO              tblDaftarcheTell(fldCodeTafzili, fldName, fldShomare, fldSms, fldSharh)
			VALUES        (@CodeTafzili,@Name,@ShomareNew,'غیرفعال','')
		
	--update tblDaftarcheTell
	--	set fldShomare=@ShomareNew,fldName=@Name
	--	Where fldShomare=@ShomareOld and fldCodeTafzili=@CodeTafzili
END

GO
/****** Object:  StoredProcedure [dbo].[UpdateGroupAshkhas]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[UpdateGroupAshkhas]
@fldGroupAshkhasId bigint,
@fldGroupAshkhasName nvarchar(50),
@flagduplicate  int output
AS

Begin
if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName)
 begin
update tblGroupAshkhas
set fldGroupName=@fldGroupAshkhasName
where fldGroupId=@fldGroupAshkhasId

set @flagduplicate=0 

 end
 else
 begin
 set @flagduplicate=1
 end
end


GO
/****** Object:  StoredProcedure [dbo].[UpdateGroupKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[UpdateGroupKala]
@fldGroupKalaId bigint,
@fldGroupKalaName nvarchar(50),
@flagduplicate  int output
AS
--BEGIN
--set @hasrow=(select count(fldGroupId) from tblGroupKala where CONVERT(nvarchar(50),fldGroupId) like CONVERT(nvarchar(50), @fldGroupKalaId) + '%')
--if @hasrow=1
--begin

--set @f=0

Begin
if not Exists(select fldGroupName  from tblGroupKala where fldGroupName=@fldGroupKalaName)
 begin
update tblGroupKala
set fldGroupName=@fldGroupKalaName
where fldGroupId=@fldGroupKalaId

set @flagduplicate=0 

 end
 else
 begin
 set @flagduplicate=1
 end
end
--end
--else
--begin
--set @f=1
--  end
--END

GO
/****** Object:  StoredProcedure [dbo].[UpdateTblAnbar]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[UpdateTblAnbar]

@ID int,
@NameAnbar nvarchar(70),
@flagOut int output
as

begin
	Update tblAnbar Set fldNameAnbar=@NameAnbar Where ID=@id
	set @flagOut=1
end
GO
/****** Object:  StoredProcedure [dbo].[UpdateTblBankeMoshtari]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[UpdateTblBankeMoshtari]

@ID int,
@NameBank nvarchar(70),
@flagOut int output
as

begin
	Update tblBankeMoshtari Set fldNameBank=@NameBank Where ID=@id
	set @flagOut=1
end
GO
/****** Object:  StoredProcedure [dbo].[UpdateTblKala]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[UpdateTblKala]
	@dtTblKala dtKala  readonly
AS
BEGIN
	delete from tblKala

	INSERT      into          dbo.tblKala( fldNameKala, fldCodeKala, fldSerial, fldCodeGroup, fldCodeVahed1, fldCodeVahed2, fldNogheSefaresh, fldSharh, fldTedadJoz, fldFeeDarsadKharid, 
                         fldFeeBadAzTakhfif, fldNerkhePorsantKol, fldNerkhePorsantJoz, fldFeeForoosh, fldPathPic, fldGhymatMasrafkonande, fldIDPrinter)
			select         fldNameKala, fldCodeKala, fldSerial, fldCodeGroup, fldCodeVahed1, fldCodeVahed2, fldNogheSefaresh, fldSharh, fldTedadJoz, fldFeeDarsadKharid, 
									 fldFeeBadAzTakhfif, fldNerkhePorsantKol, fldNerkhePorsantJoz, fldFeeForoosh, fldPathPic, fldGhymatMasrafkonande, fldIDPrinter output from @dtTblKala
END

GO
/****** Object:  StoredProcedure [dbo].[UpdateTblKolMoin]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[UpdateTblKolMoin]

@ID int,
@NameHesab nvarchar(70),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@flagOut int output
as

begin
	Update tblKolMoin Set fldSharheHesab =@NameHesab,fldCodeNoeHesab=@CodeType,fldNoeHesab=@SharheNoeTafzili Where ID=@id
	set @flagOut=1
end
GO
/****** Object:  StoredProcedure [dbo].[UpdateTblTafziliIdCaller]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[UpdateTblTafziliIdCaller] 
	@CodeTafzili nvarchar(10),
	@Address nvarchar(200),
	@SharheTafzili nvarchar(200)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	update tblTafzili Set fldAddress=@Address , fldSharheTafzili=@SharheTafzili  Where fldCodeTafzili=@CodeTafzili

END

GO
/****** Object:  StoredProcedure [dbo].[UpdateTblVahed]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo].[UpdateTblVahed]

@ID int,
@NameVahed nvarchar(70),
@flagOut int output
as

begin
	Update tblVahed Set fldNameVahed=@NameVahed Where ID=@id
	set @flagOut=1
end
GO
/****** Object:  StoredProcedure [dbo].[usp_InsertProductionLocation]    Script Date: 02/19/2018 12:56:08 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_InsertProductionLocation]  
    @TVP LocationTableType READONLY  
    AS   
    SET NOCOUNT ON  
    INSERT INTO tblTest5 
           (name1,  
            id) 
        SELECT *
        FROM  @TVP;  

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 10
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dah', @level1type=N'VIEW',@level1name=N'viewLoadVizitor'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dah', @level1type=N'VIEW',@level1name=N'viewLoadVizitor'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[22] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblDaftarcheTell"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 222
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 12
               Left = 460
               Bottom = 249
               Right = 643
            End
            DisplayFlags = 280
            TopColumn = 7
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Join_TblTell_TblTafzili'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Join_TblTell_TblTafzili'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'lstlistKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'lstlistKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[42] 4[10] 2[17] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblGroupAshkhas"
            Begin Extent = 
               Top = 51
               Left = 38
               Bottom = 199
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 27
               Left = 279
               Bottom = 257
               Right = 462
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblDaftarcheTell"
            Begin Extent = 
               Top = 39
               Left = 619
               Bottom = 230
               Right = 789
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_2'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_2'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[44] 4[8] 2[5] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 1
               Left = 369
               Bottom = 397
               Right = 552
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblDaftarcheTell"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 2
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 19
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_ListAshkhas_In_ReportFactorForosh_AliJahangard'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_ListAshkhas_In_ReportFactorForosh_AliJahangard'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[21] 2[15] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblChap"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 224
            End
            DisplayFlags = 280
            TopColumn = 4
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_TblChap'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_TblChap'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[11] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 221
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[21] 2[11] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblAnbar"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 149
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetAnbarForComboBox'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetAnbarForComboBox'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[36] 4[13] 2[11] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblEshantionTabaghati"
            Begin Extent = 
               Top = 15
               Left = 308
               Bottom = 224
               Right = 513
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 11
               Left = 602
               Bottom = 235
               Right = 800
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblKala_1"
            Begin Extent = 
               Top = 25
               Left = 32
               Bottom = 235
               Right = 230
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 10
         Width = 284
         Width = 1935
         Width = 1500
         Width = 2355
         Width = 2130
         Width = 2310
         Width = 2445
         Width = 2385
         Width = 2310
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetListEshantionTabalaghti'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetListEshantionTabalaghti'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[34] 4[16] 2[27] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 128
               Left = 483
               Bottom = 353
               Right = 710
            End
            DisplayFlags = 280
            TopColumn = 8
         End
         Begin Table = "tblRizeForoosh"
            Begin Extent = 
               Top = 0
               Left = 213
               Bottom = 370
               Right = 443
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblAnbar"
            Begin Extent = 
               Top = 12
               Left = 628
               Bottom = 124
               Right = 798
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed"
            Begin Extent = 
               Top = 11
               Left = 4
               Bottom = 106
               Right = 174
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed_2"
            Begin Extent = 
               Top = 152
               Left = 19
               Bottom = 247
               Right = 189
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 28
         Width = 284
         Width = 1500
         Width = 2280
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
   ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGridForoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'      Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGridForoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGridForoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[10] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListBarcodeKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListBarcodeKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[42] 4[21] 2[25] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala (dbo)"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed (dbo)"
            Begin Extent = 
               Top = 6
               Left = 303
               Bottom = 101
               Right = 473
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed_1"
            Begin Extent = 
               Top = 6
               Left = 482
               Bottom = 101
               Right = 652
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListKalaInFactorForoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListKalaInFactorForoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 236
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed"
            Begin Extent = 
               Top = 6
               Left = 274
               Bottom = 101
               Right = 444
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed_1"
            Begin Extent = 
               Top = 6
               Left = 482
               Bottom = 101
               Right = 652
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListKalaInFactorForooshByFldCodeGroup'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListKalaInFactorForooshByFldCodeGroup'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[11] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 222
               Right = 236
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListSmallKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewListSmallKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[33] 4[19] 2[23] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblGroupAshkhas"
            Begin Extent = 
               Top = 61
               Left = 41
               Bottom = 192
               Right = 227
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 48
               Left = 274
               Bottom = 177
               Right = 473
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblDaftarcheTell"
            Begin Extent = 
               Top = 45
               Left = 615
               Bottom = 250
               Right = 801
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewReportListAshkhasByIN'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewReportListAshkhasByIN'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[12] 2[19] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblRizeForoosh"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 209
               Right = 268
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblAnbar"
            Begin Extent = 
               Top = 0
               Left = 287
               Bottom = 112
               Right = 457
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 28
               Left = 512
               Bottom = 157
               Right = 695
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 27
               Left = 738
               Bottom = 156
               Right = 965
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGroupAshkhas"
            Begin Extent = 
               Top = 159
               Left = 486
               Bottom = 254
               Right = 656
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGroupKala"
            Begin Extent = 
               Top = 138
               Left = 38
               Bottom = 233
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 30
         Width = 284
         Width = 1500
     ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewRizeForooshEhsan'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'    Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewRizeForooshEhsan'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewRizeForooshEhsan'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[42] 4[10] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblKala (dbo)"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 213
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed (dbo)"
            Begin Extent = 
               Top = 6
               Left = 303
               Bottom = 101
               Right = 473
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblVahed_1"
            Begin Extent = 
               Top = 72
               Left = 516
               Bottom = 167
               Right = 686
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewShowListKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewShowListKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblGroupKala"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 105
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewShowListSmallGroupKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewShowListSmallGroupKala'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[4] 4[34] 2[23] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblRizeForoosh"
            Begin Extent = 
               Top = 64
               Left = 341
               Bottom = 288
               Right = 571
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili_1"
            Begin Extent = 
               Top = 11
               Left = 660
               Bottom = 248
               Right = 843
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 20
               Left = 82
               Bottom = 280
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewtestforoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewtestforoosh'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[7] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 214
               Right = 221
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblDaftarcheTell"
            Begin Extent = 
               Top = 20
               Left = 466
               Bottom = 254
               Right = 636
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewtestShomaretel'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewtestShomaretel'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[42] 4[21] 2[28] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblCheckePardakhti"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 240
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 19
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1485
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1980
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viwListeCheckHayePasNashode'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viwListeCheckHayePasNashode'
GO
USE [master]
GO
ALTER DATABASE [namedatabase] SET  READ_WRITE 
GO
